Repository: karaf Updated Branches: refs/heads/karaf-4.0.x 4c9ca1673 -> 95ee24656
KARAF-3871 - Provide diag attribute in BundleMBean Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/95ee2465 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/95ee2465 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/95ee2465 Branch: refs/heads/karaf-4.0.x Commit: 95ee246560b388d6ad64c49b3cf67787d49655e5 Parents: 4c9ca16 Author: Jean-Baptiste Onofré <[email protected]> Authored: Sun Feb 7 08:37:11 2016 +0100 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Sun Feb 7 08:37:59 2016 +0100 ---------------------------------------------------------------------- .../apache/karaf/bundle/core/BundlesMBean.java | 4 ++- .../bundle/core/internal/BundlesMBeanImpl.java | 32 +++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/95ee2465/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java ---------------------------------------------------------------------- diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java index 2011a62..0327622 100644 --- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java +++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java @@ -48,7 +48,9 @@ public interface BundlesMBean { void stop(String bundleId) throws MBeanException; void uninstall(String bundleId) throws MBeanException; - + + TabularData getDiag() throws MBeanException; + String getDiag(long bundleId); String getStatus(String bundleId) throws MBeanException; http://git-wip-us.apache.org/repos/asf/karaf/blob/95ee2465/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundlesMBeanImpl.java ---------------------------------------------------------------------- diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundlesMBeanImpl.java b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundlesMBeanImpl.java index 6490ed4..79131c1 100644 --- a/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundlesMBeanImpl.java +++ b/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundlesMBeanImpl.java @@ -36,6 +36,7 @@ import javax.management.openmbean.TabularType; import org.apache.karaf.bundle.core.BundleInfo; import org.apache.karaf.bundle.core.BundleService; import org.apache.karaf.bundle.core.BundlesMBean; +import org.apache.karaf.shell.support.ShellUtil; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.startlevel.BundleStartLevel; @@ -47,6 +48,7 @@ import org.slf4j.LoggerFactory; * BundlesMBean implementation. */ public class BundlesMBeanImpl extends StandardMBean implements BundlesMBean { + private Logger LOG = LoggerFactory.getLogger(BundlesMBeanImpl.class); private BundleContext bundleContext; @@ -69,7 +71,7 @@ public class BundlesMBeanImpl extends StandardMBean implements BundlesMBean { new String[]{"ID", "Name", "Version", "Start Level", "State"}, new String[]{"ID of the Bundle", "Name of the Bundle", "Version of the Bundle", "Start Level of the Bundle", "Current State of the Bundle"}, new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING}); - TabularType tableType = new TabularType("BundlesMBeanImpl", "Tables of all BundlesMBeanImpl", bundleType, new String[]{"ID"}); + TabularType tableType = new TabularType("Bundles", "Tables of all bundles", bundleType, new String[]{"ID"}); TabularData table = new TabularDataSupport(tableType); Bundle[] bundles = bundleContext.getBundles(); @@ -257,6 +259,34 @@ public class BundlesMBeanImpl extends StandardMBean implements BundlesMBean { } @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.getMessage()); + } + } + + @Override public String getDiag(long bundleId) { Bundle bundle = bundleContext.getBundle(bundleId); if (bundle == null) {
