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);
}
}
}
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);
}
}
}
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;
}
Aggregations