|
@@ -22,8 +22,10 @@ import java.net.InetSocketAddress;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.LinkedHashMap;
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
@@ -138,9 +140,10 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
+ "[-readonly] [-faulttolerant] [-order HASH|LOCAL|RANDOM|HASH_ALL] "
|
|
|
+ "-owner <owner> -group <group> -mode <mode>]";
|
|
|
} else if (cmd.equals("-update")) {
|
|
|
- return "\t[-update <source> <nameservice1, nameservice2, ...> "
|
|
|
- + "<destination> "
|
|
|
- + "[-readonly] [-faulttolerant] [-order HASH|LOCAL|RANDOM|HASH_ALL] "
|
|
|
+ return "\t[-update <source>"
|
|
|
+ + " [<nameservice1, nameservice2, ...> <destination>] "
|
|
|
+ + "[-readonly true|false] [-faulttolerant true|false]"
|
|
|
+ + " [-order HASH|LOCAL|RANDOM|HASH_ALL] "
|
|
|
+ "-owner <owner> -group <group> -mode <mode>]";
|
|
|
} else if (cmd.equals("-rm")) {
|
|
|
return "\t[-rm <source>]";
|
|
@@ -294,6 +297,8 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
} else if ("-update".equals(cmd)) {
|
|
|
if (updateMount(argv, i)) {
|
|
|
System.out.println("Successfully updated mount point " + argv[i]);
|
|
|
+ System.out.println(
|
|
|
+ "WARN: Changing order/destinations may lead to inconsistencies");
|
|
|
} else {
|
|
|
exitCode = -1;
|
|
|
}
|
|
@@ -366,6 +371,10 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
e.printStackTrace();
|
|
|
debugException = ex;
|
|
|
}
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ exitCode = -1;
|
|
|
+ System.err.println(cmd.substring(1) + ": " + ioe.getLocalizedMessage());
|
|
|
+ printUsage(cmd);
|
|
|
} catch (Exception e) {
|
|
|
exitCode = -1;
|
|
|
debugException = e;
|
|
@@ -473,17 +482,7 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
mount = normalizeFileSystemPath(mount);
|
|
|
// Get the existing entry
|
|
|
MountTableManager mountTable = client.getMountTableManager();
|
|
|
- GetMountTableEntriesRequest getRequest =
|
|
|
- GetMountTableEntriesRequest.newInstance(mount);
|
|
|
- GetMountTableEntriesResponse getResponse =
|
|
|
- mountTable.getMountTableEntries(getRequest);
|
|
|
- List<MountTable> results = getResponse.getEntries();
|
|
|
- MountTable existingEntry = null;
|
|
|
- for (MountTable result : results) {
|
|
|
- if (mount.equals(result.getSourcePath())) {
|
|
|
- existingEntry = result;
|
|
|
- }
|
|
|
- }
|
|
|
+ MountTable existingEntry = getMountEntry(mount, mountTable);
|
|
|
|
|
|
if (existingEntry == null) {
|
|
|
// Create and add the entry if it doesn't exist
|
|
@@ -579,100 +578,81 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
* @throws IOException If there is an error.
|
|
|
*/
|
|
|
public boolean updateMount(String[] parameters, int i) throws IOException {
|
|
|
- // Mandatory parameters
|
|
|
String mount = parameters[i++];
|
|
|
- String[] nss = parameters[i++].split(",");
|
|
|
- String dest = parameters[i++];
|
|
|
-
|
|
|
- // Optional parameters
|
|
|
- boolean readOnly = false;
|
|
|
- boolean faultTolerant = false;
|
|
|
- String owner = null;
|
|
|
- String group = null;
|
|
|
- FsPermission mode = null;
|
|
|
- DestinationOrder order = null;
|
|
|
- while (i < parameters.length) {
|
|
|
- if (parameters[i].equals("-readonly")) {
|
|
|
- readOnly = true;
|
|
|
- } else if (parameters[i].equals("-faulttolerant")) {
|
|
|
- faultTolerant = true;
|
|
|
- } else if (parameters[i].equals("-order")) {
|
|
|
- i++;
|
|
|
- try {
|
|
|
- order = DestinationOrder.valueOf(parameters[i]);
|
|
|
- } catch(Exception e) {
|
|
|
- System.err.println("Cannot parse order: " + parameters[i]);
|
|
|
- }
|
|
|
- } else if (parameters[i].equals("-owner")) {
|
|
|
- i++;
|
|
|
- owner = parameters[i];
|
|
|
- } else if (parameters[i].equals("-group")) {
|
|
|
- i++;
|
|
|
- group = parameters[i];
|
|
|
- } else if (parameters[i].equals("-mode")) {
|
|
|
- i++;
|
|
|
- short modeValue = Short.parseShort(parameters[i], 8);
|
|
|
- mode = new FsPermission(modeValue);
|
|
|
- } else {
|
|
|
- printUsage("-update");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- i++;
|
|
|
- }
|
|
|
-
|
|
|
- return updateMount(mount, nss, dest, readOnly, faultTolerant, order,
|
|
|
- new ACLEntity(owner, group, mode));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Update a mount table entry.
|
|
|
- *
|
|
|
- * @param mount Mount point.
|
|
|
- * @param nss Nameservices where this is mounted to.
|
|
|
- * @param dest Destination path.
|
|
|
- * @param readonly If the mount point is read only.
|
|
|
- * @param order Order of the destination locations.
|
|
|
- * @param aclInfo the ACL info for mount point.
|
|
|
- * @return If the mount point was updated.
|
|
|
- * @throws IOException Error updating the mount point.
|
|
|
- */
|
|
|
- public boolean updateMount(String mount, String[] nss, String dest,
|
|
|
- boolean readonly, boolean faultTolerant,
|
|
|
- DestinationOrder order, ACLEntity aclInfo)
|
|
|
- throws IOException {
|
|
|
mount = normalizeFileSystemPath(mount);
|
|
|
MountTableManager mountTable = client.getMountTableManager();
|
|
|
-
|
|
|
- // Create a new entry
|
|
|
- Map<String, String> destMap = new LinkedHashMap<>();
|
|
|
- for (String ns : nss) {
|
|
|
- destMap.put(ns, dest);
|
|
|
- }
|
|
|
- MountTable newEntry = MountTable.newInstance(mount, destMap);
|
|
|
-
|
|
|
- newEntry.setReadOnly(readonly);
|
|
|
- newEntry.setFaultTolerant(faultTolerant);
|
|
|
-
|
|
|
- if (order != null) {
|
|
|
- newEntry.setDestOrder(order);
|
|
|
- }
|
|
|
-
|
|
|
- // Update ACL info of mount table entry
|
|
|
- if (aclInfo.getOwner() != null) {
|
|
|
- newEntry.setOwnerName(aclInfo.getOwner());
|
|
|
+ MountTable existingEntry = getMountEntry(mount, mountTable);
|
|
|
+ if (existingEntry == null) {
|
|
|
+ throw new IOException(mount + " doesn't exist.");
|
|
|
}
|
|
|
+ // Check if the destination needs to be updated.
|
|
|
|
|
|
- if (aclInfo.getGroup() != null) {
|
|
|
- newEntry.setGroupName(aclInfo.getGroup());
|
|
|
+ if (!parameters[i].startsWith("-")) {
|
|
|
+ String[] nss = parameters[i++].split(",");
|
|
|
+ String dest = parameters[i++];
|
|
|
+ Map<String, String> destMap = new LinkedHashMap<>();
|
|
|
+ for (String ns : nss) {
|
|
|
+ destMap.put(ns, dest);
|
|
|
+ }
|
|
|
+ final List<RemoteLocation> locations = new LinkedList<>();
|
|
|
+ for (Entry<String, String> entry : destMap.entrySet()) {
|
|
|
+ String nsId = entry.getKey();
|
|
|
+ String path = normalizeFileSystemPath(entry.getValue());
|
|
|
+ RemoteLocation location = new RemoteLocation(nsId, path, mount);
|
|
|
+ locations.add(location);
|
|
|
+ }
|
|
|
+ existingEntry.setDestinations(locations);
|
|
|
}
|
|
|
-
|
|
|
- if (aclInfo.getMode() != null) {
|
|
|
- newEntry.setMode(aclInfo.getMode());
|
|
|
+ try {
|
|
|
+ while (i < parameters.length) {
|
|
|
+ switch (parameters[i]) {
|
|
|
+ case "-readonly":
|
|
|
+ i++;
|
|
|
+ existingEntry.setReadOnly(getBooleanValue(parameters[i]));
|
|
|
+ break;
|
|
|
+ case "-faulttolerant":
|
|
|
+ i++;
|
|
|
+ existingEntry.setFaultTolerant(getBooleanValue(parameters[i]));
|
|
|
+ break;
|
|
|
+ case "-order":
|
|
|
+ i++;
|
|
|
+ try {
|
|
|
+ existingEntry.setDestOrder(DestinationOrder.valueOf(parameters[i]));
|
|
|
+ break;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception("Cannot parse order: " + parameters[i]);
|
|
|
+ }
|
|
|
+ case "-owner":
|
|
|
+ i++;
|
|
|
+ existingEntry.setOwnerName(parameters[i]);
|
|
|
+ break;
|
|
|
+ case "-group":
|
|
|
+ i++;
|
|
|
+ existingEntry.setGroupName(parameters[i]);
|
|
|
+ break;
|
|
|
+ case "-mode":
|
|
|
+ i++;
|
|
|
+ short modeValue = Short.parseShort(parameters[i], 8);
|
|
|
+ existingEntry.setMode(new FsPermission(modeValue));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ printUsage("-update");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ } catch (IllegalArgumentException iae) {
|
|
|
+ throw iae;
|
|
|
+ } catch (Exception e) {
|
|
|
+ String msg = "Unable to parse arguments: " + e.getMessage();
|
|
|
+ if (e instanceof ArrayIndexOutOfBoundsException) {
|
|
|
+ msg = "Unable to parse arguments: no value provided for "
|
|
|
+ + parameters[i - 1];
|
|
|
+ }
|
|
|
+ throw new IOException(msg);
|
|
|
}
|
|
|
-
|
|
|
UpdateMountTableEntryRequest updateRequest =
|
|
|
- UpdateMountTableEntryRequest.newInstance(newEntry);
|
|
|
+ UpdateMountTableEntryRequest.newInstance(existingEntry);
|
|
|
UpdateMountTableEntryResponse updateResponse =
|
|
|
mountTable.updateMountTableEntry(updateRequest);
|
|
|
boolean updated = updateResponse.getStatus();
|
|
@@ -682,6 +662,45 @@ public class RouterAdmin extends Configured implements Tool {
|
|
|
return updated;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Parse string to boolean.
|
|
|
+ * @param value the string to be parsed.
|
|
|
+ * @return parsed boolean value.
|
|
|
+ * @throws Exception if other than true|false is provided.
|
|
|
+ */
|
|
|
+ private boolean getBooleanValue(String value) throws Exception {
|
|
|
+ if (value.equalsIgnoreCase("true")) {
|
|
|
+ return true;
|
|
|
+ } else if (value.equalsIgnoreCase("false")) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ throw new IllegalArgumentException("Invalid argument: " + value
|
|
|
+ + ". Please specify either true or false.");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets the mount table entry.
|
|
|
+ * @param mount name of the mount entry.
|
|
|
+ * @param mountTable the mount table.
|
|
|
+ * @return corresponding mount entry.
|
|
|
+ * @throws IOException in case of failure to retrieve mount entry.
|
|
|
+ */
|
|
|
+ private MountTable getMountEntry(String mount, MountTableManager mountTable)
|
|
|
+ throws IOException {
|
|
|
+ GetMountTableEntriesRequest getRequest =
|
|
|
+ GetMountTableEntriesRequest.newInstance(mount);
|
|
|
+ GetMountTableEntriesResponse getResponse =
|
|
|
+ mountTable.getMountTableEntries(getRequest);
|
|
|
+ List<MountTable> results = getResponse.getEntries();
|
|
|
+ MountTable existingEntry = null;
|
|
|
+ for (MountTable result : results) {
|
|
|
+ if (mount.equals(result.getSourcePath())) {
|
|
|
+ existingEntry = result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return existingEntry;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Remove mount point.
|
|
|
*
|