Search in sources :

Example 1 with Partition

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());
}
Also used : Response(javax.ws.rs.core.Response) Partition(org.apache.samza.rest.model.Partition) Task(org.apache.samza.rest.model.Task) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 2 with Partition

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;
}
Also used : Partition(org.apache.samza.rest.model.Partition) Task(org.apache.samza.rest.model.Task) StorageConfig(org.apache.samza.config.StorageConfig) ArrayList(java.util.ArrayList) JobModel(org.apache.samza.job.model.JobModel) TaskModel(org.apache.samza.job.model.TaskModel) ContainerModel(org.apache.samza.job.model.ContainerModel)

Aggregations

Partition (org.apache.samza.rest.model.Partition)2 Task (org.apache.samza.rest.model.Task)2 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 StorageConfig (org.apache.samza.config.StorageConfig)1 ContainerModel (org.apache.samza.job.model.ContainerModel)1 JobModel (org.apache.samza.job.model.JobModel)1 TaskModel (org.apache.samza.job.model.TaskModel)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1