@Test public void testOnApplicationEventWhenNoScaling() { Cluster cluster = getARunningCluster(); TimeAlert timeAlertMock = mock(TimeAlert.class); when(scalingEventMock.getAlert()).thenReturn(timeAlertMock); when(scalingEventMock.getHostGroupNodeCount()).thenReturn(2); when(scalingEventMock.getDesiredAbsoluteHostGroupNodeCount()).thenReturn(2); when(scalingPolicyMock.getHostGroup()).thenReturn("compute"); when(clusterService.findById(anyLong())).thenReturn(cluster); when(messagesService.getMessage(anyString(), any(List.class))).thenReturn(""); when(timeAlertMock.getCluster()).thenReturn(cluster); when(timeAlertMock.getScalingPolicy()).thenReturn(scalingPolicyMock); when(timeAlertMock.getName()).thenReturn("testalert"); when(timeAlertMock.getAlertType()).thenCallRealMethod(); underTest.onApplicationEvent(scalingEventMock); verify(historyService, times(1)).createEntry( eq(ScalingStatus.SUCCESS), anyString(), eq(2), eq(0), eq(scalingPolicyMock)); verify(clusterService, never()).setLastScalingActivity(eq(AUTOSCALE_CLUSTER_ID), anyLong()); verify(applicationContext, never()).getBean("ScalingRequest"); }
@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);  }