Search in sources :

Example 6 with BundleInfo

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

the class JavaSecurityTest method testJavaSecurity.

@Test
public void testJavaSecurity() throws Exception {
    assertNotNull("Karaf should run under a security manager", System.getSecurityManager());
    BundleService service = getOsgiService(BundleService.class);
    long tried = 0;
    while (true) {
        Map<Bundle, BundleState> incorrect = new HashMap<>();
        for (Bundle bundle : bundleContext.getBundles()) {
            BundleInfo info = service.getInfo(bundle);
            BundleState state = info.getState();
            if (state != BundleState.Active && state != BundleState.Resolved) {
                incorrect.put(bundle, state);
            }
        }
        if (incorrect.isEmpty()) {
            break;
        } else {
            if (++tried >= 10) {
                fail("Unable to start bundles correctly: " + incorrect);
            }
            Thread.sleep(100);
        }
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) Bundle(org.osgi.framework.Bundle) BundleState(org.apache.karaf.bundle.core.BundleState) BundleService(org.apache.karaf.bundle.core.BundleService) Test(org.junit.Test)

Example 7 with BundleInfo

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

the class ServiceManagerImpl method waitForRequiredBundles.

@Override
public void waitForRequiredBundles(String symbolicNamePrefix) throws InterruptedException {
    boolean ready = false;
    if (bundleService == null) {
        bundleService = getService(BundleService.class);
    }
    long timeoutLimit = System.currentTimeMillis() + FEATURES_AND_BUNDLES_TIMEOUT;
    while (!ready) {
        List<Bundle> bundles = Arrays.asList(getBundleContext().getBundles());
        ready = true;
        for (Bundle bundle : bundles) {
            if (bundle.getSymbolicName().startsWith(symbolicNamePrefix)) {
                String bundleName = bundle.getHeaders().get(Constants.BUNDLE_NAME);
                BundleInfo bundleInfo = bundleService.getInfo(bundle);
                BundleState bundleState = bundleInfo.getState();
                if (bundleInfo.isFragment()) {
                    if (!BundleState.Resolved.equals(bundleState)) {
                        LOGGER.info("{} bundle not ready yet", bundleName);
                        ready = false;
                    }
                } else if (bundleState != null) {
                    if (BundleState.Failure.equals(bundleState)) {
                        printInactiveBundles();
                        fail("The bundle " + bundleName + " failed.");
                    } else if (!BundleState.Active.equals(bundleState)) {
                        LOGGER.info("{} bundle not ready with state {}", bundleName, bundleState);
                        ready = false;
                    }
                }
            }
        }
        if (!ready) {
            if (System.currentTimeMillis() > timeoutLimit) {
                printInactiveBundles();
                fail(String.format("Bundles and blueprint did not start within %d minutes.", TimeUnit.MILLISECONDS.toMinutes(FEATURES_AND_BUNDLES_TIMEOUT)));
            }
            LOGGER.info("Bundles not up, sleeping...");
            Thread.sleep(1000);
        }
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) Bundle(org.osgi.framework.Bundle) BundleState(org.apache.karaf.bundle.core.BundleState) BundleService(org.apache.karaf.bundle.core.BundleService)

Example 8 with BundleInfo

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

the class List method doExecute.

@Override
protected Object doExecute(java.util.List<Bundle> bundles) throws Exception {
    if (noFormat) {
        noEllipsis = true;
    }
    determineBundleLevelThreshold();
    // Display active start level.
    FrameworkStartLevel fsl = this.bundleContext.getBundle(0).adapt(FrameworkStartLevel.class);
    if (fsl != null) {
        System.out.println("START LEVEL " + fsl.getStartLevel() + " , List Threshold: " + bundleLevelThreshold);
    }
    ShellTable table = new ShellTable();
    if (!noEllipsis && terminal != null && terminal.getWidth() > 0) {
        table.size(terminal.getWidth() - 1);
    }
    table.column("ID").alignRight();
    table.column("State");
    table.column("Lvl").alignRight();
    table.column("Version");
    boolean effectiveShowName = showName || (!showLocation && !showSymbolic && !showUpdate && !showRevisions);
    if (effectiveShowName) {
        table.column("Name");
    }
    if (showLocation) {
        table.column(new Col("Location") {

            @Override
            protected String cut(String value, int size) {
                if (showLocation && value.length() > size) {
                    String[] parts = value.split("/");
                    String cut = "";
                    int c = parts[0].length() + 4;
                    for (int idx = parts.length - 1; idx > 0; idx--) {
                        if (cut.length() + c + parts[idx].length() + 1 < size) {
                            cut = "/" + parts[idx] + cut;
                        } else {
                            break;
                        }
                    }
                    cut = parts[0] + "/..." + cut;
                    return cut;
                } else {
                    return super.cut(value, size);
                }
            }
        });
    }
    if (showSymbolic) {
        table.column("Symbolic name");
    }
    if (showUpdate) {
        table.column("Update location");
    }
    if (showRevisions) {
        table.column("Revisions");
    }
    for (Bundle bundle : bundles) {
        BundleInfo info = this.bundleService.getInfo(bundle);
        if (info.getStartLevel() >= bundleLevelThreshold) {
            String version = info.getVersion();
            ArrayList<Object> rowData = new ArrayList<>();
            rowData.add(info.getBundleId());
            rowData.add(getStateString(info.getState()));
            rowData.add(info.getStartLevel());
            rowData.add(version);
            if (effectiveShowName) {
                String bundleName = (info.getName() == null) ? info.getSymbolicName() : info.getName();
                bundleName = (bundleName == null) ? info.getUpdateLocation() : bundleName;
                String name = bundleName + printFragments(info) + printHosts(info);
                rowData.add(name);
            }
            if (showLocation) {
                rowData.add(info.getUpdateLocation());
            }
            if (showSymbolic) {
                rowData.add(info.getSymbolicName() == null ? "<no symbolic name>" : info.getSymbolicName());
            }
            if (showUpdate) {
                rowData.add(info.getUpdateLocation());
            }
            if (showRevisions) {
                rowData.add(info.getRevisions());
            }
            Row row = table.addRow();
            row.addContent(rowData);
        }
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : Col(org.apache.karaf.shell.support.table.Col) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel) ShellTable(org.apache.karaf.shell.support.table.ShellTable) BundleInfo(org.apache.karaf.bundle.core.BundleInfo) Row(org.apache.karaf.shell.support.table.Row)

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