Search in sources :

Example 1 with RemoveServersRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest in project cloudbreak by hortonworks.

the class ServerRemoveHandlerTest method testSendsFailureMessageWhenExceptionIsThrown.

@Test
void testSendsFailureMessageWhenExceptionIsThrown() throws FreeIpaClientException {
    CleanupEvent cleanupEvent = new CleanupEvent(STACK_ID, USERS, HOSTS, ROLES, IPS, STATES_TO_SKIP, ACCOUNT_ID, OPERATION_ID, CLUSTER_NAME, ENVIRONMENT_CRN);
    RemoveServersRequest request = new RemoveServersRequest(cleanupEvent);
    when(cleanupService.removeServers(any(), any())).thenThrow(new FreeIpaClientException("expected exception"));
    underTest.accept(new Event<>(request));
    verify(cleanupService, times(1)).removeServers(eq(STACK_ID), eq(HOSTS));
    verify(eventBus).notify(eq("REMOVESERVERSRESPONSE_ERROR"), ArgumentMatchers.<Event>any());
}
Also used : RemoveServersRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 2 with RemoveServersRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest in project cloudbreak by hortonworks.

the class ServerRemoveHandlerTest method testSendsFailureMessageWhenSomeServersFail.

@Test
void testSendsFailureMessageWhenSomeServersFail() throws FreeIpaClientException {
    CleanupEvent cleanupEvent = new CleanupEvent(STACK_ID, USERS, HOSTS, ROLES, IPS, STATES_TO_SKIP, ACCOUNT_ID, OPERATION_ID, CLUSTER_NAME, ENVIRONMENT_CRN);
    RemoveServersRequest request = new RemoveServersRequest(cleanupEvent);
    Set<String> successList = Set.of("example1.com");
    Map<String, String> errorMap = Map.of("example2.com", "expected exception");
    when(cleanupService.removeServers(any(), any())).thenReturn(Pair.of(successList, errorMap));
    underTest.accept(new Event<>(request));
    verify(cleanupService, times(1)).removeServers(eq(STACK_ID), eq(HOSTS));
    verify(eventBus).notify(eq("REMOVESERVERSRESPONSE_ERROR"), ArgumentMatchers.<Event>any());
}
Also used : RemoveServersRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) Test(org.junit.jupiter.api.Test)

Example 3 with RemoveServersRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest in project cloudbreak by hortonworks.

the class ServerRemoveHandlerTest method testSendsSuccessMessageWhenAllServersSucceed.

@Test
void testSendsSuccessMessageWhenAllServersSucceed() throws FreeIpaClientException {
    CleanupEvent cleanupEvent = new CleanupEvent(STACK_ID, USERS, HOSTS, ROLES, IPS, STATES_TO_SKIP, ACCOUNT_ID, OPERATION_ID, CLUSTER_NAME, ENVIRONMENT_CRN);
    RemoveServersRequest request = new RemoveServersRequest(cleanupEvent);
    Set<String> successList = HOSTS;
    Map<String, String> errorMap = Map.of();
    when(cleanupService.removeServers(any(), any())).thenReturn(Pair.of(successList, errorMap));
    underTest.accept(new Event<>(request));
    verify(cleanupService, times(1)).removeServers(eq(STACK_ID), eq(HOSTS));
    verify(eventBus).notify(eq("REMOVESERVERSRESPONSE"), ArgumentMatchers.<Event>any());
}
Also used : RemoveServersRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) Test(org.junit.jupiter.api.Test)

Example 4 with RemoveServersRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method removeServersAction.

@Bean(name = "DOWNSCALE_REMOVE_SERVERS_STATE")
public Action<?, ?> removeServersAction() {
    return new AbstractDownscaleAction<>(DownscaleStackResult.class) {

        @Override
        protected void doExecute(StackContext context, DownscaleStackResult payload, Map<Object, Object> variables) {
            CleanupEvent cleanupEvent = buildCleanupEvent(context, getDownscaleHosts(variables));
            stackUpdater.updateStackStatus(context.getStack().getId(), getInProgressStatus(variables), "Removing servers");
            RemoveServersRequest request = new RemoveServersRequest(cleanupEvent);
            sendEvent(context, request);
        }
    };
}
Also used : RemoveServersRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 5 with RemoveServersRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest in project cloudbreak by hortonworks.

the class ServerRemoveHandler method accept.

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

Aggregations

RemoveServersRequest (com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest)5 CleanupEvent (com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent)4 Test (org.junit.jupiter.api.Test)3 Map (java.util.Map)2 DownscaleStackResult (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 RemoveServersResponse (com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersResponse)1 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)1 Set (java.util.Set)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1