@Test public void testOnApplicationEventWhenFailsFirstTime() { Cluster cluster = getARunningCluster(); when(clusterService.findById(anyLong())).thenReturn(cluster); underTest.onApplicationEvent(new UpdateFailedEvent(AUTOSCALE_CLUSTER_ID)); verify(clusterService).findById(AUTOSCALE_CLUSTER_ID); verify(clusterService, never()).setState(AUTOSCALE_CLUSTER_ID, ClusterState.SUSPENDED); }
@Override public void onApplicationEvent(UpdateFailedEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); Integer failed = Optional.ofNullable(updateFailures.get(autoscaleClusterId)) .map(failedCount -> failedCount + 1) .orElse(1); if (failed < RETRY_THRESHOLD) { updateFailures.put(autoscaleClusterId, failed); LOGGER.debug("Increased failed count '{}' for cluster '{}'", failed, cluster.getStackCrn()); } else { suspendCluster(cluster); updateFailures.remove(autoscaleClusterId); LOGGER.debug("Suspended cluster monitoring for cluster '{}' due to failing update attempts", cluster.getStackCrn()); } }
UpdateFailedHandler implements ApplicationListener<UpdateFailedEvent> { @Override public void onApplicationEvent(UpdateFailedEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); Integer failed = Optional.ofNullable(updateFailures.get(autoscaleClusterId)) .map(failedCount -> failedCount + 1) .orElse(1); if (failed < RETRY_THRESHOLD) { updateFailures.put(autoscaleClusterId, failed); LOGGER.debug("Increased failed count '{}' for cluster '{}'", failed, cluster.getStackCrn()); } else { suspendCluster(cluster); updateFailures.remove(autoscaleClusterId); LOGGER.debug("Suspended cluster monitoring for cluster '{}' due to failing update attempts", cluster.getStackCrn()); } } }
UpdateFailedHandler implements ApplicationListener<UpdateFailedEvent> { @Override public void onApplicationEvent(UpdateFailedEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); Integer failed = Optional.ofNullable(updateFailures.get(autoscaleClusterId)) .map(failedCount -> failedCount + 1) .orElse(1); if (failed < RETRY_THRESHOLD) { updateFailures.put(autoscaleClusterId, failed); LOGGER.debug("Increased failed count '{}' for cluster '{}'", failed, cluster.getStackCrn()); } else { suspendCluster(cluster); updateFailures.remove(autoscaleClusterId); LOGGER.debug("Suspended cluster monitoring for cluster '{}' due to failing update attempts", cluster.getStackCrn()); } }  }
UpdateFailedHandler implements ApplicationListener<UpdateFailedEvent> { @Override public void onApplicationEvent(UpdateFailedEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); Integer failed = Optional.ofNullable(updateFailures.get(autoscaleClusterId)) .map(failedCount -> failedCount + 1) .orElse(1); if (failed < RETRY_THRESHOLD) { updateFailures.put(autoscaleClusterId, failed); LOGGER.debug("Increased failed count '{}' for cluster '{}'", failed, cluster.getStackCrn()); } else { suspendCluster(cluster); updateFailures.remove(autoscaleClusterId); LOGGER.debug("Suspended cluster monitoring for cluster '{}' due to failing update attempts", cluster.getStackCrn()); } }  @Override void onApplicationEvent(UpdateFailedEvent event); }
UpdateFailedHandler implements ApplicationListener<UpdateFailedEvent> { @Override public void onApplicationEvent(UpdateFailedEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); Integer failed = Optional.ofNullable(updateFailures.get(autoscaleClusterId)) .map(failedCount -> failedCount + 1) .orElse(1); if (failed < RETRY_THRESHOLD) { updateFailures.put(autoscaleClusterId, failed); LOGGER.debug("Increased failed count '{}' for cluster '{}'", failed, cluster.getStackCrn()); } else { suspendCluster(cluster); updateFailures.remove(autoscaleClusterId); LOGGER.debug("Suspended cluster monitoring for cluster '{}' due to failing update attempts", cluster.getStackCrn()); } }  @Override void onApplicationEvent(UpdateFailedEvent event);  }