use of com.sequenceiq.freeipa.entity.Stack 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);
}
use of com.sequenceiq.freeipa.entity.Stack 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");
}
use of com.sequenceiq.freeipa.entity.Stack 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.entity.Stack in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method testRenameStackIfNeededWhenNotAlreadyRenamed.
@Test
public void testRenameStackIfNeededWhenNotAlreadyRenamed() {
Stack stack = createStack(DELETE_COMPLETED, List.of(InstanceStatus.TERMINATED, InstanceStatus.TERMINATED), 2);
Long terminationTime = 1638311233640L;
String stackName = "freeipa";
stack.setName(stackName);
stack.setTerminated(terminationTime);
underTest.renameStackIfNeeded(stack);
verify(terminationService).finalizeTermination(STACK_ID);
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class StackServiceTest method getByEnvironmentCrnWhenOnlyParentsStackFound.
@Test
void getByEnvironmentCrnWhenOnlyParentsStackFound() {
when(stackRepository.findByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.empty());
when(childEnvironmentService.findParentByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(Optional.of(stack));
Stack stackByEnvironmentCrn = underTest.getByEnvironmentCrnAndAccountId(ENVIRONMENT_CRN, ACCOUNT_ID);
assertEquals(stack, stackByEnvironmentCrn);
}
Aggregations