Search in sources :

Example 26 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class PythonService method destroy.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
void destroy() {
    // Stopping the Python subprocess is essential, lower the interrupted flag
    boolean interrupted = Thread.interrupted();
    try {
        sink.onCompleted();
        if (!completionLatch.await(1, SECONDS)) {
            logger.info("gRPC call has not completed on time");
        }
        GrpcUtil.shutdownChannel(chan, logger, 1);
        server.stop();
    } catch (Exception e) {
        throw new JetException("PythonService.destroy() failed: " + e, e);
    } finally {
        if (interrupted) {
            currentThread().interrupt();
        }
    }
}
Also used : JetException(com.hazelcast.jet.JetException) JetException(com.hazelcast.jet.JetException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 27 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class KinesisIntegrationTest method customProjection.

@Test
@Category(SerialTest.class)
public void customProjection() {
    HELPER.createStream(1);
    sendMessages();
    Long expectedPerSequenceNo = 1L;
    try {
        Pipeline pipeline = Pipeline.create();
        StreamSource<String> source = kinesisSource().withProjectionFn((r, s) -> {
            byte[] payload = new byte[r.getData().remaining()];
            r.getData().get(payload);
            return r.getSequenceNumber();
        }).build();
        pipeline.readFrom(source).withoutTimestamps().groupingKey(r -> r).rollingAggregate(counting()).apply(assertCollectedEventually(ASSERT_TRUE_EVENTUALLY_TIMEOUT, results -> {
            assertEquals(MESSAGES, results.size());
            results.forEach(v -> assertEquals(expectedPerSequenceNo, v.getValue()));
        }));
        hz().getJet().newJob(pipeline).join();
        fail("Expected exception not thrown");
    } catch (CompletionException ce) {
        Throwable cause = peel(ce);
        assertTrue(cause instanceof JetException);
        assertTrue(cause.getCause() instanceof AssertionCompletedException);
    }
}
Also used : Shard(com.amazonaws.services.kinesis.model.Shard) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) BeforeClass(org.junit.BeforeClass) AT_SEQUENCE_NUMBER(com.amazonaws.services.kinesis.model.ShardIteratorType.AT_SEQUENCE_NUMBER) JobProxy(com.hazelcast.jet.impl.JobProxy) StreamSource(com.hazelcast.jet.pipeline.StreamSource) SDKGlobalConfiguration(com.amazonaws.SDKGlobalConfiguration) AmazonKinesisAsync(com.amazonaws.services.kinesis.AmazonKinesisAsync) JetException(com.hazelcast.jet.JetException) PutRecordsResult(com.amazonaws.services.kinesis.model.PutRecordsResult) Map(java.util.Map) AwsConfig(com.hazelcast.jet.kinesis.impl.AwsConfig) AT_TIMESTAMP(com.amazonaws.services.kinesis.model.ShardIteratorType.AT_TIMESTAMP) Assert.fail(org.junit.Assert.fail) JobStatus(com.hazelcast.jet.core.JobStatus) Tuple2(com.hazelcast.jet.datamodel.Tuple2) Job(com.hazelcast.jet.Job) Service(org.testcontainers.containers.localstack.LocalStackContainer.Service) TRIM_HORIZON(com.amazonaws.services.kinesis.model.ShardIteratorType.TRIM_HORIZON) DockerImageName.parse(org.testcontainers.utility.DockerImageName.parse) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) Logger(com.hazelcast.logging.Logger) LATEST(com.amazonaws.services.kinesis.model.ShardIteratorType.LATEST) NightlyTest(com.hazelcast.test.annotation.NightlyTest) AfterClass(org.junit.AfterClass) Assertions.assertCollectedEventually(com.hazelcast.jet.pipeline.test.Assertions.assertCollectedEventually) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) Category(org.junit.experimental.categories.Category) LocalStackContainer(org.testcontainers.containers.localstack.LocalStackContainer) Collectors(java.util.stream.Collectors) List(java.util.List) AFTER_SEQUENCE_NUMBER(com.amazonaws.services.kinesis.model.ShardIteratorType.AFTER_SEQUENCE_NUMBER) Ignore(org.junit.Ignore) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) ExceptionUtil.peel(com.hazelcast.jet.impl.util.ExceptionUtil.peel) Assert.assertFalse(org.junit.Assert.assertFalse) SerialTest(com.hazelcast.jet.test.SerialTest) DockerClientFactory(org.testcontainers.DockerClientFactory) Assume.assumeTrue(org.junit.Assume.assumeTrue) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) CompletionException(java.util.concurrent.CompletionException) JetException(com.hazelcast.jet.JetException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Category(org.junit.experimental.categories.Category) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) SerialTest(com.hazelcast.jet.test.SerialTest)

Example 28 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class KinesisIntegrationTest method timestampsAndWatermarks.

@Test
@Category(SerialTest.class)
public void timestampsAndWatermarks() {
    HELPER.createStream(1);
    sendMessages();
    try {
        Pipeline pipeline = Pipeline.create();
        pipeline.readFrom(kinesisSource().build()).withNativeTimestamps(0).window(WindowDefinition.sliding(500, 100)).aggregate(counting()).apply(assertCollectedEventually(ASSERT_TRUE_EVENTUALLY_TIMEOUT, windowResults -> {
            // multiple windows, so watermark works
            assertTrue(windowResults.size() > 1);
        }));
        hz().getJet().newJob(pipeline).join();
        fail("Expected exception not thrown");
    } catch (CompletionException ce) {
        Throwable cause = peel(ce);
        assertTrue(cause instanceof JetException);
        assertTrue(cause.getCause() instanceof AssertionCompletedException);
    }
}
Also used : Shard(com.amazonaws.services.kinesis.model.Shard) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) BeforeClass(org.junit.BeforeClass) AT_SEQUENCE_NUMBER(com.amazonaws.services.kinesis.model.ShardIteratorType.AT_SEQUENCE_NUMBER) JobProxy(com.hazelcast.jet.impl.JobProxy) StreamSource(com.hazelcast.jet.pipeline.StreamSource) SDKGlobalConfiguration(com.amazonaws.SDKGlobalConfiguration) AmazonKinesisAsync(com.amazonaws.services.kinesis.AmazonKinesisAsync) JetException(com.hazelcast.jet.JetException) PutRecordsResult(com.amazonaws.services.kinesis.model.PutRecordsResult) Map(java.util.Map) AwsConfig(com.hazelcast.jet.kinesis.impl.AwsConfig) AT_TIMESTAMP(com.amazonaws.services.kinesis.model.ShardIteratorType.AT_TIMESTAMP) Assert.fail(org.junit.Assert.fail) JobStatus(com.hazelcast.jet.core.JobStatus) Tuple2(com.hazelcast.jet.datamodel.Tuple2) Job(com.hazelcast.jet.Job) Service(org.testcontainers.containers.localstack.LocalStackContainer.Service) TRIM_HORIZON(com.amazonaws.services.kinesis.model.ShardIteratorType.TRIM_HORIZON) DockerImageName.parse(org.testcontainers.utility.DockerImageName.parse) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) Logger(com.hazelcast.logging.Logger) LATEST(com.amazonaws.services.kinesis.model.ShardIteratorType.LATEST) NightlyTest(com.hazelcast.test.annotation.NightlyTest) AfterClass(org.junit.AfterClass) Assertions.assertCollectedEventually(com.hazelcast.jet.pipeline.test.Assertions.assertCollectedEventually) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) Category(org.junit.experimental.categories.Category) LocalStackContainer(org.testcontainers.containers.localstack.LocalStackContainer) Collectors(java.util.stream.Collectors) List(java.util.List) AFTER_SEQUENCE_NUMBER(com.amazonaws.services.kinesis.model.ShardIteratorType.AFTER_SEQUENCE_NUMBER) Ignore(org.junit.Ignore) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) ExceptionUtil.peel(com.hazelcast.jet.impl.util.ExceptionUtil.peel) Assert.assertFalse(org.junit.Assert.assertFalse) SerialTest(com.hazelcast.jet.test.SerialTest) DockerClientFactory(org.testcontainers.DockerClientFactory) Assume.assumeTrue(org.junit.Assume.assumeTrue) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) CompletionException(java.util.concurrent.CompletionException) JetException(com.hazelcast.jet.JetException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Category(org.junit.experimental.categories.Category) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) SerialTest(com.hazelcast.jet.test.SerialTest)

Example 29 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class KinesisTestHelper method wait.

private void wait(int attempt, String action) {
    if (attempt > RETRY_STRATEGY.getMaxAttempts()) {
        throw new JetException(String.format("Abort waiting for %s, too many attempts", action));
    }
    logger.info(String.format("Waiting for %s ...", action));
    long duration = RETRY_STRATEGY.getIntervalFunction().waitAfterAttempt(attempt);
    try {
        TimeUnit.MILLISECONDS.sleep(duration);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new JetException(String.format("Waiting for %s interrupted", action));
    }
}
Also used : JetException(com.hazelcast.jet.JetException)

Example 30 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class JobCoordinationService method submitLightJob.

public CompletableFuture<Void> submitLightJob(long jobId, Data serializedJobDefinition, JobConfig jobConfig, Subject subject) {
    Object jobDefinition = nodeEngine().getSerializationService().toObject(serializedJobDefinition);
    DAG dag;
    if (jobDefinition instanceof DAG) {
        dag = (DAG) jobDefinition;
    } else {
        int coopThreadCount = config.getCooperativeThreadCount();
        dag = ((PipelineImpl) jobDefinition).toDag(new Context() {

            @Override
            public int defaultLocalParallelism() {
                return coopThreadCount;
            }
        });
    }
    // First insert just a marker into the map. This is to prevent initializing the light job if the jobId
    // was submitted twice. This can happen e.g. if the client retries.
    Object oldContext = lightMasterContexts.putIfAbsent(jobId, UNINITIALIZED_LIGHT_JOB_MARKER);
    if (oldContext != null) {
        throw new JetException("duplicate jobId " + idToString(jobId));
    }
    checkPermissions(subject, dag);
    // Initialize and start the job (happens in the constructor). We do this before adding the actual
    // LightMasterContext to the map to avoid possible races of the job initialization and cancellation.
    LightMasterContext mc = new LightMasterContext(nodeEngine, this, dag, jobId, jobConfig, subject);
    oldContext = lightMasterContexts.put(jobId, mc);
    assert oldContext == UNINITIALIZED_LIGHT_JOB_MARKER;
    scheduleJobTimeout(jobId, jobConfig.getTimeoutMillis());
    return mc.getCompletionFuture().whenComplete((r, t) -> {
        Object removed = lightMasterContexts.remove(jobId);
        assert removed instanceof LightMasterContext : "LMC not found: " + removed;
        unscheduleJobTimeout(jobId);
    });
}
Also used : SecurityContext(com.hazelcast.security.SecurityContext) Context(com.hazelcast.jet.impl.pipeline.PipelineImpl.Context) DAG(com.hazelcast.jet.core.DAG) JetException(com.hazelcast.jet.JetException)

Aggregations

JetException (com.hazelcast.jet.JetException)52 IOException (java.io.IOException)8 Nonnull (javax.annotation.Nonnull)8 ILogger (com.hazelcast.logging.ILogger)7 List (java.util.List)7 Map (java.util.Map)6 Util.idToString (com.hazelcast.jet.Util.idToString)5 JobConfig (com.hazelcast.jet.config.JobConfig)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 BroadcastKey (com.hazelcast.jet.core.BroadcastKey)4 JobStatus (com.hazelcast.jet.core.JobStatus)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Job (com.hazelcast.jet.Job)3 DAG (com.hazelcast.jet.core.DAG)3 Watermark (com.hazelcast.jet.core.Watermark)3 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3