use of org.osgi.service.subsystem.Subsystem in project felix by apache.
the class WebConsolePlugin method asyncSubsystemOperation.
private void asyncSubsystemOperation(long id, final SubsystemOperation op) throws IOException {
try {
Collection<ServiceReference<Subsystem>> refs = bundleContext.getServiceReferences(Subsystem.class, "(" + SubsystemConstants.SUBSYSTEM_ID_PROPERTY + "=" + id + ")");
if (refs.size() < 1)
throw new IOException(UNABLE_TO_FIND_TARGET_SUBSYSTEM);
final ServiceReference<Subsystem> ref = refs.iterator().next();
new Thread(new Runnable() {
@Override
public void run() {
Subsystem ss = bundleContext.getService(ref);
try {
op.exec(ss);
} finally {
bundleContext.ungetService(ref);
}
}
}).start();
} catch (InvalidSyntaxException e) {
throw new IOException(e);
}
}
use of org.osgi.service.subsystem.Subsystem in project felix by apache.
the class WebConsolePlugin method installSubsystem.
private void installSubsystem(HttpServletRequest req) throws IOException {
@SuppressWarnings("rawtypes") Map params = (Map) req.getAttribute(AbstractWebConsolePlugin.ATTR_FILEUPLOAD);
final boolean start = getParameter(params, "subsystemstart") != null;
FileItem[] subsystemItems = getFileItems(params, "subsystemfile");
for (final FileItem subsystemItem : subsystemItems) {
File tmpFile = null;
try {
// copy the data to a file for better processing
tmpFile = File.createTempFile("installSubsystem", ".tmp");
subsystemItem.write(tmpFile);
} catch (Exception e) {
log(LogService.LOG_ERROR, "Problem accessing uploaded subsystem file: " + subsystemItem.getName(), e);
// remove the temporary file
if (tmpFile != null) {
tmpFile.delete();
tmpFile = null;
}
}
if (tmpFile != null) {
final File file = tmpFile;
// TODO support install in other subsystems than the root one
// TODO currently this means that when installing more than one subsystem they
// will be installed concurrently. Not sure if this is the best idea.
// However the client UI does not support selecting more than one file, so
// from a practical point of view this is currently not an issue.
asyncSubsystemOperation(0, new SubsystemOperation() {
@Override
public void exec(Subsystem ss) {
try {
InputStream is = new FileInputStream(file);
try {
Subsystem nss = ss.install("inputstream:" + subsystemItem.getName(), is);
if (start)
nss.start();
} finally {
is.close();
file.delete();
}
} catch (IOException e) {
log(LogService.LOG_ERROR, "Problem installing subsystem", e);
}
}
});
}
}
}
use of org.osgi.service.subsystem.Subsystem in project sling by apache.
the class UninstallSubsystemTask method execute.
@Override
public void execute(final InstallationContext ctx) {
final TaskResource tr = this.getResource();
ctx.log("Uninstalling subsystem from {}", tr);
Subsystem subsystem = null;
try {
subsystem = this.bundleContext.getService(this.subsystemReference);
if (subsystem != null) {
subsystem.uninstall();
ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.UNINSTALLED));
ctx.log("Uninstalled subsystem {}", subsystem);
} else {
ctx.log("Unable to uninstall subsystem {}.", tr);
ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.IGNORED));
}
} finally {
if (subsystem != null) {
this.bundleContext.ungetService(this.subsystemReference);
}
}
}
use of org.osgi.service.subsystem.Subsystem in project sling by apache.
the class Activator method start.
/**
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(final BundleContext context) throws Exception {
this.rootSubsystemTracker = new ServiceTracker<Subsystem, Subsystem>(context, context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + Subsystem.class.getName() + ")" + "(" + SubsystemConstants.SUBSYSTEM_ID_PROPERTY + "=0))"), new ServiceTrackerCustomizer<Subsystem, Subsystem>() {
public Subsystem addingService(final ServiceReference<Subsystem> reference) {
final Subsystem service = context.getService(reference);
if (service != null) {
registerInstaller(context, service);
}
return service;
}
public void modifiedService(final ServiceReference<Subsystem> reference, final Subsystem service) {
// nothing to do
}
public void removedService(final ServiceReference<Subsystem> reference, final Subsystem service) {
unregisterInstaller();
}
});
this.rootSubsystemTracker.open();
}
use of org.osgi.service.subsystem.Subsystem in project sling by apache.
the class SubsystemInstaller method createTask.
/**
* @see org.apache.sling.installer.api.tasks.InstallTaskFactory#createTask(org.apache.sling.installer.api.tasks.TaskResourceGroup)
*/
public InstallTask createTask(final TaskResourceGroup toActivate) {
final InstallTask result;
final TaskResource rsrc = toActivate.getActiveResource();
if (rsrc.getType().equals(TYPE_SUBSYSTEM)) {
// check if the required info is available
final SubsystemInfo info = checkResource(toActivate);
if (info == null) {
// ignore as info is missing
result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
} else {
// search a subsystem with the symbolic name
final ServiceReference<Subsystem> ref = this.getSubsystemReference(info.symbolicName);
final Subsystem currentSubsystem = (ref != null ? this.bundleContext.getService(ref) : null);
try {
final Version newVersion = new Version(info.version);
final Version oldVersion = (ref == null ? null : (Version) ref.getProperty("subsystem.version"));
// Install
if (rsrc.getState() == ResourceState.INSTALL) {
if (oldVersion != null) {
final int compare = oldVersion.compareTo(newVersion);
if (compare < 0) {
// installed version is lower -> update
result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
} else if (compare == 0 && isSnapshot(newVersion)) {
// same version but snapshot -> update
result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
} else if (compare == 0 && currentSubsystem != null && currentSubsystem.getState() != State.ACTIVE) {
// try to start the version
result = new StartSubsystemTask(toActivate, currentSubsystem);
} else {
logger.info("{} is not installed, subsystem with same or higher version is already installed: {}", info, newVersion);
result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
}
} else {
result = new InstallSubsystemTask(toActivate, this.rootSubsystem);
}
// Uninstall
} else if (rsrc.getState() == ResourceState.UNINSTALL) {
if (oldVersion == null) {
logger.error("Nothing to uninstall. {} is currently not installed.", info);
result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
} else {
final int compare = oldVersion.compareTo(newVersion);
if (compare == 0) {
result = new UninstallSubsystemTask(toActivate, this.bundleContext, ref);
} else {
logger.error("Nothing to uninstall. {} is currently not installed, different version is installed {}", info, oldVersion);
result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
}
}
} else {
result = null;
}
} finally {
if (currentSubsystem != null) {
this.bundleContext.ungetService(ref);
}
}
}
} else {
result = null;
}
return result;
}
Aggregations