Skip to content

Commit

Permalink
Add --verbose logging flag to CLI and don't require non-default port …
Browse files Browse the repository at this point in the history
…specification when using auto for allPartitions
  • Loading branch information
srowen committed Nov 24, 2012
1 parent 9154206 commit 9d7b3a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 22 additions & 3 deletions client/src/net/myrrix/client/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
*/
public final class CLI {

private static final String VERBOSE_FLAG = "verbose";
private static final String TRANSLATE_USER_FLAG = "translateUser";
private static final String TRANSLATE_ITEM_FLAG = "translateItem";
private static final String HOST_FLAG = "host";
Expand Down Expand Up @@ -169,6 +170,10 @@ public static void main(String[] args) throws Exception {
return;
}

if (commandLine.hasOption(VERBOSE_FLAG)) {
enableDebugLoggingIn(CLI.class, ClientRecommender.class, TranslatingClientRecommender.class);
}

MyrrixClientConfiguration config = buildConfiguration(commandLine);
ClientRecommender recommender = new ClientRecommender(config);

Expand Down Expand Up @@ -486,9 +491,9 @@ private static MyrrixClientConfiguration buildConfiguration(CommandLine commandL
if (commandLine.hasOption(ALL_PARTITIONS_FLAG)) {
String allPartitionsFlagValue = commandLine.getOptionValue(ALL_PARTITIONS_FLAG);
config.setAllPartitionsSpecification(allPartitionsFlagValue);
if (MyrrixClientConfiguration.AUTO_PARTITION_SPEC.equals(allPartitionsFlagValue) && (!hasHost || !hasPort)) {
throw new ParseException("--" + HOST_FLAG + " and --" + PORT_FLAG + " are required with --allPartitions=" +
MyrrixClientConfiguration.AUTO_PARTITION_SPEC);
if (MyrrixClientConfiguration.AUTO_PARTITION_SPEC.equals(allPartitionsFlagValue) && !hasHost) {
throw new ParseException(
"--allPartitions=" + MyrrixClientConfiguration.AUTO_PARTITION_SPEC + " requires --" + HOST_FLAG);
}
}

Expand All @@ -511,6 +516,7 @@ private static MyrrixClientConfiguration buildConfiguration(CommandLine commandL

private static Options buildOptions() {
Options options = new Options();
addOption(options, "Verbose logging", VERBOSE_FLAG, false, true);
addOption(options, "Serving Layer host name", HOST_FLAG, true, false);
addOption(options, "Serving Layer port number", PORT_FLAG, true, false);
addOption(options, "If set, use HTTPS instead of HTTP", SECURE_FLAG, false, true);
Expand Down Expand Up @@ -557,4 +563,17 @@ private static void outputTranslated(Iterable<TranslatedRecommendedItem> items)
}
}

private static void enableDebugLoggingIn(Class<?>... classes) {
for (Class<?> c : classes) {
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(c.getName());
julLogger.setLevel(java.util.logging.Level.FINE);
while (julLogger != null) {
for (java.util.logging.Handler handler : julLogger.getHandlers()) {
handler.setLevel(java.util.logging.Level.FINE);
}
julLogger = julLogger.getParent();
}
}
}

}
4 changes: 4 additions & 0 deletions client/src/net/myrrix/client/ClientRecommender.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ private HttpURLConnection makeConnection(String path, String method, Long partit
// can't happen
throw new IllegalStateException(mue);
}
if (log.isDebugEnabled()) {
log.debug("{} to {}", method, url);
}

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
connection.setDoInput(true);
Expand Down

0 comments on commit 9d7b3a2

Please sign in to comment.