Search in sources :

Example 26 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class BindUserCreateServiceTest method testCreateStartedFLowNotified.

@Test
public void testCreateStartedFLowNotified() {
    BindUserCreateRequest request = createRequest();
    Operation operation = new Operation();
    operation.setOperationId("op");
    operation.setStatus(OperationState.RUNNING);
    when(operationService.startOperation(eq(ACCOUNT), eq(OperationType.BIND_USER_CREATE), anyCollection(), anyCollection())).thenReturn(operation);
    OperationStatus operationStatus = new OperationStatus();
    when(operationConverter.convert(operation)).thenReturn(operationStatus);
    OperationStatus response = underTest.createBindUser(ACCOUNT, request);
    assertEquals(operationStatus, response);
    ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
    verify(flowManager).notify(eq(CREATE_BIND_USER_EVENT.event()), captor.capture());
    Acceptable event = captor.getValue();
    assertTrue(event instanceof CreateBindUserEvent);
    CreateBindUserEvent bindUserEvent = (CreateBindUserEvent) event;
    assertEquals(CREATE_BIND_USER_EVENT.event(), bindUserEvent.selector());
    assertEquals(STACK_ID, bindUserEvent.getResourceId());
    assertEquals(ACCOUNT, bindUserEvent.getAccountId());
    assertEquals(operation.getOperationId(), bindUserEvent.getOperationId());
    assertEquals(request.getEnvironmentCrn(), bindUserEvent.getEnvironmentCrn());
    assertEquals(request.getBindUserNameSuffix(), bindUserEvent.getSuffix());
}
Also used : BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 27 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class UpgradeCcmOperationAcceptorTest method acceptTestWhenHasRunningOperationForSameStack.

@Test
void acceptTestWhenHasRunningOperationForSameStack() {
    Operation operation = createOperation(ID_1, List.of(ENVIRONMENT_CRN_1));
    when(operationRepository.findRunningByAccountIdAndType(ACCOUNT_ID, OperationType.UPGRADE_CCM)).thenReturn(List.of(createOperation(ID_2, List.of(ENVIRONMENT_CRN_1))));
    AcceptResult result = underTest.accept(operation);
    assertThat(result).isNotNull();
    assertThat(result.isAccepted()).isFalse();
    Optional<String> rejectionMessage = result.getRejectionMessage();
    assertThat(rejectionMessage).isNotNull();
    assertThat(rejectionMessage).isPresent();
    assertThat(rejectionMessage.get()).isEqualTo("There is already a running Cluster Connectivity Manager upgrade for FreeIPA stack");
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) AcceptResult(com.sequenceiq.freeipa.service.freeipa.user.AcceptResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class UpgradeCcmOperationAcceptorTest method acceptTestWhenSuccess.

@ParameterizedTest(name = "{0}")
@MethodSource("acceptTestWhenSuccessDataProvider")
void acceptTestWhenSuccess(String testCaseName, List<Operation> runningOperations) {
    Operation operation = createOperation(ID_1, List.of(ENVIRONMENT_CRN_1));
    when(operationRepository.findRunningByAccountIdAndType(ACCOUNT_ID, OperationType.UPGRADE_CCM)).thenReturn(runningOperations);
    AcceptResult result = underTest.accept(operation);
    assertThat(result).isNotNull();
    assertThat(result.isAccepted()).isTrue();
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) AcceptResult(com.sequenceiq.freeipa.service.freeipa.user.AcceptResult) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class UpgradeCcmOperationAcceptorTest method acceptTestWhenValidationFailure.

@ParameterizedTest(name = "{0}")
@MethodSource("acceptTestWhenValidationFailureDataProvider")
void acceptTestWhenValidationFailure(String testCaseName, List<String> environmentList) {
    Operation operation = createOperation(ID_1, environmentList);
    AcceptResult result = underTest.accept(operation);
    assertThat(result).isNotNull();
    assertThat(result.isAccepted()).isFalse();
    Optional<String> rejectionMessage = result.getRejectionMessage();
    assertThat(rejectionMessage).isNotNull();
    assertThat(rejectionMessage).isPresent();
    assertThat(rejectionMessage.get()).isEqualTo("Cluster Connectivity Manager upgrade must be invoked for a single environment!");
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) AcceptResult(com.sequenceiq.freeipa.service.freeipa.user.AcceptResult) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 30 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class BindUserCreateOperationAcceptorTest method testMultipleEnv.

@Test
public void testMultipleEnv() {
    Operation currentOperation = createCurrentOperation();
    currentOperation.setEnvironmentList(List.of(ENV_CRN, "env2"));
    when(repository.findRunningByAccountIdAndType(ACCOUNT, underTest.selector())).thenReturn(List.of(currentOperation));
    AcceptResult result = underTest.accept(currentOperation);
    assertFalse(result.isAccepted());
    assertEquals("Bind user create must run only for one environment!", result.getRejectionMessage().get());
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) AcceptResult(com.sequenceiq.freeipa.service.freeipa.user.AcceptResult) 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