Skip to content

Commit

Permalink
YARN-8973. [Router] Add missing methods in RMWebProtocol. (#4664)
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 authored Aug 2, 2022
1 parent 57da4bb commit 1f0a71a
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceOptionInfo;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.BulkActivitiesInfo;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo;
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;

/**
* <p>
Expand Down Expand Up @@ -745,4 +746,31 @@ RMQueueAclInfo checkUserAccessToQueue(String queue, String username,
*/
Response signalToContainer(String containerId, String command,
HttpServletRequest req) throws AuthorizationException;

/**
* This method updates the Scheduler configuration, and it is reachable by
* using {@link RMWSConsts#SCHEDULER_CONF}.
*
* @param mutationInfo th information for making scheduler configuration
* changes (supports adding, removing, or updating a queue, as well
* as global scheduler conf changes)
* @param hsr the servlet request
* @return Response containing the status code
* @throws AuthorizationException if the user is not authorized to invoke this
* method
* @throws InterruptedException if interrupted
*/
Response updateSchedulerConfiguration(SchedConfUpdateInfo mutationInfo,
HttpServletRequest hsr) throws AuthorizationException, InterruptedException;

/**
* This method retrieves all the Scheduler configuration, and it is reachable
* by using {@link RMWSConsts#SCHEDULER_CONF}.
*
* @param hsr the servlet request
* @return Response containing the status code
* @throws AuthorizationException if the user is not authorized to invoke this
* method.
*/
Response getSchedulerConfiguration(HttpServletRequest hsr) throws AuthorizationException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;

/**
Expand Down Expand Up @@ -565,6 +566,25 @@ public ContainerInfo getContainer(HttpServletRequest req,
null, null, getConf(), client);
}

@Override
public Response updateSchedulerConfiguration(SchedConfUpdateInfo mutationInfo,
HttpServletRequest req)
throws AuthorizationException, InterruptedException {
return RouterWebServiceUtil.genericForward(webAppAddress, req,
Response.class, HTTPMethods.PUT,
RMWSConsts.RM_WEB_SERVICE_PATH + RMWSConsts.SCHEDULER_CONF,
mutationInfo, null, getConf(), client);
}

@Override
public Response getSchedulerConfiguration(HttpServletRequest req)
throws AuthorizationException {
return RouterWebServiceUtil.genericForward(webAppAddress, req,
Response.class, HTTPMethods.GET,
RMWSConsts.RM_WEB_SERVICE_PATH + RMWSConsts.SCHEDULER_CONF,
null, null, getConf(), client);
}

@Override
public void setNextInterceptor(RESTRequestInterceptor next) {
throw new YarnRuntimeException("setNextInterceptor is being called on "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;
import org.apache.hadoop.yarn.util.Clock;
import org.apache.hadoop.yarn.util.MonotonicClock;
import org.apache.hadoop.yarn.webapp.NotFoundException;
Expand Down Expand Up @@ -1417,6 +1418,19 @@ public ContainerInfo getContainer(HttpServletRequest req,
throw new NotImplementedException("Code is not implemented");
}

@Override
public Response updateSchedulerConfiguration(SchedConfUpdateInfo mutationInfo,
HttpServletRequest hsr)
throws AuthorizationException, InterruptedException {
throw new NotImplementedException("Code is not implemented");
}

@Override
public Response getSchedulerConfiguration(HttpServletRequest hsr)
throws AuthorizationException {
throw new NotImplementedException("Code is not implemented");
}

@Override
public void setNextInterceptor(RESTRequestInterceptor next) {
throw new YarnRuntimeException("setNextInterceptor is being called on "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
import org.apache.hadoop.yarn.util.LRUCacheHashMap;
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -956,6 +957,33 @@ public ContainerInfo getContainer(@Context HttpServletRequest req,
appAttemptId, containerId);
}

@PUT
@Path(RMWSConsts.SCHEDULER_CONF)
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Override
public Response updateSchedulerConfiguration(SchedConfUpdateInfo mutationInfo,
HttpServletRequest hsr)
throws AuthorizationException, InterruptedException {
init();
RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
return pipeline.getRootInterceptor()
.updateSchedulerConfiguration(mutationInfo, hsr);
}

@GET
@Path(RMWSConsts.SCHEDULER_CONF)
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Override
public Response getSchedulerConfiguration(HttpServletRequest hsr)
throws AuthorizationException {
init();
RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
return pipeline.getRootInterceptor().getSchedulerConfiguration(hsr);
}

@VisibleForTesting
protected void setResponse(HttpServletResponse response) {
this.response = response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,16 @@ private HttpServletRequest createHttpServletRequest(String user) {
when(request.getRemoteUser()).thenReturn(user);
return request;
}

protected Response updateSchedulerConfiguration(String user)
throws IOException, InterruptedException {
return routerWebService.updateSchedulerConfiguration(null,
createHttpServletRequest(user));
}

protected Response getSchedulerConfiguration(String user)
throws IOException, InterruptedException {
return routerWebService.
getSchedulerConfiguration(createHttpServletRequest(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;

/**
* This class mocks the RESTRequestInterceptor.
Expand Down Expand Up @@ -373,4 +374,16 @@ public Response signalToContainer(String containerId, String command,
HttpServletRequest req) {
return Response.status(Status.OK).build();
}

@Override
public Response updateSchedulerConfiguration(SchedConfUpdateInfo mutationInfo,
HttpServletRequest hsr) throws AuthorizationException, InterruptedException {
return Response.status(Status.OK).build();
}

@Override
public Response getSchedulerConfiguration(HttpServletRequest hsr)
throws AuthorizationException {
return Response.status(Status.OK).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo;

/**
* Mock interceptor that does not do anything other than forwarding it to the
Expand Down Expand Up @@ -379,4 +380,17 @@ public Response signalToContainer(String containerId,
String command, HttpServletRequest req) throws AuthorizationException {
return getNextInterceptor().signalToContainer(containerId, command, req);
}

@Override
public Response updateSchedulerConfiguration(SchedConfUpdateInfo mutationInfo,
HttpServletRequest hsr)
throws AuthorizationException, InterruptedException {
return getNextInterceptor().updateSchedulerConfiguration(mutationInfo, hsr);
}

@Override
public Response getSchedulerConfiguration(HttpServletRequest hsr)
throws AuthorizationException {
return getNextInterceptor().getSchedulerConfiguration(hsr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ public void testRouterWebServicesE2E() throws Exception {

ContainerInfo containerInfo = getContainer(user);
Assert.assertNotNull(containerInfo);

Response response19 = updateSchedulerConfiguration(user);
Assert.assertNotNull(response19);

Response response20 = getSchedulerConfiguration(user);
Assert.assertNotNull(response20);
}

/**
Expand Down

0 comments on commit 1f0a71a

Please sign in to comment.