nickwallen commented on a change in pull request #1383: METRON-1788 Batch
profiler pull profile information from zookeeper
URL: https://github.com/apache/metron/pull/1383#discussion_r276228369
##########
File path:
metron-analytics/metron-profiler-spark/src/main/java/org/apache/metron/profiler/spark/cli/BatchProfilerCLI.java
##########
@@ -96,6 +112,65 @@ public static void main(String[] args) throws IOException,
org.apache.commons.cl
LOG.info("Profiler produced {} profile measurement(s)", count);
}
+ /**
+ * Extracts profile information from a file or from zookeeper
+ * @param commandLine Command line information.
+ * @return Profile information
+ * @throws MissingOptionException if command line options are missing
+ * @throws IOException If there are disk or network issues retrieving
profiles
+ */
+ private static ProfilerConfig handleProfileDefinitions(CommandLine
commandLine) throws MissingOptionException, IOException {
+ final String PROFILE_LOCATION_ERROR =
+ "A single profile location (--profiles or --zookeeper) must be
specified";
+ ProfilerConfig profiles;
+
+ if ((!PROFILE_ZK.has(commandLine)) &&
(!PROFILE_DEFN_FILE.has(commandLine))) {
+ throw new MissingOptionException(PROFILE_LOCATION_ERROR);
+ }
+ if (PROFILE_ZK.has(commandLine) && PROFILE_DEFN_FILE.has(commandLine)) {
+ throw new IllegalArgumentException(PROFILE_LOCATION_ERROR);
+ }
+
+ if (PROFILE_ZK.has(commandLine)) {
+ try (final CuratorFramework zkClient = createZKClient(commandLine)) {
Review comment:
It might read cleaner, if you push the Zk client creation into the
`handleProfileDefinitionsZk` method and just pass it the `CommandLine`. That
way it mirrors the signature of `handleProfileDefinitionsFile` and simplifies
the logic flow here.
```
...
if (PROFILE_ZK.has(commandLine)) {
profiles = handleProfileDefinitionsZK(commandLine);
} else {
profiles = handleProfileDefinitionsFile(commandLine);
}
...
```
```
private static ProfilerConfig handleProfileDefinitionsZK(CommandLine
commandLine) throws IOException {
LOG.info("Loading profiles from zookeeper");
try (final CuratorFramework zkClient = createZKClient(commandLine)) {
try {
profiles =
ConfigurationsUtils.readProfilerConfigFromZookeeper(zkClient);;
} catch (Exception ex) {
throw new IOException(String.format("Error reading configuration
from Zookeeper client %s", zkClient.toString()), ex);
}
}
LOG.info("Loaded {} profile(s)", profiles.getProfiles().size());
return profiles;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services