Search in sources :

Example 1 with SparkJobResponse

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

the class BatchJobSupplierTest method testPending.

/**
 * Verify handling <i>PENDING</i> responses.
 */
@Test
public void testPending() {
    // Mock rest client
    Mockito.when(restClient.createJob(process, request)).thenReturn(PENDING_RESPONSE);
    Mockito.when(restClient.getJobResult(process, PENDING_RESPONSE.getId())).thenReturn(Optional.of(PENDING_RESPONSE)).thenReturn(Optional.of(SUCCESS_RESPONSE));
    // Test success response
    final MockBatchJob job = new MockBatchJob();
    job.setPollInterval(200, TimeUnit.MILLISECONDS);
    final SparkJobResponse response = job.get();
    Assert.assertEquals(SUCCESS_RESPONSE, response);
    Assert.assertEquals(400, sleepMillis.get());
}
Also used : SparkJobResponse(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse) Test(org.junit.Test)

Example 2 with SparkJobResponse

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

the class BatchJobSupplierTest method testSuccess.

/**
 * Verify handling <i>SUCCESS</i> responses.
 */
@Test
public void testSuccess() {
    // Mock rest client
    Mockito.when(restClient.createJob(process, request)).thenReturn(SUCCESS_RESPONSE);
    // Test success response
    final SparkJobResponse response = new MockBatchJob().get();
    Assert.assertEquals(SUCCESS_RESPONSE, response);
    Assert.assertEquals(0, sleepMillis.get());
}
Also used : SparkJobResponse(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse) Test(org.junit.Test)

Example 3 with SparkJobResponse

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

the class BatchJobSupplierTest method testError.

/**
 * Verify handling <i>ERROR</i> responses.
 */
@Test
public void testError() {
    // Mock rest client
    Mockito.when(restClient.createJob(process, request)).thenReturn(ERROR_RESPONSE);
    // Test success response
    final SparkJobResponse response = new MockBatchJob().get();
    Assert.assertEquals(ERROR_RESPONSE, response);
    Assert.assertEquals(0, sleepMillis.get());
}
Also used : SparkJobResponse(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse) Test(org.junit.Test)

Example 4 with SparkJobResponse

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

the class DefaultSparkJobContextTest method testSuccess.

/**
 * Verify handling of a <i>SUCCESS</i> response.
 */
@Test
public void testSuccess() {
    // Mock response
    final SparkJobResponse response = new SparkJobResponse();
    response.setId("mock-job");
    response.setResult(new SparkJobResult());
    response.setStatus(SparkJobResponse.Status.SUCCESS);
    // Test first subscriber
    final DefaultSparkJobContext context = DefaultSparkJobContext.create(() -> response, cache, executor);
    Assert.assertNotNull(take(context));
    // Test second subscriber
    Assert.assertEquals(response.getResult(), take(context).getResult());
}
Also used : SparkJobResponse(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse) SparkJobResult(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResult) Test(org.junit.Test)

Example 5 with SparkJobResponse

use of com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse 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)

Aggregations

SparkJobResponse (com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse)12 Nonnull (javax.annotation.Nonnull)6 SparkJobResult (com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResult)4 Test (org.junit.Test)4 Statement (com.thinkbiganalytics.kylo.spark.model.Statement)2 JerseyRestClient (com.thinkbiganalytics.rest.JerseyRestClient)2 SparkJob (com.thinkbiganalytics.spark.metadata.SparkJob)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SparkException (com.thinkbiganalytics.kylo.spark.SparkException)1 ChainableSupplier (com.thinkbiganalytics.kylo.spark.job.tasks.ChainableSupplier)1 JobStatusFunction (com.thinkbiganalytics.kylo.spark.job.tasks.JobStatusFunction)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 NoSuchElementException (java.util.NoSuchElementException)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Nullable (javax.annotation.Nullable)1 ScriptException (javax.script.ScriptException)1