use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class UserSyncServiceTest method testAsyncSynchronizeUsersUsesInternalCrn.
@Test
void testAsyncSynchronizeUsersUsesInternalCrn() {
Stack stack = mock(Stack.class);
when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(anySet(), anyString())).thenReturn(List.of(stack));
Operation operation = mock(Operation.class);
when(operation.getStatus()).thenReturn(OperationState.RUNNING);
when(operation.getOperationId()).thenReturn("operationId");
when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
UserSyncStatus userSyncStatus = mock(UserSyncStatus.class);
when(userSyncStatusService.getOrCreateForStack(any(Stack.class))).thenReturn(userSyncStatus);
when(userSyncStatusService.save(userSyncStatus)).thenReturn(userSyncStatus);
UserSyncService spyService = spy(underTest);
doAnswer(invocation -> {
assertEquals(INTERNAL_ACTOR_CRN, ThreadBasedUserCrnProvider.getUserCrn());
return null;
}).when(spyService).asyncSynchronizeUsers(anyString(), anyString(), anyList(), any(), any());
spyService.synchronizeUsers("accountId", "actorCrn", Set.of(), Set.of(), Set.of(), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
verify(spyService).asyncSynchronizeUsers(anyString(), anyString(), anyList(), any(), any());
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmServiceTest method upgradeCcmTestWhenAvailableAndOperationRunning.
@Test
void upgradeCcmTestWhenAvailableAndOperationRunning() {
Stack stack = createStack(Status.AVAILABLE);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
Operation operation = createOperation(OperationState.RUNNING);
when(operationService.startOperation(ACCOUNT_ID, OperationType.UPGRADE_CCM, List.of(ENVIRONMENT_CRN), List.of())).thenReturn(operation);
when(operationConverter.convert(operation)).thenReturn(operationStatus);
OperationStatus result = underTest.upgradeCcm(ENVIRONMENT_CRN, ACCOUNT_ID);
assertThat(result).isSameAs(operationStatus);
ArgumentCaptor<UpgradeCcmFlowChainTriggerEvent> eventCaptor = ArgumentCaptor.forClass(UpgradeCcmFlowChainTriggerEvent.class);
verify(flowManager).notify(eq(UPGRADE_CCM_CHAIN_TRIGGER_EVENT), eventCaptor.capture());
UpgradeCcmFlowChainTriggerEvent event = eventCaptor.getValue();
assertThat(event.getOldTunnel()).isEqualTo(Tunnel.CCM);
assertThat(event.getOperationId()).isEqualTo(OPERATION_ID);
assertThat(event.getResourceId()).isEqualTo(STACK_ID);
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmServiceTest method upgradeCcmTestWhenAvailableAndOperationNotRunning.
@ParameterizedTest(name = "{0}")
@EnumSource(value = OperationState.class, names = { "RUNNING" }, mode = EnumSource.Mode.EXCLUDE)
void upgradeCcmTestWhenAvailableAndOperationNotRunning(OperationState operationState) {
Stack stack = createStack(Status.AVAILABLE);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
Operation operation = createOperation(operationState);
when(operationService.startOperation(ACCOUNT_ID, OperationType.UPGRADE_CCM, List.of(ENVIRONMENT_CRN), List.of())).thenReturn(operation);
when(operationConverter.convert(operation)).thenReturn(operationStatus);
OperationStatus result = underTest.upgradeCcm(ENVIRONMENT_CRN, ACCOUNT_ID);
assertThat(result).isSameAs(operationStatus);
verifyNoInteractions(flowManager);
}
use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmServiceTest method upgradeCcmTestWhenAvailableAndOperationRunningButFailedToStart.
@Test
void upgradeCcmTestWhenAvailableAndOperationRunningButFailedToStart() {
Stack stack = createStack(Status.AVAILABLE);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
Operation operation = createOperation(OperationState.RUNNING);
when(operationService.startOperation(ACCOUNT_ID, OperationType.UPGRADE_CCM, List.of(ENVIRONMENT_CRN), List.of())).thenReturn(operation);
Operation failedOperation = createOperation(OperationState.FAILED);
when(operationService.failOperation(eq(ACCOUNT_ID), eq(OPERATION_ID), any())).thenReturn(failedOperation);
when(operationConverter.convert(any())).then(invocation -> {
Operation opArg = invocation.getArgument(0);
if (!Objects.equals(opArg.getStatus(), OperationState.FAILED)) {
return operationStatus;
}
operationStatus.setStatus(OperationState.FAILED);
return operationStatus;
});
when(flowManager.notify(nullable(String.class), any())).thenThrow(new IllegalStateException("bad state"));
OperationStatus result = underTest.upgradeCcm(ENVIRONMENT_CRN, ACCOUNT_ID);
assertThat(result.getStatus()).isEqualTo(OperationState.FAILED);
}
use of com.sequenceiq.freeipa.entity.Operation 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);
}
Aggregations