use of org.apache.samza.rest.model.Partition in project samza by apache.
the class TestTasksResource method testGetTasks.
@Test
public void testGetTasks() throws IOException {
String requestUrl = String.format("v1/jobs/%s/%s/tasks", "testJobName", "testJobId");
Response response = target(requestUrl).request().get();
assertEquals(200, response.getStatus());
Task[] tasks = objectMapper.readValue(response.readEntity(String.class), Task[].class);
assertEquals(2, tasks.length);
List<Partition> partitionList = ImmutableList.of(new Partition(MockTaskProxy.SYSTEM_NAME, MockTaskProxy.STREAM_NAME, MockTaskProxy.PARTITION_ID));
assertEquals(null, tasks[0].getPreferredHost());
assertEquals(MockTaskProxy.TASK_1_CONTAINER_ID, tasks[0].getContainerId());
assertEquals(MockTaskProxy.TASK_1_NAME, tasks[0].getTaskName());
assertEquals(partitionList, tasks[0].getPartitions());
assertEquals(null, tasks[1].getPreferredHost());
assertEquals(MockTaskProxy.TASK_2_CONTAINER_ID, tasks[1].getContainerId());
assertEquals(MockTaskProxy.TASK_2_NAME, tasks[1].getTaskName());
assertEquals(partitionList, tasks[1].getPartitions());
}
use of org.apache.samza.rest.model.Partition in project samza by apache.
the class SamzaTaskProxy method getTasks.
/**
* Fetches the complete job model from the coordinator stream based upon the provided {@link JobInstance}
* param, transforms it to a list of {@link Task} and returns it.
* {@inheritDoc}
*/
@Override
public List<Task> getTasks(JobInstance jobInstance) throws IOException, InterruptedException {
Preconditions.checkArgument(installFinder.isInstalled(jobInstance), String.format("Invalid job instance : %s", jobInstance));
JobModel jobModel = getJobModel(jobInstance);
StorageConfig storageConfig = new StorageConfig(jobModel.getConfig());
List<String> storeNames = JavaConverters.seqAsJavaListConverter(storageConfig.getStoreNames()).asJava();
Map<String, String> containerLocality = jobModel.getAllContainerLocality();
List<Task> tasks = new ArrayList<>();
for (ContainerModel containerModel : jobModel.getContainers().values()) {
String containerId = containerModel.getProcessorId();
String host = containerLocality.get(containerId);
for (TaskModel taskModel : containerModel.getTasks().values()) {
String taskName = taskModel.getTaskName().getTaskName();
List<Partition> partitions = taskModel.getSystemStreamPartitions().stream().map(Partition::new).collect(Collectors.toList());
tasks.add(new Task(host, taskName, containerId, partitions, storeNames));
}
}
return tasks;
}
Aggregations