use of org.apache.sling.installer.api.tasks.TaskResource 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;
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class RegisteredResourceTest method testConfigEntity.
// @org.junit.Test
public void testConfigEntity() throws Exception {
final InstallableResource i = new InstallableResource("test:/foo/someconfig", null, new Hashtable<String, Object>(), null, null, null);
final TaskResource r = create(i);
assertNull("RegisteredResource must not have bundle symbolic name", r.getAttribute(Constants.BUNDLE_SYMBOLICNAME));
assertEquals("RegisteredResource entity ID must match", "config:someconfig", r.getEntityId());
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class RegisteredResourceTest method testBundleManifest.
@org.junit.Test
public void testBundleManifest() throws Exception {
final File f = getTestBundle("testbundle-1.0.jar");
final InstallableResource i = new InstallableResource("test:" + f.getAbsolutePath(), new FileInputStream(f), null, f.getName(), null, null);
final TaskResource r = create(i);
assertNotNull("RegisteredResource must have bundle symbolic name", r.getAttribute(Constants.BUNDLE_SYMBOLICNAME));
assertEquals("RegisteredResource entity ID must match", "bundle:osgi-installer-testbundle", r.getEntityId());
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class OsgiInstallerImpl method getInstallationState.
/**
* @see org.apache.sling.installer.api.info.InfoProvider#getInstallationState()
*/
@Override
public InstallationState getInstallationState() {
synchronized (this.resourcesLock) {
final InstallationState state = new InstallationState() {
private final List<ResourceGroup> activeResources = new ArrayList<>();
private final List<ResourceGroup> installedResources = new ArrayList<>();
private final List<RegisteredResource> untransformedResources = new ArrayList<>();
@Override
public List<ResourceGroup> getActiveResources() {
return activeResources;
}
@Override
public List<ResourceGroup> getInstalledResources() {
return installedResources;
}
@Override
public List<RegisteredResource> getUntransformedResources() {
return untransformedResources;
}
@Override
public String toString() {
return "InstallationState[active resources: " + this.activeResources + ", installed resources: " + this.installedResources + ", untransformed resources: " + this.untransformedResources + "]";
}
};
for (final String entityId : this.persistentList.getEntityIds()) {
if (!this.persistentList.isSpecialEntityId(entityId)) {
final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
final String alias = group.getAlias();
final List<Resource> resources = new ArrayList<>();
boolean first = true;
boolean isActive = false;
for (final TaskResource tr : group.getResources()) {
final ResourceState resourceState = tr.getState();
if (first) {
if (resourceState == ResourceState.INSTALL || resourceState == ResourceState.UNINSTALL) {
isActive = true;
}
first = false;
}
resources.add(new Resource() {
@Override
public String getScheme() {
return tr.getScheme();
}
@Override
public String getURL() {
return tr.getURL();
}
@Override
public String getType() {
return tr.getType();
}
@Override
public InputStream getInputStream() throws IOException {
return tr.getInputStream();
}
@Override
public Dictionary<String, Object> getDictionary() {
return tr.getDictionary();
}
@Override
public String getDigest() {
return tr.getDigest();
}
@Override
public int getPriority() {
return tr.getPriority();
}
@Override
public String getEntityId() {
return tr.getEntityId();
}
@Override
public ResourceState getState() {
return resourceState;
}
@Override
public Version getVersion() {
return tr.getVersion();
}
@Override
public long getLastChange() {
return ((RegisteredResourceImpl) tr).getLastChange();
}
@Override
public Object getAttribute(final String key) {
return tr.getAttribute(key);
}
@Override
@CheckForNull
public String getError() {
return tr.getError();
}
@Override
public String toString() {
return "resource[entityId=" + getEntityId() + ", scheme=" + getScheme() + ", url=" + getURL() + ", type=" + getType() + ", error=" + getError() + ", state=" + getState() + ", version=" + getVersion() + ", lastChange=" + getLastChange() + ", priority=" + getPriority() + ", digest=" + getDigest() + "]";
}
});
}
final ResourceGroup rg = new ResourceGroup() {
@Override
public List<Resource> getResources() {
return resources;
}
@Override
public String getAlias() {
return alias;
}
@Override
public String toString() {
return "group[" + resources + "]";
}
};
if (isActive) {
state.getActiveResources().add(rg);
} else {
state.getInstalledResources().add(rg);
}
}
}
Collections.sort(state.getActiveResources(), COMPARATOR);
Collections.sort(state.getInstalledResources(), COMPARATOR);
state.getUntransformedResources().addAll(this.persistentList.getUntransformedResources());
return state;
}
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class OsgiInstallerImpl method computeTasks.
/**
* Compute OSGi tasks based on our resources, and add to supplied list of tasks.
*/
private SortedSet<InstallTask> computeTasks() {
final SortedSet<InstallTask> tasks = new TreeSet<>();
// Walk the list of entities, and create appropriate OSGi tasks for each group
final List<InstallTaskFactory> services = this.factoryTracker.getSortedServices();
if (services.size() > 0) {
for (final String entityId : this.persistentList.getEntityIds()) {
final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
// Check the first resource in each group
final TaskResource toActivate = group.getActiveResource();
if (toActivate != null) {
final InstallTask task = getTask(services, group);
if (task != null) {
tasks.add(task);
}
}
}
}
return tasks;
}
Aggregations