use of com.thinkbiganalytics.spark.model.SaveResult 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.model.SaveResult in project kylo by Teradata.
the class SaveDataSetStage method apply.
@Nonnull
@Override
public SaveResult apply(@Nullable final TransformResult transform) {
Preconditions.checkNotNull(transform);
// Configure writer
final DataFrameWriter writer = getDataSet(transform).write();
if (request.getFormat() != null) {
writer.format(request.getFormat());
}
if (request.getMode() != null) {
writer.mode(request.getMode());
}
if (request.getOptions() != null) {
writer.options(request.getOptions());
}
// Save transformation
final SaveResult result = new SaveResult();
if (request.getJdbc() != null) {
final Properties properties = new Properties();
properties.setProperty("driver", request.getJdbc().getDatabaseDriverClassName());
properties.setProperty("user", request.getJdbc().getDatabaseUser());
properties.setProperty("password", request.getJdbc().getPassword());
writer.jdbc(request.getJdbc().getDatabaseConnectionUrl(), request.getTableName(), properties);
} else if (request.getTableName() != null) {
writer.saveAsTable(request.getTableName());
} else {
final String hadoopTmpDir = fs.getConf().get("hadoop.tmp.dir", "/tmp");
final Path absolutePath = new Path(hadoopTmpDir, UUID.randomUUID().toString());
final Path qualifiedPath = fs.makeQualified(absolutePath);
result.setPath(qualifiedPath);
writer.save(qualifiedPath.toString());
}
return result;
}
use of com.thinkbiganalytics.spark.model.SaveResult 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");
}
}
use of com.thinkbiganalytics.spark.model.SaveResult in project kylo by Teradata.
the class TransformService method saveSql.
/**
* Executes and saves a Spark SQL request.
*/
@Nonnull
public SaveResponse saveSql(@Nonnull final String id, @Nonnull final SaveRequest save) {
log.entry(id, save);
// Create task
final Supplier<SaveResult> task;
final TransformRequest transform = getTransformRequest(id);
final JdbcDatasource transformDatasource = (transform.getDatasources() != null && transform.getDatasources().size() == 1 && transform.getDatasources().get(0) instanceof JdbcDatasource) ? (JdbcDatasource) transform.getDatasources().get(0) : null;
if (transformDatasource != null && save.getJdbc() != null && Objects.equal(transformDatasource.getId(), save.getJdbc().getId())) {
Preconditions.checkArgument(save.getTableName() != null, "Missing target table name.");
task = new SaveSqlStage(save.getTableName(), transform.getScript(), save.getJdbc());
} else {
task = createSaveTask(save, createSqlTask(transform));
}
// Submit job
final SaveResponse response = submitSaveJob(task);
return log.exit(response);
}
Aggregations