public void shutdown() throws IOException {
    TraceUtil.trace(() -> {
      if (cpHost != null) {
        cpHost.preShutdown();
      }

      // Tell the servermanager cluster shutdown has been called. This makes it so when Master is
      // last running server, it'll stop itself. Next, we broadcast the cluster shutdown by setting
      // the cluster status as down. RegionServers will notice this change in state and will start
      // shutting themselves down. When last has exited, Master can go down.
      if (this.serverManager != null) {
        this.serverManager.shutdownCluster();
      }
      if (this.clusterStatusTracker != null) {
        try {
          this.clusterStatusTracker.setClusterDown();
        } catch (KeeperException e) {
          LOG.error("ZooKeeper exception trying to set cluster as down in ZK", e);
        }
      }
      // Stop the procedure executor. Will stop any ongoing assign, unassign, server crash etc.,
      // processing so we can go down.
      if (this.procedureExecutor != null) {
        this.procedureExecutor.stop();
      }
      // Shutdown our cluster connection. This will kill any hosted RPCs that might be going on;
      // this is what we want especially if the Master is in startup phase doing call outs to
      // hbase:meta, etc. when cluster is down. Without ths connection close, we'd have to wait on
      // the rpc to timeout.
      if (this.asyncClusterConnection != null) {
        this.asyncClusterConnection.close();
      }
    }, "HMaster.shutdown");
  }
Shutdown the cluster. Master runs a coordinated stop of all RegionServers and then itself.
hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java