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;
}
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());
}
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));
}
}
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);
}
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());
}
Aggregations