public InvalidProperty(String name, LogicalComponent component, Throwable cause) { super(component.getUri(), component.getDefinition().getContributionUri(), Collections.singletonList(component)); this.name = name; this.cause = cause; }
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())); } }
public Optional<ConnectionCommand> generate(LogicalComponent<?> component) { if (component instanceof LogicalCompositeComponent) { return Optional.empty(); } // determine if a binding is being added or removed. If so, an AttachWireCommand or DetachWireCommand must be generated. boolean bindingChange = false; for (LogicalService service : component.getServices()) { for (LogicalBinding<?> binding : service.getBindings()) { if (binding.getState() == LogicalState.NEW || binding.getState() == LogicalState.MARKED) { bindingChange = true; break; } } } if (LogicalState.PROVISIONED == component.getState() && !bindingChange) { return Optional.empty(); } ConnectionCommand command = new ConnectionCommand(component.getUri()); generatePhysicalWires(component, command); if (command.getAttachCommands().isEmpty() && command.getDetachCommands().isEmpty()) { return Optional.empty(); } return Optional.of(command); }
public void normalize(LogicalComponent<?> component) { LogicalComponent<?> parent = component.getParent(); ComponentDefinition<?> definition = component.getDefinition(); Autowire autowire = definition.getAutowire(); if (autowire == Autowire.INHERITED) { // check in the parent composite definition if (parent != null) { autowire = parent.getAutowire(); if (autowire == Autowire.ON || autowire == Autowire.OFF) { component.setAutowire(autowire); } } else { // off by default component.setAutowire(Autowire.OFF); } } else { component.setAutowire(autowire); } } }
@SuppressWarnings({"unchecked"}) private PhysicalWireDefinition generateRemoteWireCallback(LogicalWire wire) throws GenerationException { LogicalReference reference = wire.getSource(); LogicalComponent target = reference.getParent(); ServiceContract referenceContract = reference.getServiceContract(); ServiceContract referenceCallbackContract = referenceContract.getCallbackContract(); if (reference.getCallbackBindings().isEmpty()) { throw new GenerationException("Callback binding not set"); } LogicalBinding<?> referenceBinding = reference.getCallbackBindings().get(0); LogicalService callbackService = target.getService(referenceCallbackContract.getInterfaceName()); List<LogicalOperation> operations = reference.getCallbackOperations(); // resolve policies PolicyResult policyResult = policyResolver.resolveRemoteCallbackPolicies(wire); EffectivePolicy targetPolicy = policyResult.getTargetPolicy(); // generate metadata to attach the physical callback wire to the source transport BindingGenerator bindingGenerator = getGenerator(referenceBinding); PhysicalSourceDefinition sourceDefinition = bindingGenerator.generateSource(referenceBinding, referenceCallbackContract, operations, targetPolicy); URI contributionUri = target.getDefinition().getContributionUri(); sourceDefinition.setClassLoaderId(contributionUri); // generate the metadata used to attach the physical callback wire to the target component (the component containing the forward reference) ComponentGenerator componentGenerator = getGenerator(target); PhysicalTargetDefinition targetDefinition = componentGenerator.generateTarget(callbackService, targetPolicy); targetDefinition.setClassLoaderId(target.getDefinition().getContributionUri()); // generate the metadata for interceptors that are attached to wire invocation chains, e.g. policy implemented by an interceptor Set<PhysicalOperationDefinition> physicalOperations = operationGenerator.generateOperations(operations, true, policyResult); return new PhysicalWireDefinition(sourceDefinition, targetDefinition, physicalOperations); }
URI uri = component.getUri(); URI contributionUri = component.getDefinition().getContributionUri(); QName deployable = component.getDeployable(); String zone = component.getZone(); ComponentInfo info = new ComponentInfo(uri, contributionUri, deployable, zone); infos.add(info);
@SuppressWarnings("unchecked") protected PhysicalComponentDefinition generateDefinition(LogicalComponent<?> component) throws GenerationException { Implementation<?> implementation = component.getDefinition().getImplementation(); Class<? extends Implementation> type = implementation.getClass(); ComponentGenerator generator = generatorRegistry.getComponentGenerator(type); if (generator == null) { throw new GeneratorNotFoundException(type); } PhysicalComponentDefinition definition = generator.generate(component); URI uri = component.getUri(); definition.setComponentUri(uri); definition.setClassLoaderId(component.getDefinition().getContributionUri()); QName deployable = component.getDeployable(); definition.setDeployable(deployable); return definition; }
private <S extends LogicalComponent<?>> URI generateCallbackUri(S source, ServiceContract contract, String referenceName) { LogicalService candidate = null; for (LogicalService entry : source.getServices()) { MatchResult result = matcher.isAssignableFrom(contract, entry.getServiceContract(), false); if (result.isAssignable()) { candidate = entry; break; } } if (candidate == null) { String name = contract.getInterfaceName(); URI uri = source.getUri(); throw new Fabric3Exception("Callback service not found: " + name + " on component: " + uri + " originating from reference :" + referenceName); } return URI.create(source.getUri().toString() + "#" + candidate.getDefinition().getName()); }
/** * Adds a child component * * @param component the child component to add */ public void addComponent(LogicalComponent<?> component) { components.put(component.getUri(), component); }
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; }
private void processPropertyValues(LogicalComponent<?> component, SpringComponentDefinition physical) { for (LogicalProperty property : component.getAllProperties().values()) { Document document = property.getValue(); if (document != null) { String name = property.getName(); boolean many = property.isMany(); ComponentType componentType = component.getDefinition().getImplementation().getComponentType(); QName type = componentType.getProperties().get(property.getName()).getType(); PhysicalPropertyDefinition definition = new PhysicalPropertyDefinition(name, document, many, type); physical.setPropertyDefinition(definition); } } }
private void createConsumers(ComponentDefinition<?> definition, LogicalComponent<?> component, ComponentType componentType) { for (ConsumerDefinition consumer : componentType.getConsumers().values()) { String name = consumer.getName(); URI consumerUri = component.getUri().resolve('#' + name); LogicalConsumer logicalConsumer = new LogicalConsumer(consumerUri, consumer, component); // producer is configured in the component definition ComponentConsumer componentConsumer = definition.getConsumers().get(name); if (componentConsumer != null) { logicalConsumer.addIntents(componentConsumer.getIntents()); // TODO refactor this: URIs should be resolved to channels by a separate service that also handles promotion for (URI uri : componentConsumer.getSources()) { if (uri.isAbsolute()) { LogicalComponent<?> domain = component.getParent(); while (domain.getParent() != null) { domain = domain.getParent(); } logicalConsumer.addSource(URI.create(domain.getUri().toString() + "/" + uri.getAuthority())); } else { logicalConsumer.addSource(URI.create(component.getParent().getUri().toString() + "/" + uri.toString())); } } } component.addConsumer(logicalConsumer); } }
private void createProducers(ComponentDefinition<?> definition, LogicalComponent<?> component, ComponentType componentType) { for (ProducerDefinition producer : componentType.getProducers().values()) { String name = producer.getName(); URI producerUri = component.getUri().resolve('#' + name); LogicalProducer logicalProducer = new LogicalProducer(producerUri, producer, component); // producer is configured in the component definition ComponentProducer componentProducer = definition.getProducers().get(name); if (componentProducer != null) { logicalProducer.addIntents(componentProducer.getIntents()); // TODO refactor this: URIs should be resolved to channels by a separate service that also handles promotion for (URI uri : componentProducer.getTargets()) { if (uri.isAbsolute()) { LogicalComponent<?> domain = component.getParent(); while (domain.getParent() != null) { domain = domain.getParent(); } logicalProducer.addTarget(URI.create(domain.getUri().toString() + "/" + uri.getAuthority())); } else { logicalProducer.addTarget(URI.create(component.getParent().getUri().toString() + "/" + uri.toString())); } } } component.addProducer(logicalProducer); } }
@SuppressWarnings("unchecked") private <C extends LogicalComponent<?>> ComponentGenerator<C> getGenerator(C component) { Implementation<?> implementation = component.getDefinition().getImplementation(); return (ComponentGenerator<C>) generatorRegistry.getComponentGenerator(implementation.getClass()); }
/** * Maps a component to a zone based on a collection of deployment plans. * * @param component the component to map * @param plan the deployment plans to use for mapping * @throws AllocationException if an error occurs mapping */ private void selectZone(LogicalComponent<?> component, DeploymentPlan plan) throws AllocationException { QName deployable = component.getDeployable(); if (deployable == null) { // programming error throw new AssertionError("Deployable not found for " + component.getUri()); } String zoneName = plan.getDeployableMappings().get(deployable); if (zoneName == null) { throw new DeployableMappingNotFoundException("Zone mapping not found for deployable: " + deployable); } component.setZone(zoneName); }
private void containsIntents(List<String> intentArgs, LogicalComponent<?> component, Set<LogicalScaArtifact> artifacts) { if (containsIntents(intentArgs, component.getDefinition().getImplementation().getIntents())) { artifacts.add(component); } if (containsIntents(intentArgs, component.getDefinition().getIntents())) { artifacts.add(component); } if (containsIntents(intentArgs, component.getIntents())) { artifacts.add(component); } for (LogicalService service : component.getServices()) { if (containsIntents(intentArgs, service.getIntents())) { artifacts.add(service); } } for (LogicalReference reference : component.getReferences()) { if (containsIntents(intentArgs, reference.getIntents())) { artifacts.add(reference); } } if (component instanceof LogicalCompositeComponent) { LogicalCompositeComponent composite = (LogicalCompositeComponent) component; for (LogicalComponent<?> childComponent : composite.getComponents()) { containsIntents(intentArgs, childComponent, artifacts); } } }
private URI getContributionUri(LogicalBinding<WsBindingDefinition> binding) { LogicalComponent<?> current = binding.getParent().getParent(); while (current.getParent().getParent() != null) { // component deployed directly to the domain current = current.getParent(); } return current.getDefinition().getContributionUri(); }
private void createResourceReferences(LogicalComponent<?> component, ComponentType componentType) { for (ResourceReferenceDefinition resourceReference : componentType.getResourceReferences().values()) { URI resourceUri = component.getUri().resolve('#' + resourceReference.getName()); LogicalResourceReference<ResourceReferenceDefinition> logicalResourceReference = new LogicalResourceReference<ResourceReferenceDefinition>(resourceUri, resourceReference, component); component.addResource(logicalResourceReference); } }
Implementation<?> impl = component.getDefinition().getImplementation(); ComponentType componentType = impl.getComponentType(); Set<Contribution> extensions = new HashSet<Contribution>(); if (isGenerate(component.getState(), type)) { for (String capability : componentType.getRequiredCapabilities()) { extensions.addAll(store.resolveCapability(capability)); for (LogicalService service : component.getServices()) { for (LogicalBinding<?> binding : service.getBindings()) { if (isGenerate(binding.getState(), type)) { for (LogicalReference reference : component.getReferences()) { for (LogicalBinding<?> binding : reference.getBindings()) { if (isGenerate(binding.getState(), type)) {
sourceDefinition.setClassLoaderId(source.getDefinition().getContributionUri()); PhysicalTargetDefinition targetDefinition = targetGenerator.generateServiceBindingTarget(serviceBinding, serviceContract, sourceOperations, targetPolicy); targetDefinition.setClassLoaderId(source.getDefinition().getContributionUri()); if (callbackContract != null) { QName sourceDeployable = source.getDeployable(); QName targetDeployable = target.getDeployable();