Search in sources :

Example 1 with SaveJob

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();
    }
}
Also used : SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) SaveJob(com.thinkbiganalytics.spark.metadata.SaveJob) SaveResult(com.thinkbiganalytics.spark.model.SaveResult) MissingResourceException(java.util.MissingResourceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Nonnull(javax.annotation.Nonnull) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with SaveJob

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);
}
Also used : SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) SaveJob(com.thinkbiganalytics.spark.metadata.SaveJob) Nonnull(javax.annotation.Nonnull)

Example 3 with SaveJob

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");
    }
}
Also used : ZipStreamingOutput(com.thinkbiganalytics.spark.io.ZipStreamingOutput) SaveJob(com.thinkbiganalytics.spark.metadata.SaveJob) SaveResult(com.thinkbiganalytics.spark.model.SaveResult) MissingResourceException(java.util.MissingResourceException) Path(javax.ws.rs.Path) Nonnull(javax.annotation.Nonnull) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

SaveJob (com.thinkbiganalytics.spark.metadata.SaveJob)3 Nonnull (javax.annotation.Nonnull)3 SaveResult (com.thinkbiganalytics.spark.model.SaveResult)2 SaveResponse (com.thinkbiganalytics.spark.rest.model.SaveResponse)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 MissingResourceException (java.util.MissingResourceException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ZipStreamingOutput (com.thinkbiganalytics.spark.io.ZipStreamingOutput)1 Produces (javax.ws.rs.Produces)1