Search in sources :

Example 26 with ObjectInstance

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

the class MBeanSecurityJUnitTest method testQueryBean.

/**
   * looks like everyone can query for beans, but the AccessControlMXBean is filtered from the
   * result
   */
@Test
@ConnectionConfiguration(user = "stranger", password = "1234567")
public void testQueryBean() throws MalformedObjectNameException, IOException {
    MBeanServerConnection con = connectionRule.getMBeanServerConnection();
    Set<ObjectInstance> objects = con.queryMBeans(ObjectName.getInstance(ResourceConstants.OBJECT_NAME_ACCESSCONTROL), null);
    // no AccessControlMBean in the query result
    assertThat(objects.size()).isEqualTo(0);
    objects = con.queryMBeans(ObjectName.getInstance("GemFire:service=CacheServer,*"), null);
    assertThat(objects.size()).isEqualTo(1);
}
Also used : ObjectInstance(javax.management.ObjectInstance) MBeanServerConnection(javax.management.MBeanServerConnection) ConnectionConfiguration(org.apache.geode.test.dunit.rules.ConnectionConfiguration) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 27 with ObjectInstance

use of javax.management.ObjectInstance in project lucene-solr by apache.

the class TestJmxIntegration method testJmxUpdate.

@Test
public void testJmxUpdate() throws Exception {
    SolrInfoBean bean = null;
    // wait until searcher is registered
    for (int i = 0; i < 100; i++) {
        bean = h.getCore().getInfoRegistry().get("searcher");
        if (bean != null)
            break;
        Thread.sleep(250);
    }
    if (bean == null)
        throw new RuntimeException("searcher was never registered");
    ObjectName searcher = nameFactory.createName("gauge", registryName, "SEARCHER.searcher.*");
    log.info("Mbeans in server: " + mbeanServer.queryNames(null, null));
    Set<ObjectInstance> objects = mbeanServer.queryMBeans(searcher, null);
    assertFalse("No mbean found for SolrIndexSearcher", mbeanServer.queryMBeans(searcher, null).isEmpty());
    ObjectName name = nameFactory.createName("gauge", registryName, "SEARCHER.searcher.numDocs");
    int oldNumDocs = (Integer) mbeanServer.getAttribute(name, "Value");
    assertU(adoc("id", "1"));
    assertU("commit", commit());
    int numDocs = (Integer) mbeanServer.getAttribute(name, "Value");
    assertTrue("New numDocs is same as old numDocs as reported by JMX", numDocs > oldNumDocs);
}
Also used : ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 28 with ObjectInstance

use of javax.management.ObjectInstance in project lucene-solr by apache.

the class SolrJmxReporterTest method testReportMetrics.

@Test
public void testReportMetrics() throws Exception {
    Random random = random();
    Map<String, Counter> registered = new HashMap<>();
    String scope = SolrMetricTestUtils.getRandomScope(random, true);
    SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random, true);
    int iterations = TestUtil.nextInt(random, 0, MAX_ITERATIONS);
    for (int i = 0; i < iterations; ++i) {
        Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetricsWithReplacements(random, registered);
        SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
        coreMetricManager.registerMetricProducer(scope, producer);
        registered.putAll(metrics);
        //waitForListener();
        Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
        assertEquals(registered.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && rootName.equals(o.getObjectName().getDomain())).count());
    }
}
Also used : Counter(com.codahale.metrics.Counter) Random(java.util.Random) SolrInfoBean(org.apache.solr.core.SolrInfoBean) HashMap(java.util.HashMap) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) Test(org.junit.Test)

Example 29 with ObjectInstance

use of javax.management.ObjectInstance in project wildfly by wildfly.

the class LogStoreProbeHandler method addParticipants.

private void addParticipants(final Resource parent, Set<ObjectInstance> participants, MBeanServer mbs) throws IntrospectionException, InstanceNotFoundException, IOException, ReflectionException {
    int i = 1;
    for (ObjectInstance participant : participants) {
        final Resource resource = new LogStoreResource.LogStoreRuntimeResource(participant.getObjectName());
        final ModelNode model = resource.getModel();
        Map<String, String> pAttributes = getMBeanValues(mbs, participant.getObjectName(), LogStoreConstants.PARTICIPANT_JMX_NAMES);
        String pAddress = pAttributes.get(JNDI_PROPNAME);
        if (pAddress == null || pAddress.length() == 0) {
            pAttributes.put(JNDI_PROPNAME, String.valueOf(i++));
            pAddress = pAttributes.get(JNDI_PROPNAME);
        }
        addAttributes(model, LogStoreConstants.MODEL_TO_JMX_PARTICIPANT_NAMES, pAttributes);
        // model.get(LogStoreConstants.JMX_ON_ATTRIBUTE).set(participant.getObjectName().getCanonicalName());
        final PathElement element = PathElement.pathElement(LogStoreConstants.PARTICIPANTS, pAddress);
        parent.registerChild(element, resource);
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) ObjectInstance(javax.management.ObjectInstance) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 30 with ObjectInstance

use of javax.management.ObjectInstance in project wildfly by wildfly.

the class LogStoreProbeHandler method probeTransactions.

private Resource probeTransactions(MBeanServer mbs, boolean exposeAllLogs) throws OperationFailedException {
    try {
        ObjectName on = new ObjectName(osMBeanName);
        mbs.setAttribute(on, new javax.management.Attribute("ExposeAllRecordsAsMBeans", Boolean.valueOf(exposeAllLogs)));
        mbs.invoke(on, "probe", null, null);
        Set<ObjectInstance> transactions = mbs.queryMBeans(new ObjectName(osMBeanName + ",*"), null);
        final Resource resource = Resource.Factory.create();
        addTransactions(resource, transactions, mbs);
        return resource;
    } catch (JMException e) {
        throw new OperationFailedException("Transaction discovery error: ", e);
    } catch (IOException e) {
        throw new OperationFailedException("Transaction discovery error: ", e);
    }
}
Also used : ObjectInstance(javax.management.ObjectInstance) Resource(org.jboss.as.controller.registry.Resource) JMException(javax.management.JMException) OperationFailedException(org.jboss.as.controller.OperationFailedException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Aggregations

ObjectInstance (javax.management.ObjectInstance)75 ObjectName (javax.management.ObjectName)36 Test (org.junit.Test)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 MBeanServer (javax.management.MBeanServer)12 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)10 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)9 Result (com.googlecode.jmxtrans.model.Result)9 HashSet (java.util.HashSet)7 Attribute (javax.management.Attribute)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 HashMap (java.util.HashMap)4 AttributeList (javax.management.AttributeList)4 MBeanException (javax.management.MBeanException)4 MBeanServerConnection (javax.management.MBeanServerConnection)4 ReflectionException (javax.management.ReflectionException)4