Search in sources :

Example 1 with ScalingPath

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath in project cloudbreak by hortonworks.

the class FreeIpaScalingServiceTest method testUpscaleIfValidationFailsThenErrorThrown.

@Test
public void testUpscaleIfValidationFailsThenErrorThrown() {
    Stack stack = mock(Stack.class);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    UpscaleRequest request = createUpscaleRequest();
    doThrow(new BadRequestException("validation failed")).when(validationService).validateStackForUpscale(allInstances, stack, new ScalingPath(AvailabilityType.TWO_NODE_BASED, AvailabilityType.HA));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.upscale(ACCOUNT_ID, request));
    assertEquals(exception.getMessage(), "validation failed");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ScalingPath(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath) UpscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with ScalingPath

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath in project cloudbreak by hortonworks.

the class FreeIpaScalingService method upscale.

public UpscaleResponse upscale(String accountId, UpscaleRequest request) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
    Set<InstanceMetaData> allInstances = stack.getNotDeletedInstanceMetaDataSet();
    AvailabilityType originalAvailabilityType = AvailabilityType.getByInstanceCount(allInstances.size());
    logRequest(OperationType.UPSCALE, request, originalAvailabilityType);
    validationService.validateStackForUpscale(allInstances, stack, new ScalingPath(originalAvailabilityType, request.getTargetAvailabilityType()));
    return triggerUpscale(request, stack, originalAvailabilityType);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ScalingPath(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath) AvailabilityType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 3 with ScalingPath

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath in project cloudbreak by hortonworks.

the class FreeIpaScalingValidationServiceTest method createScalingPath.

private ScalingPath createScalingPath(boolean allowed) {
    AvailabilityType originalAvailabilityType = AvailabilityType.NON_HA;
    AvailabilityType targetAvailabilityType = AvailabilityType.HA;
    return allowed ? new ScalingPath(originalAvailabilityType, targetAvailabilityType) : new ScalingPath(targetAvailabilityType, originalAvailabilityType);
}
Also used : ScalingPath(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath) AvailabilityType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType)

Example 4 with ScalingPath

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath in project cloudbreak by hortonworks.

the class FreeIpaScalingServiceTest method testDownscaleIfValidationFailsThenErrorThrown.

@Test
public void testDownscaleIfValidationFailsThenErrorThrown() {
    Stack stack = mock(Stack.class);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    DownscaleRequest request = createDownscaleRequest();
    doThrow(new BadRequestException("validation failed")).when(validationService).validateStackForDownscale(allInstances, stack, new ScalingPath(AvailabilityType.TWO_NODE_BASED, AvailabilityType.NON_HA));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.downscale(ACCOUNT_ID, request));
    assertEquals(exception.getMessage(), "validation failed");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) DownscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleRequest) ScalingPath(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with ScalingPath

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath in project cloudbreak by hortonworks.

the class FreeIpaScalingService method downscale.

public DownscaleResponse downscale(String accountId, DownscaleRequest request) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
    Set<InstanceMetaData> allInstances = stack.getNotDeletedInstanceMetaDataSet();
    AvailabilityType originalAvailabilityType = AvailabilityType.getByInstanceCount(allInstances.size());
    logRequest(OperationType.DOWNSCALE, request, originalAvailabilityType);
    validationService.validateStackForDownscale(allInstances, stack, new ScalingPath(originalAvailabilityType, request.getTargetAvailabilityType()));
    return triggerDownscale(request, stack, originalAvailabilityType);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ScalingPath(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath) AvailabilityType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

ScalingPath (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath)5 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)4 Stack (com.sequenceiq.freeipa.entity.Stack)4 AvailabilityType (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 Test (org.junit.jupiter.api.Test)2 DownscaleRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleRequest)1 UpscaleRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest)1