Search in sources :

Example 36 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class FreeIpaUpgradeTests method addAndDeleteDnsCnameRecord.

private void addAndDeleteDnsCnameRecord(com.sequenceiq.freeipa.api.client.FreeIpaClient ipaClient, String environmentCrn) {
    try {
        AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
        request.setCname("test-cname-record");
        request.setTargetFqdn("cloudera.com");
        request.setEnvironmentCrn(environmentCrn);
        ipaClient.getDnsV1Endpoint().addDnsCnameRecord(request);
        ipaClient.getDnsV1Endpoint().deleteDnsCnameRecord(environmentCrn, null, request.getCname());
    } catch (Exception e) {
        logger.error("DNS CNAME record test failed during upgrade", e);
        throw new TestFailException("DNS CNAME record test failed during upgrade with: " + e.getMessage(), e);
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) WebApplicationException(javax.ws.rs.WebApplicationException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 37 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class FreeIpaUpgradeTests method dnsLookups.

private void dnsLookups(SdxTestDto sdxTestDto, SdxClient sdxClient) {
    InstanceMetaDataV4Response instanceGroupMetadata = getInstanceGroups(sdxTestDto, sdxClient).stream().flatMap(instanceGroup -> instanceGroup.getMetadata().stream()).filter(metadata -> metadata.getInstanceGroup().equals("idbroker")).filter(metadata -> StringUtils.isNoneBlank(metadata.getDiscoveryFQDN(), metadata.getPrivateIp())).findFirst().orElseThrow(() -> new TestFailException("FreeIPA upgrade DNS lookups test failed, idbroker instance group was not found."));
    try {
        String cmd = String.format(CHECK_DNS_LOOKUPS_CMD, instanceGroupMetadata.getDiscoveryFQDN(), instanceGroupMetadata.getPrivateIp());
        Map<String, Pair<Integer, String>> results = sshJClientActions.executeSshCommandOnHost(getInstanceGroups(sdxTestDto, sdxClient), List.of(HostGroupType.MASTER.getName()), cmd, false);
        results.values().forEach(result -> Assertions.assertEquals(0, result.getLeft()));
    } catch (Exception e) {
        logger.error("FreeIPA upgrade DNS lookups test failed with unexpected error", e);
        throw new TestFailException("FreeIPA upgrade DNS lookups test failed with unexpected error: " + e.getMessage(), e);
    }
}
Also used : SdxDatabaseAvailabilityType(com.sequenceiq.sdx.api.model.SdxDatabaseAvailabilityType) AddDnsZoneForSubnetsRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsZoneForSubnetsRequest) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Test(org.testng.annotations.Test) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) StringUtils(org.apache.commons.lang3.StringUtils) Description(com.sequenceiq.it.cloudbreak.context.Description) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) WorkloadCredentialsUpdateType(com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType) RUNNING(com.sequenceiq.freeipa.api.v1.operation.model.OperationState.RUNNING) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Set(java.util.Set) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) List(java.util.List) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) ServiceKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest) SshJClientActions(com.sequenceiq.it.cloudbreak.util.ssh.action.SshJClientActions) AbsolutTimeBasedTimeoutChecker(com.sequenceiq.cloudbreak.polling.AbsolutTimeBasedTimeoutChecker) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest) TelemetryTestDto(com.sequenceiq.it.cloudbreak.dto.telemetry.TelemetryTestDto) HostKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest) FreeIpaOperationStatusTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaOperationStatusTestDto) RunningParameter.waitForFlow(com.sequenceiq.it.cloudbreak.context.RunningParameter.waitForFlow) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) Inject(javax.inject.Inject) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) SynchronizationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus) COMPLETED(com.sequenceiq.freeipa.api.v1.operation.model.OperationState.COMPLETED) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) Assertions(org.junit.jupiter.api.Assertions) SdxClient(com.sequenceiq.it.cloudbreak.SdxClient) Collections(java.util.Collections) HostGroupType(com.sequenceiq.it.cloudbreak.cloud.HostGroupType) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) WebApplicationException(javax.ws.rs.WebApplicationException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Pair(org.apache.commons.lang3.tuple.Pair)

Example 38 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class UserSyncService method internalSynchronizeUsers.

private void internalSynchronizeUsers(String operationId, String accountId, List<Stack> stacks, UserSyncRequestFilter userSyncFilter, UserSyncOptions options) {
    tryWithOperationCleanup(operationId, accountId, () -> {
        Set<String> environmentCrns = stacks.stream().map(Stack::getEnvironmentCrn).collect(Collectors.toSet());
        Optional<String> requestId = MDCUtils.getRequestId();
        UmsEventGenerationIds umsEventGenerationIds = options.isFullSync() ? umsEventGenerationIdsProvider.getEventGenerationIds(accountId, requestId) : null;
        LogEvent logUserSyncEvent = options.isFullSync() ? LogEvent.FULL_USER_SYNC : LogEvent.PARTIAL_USER_SYNC;
        LOGGER.info("Starting {} for environments {} with operationId {} ...", logUserSyncEvent, environmentCrns, operationId);
        Map<String, Future<SyncStatusDetail>> statusFutures;
        if (userSyncFilter.getDeletedWorkloadUser().isEmpty()) {
            LogEvent logRetrieveUmsEvent = options.isFullSync() ? LogEvent.RETRIEVE_FULL_UMS_STATE : LogEvent.RETRIEVE_PARTIAL_UMS_STATE;
            LOGGER.debug("Starting {} for environments {} ...", logRetrieveUmsEvent, environmentCrns);
            Map<String, UmsUsersState> envToUmsStateMap = umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(accountId, environmentCrns, userSyncFilter.getUserCrnFilter(), userSyncFilter.getMachineUserCrnFilter(), requestId);
            LOGGER.debug("Finished {}.", logRetrieveUmsEvent);
            statusFutures = stacks.stream().collect(Collectors.toMap(Stack::getEnvironmentCrn, stack -> asyncSynchronizeStack(stack, envToUmsStateMap.get(stack.getEnvironmentCrn()), umsEventGenerationIds, options, operationId, accountId)));
        } else {
            String deletedWorkloadUser = userSyncFilter.getDeletedWorkloadUser().get();
            statusFutures = stacks.stream().collect(Collectors.toMap(Stack::getEnvironmentCrn, stack -> asyncSynchronizeStackForDeleteUser(stack, deletedWorkloadUser)));
        }
        List<SuccessDetails> success = new ArrayList<>();
        List<FailureDetails> failure = new ArrayList<>();
        statusFutures.forEach((envCrn, statusFuture) -> {
            try {
                SyncStatusDetail statusDetail = statusFuture.get();
                switch(statusDetail.getStatus()) {
                    case COMPLETED:
                        success.add(new SuccessDetails(envCrn));
                        break;
                    case FAILED:
                        failure.add(createFailureDetails(envCrn, statusDetail.getDetails(), statusDetail.getWarnings()));
                        break;
                    default:
                        failure.add(createFailureDetails(envCrn, "Unexpected status: " + statusDetail.getStatus(), statusDetail.getWarnings()));
                        break;
                }
            } catch (InterruptedException | ExecutionException e) {
                LOGGER.error("Sync is interrupted for env: {}", envCrn, e);
                failure.add(new FailureDetails(envCrn, e.getLocalizedMessage()));
            }
        });
        operationService.completeOperation(accountId, operationId, success, failure);
        LOGGER.info("Finished {} for environments {} with operationId {}.", logUserSyncEvent, environmentCrns, operationId);
    });
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Stack(com.sequenceiq.freeipa.entity.Stack) UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 39 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class EnvironmentUserSyncStateCalculator method calculateUserSyncState.

private UserSyncState calculateUserSyncState(String accountId, String envCrnString, UserSyncStatus userSyncStatus) {
    Operation lastSync = userSyncStatus.getLastStartedFullSync();
    UserSyncState state;
    switch(lastSync.getStatus()) {
        case RUNNING:
            state = UserSyncState.SYNC_IN_PROGRESS;
            break;
        case COMPLETED:
            state = calculateStateForCompletedOperation(accountId, envCrnString, userSyncStatus);
            break;
        case REQUESTED:
        case REJECTED:
            // REQUESTED or REJECTED operations will never be saved as part of the UserSyncStatus
            throw createExceptionForUnexpectedOperationStatus(envCrnString, userSyncStatus);
        case TIMEDOUT:
            LOGGER.warn("UserSyncStatus.lastStartedFullSync '{}' is timed out for environment '{}'", lastSync.getOperationId(), envCrnString);
            state = UserSyncState.SYNC_FAILED;
            break;
        case FAILED:
            state = UserSyncState.SYNC_FAILED;
            break;
        default:
            state = UserSyncState.STALE;
            break;
    }
    return state;
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) EnvironmentUserSyncState(com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState) UserSyncState(com.sequenceiq.freeipa.api.v1.freeipa.user.model.UserSyncState)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)9 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)9 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Map (java.util.Map)7 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)6 Bean (org.springframework.context.annotation.Bean)6 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)5 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)4 FlowParameters (com.sequenceiq.flow.core.FlowParameters)4 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)4 StateContext (org.springframework.statemachine.StateContext)4 Flow (com.sequenceiq.flow.core.Flow)3 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)3 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)3 Test (org.junit.jupiter.api.Test)3 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)2