Search in sources :

Example 1 with MBeanFeatureInfo

use of javax.management.MBeanFeatureInfo in project geode by apache.

the class MBeanServerWrapper method getOperationContext.

// TODO: cache this
private ResourcePermission getOperationContext(ObjectName objectName, String featureName, boolean isOp) throws InstanceNotFoundException, ReflectionException {
    MBeanInfo beanInfo = null;
    try {
        beanInfo = mbs.getMBeanInfo(objectName);
    } catch (IntrospectionException e) {
        throw new GemFireSecurityException("error getting beanInfo of " + objectName, e);
    }
    // If there is no annotation defined either in the class level or method level, we should
    // consider this operation/attribute freely accessible
    ResourcePermission result = null;
    // find the context in the beanInfo if defined in the class level
    result = getOperationContext(beanInfo.getDescriptor(), result);
    MBeanFeatureInfo[] featureInfos = null;
    if (isOp) {
        featureInfos = beanInfo.getOperations();
    } else {
        featureInfos = beanInfo.getAttributes();
    }
    // still look into the attributes/operations to see if it's defined in the method level
    for (MBeanFeatureInfo info : featureInfos) {
        if (info.getName().equals(featureName)) {
            // found the featureInfo of this method on the bean
            result = getOperationContext(info.getDescriptor(), result);
            break;
        }
    }
    return result;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) MBeanInfo(javax.management.MBeanInfo) IntrospectionException(javax.management.IntrospectionException) ResourcePermission(org.apache.geode.security.ResourcePermission) MBeanFeatureInfo(javax.management.MBeanFeatureInfo)

Example 2 with MBeanFeatureInfo

use of javax.management.MBeanFeatureInfo in project jdk8u_jdk by JetBrains.

the class MBeanInfoEqualsNPETest method main.

public static void main(String[] args) throws Exception {
    System.out.println("---MBeanInfoEqualsNPETest-main ...");
    // ----
    System.out.println("\n---Testing on MBeanAttributeInfo...");
    MBeanAttributeInfo mbeanAttributeInfo0 = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), "description", true, true, false);
    MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
    test(mbeanAttributeInfo0, mbeanAttributeInfo, "class name");
    mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
    test(mbeanAttributeInfo0, mbeanAttributeInfo, "type");
    mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
    test(mbeanAttributeInfo0, mbeanAttributeInfo, "description");
    // ----
    System.out.println("\n---Testing on MBeanConstructorInfo...");
    MBeanConstructorInfo mbeanConstructorInfo0 = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, new DescriptorSupport());
    MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "name");
    mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "description");
    mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "MBeanParameterInfo");
    mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "descriptor");
    // ----
    System.out.println("\n---Testing on MBeanOperationInfo...");
    MBeanOperationInfo mbeanOperationInfo0 = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "name");
    mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "description");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "MBeanParameterInfo");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "type");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, null);
    test(mbeanOperationInfo0, mbeanOperationInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanParameterInfo...");
    MBeanParameterInfo mbeanParameterInfo0 = new MBeanParameterInfo("name", "type", "description", new DescriptorSupport());
    MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "name");
    mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "type");
    mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "description");
    mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
    test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanFeatureInfo ...");
    MBeanFeatureInfo mbeanFeatureInfo0 = new MBeanFeatureInfo("name", "description", new DescriptorSupport());
    MBeanFeatureInfo mbeanFeatureInfo = new MBeanFeatureInfo(null, "description", new DescriptorSupport());
    test(mbeanFeatureInfo0, mbeanFeatureInfo, "name");
    mbeanFeatureInfo = new MBeanFeatureInfo("name", null, new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "description");
    mbeanFeatureInfo = new MBeanFeatureInfo("name", "description", null);
    test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanInfo...");
    String className = "toto";
    String description = "titi";
    MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
    MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
    MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
    MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
    MBeanInfo minfo0 = new MBeanInfo("toto", description, attrInfos, constrInfos, operaInfos, notifInfos);
    MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
    test(minfo0, minfo, "class name");
    minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
    test(minfo0, minfo, "description");
    minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
    test(minfo0, minfo, "attrInfos");
    minfo = new MBeanInfo(className, description, attrInfos, null, operaInfos, notifInfos);
    test(minfo0, minfo, "constrInfos");
    minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
    test(minfo0, minfo, "operaInfos");
    minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
    test(minfo0, minfo, "notifInfos");
    if (failed > 0) {
        throw new RuntimeException("Test failed: " + failed);
    } else {
        System.out.println("---Test: PASSED");
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) MBeanFeatureInfo(javax.management.MBeanFeatureInfo)

Example 3 with MBeanFeatureInfo

use of javax.management.MBeanFeatureInfo in project ignite by apache.

the class JmxExporterSpiTest method testSysJmxMetrics.

/**
 */
@Test
public void testSysJmxMetrics() throws Exception {
    DynamicMBean sysMBean = metricRegistry(ignite.name(), null, SYS_METRICS);
    Set<String> res = stream(sysMBean.getMBeanInfo().getAttributes()).map(MBeanFeatureInfo::getName).collect(toSet());
    assertTrue(res.contains(CPU_LOAD));
    assertTrue(res.contains(GC_CPU_LOAD));
    assertTrue(res.contains(metricName("memory", "heap", "init")));
    assertTrue(res.contains(metricName("memory", "heap", "used")));
    assertTrue(res.contains(metricName("memory", "nonheap", "committed")));
    assertTrue(res.contains(metricName("memory", "nonheap", "max")));
    Optional<MBeanAttributeInfo> cpuLoad = stream(sysMBean.getMBeanInfo().getAttributes()).filter(a -> a.getName().equals(CPU_LOAD)).findFirst();
    assertTrue(cpuLoad.isPresent());
    assertEquals(CPU_LOAD_DESCRIPTION, cpuLoad.get().getDescription());
    Optional<MBeanAttributeInfo> gcCpuLoad = stream(sysMBean.getMBeanInfo().getAttributes()).filter(a -> a.getName().equals(GC_CPU_LOAD)).findFirst();
    assertTrue(gcCpuLoad.isPresent());
    assertEquals(GC_CPU_LOAD_DESCRIPTION, gcCpuLoad.get().getDescription());
}
Also used : Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) TestObjectEnum(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum) Map(java.util.Map) FILTER_OPERATION(org.apache.ignite.internal.managers.systemview.SystemViewMBean.FILTER_OPERATION) IgniteUtils.toStringSafe(org.apache.ignite.internal.util.IgniteUtils.toStringSafe) CACHE_METRICS(org.apache.ignite.internal.processors.cache.CacheMetricsImpl.CACHE_METRICS) GC_CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD_DESCRIPTION) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) MBeanOperationInfo(javax.management.MBeanOperationInfo) Set(java.util.Set) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TEST_TRANSFORMER(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_TRANSFORMER) MBeanFeatureInfo(javax.management.MBeanFeatureInfo) QueryCursor(org.apache.ignite.cache.query.QueryCursor) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) DynamicMBean(javax.management.DynamicMBean) VIEWS(org.apache.ignite.internal.managers.systemview.SystemViewMBean.VIEWS) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD_DESCRIPTION) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) BINARY_METADATA_VIEW(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.BINARY_METADATA_VIEW) DISTRIBUTED_METASTORE_VIEW(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl.DISTRIBUTED_METASTORE_VIEW) IgniteClient(org.apache.ignite.client.IgniteClient) TEST_PREDICATE(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_PREDICATE) TestTransformer(org.apache.ignite.internal.metric.SystemViewSelfTest.TestTransformer) STREAM_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.STREAM_POOL_QUEUE_VIEW) TASKS_VIEW(org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW) Properties(java.util.Properties) CompositeData(javax.management.openmbean.CompositeData) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test) Field(java.lang.reflect.Field) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) SCAN_QRY_SYS_VIEW(org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW) CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CachePagesListViewWalker(org.apache.ignite.internal.managers.systemview.walker.CachePagesListViewWalker) CQ_SYS_VIEW(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) Connection(java.sql.Connection) ProtocolVersion(org.apache.ignite.internal.client.thin.ProtocolVersion) JmxMetricExporterSpi(org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) Transaction(org.apache.ignite.transactions.Transaction) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CACHE_GRP_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_PAGE_LIST_VIEW) IgniteEx(org.apache.ignite.internal.IgniteEx) METASTORE_VIEW(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalTime(java.time.LocalTime) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) DateFormat(java.text.DateFormat) Collectors.toSet(java.util.stream.Collectors.toSet) CyclicBarrier(java.util.concurrent.CyclicBarrier) SVCS_VIEW(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.SVCS_VIEW) CLI_CONN_VIEW(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_VIEW) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) IGNITE_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.IGNITE_METRICS) MetricRegistryMBean.searchHistogram(org.apache.ignite.spi.metric.jmx.MetricRegistryMBean.searchHistogram) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Optional(java.util.Optional) ACTIVE(org.apache.ignite.transactions.TransactionState.ACTIVE) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) SYS_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.SYS_METRICS) DummyService(org.apache.ignite.internal.processors.service.DummyService) Arrays.stream(java.util.Arrays.stream) GridCacheUtils.cacheGroupId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId) MBeanParameterInfo(javax.management.MBeanParameterInfo) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) CACHES_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) SYS_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.SYS_POOL_QUEUE_VIEW) TestRunnable(org.apache.ignite.internal.metric.SystemViewSelfTest.TestRunnable) GC_CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) TestPredicate(org.apache.ignite.internal.metric.SystemViewSelfTest.TestPredicate) F(org.apache.ignite.internal.util.typedef.F) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) JdbcConnectionContext(org.apache.ignite.internal.processors.odbc.jdbc.JdbcConnectionContext) CACHE_GRPS_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW) TestObjectAllTypes(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes) Consumer(java.util.function.Consumer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) Ignition(org.apache.ignite.Ignition) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) DynamicMBean(javax.management.DynamicMBean) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Test(org.junit.Test)

Aggregations

MBeanFeatureInfo (javax.management.MBeanFeatureInfo)3 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)2 MBeanInfo (javax.management.MBeanInfo)2 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 MBeanParameterInfo (javax.management.MBeanParameterInfo)2 Iterators (com.google.common.collect.Iterators)1 Field (java.lang.reflect.Field)1 Connection (java.sql.Connection)1 DateFormat (java.text.DateFormat)1 LocalTime (java.time.LocalTime)1 Arrays (java.util.Arrays)1 Arrays.stream (java.util.Arrays.stream)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1