metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmerri...@apache.org
Subject metron git commit: METRON-1735 Empty print status option causes NPE (merrimanr) closes apache/metron#1160
Date Tue, 14 Aug 2018 17:59:52 GMT
Repository: metron
Updated Branches:
  refs/heads/feature/METRON-1554-pcap-query-panel bce9b903f -> 8a926dd5a


METRON-1735 Empty print status option causes NPE (merrimanr) closes apache/metron#1160


Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/8a926dd5
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/8a926dd5
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/8a926dd5

Branch: refs/heads/feature/METRON-1554-pcap-query-panel
Commit: 8a926dd5a4501df8c7ef51b526ad5e4d752a5e19
Parents: bce9b90
Author: merrimanr <merrimanr@gmail.com>
Authored: Tue Aug 14 12:59:38 2018 -0500
Committer: rmerriman <merrimanr@gmail.com>
Committed: Tue Aug 14 12:59:38 2018 -0500

----------------------------------------------------------------------
 .../org/apache/metron/pcap/query/CliParser.java  |  4 ----
 .../apache/metron/pcap/query/PcapCliTest.java    |  7 ++-----
 .../apache/metron/pcap/config/PcapConfig.java    |  2 +-
 .../java/org/apache/metron/pcap/mr/PcapJob.java  | 18 +++++++++++++-----
 .../org/apache/metron/pcap/mr/PcapJobTest.java   | 19 +++++++++++++++++++
 5 files changed, 35 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metron/blob/8a926dd5/metron-platform/metron-pcap-backend/src/main/java/org/apache/metron/pcap/query/CliParser.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-pcap-backend/src/main/java/org/apache/metron/pcap/query/CliParser.java
b/metron-platform/metron-pcap-backend/src/main/java/org/apache/metron/pcap/query/CliParser.java
index 5040f90..b9a2a50 100644
--- a/metron-platform/metron-pcap-backend/src/main/java/org/apache/metron/pcap/query/CliParser.java
+++ b/metron-platform/metron-pcap-backend/src/main/java/org/apache/metron/pcap/query/CliParser.java
@@ -55,7 +55,6 @@ public class CliParser {
     options.addOption(newOption("rpf", "records_per_file", true, String.format("Number of
records to include in each output pcap file (defaults to %s)", NUM_RECORDS_PER_FILE_DEFAULT)));
     options.addOption(newOption("et", "end_time", true, "Packet end time range. Default is
current system time."));
     options.addOption(newOption("df", "date_format", true, "Date format to use for parsing
start_time and end_time. Default is to use time in millis since the epoch."));
-    options.addOption(newOption("ps", "print_status", false, "Print the status of the job
as it runs"));
     options.addOption(newOption("yq", "yarn_queue", true, "Yarn queue this job will be submitted
to"));
     return options;
   }
@@ -127,9 +126,6 @@ public class CliParser {
         //no-op
       }
     }
-    if (commandLine.hasOption("print_status")) {
-      config.setPrintJobStatus(true);
-    }
     if (commandLine.hasOption("yarn_queue")) {
       config.setYarnQueue(commandLine.getOptionValue("yarn_queue"));
     }

http://git-wip-us.apache.org/repos/asf/metron/blob/8a926dd5/metron-platform/metron-pcap-backend/src/test/java/org/apache/metron/pcap/query/PcapCliTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-pcap-backend/src/test/java/org/apache/metron/pcap/query/PcapCliTest.java
b/metron-platform/metron-pcap-backend/src/test/java/org/apache/metron/pcap/query/PcapCliTest.java
index a71e997..3e7aad2 100644
--- a/metron-platform/metron-pcap-backend/src/test/java/org/apache/metron/pcap/query/PcapCliTest.java
+++ b/metron-platform/metron-pcap-backend/src/test/java/org/apache/metron/pcap/query/PcapCliTest.java
@@ -172,8 +172,7 @@ public class PcapCliTest {
             "-protocol", "6",
             "-include_reverse",
             "-num_reducers", "10",
-            "-records_per_file", "1000",
-            "-ps"
+            "-records_per_file", "1000"
     };
     Map<String, String> query = new HashMap<String, String>() {{
       put(Constants.Fields.SRC_ADDR.getName(), "192.168.1.1");
@@ -217,7 +216,6 @@ public class PcapCliTest {
             "-include_reverse",
             "-num_reducers", "10",
             "-records_per_file", "1000",
-            "-ps",
             "-yq", "pcap"
     };
     Map<String, String> query = new HashMap<String, String>() {{
@@ -295,8 +293,7 @@ public class PcapCliTest {
             "-base_path", "/base/path",
             "-base_output_path", "/base/output/path",
             "-query", "some query string",
-            "-records_per_file", "1000",
-            "-ps"
+            "-records_per_file", "1000"
     };
 
     String query = "some query string";

http://git-wip-us.apache.org/repos/asf/metron/blob/8a926dd5/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/config/PcapConfig.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/config/PcapConfig.java
b/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/config/PcapConfig.java
index 4a08e14..abf35d0 100644
--- a/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/config/PcapConfig.java
+++ b/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/config/PcapConfig.java
@@ -42,7 +42,7 @@ public class PcapConfig extends AbstractMapDecorator<String, Object>{
   public PcapConfig(PrefixStrategy prefixStrategy) {
     this();
     setShowHelp(false);
-    setPrintJobStatus(false);
+    setPrintJobStatus(true);
     setBasePath("");
     setBaseInterimResultPath("");
     setStartTimeMs(-1L);

http://git-wip-us.apache.org/repos/asf/metron/blob/8a926dd5/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/mr/PcapJob.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/mr/PcapJob.java
b/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/mr/PcapJob.java
index 0f5ad4d..bf780af 100644
--- a/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/mr/PcapJob.java
+++ b/metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/mr/PcapJob.java
@@ -463,12 +463,20 @@ public class PcapJob<T> implements Statusable<Path> {
     return new JobStatus(jobStatus);
   }
 
+  protected void setJobStatus(JobStatus jobStatus) {
+    this.jobStatus = jobStatus;
+  }
+
+  protected void setMrJob(Job mrJob) {
+    this.mrJob = mrJob;
+  }
+
   /**
    * Synchronous call blocks until completion.
    */
   @Override
   public Pageable<Path> get() throws JobException, InterruptedException {
-    if (PcapOptions.PRINT_JOB_STATUS.get(configuration, Boolean.class)) {
+    if (PcapOptions.PRINT_JOB_STATUS.getOrDefault(configuration, Boolean.class, false) &&
mrJob != null) {
       try {
         mrJob.monitorAndPrintJob();
       } catch (IOException e) {
@@ -486,10 +494,6 @@ public class PcapJob<T> implements Statusable<Path> {
     }
   }
 
-  public void monitorJob() throws IOException, InterruptedException {
-    mrJob.monitorAndPrintJob();
-  }
-
   private synchronized Pageable<Path> getFinalResults() {
     return new PcapPages(finalResults);
   }
@@ -521,4 +525,8 @@ public class PcapJob<T> implements Statusable<Path> {
   public Map<String, Object> getConfiguration() {
     return new HashMap<>(this.configuration);
   }
+
+  protected void setConfiguration(Map<String, Object> configuration) {
+    this.configuration = configuration;
+  }
 }

http://git-wip-us.apache.org/repos/asf/metron/blob/8a926dd5/metron-platform/metron-pcap/src/test/java/org/apache/metron/pcap/mr/PcapJobTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-pcap/src/test/java/org/apache/metron/pcap/mr/PcapJobTest.java
b/metron-platform/metron-pcap/src/test/java/org/apache/metron/pcap/mr/PcapJobTest.java
index 0f555d0..d5ef2dc 100644
--- a/metron-platform/metron-pcap/src/test/java/org/apache/metron/pcap/mr/PcapJobTest.java
+++ b/metron-platform/metron-pcap/src/test/java/org/apache/metron/pcap/mr/PcapJobTest.java
@@ -21,6 +21,9 @@ package org.apache.metron.pcap.mr;
 import static java.lang.Long.toUnsignedString;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
@@ -287,4 +290,20 @@ public class PcapJobTest {
     Assert.assertThat(status.getJobId(), equalTo(jobIdVal));
   }
 
+  @Test
+  public void get_should_print_status() throws Exception {
+    Map<String, Object> configuration = new HashMap<>();
+    testJob.setConfiguration(configuration);
+    testJob.setMrJob(mrJob);
+    testJob.setJobStatus(new JobStatus().withState(State.SUCCEEDED));
+
+    testJob.get();
+    verify(mrJob, times(0)).monitorAndPrintJob();
+
+    PcapOptions.PRINT_JOB_STATUS.put(configuration, true);
+    testJob.get();
+    verify(mrJob, times(1)).monitorAndPrintJob();
+    verifyNoMoreInteractions(mrJob);
+  }
+
 }


Mime
View raw message