|
@@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.client.cli;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.sun.jersey.api.client.Client;
|
|
import com.sun.jersey.api.client.Client;
|
|
import com.sun.jersey.api.client.ClientResponse;
|
|
import com.sun.jersey.api.client.ClientResponse;
|
|
|
|
+import com.sun.jersey.api.client.WebResource;
|
|
import com.sun.jersey.api.client.WebResource.Builder;
|
|
import com.sun.jersey.api.client.WebResource.Builder;
|
|
import org.apache.commons.cli.CommandLine;
|
|
import org.apache.commons.cli.CommandLine;
|
|
import org.apache.commons.cli.GnuParser;
|
|
import org.apache.commons.cli.GnuParser;
|
|
@@ -30,6 +31,7 @@ import org.apache.hadoop.classification.InterfaceAudience.Public;
|
|
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
|
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configured;
|
|
import org.apache.hadoop.conf.Configured;
|
|
|
|
+import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.util.Tool;
|
|
import org.apache.hadoop.util.Tool;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.webapp.dao.QueueConfigInfo;
|
|
import org.apache.hadoop.yarn.webapp.dao.QueueConfigInfo;
|
|
@@ -56,6 +58,7 @@ public class SchedConfCLI extends Configured implements Tool {
|
|
private static final String REMOVE_QUEUES_OPTION = "removeQueues";
|
|
private static final String REMOVE_QUEUES_OPTION = "removeQueues";
|
|
private static final String UPDATE_QUEUES_OPTION = "updateQueues";
|
|
private static final String UPDATE_QUEUES_OPTION = "updateQueues";
|
|
private static final String GLOBAL_OPTIONS = "globalUpdates";
|
|
private static final String GLOBAL_OPTIONS = "globalUpdates";
|
|
|
|
+ private static final String FORMAT_CONF = "formatConfig";
|
|
private static final String HELP_CMD = "help";
|
|
private static final String HELP_CMD = "help";
|
|
|
|
|
|
private static final String CONF_ERR_MSG = "Specify configuration key " +
|
|
private static final String CONF_ERR_MSG = "Specify configuration key " +
|
|
@@ -83,6 +86,9 @@ public class SchedConfCLI extends Configured implements Tool {
|
|
"Update queue configurations");
|
|
"Update queue configurations");
|
|
opts.addOption("global", GLOBAL_OPTIONS, true,
|
|
opts.addOption("global", GLOBAL_OPTIONS, true,
|
|
"Update global scheduler configurations");
|
|
"Update global scheduler configurations");
|
|
|
|
+ opts.addOption("format", FORMAT_CONF, false,
|
|
|
|
+ "Format Scheduler Configuration and reload from" +
|
|
|
|
+ " capacity-scheduler.xml");
|
|
opts.addOption("h", HELP_CMD, false, "Displays help for all commands.");
|
|
opts.addOption("h", HELP_CMD, false, "Displays help for all commands.");
|
|
|
|
|
|
int exitCode = -1;
|
|
int exitCode = -1;
|
|
@@ -101,6 +107,7 @@ public class SchedConfCLI extends Configured implements Tool {
|
|
}
|
|
}
|
|
|
|
|
|
boolean hasOption = false;
|
|
boolean hasOption = false;
|
|
|
|
+ boolean format = false;
|
|
SchedConfUpdateInfo updateInfo = new SchedConfUpdateInfo();
|
|
SchedConfUpdateInfo updateInfo = new SchedConfUpdateInfo();
|
|
try {
|
|
try {
|
|
if (parsedCli.hasOption(ADD_QUEUES_OPTION)) {
|
|
if (parsedCli.hasOption(ADD_QUEUES_OPTION)) {
|
|
@@ -121,6 +128,11 @@ public class SchedConfCLI extends Configured implements Tool {
|
|
hasOption = true;
|
|
hasOption = true;
|
|
globalUpdates(parsedCli.getOptionValue(GLOBAL_OPTIONS), updateInfo);
|
|
globalUpdates(parsedCli.getOptionValue(GLOBAL_OPTIONS), updateInfo);
|
|
}
|
|
}
|
|
|
|
+ if (parsedCli.hasOption((FORMAT_CONF))) {
|
|
|
|
+ hasOption = true;
|
|
|
|
+ format = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
} catch (IllegalArgumentException e) {
|
|
} catch (IllegalArgumentException e) {
|
|
System.err.println(e.getMessage());
|
|
System.err.println(e.getMessage());
|
|
return -1;
|
|
return -1;
|
|
@@ -133,18 +145,78 @@ public class SchedConfCLI extends Configured implements Tool {
|
|
}
|
|
}
|
|
|
|
|
|
Configuration conf = getConf();
|
|
Configuration conf = getConf();
|
|
- return WebAppUtils.execOnActiveRM(conf,
|
|
|
|
- this::updateSchedulerConfOnRMNode, updateInfo);
|
|
|
|
|
|
+ if (format) {
|
|
|
|
+ return WebAppUtils.execOnActiveRM(conf, this::formatSchedulerConf, null);
|
|
|
|
+ } else {
|
|
|
|
+ return WebAppUtils.execOnActiveRM(conf,
|
|
|
|
+ this::updateSchedulerConfOnRMNode, updateInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ int formatSchedulerConf(String webAppAddress, WebResource resource)
|
|
|
|
+ throws Exception {
|
|
|
|
+ Client webServiceClient = Client.create();
|
|
|
|
+ ClientResponse response = null;
|
|
|
|
+ resource = (resource != null) ? resource :
|
|
|
|
+ webServiceClient.resource(webAppAddress);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Builder builder = null;
|
|
|
|
+ if (UserGroupInformation.isSecurityEnabled()) {
|
|
|
|
+ builder = resource
|
|
|
|
+ .path("ws").path("v1").path("cluster")
|
|
|
|
+ .path("/scheduler-conf/format")
|
|
|
|
+ .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON);
|
|
|
|
+ } else {
|
|
|
|
+ builder = resource
|
|
|
|
+ .path("ws").path("v1").path("cluster")
|
|
|
|
+ .path("/scheduler-conf/format").queryParam("user.name",
|
|
|
|
+ UserGroupInformation.getCurrentUser().getShortUserName())
|
|
|
|
+ .accept(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ response = builder.get(ClientResponse.class);
|
|
|
|
+ if (response != null) {
|
|
|
|
+ if (response.getStatus() == Status.OK.getStatusCode()) {
|
|
|
|
+ System.out.println(response.getEntity(String.class));
|
|
|
|
+ return 0;
|
|
|
|
+ } else {
|
|
|
|
+ System.err.println("Failed to format scheduler configuration: " +
|
|
|
|
+ response.getEntity(String.class));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ System.err.println("Failed to format scheduler configuration: " +
|
|
|
|
+ "null response");
|
|
|
|
+ }
|
|
|
|
+ return -1;
|
|
|
|
+ } finally {
|
|
|
|
+ if (response != null) {
|
|
|
|
+ response.close();
|
|
|
|
+ }
|
|
|
|
+ webServiceClient.destroy();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- private int updateSchedulerConfOnRMNode(String webAppAddress,
|
|
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ int updateSchedulerConfOnRMNode(String webAppAddress,
|
|
SchedConfUpdateInfo updateInfo) throws Exception {
|
|
SchedConfUpdateInfo updateInfo) throws Exception {
|
|
Client webServiceClient = Client.create();
|
|
Client webServiceClient = Client.create();
|
|
ClientResponse response = null;
|
|
ClientResponse response = null;
|
|
|
|
+ WebResource resource = webServiceClient.resource(webAppAddress);
|
|
|
|
+
|
|
try {
|
|
try {
|
|
- Builder builder = webServiceClient.resource(webAppAddress)
|
|
|
|
- .path("ws").path("v1").path("cluster")
|
|
|
|
- .path("scheduler-conf").accept(MediaType.APPLICATION_JSON);
|
|
|
|
|
|
+ Builder builder = null;
|
|
|
|
+ if (UserGroupInformation.isSecurityEnabled()) {
|
|
|
|
+ builder = resource.path("ws").path("v1").path("cluster")
|
|
|
|
+ .path("scheduler-conf").accept(MediaType.APPLICATION_JSON);
|
|
|
|
+ } else {
|
|
|
|
+ builder = resource.path("ws").path("v1").path("cluster")
|
|
|
|
+ .queryParam("user.name",
|
|
|
|
+ UserGroupInformation.getCurrentUser().getShortUserName())
|
|
|
|
+ .path("scheduler-conf").accept(MediaType.APPLICATION_JSON);
|
|
|
|
+ }
|
|
|
|
+
|
|
builder.entity(YarnWebServiceUtils.toJson(updateInfo,
|
|
builder.entity(YarnWebServiceUtils.toJson(updateInfo,
|
|
SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON);
|
|
SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON);
|
|
response = builder.put(ClientResponse.class);
|
|
response = builder.put(ClientResponse.class);
|
|
@@ -253,7 +325,8 @@ public class SchedConfCLI extends Configured implements Tool {
|
|
+ "[-remove \"queueRemovePath1;queueRemovePath2\"] "
|
|
+ "[-remove \"queueRemovePath1;queueRemovePath2\"] "
|
|
+ "[-update \"queueUpdatePath1:confKey1=confVal1\"] "
|
|
+ "[-update \"queueUpdatePath1:confKey1=confVal1\"] "
|
|
+ "[-global globalConfKey1=globalConfVal1,"
|
|
+ "[-global globalConfKey1=globalConfVal1,"
|
|
- + "globalConfKey2=globalConfVal2]\n"
|
|
|
|
|
|
+ + "globalConfKey2=globalConfVal2] "
|
|
|
|
+ + "[-format]\n"
|
|
+ "Example (adding queues): yarn schedulerconf -add "
|
|
+ "Example (adding queues): yarn schedulerconf -add "
|
|
+ "\"root.a.a1:capacity=100,maximum-capacity=100;root.a.a2:capacity=0,"
|
|
+ "\"root.a.a1:capacity=100,maximum-capacity=100;root.a.a2:capacity=0,"
|
|
+ "maximum-capacity=0\"\n"
|
|
+ "maximum-capacity=0\"\n"
|
|
@@ -264,6 +337,8 @@ public class SchedConfCLI extends Configured implements Tool {
|
|
+ "maximum-capacity=75\"\n"
|
|
+ "maximum-capacity=75\"\n"
|
|
+ "Example (global scheduler update): yarn schedulerconf "
|
|
+ "Example (global scheduler update): yarn schedulerconf "
|
|
+ "-global yarn.scheduler.capacity.maximum-applications=10000\n"
|
|
+ "-global yarn.scheduler.capacity.maximum-applications=10000\n"
|
|
|
|
+ + "Example (format scheduler configuration): yarn schedulerconf "
|
|
|
|
+ + "-format\n"
|
|
+ "Note: This is an alpha feature, the syntax/options are subject to "
|
|
+ "Note: This is an alpha feature, the syntax/options are subject to "
|
|
+ "change, please run at your own risk.");
|
|
+ "change, please run at your own risk.");
|
|
}
|
|
}
|