Search in sources :

Example 1 with BundleInfo

use of org.apache.karaf.bundle.core.BundleInfo in project ddf by codice.

the class ServiceManagerImpl method isBundleReady.

private boolean isBundleReady(Bundle bundle) {
    String name = bundle.getHeaders().get(Constants.BUNDLE_NAME);
    BundleInfo info = bundleService.getInfo(bundle);
    BundleState state = info.getState();
    boolean ready;
    if (info.isFragment()) {
        ready = BundleState.Resolved.equals(state);
    } else {
        if (BundleState.Failure.equals(state)) {
            printInactiveBundles();
            LOGGER.error("The bundle {} failed.", name);
        }
        ready = BundleState.Active.equals(state);
    }
    if (!ready) {
        LOGGER.debug("{} bundle not ready yet", name);
    }
    return ready;
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) BundleState(org.apache.karaf.bundle.core.BundleState)

Example 2 with BundleInfo

use of org.apache.karaf.bundle.core.BundleInfo in project ddf by codice.

the class SynchronizedInstallerImpl method getUnavailableBundles.

@VisibleForTesting
BundleStates getUnavailableBundles(Set<String> toCheck) {
    Set<Bundle> unavailableBundles = new HashSet<>();
    Set<Bundle> failedBundles = new HashSet<>();
    for (Bundle bundle : bundleContext.getBundles()) {
        if (!toCheck.contains(bundle.getSymbolicName())) {
            continue;
        }
        BundleInfo bundleInfo = bundleService.getInfo(bundle);
        BundleState bundleState = bundleInfo.getState();
        if (BundleState.Failure.equals(bundleState)) {
            failedBundles.add(bundle);
            continue;
        }
        if (bundleInfo.isFragment()) {
            if (!BundleState.Resolved.equals(bundleState)) {
                unavailableBundles.add(bundle);
            }
        } else if (!BundleState.Active.equals(bundleState)) {
            unavailableBundles.add(bundle);
        }
    }
    return new BundleStates(unavailableBundles, failedBundles);
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) Bundle(org.osgi.framework.Bundle) BundleState(org.apache.karaf.bundle.core.BundleState) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with BundleInfo

use of org.apache.karaf.bundle.core.BundleInfo in project karaf by apache.

the class BundlesMBeanImpl method getDiag.

@Override
public TabularData getDiag() throws MBeanException {
    try {
        CompositeType diagType = new CompositeType("Diag", "OSGi Bundle Diag", new String[] { "Name", "Status", "Diag" }, new String[] { "Bundle Name", "Current Status", "Diagnostic" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
        TabularType tableType = new TabularType("Diagnostics", "Tables of all bundles diagnostic", diagType, new String[] { "Name" });
        TabularData table = new TabularDataSupport(tableType);
        Bundle[] bundles = bundleContext.getBundles();
        for (Bundle bundle : bundles) {
            BundleInfo bundleInfo = bundleService.getInfo(bundle);
            String name = ShellUtil.getBundleName(bundle);
            String status = bundleInfo.getState().toString();
            String diag = bundleService.getDiag(bundle);
            CompositeData data = new CompositeDataSupport(diagType, new String[] { "Name", "Status", "Diag" }, new Object[] { name, status, diag });
            table.put(data);
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Bundle(org.osgi.framework.Bundle) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 4 with BundleInfo

use of org.apache.karaf.bundle.core.BundleInfo in project karaf by apache.

the class BundlesMBeanImpl method getBundles.

public TabularData getBundles() throws MBeanException {
    try {
        CompositeType bundleType = new CompositeType("Bundle", "OSGi Bundle", new String[] { "ID", "Name", "Symbolic Name", "Version", "Start Level", "State", "Update Location" }, new String[] { "ID of the Bundle", "Name of the Bundle", "Symbolic Name of the Bundle", "Version of the Bundle", "Start Level of the Bundle", "Current State of the Bundle", "Update location of the Bundle" }, new OpenType[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING });
        TabularType tableType = new TabularType("Bundles", "Tables of all bundles", bundleType, new String[] { "ID" });
        TabularData table = new TabularDataSupport(tableType);
        Bundle[] bundles = bundleContext.getBundles();
        for (Bundle bundle : bundles) {
            try {
                BundleInfo info = bundleService.getInfo(bundle);
                String bundleStateString = info.getState().toString();
                CompositeData data = new CompositeDataSupport(bundleType, new String[] { "ID", "Name", "Symbolic Name", "Version", "Start Level", "State", "Update Location" }, new Object[] { info.getBundleId(), info.getName(), info.getSymbolicName(), info.getVersion(), info.getStartLevel(), bundleStateString, info.getUpdateLocation() });
                table.put(data);
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Bundle(org.osgi.framework.Bundle) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 5 with BundleInfo

use of org.apache.karaf.bundle.core.BundleInfo in project karaf by apache.

the class Diag method executeOnBundle.

@Override
protected void executeOnBundle(Bundle bundle) throws Exception {
    BundleInfo info = bundleService.getInfo(bundle);
    if (info.getState() == BundleState.Failure || info.getState() == BundleState.Waiting || info.getState() == BundleState.GracePeriod || info.getState() == BundleState.Installed) {
        String title = ShellUtil.getBundleName(bundle);
        System.out.println(title);
        System.out.println(ShellUtil.getUnderlineString(title));
        System.out.println("Status: " + info.getState().toString());
        System.out.println(this.bundleService.getDiag(bundle));
        System.out.println();
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo)

Aggregations

BundleInfo (org.apache.karaf.bundle.core.BundleInfo)8 Bundle (org.osgi.framework.Bundle)6 BundleState (org.apache.karaf.bundle.core.BundleState)4 MBeanException (javax.management.MBeanException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 CompositeData (javax.management.openmbean.CompositeData)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 CompositeType (javax.management.openmbean.CompositeType)2 TabularData (javax.management.openmbean.TabularData)2 TabularDataSupport (javax.management.openmbean.TabularDataSupport)2 TabularType (javax.management.openmbean.TabularType)2 BundleService (org.apache.karaf.bundle.core.BundleService)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Col (org.apache.karaf.shell.support.table.Col)1 Row (org.apache.karaf.shell.support.table.Row)1 ShellTable (org.apache.karaf.shell.support.table.ShellTable)1 Test (org.junit.Test)1 FrameworkStartLevel (org.osgi.framework.startlevel.FrameworkStartLevel)1