use of com.sequenceiq.cloudbreak.cloud.model.HostName in project cloudbreak by hortonworks.
the class StackStatusCheckerJob method doSync.
private void doSync(Stack stack) {
ClusterApi connector = clusterApiConnectors.getConnector(stack);
Set<InstanceMetaData> runningInstances = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
try {
if (isClusterManagerRunning(stack, connector)) {
ExtendedHostStatuses extendedHostStatuses = getExtendedHostStatuses(stack, connector);
Map<HostName, Set<HealthCheck>> hostStatuses = extendedHostStatuses.getHostsHealth();
LOGGER.debug("Cluster '{}' state check, host certicates expiring: [{}], cm running, hoststates: {}", stack.getId(), extendedHostStatuses.isAnyCertExpiring(), hostStatuses);
reportHealthAndSyncInstances(stack, runningInstances, getFailedInstancesInstanceMetadata(extendedHostStatuses, runningInstances), getNewHealthyHostNames(extendedHostStatuses, runningInstances), extendedHostStatuses.isAnyCertExpiring());
} else {
syncInstances(stack, runningInstances, false);
}
} catch (RuntimeException e) {
LOGGER.warn("Error during sync", e);
syncInstances(stack, runningInstances, false);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.HostName in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method collectHostsToRemove.
public Map<String, InstanceMetaData> collectHostsToRemove(Stack stack, HostGroup hostGroup, Set<String> hostNames, ApiClient client) {
Set<InstanceMetaData> hostsInHostGroup = hostGroup.getInstanceGroup().getNotTerminatedInstanceMetaDataSet();
Map<String, InstanceMetaData> hostsToRemove = hostsInHostGroup.stream().filter(hostMetadata -> hostNames.contains(hostMetadata.getDiscoveryFQDN())).collect(Collectors.toMap(InstanceMetaData::getDiscoveryFQDN, hostMetadata -> hostMetadata));
if (hostsToRemove.size() != hostNames.size()) {
List<String> missingHosts = hostNames.stream().filter(h -> !hostsToRemove.containsKey(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CB for host group: {}. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", hostGroup.getName(), missingHosts.size(), missingHosts, hostNames);
}
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
List<String> runningHosts = hostRefList.getItems().stream().map(ApiHost::getHostname).collect(Collectors.toList());
// TODO: what if i remove a node from CM manually?
List<String> matchingCmHosts = hostsToRemove.keySet().stream().filter(hostName -> runningHosts.contains(hostName)).collect(Collectors.toList());
Set<String> matchingCmHostSet = new HashSet<>(matchingCmHosts);
if (matchingCmHosts.size() != hostsToRemove.size()) {
List<String> missingHostsInCm = hostsToRemove.keySet().stream().filter(h -> !matchingCmHostSet.contains(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CM. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", missingHostsInCm.size(), missingHostsInCm, hostsToRemove.keySet());
}
Sets.newHashSet(hostsToRemove.keySet()).stream().filter(hostName -> !matchingCmHostSet.contains(hostName)).forEach(hostsToRemove::remove);
LOGGER.debug("Collected hosts to remove: [{}]", hostsToRemove);
return hostsToRemove;
} catch (ApiException e) {
LOGGER.error("Failed to get host list for cluster: {}", stack.getName(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.HostName in project cloudbreak by hortonworks.
the class VmStatusCheckerConclusionStep method checkCMForInstanceStatuses.
private Conclusion checkCMForInstanceStatuses(ClusterApi connector, Set<InstanceMetaData> runningInstances, Long clusterId) {
ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(clusterId));
Map<HostName, Set<HealthCheck>> hostStatuses = extendedHostStatuses.getHostsHealth();
Map<String, String> unhealthyHosts = hostStatuses.keySet().stream().filter(hostName -> !extendedHostStatuses.isHostHealthy(hostName)).collect(Collectors.toMap(StringType::value, extendedHostStatuses::statusReasonForHost));
Set<String> noReportHosts = runningInstances.stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).filter(discoveryFQDN -> !hostStatuses.containsKey(hostName(discoveryFQDN))).collect(toSet());
if (!unhealthyHosts.isEmpty() || !noReportHosts.isEmpty()) {
String conclusion = String.format("Unhealthy and/or unknown VMs found based on CM status. Unhealthy VMs: %s, unknown VMs: %s. " + "Please check the instances on your cloud provider for further details.", unhealthyHosts, noReportHosts);
String details = String.format("Unhealthy and/or unknown VMs found based on CM status. Unhealthy VMs: %s, unknown VMs: %s", unhealthyHosts, noReportHosts);
LOGGER.warn(details);
return failed(conclusion, details);
} else {
return succeeded();
}
}
use of com.sequenceiq.cloudbreak.cloud.model.HostName in project cloudbreak by hortonworks.
the class ClusterServiceTest method setupClusterApi.
private void setupClusterApi(Stack stack, HealthCheckResult healthCheckResult, String statusReason) {
ClusterApi connector = mock(ClusterApi.class);
ClusterStatusService clusterStatusService = mock(ClusterStatusService.class);
when(clusterStatusService.isClusterManagerRunning()).thenReturn(true);
when(connector.clusterStatusService()).thenReturn(clusterStatusService);
Map<HostName, Set<HealthCheck>> clusterManagerStateMap = new HashMap<>();
if (healthCheckResult != null) {
clusterManagerStateMap.put(HostName.hostName(FQDN1), Sets.newHashSet(new HealthCheck(HealthCheckType.HOST, healthCheckResult, Optional.ofNullable(statusReason))));
}
ExtendedHostStatuses extendedHostStatuses = new ExtendedHostStatuses(clusterManagerStateMap);
when(clusterStatusService.getExtendedHostStatuses(any())).thenReturn(extendedHostStatuses);
when(clusterApiConnectors.getConnector(stack)).thenReturn(connector);
}
use of com.sequenceiq.cloudbreak.cloud.model.HostName in project cloudbreak by hortonworks.
the class VmStatusCheckerConclusionStepTest method createExtendedHostStatuses.
private ExtendedHostStatuses createExtendedHostStatuses(boolean healthy) {
Map<HostName, Set<HealthCheck>> hostStatuses = new HashMap<>();
HealthCheckResult status = healthy ? HealthCheckResult.HEALTHY : HealthCheckResult.UNHEALTHY;
String reason = healthy ? null : "error";
Set<HealthCheck> healthChecks = Sets.newHashSet(new HealthCheck(HealthCheckType.HOST, status, Optional.ofNullable(reason)));
hostStatuses.put(HostName.hostName("host1"), healthChecks);
hostStatuses.put(HostName.hostName("host2"), healthChecks);
return new ExtendedHostStatuses(hostStatuses);
}
Aggregations