Search in sources :

Example 1 with Operation

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());
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) OperationType(com.sequenceiq.freeipa.api.v1.operation.model.OperationType) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with Operation

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);
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) UpgradeCcmFlowChainTriggerEvent(com.sequenceiq.freeipa.flow.stack.upgrade.ccm.event.UpgradeCcmFlowChainTriggerEvent) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Operation

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);
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Operation

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);
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Operation

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);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) UpscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest) UpscaleResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleResponse) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

Operation (com.sequenceiq.freeipa.entity.Operation)88 Test (org.junit.jupiter.api.Test)55 Stack (com.sequenceiq.freeipa.entity.Stack)23 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)18 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)15 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)12 AcceptResult (com.sequenceiq.freeipa.service.freeipa.user.AcceptResult)11 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)7 OperationType (com.sequenceiq.freeipa.api.v1.operation.model.OperationType)7 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)6 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)5 FreeIpaUpgradeResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse)4 SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)4 CustomPermissionCheck (com.sequenceiq.authorization.annotation.CustomPermissionCheck)3