Search in sources :

Example 21 with WebResource

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

the class TestAMWebServices method testInfo.

@Test
public void testInfo() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("mapreduce").path("info").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    verifyAMInfo(json.getJSONObject("info"), appContext);
}
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 22 with WebResource

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

the class TestAMWebServices method testAMXML.

@Test
public void testAMXML() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("mapreduce").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8, response.getType().toString());
    String xml = response.getEntity(String.class);
    verifyAMInfoXML(xml, appContext);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 23 with WebResource

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

the class TestAMWebServices method testInvalidAccept.

@Test
public void testInvalidAccept() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
        responseStr = r.path("ws").path("v1").path("mapreduce").accept(MediaType.TEXT_PLAIN).get(String.class);
        fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.INTERNAL_SERVER_ERROR, response.getStatusInfo());
        WebServicesTestUtils.checkStringMatch("error string exists and shouldn't", "", responseStr);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 24 with WebResource

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

the class TestAMWebServicesAttempt method testGetTaskAttemptIdState.

@Test
public void testGetTaskAttemptIdState() throws Exception {
    WebResource r = resource();
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    for (JobId id : jobsMap.keySet()) {
        String jobId = MRApps.toString(id);
        for (Task task : jobsMap.get(id).getTasks().values()) {
            String tid = MRApps.toString(task.getID());
            for (TaskAttempt att : task.getAttempts().values()) {
                TaskAttemptId attemptid = att.getID();
                String attid = MRApps.toString(attemptid);
                ClientResponse response = r.path("ws").path("v1").path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid).path("attempts").path(attid).path("state").queryParam("user.name", webserviceUserName).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
                assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
                JSONObject json = response.getEntity(JSONObject.class);
                assertEquals("incorrect number of elements", 1, json.length());
                assertEquals(att.getState().toString(), json.get("state"));
            }
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Task(org.apache.hadoop.mapreduce.v2.app.job.Task) JSONObject(org.codehaus.jettison.json.JSONObject) TaskAttemptId(org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId) WebResource(com.sun.jersey.api.client.WebResource) TaskAttempt(org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) Test(org.junit.Test)

Example 25 with WebResource

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

the class TestAMWebServicesAttempts method testTaskAttemptIdXML.

@Test
public void testTaskAttemptIdXML() throws JSONException, Exception {
    WebResource r = resource();
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    for (JobId id : jobsMap.keySet()) {
        String jobId = MRApps.toString(id);
        for (Task task : jobsMap.get(id).getTasks().values()) {
            String tid = MRApps.toString(task.getID());
            for (TaskAttempt att : task.getAttempts().values()) {
                TaskAttemptId attemptid = att.getID();
                String attid = MRApps.toString(attemptid);
                ClientResponse response = r.path("ws").path("v1").path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid).path("attempts").path(attid).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 nodes = dom.getElementsByTagName("taskAttempt");
                for (int i = 0; i < nodes.getLength(); i++) {
                    Element element = (Element) nodes.item(i);
                    verifyAMTaskAttemptXML(element, att, task.getType());
                }
            }
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Task(org.apache.hadoop.mapreduce.v2.app.job.Task) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TaskAttemptId(org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) TaskAttempt(org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) 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