Esempio n. 1
0
  public static void handleClusterReset(ClusterStatusClusterResetEvent event) {
    TopologyManager.acquireWriteLock();

    try {
      Topology topology = TopologyManager.getTopology();
      Service service = topology.getService(event.getServiceName());
      if (service == null) {
        log.error(
            "Service "
                + event.getServiceName()
                + " not found in Topology, unable to update the cluster status to Created");
        return;
      }

      Cluster cluster = service.getCluster(event.getClusterId());
      if (cluster == null) {
        log.error(
            "Cluster "
                + event.getClusterId()
                + " not found in Topology, unable to update "
                + "status to Created");
        return;
      }

      ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
      if (context == null) {
        log.warn(
            "Cluster Instance Context is not found for [cluster] "
                + event.getClusterId()
                + " [instance-id] "
                + event.getInstanceId());
        return;
      }
      ClusterStatus status = ClusterStatus.Created;
      if (context.isStateTransitionValid(status)) {
        context.setStatus(status);
        log.info("Cluster Created adding status started for" + cluster.getClusterId());
        TopologyManager.updateTopology(topology);
        // publishing data
        TopologyEventPublisher.sendClusterResetEvent(
            event.getAppId(), event.getServiceName(), event.getClusterId(), event.getInstanceId());
      } else {
        log.warn(
            String.format(
                "Cluster state transition is not valid: [cluster-id] %s "
                    + " [instance-id] %s [current-status] %s [status-requested] %s",
                event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
      }

    } finally {
      TopologyManager.releaseWriteLock();
    }
  }