use of org.apache.samza.system.SystemStream in project samza by apache.
the class TestJoinOperator method getTestJoinStreamGraph.
private StreamApplicationDescriptorImpl getTestJoinStreamGraph(TestJoinFunction joinFn) throws IOException {
Map<String, String> mapConfig = new HashMap<>();
mapConfig.put("job.name", "jobName");
mapConfig.put("job.id", "jobId");
StreamTestUtils.addStreamConfigs(mapConfig, "inStream", "insystem", "instream");
StreamTestUtils.addStreamConfigs(mapConfig, "inStream2", "insystem", "instream2");
Config config = new MapConfig(mapConfig);
return new StreamApplicationDescriptorImpl(appDesc -> {
IntegerSerde integerSerde = new IntegerSerde();
KVSerde<Integer, Integer> kvSerde = KVSerde.of(integerSerde, integerSerde);
GenericSystemDescriptor sd = new GenericSystemDescriptor("insystem", "mockFactoryClassName");
GenericInputDescriptor<KV<Integer, Integer>> inputDescriptor1 = sd.getInputDescriptor("inStream", kvSerde);
GenericInputDescriptor<KV<Integer, Integer>> inputDescriptor2 = sd.getInputDescriptor("inStream2", kvSerde);
MessageStream<KV<Integer, Integer>> inStream = appDesc.getInputStream(inputDescriptor1);
MessageStream<KV<Integer, Integer>> inStream2 = appDesc.getInputStream(inputDescriptor2);
inStream.join(inStream2, joinFn, integerSerde, kvSerde, kvSerde, JOIN_TTL, "j1").sink((message, messageCollector, taskCoordinator) -> {
SystemStream outputSystemStream = new SystemStream("outputSystem", "outputStream");
messageCollector.send(new OutgoingMessageEnvelope(outputSystemStream, message));
});
}, config);
}
use of org.apache.samza.system.SystemStream in project samza by apache.
the class TestControlMessageSender method testSend.
@Test
public void testSend() {
SystemStreamMetadata metadata = mock(SystemStreamMetadata.class);
Map<Partition, SystemStreamMetadata.SystemStreamPartitionMetadata> partitionMetadata = new HashMap<>();
partitionMetadata.put(new Partition(0), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
partitionMetadata.put(new Partition(1), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
partitionMetadata.put(new Partition(2), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
partitionMetadata.put(new Partition(3), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
when(metadata.getSystemStreamPartitionMetadata()).thenReturn(partitionMetadata);
StreamMetadataCache metadataCache = mock(StreamMetadataCache.class);
when(metadataCache.getSystemStreamMetadata(anyObject(), anyBoolean())).thenReturn(metadata);
SystemStream systemStream = new SystemStream("test-system", "test-stream");
Set<Integer> partitions = new HashSet<>();
MessageCollector collector = mock(MessageCollector.class);
doAnswer(invocation -> {
OutgoingMessageEnvelope envelope = (OutgoingMessageEnvelope) invocation.getArguments()[0];
partitions.add((Integer) envelope.getPartitionKey());
assertEquals(envelope.getSystemStream(), systemStream);
return null;
}).when(collector).send(any());
ControlMessageSender sender = new ControlMessageSender(metadataCache);
WatermarkMessage watermark = new WatermarkMessage(System.currentTimeMillis(), "task 0");
sender.send(watermark, systemStream, collector);
assertEquals(partitions.size(), 1);
}
use of org.apache.samza.system.SystemStream in project samza by apache.
the class TestControlMessageSender method testBroadcast.
@Test
public void testBroadcast() {
SystemStreamMetadata metadata = mock(SystemStreamMetadata.class);
Map<Partition, SystemStreamMetadata.SystemStreamPartitionMetadata> partitionMetadata = new HashMap<>();
partitionMetadata.put(new Partition(0), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
partitionMetadata.put(new Partition(1), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
partitionMetadata.put(new Partition(2), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
partitionMetadata.put(new Partition(3), mock(SystemStreamMetadata.SystemStreamPartitionMetadata.class));
when(metadata.getSystemStreamPartitionMetadata()).thenReturn(partitionMetadata);
StreamMetadataCache metadataCache = mock(StreamMetadataCache.class);
when(metadataCache.getSystemStreamMetadata(anyObject(), anyBoolean())).thenReturn(metadata);
SystemStream systemStream = new SystemStream("test-system", "test-stream");
Set<Integer> partitions = new HashSet<>();
MessageCollector collector = mock(MessageCollector.class);
doAnswer(invocation -> {
OutgoingMessageEnvelope envelope = (OutgoingMessageEnvelope) invocation.getArguments()[0];
partitions.add((Integer) envelope.getPartitionKey());
assertEquals(envelope.getSystemStream(), systemStream);
return null;
}).when(collector).send(any());
ControlMessageSender sender = new ControlMessageSender(metadataCache);
WatermarkMessage watermark = new WatermarkMessage(System.currentTimeMillis(), "task 0");
SystemStreamPartition ssp = new SystemStreamPartition(systemStream, new Partition(0));
sender.broadcastToOtherPartitions(watermark, ssp, collector);
assertEquals(partitions.size(), 3);
}
use of org.apache.samza.system.SystemStream in project samza by apache.
the class AzureJobCoordinator method getInputStreamPartitions.
/**
* For each input stream specified in config, exactly determine its
* partitions, returning a set of SystemStreamPartitions containing them all.
*/
private Set<SystemStreamPartition> getInputStreamPartitions() {
TaskConfig taskConfig = new TaskConfig(config);
scala.collection.immutable.Set<SystemStream> inputSystemStreams = JavaConverters.asScalaSetConverter(taskConfig.getInputStreams()).asScala().toSet();
// Get the set of partitions for each SystemStream from the stream metadata
Set<SystemStreamPartition> sspSet = JavaConverters.mapAsJavaMapConverter(streamMetadataCache.getStreamMetadata(inputSystemStreams, true)).asJava().entrySet().stream().flatMap(this::mapSSMToSSP).collect(Collectors.toSet());
return sspSet;
}
use of org.apache.samza.system.SystemStream in project samza by apache.
the class ContainerStorageManager method getChangelogSystemStreams.
/**
* For each standby task, we remove its changeLogSSPs from changelogSSP map and add it to the task's taskSideInputSSPs.
* The task's sideInputManager will consume and restore these as well.
*
* @param containerModel the container's model
* @param changelogSystemStreams the passed in set of changelogSystemStreams
* @return A map of changeLogSSP to storeName across all tasks, assuming no two stores have the same changelogSSP
*/
private Map<String, SystemStream> getChangelogSystemStreams(ContainerModel containerModel, Map<String, SystemStream> changelogSystemStreams) {
if (MapUtils.invertMap(changelogSystemStreams).size() != changelogSystemStreams.size()) {
throw new SamzaException("Two stores cannot have the same changelog system-stream");
}
Map<SystemStreamPartition, String> changelogSSPToStore = new HashMap<>();
changelogSystemStreams.forEach((storeName, systemStream) -> containerModel.getTasks().forEach((taskName, taskModel) -> changelogSSPToStore.put(new SystemStreamPartition(systemStream, taskModel.getChangelogPartition()), storeName)));
getTasks(containerModel, TaskMode.Standby).forEach((taskName, taskModel) -> {
taskSideInputStoreSSPs.putIfAbsent(taskName, new HashMap<>());
changelogSystemStreams.forEach((storeName, systemStream) -> {
SystemStreamPartition ssp = new SystemStreamPartition(systemStream, taskModel.getChangelogPartition());
changelogSSPToStore.remove(ssp);
taskSideInputStoreSSPs.get(taskName).put(storeName, Collections.singleton(ssp));
});
});
// changelogSystemStreams correspond only to active tasks (since those of standby-tasks moved to sideInputs above)
return MapUtils.invertMap(changelogSSPToStore).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, x -> x.getValue().getSystemStream()));
}
Aggregations