Search in sources :

Example 11 with JobStatus

use of org.apache.metron.job.JobStatus in project metron by apache.

the class PcapServiceImpl method submit.

@Override
public PcapStatus submit(String username, PcapRequest pcapRequest) throws RestException {
    List<PcapStatus> runningJobs = getJobStatus(username, JobStatus.State.RUNNING);
    Integer userJobLimit = environment.getProperty(MetronRestConstants.USER_JOB_LIMIT_SPRING_PROPERTY, Integer.class, 1);
    if (runningJobs != null && runningJobs.size() >= userJobLimit) {
        String jobIds = runningJobs.stream().map(PcapStatus::getJobId).collect(Collectors.joining(", "));
        String message = String.format("Cannot submit job because a job is already running.  " + "Please contact the administrator to cancel job(s) with id(s) %s", jobIds);
        throw new RestException(message);
    }
    try {
        setPcapOptions(username, pcapRequest);
        pcapRequest.setFields();
        pcapJobSupplier.setPcapRequest(pcapRequest);
        JobStatus jobStatus = jobManager.submit(pcapJobSupplier, username);
        return jobStatusToPcapStatus(jobStatus);
    } catch (IOException | JobException e) {
        throw new RestException(e);
    }
}
Also used : JobStatus(org.apache.metron.job.JobStatus) JobException(org.apache.metron.job.JobException) RestException(org.apache.metron.rest.RestException) IOException(java.io.IOException) PcapStatus(org.apache.metron.rest.model.pcap.PcapStatus)

Example 12 with JobStatus

use of org.apache.metron.job.JobStatus in project metron by apache.

the class PcapControllerIntegrationTest method testKillJob.

@Test
public void testKillJob() throws Exception {
    MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
    this.mockMvc.perform(get(pcapUrl + "/jobId123").with(httpBasic(user, password))).andExpect(status().isNotFound());
    mockPcapJob.setStatus(new JobStatus().withJobId("jobId123").withState(JobStatus.State.RUNNING));
    this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobId").value("jobId123")).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
    mockPcapJob.setStatus(new JobStatus().withJobId("jobId123").withState(JobStatus.State.KILLED));
    this.mockMvc.perform(delete(pcapUrl + "/kill/{id}", "jobId123").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobId").value("jobId123")).andExpect(jsonPath("$.jobStatus").value("KILLED"));
    mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.KILLED));
}
Also used : JobStatus(org.apache.metron.job.JobStatus) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with JobStatus

use of org.apache.metron.job.JobStatus in project metron by apache.

the class PcapControllerIntegrationTest method testFixedRequest.

@Test
public void testFixedRequest() throws Exception {
    MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
    mockPcapJob.setStatus(new JobStatus().withState(JobStatus.State.RUNNING));
    this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
    assertEquals("/base/path", mockPcapJob.getBasePath());
    assertEquals("/base/interim/result/path", mockPcapJob.getBaseInterrimResultPath());
    assertEquals("/final/output/path", mockPcapJob.getFinalOutputPath());
    assertEquals(10000000, mockPcapJob.getStartTimeNs());
    assertEquals(20000000, mockPcapJob.getEndTimeNs());
    assertEquals(2, mockPcapJob.getNumReducers());
    assertTrue(mockPcapJob.getFilterImpl() instanceof FixedPcapFilter.Configurator);
    Map<String, String> actualFixedFields = mockPcapJob.getFixedFields();
    assertEquals("192.168.1.2", actualFixedFields.get(Constants.Fields.SRC_ADDR.getName()));
    assertEquals("2000", actualFixedFields.get(Constants.Fields.SRC_PORT.getName()));
    assertEquals("192.168.1.1", actualFixedFields.get(Constants.Fields.DST_ADDR.getName()));
    assertEquals("1000", actualFixedFields.get(Constants.Fields.DST_PORT.getName()));
    assertEquals("true", actualFixedFields.get(Constants.Fields.INCLUDES_REVERSE_TRAFFIC.getName()));
    assertEquals("TCP", actualFixedFields.get(Constants.Fields.PROTOCOL.getName()));
    assertEquals("filter", actualFixedFields.get(PcapHelper.PacketFields.PACKET_FILTER.getName()));
}
Also used : JobStatus(org.apache.metron.job.JobStatus) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) FixedPcapFilter(org.apache.metron.pcap.filter.fixed.FixedPcapFilter) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with JobStatus

use of org.apache.metron.job.JobStatus in project metron by apache.

the class PcapControllerIntegrationTest method testGetPdml.

@Test
public void testGetPdml() throws Exception {
    MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
    mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.RUNNING));
    this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobId").value("jobId")).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
    Pageable<Path> pageable = new PcapPages(Arrays.asList(new Path("./target")));
    mockPcapJob.setIsDone(true);
    mockPcapJob.setPageable(pageable);
    this.mockMvc.perform(get(pcapUrl + "/jobId/pdml?page=1").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.version").value("0")).andExpect(jsonPath("$.creator").value("wireshark/2.6.1")).andExpect(jsonPath("$.time").value("Thu Jun 28 14:14:38 2018")).andExpect(jsonPath("$.captureFile").value("/tmp/pcap-data-201806272004-289365c53112438ca55ea047e13a12a5+0001.pcap")).andExpect(jsonPath("$.packets[0].protos[0].name").value("geninfo")).andExpect(jsonPath("$.packets[0].protos[0].fields[0].name").value("num")).andExpect(jsonPath("$.packets[0].protos[1].name").value("ip")).andExpect(jsonPath("$.packets[0].protos[1].fields[0].name").value("ip.addr"));
    this.mockMvc.perform(get(pcapUrl + "/jobId/pdml?page=0").with(httpBasic(user, password))).andExpect(status().isNotFound());
    this.mockMvc.perform(get(pcapUrl + "/jobId/pdml?page=2").with(httpBasic(user, password))).andExpect(status().isNotFound());
}
Also used : JobStatus(org.apache.metron.job.JobStatus) Path(org.apache.hadoop.fs.Path) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) PcapPages(org.apache.metron.pcap.PcapPages) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with JobStatus

use of org.apache.metron.job.JobStatus in project metron by apache.

the class PcapControllerIntegrationTest method testGetFixedFilterConfiguration.

@Test
public void testGetFixedFilterConfiguration() throws Exception {
    MockPcapJob mockPcapJob = (MockPcapJob) wac.getBean("mockPcapJob");
    mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withState(JobStatus.State.RUNNING));
    this.mockMvc.perform(post(pcapUrl + "/fixed").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(fixedJson)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.jobId").value("jobId")).andExpect(jsonPath("$.jobStatus").value("RUNNING"));
    this.mockMvc.perform(get(pcapUrl + "/jobId/config").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.basePath").value("/base/path")).andExpect(jsonPath("$.finalOutputPath").value("/final/output/path")).andExpect(jsonPath("$.startTimeMs").value(10)).andExpect(jsonPath("$.endTimeMs").value(20)).andExpect(jsonPath("$.numReducers").value(2)).andExpect(jsonPath("$.ipSrcAddr").value("192.168.1.2")).andExpect(jsonPath("$.ipDstAddr").value("192.168.1.1")).andExpect(jsonPath("$.ipSrcPort").value("2000")).andExpect(jsonPath("$.ipDstPort").value("1000")).andExpect(jsonPath("$.protocol").value("TCP")).andExpect(jsonPath("$.packetFilter").value("filter")).andExpect(jsonPath("$.includeReverse").value("true"));
}
Also used : JobStatus(org.apache.metron.job.JobStatus) MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

JobStatus (org.apache.metron.job.JobStatus)21 Test (org.junit.jupiter.api.Test)18 MockPcapJob (org.apache.metron.rest.mock.MockPcapJob)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 Path (org.apache.hadoop.fs.Path)10 PcapPages (org.apache.metron.pcap.PcapPages)5 IOException (java.io.IOException)3 JobException (org.apache.metron.job.JobException)3 FixedPcapFilter (org.apache.metron.pcap.filter.fixed.FixedPcapFilter)2 File (java.io.File)1 QueryPcapFilter (org.apache.metron.pcap.filter.query.QueryPcapFilter)1 RestException (org.apache.metron.rest.RestException)1 PcapStatus (org.apache.metron.rest.model.pcap.PcapStatus)1