public PhysicalChannelDefinition generate(LogicalChannel channel, QName deployable) throws GenerationException { URI uri = channel.getUri(); ChannelDefinition definition = channel.getDefinition(); String channelType = definition.getType(); boolean replicate = definition.getIntents().contains(ChannelConstants.REPLICATE_INTENT); PhysicalChannelDefinition physicalDefinition = new PhysicalChannelDefinition(uri, deployable, replicate, channelType, ASYNCHRONOUS_WORKER); physicalDefinition.setMetadata(definition.getMetadata().get(ChannelConstants.METADATA)); return physicalDefinition; }
public void bind(LogicalChannel channel) { QName deployable = channel.getParent().getDeployable(); String topic = channel.getUri().toString(); JmsBindingDefinition channelDefinition = createTopicBindingDefinition(topic); LogicalBinding<JmsBindingDefinition> channelBinding = new LogicalBinding<JmsBindingDefinition>(channelDefinition, channel, deployable); channelBinding.setAssigned(true); channel.addBinding(channelBinding); }
/** * Selects and configures a binding for a channel. * * @param channel the channel * @throws BindingSelectionException if an error occurs selecting a binding */ private void selectBinding(LogicalChannel channel) throws BindingSelectionException { if (channel.isConcreteBound()) { return; } List<BindingMatchResult> results = new ArrayList<BindingMatchResult>(); for (BindingProvider provider : providers) { BindingMatchResult result = provider.canBind(channel); if (result.isMatch()) { // clear binding.sca channel.clearBinding(); provider.bind(channel); if (channel.getBindings().isEmpty()) { QName type = result.getType(); throw new BindingSelectionException("Binding provider error. Provider did not set a binding for the channel: " + type); } return; } results.add(result); } URI uri = channel.getUri(); throw new NoSCABindingProviderException("No SCA binding provider suitable for channel " + uri, results); }
public void allocate(LogicalChannel channel, DeploymentPlan plan) throws AllocationException { QName deployable = channel.getDeployable(); if (deployable == null) { // programming error throw new AssertionError("Deployable not found for " + channel.getUri()); } String zoneName = plan.getDeployableMappings().get(deployable); if (zoneName == null) { throw new DeployableMappingNotFoundException("Zone mapping not found for deployable: " + deployable); } channel.setZone(zoneName); }
private PhysicalChannelConnectionDefinition generateProducerConnection(LogicalProducer producer, LogicalChannel channel, PhysicalConnectionSourceDefinition sourceDefinition, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { if (!channel.getZone().equals(producer.getParent().getZone()) && !channel.isBound()) { String name = channel.getDefinition().getName(); throw new GenerationException("Binding not configured on a channel where the producer is in a different zone: " + name); } PhysicalConnectionTargetDefinition targetDefinition = new ChannelTargetDefinition(channel.getUri(), ChannelSide.PRODUCER); targetDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }
@SuppressWarnings({"unchecked"}) private PhysicalChannelConnectionDefinition generateProducerBinding(LogicalProducer producer, LogicalChannel channel, ChannelDeliveryType deliveryType, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { LogicalBinding<?> binding = channel.getBinding(); ConnectionBindingGenerator bindingGenerator = getGenerator(binding); PhysicalConnectionTargetDefinition targetDefinition = bindingGenerator.generateConnectionTarget(producer, binding, deliveryType); targetDefinition.setClassLoaderId(classLoaderId); ChannelSourceDefinition sourceDefinition = new ChannelSourceDefinition(channel.getUri(), ChannelSide.PRODUCER); sourceDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }
/** * Adds a channel. * * @param channel the channel to add */ public void addChannel(LogicalChannel channel) { channels.put(channel.getUri(), channel); }
private PhysicalChannelConnection generateLocalConnection(LogicalProducer producer, Class<?> type, LogicalChannel channel, PhysicalConnectionSource source, ClassLoader classLoader) { URI uri = channel.getUri(); PhysicalConnectionTarget target = new ChannelTarget(uri, ChannelSide.PRODUCER); target.setClassLoader(classLoader); boolean bound = channel.isBound(); return new PhysicalChannelConnection(uri, producer.getUri(), source, target, type, bound); }
@SuppressWarnings({"unchecked"}) private PhysicalChannelConnection generateBoundConnection(LogicalProducer producer, LogicalChannel channel, DeliveryType deliveryType, ClassLoader classLoader) { LogicalBinding<?> binding = channel.getBinding(); ConnectionBindingGenerator bindingGenerator = getGenerator(binding); PhysicalConnectionTarget target = bindingGenerator.generateConnectionTarget(producer, binding, deliveryType); target.setClassLoader(classLoader); URI uri = channel.getUri(); ChannelSource source = new ChannelSource(uri, ChannelSide.PRODUCER); source.setClassLoader(classLoader); boolean bound = channel.isBound(); Class<?> type = getType(producer); return new PhysicalChannelConnection(uri, producer.getUri(), source, target, type, bound); }
private boolean isDirect(LogicalInvocable invocable, Map<LogicalChannel, DeliveryType> channels) { boolean direct = false; if (!channels.isEmpty()) { LogicalChannel logicalChannel = channels.keySet().iterator().next(); ServiceContract contract = invocable.getServiceContract(); if (contract == null) { return false; } Class<?> interfaceClass = contract.getInterfaceClass(); if (logicalChannel.isBound()) { Binding binding = logicalChannel.getBinding().getDefinition(); if (!binding.getConnectionTypes().isEmpty()) { direct = binding.getConnectionTypes().stream().anyMatch(t -> t.isAssignableFrom(interfaceClass)); } } else { Channel channel = logicalChannel.getDefinition(); if (!channel.getConnectionTypes().isEmpty()) { direct = channel.getConnectionTypes().stream().anyMatch(t -> t.isAssignableFrom(interfaceClass)); } } } return direct; }
if (channel.getDefinition() != null && !contributionUri.equals(channel.getDefinition().getContributionUri())) { continue; // composite is not part of the contribution being undeployed if (contributionUri.equals(channel.getDefinition().getContributionUri())) { channel.setState(MARKED); LogicalBinding<?> binding = channel.getBinding(); if (binding != null && contributionUri.equals(binding.getTargetContribution())) { binding.setState(MARKED);
public void instantiateChannels(Composite composite, LogicalCompositeComponent parent, InstantiationContext context) { for (ChannelDefinition definition : composite.getChannels().values()) { URI uri = URI.create(parent.getUri() + "/" + definition.getName()); if (parent.getChannel(uri) != null) { DuplicateChannel error = new DuplicateChannel(uri, parent); context.addError(error); continue; } LogicalChannel channel = new LogicalChannel(uri, definition, parent); for (BindingDefinition binding : definition.getBindings()) { LogicalBinding<BindingDefinition> logicalBinding = new LogicalBinding<BindingDefinition>(binding, channel); channel.addBinding(logicalBinding); } channel.setDeployable(composite.getName()); parent.addChannel(channel); } }
@SuppressWarnings({"unchecked"}) private PhysicalChannelDefinition generateChannelDefinition(LogicalChannel channel, QName deployable, Direction direction) throws GenerationException { LogicalBinding<?> binding = channel.getBinding(); String type = channel.getDefinition().getType(); ChannelGenerator generator = channelGenerators.get(type); if (generator == null) { throw new GenerationException("Channel generator not found: " + type); } PhysicalChannelDefinition definition = generator.generate(channel, deployable); if (!channel.getBindings().isEmpty()) { // generate binding information if (!(binding.getDefinition() instanceof SCABinding)) { // avoid generating SCABinding ConnectionBindingGenerator bindingGenerator = getGenerator(binding); ChannelDeliveryType deliveryType = definition.getDeliveryType(); PhysicalChannelBindingDefinition bindingDefinition = bindingGenerator.generateChannelBinding(binding, deliveryType); definition.setBindingDefinition(bindingDefinition); definition.setChannelSide(Direction.CONSUMER == direction ? ChannelSide.CONSUMER : ChannelSide.PRODUCER); } else { definition.setChannelSide(ChannelSide.COLLOCATED); } } else { definition.setChannelSide(ChannelSide.COLLOCATED); } return definition; }
@SuppressWarnings("unchecked") public PhysicalChannel generate(LogicalChannel channel, URI contributionUri, ChannelDirection direction) { String type = channel.getDefinition().getType(); ChannelGeneratorExtension generator = extensions.get(type); if (generator == null) { throw new Fabric3Exception("Channel generator not found: " + type); } PhysicalChannel physicalChannel = generator.generate(channel, contributionUri); if (!channel.getBindings().isEmpty()) { // generate binding information physicalChannel.setBound(true); physicalChannel.setChannelSide(ChannelDirection.CONSUMER == direction ? ChannelSide.CONSUMER : ChannelSide.PRODUCER); } else { physicalChannel.setChannelSide(ChannelSide.COLLOCATED); } return physicalChannel; }
public void bind(LogicalChannel channel) throws BindingSelectionException { ZeroMQMetadata metadata = createMetadata(); metadata.setChannelName(channel.getDefinition().getName()); ZeroMQBindingDefinition definition = new ZeroMQBindingDefinition("binding.zeromq", metadata); LogicalBinding<ZeroMQBindingDefinition> binding = new LogicalBinding<ZeroMQBindingDefinition>(definition, channel); channel.addBinding(binding); }
if (NEW == channel.getState()) { channel.setState(PROVISIONED); LogicalBinding<?> binding = channel.getBinding(); if (binding != null && NEW == binding.getState()) { binding.setState(PROVISIONED);
private void setChannelName(LogicalBinding binding, ZeroMQMetadata metadata) { if (binding.getParent() instanceof LogicalChannel) { String channelName = ((LogicalChannel) binding.getParent()).getDefinition().getName(); metadata.setChannelName(channelName); } }
/** * Aggregates intents of a binding by walking the implementation and structural hierarchies of the parent. * * @param binding the binding * @return the aggregated intents */ protected Set<QName> aggregateIntents(LogicalBinding<?> binding) throws PolicyResolutionException { Bindable parent = binding.getParent(); Set<QName> aggregatedIntents = new LinkedHashSet<>(); // add binding intents aggregatedIntents.addAll(binding.getIntents()); validateIntents(binding); if (parent instanceof LogicalReference) { return aggregateReferenceIntents((LogicalReference) parent, aggregatedIntents); } else if (parent instanceof LogicalService) { return aggregateServiceIntents((LogicalService) parent, aggregatedIntents); } else { // channel LogicalChannel channel = (LogicalChannel) parent; aggregatedIntents.addAll(channel.getDefinition().getIntents()); aggregatedIntents.addAll(channel.getIntents()); return aggregatedIntents; } }
private List<PhysicalChannelConnection> generateDirectConnections(LogicalConsumer consumer, Map<LogicalChannel, DeliveryType> channels, PhysicalConnectionTarget target, ClassLoader classLoader) { List<PhysicalChannelConnection> connections = new ArrayList<>(); for (Map.Entry<LogicalChannel, DeliveryType> entry : channels.entrySet()) { LogicalChannel channel = entry.getKey(); if (!channel.isBound()) { PhysicalChannelConnection producerConnection = generateLocalConnection(consumer, channel, target, classLoader); connections.add(producerConnection); } else { DeliveryType deliveryType = entry.getValue(); PhysicalChannelConnection bindingConnection = generateDirectBoundConnection(consumer, channel, deliveryType, classLoader, target); connections.add(bindingConnection); } } return connections; }
if (deployable.equals(channel.getDeployable())) { channel.setState(LogicalState.MARKED); LogicalBinding<?> binding = channel.getBinding(); if (binding != null && deployable.equals(binding.getDeployable())) { binding.setState(LogicalState.MARKED);