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