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;
}
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;
}
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;
}
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;
}
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()));
}
}
Aggregations