use of org.apache.samza.container.TaskName in project samza by apache.
the class ZkJobCoordinator method getGrouperMetadata.
/**
* Builds the {@link GrouperMetadataImpl} based upon provided {@param jobModelVersion}
* and {@param processorNodes}.
* @param jobModelVersion the most recent jobModelVersion available in the zookeeper.
* @param processorNodes the list of live processors in the zookeeper.
* @return the built grouper metadata.
*/
private GrouperMetadataImpl getGrouperMetadata(String jobModelVersion, List<ProcessorNode> processorNodes) {
Map<TaskName, String> taskToProcessorId = new HashMap<>();
Map<TaskName, List<SystemStreamPartition>> taskToSSPs = new HashMap<>();
if (jobModelVersion != null) {
JobModel jobModel = readJobModelFromMetadataStore(jobModelVersion);
for (ContainerModel containerModel : jobModel.getContainers().values()) {
for (TaskModel taskModel : containerModel.getTasks().values()) {
taskToProcessorId.put(taskModel.getTaskName(), containerModel.getId());
for (SystemStreamPartition partition : taskModel.getSystemStreamPartitions()) {
taskToSSPs.computeIfAbsent(taskModel.getTaskName(), k -> new ArrayList<>());
taskToSSPs.get(taskModel.getTaskName()).add(partition);
}
}
}
}
Map<String, LocationId> processorLocality = new HashMap<>();
for (ProcessorNode processorNode : processorNodes) {
ProcessorData processorData = processorNode.getProcessorData();
processorLocality.put(processorData.getProcessorId(), processorData.getLocationId());
}
Map<TaskName, LocationId> taskLocality = zkUtils.readTaskLocality();
return new GrouperMetadataImpl(processorLocality, taskLocality, taskToSSPs, taskToProcessorId);
}
use of org.apache.samza.container.TaskName in project samza by apache.
the class TestZkJobCoordinator method testOnNewJobModelWithChangeInWorkAssignment.
@Test
public void testOnNewJobModelWithChangeInWorkAssignment() {
final TaskName taskName = new TaskName("task1");
final ContainerModel mockContainerModel = mock(ContainerModel.class);
final JobCoordinatorListener mockListener = mock(JobCoordinatorListener.class);
final JobModel mockJobModel = mock(JobModel.class);
when(mockContainerModel.getTasks()).thenReturn(ImmutableMap.of(taskName, mock(TaskModel.class)));
when(mockJobModel.getContainers()).thenReturn(ImmutableMap.of(PROCESSOR_ID, mockContainerModel));
ZkJobCoordinator zkJobCoordinator = new ZkJobCoordinator(PROCESSOR_ID, new MapConfig(), new NoOpMetricsRegistry(), zkUtils, zkMetadataStore, coordinatorStreamStore);
zkJobCoordinator.setListener(mockListener);
zkJobCoordinator.setJobModelExpired(true);
zkJobCoordinator.onNewJobModel(mockJobModel);
verify(zkUtils, times(1)).writeTaskLocality(eq(taskName), any());
verify(mockListener, times(1)).onNewJobModel(PROCESSOR_ID, mockJobModel);
assertEquals("Active job model should be updated with the new job model", mockJobModel, zkJobCoordinator.getActiveJobModel());
}
use of org.apache.samza.container.TaskName in project samza by apache.
the class TestZkUtils method testReadTaskLocalityShouldReturnAllTheExistingLocalityValue.
@Test
public void testReadTaskLocalityShouldReturnAllTheExistingLocalityValue() {
zkUtils.writeTaskLocality(new TaskName("task-1"), new LocationId("LocationId-1"));
zkUtils.writeTaskLocality(new TaskName("task-2"), new LocationId("LocationId-2"));
zkUtils.writeTaskLocality(new TaskName("task-3"), new LocationId("LocationId-3"));
zkUtils.writeTaskLocality(new TaskName("task-4"), new LocationId("LocationId-4"));
zkUtils.writeTaskLocality(new TaskName("task-5"), new LocationId("LocationId-5"));
Map<TaskName, LocationId> taskLocality = ImmutableMap.of(new TaskName("task-1"), new LocationId("LocationId-1"), new TaskName("task-2"), new LocationId("LocationId-2"), new TaskName("task-3"), new LocationId("LocationId-3"), new TaskName("task-4"), new LocationId("LocationId-4"), new TaskName("task-5"), new LocationId("LocationId-5"));
Assert.assertEquals(taskLocality, zkUtils.readTaskLocality());
}
use of org.apache.samza.container.TaskName 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());
}
use of org.apache.samza.container.TaskName 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());
}
Aggregations