code: public static boolean validateServiceName(Configuration conf,
        String nameServiceId) {
      Collection<String> nameserviceIds = DFSUtil.getNameServiceIds(conf);
      if (nameserviceIds != null && !nameserviceIds.isEmpty()) {
        if (nameServiceId == null) {
          System.err.println("Need to input a nameservice id");
          return false;
        } else if (!nameserviceIds.contains(nameServiceId)) {
          System.err.println("An invalid nameservice id: " + nameServiceId);
          return false;
        }
      } else if (nameServiceId != null) {
        System.err.println("An invalid nameservice id: " + nameServiceId);
        return false;
      }
      return true;
    }
docs: Valide if the input service name is valid
  @param conf configuration
  @param nameServiceId name service id
  @return true if valid; false otherwise