@Test public void testUpdateClusterStatusShouldOnlyNotifyWhenStackStatusNotChanged() { Stack stack = createStack(Status.AVAILABLE, Status.AVAILABLE); underTest.updateClusterStatus(stack, stack.getCluster()); Mockito.verify(clusterService, Mockito.times(0)).updateClusterStatusByStackId(any(Long.class), any(Status.class)); }
public void updateClusterStatus(Stack stack, Cluster cluster) { if (isStackOrClusterStatusInvalid(stack, cluster)) { if ((stack.isStackInStopPhase() || stack.isDeleteCompleted()) && cluster != null) { updateClusterStatus(stack.getId(), cluster, stack.getStatus()); cluster.setStatus(stack.getStatus()); } List<String> eventMessageArgs = Arrays.asList(stack.getStatus().name(), cluster == null ? "" : cluster.getStatus().name()); cloudbreakEventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_AMBARI_CLUSTER_COULD_NOT_SYNC, eventMessageArgs); } else if (cluster != null && cluster.getClusterManagerIp() != null) { Long stackId = stack.getId(); clusterService.updateClusterMetadata(stackId); String blueprintName = cluster.getBlueprint().getStackName(); ClusterStatusResult clusterStatusResult = clusterApiConnectors.getConnector(stack).clusterStatusService().getStatus(StringUtils.isNotBlank(blueprintName)); LOGGER.debug("Cluster status: [{}] Status reason: [{}]", clusterStatusResult.getClusterStatus(), clusterStatusResult.getStatusReason()); updateClusterStatus(stackId, stack.getStatus(), cluster, clusterStatusResult); } }
ClusterStatusUpdater { public void updateClusterStatus(Stack stack, Cluster cluster) { if (isStackOrClusterStatusInvalid(stack, cluster)) { if ((stack.isStackInStopPhase() || stack.isDeleteCompleted()) && cluster != null) { updateClusterStatus(stack.getId(), cluster, stack.getStatus()); cluster.setStatus(stack.getStatus()); } List<String> eventMessageArgs = Arrays.asList(stack.getStatus().name(), cluster == null ? "" : cluster.getStatus().name()); cloudbreakEventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_AMBARI_CLUSTER_COULD_NOT_SYNC, eventMessageArgs); } else if (cluster != null && cluster.getClusterManagerIp() != null) { Long stackId = stack.getId(); clusterService.updateClusterMetadata(stackId); String blueprintName = cluster.getBlueprint().getStackName(); ClusterStatusResult clusterStatusResult = clusterApiConnectors.getConnector(stack).clusterStatusService().getStatus(StringUtils.isNotBlank(blueprintName)); LOGGER.debug("Cluster status: [{}] Status reason: [{}]", clusterStatusResult.getClusterStatus(), clusterStatusResult.getStatusReason()); updateClusterStatus(stackId, stack.getStatus(), cluster, clusterStatusResult); } } }
ClusterStatusUpdater { public void updateClusterStatus(Stack stack, Cluster cluster) { if (isStackOrClusterStatusInvalid(stack, cluster)) { if ((stack.isStackInStopPhase() || stack.isDeleteCompleted()) && cluster != null) { updateClusterStatus(stack.getId(), cluster, stack.getStatus()); cluster.setStatus(stack.getStatus()); } List<String> eventMessageArgs = Arrays.asList(stack.getStatus().name(), cluster == null ? "" : cluster.getStatus().name()); cloudbreakEventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_AMBARI_CLUSTER_COULD_NOT_SYNC, eventMessageArgs); } else if (cluster != null && cluster.getClusterManagerIp() != null) { Long stackId = stack.getId(); clusterService.updateClusterMetadata(stackId); String blueprintName = cluster.getBlueprint().getStackName(); ClusterStatusResult clusterStatusResult = clusterApiConnectors.getConnector(stack).clusterStatusService().getStatus(StringUtils.isNotBlank(blueprintName)); LOGGER.debug("Cluster status: [{}] Status reason: [{}]", clusterStatusResult.getClusterStatus(), clusterStatusResult.getStatusReason()); updateClusterStatus(stackId, stack.getStatus(), cluster, clusterStatusResult); } }  }
ClusterStatusUpdater { public void updateClusterStatus(Stack stack, Cluster cluster) { if (isStackOrClusterStatusInvalid(stack, cluster)) { if ((stack.isStackInStopPhase() || stack.isDeleteCompleted()) && cluster != null) { updateClusterStatus(stack.getId(), cluster, stack.getStatus()); cluster.setStatus(stack.getStatus()); } List<String> eventMessageArgs = Arrays.asList(stack.getStatus().name(), cluster == null ? "" : cluster.getStatus().name()); cloudbreakEventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_AMBARI_CLUSTER_COULD_NOT_SYNC, eventMessageArgs); } else if (cluster != null && cluster.getClusterManagerIp() != null) { Long stackId = stack.getId(); clusterService.updateClusterMetadata(stackId); String blueprintName = cluster.getBlueprint().getStackName(); ClusterStatusResult clusterStatusResult = clusterApiConnectors.getConnector(stack).clusterStatusService().getStatus(StringUtils.isNotBlank(blueprintName)); LOGGER.debug("Cluster status: [{}] Status reason: [{}]", clusterStatusResult.getClusterStatus(), clusterStatusResult.getStatusReason()); updateClusterStatus(stackId, stack.getStatus(), cluster, clusterStatusResult); } }  void updateClusterStatus(Stack stack, Cluster cluster); }
ClusterStatusUpdater { public void updateClusterStatus(Stack stack, Cluster cluster) { if (isStackOrClusterStatusInvalid(stack, cluster)) { if ((stack.isStackInStopPhase() || stack.isDeleteCompleted()) && cluster != null) { updateClusterStatus(stack.getId(), cluster, stack.getStatus()); cluster.setStatus(stack.getStatus()); } List<String> eventMessageArgs = Arrays.asList(stack.getStatus().name(), cluster == null ? "" : cluster.getStatus().name()); cloudbreakEventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_AMBARI_CLUSTER_COULD_NOT_SYNC, eventMessageArgs); } else if (cluster != null && cluster.getClusterManagerIp() != null) { Long stackId = stack.getId(); clusterService.updateClusterMetadata(stackId); String blueprintName = cluster.getBlueprint().getStackName(); ClusterStatusResult clusterStatusResult = clusterApiConnectors.getConnector(stack).clusterStatusService().getStatus(StringUtils.isNotBlank(blueprintName)); LOGGER.debug("Cluster status: [{}] Status reason: [{}]", clusterStatusResult.getClusterStatus(), clusterStatusResult.getStatusReason()); updateClusterStatus(stackId, stack.getStatus(), cluster, clusterStatusResult); } }  void updateClusterStatus(Stack stack, Cluster cluster);  }