Search in sources :

Example 1 with HostName

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);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Collectors.toSet(java.util.stream.Collectors.toSet) EnumSet(java.util.EnumSet) Set(java.util.Set) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Example 2 with HostName

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);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiException(com.cloudera.api.swagger.client.ApiException) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) FlowMessageService(com.sequenceiq.cloudbreak.message.FlowMessageService) Map(java.util.Map) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) NotEnoughNodeException(com.sequenceiq.cloudbreak.cluster.service.NotEnoughNodeException) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ApiHostsToRemoveArgs(com.cloudera.api.swagger.model.ApiHostsToRemoveArgs) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiHostNameList(com.cloudera.api.swagger.model.ApiHostNameList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Stream(java.util.stream.Stream) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Joiner(com.google.common.base.Joiner) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) HostServiceStatuses(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatuses) HostServiceStatus(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatus) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) Function(java.util.function.Function) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ApiHost(com.cloudera.api.swagger.model.ApiHost) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) Logger(org.slf4j.Logger) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Consumer(java.util.function.Consumer) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) Component(org.springframework.stereotype.Component) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CommandsResourceApi(com.cloudera.api.swagger.CommandsResourceApi) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) Comparator(java.util.Comparator) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) StringUtils(org.springframework.util.StringUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) HashSet(java.util.HashSet) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 3 with HostName

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();
    }
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Inject(javax.inject.Inject) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) StackInstanceStatusChecker(com.sequenceiq.cloudbreak.service.stack.StackInstanceStatusChecker) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) RuntimeVersionService(com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService) Set(java.util.Set) StringType(com.sequenceiq.cloudbreak.cloud.model.generic.StringType) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) List(java.util.List) Component(org.springframework.stereotype.Component) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceSyncState(com.sequenceiq.cloudbreak.service.stack.flow.InstanceSyncState) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) Objects(java.util.Objects) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Example 4 with HostName

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);
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Set(java.util.Set) HashMap(java.util.HashMap) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ClusterStatusService(com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Example 5 with HostName

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);
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) Set(java.util.Set) HashMap(java.util.HashMap) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) HealthCheckResult(com.sequenceiq.cloudbreak.common.type.HealthCheckResult) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Aggregations

HostName (com.sequenceiq.cloudbreak.cloud.model.HostName)7 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)5 Set (java.util.Set)5 ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)4 ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)3 HealthCheck (com.sequenceiq.cloudbreak.common.type.HealthCheck)3 HashMap (java.util.HashMap)3 HostName.hostName (com.sequenceiq.cloudbreak.cloud.model.HostName.hostName)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Inject (javax.inject.Inject)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)1