Search in sources :

Example 91 with HostGroup

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

the class ClusterDownscaleService method updateMetadata.

public void updateMetadata(Long stackId, Collection<String> hostNames, String hostGroupName) {
    StackView stackView = stackService.getByIdView(stackId);
    ClusterView clusterView = stackView.getClusterView();
    hostNames.forEach(hn -> {
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(clusterView.getId(), hostGroupName);
        List<HostMetadata> hostMetaToRemove = hostGroup.getHostMetadata().stream().filter(md -> hostNames.contains(md.getHostName())).collect(Collectors.toList());
        hostGroup.getHostMetadata().removeAll(hostMetaToRemove);
        hostGroupService.save(hostGroup);
    });
    LOGGER.info("Start updating metadata");
    for (String hostName : hostNames) {
        stackService.updateMetaDataStatus(stackView.getId(), hostName, InstanceStatus.DECOMMISSIONED);
    }
    clusterService.updateClusterStatusByStackId(stackView.getId(), AVAILABLE);
    flowMessageService.fireEventAndLog(stackId, Msg.AMBARI_CLUSTER_SCALED_DOWN, AVAILABLE.name());
}
Also used : ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_FAILED) LoggerFactory(org.slf4j.LoggerFactory) Msg(com.sequenceiq.cloudbreak.core.flow2.stack.Msg) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) Inject(javax.inject.Inject) Status(com.sequenceiq.cloudbreak.api.model.Status) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) Service(org.springframework.stereotype.Service) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Collection(java.util.Collection) Set(java.util.Set) FlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.FlowMessageService) NotEnoughNodeException(com.sequenceiq.cloudbreak.service.cluster.NotEnoughNodeException) Collectors(java.util.stream.Collectors) StackUpdater(com.sequenceiq.cloudbreak.repository.StackUpdater) List(java.util.List) ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) CollectionUtils(org.springframework.util.CollectionUtils) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 92 with HostGroup

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

the class StackPreTerminationHandler method accept.

@Override
public void accept(Event<StackPreTerminationRequest> requestEvent) {
    StackPreTerminationRequest request = requestEvent.getData();
    Stack stack = stackService.getByIdWithLists(request.getStackId());
    try {
        Cluster cluster = stack.getCluster();
        if (cluster != null) {
            Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
            recipeEngine.executePreTerminationRecipes(stack, hostGroups);
        }
    } catch (Exception ex) {
        LOGGER.error("Pre-termination failed: {}", ex.getMessage(), ex);
    }
    Selectable result = new StackPreTerminationSuccess(stack.getId());
    eventBus.notify(result.selector(), new Event<>(requestEvent.getHeaders(), result));
}
Also used : StackPreTerminationRequest(com.sequenceiq.cloudbreak.reactor.api.event.recipe.StackPreTerminationRequest) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) StackPreTerminationSuccess(com.sequenceiq.cloudbreak.reactor.api.event.recipe.StackPreTerminationSuccess) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 93 with HostGroup

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

the class UploadRecipesHandler method accept.

@Override
public void accept(Event<UploadRecipesRequest> event) {
    UploadRecipesRequest request = event.getData();
    Selectable result;
    Long stackId = request.getStackId();
    try {
        Stack stack = stackService.getByIdWithLists(stackId);
        Set<HostGroup> hostGroups = hostGroupService.getByCluster(stack.getCluster().getId());
        recipeEngine.uploadRecipes(stack, hostGroups);
        result = new UploadRecipesSuccess(stackId);
    } catch (Exception e) {
        LOGGER.error("Failed to upload recipes", e);
        result = new UploadRecipesFailed(stackId, e);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : UploadRecipesFailed(com.sequenceiq.cloudbreak.reactor.api.event.recipe.UploadRecipesFailed) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) UploadRecipesSuccess(com.sequenceiq.cloudbreak.reactor.api.event.recipe.UploadRecipesSuccess) UploadRecipesRequest(com.sequenceiq.cloudbreak.reactor.api.event.recipe.UploadRecipesRequest) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 94 with HostGroup

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

the class DecommissionHandler method executePreTerminationRecipes.

private void executePreTerminationRecipes(Stack stack, String hostGroupName, Collection<String> hostNames) {
    try {
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroupName);
        recipeEngine.executePreTerminationRecipes(stack, Collections.singleton(hostGroup), hostNames);
    } catch (Exception ex) {
        LOGGER.error(ex.getLocalizedMessage(), ex);
    }
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup)

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