public Runnable getRunnable()

in java/metric-scaler/src/main/java/com/example/bigtable/scaler/MetricScaler.java [163:189]


  public Runnable getRunnable() {
    return new Runnable() {
      @Override
      public void run() {
        try {
          // [START bigtable_scale]
          double latestValue = getLatestValue().getValue().getDoubleValue();
          if (latestValue < CPU_PERCENT_TO_DOWNSCALE) {
            int clusterSize = clusterUtility.getClusterNodeCount(clusterId, zoneId);
            if (clusterSize > MIN_NODE_COUNT) {
              clusterUtility.setClusterSize(clusterId, zoneId,
                Math.max(clusterSize - SIZE_CHANGE_STEP, MIN_NODE_COUNT));
            }
          } else if (latestValue > CPU_PERCENT_TO_UPSCALE) {
            int clusterSize = clusterUtility.getClusterNodeCount(clusterId, zoneId);
            if (clusterSize <= MAX_NODE_COUNT) {
              clusterUtility.setClusterSize(clusterId, zoneId,
                Math.min(clusterSize + SIZE_CHANGE_STEP, MAX_NODE_COUNT));
            }
          }
          // [END bigtable_scale]
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    };
  }