Search in sources :

Example 1 with SparkJob

use of com.thinkbiganalytics.spark.metadata.SparkJob in project kylo by Teradata.

the class TransformService method submitSparkJob.

/**
 * Submits the specified job to be executed.
 */
@Nonnull
public SparkJobResponse submitSparkJob(@Nonnull final Supplier<SparkJobResult> task) {
    log.entry(task);
    // Execute script
    final String id = newTableName();
    final SparkJob job = new SparkJob(id, task, engine.getSparkContext());
    tracker.submitJob(job);
    // Build response
    final SparkJobResponse response = new SparkJobResponse();
    response.setId(id);
    response.setStatus(SparkJobResponse.Status.PENDING);
    return log.exit(response);
}
Also used : SparkJobResponse(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse) SparkJob(com.thinkbiganalytics.spark.metadata.SparkJob) Nonnull(javax.annotation.Nonnull)

Example 2 with SparkJob

use of com.thinkbiganalytics.spark.metadata.SparkJob in project kylo by Teradata.

the class SparkJobController method getJobResult.

@GET
@Path("/{job}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Fetches the status of a job")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the status of the job.", response = SparkJobResponse.class), @ApiResponse(code = 404, message = "The job does not exist.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "There was a problem accessing the data.", response = SparkJobResponse.class) })
public Response getJobResult(@PathParam("job") final String id) {
    try {
        final SparkJob job = transformService.getSparkJob(id);
        final SparkJobResponse response = new SparkJobResponse();
        response.setId(job.getGroupId());
        if (job.isDone()) {
            final SparkJobResult result = job.get();
            response.setResult(result);
            response.setStatus(SparkJobResponse.Status.SUCCESS);
        } else {
            response.setStatus(SparkJobResponse.Status.PENDING);
        }
        return Response.ok(response).build();
    } catch (final IllegalArgumentException e) {
        throw new NotFoundException(getMessage("job.not-found"));
    } catch (final Exception e) {
        throw new InternalServerErrorException(e);
    }
}
Also used : SparkJobResponse(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse) SparkJob(com.thinkbiganalytics.spark.metadata.SparkJob) SparkJobResult(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResult) NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NoSuchMessageException(org.springframework.context.NoSuchMessageException) BadRequestException(javax.ws.rs.BadRequestException) ScriptException(javax.script.ScriptException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

SparkJobResponse (com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse)2 SparkJob (com.thinkbiganalytics.spark.metadata.SparkJob)2 SparkJobResult (com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResult)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Nonnull (javax.annotation.Nonnull)1 ScriptException (javax.script.ScriptException)1 BadRequestException (javax.ws.rs.BadRequestException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 NoSuchMessageException (org.springframework.context.NoSuchMessageException)1