use of com.sequenceiq.cloudbreak.domain.HostMetadata 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.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterService method repairCluster.
@Override
public void repairCluster(Long stackId, List<String> repairedHostGroups, boolean removeOnly) {
Stack stack = stackService.get(stackId);
Cluster cluster = stack.getCluster();
Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
Map<String, List<String>> failedNodeMap = new HashMap<>();
for (HostGroup hg : hostGroups) {
List<String> failedNodes = new ArrayList<>();
if (repairedHostGroups.contains(hg.getName()) && hg.getRecoveryMode() == RecoveryMode.MANUAL) {
for (HostMetadata hmd : hg.getHostMetadata()) {
if (hmd.getHostMetadataState() == HostMetadataState.UNHEALTHY) {
validateRepair(stack, hmd);
if (!failedNodeMap.containsKey(hg.getName())) {
failedNodeMap.put(hg.getName(), failedNodes);
}
failedNodes.add(hmd.getHostName());
}
}
}
}
if (!failedNodeMap.isEmpty()) {
flowManager.triggerClusterRepairFlow(stackId, failedNodeMap, removeOnly);
String recoveryMessage = cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_MANUALRECOVERY_REQUESTED.code(), Collections.singletonList(repairedHostGroups));
LOGGER.info(recoveryMessage);
eventService.fireCloudbreakEvent(stack.getId(), "RECOVERY", recoveryMessage);
}
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariDecommissioner method collectHostMetadata.
private Map<String, HostMetadata> collectHostMetadata(Cluster cluster, String hostGroupName, Collection<String> hostNames) {
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(cluster.getId(), hostGroupName);
Set<HostMetadata> hostsInHostGroup = hostGroup.getHostMetadata();
Map<String, HostMetadata> hostMetadatas = hostsInHostGroup.stream().filter(hostMetadata -> hostNames.contains(hostMetadata.getHostName())).collect(Collectors.toMap(HostMetadata::getHostName, hostMetadata -> hostMetadata));
return hostMetadatas;
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariDecommissioner method selectHostsToRemove.
private Set<String> selectHostsToRemove(Iterable<HostMetadata> decommissionCandidates, int adjustment) {
Set<String> hostsToRemove = new HashSet<>();
int i = 0;
for (HostMetadata hostMetadata : decommissionCandidates) {
String hostName = hostMetadata.getHostName();
if (i < adjustment) {
LOGGER.info("Host '{}' will be removed from Ambari cluster", hostName);
hostsToRemove.add(hostName);
} else {
break;
}
i++;
}
return hostsToRemove;
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariDecommissioner method collectHostsToRemove.
public Map<String, HostMetadata> collectHostsToRemove(Stack stack, String hostGroupName, Collection<String> hostNames) throws CloudbreakException {
Map<String, HostMetadata> hostsToRemove = collectHostMetadata(stack.getCluster(), hostGroupName, hostNames);
if (hostsToRemove.size() != hostNames.size()) {
throw new CloudbreakException("Not all the hosts found in the given host group.");
}
Cluster cluster = stack.getCluster();
HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp());
AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), cluster);
List<String> runningHosts = ambariClient.getClusterHosts();
Sets.newHashSet(hostsToRemove.keySet()).forEach(hostName -> {
if (!runningHosts.contains(hostName)) {
hostsToRemove.remove(hostName);
}
});
return hostsToRemove;
}
Aggregations