@Test public void testOnApplicationEventWhenCBStackStatusInActiveCBClusterStatusActive() { Cluster cluster = getACluster(ClusterState.SUSPENDED); when(clusterService.findById(anyLong())).thenReturn(cluster); StackStatusV4Response stackStatusV4Response = new StackStatusV4Response(); stackStatusV4Response.setStatus(Status.UPDATE_IN_PROGRESS); stackStatusV4Response.setClusterStatus(Status.AVAILABLE); when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenReturn(stackStatusV4Response); underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID)); verify(clusterService, never()).setState(anyLong(), any(ClusterState.class)); verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN); }
@Override public void onApplicationEvent(ClusterStatusSyncEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn()); boolean clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false) && Optional.ofNullable(statusResponse.getClusterStatus()).map(Status::isAvailable).orElse(false); LOGGER.debug("Analysing CBCluster Status '{}' for Cluster '{}' ", statusResponse, cluster.getStackCrn()); if (DELETE_COMPLETED.equals(statusResponse.getStatus())) { clusterService.removeById(autoscaleClusterId); LOGGER.info("Deleted cluster '{}', CB Stack Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus()); } else if (clusterAvailable && !RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.RUNNING); LOGGER.info("Updated cluster '{}' to Running, CB Stack Status '{}', CB Cluster Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } else if (!clusterAvailable && RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.SUSPENDED); LOGGER.info("Suspended cluster '{}', CB Stack Status '{}', CB Cluster Status '{}'", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } }
ClusterStatusSyncHandler implements ApplicationListener<ClusterStatusSyncEvent> { @Override public void onApplicationEvent(ClusterStatusSyncEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn()); boolean clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false) && Optional.ofNullable(statusResponse.getClusterStatus()).map(Status::isAvailable).orElse(false); LOGGER.debug("Analysing CBCluster Status '{}' for Cluster '{}' ", statusResponse, cluster.getStackCrn()); if (DELETE_COMPLETED.equals(statusResponse.getStatus())) { clusterService.removeById(autoscaleClusterId); LOGGER.info("Deleted cluster '{}', CB Stack Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus()); } else if (clusterAvailable && !RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.RUNNING); LOGGER.info("Updated cluster '{}' to Running, CB Stack Status '{}', CB Cluster Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } else if (!clusterAvailable && RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.SUSPENDED); LOGGER.info("Suspended cluster '{}', CB Stack Status '{}', CB Cluster Status '{}'", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } } }
ClusterStatusSyncHandler implements ApplicationListener<ClusterStatusSyncEvent> { @Override public void onApplicationEvent(ClusterStatusSyncEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn()); boolean clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false) && Optional.ofNullable(statusResponse.getClusterStatus()).map(Status::isAvailable).orElse(false); LOGGER.debug("Analysing CBCluster Status '{}' for Cluster '{}' ", statusResponse, cluster.getStackCrn()); if (DELETE_COMPLETED.equals(statusResponse.getStatus())) { clusterService.removeById(autoscaleClusterId); LOGGER.info("Deleted cluster '{}', CB Stack Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus()); } else if (clusterAvailable && !RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.RUNNING); LOGGER.info("Updated cluster '{}' to Running, CB Stack Status '{}', CB Cluster Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } else if (!clusterAvailable && RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.SUSPENDED); LOGGER.info("Suspended cluster '{}', CB Stack Status '{}', CB Cluster Status '{}'", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } }  }
ClusterStatusSyncHandler implements ApplicationListener<ClusterStatusSyncEvent> { @Override public void onApplicationEvent(ClusterStatusSyncEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn()); boolean clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false) && Optional.ofNullable(statusResponse.getClusterStatus()).map(Status::isAvailable).orElse(false); LOGGER.debug("Analysing CBCluster Status '{}' for Cluster '{}' ", statusResponse, cluster.getStackCrn()); if (DELETE_COMPLETED.equals(statusResponse.getStatus())) { clusterService.removeById(autoscaleClusterId); LOGGER.info("Deleted cluster '{}', CB Stack Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus()); } else if (clusterAvailable && !RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.RUNNING); LOGGER.info("Updated cluster '{}' to Running, CB Stack Status '{}', CB Cluster Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } else if (!clusterAvailable && RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.SUSPENDED); LOGGER.info("Suspended cluster '{}', CB Stack Status '{}', CB Cluster Status '{}'", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } }  @Override void onApplicationEvent(ClusterStatusSyncEvent event); }
ClusterStatusSyncHandler implements ApplicationListener<ClusterStatusSyncEvent> { @Override public void onApplicationEvent(ClusterStatusSyncEvent event) { long autoscaleClusterId = event.getClusterId(); Cluster cluster = clusterService.findById(autoscaleClusterId); if (cluster == null) { return; } MDCBuilder.buildMdcContext(cluster); StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn()); boolean clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false) && Optional.ofNullable(statusResponse.getClusterStatus()).map(Status::isAvailable).orElse(false); LOGGER.debug("Analysing CBCluster Status '{}' for Cluster '{}' ", statusResponse, cluster.getStackCrn()); if (DELETE_COMPLETED.equals(statusResponse.getStatus())) { clusterService.removeById(autoscaleClusterId); LOGGER.info("Deleted cluster '{}', CB Stack Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus()); } else if (clusterAvailable && !RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.RUNNING); LOGGER.info("Updated cluster '{}' to Running, CB Stack Status '{}', CB Cluster Status '{}'.", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } else if (!clusterAvailable && RUNNING.equals(cluster.getState())) { clusterService.setState(cluster.getId(), ClusterState.SUSPENDED); LOGGER.info("Suspended cluster '{}', CB Stack Status '{}', CB Cluster Status '{}'", cluster.getStackCrn(), statusResponse.getStatus(), statusResponse.getClusterStatus()); } }  @Override void onApplicationEvent(ClusterStatusSyncEvent event);  }