Search in sources :

Example 91 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class WordCountTest method testJetTwoPhaseAggregation.

@Test
@Ignore
public void testJetTwoPhaseAggregation() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", SourceProcessors.readMapP("words"));
    Vertex mapReduce = dag.newVertex("map-reduce", MapReduceP::new);
    Vertex combineLocal = dag.newVertex("combine-local", CombineP::new);
    Vertex combineGlobal = dag.newVertex("combine-global", CombineP::new);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("counts"));
    dag.edge(between(source, mapReduce)).edge(between(mapReduce, combineLocal)).edge(between(combineLocal, combineGlobal).distributed().allToOne("ALL")).edge(between(combineGlobal, sink));
    benchmark("jet", () -> instance.getJet().newJob(dag).join());
    assertCounts((Map<String, Long>) instance.getMap("counts").get("result"));
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) DAG(com.hazelcast.jet.core.DAG) Ignore(org.junit.Ignore) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 92 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class BackpressureTest method testBackpressure.

@Test
public void testBackpressure() {
    DAG dag = new DAG();
    final int member1Port = hz1.getCluster().getLocalMember().getAddress().getPort();
    final Member member2 = hz2.getCluster().getLocalMember();
    final int ptionOwnedByMember2 = hz1.getPartitionService().getPartitions().stream().filter(p -> p.getOwner().equals(member2)).map(Partition::getPartitionId).findAny().orElseThrow(() -> new RuntimeException("Can't find a partition owned by member " + hz2));
    Vertex source = dag.newVertex("source", ProcessorMetaSupplier.of((Address address) -> ProcessorSupplier.of(address.getPort() == member1Port ? GenerateP::new : noopP())));
    Vertex hiccup = dag.newVertex("hiccup", HiccupP::new);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("counts"));
    dag.edge(between(source, hiccup).distributed().partitioned(wholeItem(), (x, y) -> ptionOwnedByMember2)).edge(between(hiccup, sink));
    hz1.getJet().newJob(dag).join();
    assertCounts(hz1.getMap("counts"));
}
Also used : Address(com.hazelcast.cluster.Address) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) Member(com.hazelcast.cluster.Member) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) Partition(com.hazelcast.partition.Partition) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Traversers.lazy(com.hazelcast.jet.Traversers.lazy) Traversers.traverseIterable(com.hazelcast.jet.Traversers.traverseIterable) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DAG(com.hazelcast.jet.core.DAG) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Before(org.junit.Before) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) Assert.assertNotNull(org.junit.Assert.assertNotNull) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test) Math.min(java.lang.Math.min) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Category(org.junit.experimental.categories.Category) Vertex(com.hazelcast.jet.core.Vertex) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) Entry(java.util.Map.Entry) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) Partition(com.hazelcast.partition.Partition) Vertex(com.hazelcast.jet.core.Vertex) Address(com.hazelcast.cluster.Address) DAG(com.hazelcast.jet.core.DAG) Member(com.hazelcast.cluster.Member) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 93 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class FileSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table0, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projections, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    if (eventTimePolicyProvider != null) {
        throw QueryException.error("Ordering functions are not supported on top of " + TYPE_NAME + " mappings");
    }
    FileTable table = (FileTable) table0;
    Vertex vStart = dag.newUniqueVertex(table.toString(), table.processorMetaSupplier());
    Vertex vEnd = dag.newUniqueVertex("Project(" + table + ")", SqlProcessors.rowProjector(table.paths(), table.types(), table.queryTargetSupplier(), predicate, projections));
    dag.edge(between(vStart, vEnd).isolated());
    return vEnd;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Nonnull(javax.annotation.Nonnull)

Example 94 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class MasterJobContext method rewriteDagWithSnapshotRestore.

private void rewriteDagWithSnapshotRestore(DAG dag, long snapshotId, String mapName, String snapshotName) {
    IMap<Object, Object> snapshotMap = mc.nodeEngine().getHazelcastInstance().getMap(mapName);
    long resolvedSnapshotId = validateSnapshot(snapshotId, snapshotMap, mc.jobIdString(), snapshotName);
    logger.info(String.format("About to restore the state of %s from snapshot %d, mapName = %s", mc.jobIdString(), resolvedSnapshotId, mapName));
    List<Vertex> originalVertices = new ArrayList<>();
    dag.iterator().forEachRemaining(originalVertices::add);
    Map<String, Integer> vertexToOrdinal = new HashMap<>();
    Vertex readSnapshotVertex = dag.newVertex(SNAPSHOT_VERTEX_PREFIX + "read", readMapP(mapName));
    Vertex explodeVertex = dag.newVertex(SNAPSHOT_VERTEX_PREFIX + "explode", () -> new ExplodeSnapshotP(vertexToOrdinal, resolvedSnapshotId));
    dag.edge(between(readSnapshotVertex, explodeVertex).isolated());
    int index = 0;
    // add the edges
    for (Vertex userVertex : originalVertices) {
        vertexToOrdinal.put(userVertex.getName(), index);
        int destOrdinal = dag.getInboundEdges(userVertex.getName()).size();
        dag.edge(new SnapshotRestoreEdge(explodeVertex, index, userVertex, destOrdinal));
        index++;
    }
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Util.idToString(com.hazelcast.jet.Util.idToString)

Example 95 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class LightMasterContext method finalizeJob.

private void finalizeJob(@Nullable Throwable failure) {
    // close ProcessorMetaSuppliers
    for (Vertex vertex : vertices) {
        try {
            vertex.getMetaSupplier().close(failure);
        } catch (Throwable e) {
            logger.severe(jobIdString + " encountered an exception in ProcessorMetaSupplier.complete(), ignoring it", e);
        }
    }
    if (failure == null) {
        jobCompletionFuture.complete(null);
    } else {
        // translate JobTerminateRequestedException(CANCEL_FORCEFUL) to CancellationException
        if (failure instanceof JobTerminateRequestedException && ((JobTerminateRequestedException) failure).mode() == CANCEL_FORCEFUL) {
            CancellationException newFailure = new CancellationException();
            newFailure.initCause(failure);
            failure = newFailure;
        }
        jobCompletionFuture.completeExceptionally(failure);
    }
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) CancellationException(java.util.concurrent.CancellationException) JobTerminateRequestedException(com.hazelcast.jet.impl.exception.JobTerminateRequestedException)

Aggregations

Vertex (com.hazelcast.jet.core.Vertex)189 DAG (com.hazelcast.jet.core.DAG)130 Test (org.junit.Test)95 QuickTest (com.hazelcast.test.annotation.QuickTest)57 Job (com.hazelcast.jet.Job)53 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)48 Entry (java.util.Map.Entry)41 List (java.util.List)28 Edge.between (com.hazelcast.jet.core.Edge.between)26 Map (java.util.Map)26 Assert.assertEquals (org.junit.Assert.assertEquals)23 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)21 IntStream (java.util.stream.IntStream)21 Assert.assertTrue (org.junit.Assert.assertTrue)19 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)18 Category (org.junit.experimental.categories.Category)18 Collectors.toList (java.util.stream.Collectors.toList)17 Nonnull (javax.annotation.Nonnull)17 FunctionEx (com.hazelcast.function.FunctionEx)15 Edge (com.hazelcast.jet.core.Edge)15