use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses 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.cluster.status.ExtendedHostStatuses in project cloudbreak by hortonworks.
the class ClusterService method updateClusterMetadata.
public Cluster updateClusterMetadata(Long stackId) {
Stack stack = stackService.getById(stackId);
ClusterApi connector = clusterApiConnectors.getConnector(stack);
if (!connector.clusterStatusService().isClusterManagerRunning()) {
Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
InstanceMetaData cmInstance = updateClusterManagerHostStatus(notTerminatedInstanceMetaDatas);
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), CLUSTER_HOST_STATUS_UPDATED, Arrays.asList(cmInstance.getDiscoveryFQDN(), cmInstance.getInstanceStatus().name()));
return stack.getCluster();
} else {
ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(stack.getCluster().getId()));
updateClusterCertExpirationState(stack.getCluster(), extendedHostStatuses.isAnyCertExpiring());
try {
return transactionService.required(() -> {
Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
List<InstanceMetaData> updatedInstanceMetaData = updateInstanceStatuses(notTerminatedInstanceMetaDatas, extendedHostStatuses);
instanceMetaDataService.saveAll(updatedInstanceMetaData);
fireHostStatusUpdateNotification(stack, updatedInstanceMetaData);
return stack.getCluster();
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
}
use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses 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.cluster.status.ExtendedHostStatuses in project cloudbreak by hortonworks.
the class StackStatusCheckerJobTest method internalTestInstanceSyncStopStart.
private void internalTestInstanceSyncStopStart(String instanceHgName, InstanceStatus instanceStatus, DetailedStackStatus expected) throws JobExecutionException {
setupForCM();
Set<HealthCheck> healthChecks = Sets.newHashSet(new HealthCheck(HealthCheckType.HOST, HealthCheckResult.UNHEALTHY, Optional.empty()), new HealthCheck(HealthCheckType.CERT, HealthCheckResult.UNHEALTHY, Optional.empty()));
ExtendedHostStatuses extendedHostStatuses = new ExtendedHostStatuses(Map.of(HostName.hostName("host1"), healthChecks));
when(clusterStatusService.getExtendedHostStatuses(any())).thenReturn(extendedHostStatuses);
when(instanceMetaData.getInstanceStatus()).thenReturn(instanceStatus);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.datahub()).thenReturn(regionAwareInternalCrnGenerator);
when(instanceMetaData.getDiscoveryFQDN()).thenReturn("host1");
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName(instanceHgName);
when(instanceMetaData.getInstanceGroup()).thenReturn(instanceGroup);
when(clusterApiConnectors.getConnector(stack)).thenReturn(clusterApi);
when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
when(stackUtil.stopStartScalingEntitlementEnabled(any())).thenReturn(true);
Set<String> computeGroups = new HashSet<>();
computeGroups.add("compute");
when(cmTemplateProcessor.getComputeHostGroups(any())).thenReturn(computeGroups);
underTest.executeTracedJob(jobExecutionContext);
verify(clusterOperationService, times(1)).reportHealthChange(any(), any(), anySet());
verify(stackInstanceStatusChecker).queryInstanceStatuses(eq(stack), any());
verify(clusterService, times(1)).updateClusterCertExpirationState(stack.getCluster(), true);
verify(clusterService, times(1)).updateClusterStatusByStackId(stack.getId(), expected);
}
use of com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses in project cloudbreak by hortonworks.
the class StackStatusCheckerJobTest method testInstanceSyncCMRunningNodeStopped.
@Test
public void testInstanceSyncCMRunningNodeStopped() throws JobExecutionException {
setupForCM();
Set<HealthCheck> healthChecks = Sets.newHashSet(new HealthCheck(HealthCheckType.HOST, HealthCheckResult.UNHEALTHY, Optional.empty()), new HealthCheck(HealthCheckType.CERT, HealthCheckResult.UNHEALTHY, Optional.empty()));
ExtendedHostStatuses extendedHostStatuses = new ExtendedHostStatuses(Map.of(HostName.hostName("host1"), healthChecks));
when(clusterStatusService.getExtendedHostStatuses(any())).thenReturn(extendedHostStatuses);
when(instanceMetaData.getInstanceStatus()).thenReturn(InstanceStatus.STOPPED);
when(instanceMetaData.getDiscoveryFQDN()).thenReturn("host1");
when(clusterApiConnectors.getConnector(stack)).thenReturn(clusterApi);
when(clusterApi.clusterStatusService()).thenReturn(clusterStatusService);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.datahub()).thenReturn(regionAwareInternalCrnGenerator);
underTest.executeTracedJob(jobExecutionContext);
verify(clusterOperationService, times(1)).reportHealthChange(any(), any(), anySet());
verify(stackInstanceStatusChecker).queryInstanceStatuses(eq(stack), any());
verify(clusterService, times(1)).updateClusterCertExpirationState(stack.getCluster(), true);
verify(clusterService, times(1)).updateClusterStatusByStackId(stack.getId(), DetailedStackStatus.NODE_FAILURE);
}
Aggregations