Search in sources :

Example 1 with AbstractInfo

use of org.apache.felix.deploymentadmin.AbstractInfo in project felix by apache.

the class ProcessResourceCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    // Allow proper rollback in case the drop fails...
    addRollback(new RollbackCommitAction(session));
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    BundleContext context = session.getBundleContext();
    Map expectedResources = new HashMap();
    AbstractInfo[] resourceInfos = (AbstractInfo[]) source.getResourceInfos();
    for (int i = 0; i < resourceInfos.length; i++) {
        AbstractInfo resourceInfo = resourceInfos[i];
        if (!resourceInfo.isMissing()) {
            expectedResources.put(resourceInfo.getPath(), resourceInfo);
        }
    }
    try {
        while (!expectedResources.isEmpty()) {
            AbstractInfo jarEntry = source.getNextEntry();
            if (jarEntry == null) {
                throw new DeploymentException(CODE_OTHER_ERROR, "Expected more resources in the stream: " + expectedResources.keySet());
            }
            String name = jarEntry.getPath();
            ResourceInfoImpl resourceInfo = (ResourceInfoImpl) expectedResources.remove(name);
            if (resourceInfo == null) {
                throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
            }
            // 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;
            }
            ServiceReference ref = source.getResourceProcessor(name);
            if (ref == null) {
                throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
            }
            if (!isValidCustomizer(session, ref)) {
                throw new DeploymentException(CODE_FOREIGN_CUSTOMIZER, "Resource processor for resource '" + name + "' belongs to foreign deployment package");
            }
            ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
            if (resourceProcessor == null) {
                throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
            }
            try {
                if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
                    resourceProcessor.begin(session);
                }
                resourceProcessor.process(name, source.getCurrentEntryStream());
            } catch (ResourceProcessorException rpe) {
                if (rpe.getCode() == ResourceProcessorException.CODE_RESOURCE_SHARING_VIOLATION) {
                    throw new DeploymentException(CODE_RESOURCE_SHARING_VIOLATION, "Sharing violation while processing resource '" + name + "'", rpe);
                } else {
                    throw new DeploymentException(CODE_OTHER_ERROR, "Error while processing resource '" + name + "'", rpe);
                }
            }
        }
    } catch (IOException e) {
        throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
    }
}
Also used : ResourceProcessorException(org.osgi.service.deploymentadmin.spi.ResourceProcessorException) HashMap(java.util.HashMap) ResourceInfoImpl(org.apache.felix.deploymentadmin.ResourceInfoImpl) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) IOException(java.io.IOException) ResourceProcessor(org.osgi.service.deploymentadmin.spi.ResourceProcessor) AbstractInfo(org.apache.felix.deploymentadmin.AbstractInfo) ServiceReference(org.osgi.framework.ServiceReference) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Map(java.util.Map) HashMap(java.util.HashMap) BundleContext(org.osgi.framework.BundleContext)

Example 2 with AbstractInfo

use of org.apache.felix.deploymentadmin.AbstractInfo in project felix by apache.

the class UpdateCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    AbstractDeploymentPackage targetPackage = session.getTargetAbstractDeploymentPackage();
    BundleContext context = session.getBundleContext();
    LogService log = session.getLog();
    Map expectedBundles = new HashMap();
    AbstractInfo[] bundleInfos = (AbstractInfo[]) source.getBundleInfos();
    for (int i = 0; i < bundleInfos.length; i++) {
        AbstractInfo bundleInfo = bundleInfos[i];
        if (!bundleInfo.isMissing()) {
            expectedBundles.put(bundleInfo.getPath(), bundleInfo);
        }
    }
    try {
        while (!expectedBundles.isEmpty()) {
            AbstractInfo entry = source.getNextEntry();
            if (entry == null) {
                throw new DeploymentException(CODE_OTHER_ERROR, "Expected more bundles in the stream: " + expectedBundles.keySet());
            }
            String name = entry.getPath();
            BundleInfoImpl bundleInfo = (BundleInfoImpl) expectedBundles.remove(name);
            if (bundleInfo == null) {
                if (isLocalizationFile(name)) {
                    // FELIX-518: do not try to process signature or localization files...
                    continue;
                }
                throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
            }
            String bsn = bundleInfo.getSymbolicName();
            Version sourceVersion = bundleInfo.getVersion();
            Bundle bundle = targetPackage.getBundle(bsn);
            try {
                if (bundle == null) {
                    // new bundle, install it
                    bundle = context.installBundle(BUNDLE_LOCATION_PREFIX + bsn, new BundleInputStream(source.getCurrentEntryStream()));
                    addRollback(new UninstallBundleRunnable(bundle, log));
                } else {
                    // existing bundle, update it
                    Version currentVersion = getVersion(bundle);
                    if (!sourceVersion.equals(currentVersion)) {
                        bundle.update(new BundleInputStream(source.getCurrentEntryStream()));
                        addRollback(new UpdateBundleRunnable(bundle, targetPackage, log));
                    }
                }
            } catch (Exception be) {
                if (isCancelled()) {
                    return;
                }
                throw new DeploymentException(CODE_OTHER_ERROR, "Could not install new bundle '" + name + "' (" + bsn + ")", be);
            }
            if (!bundle.getSymbolicName().equals(bsn)) {
                throw new DeploymentException(CODE_BUNDLE_NAME_ERROR, "Installed/updated bundle symbolicname (" + bundle.getSymbolicName() + ") do not match what was installed/updated: " + bsn);
            }
            Version targetVersion = getVersion(bundle);
            if (!sourceVersion.equals(targetVersion)) {
                throw new DeploymentException(CODE_OTHER_ERROR, "Installed/updated bundle version (" + targetVersion + ") do not match what was installed/updated: " + sourceVersion + ", offending bundle = " + bsn);
            }
        }
    } catch (IOException e) {
        throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
    }
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) IOException(java.io.IOException) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) IOException(java.io.IOException) AbstractInfo(org.apache.felix.deploymentadmin.AbstractInfo) Version(org.osgi.framework.Version) BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Map(java.util.Map) HashMap(java.util.HashMap) LogService(org.osgi.service.log.LogService) BundleContext(org.osgi.framework.BundleContext)

Aggregations

IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AbstractDeploymentPackage (org.apache.felix.deploymentadmin.AbstractDeploymentPackage)2 AbstractInfo (org.apache.felix.deploymentadmin.AbstractInfo)2 BundleContext (org.osgi.framework.BundleContext)2 DeploymentException (org.osgi.service.deploymentadmin.DeploymentException)2 BundleInfoImpl (org.apache.felix.deploymentadmin.BundleInfoImpl)1 ResourceInfoImpl (org.apache.felix.deploymentadmin.ResourceInfoImpl)1 Bundle (org.osgi.framework.Bundle)1 ServiceReference (org.osgi.framework.ServiceReference)1 Version (org.osgi.framework.Version)1 ResourceProcessor (org.osgi.service.deploymentadmin.spi.ResourceProcessor)1 ResourceProcessorException (org.osgi.service.deploymentadmin.spi.ResourceProcessorException)1 LogService (org.osgi.service.log.LogService)1