/// <summary>Create application log directories on all disks.</summary>
        /// <exception cref="System.IO.IOException"/>
        internal virtual void CreateAppLogDirs(string appId, IList <string> logDirs, string
                                               user)
        {
            bool         appLogDirStatus = false;
            FsPermission appLogDirPerms  = new FsPermission(LogdirPerm);

            foreach (string rootLogDir in logDirs)
            {
                // create $log.dir/$appid
                Path appLogDir = new Path(rootLogDir, appId);
                try
                {
                    CreateDir(appLogDir, appLogDirPerms, true, user);
                }
                catch (IOException e)
                {
                    Log.Warn("Unable to create the app-log directory : " + appLogDir, e);
                    continue;
                }
                appLogDirStatus = true;
            }
            if (!appLogDirStatus)
            {
                throw new IOException("Not able to initialize app-log directories " + "in any of the configured local directories for app "
                                      + appId);
            }
        }
        // copy user specified log4j.property file in local
        // to HDFS with putting on distributed cache and adding its parent directory
        // to classpath.
        /// <exception cref="System.IO.IOException"/>
        private void CopyLog4jPropertyFile(Job job, Path submitJobDir, short replication)
        {
            Configuration conf = job.GetConfiguration();
            string        file = ValidateFilePath(conf.Get(MRJobConfig.MapreduceJobLog4jPropertiesFile
                                                           ), conf);

            Log.Debug("default FileSystem: " + jtFs.GetUri());
            FsPermission mapredSysPerms = new FsPermission(JobSubmissionFiles.JobDirPermission
                                                           );

            if (!jtFs.Exists(submitJobDir))
            {
                throw new IOException("Cannot find job submission directory! " + "It should just be created, so something wrong here."
                                      );
            }
            Path fileDir = JobSubmissionFiles.GetJobLog4jFile(submitJobDir);

            // first copy local log4j.properties file to HDFS under submitJobDir
            if (file != null)
            {
                FileSystem.Mkdirs(jtFs, fileDir, mapredSysPerms);
                URI tmpURI = null;
                try
                {
                    tmpURI = new URI(file);
                }
                catch (URISyntaxException e)
                {
                    throw new ArgumentException(e);
                }
                Path tmp     = new Path(tmpURI);
                Path newPath = CopyRemoteFiles(fileDir, tmp, conf, replication);
                DistributedCache.AddFileToClassPath(new Path(newPath.ToUri().GetPath()), conf);
            }
        }
        /// <summary>Initialize the local directories for a particular user.</summary>
        /// <remarks>
        /// Initialize the local directories for a particular user.
        /// <ul>.mkdir
        /// <li>$local.dir/usercache/$user</li>
        /// </ul>
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal virtual void CreateUserLocalDirs(IList <string> localDirs, string user)
        {
            bool         userDirStatus = false;
            FsPermission userperms     = new FsPermission(UserPerm);

            foreach (string localDir in localDirs)
            {
                // create $local.dir/usercache/$user and its immediate parent
                try
                {
                    CreateDir(GetUserCacheDir(new Path(localDir), user), userperms, true, user);
                }
                catch (IOException e)
                {
                    Log.Warn("Unable to create the user directory : " + localDir, e);
                    continue;
                }
                userDirStatus = true;
            }
            if (!userDirStatus)
            {
                throw new IOException("Not able to initialize user directories " + "in any of the configured local directories for user "
                                      + user);
            }
        }
        /// <summary>Initialize the local directories for a particular user.</summary>
        /// <remarks>
        /// Initialize the local directories for a particular user.
        /// <ul>
        /// <li>$local.dir/usercache/$user/appcache/$appid</li>
        /// </ul>
        /// </remarks>
        /// <param name="localDirs"/>
        /// <exception cref="System.IO.IOException"/>
        internal virtual void CreateAppDirs(IList <string> localDirs, string user, string
                                            appId)
        {
            bool         initAppDirStatus = false;
            FsPermission appperms         = new FsPermission(AppdirPerm);

            foreach (string localDir in localDirs)
            {
                Path fullAppDir = GetApplicationDir(new Path(localDir), user, appId);
                // create $local.dir/usercache/$user/appcache/$appId
                try
                {
                    CreateDir(fullAppDir, appperms, true, user);
                    initAppDirStatus = true;
                }
                catch (IOException e)
                {
                    Log.Warn("Unable to create app directory " + fullAppDir.ToString(), e);
                }
            }
            if (!initAppDirStatus)
            {
                throw new IOException("Not able to initialize app directories " + "in any of the configured local directories for app "
                                      + appId.ToString());
            }
        }
        public virtual void TestSetPermission()
        {
            if (Path.Windows)
            {
                System.Console.Out.WriteLine("Cannot run test for Windows");
                return;
            }
            string filename = "foo";
            Path   f        = fileContextTestHelper.GetTestRootPath(fc, filename);

            FileContextTestHelper.CreateFile(fc, f);
            try
            {
                // create files and manipulate them.
                FsPermission all  = new FsPermission((short)0x1ff);
                FsPermission none = new FsPermission((short)0);
                fc.SetPermission(f, none);
                DoFilePermissionCheck(none, fc.GetFileStatus(f).GetPermission());
                fc.SetPermission(f, all);
                DoFilePermissionCheck(all, fc.GetFileStatus(f).GetPermission());
            }
            finally
            {
                CleanupFile(fc, f);
            }
        }
                /// <exception cref="System.IO.IOException"/>
                protected override bool MkOneDirWithMode(Path path, FilePath p2f, FsPermission permission
                                                         )
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug(string.Format("EFS:mkOneDirWithMode: %s %s", path, permission));
                    }
                    bool ret = false;

                    // File.mkdir returns false, does not throw. Must mimic it.
                    try
                    {
                        WindowsSecureContainerExecutor.Native.Elevated.Mkdir(path);
                        SetPermission(path, permission);
                        ret = true;
                    }
                    catch (Exception e)
                    {
                        if (Log.IsDebugEnabled())
                        {
                            Log.Debug(string.Format("EFS:mkOneDirWithMode: %s", StringUtils.StringifyException
                                                        (e)));
                        }
                    }
                    return(ret);
                }
 /// <exception cref="System.Exception"/>
 public virtual void TestFavoredNodesEndToEndForAppend()
 {
     // create 10 files with random preferred nodes
     for (int i = 0; i < NumFiles; i++)
     {
         Random rand = new Random(Runtime.CurrentTimeMillis() + i);
         // pass a new created rand so as to get a uniform distribution each time
         // without too much collisions (look at the do-while loop in getDatanodes)
         IPEndPoint[] datanode = GetDatanodes(rand);
         Path         p        = new Path("/filename" + i);
         // create and close the file.
         dfs.Create(p, FsPermission.GetDefault(), true, 4096, (short)3, 4096L, null, null)
         .Close();
         // re-open for append
         FSDataOutputStream @out = dfs.Append(p, EnumSet.Of(CreateFlag.Append), 4096, null
                                              , datanode);
         @out.Write(SomeBytes);
         @out.Close();
         BlockLocation[] locations = GetBlockLocations(p);
         // verify the files got created in the right nodes
         foreach (BlockLocation loc in locations)
         {
             string[] hosts  = loc.GetNames();
             string[] hosts1 = GetStringForInetSocketAddrs(datanode);
             NUnit.Framework.Assert.IsTrue(CompareNodes(hosts, hosts1));
         }
     }
 }
Example #8
0
        /// <exception cref="System.Exception"/>
        private void _mkdirs(bool exists, FsPermission before, FsPermission after)
        {
            FilePath localDir = MockitoMaker.Make(MockitoMaker.Stub <FilePath>().Returning(exists
                                                                                           ).from.Exists());

            Org.Mockito.Mockito.When(localDir.Mkdir()).ThenReturn(true);
            Path dir = Org.Mockito.Mockito.Mock <Path>();
            // use default stubs
            LocalFileSystem fs = MockitoMaker.Make(MockitoMaker.Stub <LocalFileSystem>().Returning
                                                       (localDir).from.PathToFile(dir));
            FileStatus stat = MockitoMaker.Make(MockitoMaker.Stub <FileStatus>().Returning(after
                                                                                           ).from.GetPermission());

            Org.Mockito.Mockito.When(fs.GetFileStatus(dir)).ThenReturn(stat);
            try
            {
                DiskChecker.MkdirsWithExistsAndPermissionCheck(fs, dir, before);
                if (!exists)
                {
                    Org.Mockito.Mockito.Verify(fs).SetPermission(dir, before);
                }
                else
                {
                    Org.Mockito.Mockito.Verify(fs).GetFileStatus(dir);
                    Org.Mockito.Mockito.Verify(stat).GetPermission();
                }
            }
            catch (DiskChecker.DiskErrorException e)
            {
                if (before != after)
                {
                    Assert.True(e.Message.StartsWith("Incorrect permission"));
                }
            }
        }
Example #9
0
 /// <summary>
 /// Creates the new FsPermission for an inode that is receiving an extended
 /// ACL, based on its access ACL entries.
 /// </summary>
 /// <remarks>
 /// Creates the new FsPermission for an inode that is receiving an extended
 /// ACL, based on its access ACL entries.  For a correctly sorted ACL, the
 /// first entry is the owner and the last 2 entries are the mask and other
 /// entries respectively.  Also preserve sticky bit and toggle ACL bit on.
 /// Note that this method intentionally copies the permissions of the mask
 /// entry into the FsPermission group permissions.  This is consistent with the
 /// POSIX ACLs model, which presents the mask as the permissions of the group
 /// class.
 /// </remarks>
 /// <param name="accessEntries">List<AclEntry> access ACL entries</param>
 /// <param name="existingPerm">FsPermission existing permissions</param>
 /// <returns>FsPermission new permissions</returns>
 private static FsPermission CreateFsPermissionForExtendedAcl(IList <AclEntry> accessEntries
                                                              , FsPermission existingPerm)
 {
     return(new FsPermission(accessEntries[0].GetPermission(), accessEntries[accessEntries
                                                                             .Count - 2].GetPermission(), accessEntries[accessEntries.Count - 1].GetPermission
                                 (), existingPerm.GetStickyBit()));
 }
Example #10
0
        /// <exception cref="System.IO.IOException"/>
        protected internal void MakeTestFile(Path path, long length, bool isLazyPersist)
        {
            EnumSet <CreateFlag> createFlags = EnumSet.Of(CreateFlag.Create);

            if (isLazyPersist)
            {
                createFlags.AddItem(CreateFlag.LazyPersist);
            }
            FSDataOutputStream fos = null;

            try
            {
                fos = fs.Create(path, FsPermission.GetFileDefault(), createFlags, BufferLength, ReplFactor
                                , BlockSize, null);
                // Allocate a block.
                byte[] buffer = new byte[BufferLength];
                for (int bytesWritten = 0; bytesWritten < length;)
                {
                    fos.Write(buffer, 0, buffer.Length);
                    bytesWritten += buffer.Length;
                }
                if (length > 0)
                {
                    fos.Hsync();
                }
            }
            finally
            {
                IOUtils.CloseQuietly(fos);
            }
        }
        /// <exception cref="NoSuchAlgorithmException"/>
        /// <exception cref="CertificateException"/>
        /// <exception cref="System.IO.IOException"/>
        private FsPermission LoadAndReturnPerm(Path pathToLoad, Path pathToDelete)
        {
            FsPermission perm = null;

            try
            {
                perm = LoadFromPath(pathToLoad, password);
                RenameOrFail(pathToLoad, path);
                Log.Debug(string.Format("KeyStore loaded successfully from '%s'!!", pathToLoad));
                if (fs.Exists(pathToDelete))
                {
                    fs.Delete(pathToDelete, true);
                }
            }
            catch (IOException e)
            {
                // Check for password issue : don't want to trash file due
                // to wrong password
                if (IsBadorWrongPassword(e))
                {
                    throw;
                }
            }
            return(perm);
        }
        /// <summary>
        /// The KeyStore might have gone down during a flush, In which case either the
        /// _NEW or _OLD files might exists.
        /// </summary>
        /// <remarks>
        /// The KeyStore might have gone down during a flush, In which case either the
        /// _NEW or _OLD files might exists. This method tries to load the KeyStore
        /// from one of these intermediate files.
        /// </remarks>
        /// <param name="oldPath">the _OLD file created during flush</param>
        /// <param name="newPath">the _NEW file created during flush</param>
        /// <returns>The permissions of the loaded file</returns>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="NoSuchAlgorithmException"/>
        /// <exception cref="CertificateException"/>
        private FsPermission TryLoadIncompleteFlush(Path oldPath, Path newPath)
        {
            FsPermission perm = null;

            // Check if _NEW exists (in case flush had finished writing but not
            // completed the re-naming)
            if (fs.Exists(newPath))
            {
                perm = LoadAndReturnPerm(newPath, oldPath);
            }
            // try loading from _OLD (An earlier Flushing MIGHT not have completed
            // writing completely)
            if ((perm == null) && fs.Exists(oldPath))
            {
                perm = LoadAndReturnPerm(oldPath, newPath);
            }
            // If not loaded yet,
            // required to create an empty keystore. *sigh*
            if (perm == null)
            {
                keyStore.Load(null, password);
                Log.Debug("KeyStore initialized anew successfully !!");
                perm = new FsPermission("700");
            }
            return(perm);
        }
        /// <summary>
        /// Try loading from the user specified path, else load from the backup
        /// path in case Exception is not due to bad/wrong password
        /// </summary>
        /// <param name="path">Actual path to load from</param>
        /// <param name="backupPath">Backup path (_OLD)</param>
        /// <returns>The permissions of the loaded file</returns>
        /// <exception cref="NoSuchAlgorithmException"/>
        /// <exception cref="CertificateException"/>
        /// <exception cref="System.IO.IOException"/>
        private FsPermission TryLoadFromPath(Path path, Path backupPath)
        {
            FsPermission perm = null;

            try
            {
                perm = LoadFromPath(path, password);
                // Remove _OLD if exists
                if (fs.Exists(backupPath))
                {
                    fs.Delete(backupPath, true);
                }
                Log.Debug("KeyStore loaded successfully !!");
            }
            catch (IOException ioe)
            {
                // If file is corrupted for some reason other than
                // wrong password try the _OLD file if exits
                if (!IsBadorWrongPassword(ioe))
                {
                    perm = LoadFromPath(backupPath, password);
                    // Rename CURRENT to CORRUPTED
                    RenameOrFail(path, new Path(path.ToString() + "_CORRUPTED_" + Runtime.CurrentTimeMillis
                                                    ()));
                    RenameOrFail(backupPath, path);
                    Log.Debug(string.Format("KeyStore loaded successfully from '%s' since '%s'" + "was corrupted !!"
                                            , backupPath, path));
                }
                else
                {
                    throw;
                }
            }
            return(perm);
        }
Example #14
0
        /// <exception cref="System.Exception"/>
        private void TestCreate(Path path, bool @override)
        {
            FileSystem   fs         = GetHttpFSFileSystem();
            FsPermission permission = new FsPermission(FsAction.ReadWrite, FsAction.None, FsAction
                                                       .None);
            OutputStream os = fs.Create(new Path(path.ToUri().GetPath()), permission, @override
                                        , 1024, (short)2, 100 * 1024 * 1024, null);

            os.Write(1);
            os.Close();
            fs.Close();
            fs = FileSystem.Get(GetProxiedFSConf());
            FileStatus status = fs.GetFileStatus(path);

            if (!IsLocalFS())
            {
                NUnit.Framework.Assert.AreEqual(status.GetReplication(), 2);
                NUnit.Framework.Assert.AreEqual(status.GetBlockSize(), 100 * 1024 * 1024);
            }
            NUnit.Framework.Assert.AreEqual(status.GetPermission(), permission);
            InputStream @is = fs.Open(path);

            NUnit.Framework.Assert.AreEqual(@is.Read(), 1);
            @is.Close();
            fs.Close();
        }
Example #15
0
        /// <exception cref="System.Exception"/>
        protected internal virtual void TestSetPermission()
        {
            FileSystem fs   = FileSystem.Get(GetProxiedFSConf());
            Path       path = new Path(GetProxiedFSTestDir(), "foodir");

            fs.Mkdirs(path);
            fs = GetHttpFSFileSystem();
            FsPermission permission1 = new FsPermission(FsAction.ReadWrite, FsAction.None, FsAction
                                                        .None);

            fs.SetPermission(path, permission1);
            fs.Close();
            fs = FileSystem.Get(GetProxiedFSConf());
            FileStatus status1 = fs.GetFileStatus(path);

            fs.Close();
            FsPermission permission2 = status1.GetPermission();

            NUnit.Framework.Assert.AreEqual(permission2, permission1);
            //sticky bit
            fs          = GetHttpFSFileSystem();
            permission1 = new FsPermission(FsAction.ReadWrite, FsAction.None, FsAction.None,
                                           true);
            fs.SetPermission(path, permission1);
            fs.Close();
            fs      = FileSystem.Get(GetProxiedFSConf());
            status1 = fs.GetFileStatus(path);
            fs.Close();
            permission2 = status1.GetPermission();
            NUnit.Framework.Assert.IsTrue(permission2.GetStickyBit());
            NUnit.Framework.Assert.AreEqual(permission2, permission1);
        }
Example #16
0
            // add a bunch of transactions.
            public virtual void Run()
            {
                thr = Sharpen.Thread.CurrentThread();
                FsPermission p = new FsPermission((short)0x1ff);
                int          i = 0;

                while (!stopped)
                {
                    try
                    {
                        string dirname = "/thr-" + thr.GetId() + "-dir-" + i;
                        nn.Mkdirs(dirname, p, true);
                        nn.Delete(dirname, true);
                    }
                    catch (SafeModeException)
                    {
                    }
                    catch (Exception e)
                    {
                        // This is OK - the tests will bring NN in and out of safemode
                        Log.Warn("Got error in transaction thread", e);
                        caught.CompareAndSet(null, e);
                        break;
                    }
                    i++;
                }
            }
Example #17
0
 /// <summary>
 /// Set the
 /// <see cref="Org.Apache.Hadoop.FS.Permission.FsPermission"/>
 /// of this
 /// <see cref="INode"/>
 ///
 /// </summary>
 internal virtual Org.Apache.Hadoop.Hdfs.Server.Namenode.INode SetPermission(FsPermission
                                                                             permission, int latestSnapshotId)
 {
     RecordModification(latestSnapshotId);
     SetPermission(permission);
     return(this);
 }
Example #18
0
        /// <exception cref="System.IO.IOException"/>
        private static void UnprotectedRemoveAcl(FSDirectory fsd, INodesInPath iip)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            INode      inode      = FSDirectory.ResolveLastINode(iip);
            int        snapshotId = iip.GetLatestSnapshotId();
            AclFeature f          = inode.GetAclFeature();

            if (f == null)
            {
                return;
            }
            FsPermission     perm           = inode.GetFsPermission();
            IList <AclEntry> featureEntries = AclStorage.GetEntriesFromAclFeature(f);

            if (featureEntries[0].GetScope() == AclEntryScope.Access)
            {
                // Restore group permissions from the feature's entry to permission
                // bits, overwriting the mask, which is not part of a minimal ACL.
                AclEntry groupEntryKey = new AclEntry.Builder().SetScope(AclEntryScope.Access).SetType
                                             (AclEntryType.Group).Build();
                int groupEntryIndex = Sharpen.Collections.BinarySearch(featureEntries, groupEntryKey
                                                                       , AclTransformation.AclEntryComparator);
                System.Diagnostics.Debug.Assert(groupEntryIndex >= 0);
                FsAction     groupPerm = featureEntries[groupEntryIndex].GetPermission();
                FsPermission newPerm   = new FsPermission(perm.GetUserAction(), groupPerm, perm.GetOtherAction
                                                              (), perm.GetStickyBit());
                inode.SetPermission(newPerm, snapshotId);
            }
            inode.RemoveAclFeature(snapshotId);
        }
        /// <summary>Tests modifying xattrs on a directory that has been snapshotted</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestModifyReadsCurrentState()
        {
            // Init
            FileSystem.Mkdirs(hdfs, path, FsPermission.CreateImmutable((short)0x1c0));
            SnapshotTestHelper.CreateSnapshot(hdfs, path, snapshotName);
            hdfs.SetXAttr(path, name1, value1);
            hdfs.SetXAttr(path, name2, value2);
            // Verify that current path reflects xattrs, snapshot doesn't
            IDictionary <string, byte[]> xattrs = hdfs.GetXAttrs(path);

            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value1, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            xattrs = hdfs.GetXAttrs(snapshotPath);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 0);
            // Modify each xattr and make sure it's reflected
            hdfs.SetXAttr(path, name1, value2, EnumSet.Of(XAttrSetFlag.Replace));
            xattrs = hdfs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value2, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            hdfs.SetXAttr(path, name2, value1, EnumSet.Of(XAttrSetFlag.Replace));
            xattrs = hdfs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value2, xattrs[name1]);
            Assert.AssertArrayEquals(value1, xattrs[name2]);
            // Paranoia checks
            xattrs = hdfs.GetXAttrs(snapshotPath);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 0);
            hdfs.RemoveXAttr(path, name1);
            hdfs.RemoveXAttr(path, name2);
            xattrs = hdfs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 0);
        }
Example #20
0
        internal override void SetPermission(FsPermission permission)
        {
            short mode = permission.ToShort();

            UpdatePermissionStatus(INodeWithAdditionalFields.PermissionStatusFormat.Mode, mode
                                   );
        }
        public virtual void TestXAttrForSnapshotRootAfterRemove()
        {
            FileSystem.Mkdirs(hdfs, path, FsPermission.CreateImmutable((short)0x1c0));
            hdfs.SetXAttr(path, name1, value1);
            hdfs.SetXAttr(path, name2, value2);
            SnapshotTestHelper.CreateSnapshot(hdfs, path, snapshotName);
            // Both original and snapshot have same XAttrs.
            IDictionary <string, byte[]> xattrs = hdfs.GetXAttrs(path);

            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value1, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            xattrs = hdfs.GetXAttrs(snapshotPath);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value1, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            // Original XAttrs have been removed, but snapshot still has old XAttrs.
            hdfs.RemoveXAttr(path, name1);
            hdfs.RemoveXAttr(path, name2);
            DoSnapshotRootRemovalAssertions(path, snapshotPath);
            Restart(false);
            DoSnapshotRootRemovalAssertions(path, snapshotPath);
            Restart(true);
            DoSnapshotRootRemovalAssertions(path, snapshotPath);
        }
 public virtual void TestSetXAttrSnapshotPath()
 {
     FileSystem.Mkdirs(hdfs, path, FsPermission.CreateImmutable((short)0x1c0));
     SnapshotTestHelper.CreateSnapshot(hdfs, path, snapshotName);
     exception.Expect(typeof(SnapshotAccessControlException));
     hdfs.SetXAttr(snapshotPath, name1, value1);
 }
Example #23
0
 public override FSDataOutputStream CreateNonRecursive(Path f, FsPermission permission
                                                       , EnumSet <CreateFlag> flags, int bufferSize, short replication, long blockSize,
                                                       Progressable progress)
 {
     return(fs.CreateNonRecursive(f, permission, flags, bufferSize, replication, blockSize
                                  , progress));
 }
Example #24
0
 /// <exception cref="System.IO.IOException"/>
 protected internal override FSDataOutputStream PrimitiveCreate(Path f, FsPermission
                                                                absolutePermission, EnumSet <CreateFlag> flag, int bufferSize, short replication
                                                                , long blockSize, Progressable progress, Options.ChecksumOpt checksumOpt)
 {
     return(fs.PrimitiveCreate(f, absolutePermission, flag, bufferSize, replication, blockSize
                               , progress, checksumOpt));
 }
        public virtual void TestCreateDirectories()
        {
            conf.Set(CommonConfigurationKeys.FsPermissionsUmaskKey, "077");
            string       dirA     = new FilePath(testDir, "dirA").GetPath();
            string       dirB     = new FilePath(dirA, "dirB").GetPath();
            string       dirC     = new FilePath(testDir, "dirC").GetPath();
            Path         pathC    = new Path(dirC);
            FsPermission permDirC = new FsPermission((short)0x1c8);

            localFs.Mkdir(pathC, null, true);
            localFs.SetPermission(pathC, permDirC);
            string[]            dirs = new string[] { dirA, dirB, dirC };
            DirectoryCollection dc   = new DirectoryCollection(dirs, conf.GetFloat(YarnConfiguration
                                                                                   .NmMaxPerDiskUtilizationPercentage, YarnConfiguration.DefaultNmMaxPerDiskUtilizationPercentage
                                                                                   ));
            FsPermission defaultPerm = FsPermission.GetDefault().ApplyUMask(new FsPermission(
                                                                                (short)FsPermission.DefaultUmask));
            bool createResult = dc.CreateNonExistentDirs(localFs, defaultPerm);

            NUnit.Framework.Assert.IsTrue(createResult);
            FileStatus status = localFs.GetFileStatus(new Path(dirA));

            NUnit.Framework.Assert.AreEqual("local dir parent not created with proper permissions"
                                            , defaultPerm, status.GetPermission());
            status = localFs.GetFileStatus(new Path(dirB));
            NUnit.Framework.Assert.AreEqual("local dir not created with proper permissions",
                                            defaultPerm, status.GetPermission());
            status = localFs.GetFileStatus(pathC);
            NUnit.Framework.Assert.AreEqual("existing local directory permissions modified",
                                            permDirC, status.GetPermission());
        }
Example #26
0
 /// <exception cref="System.IO.IOException"/>
 public override FSDataOutputStream Create(Path f, FsPermission permission, EnumSet
                                           <CreateFlag> flags, int bufferSize, short replication, long blockSize, Progressable
                                           progress, Options.ChecksumOpt checksumOpt)
 {
     return(fs.Create(f, permission, flags, bufferSize, replication, blockSize, progress
                      , checksumOpt));
 }
Example #27
0
        public virtual void TestBackwardCompatibility()
        {
            // Test 1 - old configuration key with decimal
            // umask value should be handled when set using
            // FSPermission.setUMask() API
            FsPermission  perm = new FsPermission((short)18);
            Configuration conf = new Configuration();

            FsPermission.SetUMask(conf, perm);
            NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort());
            // Test 2 - old configuration key set with decimal
            // umask value should be handled
            perm = new FsPermission((short)18);
            conf = new Configuration();
            conf.Set(FsPermission.DeprecatedUmaskLabel, "18");
            NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort());
            // Test 3 - old configuration key overrides the new one
            conf = new Configuration();
            conf.Set(FsPermission.DeprecatedUmaskLabel, "18");
            conf.Set(FsPermission.UmaskLabel, "000");
            NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort());
            // Test 4 - new configuration key is handled
            conf = new Configuration();
            conf.Set(FsPermission.UmaskLabel, "022");
            NUnit.Framework.Assert.AreEqual(18, FsPermission.GetUMask(conf).ToShort());
        }
Example #28
0
 public _PrivilegedExceptionAction_419(FSDownload _enclosing, Path path, FsPermission
                                       fPerm)
 {
     this._enclosing = _enclosing;
     this.path       = path;
     this.fPerm      = fPerm;
 }
 /// <summary>
 /// Create any non-existent directories and parent directories, updating the
 /// list of valid directories if necessary.
 /// </summary>
 /// <param name="localFs">local file system to use</param>
 /// <param name="perm">absolute permissions to use for any directories created</param>
 /// <returns>true if there were no errors, false if at least one error occurred</returns>
 internal virtual bool CreateNonExistentDirs(FileContext localFs, FsPermission perm
                                             )
 {
     lock (this)
     {
         bool failed = false;
         foreach (string dir in localDirs)
         {
             try
             {
                 CreateDir(localFs, new Path(dir), perm);
             }
             catch (IOException e)
             {
                 Log.Warn("Unable to create directory " + dir + " error " + e.Message + ", removing from the list of valid directories."
                          );
                 localDirs.Remove(dir);
                 errorDirs.AddItem(dir);
                 numFailures++;
                 failed = true;
             }
         }
         return(!failed);
     }
 }
Example #30
0
        /// <summary>Create a new cache pool based on a CachePoolInfo object and the defaults.
        ///     </summary>
        /// <remarks>
        /// Create a new cache pool based on a CachePoolInfo object and the defaults.
        /// We will fill in information that was not supplied according to the
        /// defaults.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal static CachePool CreateFromInfoAndDefaults(CachePoolInfo info)
        {
            UserGroupInformation ugi = null;
            string ownerName         = info.GetOwnerName();

            if (ownerName == null)
            {
                ugi       = NameNode.GetRemoteUser();
                ownerName = ugi.GetShortUserName();
            }
            string groupName = info.GetGroupName();

            if (groupName == null)
            {
                if (ugi == null)
                {
                    ugi = NameNode.GetRemoteUser();
                }
                groupName = ugi.GetPrimaryGroupName();
            }
            FsPermission mode = (info.GetMode() == null) ? FsPermission.GetCachePoolDefault()
                                 : info.GetMode();
            long limit = info.GetLimit() == null ? CachePoolInfo.DefaultLimit : info.GetLimit
                             ();
            long maxRelativeExpiry = info.GetMaxRelativeExpiryMs() == null ? CachePoolInfo.DefaultMaxRelativeExpiry
                                 : info.GetMaxRelativeExpiryMs();

            return(new CachePool(info.GetPoolName(), ownerName, groupName, mode, limit, maxRelativeExpiry
                                 ));
        }
 public FSDataOutputStream create(Path path, FsPermission fsPermission,
                                  bool overwrite, int bufferSize,
                                  short replication, long blockSize,
                                  Progressable progressable
                                  ) {
   MockFile file = null;
   for(MockFile currentFile: files) {
     if (currentFile.path.equals(path)) {
       file = currentFile;
       break;
     }
   }
   if (file == null) {
     file = new MockFile(path.toString(), (int) blockSize, new byte[0]);
     files.add(file);
   }
   return new MockOutputStream(file);
 }
 public bool mkdirs(Path path, FsPermission fsPermission) {
   return false;
 }