PigResource { @GET @Path("/request/{requestId}/stats") @Produces( {MediaType.APPLICATION_JSON} ) public Response getRequestStats(@PathParam("requestId") String requestId) throws IOException { logger.info("Request for getting stats for request " + requestId); PigRequestStats stats = PigJobServerImpl .getPigJobServer() .getRequestStats(requestId); return Response.ok() .entity(new Gson().toJson(stats, PigRequestStats.class)) .build(); }  @POST @Path("/jar/{jarName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) Response registerJar(@PathParam("jarName") String jarName, InputStream uploadedJar); @DELETE @Path("/jar/{jarName}") @Produces ( {MediaType.TEXT_PLAIN} ) Response unregisterJar(@PathParam("jarName") String jarName); @GET @Path("/jar/{jarName}") @Produces ( {MediaType.APPLICATION_OCTET_STREAM} ) Response getRegisteredJar(@PathParam("jarName") String jarName); @POST @Path("/script/{scriptName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) Response registerScript(@PathParam("scriptName") String scriptName, InputStream uploadedScript); @DELETE @Path("/script/{scriptName}") @Produces ( {MediaType.TEXT_PLAIN} ) Response unregisterScript(@PathParam("scriptName") String scriptName); @GET @Path("/script/{scriptName}") @Produces ( {MediaType.APPLICATION_OCTET_STREAM} ) Response getRegisteredScript(@PathParam("scriptName") String scriptName); @POST @Path("/request/{scriptName}") @Consumes( {MediaType.APPLICATION_JSON} ) @Produces( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN} ) Response submitPigJob(@PathParam("scriptName") String scriptName, String data); @GET @Path("/request/{requestId}") @Produces( {MediaType.APPLICATION_JSON} ) Response getInput(@PathParam("requestId") String requestId); @GET @Path("/request/{requestId}/stats") @Produces( {MediaType.APPLICATION_JSON} ) Response getRequestStats(@PathParam("requestId") String requestId); @GET @Path("/request/{requestId}/output") @Produces( {MediaType.TEXT_PLAIN} ) Response getOutput(@PathParam("requestId") String requestId); @GET @Path("request/{requestId}/status") @Produces( {MediaType.TEXT_PLAIN} ) Response getRequestStatus(@PathParam("requestId") String requestId); @GET @Path("request/{requestId}/cancel") @Produces( {MediaType.TEXT_PLAIN} ) Response cancelRequest(@PathParam("requestId") String requestId);  }
@Test public void testGetStats() throws Exception { PigResource resource= new PigResource(); PigRequestStats stats= new PigRequestStats(15, 14, null, 5); stats.setStatus("STATUS"); String requestId= UUID.randomUUID().toString(); String path= PropertyLoader.getInstance().getProperty("requests.basepath") + requestId + "/stats"; PigUtils.writeStatsFile(new Path(path), stats); Response resp= resource.getRequestStats(requestId); Assert.assertEquals(resp.getStatus(), 200); requestId= "abc"; try { resp= resource.getRequestStats(requestId); } catch (Exception e) { Assert.assertNotNull(resp); } requestId= UUID.randomUUID().toString(); fileSystem.mkdirs(new Path(PropertyLoader.getInstance().getProperty("requests.basepath") + requestId)); try { resp= resource.getRequestStats(requestId); } catch (Exception e) { Assert.assertNotNull(e); } }