Search in sources :

Example 91 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWebServicesApps method testInvalidApp.

@Test
public void testInvalidApp() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    try {
        r.path("ws").path("v1").path("cluster").path("apps").path("application_invalid_12").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
        fail("should have thrown exception on invalid appid");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject msg = response.getEntity(JSONObject.class);
        JSONObject exception = msg.getJSONObject("RemoteException");
        assertEquals("incorrect number of elements", 3, exception.length());
        String message = exception.getString("message");
        String type = exception.getString("exception");
        String classname = exception.getString("javaClassName");
        WebServicesTestUtils.checkStringMatch("exception message", "java.lang.IllegalArgumentException: Invalid ApplicationId:" + " application_invalid_12", message);
        WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type);
        WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
    } finally {
        rm.stop();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 92 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWebServicesFairScheduler method testClusterSchedulerSlash.

@Test
public void testClusterSchedulerSlash() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifyClusterScheduler(json);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 93 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWebServicesForCSWithPartitions method testSchedulerPartitions.

@Test
public void testSchedulerPartitions() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifySchedulerInfoJson(json);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 94 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWebServicesCapacitySched method testPerUserResourcesXML.

/**
   * Test per user resources and resourcesUsed elements in the web services XML
   * @throws Exception
   */
@Test
public void testPerUserResourcesXML() throws Exception {
    //Start RM so that it accepts app submissions
    rm.start();
    try {
        rm.submitApp(10, "app1", "user1", null, "b1");
        rm.submitApp(20, "app2", "user2", null, "b1");
        //Get the XML from ws/v1/cluster/scheduler
        WebResource r = resource();
        ClientResponse response = r.path("ws/v1/cluster/scheduler").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        String xml = response.getEntity(String.class);
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));
        //Parse the XML we got
        Document dom = db.parse(is);
        //Get all users elements (1 for each leaf queue)
        NodeList allUsers = dom.getElementsByTagName("users");
        for (int i = 0; i < allUsers.getLength(); ++i) {
            Node perUserResources = allUsers.item(i);
            String queueName = getChildNodeByName(perUserResources.getParentNode(), "queueName").getTextContent();
            if (queueName.equals("b1")) {
                //b1 should have two users (user1 and user2) which submitted jobs
                assertEquals(2, perUserResources.getChildNodes().getLength());
                NodeList users = perUserResources.getChildNodes();
                for (int j = 0; j < users.getLength(); ++j) {
                    Node user = users.item(j);
                    String username = getChildNodeByName(user, "username").getTextContent();
                    assertTrue(username.equals("user1") || username.equals("user2"));
                    //Should be a parsable integer
                    Integer.parseInt(getChildNodeByName(getChildNodeByName(user, "resourcesUsed"), "memory").getTextContent());
                    Integer.parseInt(getChildNodeByName(user, "numActiveApplications").getTextContent());
                    Integer.parseInt(getChildNodeByName(user, "numPendingApplications").getTextContent());
                }
            } else {
                //Queues other than b1 should have 0 users
                assertEquals(0, perUserResources.getChildNodes().getLength());
            }
        }
        NodeList allResourcesUsed = dom.getElementsByTagName("resourcesUsed");
        for (int i = 0; i < allResourcesUsed.getLength(); ++i) {
            Node resourcesUsed = allResourcesUsed.item(i);
            Integer.parseInt(getChildNodeByName(resourcesUsed, "memory").getTextContent());
            Integer.parseInt(getChildNodeByName(resourcesUsed, "vCores").getTextContent());
        }
    } finally {
        rm.stop();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) StringReader(java.io.StringReader) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 95 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWebServicesCapacitySched method testClusterSchedulerXML.

@Test
public void testClusterSchedulerXML() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    String xml = response.getEntity(String.class);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList scheduler = dom.getElementsByTagName("scheduler");
    assertEquals("incorrect number of elements", 1, scheduler.getLength());
    NodeList schedulerInfo = dom.getElementsByTagName("schedulerInfo");
    assertEquals("incorrect number of elements", 1, schedulerInfo.getLength());
    verifyClusterSchedulerXML(schedulerInfo);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

WebResource (com.sun.jersey.api.client.WebResource)504 ClientResponse (com.sun.jersey.api.client.ClientResponse)439 Test (org.junit.Test)389 JSONObject (org.codehaus.jettison.json.JSONObject)296 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)110 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)103 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)67 JSONArray (org.codehaus.jettison.json.JSONArray)65 Document (org.w3c.dom.Document)46 StringReader (java.io.StringReader)43 DocumentBuilder (javax.xml.parsers.DocumentBuilder)43 NodeList (org.w3c.dom.NodeList)43 InputSource (org.xml.sax.InputSource)43 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)42 Task (org.apache.hadoop.mapreduce.v2.app.job.Task)42 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)39 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)29 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)22 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)21 Client (com.sun.jersey.api.client.Client)19