Search in sources :

Example 91 with ContainerModel

use of org.apache.samza.job.model.ContainerModel in project samza by apache.

the class TestJobModelHelper method testAddBroadcastInput.

@Test
public void testAddBroadcastInput() {
    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);
    TaskModel taskModel0 = taskModel(0, ImmutableSet.of(new SystemStreamPartition(SYSTEM_STREAM0, new Partition(0)), new SystemStreamPartition(SYSTEM_STREAM1, new Partition(0))));
    TaskModel taskModel1 = taskModel(1, ImmutableSet.of(new SystemStreamPartition(SYSTEM_STREAM0, new Partition(1)), new SystemStreamPartition(SYSTEM_STREAM1, new Partition(0))));
    Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel0)), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel1)));
    runAndCheckNewJobModel(config(), containerModels);
    verifyGrouperMetadata(anyHostProcessorIdToLocationId(), anyHostTaskNameToLocationId(2), activeTaskToSSPs(oldContainerModels), activeTaskToContainer(oldContainerModels));
    verifyNewTaskAssignments(null, null, containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) TaskModel(org.apache.samza.job.model.TaskModel) ContainerModel(org.apache.samza.job.model.ContainerModel) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 92 with ContainerModel

use of org.apache.samza.job.model.ContainerModel in project samza by apache.

the class TestJobModelHelper method testExistingBroadcastInput.

@Test
public void testExistingBroadcastInput() {
    TaskModel taskModel0 = taskModel(0, ImmutableSet.of(new SystemStreamPartition(SYSTEM_STREAM0, new Partition(0)), new SystemStreamPartition(SYSTEM_STREAM1, new Partition(0))));
    TaskModel taskModel1 = taskModel(1, ImmutableSet.of(new SystemStreamPartition(SYSTEM_STREAM0, new Partition(1)), new SystemStreamPartition(SYSTEM_STREAM1, new Partition(0))));
    Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel0)), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel1)));
    setupOldTaskAssignments(containerModels);
    runAndCheckNewJobModel(config(), containerModels);
    verifyGrouperMetadata(anyHostProcessorIdToLocationId(), anyHostTaskNameToLocationId(2), activeTaskToSSPs(containerModels), activeTaskToContainer(containerModels));
    verifyNewTaskAssignments(null, null, containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) TaskModel(org.apache.samza.job.model.TaskModel) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 93 with ContainerModel

use of org.apache.samza.job.model.ContainerModel in project samza by apache.

the class TestJobModelHelper method testSameJobModelAsPrevious.

@Test
public void testSameJobModelAsPrevious() {
    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))));
    setupOldTaskAssignments(containerModels);
    runAndCheckNewJobModel(config(), containerModels);
    verifyGrouperMetadata(anyHostProcessorIdToLocationId(), anyHostTaskNameToLocationId(4), activeTaskToSSPs(containerModels), activeTaskToContainer(containerModels));
    verifyNewTaskAssignments(null, null, containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
Also used : ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 94 with ContainerModel

use of org.apache.samza.job.model.ContainerModel in project samza by apache.

the class TestJobModelHelper method testNewStandbyTasks.

@Test
public void testNewStandbyTasks() {
    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))), "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))));
    setupOldTaskAssignments(oldContainerModels);
    Map<String, ContainerModel> containerModels = new ImmutableMap.Builder<String, ContainerModel>().put("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0)))).put("1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1)))).put("2", new ContainerModel("2", ImmutableMap.of(taskName(2), taskModel(2, 2)))).put("0-0", new ContainerModel("0-0", ImmutableMap.of(standbyTaskName(0, 0), standbyTaskModel(0, 0)))).put("1-0", new ContainerModel("1-0", ImmutableMap.of(standbyTaskName(1, 0), standbyTaskModel(1, 0)))).put("2-0", new ContainerModel("2-0", ImmutableMap.of(standbyTaskName(2, 0), standbyTaskModel(2, 0)))).build();
    runAndCheckNewJobModel(config(), containerModels);
    verifyGrouperMetadata(anyHostProcessorIdToLocationId(), anyHostTaskNameToLocationId(2), activeTaskToSSPs(oldContainerModels), activeTaskToContainer(oldContainerModels));
    // noinspection unchecked: ArgumentCaptor doesn't ideally handle multiple levels of generics, so need cast
    ArgumentCaptor<Iterable<String>> deleteTaskContainerMappingsCaptor = (ArgumentCaptor<Iterable<String>>) (ArgumentCaptor<?>) ArgumentCaptor.forClass(Iterable.class);
    verify(this.taskAssignmentManager, times(2)).deleteTaskContainerMappings(deleteTaskContainerMappingsCaptor.capture());
    assertEquals(taskNameStrings(oldContainerModels, TaskMode.Active), ImmutableSet.copyOf(deleteTaskContainerMappingsCaptor.getAllValues().get(0)));
    assertEquals(taskNameStrings(oldContainerModels, TaskMode.Standby), ImmutableSet.copyOf(deleteTaskContainerMappingsCaptor.getAllValues().get(1)));
    verify(this.taskPartitionAssignmentManager).delete(allSSPs(containerModels));
    verify(this.taskPartitionAssignmentManager).delete(any());
    verify(this.taskAssignmentManager).writeTaskContainerMappings(containerToTaskToMode(containerModels));
    verify(this.taskAssignmentManager).writeTaskContainerMappings(any());
    verify(this.taskPartitionAssignmentManager).writeTaskPartitionAssignments(sspToTasks(containerModels));
    verify(this.taskPartitionAssignmentManager).writeTaskPartitionAssignments(any());
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableMap(com.google.common.collect.ImmutableMap) ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 95 with ContainerModel

use of org.apache.samza.job.model.ContainerModel in project samza by apache.

the class TestApplicationMasterRestClient method generateContainers.

private HashMap<String, ContainerModel> generateContainers() {
    Set<TaskModel> taskModels = ImmutableSet.of(new TaskModel(new TaskName("task1"), ImmutableSet.of(new SystemStreamPartition(new SystemStream("system1", "stream1"), new Partition(0))), new Partition(0)), new TaskModel(new TaskName("task2"), ImmutableSet.of(new SystemStreamPartition(new SystemStream("system1", "stream1"), new Partition(1))), new Partition(1)));
    GroupByContainerCount grouper = new GroupByContainerCount(2);
    Set<ContainerModel> containerModels = grouper.group(taskModels);
    HashMap<String, ContainerModel> containers = new HashMap<>();
    for (ContainerModel containerModel : containerModels) {
        containers.put(containerModel.getId(), containerModel);
    }
    return containers;
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) GroupByContainerCount(org.apache.samza.container.grouper.task.GroupByContainerCount) TaskName(org.apache.samza.container.TaskName) HashMap(java.util.HashMap) SystemStream(org.apache.samza.system.SystemStream) TaskModel(org.apache.samza.job.model.TaskModel) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) ContainerModel(org.apache.samza.job.model.ContainerModel)

Aggregations

ContainerModel (org.apache.samza.job.model.ContainerModel)96 TaskModel (org.apache.samza.job.model.TaskModel)68 TaskName (org.apache.samza.container.TaskName)60 Test (org.junit.Test)57 HashMap (java.util.HashMap)53 JobModel (org.apache.samza.job.model.JobModel)37 MapConfig (org.apache.samza.config.MapConfig)30 Config (org.apache.samza.config.Config)28 Partition (org.apache.samza.Partition)24 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)22 StorageConfig (org.apache.samza.config.StorageConfig)19 Map (java.util.Map)18 JobConfig (org.apache.samza.config.JobConfig)18 TaskConfig (org.apache.samza.config.TaskConfig)18 HashSet (java.util.HashSet)16 ArrayList (java.util.ArrayList)14 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)12 LocationId (org.apache.samza.runtime.LocationId)12 Collectors (java.util.stream.Collectors)10 SystemStream (org.apache.samza.system.SystemStream)10