Search in sources :

Example 1 with Task

use of org.apache.samza.rest.model.Task in project samza by apache.

the class TestLocalStoreMonitor method shouldDeleteTaskStoreWhenTaskPreferredStoreIsNotLocalHost.

// TODO fix in SAMZA-1243
// @Test
public void shouldDeleteTaskStoreWhenTaskPreferredStoreIsNotLocalHost() throws Exception {
    Task task = new Task("notLocalHost", "test-task", "0", new ArrayList<>(), ImmutableList.of("test-store"));
    Mockito.when(jobsClientMock.getTasks(Mockito.any())).thenReturn(ImmutableList.of(task));
    localStoreMonitor.monitor();
    assertTrue("Task store directory should not exist.", !taskStoreDir.exists());
    assertEquals(taskStoreSize, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount());
    assertEquals(1, localStoreMonitorMetrics.noOfDeletedTaskPartitionStores.getCount());
}
Also used : Task(org.apache.samza.rest.model.Task)

Example 2 with Task

use of org.apache.samza.rest.model.Task in project samza by apache.

the class TestLocalStoreMonitor method shouldContinueLocalStoreCleanUpAfterFailureToCleanUpStoreOfAJob.

@Test
public void shouldContinueLocalStoreCleanUpAfterFailureToCleanUpStoreOfAJob() throws Exception {
    File testFailingJobDir = new File(System.getProperty("java.io.tmpdir") + File.separator + "samza-test-job/", "test-jobName-jobId-1");
    File testFailingTaskStoreDir = new File(new File(testFailingJobDir, "test-store"), "test-task");
    FileUtils.forceMkdir(testFailingTaskStoreDir);
    // For job: test-jobName-jobId-1, throw up in getTasks call and
    // expect the cleanup to succeed for other job: test-jobName-jobId.
    Mockito.doThrow(new RuntimeException("Dummy exception message.")).when(jobsClientMock).getTasks(new JobInstance("test-jobName", "jobId-1"));
    Task task = new Task("notLocalHost", "test-task", "0", new ArrayList<>(), ImmutableList.of("test-store"));
    Mockito.when(jobsClientMock.getTasks(new JobInstance("test-jobName", "jobId"))).thenReturn(ImmutableList.of(task));
    Map<String, String> configMap = new HashMap<>(config);
    configMap.put(LocalStoreMonitorConfig.CONFIG_IGNORE_FAILURES, "true");
    LocalStoreMonitor localStoreMonitor = new LocalStoreMonitor(new LocalStoreMonitorConfig(new MapConfig(configMap)), localStoreMonitorMetrics, jobsClientMock);
    localStoreMonitor.monitor();
    // Non failing job directory should be cleaned up.
    assertTrue("Task store directory should not exist.", !taskStoreDir.exists());
    FileUtils.deleteDirectory(testFailingJobDir);
}
Also used : Task(org.apache.samza.rest.model.Task) JobInstance(org.apache.samza.rest.proxy.job.JobInstance) HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) File(java.io.File) Test(org.junit.Test)

Example 3 with Task

use of org.apache.samza.rest.model.Task in project samza by apache.

the class TestLocalStoreMonitor method setUp.

@Before
public void setUp() throws Exception {
    // Make scaffold directories for testing.
    FileUtils.forceMkdir(taskStoreDir);
    taskStoreSize = taskStoreDir.getTotalSpace();
    // Set default return values for methods.
    Mockito.when(jobsClientMock.getJobStatus(Mockito.any())).thenReturn(JobStatus.STOPPED);
    Task task = new Task("localHost", "test-task", "0", new ArrayList<>(), ImmutableList.of("test-store"));
    Mockito.when(jobsClientMock.getTasks(Mockito.any())).thenReturn(ImmutableList.of(task));
    localStoreMonitorMetrics = new LocalStoreMonitorMetrics("TestMonitorName", new NoOpMetricsRegistry());
    // Initialize the local store monitor with mock and config
    localStoreMonitor = new LocalStoreMonitor(new LocalStoreMonitorConfig(new MapConfig(config)), localStoreMonitorMetrics, jobsClientMock);
}
Also used : Task(org.apache.samza.rest.model.Task) NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) MapConfig(org.apache.samza.config.MapConfig) Before(org.junit.Before)

Example 4 with Task

use of org.apache.samza.rest.model.Task 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 5 with Task

use of org.apache.samza.rest.model.Task 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

Task (org.apache.samza.rest.model.Task)6 File (java.io.File)2 MapConfig (org.apache.samza.config.MapConfig)2 Partition (org.apache.samza.rest.model.Partition)2 JobInstance (org.apache.samza.rest.proxy.job.JobInstance)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 StorageConfig (org.apache.samza.config.StorageConfig)1 TaskName (org.apache.samza.container.TaskName)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 JobStatus (org.apache.samza.rest.model.JobStatus)1 NoOpMetricsRegistry (org.apache.samza.util.NoOpMetricsRegistry)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Before (org.junit.Before)1