String jmxPort = null;
StringBuilder commandLineBuilder = new StringBuilder(400);
int classpathIndex = -1;
ProcessInfo processInfo = processScanResult.getProcessInfo();
String[] arguments = processInfo.getCommandLine();
for (int i = 0; i < arguments.length; i++) {
String arg = arguments[i];
if (arg.startsWith("-Dcom.sun.management.jmxremote.port")) {
String[] jmxPortArg = arg.split("=");
jmxPort = jmxPortArg[1];
}
if (arg.startsWith("-cp") || (arg.startsWith("-classpath"))) {
classpathIndex = i;
}
commandLineBuilder.append(arg);
commandLineBuilder.append(' ');
}
pluginConfig.put(new PropertySimple(COMMAND_LINE_CONFIG_PROPERTY, commandLineBuilder.toString()));
if (classpathIndex != -1 && classpathIndex + 1 < arguments.length) {
String[] classpathEntries = arguments[classpathIndex + 1].split(File.pathSeparator);
File yamlConfigurationPath = null;
for (String classpathEntry : classpathEntries) {
if (classpathEntry.endsWith("conf")) {
yamlConfigurationPath = new File(classpathEntry);
if (!yamlConfigurationPath.isAbsolute()) {
try {
//relative path, use process CWD to find absolute path of the conf directory
yamlConfigurationPath = new File(processInfo.getExecutable().getCwd(), classpathEntry);
} catch (Exception e) {
log.error("Error creating path for yaml file.", e);
}
}
}
}
if (yamlConfigurationPath != null) {
File yamlConfigurationFile = new File(yamlConfigurationPath, "cassandra.yaml");
ConfigEditor yamlEditor = new ConfigEditor(yamlConfigurationFile);
yamlEditor.load();
pluginConfig.put(new PropertySimple(YAML_PROPERTY, yamlConfigurationFile.getAbsolutePath()));
pluginConfig.put(new PropertySimple(CLUSTER_NAME_PROPERTY, yamlEditor.getClusterName()));
pluginConfig.put(new PropertySimple(HOST_PROPERTY, yamlEditor.getListenAddress()));
pluginConfig.put(new PropertySimple(AUTHENTICATOR_PROPERTY, yamlEditor.getAuthenticator()));
}
}
if (jmxPort != null) {
pluginConfig.put(new PropertySimple(JMX_PORT_PROPERTY, jmxPort));
pluginConfig.put(new PropertySimple(JMXDiscoveryComponent.CONNECTION_TYPE,
J2SE5ConnectionTypeDescriptor.class.getName()));
pluginConfig.put(new PropertySimple(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY,
"service:jmx:rmi:///jndi/rmi://" + pluginConfig.getSimpleValue(HOST_PROPERTY) + ":" + jmxPort
+ "/jmxrmi"));
}
String resourceKey = "Cassandra (" + pluginConfig.getSimpleValue(HOST_PROPERTY) + ") " + jmxPort;
String resourceName = RESOURCE_NAME;
String path = processInfo.getExecutable().getCwd();
pluginConfig.put(new PropertySimple(BASEDIR_PROPERTY, new File(path).getParentFile().getAbsolutePath()));
return new DiscoveredResourceDetails(context.getResourceType(), resourceKey, resourceName, null, null,
pluginConfig, processInfo);
}