@Override
  public void perform() throws Exception {
    getLogger().info("Performing action: Restart active namenode");

    final String hadoopHAZkNode;
    String activeNamenode = null;
    int activeNamenodePort = -1;
    try (final DistributedFileSystem dfs = HdfsActionUtils.createDfs(getConf())) {
      final Configuration conf = dfs.getConf();
      hadoopHAZkNode = conf.get(ZK_PARENT_ZNODE_KEY, ZK_PARENT_ZNODE_DEFAULT);
      final String nameServiceID = DFSUtil.getNamenodeNameServiceId(conf);

      if (!HAUtil.isHAEnabled(conf, nameServiceID)) {
        getLogger().info("HA for HDFS is not enabled; skipping");
        return;
      }
      try (final ZKWatcher zkw = new ZKWatcher(conf, "get-active-namenode", null)) {
        final RecoverableZooKeeper rzk = zkw.getRecoverableZooKeeper();
        // If hadoopHAZkNode == '/', pass '' instead because then joinZNode will return '//' as a
        // prefix
        // which zk doesn't like as a prefix on the path.
        final String hadoopHAZkNodePath = ZNodePaths.joinZNode(
          (hadoopHAZkNode != null && hadoopHAZkNode.equals("/")) ? "" : hadoopHAZkNode,
          nameServiceID);
        final List<String> subChildren =
          Optional.ofNullable(ZKUtil.listChildrenNoWatch(zkw, hadoopHAZkNodePath))
            .orElse(Collections.emptyList());
        for (final String eachEntry : subChildren) {
          if (!eachEntry.contains(ACTIVE_NN_LOCK_NAME)) {
            continue;
          }
          byte[] data =
            rzk.getData(ZNodePaths.joinZNode(hadoopHAZkNodePath, ACTIVE_NN_LOCK_NAME), false, null);
          ActiveNodeInfo proto = ActiveNodeInfo.parseFrom(data);
          activeNamenode = proto.getHostname();
          activeNamenodePort = proto.getPort();
        }
      }
    }

    if (activeNamenode == null) {
      getLogger().info("No active Name node found in zookeeper under '{}'", hadoopHAZkNode);
      return;
    }

    getLogger().info("Found Active NameNode host: {}", activeNamenode);
    final ServerName activeNNHost = ServerName.valueOf(activeNamenode, activeNamenodePort, -1L);
    getLogger().info("Restarting Active NameNode: {}", activeNamenode);
    restartNameNode(activeNNHost, this.sleepTime);
  }
Action that tries to restart the active namenode.
hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/RestartActiveNameNodeAction.java