Search in sources :

Example 1 with AbstractDeploymentPackage

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);
        }
    }
}
Also used : BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService)

Example 2 with AbstractDeploymentPackage

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);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResourceInfoImpl(org.apache.felix.deploymentadmin.ResourceInfoImpl) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) ResourceProcessor(org.osgi.service.deploymentadmin.spi.ResourceProcessor) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) ServiceReference(org.osgi.framework.ServiceReference) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) LogService(org.osgi.service.log.LogService) BundleContext(org.osgi.framework.BundleContext) HashSet(java.util.HashSet)

Example 3 with AbstractDeploymentPackage

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.");
            }
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) IOException(java.io.IOException) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Map(java.util.Map) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 4 with AbstractDeploymentPackage

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);
            }
        }
    }
}
Also used : BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService)

Example 5 with AbstractDeploymentPackage

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);
                    }
                }
            }
        }
    }
}
Also used : ResourceInfoImpl(org.apache.felix.deploymentadmin.ResourceInfoImpl) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService) ResourceProcessor(org.osgi.service.deploymentadmin.spi.ResourceProcessor) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

AbstractDeploymentPackage (org.apache.felix.deploymentadmin.AbstractDeploymentPackage)11 Bundle (org.osgi.framework.Bundle)7 LogService (org.osgi.service.log.LogService)7 DeploymentException (org.osgi.service.deploymentadmin.DeploymentException)6 BundleInfoImpl (org.apache.felix.deploymentadmin.BundleInfoImpl)5 BundleContext (org.osgi.framework.BundleContext)5 IOException (java.io.IOException)3 Map (java.util.Map)3 ResourceInfoImpl (org.apache.felix.deploymentadmin.ResourceInfoImpl)3 ServiceReference (org.osgi.framework.ServiceReference)3 ResourceProcessor (org.osgi.service.deploymentadmin.spi.ResourceProcessor)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AbstractInfo (org.apache.felix.deploymentadmin.AbstractInfo)2 BundleInfo (org.osgi.service.deploymentadmin.BundleInfo)2 File (java.io.File)1 Iterator (java.util.Iterator)1 Version (org.osgi.framework.Version)1 ResourceProcessorException (org.osgi.service.deploymentadmin.spi.ResourceProcessorException)1