use of com.sequenceiq.cloudbreak.common.type.HostMetadataState in project cloudbreak by hortonworks.
the class AmbariClusterService method updateClusterMetadata.
@Override
@Transactional(TxType.NEVER)
public Cluster updateClusterMetadata(Long stackId) {
Stack stack = stackService.getById(stackId);
AmbariClient ambariClient = getAmbariClient(stack);
Map<String, Integer> hostGroupCounter = new HashMap<>();
Set<HostMetadata> hosts = hostMetadataRepository.findHostsInCluster(stack.getCluster().getId());
Map<String, String> hostStatuses = ambariClient.getHostStatuses();
for (HostMetadata host : hosts) {
if (hostStatuses.containsKey(host.getHostName())) {
String hgName = host.getHostGroup().getName();
Integer hgCounter = hostGroupCounter.getOrDefault(hgName, 0) + 1;
hostGroupCounter.put(hgName, hgCounter);
HostMetadataState newState = HostMetadataState.HEALTHY.name().equals(hostStatuses.get(host.getHostName())) ? HostMetadataState.HEALTHY : HostMetadataState.UNHEALTHY;
boolean stateChanged = updateHostMetadataByHostState(stack, host.getHostName(), newState);
if (stateChanged && HostMetadataState.HEALTHY == newState) {
updateInstanceMetadataStateToRegistered(stackId, host);
}
}
}
hostGroupCounter(stack.getCluster().getId(), hostGroupCounter);
return stack.getCluster();
}
use of com.sequenceiq.cloudbreak.common.type.HostMetadataState in project cloudbreak by hortonworks.
the class AmbariClusterService method updateHostMetadataByHostState.
private boolean updateHostMetadataByHostState(Stack stack, String hostName, HostMetadataState newState) {
boolean stateChanged = false;
HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), hostName);
HostMetadataState oldState = hostMetadata.getHostMetadataState();
if (!oldState.equals(newState)) {
stateChanged = true;
hostMetadata.setHostMetadataState(newState);
hostMetadataRepository.save(hostMetadata);
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_HOST_STATUS_UPDATED.code(), Arrays.asList(hostName, newState.name())));
}
return stateChanged;
}
use of com.sequenceiq.cloudbreak.common.type.HostMetadataState in project cloudbreak by hortonworks.
the class AmbariClusterService method updateHostMetadata.
@Override
public void updateHostMetadata(Long clusterId, Map<String, List<String>> hostsPerHostGroup, HostMetadataState hostMetadataState) {
for (Entry<String, List<String>> hostGroupEntry : hostsPerHostGroup.entrySet()) {
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(clusterId, hostGroupEntry.getKey());
if (hostGroup != null) {
Set<String> existingHosts = hostMetadataRepository.findEmptyHostsInHostGroup(hostGroup.getId()).stream().map(HostMetadata::getHostName).collect(Collectors.toSet());
hostGroupEntry.getValue().stream().filter(hostName -> !existingHosts.contains(hostName)).forEach(hostName -> {
HostMetadata hostMetadataEntry = new HostMetadata();
hostMetadataEntry.setHostName(hostName);
hostMetadataEntry.setHostGroup(hostGroup);
hostMetadataEntry.setHostMetadataState(hostMetadataState);
hostGroup.getHostMetadata().add(hostMetadataEntry);
});
hostGroupService.save(hostGroup);
}
}
}
Aggregations