@GET @Path("logs/{runner:.*}/{id}") public void getLogs( @PathParam("runner") String runner, @PathParam("id") Long id, @Context HttpServletResponse httpServletResponse) throws Exception { final Runner myRunner = getRunner(runner); final RunnerProcess process = myRunner.getProcess(id); final Throwable error = process.getError(); if (error != null) { final PrintWriter output = httpServletResponse.getWriter(); httpServletResponse.setContentType("text/plain"); if (error instanceof RunnerException) { // expect ot have nice messages from our API output.write(error.getMessage()); } else { error.printStackTrace(output); } output.flush(); } else { final ApplicationLogger logger = process.getLogger(); final PrintWriter output = httpServletResponse.getWriter(); httpServletResponse.setContentType(logger.getContentType()); logger.getLogs(output); output.flush(); } }
@GET @Path("status/{runner:.*}/{id}") @Produces(MediaType.APPLICATION_JSON) public ApplicationProcessDescriptor getStatus( @PathParam("runner") String runner, @PathParam("id") Long id) throws Exception { final Runner myRunner = getRunner(runner); final RunnerProcess process = myRunner.getProcess(id); return getDescriptor(process, getServiceContext()).withRunStats(myRunner.getStats(id)); }
@GET @Path("recipe/{runner:.*}/{id}") public void getRecipeFile( @PathParam("runner") String runner, @PathParam("id") Long id, @Context HttpServletResponse httpServletResponse) throws Exception { final Runner myRunner = getRunner(runner); final RunnerProcess process = myRunner.getProcess(id); final java.io.File recipeFile = process.getConfiguration().getRecipeFile(); if (recipeFile == null) { throw new NotFoundException("Recipe file isn't available. "); } final PrintWriter output = httpServletResponse.getWriter(); httpServletResponse.setContentType("text/plain"); Files.copy(recipeFile, Charset.forName("UTF-8"), output); output.flush(); }