use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersRequest in project cloudbreak by hortonworks.
the class FreeIpaCleanupActions method removeUsersAction.
@Bean(name = "REMOVE_USERS_STATE")
public Action<?, ?> removeUsersAction() {
return new AbstractFreeIpaCleanupAction<>(RemoveVaultEntriesResponse.class) {
@Override
protected void doExecute(FreeIpaContext context, RemoveVaultEntriesResponse payload, Map<Object, Object> variables) {
if (shouldSkipState(payload, variables) || payload.getUsers() == null || payload.getUsers().isEmpty()) {
LOGGER.info("User is empty, skipping removing users");
RemoveUsersResponse response = new RemoveUsersResponse(payload, Collections.emptySet(), Collections.emptyMap());
sendEvent(context, response);
} else {
RemoveUsersRequest request = new RemoveUsersRequest(payload, context.getStack());
sendEvent(context, request);
}
}
};
}
use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersRequest in project cloudbreak by hortonworks.
the class UserRemoveHandler method accept.
@Override
public void accept(Event<RemoveUsersRequest> event) {
RemoveUsersRequest request = event.getData();
try {
Pair<Set<String>, Map<String, String>> removeUsersResult = cleanupService.removeUsers(request.getResourceId(), request.getUsers(), request.getClusterName(), request.getEnvironmentCrn());
RemoveUsersResponse response = new RemoveUsersResponse(request, removeUsersResult.getFirst(), removeUsersResult.getSecond());
eventBus.notify(response.getUserCleanupFailed().isEmpty() ? EventSelectorUtil.selector(RemoveUsersResponse.class) : EventSelectorUtil.failureSelector(RemoveUsersResponse.class), new Event<>(event.getHeaders(), response));
} catch (Exception e) {
LOGGER.error("Removing users failed: [{}]", request.getUsers(), e);
Map<String, String> failureResult = request.getUsers().stream().collect(Collectors.toMap(h -> h, h -> e.getMessage()));
RemoveUsersResponse response = new RemoveUsersResponse(request, Collections.emptySet(), failureResult);
eventBus.notify(EventSelectorUtil.failureSelector(RemoveUsersResponse.class), new Event<>(event.getHeaders(), response));
}
}
Aggregations