/** * Selects and configures bindings for wires sourced from the given component. * * @param component the component * @throws BindingSelectionException if an error occurs selecting a binding */ private void selectBindings(LogicalComponent<?> component) throws BindingSelectionException { for (LogicalReference reference : component.getReferences()) { for (LogicalWire wire : reference.getWires()) { LogicalService targetService = wire.getTarget(); if (targetService != null) { LogicalComponent<?> targetComponent = targetService.getParent(); if ((LOCAL_ZONE.equals(component.getZone()) && LOCAL_ZONE.equals(targetComponent.getZone()))) { // components are local, no need for a binding continue; } else if (!LOCAL_ZONE.equals(component.getZone()) && component.getZone().equals(targetComponent.getZone())) { // components are local, no need for a binding continue; } selectBinding(wire); } } } }
public Map<String, List<CompensatableCommand>> generate(List<LogicalComponent<?>> components) throws GenerationException { Map<String, List<CompensatableCommand>> commands = new HashMap<String, List<CompensatableCommand>>(); for (LogicalComponent<?> component : components) { if (component.getState() == LogicalState.MARKED) { List<CompensatableCommand> list = getCommands(component.getZone(), commands); QName deployable = component.getDeployable(); // only log application composite deployments boolean log = !component.getUri().toString().startsWith(Names.RUNTIME_NAME); StopContextCommand command = new StopContextCommand(deployable, log); if (!list.contains(command)) { list.add(command); } } } return commands; }
public Map<String, List<CompensatableCommand>> generate(List<LogicalComponent<?>> components, boolean incremental) throws GenerationException { Map<String, List<CompensatableCommand>> commands = new HashMap<String, List<CompensatableCommand>>(); for (LogicalComponent<?> component : components) { if (component.getState() == LogicalState.NEW || !incremental) { QName deployable = component.getDeployable(); // only log application composite deployments boolean log = !component.getUri().toString().startsWith(Names.RUNTIME_NAME); StartContextCommand command = new StartContextCommand(deployable, log); String zone = component.getZone(); List<CompensatableCommand> list = getCommands(zone, commands); if (!list.contains(command)) { list.add(command); } } } return commands; }
/** * Evaluates components for required capabilities, resolving those capabilities to extensions. * * @param components the components to evaluate * @param commands the list of commands to update with un/provision extension commands * @param type the generation type */ private void evaluateComponents(List<LogicalComponent<?>> components, Map<String, CompensatableCommand> commands, GenerationType type) { for (LogicalComponent<?> component : components) { String zone = component.getZone(); if (LogicalComponent.LOCAL_ZONE.equals(zone)) { // skip local runtime continue; } AbstractExtensionsCommand command = getExtensionsCommand(commands, zone, type); evaluateComponent(component, command, type); if (!command.getExtensionUris().isEmpty()) { commands.put(zone, command); } } }
public Map<String, List<Contribution>> collateContributions(List<LogicalComponent<?>> components, GenerationType type) { // collate all contributions that must be provisioned as part of the change set Map<String, List<Contribution>> contributionsPerZone = new HashMap<String, List<Contribution>>(); for (LogicalComponent<?> component : components) { if (type != GenerationType.FULL) { if (GenerationType.INCREMENTAL == type && LogicalState.NEW != component.getState()) { continue; } else if (GenerationType.UNDEPLOY == type && LogicalState.MARKED != component.getState()) { continue; } } URI contributionUri = component.getDefinition().getContributionUri(); String zone = component.getZone(); List<Contribution> contributions = contributionsPerZone.get(zone); if (contributions == null) { contributions = new ArrayList<Contribution>(); contributionsPerZone.put(zone, contributions); } Contribution contribution = store.find(contributionUri); if (include(contribution, contributions)) { collateDependencies(contribution, contributions); } } return contributionsPerZone; }
URI contributionUri = component.getDefinition().getContributionUri(); QName deployable = component.getDeployable(); String zone = component.getZone(); ComponentInfo info = new ComponentInfo(uri, contributionUri, deployable, zone); infos.add(info);
public void allocate(LogicalComponent<?> component, DeploymentPlan plan) throws AllocationException { if (Names.LOCAL_ZONE.equals(component.getZone())) { if (component instanceof LogicalCompositeComponent) { LogicalCompositeComponent composite = (LogicalCompositeComponent) component; for (LogicalComponent<?> child : composite.getComponents()) { allocate(child, plan); } for (LogicalResource<?> resource : composite.getResources()) { allocate(resource, plan); } for (LogicalChannel channel : composite.getChannels()) { allocate(channel, plan); } } component.setZone(zoneName); } }
public void allocate(LogicalComponent<?> component, DeploymentPlan plan) throws AllocationException { if (Names.LOCAL_ZONE.equals(component.getZone())) { if (component instanceof LogicalCompositeComponent) { LogicalCompositeComponent composite = (LogicalCompositeComponent) component; for (LogicalComponent<?> child : composite.getComponents()) { allocate(child, plan); } for (LogicalResource<?> resource : composite.getResources()) { allocate(resource, plan); } for (LogicalChannel channel : composite.getChannels()) { allocate(channel, plan); } } selectZone(component, plan); } }
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); }
CompensatableCommand command = generator.generate(component, incremental); if (command != null) { String zone = component.getZone(); if (deployment.getDeploymentUnit(zone).getCommands().contains(command)) { continue;
public <T> T resolve(Class<T> interfaze) throws ResolverException { LogicalWire wire = createWire(interfaze); try { boolean remote = !wire.getSource().getParent().getZone().equals(wire.getTarget().getParent().getZone()); PhysicalWireDefinition pwd; if (remote) { bindingSelector.selectBinding(wire); pwd = wireGenerator.generateBoundReference(wire.getSourceBinding()); pwd.getSource().setUri(wire.getSource().getParent().getUri()); } else { pwd = wireGenerator.generateWire(wire); } NonManagedPhysicalWireSourceDefinition source = (NonManagedPhysicalWireSourceDefinition) pwd.getSource(); URI uri = ContributionResolver.getContribution(interfaze); pwd.getTarget().setClassLoaderId(uri); source.setClassLoaderId(uri); connector.connect(pwd); return interfaze.cast(source.getProxy()); } catch (GenerationException | ContainerException e) { throw new ResolverException(e); } }
private PhysicalChannelConnectionDefinition generateConsumerConnection(LogicalConsumer consumer, LogicalChannel channel, PhysicalConnectionTargetDefinition targetDefinition, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { // the channel does not have bindings, which means it is a local channel if (!channel.getZone().equals(consumer.getParent().getZone()) && !channel.isBound()) { String name = channel.getDefinition().getName(); throw new GenerationException("Binding not configured on a channel where the consumer is in a different zone: " + name); } // construct a local connection to the channel PhysicalConnectionSourceDefinition sourceDefinition = new ChannelSourceDefinition(channel.getUri(), ChannelSide.CONSUMER); sourceDefinition.setSequence(consumer.getDefinition().getSequence()); sourceDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }