Search in sources :

Example 1 with StackScaleV4Request

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

the class DistroXScaleV1RequestToStackScaleV4RequestConverter method setStackNetworkScaleRequest.

private void setStackNetworkScaleRequest(NetworkScaleV1Request networkScaleV1Request, StackScaleV4Request stackScaleV4Request) {
    if (networkScaleV1Request != null) {
        NetworkScaleV4Request networkScaleV4Request = new NetworkScaleV4Request();
        networkScaleV4Request.setPreferredSubnetIds(networkScaleV1Request.getPreferredSubnetIds());
        stackScaleV4Request.setStackNetworkScaleV4Request(networkScaleV4Request);
    }
}
Also used : NetworkScaleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkScaleV4Request)

Example 2 with StackScaleV4Request

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

the class DistroXScaleV1RequestToStackScaleV4RequestConverter method convert.

public StackScaleV4Request convert(DistroXScaleV1Request source) {
    StackScaleV4Request stackScaleV4Request = new StackScaleV4Request();
    stackScaleV4Request.setDesiredCount(source.getDesiredCount());
    stackScaleV4Request.setGroup(source.getGroup());
    stackScaleV4Request.setAdjustmentType(source.getAdjustmentType());
    stackScaleV4Request.setThreshold(source.getThreshold());
    setStackNetworkScaleRequest(source.getNetworkScaleRequest(), stackScaleV4Request);
    return stackScaleV4Request;
}
Also used : StackScaleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackScaleV4Request)

Example 3 with StackScaleV4Request

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

the class DistroXV1Controller method putScalingByName.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.SCALE_DATAHUB)
public FlowIdentifier putScalingByName(@ResourceName String name, @Valid DistroXScaleV1Request updateRequest) {
    StackScaleV4Request stackScaleV4Request = scaleRequestConverter.convert(updateRequest);
    stackScaleV4Request.setStackId(stackOperations.getStackByName(name).getId());
    return stackOperations.putScaling(NameOrCrn.ofName(name), getWorkspaceIdForCurrentUser(), stackScaleV4Request);
}
Also used : StackScaleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackScaleV4Request) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Example 4 with StackScaleV4Request

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

the class StackScaleV4RequestToUpdateClusterV4RequestConverter method convert.

public UpdateClusterV4Request convert(StackScaleV4Request source) {
    try {
        return transactionService.required(() -> {
            UpdateClusterV4Request updateStackJson = new UpdateClusterV4Request();
            Stack stack = stackService.getByIdWithListsInTransaction(source.getStackId());
            stack.getInstanceGroups().stream().filter(instanceGroup -> source.getGroup().equals(instanceGroup.getGroupName())).findFirst().ifPresentOrElse(instanceGroup -> {
                String blueprintText = stack.getCluster().getBlueprint().getBlueprintText();
                BlueprintTextProcessor blueprintTextProcessor = clusterDefinitionTextProcessorFactory.createBlueprintTextProcessor(blueprintText);
                boolean dataNodeComponentInHostGroup = blueprintTextProcessor.isComponentExistsInHostGroup("DATANODE", instanceGroup.getGroupName());
                HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
                hostGroupAdjustmentJson.setWithStackUpdate(true);
                hostGroupAdjustmentJson.setValidateNodeCount(dataNodeComponentInHostGroup);
                hostGroupAdjustmentJson.setHostGroup(source.getGroup());
                hostGroupAdjustmentJson.setForced(source.getForced());
                int scaleNumber = source.getDesiredCount() - instanceGroup.getNotTerminatedInstanceMetaDataSet().size();
                hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
                updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
            }, () -> {
                throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
            });
            return updateStackJson;
        });
    } catch (TransactionExecutionException e) {
        throw e.getCause();
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 5 with StackScaleV4Request

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

the class StackScaleV4RequestToUpdateStackV4RequestConverter method convert.

public UpdateStackV4Request convert(StackScaleV4Request source) {
    UpdateStackV4Request updateStackJson = new UpdateStackV4Request();
    updateStackJson.setWithClusterEvent(true);
    Optional<InstanceGroup> instanceGroup = instanceGroupService.findOneWithInstanceMetadataByGroupNameInStack(source.getStackId(), source.getGroup());
    if (instanceGroup.isPresent()) {
        InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson = new InstanceGroupAdjustmentV4Request();
        instanceGroupAdjustmentJson.setInstanceGroup(source.getGroup());
        int scaleNumber = source.getDesiredCount() - instanceGroup.get().getNodeCount();
        instanceGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
        instanceGroupAdjustmentJson.setNetworkScaleRequest(source.getStackNetworkScaleV4Request());
        instanceGroupAdjustmentJson.setAdjustmentType(source.getAdjustmentType());
        instanceGroupAdjustmentJson.setThreshold(source.getThreshold());
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
    } else {
        throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
    }
    return updateStackJson;
}
Also used : UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Aggregations

StackScaleV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackScaleV4Request)4 UpdateStackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 InstanceGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)2 UpdateClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request)2 NetworkScaleV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkScaleV4Request)2 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)1 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)1 User (com.sequenceiq.cloudbreak.workspace.model.User)1 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1 Supplier (java.util.function.Supplier)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1