src/main/java/org/apache/hadoop/hdfs/server/namenode/TransferFsImageWrapper.java
public void downloadMostRecentImage() throws IOException {
    FileSystem fileSystem = nameNodeLoader.getFileSystem();
    Configuration conf = nameNodeLoader.getConfiguration();
    String namespaceDirPath = conf.get(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY);
    File namespaceDir = new File(namespaceDirPath, "current");
    SecurityUtil.login(
        conf,
        DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY,
        DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY,
        InetAddress.getLocalHost().getCanonicalHostName());
    InetSocketAddress addressOfActive = HAUtil.getAddressOfActive(fileSystem);
    URL infoServer =
        DFSUtil.getInfoServer(addressOfActive, conf, DFSUtil.getHttpClientScheme(conf)).toURL();
    SecurityUtil.doAsLoginUser(
        () -> {
          NamenodeProtocol nnProtocolProxy =
              NameNodeProxies.createNonHAProxy(
                      conf,
                      addressOfActive,
                      NamenodeProtocol.class,
                      UserGroupInformation.getLoginUser(),
                      true)
                  .getProxy();
          NamespaceInfo namespaceInfo = nnProtocolProxy.versionRequest();
          String fileId = ImageServlet.getParamStringForMostRecentImage();
          NNStorage storage =
              new NNStorage(
                  conf,
                  FSNamesystem.getNamespaceDirs(conf),
                  FSNamesystem.getNamespaceEditsDirs(conf));
          storage.format(namespaceInfo);
          MD5Hash md5 =
              TransferFsImage.getFileClient(
                  infoServer, fileId, Lists.newArrayList(namespaceDir), storage, true);
          FSImageTransactionalStorageInspector inspector =
              new FSImageTransactionalStorageInspector(EnumSet.of(NNStorage.NameNodeFile.IMAGE));
          storage.inspectStorageDirs(inspector);
          File imageFile = inspector.getLatestImages().get(0).getFile();
          MD5FileUtils.saveMD5File(imageFile, md5);
          return null;
        });
  }
/**
   * This is meant to download the latest FSImage without relying on FSNamesystem or other running
   * HDFS classes within NameNodeLoader.
   *
   * @throws IOException if FileSystem can not be initialized
   */
This is meant to download the latest FSImage without relying on FSNamesystem or other running
HDFS classes within NameNodeLoader.

@throws IOException if FileSystem can not be initialized
This is meant to download the latest FSImage without relying on FSNamesystem or other running HDFS classes within NameNodeLoader . @throws IOException if FileSystem can not be initialized
public void downloadMostRecentImage() throws IOException {
    FileSystem fileSystem = nameNodeLoader.getFileSystem();
    Configuration conf = nameNodeLoader.getConfiguration();
    String namespaceDirPath = conf.get(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY);
    File namespaceDir = new File(namespaceDirPath, "current");
    SecurityUtil.login(
        conf,
        DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY,
        DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY,
        InetAddress.getLocalHost().getCanonicalHostName());
    InetSocketAddress addressOfActive = HAUtil.getAddressOfActive(fileSystem);
    URL infoServer =
        DFSUtil.getInfoServer(addressOfActive, conf, DFSUtil.getHttpClientScheme(conf)).toURL();
    SecurityUtil.doAsLoginUser(
        () -> {
          NamenodeProtocol nnProtocolProxy =
              NameNodeProxies.createNonHAProxy(
                      conf,
                      addressOfActive,
                      NamenodeProtocol.class,
                      UserGroupInformation.getLoginUser(),
                      true)
                  .getProxy();
          NamespaceInfo namespaceInfo = nnProtocolProxy.versionRequest();
          String fileId = ImageServlet.getParamStringForMostRecentImage();
          NNStorage storage =
              new NNStorage(
                  conf,
                  FSNamesystem.getNamespaceDirs(conf),
                  FSNamesystem.getNamespaceEditsDirs(conf));
          storage.format(namespaceInfo);
          MD5Hash md5 =
              TransferFsImage.getFileClient(
                  infoServer, fileId, Lists.newArrayList(namespaceDir), storage, true);
          FSImageTransactionalStorageInspector inspector =
              new FSImageTransactionalStorageInspector(EnumSet.of(NNStorage.NameNodeFile.IMAGE));
          storage.inspectStorageDirs(inspector);
          File imageFile = inspector.getLatestImages().get(0).getFile();
          MD5FileUtils.saveMD5File(imageFile, md5);
          return null;
        });
  }
public void downloadMostRecentImage ( ) throws IOException { FileSystem fileSystem = nameNodeLoader . getFileSystem ( ) ; Configuration conf = nameNodeLoader . getConfiguration ( ) ; String namespaceDirPath = conf . get ( DFSConfigKeys . DFS_NAMENODE_NAME_DIR_KEY ) ; File namespaceDir = new File ( namespaceDirPath , "current" ) ; SecurityUtil . login ( conf , DFSConfigKeys . DFS_NAMENODE_KEYTAB_FILE_KEY , DFSConfigKeys . DFS_NAMENODE_USER_NAME_KEY , InetAddress . getLocalHost ( ) . getCanonicalHostName ( ) ) ; InetSocketAddress addressOfActive = HAUtil . getAddressOfActive ( fileSystem ) ; URL infoServer = DFSUtil . getInfoServer ( addressOfActive , conf , DFSUtil . getHttpClientScheme ( conf ) ) . toURL ( ) ; SecurityUtil . doAsLoginUser ( ( ) -> { NamenodeProtocol nnProtocolProxy = NameNodeProxies . createNonHAProxy ( conf , addressOfActive , NamenodeProtocol . class , UserGroupInformation . getLoginUser ( ) , true ) . getProxy ( ) ; NamespaceInfo namespaceInfo = nnProtocolProxy . versionRequest ( ) ; String fileId = ImageServlet . getParamStringForMostRecentImage ( ) ; NNStorage storage = new NNStorage ( conf , FSNamesystem . getNamespaceDirs ( conf ) , FSNamesystem . getNamespaceEditsDirs ( conf ) ) ; storage . format ( namespaceInfo ) ; MD5Hash md5 = TransferFsImage . getFileClient ( infoServer , fileId , Lists . newArrayList ( namespaceDir ) , storage , true ) ; FSImageTransactionalStorageInspector inspector = new FSImageTransactionalStorageInspector ( EnumSet . of ( NNStorage . NameNodeFile . IMAGE ) ) ; storage . inspectStorageDirs ( inspector ) ; File imageFile = inspector . getLatestImages ( ) . get ( 0 ) . getFile ( ) ; MD5FileUtils . saveMD5File ( imageFile , md5 ) ; return null ; } ) ; }
This is meant to download the latest FSImage without relying on FSNamesystem or other running
 HDFS classes within NameNodeLoader.
This is meant to download the latest FSImage without relying on FSNamesystem or other running HDFS classes within NameNodeLoader .