Search in sources :

Example 1 with RemoveUsersResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse 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 RemoveUsersResponse

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

Example 3 with RemoveUsersResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse in project cloudbreak by hortonworks.

the class RemoveUsersResponseToCleanupFailureEventConverter method convert.

@Override
public CleanupFailureEvent convert(Object payload) {
    RemoveUsersResponse removeUsersResponse = (RemoveUsersResponse) payload;
    CleanupFailureEvent event = new CleanupFailureEvent(removeUsersResponse, "Users removal", removeUsersResponse.getUserCleanupFailed(), removeUsersResponse.getUserCleanupSuccess());
    return event;
}
Also used : RemoveUsersResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse)

Example 4 with RemoveUsersResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse 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));
    }
}
Also used : RemoveUsersResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse) Set(java.util.Set) Event(reactor.bus.Event) Map(java.util.Map) RemoveUsersRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersRequest)

Aggregations

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