Exemple #1
0
 /// <exception cref="URISyntaxException"/>
 public InternalDirOfViewFs(InodeTree.INodeDir <FileSystem> dir, long cTime, UserGroupInformation
                            ugi, URI uri)
 {
     /*
      * An instance of this class represents an internal dir of the viewFs
      * that is internal dir of the mount table.
      * It is a read only mount tables and create, mkdir or delete operations
      * are not allowed.
      * If called on create or mkdir then this target is the parent of the
      * directory in which one is trying to create or mkdir; hence
      * in this case the path name passed in is the last component.
      * Otherwise this target is the end point of the path and hence
      * the path name passed in is null.
      */
     // of the the mount table
     // the user/group of user who created mtable
     myUri = uri;
     try
     {
         Initialize(myUri, new Configuration());
     }
     catch (IOException)
     {
         throw new RuntimeException("Cannot occur");
     }
     theInternalDir = dir;
     creationTime   = cTime;
     this.ugi       = ugi;
 }
Exemple #2
0
 /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
 internal virtual InodeTree.INodeDir <T> AddDir(string pathComponent, UserGroupInformation
                                                aUgi)
 {
     if (children.Contains(pathComponent))
     {
         throw new FileAlreadyExistsException();
     }
     InodeTree.INodeDir <T> newDir = new InodeTree.INodeDir <T>(fullPath + (isRoot ? string.Empty
                              : "/") + pathComponent, aUgi);
     children[pathComponent] = newDir;
     return(newDir);
 }
 /// <exception cref="URISyntaxException"/>
 protected internal override _T611036023 GetTargetFileSystem(InodeTree.INodeDir <_T611036023
                                                                                 > dir)
 {
     return(null);
 }
Exemple #4
0
        /// <summary>Resolve the pathname p relative to root InodeDir</summary>
        /// <param name="p">- inout path</param>
        /// <param name="resolveLastComponent"></param>
        /// <returns>ResolveResult which allows further resolution of the remaining path</returns>
        /// <exception cref="System.IO.FileNotFoundException"/>
        internal virtual InodeTree.ResolveResult <T> Resolve(string p, bool resolveLastComponent
                                                             )
        {
            // TO DO: - more efficient to not split the path, but simply compare
            string[] path = BreakIntoPathComponents(p);
            if (path.Length <= 1)
            {
                // special case for when path is "/"
                InodeTree.ResolveResult <T> res = new InodeTree.ResolveResult <T>(InodeTree.ResultKind
                                                                                  .isInternalDir, root.InodeDirFs, root.fullPath, SlashPath);
                return(res);
            }
            InodeTree.INodeDir <T> curInode = root;
            int i;

            // ignore first slash
            for (i = 1; i < path.Length - (resolveLastComponent ? 0 : 1); i++)
            {
                InodeTree.INode <T> nextInode = curInode.ResolveInternal(path[i]);
                if (nextInode == null)
                {
                    StringBuilder failedAt = new StringBuilder(path[0]);
                    for (int j = 1; j <= i; ++j)
                    {
                        failedAt.Append('/').Append(path[j]);
                    }
                    throw (new FileNotFoundException(failedAt.ToString()));
                }
                if (nextInode is InodeTree.INodeLink)
                {
                    InodeTree.INodeLink <T> link = (InodeTree.INodeLink <T>)nextInode;
                    Path remainingPath;
                    if (i >= path.Length - 1)
                    {
                        remainingPath = SlashPath;
                    }
                    else
                    {
                        StringBuilder remainingPathStr = new StringBuilder("/" + path[i + 1]);
                        for (int j = i + 2; j < path.Length; ++j)
                        {
                            remainingPathStr.Append('/').Append(path[j]);
                        }
                        remainingPath = new Path(remainingPathStr.ToString());
                    }
                    InodeTree.ResolveResult <T> res = new InodeTree.ResolveResult <T>(InodeTree.ResultKind
                                                                                      .isExternalDir, link.targetFileSystem, nextInode.fullPath, remainingPath);
                    return(res);
                }
                else
                {
                    if (nextInode is InodeTree.INodeDir)
                    {
                        curInode = (InodeTree.INodeDir <T>)nextInode;
                    }
                }
            }
            // We have resolved to an internal dir in mount table.
            Path remainingPath_1;

            if (resolveLastComponent)
            {
                remainingPath_1 = SlashPath;
            }
            else
            {
                // note we have taken care of when path is "/" above
                // for internal dirs rem-path does not start with / since the lookup
                // that follows will do a children.get(remaningPath) and will have to
                // strip-out the initial /
                StringBuilder remainingPathStr = new StringBuilder("/" + path[i]);
                for (int j = i + 1; j < path.Length; ++j)
                {
                    remainingPathStr.Append('/').Append(path[j]);
                }
                remainingPath_1 = new Path(remainingPathStr.ToString());
            }
            InodeTree.ResolveResult <T> res_1 = new InodeTree.ResolveResult <T>(InodeTree.ResultKind
                                                                                .isInternalDir, curInode.InodeDirFs, curInode.fullPath, remainingPath_1);
            return(res_1);
        }
Exemple #5
0
        /// <summary>Create Inode Tree from the specified mount-table specified in Config</summary>
        /// <param name="config">
        /// - the mount table keys are prefixed with
        /// FsConstants.CONFIG_VIEWFS_PREFIX
        /// </param>
        /// <param name="viewName">- the name of the mount table - if null use defaultMT name
        ///     </param>
        /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/>
        /// <exception cref="URISyntaxException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
        /// <exception cref="System.IO.IOException"/>
        protected internal InodeTree(Configuration config, string viewName)
        {
            string vName = viewName;

            if (vName == null)
            {
                vName = Constants.ConfigViewfsDefaultMountTable;
            }
            homedirPrefix   = ConfigUtil.GetHomeDirValue(config, vName);
            root            = new InodeTree.INodeDir <T>("/", UserGroupInformation.GetCurrentUser());
            root.InodeDirFs = GetTargetFileSystem(root);
            root.isRoot     = true;
            string mtPrefix           = Constants.ConfigViewfsPrefix + "." + vName + ".";
            string linkPrefix         = Constants.ConfigViewfsLink + ".";
            string linkMergePrefix    = Constants.ConfigViewfsLinkMerge + ".";
            bool   gotMountTableEntry = false;
            UserGroupInformation ugi  = UserGroupInformation.GetCurrentUser();

            foreach (KeyValuePair <string, string> si in config)
            {
                string key = si.Key;
                if (key.StartsWith(mtPrefix))
                {
                    gotMountTableEntry = true;
                    bool   isMergeLink = false;
                    string src         = Runtime.Substring(key, mtPrefix.Length);
                    if (src.StartsWith(linkPrefix))
                    {
                        src = Runtime.Substring(src, linkPrefix.Length);
                    }
                    else
                    {
                        if (src.StartsWith(linkMergePrefix))
                        {
                            // A merge link
                            isMergeLink = true;
                            src         = Runtime.Substring(src, linkMergePrefix.Length);
                        }
                        else
                        {
                            if (src.StartsWith(Constants.ConfigViewfsHomedir))
                            {
                                // ignore - we set home dir from config
                                continue;
                            }
                            else
                            {
                                throw new IOException("ViewFs: Cannot initialize: Invalid entry in Mount table in config: "
                                                      + src);
                            }
                        }
                    }
                    string target = si.Value;
                    // link or merge link
                    CreateLink(src, target, isMergeLink, ugi);
                }
            }
            if (!gotMountTableEntry)
            {
                throw new IOException("ViewFs: Cannot initialize: Empty Mount table in config for "
                                      + vName == null ? "viewfs:///" : ("viewfs://" + vName + "/"));
            }
        }
Exemple #6
0
 /// <exception cref="URISyntaxException"/>
 protected internal abstract T GetTargetFileSystem(InodeTree.INodeDir <T> dir);
Exemple #7
0
        /// <exception cref="URISyntaxException"/>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/>
        private void CreateLink(string src, string target, bool isLinkMerge, UserGroupInformation
                                aUgi)
        {
            // Validate that src is valid absolute path
            Path srcPath = new Path(src);

            if (!srcPath.IsAbsoluteAndSchemeAuthorityNull())
            {
                throw new IOException("ViewFs:Non absolute mount name in config:" + src);
            }
            string[] srcPaths = BreakIntoPathComponents(src);
            InodeTree.INodeDir <T> curInode = root;
            int i;

            // Ignore first initial slash, process all except last component
            for (i = 1; i < srcPaths.Length - 1; i++)
            {
                string iPath = srcPaths[i];
                InodeTree.INode <T> nextInode = curInode.ResolveInternal(iPath);
                if (nextInode == null)
                {
                    InodeTree.INodeDir <T> newDir = curInode.AddDir(iPath, aUgi);
                    newDir.InodeDirFs = GetTargetFileSystem(newDir);
                    nextInode         = newDir;
                }
                if (nextInode is InodeTree.INodeLink)
                {
                    // Error - expected a dir but got a link
                    throw new FileAlreadyExistsException("Path " + nextInode.fullPath + " already exists as link"
                                                         );
                }
                else
                {
                    System.Diagnostics.Debug.Assert((nextInode is InodeTree.INodeDir));
                    curInode = (InodeTree.INodeDir <T>)nextInode;
                }
            }
            // Now process the last component
            // Add the link in 2 cases: does not exist or a link exists
            string iPath_1 = srcPaths[i];

            // last component
            if (curInode.ResolveInternal(iPath_1) != null)
            {
                //  directory/link already exists
                StringBuilder strB = new StringBuilder(srcPaths[0]);
                for (int j = 1; j <= i; ++j)
                {
                    strB.Append('/').Append(srcPaths[j]);
                }
                throw new FileAlreadyExistsException("Path " + strB + " already exists as dir; cannot create link here"
                                                     );
            }
            InodeTree.INodeLink <T> newLink;
            string fullPath = curInode.fullPath + (curInode == root ? string.Empty : "/") + iPath_1;

            if (isLinkMerge)
            {
                // Target is list of URIs
                string[] targetsList    = StringUtils.GetStrings(target);
                URI[]    targetsListURI = new URI[targetsList.Length];
                int      k = 0;
                foreach (string itarget in targetsList)
                {
                    targetsListURI[k++] = new URI(itarget);
                }
                newLink = new InodeTree.INodeLink <T>(fullPath, aUgi, GetTargetFileSystem(targetsListURI
                                                                                          ), targetsListURI);
            }
            else
            {
                newLink = new InodeTree.INodeLink <T>(fullPath, aUgi, GetTargetFileSystem(new URI(
                                                                                              target)), new URI(target));
            }
            curInode.AddLink(iPath_1, newLink);
            mountPoints.AddItem(new InodeTree.MountPoint <T>(src, newLink));
        }
Exemple #8
0
 /// <exception cref="URISyntaxException"/>
 protected internal override FileSystem GetTargetFileSystem(InodeTree.INodeDir <FileSystem
                                                                                > dir)
 {
     return(new ViewFileSystem.InternalDirOfViewFs(dir, this._enclosing.creationTime,
                                                   this._enclosing.ugi, this._enclosing.myUri));
 }