use of org.apache.felix.deploymentadmin.ResourceInfoImpl 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);
}
}
}
use of org.apache.felix.deploymentadmin.ResourceInfoImpl 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);
}
}
}
}
}
}
use of org.apache.felix.deploymentadmin.ResourceInfoImpl 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);
}
}
Aggregations