Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

METRON-1685: Retrieve Pcap results in raw binary format#1123

Closed
merrimanr wants to merge 56 commits intoapache:feature/METRON-1554-pcap-query-panelfrom
merrimanr:METRON-1685
Closed

METRON-1685: Retrieve Pcap results in raw binary format#1123
merrimanr wants to merge 56 commits intoapache:feature/METRON-1554-pcap-query-panelfrom
merrimanr:METRON-1685

Conversation

@merrimanr
Copy link
Contributor

Contributor Comments

This PR adds a REST endpoint that allows a user to download a pcap page in HDFS as a file to their local file system. This will allow users to save files for further investigation outside of Metron, in a tool like wireshark.

A new getRawPcap method was added to the PcapService. This function gets a HDFS input stream given a path that's looked up by username, job id and page number. The stream is then copied to the http response outputstream and the appropriate response headers are set. Filenames follow the format pcap_{jobId}_{pageNumber}.pcap but can be overriden by the fileName request parameter.

Changes Included

  • A new Pcap download endpoint that accepts a job id and page number and returns a file for download
  • A new PcapService getRawPcap method that returns an input stream from an HDFS path given a username, job id and page number
  • Unit and integration tests

Testing

This has been tested in full dev. Testing instructions are as follows:

  1. Spin up full dev
  2. Create the HDFS directories specified in application.yml
  • /apps/metron/pcap/input
  • /apps/metron/pcap/interim
  • /apps/metron/pcap/output
  1. Put pcap data in /apps/metron/pcap/input
  2. Run a fixed pcap query to generate results:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "endTimeMs": 1458240269424,
  "startTimeMs": 1458240269419
}' 'http://node1:8082/api/v1/pcap/fixed'
  1. Monitor the job with the get status endpoint until the job has SUCCEEDED and returns a pageTotal:
{
  "jobId": "job_1532012905403_0001",
  "jobStatus": "SUCCEEDED",
  "description": "map: 20.0%, reduce: 0.0%",
  "percentComplete": 100,
  "pageTotal": 2
}
  1. Download a file for a job and page number:
curl -X GET --header 'Accept: application/octet-stream' 'http://node1:8082/api/v1/pcap/job_1532012905403_0001/raw?page=1'

This should download a file named `pcap_job_1532012905403_0001_1.pcap' to your local file system (job id will match yours).

  1. Download a file for a job and page number with a custom file name pcap1.pcap:
curl -X GET --header 'Accept: application/octet-stream' 'http://node1:8082/api/v1/pcap/job_1532012905403_0001/raw?page=1&fileName=pcap1.pcap'

This should download a file named pcap1.pcap.

  1. Attempt to download a file for a job or page number that doesn't exist. You should get a 404.

I also verified that the file sizes of the files downloaded and the results in HDFS match.

Pull Request Checklist

Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines for complete smoke testing guides.

In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:

For all changes:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • Have you included steps or a guide to how the change may be verified and tested manually?

  • Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:

    mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via site-book/target/site/index.html:

    cd site-book
    mvn site
    

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.

mmiklavc and others added 30 commits June 26, 2018 23:48
Pcap job manager generics from cestella
…r for synchronicity. Kill remnants of the job service.
Get PcapTopologyIntegrationTest working
merrimanr and others added 24 commits July 17, 2018 08:29
# Conflicts:
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/MetronRestConstants.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/controller/PcapController.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/PcapService.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/PcapServiceImpl.java
#	metron-interface/metron-rest/src/main/resources/application.yml
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/PcapServiceImplTest.java
# Conflicts:
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/PcapServiceImplTest.java
# Conflicts:
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/PcapServiceImpl.java
# Conflicts:
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/PcapServiceImpl.java
…anel' into METRON-1685

# Conflicts:
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/controller/PcapController.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/PcapService.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/PcapServiceImpl.java
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/config/TestConfig.java
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/controller/PcapControllerIntegrationTest.java
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/PcapServiceImplTest.java
#	metron-platform/metron-job/src/main/java/org/apache/metron/job/manager/InMemoryJobManager.java
@cestella
Copy link
Member

+1 by inspection, this looks very clean.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants