Search in sources :

Example 21 with SystemStream

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

the class DefaultChooserConfig method getPriorityStreams.

/**
   * Gets the priority of every SystemStream for which the priority
   * was explicitly configured with a value >=0.
   *
   * @return  the explicitly-configured stream priorities as a map from
   *          SystemStream to the configured priority value. Streams that
   *          were not explicitly configured with a priority are not returned.
   */
public Map<SystemStream, Integer> getPriorityStreams() {
    Set<SystemStream> allInputs = taskConfigJava.getAllInputStreams();
    Map<SystemStream, Integer> priorityStreams = new HashMap<>();
    for (SystemStream systemStream : allInputs) {
        int priority = streamConfig.getPriority(systemStream);
        if (priority >= 0) {
            priorityStreams.put(systemStream, priority);
        }
    }
    return Collections.unmodifiableMap(priorityStreams);
}
Also used : HashMap(java.util.HashMap) SystemStream(org.apache.samza.system.SystemStream)

Example 22 with SystemStream

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

the class TaskConfigJava method getBroadcastSystemStreamPartitions.

/**
   * Get the systemStreamPartitions of the broadcast stream. Specifying
   * one partition for one stream or a range of the partitions for one
   * stream is allowed.
   *
   * @return a Set of SystemStreamPartitions
   */
public Set<SystemStreamPartition> getBroadcastSystemStreamPartitions() {
    HashSet<SystemStreamPartition> systemStreamPartitionSet = new HashSet<SystemStreamPartition>();
    List<String> systemStreamPartitions = getList(BROADCAST_INPUT_STREAMS, Collections.<String>emptyList());
    for (String systemStreamPartition : systemStreamPartitions) {
        int hashPosition = systemStreamPartition.indexOf("#");
        if (hashPosition == -1) {
            throw new IllegalArgumentException("incorrect format in " + systemStreamPartition + ". Broadcast stream names should be in the form 'system.stream#partitionId' or 'system.stream#[partitionN-partitionM]'");
        } else {
            String systemStreamName = systemStreamPartition.substring(0, hashPosition);
            String partitionSegment = systemStreamPartition.substring(hashPosition + 1);
            SystemStream systemStream = Util.getSystemStreamFromNames(systemStreamName);
            if (Pattern.matches(BROADCAST_STREAM_PATTERN, partitionSegment)) {
                systemStreamPartitionSet.add(new SystemStreamPartition(systemStream, new Partition(Integer.valueOf(partitionSegment))));
            } else {
                if (Pattern.matches(BROADCAST_STREAM_RANGE_PATTERN, partitionSegment)) {
                    int partitionStart = Integer.valueOf(partitionSegment.substring(1, partitionSegment.lastIndexOf("-")));
                    int partitionEnd = Integer.valueOf(partitionSegment.substring(partitionSegment.lastIndexOf("-") + 1, partitionSegment.indexOf("]")));
                    if (partitionStart > partitionEnd) {
                        LOGGER.warn("The starting partition in stream " + systemStream.toString() + " is bigger than the ending Partition. No partition is added");
                    }
                    for (int i = partitionStart; i <= partitionEnd; i++) {
                        systemStreamPartitionSet.add(new SystemStreamPartition(systemStream, new Partition(i)));
                    }
                } else {
                    throw new IllegalArgumentException("incorrect format in " + systemStreamPartition + ". Broadcast stream names should be in the form 'system.stream#partitionId' or 'system.stream#[partitionN-partitionM]'");
                }
            }
        }
    }
    return systemStreamPartitionSet;
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) SystemStream(org.apache.samza.system.SystemStream) HashSet(java.util.HashSet) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition)

Aggregations

SystemStream (org.apache.samza.system.SystemStream)22 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)7 Test (org.junit.Test)7 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Partition (org.apache.samza.Partition)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 SinglePartitionWithoutOffsetsSystemAdmin (org.apache.samza.util.SinglePartitionWithoutOffsetsSystemAdmin)3 SamzaException (org.apache.samza.SamzaException)2 CoordinatorStreamMessage (org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage)2 SetConfig (org.apache.samza.coordinator.stream.messages.SetConfig)2 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)2 MessageType (org.apache.samza.operators.data.MessageType)2 TestMessageEnvelope (org.apache.samza.operators.data.TestMessageEnvelope)2 MessageCollector (org.apache.samza.task.MessageCollector)2 TaskCoordinator (org.apache.samza.task.TaskCoordinator)2 Collection (java.util.Collection)1