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

Conversation

@merrimanr
Copy link
Contributor

@merrimanr merrimanr commented Jul 16, 2018

Contributor Comments

This PR is built on top of #1108 and should be merged and final review done after that is accepted into the feature branch. This exposes the job manager and job status abstraction through a REST endpoint.

A summary of the changes included:

  • Adjustments to the existing PcapService to accommodate the new JobManager abstraction
    • JobManager is now a Spring bean and job submission/status is done through that
    • New properties were added to application.yml and PcapServiceImpl
    • PcapJobSupplier was added that allows switching to a mock pcap job during integration testing
    • Unit and integration tests were adjusted to match
    • Time parameters are now startTimeMs and endTimeMs
  • FixedPcapRequest now matches the pattern used in PcapRequest
  • Addition of a PcapStatus object to return status in a simple, consumable structure for the UI
  • Endpoint to get job status was added
  • ConfigOption was adjusted to automatically handle type conversions in cases where Jackson deserialization is used (Integer to Long for example)
  • InMemoryJobManager now throws a JobNotFoundException when jobs don't exist for a username/job id combination
  • PcapJob will automatically convert PcapOptions.START_TIME_MS to PcapOptions.START_TIME_NS when START_TIME_NS is not set (same goes for END_TIME_NS)
  • New unit and integration tests added for get status endpoint and service

This has been tested in full dev. The HDFS paths must be created manually for the paths specified in application.yml:

  • /apps/metron/pcap/input
  • /apps/metron/pcap/interim
  • /apps/metron/pcap/output

To test in full dev, create the HDFS directories mentioned above and put pcap data in /apps/metron/pcap/input. Submit a fixed pcap query:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "endTimeMs": 1458240269424,
  "startTimeMs": 1458240269419
}' 'http://node1:8082/api/v1/pcap/fixed'

A job id should be returned in the response:

{
  "jobId": "job_1531258337010_0021",
  "jobStatus": "RUNNING",
  "description": "map: 0.0%, reduce: 0.0%",
  "percentComplete": 0,
  "size": 0
}

Job status can now be retrieved using the get job status endpoint:

curl -X GET --header 'Accept: application/json' 'http://node1:8082/api/v1/pcap/job_1531258337010_0021'

Check the job status with this endpoint for the next minute or so. The percentComplete field in the response should increase over time:

{
  "jobId": "job_1531258337010_0021",
  "jobStatus": "RUNNING",
  "description": "map: 20.0%, reduce: 0.0%",
  "percentComplete": 10,
  "size": 0
}

The jobStatus field should transition from RUNNING > FINALIZING > SUCCEEDED. Once the job is in the SUCCEEDED state, the results should be available in HDFS. The result path will follow this pattern:

/apps/metron/pcap/output/{user}/{jobType}/{jobId}/page-*

Depending on the page size, the output should look something like:

Found 2 items
-rw-r--r--   1 metron metron       2236 2018-07-15 16:51 /apps/metron/pcap/output/user/MAP_REDUCE/job_1531258337010_0021/page-1
-rw-r--r--   1 metron metron       1388 2018-07-15 16:51 /apps/metron/pcap/output/user/MAP_REDUCE/job_1531258337010_0021/page-2

A full, comprehensive review should be done after #1108 has been merged.

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
return pcapJob.submit(PcapFinalizerStrategies.REST, pcapRequest);
} catch (JobException e) {
return null;
//return new JobStatus().withState(JobStatus.State.FAILED).withDescription(JobStatus.State.FAILED.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended? Seems like we should be passing back info about the exception or at the very least throwing a runtime exception, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was a mistake. A runtime exception is thrown now.


public static byte[] readBytes(Path inPath) throws IOException {
FileSystem fs = FileSystem.get(inPath.toUri(), new Configuration());
FSDataInputStream inputStream = fs.open(inPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a try with resources block otherwise you're leaving streams open.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retract this, it originated in @mmiklavc 's PR. I moved the comment there.

Copy link
Member

@cestella cestella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good, I'm going to try to pick out the parts that are unique to this and not @mmiklavc 's ticket for review. I'll make another pass in a bit.

@james-sirota
Copy link

Here is what I've done so far:

Capture a random PCAP using tcpdump, place that PCAP into /apps/metron/pcap/input on HDFS, run the service in Swager under POST /api/v1/pcap/fixed

I send

{
"endTime":1531892977000,
"startTime":1458240269424
}

which are the right timestamps for my PCAP, and get back an error:

{
"timestamp": "2018-07-18 06:00:45",
"status": 500,
"error": "Internal Server Error",
"message": "-1",
"path": "/api/v1/pcap/fixed"
}

Which in metron-rest.log corresponds to:

Jul 18, 2018 6:00:45 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ArrayIndexOutOfBoundsException: -1] with root cause
java.lang.ArrayIndexOutOfBoundsException: -1
at org.apache.metron.pcap.PcapFilenameHelper.getKafkaPartition(PcapFilenameHelper.java:66)
at org.apache.metron.pcap.utils.FileFilterUtil.getFilesByPartition(FileFilterUtil.java:63)
at org.apache.metron.pcap.utils.FileFilterUtil.getPathsInTimeRange(FileFilterUtil.java:50)
at org.apache.metron.pcap.mr.PcapJob.createJob(PcapJob.java:382)
at org.apache.metron.pcap.mr.PcapJob.query(PcapJob.java:276)
at org.apache.metron.pcap.mr.PcapJob.submit(PcapJob.java:235)
at org.apache.metron.rest.config.PcapJobSupplier.get(PcapJobSupplier.java:38)
at org.apache.metron.rest.config.PcapJobSupplier.get(PcapJobSupplier.java:30)
at org.apache.metron.job.manager.InMemoryJobManager.submit(InMemoryJobManager.java:48)
at org.apache.metron.rest.service.impl.PcapServiceImpl.fixed(PcapServiceImpl.java:64)
at org.apache.metron.rest.controller.PcapController.fixed(PcapController.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)

@merrimanr
Copy link
Contributor Author

The latest commit addresses feedback received so far. I also changed the structure of the HDFS paths to avoid issues around reading input and also to output data to unique locations. Previously all data was written to /apps/metron/pcap/output/page-* which obviously won't work. I will update the PR description with new testing instructions.

@james-sirota this should resolve the error you were getting.

@james-sirota
Copy link

+1 works great. I was able to put the output of the pcap topology into a directory in HDFS, run a query over it, got a page in the output directory (with status correctly updating while the job was running), was able to open the page in wireshark

@Override
protected Path getOutputPath(Map<String, Object> config, int partition) {
String jobId = PcapOptions.JOB_ID.get(config, String.class);
String finalOutputPath = PcapOptions.FINAL_OUTPUT_PATH.get(config, String.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't the user passed into the config rather than being in a member variable? This seems inconsistent. I'd expect a PcapOptions.USERNAME.get(config, String.class) rather than a member variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I did it that way is because that user property is only used here. Happy to change it to a config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merrimanr Yeah, let's do what we did with the interim output path. We've gone down the Map config path so I think we should keep that consistent. There may be some brainstorming we can do around creating pointed option validation (e.g. specific to a finalizer), but for now the PcapOptions route seems sufficient to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tiborm
Copy link
Contributor

tiborm commented Jul 19, 2018

Is it necessary to have /{user}/{jobType}/ in the output url?
Right now our UI calling this:
/apps/metron/pcap/output/{jobId}/{pageId}

On our side, pageId is a simple int at the moment. Is "page-*" at the end of the URL pattern means the service expecting something like "page-5"?

@merrimanr
Copy link
Contributor Author

@tiborm That is an HDFS path, not a URL. It's of no concern to the UI.

@tiborm
Copy link
Contributor

tiborm commented Jul 19, 2018

I see, thanks. Is there an endpoint for the PDML output?
Or it is out of the scope of this PR?

@merrimanr
Copy link
Contributor Author

That PR should be up for review soon.

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.

5 participants