Search in sources :

Example 6 with StackScaleV4Request

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

the class DistroXV1Controller method putScalingByCrn.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.SCALE_DATAHUB)
public void putScalingByCrn(@ValidCrn(resource = CrnResourceDescriptor.DATAHUB) @TenantAwareParam @ResourceCrn String crn, @Valid DistroXScaleV1Request updateRequest) {
    StackScaleV4Request stackScaleV4Request = scaleRequestConverter.convert(updateRequest);
    stackScaleV4Request.setStackId(stackOperations.getStackByCrn(crn).getId());
    stackOperations.putScaling(NameOrCrn.ofCrn(crn), getWorkspaceIdForCurrentUser(), stackScaleV4Request);
}
Also used : StackScaleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackScaleV4Request) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 7 with StackScaleV4Request

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

the class StackCommonServiceTest method testPutScalingInWorkspaceWhenThereIsPreferredAzAndStackProvisionedInMultipleSubnetButScalingIsNotSupportedOnPlatform.

@Test
public void testPutScalingInWorkspaceWhenThereIsPreferredAzAndStackProvisionedInMultipleSubnetButScalingIsNotSupportedOnPlatform() throws TransactionService.TransactionExecutionException {
    Stack stack = new Stack();
    stack.setCloudPlatform(AwsConstants.AWS_PLATFORM.value());
    String variant = AwsConstants.AwsVariant.AWS_NATIVE_VARIANT.name();
    stack.setPlatformVariant(variant);
    when(transactionService.required(any(Supplier.class))).thenReturn(stack);
    NetworkScaleV4Request networkScaleV4Request = new NetworkScaleV4Request();
    networkScaleV4Request.setPreferredSubnetIds(List.of(SUBNET_ID));
    StackScaleV4Request updateRequest = new StackScaleV4Request();
    updateRequest.setStackNetworkScaleV4Request(networkScaleV4Request);
    UpdateStackV4Request updateStackV4Request = new UpdateStackV4Request();
    InstanceGroupAdjustmentV4Request instanceGroupAdjustment = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustment.setScalingAdjustment(1);
    updateStackV4Request.setInstanceGroupAdjustment(instanceGroupAdjustment);
    when(stackScaleV4RequestToUpdateStackV4RequestConverter.convert(any())).thenReturn(updateStackV4Request);
    when(cloudParameterCache.isUpScalingSupported(anyString())).thenReturn(Boolean.FALSE);
    BadRequestException actual = assertThrows(BadRequestException.class, () -> underTest.putScalingInWorkspace(STACK_NAME, WORKSPACE_ID, updateRequest));
    assertEquals(actual.getMessage(), "Upscaling is not supported on AWS cloudplatform");
}
Also used : NetworkScaleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkScaleV4Request) StackScaleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackScaleV4Request) 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) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 8 with StackScaleV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackScaleV4Request 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)

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