Search in sources :

Example 21 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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 22 with Cluster

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

Example 23 with Cluster

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

the class ClusterTerminationService method deleteClusterContainers.

public Boolean deleteClusterContainers(Cluster cluster) {
    try {
        Orchestrator orchestrator = cluster.getStack().getOrchestrator();
        ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
        try {
            Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
            OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
            Set<Container> containers = containerRepository.findContainersInCluster(cluster.getId());
            List<ContainerInfo> containerInfo = containers.stream().map(c -> new ContainerInfo(c.getContainerId(), c.getName(), c.getHost(), c.getImage())).collect(Collectors.toList());
            containerOrchestrator.deleteContainer(containerInfo, credential);
            containerRepository.delete(containers);
            deleteClusterHostGroupsWithItsMetadata(cluster);
        } catch (CloudbreakOrchestratorException e) {
            throw new TerminationFailedException(String.format("Failed to delete containers of cluster (id:'%s',name:'%s').", cluster.getId(), cluster.getName()), e);
        }
        return Boolean.TRUE;
    } catch (CloudbreakException ignored) {
        return Boolean.FALSE;
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Date(java.util.Date) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) HostGroupRepository(com.sequenceiq.cloudbreak.repository.HostGroupRepository) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException) HashSet(java.util.HashSet) Inject(javax.inject.Inject) FileSystemConfiguration(com.sequenceiq.cloudbreak.api.model.FileSystemConfiguration) OrchestratorTypeResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver) RdsConfigService(com.sequenceiq.cloudbreak.service.rdsconfig.RdsConfigService) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Map(java.util.Map) FileSystemType(com.sequenceiq.cloudbreak.api.model.FileSystemType) FileSystemConfigurator(com.sequenceiq.cloudbreak.blueprint.filesystem.FileSystemConfigurator) DELETE_COMPLETED(com.sequenceiq.cloudbreak.api.model.Status.DELETE_COMPLETED) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) ContainerRepository(com.sequenceiq.cloudbreak.repository.ContainerRepository) LinkedList(java.util.LinkedList) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) Logger(org.slf4j.Logger) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) Transactional(javax.transaction.Transactional) Collection(java.util.Collection) Resource(javax.annotation.Resource) JsonUtil.writeValueAsString(com.sequenceiq.cloudbreak.util.JsonUtil.writeValueAsString) Set(java.util.Set) IOException(java.io.IOException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) JsonUtil.readValue(com.sequenceiq.cloudbreak.util.JsonUtil.readValue) Container(com.sequenceiq.cloudbreak.domain.Container) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) List(java.util.List) Component(org.springframework.stereotype.Component) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) ConstraintRepository(com.sequenceiq.cloudbreak.repository.ConstraintRepository) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) ComponentConfigProvider(com.sequenceiq.cloudbreak.service.ComponentConfigProvider) HashMap(java.util.HashMap) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) JsonUtil.writeValueAsString(com.sequenceiq.cloudbreak.util.JsonUtil.writeValueAsString) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) Container(com.sequenceiq.cloudbreak.domain.Container) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException)

Example 24 with Cluster

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

the class ConsulServerFilter method filter.

@Override
public List<HostMetadata> filter(long clusterId, Map<String, String> config, List<HostMetadata> hosts) {
    List<HostMetadata> copy = new ArrayList<>(hosts);
    Cluster cluster = clusterRepository.findById(clusterId);
    for (HostMetadata host : hosts) {
        InstanceMetaData instanceMetaData = instanceMetadataRepository.findHostInStack(cluster.getStack().getId(), host.getHostName());
        if (instanceMetaData != null && instanceMetaData.getConsulServer()) {
            copy.remove(host);
        }
    }
    return copy;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 25 with Cluster

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

the class RDSConfigToRDSConfigResponseConverter method convert.

@Override
public RDSConfigResponse convert(RDSConfig source) {
    RDSConfigResponse json = new RDSConfigResponse();
    json.setId(source.getId());
    json.setName(source.getName());
    json.setConnectionURL(source.getConnectionURL());
    json.setDatabaseEngine(source.getDatabaseEngine());
    json.setConnectionDriver(source.getConnectionDriver());
    json.setPublicInAccount(source.isPublicInAccount());
    json.setCreationDate(source.getCreationDate());
    if (source.getClusters() != null) {
        json.setClusterNames(source.getClusters().stream().map(Cluster::getName).collect(Collectors.toSet()));
    } else {
        json.setClusterNames(new HashSet<>());
    }
    json.setStackVersion(source.getStackVersion());
    json.setType(source.getType());
    return json;
}
Also used : RDSConfigResponse(com.sequenceiq.cloudbreak.api.model.rds.RDSConfigResponse) Cluster(com.sequenceiq.cloudbreak.domain.Cluster)

Aggregations

Cluster (com.sequenceiq.cloudbreak.domain.Cluster)144 Stack (com.sequenceiq.cloudbreak.domain.Stack)68 Test (org.junit.Test)64 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)31 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)26 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)22 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)22 HashMap (java.util.HashMap)22 HashSet (java.util.HashSet)15 List (java.util.List)15 ArrayList (java.util.ArrayList)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)11 Matchers.anyString (org.mockito.Matchers.anyString)11 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)10 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 Json (com.sequenceiq.cloudbreak.domain.json.Json)9 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)9