Search in sources :

Example 16 with FAILED

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

the class UserSyncForStackServiceTest method testSynchronizeStackSuccessFullWithRetry.

@Test
public void testSynchronizeStackSuccessFullWithRetry() throws Exception {
    UmsUsersState umsUsersState = mock(UmsUsersState.class);
    UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.FORCE_UPDATE);
    UsersState usersState = mock(UsersState.class);
    when(usersState.getUsers()).thenReturn(ImmutableSet.of());
    when(usersState.getGroups()).thenReturn(ImmutableSet.of());
    when(freeIpaUsersStateProvider.getUsersState(FREE_IPA_CLIENT)).thenReturn(usersState);
    UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
    when(userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, usersState, options)).thenReturn(usersStateDifference);
    when(userStateDifferenceCalculator.usersStateDifferenceChanged(any(), any())).thenReturn(TRUE);
    when(entitlementService.cloudIdentityMappingEnabled(ACCOUNT)).thenReturn(TRUE);
    when(entitlementService.isEnvironmentPrivilegedUserEnabled(ACCOUNT)).thenReturn(TRUE);
    doAnswer(invocation -> {
        Multimap<String, String> warnings = invocation.getArgument(2, Multimap.class);
        warnings.put(ENV_CRN, "failed");
        return null;
    }).doNothing().when(stateApplier).applyDifference(eq(umsUsersState), eq(ENV_CRN), any(), eq(usersStateDifference), eq(options), eq(FREE_IPA_CLIENT));
    SyncStatusDetail result = underTest.synchronizeStack(STACK, umsUsersState, options);
    verify(freeIpaUsersStateProvider, never()).getFilteredFreeIpaState(any(), any());
    verify(cloudIdentitySyncService).syncCloudIdentities(eq(STACK), eq(umsUsersState), any());
    verify(sudoRuleService).setupSudoRule(STACK, FREE_IPA_CLIENT);
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(COMPLETED, result.getStatus());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) TimeoutException(java.util.concurrent.TimeoutException) Multimap(com.google.common.collect.Multimap) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Mockito.doAnswer(org.mockito.Mockito.doAnswer) WorkloadCredentialsUpdateType(com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Stack(com.sequenceiq.freeipa.entity.Stack) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableSet(com.google.common.collect.ImmutableSet) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) COMPLETED(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.COMPLETED) Collection(java.util.Collection) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) FAILED(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) TRUE(java.lang.Boolean.TRUE) Mockito.mock(org.mockito.Mockito.mock) Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

Example 17 with FAILED

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

the class FreeIpaCreationRetrievalTask method checkStatus.

@Override
public boolean checkStatus(FreeIpaPollerObject freeIpaPollerObject) {
    String environmentCrn = freeIpaPollerObject.getEnvironmentCrn();
    try {
        LOGGER.info("Checking the state of FreeIpa creation progress for environment: '{}'", environmentCrn);
        Optional<DescribeFreeIpaResponse> freeIpaOptional = freeIpaService.describe(environmentCrn);
        if (freeIpaOptional.isEmpty()) {
            throw new FreeIpaOperationFailedException("FreeIpa cluster not found for environment: " + environmentCrn);
        }
        DescribeFreeIpaResponse freeIpa = freeIpaOptional.get();
        if (freeIpa.getStatus().isDeletionInProgress() || freeIpa.getStatus().isSuccessfullyDeleted()) {
            LOGGER.error("FreeIpa '{}' '{}' is getting terminated (status:'{}'), polling is cancelled.", freeIpa.getName(), freeIpa.getCrn(), freeIpa.getStatus());
            throw new FreeIpaOperationFailedException("FreeIpa instance deleted under the creation process.");
        }
        if (freeIpa.getStatus().isFailed()) {
            LOGGER.error("FreeIpa '{}' '{}' is in failed state (status:'{}'), polling is cancelled.", freeIpa.getName(), freeIpa.getCrn(), freeIpa.getStatus());
            throw new FreeIpaOperationFailedException(String.format("Reason: '%s'", freeIpa.getStatusReason()));
        }
        if (freeIpa.getAvailabilityStatus() != null && freeIpa.getAvailabilityStatus().isAvailable()) {
            return true;
        }
    } catch (Exception e) {
        throw new FreeIpaOperationFailedException("FreeIpa creation operation failed. " + e.getMessage(), e);
    }
    return false;
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException)

Example 18 with FAILED

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

the class UserSyncForEnvService method synchronizeUsers.

public void synchronizeUsers(String operationId, String accountId, List<Stack> stacks, UserSyncRequestFilter userSyncFilter, UserSyncOptions options, long startTime) {
    operationService.tryWithOperationCleanup(operationId, accountId, () -> {
        Set<String> environmentCrns = stacks.stream().map(Stack::getEnvironmentCrn).collect(Collectors.toSet());
        UserSyncLogEvent logUserSyncEvent = options.isFullSync() ? FULL_USER_SYNC : PARTIAL_USER_SYNC;
        LOGGER.info("Starting {} for environments {} with operationId {} ...", logUserSyncEvent, environmentCrns, operationId);
        if (options.isFullSync()) {
            umsVirtualGroupCreateService.createVirtualGroups(accountId, stacks);
        }
        Map<String, Future<SyncStatusDetail>> statusFutures = startAsyncSyncsForStacks(operationId, accountId, stacks, userSyncFilter, options, environmentCrns);
        List<SuccessDetails> success = new ArrayList<>();
        List<FailureDetails> failure = new ArrayList<>();
        statusFutures.forEach((envCrn, statusFuture) -> {
            try {
                SyncStatusDetail statusDetail = waitForSyncStatusDetailResult(startTime, statusFuture, accountId);
                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 (TimeoutException e) {
                LOGGER.warn("Sync timed out for env: {}", envCrn, e);
                statusFuture.cancel(true);
                failure.add(new FailureDetails(envCrn, "Timed out"));
            } 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) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 19 with FAILED

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

the class CoreImageProvider method getImage.

@Override
public Optional<ImageWrapper> getImage(ImageSettingsRequest imageSettings, String region, String platform) {
    try {
        ImageV4Response imageV4Response = imageCatalogV4Endpoint.getSingleImageByCatalogNameAndImageId(WORKSPACE_ID_DEFAULT, imageSettings.getCatalog(), imageSettings.getId());
        Optional<Image> image = convert(imageV4Response);
        return image.map(i -> new ImageWrapper(i, defaultCatalogUrl, imageSettings.getCatalog()));
    } catch (Exception ex) {
        LOGGER.warn("Image lookup failed: {}", ex.getMessage());
        return Optional.empty();
    }
}
Also used : ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 20 with FAILED

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

the class ImageCatalogProvider method getImageCatalog.

@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl")
public ImageCatalog getImageCatalog(String catalogUrl) {
    try {
        if (Objects.nonNull(catalogUrl)) {
            long started = System.currentTimeMillis();
            String content = readCatalogContent(catalogUrl);
            ImageCatalog catalog = objectMapper.readValue(content, ImageCatalog.class);
            if (Objects.nonNull(catalog)) {
                ImageCatalog filteredCatalog = filterImagesByOsType(catalog);
                long timeOfParse = System.currentTimeMillis() - started;
                LOGGER.debug("ImageCatalog was fetched and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse);
                return filteredCatalog;
            }
            throw new ImageCatalogException(String.format("Failed to read the content of '%s' as an image catalog.", catalogUrl));
        }
        throw new ImageCatalogException("Unable to fetch image catalog. The catalogUrl is null.");
    } catch (ImageCatalogException e) {
        throw e;
    } catch (RuntimeException e) {
        throw new ImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getCause(), catalogUrl), e);
    } catch (JsonMappingException e) {
        throw new ImageCatalogException(String.format("Invalid json format for image catalog with error: %s", e.getMessage()), e);
    } catch (IOException e) {
        throw new ImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl));
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog) Cacheable(org.springframework.cache.annotation.Cacheable)

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