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);
}
}
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");
}
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;
}
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");
}
Aggregations