use of org.apache.felix.deploymentadmin.AbstractDeploymentPackage in project felix by apache.
the class DropAllBundlesCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
LogService log = session.getLog();
BundleInfoImpl[] orderedTargetBundles = target.getOrderedBundleInfos();
for (int i = orderedTargetBundles.length - 1; i >= 0; i--) {
BundleInfoImpl bundleInfo = orderedTargetBundles[i];
// stale bundle, save a copy for rolling back and uninstall it
String symbolicName = bundleInfo.getSymbolicName();
try {
Bundle bundle = target.getBundle(symbolicName);
if (bundle != null) {
bundle.uninstall();
addRollback(new InstallBundleRunnable(bundle, target, log));
}
} catch (Exception be) {
log.log(LogService.LOG_WARNING, "Bundle '" + symbolicName + "' could not be uninstalled", be);
}
}
}
use of org.apache.felix.deploymentadmin.AbstractDeploymentPackage in project felix by apache.
the class DropAllResourcesCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
// Allow proper rollback in case the drop fails...
addRollback(new RollbackCommitAction(session));
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
BundleContext context = session.getBundleContext();
LogService log = session.getLog();
// Collect all unique paths of all processed resources...
Set resourceProcessors = new HashSet();
ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
ResourceInfoImpl resourceInfo = orderedTargetResources[i];
// FELIX-4491: only resources that need to be processed should be handled...
if (!resourceInfo.isProcessedResource()) {
session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
continue;
}
String rpName = resourceInfo.getResourceProcessor();
String path = resourceInfo.getPath();
// Keep track of which resource processors we've seen already...
if (!resourceProcessors.add(rpName)) {
// Already seen this RP; continue on the next one...
continue;
}
ServiceReference ref = target.getResourceProcessor(path);
if (ref == null) {
log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
}
ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
if (resourceProcessor == null) {
log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
}
try {
if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
resourceProcessor.begin(session);
}
resourceProcessor.dropAllResources();
} catch (Exception e) {
log.log(LogService.LOG_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
throw new DeploymentException(CODE_OTHER_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
}
}
}
use of org.apache.felix.deploymentadmin.AbstractDeploymentPackage in project felix by apache.
the class SnapshotCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
BundleContext context = session.getBundleContext();
BundleInfo[] infos = target.getBundleInfos();
Map storageAreas = m_getStorageAreaCommand.getStorageAreas();
for (int i = 0; i < infos.length; i++) {
if (isCancelled()) {
throw new DeploymentException(CODE_CANCELLED);
}
String symbolicName = infos[i].getSymbolicName();
Bundle bundle = target.getBundle(symbolicName);
if (bundle != null) {
File root = (File) storageAreas.get(symbolicName);
if (root != null) {
File snapshot = context.getDataFile("snapshots");
snapshot.mkdirs();
snapshot = new File(snapshot, infos[i].getSymbolicName());
try {
snapshot.createNewFile();
store(root, snapshot);
addRollback(new RestoreSnapshotRunnable(session, snapshot, root));
addCommit(new DeleteSnapshotRunnable(session, snapshot));
} catch (Exception e) {
session.getLog().log(LogService.LOG_WARNING, "Could not access storage area of bundle '" + symbolicName + "'!", e);
snapshot.delete();
}
} else {
session.getLog().log(LogService.LOG_WARNING, "Could not retrieve storage area of bundle '" + symbolicName + "', skipping it.");
}
}
}
}
use of org.apache.felix.deploymentadmin.AbstractDeploymentPackage in project felix by apache.
the class DropBundleCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
LogService log = session.getLog();
BundleInfoImpl[] orderedTargetBundles = target.getOrderedBundleInfos();
for (int i = orderedTargetBundles.length - 1; i >= 0; i--) {
BundleInfoImpl bundleInfo = orderedTargetBundles[i];
String symbolicName = bundleInfo.getSymbolicName();
if (!bundleInfo.isCustomizer() && source.getBundleInfoByName(symbolicName) == null) {
// stale bundle, save a copy for rolling back and uninstall it
try {
Bundle bundle = target.getBundle(symbolicName);
bundle.uninstall();
addRollback(new InstallBundleRunnable(bundle, target, log));
} catch (Exception be) {
log.log(LogService.LOG_WARNING, "Bundle '" + symbolicName + "' could not be uninstalled", be);
}
}
}
}
use of org.apache.felix.deploymentadmin.AbstractDeploymentPackage in project felix by apache.
the class DropResourceCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
// Allow proper rollback in case the drop fails...
addRollback(new RollbackCommitAction(session));
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
BundleContext context = session.getBundleContext();
LogService log = session.getLog();
ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
ResourceInfoImpl resourceInfo = orderedTargetResources[i];
// FELIX-4491: only resources that need to be processed should be handled...
if (!resourceInfo.isProcessedResource()) {
session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
continue;
}
String path = resourceInfo.getPath();
if (source.getResourceInfoByPath(path) == null) {
ServiceReference ref = target.getResourceProcessor(path);
if (ref != null) {
ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
if (resourceProcessor != null) {
try {
if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
resourceProcessor.begin(session);
}
resourceProcessor.dropped(path);
} catch (Exception e) {
log.log(LogService.LOG_WARNING, "Not allowed to drop resource '" + path + "'", e);
}
}
}
}
}
}
Aggregations