Search in sources :

Example 6 with UpdateClusterV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request in project cloudbreak by hortonworks.

the class StackCommonService method putScalingInWorkspace.

public FlowIdentifier putScalingInWorkspace(NameOrCrn nameOrCrn, Long workspaceId, StackScaleV4Request stackScaleV4Request) {
    User user = userService.getOrCreate(restRequestThreadLocalService.getCloudbreakUser());
    Stack stack;
    try {
        stack = transactionService.required(() -> {
            Stack stackInTransaction = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
            validateNetworkScaleRequest(stackInTransaction, stackScaleV4Request.getStackNetworkScaleV4Request());
            return stackInTransaction;
        });
    } catch (TransactionService.TransactionExecutionException e) {
        LOGGER.error("Cannot validate network scaling: {}", e.getMessage(), e);
        throw new TransactionService.TransactionRuntimeExecutionException(e);
    }
    MDCBuilder.buildMdcContext(stack);
    stackScaleV4Request.setStackId(stack.getId());
    UpdateStackV4Request updateStackJson = stackScaleV4RequestToUpdateStackV4RequestConverter.convert(stackScaleV4Request);
    Integer scalingAdjustment = updateStackJson.getInstanceGroupAdjustment().getScalingAdjustment();
    validateScalingRequest(stack, scalingAdjustment);
    FlowIdentifier flowIdentifier;
    if (scalingAdjustment > 0) {
        flowIdentifier = put(stack, updateStackJson);
    } else {
        UpdateClusterV4Request updateClusterJson = stackScaleV4RequestToUpdateClusterV4RequestConverter.convert(stackScaleV4Request);
        workspaceService.get(workspaceId, user);
        flowIdentifier = clusterCommonService.put(stack.getResourceCrn(), updateClusterJson);
    }
    return flowIdentifier;
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 7 with UpdateClusterV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request in project cloudbreak by hortonworks.

the class UserNamePasswordV4RequestToUpdateClusterV4RequestConverter method convert.

public UpdateClusterV4Request convert(UserNamePasswordV4Request source) {
    UpdateClusterV4Request updateStackJson = new UpdateClusterV4Request();
    updateStackJson.setUserNamePassword(source);
    return updateStackJson;
}
Also used : UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request)

Example 8 with UpdateClusterV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request in project cloudbreak by hortonworks.

the class ScalingRequest method scaleDown.

private void scaleDown(int scalingAdjustment, int totalNodes) {
    metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_TRIGGERED);
    String hostGroup = policy.getHostGroup();
    String statusReason = null;
    ScalingStatus scalingStatus = null;
    String stackCrn = cluster.getStackCrn();
    String userCrn = cluster.getClusterPertain().getUserCrn();
    try {
        LOGGER.info("Sending request to remove '{}' node(s) from host group '{}', triggered adjustmentType '{}', cluster '{}', user '{}'", scalingAdjustment, hostGroup, policy.getAdjustmentType(), stackCrn, userCrn);
        UpdateClusterV4Request updateClusterJson = new UpdateClusterV4Request();
        HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        hostGroupAdjustmentJson.setWithStackUpdate(true);
        hostGroupAdjustmentJson.setHostGroup(hostGroup);
        hostGroupAdjustmentJson.setValidateNodeCount(false);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        // TODO CB-14929: CB-15153 List of nodes not provided. Do we really need to support this? Can Periscope always specify the list of nodes?
        cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putCluster(stackCrn, cluster.getClusterPertain().getUserId(), updateClusterJson);
        scalingStatus = ScalingStatus.SUCCESS;
        statusReason = getMessageForCBSuccess();
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_SUCCESSFUL);
    } catch (Exception e) {
        scalingStatus = ScalingStatus.FAILED;
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_FAILED);
        statusReason = getMessageForCBException(e);
        LOGGER.error("Couldn't trigger downscaling for host group '{}', cluster '{}', desiredNodeCount '{}', error '{}' ", hostGroup, cluster.getStackCrn(), desiredHostGroupNodeCount, statusReason, e);
    } finally {
        processAutoscalingTriggered(scalingAdjustment, totalNodes, statusReason, scalingStatus);
    }
}
Also used : ScalingStatus(com.sequenceiq.periscope.api.model.ScalingStatus) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) ClientErrorException(javax.ws.rs.ClientErrorException)

Aggregations

UpdateClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 UpdateStackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request)1 HostGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupV4Request)1 UserNamePasswordV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request)1 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)1 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)1 BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)1 User (com.sequenceiq.cloudbreak.workspace.model.User)1 ScalingStatus (com.sequenceiq.periscope.api.model.ScalingStatus)1 HashSet (java.util.HashSet)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Test (org.junit.jupiter.api.Test)1