/// <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); }
/// <exception cref="System.IO.IOException"/> private static INodeFile[] VerifySrcFiles(FSDirectory fsd, string[] srcs, INodesInPath targetIIP, FSPermissionChecker pc) { // to make sure no two files are the same ICollection <INodeFile> si = new LinkedHashSet <INodeFile>(); INodeFile targetINode = targetIIP.GetLastINode().AsFile(); INodeDirectory targetParent = targetINode.GetParent(); // now check the srcs foreach (string src in srcs) { INodesInPath iip = fsd.GetINodesInPath4Write(src); // permission check for srcs if (pc != null) { fsd.CheckPathAccess(pc, iip, FsAction.Read); // read the file fsd.CheckParentAccess(pc, iip, FsAction.Write); } // for delete INode srcINode = iip.GetLastINode(); INodeFile srcINodeFile = INodeFile.ValueOf(srcINode, src); // make sure the src file and the target file are in the same dir if (srcINodeFile.GetParent() != targetParent) { throw new HadoopIllegalArgumentException("Source file " + src + " is not in the same directory with the target " + targetIIP.GetPath()); } // make sure all the source files are not in snapshot if (srcINode.IsInLatestSnapshot(iip.GetLatestSnapshotId())) { throw new SnapshotException("Concat: the source file " + src + " is in snapshot"); } // check if the file has other references. if (srcINode.IsReference() && ((INodeReference.WithCount)srcINode.AsReference().GetReferredINode ()).GetReferenceCount() > 1) { throw new SnapshotException("Concat: the source file " + src + " is referred by some other reference in some snapshot." ); } // source file cannot be the same with the target file if (srcINode == targetINode) { throw new HadoopIllegalArgumentException("concat: the src file " + src + " is the same with the target file " + targetIIP.GetPath()); } // source file cannot be under construction or empty if (srcINodeFile.IsUnderConstruction() || srcINodeFile.NumBlocks() == 0) { throw new HadoopIllegalArgumentException("concat: source file " + src + " is invalid or empty or underConstruction" ); } // source file's preferred block size cannot be greater than the target // file if (srcINodeFile.GetPreferredBlockSize() > targetINode.GetPreferredBlockSize()) { throw new HadoopIllegalArgumentException("concat: source file " + src + " has preferred block size " + srcINodeFile.GetPreferredBlockSize() + " which is greater than the target file's preferred block size " + targetINode.GetPreferredBlockSize()); } si.AddItem(srcINodeFile); } // make sure no two files are the same if (si.Count < srcs.Length) { // it means at least two files are the same throw new HadoopIllegalArgumentException("concat: at least two of the source files are the same" ); } return(Sharpen.Collections.ToArray(si, new INodeFile[si.Count])); }