Search in sources :

Example 71 with TaskName

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);
}
Also used : HashMap(java.util.HashMap) GrouperMetadataImpl(org.apache.samza.container.grouper.task.GrouperMetadataImpl) LocationId(org.apache.samza.runtime.LocationId) ContainerModel(org.apache.samza.job.model.ContainerModel) ProcessorNode(org.apache.samza.zk.ZkUtils.ProcessorNode) TaskName(org.apache.samza.container.TaskName) List(java.util.List) ArrayList(java.util.ArrayList) JobModel(org.apache.samza.job.model.JobModel) TaskModel(org.apache.samza.job.model.TaskModel) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition)

Example 72 with TaskName

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());
}
Also used : JobCoordinatorListener(org.apache.samza.coordinator.JobCoordinatorListener) NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) TaskName(org.apache.samza.container.TaskName) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) ContainerModel(org.apache.samza.job.model.ContainerModel) Test(org.junit.Test)

Example 73 with TaskName

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

Example 74 with TaskName

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

Example 75 with TaskName

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

Aggregations

TaskName (org.apache.samza.container.TaskName)212 HashMap (java.util.HashMap)136 Test (org.junit.Test)133 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)117 Partition (org.apache.samza.Partition)106 MapConfig (org.apache.samza.config.MapConfig)92 TaskModel (org.apache.samza.job.model.TaskModel)90 Map (java.util.Map)75 Set (java.util.Set)73 Config (org.apache.samza.config.Config)71 ContainerModel (org.apache.samza.job.model.ContainerModel)63 ImmutableMap (com.google.common.collect.ImmutableMap)53 File (java.io.File)53 SystemStream (org.apache.samza.system.SystemStream)52 ImmutableSet (com.google.common.collect.ImmutableSet)50 TaskMode (org.apache.samza.job.model.TaskMode)46 TaskConfig (org.apache.samza.config.TaskConfig)43 ImmutableList (com.google.common.collect.ImmutableList)42 Collections (java.util.Collections)41 CheckpointId (org.apache.samza.checkpoint.CheckpointId)41