use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails 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.FailureDetails in project cloudbreak by hortonworks.
the class RebootActions method rebootFailureAction.
@Bean(name = "REBOOT_FAILED_STATE")
public Action<?, ?> rebootFailureAction() {
return new AbstractRebootAction<>(InstanceFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(RebootContext context, InstanceFailureEvent payload, Map<Object, Object> variables) {
addMdcOperationId(variables);
rebootService.handleInstanceRebootError(context);
String message = String.format("Rebooting failed for %s.", context.getInstanceIds());
LOGGER.error(message);
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
FailureDetails failureDetails = new FailureDetails(stack.getEnvironmentCrn(), message);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
sendEvent(context, new InstanceEvent(RebootEvent.REBOOT_FAIL_HANDLED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList()));
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, InstanceFailureEvent payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getStackById(stackId);
MDCBuilder.buildMdcContext(stack);
return new RebootContext(flowParameters, stack, payload.getInstanceIds().stream().map(instanceId -> {
InstanceMetaData md = new InstanceMetaData();
md.setInstanceId(instanceId);
return md;
}).collect(Collectors.toList()), null, null);
}
@Override
protected Object getFailurePayload(InstanceFailureEvent payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<InstanceFailureEvent>> payloadConverters) {
payloadConverters.add(new RebootInstancesResultToCleanupFailureEventConverter());
payloadConverters.add(new WaitUntilAvailableFailedToInstanceFailureEventConverter());
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class SyncOperationToOperationStatusConverterTest method convertCompleted.
@Test
void convertCompleted() {
OperationState operationState = OperationState.COMPLETED;
SynchronizationStatus synchronizationStatus = SynchronizationStatus.fromOperationState(operationState);
List<SuccessDetails> successDetails = List.of(new SuccessDetails("environment1"), new SuccessDetails("environment2"));
List<FailureDetails> failureDetails = List.of(new FailureDetails("environment3", "failure message1"), new FailureDetails("environment4", "failure message2"));
Operation operation = createSyncOperation(operationState);
operation.setSuccessList(successDetails);
operation.setFailureList(failureDetails);
SyncOperationStatus actual = underTest.convert(operation);
assertEqualsDefaults(actual);
assertEquals(synchronizationStatus, actual.getStatus());
assertEquals(successDetails, actual.getSuccess());
assertEquals(failureDetails, actual.getFailure());
assertNull(actual.getError());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class FreeIpaCleanupActions method cleanupFailureAction.
@Bean(name = "CLEANUP_FAILED_STATE")
public Action<?, ?> cleanupFailureAction() {
return new AbstractFreeIpaCleanupAction<>(CleanupFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(FreeIpaContext context, CleanupFailureEvent payload, Map<Object, Object> variables) {
LOGGER.error("Cleanup failed with payload: " + payload);
String environmentCrn = payload.getEnvironmentCrn();
SuccessDetails successDetails = new SuccessDetails(environmentCrn);
successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
String message = "Cleanup failed during " + payload.getFailedPhase();
FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
if (payload.getFailureDetails() != null) {
failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
}
operationService.failOperation(payload.getAccountId(), payload.getOperationId(), message, List.of(successDetails), List.of(failureDetails));
sendEvent(context, FreeIpaCleanupEvent.CLEANUP_FAILURE_HANDLED_EVENT.event(), payload);
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<CleanupFailureEvent>> payloadConverters) {
payloadConverters.add(new RemoveDnsResponseToCleanupFailureEventConverter());
payloadConverters.add(new RemoveHostsResponseToCleanupFailureEventConverter());
payloadConverters.add(new RemoveRolesResponseToCleanupFailureEventConverter());
payloadConverters.add(new RemoveUsersResponseToCleanupFailureEventConverter());
payloadConverters.add(new RevokeCertsResponseToCleanupFailureEventConverter());
payloadConverters.add(new RemoveVaultEntriesResponseToCleanupFailureEventConverter());
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class UserSyncForEnvServiceTest method testSyncUsersInterrupted.
@Test
public void testSyncUsersInterrupted() {
Stack stack1 = mock(Stack.class);
when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
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);
when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1));
when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
Future future = mock(Future.class);
when(future.get()).thenThrow(new InterruptedException("interrupt"));
return future;
});
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1), 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("interrupt")), hasProperty("additionalDetails", anEmptyMap())))));
}
Aggregations