@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); Logger logger = context.getLogger(); logger.log(Level.INFO, Strings.get("get.health.called", clusterName)); // output will be handled within this method if (!checkEnvAndParams(logger, report)) { return; } /* * Check that gms is enabled for this cluster. Could also check * gmsAdapterService.isGmsEnabled() and * domain.getClusterNamed(clusterName).getGmsEnabled(), but that * should be redundant. If the GMSAdapter exists for the cluster, * we can use GMS. */ GMSAdapter gmsAdapter = gmsAdapterService.getGMSAdapterByName(clusterName); if (gmsAdapter != null) { getHealthWithGMS(logger, report, gmsAdapter); } else { // if someone wants to implement the non-gms case, here's where setFail(logger, report, Strings.get("get.health.noGMS", clusterName)); } }
private boolean checkEnvAndParams(Logger logger, ActionReport report) { // first check that we're the DAS if (!env.isDas()) { return setFail(logger, report, Strings.get("get.health.onlyRunsOnDas")); } // check that cluster exists Cluster cluster = domain.getClusterNamed(clusterName); if (cluster == null) { return setFail(logger, report, Strings.get("get.health.noCluster", clusterName)); } // ok to go return true; }
private boolean checkEnvAndParams() { // first check that we're the DAS if (!env.isDas()) { return setFail(Strings.get("get.health.onlyRunsOnDas")); } // check that cluster exists Cluster cluster = domain.getClusterNamed(clusterName); if (cluster == null) { return setFail(Strings.get("get.health.noCluster", clusterName)); } // ok to go return true; }
@Override public void execute(AdminCommandContext context) { report = context.getActionReport(); logger = context.getLogger(); logger.log(Level.INFO, Strings.get("get.health.called", clusterName)); // output will be handled within this method if (!checkEnvAndParams()) { return; } /* * Check that gms is enabled for this cluster. Could also check * gmsAdapterService.isGmsEnabled() and * domain.getClusterNamed(clusterName).getGmsEnabled(), but that * should be redundant. If the GMSAdapter exists for the cluster, * we can use GMS. */ gmsAdapter = gmsAdapterService.getGMSAdapterByName(clusterName); if (gmsAdapter != null) { getHealthWithGMS(); } else { // if someone wants to implement the non-gms case, here's where setFail(Strings.get("get.health.noGMS", clusterName)); } }
HealthHistory history = gmsAdapter.getHealthHistory(); if (history == null) { setFail(logger, report, Strings.get("get.health.noHistoryError")); return;
private void getHealthWithGMS() { StringBuilder result = new StringBuilder(); HealthHistory history = gmsAdapter.getHealthHistory(); if (history == null) { setFail(Strings.get("get.health.noHistoryError")); return; } // check for data if (history.getInstances().isEmpty()) { report.setMessage(Strings.get( "get.health.no.instances", clusterName)); return; } // order by instance name and output SortedSet<String> names = new TreeSet<String>(history.getInstances()); for(String name : names) { HealthHistory.InstanceHealth ih = history.getHealthByInstance(name); if (HealthHistory.NOTIME == ih.time) { result.append(Strings.get("get.health.instance.state", name, ih.state)); } else { result.append(Strings.get("get.health.instance.state.since", name, ih.state, new Date(ih.time).toString())); } result.append("\n"); } String rawResult = result.toString(); report.setMessage(rawResult.substring(0, rawResult.lastIndexOf("\n"))); }