Search in sources :

Example 1 with ResourceProcessor

use of org.osgi.service.deploymentadmin.spi.ResourceProcessor 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 2 with ResourceProcessor

use of org.osgi.service.deploymentadmin.spi.ResourceProcessor 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)

Example 3 with ResourceProcessor

use of org.osgi.service.deploymentadmin.spi.ResourceProcessor 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)

Aggregations

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