[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user merrimanr closed the pull request at: https://github.com/apache/metron/pull/1109 ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user merrimanr commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203518190 --- Diff: metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/finalizer/PcapRestFinalizer.java --- @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.metron.pcap.finalizer; + +import java.nio.file.Paths; +import java.util.Map; +import org.apache.hadoop.fs.Path; +import org.apache.metron.job.Statusable; +import org.apache.metron.pcap.config.PcapOptions; + +/** + * Write to HDFS. + */ +public class PcapRestFinalizer extends PcapFinalizer { + + private String user; + private String jobType = Statusable.JobType.MAP_REDUCE.name(); + + public void setUser(String user) { +this.user = user; + } + + @Override + protected Path getOutputPath(Map config, int partition) { +String jobId = PcapOptions.JOB_ID.get(config, String.class); +String finalOutputPath = PcapOptions.FINAL_OUTPUT_PATH.get(config, String.class); --- End diff -- Done ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user mmiklavc commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203515166 --- Diff: metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/finalizer/PcapRestFinalizer.java --- @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.metron.pcap.finalizer; + +import java.nio.file.Paths; +import java.util.Map; +import org.apache.hadoop.fs.Path; +import org.apache.metron.job.Statusable; +import org.apache.metron.pcap.config.PcapOptions; + +/** + * Write to HDFS. + */ +public class PcapRestFinalizer extends PcapFinalizer { + + private String user; + private String jobType = Statusable.JobType.MAP_REDUCE.name(); + + public void setUser(String user) { +this.user = user; + } + + @Override + protected Path getOutputPath(Map config, int partition) { +String jobId = PcapOptions.JOB_ID.get(config, String.class); +String finalOutputPath = PcapOptions.FINAL_OUTPUT_PATH.get(config, String.class); --- End diff -- @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. ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user merrimanr commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r20353 --- Diff: metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/finalizer/PcapRestFinalizer.java --- @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.metron.pcap.finalizer; + +import java.nio.file.Paths; +import java.util.Map; +import org.apache.hadoop.fs.Path; +import org.apache.metron.job.Statusable; +import org.apache.metron.pcap.config.PcapOptions; + +/** + * Write to HDFS. + */ +public class PcapRestFinalizer extends PcapFinalizer { + + private String user; + private String jobType = Statusable.JobType.MAP_REDUCE.name(); + + public void setUser(String user) { +this.user = user; + } + + @Override + protected Path getOutputPath(Map config, int partition) { +String jobId = PcapOptions.JOB_ID.get(config, String.class); +String finalOutputPath = PcapOptions.FINAL_OUTPUT_PATH.get(config, String.class); --- End diff -- The reason I did it that way is because that user property is only used here. Happy to change it to a config. ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user cestella commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203502396 --- Diff: metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/finalizer/PcapRestFinalizer.java --- @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.metron.pcap.finalizer; + +import java.nio.file.Paths; +import java.util.Map; +import org.apache.hadoop.fs.Path; +import org.apache.metron.job.Statusable; +import org.apache.metron.pcap.config.PcapOptions; + +/** + * Write to HDFS. + */ +public class PcapRestFinalizer extends PcapFinalizer { + + private String user; + private String jobType = Statusable.JobType.MAP_REDUCE.name(); + + public void setUser(String user) { +this.user = user; + } + + @Override + protected Path getOutputPath(Map config, int partition) { +String jobId = PcapOptions.JOB_ID.get(config, String.class); +String finalOutputPath = PcapOptions.FINAL_OUTPUT_PATH.get(config, String.class); --- End diff -- 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. ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user merrimanr commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203370606 --- Diff: metron-interface/metron-rest/src/main/java/org/apache/metron/rest/config/PcapJobSupplier.java --- @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.metron.rest.config; + +import org.apache.hadoop.fs.Path; +import org.apache.metron.job.JobException; +import org.apache.metron.job.JobStatus; +import org.apache.metron.job.Statusable; +import org.apache.metron.pcap.finalizer.PcapFinalizerStrategies; +import org.apache.metron.pcap.mr.PcapJob; +import org.apache.metron.rest.model.pcap.PcapRequest; + +import java.util.function.Supplier; + +public class PcapJobSupplier implements Supplier> { + + private PcapRequest pcapRequest; + + @Override + public Statusable get() { +try { + PcapJob pcapJob = createPcapJob(); + return pcapJob.submit(PcapFinalizerStrategies.REST, pcapRequest); +} catch (JobException e) { + return null; + //return new JobStatus().withState(JobStatus.State.FAILED).withDescription(JobStatus.State.FAILED.toString()); --- End diff -- Yes this was a mistake. A runtime exception is thrown now. ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user merrimanr commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203370393 --- Diff: metron-interface/metron-rest-client/src/main/java/org/apache/metron/rest/model/pcap/PcapRequest.java --- @@ -17,75 +17,65 @@ */ package org.apache.metron.rest.model.pcap; -public class PcapRequest { +import org.apache.commons.collections4.map.AbstractMapDecorator; +import org.apache.metron.pcap.config.PcapOptions; - private String baseOutputPath; - private String basePath; - private Long startTime = 0L; - private Long endTime = System.currentTimeMillis(); - private Integer numReducers = 1; +import java.util.HashMap; - public String getBaseOutputPath() { -return baseOutputPath; - } +public class PcapRequest extends AbstractMapDecorator { - public void setBaseOutputPath(String baseOutputPath) { -this.baseOutputPath = baseOutputPath; + public PcapRequest() { +super(new HashMap<>()); +setStartTimeMs(0L); +setEndTimeMs(System.currentTimeMillis()); +setNumReducers(1); --- End diff -- Default is now 10. ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user cestella commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203047956 --- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/utils/HDFSUtils.java --- @@ -29,6 +29,16 @@ public class HDFSUtils { + public static byte[] readBytes(String path) throws IOException { +return readBytes(new Path(path)); + } + + public static byte[] readBytes(Path inPath) throws IOException { +FileSystem fs = FileSystem.get(inPath.toUri(), new Configuration()); +FSDataInputStream inputStream = fs.open(inPath); --- End diff -- This should be in a try with resources block otherwise you're leaving streams open. ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user cestella commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203047410 --- Diff: metron-interface/metron-rest/src/main/java/org/apache/metron/rest/config/PcapJobSupplier.java --- @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.metron.rest.config; + +import org.apache.hadoop.fs.Path; +import org.apache.metron.job.JobException; +import org.apache.metron.job.JobStatus; +import org.apache.metron.job.Statusable; +import org.apache.metron.pcap.finalizer.PcapFinalizerStrategies; +import org.apache.metron.pcap.mr.PcapJob; +import org.apache.metron.rest.model.pcap.PcapRequest; + +import java.util.function.Supplier; + +public class PcapJobSupplier implements Supplier> { + + private PcapRequest pcapRequest; + + @Override + public Statusable get() { +try { + PcapJob pcapJob = createPcapJob(); + return pcapJob.submit(PcapFinalizerStrategies.REST, pcapRequest); +} catch (JobException e) { + return null; + //return new JobStatus().withState(JobStatus.State.FAILED).withDescription(JobStatus.State.FAILED.toString()); --- End diff -- Is this intended? Seems like we should be passing back info about the exception or at the very least throwing a runtime exception, right? ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
Github user cestella commented on a diff in the pull request: https://github.com/apache/metron/pull/1109#discussion_r203046824 --- Diff: metron-interface/metron-rest-client/src/main/java/org/apache/metron/rest/model/pcap/PcapRequest.java --- @@ -17,75 +17,65 @@ */ package org.apache.metron.rest.model.pcap; -public class PcapRequest { +import org.apache.commons.collections4.map.AbstractMapDecorator; +import org.apache.metron.pcap.config.PcapOptions; - private String baseOutputPath; - private String basePath; - private Long startTime = 0L; - private Long endTime = System.currentTimeMillis(); - private Integer numReducers = 1; +import java.util.HashMap; - public String getBaseOutputPath() { -return baseOutputPath; - } +public class PcapRequest extends AbstractMapDecorator { - public void setBaseOutputPath(String baseOutputPath) { -this.baseOutputPath = baseOutputPath; + public PcapRequest() { +super(new HashMap<>()); +setStartTimeMs(0L); +setEndTimeMs(System.currentTimeMillis()); +setNumReducers(1); --- End diff -- It might be worthwhile to pick the number of reducers > 1 just because this is going to be slow by default. Maybe 10 would be a sensible middle ground? ---
[GitHub] metron pull request #1109: METRON-1674: Create REST endpoint for job status ...
GitHub user merrimanr opened a pull request: https://github.com/apache/metron/pull/1109 METRON-1674: Create REST endpoint for job status abstraction ## Contributor Comments This PR is built on top of https://github.com/apache/metron/pull/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 lightly tested in full dev. The HDFS paths must be created manually for the paths specified in application.yml. For now and only job submission and subsequent status retrieval had been tested. This PR should strictly be used for testing at this point. 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 '{ "endTime": 1458240269424, "startTime": 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' ``` A full, comprehensive review should be done after https://github.com/apache/metron/pull/1108 has been merged. ## Pull Request Checklist Thank you for submitting a contribution to Apache Metron. Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions. Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) 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: - [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel). - [x] Does your PR title start with METRON- where is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character. - [x] 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 ``` - [x] Have you written or updated unit tests and or integration tests to verify your changes? - [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? - [x] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent? ### For documentation