Search in sources :

Example 36 with ContainerModel

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);
}
Also used : MapConfig(org.apache.samza.config.MapConfig) StorageConfig(org.apache.samza.config.StorageConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) ClusterManagerConfig(org.apache.samza.config.ClusterManagerConfig) TaskConfig(org.apache.samza.config.TaskConfig) JobModel(org.apache.samza.job.model.JobModel) ContainerModel(org.apache.samza.job.model.ContainerModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with ContainerModel

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));
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) TaskName(org.apache.samza.container.TaskName) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) 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 38 with ContainerModel

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));
}
Also used : ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 39 with ContainerModel

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));
}
Also used : ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) LocationId(org.apache.samza.runtime.LocationId) ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 40 with ContainerModel

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));
}
Also used : ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

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