@@ -249,6 +249,10 @@ private boolean validateMin(String[] argv) {
249
249
if (argv .length < 2 ) {
250
250
return false ;
251
251
}
252
+ } else if ("-initViewFsToMountTable" .equals (cmd )) {
253
+ if (argv .length < 2 ) {
254
+ return false ;
255
+ }
252
256
} else if ("-getDestination" .equals (cmd )) {
253
257
if (argv .length < 2 ) {
254
258
return false ;
@@ -392,8 +396,9 @@ public int run(String[] argv) throws Exception {
392
396
} else if ("-refresh" .equals (cmd )) {
393
397
refresh (address );
394
398
} 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 ]);
397
402
} else {
398
403
exitCode = -1 ;
399
404
}
@@ -1052,53 +1057,63 @@ private boolean updateQuota(String mount, long nsQuota, long ssQuota)
1052
1057
1053
1058
/**
1054
1059
* 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.
1058
1061
* @return If the quota was updated.
1059
1062
* @throws IOException Error adding the mount point.
1060
1063
*/
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
1067
1067
final String mountTablePrefix =
1068
1068
Constants .CONFIG_VIEWFS_PREFIX + "." + clusterName + "." +
1069
1069
Constants .CONFIG_VIEWFS_LINK + "./" ;
1070
1070
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 ;
1074
1074
}
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 ());
1091
1077
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
+ }
1095
1084
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
+ }
1098
1091
}
1099
1092
return true ;
1100
1093
}
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
+
1102
1117
/**
1103
1118
* Update storage type quota of specified mount table.
1104
1119
*
0 commit comments