Search in sources :

Example 6 with SaveResponse

use of com.thinkbiganalytics.spark.rest.model.SaveResponse 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);
}
Also used : JdbcDatasource(com.thinkbiganalytics.spark.rest.model.JdbcDatasource) SaveSqlStage(com.thinkbiganalytics.spark.metadata.SaveSqlStage) SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) SaveResult(com.thinkbiganalytics.spark.model.SaveResult) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) Nonnull(javax.annotation.Nonnull)

Example 7 with SaveResponse

use of com.thinkbiganalytics.spark.rest.model.SaveResponse in project kylo by Teradata.

the class TransformService method saveShell.

/**
 * Executes and saves a Spark shell request.
 */
@Nonnull
public SaveResponse saveShell(@Nonnull final String id, @Nonnull final SaveRequest save) throws ScriptException {
    log.entry(id, save);
    final DataSet dataSet = createShellTask(getTransformRequest(id));
    final SaveResponse response = submitSaveJob(createSaveTask(save, new ShellTransformStage(dataSet)));
    return log.exit(response);
}
Also used : DataSet(com.thinkbiganalytics.spark.DataSet) SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) ShellTransformStage(com.thinkbiganalytics.spark.metadata.ShellTransformStage) Nonnull(javax.annotation.Nonnull)

Example 8 with SaveResponse

use of com.thinkbiganalytics.spark.rest.model.SaveResponse in project kylo by Teradata.

the class SparkShellIT method testScriptSave.

/**
 * Verify saving the result of a script.
 */
@Test
public void testScriptSave() {
    final TransformResponse transform = executeScript(SCRIPT, true);
    final String tableName = newTableName();
    final SaveResponse save = saveScript(transform.getTable(), "orc", null, tableName);
    Assert.assertEquals(SaveResponse.Status.SUCCESS, save.getStatus());
    try {
        final List<HashMap<String, String>> table = getHiveQuery("SELECT * FROM " + tableName);
        Assert.assertEquals(ImmutableList.of(ImmutableMap.of("id", 1, "value", "a"), ImmutableMap.of("id", 2, "value", "b"), ImmutableMap.of("id", 3, "value", "c")), table);
    } finally {
        ssh("hive -e \"drop table " + tableName + "\"");
    }
}
Also used : SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) HashMap(java.util.HashMap) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Test(org.junit.Test)

Example 9 with SaveResponse

use of com.thinkbiganalytics.spark.rest.model.SaveResponse in project kylo by Teradata.

the class SparkShellIT method save.

/**
 * Saves the result of a script or query.
 *
 * @param id          the transform or query identifier
 * @param requestPath the URL path to initiate the save
 * @param resultPath  the URL path to get the result
 * @param request     the save request
 * @return the save response
 */
private SaveResponse save(@Nonnull final String id, @Nonnull final String requestPath, @Nonnull final String resultPath, @Nonnull final SaveRequest request) {
    // Execute request
    Response response = given(SparkShellProxyController.BASE).body(request).when().post(requestPath, id);
    SaveResponse save = null;
    Stopwatch timeout = Stopwatch.createStarted();
    do {
        if (save != null) {
            response = given(SparkShellProxyController.BASE).get(resultPath, id, save.getId());
        }
        save = response.as(SaveResponse.class);
        if (save.getStatus() == SaveResponse.Status.PENDING && TIMEOUT - timeout.elapsed(TimeUnit.SECONDS) > 1) {
            waitFor(1, TimeUnit.SECONDS, "for save to finish");
        }
    } while (save.getStatus() == SaveResponse.Status.PENDING && timeout.elapsed(TimeUnit.SECONDS) < TIMEOUT);
    // Verify response
    response.then().statusCode(HTTP_OK);
    return response.as(SaveResponse.class);
}
Also used : Response(com.jayway.restassured.response.Response) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) Stopwatch(com.google.common.base.Stopwatch)

Aggregations

SaveResponse (com.thinkbiganalytics.spark.rest.model.SaveResponse)9 Nonnull (javax.annotation.Nonnull)6 TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)4 MissingResourceException (java.util.MissingResourceException)3 SaveJob (com.thinkbiganalytics.spark.metadata.SaveJob)2 SaveResult (com.thinkbiganalytics.spark.model.SaveResult)2 SparkShellSaveException (com.thinkbiganalytics.spark.shell.SparkShellSaveException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Test (org.junit.Test)2 Stopwatch (com.google.common.base.Stopwatch)1 Response (com.jayway.restassured.response.Response)1 DataSet (com.thinkbiganalytics.spark.DataSet)1 SaveSqlStage (com.thinkbiganalytics.spark.metadata.SaveSqlStage)1 ShellTransformStage (com.thinkbiganalytics.spark.metadata.ShellTransformStage)1 JdbcDatasource (com.thinkbiganalytics.spark.rest.model.JdbcDatasource)1 TransformRequest (com.thinkbiganalytics.spark.rest.model.TransformRequest)1 SparkShellTransformException (com.thinkbiganalytics.spark.shell.SparkShellTransformException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1