use of com.sequenceiq.freeipa.api.v1.operation.model.OperationState.COMPLETED 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.operation.model.OperationState.COMPLETED 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.operation.model.OperationState.COMPLETED in project cloudbreak by hortonworks.
the class UpgradeCcmService method finishedState.
public void finishedState(Long stackId) {
InMemoryStateStore.deleteStack(stackId);
DetailedStackStatus detailedStatus = AVAILABLE;
String statusReason = "Upgrade CCM completed";
stackUpdater.updateStackStatus(stackId, detailedStatus, statusReason);
}
use of com.sequenceiq.freeipa.api.v1.operation.model.OperationState.COMPLETED 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);
});
}
use of com.sequenceiq.freeipa.api.v1.operation.model.OperationState.COMPLETED 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;
}
Aggregations