Search in sources :

Example 1 with RemoveHostsResponse

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

the class RemoveHostsResponseToDownscaleFailureEventConverter method convert.

@Override
public DownscaleFailureEvent convert(Object payload) {
    RemoveHostsResponse removeHostsResponse = (RemoveHostsResponse) payload;
    DownscaleFailureEvent event = new DownscaleFailureEvent(removeHostsResponse.getResourceId(), "Hosts removal", removeHostsResponse.getHostCleanupSuccess(), removeHostsResponse.getHostCleanupFailed(), new Exception("Payload failed: " + payload));
    return event;
}
Also used : RemoveHostsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsResponse) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)

Example 2 with RemoveHostsResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsResponse 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 3 with RemoveHostsResponse

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

the class FreeIpaCleanupActions method removeDnsEntriesAction.

@Bean(name = "REMOVE_DNS_ENTRIES_STATE")
public Action<?, ?> removeDnsEntriesAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveHostsResponse.class) {

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

Example 4 with RemoveHostsResponse

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

the class RemoveHostsResponseToCleanupFailureEventConverter method convert.

@Override
public CleanupFailureEvent convert(Object payload) {
    RemoveHostsResponse removeHostsResponse = (RemoveHostsResponse) payload;
    CleanupFailureEvent event = new CleanupFailureEvent(removeHostsResponse, "Hosts removal", removeHostsResponse.getHostCleanupFailed(), removeHostsResponse.getHostCleanupSuccess());
    return event;
}
Also used : RemoveHostsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.host.RemoveHostsResponse)

Example 5 with RemoveHostsResponse

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

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