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