コード例 #1
0
 private string GetCacheEntryFilePath(string checksum, string filename)
 {
     return(SharedCacheUtil.GetCacheEntryPath(this.cacheDepth, this.cacheRoot, checksum
                                              ) + Path.SeparatorChar + filename);
 }
コード例 #2
0
        /// <summary>
        /// Uploads the file under the shared cache, and notifies the shared cache
        /// manager.
        /// </summary>
        /// <remarks>
        /// Uploads the file under the shared cache, and notifies the shared cache
        /// manager. If it is unable to upload the file because it already exists, it
        /// returns false.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual bool Call()
        {
            Path tempPath = null;

            try
            {
                if (!VerifyAccess())
                {
                    Log.Warn("User " + user + " is not authorized to upload file " + localPath.GetName
                                 ());
                    return(false);
                }
                // first determine the actual local path that will be used for upload
                Path actualPath = GetActualPath();
                // compute the checksum
                string checksumVal = ComputeChecksum(actualPath);
                // create the directory (if it doesn't exist)
                Path directoryPath = new Path(SharedCacheUtil.GetCacheEntryPath(nestedLevel, sharedCacheRootDir
                                                                                , checksumVal));
                // let's not check if the directory already exists: in the vast majority
                // of the cases, the directory does not exist; as long as mkdirs does not
                // error out if it exists, we should be fine
                fs.Mkdirs(directoryPath, DirectoryPermission);
                // create the temporary file
                tempPath = new Path(directoryPath, GetTemporaryFileName(actualPath));
                if (!UploadFile(actualPath, tempPath))
                {
                    Log.Warn("Could not copy the file to the shared cache at " + tempPath);
                    return(false);
                }
                // set the permission so that it is readable but not writable
                fs.SetPermission(tempPath, FilePermission);
                // rename it to the final filename
                Path finalPath = new Path(directoryPath, actualPath.GetName());
                if (!fs.Rename(tempPath, finalPath))
                {
                    Log.Warn("The file already exists under " + finalPath + ". Ignoring this attempt."
                             );
                    DeleteTempFile(tempPath);
                    return(false);
                }
                // notify the SCM
                if (!NotifySharedCacheManager(checksumVal, actualPath.GetName()))
                {
                    // the shared cache manager rejected the upload (as it is likely
                    // uploaded under a different name
                    // clean up this file and exit
                    fs.Delete(finalPath, false);
                    return(false);
                }
                // set the replication factor
                short replication = (short)conf.GetInt(YarnConfiguration.SharedCacheNmUploaderReplicationFactor
                                                       , YarnConfiguration.DefaultSharedCacheNmUploaderReplicationFactor);
                fs.SetReplication(finalPath, replication);
                Log.Info("File " + actualPath.GetName() + " was uploaded to the shared cache at "
                         + finalPath);
                return(true);
            }
            catch (IOException e)
            {
                Log.Warn("Exception while uploading the file " + localPath.GetName(), e);
                // in case an exception is thrown, delete the temp file
                DeleteTempFile(tempPath);
                throw;
            }
        }