Search in sources :

Example 1 with RemoveRolesResponse

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

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse in project cloudbreak by hortonworks.

the class FreeIpaCleanupActions method cleanupFinishedAction.

@Bean(name = "CLEANUP_FINISHED_STATE")
public Action<?, ?> cleanupFinishedAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveRolesResponse.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(FreeIpaContext context, RemoveRolesResponse payload, Map<Object, Object> variables) {
            CleanupEvent cleanupEvent = new CleanupEvent(FreeIpaCleanupEvent.CLEANUP_FINISHED_EVENT.event(), payload.getResourceId(), payload.getUsers(), payload.getHosts(), payload.getRoles(), payload.getIps(), payload.getStatesToSkip(), payload.getAccountId(), payload.getOperationId(), payload.getClusterName(), payload.getEnvironmentCrn());
            SuccessDetails successDetails = new SuccessDetails(payload.getEnvironmentCrn());
            successDetails.getAdditionalDetails().put("Hosts", payload.getHosts() == null ? List.of() : new ArrayList<>(payload.getHosts()));
            successDetails.getAdditionalDetails().put("Users", payload.getUsers() == null ? List.of() : new ArrayList<>(payload.getUsers()));
            successDetails.getAdditionalDetails().put("Roles", payload.getRoles() == null ? List.of() : new ArrayList<>(payload.getRoles()));
            successDetails.getAdditionalDetails().put("IPs", payload.getIps() == null ? List.of() : new ArrayList<>(payload.getIps()));
            operationService.completeOperation(payload.getAccountId(), payload.getOperationId(), List.of(successDetails), Collections.emptyList());
            LOGGER.info("Cleanup successfully finished with: " + successDetails);
            sendEvent(context, cleanupEvent);
        }
    };
}
Also used : RemoveRolesResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) ArrayList(java.util.ArrayList) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with RemoveRolesResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse 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)

Example 4 with RemoveRolesResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse in project cloudbreak by hortonworks.

the class RemoveRolesResponseToCleanupFailureEventConverter method convert.

@Override
public CleanupFailureEvent convert(Object payload) {
    RemoveRolesResponse removeRolesResponse = (RemoveRolesResponse) payload;
    CleanupFailureEvent event = new CleanupFailureEvent(removeRolesResponse, "Roles removal", removeRolesResponse.getRoleCleanupFailed(), removeRolesResponse.getRoleCleanupSuccess());
    return event;
}
Also used : RemoveRolesResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse)

Aggregations

RemoveRolesResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse)4 Map (java.util.Map)3 RemoveRolesRequest (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesRequest)2 Bean (org.springframework.context.annotation.Bean)2 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 RemoveUsersResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse)1 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Event (reactor.bus.Event)1