Search in sources :

Example 1 with RemoveVaultEntriesResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesResponse in project cloudbreak by hortonworks.

the class FreeIpaCleanupActions method removeUsersAction.

@Bean(name = "REMOVE_USERS_STATE")
public Action<?, ?> removeUsersAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveVaultEntriesResponse.class) {

        @Override
        protected void doExecute(FreeIpaContext context, RemoveVaultEntriesResponse payload, Map<Object, Object> variables) {
            if (shouldSkipState(payload, variables) || payload.getUsers() == null || payload.getUsers().isEmpty()) {
                LOGGER.info("User is empty, skipping removing users");
                RemoveUsersResponse response = new RemoveUsersResponse(payload, Collections.emptySet(), Collections.emptyMap());
                sendEvent(context, response);
            } else {
                RemoveUsersRequest request = new RemoveUsersRequest(payload, context.getStack());
                sendEvent(context, request);
            }
        }
    };
}
Also used : RemoveUsersResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse) RemoveVaultEntriesResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesResponse) Map(java.util.Map) RemoveUsersRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersRequest) Bean(org.springframework.context.annotation.Bean)

Example 2 with RemoveVaultEntriesResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesResponse in project cloudbreak by hortonworks.

the class FreeIpaCleanupActions method removeVaultEntriesAction.

@Bean(name = "REMOVE_VAULT_ENTRIES_STATE")
public Action<?, ?> removeVaultEntriesAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveDnsResponse.class) {

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

Example 3 with RemoveVaultEntriesResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesResponse in project cloudbreak by hortonworks.

the class RemoveVaultEntriesResponseToCleanupFailureEventConverter method convert.

@Override
public CleanupFailureEvent convert(Object payload) {
    RemoveVaultEntriesResponse removeVaultEntriesResponse = (RemoveVaultEntriesResponse) payload;
    CleanupFailureEvent event = new CleanupFailureEvent(removeVaultEntriesResponse, "Vault entry removal", removeVaultEntriesResponse.getVaultCleanupFailed(), removeVaultEntriesResponse.getVaultCleanupSuccess());
    return event;
}
Also used : RemoveVaultEntriesResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesResponse)

Example 4 with RemoveVaultEntriesResponse

use of com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesResponse in project cloudbreak by hortonworks.

the class VaultRemoveHandler method accept.

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

Aggregations

RemoveVaultEntriesResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesResponse)4 Map (java.util.Map)3 RemoveVaultEntriesRequest (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.vault.RemoveVaultEntriesRequest)2 Bean (org.springframework.context.annotation.Bean)2 RemoveDnsResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.dns.RemoveDnsResponse)1 RemoveUsersRequest (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersRequest)1 RemoveUsersResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.users.RemoveUsersResponse)1 Set (java.util.Set)1 Event (reactor.bus.Event)1