private PhysicalClassLoaderDefinition createClassLoaderDefinition(Contribution contribution) { URI uri = contribution.getUri(); if (Names.BOOT_CONTRIBUTION.equals(uri) || Names.HOST_CONTRIBUTION.equals(uri)) { return null; } boolean provisionArtifact = contribution.getLocation() != null; // don't provision synthetic artifacts; List<Library> libraries = contribution.getManifest().getLibraries(); PhysicalClassLoaderDefinition definition = new PhysicalClassLoaderDefinition(uri, libraries, provisionArtifact); List<ContributionWire<?, ?>> contributionWires = contribution.getWires(); for (ContributionWire<?, ?> wire : contributionWires) { ClassLoaderWireGenerator generator = generators.get(wire.getClass()); if (generator == null) { // not all contribution wires resolve resources through classloaders, so skip if one is not found continue; } PhysicalClassLoaderWireDefinition wireDefinition = generator.generate(wire); definition.add(wireDefinition); } return definition; }
public void onInstall(Contribution contribution) { String sourceUrl = contribution.getLocation().toString(); if (!sourceUrl.endsWith(".war")) { // not a WAR file return; } ContributionManifest manifest = contribution.getManifest(); if (!manifest.getDeployables().isEmpty()) { return; } for (Resource resource : contribution.getResources()) { for (ResourceElement<?, ?> element : resource.getResourceElements()) { if (element.getValue() instanceof Composite) { // a composite was defined, return; return; } } } // no composites were defined, synthesize one Composite composite = createComposite(contribution); Source source = contribution.getSource(); Resource resource = createResource(contribution, composite, source); contribution.addResource(resource); QName name = composite.getName(); Deployable deployable = new Deployable(name); manifest.addDeployable(deployable); }
@ManagementOperation(description = "Returns metadata for all contributions deployed in a domain") public Set<ContributionInfo> getContributions() { Set<Contribution> contributions = metaDataStore.getContributions(); Set<ContributionInfo> infos = new TreeSet<ContributionInfo>(); for (Contribution contribution : contributions) { URI uri = contribution.getUri(); String state = contribution.getState().toString(); long timestamp = contribution.getTimestamp(); List<QName> deployables = new ArrayList<QName>(); for (Deployable deployable : contribution.getManifest().getDeployables()) { deployables.add(deployable.getName()); } ContributionInfo info = new ContributionInfo(uri, state, deployables, timestamp); infos.add(info); } return infos; }
/** * Updates the repository index based on the changed contribution. * * @param contribution the changed contribution */ private void update(Contribution contribution) { if (!contribution.isPersistent()) { return; } mappings.put(contribution.getUri(), contribution.getProfiles()); persist(); }
private URI createWebUri(Contribution contribution) { String context = contribution.getManifest().getContext(); if (context != null) { return URI.create(context); } return contribution.getUri(); }
public void onRemove(Contribution contribution) { if (!contribution.isPersistent()) { return; } mappings.remove(contribution.getUri()); persist(); }
/** * Returns true if the contribution should be added to the list of contributions, i.e. it is not already present and is not the host or boot * contribution. * * @param contribution the contribution * @param contributions the list of contributions * @return true if the contribution should be included */ private boolean include(Contribution contribution, List<Contribution> contributions) { URI uri = contribution.getUri(); return !contributions.contains(contribution) && !Names.HOST_CONTRIBUTION.equals(uri) && !Names.BOOT_CONTRIBUTION.equals(uri); }
public void onProcessManifest(Contribution contribution) { if (contribution.getManifest().isExtension()) { boolean sunImported = false; ContributionManifest manifest = contribution.getManifest(); for (Import imprt : manifest.getImports()) { if (imprt instanceof JavaImport) {
public Resource inspect(Class<?> clazz, URL url, Contribution contribution, IntrospectionContext context) { String sourceUrl = contribution.getLocation().toString(); if (!sourceUrl.endsWith(".war")) { // not a WAR file return null; } if (contribution.getManifest().isExtension()) { return null; } if (!Servlet.class.isAssignableFrom(clazz) && !Filter.class.isAssignableFrom(clazz)) { // skip classes that are not servlets or filters return null; } return introspect(clazz, contribution, context); }
public void iterateArtifacts(Contribution contribution, Consumer<Resource> callback, IntrospectionContext context) throws Fabric3Exception { URL location = contribution.getLocation(); ContributionManifest manifest = contribution.getManifest(); ZipInputStream zipStream = null; try { continue; contribution.addResource(resource); callback.accept(resource); } catch (ClassNotFoundException | NoClassDefFoundError e) { UrlSource source = new UrlSource(entryUrl); Resource resource = new Resource(contribution, source, contentType); contribution.addResource(resource);
public void processManifest(Contribution contribution, IntrospectionContext context) throws Fabric3Exception { ContributionManifest manifest; try { URL sourceUrl = contribution.getLocation(); URL manifestUrl = new URL("jar:" + sourceUrl.toExternalForm() + "!/WEB-INF/sca-contribution.xml"); ClassLoader cl = getClass().getClassLoader(); URI uri = contribution.getUri(); IntrospectionContext childContext = new DefaultIntrospectionContext(uri, cl); Source source = new UrlSource(manifestUrl); manifest = loader.load(source, ContributionManifest.class, childContext); if (childContext.hasErrors()) { context.addErrors(childContext.getErrors()); } if (childContext.hasWarnings()) { context.addWarnings(childContext.getWarnings()); } contribution.setManifest(manifest); } catch (Fabric3Exception e) { if (e.getCause() instanceof FileNotFoundException) { // ignore no manifest found } else { throw e; } } catch (MalformedURLException e) { // ignore no manifest found } }
public List<Composite> getDeployables(Set<Contribution> contributions) { List<Composite> deployables = new ArrayList<>(); for (Contribution contribution : contributions) { for (Resource resource : contribution.getResources()) { for (ResourceElement<?, ?> entry : resource.getResourceElements()) { if (!(entry.getValue() instanceof Composite)) { continue; } @SuppressWarnings({"unchecked"}) ResourceElement<QNameSymbol, Composite> element = (ResourceElement<QNameSymbol, Composite>) entry; QName name = element.getSymbol().getKey(); Composite composite = element.getValue(); for (Deployable deployable : contribution.getManifest().getDeployables()) { if (deployable.getName().equals(name)) { List<RuntimeMode> deployableModes = deployable.getRuntimeModes(); // only add deployables that are set to boot in the current runtime mode and where the environment matches if (deployableModes.contains(hostInfo.getRuntimeMode())) { List<String> environments = deployable.getEnvironments(); if (environments.isEmpty() || environments.contains(hostInfo.getEnvironment())) { deployables.add(composite); } } break; } } } } } return deployables; }
/** * 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); }
ClassLoader loader, boolean extension) throws Fabric3Exception { Contribution contribution = new Contribution(contributionUri); contribution.install(); ContributionManifest manifest = contribution.getManifest(); manifest.setExtension(extension);
/** * 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(); }
public void onInstall(Contribution contribution) { if (!isWar(contribution)) { return; } if (hasImplementation(contribution)) { return; // web component was explicitly configured in the contribution } // synthesize a web implementation URI uri = createWebUri(contribution); WebImplementation implementation = new WebImplementation(uri); // retrieve the component type introspected during contribution indexing or create one if no web artifacts resulted in it being generated WebComponentType componentType = getComponentType(contribution); implementation.setComponentType(componentType); // synthesize a deployable composite IndexHelper.indexImplementation(implementation, contribution); Composite composite = createComposite(implementation, contribution); contribution.getManifest().addDeployable(new Deployable(composite.getName())); contribution.addResource(createResource(contribution, composite)); }
public void releaseLocks(Set<Contribution> contributions) { for (Contribution contribution : contributions) { for (Deployable deployable : contribution.getManifest().getDeployables()) { QName name = deployable.getName(); if (contribution.getLockOwners().contains(name)) { contribution.releaseLock(name); } } } }
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 void lock(Set<Contribution> contributions) throws CompositeAlreadyDeployedException { for (Contribution contribution : contributions) { for (Deployable deployable : contribution.getManifest().getDeployables()) { QName name = deployable.getName(); // check if the deployable has already been deployed by querying the lock owners if (contribution.getLockOwners().contains(name)) { throw new CompositeAlreadyDeployedException("Composite has already been deployed: " + name); } contribution.acquireLock(name); } } }
ClassLoader loader, boolean extension) throws ContributionException { Contribution contribution = new Contribution(contributionUri); contribution.setState(ContributionState.INSTALLED); ContributionManifest manifest = contribution.getManifest(); manifest.setExtension(extension);