Search in sources :

Example 1 with AppPriority

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority in project hadoop by apache.

the class RMWebServices method updateApplicationPriority.

@PUT
@Path("/apps/{appid}/priority")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateApplicationPriority(AppPriority targetPriority, @Context HttpServletRequest hsr, @PathParam("appid") String appId) throws AuthorizationException, YarnException, InterruptedException, IOException {
    init();
    if (targetPriority == null) {
        throw new YarnException("Target Priority cannot be null");
    }
    UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
    if (callerUGI == null) {
        throw new AuthorizationException("Unable to obtain user name, user not authenticated");
    }
    if (UserGroupInformation.isSecurityEnabled() && isStaticUser(callerUGI)) {
        return Response.status(Status.FORBIDDEN).entity("The default static user cannot carry out this operation.").build();
    }
    String userName = callerUGI.getUserName();
    RMApp app = null;
    try {
        app = getRMAppForAppId(appId);
    } catch (NotFoundException e) {
        RMAuditLogger.logFailure(userName, AuditConstants.UPDATE_APP_PRIORITY, "UNKNOWN", "RMWebService", "Trying to update priority an absent application " + appId);
        throw e;
    }
    Priority priority = app.getApplicationPriority();
    if (priority == null || priority.getPriority() != targetPriority.getPriority()) {
        return modifyApplicationPriority(app, callerUGI, targetPriority.getPriority());
    }
    return Response.status(Status.OK).entity(targetPriority).build();
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) Priority(org.apache.hadoop.yarn.api.records.Priority) AppPriority(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 2 with AppPriority

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority in project hadoop by apache.

the class RMWebServices method modifyApplicationPriority.

private Response modifyApplicationPriority(final RMApp app, UserGroupInformation callerUGI, final int appPriority) throws IOException, InterruptedException {
    String userName = callerUGI.getUserName();
    try {
        callerUGI.doAs(new PrivilegedExceptionAction<Void>() {

            @Override
            public Void run() throws IOException, YarnException {
                Priority priority = Priority.newInstance(appPriority);
                UpdateApplicationPriorityRequest request = UpdateApplicationPriorityRequest.newInstance(app.getApplicationId(), priority);
                rm.getClientRMService().updateApplicationPriority(request);
                return null;
            }
        });
    } catch (UndeclaredThrowableException ue) {
        // bubble that up to the user
        if (ue.getCause() instanceof YarnException) {
            YarnException ye = (YarnException) ue.getCause();
            if (ye.getCause() instanceof AccessControlException) {
                String appId = app.getApplicationId().toString();
                String msg = "Unauthorized attempt to change priority of appid " + appId + " by remote user " + userName;
                return Response.status(Status.FORBIDDEN).entity(msg).build();
            } else if (ye.getMessage().startsWith("Application in") && ye.getMessage().endsWith("state cannot be update priority.")) {
                return Response.status(Status.BAD_REQUEST).entity(ye.getMessage()).build();
            } else {
                throw ue;
            }
        } else {
            throw ue;
        }
    }
    AppPriority ret = new AppPriority(app.getApplicationPriority().getPriority());
    return Response.status(Status.OK).entity(ret).build();
}
Also used : AppPriority(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority) Priority(org.apache.hadoop.yarn.api.records.Priority) AppPriority(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) UpdateApplicationPriorityRequest(org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationPriorityRequest) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 3 with AppPriority

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority in project hadoop by apache.

the class RMWebServices method getAppPriority.

@GET
@Path("/apps/{appid}/priority")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppPriority getAppPriority(@Context HttpServletRequest hsr, @PathParam("appid") String appId) throws AuthorizationException {
    init();
    UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
    String userName = "UNKNOWN-USER";
    if (callerUGI != null) {
        userName = callerUGI.getUserName();
    }
    RMApp app = null;
    try {
        app = getRMAppForAppId(appId);
    } catch (NotFoundException e) {
        RMAuditLogger.logFailure(userName, AuditConstants.GET_APP_PRIORITY, "UNKNOWN", "RMWebService", "Trying to get priority of an absent application " + appId);
        throw e;
    }
    AppPriority ret = new AppPriority();
    ret.setPriority(app.getApplicationPriority().getPriority());
    return ret;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) AppPriority(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with AppPriority

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority in project hadoop by apache.

the class TestRMWebServicesAppsModification method testUpdateAppPriority.

@Test(timeout = 90000)
public void testUpdateAppPriority() throws Exception {
    client().addFilter(new LoggingFilter(System.out));
    if (!(rm.getResourceScheduler() instanceof CapacityScheduler)) {
        // till the fair scheduler modifications for priority is completed
        return;
    }
    CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
    Configuration conf = new Configuration();
    conf.setInt(YarnConfiguration.MAX_CLUSTER_LEVEL_APPLICATION_PRIORITY, 10);
    cs.setClusterMaxPriority(conf);
    // default root queue allows anyone to have admin acl
    CapacitySchedulerConfiguration csconf = new CapacitySchedulerConfiguration();
    String[] queues = { "default", "test" };
    csconf.setQueues("root", queues);
    csconf.setCapacity("root.default", 50.0f);
    csconf.setCapacity("root.test", 50.0f);
    csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
    csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser");
    csconf.setAcl("root.test", QueueACL.ADMINISTER_QUEUE, "someuser");
    rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext());
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
    MediaType[] contentTypes = { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE };
    for (String mediaType : mediaTypes) {
        for (MediaType contentType : contentTypes) {
            RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
            amNodeManager.nodeHeartbeat(true);
            int modifiedPriority = 8;
            AppPriority priority = new AppPriority(modifiedPriority);
            Object entity;
            if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
                entity = appPriorityToJSON(priority);
            } else {
                entity = priority;
            }
            ClientResponse response = this.constructWebResource("apps", app.getApplicationId().toString(), "priority").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            if (!isAuthenticationEnabled()) {
                assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
                continue;
            }
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppPriorityJson(response, modifiedPriority);
            } else {
                verifyAppPriorityXML(response, modifiedPriority);
            }
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "priority").accept(mediaType).get(ClientResponse.class);
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppPriorityJson(response, modifiedPriority);
            } else {
                verifyAppPriorityXML(response, modifiedPriority);
            }
            // check unauthorized
            app = rm.submitApp(CONTAINER_MB, "", "someuser");
            amNodeManager.nodeHeartbeat(true);
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "priority").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
        }
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) AppPriority(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) FairSchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration) JSONConfiguration(com.sun.jersey.api.json.JSONConfiguration) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) MediaType(javax.ws.rs.core.MediaType) JSONObject(org.codehaus.jettison.json.JSONObject) CapacityScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Test(org.junit.Test)

Aggregations

AppPriority (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority)4 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)3 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 Priority (org.apache.hadoop.yarn.api.records.Priority)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)1 JSONConfiguration (com.sun.jersey.api.json.JSONConfiguration)1 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AccessControlException (java.security.AccessControlException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 MediaType (javax.ws.rs.core.MediaType)1 Configuration (org.apache.hadoop.conf.Configuration)1 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)1