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; }
private <T> LogicalWire createWire(Class<T> interfaze) throws Fabric3Exception { LogicalReference logicalReference = createReference(interfaze); LogicalCompositeComponent domainComponent = lcm.getDomainComposite(); List<LogicalService> services = autowireResolver.resolve(logicalReference, domainComponent); if (services.isEmpty()) { throw new NotFoundException("Service not found for type: " + interfaze.getName()); } LogicalService targetService = services.get(0); return new LogicalWire(domainComponent, logicalReference, targetService, SYNTHETIC_CONTRIBUTION); }
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; }
private <T> LogicalWire createWire(Class<T> interfaze) throws Fabric3Exception { LogicalReference logicalReference = createReference(interfaze); LogicalCompositeComponent domainComponent = lcm.getDomainComposite(); List<LogicalService> services = autowireResolver.resolve(logicalReference, domainComponent); if (services.isEmpty()) { throw new NotFoundException("Service not found for type: " + interfaze.getName()); } LogicalService targetService = services.get(0); return new LogicalWire(domainComponent, logicalReference, targetService, SYNTHETIC_CONTRIBUTION); }
private <T> LogicalProducer createProducer(Class<T> interfaze, URI channelUri) throws Fabric3Exception { JavaServiceContract contract = introspector.introspect(interfaze); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(interfaze, domain, root); Producer producer = new Producer("producer", contract); int pos = counter.getAndIncrement(); LogicalProducer logicalProducer = new LogicalProducer(URI.create(root + "/F3Synthetic#producer" + pos), producer, logicalComponent); logicalProducer.setServiceContract(contract); logicalProducer.addTarget(channelUri); return logicalProducer; }
private <T> LogicalProducer createProducer(Class<T> interfaze, URI channelUri) throws Fabric3Exception { JavaServiceContract contract = introspector.introspect(interfaze); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(interfaze, domain, root); Producer producer = new Producer("producer", contract); int pos = counter.getAndIncrement(); LogicalProducer logicalProducer = new LogicalProducer(URI.create(root + "/F3Synthetic#producer" + pos), producer, logicalComponent); logicalProducer.setServiceContract(contract); logicalProducer.addTarget(channelUri); return logicalProducer; }
private <T> LogicalConsumer createConsumer(Class<T> type, URI channelUri) { JavaServiceContract contract = introspector.introspect(type); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(Object.class, domain, root); DataType dataType = new JavaType(type); Consumer consumer = new Consumer("consumer", dataType, true); int pos = counter.getAndIncrement(); LogicalConsumer logicalConsumer = new LogicalConsumer(URI.create(root + "/F3Synthetic#consumer" + pos), consumer, logicalComponent); logicalConsumer.setServiceContract(contract); logicalConsumer.addSource(channelUri); return logicalConsumer; }
private <T> LogicalConsumer createConsumer(Class<T> type, URI channelUri) { JavaServiceContract contract = introspector.introspect(type); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(Object.class, domain, root); DataType dataType = new JavaType(type); Consumer consumer = new Consumer("consumer", dataType, true); int pos = counter.getAndIncrement(); LogicalConsumer logicalConsumer = new LogicalConsumer(URI.create(root + "/F3Synthetic#consumer" + pos), consumer, logicalComponent); logicalConsumer.setServiceContract(contract); logicalConsumer.addSource(channelUri); return logicalConsumer; }
private LogicalReference createReference(Class<?> interfaze) { LogicalCompositeComponent domainComponent = lcm.getDomainComposite(); 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); Component<NonManagedImplementation> component = new Component<>(name); component.setParent(composite); component.setContributionUri(Names.HOST_CONTRIBUTION); NonManagedImplementation implementation = new NonManagedImplementation(); component.setImplementation(implementation); Reference<ComponentType> reference = new Reference<>("reference", Multiplicity.ONE_ONE); composite.add(reference); JavaServiceContract contract = introspector.introspect(interfaze); LogicalComponent<NonManagedImplementation> logicalComponent = new LogicalComponent<>(componentUri, component, domainComponent); reference.setServiceContract(contract); LogicalReference logicalReference = new LogicalReference(referenceUri, reference, logicalComponent); logicalReference.setServiceContract(contract); logicalComponent.addReference(logicalReference); return logicalReference; }
private LogicalReference createReference(Class<?> interfaze) { LogicalCompositeComponent domainComponent = lcm.getDomainComposite(); 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); Component<NonManagedImplementation> component = new Component<>(name); component.setParent(composite); component.setContributionUri(Names.HOST_CONTRIBUTION); NonManagedImplementation implementation = new NonManagedImplementation(); component.setImplementation(implementation); Reference<ComponentType> reference = new Reference<>("reference", Multiplicity.ONE_ONE); composite.add(reference); JavaServiceContract contract = introspector.introspect(interfaze); LogicalComponent<NonManagedImplementation> logicalComponent = new LogicalComponent<>(componentUri, component, domainComponent); reference.setServiceContract(contract); LogicalReference logicalReference = new LogicalReference(referenceUri, reference, logicalComponent); logicalReference.setServiceContract(contract); logicalComponent.addReference(logicalReference); return logicalReference; }
public synchronized void undeploy(Composite composite) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); URI contributionUri = composite.getContributionUri(); collector.markForCollection(contributionUri, domain); Deployment deployment = generator.generate(domain); collector.collect(domain); deployer.deploy(deployment); Contribution contribution = metadataStore.find(contributionUri); contribution.undeploy(); }
public synchronized void undeploy(Composite composite) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); URI contributionUri = composite.getContributionUri(); collector.markForCollection(contributionUri, domain); Deployment deployment = generator.generate(domain); collector.collect(domain); deployer.deploy(deployment); Contribution contribution = metadataStore.find(contributionUri); contribution.undeploy(); }
public synchronized void undeploy(URI uri) throws Fabric3Exception { Contribution contribution = metadataStore.find(uri); if (contribution == null) { throw new Fabric3Exception("Contribution not found: " + uri); } List<Deployable> deployables = contribution.getManifest().getDeployables(); if (deployables.isEmpty()) { return; } LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); collector.markForCollection(uri, domain); Deployment deployment = generator.generate(domain); collector.collect(domain); deployer.deploy(deployment); contribution.undeploy(); }
public synchronized void undeploy(URI uri) throws Fabric3Exception { Contribution contribution = metadataStore.find(uri); if (contribution == null) { throw new Fabric3Exception("Contribution not found: " + uri); } List<Deployable> deployables = contribution.getManifest().getDeployables(); if (deployables.isEmpty()) { return; } LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); collector.markForCollection(uri, domain); Deployment deployment = generator.generate(domain); collector.collect(domain); deployer.deploy(deployment); contribution.undeploy(); }
/** * Instantiates and optionally deploys deployables from a set of contributions. Deployment is performed if recovery mode is false or the runtime is * operating in single VM mode. When recovering in a distributed domain, the components contained in the deployables will be instantiated but not deployed * to zones. This is because the domain can run headless (i.e. without a controller) and may already be hosting deployed components. * * @param deployables the deployables * @param contributions the contributions to deploy * @param recover true if recovery mode is enabled * @throws Fabric3Exception if an error occurs during instantiation or deployment */ private void instantiateAndDeploy(List<Composite> deployables, Set<Contribution> contributions, boolean recover) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); for (Contribution contribution : contributions) { if (ContributionState.STORED == contribution.getState()) { throw new Fabric3Exception("Contribution is not installed: " + contribution.getUri()); } } InstantiationContext context = logicalModelInstantiator.include(deployables, domain); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } if (!recover || RuntimeMode.VM == info.getRuntimeMode()) { // in single VM mode, recovery includes deployment deploy(domain); } else { collector.markAsProvisioned(domain); } contributions.forEach(Contribution::deploy); }
/** * Instantiates and optionally deploys deployables from a set of contributions. Deployment is performed if recovery mode is false or the runtime is * operating in single VM mode. When recovering in a distributed domain, the components contained in the deployables will be instantiated but not deployed * to zones. This is because the domain can run headless (i.e. without a controller) and may already be hosting deployed components. * * @param deployables the deployables * @param contributions the contributions to deploy * @param recover true if recovery mode is enabled * @throws Fabric3Exception if an error occurs during instantiation or deployment */ private void instantiateAndDeploy(List<Composite> deployables, Set<Contribution> contributions, boolean recover) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); for (Contribution contribution : contributions) { if (ContributionState.STORED == contribution.getState()) { throw new Fabric3Exception("Contribution is not installed: " + contribution.getUri()); } } InstantiationContext context = logicalModelInstantiator.include(deployables, domain); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } if (!recover || RuntimeMode.VM == info.getRuntimeMode()) { // in single VM mode, recovery includes deployment deploy(domain); } else { collector.markAsProvisioned(domain); } contributions.forEach(Contribution::deploy); }
private <S, I extends S> LogicalComponent<?> createLogicalComponent(String name, Class<S> type, I instance, boolean introspect) throws InvalidServiceContractException, AssemblyException { LogicalCompositeComponent domain = lcm.getDomainComposite(); Component<Implementation<?>> definition = createDefinition(name, type, instance, introspect); InstantiationContext context = new InstantiationContext(); LogicalComponent<?> logical = instantiator.instantiate(definition, domain, context); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } // mark singleton components as provisioned since instances are not created logical.setState(LogicalState.PROVISIONED); // all references are initially resolved since they are manually injected for (LogicalReference reference : logical.getReferences()) { reference.setResolved(true); for (LogicalWire wire : reference.getWires()) { wire.setState(LogicalState.PROVISIONED); } } return logical; }
private <S, I extends S> LogicalComponent<?> createLogicalComponent(String name, Class<S> type, I instance, boolean introspect) throws InvalidServiceContractException, AssemblyException { LogicalCompositeComponent domain = lcm.getDomainComposite(); Component<Implementation<?>> definition = createDefinition(name, type, instance, introspect); InstantiationContext context = new InstantiationContext(); LogicalComponent<?> logical = instantiator.instantiate(definition, domain, context); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } // mark singleton components as provisioned since instances are not created logical.setState(LogicalState.PROVISIONED); // all references are initially resolved since they are manually injected for (LogicalReference reference : logical.getReferences()) { reference.setResolved(true); for (LogicalWire wire : reference.getWires()) { wire.setState(LogicalState.PROVISIONED); } } return logical; }
/** * Instantiates and deploys the given composite. * * @param composite the composite to instantiate and deploy * @throws Fabric3Exception if a deployment error occurs */ private void instantiateAndDeploy(Composite composite) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); QName name = composite.getName(); QNameSymbol symbol = new QNameSymbol(name); ResourceElement<QNameSymbol, Composite> element = metadataStore.find(Composite.class, symbol); if (element == null) { throw new Fabric3Exception("Composite not found in metadata store: " + name); } Contribution contribution = element.getResource().getContribution(); if (ContributionState.STORED == contribution.getState()) { throw new Fabric3Exception("Contribution is not installed: " + contribution.getUri()); } InstantiationContext context = logicalModelInstantiator.include(composite, domain); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } deploy(domain); contribution.deploy(); }
/** * Instantiates and deploys the given composite. * * @param composite the composite to instantiate and deploy * @throws Fabric3Exception if a deployment error occurs */ private void instantiateAndDeploy(Composite composite) throws Fabric3Exception { LogicalCompositeComponent domain = logicalComponentManager.getDomainComposite(); QName name = composite.getName(); QNameSymbol symbol = new QNameSymbol(name); ResourceElement<QNameSymbol, Composite> element = metadataStore.find(Composite.class, symbol); if (element == null) { throw new Fabric3Exception("Composite not found in metadata store: " + name); } Contribution contribution = element.getResource().getContribution(); if (ContributionState.STORED == contribution.getState()) { throw new Fabric3Exception("Contribution is not installed: " + contribution.getUri()); } InstantiationContext context = logicalModelInstantiator.include(composite, domain); if (context.hasErrors()) { throw new AssemblyException(context.getErrors()); } deploy(domain); contribution.deploy(); }