use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestJobModelCalculator method testNoPreviousTasksAssignsNewChangelogPartitions.
@Test
public void testNoPreviousTasksAssignsNewChangelogPartitions() {
Config config = config(ImmutableList.of(SYSTEM_STREAM0, SYSTEM_STREAM1), ImmutableMap.of());
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))));
JobModel expected = new JobModel(config, containerModels);
JobModel actual = JobModelCalculator.INSTANCE.calculateJobModel(config, ImmutableMap.of(), this.streamMetadataCache, this.grouperMetadata);
assertEquals(expected, actual);
}
use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestJobModelServingContext method testSetGet.
@Test
public void testSetGet() throws IOException {
// return empty if no job model has been set
assertFalse(this.jobModelServingContext.getSerializedJobModel().isPresent());
Config config = new MapConfig(ImmutableMap.of("samza.user.config", "config-value"));
Map<String, ContainerModel> containerModelMap = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(new TaskName("Partition 0"), new TaskModel(new TaskName("Partition 0"), ImmutableSet.of(new SystemStreamPartition("system", "stream", new Partition(0))), new Partition(0)))));
JobModel jobModel = new JobModel(config, containerModelMap);
this.jobModelServingContext.setJobModel(jobModel);
Optional<byte[]> serializedJobModel = this.jobModelServingContext.getSerializedJobModel();
assertTrue(serializedJobModel.isPresent());
assertEquals(jobModel, SamzaObjectMapper.getObjectMapper().readValue(serializedJobModel.get(), JobModel.class));
config = new MapConfig(ImmutableMap.of("samza.user.config0", "config-value0"));
containerModelMap = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(new TaskName("Partition 0"), new TaskModel(new TaskName("Partition 0"), ImmutableSet.of(new SystemStreamPartition("system0", "stream0", new Partition(0))), new Partition(0)))));
jobModel = new JobModel(config, containerModelMap);
this.jobModelServingContext.setJobModel(jobModel);
serializedJobModel = this.jobModelServingContext.getSerializedJobModel();
assertTrue(serializedJobModel.isPresent());
assertEquals(jobModel, SamzaObjectMapper.getObjectMapper().readValue(serializedJobModel.get(), JobModel.class));
}
use of org.apache.samza.job.model.ContainerModel in project samza by apache.
the class TestJobModelHelper method testNewStandbyContainers.
@Test
public void testNewStandbyContainers() {
Map<String, ContainerModel> oldContainerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1))));
setupOldTaskAssignments(oldContainerModels);
Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1))), "0-0", new ContainerModel("0-0", ImmutableMap.of(standbyTaskName(0, 0), standbyTaskModel(0, 0))), "1-0", new ContainerModel("1-0", ImmutableMap.of(standbyTaskName(1, 0), standbyTaskModel(1, 0))));
runAndCheckNewJobModel(config(), containerModels);
verifyGrouperMetadata(anyHostProcessorIdToLocationId(), anyHostTaskNameToLocationId(2), activeTaskToSSPs(oldContainerModels), activeTaskToContainer(oldContainerModels));
// TaskAssignmentManager.deleteTaskContainerMappings is called once due to change in standby task count
verifyNewTaskAssignments(ImmutableSet.of(), null, containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
use of org.apache.samza.job.model.ContainerModel 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.job.model.ContainerModel in project samza by apache.
the class TestJobModelHelper method testNoPreviousJob.
@Test
public void testNoPreviousJob() {
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(anyHostProcessorIdToLocationId(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of());
verifyNewTaskAssignments(ImmutableSet.of(), allSSPs(containerModels), containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
Aggregations