use of org.apache.samza.coordinator.stream.messages.SetTaskContainerMapping in project samza by apache.
the class TaskAssignmentManager method writeTaskContainerMapping.
/**
* Method to write task container info to coordinator stream.
*
* @param taskName the task name
* @param containerId the SamzaContainer ID or {@code null} to delete the mapping
*/
public void writeTaskContainerMapping(String taskName, String containerId) {
String existingContainerId = taskNameToContainerId.get(taskName);
if (existingContainerId != null && !existingContainerId.equals(containerId)) {
log.info("Task \"{}\" moved from container {} to container {}", new Object[] { taskName, existingContainerId, containerId });
} else {
log.debug("Task \"{}\" assigned to container {}", taskName, containerId);
}
if (containerId == null) {
send(new Delete(getSource(), taskName, SetTaskContainerMapping.TYPE));
taskNameToContainerId.remove(taskName);
} else {
send(new SetTaskContainerMapping(getSource(), taskName, String.valueOf(containerId)));
taskNameToContainerId.put(taskName, containerId);
}
}
use of org.apache.samza.coordinator.stream.messages.SetTaskContainerMapping in project samza by apache.
the class TaskAssignmentManager method readTaskAssignment.
/**
* Method to allow read container task information from coordinator stream. This method is used
* in {@link org.apache.samza.coordinator.JobModelManager}.
*
* @return the map of taskName: containerId
*/
public Map<String, String> readTaskAssignment() {
taskNameToContainerId.clear();
for (CoordinatorStreamMessage message : getBootstrappedStream(SetTaskContainerMapping.TYPE)) {
if (message.isDelete()) {
taskNameToContainerId.remove(message.getKey());
log.debug("Got TaskContainerMapping delete message: {}", message);
} else {
SetTaskContainerMapping mapping = new SetTaskContainerMapping(message);
taskNameToContainerId.put(mapping.getKey(), mapping.getTaskAssignment());
log.debug("Got TaskContainerMapping message: {}", mapping);
}
}
for (Map.Entry<String, String> entry : taskNameToContainerId.entrySet()) {
log.debug("Assignment for task \"{}\": {}", entry.getKey(), entry.getValue());
}
return Collections.unmodifiableMap(new HashMap<>(taskNameToContainerId));
}
Aggregations