Search in sources :

Example 1 with InstanceGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class UpdateStackRequestValidator method isValid.

@Override
public boolean isValid(UpdateStackV4Request value, ConstraintValidatorContext context) {
    int updateResources = 0;
    if (value.getStatus() != null) {
        updateResources++;
    }
    InstanceGroupAdjustmentV4Request instanceGroupAdjustment = value.getInstanceGroupAdjustment();
    if (instanceGroupAdjustment != null) {
        updateResources++;
        if (value.getWithClusterEvent() && instanceGroupAdjustment.getScalingAdjustment() < 0) {
            ValidatorUtil.addConstraintViolation(context, "Invalid PUT request on this resource. Update event has to be upscale if you define withClusterEvent = 'true'.", "status");
            return false;
        }
    }
    if (updateResources != 1) {
        ValidatorUtil.addConstraintViolation(context, "Invalid PUT request on this resource. 1 update request is allowed at a time.", "status");
        return false;
    }
    return true;
}
Also used : InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)

Example 2 with InstanceGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class StackOperationServiceTest method testUpdateNodeCountAndCheckDownscaleAndUpscaleStatusChange.

@Test
public void testUpdateNodeCountAndCheckDownscaleAndUpscaleStatusChange() throws TransactionService.TransactionExecutionException {
    Stack stack = new Stack();
    stack.setId(9876L);
    stack.setStackStatus(new StackStatus(stack, AVAILABLE));
    InstanceGroupAdjustmentV4Request upscaleAdjustment = new InstanceGroupAdjustmentV4Request();
    upscaleAdjustment.setScalingAdjustment(5);
    when(transactionService.required(any(Supplier.class))).thenAnswer(ans -> ((Supplier) ans.getArgument(0)).get());
    when(stackService.getByIdWithLists(stack.getId())).thenReturn(stack);
    when(targetedUpscaleSupportService.targetedUpscaleOperationSupported(any())).thenReturn(Boolean.TRUE);
    doNothing().when(updateNodeCountValidator).validateServiceRoles(any(), any(InstanceGroupAdjustmentV4Request.class));
    doNothing().when(updateNodeCountValidator).validateInstanceGroup(any(), any());
    doNothing().when(updateNodeCountValidator).validateScalabilityOfInstanceGroup(any(), any(InstanceGroupAdjustmentV4Request.class));
    doNothing().when(updateNodeCountValidator).validateScalingAdjustment(any(InstanceGroupAdjustmentV4Request.class), any());
    doNothing().when(updateNodeCountValidator).validateHostGroupIsPresent(any(InstanceGroupAdjustmentV4Request.class), any());
    underTest.updateNodeCount(stack, upscaleAdjustment, true);
    verify(stackUpdater).updateStackStatus(stack.getId(), DetailedStackStatus.UPSCALE_REQUESTED, "Requested node count for upscaling: " + upscaleAdjustment.getScalingAdjustment());
    verify(flowManager).triggerStackUpscale(stack.getId(), upscaleAdjustment, true);
    verify(updateNodeCountValidator, times(0)).validateInstanceStatuses(any(), any());
    verify(updateNodeCountValidator, times(0)).validataHostMetadataStatuses(any(), any());
    InstanceGroupAdjustmentV4Request downscaleAdjustment = new InstanceGroupAdjustmentV4Request();
    downscaleAdjustment.setScalingAdjustment(-5);
    underTest.updateNodeCount(stack, downscaleAdjustment, true);
    verify(stackUpdater).updateStackStatus(stack.getId(), DetailedStackStatus.DOWNSCALE_REQUESTED, "Requested node count for downscaling: " + 5);
    verify(flowManager).triggerStackDownscale(stack.getId(), downscaleAdjustment);
    when(targetedUpscaleSupportService.targetedUpscaleOperationSupported(any())).thenReturn(Boolean.FALSE);
    underTest.updateNodeCount(stack, upscaleAdjustment, true);
    verify(updateNodeCountValidator, times(2)).validateInstanceStatuses(any(), any());
    verify(updateNodeCountValidator, times(2)).validataHostMetadataStatuses(any(), any());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Supplier(java.util.function.Supplier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with InstanceGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class UpdateNodeCountValidatorTest method testValidateScalabilityOfInstanceGroup.

@ParameterizedTest(name = "The master node count is {0} this will be scaled with {2} " + "node and the minimum is {1} the ScalabilityOption is {3}.")
@MethodSource("testValidateScalabilityOfInstanceGroupData")
public void testValidateScalabilityOfInstanceGroup(int instanceGroupNodeCount, int minimumNodeCount, int scalingNodeCount, ScalabilityOption scalabilityOption, Optional<String> errorMessageSegment) {
    Stack stack = mock(Stack.class);
    InstanceGroupAdjustmentV4Request instanceGroupAdjustmentV4Request = mock(InstanceGroupAdjustmentV4Request.class);
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroupAdjustmentV4Request.getInstanceGroup()).thenReturn("master");
    when(instanceGroupAdjustmentV4Request.getScalingAdjustment()).thenReturn(scalingNodeCount);
    when(stack.getInstanceGroupByInstanceGroupName("master")).thenReturn(instanceGroup);
    when(stack.getName()).thenReturn("master-stack");
    when(instanceGroup.getGroupName()).thenReturn("master");
    when(instanceGroup.getMinimumNodeCount()).thenReturn(minimumNodeCount);
    when(instanceGroup.getNodeCount()).thenReturn(instanceGroupNodeCount);
    when(instanceGroup.getScalabilityOption()).thenReturn(scalabilityOption);
    if (errorMessageSegment.isPresent()) {
        BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> {
            underTest.validateScalabilityOfInstanceGroup(stack, instanceGroupAdjustmentV4Request);
        });
        Assert.assertTrue(badRequestException.getMessage().contains(errorMessageSegment.get()));
    } else {
        assertDoesNotThrow(() -> underTest.validateScalabilityOfInstanceGroup(stack, instanceGroupAdjustmentV4Request));
    }
}
Also used : InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with InstanceGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class UpdateStackRequestValidatorTest method testIsValidShouldReturnFalseWhenRequestContainsNodeCountAndStatus.

@Test
public void testIsValidShouldReturnFalseWhenRequestContainsNodeCountAndStatus() {
    UpdateStackV4Request updateStackJson = new UpdateStackV4Request();
    InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustmentJson.setScalingAdjustment(4);
    instanceGroupAdjustmentJson.setInstanceGroup("slave_1");
    updateStackJson.setStatus(StatusRequest.STARTED);
    updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
    boolean valid = underTest.isValid(updateStackJson, constraintValidatorContext);
    assertFalse(valid);
}
Also used : UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Test(org.junit.Test)

Example 5 with InstanceGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method testTriggerUpscaleWithoutClusterEvent.

@Test
public void testTriggerUpscaleWithoutClusterEvent() {
    InstanceGroupAdjustmentV4Request instanceGroupAdjustment = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustment.setInstanceGroup("ig");
    instanceGroupAdjustment.setScalingAdjustment(3);
    when(stackService.getPlatformVariantByStackId(STACK_ID)).thenReturn(cloudPlatformVariant);
    when(cloudPlatformVariant.getVariant()).thenReturn(Variant.variant("AWS"));
    underTest.triggerStackUpscale(stack.getId(), instanceGroupAdjustment, false);
    ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
    verify(reactorNotifier, times(1)).notify(eq(stack.getId()), eq(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT), captor.capture());
    StackAndClusterUpscaleTriggerEvent event = (StackAndClusterUpscaleTriggerEvent) captor.getValue();
    assertEquals(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.selector());
    assertEquals(stack.getId(), event.getResourceId());
    assertEquals(instanceGroupAdjustment.getInstanceGroup(), event.getHostGroupsWithAdjustment().keySet().stream().findFirst().get());
    assertEquals(instanceGroupAdjustment.getScalingAdjustment(), event.getHostGroupsWithAdjustment().values().stream().findFirst().get());
    assertEquals(ScalingType.UPSCALE_ONLY_STACK, event.getScalingType());
}
Also used : StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Test(org.junit.Test)

Aggregations

InstanceGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)16 UpdateStackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request)8 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)6 Test (org.junit.Test)6 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 Supplier (java.util.function.Supplier)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)3 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)3 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 StackAndClusterUpscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CertificatesRotationV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request)1 HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)1 StackScaleV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackScaleV4Request)1 NetworkScaleV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkScaleV4Request)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1