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;
}
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;
}
Aggregations