@Test public void testClusterDownscaleStartedWhenScalingAdjustmentIsGivenAndItIsNegativeThenInstanceGroupEventWillBeCalledWithTheAbsoluteValueOfThisNumber() { doNothing().when(flowMessageService).fireEventAndLog(STACK_ID, Status.UPDATE_IN_PROGRESS.name(), ResourceEvent.CLUSTER_SCALING_DOWN); underTest.clusterDownscaleStarted(STACK_ID, HOST_GROUP_NAME, -1, PRIVATE_IDS, details); verify(flowMessageService, times(1)).fireInstanceGroupEventAndLog(STACK_ID, Status.UPDATE_IN_PROGRESS.name(), HOST_GROUP_NAME, ResourceEvent.CLUSTER_REMOVING_NODE_FROM_HOSTGROUP, "1", HOST_GROUP_NAME); verify(flowMessageService, times(1)).fireEventAndLog(STACK_ID, Status.UPDATE_IN_PROGRESS.name(), ResourceEvent.CLUSTER_SCALING_DOWN, "worker"); verify(clusterService, times(1)).updateClusterStatusByStackId(STACK_ID, Status.UPDATE_IN_PROGRESS); verify(stackService, times(0)).getByIdWithListsInTransaction(anyLong()); verify(stackService, times(0)).getByIdWithListsInTransaction(STACK_ID); verify(stackService, times(0)).getHostNamesForPrivateIds(anyListOf(InstanceMetaData.class), anySet()); verify(flowMessageService, times(0)).fireInstanceGroupEventAndLog(eq(STACK_ID), anyString(), anyString(), any(ResourceEvent.class), anyString()); }
public void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds, ClusterDownscaleDetails details) { flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_DOWN, hostGroupName); clusterService.updateClusterStatusByStackId(stackId, Status.UPDATE_IN_PROGRESS); if (scalingAdjustment != null) { LOGGER.info("Decommissioning {} hosts from host group '{}'", Math.abs(scalingAdjustment), hostGroupName); flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, CLUSTER_REMOVING_NODE_FROM_HOSTGROUP, String.valueOf(Math.abs(scalingAdjustment)), hostGroupName); } else if (!CollectionUtils.isEmpty(privateIds)) { LOGGER.info("Decommissioning {} hosts from host group '{}'", privateIds, hostGroupName); Stack stack = stackService.getByIdWithListsInTransaction(stackId); List<String> decomissionedHostNames = stackService.getHostNamesForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds); ResourceEvent resourceEvent = details.isForced() ? CLUSTER_FORCE_REMOVING_NODE_FROM_HOSTGROUP : CLUSTER_REMOVING_NODE_FROM_HOSTGROUP; flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, resourceEvent, String.join(",", decomissionedHostNames), hostGroupName); } }
ClusterDownscaleService { public void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds, ClusterDownscaleDetails details) { flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_DOWN, hostGroupName); clusterService.updateClusterStatusByStackId(stackId, Status.UPDATE_IN_PROGRESS); if (scalingAdjustment != null) { LOGGER.info("Decommissioning {} hosts from host group '{}'", Math.abs(scalingAdjustment), hostGroupName); flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, CLUSTER_REMOVING_NODE_FROM_HOSTGROUP, String.valueOf(Math.abs(scalingAdjustment)), hostGroupName); } else if (!CollectionUtils.isEmpty(privateIds)) { LOGGER.info("Decommissioning {} hosts from host group '{}'", privateIds, hostGroupName); Stack stack = stackService.getByIdWithListsInTransaction(stackId); List<String> decomissionedHostNames = stackService.getHostNamesForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds); ResourceEvent resourceEvent = details.isForced() ? CLUSTER_FORCE_REMOVING_NODE_FROM_HOSTGROUP : CLUSTER_REMOVING_NODE_FROM_HOSTGROUP; flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, resourceEvent, String.join(",", decomissionedHostNames), hostGroupName); } } }
ClusterDownscaleService { public void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds, ClusterDownscaleDetails details) { flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_DOWN, hostGroupName); clusterService.updateClusterStatusByStackId(stackId, Status.UPDATE_IN_PROGRESS); if (scalingAdjustment != null) { LOGGER.info("Decommissioning {} hosts from host group '{}'", Math.abs(scalingAdjustment), hostGroupName); flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, CLUSTER_REMOVING_NODE_FROM_HOSTGROUP, String.valueOf(Math.abs(scalingAdjustment)), hostGroupName); } else if (!CollectionUtils.isEmpty(privateIds)) { LOGGER.info("Decommissioning {} hosts from host group '{}'", privateIds, hostGroupName); Stack stack = stackService.getByIdWithListsInTransaction(stackId); List<String> decomissionedHostNames = stackService.getHostNamesForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds); ResourceEvent resourceEvent = details.isForced() ? CLUSTER_FORCE_REMOVING_NODE_FROM_HOSTGROUP : CLUSTER_REMOVING_NODE_FROM_HOSTGROUP; flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, resourceEvent, String.join(",", decomissionedHostNames), hostGroupName); } }  }
ClusterDownscaleService { public void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds, ClusterDownscaleDetails details) { flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_DOWN, hostGroupName); clusterService.updateClusterStatusByStackId(stackId, Status.UPDATE_IN_PROGRESS); if (scalingAdjustment != null) { LOGGER.info("Decommissioning {} hosts from host group '{}'", Math.abs(scalingAdjustment), hostGroupName); flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, CLUSTER_REMOVING_NODE_FROM_HOSTGROUP, String.valueOf(Math.abs(scalingAdjustment)), hostGroupName); } else if (!CollectionUtils.isEmpty(privateIds)) { LOGGER.info("Decommissioning {} hosts from host group '{}'", privateIds, hostGroupName); Stack stack = stackService.getByIdWithListsInTransaction(stackId); List<String> decomissionedHostNames = stackService.getHostNamesForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds); ResourceEvent resourceEvent = details.isForced() ? CLUSTER_FORCE_REMOVING_NODE_FROM_HOSTGROUP : CLUSTER_REMOVING_NODE_FROM_HOSTGROUP; flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, resourceEvent, String.join(",", decomissionedHostNames), hostGroupName); } }  void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds, ClusterDownscaleDetails details); void finalizeClusterScaleDown(Long stackId, String hostGroupName); void updateMetadataStatusToFailed(DecommissionResult payload); void updateMetadataStatus(RemoveHostsFailed payload); void handleClusterDownscaleFailure(long stackId, Exception error); }
ClusterDownscaleService { public void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds, ClusterDownscaleDetails details) { flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_SCALING_DOWN, hostGroupName); clusterService.updateClusterStatusByStackId(stackId, Status.UPDATE_IN_PROGRESS); if (scalingAdjustment != null) { LOGGER.info("Decommissioning {} hosts from host group '{}'", Math.abs(scalingAdjustment), hostGroupName); flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, CLUSTER_REMOVING_NODE_FROM_HOSTGROUP, String.valueOf(Math.abs(scalingAdjustment)), hostGroupName); } else if (!CollectionUtils.isEmpty(privateIds)) { LOGGER.info("Decommissioning {} hosts from host group '{}'", privateIds, hostGroupName); Stack stack = stackService.getByIdWithListsInTransaction(stackId); List<String> decomissionedHostNames = stackService.getHostNamesForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds); ResourceEvent resourceEvent = details.isForced() ? CLUSTER_FORCE_REMOVING_NODE_FROM_HOSTGROUP : CLUSTER_REMOVING_NODE_FROM_HOSTGROUP; flowMessageService.fireInstanceGroupEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), hostGroupName, resourceEvent, String.join(",", decomissionedHostNames), hostGroupName); } }  void clusterDownscaleStarted(long stackId, String hostGroupName, Integer scalingAdjustment, Set<Long> privateIds, ClusterDownscaleDetails details); void finalizeClusterScaleDown(Long stackId, String hostGroupName); void updateMetadataStatusToFailed(DecommissionResult payload); void updateMetadataStatus(RemoveHostsFailed payload); void handleClusterDownscaleFailure(long stackId, Exception error);  }