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