Search in sources :

Example 1 with State

use of org.osgi.service.subsystem.Subsystem.State in project aries by apache.

the class SubsystemTest method installSubsystem.

protected Subsystem installSubsystem(Subsystem parent, String location, InputStream content, Boolean... configChecks) throws Exception {
    //set default value
    boolean ariesProvisionDepsAtInstall = true;
    if (configChecks != null && configChecks.length > 0) {
        ariesProvisionDepsAtInstall = configChecks[0].booleanValue();
    }
    subsystemEvents.clear();
    Subsystem subsystem = parent.install(location, content);
    assertSubsystemNotNull(subsystem);
    assertEvent(subsystem, State.INSTALLING, 5000);
    if (ariesProvisionDepsAtInstall) {
        assertEvent(subsystem, State.INSTALLED, 5000);
    }
    assertChild(parent, subsystem);
    assertLocation(location, subsystem);
    assertParent(parent, subsystem);
    State finalState = State.INSTALLED;
    if (!ariesProvisionDepsAtInstall) {
        finalState = State.INSTALLING;
    }
    assertState(finalState, subsystem);
    assertLocation(location, subsystem);
    assertId(subsystem);
    //		assertDirectory(subsystem);
    return subsystem;
}
Also used : State(org.osgi.service.subsystem.Subsystem.State) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem)

Example 2 with State

use of org.osgi.service.subsystem.Subsystem.State 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)

Example 3 with State

use of org.osgi.service.subsystem.Subsystem.State in project aries by apache.

the class InstallAction method run.

@Override
public BasicSubsystem run() {
    // Doesn't appear to be any need of protecting against re-entry in the
    // case of installation.
    BasicSubsystem result = null;
    // Acquire the global write lock to prevent all other operations until
    // the installation is complete. There is no need to hold any other locks.
    Activator.getInstance().getLockingStrategy().writeLock();
    try {
        State state = parent.getState();
        if (State.INSTALLING.equals(state)) {
            throw new SubsystemException("A child subsystem may not be installed while the parent is in the INSTALLING state");
        }
        // Initialization of a null coordination must be privileged and,
        // therefore, occur in the run() method rather than in the constructor.
        Coordination coordination = Utils.createCoordination(parent);
        try {
            TargetRegion region = new TargetRegion(parent);
            SubsystemResource ssr = new SubsystemResource(location, content, parent, coordination);
            result = Activator.getInstance().getSubsystems().getSubsystemByLocation(location);
            if (result != null) {
                if (!region.contains(result))
                    throw new SubsystemException("Location already exists but existing subsystem is not part of target region: " + location);
                if (!(result.getSymbolicName().equals(ssr.getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName()) && result.getVersion().equals(ssr.getSubsystemManifest().getSubsystemVersionHeader().getVersion()) && result.getType().equals(ssr.getSubsystemManifest().getSubsystemTypeHeader().getType())))
                    throw new SubsystemException("Location already exists but symbolic name, version, and type are not the same: " + location);
            } else {
                result = (BasicSubsystem) region.find(ssr.getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName(), ssr.getSubsystemManifest().getSubsystemVersionHeader().getVersion());
                if (result != null) {
                    if (!result.getType().equals(ssr.getSubsystemManifest().getSubsystemTypeHeader().getType()))
                        throw new SubsystemException("Subsystem already exists in target region but has a different type: " + location);
                } else {
                    result = new BasicSubsystem(ssr, deploymentManifest);
                }
            }
            checkLifecyclePermission(result);
            return (BasicSubsystem) ResourceInstaller.newInstance(coordination, result, parent).install();
        } catch (Throwable t) {
            coordination.fail(t);
        } finally {
            try {
                coordination.end();
            } catch (CoordinationException e) {
                Throwable t = e.getCause();
                if (t instanceof SubsystemException)
                    throw (SubsystemException) t;
                if (t instanceof SecurityException)
                    throw (SecurityException) t;
                throw new SubsystemException(t);
            }
        }
    } finally {
        // Release the global write lock.
        Activator.getInstance().getLockingStrategy().writeUnlock();
    }
    return result;
}
Also used : Coordination(org.osgi.service.coordinator.Coordination) CoordinationException(org.osgi.service.coordinator.CoordinationException) State(org.osgi.service.subsystem.Subsystem.State) SubsystemException(org.osgi.service.subsystem.SubsystemException)

Example 4 with State

use of org.osgi.service.subsystem.Subsystem.State in project aries by apache.

the class UninstallAction method run.

@Override
public Object run() {
    // Protect against re-entry now that cycles are supported.
    if (!Activator.getInstance().getLockingStrategy().set(State.UNINSTALLING, target)) {
        return null;
    }
    try {
        // Acquire the global write lock to prevent all other operations 
        // until the uninstall is complete. There is no need to hold any 
        // other locks.
        Activator.getInstance().getLockingStrategy().writeLock();
        try {
            checkRoot();
            checkValid();
            State state = target.getState();
            if (EnumSet.of(State.UNINSTALLED).contains(state)) {
                return null;
            }
            if (state.equals(State.ACTIVE)) {
                new StopAction(requestor, target, disableRootCheck).run();
            }
            ResourceUninstaller.newInstance(requestor, target).uninstall();
        } finally {
            // Release the global write lock.
            Activator.getInstance().getLockingStrategy().writeUnlock();
        }
    } finally {
        // Protection against re-entry no longer required.
        Activator.getInstance().getLockingStrategy().unset(State.UNINSTALLING, target);
    }
    return null;
}
Also used : State(org.osgi.service.subsystem.Subsystem.State)

Example 5 with State

use of org.osgi.service.subsystem.Subsystem.State in project aries by apache.

the class SubsystemTest method uninstallSubsystem.

protected void uninstallSubsystem(Subsystem subsystem, boolean quietly) throws Exception {
    BasicSubsystem basicSubsystem = (BasicSubsystem) subsystem;
    AriesProvisionDependenciesDirective directive = basicSubsystem.getAriesProvisionDependenciesDirective();
    Bundle b = null;
    Region region = null;
    RegionDigraph digraph = context().getService(RegionDigraph.class);
    if (!quietly) {
        if (directive.isResolve()) {
            assertState(EnumSet.of(State.INSTALLING, State.INSTALLED, State.RESOLVED), subsystem);
        } else {
            assertState(EnumSet.of(State.INSTALLED, State.RESOLVED), subsystem);
        }
        subsystemEvents.clear();
        if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION) || subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
            b = getRegionContextBundle(subsystem);
            region = digraph.getRegion(b);
        }
    }
    State state = subsystem.getState();
    subsystem.uninstall();
    if (quietly) {
        return;
    }
    Collection<Subsystem> parents = subsystem.getParents();
    if (!EnumSet.of(State.INSTALL_FAILED, State.INSTALLED, State.INSTALLING).contains(state)) {
        assertEvent(subsystem, State.INSTALLED, 5000);
    }
    assertEvent(subsystem, State.UNINSTALLING, 5000);
    assertEvent(subsystem, State.UNINSTALLED, 5000);
    assertState(State.UNINSTALLED, subsystem);
    for (Subsystem parent : parents) {
        assertNotChild(parent, subsystem);
    }
    if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION) || subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
        assertEquals("Region context bundle not uninstalled", Bundle.UNINSTALLED, b.getState());
        assertNull("Region not removed", digraph.getRegion(region.getName()));
    }
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Bundle(org.osgi.framework.Bundle) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) CoreOptions.streamBundle(org.ops4j.pax.exam.CoreOptions.streamBundle) State(org.osgi.service.subsystem.Subsystem.State) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) Region(org.eclipse.equinox.region.Region) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) AriesProvisionDependenciesDirective(org.apache.aries.subsystem.core.archive.AriesProvisionDependenciesDirective)

Aggregations

State (org.osgi.service.subsystem.Subsystem.State)5 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)2 BasicSubsystem (org.apache.aries.subsystem.core.internal.BasicSubsystem)2 Subsystem (org.osgi.service.subsystem.Subsystem)2 SubsystemException (org.osgi.service.subsystem.SubsystemException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 AriesProvisionDependenciesDirective (org.apache.aries.subsystem.core.archive.AriesProvisionDependenciesDirective)1 DeploymentManifest (org.apache.aries.subsystem.core.archive.DeploymentManifest)1 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)1 Region (org.eclipse.equinox.region.Region)1 RegionDigraph (org.eclipse.equinox.region.RegionDigraph)1 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)1 CoreOptions.streamBundle (org.ops4j.pax.exam.CoreOptions.streamBundle)1 Bundle (org.osgi.framework.Bundle)1 BundleException (org.osgi.framework.BundleException)1 Resource (org.osgi.resource.Resource)1 Coordination (org.osgi.service.coordinator.Coordination)1 CoordinationException (org.osgi.service.coordinator.CoordinationException)1