Search in sources :

Example 6 with ResourceProcessorException

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

use of org.osgi.service.deploymentadmin.spi.ResourceProcessorException in project felix by apache.

the class StoreResourceTask method prepare.

public void prepare() throws ResourceProcessorException {
    m_log.log(LogService.LOG_DEBUG, "prepare");
    assertInDeploymentSession("Can not prepare resource without a Deployment Session");
    Map<String, List<AutoConfResource>> toBeDeleted;
    Map<String, List<AutoConfResource>> toBeInstalled;
    synchronized (m_lock) {
        toBeDeleted = new HashMap<String, List<AutoConfResource>>(m_toBeDeleted);
        toBeInstalled = new HashMap<String, List<AutoConfResource>>(m_toBeInstalled);
    }
    List<ConfigurationAdminTask> configAdminTasks = new ArrayList<ConfigurationAdminTask>();
    List<PostCommitTask> postCommitTasks = new ArrayList<PostCommitTask>();
    m_log.log(LogService.LOG_DEBUG, "prepare delete");
    // delete dropped resources
    for (Map.Entry<String, List<AutoConfResource>> entry : toBeDeleted.entrySet()) {
        String name = entry.getKey();
        for (AutoConfResource resource : entry.getValue()) {
            configAdminTasks.add(new DropResourceTask(resource));
        }
        postCommitTasks.add(new DeleteResourceTask(name));
    }
    m_log.log(LogService.LOG_DEBUG, "prepare install/update");
    // install new/updated resources
    for (Map.Entry<String, List<AutoConfResource>> entry : toBeInstalled.entrySet()) {
        String name = entry.getKey();
        List<AutoConfResource> existingResources = null;
        try {
            existingResources = m_persistencyManager.load(name);
        } catch (IOException ioe) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_PREPARE, "Unable to read existing resources for resource " + name, ioe);
        }
        List<AutoConfResource> resources = entry.getValue();
        for (AutoConfResource resource : resources) {
            // When updating existing configurations, make sure that we delete the ones that have become obsolete...
            if (existingResources != null) {
                Iterator<AutoConfResource> iter = existingResources.iterator();
                while (iter.hasNext()) {
                    AutoConfResource existing = iter.next();
                    if (existing.equalsTargetConfiguration(resource)) {
                        iter.remove();
                    }
                }
            }
            configAdminTasks.add(new InstallOrUpdateResourceTask(resource));
        }
        // remove existing configurations that were not in the new version of the resource
        for (AutoConfResource existingResource : existingResources) {
            configAdminTasks.add(new DropResourceTask(existingResource));
        }
        postCommitTasks.add(new StoreResourceTask(name, resources));
    }
    synchronized (m_lock) {
        m_configurationAdminTasks.addAll(configAdminTasks);
        m_postCommitTasks.addAll(postCommitTasks);
    }
    m_log.log(LogService.LOG_DEBUG, "prepare done");
}
Also used : ResourceProcessorException(org.osgi.service.deploymentadmin.spi.ResourceProcessorException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ResourceProcessorException

use of org.osgi.service.deploymentadmin.spi.ResourceProcessorException in project felix by apache.

the class StoreResourceTask method parseAutoConfResource.

private MetaData parseAutoConfResource(InputStream stream) throws ResourceProcessorException {
    MetaDataReader reader = new MetaDataReader();
    MetaData data = null;
    try {
        data = reader.parse(stream);
    } catch (IOException e) {
        throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unable to process resource.", e);
    }
    if (data == null) {
        throw new ResourceProcessorException(CODE_OTHER_ERROR, "Supplied configuration is not conform the metatype xml specification.");
    }
    return data;
}
Also used : ResourceProcessorException(org.osgi.service.deploymentadmin.spi.ResourceProcessorException) MetaData(org.apache.felix.metatype.MetaData) IOException(java.io.IOException) MetaDataReader(org.apache.felix.metatype.MetaDataReader)

Example 9 with ResourceProcessorException

use of org.osgi.service.deploymentadmin.spi.ResourceProcessorException in project felix by apache.

the class StoreResourceTask method dropped.

public void dropped(String name) throws ResourceProcessorException {
    m_log.log(LogService.LOG_DEBUG, "dropped " + name);
    assertInDeploymentSession("Can not drop resource without a Deployment Session");
    Map<String, List<AutoConfResource>> toBeDeleted;
    synchronized (m_lock) {
        toBeDeleted = new HashMap<String, List<AutoConfResource>>(m_toBeDeleted);
    }
    try {
        List<AutoConfResource> resources = m_persistencyManager.load(name);
        if (!toBeDeleted.containsKey(name)) {
            toBeDeleted.put(name, new ArrayList());
        }
        toBeDeleted.get(name).addAll(resources);
    } catch (IOException ioe) {
        throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unable to drop resource: " + name, ioe);
    }
    synchronized (m_lock) {
        m_toBeDeleted.putAll(toBeDeleted);
    }
    m_log.log(LogService.LOG_DEBUG, "dropped " + name + " done");
}
Also used : ResourceProcessorException(org.osgi.service.deploymentadmin.spi.ResourceProcessorException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Aggregations

ResourceProcessorException (org.osgi.service.deploymentadmin.spi.ResourceProcessorException)9 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Dictionary (java.util.Dictionary)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DesignateObject (org.apache.felix.metatype.DesignateObject)2 MetaData (org.apache.felix.metatype.MetaData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Enumeration (java.util.Enumeration)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 AbstractDeploymentPackage (org.apache.felix.deploymentadmin.AbstractDeploymentPackage)1 AbstractInfo (org.apache.felix.deploymentadmin.AbstractInfo)1 ResourceInfoImpl (org.apache.felix.deploymentadmin.ResourceInfoImpl)1 Attribute (org.apache.felix.metatype.Attribute)1 Designate (org.apache.felix.metatype.Designate)1 MetaDataReader (org.apache.felix.metatype.MetaDataReader)1