use of org.osgi.service.log.LogService 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.osgi.service.log.LogService 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.osgi.service.log.LogService 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");
}
}
}
use of org.osgi.service.log.LogService in project felix by apache.
the class UpdateCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
AbstractDeploymentPackage targetPackage = session.getTargetAbstractDeploymentPackage();
BundleContext context = session.getBundleContext();
LogService log = session.getLog();
Map expectedBundles = new HashMap();
AbstractInfo[] bundleInfos = (AbstractInfo[]) source.getBundleInfos();
for (int i = 0; i < bundleInfos.length; i++) {
AbstractInfo bundleInfo = bundleInfos[i];
if (!bundleInfo.isMissing()) {
expectedBundles.put(bundleInfo.getPath(), bundleInfo);
}
}
try {
while (!expectedBundles.isEmpty()) {
AbstractInfo entry = source.getNextEntry();
if (entry == null) {
throw new DeploymentException(CODE_OTHER_ERROR, "Expected more bundles in the stream: " + expectedBundles.keySet());
}
String name = entry.getPath();
BundleInfoImpl bundleInfo = (BundleInfoImpl) expectedBundles.remove(name);
if (bundleInfo == null) {
if (isLocalizationFile(name)) {
// FELIX-518: do not try to process signature or localization files...
continue;
}
throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
}
String bsn = bundleInfo.getSymbolicName();
Version sourceVersion = bundleInfo.getVersion();
Bundle bundle = targetPackage.getBundle(bsn);
try {
if (bundle == null) {
// new bundle, install it
bundle = context.installBundle(BUNDLE_LOCATION_PREFIX + bsn, new BundleInputStream(source.getCurrentEntryStream()));
addRollback(new UninstallBundleRunnable(bundle, log));
} else {
// existing bundle, update it
Version currentVersion = getVersion(bundle);
if (!sourceVersion.equals(currentVersion)) {
bundle.update(new BundleInputStream(source.getCurrentEntryStream()));
addRollback(new UpdateBundleRunnable(bundle, targetPackage, log));
}
}
} catch (Exception be) {
if (isCancelled()) {
return;
}
throw new DeploymentException(CODE_OTHER_ERROR, "Could not install new bundle '" + name + "' (" + bsn + ")", be);
}
if (!bundle.getSymbolicName().equals(bsn)) {
throw new DeploymentException(CODE_BUNDLE_NAME_ERROR, "Installed/updated bundle symbolicname (" + bundle.getSymbolicName() + ") do not match what was installed/updated: " + bsn);
}
Version targetVersion = getVersion(bundle);
if (!sourceVersion.equals(targetVersion)) {
throw new DeploymentException(CODE_OTHER_ERROR, "Installed/updated bundle version (" + targetVersion + ") do not match what was installed/updated: " + sourceVersion + ", offending bundle = " + bsn);
}
}
} catch (IOException e) {
throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
}
}
use of org.osgi.service.log.LogService in project felix by apache.
the class Activator method init.
/**
* Initialize our DependencyManager Runtime service.
*
* We depend on the OSGi LogService, and we track all started bundles which do have a
* "DependencyManager-Component" Manifest header.
* If the "dm.runtime.log=true" or "dm.runtime.packageAdmin=true" parameter is configured in the Felix config.properties
* then we'll use a required/temporal service dependency over the respective service.
* These temporal dependencies avoid us to be restarted if the respective service is temporarily
* unavailable (that is: when the service is updating).
* if the "dm.runtime.log" or "dm.runtime.packageAdmin" is not configured or it it is set to false, then we'll use
* an optional dependency over the respective service, in order to use a NullObject in case
* the service is not available.
*/
@Override
public void init(BundleContext context, DependencyManager dm) throws Exception {
boolean logEnabled = "true".equalsIgnoreCase(context.getProperty(CONF_LOG));
Log.instance().enableLogs(logEnabled);
Component component = createComponent().setImplementation(DependencyManagerRuntime.class).setComposition("getComposition").add(createBundleDependency().setRequired(false).setStateMask(Bundle.ACTIVE).setFilter("(DependencyManager-Component=*)").setCallbacks("bundleStarted", "bundleStopped")).add(createServiceDependency().setRequired(true).setService(PackageAdmin.class)).add(createServiceDependency().setRequired(logEnabled).setService(LogService.class));
dm.add(component);
}
Aggregations