use of com.sun.enterprise.util.cluster.InstanceInfo in project Payara by payara.
the class ListClustersCommand method execute.
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
Logger logger = context.getLogger();
ActionReport.MessagePart top = report.getTopMessagePart();
List<Cluster> clusterList = null;
// defaults to domain
if (whichTarget.equals("domain")) {
Clusters clusters = domain.getClusters();
clusterList = clusters.getCluster();
} else {
clusterList = createClusterList();
if (clusterList == null) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(Strings.get("list.instances.badTarget", whichTarget));
return;
}
}
StringBuilder sb = new StringBuilder();
if (clusterList.size() < 1) {
sb.append(NONE);
}
int timeoutInMsec = 2000;
Map<String, ClusterInfo> clusterMap = new HashMap<String, ClusterInfo>();
List<InstanceInfo> infos = new LinkedList<InstanceInfo>();
for (Cluster cluster : clusterList) {
String clusterName = cluster.getName();
List<Server> servers = cluster.getInstances();
if (servers.isEmpty()) {
ClusterInfo ci = clusterMap.get(clusterName);
if (ci == null) {
ci = new ClusterInfo(clusterName);
}
ci.serversEmpty = true;
clusterMap.put(clusterName, ci);
}
// Then check the status for them
for (Server server : servers) {
String name = server.getName();
if (name != null) {
ActionReport tReport = habitat.getService(ActionReport.class, "html");
InstanceInfo ii = new InstanceInfo(habitat, server, new RemoteInstanceCommandHelper(habitat).getAdminPort(server), server.getAdminHost(), clusterName, "", logger, timeoutInMsec, tReport, stateService);
infos.add(ii);
}
}
}
for (InstanceInfo ii : infos) {
String clusterforInstance = ii.getCluster();
ClusterInfo ci = clusterMap.get(clusterforInstance);
if (ci == null) {
ci = new ClusterInfo(clusterforInstance);
}
ci.allInstancesRunning &= ii.isRunning();
if (ii.isRunning()) {
ci.atleastOneInstanceRunning = true;
}
clusterMap.put(clusterforInstance, ci);
}
// List the cluster and also the state
// A cluster is a three-state entity and
// list-cluster should return one of the following:
// running (all instances running)
// not running (no instance running)
// partially running (at least 1 instance is not running)
String display;
String value;
for (ClusterInfo ci : clusterMap.values()) {
if (ci.serversEmpty || !ci.atleastOneInstanceRunning) {
display = InstanceState.StateType.NOT_RUNNING.getDisplayString();
value = InstanceState.StateType.NOT_RUNNING.getDescription();
} else if (ci.allInstancesRunning) {
display = InstanceState.StateType.RUNNING.getDisplayString();
value = InstanceState.StateType.RUNNING.getDescription();
} else {
display = PARTIALLY_RUNNING_DISPLAY;
value = PARTIALLY_RUNNING;
}
sb.append(ci.getName()).append(display).append(EOL);
top.addProperty(ci.getName(), value);
}
String output = sb.toString();
// Fix for isue 12885
report.setMessage(output.substring(0, output.length() - 1));
}
use of com.sun.enterprise.util.cluster.InstanceInfo in project Payara by payara.
the class ListInstancesCommand method yesStatus.
private void yesStatus(List<Server> serverList, int timeoutInMsec, Logger logger) {
// Gather a list of InstanceInfo -- one per instance in domain.xml
RemoteInstanceCommandHelper helper = new RemoteInstanceCommandHelper(habitat);
for (Server server : serverList) {
boolean clustered = server.getCluster() != null;
int port = helper.getAdminPort(server);
String host = server.getAdminHost();
if (standaloneonly && clustered) {
continue;
}
String name = server.getName();
if (name == null) {
// can this happen?!?
continue;
}
StringBuilder deploymentGroup = new StringBuilder();
for (DeploymentGroup dg : server.getDeploymentGroup()) {
deploymentGroup.append(dg.getName()).append(' ');
}
Cluster cluster = domain.getClusterForInstance(name);
String clusterName = (cluster != null) ? cluster.getName() : null;
// skip DAS
if (notDas(name)) {
ActionReport tReport = habitat.getService(ActionReport.class, "html");
InstanceInfo ii = new InstanceInfo(habitat, server, port, host, clusterName, deploymentGroup.toString(), logger, timeoutInMsec, tReport, stateService);
infos.add(ii);
}
}
if (infos.size() < 1) {
report.setMessage(NONE);
return;
}
Properties extraProps = new Properties();
List instanceList = new ArrayList();
for (InstanceInfo ii : infos) {
String name = ii.getName();
String value = (ii.isRunning()) ? InstanceState.StateType.RUNNING.getDescription() : InstanceState.StateType.NOT_RUNNING.getDescription();
InstanceState.StateType state = (ii.isRunning()) ? (stateService.setState(name, InstanceState.StateType.RUNNING, false)) : (stateService.setState(name, InstanceState.StateType.NOT_RUNNING, false));
List<String> failedCmds = stateService.getFailedCommands(name);
if (state == InstanceState.StateType.RESTART_REQUIRED) {
if (ii.isRunning()) {
// value += (";" + InstanceState.StateType.RESTART_REQUIRED.getDescription());
value = InstanceState.StateType.RESTART_REQUIRED.getDescription();
}
}
HashMap<String, Object> insDetails = new HashMap<String, Object>();
insDetails.put("name", name);
insDetails.put("status", value);
insDetails.put("deploymentgroup", ii.getDeploymentGroups().trim());
if (state == InstanceState.StateType.RESTART_REQUIRED) {
insDetails.put("restartReasons", failedCmds);
}
if (ii.isRunning()) {
insDetails.put("uptime", ii.getUptime());
}
instanceList.add(insDetails);
}
extraProps.put("instanceList", instanceList);
report.setExtraProperties(extraProps);
if (long_opt) {
report.setMessage(InstanceInfo.format(infos));
} else {
report.setMessage(InstanceInfo.formatBrief(infos));
}
}
Aggregations