Search in sources :

Example 1 with OperationStatus

use of com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus in project cloudbreak by hortonworks.

the class StartBindUserCreationService method invokeCreateBindUser.

private OperationStatus invokeCreateBindUser(StackView stackView) {
    BindUserCreateRequest request = createRequest(stackView);
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    return ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> freeIpaV1Endpoint.createBindUser(request, userCrn));
}
Also used : BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest)

Example 2 with OperationStatus

use of com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus in project cloudbreak by hortonworks.

the class FreeIpaCleanupService method sendCleanupRequest.

private OperationStatus sendCleanupRequest(Stack stack, Set<CleanupStep> stepsToSkip, Set<String> hostNames, Set<String> ips) {
    try {
        CleanupRequest cleanupRequest = createCleanupRequest(stack, stepsToSkip, hostNames, ips);
        LOGGER.info("Sending cleanup request to FreeIPA: [{}]", cleanupRequest);
        OperationStatus cleanup = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> freeIpaV1Endpoint.internalCleanup(cleanupRequest, Crn.fromString(stack.getResourceCrn()).getAccountId()));
        LOGGER.info("Cleanup operation started: {}", cleanup);
        return cleanup;
    } catch (WebApplicationException e) {
        String errorMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Couldn't start cleanup due to: '%s' ", errorMessage);
        LOGGER.error(message, e);
        throw new FreeIpaOperationFailedException(message, e);
    } catch (Exception e) {
        LOGGER.error("Couldn't start cleanup", e);
        throw new FreeIpaOperationFailedException("Couldn't start cleanup", e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 3 with OperationStatus

use of com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus in project cloudbreak by hortonworks.

the class FreeIpaOperationCheckerTask method checkStatus.

@Override
public boolean checkStatus(T operationPollerObject) {
    OperationStatus operationStatus = ThreadBasedUserCrnProvider.doAsInternalActor(operationPollerObject.getRegionalAwareInternalCrnGeneratorFactory().iam().getInternalCrnForServiceAsString(), () -> operationPollerObject.getOperationV1Endpoint().getOperationStatus(operationPollerObject.getOperationId(), operationPollerObject.getAccountId()));
    LOGGER.debug("OperationStatus for operationId[{}]: {}", operationPollerObject.getOperationId(), operationStatus);
    if (OperationState.COMPLETED.equals(operationStatus.getStatus())) {
        return true;
    } else if (OperationState.RUNNING.equals(operationStatus.getStatus())) {
        return false;
    } else {
        String failureDetails = extractFailureDetails(operationStatus);
        throw new FreeIpaOperationFailedException(String.format("FreeIPA [%s] operation [%s] failed with state [%s] and error message [%s]. " + "Failure details: [%s]", operationStatus.getOperationType(), operationPollerObject.getOperationId(), operationStatus.getStatus(), operationStatus.getError(), failureDetails));
    }
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)

Example 4 with OperationStatus

use of com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus in project cloudbreak by hortonworks.

the class FreeIpaUpgradeTests method cleanUp.

private void cleanUp(TestContext testContext, com.sequenceiq.freeipa.api.client.FreeIpaClient ipaClient, String environmentCrn) {
    try {
        CleanupRequest cleanupRequest = new CleanupRequest();
        cleanupRequest.setEnvironmentCrn(environmentCrn);
        cleanupRequest.setClusterName("testuser");
        cleanupRequest.setUsers(Set.of("kerberosbind-testuser", "ldapbind-testuser"));
        OperationStatus operationStatus = ipaClient.getFreeIpaV1Endpoint().cleanup(cleanupRequest);
        waitToCompleted(testContext, operationStatus.getOperationId(), "cleanupOperation");
    } catch (Exception e) {
        logger.error("CLEANUP test failed during upgrade", e);
    // throw new TestFailException("CLEANUP test failed during upgrade with: " + e.getMessage(), e);
    }
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) WebApplicationException(javax.ws.rs.WebApplicationException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 5 with OperationStatus

use of com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus in project cloudbreak by hortonworks.

the class StartBindUserCreationServiceTest method testOperationRejected.

@Test
public void testOperationRejected() {
    OperationStatus operationStatus = new OperationStatus(OPERATION_ID, OperationType.BIND_USER_CREATE, OperationState.REJECTED, List.of(), List.of(), "errMsg", 1L, 2L);
    when(freeIpaV1Endpoint.createBindUser(any(BindUserCreateRequest.class), anyString())).thenReturn(operationStatus);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    assertThrows(RetryException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.startBindUserCreation(stackView)));
}
Also used : BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Test(org.junit.jupiter.api.Test)

Aggregations

OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)42 Test (org.junit.jupiter.api.Test)32 Stack (com.sequenceiq.freeipa.entity.Stack)12 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)9 CleanupRequest (com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest)8 BindUserCreateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest)8 Operation (com.sequenceiq.freeipa.entity.Operation)8 KerberosConfig (com.sequenceiq.cloudbreak.dto.KerberosConfig)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)6 RepairInstancesRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest)6 RebootInstancesRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.reboot.RebootInstancesRequest)5 RepairEvent (com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent)5 InstanceEvent (com.sequenceiq.freeipa.flow.instance.InstanceEvent)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ArgumentCaptor (org.mockito.ArgumentCaptor)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)2 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)2 InstanceStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)2