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);
}
}
};
}
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);
}
};
}
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));
}
}
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;
}
Aggregations