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;
}
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);
}
}
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()));
}
}
Aggregations