Search in sources :

Example 11 with InMemoryJobManager

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

the class PcapServiceImplTest method getStatusShouldReturnNullOnMissingStatus.

@Test
public void getStatusShouldReturnNullOnMissingStatus() throws Exception {
    JobManager jobManager = new InMemoryJobManager();
    PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper);
    assertNull(pcapService.getJobStatus("user", "jobId"));
}
Also used : InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Example 12 with InMemoryJobManager

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

the class PcapServiceImplTest method submitShouldProperlySubmitWithDefaults.

@Test
public void submitShouldProperlySubmitWithDefaults() throws Exception {
    long beforeJobTime = System.currentTimeMillis();
    FixedPcapRequest fixedPcapRequest = new FixedPcapRequest();
    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));
    PcapStatus expectedPcapStatus = new PcapStatus();
    expectedPcapStatus.setJobId("jobId");
    expectedPcapStatus.setJobStatus(JobStatus.State.RUNNING.name());
    expectedPcapStatus.setDescription("description");
    assertEquals(expectedPcapStatus, pcapService.submit("user", fixedPcapRequest));
    assertEquals("/base/path", mockPcapJob.getBasePath());
    assertEquals("/base/interim/result/path", mockPcapJob.getBaseInterrimResultPath());
    assertEquals("/final/output/path", mockPcapJob.getFinalOutputPath());
    assertEquals(0, mockPcapJob.getStartTimeNs());
    assertTrue(beforeJobTime <= mockPcapJob.getEndTimeNs() / 1000000);
    assertTrue(System.currentTimeMillis() >= mockPcapJob.getEndTimeNs() / 1000000);
    assertEquals(10, mockPcapJob.getNumReducers());
    assertEquals(100, mockPcapJob.getRecPerFile());
    assertTrue(mockPcapJob.getFilterImpl() instanceof FixedPcapFilter.Configurator);
    assertEquals(new HashMap<>(), mockPcapJob.getFixedFields());
}
Also used : 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) FixedPcapFilter(org.apache.metron.pcap.filter.fixed.FixedPcapFilter) Test(org.junit.jupiter.api.Test)

Example 13 with InMemoryJobManager

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

the class PcapServiceImplTest method getRawShouldProperlyReturnInputStream.

@Test
public void getRawShouldProperlyReturnInputStream() throws Exception {
    FSDataInputStream inputStream = mock(FSDataInputStream.class);
    Path path = new Path("./target");
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), new PcapToPdmlScriptWrapper()));
    FileSystem fileSystem = mock(FileSystem.class);
    doReturn(fileSystem).when(pcapService).getFileSystem();
    when(fileSystem.exists(path)).thenReturn(true);
    doReturn(path).when(pcapService).getPath("user", "jobId", 1);
    when(fileSystem.open(path)).thenReturn(inputStream);
    assertEquals(inputStream, pcapService.getRawPcap("user", "jobId", 1));
}
Also used : Path(org.apache.hadoop.fs.Path) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) Test(org.junit.jupiter.api.Test)

Example 14 with InMemoryJobManager

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

the class PcapServiceImplTest method getPdmlShouldThrowException.

@Test
public void getPdmlShouldThrowException() throws Exception {
    Path path = new Path("./target");
    PcapToPdmlScriptWrapper pcapToPdmlScriptWrapper = spy(new PcapToPdmlScriptWrapper());
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
    FileSystem fileSystem = mock(FileSystem.class);
    doReturn(fileSystem).when(pcapService).getFileSystem();
    when(fileSystem.exists(path)).thenReturn(true);
    doReturn(path).when(pcapService).getPath("user", "jobId", 1);
    ProcessBuilder pb = mock(ProcessBuilder.class);
    doReturn(pb).when(pcapToPdmlScriptWrapper).getProcessBuilder("/path/to/pdml/script", "target");
    when(pb.start()).thenThrow(new IOException("some exception"));
    RestException e = assertThrows(RestException.class, () -> pcapService.getPdml("user", "jobId", 1));
    assertEquals("some exception", e.getMessage());
}
Also used : Path(org.apache.hadoop.fs.Path) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) 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) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 15 with InMemoryJobManager

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

the class PcapServiceImplTest method submitShouldThrowExceptionOnRunningJobFound.

@Test
public void submitShouldThrowExceptionOnRunningJobFound() throws Exception {
    PcapStatus runningStatus1 = new PcapStatus();
    runningStatus1.setJobStatus("RUNNING");
    runningStatus1.setJobId("jobId1");
    PcapStatus runningStatus2 = new PcapStatus();
    runningStatus2.setJobStatus("RUNNING");
    runningStatus2.setJobId("jobId2");
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
    doReturn(Arrays.asList(runningStatus1, runningStatus2)).when(pcapService).getJobStatus("user", JobStatus.State.RUNNING);
    when(environment.getProperty(MetronRestConstants.USER_JOB_LIMIT_SPRING_PROPERTY, Integer.class, 1)).thenReturn(2);
    RestException e = assertThrows(RestException.class, () -> pcapService.submit("user", new FixedPcapRequest()));
    assertTrue(e.getMessage().contains("Cannot submit job because a job is already running.  Please contact the administrator to cancel job(s) with id(s) jobId"));
}
Also used : InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) RestException(org.apache.metron.rest.RestException) Test(org.junit.jupiter.api.Test)

Aggregations

InMemoryJobManager (org.apache.metron.job.manager.InMemoryJobManager)15 Test (org.junit.jupiter.api.Test)14 FileSystem (org.apache.hadoop.fs.FileSystem)12 PcapJobSupplier (org.apache.metron.rest.config.PcapJobSupplier)8 MockPcapJobSupplier (org.apache.metron.rest.mock.MockPcapJobSupplier)8 Path (org.apache.hadoop.fs.Path)7 JobManager (org.apache.metron.job.manager.JobManager)6 MockPcapJob (org.apache.metron.rest.mock.MockPcapJob)5 RestException (org.apache.metron.rest.RestException)3 IOException (java.io.IOException)2 FixedPcapFilter (org.apache.metron.pcap.filter.fixed.FixedPcapFilter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 QueryPcapFilter (org.apache.metron.pcap.filter.query.QueryPcapFilter)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1