Search in sources :

Example 1 with RemoveRolesRequest

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);
            }
        }
    };
}
Also used : RemoveRolesResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse) RemoveUsersResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse) RemoveRolesRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesRequest) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with RemoveRolesRequest

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));
    }
}
Also used : RemoveRolesResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse) RemoveRolesRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesRequest) Set(java.util.Set) Event(reactor.bus.Event) Map(java.util.Map)

Aggregations

RemoveRolesRequest (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesRequest)2 RemoveRolesResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse)2 Map (java.util.Map)2 RemoveUsersResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse)1 Set (java.util.Set)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1