use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleResponse in project cloudbreak by hortonworks.
the class FreeIpaScalingServiceTest method testDownscaleIfValidationPassesAndOperationRunningThenSucceed.
@Test
public void testDownscaleIfValidationPassesAndOperationRunningThenSucceed() {
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.DOWNSCALE, 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);
DownscaleRequest request = createDownscaleRequest();
DownscaleResponse response = underTest.downscale(ACCOUNT_ID, request);
assertEquals(response.getOperationId(), OPERATION_ID);
assertEquals(response.getOriginalAvailabilityType(), AvailabilityType.TWO_NODE_BASED);
assertEquals(response.getTargetAvailabilityType(), AvailabilityType.NON_HA);
assertEquals(response.getFlowIdentifier(), flowIdentifier);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleResponse 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.scale.DownscaleResponse 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);
}
Aggregations