Search in sources :

Example 1 with HostOrchestrator

use of com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator in project cloudbreak by hortonworks.

the class ClusterHostServiceRunner method runAmbariServices.

@Transactional
public void runAmbariServices(Stack stack, Cluster cluster) throws CloudbreakException {
    try {
        Set<Node> nodes = collectNodes(stack);
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        SaltConfig saltConfig = createSaltConfig(stack, cluster, primaryGatewayConfig, gatewayConfigs);
        hostOrchestrator.runService(gatewayConfigs, nodes, saltConfig, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
    } catch (CloudbreakOrchestratorCancelledException e) {
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException | IOException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) IOException(java.io.IOException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Transactional(javax.transaction.Transactional)

Example 2 with HostOrchestrator

use of com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator in project cloudbreak by hortonworks.

the class AmbariDecommissioner method removeHostsFromOrchestrator.

private PollingResult removeHostsFromOrchestrator(Stack stack, AmbariClient ambariClient, List<String> hostNames) throws CloudbreakException {
    Orchestrator orchestrator = stack.getOrchestrator();
    Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
    OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
    try {
        if (orchestratorType.containerOrchestrator()) {
            OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
            ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
            Set<Container> containers = containerRepository.findContainersInCluster(stack.getCluster().getId());
            List<ContainerInfo> containersToDelete = containers.stream().filter(input -> hostNames.contains(input.getHost()) && input.getImage().contains(AMBARI_AGENT.getName())).map(input -> new ContainerInfo(input.getContainerId(), input.getName(), input.getHost(), input.getImage())).collect(Collectors.toList());
            containerOrchestrator.deleteContainer(containersToDelete, credential);
            containerRepository.delete(containers);
            return waitForHostsToLeave(stack, ambariClient, hostNames);
        } else if (orchestratorType.hostOrchestrator()) {
            HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
            Map<String, String> privateIpsByFQDN = new HashMap<>();
            stack.getInstanceMetaDataAsList().stream().filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.contains(instanceMetaData.getDiscoveryFQDN().split("\\.")[0]))).forEach(instanceMetaData -> privateIpsByFQDN.put(instanceMetaData.getDiscoveryFQDN(), instanceMetaData.getPrivateIp()));
            List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
            hostOrchestrator.tearDown(allGatewayConfigs, privateIpsByFQDN);
        }
    } catch (CloudbreakOrchestratorException e) {
        LOGGER.error("Failed to delete orchestrator components while decommissioning: ", e);
        throw new CloudbreakException("Failed to delete orchestrator components while decommissioning: ", e);
    }
    return SUCCESS;
}
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) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HashMap(java.util.HashMap) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) 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) AmbariClientPollerObject(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariClientPollerObject) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap)

Example 3 with HostOrchestrator

use of com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method postAmbariStartRecipes.

public void postAmbariStartRecipes(Stack stack) throws CloudbreakException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
    try {
        hostOrchestrator.postAmbariStartRecipes(gatewayConfig, collectNodes(stack), clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
    } catch (CloudbreakOrchestratorFailedException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 4 with HostOrchestrator

use of com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator in project cloudbreak by hortonworks.

the class OrchestratorRecipeExecutor method uploadRecipes.

public void uploadRecipes(Stack stack, Collection<HostGroup> hostGroups) throws CloudbreakException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    Map<String, List<RecipeModel>> recipeMap = hostGroups.stream().filter(hg -> !hg.getRecipes().isEmpty()).collect(Collectors.toMap(HostGroup::getName, h -> convert(h.getRecipes())));
    List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
    recipesEvent(stack.getId(), stack.getStatus(), recipeMap);
    try {
        hostOrchestrator.uploadRecipes(allGatewayConfigs, recipeMap, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
    } catch (CloudbreakOrchestratorFailedException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Joiner(com.google.api.client.util.Joiner) Base64(org.apache.commons.codec.binary.Base64) ArrayList(java.util.ArrayList) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Status(com.sequenceiq.cloudbreak.api.model.Status) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Collection(java.util.Collection) Set(java.util.Set) DEFAULT_RECIPES(com.sequenceiq.cloudbreak.service.cluster.flow.RecipeEngine.DEFAULT_RECIPES) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) Collectors(java.util.stream.Collectors) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) Component(org.springframework.stereotype.Component) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Entry(java.util.Map.Entry) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Collections(java.util.Collections) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArrayList(java.util.ArrayList) List(java.util.List) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 5 with HostOrchestrator

use of com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator in project cloudbreak by hortonworks.

the class HostMetadataSetup method updateWithHostData.

private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) throws CloudbreakSecuritySetupException {
    try {
        List<String> privateIps = metadataToUpdate.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
        GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
        LOGGER.info("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
        for (InstanceMetaData instanceMetaData : metadataToUpdate) {
            instanceMetaData.setConsulServer(false);
            String address = members.get(instanceMetaData.getPrivateIp());
            instanceMetaData.setDiscoveryFQDN(address);
            LOGGER.info("Domain used for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), address, instanceMetaData.getDiscoveryFQDN());
        }
    } catch (Exception e) {
        throw new CloudbreakSecuritySetupException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)14 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)12 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)7 Stack (com.sequenceiq.cloudbreak.domain.Stack)6 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)6 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)5 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)5 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)5 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)4 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)4 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 HostOrchestratorResolver (com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver)3 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)3 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)3 GatewayConfigService (com.sequenceiq.cloudbreak.service.GatewayConfigService)3 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)2 HostBootstrapApiContext (com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext)2