@Test void testSendsSuccessMessageWhenAllServersSucceed() throws Exception { CleanupEvent cleanupEvent = new CleanupEvent(STACK_ID, USERS, HOSTS, ROLES, IPS, STATES_TO_SKIP, ACCOUNT_ID, OPERATION_ID, CLUSTER_NAME, ENVIRONMENT_CRN); RemoveHostsFromOrchestrationRequest request = new RemoveHostsFromOrchestrationRequest(cleanupEvent); Stack stack = new Stack(); when(stackService.getByIdWithListsInTransaction(any())).thenReturn(stack); underTest.accept(new Event<>(request)); verify(eventBus, times(1)).notify(eq("REMOVEHOSTSFROMORCHESTRATIONSUCCESS"), ArgumentMatchers.<Event>any()); verify(bootstrapService).bootstrap(any(), any()); verify(hostOrchestrator).tearDown(any(), any(), any(), any()); }
@Override public void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent) { RemoveHostsFromOrchestrationRequest request = removeHostsRequestEvent.getData(); Set<String> hostNames = request.getHosts(); Selectable result; try { if (!hostNames.isEmpty()) { Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames)); if (!PollingResult.isSuccess(orchestratorRemovalPollingResult)) { LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames); } List<String> remainingInstanceIds = stack.getNotDeletedInstanceMetaDataList().stream() .filter(metadata -> Objects.nonNull(metadata.getDiscoveryFQDN())) .filter(metadata -> !hostNames.contains(metadata.getDiscoveryFQDN())) .map(InstanceMetaData::getInstanceId) .collect(Collectors.toList()); bootstrapService.bootstrap(stack.getId(), remainingInstanceIds); } result = new RemoveHostsFromOrchestrationSuccess(request.getResourceId()); } catch (Exception e) { LOGGER.error("Failed to remove hosts from orchestration", e); result = new DownscaleFailureEvent(REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT.event(), request.getResourceId(), "Removing host from orchestration", Set.of(), Map.of(), e); } eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result)); }
RemoveHostsHandler implements EventHandler<RemoveHostsFromOrchestrationRequest> { @Override public void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent) { RemoveHostsFromOrchestrationRequest request = removeHostsRequestEvent.getData(); Set<String> hostNames = request.getHosts(); Selectable result; try { if (!hostNames.isEmpty()) { Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames)); if (!PollingResult.isSuccess(orchestratorRemovalPollingResult)) { LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames); } List<String> remainingInstanceIds = stack.getNotDeletedInstanceMetaDataList().stream() .filter(metadata -> Objects.nonNull(metadata.getDiscoveryFQDN())) .filter(metadata -> !hostNames.contains(metadata.getDiscoveryFQDN())) .map(InstanceMetaData::getInstanceId) .collect(Collectors.toList()); bootstrapService.bootstrap(stack.getId(), remainingInstanceIds); } result = new RemoveHostsFromOrchestrationSuccess(request.getResourceId()); } catch (Exception e) { LOGGER.error("Failed to remove hosts from orchestration", e); result = new DownscaleFailureEvent(REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT.event(), request.getResourceId(), "Removing host from orchestration", Set.of(), Map.of(), e); } eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result)); } }
RemoveHostsHandler implements EventHandler<RemoveHostsFromOrchestrationRequest> { @Override public void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent) { RemoveHostsFromOrchestrationRequest request = removeHostsRequestEvent.getData(); Set<String> hostNames = request.getHosts(); Selectable result; try { if (!hostNames.isEmpty()) { Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames)); if (!PollingResult.isSuccess(orchestratorRemovalPollingResult)) { LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames); } List<String> remainingInstanceIds = stack.getNotDeletedInstanceMetaDataList().stream() .filter(metadata -> Objects.nonNull(metadata.getDiscoveryFQDN())) .filter(metadata -> !hostNames.contains(metadata.getDiscoveryFQDN())) .map(InstanceMetaData::getInstanceId) .collect(Collectors.toList()); bootstrapService.bootstrap(stack.getId(), remainingInstanceIds); } result = new RemoveHostsFromOrchestrationSuccess(request.getResourceId()); } catch (Exception e) { LOGGER.error("Failed to remove hosts from orchestration", e); result = new DownscaleFailureEvent(REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT.event(), request.getResourceId(), "Removing host from orchestration", Set.of(), Map.of(), e); } eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result)); }  }
RemoveHostsHandler implements EventHandler<RemoveHostsFromOrchestrationRequest> { @Override public void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent) { RemoveHostsFromOrchestrationRequest request = removeHostsRequestEvent.getData(); Set<String> hostNames = request.getHosts(); Selectable result; try { if (!hostNames.isEmpty()) { Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames)); if (!PollingResult.isSuccess(orchestratorRemovalPollingResult)) { LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames); } List<String> remainingInstanceIds = stack.getNotDeletedInstanceMetaDataList().stream() .filter(metadata -> Objects.nonNull(metadata.getDiscoveryFQDN())) .filter(metadata -> !hostNames.contains(metadata.getDiscoveryFQDN())) .map(InstanceMetaData::getInstanceId) .collect(Collectors.toList()); bootstrapService.bootstrap(stack.getId(), remainingInstanceIds); } result = new RemoveHostsFromOrchestrationSuccess(request.getResourceId()); } catch (Exception e) { LOGGER.error("Failed to remove hosts from orchestration", e); result = new DownscaleFailureEvent(REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT.event(), request.getResourceId(), "Removing host from orchestration", Set.of(), Map.of(), e); } eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result)); }  @Override String selector(); @Override void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent); }
RemoveHostsHandler implements EventHandler<RemoveHostsFromOrchestrationRequest> { @Override public void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent) { RemoveHostsFromOrchestrationRequest request = removeHostsRequestEvent.getData(); Set<String> hostNames = request.getHosts(); Selectable result; try { if (!hostNames.isEmpty()) { Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId()); PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames)); if (!PollingResult.isSuccess(orchestratorRemovalPollingResult)) { LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames); } List<String> remainingInstanceIds = stack.getNotDeletedInstanceMetaDataList().stream() .filter(metadata -> Objects.nonNull(metadata.getDiscoveryFQDN())) .filter(metadata -> !hostNames.contains(metadata.getDiscoveryFQDN())) .map(InstanceMetaData::getInstanceId) .collect(Collectors.toList()); bootstrapService.bootstrap(stack.getId(), remainingInstanceIds); } result = new RemoveHostsFromOrchestrationSuccess(request.getResourceId()); } catch (Exception e) { LOGGER.error("Failed to remove hosts from orchestration", e); result = new DownscaleFailureEvent(REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT.event(), request.getResourceId(), "Removing host from orchestration", Set.of(), Map.of(), e); } eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result)); }  @Override String selector(); @Override void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent);  }