org.apache.samza.zk.ZkUtils.readTaskLocality()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中org.apache.samza.zk.ZkUtils.readTaskLocality()方法的一些代码示例,展示了ZkUtils.readTaskLocality()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkUtils.readTaskLocality()方法的具体详情如下:
包路径:org.apache.samza.zk.ZkUtils
类名称:ZkUtils
方法名:readTaskLocality

ZkUtils.readTaskLocality介绍

暂无

代码示例

代码示例来源:origin: apache/samza

@Test
public void testReadWhenTaskLocalityDoesNotExist() {
 Map<TaskName, LocationId> taskLocality = zkUtils.readTaskLocality();
 Assert.assertEquals(0, taskLocality.size());
}

代码示例来源:origin: apache/samza

/**
 * 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 = zkUtils.getJobModel(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);
}

代码示例来源:origin: apache/samza

@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());
}

代码示例来源:origin: apache/samza

@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());
}

代码示例来源:origin: apache/samza

@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());
}

相关文章