Search in sources :

Example 1 with MockHistoryContext

use of org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext in project hadoop by apache.

the class TestHsWebServicesJobs method testJobCountersForKilledJob.

@Test
public void testJobCountersForKilledJob() throws Exception {
    WebResource r = resource();
    appContext = new MockHistoryContext(0, 1, 1, 1, true);
    GuiceServletConfig.setInjector(Guice.createInjector(new ServletModule() {

        @Override
        protected void configureServlets() {
            webApp = mock(HsWebApp.class);
            when(webApp.name()).thenReturn("hsmockwebapp");
            bind(JAXBContextResolver.class);
            bind(HsWebServices.class);
            bind(GenericExceptionHandler.class);
            bind(WebApp.class).toInstance(webApp);
            bind(AppContext.class).toInstance(appContext);
            bind(HistoryContext.class).toInstance(appContext);
            bind(Configuration.class).toInstance(conf);
            serve("/*").with(GuiceContainer.class);
        }
    }));
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    for (JobId id : jobsMap.keySet()) {
        String jobId = MRApps.toString(id);
        ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").path(jobId).path("counters/").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());
        JSONObject info = json.getJSONObject("jobCounters");
        WebServicesTestUtils.checkStringMatch("id", MRApps.toString(id), info.getString("id"));
        assertTrue("Job shouldn't contain any counters", info.length() == 1);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Configuration(org.apache.hadoop.conf.Configuration) MockHistoryContext(org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext) AppContext(org.apache.hadoop.mapreduce.v2.app.AppContext) MockHistoryContext(org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext) HistoryContext(org.apache.hadoop.mapreduce.v2.hs.HistoryContext) WebResource(com.sun.jersey.api.client.WebResource) ServletModule(com.google.inject.servlet.ServletModule) JSONObject(org.codehaus.jettison.json.JSONObject) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) WebApp(org.apache.hadoop.yarn.webapp.WebApp) Test(org.junit.Test)

Example 2 with MockHistoryContext

use of org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext in project hadoop by apache.

the class TestHsWebServicesJobs method verifyHsJobPartialXML.

public void verifyHsJobPartialXML(NodeList nodes, MockHistoryContext appContext) {
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        Job job = appContext.getPartialJob(MRApps.toJobID(WebServicesTestUtils.getXmlString(element, "id")));
        assertNotNull("Job not found - output incorrect", job);
        VerifyJobsUtils.verifyHsJobGeneric(job, WebServicesTestUtils.getXmlString(element, "id"), WebServicesTestUtils.getXmlString(element, "user"), WebServicesTestUtils.getXmlString(element, "name"), WebServicesTestUtils.getXmlString(element, "state"), WebServicesTestUtils.getXmlString(element, "queue"), WebServicesTestUtils.getXmlLong(element, "startTime"), WebServicesTestUtils.getXmlLong(element, "finishTime"), WebServicesTestUtils.getXmlInt(element, "mapsTotal"), WebServicesTestUtils.getXmlInt(element, "mapsCompleted"), WebServicesTestUtils.getXmlInt(element, "reducesTotal"), WebServicesTestUtils.getXmlInt(element, "reducesCompleted"));
    }
}
Also used : Element(org.w3c.dom.Element) Job(org.apache.hadoop.mapreduce.v2.app.job.Job)

Example 3 with MockHistoryContext

use of org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext in project hadoop by apache.

the class TestHsWebServicesAcls method buildHistoryContext.

private static HistoryContext buildHistoryContext(final Configuration conf) throws IOException {
    HistoryContext ctx = new MockHistoryContext(1, 1, 1);
    Map<JobId, Job> jobs = ctx.getAllJobs();
    JobId jobId = jobs.keySet().iterator().next();
    Job mockJob = new MockJobForAcls(jobs.get(jobId), conf);
    jobs.put(jobId, mockJob);
    return ctx;
}
Also used : MockHistoryContext(org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext) HistoryContext(org.apache.hadoop.mapreduce.v2.hs.HistoryContext) MockHistoryContext(org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId)

Aggregations

Job (org.apache.hadoop.mapreduce.v2.app.job.Job)3 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)2 HistoryContext (org.apache.hadoop.mapreduce.v2.hs.HistoryContext)2 MockHistoryContext (org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext)2 ServletModule (com.google.inject.servlet.ServletModule)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 Configuration (org.apache.hadoop.conf.Configuration)1 AppContext (org.apache.hadoop.mapreduce.v2.app.AppContext)1 WebApp (org.apache.hadoop.yarn.webapp.WebApp)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1