Skip to content

Commit

Permalink
Gets hadoop version for reporting at startup. Allows Hadoop mapper to…
Browse files Browse the repository at this point in the history
… opt out all jobs (via .h2o_no_collect file). Allow h2o node startup to opt out via command-line.
  • Loading branch information
bghill committed Nov 14, 2014
1 parent 9e822e0 commit 573fdfd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
21 changes: 21 additions & 0 deletions hadoop/src/main/java/water/hadoop/h2odriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,22 @@ private void waitForClusterToShutdown() throws Exception {
}
}

private String calcHadoopVersion() {
try {
Process p = new ProcessBuilder("hadoop", "version").start();
p.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = br.readLine();
if (line == null) {
line = "(unknown)";
}
return line;
}
catch (Exception e) {
return "(unknown)";
}
}

private int run2(String[] args) throws Exception {
// Parse arguments.
// ----------------
Expand Down Expand Up @@ -895,6 +911,11 @@ private int run2(String[] args) throws Exception {
if (licenseData != null) {
conf.set(h2omapper.H2O_LICENSE_DATA_KEY, licenseData);
}
String hadoopVersion = calcHadoopVersion();
conf.set(h2omapper.H2O_HADOOP_VERSION, hadoopVersion);
if((new File(".h2o_no_collect")).exists() || (new File(System.getProperty("user.home")+"/.h2o_no_collect")).exists()) {
conf.set(h2omapper.H2O_GA_OPTOUT, "-ga_optout");
}

// Set up job stuff.
// -----------------
Expand Down
9 changes: 9 additions & 0 deletions hadoop/src/main/java/water/hadoop/h2omapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class h2omapper extends Mapper<Text, Text, Text, Text> {
final static public String H2O_NTHREADS_KEY = "h2o.nthreads";
final static public String H2O_BASE_PORT_KEY = "h2o.baseport";
final static public String H2O_LICENSE_DATA_KEY = "h2o.license.data";
final static public String H2O_HADOOP_VERSION = "h2o.hadoop.version";
final static public String H2O_GA_OPTOUT = "h2o.ga.optout";

static EmbeddedH2OConfig _embeddedH2OConfig;

Expand Down Expand Up @@ -363,6 +365,8 @@ private int run2(Context context) throws IOException, InterruptedException {
String betaString = conf.get(H2O_BETA_KEY);
String randomUdpDropString = conf.get(H2O_RANDOM_UDP_DROP_KEY);
String licenseData = conf.get(H2O_LICENSE_DATA_KEY);
String hadoopVersion = conf.get(H2O_HADOOP_VERSION);
String gaOptOut = conf.get(H2O_GA_OPTOUT);

ServerSocket ss = new ServerSocket();
InetSocketAddress sa = new InetSocketAddress("127.0.0.1", 0);
Expand Down Expand Up @@ -427,6 +431,11 @@ private int run2(Context context) throws IOException, InterruptedException {
argsList.add(fileName);
}
}
if (hadoopVersion != null) {
argsList.add("-ga_hdp_ver");
argsList.add(hadoopVersion);
}
if (gaOptOut != null) argsList.add(gaOptOut);

// Options passed through to UserMain for configuring the EmbeddedH2OConfig.
argsList.add("-driverip");
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/water/H2O.java
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ public static class OptArgs extends Arguments.Opt {
public String beta = null;
public String mem_watchdog = null; // For developer debugging
public boolean md5skip = false;
public boolean ga_opt_out = false;
public String ga_hdp_ver = null;
}

public static void printHelp() {
Expand Down Expand Up @@ -775,6 +777,9 @@ public static void printHelp() {
" -license <licenseFilePath>\n" +
" Path to license file on local filesystem.\n" +
"\n" +
" -ga_opt_out\n" +
" Opt out of sending anonymous usage metrics to Google Analytics.\n" +
"\n" +
"Cloud formation behavior:\n" +
"\n" +
" New H2O nodes join together to form a cloud at startup time.\n" +
Expand Down Expand Up @@ -889,8 +894,12 @@ public static void main( String[] args ) {
START_TIME_MILLIS = System.currentTimeMillis();

GA = new GoogleAnalytics("UA-56665317-2","H2O",H2O.getVersion());
if((new File(".h2o_no_collect")).exists() || (new File(System.getProperty("user.home")+"/.h2o_no_collect")).exists())
if((new File(".h2o_no_collect")).exists()
|| (new File(System.getProperty("user.home")+"/.h2o_no_collect")).exists()
|| OPT_ARGS.ga_opt_out ) {
GA.setEnabled(false);
Log.info("Opted out of sending usage metrics.");
}

// Parse args
Arguments arguments = new Arguments(args);
Expand Down Expand Up @@ -1995,7 +2004,8 @@ public void run() {
}

private static void postStartupGAEvents() {
//TODO place an EventHit that records the HDFS version at startup
if (OPT_ARGS.ga_hdp_ver != null)
GA.postAsync(new EventHit("System startup info", "Hadoop version", OPT_ARGS.ga_hdp_ver, 1));
GA.postAsync(new EventHit("System startup info", "Cloud", "Cloud size", CLOUD.size()));
}
}
2 changes: 1 addition & 1 deletion src/main/java/water/ga/GoogleAnalytics.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public GoogleAnalyticsResponse post(GoogleAnalyticsRequest request) {
//Process custom metrics
processCustomMetricParameters(request, postParms);

Log.warn("GA Processed all parameters and sending the request " + postParms);
Log.debug("GA Processed all parameters and sending the request " + postParms);

HttpPost httpPost = new HttpPost(config.getUrl());
try {
Expand Down

0 comments on commit 573fdfd

Please sign in to comment.