Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public Options buildOptions() {
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;
}
Expand Down Expand Up @@ -127,9 +126,6 @@ public void parse(CommandLine commandLine, PcapConfig config) throws java.text.P
//no-op
}
}
if (commandLine.hasOption("print_status")) {
config.setPrintJobStatus(true);
}
if (commandLine.hasOption("yarn_queue")) {
config.setYarnQueue(commandLine.getOptionValue("yarn_queue"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ public void runs_fixed_pcap_filter_job_with_full_argument_list_and_default_datef
"-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");
Expand Down Expand Up @@ -217,7 +216,6 @@ public void runs_fixed_pcap_filter_job_with_full_argument_list() throws Exceptio
"-include_reverse",
"-num_reducers", "10",
"-records_per_file", "1000",
"-ps",
"-yq", "pcap"
};
Map<String, String> query = new HashMap<String, String>() {{
Expand Down Expand Up @@ -295,8 +293,7 @@ public void runs_query_pcap_filter_job_with_full_argument_list() throws Exceptio
"-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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PcapConfig() {
public PcapConfig(PrefixStrategy prefixStrategy) {
this();
setShowHelp(false);
setPrintJobStatus(false);
setPrintJobStatus(true);
setBasePath("");
setBaseInterimResultPath("");
setStartTimeMs(-1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,20 @@ public synchronized JobStatus getStatus() throws JobException {
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) {
Expand All @@ -486,10 +494,6 @@ public Pageable<Path> get() throws JobException, InterruptedException {
}
}

public void monitorJob() throws IOException, InterruptedException {
mrJob.monitorAndPrintJob();
}

private synchronized Pageable<Path> getFinalResults() {
return new PcapPages(finalResults);
}
Expand Down Expand Up @@ -521,4 +525,8 @@ public boolean validate(Map<String, Object> configuration) {
public Map<String, Object> getConfiguration() {
return new HashMap<>(this.configuration);
}

protected void setConfiguration(Map<String, Object> configuration) {
this.configuration = configuration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
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;
Expand Down Expand Up @@ -287,4 +290,20 @@ public void handles_null_values_with_defaults() throws Exception {
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);
}

}