public WireSourceReferenceNotFound(URI sourceUri, String referenceName, LogicalCompositeComponent composite) { super(composite.getUri(), composite.getDefinition().getContributionUri(), Collections.singletonList(composite)); this.sourceUri = sourceUri; this.referenceName = referenceName; }
/** * Recursively sets the deployable composite the logical component was instantiated from. * * @param component the logical component * @param deployable the deployable */ private void setDeployable(LogicalComponent<?> component, QName deployable) { if (component instanceof LogicalCompositeComponent) { LogicalCompositeComponent composite = (LogicalCompositeComponent) component; for (LogicalComponent<?> child : composite.getComponents()) { setDeployable(child, deployable); } for (LogicalResource<?> resource : composite.getResources()) { resource.setDeployable(deployable); } for (LogicalChannel channel : composite.getChannels()) { channel.setDeployable(deployable); } } component.setDeployable(deployable); }
public LogicalComponent<?> getComponent(URI uri) { String defragmentedUri = UriHelper.getDefragmentedNameAsString(uri); String domainString = domain.getUri().toString(); String[] hierarchy = defragmentedUri.substring(domainString.length() + 1).split("/"); String currentUri = domainString; LogicalComponent<?> currentComponent = domain; for (String name : hierarchy) { currentUri = currentUri + "/" + name; if (currentComponent instanceof LogicalCompositeComponent) { LogicalCompositeComponent composite = (LogicalCompositeComponent) currentComponent; currentComponent = composite.getComponent(URI.create(currentUri)); } if (currentComponent == null) { return null; } } return currentComponent; }
private LogicalChannel getChannel(String name) throws Fabric3Exception { LogicalCompositeComponent domainComponent = lcm.getDomainComposite(); String domainRoot = domainComponent.getUri().toString(); URI channelUri = URI.create(domainRoot + "/" + name); LogicalChannel logicalChannel = domainComponent.getChannel(channelUri); if (logicalChannel == null) { throw new NotFoundException("Channel not found: " + name); } return logicalChannel; }
public void collect(LogicalCompositeComponent composite) { Iterator<LogicalComponent<?>> iter = composite.getComponents().iterator(); while (iter.hasNext()) { LogicalComponent<?> component = iter.next(); for (Map.Entry<LogicalReference, List<LogicalWire>> wires : composite.getWires().entrySet()) { for (Iterator<LogicalWire> it = wires.getValue().iterator(); it.hasNext(); ) { LogicalWire wire = it.next(); composite.getWires().remove(reference); Iterator<LogicalChannel> channelIter = composite.getChannels().iterator(); while (channelIter.hasNext()) { LogicalChannel channel = channelIter.next(); Iterator<LogicalResource<?>> resourceIter = composite.getResources().iterator(); while (resourceIter.hasNext()) { LogicalResource<?> resource = resourceIter.next();
public LogicalComponent<CompositeImplementation> instantiate(Component<CompositeImplementation> component, LogicalCompositeComponent parent, InstantiationContext context) { URI uri = URI.create(parent.getUri() + "/" + component.getName()); Composite composite = Composite.class.cast(component.getComponentType()); LogicalCompositeComponent logicalComponent = new LogicalCompositeComponent(uri, component, parent); initializeProperties(logicalComponent, component, context); instantiateChildComponents(logicalComponent, composite, context); wireInstantiator.instantiateCompositeWires(composite, logicalComponent, context); instantiateResources(logicalComponent, composite); wireInstantiator.instantiateCompositeWires(composite, logicalComponent, context); if (channelInstantiator != null) { channelInstantiator.instantiateChannels(composite, logicalComponent, context); } if (parent.getComponent(uri) != null) { DuplicateComponent error = new DuplicateComponent(uri, parent); context.addError(error); } parent.addComponent(logicalComponent); return logicalComponent; }
@SuppressWarnings({"unchecked"}) public LogicalComponent instantiate(Component<?> component, LogicalCompositeComponent parent, InstantiationContext context) { URI uri = URI.create(parent.getUri() + "/" + component.getName()); LogicalComponent<?> logicalComponent = new LogicalComponent(uri, component, parent); if (parent.getComponent(uri) != null) { DuplicateComponent error = new DuplicateComponent(uri, parent); context.addError(error); } parent.addComponent(logicalComponent); ComponentType componentType = component.getComponentType(); if (componentType == null) { return logicalComponent; } initializeProperties(logicalComponent, component, context); createServices(component, logicalComponent, componentType); createReferences(component, logicalComponent, componentType); createProducers(component, logicalComponent, componentType); createConsumers(component, logicalComponent, componentType); createResourceReferences(logicalComponent, componentType); return logicalComponent; }
public boolean hasNext() { return pos < composite.getComponents().size(); }
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); } }
private void addTarget(LogicalProducer logicalProducer, URI uri, LogicalComponent<?> logicalComponent) { if (uri.isAbsolute()) { LogicalComponent<?> domain = logicalComponent.getParent(); while (domain.getParent() != null) { domain = domain.getParent(); } logicalProducer.addTarget(URI.create(domain.getUri().toString() + "/" + uri.getAuthority())); } else { logicalProducer.addTarget(URI.create(logicalComponent.getParent().getUri().toString() + "/" + uri.toString())); } }
/** * Returns the channel in the invocable hierarchy. * * @param channelUri the channel uri * @param invocable the invocable * @return the channel * @throws ChannelNotFoundException if the channel is not found */ public static LogicalChannel getChannelInHierarchy(URI channelUri, LogicalInvocable invocable) throws ChannelNotFoundException { LogicalChannel channel = null; LogicalCompositeComponent parent = invocable.getParent().getParent(); while (true) { if (parent != null) { channel = parent.getChannel(channelUri); if (channel != null) { break; } parent = parent.getParent(); } else { break; } } if (channel == null) { throw new ChannelNotFoundException("Channel not found: " + channelUri); } return channel; }
public Deployment generate(LogicalCompositeComponent domain) throws Fabric3Exception { List<LogicalComponent<?>> components = domain.getComponents().stream().collect(Collectors.toList()); for (LogicalResource<?> resource : domain.getResources()) { Optional<Command> command = resourceGenerator.generateBuild(resource); command.ifPresent(deployment::addCommand); for (LogicalResource<?> resource : domain.getResources()) { Optional<Command> command = resourceGenerator.generateDispose(resource); command.ifPresent(deployment::addCommand);
Multiplicity refMultiplicity = logicalReference.getDefinition().getMultiplicity(); boolean multiplicity = Multiplicity.ZERO_N.equals(refMultiplicity) || Multiplicity.ONE_N.equals(refMultiplicity); for (LogicalComponent<?> child : composite.getComponents()) { if (logicalReference.getParent() == child) { LogicalComponent<?> parent = leafReference.getParent(); LogicalCompositeComponent parentComposite = parent.getParent(); List<LogicalWire> existingWires = parentComposite.getWires(leafReference); parentComposite.addWire(leafReference, wire); for (LogicalWire existingWire : existingWires) {
LogicalComponent<?> component = currentComponent.getComponent(URI.create(currentPath)); if (component == null) { throw new InvalidPathException("Deployed composite not exist: " + path); for (LogicalComponent<?> component : currentComponent.getComponents()) { URI uri = component.getUri(); URI contributionUri = component.getDefinition().getContributionUri();
public void selectBindings(LogicalCompositeComponent domain) throws BindingSelectionException { if (RuntimeMode.CONTROLLER != info.getRuntimeMode() || disable) { // there are no remote wires when the domain is contained withing a single VM (including Participant mode, which has a runtime domain) return; } Collection<LogicalComponent<?>> components = domain.getComponents(); for (LogicalComponent<?> component : components) { if (component.getState() == LogicalState.NEW) { selectBindings(component); } } for (LogicalChannel channel : domain.getChannels()) { selectBinding(channel); } }
private InstantiationContext include(LogicalCompositeComponent domain, Composite composite, boolean synthetic) { InstantiationContext context = new InstantiationContext(); // merge the property values into the parent includeProperties(composite, domain, context); // merge resources includeResources(composite, domain, synthetic); // instantiate all the components in the composite and add them to the parent instantiate(composite, domain, synthetic, context); // resolve services and references - evaluate all references since reinjection may apply if (domain.isAutowire()) { for (LogicalComponent<?> component : domain.getComponents()) { autowireInstantiator.instantiate(component, context); } } return context; }
@SuppressWarnings({"unchecked"}) public Optional<BuildResourcesCommand> generate(LogicalComponent<?> component) { if (!(component instanceof LogicalCompositeComponent) || (component.getState() != LogicalState.NEW)) { return Optional.empty(); } LogicalCompositeComponent composite = (LogicalCompositeComponent) component; if (composite.getResources().isEmpty()) { return Optional.empty(); } List<PhysicalResource> physicalResources = new ArrayList<>(); for (LogicalResource<?> logicalResource : composite.getResources()) { Resource resource = logicalResource.getDefinition(); ResourceGenerator generator = generatorRegistry.getResourceGenerator(resource.getClass()); PhysicalResource physicalResource = generator.generateResource(logicalResource); physicalResources.add(physicalResource); } if (physicalResources.isEmpty()) { return Optional.empty(); } return Optional.of(new BuildResourcesCommand(physicalResources)); }
private void initializeDomainComposite() { Composite type = new Composite(null); CompositeImplementation impl = new CompositeImplementation(); impl.setComponentType(type); ComponentDefinition<CompositeImplementation> definition = new ComponentDefinition<CompositeImplementation>(domainUri.toString()); definition.setImplementation(impl); definition.setContributionUri(Names.BOOT_CONTRIBUTION); type.setAutowire(autowire); domain = new LogicalCompositeComponent(domainUri, definition, null); domain.setState(LogicalState.PROVISIONED); domain.setAutowire(autowire); }
private void initializeDomainComposite() { Composite type = new Composite(null); CompositeImplementation impl = new CompositeImplementation(); impl.setComponentType(type); Component<CompositeImplementation> definition = new Component<>(domainUri.toString()); definition.setImplementation(impl); definition.setContributionUri(Names.BOOT_CONTRIBUTION); domain = new LogicalCompositeComponent(domainUri, definition, autowire); domain.setState(LogicalState.PROVISIONED); }