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