Search in sources :

Example 1 with SetChangelogMapping

use of org.apache.samza.coordinator.stream.messages.SetChangelogMapping in project samza by apache.

the class ChangelogPartitionManager method readChangeLogPartitionMapping.

/**
   * Read the taskName to partition mapping that is being maintained by this ChangelogManager
   * @return TaskName to change log partition mapping, or an empty map if there were no messages.
   */
public Map<TaskName, Integer> readChangeLogPartitionMapping() {
    log.debug("Reading changelog partition information");
    final HashMap<TaskName, Integer> changelogMapping = new HashMap<TaskName, Integer>();
    for (CoordinatorStreamMessage coordinatorStreamMessage : getBootstrappedStream(SetChangelogMapping.TYPE)) {
        SetChangelogMapping changelogMapEntry = new SetChangelogMapping(coordinatorStreamMessage);
        changelogMapping.put(new TaskName(changelogMapEntry.getTaskName()), changelogMapEntry.getPartition());
        log.debug("TaskName: {} is mapped to {}", changelogMapEntry.getTaskName(), changelogMapEntry.getPartition());
    }
    return changelogMapping;
}
Also used : CoordinatorStreamMessage(org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage) HashMap(java.util.HashMap) TaskName(org.apache.samza.container.TaskName) SetChangelogMapping(org.apache.samza.coordinator.stream.messages.SetChangelogMapping)

Example 2 with SetChangelogMapping

use of org.apache.samza.coordinator.stream.messages.SetChangelogMapping in project samza by apache.

the class MockCoordinatorStreamWrappedConsumer method convertConfigToCoordinatorMessage.

private void convertConfigToCoordinatorMessage(Config config) {
    try {
        for (Map.Entry<String, String> configPair : config.entrySet()) {
            byte[] keyBytes = null;
            byte[] messgeBytes = null;
            if (configPair.getKey().startsWith(CHANGELOGPREFIX)) {
                String[] changelogInfo = configPair.getKey().split(":");
                String changeLogPartition = configPair.getValue();
                SetChangelogMapping changelogMapping = new SetChangelogMapping(changelogInfo[1], changelogInfo[2], Integer.parseInt(changeLogPartition));
                keyBytes = MAPPER.writeValueAsString(changelogMapping.getKeyArray()).getBytes("UTF-8");
                messgeBytes = MAPPER.writeValueAsString(changelogMapping.getMessageMap()).getBytes("UTF-8");
            } else {
                SetConfig setConfig = new SetConfig("source", configPair.getKey(), configPair.getValue());
                keyBytes = MAPPER.writeValueAsString(setConfig.getKeyArray()).getBytes("UTF-8");
                messgeBytes = MAPPER.writeValueAsString(setConfig.getMessageMap()).getBytes("UTF-8");
            }
            // The ssp here is the coordinator ssp (which is always fixed) and not the task ssp.
            put(systemStreamPartition, new IncomingMessageEnvelope(systemStreamPartition, "", keyBytes, messgeBytes));
        }
        setIsAtHead(systemStreamPartition, true);
    } catch (Exception e) {
        throw new SamzaException(e);
    }
}
Also used : IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) SetChangelogMapping(org.apache.samza.coordinator.stream.messages.SetChangelogMapping) SetConfig(org.apache.samza.coordinator.stream.messages.SetConfig) BlockingEnvelopeMap(org.apache.samza.util.BlockingEnvelopeMap) Map(java.util.Map) SamzaException(org.apache.samza.SamzaException) IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException)

Example 3 with SetChangelogMapping

use of org.apache.samza.coordinator.stream.messages.SetChangelogMapping in project samza by apache.

the class ChangelogPartitionManager method writeChangeLogPartitionMapping.

/**
   * Write the taskName to partition mapping that is being maintained by this ChangelogManager
   * @param changelogEntries The entries that needs to be written to the coordinator stream, the map takes the taskName
   *                       and it's corresponding changelog partition.
   */
public void writeChangeLogPartitionMapping(Map<TaskName, Integer> changelogEntries) {
    log.debug("Updating changelog information with: ");
    for (Map.Entry<TaskName, Integer> entry : changelogEntries.entrySet()) {
        log.debug("TaskName: {} to Partition: {}", entry.getKey().getTaskName(), entry.getValue());
        send(new SetChangelogMapping(getSource(), entry.getKey().getTaskName(), entry.getValue()));
    }
}
Also used : TaskName(org.apache.samza.container.TaskName) SetChangelogMapping(org.apache.samza.coordinator.stream.messages.SetChangelogMapping) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SetChangelogMapping (org.apache.samza.coordinator.stream.messages.SetChangelogMapping)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TaskName (org.apache.samza.container.TaskName)2 IOException (java.io.IOException)1 SamzaException (org.apache.samza.SamzaException)1 CoordinatorStreamMessage (org.apache.samza.coordinator.stream.messages.CoordinatorStreamMessage)1 SetConfig (org.apache.samza.coordinator.stream.messages.SetConfig)1 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)1 BlockingEnvelopeMap (org.apache.samza.util.BlockingEnvelopeMap)1