if (!FabricCommand.doesContainerExist(fabricService, container)) {
System.out.println("Container " + container + " does not exists!");
return null;
}
Container containerInstance = FabricCommand.getContainerIfExists(fabricService, container);
String type = containerInstance.getType();
if (!"karaf".equals(type)) {
System.out.println("Sorry, currently only \"karaf\" type container are supported");
return null;
}
String jmxUrl = null;
JMXConnector connector = null;
MBeanServerConnection remote = null;
HashMap<String, String[]> authenticationData = null;
jmxUrl = containerInstance.getJmxUrl();
authenticationData = prepareAuthenticationData();
try {
connector = connectOrRetry(authenticationData, jmxUrl);
} catch (Exception e){
username = null;
password = null;
System.out.println("Operation Failed. Check logs.");
log.error("Unable to connect to JMX Server", e);
return null;
}
remote = connector.getMBeanServerConnection();
ObjectName objName = null;
if (jvmOptions == null) {
objName = new ObjectName(JAVA_LANG_OBJECT_NAME);
try {
String[] arguments = (String[]) remote.getAttribute(objName, "InputArguments");
String output = Arrays.toString(arguments);
output = output.replaceAll(",", "");
output = output.substring(1, output.length() - 1);
System.out.println(output);
} catch (Exception e) {
System.out.println("Operation Failed. Check logs.");
log.error("Unable to fetch child jvm opts", e);
}
} else {
jvmOptions = stripSlashes(jvmOptions);
String providerType = null;
CreateContainerMetadata<?> metadata = containerInstance.getMetadata();
if(metadata == null){
//root container
//disallowed for the time being. something odd screws authentication
// providerType = "child";
System.out.println("Modifying current container is not allowed. Please turn the instance off and manually edit env variables");
return null;
}else{
providerType = metadata.getCreateOptions().getProviderType();
}
switch(providerType){
case "ssh":
//we need to operate on an ensamble member container
containerInstance= fabricService.getCurrentContainer();
jmxUrl = containerInstance.getJmxUrl();
authenticationData = prepareAuthenticationData();
connector = connectOrRetry(authenticationData, jmxUrl);
remote = connector.getMBeanServerConnection();