Search in sources :

Example 1 with AvailabilityType

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType 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 2 with AvailabilityType

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType in project cloudbreak by hortonworks.

the class FreeIpaScalingService method triggerDownscale.

private DownscaleResponse triggerDownscale(DownscaleRequest request, Stack stack, AvailabilityType originalAvailabilityType) {
    Operation operation = startScalingOperation(stack.getAccountId(), request.getEnvironmentCrn(), OperationType.DOWNSCALE);
    ArrayList<String> instanceIdList = getDownscaleCandidates(stack, originalAvailabilityType, request.getTargetAvailabilityType());
    DownscaleEvent downscaleEvent = new DownscaleEvent(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), stack.getId(), instanceIdList, request.getTargetAvailabilityType().getInstanceCount(), false, false, false, operation.getOperationId());
    try {
        LOGGER.info("Trigger downscale flow with event: {}", downscaleEvent);
        FlowIdentifier flowIdentifier = flowManager.notify(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent);
        DownscaleResponse response = new DownscaleResponse();
        response.setOperationId(operation.getOperationId());
        response.setOriginalAvailabilityType(originalAvailabilityType);
        response.setTargetAvailabilityType(request.getTargetAvailabilityType());
        response.setFlowIdentifier(flowIdentifier);
        return response;
    } catch (Exception e) {
        String exception = handleFlowException(operation, e, stack);
        throw new BadRequestException(exception);
    }
}
Also used : DownscaleEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent) DownscaleResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 3 with AvailabilityType

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType in project cloudbreak by hortonworks.

the class FreeIpaScalingService method triggerUpscale.

private UpscaleResponse triggerUpscale(UpscaleRequest request, Stack stack, AvailabilityType originalAvailabilityType) {
    Operation operation = startScalingOperation(stack.getAccountId(), request.getEnvironmentCrn(), OperationType.UPSCALE);
    UpscaleEvent upscaleEvent = new UpscaleEvent(UpscaleFlowEvent.UPSCALE_EVENT.event(), stack.getId(), request.getTargetAvailabilityType().getInstanceCount(), false, false, false, operation.getOperationId());
    try {
        LOGGER.info("Trigger upscale flow with event: {}", upscaleEvent);
        FlowIdentifier flowIdentifier = flowManager.notify(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent);
        UpscaleResponse response = new UpscaleResponse();
        response.setOperationId(operation.getOperationId());
        response.setOriginalAvailabilityType(originalAvailabilityType);
        response.setTargetAvailabilityType(request.getTargetAvailabilityType());
        response.setFlowIdentifier(flowIdentifier);
        return response;
    } catch (Exception e) {
        String exception = handleFlowException(operation, e, stack);
        throw new BadRequestException(exception);
    }
}
Also used : UpscaleEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleEvent) UpscaleResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 4 with AvailabilityType

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType 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 5 with AvailabilityType

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType in project cloudbreak by hortonworks.

the class FreeIpaScalingValidationServiceTest method testUpscaleIfPathNotPermittedAndAlternativeExistsThenValidationFails.

@Test
public void testUpscaleIfPathNotPermittedAndAlternativeExistsThenValidationFails() {
    Stack stack = mock(Stack.class);
    Set<InstanceMetaData> validImSet = createValidImSet(2);
    when(stack.isAvailable()).thenReturn(true);
    Map<AvailabilityType, List<AvailabilityType>> allowedScalingPaths = createAllowedScalingPaths();
    allowedScalingPaths.put(AvailabilityType.HA, List.of(AvailabilityType.TWO_NODE_BASED));
    when(this.allowedScalingPaths.getPaths()).thenReturn(allowedScalingPaths);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.validateStackForUpscale(validImSet, stack, createScalingPath(false)));
    assertEquals("Refusing upscale as scaling from 3 node to 1 is not supported. Supported upscale targets: [TWO_NODE_BASED]", exception.getMessage());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) AvailabilityType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) List(java.util.List) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

AvailabilityType (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.AvailabilityType)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 ScalingPath (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath)3 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)3 Stack (com.sequenceiq.freeipa.entity.Stack)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 Operation (com.sequenceiq.freeipa.entity.Operation)2 DownscaleResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleResponse)1 UpscaleResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleResponse)1 DownscaleEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent)1 UpscaleEvent (com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleEvent)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1