public virtual void TestPolicyPropagation()
        {
            StartUpCluster(false, -1);
            string MethodName = GenericTestUtils.GetMethodName();
            Path   path       = new Path("/" + MethodName + ".dat");

            MakeTestFile(path, 0, true);
            // Stat the file and check that the lazyPersist flag is returned back.
            HdfsFileStatus status = client.GetFileInfo(path.ToString());

            Assert.AssertThat(status.GetStoragePolicy(), IS.Is(LazyPersistPolicyId));
        }
        public virtual void TestPolicyNotSetByDefault()
        {
            StartUpCluster(false, -1);
            string MethodName = GenericTestUtils.GetMethodName();
            Path   path       = new Path("/" + MethodName + ".dat");

            MakeTestFile(path, 0, false);
            // Stat the file and check that the LAZY_PERSIST policy is not
            // returned back.
            HdfsFileStatus status = client.GetFileInfo(path.ToString());

            Assert.AssertThat(status.GetStoragePolicy(), IsNot.Not(LazyPersistPolicyId));
        }
示例#3
0
        /// <summary>Convert a HdfsFileStatus object to a Json string.</summary>
        public static string ToJsonString(HdfsFileStatus status, bool includeType)
        {
            if (status == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["pathSuffix"] = status.GetLocalName();
            m["type"]       = JsonUtil.PathType.ValueOf(status);
            if (status.IsSymlink())
            {
                m["symlink"] = status.GetSymlink();
            }
            m["length"] = status.GetLen();
            m["owner"]  = status.GetOwner();
            m["group"]  = status.GetGroup();
            FsPermission perm = status.GetPermission();

            m["permission"] = ToString(perm);
            if (perm.GetAclBit())
            {
                m["aclBit"] = true;
            }
            if (perm.GetEncryptedBit())
            {
                m["encBit"] = true;
            }
            m["accessTime"]       = status.GetAccessTime();
            m["modificationTime"] = status.GetModificationTime();
            m["blockSize"]        = status.GetBlockSize();
            m["replication"]      = status.GetReplication();
            m["fileId"]           = status.GetFileId();
            m["childrenNum"]      = status.GetChildrenNum();
            m["storagePolicy"]    = status.GetStoragePolicy();
            ObjectMapper mapper = new ObjectMapper();

            try
            {
                return(includeType ? ToJsonString(typeof(FileStatus), m) : mapper.WriteValueAsString
                           (m));
            }
            catch (IOException)
            {
            }
            return(null);
        }
        public virtual void TestPolicyPersistenceInFsImage()
        {
            StartUpCluster(false, -1);
            string MethodName = GenericTestUtils.GetMethodName();
            Path   path       = new Path("/" + MethodName + ".dat");

            MakeTestFile(path, 0, true);
            // checkpoint
            fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
            fs.SaveNamespace();
            fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
            cluster.RestartNameNode(true);
            // Stat the file and check that the lazyPersist flag is returned back.
            HdfsFileStatus status = client.GetFileInfo(path.ToString());

            Assert.AssertThat(status.GetStoragePolicy(), IS.Is(LazyPersistPolicyId));
        }
示例#5
0
            /// <exception cref="System.IO.IOException"/>
            public virtual int Run(Configuration conf, IList <string> args)
            {
                string path = StringUtils.PopOptionWithArgument("-path", args);

                if (path == null)
                {
                    System.Console.Error.WriteLine("Please specify the path with -path.\nUsage:" + GetLongUsage
                                                       ());
                    return(1);
                }
                DistributedFileSystem dfs = AdminHelper.GetDFS(conf);

                try
                {
                    HdfsFileStatus status = dfs.GetClient().GetFileInfo(path);
                    if (status == null)
                    {
                        System.Console.Error.WriteLine("File/Directory does not exist: " + path);
                        return(2);
                    }
                    byte storagePolicyId = status.GetStoragePolicy();
                    if (storagePolicyId == BlockStoragePolicySuite.IdUnspecified)
                    {
                        System.Console.Out.WriteLine("The storage policy of " + path + " is unspecified");
                        return(0);
                    }
                    BlockStoragePolicy[] policies = dfs.GetStoragePolicies();
                    foreach (BlockStoragePolicy p in policies)
                    {
                        if (p.GetId() == storagePolicyId)
                        {
                            System.Console.Out.WriteLine("The storage policy of " + path + ":\n" + p);
                            return(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine(AdminHelper.PrettifyException(e));
                    return(2);
                }
                System.Console.Error.WriteLine("Cannot identify the storage policy for " + path);
                return(2);
            }