Search in sources :

Example 6 with HostMetadata

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;
}
Also used : HostMetadataState(com.sequenceiq.cloudbreak.common.type.HostMetadataState) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 7 with HostMetadata

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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ArrayList(java.util.ArrayList) List(java.util.List) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 8 with HostMetadata

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;
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HttpResponseException(groovyx.net.http.HttpResponseException) LoggerFactory(org.slf4j.LoggerFactory) RSDecommissionStatusCheckerTask(com.sequenceiq.cloudbreak.service.cluster.flow.RSDecommissionStatusCheckerTask) DECOMMISSION_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.DECOMMISSION_AMBARI_PROGRESS_STATE) Msg(com.sequenceiq.cloudbreak.core.flow2.stack.Msg) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) START_SERVICES_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.START_SERVICES_AMBARI_PROGRESS_STATE) Collections.singletonList(java.util.Collections.singletonList) PollingResult.isTimeout(com.sequenceiq.cloudbreak.service.PollingResult.isTimeout) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Map(java.util.Map) ContainerRepository(com.sequenceiq.cloudbreak.repository.ContainerRepository) HostMetadataState(com.sequenceiq.cloudbreak.common.type.HostMetadataState) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HostMetadataRepository(com.sequenceiq.cloudbreak.repository.HostMetadataRepository) TlsSecurityService(com.sequenceiq.cloudbreak.service.TlsSecurityService) Collection(java.util.Collection) MAX_ATTEMPTS_FOR_HOSTS(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariOperationService.MAX_ATTEMPTS_FOR_HOSTS) Set(java.util.Set) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) FlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.FlowMessageService) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) NotEnoughNodeException(com.sequenceiq.cloudbreak.service.cluster.NotEnoughNodeException) Collectors(java.util.stream.Collectors) AMBARI_POLLING_INTERVAL(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariOperationService.AMBARI_POLLING_INTERVAL) Sets(com.google.common.collect.Sets) PollingResult.isSuccess(com.sequenceiq.cloudbreak.service.PollingResult.isSuccess) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) AmbariOperationService(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariOperationService) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) AmbariClientPollerObject(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariClientPollerObject) DataNodeUtils.sortByUsedSpace(com.sequenceiq.cloudbreak.service.cluster.ambari.DataNodeUtils.sortByUsedSpace) PollingService(com.sequenceiq.cloudbreak.service.PollingService) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) HashMap(java.util.HashMap) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) ServiceAndHostService(com.sequenceiq.ambari.client.services.ServiceAndHostService) ConfigParam(com.sequenceiq.cloudbreak.service.cluster.filter.ConfigParam) OrchestratorTypeResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Objects.requireNonNull(java.util.Objects.requireNonNull) Collections.singletonMap(java.util.Collections.singletonMap) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Stack(com.sequenceiq.cloudbreak.domain.Stack) Nonnull(javax.annotation.Nonnull) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) AMBARI_AGENT(com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer.AMBARI_AGENT) AmbariDFSSpaceRetrievalTask(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariDFSSpaceRetrievalTask) AmbariHostsLeaveStatusCheckerTask(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariHostsLeaveStatusCheckerTask) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) Iterator(java.util.Iterator) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) DECOMMISSION_SERVICES_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.DECOMMISSION_SERVICES_AMBARI_PROGRESS_STATE) DNDecommissionStatusCheckerTask(com.sequenceiq.cloudbreak.service.cluster.flow.DNDecommissionStatusCheckerTask) AmbariClientExceptionUtil(com.sequenceiq.cloudbreak.util.AmbariClientExceptionUtil) SUCCESS(com.sequenceiq.cloudbreak.service.PollingResult.SUCCESS) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Container(com.sequenceiq.cloudbreak.domain.Container) Component(org.springframework.stereotype.Component) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) STOP_SERVICES_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.STOP_SERVICES_AMBARI_PROGRESS_STATE) HostFilterService(com.sequenceiq.cloudbreak.service.cluster.filter.HostFilterService) Collections(java.util.Collections) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) AmbariClientProvider(com.sequenceiq.cloudbreak.service.cluster.AmbariClientProvider) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 9 with HostMetadata

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;
}
Also used : HashSet(java.util.HashSet) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 10 with HostMetadata

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;
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Aggregations

HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)52 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)20 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)17 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)16 HashSet (java.util.HashSet)16 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Test (org.junit.Test)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 List (java.util.List)10 Map (java.util.Map)10 Status (com.sequenceiq.cloudbreak.api.model.Status)8 Collections.singletonMap (java.util.Collections.singletonMap)8 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)7 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)7 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 LinkedHashMap (java.util.LinkedHashMap)5 Set (java.util.Set)5