@@ -249,6 +249,10 @@ private boolean validateMin(String[] argv) {
249249 if (argv .length < 2 ) {
250250 return false ;
251251 }
252+ } else if ("-initViewFsToMountTable" .equals (cmd )) {
253+ if (argv .length < 2 ) {
254+ return false ;
255+ }
252256 } else if ("-getDestination" .equals (cmd )) {
253257 if (argv .length < 2 ) {
254258 return false ;
@@ -392,8 +396,9 @@ public int run(String[] argv) throws Exception {
392396 } else if ("-refresh" .equals (cmd )) {
393397 refresh (address );
394398 } else if ("-initViewFsToMountTable" .equals (cmd )) {
395- if (initViewFsToMountTable (argv , i )) {
396- System .out .println ("Successfully init ViewFs mapping to router " + argv [i ]);
399+ if (initViewFsToMountTable (argv [i ])) {
400+ System .out .println ("Successfully init ViewFs mapping to router " +
401+ argv [i ]);
397402 } else {
398403 exitCode = -1 ;
399404 }
@@ -1052,53 +1057,63 @@ private boolean updateQuota(String mount, long nsQuota, long ssQuota)
10521057
10531058 /**
10541059 * initViewFsToMountTable.
1055- *
1056- * @param parameters The specified cluster to initialize.
1057- * @param i Index in the parameters
1060+ * @param clusterName The specified cluster to initialize.
10581061 * @return If the quota was updated.
10591062 * @throws IOException Error adding the mount point.
10601063 */
1061- public boolean initViewFsToMountTable (String [] parameters , int i ) throws IOException {
1062- String clusterName = parameters [i ++];
1063- if (clusterName == null ) {
1064- System .out .println ("Please enter the cluster name." );
1065- return false ;
1066- }
1064+ public boolean initViewFsToMountTable (String clusterName )
1065+ throws IOException {
1066+ // fs.viewfs.mounttable.ClusterX.link./data
10671067 final String mountTablePrefix =
10681068 Constants .CONFIG_VIEWFS_PREFIX + "." + clusterName + "." +
10691069 Constants .CONFIG_VIEWFS_LINK + "./" ;
10701070 Map <String , String > viewFsMap = getConf ().getValByRegex (mountTablePrefix );
1071- if (viewFsMap .size () == 0 ) {
1072- System .out .println ("Please check the cluster name and veiwfs " +
1073- "configuration." ) ;
1071+ if (viewFsMap .isEmpty () ) {
1072+ System .out .println ("There is no ViewFs mapping to initialize." );
1073+ return true ;
10741074 }
1075- for (String key : viewFsMap .keySet ()) {
1076- Path path = new Path (viewFsMap .get (key ));
1077- String owner = null ;
1078- String group = null ;
1079- FsPermission mode = null ;
1080- try {
1081- FileSystem fs = path .getFileSystem (getConf ());
1082- if (fs .exists (path )) {
1083- FileStatus fileStatus = fs .getFileStatus (path );
1084- owner = fileStatus .getOwner ();
1085- group = fileStatus .getGroup ();
1086- mode = fileStatus .getPermission ();
1087- }
1088- } catch (Exception e ) {
1089- LOG .warn ("Exception encountered" , e );
1090- }
1075+ for (Entry <String , String > entry : viewFsMap .entrySet ()) {
1076+ Path path = new Path (entry .getValue ());
10911077 DestinationOrder order = DestinationOrder .HASH ;
1092- String mount =
1093- key .split (clusterName + "." + Constants .CONFIG_VIEWFS_LINK + "." )[1 ];
1094- String dest = path .toUri ().getPath ();
1078+ String [] mount = entry .getKey ().split (
1079+ clusterName + "." + Constants .CONFIG_VIEWFS_LINK + "." );
1080+ if (mount .length < 2 ) {
1081+ System .out .println ("Added Mount Point failed " + entry .getKey ());
1082+ continue ;
1083+ }
10951084 String [] nss = new String []{path .toUri ().getAuthority ()};
1096- addMount (mount , nss , dest , false , false , order ,
1097- new ACLEntity (owner , group , mode ));
1085+ boolean added = addMount (
1086+ mount [1 ], nss , path .toUri ().getPath (), false ,
1087+ false , order , getACLEntityFormHdfsPath (path ));
1088+ if (added ) {
1089+ System .out .println ("added mount point " + mount [1 ]);
1090+ }
10981091 }
10991092 return true ;
11001093 }
1101-
1094+
1095+ /**
1096+ * Returns ACLEntity according to a HDFS pat.
1097+ * @param path A path of HDFS.
1098+ */
1099+ public ACLEntity getACLEntityFormHdfsPath (Path path ){
1100+ String owner = null ;
1101+ String group = null ;
1102+ FsPermission mode = null ;
1103+ try {
1104+ FileSystem fs = path .getFileSystem (getConf ());
1105+ if (fs .exists (path )) {
1106+ FileStatus fileStatus = fs .getFileStatus (path );
1107+ owner = fileStatus .getOwner ();
1108+ group = fileStatus .getGroup ();
1109+ mode = fileStatus .getPermission ();
1110+ }
1111+ } catch (IOException e ) {
1112+ System .out .println ("Exception encountered " + e );
1113+ }
1114+ return new ACLEntity (owner , group , mode );
1115+ }
1116+
11021117 /**
11031118 * Update storage type quota of specified mount table.
11041119 *
0 commit comments