Search in sources :

Example 1 with PipelineImpl

use of com.hazelcast.jet.impl.pipeline.PipelineImpl in project hazelcast by hazelcast.

the class OrderedBatchParallelismTest method applyTransformAndGetDag.

private DAG applyTransformAndGetDag(FunctionEx<BatchStage<Long>, BatchStage<Long>> transform) {
    PipelineImpl p = (PipelineImpl) Pipeline.create().setPreserveOrder(true);
    BatchStage<Long> source = p.readFrom(TestSources.items(1L)).setLocalParallelism(UPSTREAM_PARALLELISM);
    BatchStage<Long> applied = source.apply(transform);
    applied.mapStateful(LongAccumulator::new, (s, x) -> x).writeTo(Sinks.noop());
    return p.toDag(PIPELINE_CTX);
}
Also used : PipelineImpl(com.hazelcast.jet.impl.pipeline.PipelineImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Arrays(java.util.Arrays) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Processors(com.hazelcast.jet.core.processor.Processors) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) DAG(com.hazelcast.jet.core.DAG) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) FunctionEx(com.hazelcast.function.FunctionEx) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) Test(org.junit.Test) Traversers(com.hazelcast.jet.Traversers) Category(org.junit.experimental.categories.Category) Vertex(com.hazelcast.jet.core.Vertex) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) Context(com.hazelcast.jet.impl.pipeline.PipelineImpl.Context) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PipelineImpl(com.hazelcast.jet.impl.pipeline.PipelineImpl)

Example 2 with PipelineImpl

use of com.hazelcast.jet.impl.pipeline.PipelineImpl in project hazelcast by hazelcast.

the class JobCoordinationService method submitJob.

public CompletableFuture<Void> submitJob(long jobId, Data serializedJobDefinition, JobConfig jobConfig, Subject subject) {
    CompletableFuture<Void> res = new CompletableFuture<>();
    submitToCoordinatorThread(() -> {
        MasterContext masterContext;
        try {
            assertIsMaster("Cannot submit job " + idToString(jobId) + " to non-master node");
            checkOperationalState();
            // the order of operations is important.
            // first, check if the job is already completed
            JobResult jobResult = jobRepository.getJobResult(jobId);
            if (jobResult != null) {
                logger.fine("Not starting job " + idToString(jobId) + " since already completed with result: " + jobResult);
                return;
            }
            if (!config.isResourceUploadEnabled() && !jobConfig.getResourceConfigs().isEmpty()) {
                throw new JetException(Util.JET_RESOURCE_UPLOAD_DISABLED_MESSAGE);
            }
            int quorumSize = jobConfig.isSplitBrainProtectionEnabled() ? getQuorumSize() : 0;
            Object jobDefinition = deserializeJobDefinition(jobId, jobConfig, serializedJobDefinition);
            DAG dag;
            Data serializedDag;
            if (jobDefinition instanceof PipelineImpl) {
                int coopThreadCount = config.getCooperativeThreadCount();
                dag = ((PipelineImpl) jobDefinition).toDag(new Context() {

                    @Override
                    public int defaultLocalParallelism() {
                        return coopThreadCount;
                    }
                });
                serializedDag = nodeEngine().getSerializationService().toData(dag);
            } else {
                dag = (DAG) jobDefinition;
                serializedDag = serializedJobDefinition;
            }
            checkPermissions(subject, dag);
            Set<String> ownedObservables = ownedObservables(dag);
            JobRecord jobRecord = new JobRecord(nodeEngine.getClusterService().getClusterVersion(), jobId, serializedDag, dagToJson(dag), jobConfig, ownedObservables, subject);
            JobExecutionRecord jobExecutionRecord = new JobExecutionRecord(jobId, quorumSize);
            masterContext = createMasterContext(jobRecord, jobExecutionRecord);
            boolean hasDuplicateJobName;
            synchronized (lock) {
                assertIsMaster("Cannot submit job " + idToString(jobId) + " to non-master node");
                checkOperationalState();
                hasDuplicateJobName = jobConfig.getName() != null && hasActiveJobWithName(jobConfig.getName());
                if (!hasDuplicateJobName) {
                    // just try to initiate the coordination
                    MasterContext prev = masterContexts.putIfAbsent(jobId, masterContext);
                    if (prev != null) {
                        logger.fine("Joining to already existing masterContext " + prev.jobIdString());
                        return;
                    }
                }
            }
            if (hasDuplicateJobName) {
                jobRepository.deleteJob(jobId);
                throw new JobAlreadyExistsException("Another active job with equal name (" + jobConfig.getName() + ") exists: " + idToString(jobId));
            }
            // If job is not currently running, it might be that it is just completed
            if (completeMasterContextIfJobAlreadyCompleted(masterContext)) {
                return;
            }
            // If there is no master context and job result at the same time, it means this is the first submission
            jobSubmitted.inc();
            jobRepository.putNewJobRecord(jobRecord);
            logger.info("Starting job " + idToString(masterContext.jobId()) + " based on submit request");
        } catch (Throwable e) {
            jetServiceBackend.getJobClassLoaderService().tryRemoveClassloadersForJob(jobId, COORDINATOR);
            res.completeExceptionally(e);
            throw e;
        } finally {
            res.complete(null);
        }
        tryStartJob(masterContext);
    });
    return res;
}
Also used : SecurityContext(com.hazelcast.security.SecurityContext) Context(com.hazelcast.jet.impl.pipeline.PipelineImpl.Context) PipelineImpl(com.hazelcast.jet.impl.pipeline.PipelineImpl) JobAlreadyExistsException(com.hazelcast.jet.JobAlreadyExistsException) Data(com.hazelcast.internal.serialization.Data) JetException(com.hazelcast.jet.JetException) DAG(com.hazelcast.jet.core.DAG) Util.idToString(com.hazelcast.jet.Util.idToString) CompletableFuture(java.util.concurrent.CompletableFuture) WrappedThrowable(com.hazelcast.jet.impl.observer.WrappedThrowable)

Example 3 with PipelineImpl

use of com.hazelcast.jet.impl.pipeline.PipelineImpl in project hazelcast by hazelcast.

the class OrderedStreamParallelismTest method applyTransformAndGetDag.

private DAG applyTransformAndGetDag(FunctionEx<StreamStage<Integer>, StreamStage<Integer>> transform) {
    PipelineImpl p = (PipelineImpl) Pipeline.create().setPreserveOrder(true);
    StreamStage<Integer> source = p.readFrom(TestSources.items(1)).setLocalParallelism(UPSTREAM_PARALLELISM).addTimestamps(t -> 0, Long.MAX_VALUE);
    StreamStage<Integer> applied = source.apply(transform);
    applied.mapStateful(LongAccumulator::new, (s, x) -> x).writeTo(Sinks.noop());
    return p.toDag(PIPELINE_CTX);
}
Also used : PipelineImpl(com.hazelcast.jet.impl.pipeline.PipelineImpl) FunctionEx(com.hazelcast.function.FunctionEx) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) QuickTest(com.hazelcast.test.annotation.QuickTest) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Test(org.junit.Test) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) Traversers(com.hazelcast.jet.Traversers) Category(org.junit.experimental.categories.Category) Vertex(com.hazelcast.jet.core.Vertex) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) DAG(com.hazelcast.jet.core.DAG) Context(com.hazelcast.jet.impl.pipeline.PipelineImpl.Context) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) PipelineImpl(com.hazelcast.jet.impl.pipeline.PipelineImpl)

Aggregations

DAG (com.hazelcast.jet.core.DAG)3 PipelineImpl (com.hazelcast.jet.impl.pipeline.PipelineImpl)3 Context (com.hazelcast.jet.impl.pipeline.PipelineImpl.Context)3 FunctionEx (com.hazelcast.function.FunctionEx)2 Traversers (com.hazelcast.jet.Traversers)2 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)2 Vertex (com.hazelcast.jet.core.Vertex)2 TestSources (com.hazelcast.jet.pipeline.test.TestSources)2 HazelcastParametrizedRunner (com.hazelcast.test.HazelcastParametrizedRunner)2 HazelcastSerialParametersRunnerFactory (com.hazelcast.test.HazelcastSerialParametersRunnerFactory)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Test (org.junit.Test)2 Category (org.junit.experimental.categories.Category)2 RunWith (org.junit.runner.RunWith)2