Skip to content

Commit a9a5830

Browse files
YARN-11048. Add tests that shows how to delete config values with Mutation API (#3799). Contributed by Szilard Nemeth
1 parent bdec546 commit a9a5830

File tree

5 files changed

+301
-67
lines changed

5 files changed

+301
-67
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/ParentQueue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void setChildQueues(Collection<CSQueue> childQueues) throws IOException {
344344
if (Math.abs(childrenPctSum) > PRECISION) {
345345
// It is wrong when percent sum != {0, 1}
346346
throw new IOException(
347-
"Illegal" + " capacity sum of " + childrenPctSum
347+
"Illegal capacity sum of " + childrenPctSum
348348
+ " for children of queue " + getQueueName() + " for label="
349349
+ nodeLabel + ". It should be either 0 or 1.0");
350350
} else{
@@ -357,7 +357,7 @@ void setChildQueues(Collection<CSQueue> childQueues) throws IOException {
357357
if ((Math.abs(queueCapacities.getCapacity(nodeLabel))
358358
> PRECISION) && (!allowZeroCapacitySum)) {
359359
throw new IOException(
360-
"Illegal" + " capacity sum of " + childrenPctSum
360+
"Illegal capacity sum of " + childrenPctSum
361361
+ " for children of queue " + getQueueName()
362362
+ " for label=" + nodeLabel
363363
+ ". It is set to 0, but parent percent != 0, and "
@@ -372,7 +372,7 @@ void setChildQueues(Collection<CSQueue> childQueues) throws IOException {
372372
queueCapacities.getCapacity(nodeLabel)) <= 0f
373373
&& !allowZeroCapacitySum) {
374374
throw new IOException(
375-
"Illegal" + " capacity sum of " + childrenPctSum
375+
"Illegal capacity sum of " + childrenPctSum
376376
+ " for children of queue " + getQueueName() + " for label="
377377
+ nodeLabel + ". queue=" + getQueueName()
378378
+ " has zero capacity, but child"

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueuePath.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ public QueuePath(String fullPath) {
6161
}
6262

6363
/**
64-
* Concatenate queue path parts into one queue path string.
65-
* @param parts Parts of the full queue pathAutoCreatedQueueTemplate
66-
* @return full path of the given queue parts
64+
* Constructor to create Queue path from queue names.
65+
* The provided queue names will be concatenated by dots, giving a full queue path.
66+
* @param parts Parts of queue path
67+
* @return QueuePath object
6768
*/
68-
public static String concatenatePath(String... parts) {
69-
return String.join(DOT, parts);
69+
public static QueuePath createFromQueues(String... parts) {
70+
return new QueuePath(String.join(DOT, parts));
7071
}
7172

7273
/**

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,8 +2656,7 @@ public Response formatSchedulerConfiguration(@Context HttpServletRequest hsr)
26562656
initForWritableEndpoints(callerUGI, true);
26572657

26582658
ResourceScheduler scheduler = rm.getResourceScheduler();
2659-
if (scheduler instanceof MutableConfScheduler
2660-
&& ((MutableConfScheduler) scheduler).isConfigurationMutable()) {
2659+
if (isConfigurationMutable(scheduler)) {
26612660
try {
26622661
MutableConfigurationProvider mutableConfigurationProvider =
26632662
((MutableConfScheduler) scheduler).getMutableConfProvider();
@@ -2696,8 +2695,7 @@ public synchronized Response validateAndGetSchedulerConfiguration(
26962695
UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
26972696
initForWritableEndpoints(callerUGI, true);
26982697
ResourceScheduler scheduler = rm.getResourceScheduler();
2699-
if (scheduler instanceof MutableConfScheduler && ((MutableConfScheduler)
2700-
scheduler).isConfigurationMutable()) {
2698+
if (isConfigurationMutable(scheduler)) {
27012699
try {
27022700
MutableConfigurationProvider mutableConfigurationProvider =
27032701
((MutableConfScheduler) scheduler).getMutableConfProvider();
@@ -2746,51 +2744,61 @@ public synchronized Response validateAndGetSchedulerConfiguration(
27462744
public synchronized Response updateSchedulerConfiguration(SchedConfUpdateInfo
27472745
mutationInfo, @Context HttpServletRequest hsr)
27482746
throws AuthorizationException, InterruptedException {
2749-
27502747
UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
27512748
initForWritableEndpoints(callerUGI, true);
27522749

27532750
ResourceScheduler scheduler = rm.getResourceScheduler();
2754-
if (scheduler instanceof MutableConfScheduler && ((MutableConfScheduler)
2755-
scheduler).isConfigurationMutable()) {
2751+
if (isConfigurationMutable(scheduler)) {
27562752
try {
2757-
callerUGI.doAs(new PrivilegedExceptionAction<Void>() {
2758-
@Override
2759-
public Void run() throws Exception {
2760-
MutableConfigurationProvider provider = ((MutableConfScheduler)
2761-
scheduler).getMutableConfProvider();
2762-
if (!provider.getAclMutationPolicy().isMutationAllowed(callerUGI,
2763-
mutationInfo)) {
2764-
throw new org.apache.hadoop.security.AccessControlException("User"
2765-
+ " is not admin of all modified queues.");
2766-
}
2767-
LogMutation logMutation = provider.logAndApplyMutation(callerUGI,
2768-
mutationInfo);
2769-
try {
2770-
rm.getRMContext().getRMAdminService().refreshQueues();
2771-
} catch (IOException | YarnException e) {
2772-
provider.confirmPendingMutation(logMutation, false);
2773-
throw e;
2774-
}
2775-
provider.confirmPendingMutation(logMutation, true);
2776-
return null;
2777-
}
2753+
callerUGI.doAs((PrivilegedExceptionAction<Void>) () -> {
2754+
MutableConfigurationProvider provider = ((MutableConfScheduler)
2755+
scheduler).getMutableConfProvider();
2756+
LogMutation logMutation = applyMutation(provider, callerUGI, mutationInfo);
2757+
return refreshQueues(provider, logMutation);
27782758
});
27792759
} catch (IOException e) {
27802760
LOG.error("Exception thrown when modifying configuration.", e);
27812761
return Response.status(Status.BAD_REQUEST).entity(e.getMessage())
27822762
.build();
27832763
}
2784-
return Response.status(Status.OK).entity("Configuration change " +
2785-
"successfully applied.").build();
2764+
return Response.status(Status.OK).entity("Configuration change successfully applied.")
2765+
.build();
27862766
} else {
27872767
return Response.status(Status.BAD_REQUEST)
2788-
.entity("Configuration change only supported by " +
2789-
"MutableConfScheduler.")
2768+
.entity(String.format("Configuration change only supported by " +
2769+
"%s.", MutableConfScheduler.class.getSimpleName()))
27902770
.build();
27912771
}
27922772
}
27932773

2774+
private Void refreshQueues(MutableConfigurationProvider provider, LogMutation logMutation)
2775+
throws Exception {
2776+
try {
2777+
rm.getRMContext().getRMAdminService().refreshQueues();
2778+
} catch (IOException | YarnException e) {
2779+
provider.confirmPendingMutation(logMutation, false);
2780+
throw e;
2781+
}
2782+
provider.confirmPendingMutation(logMutation, true);
2783+
return null;
2784+
}
2785+
2786+
private LogMutation applyMutation(MutableConfigurationProvider provider,
2787+
UserGroupInformation callerUGI, SchedConfUpdateInfo mutationInfo) throws Exception {
2788+
if (!provider.getAclMutationPolicy().isMutationAllowed(callerUGI,
2789+
mutationInfo)) {
2790+
throw new org.apache.hadoop.security.AccessControlException("User"
2791+
+ " is not admin of all modified queues.");
2792+
}
2793+
return provider.logAndApplyMutation(callerUGI,
2794+
mutationInfo);
2795+
}
2796+
2797+
private boolean isConfigurationMutable(ResourceScheduler scheduler) {
2798+
return scheduler instanceof MutableConfScheduler && ((MutableConfScheduler)
2799+
scheduler).isConfigurationMutable();
2800+
}
2801+
27942802
@GET
27952803
@Path(RMWSConsts.SCHEDULER_CONF)
27962804
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
@@ -2803,8 +2811,7 @@ public Response getSchedulerConfiguration(@Context HttpServletRequest hsr)
28032811
initForWritableEndpoints(callerUGI, true);
28042812

28052813
ResourceScheduler scheduler = rm.getResourceScheduler();
2806-
if (scheduler instanceof MutableConfScheduler
2807-
&& ((MutableConfScheduler) scheduler).isConfigurationMutable()) {
2814+
if (isConfigurationMutable(scheduler)) {
28082815
MutableConfigurationProvider mutableConfigurationProvider =
28092816
((MutableConfScheduler) scheduler).getMutableConfProvider();
28102817
// We load the cached configuration from configuration store,
@@ -2835,8 +2842,7 @@ public Response getSchedulerConfigurationVersion(@Context
28352842
initForWritableEndpoints(callerUGI, true);
28362843

28372844
ResourceScheduler scheduler = rm.getResourceScheduler();
2838-
if (scheduler instanceof MutableConfScheduler
2839-
&& ((MutableConfScheduler) scheduler).isConfigurationMutable()) {
2845+
if (isConfigurationMutable(scheduler)) {
28402846
MutableConfigurationProvider mutableConfigurationProvider =
28412847
((MutableConfScheduler) scheduler).getMutableConfProvider();
28422848

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,4 +1098,4 @@ private RMWebServices prepareWebServiceForValidation(
10981098
return webService;
10991099
}
11001100

1101-
}
1101+
}

0 commit comments

Comments
 (0)