use of org.apache.karaf.bundle.core.BundleStateService in project karaf by apache.
the class BundleServiceImpl method getDiag.
@Override
public String getDiag(Bundle bundle) {
StringBuilder message = new StringBuilder();
for (BundleStateService bundleStateService : stateServices) {
String part = bundleStateService.getDiag(bundle);
if (part != null) {
message.append(bundleStateService.getName());
message.append("\n");
message.append(part);
}
}
if (bundle.getState() == Bundle.INSTALLED) {
System.out.println("Unsatisfied Requirements:");
List<BundleRequirement> reqs = getUnsatisfiedRequirements(bundle, null);
for (BundleRequirement req : reqs) {
System.out.println(req);
}
}
return message.toString();
}
use of org.apache.karaf.bundle.core.BundleStateService in project ddf by codice.
the class ApplicationServiceImplTest method setUp.
/**
* Creates default {@link BundleContext}, {@code List} of {@code BundleStateService}s, and {@link
* Repository} objects for use in the tests.
*
* <p>NOTE: These must be in {@code setUp()} method rather than a {@code beforeClass()} method
* because they are modified by individual tests as part of the setup for individual test
* conditions. @see {@link #createMockFeaturesService(Set, Set, Set)}
*/
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
// Recreate the repos and BundleContext prior to each test in order to
// ensure modifications made in one test do not effect another test.
noMainFeatureRepo1 = createRepo(TEST_NO_MAIN_FEATURE_1_FILE_NAME);
mainFeatureRepo = createRepo(TEST_MAIN_FEATURE_1_FILE_NAME);
bundleContext = mock(BundleContext.class);
mockFeatureRef = (ServiceReference<FeaturesService>) mock(ServiceReference.class);
when(bundleContext.getServiceReference(FeaturesService.class)).thenReturn(mockFeatureRef);
bundleStateServices = new ArrayList<>();
// Create a BundleStateService for Blueprint
BundleStateService mockBundleStateService = mock(BundleStateService.class);
when(mockBundleStateService.getName()).thenReturn(BundleStateService.NAME_BLUEPRINT);
bundleStateServices.add(mockBundleStateService);
}
use of org.apache.karaf.bundle.core.BundleStateService in project karaf by apache.
the class Activator method doStart.
@Override
protected void doStart() throws Exception {
ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
if (configurationAdmin == null) {
return;
}
final BundleServiceImpl bundleService = new BundleServiceImpl(bundleContext);
register(BundleService.class, bundleService);
bundleStateServicesTracker = new ServiceTracker<>(bundleContext, BundleStateService.class, new ServiceTrackerCustomizer<BundleStateService, BundleStateService>() {
@Override
public BundleStateService addingService(ServiceReference<BundleStateService> reference) {
BundleStateService service = bundleContext.getService(reference);
bundleService.registerBundleStateService(service);
return service;
}
@Override
public void modifiedService(ServiceReference<BundleStateService> reference, BundleStateService service) {
}
@Override
public void removedService(ServiceReference<BundleStateService> reference, BundleStateService service) {
bundleService.unregisterBundleStateService(service);
bundleContext.ungetService(reference);
}
});
bundleStateServicesTracker.open();
bundleWatcher = new BundleWatcherImpl(bundleContext, new MavenConfigService(configurationAdmin), bundleService);
bundleWatcher.start();
register(BundleWatcher.class, bundleWatcher);
BundlesMBeanImpl bundlesMBeanImpl = new BundlesMBeanImpl(bundleContext, bundleService);
registerMBean(bundlesMBeanImpl, "type=bundle");
}
use of org.apache.karaf.bundle.core.BundleStateService in project ddf by codice.
the class ApplicationServiceImpl method getCurrentBundleStates.
/**
* Evaluates the bundles contained in a set of {@link Feature}s and
* determines if each bundle is currently in an active, inactive, or failed
* state.
*
* @param features
* @return {@link BundleStateSet} containing information on the state of
* each bundle
*/
private final BundleStateSet getCurrentBundleStates(Set<Feature> features) {
BundleStateSet bundleStateSet = new BundleStateSet();
for (Feature curFeature : features) {
for (BundleInfo curBundleInfo : curFeature.getBundles()) {
Bundle curBundle = getContext().getBundle(curBundleInfo.getLocation());
if (curBundle != null && curBundle.adapt(BundleRevision.class).getTypes() != BundleRevision.TYPE_FRAGMENT) {
// check if bundle is inactive
int bundleState = curBundle.getState();
switch(bundleState) {
case Bundle.RESOLVED:
case Bundle.STARTING:
case Bundle.STOPPING:
bundleStateSet.addInactiveBundle(curBundle);
break;
case Bundle.INSTALLED:
case Bundle.UNINSTALLED:
bundleStateSet.addFailedBundle(curBundle);
break;
case Bundle.ACTIVE:
// and SpringDM) failed on start
for (BundleStateService curStateService : bundleStateServices) {
LOGGER.trace("Checking {} for bundle state of {}.", curStateService.getName(), curBundle.getSymbolicName());
BundleState curState = curStateService.getState(curBundle);
switch(curState) {
case Resolved:
case Stopping:
LOGGER.trace("{} is in an inactive state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
bundleStateSet.addInactiveBundle(curBundle);
break;
case Installed:
case Failure:
LOGGER.trace("{} is in a failed state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
bundleStateSet.addFailedBundle(curBundle);
break;
case Waiting:
case Starting:
case GracePeriod:
LOGGER.trace("{} is in a transitional state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
bundleStateSet.addTransitionalBundle(curBundle);
break;
case Active:
LOGGER.trace("{} is in an active state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
bundleStateSet.addActiveBundle(curBundle);
break;
case Unknown:
default:
// Ignore - BundleStateService unaware of this bundle.
break;
}
}
// end case Bundle.Active
break;
default:
bundleStateSet.addActiveBundle(curBundle);
break;
}
}
}
}
return bundleStateSet;
}
Aggregations