use of com.thinkbiganalytics.spark.metadata.SaveJob in project kylo by Teradata.
the class AbstractTransformController method getSave.
/**
* Requests the status of a save.
*
* @param id the save id
* @return the save status
*/
@GET
@Path("{table}/save/{save}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Fetches the status of a save")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the status of the save.", response = SaveResponse.class), @ApiResponse(code = 404, message = "The transformation or save does not exist.", response = SaveResponse.class), @ApiResponse(code = 500, message = "There was a problem accessing the data.", response = SaveResponse.class) })
@Nonnull
public Response getSave(@Nonnull @PathParam("save") final String id) {
try {
final SaveJob job = transformService.getSaveJob(id, false);
final SaveResponse response = new SaveResponse();
if (job.isDone()) {
response.setId(job.getGroupId());
response.setStatus(SaveResponse.Status.SUCCESS);
final SaveResult result = job.get();
if (result.getPath() != null) {
response.setLocation("./zip");
} else {
transformService.getSaveJob(id, true);
}
} else {
response.setId(job.getGroupId());
response.setProgress(job.progress());
response.setStatus(SaveResponse.Status.PENDING);
}
return Response.ok(response).build();
} catch (final IllegalArgumentException e) {
return error(Response.Status.NOT_FOUND, "getSave.notFound");
} catch (final Exception e) {
final SaveResponse save = new SaveResponse();
save.setId(id);
save.setMessage(e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName());
save.setStatus(SaveResponse.Status.ERROR);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(save).build();
}
}
use of com.thinkbiganalytics.spark.metadata.SaveJob in project kylo by Teradata.
the class TransformService method submitSaveJob.
/**
* Submits the specified task for saving a transformation and returns the result.
*/
@Nonnull
private SaveResponse submitSaveJob(@Nonnull final Supplier<SaveResult> task) {
log.entry(task);
// Execute script
final String table = newTableName();
final SaveJob job = new SaveJob(table, task, engine.getSparkContext());
tracker.submitJob(job);
// Build response
final SaveResponse response = new SaveResponse();
response.setId(table);
response.setProgress(0.0);
response.setStatus(SaveResponse.Status.PENDING);
return log.exit(response);
}
use of com.thinkbiganalytics.spark.metadata.SaveJob in project kylo by Teradata.
the class AbstractTransformController method download.
/**
* Downloads the saved results as a ZIP file.
*
* @param id the save id
* @return the zip file response
*/
@GET
@Path("{table}/save/{save}/zip")
@ApiOperation("Downloads the saved results in a ZIP file")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the saved file."), @ApiResponse(code = 404, message = "The save does not exist."), @ApiResponse(code = 500, message = "There was a problem accessing the data.") })
@Nonnull
public Response download(@Nonnull @PathParam("save") final String id) {
// Find job
SaveJob job;
try {
job = transformService.getSaveJob(id, true);
} catch (final IllegalArgumentException e) {
job = null;
}
// Get result
final SaveResult result;
if (job != null && job.isDone()) {
try {
result = job.get();
} catch (final Exception e) {
return error(Response.Status.INTERNAL_SERVER_ERROR, e);
}
} else {
result = null;
}
// Return response
if (result != null && result.getPath() != null) {
return Response.ok(new ZipStreamingOutput(result.getPath(), fileSystem)).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + id + ".zip\"").build();
} else {
return error(Response.Status.NOT_FOUND, "download.notFound");
}
}
Aggregations