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;
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class EntityResourceList method compact.
/**
* Compact the resource group by removing uninstalled entries
* @return <code>true</code> if another cycle should be started.
*/
public boolean compact() {
synchronized (lock) {
Collections.sort(this.resources);
boolean startNewCycle = false;
final List<TaskResource> toDelete = new ArrayList<TaskResource>();
boolean first = true;
for (final TaskResource r : resources) {
if (r.getState() == ResourceState.UNINSTALLED || (!first && r.getState() == ResourceState.UNINSTALL)) {
toDelete.add(r);
}
first = false;
}
if (!toDelete.isEmpty()) {
// Avoid resources.remove(r) as the resource might have
// changed since it was added, which causes it to compare()
// differently and trip the TreeSet.remove() search.
final Set<RegisteredResourceImpl> copy = new HashSet<RegisteredResourceImpl>(resources);
for (final RegisteredResource r : toDelete) {
copy.remove(r);
this.cleanup(r);
LOGGER.debug("Removing uninstalled from list: {}", r);
}
resources.clear();
resources.addAll(copy);
if (!this.isEmpty()) {
startNewCycle = true;
}
}
return startNewCycle;
}
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class EntityResourceList method getActiveResource.
/**
* @see org.apache.sling.installer.api.tasks.TaskResourceGroup#getActiveResource()
*/
@Override
public TaskResource getActiveResource() {
synchronized (lock) {
if (!resources.isEmpty()) {
Collections.sort(this.resources);
final TaskResource r = resources.get(0);
if (r.getState() == ResourceState.INSTALL || r.getState() == ResourceState.UNINSTALL) {
return r;
}
}
}
return null;
}
use of org.apache.sling.installer.api.tasks.TaskResource in project sling by apache.
the class DeployPckTask method execute.
@Override
public void execute(final InstallationContext ctx) {
final TaskResource tr = this.getResource();
// get and check symbolic name
final String symbolicName = (String) tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_SYMBOLICMAME);
if (symbolicName == null) {
logger.error("Resource {} has no symbolic name - ignoring.", tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
return;
}
// get package if available
final DeploymentPackage dp = this.deploymentAdmin.getDeploymentPackage(symbolicName);
if (tr.getState() == ResourceState.INSTALL) {
InputStream is = null;
try {
is = tr.getInputStream();
if (is == null) {
// something went wrong
logger.error("Resource {} does not provide an input stream!", tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
} else {
final Version newVersion = new Version((String) tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_VERSION));
// check version
if (dp != null) {
final int compare = dp.getVersion().compareTo(newVersion);
if (compare < 0) {
// installed version is lower -> update
this.deploymentAdmin.installDeploymentPackage(is);
ctx.log("Installed deployment package {} : {}", symbolicName, newVersion);
this.getResourceGroup().setFinishState(ResourceState.INSTALLED);
} else if (compare >= 0) {
logger.debug("Deployment package " + symbolicName + " " + newVersion + " is not installed, package with higher or same version is already installed.");
}
} else {
this.deploymentAdmin.installDeploymentPackage(is);
ctx.log("Installed deployment package {} : {}", symbolicName, newVersion);
this.getResourceGroup().setFinishState(ResourceState.INSTALLED);
}
}
} catch (final DeploymentException e) {
logger.error("Unable to install deployment package {} from resource {}", symbolicName, tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
} catch (final IOException ioe) {
logger.error("Unable to install deployment package {} from resource {}", symbolicName, tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ignore) {
}
}
}
} else {
// uninstall
if (dp != null) {
try {
dp.uninstall();
} catch (final DeploymentException e) {
logger.error("Unable to uninstall deployment package {} from resource {}", symbolicName, tr);
}
} else {
logger.info("Unable to find deployment package with symbolic name {} for uninstalling.", symbolicName);
}
this.getResourceGroup().setFinishState(ResourceState.UNINSTALLED);
}
}
Aggregations