use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.
the class UserSyncForEnvService method startAsyncSyncsForStacks.
private Map<String, Future<SyncStatusDetail>> startAsyncSyncsForStacks(String operationId, String accountId, List<Stack> stacks, UserSyncRequestFilter userSyncFilter, UserSyncOptions options, Set<String> environmentCrns) {
if (userSyncFilter.getDeletedWorkloadUser().isEmpty()) {
UserSyncLogEvent logRetrieveUmsEvent = options.isFullSync() ? RETRIEVE_FULL_UMS_STATE : RETRIEVE_PARTIAL_UMS_STATE;
LOGGER.debug("Starting {} for environments {} ...", logRetrieveUmsEvent, environmentCrns);
Map<String, UmsUsersState> envToUmsStateMap = umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(accountId, environmentCrns, userSyncFilter.getUserCrnFilter(), userSyncFilter.getMachineUserCrnFilter(), MDCUtils.getRequestId());
LOGGER.debug("Finished {}.", logRetrieveUmsEvent);
UmsEventGenerationIds umsEventGenerationIds = options.isFullSync() ? umsEventGenerationIdsProvider.getEventGenerationIds(accountId, MDCUtils.getRequestId()) : null;
return stacks.stream().collect(Collectors.toMap(Stack::getEnvironmentCrn, stack -> asyncSynchronizeStack(stack, envToUmsStateMap.get(stack.getEnvironmentCrn()), umsEventGenerationIds, options, operationId, accountId)));
} else {
String deletedWorkloadUser = userSyncFilter.getDeletedWorkloadUser().get();
return stacks.stream().collect(Collectors.toMap(Stack::getEnvironmentCrn, stack -> asyncSynchronizeStackForDeleteUser(stack, deletedWorkloadUser)));
}
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.
the class EventGenerationIdsChecker method isInSync.
public boolean isInSync(UserSyncStatus userSyncStatus, UmsEventGenerationIds currentGeneration) {
Stack stack = userSyncStatus.getStack();
boolean inSync = userSyncStatus != null && userSyncStatus.getUmsEventGenerationIds() != null;
if (inSync) {
try {
UmsEventGenerationIds lastUmsEventGenerationIds = userSyncStatus.getUmsEventGenerationIds().get(UmsEventGenerationIds.class);
inSync = currentGeneration.equals(lastUmsEventGenerationIds);
} catch (IOException e) {
LOGGER.warn("Failed to retrieve UmsEventGenerationIds for Environment {} in Account {}. Assuming not in sync", stack.getEnvironmentCrn(), stack.getAccountId());
inSync = false;
}
}
LOGGER.debug("Environment {} in Account {} {} in sync", stack.getEnvironmentCrn(), stack.getAccountId(), inSync ? "is" : "is not");
return inSync;
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.
the class UserSyncPoller method syncFreeIpaStacksInAccount.
private void syncFreeIpaStacksInAccount(Optional<String> requestId, String accountId, List<Stack> stacks) {
Instant cooldownThresholdTime = Instant.now().minus(cooldown);
UmsEventGenerationIds currentGeneration = umsEventGenerationIdsProvider.getEventGenerationIds(accountId, requestId);
stacks.forEach(stack -> {
UserSyncStatus userSyncStatus = userSyncStatusService.getOrCreateForStack(stack);
if (!eventGenerationIdsChecker.isInSync(userSyncStatus, currentGeneration) && cooldownChecker.isCooldownExpired(userSyncStatus, cooldownThresholdTime)) {
LOGGER.debug("Environment {} in Account {} is not in sync.", stack.getEnvironmentCrn(), stack.getAccountId());
Operation operation = userSyncService.synchronizeUsers(stack.getAccountId(), regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), Set.of(stack.getEnvironmentCrn()), Set.of(), Set.of(), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
LOGGER.debug("User Sync request resulted in operation {}", operation);
} else {
LOGGER.debug("Environment {} in Account {} is in sync or has been synchronized recently.", stack.getEnvironmentCrn(), stack.getAccountId());
}
});
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds 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);
});
}
Aggregations