Ejemplo n.º 1
0
        /// <returns>
        ///
        /// <see cref="Org.Apache.Hadoop.FS.Path"/>
        /// absolute path for localization which includes local
        /// directory path and the relative hierarchical path (if use local
        /// cache directory manager is enabled)
        /// </returns>
        /// <?/>
        /// <?/>
        /// <?/>
        public virtual Path GetPathForLocalization(LocalResourceRequest req, Path localDirPath
                                                   , DeletionService delService)
        {
            Path rPath = localDirPath;

            if (useLocalCacheDirectoryManager && localDirPath != null)
            {
                if (!directoryManagers.Contains(localDirPath))
                {
                    directoryManagers.PutIfAbsent(localDirPath, new LocalCacheDirectoryManager(conf));
                }
                LocalCacheDirectoryManager dir = directoryManagers[localDirPath];
                rPath = localDirPath;
                string hierarchicalPath = dir.GetRelativePathForLocalization();
                // For most of the scenarios we will get root path only which
                // is an empty string
                if (!hierarchicalPath.IsEmpty())
                {
                    rPath = new Path(localDirPath, hierarchicalPath);
                }
                inProgressLocalResourcesMap[req] = rPath;
            }
            while (true)
            {
                Path uniquePath = new Path(rPath, System.Convert.ToString(uniqueNumberGenerator.IncrementAndGet
                                                                              ()));
                FilePath file = new FilePath(uniquePath.ToUri().GetRawPath());
                if (!file.Exists())
                {
                    rPath = uniquePath;
                    break;
                }
                // If the directory already exists, delete it and move to next one.
                Log.Warn("Directory " + uniquePath + " already exists, " + "try next one.");
                if (delService != null)
                {
                    delService.Delete(GetUser(), uniquePath);
                }
            }
            Path localPath         = new Path(rPath, req.GetPath().GetName());
            LocalizedResource rsrc = localrsrc[req];

            rsrc.SetLocalPath(localPath);
            LocalResource lr = LocalResource.NewInstance(req.GetResource(), req.GetType(), req
                                                         .GetVisibility(), req.GetSize(), req.GetTimestamp());

            try
            {
                stateStore.StartResourceLocalization(user, appId, ((LocalResourcePBImpl)lr).GetProto
                                                         (), localPath);
            }
            catch (IOException e)
            {
                Log.Error("Unable to record localization start for " + rsrc, e);
            }
            return(rPath);
        }