Search in sources :

Example 1 with RemoveHostsRequest

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsRequest in project cloudbreak by hortonworks.

the class FreeIpaCleanupActions method removeHostsAction.

@Bean(name = "REMOVE_HOSTS_STATE")
public Action<?, ?> removeHostsAction() {
    return new AbstractFreeIpaCleanupAction<>(RevokeCertsResponse.class) {

        @Override
        protected void doExecute(FreeIpaContext context, RevokeCertsResponse payload, Map<Object, Object> variables) {
            if (shouldSkipState(payload, variables) || payload.getHosts() == null || payload.getHosts().isEmpty()) {
                LOGGER.info("Host is empty, skipping removing hosts");
                RemoveHostsResponse response = new RemoveHostsResponse(payload, Collections.emptySet(), Collections.emptyMap());
                sendEvent(context, response);
            } else {
                RemoveHostsRequest request = new RemoveHostsRequest(payload, context.getStack());
                sendEvent(context, request);
            }
        }
    };
}
Also used : RemoveHostsRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsRequest) RemoveHostsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsResponse) RevokeCertsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.cert.RevokeCertsResponse) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with RemoveHostsRequest

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsRequest in project cloudbreak by hortonworks.

the class HostRemoveHandler method accept.

@Override
public void accept(Event<RemoveHostsRequest> event) {
    RemoveHostsRequest request = event.getData();
    try {
        Pair<Set<String>, Map<String, String>> removeHostsResult = cleanupService.removeHosts(request.getResourceId(), request.getHosts());
        RemoveHostsResponse response = new RemoveHostsResponse(request, removeHostsResult.getFirst(), removeHostsResult.getSecond());
        eventBus.notify(response.getHostCleanupFailed().isEmpty() ? EventSelectorUtil.selector(RemoveHostsResponse.class) : EventSelectorUtil.failureSelector(RemoveHostsResponse.class), new Event<>(event.getHeaders(), response));
    } catch (Exception e) {
        LOGGER.error("Removing failed for hosts: [{}]", request.getHosts(), e);
        Map<String, String> failureResult = request.getHosts().stream().collect(Collectors.toMap(h -> h, h -> e.getMessage()));
        RemoveHostsResponse response = new RemoveHostsResponse(request, Collections.emptySet(), failureResult);
        eventBus.notify(EventSelectorUtil.failureSelector(RemoveHostsResponse.class), new Event<>(event.getHeaders(), response));
    }
}
Also used : RemoveHostsRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsRequest) Set(java.util.Set) RemoveHostsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsResponse) Event(reactor.bus.Event) Map(java.util.Map)

Aggregations

RemoveHostsRequest (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsRequest)2 RemoveHostsResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsResponse)2 Map (java.util.Map)2 RevokeCertsResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.cert.RevokeCertsResponse)1 Set (java.util.Set)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1