@Override public void run() { try { // [START scale_bigtable] 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 scale_bigtable] } catch (Exception e) { e.printStackTrace(); } } };