Search in sources :

Example 86 with JMException

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

the class JmxSystemViewExporterSpi method register.

/**
 * Registers JMX bean for specific system view.
 *
 * @param sysView System view.
 */
protected void register(SystemView<?> sysView) {
    if (log.isDebugEnabled())
        log.debug("Found new system view [name=" + sysView.name() + ']');
    try {
        SystemViewMBean<?> mlBean = new SystemViewMBean<>(sysView);
        ObjectName mbean = U.registerMBean(ignite().configuration().getMBeanServer(), igniteInstanceName, VIEWS, sysView.name(), mlBean, SystemViewMBean.class);
        mBeans.add(mbean);
        if (log.isDebugEnabled())
            log.debug("MetricRegistry MBean created [mbean=" + mbean + ']');
    } catch (JMException e) {
        log.error("MBean for system view '" + sysView.name() + "' can't be created.", e);
    }
}
Also used : JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 87 with JMException

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

the class GridTcpRouterImpl method registerMBean.

/**
 * Try to register MBean.
 */
private void registerMBean() {
    if (U.IGNITE_MBEANS_DISABLED)
        return;
    try {
        ObjectName objName = U.registerMBean(ManagementFactory.getPlatformMBeanServer(), "Router", "TCP Router " + id, getClass().getSimpleName(), this, GridTcpRouterMBean.class);
        if (log.isDebugEnabled())
            log.debug("Registered MBean: " + objName);
        mbeanName = objName;
    } catch (JMException e) {
        U.error(log, "Failed to register MBean.", e);
    }
}
Also used : JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 88 with JMException

use of javax.management.JMException in project zookeeper by apache.

the class QuorumPeerMain method runFromConfig.

public void runFromConfig(QuorumPeerConfig config) throws IOException, AdminServerException {
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }
    LOG.info("Starting quorum peer, myid=" + config.getServerId());
    final MetricsProvider metricsProvider;
    try {
        metricsProvider = MetricsProviderBootstrap.startMetricsProvider(config.getMetricsProviderClassName(), config.getMetricsProviderConfiguration());
    } catch (MetricsProviderLifeCycleException error) {
        throw new IOException("Cannot boot MetricsProvider " + config.getMetricsProviderClassName(), error);
    }
    try {
        ServerMetrics.metricsProviderInitialized(metricsProvider);
        ProviderRegistry.initialize();
        ServerCnxnFactory cnxnFactory = null;
        ServerCnxnFactory secureCnxnFactory = null;
        if (config.getClientPortAddress() != null) {
            cnxnFactory = ServerCnxnFactory.createFactory();
            cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns(), config.getClientPortListenBacklog(), false);
        }
        if (config.getSecureClientPortAddress() != null) {
            secureCnxnFactory = ServerCnxnFactory.createFactory();
            secureCnxnFactory.configure(config.getSecureClientPortAddress(), config.getMaxClientCnxns(), config.getClientPortListenBacklog(), true);
        }
        quorumPeer = getQuorumPeer();
        quorumPeer.setTxnFactory(new FileTxnSnapLog(config.getDataLogDir(), config.getDataDir()));
        quorumPeer.enableLocalSessions(config.areLocalSessionsEnabled());
        quorumPeer.enableLocalSessionsUpgrading(config.isLocalSessionsUpgradingEnabled());
        // quorumPeer.setQuorumPeers(config.getAllMembers());
        quorumPeer.setElectionType(config.getElectionAlg());
        quorumPeer.setMyid(config.getServerId());
        quorumPeer.setTickTime(config.getTickTime());
        quorumPeer.setMinSessionTimeout(config.getMinSessionTimeout());
        quorumPeer.setMaxSessionTimeout(config.getMaxSessionTimeout());
        quorumPeer.setInitLimit(config.getInitLimit());
        quorumPeer.setSyncLimit(config.getSyncLimit());
        quorumPeer.setConnectToLearnerMasterLimit(config.getConnectToLearnerMasterLimit());
        quorumPeer.setObserverMasterPort(config.getObserverMasterPort());
        quorumPeer.setConfigFileName(config.getConfigFilename());
        quorumPeer.setClientPortListenBacklog(config.getClientPortListenBacklog());
        quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
        quorumPeer.setQuorumVerifier(config.getQuorumVerifier(), false);
        if (config.getLastSeenQuorumVerifier() != null) {
            quorumPeer.setLastSeenQuorumVerifier(config.getLastSeenQuorumVerifier(), false);
        }
        quorumPeer.initConfigInZKDatabase();
        quorumPeer.setCnxnFactory(cnxnFactory);
        quorumPeer.setSecureCnxnFactory(secureCnxnFactory);
        quorumPeer.setSslQuorum(config.isSslQuorum());
        quorumPeer.setUsePortUnification(config.shouldUsePortUnification());
        quorumPeer.setLearnerType(config.getPeerType());
        quorumPeer.setSyncEnabled(config.getSyncEnabled());
        quorumPeer.setQuorumListenOnAllIPs(config.getQuorumListenOnAllIPs());
        if (config.sslQuorumReloadCertFiles) {
            quorumPeer.getX509Util().enableCertFileReloading();
        }
        quorumPeer.setMultiAddressEnabled(config.isMultiAddressEnabled());
        quorumPeer.setMultiAddressReachabilityCheckEnabled(config.isMultiAddressReachabilityCheckEnabled());
        quorumPeer.setMultiAddressReachabilityCheckTimeoutMs(config.getMultiAddressReachabilityCheckTimeoutMs());
        // sets quorum sasl authentication configurations
        quorumPeer.setQuorumSaslEnabled(config.quorumEnableSasl);
        if (quorumPeer.isQuorumSaslAuthEnabled()) {
            quorumPeer.setQuorumServerSaslRequired(config.quorumServerRequireSasl);
            quorumPeer.setQuorumLearnerSaslRequired(config.quorumLearnerRequireSasl);
            quorumPeer.setQuorumServicePrincipal(config.quorumServicePrincipal);
            quorumPeer.setQuorumServerLoginContext(config.quorumServerLoginContext);
            quorumPeer.setQuorumLearnerLoginContext(config.quorumLearnerLoginContext);
        }
        quorumPeer.setQuorumCnxnThreadsSize(config.quorumCnxnThreadsSize);
        quorumPeer.initialize();
        if (config.jvmPauseMonitorToRun) {
            quorumPeer.setJvmPauseMonitor(new JvmPauseMonitor(config));
        }
        quorumPeer.start();
        ZKAuditProvider.addZKStartStopAuditLog();
        quorumPeer.join();
    } catch (InterruptedException e) {
        // warn, but generally this is ok
        LOG.warn("Quorum Peer interrupted", e);
    } finally {
        try {
            metricsProvider.stop();
        } catch (Throwable error) {
            LOG.warn("Error while stopping metrics", error);
        }
    }
}
Also used : JMException(javax.management.JMException) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) IOException(java.io.IOException) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) MetricsProvider(org.apache.zookeeper.metrics.MetricsProvider) MetricsProviderLifeCycleException(org.apache.zookeeper.metrics.MetricsProviderLifeCycleException) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) JvmPauseMonitor(org.apache.zookeeper.server.util.JvmPauseMonitor)

Example 89 with JMException

use of javax.management.JMException in project zookeeper by apache.

the class MBeanRegistry method register.

/**
 * Registers a new MBean with the platform MBean server.
 * @param bean the bean being registered
 * @param parent if not null, the new bean will be registered as a child
 * node of this parent.
 */
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent) throws JMException {
    assert bean != null;
    String path = null;
    if (parent != null) {
        path = mapBean2Path.get(parent);
        assert path != null;
    }
    path = makeFullPath(path, parent);
    if (bean.isHidden()) {
        return;
    }
    ObjectName oname = makeObjectName(path, bean);
    try {
        synchronized (LOCK) {
            mBeanServer.registerMBean(bean, oname);
            mapBean2Path.put(bean, path);
        }
    } catch (JMException e) {
        LOG.warn("Failed to register MBean {}", bean.getName());
        throw e;
    }
}
Also used : JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 90 with JMException

use of javax.management.JMException in project zookeeper by apache.

the class ManagedUtil method registerLog4jMBeans.

/**
 * Register the log4j JMX mbeans. Set system property
 * "zookeeper.jmx.log4j.disable" to true to disable registration.
 * @see <a href="http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html">Log4J 1.2 API docs</a>
 * @throws JMException if registration fails
 */
@SuppressWarnings("rawtypes")
public static void registerLog4jMBeans() throws JMException {
    if (isLog4jJmxEnabled()) {
        LOG.debug("registerLog4jMBeans()");
        MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer();
        try {
            // Create and Register the top level Log4J MBean
            // org.apache.log4j.jmx.HierarchyDynamicMBean hdm = new org.apache.log4j.jmx.HierarchyDynamicMBean();
            Object hdm = Class.forName("org.apache.log4j.jmx.HierarchyDynamicMBean").getConstructor().newInstance();
            String mbean = System.getProperty("zookeeper.jmx.log4j.mbean", "log4j:hierarchy=default");
            ObjectName mbo = new ObjectName(mbean);
            mbs.registerMBean(hdm, mbo);
            // Add the root logger to the Hierarchy MBean
            // org.apache.log4j.Logger rootLogger =
            // org.apache.log4j.Logger.getRootLogger();
            Object rootLogger = Class.forName("org.apache.log4j.Logger").getMethod("getRootLogger", (Class<?>[]) null).invoke(null, (Object[]) null);
            // hdm.addLoggerMBean(rootLogger.getName());
            Object rootLoggerName = rootLogger.getClass().getMethod("getName", (Class<?>[]) null).invoke(rootLogger, (Object[]) null);
            hdm.getClass().getMethod("addLoggerMBean", String.class).invoke(hdm, rootLoggerName);
            // Get each logger from the Log4J Repository and add it to the
            // Hierarchy MBean created above.
            // org.apache.log4j.spi.LoggerRepository r =
            // org.apache.log4j.LogManager.getLoggerRepository();
            Object r = Class.forName("org.apache.log4j.LogManager").getMethod("getLoggerRepository", (Class<?>[]) null).invoke(null, (Object[]) null);
            // Enumeration enumer = r.getCurrentLoggers();
            Enumeration enumer = (Enumeration) r.getClass().getMethod("getCurrentLoggers", (Class<?>[]) null).invoke(r, (Object[]) null);
            while (enumer.hasMoreElements()) {
                Object logger = enumer.nextElement();
                // hdm.addLoggerMBean(logger.getName());
                Object loggerName = logger.getClass().getMethod("getName", (Class<?>[]) null).invoke(logger, (Object[]) null);
                hdm.getClass().getMethod("addLoggerMBean", String.class).invoke(hdm, loggerName);
            }
        } catch (Exception e) {
            LOG.error("Problems while registering log4j 1.2 jmx beans!", e);
            throw new JMException(e.toString());
        }
    }
}
Also used : Enumeration(java.util.Enumeration) JMException(javax.management.JMException) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

JMException (javax.management.JMException)116 ObjectName (javax.management.ObjectName)66 MBeanServer (javax.management.MBeanServer)33 IOException (java.io.IOException)22 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MBeanInfo (javax.management.MBeanInfo)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 StandardMBean (javax.management.StandardMBean)7 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)6 Date (java.util.Date)5 Attribute (javax.management.Attribute)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 Element (org.w3c.dom.Element)5 PostConstruct (javax.annotation.PostConstruct)4 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)4