use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class UserSyncForEnvServiceTest method testSyncUsersFailures.
@Test
public void testSyncUsersFailures() {
Stack stack1 = mock(Stack.class);
when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
Stack stack2 = mock(Stack.class);
when(stack2.getEnvironmentCrn()).thenReturn(ENV_CRN_2);
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(), Set.of(), Optional.empty());
UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
doAnswer(inv -> {
inv.getArgument(2, Runnable.class).run();
return null;
}).when(operationService).tryWithOperationCleanup(eq(OPERATION_ID), eq(ACCOUNT_ID), any(Runnable.class));
UmsUsersState umsUsersState1 = mock(UmsUsersState.class);
UmsUsersState umsUsersState2 = mock(UmsUsersState.class);
when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN, ENV_CRN_2)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1, ENV_CRN_2, umsUsersState2));
when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
SyncStatusDetail result = (SyncStatusDetail) inv.getArgument(0, Callable.class).call();
Future future = mock(Future.class);
when(future.get()).thenReturn(result);
return future;
});
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
when(userSyncForStackService.synchronizeStack(stack1, umsUsersState1, options)).thenReturn(new SyncStatusDetail(ENV_CRN, SynchronizationStatus.FAILED, "fial1", ImmutableMultimap.of(ENV_CRN, "failed1")));
when(userSyncForStackService.synchronizeStack(stack2, umsUsersState2, options)).thenReturn(new SyncStatusDetail(ENV_CRN_2, SynchronizationStatus.REJECTED, "fial2", ImmutableMultimap.of(ENV_CRN_2, "failed2")));
underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1, stack2), userSyncFilter, options, System.currentTimeMillis());
verifyNoInteractions(userSyncStatusService);
ArgumentCaptor<Collection> successCaptor = ArgumentCaptor.forClass(Collection.class);
ArgumentCaptor<Collection> failureCaptor = ArgumentCaptor.forClass(Collection.class);
verify(operationService).completeOperation(eq(ACCOUNT_ID), eq(OPERATION_ID), successCaptor.capture(), failureCaptor.capture());
assertTrue(successCaptor.getValue().isEmpty());
List<FailureDetails> failures = (List<FailureDetails>) failureCaptor.getValue();
assertThat(failures, allOf(hasItem(allOf(hasProperty("environment", is(ENV_CRN)), hasProperty("message", is("fial1")), hasProperty("additionalDetails", hasEntry(ENV_CRN, "failed1")))), hasItem(allOf(hasProperty("environment", is(ENV_CRN_2)), hasProperty("message", is("Unexpected status: REJECTED")), hasProperty("additionalDetails", hasEntry(ENV_CRN_2, "failed2"))))));
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayActions method failureAction.
@Bean(name = "CHANGE_PRIMARY_GATEWAY_FAIL_STATE")
public Action<?, ?> failureAction() {
return new AbstractChangePrimaryGatewayAction<>(ChangePrimaryGatewayFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected ChangePrimaryGatewayContext createFlowContext(FlowParameters flowParameters, StateContext<ChangePrimaryGatewayState, ChangePrimaryGatewayFlowEvent> stateContext, ChangePrimaryGatewayFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected void doExecute(ChangePrimaryGatewayContext context, ChangePrimaryGatewayFailureEvent payload, Map<Object, Object> variables) {
LOGGER.error("Change primary gateway failed with payload: " + payload);
Stack stack = context.getStack();
String environmentCrn = stack.getEnvironmentCrn();
SuccessDetails successDetails = new SuccessDetails(environmentCrn);
successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
String message = "Change primary gateway failed during " + payload.getFailedPhase();
FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
if (payload.getFailureDetails() != null) {
failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
}
String errorReason = getErrorReason(payload.getException());
stackUpdater.updateStackStatus(context.getStack().getId(), DetailedStackStatus.REPAIR_FAILED, errorReason);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
LOGGER.info("Enabling the status checker for stack ID {} after failing repairing", stack.getId());
enableStatusChecker(stack, "Failed to repair FreeIPA");
enableNodeStatusChecker(stack, "Failed to repair FreeIPA");
sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<ChangePrimaryGatewayFailureEvent>> payloadConverters) {
payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter());
payloadConverters.add(new HealthCheckFailedToChangePrimaryGatewayFailureEventConverter());
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class PasswordService method internalSetPasswords.
private void internalSetPasswords(String operationId, String accountId, String userCrn, String password, List<Stack> stacks) {
try {
String userId = getUserIdFromUserCrn(userCrn);
Optional<Instant> expirationInstant = calculateExpirationTime(userCrn, accountId);
List<SetPasswordRequest> requests = new ArrayList<>();
for (Stack stack : stacks) {
requests.add(triggerSetPassword(stack, stack.getEnvironmentCrn(), userId, userCrn, password, expirationInstant));
}
List<SuccessDetails> success = new ArrayList<>();
List<FailureDetails> failure = new ArrayList<>();
for (SetPasswordRequest request : requests) {
try {
waitSetPassword(request);
success.add(new SuccessDetails(request.getEnvironment()));
} catch (InterruptedException e) {
LOGGER.error("Interrupted while setting passwords for user {} in account {}", userCrn, accountId);
throw e;
} catch (Exception e) {
LOGGER.debug("Failed to set password for user {} in environment {}", userCrn, request.getEnvironment(), e);
failure.add(new FailureDetails(request.getEnvironment(), e.getLocalizedMessage()));
}
}
operationService.completeOperation(accountId, operationId, success, failure);
} catch (InterruptedException e) {
operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
Thread.currentThread().interrupt();
} catch (RuntimeException e) {
operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
throw e;
}
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class UserSyncForEnvService method createFailureDetails.
private FailureDetails createFailureDetails(String envCrn, String details, Multimap<String, String> warnings) {
FailureDetails failureDetails = new FailureDetails(envCrn, details);
Map<String, String> additionalDetails = failureDetails.getAdditionalDetails();
warnings.asMap().forEach((key, value) -> additionalDetails.put(key, String.join(", ", value)));
return failureDetails;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class UserSyncService method createFailureDetails.
private FailureDetails createFailureDetails(String envCrn, String details, Multimap<String, String> warnings) {
FailureDetails failureDetails = new FailureDetails(envCrn, details);
Map<String, String> additionalDetails = failureDetails.getAdditionalDetails();
warnings.asMap().entrySet().forEach(entry -> additionalDetails.put(entry.getKey(), entry.getValue().stream().collect(Collectors.joining(", "))));
return failureDetails;
}
Aggregations