Search in sources :

Example 1 with JmxManagerInfo

use of org.apache.geode.tools.pulse.internal.data.JmxManagerFinder.JmxManagerInfo in project geode by apache.

the class JMXDataUpdater method connect.

/**
   * Get the jmx connection
   */
public JMXConnector connect(String username, String password) {
    // Reference to repository
    Repository repository = Repository.get();
    try {
        String jmxSerURL = "";
        logger.info("{}:{}", resourceBundle.getString("LOG_MSG_USE_LOCATOR_VALUE"), repository.getJmxUseLocator());
        if (repository.getJmxUseLocator()) {
            JmxManagerInfo jmxManagerInfo = getManagerInfoFromLocator(repository);
            if (jmxManagerInfo.port == 0) {
                logger.info(resourceBundle.getString("LOG_MSG_LOCATOR_COULD_NOT_FIND_MANAGER"));
            } else {
                logger.info("{}: {}={} & {}={}, {}", resourceBundle.getString("LOG_MSG_LOCATOR_FOUND_MANAGER"), resourceBundle.getString("LOG_MSG_HOST"), jmxManagerInfo.host, resourceBundle.getString("LOG_MSG_PORT"), jmxManagerInfo.port, (jmxManagerInfo.ssl ? resourceBundle.getString("LOG_MSG_WITH_SSL") : resourceBundle.getString("LOG_MSG_WITHOUT_SSL")));
                jmxSerURL = formJMXServiceURLString(jmxManagerInfo.host, String.valueOf(jmxManagerInfo.port));
            }
        } else {
            logger.info("{}={} & {}={}", resourceBundle.getString("LOG_MSG_HOST"), this.serverName, resourceBundle.getString("LOG_MSG_PORT"), this.port);
            jmxSerURL = formJMXServiceURLString(this.serverName, this.port);
        }
        if (StringUtils.isNotBlank(jmxSerURL)) {
            JMXServiceURL url = new JMXServiceURL(jmxSerURL);
            String[] creds = { username, password };
            Map<String, Object> env = new HashMap<String, Object>();
            env.put(JMXConnector.CREDENTIALS, creds);
            if (repository.isUseSSLManager()) {
                // use ssl to connect
                env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
            }
            logger.info("Connecting to jmxURL : {}", jmxSerURL);
            this.conn = JMXConnectorFactory.connect(url, env);
            this.mbs = this.conn.getMBeanServerConnection();
            cluster.setConnectedFlag(true);
        }
    } catch (Exception e) {
        cluster.setConnectedFlag(false);
        cluster.setConnectionErrorMsg(e.getMessage());
        logger.fatal(e.getMessage(), e);
        if (this.conn != null) {
            try {
                this.conn.close();
            } catch (Exception e1) {
                logger.fatal(e1.getMessage(), e1);
            }
            this.conn = null;
        }
    }
    return this.conn;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) JmxManagerInfo(org.apache.geode.tools.pulse.internal.data.JmxManagerFinder.JmxManagerInfo) HashMap(java.util.HashMap) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException)

Example 2 with JmxManagerInfo

use of org.apache.geode.tools.pulse.internal.data.JmxManagerFinder.JmxManagerInfo in project geode by apache.

the class JMXDataUpdater method getManagerInfoFromLocator.

private JmxManagerInfo getManagerInfoFromLocator(Repository repository) {
    try {
        String locatorHost = repository.getHost();
        int locatorPort = Integer.parseInt(repository.getPort());
        logger.info("{}={} & {}={}", resourceBundle.getString("LOG_MSG_HOST"), locatorHost, resourceBundle.getString("LOG_MSG_PORT"), locatorPort);
        InetAddress inetAddr = InetAddress.getByName(locatorHost);
        if ((inetAddr instanceof Inet4Address) || (inetAddr instanceof Inet6Address)) {
            if (inetAddr instanceof Inet4Address) {
                logger.info("{}: {}", resourceBundle.getString("LOG_MSG_LOCATOR_IPV4_ADDRESS"), inetAddr);
            } else {
                logger.info("{}: {}", resourceBundle.getString("LOG_MSG_LOCATOR_IPV6_ADDRESS"), inetAddr);
            }
            JmxManagerInfo jmxManagerInfo = JmxManagerFinder.askLocatorForJmxManager(inetAddr, locatorPort, 15000, repository.isUseSSLLocator());
            if (jmxManagerInfo.port == 0) {
                logger.info(resourceBundle.getString("LOG_MSG_LOCATOR_COULD_NOT_FIND_MANAGER"));
            }
            return jmxManagerInfo;
        } else {
            // Locator has Invalid locator Address
            logger.info(resourceBundle.getString("LOG_MSG_LOCATOR_BAD_ADDRESS"));
            cluster.setConnectionErrorMsg(resourceBundle.getString("LOG_MSG_JMX_CONNECTION_BAD_ADDRESS"));
            // update message to display on UI
            cluster.setConnectionErrorMsg(resourceBundle.getString("LOG_MSG_JMX_CONNECTION_BAD_ADDRESS"));
            return null;
        }
    } catch (IOException e) {
        StringWriter swBuffer = new StringWriter();
        PrintWriter prtWriter = new PrintWriter(swBuffer);
        e.printStackTrace(prtWriter);
        logger.fatal("Exception Details : {}\n", swBuffer);
    }
    return null;
}
Also used : JmxManagerInfo(org.apache.geode.tools.pulse.internal.data.JmxManagerFinder.JmxManagerInfo) Inet4Address(java.net.Inet4Address) StringWriter(java.io.StringWriter) Inet6Address(java.net.Inet6Address) IOException(java.io.IOException) InetAddress(java.net.InetAddress) PrintWriter(java.io.PrintWriter)

Aggregations

IOException (java.io.IOException)2 JmxManagerInfo (org.apache.geode.tools.pulse.internal.data.JmxManagerFinder.JmxManagerInfo)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 MBeanException (javax.management.MBeanException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ReflectionException (javax.management.ReflectionException)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 SslRMIClientSocketFactory (javax.rmi.ssl.SslRMIClientSocketFactory)1