use of io.fabric8.core.jmx.FabricManager in project fabric8 by jboss-fuse.
the class ContainerEditJvmOptionsAction method doExecute.
protected Object doExecute() throws Exception {
validateContainerName(container);
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;
}
// read current jvm values
FabricManager fabricManager = new FabricManager(fabricService);
if (full) {
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;
}
ObjectName objName = new ObjectName(JAVA_LANG_OBJECT_NAME);
try {
remote = connector.getMBeanServerConnection();
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);
}
try {
connector.close();
} catch (IOException e) {
log.error("Errors closing remote MBean connection", e);
}
} else {
try {
String output = fabricManager.getJvmOpts(container);
if ("Inapplicable".equals(output)) {
String message = container + " jvmOpts cannot be handled within Fabric. You have to set required values directly in startup scripts.";
System.out.println(message);
log.error(message);
return null;
}
if (jvmOptions == null) {
System.out.println(output);
} else {
fabricManager.setJvmOpts(container, jvmOptions);
System.out.println("Operation succeeded. New JVM flags will be loaded at the next start of " + container + " container");
log.info("Updated JVM flags for container {}", container);
}
} catch (Exception e) {
System.out.println("Operation Failed. Check logs.");
log.error("Unable to set ssh jvm opts", e);
}
}
return null;
}
use of io.fabric8.core.jmx.FabricManager in project fabric8 by jboss-fuse.
the class FabricMBeanRegistrationListener method registerFabricMBeans.
private void registerFabricMBeans() {
this.healthCheck = new HealthCheck(fabricService.get());
this.managerMBean = new FabricManager((FabricServiceImpl) fabricService.get());
this.zooKeeperMBean = new ZooKeeperFacade((FabricServiceImpl) fabricService.get());
this.fileSystemMBean = new FileSystem(runtimeProperties.get());
healthCheck.registerMBeanServer(shutdownTracker, mbeanServer.get());
managerMBean.registerMBeanServer(shutdownTracker, mbeanServer.get());
fileSystemMBean.registerMBeanServer(shutdownTracker, mbeanServer.get());
zooKeeperMBean.registerMBeanServer(shutdownTracker, mbeanServer.get());
}
Aggregations