Search in sources :

Example 46 with HostMetadata

use of com.sequenceiq.cloudbreak.domain.HostMetadata 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)

Example 47 with HostMetadata

use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.

the class AmbariDecommissioner method decommissionAmbariNodes.

public Set<String> decommissionAmbariNodes(Stack stack, Map<String, HostMetadata> hostsToRemove) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp());
    AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), cluster);
    Map<String, HostMetadata> unhealthyHosts = new HashMap<>();
    Map<String, HostMetadata> healthyHosts = new HashMap<>();
    for (Entry<String, HostMetadata> hostToRemove : hostsToRemove.entrySet()) {
        if ("UNKNOWN".equals(ambariClient.getHostState(hostToRemove.getKey()))) {
            unhealthyHosts.put(hostToRemove.getKey(), hostToRemove.getValue());
        } else {
            healthyHosts.put(hostToRemove.getKey(), hostToRemove.getValue());
        }
    }
    Set<String> deletedHosts = new HashSet<>();
    Map<String, Map<String, String>> runningComponents = ambariClient.getHostComponentsStates();
    if (!unhealthyHosts.isEmpty()) {
        List<String> hostList = new ArrayList<>(hostsToRemove.keySet());
        removeHostsFromOrchestrator(stack, ambariClient, hostList);
        for (Entry<String, HostMetadata> host : unhealthyHosts.entrySet()) {
            deleteHostFromAmbari(host.getValue(), runningComponents, ambariClient);
            hostMetadataRepository.delete(host.getValue().getId());
            deletedHosts.add(host.getKey());
        }
    }
    if (!healthyHosts.isEmpty()) {
        deletedHosts.addAll(decommissionAmbariNodes(stack, healthyHosts, runningComponents, ambariClient));
    }
    return deletedHosts;
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet)

Example 48 with HostMetadata

use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.

the class AmbariDecommissioner method collectDownscaleCandidates.

private Iterable<HostMetadata> collectDownscaleCandidates(Stack stack, Cluster cluster, String hostGroupName, Integer scalingAdjustment) {
    List<HostMetadata> downScaleCandidates;
    HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp());
    HostGroup hostGroup = hostGroupService.getByClusterIdAndName(cluster.getId(), hostGroupName);
    Set<HostMetadata> hostsInHostGroup = hostGroup.getHostMetadata();
    List<HostMetadata> filteredHostList = hostFilterService.filterHostsForDecommission(cluster, hostsInHostGroup, hostGroupName);
    int reservedInstances = hostsInHostGroup.size() - filteredHostList.size();
    String blueprintName = cluster.getBlueprint().getAmbariName();
    AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), cluster);
    if (ambariClient.getBlueprintMap(blueprintName).get(hostGroupName).contains(DATANODE)) {
        int replication = getReplicationFactor(ambariClient, hostGroupName);
        verifyNodeCount(replication, scalingAdjustment, filteredHostList.size(), reservedInstances);
        downScaleCandidates = checkAndSortByAvailableSpace(stack, ambariClient, replication, scalingAdjustment, filteredHostList);
    } else {
        verifyNodeCount(NO_REPLICATION, scalingAdjustment, filteredHostList.size(), reservedInstances);
        downScaleCandidates = filteredHostList;
    }
    return downScaleCandidates;
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 49 with HostMetadata

use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.

the class AmbariClusterModificationService method startCluster.

@Override
public int startCluster(Stack stack) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    PollingResult ambariHealthCheckResult = ambariPollingServiceProvider.ambariHealthChecker(stack, ambariClient);
    if (isExited(ambariHealthCheckResult)) {
        throw new CancellationException("Cluster was terminated while waiting for Ambari to start.");
    } else if (isTimeout(ambariHealthCheckResult)) {
        throw new CloudbreakException("Ambari server was not restarted properly.");
    }
    LOGGER.info("Starting Ambari agents on the hosts.");
    Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(stack.getCluster().getId());
    PollingResult hostsJoinedResult = ambariPollingServiceProvider.ambariHostJoin(stack, ambariClient, hostsInCluster);
    if (isExited(hostsJoinedResult)) {
        throw new CancellationException("Cluster was terminated while starting Ambari agents.");
    }
    LOGGER.info("Start all Hadoop services");
    eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STARTING.code()));
    int requestId = ambariClient.startAllServices();
    if (requestId == -1) {
        LOGGER.error("Failed to start Hadoop services.");
        throw new CloudbreakException("Failed to start Hadoop services.");
    }
    return requestId;
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 50 with HostMetadata

use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.

the class TestUtil method hostMetadata.

public static Set<HostMetadata> hostMetadata(HostGroup hostGroup, int count) {
    Set<HostMetadata> hostMetadataSet = new HashSet<>();
    for (int i = 1; i <= count; i++) {
        HostMetadata hostMetadata = new HostMetadata();
        hostMetadata.setHostName("hostname-" + (i + 1));
        hostMetadata.setHostGroup(hostGroup);
        hostMetadataSet.add(hostMetadata);
    }
    return hostMetadataSet;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet)

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