Search in sources :

Example 11 with TabularType

use of javax.management.openmbean.TabularType in project jackrabbit-oak by apache.

the class LuceneIndexMBeanImpl method getBadPersistedIndexStats.

@Override
public TabularData getBadPersistedIndexStats() {
    TabularDataSupport tds;
    try {
        TabularType tt = new TabularType(LuceneIndexMBeanImpl.class.getName(), "Lucene Bad Persisted Index Stats", BadIndexStats.TYPE, new String[] { "path" });
        tds = new TabularDataSupport(tt);
        Set<String> indexes = indexTracker.getBadIndexTracker().getBadPersistedIndexPaths();
        for (String path : indexes) {
            BadIndexInfo info = indexTracker.getBadIndexTracker().getPersistedIndexInfo(path);
            if (info != null) {
                BadIndexStats stats = new BadIndexStats(info);
                tds.put(stats.toCompositeData());
            }
        }
    } catch (OpenDataException e) {
        throw new IllegalStateException(e);
    }
    return tds;
}
Also used : BadIndexInfo(org.apache.jackrabbit.oak.plugins.index.lucene.BadIndexTracker.BadIndexInfo) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType)

Example 12 with TabularType

use of javax.management.openmbean.TabularType in project jackrabbit-oak by apache.

the class LuceneIndexMBeanImpl method getBadIndexStats.

@Override
public TabularData getBadIndexStats() {
    TabularDataSupport tds;
    try {
        TabularType tt = new TabularType(LuceneIndexMBeanImpl.class.getName(), "Lucene Bad Index Stats", BadIndexStats.TYPE, new String[] { "path" });
        tds = new TabularDataSupport(tt);
        Set<String> indexes = indexTracker.getBadIndexTracker().getIndexPaths();
        for (String path : indexes) {
            BadIndexInfo info = indexTracker.getBadIndexTracker().getInfo(path);
            if (info != null) {
                BadIndexStats stats = new BadIndexStats(info);
                tds.put(stats.toCompositeData());
            }
        }
    } catch (OpenDataException e) {
        throw new IllegalStateException(e);
    }
    return tds;
}
Also used : BadIndexInfo(org.apache.jackrabbit.oak.plugins.index.lucene.BadIndexTracker.BadIndexInfo) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType)

Example 13 with TabularType

use of javax.management.openmbean.TabularType in project karaf by apache.

the class PackagesMBeanImpl method getImports.

@Override
public TabularData getImports() {
    try {
        String[] names = new String[] { "PackageName", "Filter", "Optional", "ID", "Bundle Name", "Resolvable" };
        CompositeType bundleType = new CompositeType("PackageImports", "Imported packages", names, names, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.STRING, SimpleType.BOOLEAN });
        TabularType tableType = new TabularType("PackageImports", "Imported packages", bundleType, new String[] { "Filter", "ID" });
        TabularData table = new TabularDataSupport(tableType);
        List<PackageRequirement> imports = packageService.getImports();
        for (PackageRequirement req : imports) {
            Object[] data = new Object[] { req.getPackageName(), req.getFilter(), req.isOptional(), req.getBundle().getBundleId(), req.getBundle().getSymbolicName(), req.isResolveable() };
            CompositeData comp = new CompositeDataSupport(bundleType, names, data);
            try {
                table.put(comp);
            } catch (KeyAlreadyExistsException e) {
                throw new RuntimeException("Id: " + req.getBundle().getBundleId() + ", filter: " + req.getFilter(), e);
            }
        }
        return table;
    } catch (RuntimeException e) {
        // To avoid the exception gets swallowed by jmx
        LOGGER.error(e.getMessage(), e);
        throw e;
    } catch (OpenDataException e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) KeyAlreadyExistsException(javax.management.openmbean.KeyAlreadyExistsException) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 14 with TabularType

use of javax.management.openmbean.TabularType in project karaf by apache.

the class HttpMBeanImpl method getServlets.

public TabularData getServlets() throws MBeanException {
    try {
        CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[] { "Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL" }, new String[] { "ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet" }, new OpenType[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
        TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[] { "Bundle-ID", "Servlet Name", "State" });
        TabularData table = new TabularDataSupport(tableType);
        List<ServletInfo> servletInfos = servletService.getServlets();
        for (ServletInfo info : servletInfos) {
            CompositeData data = new CompositeDataSupport(servletType, new String[] { "Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL" }, new Object[] { info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls()) });
            table.put(data);
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : ServletInfo(org.apache.karaf.http.core.ServletInfo) TabularDataSupport(javax.management.openmbean.TabularDataSupport) 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 15 with TabularType

use of javax.management.openmbean.TabularType in project karaf by apache.

the class JMXSecurityTest method testOSGiConfigAdminMBean.

private void testOSGiConfigAdminMBean(MBeanServerConnection connection, ObjectName mbean, String pidPrefix, boolean shouldSucceed, boolean isAdmin) throws Exception {
    String infix = "." + System.currentTimeMillis();
    String suffix = infix + "_" + counter.incrementAndGet();
    String pid = pidPrefix + suffix;
    CompositeType ct = new CompositeType("PROPERTY", "X", new String[] { "Key", "Value", "Type" }, new String[] { "X", "X", "X" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
    TabularType tt = new TabularType("PROPERTIES", "X", ct, new String[] { "Key" });
    TabularDataSupport tds = new TabularDataSupport(tt);
    Map<String, Object> data = new HashMap<>();
    data.put("Key", "foo");
    data.put("Value", "bar");
    data.put("Type", "String");
    CompositeDataSupport cds = new CompositeDataSupport(ct, data);
    tds.put(cds);
    assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid, tds }, new String[] { String.class.getName(), TabularData.class.getName() });
    TabularData td = (TabularData) connection.invoke(mbean, "getProperties", new Object[] { pid }, new String[] { String.class.getName() });
    if (shouldSucceed) {
        assertEquals("bar", td.get(new Object[] { "foo" }).get("Value"));
    }
    String[][] configs = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pid + ")" }, new String[] { String.class.getName() });
    if (shouldSucceed) {
        assertEquals(1, configs.length);
        assertEquals(pid, configs[0][0]);
    }
    assertJmxInvoke(shouldSucceed, connection, mbean, "delete", new Object[] { pid }, new String[] { String.class.getName() });
    TabularDataSupport tds2 = new TabularDataSupport(tt);
    Map<String, Object> data2 = new HashMap<>();
    data2.put("Key", "a.b.c");
    data2.put("Value", "d.e.f");
    data2.put("Type", "String");
    CompositeDataSupport cds2 = new CompositeDataSupport(ct, data2);
    tds2.put(cds2);
    String suffix2 = infix + "_" + counter.incrementAndGet();
    String pid2 = pidPrefix + suffix2;
    String location2 = "mylocation" + System.currentTimeMillis();
    assertJmxInvoke(shouldSucceed, connection, mbean, "updateForLocation", new Object[] { pid2, location2, tds2 }, new String[] { String.class.getName(), String.class.getName(), TabularData.class.getName() });
    TabularData td2 = (TabularData) connection.invoke(mbean, "getPropertiesForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
    if (shouldSucceed) {
        assertEquals("d.e.f", td2.get(new Object[] { "a.b.c" }).get("Value"));
    }
    assertJmxInvoke(shouldSucceed, connection, mbean, "deleteForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
    if (isAdmin) {
        String suffix3 = infix + "_" + counter.incrementAndGet();
        String pid3 = pidPrefix + suffix3;
        TabularDataSupport tds3 = new TabularDataSupport(tt);
        assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid3, tds3 }, new String[] { String.class.getName(), TabularData.class.getName() });
        String[][] configs2 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
        assertEquals(1, configs2.length);
        assertEquals(pid3, configs2[0][0]);
        String location3 = "my.other.location." + System.currentTimeMillis();
        assertJmxInvoke(shouldSucceed, connection, mbean, "setBundleLocation", new Object[] { pid3, location3 }, new String[] { String.class.getName(), String.class.getName() });
        String[][] configs3 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
        assertEquals(1, configs3.length);
        assertEquals(pid3, configs3[0][0]);
        connection.invoke(mbean, "deleteConfigurations", new Object[] { "(service.pid=" + pid3 + ")" }, new String[] { String.class.getName() });
        assertEquals(0, ((String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() })).length);
    }
}
Also used : HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Aggregations

TabularType (javax.management.openmbean.TabularType)41 TabularDataSupport (javax.management.openmbean.TabularDataSupport)36 CompositeType (javax.management.openmbean.CompositeType)25 OpenDataException (javax.management.openmbean.OpenDataException)22 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)19 TabularData (javax.management.openmbean.TabularData)18 CompositeData (javax.management.openmbean.CompositeData)13 Map (java.util.Map)8 OpenType (javax.management.openmbean.OpenType)8 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 MBeanException (javax.management.MBeanException)5 ObjectName (javax.management.ObjectName)4 Bundle (org.osgi.framework.Bundle)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 MBeanInfo (javax.management.MBeanInfo)3 Field (java.lang.reflect.Field)2