Search in sources :

Example 31 with HostGroup

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

the class HostGroupDecorator method getHostGroupByInstanceGroupName.

private HostGroup getHostGroupByInstanceGroupName(Constraint constraint, HostGroup subject, Cluster cluster, String instanceGroupName) {
    HostGroup result = subject;
    Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
    if (hostGroups.isEmpty()) {
        Stack stack = cluster.getStack();
        if (stack == null) {
            String msg = String.format("There is no stack associated to cluster (id:'%s', name: '%s')!", cluster.getId(), cluster.getName());
            throw new BadRequestException(msg);
        } else {
            subject.setConstraint(constraint);
        }
    } else {
        result = getDetailsFromExistingHostGroup(constraint, subject, instanceGroupName, hostGroups);
    }
    return result;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 32 with HostGroup

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

the class AmbariClusterModificationService method upscaleCluster.

@Override
public void upscaleCluster(Stack stack, HostGroup hostGroup, Collection<HostMetadata> hostMetadata) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    List<String> upscaleHostNames = hostMetadata.stream().map(HostMetadata::getHostName).collect(Collectors.toList()).stream().filter(hostName -> !ambariClient.getClusterHosts().contains(hostName)).collect(Collectors.toList());
    if (!upscaleHostNames.isEmpty()) {
        recipeEngine.executePostAmbariStartRecipes(stack, Sets.newHashSet(hostGroup));
        Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperations(stack, ambariClient, installServices(upscaleHostNames, stack, ambariClient, hostGroup.getName()), UPSCALE_AMBARI_PROGRESS_STATE);
        String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_UPSCALE_FAILED.code()) : pollingResult.getRight().getMessage();
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) HttpResponseException(groovyx.net.http.HttpResponseException) LoggerFactory(org.slf4j.LoggerFactory) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_IN_PROGRESS) UPSCALE_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.UPSCALE_AMBARI_PROGRESS_STATE) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) Inject(javax.inject.Inject) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) Pair(org.apache.commons.lang3.tuple.Pair) PollingResult.isTimeout(com.sequenceiq.cloudbreak.service.PollingResult.isTimeout) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) RecipeEngine(com.sequenceiq.cloudbreak.service.cluster.flow.RecipeEngine) Service(org.springframework.stereotype.Service) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) ClusterModificationService(com.sequenceiq.cloudbreak.service.cluster.api.ClusterModificationService) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadataRepository(com.sequenceiq.cloudbreak.repository.HostMetadataRepository) AMBARI_CLUSTER_UPSCALE_FAILED(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_UPSCALE_FAILED) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) AMBARI_CLUSTER_SERVICES_STOPPED(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_SERVICES_STOPPED) Logger(org.slf4j.Logger) AMBARI_CLUSTER_SERVICES_STARTING(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_SERVICES_STARTING) Collection(java.util.Collection) Set(java.util.Set) AmbariClientExceptionUtil(com.sequenceiq.cloudbreak.util.AmbariClientExceptionUtil) Collectors(java.util.stream.Collectors) PollingResult.isExited(com.sequenceiq.cloudbreak.service.PollingResult.isExited) Sets(com.google.common.collect.Sets) AMBARI_CLUSTER_SERVICES_STOPPING(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariMessages.AMBARI_CLUSTER_SERVICES_STOPPING) List(java.util.List) AmbariOperationService(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariOperationService) STOP_AMBARI_PROGRESS_STATE(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariOperationType.STOP_AMBARI_PROGRESS_STATE) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) HttpResponseException(groovyx.net.http.HttpResponseException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 33 with HostGroup

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

the class AmbariClusterSetupService method buildCluster.

@Override
public void buildCluster(Stack stack) {
    Cluster cluster = stack.getCluster();
    try {
        clusterService.updateCreationDateOnCluster(cluster);
        AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
        Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
        BlueprintPreparationObject blueprintPreparationObject = conversionService.convert(stack, BlueprintPreparationObject.class);
        Map<String, List<Map<String, String>>> hostGroupMappings = hostGroupAssociationBuilder.buildHostGroupAssociations(hostGroups);
        Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(cluster.getId());
        recipeEngine.executePostAmbariStartRecipes(stack, hostGroups);
        ambariRepositoryVersionService.setBaseRepoURL(stack.getName(), cluster.getId(), stack.getOrchestrator(), ambariClient);
        String blueprintText = centralBlueprintUpdater.getBlueprintText(blueprintPreparationObject);
        addBlueprint(stack.getId(), ambariClient, blueprintText, cluster.getTopologyValidation());
        cluster.setExtendedBlueprintText(blueprintText);
        clusterService.updateCluster(cluster);
        PollingResult waitForHostsResult = ambariPollingServiceProvider.hostsPollingService(stack, ambariClient, hostsInCluster);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(waitForHostsResult, cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_HOST_JOIN_FAILED.code()));
        ambariClusterTemplateService.addClusterTemplate(cluster, hostGroupMappings, ambariClient);
        Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperationsToStart(stack, ambariClient, singletonMap("INSTALL_START", 1), START_OPERATION_STATE);
        String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()) : pollingResult.getRight().getMessage();
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
        Pair<PollingResult, Exception> pollingResultExceptionPair = ambariOperationService.waitForOperations(stack, ambariClient, new HashMap<String, Integer>() {

            {
                put("CLUSTER_INSTALL", 1);
            }
        }, INSTALL_AMBARI_PROGRESS_STATE);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResultExceptionPair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()));
        recipeEngine.executePostInstall(stack);
        ambariSmartSenseCapturer.capture(0, ambariClient);
        cluster = ambariViewProvider.provideViewInformation(ambariClient, cluster);
        ambariClusterCreationSuccessHandler.handleClusterCreationSuccess(stack, cluster);
    } catch (CancellationException cancellationException) {
        throw cancellationException;
    } catch (HttpResponseException hre) {
        throw new AmbariOperationFailedException("Ambari could not create the cluster: " + AmbariClientExceptionUtil.getErrorMessage(hre), hre);
    } catch (Exception e) {
        LOGGER.error("Error while building the Ambari cluster. Message {}, throwable: {}", e.getMessage(), e);
        throw new AmbariOperationFailedException(e.getMessage(), e);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) BlueprintPreparationObject(com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject) List(java.util.List) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 34 with HostGroup

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

the class RecipeEngine method addHDFSRecipe.

private void addHDFSRecipe(Cluster cluster, String blueprintText, Iterable<HostGroup> hostGroups) {
    try {
        for (HostGroup hostGroup : hostGroups) {
            if (isComponentPresent(blueprintText, "NAMENODE", hostGroup)) {
                String script = FileReaderUtils.readFileFromClasspath("scripts/hdfs-home.sh").replaceAll("\\$USER", cluster.getUserName());
                RecipeScript recipeScript = new RecipeScript(script, RecipeType.POST_CLUSTER_INSTALL);
                Recipe recipe = recipeBuilder.buildRecipes("hdfs-home", Collections.singletonList(recipeScript)).get(0);
                hostGroup.addRecipe(recipe);
                break;
            }
        }
    } catch (IOException e) {
        LOGGER.warn("Cannot create HDFS home dir recipe", e);
    }
}
Also used : RecipeScript(com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) IOException(java.io.IOException)

Example 35 with HostGroup

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

the class RecipeEngine method addContainerExecutorScripts.

private void addContainerExecutorScripts(Stack stack, Iterable<HostGroup> hostGroups) {
    try {
        Cluster cluster = stack.getCluster();
        if (cluster != null && ExecutorType.CONTAINER.equals(cluster.getExecutorType())) {
            for (HostGroup hostGroup : hostGroups) {
                String script = FileReaderUtils.readFileFromClasspath("scripts/configure-container-executor.sh");
                RecipeScript recipeScript = new RecipeScript(script, RecipeType.POST_CLUSTER_INSTALL);
                Recipe recipe = recipeBuilder.buildRecipes("getConfigurationEntries-container-executor", Collections.singletonList(recipeScript)).get(0);
                hostGroup.addRecipe(recipe);
            }
        }
    } catch (IOException e) {
        LOGGER.warn("Cannot getConfigurationEntries container executor", e);
    }
}
Also used : RecipeScript(com.sequenceiq.cloudbreak.common.model.recipe.RecipeScript) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) IOException(java.io.IOException)

Aggregations

HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)94 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)33 Test (org.junit.Test)33 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)31 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)29 HashSet (java.util.HashSet)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)20 List (java.util.List)20 HashMap (java.util.HashMap)19 Stack (com.sequenceiq.cloudbreak.domain.Stack)18 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)16 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)15 Map (java.util.Map)14 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)13 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)11 ArrayList (java.util.ArrayList)11 Set (java.util.Set)11 Inject (javax.inject.Inject)11