Ejemplo n.º 1
0
 /// <summary>
 /// Simulate the
 /// <see cref="DFSConfigKeys.DfsDatanodeDataDirKey"/>
 /// of a
 /// populated DFS filesystem.
 /// This method populates for each parent directory, <code>parent/dirName</code>
 /// with the content of datanode storage directory that comes from a singleton
 /// datanode master (that contains version and block files). If the destination
 /// directory does not exist, it will be created.  If the directory already
 /// exists, it will first be deleted.
 /// </summary>
 /// <param name="parents">
 /// parent directory where
 /// <paramref name="dirName"/>
 /// is created
 /// </param>
 /// <param name="dirName">directory under which storage directory is created</param>
 /// <returns>the array of created directories</returns>
 /// <exception cref="System.Exception"/>
 public static FilePath[] CreateDataNodeStorageDirs(string[] parents, string dirName
                                                    )
 {
     FilePath[] retVal = new FilePath[parents.Length];
     for (int i = 0; i < parents.Length; i++)
     {
         FilePath newDir = new FilePath(parents[i], dirName);
         CreateEmptyDirs(new string[] { newDir.ToString() });
         LocalFileSystem localFS = FileSystem.GetLocal(new HdfsConfiguration());
         localFS.CopyToLocalFile(new Path(datanodeStorage.ToString(), "current"), new Path
                                     (newDir.ToString()), false);
         retVal[i] = newDir;
     }
     return(retVal);
 }
Ejemplo n.º 2
0
        /// <summary>Test the capability of setting the working directory.</summary>
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestWorkingDirectory()
        {
            Path origDir = fileSys.GetWorkingDirectory();
            Path subdir  = new Path(TestRootDir, "new");

            try
            {
                // make sure it doesn't already exist
                Assert.True(!fileSys.Exists(subdir));
                // make it and check for it
                Assert.True(fileSys.Mkdirs(subdir));
                Assert.True(fileSys.IsDirectory(subdir));
                fileSys.SetWorkingDirectory(subdir);
                // create a directory and check for it
                Path dir1 = new Path("dir1");
                Assert.True(fileSys.Mkdirs(dir1));
                Assert.True(fileSys.IsDirectory(dir1));
                // delete the directory and make sure it went away
                fileSys.Delete(dir1, true);
                Assert.True(!fileSys.Exists(dir1));
                // create files and manipulate them.
                Path   file1    = new Path("file1");
                Path   file2    = new Path("sub/file2");
                string contents = FileSystemTestHelper.WriteFile(fileSys, file1, 1);
                fileSys.CopyFromLocalFile(file1, file2);
                Assert.True(fileSys.Exists(file1));
                Assert.True(fileSys.IsFile(file1));
                CleanupFile(fileSys, file2);
                fileSys.CopyToLocalFile(file1, file2);
                CleanupFile(fileSys, file2);
                // try a rename
                fileSys.Rename(file1, file2);
                Assert.True(!fileSys.Exists(file1));
                Assert.True(fileSys.Exists(file2));
                fileSys.Rename(file2, file1);
                // try reading a file
                InputStream stm       = fileSys.Open(file1);
                byte[]      buffer    = new byte[3];
                int         bytesRead = stm.Read(buffer, 0, 3);
                Assert.Equal(contents, Runtime.GetStringForBytes(buffer
                                                                 , 0, bytesRead));
                stm.Close();
            }
            finally
            {
                fileSys.SetWorkingDirectory(origDir);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Simulate the
        /// <see cref="DFSConfigKeys.DfsDatanodeDataDirKey"/>
        /// of a
        /// populated DFS filesystem.
        /// This method populates for each parent directory, <code>parent/dirName</code>
        /// with the content of block pool storage directory that comes from a singleton
        /// datanode master (that contains version and block files). If the destination
        /// directory does not exist, it will be created.  If the directory already
        /// exists, it will first be deleted.
        /// </summary>
        /// <param name="parents">
        /// parent directory where
        /// <paramref name="dirName"/>
        /// is created
        /// </param>
        /// <param name="dirName">directory under which storage directory is created</param>
        /// <param name="bpid">block pool id for which the storage directory is created.</param>
        /// <returns>the array of created directories</returns>
        /// <exception cref="System.Exception"/>
        public static FilePath[] CreateBlockPoolStorageDirs(string[] parents, string dirName
                                                            , string bpid)
        {
            FilePath[] retVal   = new FilePath[parents.Length];
            Path       bpCurDir = new Path(MiniDFSCluster.GetBPDir(datanodeStorage, bpid, Storage.StorageDirCurrent
                                                                   ));

            for (int i = 0; i < parents.Length; i++)
            {
                FilePath newDir = new FilePath(parents[i] + "/current/" + bpid, dirName);
                CreateEmptyDirs(new string[] { newDir.ToString() });
                LocalFileSystem localFS = FileSystem.GetLocal(new HdfsConfiguration());
                localFS.CopyToLocalFile(bpCurDir, new Path(newDir.ToString()), false);
                retVal[i] = newDir;
            }
            return(retVal);
        }