use of org.osgi.service.subsystem.SubsystemException 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.SubsystemException in project aries by apache.
the class BundleResourceInstaller method install.
public Resource install() {
BundleRevision revision;
if (resource instanceof BundleRevision) {
revision = (BundleRevision) resource;
} else if (resource instanceof BundleRevisionResource) {
revision = ((BundleRevisionResource) resource).getRevision();
} else {
try {
revision = installBundle();
} catch (Exception e) {
throw new SubsystemException(e);
}
}
addReference(revision);
addConstituent(new BundleConstituent(resource, revision));
return revision;
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class SubsystemGraph method add.
public synchronized void add(BasicSubsystem parent, BasicSubsystem child) {
SubsystemWrapper parentWrap = new SubsystemWrapper(parent);
SubsystemWrapper childWrap = new SubsystemWrapper(child);
if (containsAncestor(childWrap, parentWrap))
throw new SubsystemException("Cycle detected between '" + parentWrap + "' and '" + childWrap + "'");
Collection<SubsystemWrapper> subsystems = adjacencyList.get(childWrap);
if (subsystems == null) {
subsystems = new HashSet<SubsystemWrapper>();
adjacencyList.put(childWrap, subsystems);
}
subsystems = adjacencyList.get(parentWrap);
if (subsystems == null) {
subsystems = new HashSet<SubsystemWrapper>();
adjacencyList.put(parentWrap, subsystems);
}
subsystems.add(childWrap);
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class SubsystemResourceUninstaller method uninstallSubsystem.
private void uninstallSubsystem() {
BasicSubsystem subsystem = (BasicSubsystem) resource;
try {
if (subsystem.getState().equals(Subsystem.State.RESOLVED))
subsystem.setState(State.INSTALLED);
subsystem.setState(State.UNINSTALLING);
Throwable firstError = null;
for (Resource resource : Activator.getInstance().getSubsystems().getResourcesReferencedBy(subsystem)) {
// Don't uninstall the region context bundle here.
if (Utils.isRegionContextBundle(resource))
continue;
try {
ResourceUninstaller.newInstance(resource, subsystem).uninstall();
} catch (Throwable t) {
logger.error("An error occurred while uninstalling resource " + resource + " of subsystem " + subsystem, t);
if (firstError == null)
firstError = t;
}
}
subsystem.setState(State.UNINSTALLED);
Activator activator = Activator.getInstance();
activator.getSubsystemServiceRegistrar().unregister(subsystem);
if (subsystem.isScoped()) {
RegionContextBundleHelper.uninstallRegionContextBundle(subsystem);
activator.getRegionDigraph().removeRegion(subsystem.getRegion());
}
if (firstError != null)
throw new SubsystemException(firstError);
} finally {
// Let's be sure to always clean up the directory.
IOUtils.deleteRecursive(subsystem.getDirectory());
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class Subsystems method getRootSubsystem.
public synchronized BasicSubsystem getRootSubsystem() {
if (root == null) {
File file = Activator.getInstance().getBundleContext().getDataFile("");
File[] fileArray = file.listFiles();
List<File> fileList = new ArrayList<File>(Arrays.asList(fileArray));
Collections.sort(fileList, new Comparator<File>() {
@Override
public int compare(File file1, File file2) {
String name1 = file1.getName();
String name2 = file2.getName();
return Long.valueOf(name1).compareTo(Long.valueOf(name2));
}
});
if (fileList.isEmpty()) {
// There are no persisted subsystems, including root.
SubsystemResource resource;
try {
resource = new SubsystemResource(file);
} catch (SubsystemException e) {
throw e;
} catch (Exception e) {
throw new SubsystemException(e);
}
Coordination coordination = Utils.createCoordination();
try {
root = new BasicSubsystem(resource);
// TODO This initialization is a bit brittle. The root subsystem
// must be gotten before anything else will be able to use the
// graph. At the very least, throw IllegalStateException where
// appropriate.
graph = new SubsystemGraph(root);
ResourceInstaller.newInstance(coordination, root, root).install();
populateRootSubsystem(root, coordination);
} catch (Exception e) {
coordination.fail(e);
} finally {
coordination.end();
}
} else {
// There are persisted subsystems.
Coordination coordination = Utils.createCoordination();
Collection<BasicSubsystem> subsystems = new ArrayList<BasicSubsystem>(fileList.size());
try {
for (File f : fileList) {
BasicSubsystem s = new BasicSubsystem(f);
if (State.UNINSTALLED.equals(s.getState())) {
// left over cache, delete this
IOUtils.deleteRecursive(f);
} else {
subsystems.add(s);
addSubsystem(s);
}
}
root = getSubsystemById(0);
SubsystemIdentifier.setLastId(Long.parseLong(root.getDeploymentManifest().getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_LASTID).getValue()));
graph = new SubsystemGraph(root);
ResourceInstaller.newInstance(coordination, root, root).install();
populateRootSubsystem(root, coordination);
} catch (Exception e) {
coordination.fail(e);
} finally {
coordination.end();
}
}
}
return root;
}
Aggregations