Search in sources :

Example 11 with SystemStream

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

the class IdentityStreamTask method process.

@Override
public void process(IncomingMessageEnvelope incomingMessageEnvelope, MessageCollector messageCollector, TaskCoordinator taskCoordinator) throws Exception {
    messageCollector.send(new OutgoingMessageEnvelope(new SystemStream(outputSystem, outputTopic), incomingMessageEnvelope.getMessage()));
    processedMessageCount++;
    if (processedMessageCount == expectedMessageCount) {
        endLatch.countDown();
    }
}
Also used : SystemStream(org.apache.samza.system.SystemStream) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope)

Example 12 with SystemStream

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

the class Checker method window.

@Override
public void window(MessageCollector collector, TaskCoordinator coordinator) {
    String currentEpoch = this.store.get(CURRENT_EPOCH);
    logger.info("Checking if epoch " + currentEpoch + " is complete.");
    int count = 0;
    KeyValueIterator<String, String> iter = this.store.all();
    while (iter.hasNext()) {
        Entry<String, String> entry = iter.next();
        String foundEpoch = entry.getValue();
        if (foundEpoch.equals(currentEpoch)) {
            count += 1;
        } else {
            logger.info("####### Found a different epoch! - " + foundEpoch + " Current epoch is " + currentEpoch);
        }
    }
    iter.close();
    if (count == expectedKeys + 1) {
        logger.info("Epoch " + currentEpoch + " is complete.");
        int nextEpoch = Integer.parseInt(currentEpoch) + 1;
        for (int i = 0; i < numPartitions; i++) {
            logger.info("Emitting next epoch - " + Integer.toString(i) + " -> " + Integer.toString(nextEpoch));
            collector.send(new OutgoingMessageEnvelope(new SystemStream("kafka", "epoch"), Integer.toString(i), Integer.toString(nextEpoch)));
        }
        this.store.put(CURRENT_EPOCH, Integer.toString(nextEpoch));
    } else if (count > expectedKeys + 1) {
        throw new IllegalStateException("Got " + count + " keys, which is more than the expected " + (expectedKeys + 1));
    } else {
        logger.info("Only found " + count + " valid keys, try again later.");
    }
}
Also used : SystemStream(org.apache.samza.system.SystemStream) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope)

Example 13 with SystemStream

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

the class Joiner method process.

@Override
public void process(IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
    String key = (String) envelope.getKey();
    String value = (String) envelope.getMessage();
    String[] pieces = value.split("-");
    int epoch = Integer.parseInt(pieces[0]);
    int partition = Integer.parseInt(pieces[1].split(" ")[1]);
    Partitions partitions = loadPartitions(epoch, key);
    logger.info("Joiner got epoch = " + epoch + ", partition = " + partition + ", parts = " + partitions);
    if (partitions.epoch < epoch) {
        // we are in a new era
        if (partitions.partitions.size() != expected)
            throw new IllegalArgumentException("Should have " + expected + " partitions when new epoch starts.");
        logger.info("Reseting epoch to " + epoch);
        this.store.delete(key);
        partitions.epoch = epoch;
        partitions.partitions.clear();
        partitions.partitions.add(partition);
    } else if (partitions.epoch > epoch) {
        logger.info("Ignoring message for epoch " + epoch);
    } else {
        partitions.partitions.add(partition);
        if (partitions.partitions.size() == expected) {
            logger.info("Completed: " + key + " -> " + Integer.toString(epoch));
            collector.send(new OutgoingMessageEnvelope(new SystemStream("kafka", "completed-keys"), key, Integer.toString(epoch)));
        }
    }
    this.store.put(key, partitions.toString());
    logger.info("Join store in Task " + this.taskName + " " + key + " -> " + partitions.toString());
}
Also used : SystemStream(org.apache.samza.system.SystemStream) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope)

Example 14 with SystemStream

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

the class Log4jSystemConfig method getStreamSerdeName.

public String getStreamSerdeName(String systemName, String streamName) {
    StreamConfig streamConfig = new StreamConfig(this);
    scala.Option<String> option = streamConfig.getStreamMsgSerde(new SystemStream(systemName, streamName));
    return option.isEmpty() ? null : option.get();
}
Also used : SystemStream(org.apache.samza.system.SystemStream)

Example 15 with SystemStream

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

the class DefaultChooserConfig method getBootstrapStreams.

/**
   * @return  the set of SystemStreams which were configured as bootstrap streams.
   */
public Set<SystemStream> getBootstrapStreams() {
    Set<SystemStream> bootstrapInputs = new HashSet<>();
    Set<SystemStream> allInputs = taskConfigJava.getAllInputStreams();
    for (SystemStream systemStream : allInputs) {
        if (streamConfig.getBootstrapEnabled(systemStream)) {
            bootstrapInputs.add(systemStream);
        }
    }
    return Collections.unmodifiableSet(bootstrapInputs);
}
Also used : SystemStream(org.apache.samza.system.SystemStream) HashSet(java.util.HashSet)

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