Search in sources :

Example 1 with BundleStateService

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();
}
Also used : BundleStateService(org.apache.karaf.bundle.core.BundleStateService) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 2 with BundleStateService

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);
}
Also used : BundleStateService(org.apache.karaf.bundle.core.BundleStateService) FeaturesService(org.apache.karaf.features.FeaturesService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 3 with BundleStateService

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");
}
Also used : MavenConfigService(org.apache.karaf.bundle.core.internal.MavenConfigService) BundleStateService(org.apache.karaf.bundle.core.BundleStateService) BundleWatcherImpl(org.apache.karaf.bundle.core.internal.BundleWatcherImpl) BundleServiceImpl(org.apache.karaf.bundle.core.internal.BundleServiceImpl) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) BundlesMBeanImpl(org.apache.karaf.bundle.core.internal.BundlesMBeanImpl) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceReference(org.osgi.framework.ServiceReference)

Example 4 with BundleStateService

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;
}
Also used : BundleStateService(org.apache.karaf.bundle.core.BundleStateService) BundleInfo(org.apache.karaf.features.BundleInfo) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleState(org.apache.karaf.bundle.core.BundleState) Feature(org.apache.karaf.features.Feature)

Aggregations

BundleStateService (org.apache.karaf.bundle.core.BundleStateService)4 BundleState (org.apache.karaf.bundle.core.BundleState)1 BundleServiceImpl (org.apache.karaf.bundle.core.internal.BundleServiceImpl)1 BundleWatcherImpl (org.apache.karaf.bundle.core.internal.BundleWatcherImpl)1 BundlesMBeanImpl (org.apache.karaf.bundle.core.internal.BundlesMBeanImpl)1 MavenConfigService (org.apache.karaf.bundle.core.internal.MavenConfigService)1 BundleInfo (org.apache.karaf.features.BundleInfo)1 Feature (org.apache.karaf.features.Feature)1 FeaturesService (org.apache.karaf.features.FeaturesService)1 Before (org.junit.Before)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceReference (org.osgi.framework.ServiceReference)1 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1