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