Search in sources :

Example 6 with AbstractDeploymentPackage

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

the class ProcessResourceCommand method isValidCustomizer.

private boolean isValidCustomizer(DeploymentSessionImpl session, ServiceReference ref) {
    if (session.getConfiguration().isAllowForeignCustomizers()) {
        // If foreign customizers are allowed, any non-null customizer will do...
        return ref != null;
    }
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    String serviceOwnerSymName = ref.getBundle().getSymbolicName();
    // If only local customizers are allowed, we must be able to find this customizer in our DP...
    return source.getBundleInfoByName(serviceOwnerSymName) != null;
}
Also used : AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage)

Example 7 with AbstractDeploymentPackage

use of org.apache.felix.deploymentadmin.AbstractDeploymentPackage 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 8 with AbstractDeploymentPackage

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

the class StartBundleCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    PackageAdmin packageAdmin = session.getPackageAdmin();
    RefreshPackagesListener listener = new RefreshPackagesListener();
    LogService log = session.getLog();
    session.getBundleContext().addFrameworkListener(listener);
    packageAdmin.refreshPackages(null);
    m_refreshMonitor.waitForRefresh();
    session.getBundleContext().removeFrameworkListener(listener);
    // start source bundles
    BundleInfoImpl[] bundleInfos = source.getOrderedBundleInfos();
    for (int i = 0; i < bundleInfos.length; i++) {
        BundleInfoImpl bundleInfoImpl = bundleInfos[i];
        if (!bundleInfoImpl.isCustomizer()) {
            String symbolicName = bundleInfoImpl.getSymbolicName();
            Bundle bundle = source.getBundle(symbolicName);
            if (bundle != null) {
                if (isFragmentBundle(bundle)) {
                    log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
                } else {
                    try {
                        bundle.start();
                    } catch (Exception be) {
                        log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "'", be);
                    }
                }
            } else {
                log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "' because it is not present in the framework");
            }
        }
    }
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService)

Example 9 with AbstractDeploymentPackage

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

the class StartCustomizerCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    Set bundles = new HashSet();
    Set sourceBundlePaths = new HashSet();
    BundleInfoImpl[] targetInfos = target.getBundleInfoImpls();
    BundleInfoImpl[] sourceInfos = source.getBundleInfoImpls();
    for (int i = 0; i < sourceInfos.length; i++) {
        if (sourceInfos[i].isCustomizer()) {
            sourceBundlePaths.add(sourceInfos[i].getPath());
            Bundle bundle = source.getBundle(sourceInfos[i].getSymbolicName());
            if (bundle != null) {
                bundles.add(bundle);
            }
        }
    }
    for (int i = 0; i < targetInfos.length; i++) {
        if (targetInfos[i].isCustomizer() && !sourceBundlePaths.contains(targetInfos[i].getPath())) {
            Bundle bundle = target.getBundle(targetInfos[i].getSymbolicName());
            if (bundle != null) {
                bundles.add(bundle);
            }
        }
    }
    for (Iterator i = bundles.iterator(); i.hasNext(); ) {
        Bundle bundle = (Bundle) i.next();
        try {
            bundle.start();
        } catch (Exception be) {
            throw new DeploymentException(CODE_OTHER_ERROR, "Could not start customizer bundle '" + bundle.getSymbolicName() + "'", be);
        }
        addRollback(new StopCustomizerRunnable(session, bundle));
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) Iterator(java.util.Iterator) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) HashSet(java.util.HashSet)

Example 10 with AbstractDeploymentPackage

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

the class StopBundleCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    LogService log = session.getLog();
    AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
    BundleInfo[] bundleInfos = target.getOrderedBundleInfos();
    for (int i = 0; i < bundleInfos.length; i++) {
        if (isCancelled()) {
            throw new DeploymentException(CODE_CANCELLED);
        }
        String symbolicName = bundleInfos[i].getSymbolicName();
        Bundle bundle = target.getBundle(symbolicName);
        if (bundle != null) {
            if (omitBundleStop(session, symbolicName)) {
                continue;
            }
            if (isFragmentBundle(bundle)) {
                log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
            } else {
                addRollback(new StartBundleRunnable(session, bundle));
                try {
                    bundle.stop();
                } catch (Exception e) {
                    log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "'", e);
                }
            }
        } else {
            log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "' because it was not present in the framework");
        }
    }
}
Also used : BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) Bundle(org.osgi.framework.Bundle) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException)

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