use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestGroupByContainerIds method testGroupHappyPath.
@Test
public void testGroupHappyPath() {
Set<TaskModel> taskModels = generateTaskModels(5);
Set<ContainerModel> containers = buildSimpleGrouper(2).group(taskModels);
Map<String, ContainerModel> containersMap = new HashMap<>();
for (ContainerModel container : containers) {
containersMap.put(container.getId(), container);
}
assertEquals(2, containers.size());
ContainerModel container0 = containersMap.get("0");
ContainerModel container1 = containersMap.get("1");
assertNotNull(container0);
assertNotNull(container1);
assertEquals("0", container0.getId());
assertEquals("1", container1.getId());
assertEquals(3, container0.getTasks().size());
assertEquals(2, container1.getTasks().size());
assertTrue(container0.getTasks().containsKey(getTaskName(0)));
assertTrue(container0.getTasks().containsKey(getTaskName(2)));
assertTrue(container0.getTasks().containsKey(getTaskName(4)));
assertTrue(container1.getTasks().containsKey(getTaskName(1)));
assertTrue(container1.getTasks().containsKey(getTaskName(3)));
}
use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestGroupByContainerIds method testGroupWithNullContainerIds.
@Test
public void testGroupWithNullContainerIds() {
Set<TaskModel> taskModels = generateTaskModels(5);
List<String> containerIds = null;
Set<ContainerModel> containers = buildSimpleGrouper(2).group(taskModels, containerIds);
Map<String, ContainerModel> containersMap = new HashMap<>();
for (ContainerModel container : containers) {
containersMap.put(container.getId(), container);
}
assertEquals(2, containers.size());
ContainerModel container0 = containersMap.get("0");
ContainerModel container1 = containersMap.get("1");
assertNotNull(container0);
assertNotNull(container1);
assertEquals("0", container0.getId());
assertEquals("1", container1.getId());
assertEquals(3, container0.getTasks().size());
assertEquals(2, container1.getTasks().size());
assertTrue(container0.getTasks().containsKey(getTaskName(0)));
assertTrue(container0.getTasks().containsKey(getTaskName(2)));
assertTrue(container0.getTasks().containsKey(getTaskName(4)));
assertTrue(container1.getTasks().containsKey(getTaskName(1)));
assertTrue(container1.getTasks().containsKey(getTaskName(3)));
}
use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestGroupByContainerIds method testGroupManyTasks.
@Test
public void testGroupManyTasks() {
Set<TaskModel> taskModels = generateTaskModels(21);
List<String> containerIds = new ArrayList<String>() {
{
add("4");
add("2");
}
};
Set<ContainerModel> containers = buildSimpleGrouper().group(taskModels, containerIds);
Map<String, ContainerModel> containersMap = new HashMap<>();
for (ContainerModel container : containers) {
containersMap.put(container.getId(), container);
}
assertEquals(2, containers.size());
ContainerModel container0 = containersMap.get("4");
ContainerModel container1 = containersMap.get("2");
assertNotNull(container0);
assertNotNull(container1);
assertEquals("4", container0.getId());
assertEquals("2", container1.getId());
assertEquals(11, container0.getTasks().size());
assertEquals(10, container1.getTasks().size());
// NOTE: tasks are sorted lexicographically, so the container assignment
// can seem odd, but the consistency is the key focus
assertTrue(container0.getTasks().containsKey(getTaskName(0)));
assertTrue(container0.getTasks().containsKey(getTaskName(10)));
assertTrue(container0.getTasks().containsKey(getTaskName(12)));
assertTrue(container0.getTasks().containsKey(getTaskName(14)));
assertTrue(container0.getTasks().containsKey(getTaskName(16)));
assertTrue(container0.getTasks().containsKey(getTaskName(18)));
assertTrue(container0.getTasks().containsKey(getTaskName(2)));
assertTrue(container0.getTasks().containsKey(getTaskName(3)));
assertTrue(container0.getTasks().containsKey(getTaskName(5)));
assertTrue(container0.getTasks().containsKey(getTaskName(7)));
assertTrue(container0.getTasks().containsKey(getTaskName(9)));
assertTrue(container1.getTasks().containsKey(getTaskName(1)));
assertTrue(container1.getTasks().containsKey(getTaskName(11)));
assertTrue(container1.getTasks().containsKey(getTaskName(13)));
assertTrue(container1.getTasks().containsKey(getTaskName(15)));
assertTrue(container1.getTasks().containsKey(getTaskName(17)));
assertTrue(container1.getTasks().containsKey(getTaskName(19)));
assertTrue(container1.getTasks().containsKey(getTaskName(20)));
assertTrue(container1.getTasks().containsKey(getTaskName(4)));
assertTrue(container1.getTasks().containsKey(getTaskName(6)));
assertTrue(container1.getTasks().containsKey(getTaskName(8)));
}
use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestGroupByContainerIds method testGenerateContainerModelForSingleContainer.
@Test
public void testGenerateContainerModelForSingleContainer() {
TaskNameGrouper taskNameGrouper = buildSimpleGrouper(1);
String testProcessorId1 = "testProcessorId1";
LocationId testLocationId1 = new LocationId("testLocationId1");
LocationId testLocationId2 = new LocationId("testLocationId2");
LocationId testLocationId3 = new LocationId("testLocationId3");
TaskName testTaskName1 = new TaskName("testTasKId1");
TaskName testTaskName2 = new TaskName("testTaskId2");
TaskName testTaskName3 = new TaskName("testTaskId3");
TaskModel testTaskModel1 = new TaskModel(testTaskName1, new HashSet<>(), new Partition(0));
TaskModel testTaskModel2 = new TaskModel(testTaskName2, new HashSet<>(), new Partition(1));
TaskModel testTaskModel3 = new TaskModel(testTaskName3, new HashSet<>(), new Partition(2));
Map<String, LocationId> processorLocality = ImmutableMap.of(testProcessorId1, testLocationId1);
Map<TaskName, LocationId> taskLocality = ImmutableMap.of(testTaskName1, testLocationId1, testTaskName2, testLocationId2, testTaskName3, testLocationId3);
GrouperMetadataImpl grouperMetadata = new GrouperMetadataImpl(processorLocality, taskLocality, new HashMap<>(), new HashMap<>());
Set<TaskModel> taskModels = ImmutableSet.of(testTaskModel1, testTaskModel2, testTaskModel3);
Set<ContainerModel> expectedContainerModels = ImmutableSet.of(new ContainerModel(testProcessorId1, ImmutableMap.of(testTaskName1, testTaskModel1, testTaskName2, testTaskModel2, testTaskName3, testTaskModel3)));
Set<ContainerModel> actualContainerModels = taskNameGrouper.group(taskModels, grouperMetadata);
assertEquals(expectedContainerModels, actualContainerModels);
}
use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestGroupByContainerCount method testBalancerAfterContainerDecrease.
/**
* Before:
* C0 C1 C2 C3
* ----------------
* T0 T1 T2 T3
* T4 T5 T6 T7
* T8
*
* After:
* C0 C1
* --------
* T0 T1
* T4 T5
* T8 T7
* T6 T3
* T2
*
* NOTE for host affinity, it would help to have some additional logic to reassign tasks
* from C2 and C3 to containers that were on the same respective hosts, it wasn't implemented
* because the scenario is infrequent, the benefits are not guaranteed, and the code complexity
* wasn't worth it. It certainly could be implemented in the future.
*/
@Test
public void testBalancerAfterContainerDecrease() {
Set<TaskModel> taskModels = generateTaskModels(9);
Set<ContainerModel> prevContainers = new GroupByContainerCount(4).group(taskModels);
Map<TaskName, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
GrouperMetadataImpl grouperMetadata = new GrouperMetadataImpl(new HashMap<>(), new HashMap<>(), new HashMap<>(), prevTaskToContainerMapping);
Set<ContainerModel> containers = new GroupByContainerCount(2).group(taskModels, grouperMetadata);
Map<String, ContainerModel> containersMap = new HashMap<>();
for (ContainerModel container : containers) {
containersMap.put(container.getId(), container);
}
assertEquals(2, containers.size());
ContainerModel container0 = containersMap.get("0");
ContainerModel container1 = containersMap.get("1");
assertNotNull(container0);
assertNotNull(container1);
assertEquals("0", container0.getId());
assertEquals("1", container1.getId());
assertEquals(5, container0.getTasks().size());
assertEquals(4, container1.getTasks().size());
// Tasks 0,4,8 and 1,5 should stay on the same original containers
assertTrue(container0.getTasks().containsKey(getTaskName(0)));
assertTrue(container0.getTasks().containsKey(getTaskName(4)));
assertTrue(container0.getTasks().containsKey(getTaskName(8)));
assertTrue(container1.getTasks().containsKey(getTaskName(1)));
assertTrue(container1.getTasks().containsKey(getTaskName(5)));
// Tasks 2,6 and 3,7 should be reassigned to the new containers.
// Consistency is the goal with these reassignments
assertTrue(container0.getTasks().containsKey(getTaskName(6)));
assertTrue(container0.getTasks().containsKey(getTaskName(2)));
assertTrue(container1.getTasks().containsKey(getTaskName(7)));
assertTrue(container1.getTasks().containsKey(getTaskName(3)));
}
Aggregations