/** * 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 LogicalReference createReference(JavaServiceContract contract) { LogicalCompositeComponent domainComponent = lcm.getRootComponent(); int id = idCounter.getAndIncrement(); String name = "Synthetic" + id; URI componentUri = URI.create(domainComponent.getUri().toString() + "/" + name); URI referenceUri = URI.create(componentUri.toString() + "#reference"); QName qName = new QName(HostNamespaces.SYNTHESIZED, "SyntheticComposite" + id); Composite composite = new Composite(qName); ComponentDefinition<NonManagedImplementation> componentDefinition = new ComponentDefinition<>(name); componentDefinition.setParent(composite); NonManagedImplementation implementation = new NonManagedImplementation(); componentDefinition.setImplementation(implementation); ComponentReference reference = new ComponentReference("reference", Multiplicity.ONE_ONE); componentDefinition.add(reference); LogicalComponent<NonManagedImplementation> logicalComponent = new LogicalComponent<>(componentUri, componentDefinition, domainComponent); logicalComponent.setZone(info.getZoneName()); reference.setServiceContract(contract); LogicalReference logicalReference = new LogicalReference(referenceUri, reference, logicalComponent); logicalReference.setServiceContract(contract); logicalComponent.addReference(logicalReference); return logicalReference; }
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); } }