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());
}
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;
}
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);
});
}
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();
}
}
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));
}
}
Aggregations