Search in sources :

Example 6 with JobManager

use of org.apache.metron.job.manager.JobManager in project metron by apache.

the class PcapServiceImplTest method submitShouldProperlySubmitQueryPcapRequest.

@Test
public void submitShouldProperlySubmitQueryPcapRequest() throws Exception {
    QueryPcapRequest queryPcapRequest = new QueryPcapRequest();
    queryPcapRequest.setBasePath("basePath");
    queryPcapRequest.setBaseInterimResultPath("baseOutputPath");
    queryPcapRequest.setFinalOutputPath("finalOutputPath");
    queryPcapRequest.setStartTimeMs(1L);
    queryPcapRequest.setEndTimeMs(2L);
    queryPcapRequest.setNumReducers(2);
    queryPcapRequest.setQuery("query");
    MockPcapJob mockPcapJob = new MockPcapJob();
    mockPcapJobSupplier.setMockPcapJob(mockPcapJob);
    JobManager jobManager = new InMemoryJobManager<>();
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper));
    FileSystem fileSystem = mock(FileSystem.class);
    doReturn(fileSystem).when(pcapService).getFileSystem();
    mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withDescription("description").withPercentComplete(0L).withState(JobStatus.State.RUNNING));
    String expectedFields = "query";
    PcapStatus expectedPcapStatus = new PcapStatus();
    expectedPcapStatus.setJobId("jobId");
    expectedPcapStatus.setJobStatus(JobStatus.State.RUNNING.name());
    expectedPcapStatus.setDescription("description");
    assertEquals(expectedPcapStatus, pcapService.submit("user", queryPcapRequest));
    assertEquals(expectedPcapStatus, pcapService.jobStatusToPcapStatus(jobManager.getJob("user", "jobId").getStatus()));
    assertEquals("basePath", mockPcapJob.getBasePath());
    assertEquals("baseOutputPath", mockPcapJob.getBaseInterrimResultPath());
    assertEquals("finalOutputPath", mockPcapJob.getFinalOutputPath());
    assertEquals(1000000, mockPcapJob.getStartTimeNs());
    assertEquals(2000000, mockPcapJob.getEndTimeNs());
    assertEquals(2, mockPcapJob.getNumReducers());
    assertEquals(100, mockPcapJob.getRecPerFile());
    assertTrue(mockPcapJob.getFilterImpl() instanceof QueryPcapFilter.Configurator);
    Map<String, String> actualFixedFields = mockPcapJob.getFixedFields();
    assertEquals("query", mockPcapJob.getQuery());
}
Also used : QueryPcapFilter(org.apache.metron.pcap.filter.query.QueryPcapFilter) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) FileSystem(org.apache.hadoop.fs.FileSystem) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Example 7 with JobManager

use of org.apache.metron.job.manager.JobManager in project metron by apache.

the class PcapServiceImplTest method fixedShouldThrowRestException.

@Test
public void fixedShouldThrowRestException() throws Exception {
    FixedPcapRequest fixedPcapRequest = new FixedPcapRequest();
    JobManager jobManager = mock(JobManager.class);
    PcapJobSupplier pcapJobSupplier = new PcapJobSupplier();
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, pcapJobSupplier, jobManager, pcapToPdmlScriptWrapper));
    FileSystem fileSystem = mock(FileSystem.class);
    doReturn(fileSystem).when(pcapService).getFileSystem();
    when(jobManager.submit(pcapJobSupplier, "user")).thenThrow(new JobException("some job exception"));
    RestException e = assertThrows(RestException.class, () -> pcapService.submit("user", fixedPcapRequest));
    assertEquals("some job exception", e.getMessage());
}
Also used : MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) FileSystem(org.apache.hadoop.fs.FileSystem) RestException(org.apache.metron.rest.RestException) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Example 8 with JobManager

use of org.apache.metron.job.manager.JobManager in project metron by apache.

the class PcapServiceImplTest method getConfigurationShouldThrowRestException.

@Test
public void getConfigurationShouldThrowRestException() throws Exception {
    JobManager jobManager = mock(JobManager.class);
    when(jobManager.getJob("user", "jobId")).thenThrow(new JobException("some job exception"));
    PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper);
    RestException e = assertThrows(RestException.class, () -> pcapService.getConfiguration("user", "jobId"));
    assertEquals("some job exception", e.getMessage());
}
Also used : MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) RestException(org.apache.metron.rest.RestException) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Example 9 with JobManager

use of org.apache.metron.job.manager.JobManager in project metron by apache.

the class PcapServiceImplTest method killJobShouldKillJobAndReportStatus.

@Test
public void killJobShouldKillJobAndReportStatus() throws Exception {
    MockPcapJob mockPcapJob = mock(MockPcapJob.class);
    JobManager jobManager = mock(JobManager.class);
    JobStatus actualJobStatus = new JobStatus().withJobId("jobId").withState(JobStatus.State.KILLED).withDescription("description").withPercentComplete(100.0);
    Pageable pageable = mock(Pageable.class);
    when(pageable.getSize()).thenReturn(0);
    when(mockPcapJob.getStatus()).thenReturn(actualJobStatus);
    when(mockPcapJob.isDone()).thenReturn(true);
    when(mockPcapJob.get()).thenReturn(pageable);
    when(jobManager.getJob("user", "jobId")).thenReturn(mockPcapJob);
    PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper);
    PcapStatus status = pcapService.killJob("user", "jobId");
    verify(jobManager, times(1)).killJob("user", "jobId");
    assertThat(status.getJobStatus(), CoreMatchers.equalTo(JobStatus.State.KILLED.toString()));
}
Also used : MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Example 10 with JobManager

use of org.apache.metron.job.manager.JobManager in project metron by apache.

the class PcapServiceImplTest method killNonExistentJobShouldReturnNull.

@Test
public void killNonExistentJobShouldReturnNull() throws Exception {
    MockPcapJob mockPcapJob = mock(MockPcapJob.class);
    JobManager jobManager = mock(JobManager.class);
    doThrow(new JobNotFoundException("Not found test exception.")).when(jobManager).killJob("user", "jobId");
    PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper);
    PcapStatus status = pcapService.killJob("user", "jobId");
    verify(jobManager, times(1)).killJob("user", "jobId");
    assertNull(status);
}
Also used : MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Aggregations

InMemoryJobManager (org.apache.metron.job.manager.InMemoryJobManager)16 JobManager (org.apache.metron.job.manager.JobManager)16 Test (org.junit.jupiter.api.Test)16 MockPcapJob (org.apache.metron.rest.mock.MockPcapJob)12 FileSystem (org.apache.hadoop.fs.FileSystem)6 PcapJobSupplier (org.apache.metron.rest.config.PcapJobSupplier)6 MockPcapJobSupplier (org.apache.metron.rest.mock.MockPcapJobSupplier)6 RestException (org.apache.metron.rest.RestException)3 Path (org.apache.hadoop.fs.Path)2 FixedPcapFilter (org.apache.metron.pcap.filter.fixed.FixedPcapFilter)2 HashMap (java.util.HashMap)1 QueryPcapFilter (org.apache.metron.pcap.filter.query.QueryPcapFilter)1