Search in sources :

Example 1 with AcceptResult

use of com.sequenceiq.freeipa.service.freeipa.user.AcceptResult in project cloudbreak by hortonworks.

the class OperationService method startOperation.

public Operation startOperation(String accountId, OperationType operationType, Collection<String> environmentCrns, Collection<String> userCrns) {
    Operation requestedOperation = requestOperation(accountId, operationType, environmentCrns, userCrns);
    OperationAcceptor acceptor = operationAcceptorMap.get(operationType);
    AcceptResult acceptResult = acceptor.accept(requestedOperation);
    if (acceptResult.isAccepted()) {
        return acceptOperation(requestedOperation);
    } else {
        return rejectOperation(requestedOperation, acceptResult.getRejectionMessage().orElse("Rejected for unspecified reason."));
    }
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) AcceptResult(com.sequenceiq.freeipa.service.freeipa.user.AcceptResult)

Example 2 with AcceptResult

use of com.sequenceiq.freeipa.service.freeipa.user.AcceptResult 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 3 with AcceptResult

use of com.sequenceiq.freeipa.service.freeipa.user.AcceptResult 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 4 with AcceptResult

use of com.sequenceiq.freeipa.service.freeipa.user.AcceptResult 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 5 with AcceptResult

use of com.sequenceiq.freeipa.service.freeipa.user.AcceptResult 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)11 AcceptResult (com.sequenceiq.freeipa.service.freeipa.user.AcceptResult)11 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)2