use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class FreeIpaServiceTest method synchronizeAllUsersInEnvironmentOngoing.
// @Test
// void getSyncOperationStatusSuccess() {
// SyncOperationStatus status = createStatus(SynchronizationStatus.COMPLETED, "nope");
// when(userV1Endpoint.getSyncOperationStatusInternal(any(), eq(OPERATION))).thenReturn(status);
// SyncOperationStatus result = ThreadBasedUserCrnProvider.doAsInternalActor(() ->
// underTest.getSyncOperationStatus(ENVCRN, OPERATION));
// assertThat(result).isEqualTo(status);
// }
// @Test
// void getSyncOperationStatusFailure() {
// when(webApplicationExceptionMessageExtractor.getErrorMessage(any())).thenReturn("custom error");
// when(userV1Endpoint.getSyncOperationStatusInternal(any(), eq(OPERATION))).thenThrow(new WebApplicationException("network error"));
// assertThatThrownBy(() -> ThreadBasedUserCrnProvider.doAsInternalActor(() ->
// underTest.getSyncOperationStatus(ENVCRN, OPERATION))).isInstanceOf(FreeIpaOperationFailedException.class);
// }
@Test
void synchronizeAllUsersInEnvironmentOngoing() {
SyncOperationStatus status = createStatus(SynchronizationStatus.RUNNING, "");
when(userV1Endpoint.getLastSyncOperationStatus(any())).thenReturn(status);
SyncOperationStatus result = underTest.synchronizeAllUsersInEnvironment(ENVCRN);
assertThat(result).isEqualTo(status);
verify(userV1Endpoint, times(0)).synchronizeAllUsers(any());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class AltusMachineUserService method syncEnvironment.
private void syncEnvironment(String accountId, String machineUserCrn, String environmentCrn, Optional<String> deletedWorkloadUserName) {
SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
request.setAccountId(accountId);
request.setEnvironments(Set.of(environmentCrn));
request.setMachineUsers(Set.of(machineUserCrn));
deletedWorkloadUserName.ifPresent(s -> request.setDeletedWorkloadUsers(Set.of(s)));
SyncOperationStatus statusResponse = freeIpaCommunicator.synchronizeAllUsers(request);
LOGGER.info("Finished invoking freeIpa user Sync with operation: {}, for environmentCrn: {} and machineUserCrn: {}", statusResponse.getOperationId(), environmentCrn, machineUserCrn);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class UserV1Controller method getLastSyncOperationStatus.
@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.GET_OPERATION_STATUS)
public SyncOperationStatus getLastSyncOperationStatus(@ResourceCrn @TenantAwareParam @NotEmpty String environmentCrn) {
Crn envCrn = Crn.safeFromString(environmentCrn);
EnvironmentUserSyncState userSyncState = environmentUserSyncStateCalculator.calculateEnvironmentUserSyncState(envCrn.getAccountId(), envCrn);
return operationToSyncOperationStatus.convert(operationService.getOperationForAccountIdAndOperationId(envCrn.getAccountId(), userSyncState.getLastUserSyncOperationId()));
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class SyncOperationToOperationStatusConverterTest method convertRunning.
@Test
void convertRunning() {
OperationState operationState = OperationState.RUNNING;
SynchronizationStatus synchronizationStatus = SynchronizationStatus.fromOperationState(operationState);
Operation operation = createSyncOperation(operationState);
SyncOperationStatus actual = underTest.convert(operation);
assertEqualsDefaults(actual);
assertEquals(synchronizationStatus, actual.getStatus());
assertEquals(List.of(), actual.getSuccess());
assertEquals(List.of(), actual.getFailure());
assertNull(actual.getError());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.
the class UserV1ControllerTest method synchronizeAllUsers.
@Test
void synchronizeAllUsers() {
Set<String> environments = Set.of(ENV_CRN);
Set<String> users = Set.of(USER_CRN);
Set<String> machineUsers = Set.of(MACHINE_USER_CRN);
SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
request.setEnvironments(environments);
request.setUsers(users);
request.setMachineUsers(machineUsers);
request.setWorkloadCredentialsUpdateType(WorkloadCredentialsUpdateType.FORCE_UPDATE);
Operation operation = mock(Operation.class);
when(userSyncService.synchronizeUsersWithCustomPermissionCheck(any(), any(), any(), any(), any(), any())).thenReturn(operation);
SyncOperationStatus status = mock(SyncOperationStatus.class);
when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeAllUsers(request)));
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(users, machineUsers, Optional.empty());
verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, environments, userSyncFilter, WorkloadCredentialsUpdateType.FORCE_UPDATE, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Aggregations