Search in sources :

Example 6 with LocationId

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());
}
Also used : TaskName(org.apache.samza.container.TaskName) LocationId(org.apache.samza.runtime.LocationId) Test(org.junit.Test)

Example 7 with LocationId

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());
}
Also used : TaskName(org.apache.samza.container.TaskName) LocationId(org.apache.samza.runtime.LocationId) Test(org.junit.Test)

Example 8 with LocationId

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));
}
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 9 with LocationId

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));
}
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 10 with LocationId

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;
}
Also used : TaskName(org.apache.samza.container.TaskName) HashMap(java.util.HashMap) LocationId(org.apache.samza.runtime.LocationId) ArrayList(java.util.ArrayList)

Aggregations

LocationId (org.apache.samza.runtime.LocationId)16 TaskName (org.apache.samza.container.TaskName)13 ContainerModel (org.apache.samza.job.model.ContainerModel)11 Test (org.junit.Test)11 TaskModel (org.apache.samza.job.model.TaskModel)9 HashMap (java.util.HashMap)7 Partition (org.apache.samza.Partition)6 ContainerMocks.getTaskName (org.apache.samza.container.mock.ContainerMocks.getTaskName)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 ProcessorLocality (org.apache.samza.job.model.ProcessorLocality)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Collections (java.util.Collections)2 Optional (java.util.Optional)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Config (org.apache.samza.config.Config)2 JobConfig (org.apache.samza.config.JobConfig)2