Search in sources :

Example 1 with HostMetadataState

use of com.sequenceiq.cloudbreak.common.type.HostMetadataState in project cloudbreak by hortonworks.

the class AmbariClusterService method updateClusterMetadata.

@Override
@Transactional(TxType.NEVER)
public Cluster updateClusterMetadata(Long stackId) {
    Stack stack = stackService.getById(stackId);
    AmbariClient ambariClient = getAmbariClient(stack);
    Map<String, Integer> hostGroupCounter = new HashMap<>();
    Set<HostMetadata> hosts = hostMetadataRepository.findHostsInCluster(stack.getCluster().getId());
    Map<String, String> hostStatuses = ambariClient.getHostStatuses();
    for (HostMetadata host : hosts) {
        if (hostStatuses.containsKey(host.getHostName())) {
            String hgName = host.getHostGroup().getName();
            Integer hgCounter = hostGroupCounter.getOrDefault(hgName, 0) + 1;
            hostGroupCounter.put(hgName, hgCounter);
            HostMetadataState newState = HostMetadataState.HEALTHY.name().equals(hostStatuses.get(host.getHostName())) ? HostMetadataState.HEALTHY : HostMetadataState.UNHEALTHY;
            boolean stateChanged = updateHostMetadataByHostState(stack, host.getHostName(), newState);
            if (stateChanged && HostMetadataState.HEALTHY == newState) {
                updateInstanceMetadataStateToRegistered(stackId, host);
            }
        }
    }
    hostGroupCounter(stack.getCluster().getId(), hostGroupCounter);
    return stack.getCluster();
}
Also used : HashMap(java.util.HashMap) HostMetadataState(com.sequenceiq.cloudbreak.common.type.HostMetadataState) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) Transactional(javax.transaction.Transactional)

Example 2 with HostMetadataState

use of com.sequenceiq.cloudbreak.common.type.HostMetadataState 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 3 with HostMetadataState

use of com.sequenceiq.cloudbreak.common.type.HostMetadataState in project cloudbreak by hortonworks.

the class AmbariClusterService method updateHostMetadata.

@Override
public void updateHostMetadata(Long clusterId, Map<String, List<String>> hostsPerHostGroup, HostMetadataState hostMetadataState) {
    for (Entry<String, List<String>> hostGroupEntry : hostsPerHostGroup.entrySet()) {
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(clusterId, hostGroupEntry.getKey());
        if (hostGroup != null) {
            Set<String> existingHosts = hostMetadataRepository.findEmptyHostsInHostGroup(hostGroup.getId()).stream().map(HostMetadata::getHostName).collect(Collectors.toSet());
            hostGroupEntry.getValue().stream().filter(hostName -> !existingHosts.contains(hostName)).forEach(hostName -> {
                HostMetadata hostMetadataEntry = new HostMetadata();
                hostMetadataEntry.setHostName(hostName);
                hostMetadataEntry.setHostGroup(hostGroup);
                hostMetadataEntry.setHostMetadataState(hostMetadataState);
                hostGroup.getHostMetadata().add(hostMetadataEntry);
            });
            hostGroupService.save(hostGroup);
        }
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) HttpResponseException(groovyx.net.http.HttpResponseException) StatusToPollGroupConverter(com.sequenceiq.cloudbreak.converter.scheduler.StatusToPollGroupConverter) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) Pair(org.apache.commons.lang3.tuple.Pair) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostMetadataRepository(com.sequenceiq.cloudbreak.repository.HostMetadataRepository) TxType(javax.transaction.Transactional.TxType) Transactional(javax.transaction.Transactional) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) TlsSecurityService(com.sequenceiq.cloudbreak.service.TlsSecurityService) ClusterTerminationService(com.sequenceiq.cloudbreak.service.cluster.flow.ClusterTerminationService) START_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.START_REQUESTED) Set(java.util.Set) BlueprintValidator(com.sequenceiq.cloudbreak.blueprint.validation.BlueprintValidator) UserNamePasswordJson(com.sequenceiq.cloudbreak.api.model.UserNamePasswordJson) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) Stream(java.util.stream.Stream) STOP_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.STOP_REQUESTED) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) PkiUtil(com.sequenceiq.cloudbreak.client.PkiUtil) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) ArrayList(java.util.ArrayList) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) Service(org.springframework.stereotype.Service) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) KerberosConfigRepository(com.sequenceiq.cloudbreak.repository.KerberosConfigRepository) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.service.ClusterComponentConfigProvider) Stack(com.sequenceiq.cloudbreak.domain.Stack) ConversionService(org.springframework.core.convert.ConversionService) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) InMemoryStateStore(com.sequenceiq.cloudbreak.cloud.store.InMemoryStateStore) IOException(java.io.IOException) ConstraintRepository(com.sequenceiq.cloudbreak.repository.ConstraintRepository) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) StatusRequest(com.sequenceiq.cloudbreak.api.model.StatusRequest) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) X509Certificate(java.security.cert.X509Certificate) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Gateway(com.sequenceiq.cloudbreak.domain.Gateway) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) FileSystemRepository(com.sequenceiq.cloudbreak.repository.FileSystemRepository) HostMetadataState(com.sequenceiq.cloudbreak.common.type.HostMetadataState) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.REQUESTED) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) Collection(java.util.Collection) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) Collectors(java.util.stream.Collectors) List(java.util.List) Entry(java.util.Map.Entry) UPDATE_REQUESTED(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_REQUESTED) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) RdsType(com.sequenceiq.cloudbreak.api.model.rds.RdsType) HashMap(java.util.HashMap) RecoveryMode(com.sequenceiq.cloudbreak.api.model.RecoveryMode) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Status(com.sequenceiq.cloudbreak.api.model.Status) JsonHelper(com.sequenceiq.cloudbreak.json.JsonHelper) OrchestratorTypeResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Json(com.sequenceiq.cloudbreak.domain.json.Json) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) DatabaseVendor(com.sequenceiq.cloudbreak.api.model.DatabaseVendor) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AmbariClientExceptionUtil(com.sequenceiq.cloudbreak.util.AmbariClientExceptionUtil) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) ConfigsResponse(com.sequenceiq.cloudbreak.api.model.ConfigsResponse) Collections(java.util.Collections) JsonUtil(com.sequenceiq.cloudbreak.util.JsonUtil) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) StringUtils(org.springframework.util.StringUtils) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ArrayList(java.util.ArrayList) List(java.util.List) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

HostMetadataState (com.sequenceiq.cloudbreak.common.type.HostMetadataState)3 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)2 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)1 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)1 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)1 ConfigsResponse (com.sequenceiq.cloudbreak.api.model.ConfigsResponse)1 DatabaseVendor (com.sequenceiq.cloudbreak.api.model.DatabaseVendor)1 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)1 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)1 InstanceStatus (com.sequenceiq.cloudbreak.api.model.InstanceStatus)1 RecoveryMode (com.sequenceiq.cloudbreak.api.model.RecoveryMode)1 Status (com.sequenceiq.cloudbreak.api.model.Status)1 AVAILABLE (com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE)1 REQUESTED (com.sequenceiq.cloudbreak.api.model.Status.REQUESTED)1 START_REQUESTED (com.sequenceiq.cloudbreak.api.model.Status.START_REQUESTED)1 STOP_REQUESTED (com.sequenceiq.cloudbreak.api.model.Status.STOP_REQUESTED)1 UPDATE_REQUESTED (com.sequenceiq.cloudbreak.api.model.Status.UPDATE_REQUESTED)1