Search in sources :

Example 1 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class AsyncRunLoop method getSspToAsyncTaskWorkerMap.

/**
   * Returns mapping of the SystemStreamPartition to the AsyncTaskWorkers to efficiently route the envelopes
   */
private static Map<SystemStreamPartition, List<AsyncTaskWorker>> getSspToAsyncTaskWorkerMap(Map<TaskName, TaskInstance> taskInstances, Map<TaskName, AsyncTaskWorker> taskWorkers) {
    Map<SystemStreamPartition, List<AsyncTaskWorker>> sspToWorkerMap = new HashMap<>();
    for (TaskInstance task : taskInstances.values()) {
        Set<SystemStreamPartition> ssps = JavaConverters.setAsJavaSetConverter(task.systemStreamPartitions()).asJava();
        for (SystemStreamPartition ssp : ssps) {
            sspToWorkerMap.putIfAbsent(ssp, new ArrayList<>());
            sspToWorkerMap.get(ssp).add(taskWorkers.get(task.taskName()));
        }
    }
    return sspToWorkerMap;
}
Also used : TaskInstance(org.apache.samza.container.TaskInstance) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition)

Example 2 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class GroupBySystemStreamPartition method group.

@Override
public Map<TaskName, Set<SystemStreamPartition>> group(Set<SystemStreamPartition> ssps) {
    Map<TaskName, Set<SystemStreamPartition>> groupedMap = new HashMap<TaskName, Set<SystemStreamPartition>>();
    for (SystemStreamPartition ssp : ssps) {
        if (broadcastStreams.contains(ssp)) {
            continue;
        }
        HashSet<SystemStreamPartition> sspSet = new HashSet<SystemStreamPartition>();
        sspSet.add(ssp);
        groupedMap.put(new TaskName(ssp.toString()), sspSet);
    }
    // assign the broadcast streams to all the taskNames
    if (!broadcastStreams.isEmpty()) {
        for (Set<SystemStreamPartition> value : groupedMap.values()) {
            for (SystemStreamPartition ssp : broadcastStreams) {
                value.add(ssp);
            }
        }
    }
    return groupedMap;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) TaskName(org.apache.samza.container.TaskName) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) HashSet(java.util.HashSet)

Example 3 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class TestJoinOperator method createStreamOperatorTask.

private StreamOperatorTask createStreamOperatorTask(Clock clock, StreamApplication app) throws Exception {
    ApplicationRunner runner = mock(ApplicationRunner.class);
    when(runner.getStreamSpec("instream")).thenReturn(new StreamSpec("instream", "instream", "insystem"));
    when(runner.getStreamSpec("instream2")).thenReturn(new StreamSpec("instream2", "instream2", "insystem2"));
    TaskContext taskContext = mock(TaskContext.class);
    when(taskContext.getSystemStreamPartitions()).thenReturn(ImmutableSet.of(new SystemStreamPartition("insystem", "instream", new Partition(0)), new SystemStreamPartition("insystem2", "instream2", new Partition(0))));
    when(taskContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
    Config config = mock(Config.class);
    StreamOperatorTask sot = new StreamOperatorTask(app, runner, clock);
    sot.init(config, taskContext);
    return sot;
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) TaskContext(org.apache.samza.task.TaskContext) ApplicationRunner(org.apache.samza.runtime.ApplicationRunner) Config(org.apache.samza.config.Config) StreamOperatorTask(org.apache.samza.task.StreamOperatorTask) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition)

Example 4 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class TestWindowOperator method setup.

@Before
public void setup() throws Exception {
    config = mock(Config.class);
    taskContext = mock(TaskContext.class);
    runner = mock(ApplicationRunner.class);
    when(taskContext.getSystemStreamPartitions()).thenReturn(ImmutableSet.of(new SystemStreamPartition("kafka", "integers", new Partition(0))));
    when(taskContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap());
    when(runner.getStreamSpec("integers")).thenReturn(new StreamSpec("integers", "integers", "kafka"));
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) StreamSpec(org.apache.samza.system.StreamSpec) TaskContext(org.apache.samza.task.TaskContext) ApplicationRunner(org.apache.samza.runtime.ApplicationRunner) Config(org.apache.samza.config.Config) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Before(org.junit.Before)

Example 5 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class TestSamzaObjectMapper method setup.

@Before
public void setup() throws IOException {
    Map<String, String> configMap = new HashMap<String, String>();
    Set<SystemStreamPartition> ssp = new HashSet<>();
    configMap.put("a", "b");
    Config config = new MapConfig(configMap);
    TaskName taskName = new TaskName("test");
    ssp.add(new SystemStreamPartition("foo", "bar", new Partition(1)));
    TaskModel taskModel = new TaskModel(taskName, ssp, new Partition(2));
    Map<TaskName, TaskModel> tasks = new HashMap<TaskName, TaskModel>();
    tasks.put(taskName, taskModel);
    ContainerModel containerModel = new ContainerModel("1", 1, tasks);
    Map<String, ContainerModel> containerMap = new HashMap<String, ContainerModel>();
    containerMap.put("1", containerModel);
    jobModel = new JobModel(config, containerMap);
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) HashMap(java.util.HashMap) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) ContainerModel(org.apache.samza.job.model.ContainerModel) TaskName(org.apache.samza.container.TaskName) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) TaskModel(org.apache.samza.job.model.TaskModel) HashSet(java.util.HashSet) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Before(org.junit.Before)

Aggregations

SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)43 Partition (org.apache.samza.Partition)29 Test (org.junit.Test)26 HashMap (java.util.HashMap)17 HashSet (java.util.HashSet)17 TaskName (org.apache.samza.container.TaskName)13 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)13 Config (org.apache.samza.config.Config)10 Set (java.util.Set)8 MapConfig (org.apache.samza.config.MapConfig)7 GenericRecord (org.apache.avro.generic.GenericRecord)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 SystemStream (org.apache.samza.system.SystemStream)5 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)4 SystemStreamMetadata (org.apache.samza.system.SystemStreamMetadata)4 LinkedHashMap (java.util.LinkedHashMap)3 SamzaException (org.apache.samza.SamzaException)3 TaskInstance (org.apache.samza.container.TaskInstance)3 SystemConsumer (org.apache.samza.system.SystemConsumer)3