use of org.apache.samza.runtime.LocationId in project samza by apache.
the class TestZkUtils method testWriteTaskLocalityShouldUpdateTheExistingValue.
@Test
public void testWriteTaskLocalityShouldUpdateTheExistingValue() {
zkUtils.writeTaskLocality(new TaskName("task-1"), new LocationId("LocationId-1"));
Map<TaskName, LocationId> taskLocality = ImmutableMap.of(new TaskName("task-1"), new LocationId("LocationId-1"));
Assert.assertEquals(taskLocality, zkUtils.readTaskLocality());
zkUtils.writeTaskLocality(new TaskName("task-1"), new LocationId("LocationId-2"));
taskLocality = ImmutableMap.of(new TaskName("task-1"), new LocationId("LocationId-2"));
Assert.assertEquals(taskLocality, zkUtils.readTaskLocality());
}
use of org.apache.samza.runtime.LocationId in project samza by apache.
the class TestZkUtils method testReadAfterWriteTaskLocality.
@Test
public void testReadAfterWriteTaskLocality() {
zkUtils.writeTaskLocality(new TaskName("task-1"), new LocationId("LocationId-1"));
zkUtils.writeTaskLocality(new TaskName("task-2"), new LocationId("LocationId-2"));
Map<TaskName, LocationId> taskLocality = ImmutableMap.of(new TaskName("task-1"), new LocationId("LocationId-1"), new TaskName("task-2"), new LocationId("LocationId-2"));
Assert.assertEquals(taskLocality, zkUtils.readTaskLocality());
}
use of org.apache.samza.runtime.LocationId in project samza by apache.
the class TestJobModelHelper method testAllProcessorLocalityExists.
@Test
public void testAllProcessorLocalityExists() {
Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0), taskName(2), taskModel(2, 2, 2))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1, 1), taskName(3), taskModel(3, 3))));
Map<String, ProcessorLocality> processorLocalities = ImmutableMap.of("0", processorLocality("0", HOST0), "1", processorLocality("1", HOST1));
when(this.localityModel.getProcessorLocalities()).thenReturn(processorLocalities);
setupOldTaskAssignments(containerModels);
runAndCheckNewJobModel(config(), containerModels);
verifyGrouperMetadata(processorIdToLocationId(ImmutableMap.of("0", HOST0, "1", HOST1)), ImmutableMap.of(taskName(0), new LocationId(HOST0), taskName(1), new LocationId(HOST1), taskName(2), new LocationId(HOST0), taskName(3), new LocationId(HOST1)), activeTaskToSSPs(containerModels), activeTaskToContainer(containerModels));
verifyNewTaskAssignments(null, null, containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
use of org.apache.samza.runtime.LocationId in project samza by apache.
the class TestJobModelHelper method testNewContainerWithProcessorLocality.
@Test
public void testNewContainerWithProcessorLocality() {
Map<String, ContainerModel> oldContainerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0))));
Map<String, ProcessorLocality> processorLocalities = ImmutableMap.of("0", processorLocality("0", HOST0));
when(this.localityModel.getProcessorLocalities()).thenReturn(processorLocalities);
setupOldTaskAssignments(oldContainerModels);
Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0), taskName(2), taskModel(2, 2, 2))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1, 1), taskName(3), taskModel(3, 3))));
runAndCheckNewJobModel(config(), containerModels);
verifyGrouperMetadata(processorIdToLocationId(ImmutableMap.of("0", HOST0)), ImmutableMap.of(taskName(0), new LocationId(HOST0)), activeTaskToSSPs(oldContainerModels), activeTaskToContainer(oldContainerModels));
verifyNewTaskAssignments(taskNameStrings(oldContainerModels, TaskMode.Active), allSSPs(containerModels), containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
use of org.apache.samza.runtime.LocationId in project samza by apache.
the class ZkUtils method readTaskLocality.
public Map<TaskName, LocationId> readTaskLocality() {
Map<TaskName, LocationId> taskLocality = new HashMap<>();
String taskLocalityPath = keyBuilder.getTaskLocalityPath();
List<String> tasks = new ArrayList<>();
if (zkClient.exists(taskLocalityPath)) {
tasks = zkClient.getChildren(taskLocalityPath);
}
for (String taskName : tasks) {
String taskPath = String.format("%s/%s", keyBuilder.getTaskLocalityPath(), taskName);
String locationId = zkClient.readData(taskPath, true);
if (locationId != null) {
taskLocality.put(new TaskName(taskName), new LocationId(locationId));
}
}
return taskLocality;
}
Aggregations