Search in sources :

Example 1 with DeploymentManifest

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

the class Aries1084Test method testBundleStartsWhenSubsystemLeftInInvalidState.

@Test
public void testBundleStartsWhenSubsystemLeftInInvalidState() throws Exception {
    Subsystem featureA = installSubsystemFromFile(FEATURE_A);
    try {
        startSubsystem(featureA);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureA);
        Bundle core = getSubsystemCoreBundle();
        File file = core.getBundleContext().getDataFile(featureA.getSubsystemId() + "/OSGI-INF/DEPLOYMENT.MF");
        core.stop();
        DeploymentManifest manifest = new DeploymentManifest(file);
        FileOutputStream fos = new FileOutputStream(file);
        try {
            new DeploymentManifest.Builder().manifest(manifest).state(Subsystem.State.ACTIVE).build().write(fos);
        } finally {
            fos.close();
        }
        core.start();
        featureA = getChild(getRootSubsystem(), FEATURE_A);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureA);
    } finally {
        stopAndUninstallSubsystemSilently(featureA);
    }
}
Also used : DeploymentManifest(org.apache.aries.subsystem.core.archive.DeploymentManifest) Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Example 2 with DeploymentManifest

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

the class SubsystemResource method computeDeploymentManifest.

private DeploymentManifest computeDeploymentManifest() throws IOException {
    DeploymentManifest result = computeExistingDeploymentManifest();
    if (result != null)
        return result;
    result = new DeploymentManifest.Builder().manifest(resource.getSubsystemManifest()).header(computeDeployedContentHeader()).header(computeProvisionResourceHeader()).build();
    return result;
}
Also used : DeploymentManifest(org.apache.aries.subsystem.core.archive.DeploymentManifest)

Example 3 with DeploymentManifest

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

the class BasicSubsystem method getRegionName.

String getRegionName() {
    DeploymentManifest manifest = getDeploymentManifest();
    Header<?> header = manifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_REGION);
    if (header == null)
        return null;
    return header.getValue();
}
Also used : DeploymentManifest(org.apache.aries.subsystem.core.archive.DeploymentManifest)

Example 4 with DeploymentManifest

use of org.apache.aries.subsystem.core.archive.DeploymentManifest 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) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) 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)

Example 5 with DeploymentManifest

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

the class BasicSubsystem method isAutostart.

boolean isAutostart() {
    DeploymentManifest manifest = getDeploymentManifest();
    Header<?> header = manifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_AUTOSTART);
    return Boolean.valueOf(header.getValue());
}
Also used : DeploymentManifest(org.apache.aries.subsystem.core.archive.DeploymentManifest)

Aggregations

DeploymentManifest (org.apache.aries.subsystem.core.archive.DeploymentManifest)9 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DeployedContentHeader (org.apache.aries.subsystem.core.archive.DeployedContentHeader)2 ProvisionResourceHeader (org.apache.aries.subsystem.core.archive.ProvisionResourceHeader)2 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)2 BundleException (org.osgi.framework.BundleException)2 SubsystemException (org.osgi.service.subsystem.SubsystemException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashSet (java.util.LinkedHashSet)1 AriesSubsystemParentsHeader (org.apache.aries.subsystem.core.archive.AriesSubsystemParentsHeader)1 Header (org.apache.aries.subsystem.core.archive.Header)1 SubsystemTypeHeader (org.apache.aries.subsystem.core.archive.SubsystemTypeHeader)1 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 Resource (org.osgi.resource.Resource)1