Search in sources :

Example 6 with SubsystemContentHeader

use of org.apache.aries.subsystem.core.archive.SubsystemContentHeader in project aries by apache.

the class SubsystemResource method setImportIsolationPolicy.

private void setImportIsolationPolicy(Map<Resource, List<Wire>> resolution) throws Exception {
    if (!isApplication()) {
        return;
    }
    SubsystemContentHeader contentHeader = getSubsystemManifest().getSubsystemContentHeader();
    // Prepare the regions and filter builder to set the sharing policy.
    Region from = getRegion();
    Region to = ((BasicSubsystem) getParents().iterator().next()).getRegion();
    RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
    // Always provide visibility to this subsystem's service registration.
    addSubsystemServiceImportToSharingPolicy(builder, to);
    for (Resource resource : resolution.keySet()) {
        if (!contentHeader.contains(resource)) {
            continue;
        }
        // If the resource is content but the wire provider is not,
        // the sharing policy must be updated.
        List<Wire> wires = resolution.get(resource);
        for (Wire wire : wires) {
            Resource provider = wire.getProvider();
            // visible.
            if (contentHeader.contains(provider)) {
                continue;
            }
            // requirements become part of the sharing policy.
            if (!(wire.getCapability() instanceof DependencyCalculator.MissingCapability) && Constants.ResourceTypeSynthesized.equals(ResourceHelper.getTypeAttribute(provider))) {
                continue;
            }
            // The requirement must be added to the sharing policy.
            Requirement requirement = wire.getRequirement();
            List<String> namespaces = new ArrayList<String>(2);
            namespaces.add(requirement.getNamespace());
            if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespaces.get(0))) {
                // Both service capabilities and services must be visible.
                namespaces.add(RegionFilter.VISIBLE_SERVICE_NAMESPACE);
            }
            String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
            if (filter == null) {
                for (String namespace : namespaces) builder.allowAll(namespace);
            } else {
                for (String namespace : namespaces) builder.allow(namespace, filter);
            }
        }
    }
    // Always add access to osgi.ee and osgi.native namespaces
    setImplicitAccessToNativeAndEECapabilities(builder);
    // Now set the sharing policy, if the regions are different.
    RegionFilter regionFilter = builder.build();
    from.connectRegion(to, regionFilter);
}
Also used : Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) Wire(org.osgi.resource.Wire) SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) RequireBundleRequirement(org.apache.aries.subsystem.core.archive.RequireBundleRequirement) Requirement(org.osgi.resource.Requirement) RequireCapabilityRequirement(org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement) ImportPackageRequirement(org.apache.aries.subsystem.core.archive.ImportPackageRequirement) SubsystemImportServiceRequirement(org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement) RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder)

Example 7 with SubsystemContentHeader

use of org.apache.aries.subsystem.core.archive.SubsystemContentHeader in project aries by apache.

the class SubsystemResource method computeContentResources.

private void computeContentResources(SubsystemManifest manifest) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
    SubsystemContentHeader contentHeader = manifest.getSubsystemContentHeader();
    if (contentHeader == null)
        return;
    for (SubsystemContentHeader.Clause clause : contentHeader.getClauses()) {
        Requirement requirement = clause.toRequirement(this);
        Resource resource = findContent(requirement);
        if (resource == null) {
            if (clause.isMandatory())
                throw new SubsystemException("A required content resource could not be found. This means the resource was either missing or not recognized as a supported resource format due to, for example, an invalid bundle manifest or blueprint XML file. Turn on debug logging for more information. The resource was: " + requirement);
            continue;
        }
        addContentResource(resource);
    }
}
Also used : SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) RequireBundleRequirement(org.apache.aries.subsystem.core.archive.RequireBundleRequirement) Requirement(org.osgi.resource.Requirement) RequireCapabilityRequirement(org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement) ImportPackageRequirement(org.apache.aries.subsystem.core.archive.ImportPackageRequirement) SubsystemImportServiceRequirement(org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement) SubsystemException(org.osgi.service.subsystem.SubsystemException) Resource(org.osgi.resource.Resource)

Example 8 with SubsystemContentHeader

use of org.apache.aries.subsystem.core.archive.SubsystemContentHeader in project aries by apache.

the class BasicSubsystem method getRequirements.

@Override
public List<Requirement> getRequirements(String namespace) {
    // First, add the requirements from the manifest.
    SubsystemManifest manifest = getSubsystemManifest();
    List<Requirement> result = manifest.toRequirements(this);
    if (namespace != null)
        for (Iterator<Requirement> i = result.iterator(); i.hasNext(); ) if (!i.next().getNamespace().equals(namespace))
            i.remove();
    if (isScoped())
        return result;
    SubsystemContentHeader header = manifest.getSubsystemContentHeader();
    for (Resource constituent : getConstituents()) if (header.contains(constituent))
        for (Requirement requirement : constituent.getRequirements(namespace)) result.add(new BasicRequirement(requirement, this));
    return result;
}
Also used : SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) Requirement(org.osgi.resource.Requirement) SubsystemManifest(org.apache.aries.subsystem.core.archive.SubsystemManifest) Iterator(java.util.Iterator) Resource(org.osgi.resource.Resource)

Example 9 with SubsystemContentHeader

use of org.apache.aries.subsystem.core.archive.SubsystemContentHeader in project aries by apache.

the class BasicSubsystem method getCapabilities.

@Override
public List<Capability> getCapabilities(String namespace) {
    // First, add the capabilities from the manifest.
    SubsystemManifest manifest = getSubsystemManifest();
    List<Capability> result = manifest.toCapabilities(this);
    if (namespace != null)
        for (Iterator<Capability> i = result.iterator(); i.hasNext(); ) if (!i.next().getNamespace().equals(namespace))
            i.remove();
    // in FeatureTest.testSharedContent() under certain conditions.
    if (isScoped() || IdentityNamespace.IDENTITY_NAMESPACE.equals(namespace))
        return result;
    SubsystemContentHeader header = manifest.getSubsystemContentHeader();
    for (Resource constituent : getConstituents()) {
        if (header.contains(constituent)) {
            for (Capability capability : constituent.getCapabilities(namespace)) {
                if (namespace == null && (IdentityNamespace.IDENTITY_NAMESPACE.equals(capability.getNamespace()) || HostNamespace.HOST_NAMESPACE.equals(capability.getNamespace()))) {
                    // is null.
                    continue;
                }
                result.add(new BasicCapability(capability, this));
            }
        }
    }
    return result;
}
Also used : SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) SubsystemManifest(org.apache.aries.subsystem.core.archive.SubsystemManifest) Capability(org.osgi.resource.Capability) Iterator(java.util.Iterator) Resource(org.osgi.resource.Resource)

Example 10 with SubsystemContentHeader

use of org.apache.aries.subsystem.core.archive.SubsystemContentHeader in project aries by apache.

the class StopAction method run.

@Override
public Object run() {
    // Protect against re-entry now that cycles are supported.
    if (!Activator.getInstance().getLockingStrategy().set(State.STOPPING, target)) {
        return null;
    }
    try {
        // We are now protected against re-entry.
        // Acquire the global read lock to prevent installs and uninstalls
        // but allow starts and stops.
        Activator.getInstance().getLockingStrategy().readLock();
        try {
            // We are now protected against installs and uninstalls.
            checkRoot();
            // Compute affected subsystems. This is safe to do while only 
            // holding the read lock since we know that nothing can be added 
            // or removed.
            LinkedHashSet<BasicSubsystem> subsystems = new LinkedHashSet<BasicSubsystem>();
            subsystems.add(target);
            List<Resource> resources = new ArrayList<Resource>(Activator.getInstance().getSubsystems().getResourcesReferencedBy(target));
            for (Resource resource : resources) {
                if (resource instanceof BasicSubsystem) {
                    subsystems.add((BasicSubsystem) resource);
                }
            }
            // Acquire the global mutual exclusion lock while acquiring the
            // state change locks of affected subsystems.
            Activator.getInstance().getLockingStrategy().lock();
            try {
                // We are now protected against cycles.
                // Acquire the state change locks of affected subsystems.
                Activator.getInstance().getLockingStrategy().lock(subsystems);
            } finally {
                // Release the global mutual exclusion lock as soon as possible.
                Activator.getInstance().getLockingStrategy().unlock();
            }
            try {
                // We are now protected against other starts and stops of the affected subsystems.
                State state = target.getState();
                if (EnumSet.of(State.INSTALLED, State.INSTALLING, State.RESOLVED).contains(state)) {
                    // apache-aries-provision-dependencies:=resolve.
                    return null;
                } else if (EnumSet.of(State.INSTALL_FAILED, State.UNINSTALLED).contains(state)) {
                    throw new IllegalStateException("Cannot stop from state " + state);
                }
                target.setState(State.STOPPING);
                SubsystemContentHeader header = target.getSubsystemManifest().getSubsystemContentHeader();
                if (header != null) {
                    Collections.sort(resources, new StartResourceComparator(target.getSubsystemManifest().getSubsystemContentHeader()));
                    Collections.reverse(resources);
                }
                for (Resource resource : resources) {
                    // Don't stop the region context bundle.
                    if (Utils.isRegionContextBundle(resource))
                        continue;
                    try {
                        stopResource(resource);
                    } catch (Exception e) {
                        logger.error("An error occurred while stopping resource " + resource + " of subsystem " + target, e);
                    }
                }
                // TODO Can we automatically assume it actually is resolved?
                target.setState(State.RESOLVED);
                try {
                    synchronized (target) {
                        target.setDeploymentManifest(new DeploymentManifest(target.getDeploymentManifest(), null, target.isAutostart(), target.getSubsystemId(), SubsystemIdentifier.getLastId(), target.getLocation(), false, false));
                    }
                } catch (Exception e) {
                    throw new SubsystemException(e);
                }
            } finally {
                // Release the state change locks of affected subsystems.
                Activator.getInstance().getLockingStrategy().unlock(subsystems);
            }
        } finally {
            // Release the read lock.
            Activator.getInstance().getLockingStrategy().readUnlock();
        }
    } finally {
        // Protection against re-entry no longer required.
        Activator.getInstance().getLockingStrategy().unset(State.STOPPING, target);
    }
    return null;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DeploymentManifest(org.apache.aries.subsystem.core.archive.DeploymentManifest) SubsystemException(org.osgi.service.subsystem.SubsystemException) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) State(org.osgi.service.subsystem.Subsystem.State)

Aggregations

SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)13 Resource (org.osgi.resource.Resource)8 SubsystemManifest (org.apache.aries.subsystem.core.archive.SubsystemManifest)4 Requirement (org.osgi.resource.Requirement)4 SubsystemException (org.osgi.service.subsystem.SubsystemException)4 ArrayList (java.util.ArrayList)3 Capability (org.osgi.resource.Capability)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 ImportPackageRequirement (org.apache.aries.subsystem.core.archive.ImportPackageRequirement)2 RequireBundleRequirement (org.apache.aries.subsystem.core.archive.RequireBundleRequirement)2 RequireCapabilityRequirement (org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement)2 SubsystemImportServiceRequirement (org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement)2 Region (org.eclipse.equinox.region.Region)2 BundleException (org.osgi.framework.BundleException)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Attribute (org.apache.aries.subsystem.core.archive.Attribute)1 DeploymentManifest (org.apache.aries.subsystem.core.archive.DeploymentManifest)1 GenericHeader (org.apache.aries.subsystem.core.archive.GenericHeader)1