use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class RepairInstancesServiceTest method createOperation.
private Operation createOperation() {
Operation operation = new Operation();
operation.setId(1L);
operation.setStatus(OperationState.RUNNING);
return operation;
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class FreeIpaScalingServiceTest method testUpscaleIfValidationPassesAndOperationFailedThenThrowException.
@Test
public void testUpscaleIfValidationPassesAndOperationFailedThenThrowException() {
Stack stack = mock(Stack.class);
Set<InstanceMetaData> allInstances = createValidImSet();
Operation operation = createOperation(false);
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);
UpscaleRequest request = createUpscaleRequest();
BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.upscale(ACCOUNT_ID, request));
assertEquals(exception.getMessage(), "upscale operation couldn't be started with: operationError");
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class FreeIpaScalingServiceTest method testDownscaleIfValidationPassesAndOperationFailedThenThrowException.
@Test
public void testDownscaleIfValidationPassesAndOperationFailedThenThrowException() {
Stack stack = mock(Stack.class);
Set<InstanceMetaData> allInstances = createValidImSet();
Operation operation = createOperation(false);
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);
DownscaleRequest request = createDownscaleRequest();
BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.downscale(ACCOUNT_ID, request));
assertEquals(exception.getMessage(), "downscale operation couldn't be started with: operationError");
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class UpgradeServiceTest method mockOperation.
private Operation mockOperation(OperationState operationState) {
Operation operation = new Operation();
operation.setStatus(operationState);
operation.setOperationId("opId");
when(operationService.startOperation(any(), any(), any(), any())).thenReturn(operation);
return operation;
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class UpgradeServiceTest method testImageSettingsCreatedIfMissingAndUpgradeTriggered.
@Test
public void testImageSettingsCreatedIfMissingAndUpgradeTriggered() {
FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
request.setEnvironmentCrn(ENVIRONMENT_CRN);
Stack stack = mock(Stack.class);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
Set<InstanceMetaData> allInstances = createValidImSet();
when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
ImageInfoResponse selectedImage = new ImageInfoResponse();
when(imageService.selectImage(eq(stack), any(ImageSettingsRequest.class))).thenReturn(selectedImage);
ImageInfoResponse currentImage = mockCurrentImage(stack);
Operation operation = mockOperation(OperationState.RUNNING);
ArgumentCaptor<Acceptable> eventCaptor = ArgumentCaptor.forClass(Acceptable.class);
FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "flowId");
when(flowManager.notify(eq(FlowChainTriggers.UPGRADE_TRIGGER_EVENT), eventCaptor.capture())).thenReturn(flowIdentifier);
when(instanceMetaDataService.getPrimaryGwInstance(allInstances)).thenReturn(createPgwIm());
when(instanceMetaDataService.getNonPrimaryGwInstances(allInstances)).thenReturn(createGwImSet());
FreeIpaUpgradeResponse response = underTest.upgradeFreeIpa(ACCOUNT_ID, request);
assertEquals(flowIdentifier, response.getFlowIdentifier());
assertEquals(operation.getOperationId(), response.getOperationId());
assertEquals(currentImage, response.getOriginalImage());
assertEquals(selectedImage, response.getTargetImage());
UpgradeEvent upgradeEvent = (UpgradeEvent) eventCaptor.getValue();
assertNotNull(upgradeEvent.getImageSettingsRequest());
assertEquals(operation.getOperationId(), upgradeEvent.getOperationId());
assertEquals("pgw", upgradeEvent.getPrimareGwInstanceId());
assertEquals(2, upgradeEvent.getInstanceIds().size());
assertTrue(Set.of("im2", "im3").containsAll(upgradeEvent.getInstanceIds()));
verify(validationService).validateEntitlement(ACCOUNT_ID);
verify(validationService).validateStackForUpgrade(allInstances, stack);
verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
Aggregations