Search in sources :

Example 71 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project zalenium by zalando.

the class CloudTestingRemoteProxyTest method defaultValuesAreAlwaysNull.

@Test
public void defaultValuesAreAlwaysNull() {
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
        new JMXHelper().unregister(objectName);
    } catch (MalformedObjectNameException | InstanceNotFoundException e) {
    // Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
    }
    GridRegistry registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30003, CloudTestingRemoteProxy.class.getCanonicalName());
    CloudTestingRemoteProxy proxy = CloudTestingRemoteProxy.getNewInstance(request, registry);
    Assert.assertNull(proxy.getAccessKeyProperty());
    Assert.assertNull(proxy.getAccessKeyValue());
    Assert.assertNotNull(proxy.getCloudTestingServiceUrl());
    Assert.assertNull(proxy.getUserNameProperty());
    Assert.assertNull(proxy.getUserNameValue());
    Assert.assertNotNull(proxy.getRemoteHost());
    Assert.assertNull(proxy.getVideoFileExtension());
    Assert.assertNull(proxy.getProxyName());
    Assert.assertNull(proxy.getProxyClassName());
    Assert.assertNull(proxy.getTestInformation("seleniumSessionId"));
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Hub(org.openqa.grid.web.Hub) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) GridRegistry(org.openqa.grid.internal.GridRegistry) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 72 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project infrautils by opendaylight.

the class MBeanUtils method unregisterServerMBean.

public static void unregisterServerMBean(Object mxBeanImplementor, String objNameStr) throws MalformedObjectNameException, InstanceNotFoundException, MBeanRegistrationException {
    LOG.debug("unregister MXBean for {}", objNameStr);
    MBeanServer mplatformMbeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        mplatformMbeanServer.unregisterMBean(new ObjectName(objNameStr));
    } catch (InstanceNotFoundException | MalformedObjectNameException | MBeanRegistrationException e) {
        LOG.error("Error while unregistering MBean {}", objNameStr, e);
        throw e;
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 73 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project infrautils by opendaylight.

the class AbstractMXBean method unregisterMBean.

/**
 * Unregisters this bean with the platform MBean server.
 *
 * @return true is successfully unregistered, false otherwise.
 */
protected boolean unregisterMBean() {
    @Var boolean unregister = false;
    try {
        ObjectName mbeanobjectname = this.getMBeanObjectName();
        unregisterMBean(mbeanobjectname);
        unregister = true;
    } catch (InstanceNotFoundException | MBeanRegistrationException | MalformedObjectNameException e) {
        LOG.debug("Failed when unregistering MBean {}", e);
    }
    return unregister;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Var(com.google.errorprone.annotations.Var) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 74 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project LogHub by fbacchella.

the class TestIntegrated method runStart.

@Test(timeout = 5000)
public void runStart() throws ConfigException, IOException, InterruptedException, IntrospectionException, InstanceNotFoundException, MalformedObjectNameException, ReflectionException {
    loghub.Stats.reset();
    String conffile = Configuration.class.getClassLoader().getResource("test.conf").getFile();
    Start.main(new String[] { "--canexit", "-c", conffile });
    Thread.sleep(500);
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    StatsMBean stats = JMX.newMBeanProxy(mbs, StatsMBean.Implementation.NAME, StatsMBean.class);
    JmxTimerMBean allevents_timer = JMX.newMBeanProxy(mbs, new ObjectName("metrics:name=Allevents.timer"), JmxTimerMBean.class);
    JmxCounterMBean allevents_inflight = JMX.newMBeanProxy(mbs, new ObjectName("metrics:name=Allevents.inflight"), JmxCounterMBean.class);
    Socket sender = tctxt.ctx.newSocket(Method.CONNECT, Type.PUB, "inproc://listener");
    Socket receiver = tctxt.ctx.newSocket(Method.CONNECT, Type.PULL, "inproc://sender");
    AtomicLong send = new AtomicLong();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                for (int i = 0; i < 100 && tctxt.ctx.isRunning(); i++) {
                    sender.send("message " + i);
                    send.incrementAndGet();
                    Thread.sleep(1);
                }
            } catch (InterruptedException e) {
            }
            logger.debug("All events sent");
        }
    };
    t.start();
    Pattern messagePattern = Pattern.compile("\\{\"a\":1,\"b\":\"google-public-dns-a\",\"message\":\"message \\d+\"\\}");
    while (send.get() < 99 || allevents_inflight.getCount() != 0) {
        logger.debug("send: {}, in flight: {}", send.get(), allevents_inflight.getCount());
        while (receiver.getEvents() > 0) {
            logger.debug("in flight: {}", allevents_inflight.getCount());
            String content = receiver.recvStr();
            Assert.assertTrue(messagePattern.matcher(content).find());
            Thread.sleep(1);
        }
        ;
        Thread.sleep(50);
    }
    Thread.sleep(10);
    Set<ObjectName> metrics = mbs.queryNames(new ObjectName("metrics:*"), null);
    long blocked = 0;
    dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=EventWaiting.") && i.toString().endsWith(".failed"), i -> (long) i.getValue(), JmxGaugeMBean.class);
    dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".failed"), i -> i.getCount(), JmxMeterMBean.class);
    dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".droped"), i -> i.getCount(), JmxMeterMBean.class);
    blocked += dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".blocked.in"), i -> i.getCount(), JmxMeterMBean.class);
    blocked += dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".blocked.out"), i -> i.getCount(), JmxMeterMBean.class);
    dumpstatus(mbs, metrics, i -> i.toString().startsWith("metrics:name=Pipeline.") && i.toString().endsWith(".inflight"), i -> i.getCount(), JmxMeterMBean.class);
    logger.debug("dropped: " + stats.getDropped());
    logger.debug("failed: " + stats.getFailed());
    logger.debug("received: " + stats.getReceived());
    logger.debug("sent: " + stats.getSent());
    logger.debug(Arrays.toString(stats.getErrors()));
    logger.debug(Arrays.toString(stats.getExceptions()));
    long received = stats.getReceived();
    Assert.assertTrue(received > 95);
    Assert.assertEquals(0L, allevents_inflight.getCount());
    Assert.assertEquals(received, allevents_timer.getCount());
    Assert.assertEquals(received, blocked + stats.getSent());
}
Also used : Arrays(java.util.Arrays) IntrospectionException(javax.management.IntrospectionException) BeforeClass(org.junit.BeforeClass) Level(org.apache.logging.log4j.Level) Function(java.util.function.Function) ConfigException(loghub.configuration.ConfigException) MBeanServer(javax.management.MBeanServer) JMX(javax.management.JMX) ManagementFactory(java.lang.management.ManagementFactory) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) Socket(org.zeromq.ZMQ.Socket) JmxCounterMBean(com.codahale.metrics.jmx.JmxReporter.JmxCounterMBean) Type(loghub.zmq.ZMQHelper.Type) Set(java.util.Set) JmxTimerMBean(com.codahale.metrics.jmx.JmxReporter.JmxTimerMBean) IOException(java.io.IOException) Test(org.junit.Test) ObjectName(javax.management.ObjectName) StatsMBean(loghub.jmx.StatsMBean) Method(loghub.zmq.ZMQHelper.Method) MalformedObjectNameException(javax.management.MalformedObjectNameException) AtomicLong(java.util.concurrent.atomic.AtomicLong) JmxMeterMBean(com.codahale.metrics.jmx.JmxReporter.JmxMeterMBean) Logger(org.apache.logging.log4j.Logger) Rule(org.junit.Rule) Configuration(loghub.configuration.Configuration) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) JmxGaugeMBean(com.codahale.metrics.jmx.JmxReporter.JmxGaugeMBean) Pattern(java.util.regex.Pattern) StatsMBean(loghub.jmx.StatsMBean) ObjectName(javax.management.ObjectName) JmxTimerMBean(com.codahale.metrics.jmx.JmxReporter.JmxTimerMBean) AtomicLong(java.util.concurrent.atomic.AtomicLong) JmxMeterMBean(com.codahale.metrics.jmx.JmxReporter.JmxMeterMBean) Socket(org.zeromq.ZMQ.Socket) MBeanServer(javax.management.MBeanServer) JmxCounterMBean(com.codahale.metrics.jmx.JmxReporter.JmxCounterMBean) Test(org.junit.Test)

Example 75 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project LogHub by fbacchella.

the class Start method launch.

public void launch(Properties props) throws ConfigException, IOException {
    for (Source s : props.sources.values()) {
        if (!s.configure(props)) {
            logger.error("failed to start source {}", s.getName());
            throw new IllegalStateException();
        }
        ;
    }
    props.pipelines.stream().forEach(i -> i.configure(props));
    for (Sender s : props.senders) {
        if (s.configure(props)) {
            s.start();
        } else {
            logger.error("failed to configure output {}", s.getName());
            throw new IllegalStateException();
        }
        ;
    }
    for (int i = 0; i < props.numWorkers; i++) {
        Thread t = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
        t.setName("ProcessingThread" + i);
        t.setDaemon(false);
        t.start();
    }
    for (Receiver r : props.receivers) {
        if (r.configure(props)) {
            r.start();
        } else {
            logger.error("failed to configure input {}", r.getName());
            throw new IllegalStateException();
        }
    }
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new StatsMBean.Implementation(), StatsMBean.Implementation.NAME);
        JmxReporter reporter = Properties.metrics.getJmxReporter();
        reporter.start();
        mbs.queryNames(ObjectName.getInstance("metrics", "name", "Pipeline.*.timer"), null).stream().map(i -> i.getKeyProperty("name")).map(i -> i.replaceAll("^Pipeline\\.(.*)\\.timer$", "$1")).forEach(i -> {
            try {
                mbs.registerMBean(new PipelineStat.Implementation(i), null);
            } catch (NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
            }
        });
        int port = props.jmxport;
        if (port > 0) {
            Helper.start(props.jmxproto, props.jmxlisten, port);
        }
    } catch (IOException | NotBoundException | NotCompliantMBeanException | MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
        throw new RuntimeException("jmx configuration failed: " + e.getMessage(), e);
    }
    if (props.httpPort >= 0) {
        AbstractHttpServer server = new DashboardHttpServer();
        server.setPort(props.httpPort);
        server.configure(props);
    }
}
Also used : PipelineStat(loghub.jmx.PipelineStat) ParameterException(com.beust.jcommander.ParameterException) Parameter(com.beust.jcommander.Parameter) AbstractHttpServer(loghub.netty.http.AbstractHttpServer) ConfigException(loghub.configuration.ConfigException) JmxReporter(com.codahale.metrics.jmx.JmxReporter) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer) MBeanRegistrationException(javax.management.MBeanRegistrationException) ManagementFactory(java.lang.management.ManagementFactory) NotBoundException(java.rmi.NotBoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) FieldsProcessor(loghub.processors.FieldsProcessor) JCommander(com.beust.jcommander.JCommander) IOException(java.io.IOException) TestEventProcessing(loghub.configuration.TestEventProcessing) ObjectName(javax.management.ObjectName) StatsMBean(loghub.jmx.StatsMBean) InputStreamReader(java.io.InputStreamReader) MalformedObjectNameException(javax.management.MalformedObjectNameException) Logger(org.apache.logging.log4j.Logger) Helper(loghub.jmx.Helper) Configuration(loghub.configuration.Configuration) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LogManager(org.apache.logging.log4j.LogManager) Properties(loghub.configuration.Properties) NotBoundException(java.rmi.NotBoundException) AbstractHttpServer(loghub.netty.http.AbstractHttpServer) MBeanServer(javax.management.MBeanServer) MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) IOException(java.io.IOException) JmxReporter(com.codahale.metrics.jmx.JmxReporter) StatsMBean(loghub.jmx.StatsMBean) PipelineStat(loghub.jmx.PipelineStat) MBeanRegistrationException(javax.management.MBeanRegistrationException)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10