|
@@ -69,6 +69,10 @@ public class RMAdminCLI extends HAAdmin {
|
|
RecordFactoryProvider.getRecordFactory(null);
|
|
RecordFactoryProvider.getRecordFactory(null);
|
|
private boolean directlyAccessNodeLabelStore = false;
|
|
private boolean directlyAccessNodeLabelStore = false;
|
|
static CommonNodeLabelsManager localNodeLabelsManager = null;
|
|
static CommonNodeLabelsManager localNodeLabelsManager = null;
|
|
|
|
+ private static final String NO_LABEL_ERR_MSG =
|
|
|
|
+ "No cluster node-labels are specified";
|
|
|
|
+ private static final String NO_MAPPING_ERR_MSG =
|
|
|
|
+ "No node-to-labels mappings are specified";
|
|
|
|
|
|
protected final static Map<String, UsageInfo> ADMIN_USAGE =
|
|
protected final static Map<String, UsageInfo> ADMIN_USAGE =
|
|
ImmutableMap.<String, UsageInfo>builder()
|
|
ImmutableMap.<String, UsageInfo>builder()
|
|
@@ -332,18 +336,24 @@ public class RMAdminCLI extends HAAdmin {
|
|
return localNodeLabelsManager;
|
|
return localNodeLabelsManager;
|
|
}
|
|
}
|
|
|
|
|
|
- private int addToClusterNodeLabels(String args) throws IOException,
|
|
|
|
- YarnException {
|
|
|
|
|
|
+ private Set<String> buildNodeLabelsSetFromStr(String args) {
|
|
Set<String> labels = new HashSet<String>();
|
|
Set<String> labels = new HashSet<String>();
|
|
for (String p : args.split(",")) {
|
|
for (String p : args.split(",")) {
|
|
- labels.add(p);
|
|
|
|
|
|
+ if (!p.trim().isEmpty()) {
|
|
|
|
+ labels.add(p.trim());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- return addToClusterNodeLabels(labels);
|
|
|
|
|
|
+ if (labels.isEmpty()) {
|
|
|
|
+ throw new IllegalArgumentException(NO_LABEL_ERR_MSG);
|
|
|
|
+ }
|
|
|
|
+ return labels;
|
|
}
|
|
}
|
|
|
|
|
|
- private int addToClusterNodeLabels(Set<String> labels) throws IOException,
|
|
|
|
|
|
+ private int addToClusterNodeLabels(String args) throws IOException,
|
|
YarnException {
|
|
YarnException {
|
|
|
|
+ Set<String> labels = buildNodeLabelsSetFromStr(args);
|
|
|
|
+
|
|
if (directlyAccessNodeLabelStore) {
|
|
if (directlyAccessNodeLabelStore) {
|
|
getNodeLabelManagerInstance(getConf()).addToCluserNodeLabels(labels);
|
|
getNodeLabelManagerInstance(getConf()).addToCluserNodeLabels(labels);
|
|
} else {
|
|
} else {
|
|
@@ -358,10 +368,7 @@ public class RMAdminCLI extends HAAdmin {
|
|
|
|
|
|
private int removeFromClusterNodeLabels(String args) throws IOException,
|
|
private int removeFromClusterNodeLabels(String args) throws IOException,
|
|
YarnException {
|
|
YarnException {
|
|
- Set<String> labels = new HashSet<String>();
|
|
|
|
- for (String p : args.split(",")) {
|
|
|
|
- labels.add(p);
|
|
|
|
- }
|
|
|
|
|
|
+ Set<String> labels = buildNodeLabelsSetFromStr(args);
|
|
|
|
|
|
if (directlyAccessNodeLabelStore) {
|
|
if (directlyAccessNodeLabelStore) {
|
|
getNodeLabelManagerInstance(getConf()).removeFromClusterNodeLabels(
|
|
getNodeLabelManagerInstance(getConf()).removeFromClusterNodeLabels(
|
|
@@ -377,7 +384,7 @@ public class RMAdminCLI extends HAAdmin {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- private Map<NodeId, Set<String>> buildNodeLabelsFromStr(String args)
|
|
|
|
|
|
+ private Map<NodeId, Set<String>> buildNodeLabelsMapFromStr(String args)
|
|
throws IOException {
|
|
throws IOException {
|
|
Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
|
|
Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
|
|
|
|
|
|
@@ -404,12 +411,15 @@ public class RMAdminCLI extends HAAdmin {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (map.isEmpty()) {
|
|
|
|
+ throw new IllegalArgumentException(NO_MAPPING_ERR_MSG);
|
|
|
|
+ }
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
private int replaceLabelsOnNodes(String args) throws IOException,
|
|
private int replaceLabelsOnNodes(String args) throws IOException,
|
|
YarnException {
|
|
YarnException {
|
|
- Map<NodeId, Set<String>> map = buildNodeLabelsFromStr(args);
|
|
|
|
|
|
+ Map<NodeId, Set<String>> map = buildNodeLabelsMapFromStr(args);
|
|
return replaceLabelsOnNodes(map);
|
|
return replaceLabelsOnNodes(map);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -507,21 +517,21 @@ public class RMAdminCLI extends HAAdmin {
|
|
exitCode = getGroups(usernames);
|
|
exitCode = getGroups(usernames);
|
|
} else if ("-addToClusterNodeLabels".equals(cmd)) {
|
|
} else if ("-addToClusterNodeLabels".equals(cmd)) {
|
|
if (i >= args.length) {
|
|
if (i >= args.length) {
|
|
- System.err.println("No cluster node-labels are specified");
|
|
|
|
|
|
+ System.err.println(NO_LABEL_ERR_MSG);
|
|
exitCode = -1;
|
|
exitCode = -1;
|
|
} else {
|
|
} else {
|
|
exitCode = addToClusterNodeLabels(args[i]);
|
|
exitCode = addToClusterNodeLabels(args[i]);
|
|
}
|
|
}
|
|
} else if ("-removeFromClusterNodeLabels".equals(cmd)) {
|
|
} else if ("-removeFromClusterNodeLabels".equals(cmd)) {
|
|
if (i >= args.length) {
|
|
if (i >= args.length) {
|
|
- System.err.println("No cluster node-labels are specified");
|
|
|
|
|
|
+ System.err.println(NO_LABEL_ERR_MSG);
|
|
exitCode = -1;
|
|
exitCode = -1;
|
|
} else {
|
|
} else {
|
|
exitCode = removeFromClusterNodeLabels(args[i]);
|
|
exitCode = removeFromClusterNodeLabels(args[i]);
|
|
}
|
|
}
|
|
} else if ("-replaceLabelsOnNode".equals(cmd)) {
|
|
} else if ("-replaceLabelsOnNode".equals(cmd)) {
|
|
if (i >= args.length) {
|
|
if (i >= args.length) {
|
|
- System.err.println("No cluster node-labels are specified");
|
|
|
|
|
|
+ System.err.println(NO_MAPPING_ERR_MSG);
|
|
exitCode = -1;
|
|
exitCode = -1;
|
|
} else {
|
|
} else {
|
|
exitCode = replaceLabelsOnNodes(args[i]);
|
|
exitCode = replaceLabelsOnNodes(args[i]);
|