return response;
}
protected void processHostStatus(HeartBeat heartbeat, String hostname) throws AmbariException {
Host host = clusterFsm.getHost(hostname);
HealthStatus healthStatus = host.getHealthStatus().getHealthStatus();
if (!healthStatus.equals(HostHealthStatus.HealthStatus.UNKNOWN)) {
List<ComponentStatus> componentStatuses = heartbeat.getComponentStatus();
//Host status info could be calculated only if agent returned statuses in heartbeat
//Or, if a command is executed that can change component status
boolean calculateHostStatus = false;
String clusterName = null;
if (componentStatuses.size() > 0) {
calculateHostStatus = true;
for (ComponentStatus componentStatus : componentStatuses) {
clusterName = componentStatus.getClusterName();
break;
}
}
if (!calculateHostStatus) {
List<CommandReport> reports = heartbeat.getReports();
for (CommandReport report : reports) {
if (RoleCommand.ACTIONEXECUTE.toString().equals(report.getRoleCommand())) {
continue;
}
String service = report.getServiceName();
if (actionMetadata.getActions(service.toLowerCase()).contains(report.getRole())) {
continue;
}
if (report.getStatus().equals("COMPLETED")) {
calculateHostStatus = true;
clusterName = report.getClusterName();
break;
}
}
}
if (calculateHostStatus) {
//Use actual component status to compute the host status
int masterCount = 0;
int mastersRunning = 0;
int slaveCount = 0;
int slavesRunning = 0;
StackId stackId;
Cluster cluster = clusterFsm.getCluster(clusterName);
stackId = cluster.getDesiredStackVersion();
MaintenanceStateHelper psh = injector.getInstance(MaintenanceStateHelper.class);
List<ServiceComponentHost> scHosts = cluster.getServiceComponentHosts(heartbeat.getHostname());
for (ServiceComponentHost scHost : scHosts) {
ComponentInfo componentInfo =
ambariMetaInfo.getComponent(stackId.getStackName(),
stackId.getStackVersion(), scHost.getServiceName(),
scHost.getServiceComponentName());
String status = scHost.getState().name();
String category = componentInfo.getCategory();
if (MaintenanceState.OFF == psh.getEffectiveState(scHost, host)) {
if (category.equals("MASTER")) {
++masterCount;
if (status.equals("STARTED")) {
++mastersRunning;
}
} else if (category.equals("SLAVE")) {
++slaveCount;
if (status.equals("STARTED")) {
++slavesRunning;
}
}
}
}
if (masterCount == mastersRunning && slaveCount == slavesRunning) {
healthStatus = HostHealthStatus.HealthStatus.HEALTHY;
} else if (masterCount > 0 && mastersRunning < masterCount) {
healthStatus = HostHealthStatus.HealthStatus.UNHEALTHY;
} else {
healthStatus = HostHealthStatus.HealthStatus.ALERT;
}
host.setStatus(healthStatus.name());
host.persist();
}
//If host doesn't belongs to any cluster
if ((clusterFsm.getClustersForHost(host.getHostName())).size() == 0) {
healthStatus = HostHealthStatus.HealthStatus.HEALTHY;
host.setStatus(healthStatus.name());
host.persist();
}
}
}