示例#1
0
        /// <exception cref="System.IO.IOException"/>
        private static INodeDirectory CreateINodeDirectory(INodeDirectory parent, string
                                                           name, string owner, string group, short perm)
        {
            PermissionStatus permStatus = PermissionStatus.CreateImmutable(owner, group, FsPermission
                                                                           .CreateImmutable(perm));
            INodeDirectory inodeDirectory = new INodeDirectory(INodeId.GrandfatherInodeId, Sharpen.Runtime.GetBytesForString
                                                                   (name, "UTF-8"), permStatus, 0L);

            parent.AddChild(inodeDirectory);
            return(inodeDirectory);
        }
示例#2
0
        /// <exception cref="System.IO.IOException"/>
        private static INodeFile CreateINodeFile(INodeDirectory parent, string name, string
                                                 owner, string group, short perm)
        {
            PermissionStatus permStatus = PermissionStatus.CreateImmutable(owner, group, FsPermission
                                                                           .CreateImmutable(perm));
            INodeFile inodeFile = new INodeFile(INodeId.GrandfatherInodeId, Sharpen.Runtime.GetBytesForString
                                                    (name, "UTF-8"), permStatus, 0L, 0L, null, Replication, PreferredBlockSize, unchecked (
                                                    (byte)0));

            parent.AddChild(inodeFile);
            return(inodeFile);
        }
示例#3
0
 private void AddToParent(INodeDirectory parent, INode child)
 {
     if (parent == dir.rootDir && FSDirectory.IsReservedName(child))
     {
         throw new HadoopIllegalArgumentException("File name \"" + child.GetLocalName() +
                                                  "\" is reserved. Please " + " change the name of the existing file or directory to another "
                                                  + "name before upgrading to this release.");
     }
     // NOTE: This does not update space counts for parents
     if (!parent.AddChild(child))
     {
         return;
     }
     dir.CacheName(child);
     if (child.IsFile())
     {
         UpdateBlocksMap(child.AsFile(), fsn.GetBlockManager());
     }
 }
示例#4
0
        /// <exception cref="System.IO.IOException"/>
        private FSNamesystem MakeNameSystemSpy(Block block, INodeFile file)
        {
            Configuration conf  = new Configuration();
            FSImage       image = new FSImage(conf);

            DatanodeStorageInfo[] targets    = new DatanodeStorageInfo[] {  };
            FSNamesystem          namesystem = new FSNamesystem(conf, image);

            namesystem.SetImageLoaded(true);
            // set file's parent as root and put the file to inodeMap, so
            // FSNamesystem's isFileDeleted() method will return false on this file
            if (file.GetParent() == null)
            {
                INodeDirectory mparent = Org.Mockito.Mockito.Mock <INodeDirectory>();
                INodeDirectory parent  = new INodeDirectory(mparent.GetId(), new byte[0], mparent.
                                                            GetPermissionStatus(), mparent.GetAccessTime());
                parent.SetLocalName(new byte[0]);
                parent.AddChild(file);
                file.SetParent(parent);
            }
            namesystem.dir.GetINodeMap().Put(file);
            FSNamesystem namesystemSpy = Org.Mockito.Mockito.Spy(namesystem);
            BlockInfoContiguousUnderConstruction blockInfo = new BlockInfoContiguousUnderConstruction
                                                                 (block, (short)1, HdfsServerConstants.BlockUCState.UnderConstruction, targets);

            blockInfo.SetBlockCollection(file);
            blockInfo.SetGenerationStamp(genStamp);
            blockInfo.InitializeBlockRecovery(genStamp);
            Org.Mockito.Mockito.DoReturn(true).When(file).RemoveLastBlock(Matchers.Any <Block>
                                                                              ());
            Org.Mockito.Mockito.DoReturn(true).When(file).IsUnderConstruction();
            Org.Mockito.Mockito.DoReturn(new BlockInfoContiguous[1]).When(file).GetBlocks();
            Org.Mockito.Mockito.DoReturn(blockInfo).When(namesystemSpy).GetStoredBlock(Matchers.Any
                                                                                       <Block>());
            Org.Mockito.Mockito.DoReturn(blockInfo).When(file).GetLastBlock();
            Org.Mockito.Mockito.DoReturn(string.Empty).When(namesystemSpy).CloseFileCommitBlocks
                (Matchers.Any <INodeFile>(), Matchers.Any <BlockInfoContiguous>());
            Org.Mockito.Mockito.DoReturn(Org.Mockito.Mockito.Mock <FSEditLog>()).When(namesystemSpy
                                                                                      ).GetEditLog();
            return(namesystemSpy);
        }