Search in sources :

Example 1 with UpscaleRequest

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

the class FreeIpaUpscaleAction method action.

@Override
public FreeIpaUpscaleTestDto action(TestContext testContext, FreeIpaUpscaleTestDto testDto, FreeIpaClient client) throws Exception {
    Log.whenJson(LOGGER, format(" FreeIPA upscale request:%n"), testDto.getRequest());
    UpscaleRequest upscaleRequest = new UpscaleRequest();
    upscaleRequest.setEnvironmentCrn(testDto.getRequest().getEnvironmentCrn());
    upscaleRequest.setTargetAvailabilityType(testDto.getRequest().getTargetAvailabilityType());
    testDto.setResponse(client.getDefaultClient().getFreeIpaV1Endpoint().upscale(upscaleRequest));
    testDto.setFlow("FreeIPA upscale", testDto.getResponse().getFlowIdentifier());
    testDto.setOperationId(testDto.getResponse().getOperationId());
    Log.whenJson(LOGGER, format(" FreeIPA upscale started: %n"), testDto.getResponse());
    return testDto;
}
Also used : UpscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest)

Example 2 with UpscaleRequest

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

the class FreeIpaScalingServiceTest method testUpscaleIfValidationPassesAndOperationRunningThenSucceed.

@Test
public void testUpscaleIfValidationPassesAndOperationRunningThenSucceed() {
    Stack stack = mock(Stack.class);
    Set<InstanceMetaData> allInstances = createValidImSet();
    Operation operation = createOperation(true);
    when(stack.getAccountId()).thenReturn(ACCOUNT_ID);
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    when(operationService.startOperation(ACCOUNT_ID, OperationType.UPSCALE, List.of(ENV_CRN), List.of())).thenReturn(operation);
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, POLLABLE_ID);
    when(flowManager.notify(anyString(), any())).thenReturn(flowIdentifier);
    UpscaleRequest request = createUpscaleRequest();
    UpscaleResponse response = underTest.upscale(ACCOUNT_ID, request);
    assertEquals(response.getOperationId(), OPERATION_ID);
    assertEquals(response.getOriginalAvailabilityType(), AvailabilityType.TWO_NODE_BASED);
    assertEquals(response.getTargetAvailabilityType(), AvailabilityType.HA);
    assertEquals(response.getFlowIdentifier(), flowIdentifier);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) UpscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest) UpscaleResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleResponse) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with UpscaleRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest 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 4 with UpscaleRequest

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

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest 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)

Aggregations

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