use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class ExecutionPlan method initialize.
public void initialize(NodeEngine nodeEngine, long jobId, long executionId, SnapshotContext snapshotContext) {
this.nodeEngine = nodeEngine;
this.executionId = executionId;
initProcSuppliers();
initDag();
this.ptionArrgmt = new PartitionArrangement(partitionOwners, nodeEngine.getThisAddress());
JetInstance instance = getJetInstance(nodeEngine);
for (VertexDef vertex : vertices) {
Collection<? extends Processor> processors = createProcessors(vertex, vertex.localParallelism());
// create StoreSnapshotTasklet and the queues to it
QueuedPipe<Object>[] snapshotQueues = new QueuedPipe[vertex.localParallelism()];
Arrays.setAll(snapshotQueues, i -> new OneToOneConcurrentArrayQueue<>(SNAPSHOT_QUEUE_SIZE));
ConcurrentConveyor<Object> ssConveyor = ConcurrentConveyor.concurrentConveyor(null, snapshotQueues);
StoreSnapshotTasklet ssTasklet = new StoreSnapshotTasklet(snapshotContext, jobId, new ConcurrentInboundEdgeStream(ssConveyor, 0, 0, lastSnapshotId, true, -1, "ssFrom:" + vertex.name()), nodeEngine, vertex.name(), vertex.isHigherPriorityUpstream());
tasklets.add(ssTasklet);
int localProcessorIdx = 0;
for (Processor p : processors) {
int globalProcessorIndex = vertex.getProcIdxOffset() + localProcessorIdx;
String loggerName = createLoggerName(p.getClass().getName(), vertex.name(), globalProcessorIndex);
ProcCtx context = new ProcCtx(instance, nodeEngine.getSerializationService(), nodeEngine.getLogger(loggerName), vertex.name(), globalProcessorIndex, jobConfig.getProcessingGuarantee(), vertex.localParallelism(), vertex.totalParallelism());
String probePrefix = String.format("jet.job.%s.%s#%d", idToString(executionId), vertex.name(), localProcessorIdx);
((NodeEngineImpl) nodeEngine).getMetricsRegistry().scanAndRegister(p, probePrefix);
// createOutboundEdgeStreams() populates localConveyorMap and edgeSenderConveyorMap.
// Also populates instance fields: senderMap, receiverMap, tasklets.
List<OutboundEdgeStream> outboundStreams = createOutboundEdgeStreams(vertex, localProcessorIdx);
List<InboundEdgeStream> inboundStreams = createInboundEdgeStreams(vertex, localProcessorIdx);
OutboundCollector snapshotCollector = new ConveyorCollector(ssConveyor, localProcessorIdx, null);
ProcessorTasklet processorTasklet = new ProcessorTasklet(context, p, inboundStreams, outboundStreams, snapshotContext, snapshotCollector, jobConfig.getMaxWatermarkRetainMillis());
tasklets.add(processorTasklet);
this.processors.add(p);
localProcessorIdx++;
}
}
List<ReceiverTasklet> allReceivers = receiverMap.values().stream().flatMap(o -> o.values().stream()).flatMap(a -> a.values().stream()).collect(toList());
tasklets.addAll(allReceivers);
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class ExecutionPlanBuilder method createExecutionPlans.
public static Map<MemberInfo, ExecutionPlan> createExecutionPlans(NodeEngine nodeEngine, MembersView membersView, DAG dag, JobConfig jobConfig, long lastSnapshotId) {
final JetInstance instance = getJetInstance(nodeEngine);
final int defaultParallelism = instance.getConfig().getInstanceConfig().getCooperativeThreadCount();
final Collection<MemberInfo> members = new HashSet<>(membersView.size());
final Address[] partitionOwners = new Address[nodeEngine.getPartitionService().getPartitionCount()];
initPartitionOwnersAndMembers(nodeEngine, membersView, members, partitionOwners);
final List<Address> addresses = members.stream().map(MemberInfo::getAddress).collect(toList());
final int clusterSize = members.size();
final boolean isJobDistributed = clusterSize > 1;
final EdgeConfig defaultEdgeConfig = instance.getConfig().getDefaultEdgeConfig();
final Map<MemberInfo, ExecutionPlan> plans = members.stream().collect(toMap(m -> m, m -> new ExecutionPlan(partitionOwners, jobConfig, lastSnapshotId)));
final Map<String, Integer> vertexIdMap = assignVertexIds(dag);
for (Entry<String, Integer> entry : vertexIdMap.entrySet()) {
final Vertex vertex = dag.getVertex(entry.getKey());
final ProcessorMetaSupplier metaSupplier = vertex.getMetaSupplier();
final int vertexId = entry.getValue();
final int localParallelism = determineParallelism(vertex, metaSupplier.preferredLocalParallelism(), defaultParallelism);
final int totalParallelism = localParallelism * clusterSize;
final List<EdgeDef> inbound = toEdgeDefs(dag.getInboundEdges(vertex.getName()), defaultEdgeConfig, e -> vertexIdMap.get(e.getSourceName()), isJobDistributed);
final List<EdgeDef> outbound = toEdgeDefs(dag.getOutboundEdges(vertex.getName()), defaultEdgeConfig, e -> vertexIdMap.get(e.getDestName()), isJobDistributed);
final ILogger logger = nodeEngine.getLogger(String.format("%s.%s#ProcessorMetaSupplier", metaSupplier.getClass().getName(), vertex.getName()));
metaSupplier.init(new MetaSupplierCtx(instance, logger, vertex.getName(), localParallelism, totalParallelism));
Function<Address, ProcessorSupplier> procSupplierFn = metaSupplier.get(addresses);
int procIdxOffset = 0;
for (Entry<MemberInfo, ExecutionPlan> e : plans.entrySet()) {
final ProcessorSupplier processorSupplier = procSupplierFn.apply(e.getKey().getAddress());
checkSerializable(processorSupplier, "ProcessorSupplier in vertex '" + vertex.getName() + '\'');
final VertexDef vertexDef = new VertexDef(vertexId, vertex.getName(), processorSupplier, procIdxOffset, localParallelism, totalParallelism);
vertexDef.addInboundEdges(inbound);
vertexDef.addOutboundEdges(outbound);
e.getValue().addVertex(vertexDef);
procIdxOffset += localParallelism;
}
}
return plans;
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class AggregateTransform_IntegrationTest method test_aggregate.
@Test
public void test_aggregate() {
// Given
JetInstance instance = createJetMember();
IMap<Long, String> map = instance.getMap("source");
map.put(0L, "foo");
map.put(1L, "bar");
// When
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<Long, String>map("source")).aggregate(toSet()).drainTo(Sinks.list("sink"));
instance.newJob(p).join();
// Then
assertEquals(listToString(singletonList(set(entry(0L, "foo"), entry(1L, "bar")))), listToString(instance.getHazelcastInstance().getList("sink")));
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class AggregateTransform_IntegrationTest method test_aggregate2.
@Test
public void test_aggregate2() {
// Given
JetInstance instance = createJetMember();
IListJet<Integer> list = instance.getList("list");
list.add(1);
list.add(2);
list.add(3);
IListJet<String> list1 = instance.getList("list1");
list1.add("a");
list1.add("b");
list1.add("c");
// When
Pipeline p = Pipeline.create();
BatchStage<Integer> stage1 = p.drawFrom(Sources.list("list1"));
p.drawFrom(Sources.list("list")).aggregate2(stage1, toTwoBags()).drainTo(Sinks.list("sink"));
instance.newJob(p).join();
// Then
TwoBags twoBags = (TwoBags) instance.getHazelcastInstance().getList("sink").iterator().next();
assertNotNull(twoBags);
sort(twoBags);
assertEquals(TwoBags.twoBags(list, list1), twoBags);
}
use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.
the class AbstractStreamTest method getCache.
static <K, V> ICacheJet<K, V> getCache() {
String cacheName = randomName();
ICacheJet<K, V> cache = null;
for (JetInstance jetInstance : allJetInstances()) {
cache = jetInstance.getCacheManager().getCache(cacheName);
}
return cache;
}
Aggregations