From 0658db7c9bc5877be6af8f4a851d21c435e4fe11 Mon Sep 17 00:00:00 2001 From: vkorukanti Date: Wed, 20 Aug 2014 13:31:40 -0700 Subject: [PATCH] HIVE-7807: Refer to umask property using FsPermission.UMASK_LABEL --- .../apache/hadoop/hive/ql/TestUtilitiesDfs.java | 69 ++++++++++++++++++++++ .../org/apache/hadoop/hive/ql/exec/Utilities.java | 8 +-- .../apache/hadoop/hive/ql/exec/TestUtilities.java | 5 +- 3 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestUtilitiesDfs.java diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestUtilitiesDfs.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestUtilitiesDfs.java new file mode 100644 index 0000000..69d88c1 --- /dev/null +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestUtilitiesDfs.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql; + +import java.io.IOException; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.exec.Utilities; +import org.apache.hadoop.hive.shims.HadoopShims.MiniDFSShim; +import org.apache.hadoop.hive.shims.ShimLoader; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class TestUtilitiesDfs { + private static final FsPermission FULL_PERM = new FsPermission((short) 00777); + private static MiniDFSShim dfs; + private static HiveConf conf; + + @BeforeClass + public static void setupDfs() throws Exception { + conf = new HiveConf(); + dfs = ShimLoader.getHadoopShims().getMiniDfs(conf, 4, true, null); + + assertNotNull("MiniDFS is not initialized", dfs); + assertNotNull("HiveConf is not initialized", conf); + } + + @Test + public void testCreateDirWithPermissionRecursive() throws IllegalArgumentException, IOException { + FileSystem fs = dfs.getFileSystem(); + Path dir = new Path(new Path(fs.getUri()), "/testUtilitiesUMaskReset"); + Utilities.createDirsWithPermission(conf, dir, FULL_PERM, true); + FileStatus status = fs.getFileStatus(dir); + assertEquals("Created dir has invalid permissions.", + FULL_PERM.toString(), status.getPermission().toString()); + } + + @AfterClass + public static void shutdownDfs() throws Exception { + if (dfs != null) { + dfs.shutdown(); + dfs = null; + } + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index 1d6a93a..76fee61 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -3466,9 +3466,9 @@ private static void resetConfAndCloseFS (Configuration conf, boolean unsetUmask, String origUmask, FileSystem fs) throws IOException { if (unsetUmask) { if (origUmask != null) { - conf.set("fs.permissions.umask-mode", origUmask); + conf.set(FsPermission.UMASK_LABEL, origUmask); } else { - conf.unset("fs.permissions.umask-mode"); + conf.unset(FsPermission.UMASK_LABEL); } } @@ -3482,10 +3482,10 @@ public static boolean createDirsWithPermission(Configuration conf, Path mkdirPat recursive); if (recursive) { - origUmask = conf.get("fs.permissions.umask-mode"); + origUmask = conf.get(FsPermission.UMASK_LABEL); // this umask is required because by default the hdfs mask is 022 resulting in // all parents getting the fsPermission & !(022) permission instead of fsPermission - conf.set("fs.permissions.umask-mode", "000"); + conf.set(FsPermission.UMASK_LABEL, "000"); } FileSystem fs = ShimLoader.getHadoopShims().getNonCachedFileSystem(mkdirPath.toUri(), conf); diff --git ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java index bf3fd88..7fd6c17 100644 --- ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java +++ ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java @@ -118,14 +118,13 @@ public void testFSUmaskReset() throws Exception { } private void checkFSUMaskReset(boolean recursiveArg) throws IllegalArgumentException, IOException { - final String FS_MASK_PARAM = "fs.permissions.umask-mode"; final String FS_MASK_VAL = "055"; HiveConf conf = new HiveConf(); String dir = System.getProperty("test.tmp.dir") + "/testUtilitiesUMaskReset"; - conf.set(FS_MASK_PARAM, FS_MASK_VAL); + conf.set(FsPermission.UMASK_LABEL, FS_MASK_VAL); Utilities.createDirsWithPermission(conf, new Path(dir), new FsPermission((short) 00777), recursiveArg); - assertEquals(conf.get(FS_MASK_PARAM), FS_MASK_VAL); + assertEquals(conf.get(FsPermission.UMASK_LABEL), FS_MASK_VAL); } -- 1.8.5.2 (Apple Git-48)