@Test public void testOnApplicationEventWhenLoadAlertDecommissionNodes() { LoadAlert loadAlertMock = mock(LoadAlert.class); Cluster cluster = getARunningCluster(); int hostGroupNodeCount = 10; List nodeIds = List.of("nodeId1", "nodeId2", "nodeId3"); int expectedNodeCount = hostGroupNodeCount - nodeIds.size(); when(scalingEventMock.getAlert()).thenReturn(loadAlertMock); when(loadAlertMock.getCluster()).thenReturn(cluster); when(loadAlertMock.getScalingPolicy()).thenReturn(scalingPolicyMock); when(clusterService.findById(anyLong())).thenReturn(cluster); when(scalingPolicyMock.getAdjustmentType()).thenReturn(LOAD_BASED); when(scalingEventMock.getHostGroupNodeCount()).thenReturn(hostGroupNodeCount); when(scalingEventMock.getDesiredAbsoluteHostGroupNodeCount()).thenReturn(expectedNodeCount); when(scalingEventMock.getDecommissionNodeIds()).thenReturn(nodeIds); when(applicationContext.getBean("ScalingRequest", cluster, scalingPolicyMock, hostGroupNodeCount, expectedNodeCount, nodeIds)).thenReturn(runnableMock); underTest.onApplicationEvent(scalingEventMock); verify(rejectedThreadService).remove(AUTOSCALE_CLUSTER_ID); verify(clusterService).setLastScalingActivity(eq(AUTOSCALE_CLUSTER_ID), anyLong()); verify(executorService).submit(runnableMock); }
@Override public void onApplicationEvent(ScalingEvent event) { BaseAlert alert = event.getAlert(); Cluster cluster = clusterService.findById(alert.getCluster().getId()); MDCBuilder.buildMdcContext(cluster); ScalingPolicy policy = alert.getScalingPolicy(); int hostGroupNodeCount = event.getHostGroupNodeCount(); int desiredAbsoluteHostGroupNodeCount = event.getDesiredAbsoluteHostGroupNodeCount(); if (hostGroupNodeCount != desiredAbsoluteHostGroupNodeCount) { Runnable scalingRequest = (Runnable) applicationContext.getBean("ScalingRequest", cluster, policy, hostGroupNodeCount, desiredAbsoluteHostGroupNodeCount, event.getDecommissionNodeIds()); executorService.submit(scalingRequest); rejectedThreadService.remove(cluster.getId()); clusterService.setLastScalingActivity(cluster.getId(), System.currentTimeMillis()); } else { LOGGER.info("Autoscaling activity not required for config '{}', cluster '{}'.", alert.getName(), cluster.getStackCrn()); if (alert instanceof TimeAlert) { historyService.createEntry(ScalingStatus.SUCCESS, messagesService.getMessage(MessageCode.AUTOSCALING_ACTIVITY_NOT_REQUIRED, List.of(alert.getAlertType(), alert.getName(), alert.getScalingPolicy().getHostGroup(), hostGroupNodeCount)), hostGroupNodeCount, 0, policy); } } }
ScalingHandler implements ApplicationListener<ScalingEvent> { @Override public void onApplicationEvent(ScalingEvent event) { BaseAlert alert = event.getAlert(); Cluster cluster = clusterService.findById(alert.getCluster().getId()); MDCBuilder.buildMdcContext(cluster); ScalingPolicy policy = alert.getScalingPolicy(); int hostGroupNodeCount = event.getHostGroupNodeCount(); int desiredAbsoluteHostGroupNodeCount = event.getDesiredAbsoluteHostGroupNodeCount(); if (hostGroupNodeCount != desiredAbsoluteHostGroupNodeCount) { Runnable scalingRequest = (Runnable) applicationContext.getBean("ScalingRequest", cluster, policy, hostGroupNodeCount, desiredAbsoluteHostGroupNodeCount, event.getDecommissionNodeIds()); executorService.submit(scalingRequest); rejectedThreadService.remove(cluster.getId()); clusterService.setLastScalingActivity(cluster.getId(), System.currentTimeMillis()); } else { LOGGER.info("Autoscaling activity not required for config '{}', cluster '{}'.", alert.getName(), cluster.getStackCrn()); if (alert instanceof TimeAlert) { historyService.createEntry(ScalingStatus.SUCCESS, messagesService.getMessage(MessageCode.AUTOSCALING_ACTIVITY_NOT_REQUIRED, List.of(alert.getAlertType(), alert.getName(), alert.getScalingPolicy().getHostGroup(), hostGroupNodeCount)), hostGroupNodeCount, 0, policy); } } } }
ScalingHandler implements ApplicationListener<ScalingEvent> { @Override public void onApplicationEvent(ScalingEvent event) { BaseAlert alert = event.getAlert(); Cluster cluster = clusterService.findById(alert.getCluster().getId()); MDCBuilder.buildMdcContext(cluster); ScalingPolicy policy = alert.getScalingPolicy(); int hostGroupNodeCount = event.getHostGroupNodeCount(); int desiredAbsoluteHostGroupNodeCount = event.getDesiredAbsoluteHostGroupNodeCount(); if (hostGroupNodeCount != desiredAbsoluteHostGroupNodeCount) { Runnable scalingRequest = (Runnable) applicationContext.getBean("ScalingRequest", cluster, policy, hostGroupNodeCount, desiredAbsoluteHostGroupNodeCount, event.getDecommissionNodeIds()); executorService.submit(scalingRequest); rejectedThreadService.remove(cluster.getId()); clusterService.setLastScalingActivity(cluster.getId(), System.currentTimeMillis()); } else { LOGGER.info("Autoscaling activity not required for config '{}', cluster '{}'.", alert.getName(), cluster.getStackCrn()); if (alert instanceof TimeAlert) { historyService.createEntry(ScalingStatus.SUCCESS, messagesService.getMessage(MessageCode.AUTOSCALING_ACTIVITY_NOT_REQUIRED, List.of(alert.getAlertType(), alert.getName(), alert.getScalingPolicy().getHostGroup(), hostGroupNodeCount)), hostGroupNodeCount, 0, policy); } } }  }
ScalingHandler implements ApplicationListener<ScalingEvent> { @Override public void onApplicationEvent(ScalingEvent event) { BaseAlert alert = event.getAlert(); Cluster cluster = clusterService.findById(alert.getCluster().getId()); MDCBuilder.buildMdcContext(cluster); ScalingPolicy policy = alert.getScalingPolicy(); int hostGroupNodeCount = event.getHostGroupNodeCount(); int desiredAbsoluteHostGroupNodeCount = event.getDesiredAbsoluteHostGroupNodeCount(); if (hostGroupNodeCount != desiredAbsoluteHostGroupNodeCount) { Runnable scalingRequest = (Runnable) applicationContext.getBean("ScalingRequest", cluster, policy, hostGroupNodeCount, desiredAbsoluteHostGroupNodeCount, event.getDecommissionNodeIds()); executorService.submit(scalingRequest); rejectedThreadService.remove(cluster.getId()); clusterService.setLastScalingActivity(cluster.getId(), System.currentTimeMillis()); } else { LOGGER.info("Autoscaling activity not required for config '{}', cluster '{}'.", alert.getName(), cluster.getStackCrn()); if (alert instanceof TimeAlert) { historyService.createEntry(ScalingStatus.SUCCESS, messagesService.getMessage(MessageCode.AUTOSCALING_ACTIVITY_NOT_REQUIRED, List.of(alert.getAlertType(), alert.getName(), alert.getScalingPolicy().getHostGroup(), hostGroupNodeCount)), hostGroupNodeCount, 0, policy); } } }  @Override void onApplicationEvent(ScalingEvent event); }
ScalingHandler implements ApplicationListener<ScalingEvent> { @Override public void onApplicationEvent(ScalingEvent event) { BaseAlert alert = event.getAlert(); Cluster cluster = clusterService.findById(alert.getCluster().getId()); MDCBuilder.buildMdcContext(cluster); ScalingPolicy policy = alert.getScalingPolicy(); int hostGroupNodeCount = event.getHostGroupNodeCount(); int desiredAbsoluteHostGroupNodeCount = event.getDesiredAbsoluteHostGroupNodeCount(); if (hostGroupNodeCount != desiredAbsoluteHostGroupNodeCount) { Runnable scalingRequest = (Runnable) applicationContext.getBean("ScalingRequest", cluster, policy, hostGroupNodeCount, desiredAbsoluteHostGroupNodeCount, event.getDecommissionNodeIds()); executorService.submit(scalingRequest); rejectedThreadService.remove(cluster.getId()); clusterService.setLastScalingActivity(cluster.getId(), System.currentTimeMillis()); } else { LOGGER.info("Autoscaling activity not required for config '{}', cluster '{}'.", alert.getName(), cluster.getStackCrn()); if (alert instanceof TimeAlert) { historyService.createEntry(ScalingStatus.SUCCESS, messagesService.getMessage(MessageCode.AUTOSCALING_ACTIVITY_NOT_REQUIRED, List.of(alert.getAlertType(), alert.getName(), alert.getScalingPolicy().getHostGroup(), hostGroupNodeCount)), hostGroupNodeCount, 0, policy); } } }  @Override void onApplicationEvent(ScalingEvent event);  }