Search in sources :

Example 6 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.

the class PcapServiceImplTest method getRawShouldReturnNullOnNonexistentPath.

@Test
public void getRawShouldReturnNullOnNonexistentPath() throws Exception {
    Path path = new Path("/some/path");
    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(false);
    doReturn(path).when(pcapService).getPath("user", "jobId", 1);
    assertNull(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) Test(org.junit.jupiter.api.Test)

Example 7 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier 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 PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier 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 PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.

the class PcapServiceImplTest method getPdmlShouldGetPdml.

@Test
public void getPdmlShouldGetPdml() 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);
    doReturn(new ByteArrayInputStream(pdmlXml.getBytes(StandardCharsets.UTF_8))).when(pcapToPdmlScriptWrapper).getRawInputStream(fileSystem, path);
    ProcessBuilder pb = mock(ProcessBuilder.class);
    Process p = mock(Process.class);
    OutputStream outputStream = new ByteArrayOutputStream();
    when(p.getOutputStream()).thenReturn(outputStream);
    when(p.isAlive()).thenReturn(true);
    when(p.getInputStream()).thenReturn(new ByteArrayInputStream(pdmlXml.getBytes(StandardCharsets.UTF_8)));
    doReturn(pb).when(pcapToPdmlScriptWrapper).getProcessBuilder(any());
    when(pb.start()).thenReturn(p);
    assertEquals(JSONUtils.INSTANCE.load(expectedPdml, Pdml.class), pcapService.getPdml("user", "jobId", 1));
}
Also used : Path(org.apache.hadoop.fs.Path) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) ByteArrayInputStream(java.io.ByteArrayInputStream) MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) FileSystem(org.apache.hadoop.fs.FileSystem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 10 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier 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)

Aggregations

InMemoryJobManager (org.apache.metron.job.manager.InMemoryJobManager)13 PcapJobSupplier (org.apache.metron.rest.config.PcapJobSupplier)13 MockPcapJobSupplier (org.apache.metron.rest.mock.MockPcapJobSupplier)13 Test (org.junit.jupiter.api.Test)13 FileSystem (org.apache.hadoop.fs.FileSystem)8 Path (org.apache.hadoop.fs.Path)8 JobManager (org.apache.metron.job.manager.JobManager)6 RestException (org.apache.metron.rest.RestException)5 IOException (java.io.IOException)2 MockPcapJob (org.apache.metron.rest.mock.MockPcapJob)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1