@Test public void testRegisterScript() throws Exception { PigResource resource= new PigResource(); String str= "STORE E into '$output' using PigStorage(',');"; InputStream input= new ByteArrayInputStream(str.getBytes("UTF-8")); Response resp= resource.registerScript("script.pig", input); Assert.assertEquals(resp.getStatus(), 200); input= new ByteArrayInputStream(str.getBytes("UTF-8")); try { resp= resource.registerScript("script.pig", input); } catch (Exception e) { Assert.assertNotNull(e); } str= "DUMP E"; input= new ByteArrayInputStream(str.getBytes("UTF-8")); resp= resource.registerScript("script1.pig", input); Assert.assertEquals(resp.getStatus(), 400); }
@POST @Path("/script/{scriptName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) public Response registerScript(@PathParam("scriptName") String scriptName, InputStream uploadedScript) throws IOException { logger.info("Request for registering script " + scriptName); if (uploadedScript == null || uploadedScript.available() == 0){ logger.error("Empty input stream passed"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad request. No script uploaded!") .build(); } StringWriter writer = new StringWriter(); IOUtils.copy(uploadedScript, writer, "UTF-8"); String script= writer.toString(); if (PigScriptValidator.validatePigScript(script)) { InputStream stream= new ByteArrayInputStream(script.getBytes()); String pathName= PropertyLoader.getInstance().getProperty(Constants.SCRIPTS_PATH) + scriptName; PigJobServerImpl.getPigJobServer().registerFile(pathName, stream); return Response.ok().entity(pathName).build(); } logger.info("Script " + scriptName + " is not valid"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad Request. Either DUMP command is used or STORE is used without '$output'") .build(); }
PigResource { @POST @Path("/script/{scriptName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) public Response registerScript(@PathParam("scriptName") String scriptName, InputStream uploadedScript) throws IOException { logger.info("Request for registering script " + scriptName); if (uploadedScript == null || uploadedScript.available() == 0){ logger.error("Empty input stream passed"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad request. No script uploaded!") .build(); } StringWriter writer = new StringWriter(); IOUtils.copy(uploadedScript, writer, "UTF-8"); String script= writer.toString(); if (PigScriptValidator.validatePigScript(script)) { InputStream stream= new ByteArrayInputStream(script.getBytes()); String pathName= PropertyLoader.getInstance().getProperty(Constants.SCRIPTS_PATH) + scriptName; PigJobServerImpl.getPigJobServer().registerFile(pathName, stream); return Response.ok().entity(pathName).build(); } logger.info("Script " + scriptName + " is not valid"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad Request. Either DUMP command is used or STORE is used without '$output'") .build(); } }
PigResource { @POST @Path("/script/{scriptName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) public Response registerScript(@PathParam("scriptName") String scriptName, InputStream uploadedScript) throws IOException { logger.info("Request for registering script " + scriptName); if (uploadedScript == null || uploadedScript.available() == 0){ logger.error("Empty input stream passed"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad request. No script uploaded!") .build(); } StringWriter writer = new StringWriter(); IOUtils.copy(uploadedScript, writer, "UTF-8"); String script= writer.toString(); if (PigScriptValidator.validatePigScript(script)) { InputStream stream= new ByteArrayInputStream(script.getBytes()); String pathName= PropertyLoader.getInstance().getProperty(Constants.SCRIPTS_PATH) + scriptName; PigJobServerImpl.getPigJobServer().registerFile(pathName, stream); return Response.ok().entity(pathName).build(); } logger.info("Script " + scriptName + " is not valid"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad Request. Either DUMP command is used or STORE is used without '$output'") .build(); }  }
PigResource { @POST @Path("/script/{scriptName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) public Response registerScript(@PathParam("scriptName") String scriptName, InputStream uploadedScript) throws IOException { logger.info("Request for registering script " + scriptName); if (uploadedScript == null || uploadedScript.available() == 0){ logger.error("Empty input stream passed"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad request. No script uploaded!") .build(); } StringWriter writer = new StringWriter(); IOUtils.copy(uploadedScript, writer, "UTF-8"); String script= writer.toString(); if (PigScriptValidator.validatePigScript(script)) { InputStream stream= new ByteArrayInputStream(script.getBytes()); String pathName= PropertyLoader.getInstance().getProperty(Constants.SCRIPTS_PATH) + scriptName; PigJobServerImpl.getPigJobServer().registerFile(pathName, stream); return Response.ok().entity(pathName).build(); } logger.info("Script " + scriptName + " is not valid"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad Request. Either DUMP command is used or STORE is used without '$output'") .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); }
PigResource { @POST @Path("/script/{scriptName}") @Consumes ( {MediaType.APPLICATION_OCTET_STREAM} ) @Produces ({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) public Response registerScript(@PathParam("scriptName") String scriptName, InputStream uploadedScript) throws IOException { logger.info("Request for registering script " + scriptName); if (uploadedScript == null || uploadedScript.available() == 0){ logger.error("Empty input stream passed"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad request. No script uploaded!") .build(); } StringWriter writer = new StringWriter(); IOUtils.copy(uploadedScript, writer, "UTF-8"); String script= writer.toString(); if (PigScriptValidator.validatePigScript(script)) { InputStream stream= new ByteArrayInputStream(script.getBytes()); String pathName= PropertyLoader.getInstance().getProperty(Constants.SCRIPTS_PATH) + scriptName; PigJobServerImpl.getPigJobServer().registerFile(pathName, stream); return Response.ok().entity(pathName).build(); } logger.info("Script " + scriptName + " is not valid"); return Response .status(HttpURLConnection.HTTP_BAD_REQUEST) .entity("Bad Request. Either DUMP command is used or STORE is used without '$output'") .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);  }