use of org.apache.sling.installer.api.tasks.ChangeStateTask in project sling by apache.
the class PackageTransformer method createTask.
/**
* @see org.apache.sling.installer.api.tasks.InstallTaskFactory#createTask(org.apache.sling.installer.api.tasks.TaskResourceGroup)
*/
@Override
public InstallTask createTask(final TaskResourceGroup toActivate) {
final TaskResource resource = toActivate.getActiveResource();
if (resource == null || !resource.getType().equals(RESOURCE_TYPE)) {
return null;
}
// extract the package id
final String id = (String) resource.getAttribute(ATTR_PCK_ID);
final PackageId pkgId = PackageId.fromString(id);
if (pkgId == null) {
logger.error("Error during processing of {}: Package id is wrong/null.", resource);
return new ChangeStateTask(toActivate, ResourceState.IGNORED);
}
if (resource.getState() == ResourceState.INSTALL) {
return new InstallPackageTask(pkgId, toActivate);
}
return new UninstallPackageTask(pkgId, toActivate);
}
use of org.apache.sling.installer.api.tasks.ChangeStateTask 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.apache.sling.installer.api.tasks.ChangeStateTask in project sling by apache.
the class BundleTaskCreatorTest method testDowngradeOfRemovedResource.
@Test
public void testDowngradeOfRemovedResource() throws IOException {
final MockBundleResource[] r = { new MockBundleResource(SN, "1.0.0"), new MockBundleResource(SN, "1.1.0") };
// Simulate V1.1 installed but resource is gone -> downgrade to 1.0
r[1].setState(ResourceState.UNINSTALL);
{
final MockBundleTaskCreator c = new MockBundleTaskCreator();
c.addBundleInfo(SN, "1.1.0", Bundle.ACTIVE);
final SortedSet<InstallTask> s = getTasks(r, c);
assertEquals("Expected two tasks", 2, s.size());
final Iterator<InstallTask> i = s.iterator();
final InstallTask first = i.next();
assertTrue("Expected a ChangeStateTask:" + first, first instanceof ChangeStateTask);
final InstallTask second = i.next();
assertTrue("Expected a BundleRemoveTask", second instanceof BundleRemoveTask);
final BundleRemoveTask t = (BundleRemoveTask) second;
assertEquals("Remove should be to V1.1", r[1].getEntityId(), t.getResource().getEntityId());
}
}
use of org.apache.sling.installer.api.tasks.ChangeStateTask in project sling by apache.
the class StartSubsystemTask method execute.
@Override
public void execute(final InstallationContext ctx) {
final TaskResource tr = this.getResource();
ctx.log("Starting subsystem from {}", tr);
this.subsystem.start();
ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.INSTALLED));
ctx.log("Started subsystem {}", this.subsystem);
}
use of org.apache.sling.installer.api.tasks.ChangeStateTask 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