From: pvtroshin Date: Tue, 11 Oct 2011 11:37:05 +0000 (+0000) Subject: Google Analytics statistics is added X-Git-Url: http://source.jalview.org/gitweb/?p=jabaws.git;a=commitdiff_plain;h=23fb18b3f14a1b396f0c61f2ea4559fec758cb1d Google Analytics statistics is added git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4651 e3abac25-378b-4346-85de-24260fe3988d --- diff --git a/.classpath b/.classpath index 9651a3f..c9f256a 100644 --- a/.classpath +++ b/.classpath @@ -13,5 +13,6 @@ + diff --git a/WEB-INF/lib/compbio-ga-1.0.jar b/WEB-INF/lib/compbio-ga-1.0.jar new file mode 100644 index 0000000..378a99a Binary files /dev/null and b/WEB-INF/lib/compbio-ga-1.0.jar differ diff --git a/build.xml b/build.xml index 208fcbf..426e3ca 100644 --- a/build.xml +++ b/build.xml @@ -17,6 +17,7 @@ + diff --git a/conf/GA.properties b/conf/GA.properties index 223b9a7..526a654 100644 --- a/conf/GA.properties +++ b/conf/GA.properties @@ -1,14 +1,14 @@ -# This file contains settings for Google Analytics Statistics Engine. +# This file contains settings for Google Analytics (GA) Statistics Engine. # Feel free to remove/delete this file if you do not want us to see that you # use JABAWS. However, we would appreciate it greatly if you could leave it on. -# We depend on the JABAWS usage statistics for our future funding. We do not -# collect any personal data. That data that we submit is as follows +# JABAWS usage statistics are collected for funding and reporting purposes, and +# no private information is collected. The data sent by JABAWS is as follows: # 1) The IP address of the JABAWS server machine. # 2) The name of the web service that was called. # 3) A few details of the system such as java version, user language, color depth, screen # resolution and character encoding. -# All calls to statistics are completed asynchronously and create very little +# All calls to GA are completed asynchronously and create very little # overhead. Thus they do not influence the server response time or performance. # Values yes or true = enable GA, any other value will disable it diff --git a/engine/compbio/engine/conf/PropertyHelperManager.java b/engine/compbio/engine/conf/PropertyHelperManager.java index fb35362..b3d2b66 100644 --- a/engine/compbio/engine/conf/PropertyHelperManager.java +++ b/engine/compbio/engine/conf/PropertyHelperManager.java @@ -61,8 +61,10 @@ public final class PropertyHelperManager { + "Engine.cluster.properties"); File execProp = getResourceFromClasspath(confDir + "Executable.properties"); + File gaProp = getResourceFromClasspath(confDir + + "GA.properties"); ph = new PropertyHelper(locEngineProp, clustEngineProp, - execProp); + execProp, gaProp); } catch (IOException e) { log.warn( "Cannot read property files! Reason: " diff --git a/lib/src/compbio-ga-src-1.0.jar b/lib/src/compbio-ga-src-1.0.jar new file mode 100644 index 0000000..fad0585 Binary files /dev/null and b/lib/src/compbio-ga-src-1.0.jar differ diff --git a/webservices/compbio/ws/server/GAUtils.java b/webservices/compbio/ws/server/GAUtils.java new file mode 100644 index 0000000..e4473d1 --- /dev/null +++ b/webservices/compbio/ws/server/GAUtils.java @@ -0,0 +1,82 @@ +package compbio.ws.server; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.apache.log4j.Logger; + +import compbio.engine.conf.PropertyHelperManager; +import compbio.stat.ga.AnalyticsConfigData; +import compbio.stat.ga.GoogleAnalyticsTracker; +import compbio.util.PropertyHelper; +import compbio.util.Util; +import compbio.ws.client.Services; + +public class GAUtils { + + // MODIFY BEFORE RELEASE! + final static String VERSION_TYPE = "WAR"; + + private static final Logger log = Logger.getLogger(GAUtils.class); + + static PropertyHelper PROP_HELPER = PropertyHelperManager + .getPropertyHelper(); + + private static AnalyticsConfigData config = new AnalyticsConfigData( + "UA-26161150-1"); + + private static GoogleAnalyticsTracker TRACKER = new GoogleAnalyticsTracker( + config); + + public static final boolean IS_GA_ENABLED = isGoogleAnalyticsEnabled(); + + private static String SERVER_ADDRESS = getServerIP(); + + private static boolean isGoogleAnalyticsEnabled() { + String val = PROP_HELPER.getProperty("enable.ga"); + if (Util.isEmpty(val)) { + return false; + } + val = val.trim(); + if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) { + return true; + } + return false; + } + + private static String getServerIP() { + String IP = "127.0.0.1"; + if (!anonymizeIP()) { + try { + InetAddress localAddrIP = InetAddress.getLocalHost(); + IP = localAddrIP.getCanonicalHostName(); + } catch (UnknownHostException ignored) { + } + } + return IP; + } + + private static boolean anonymizeIP() { + String val = PROP_HELPER.getProperty("anonymize.ip"); + if (Util.isEmpty(val)) { + return false; + } + if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) { + return true; + } + return false; + } + + static void reportUsage(Services service) { + String service_name = "UNKNOWN"; + if (service == null) { + log.warn("GA: Services was NULL!"); + } else { + service_name = service.toString(); + } + TRACKER.trackPageViewFromReferrer("JABAWS/2.0/" + service_name, + service_name, "http://www.compbio.dundee.ac.uk", + SERVER_ADDRESS, VERSION_TYPE); + TRACKER.resetSession(); + } +} diff --git a/webservices/compbio/ws/server/LocalURL.txt b/webservices/compbio/ws/server/LocalURL.txt deleted file mode 100644 index aa70a6f..0000000 --- a/webservices/compbio/ws/server/LocalURL.txt +++ /dev/null @@ -1,3 +0,0 @@ -http://localhost:7979/Clustal -http://localhost:8080/ws/Clustal -http://localhost:7979/Muscle diff --git a/webservices/compbio/ws/server/MafftWS.java b/webservices/compbio/ws/server/MafftWS.java index 63de39b..f293ae7 100644 --- a/webservices/compbio/ws/server/MafftWS.java +++ b/webservices/compbio/ws/server/MafftWS.java @@ -66,7 +66,7 @@ public class MafftWS implements MsaWS { throws JobSubmissionException { WSUtil.validateFastaInput(sequences); ConfiguredExecutable confMafft = init(sequences); - return WSUtil.align(sequences, confMafft, null, "align", getLimit("")); + return WSUtil.align(sequences, confMafft, log, "align", getLimit("")); } ConfiguredExecutable init(List dataSet) @@ -88,7 +88,7 @@ public class MafftWS implements MsaWS { Mafft.KEY_VALUE_SEPARATOR); log.info("Setting parameters: " + params); confMafft.addParameters(params); - return WSUtil.align(sequences, confMafft, null, "customAlign", + return WSUtil.align(sequences, confMafft, log, "customAlign", getLimit("")); } @@ -106,7 +106,7 @@ public class MafftWS implements MsaWS { // particular preset is not found Limit limit = getLimit(preset.getName()); - return WSUtil.align(sequences, confMafft, null, "presetAlign", limit); + return WSUtil.align(sequences, confMafft, log, "presetAlign", limit); } @SuppressWarnings("unchecked") diff --git a/webservices/compbio/ws/server/MuscleWS.java b/webservices/compbio/ws/server/MuscleWS.java index 95cef8b..a9d6c52 100644 --- a/webservices/compbio/ws/server/MuscleWS.java +++ b/webservices/compbio/ws/server/MuscleWS.java @@ -66,7 +66,7 @@ public class MuscleWS implements MsaWS { throws JobSubmissionException { WSUtil.validateFastaInput(sequences); ConfiguredExecutable confMuscle = init(sequences); - return WSUtil.align(sequences, confMuscle, null, "align", getLimit("")); + return WSUtil.align(sequences, confMuscle, log, "align", getLimit("")); } ConfiguredExecutable init(List sequences) @@ -90,7 +90,7 @@ public class MuscleWS implements MsaWS { List params = WSUtil.getCommands(options, Muscle.KEY_VALUE_SEPARATOR); confMuscle.addParameters(params); - return WSUtil.align(sequences, confMuscle, null, "customAlign", + return WSUtil.align(sequences, confMuscle, log, "customAlign", getLimit("")); } @@ -105,7 +105,7 @@ public class MuscleWS implements MsaWS { ConfiguredExecutable confMuscle = init(sequences); confMuscle.addParameters(preset.getOptions()); Limit limit = getLimit(preset.getName()); - return WSUtil.align(sequences, confMuscle, null, "presetAlign", limit); + return WSUtil.align(sequences, confMuscle, log, "presetAlign", limit); } @SuppressWarnings("unchecked") diff --git a/webservices/compbio/ws/server/ProbconsWS.java b/webservices/compbio/ws/server/ProbconsWS.java index 3d80cad..71f4730 100644 --- a/webservices/compbio/ws/server/ProbconsWS.java +++ b/webservices/compbio/ws/server/ProbconsWS.java @@ -63,8 +63,8 @@ public class ProbconsWS implements MsaWS { throws JobSubmissionException { WSUtil.validateFastaInput(sequences); ConfiguredExecutable confProbcons = init(sequences); - return WSUtil.align(sequences, confProbcons, null, "align", - getLimit("")); + return WSUtil + .align(sequences, confProbcons, log, "align", getLimit("")); } ConfiguredExecutable init(List dataSet) @@ -86,7 +86,7 @@ public class ProbconsWS implements MsaWS { Probcons.KEY_VALUE_SEPARATOR); log.info("Setting parameters:" + params); confProbcons.addParameters(params); - return WSUtil.align(sequences, confProbcons, null, "customAlign", + return WSUtil.align(sequences, confProbcons, log, "customAlign", getLimit("")); } @@ -101,8 +101,7 @@ public class ProbconsWS implements MsaWS { ConfiguredExecutable confProbcons = init(sequences); confProbcons.addParameters(preset.getOptions()); Limit limit = getLimit(preset.getName()); - return WSUtil - .align(sequences, confProbcons, null, "presetAlign", limit); + return WSUtil.align(sequences, confProbcons, log, "presetAlign", limit); } @SuppressWarnings("unchecked") diff --git a/webservices/compbio/ws/server/TcoffeeWS.java b/webservices/compbio/ws/server/TcoffeeWS.java index e9bda4d..086d870 100644 --- a/webservices/compbio/ws/server/TcoffeeWS.java +++ b/webservices/compbio/ws/server/TcoffeeWS.java @@ -67,8 +67,7 @@ public class TcoffeeWS implements MsaWS { throws JobSubmissionException { WSUtil.validateFastaInput(sequences); ConfiguredExecutable confTcoffee = init(sequences); - return WSUtil - .align(sequences, confTcoffee, null, "align", getLimit("")); + return WSUtil.align(sequences, confTcoffee, log, "align", getLimit("")); } ConfiguredExecutable init(List sequences) @@ -101,7 +100,7 @@ public class TcoffeeWS implements MsaWS { Tcoffee.KEY_VALUE_SEPARATOR); log.info("Setting parameters:" + params); confTcoffee.addParameters(params); - return WSUtil.align(sequences, confTcoffee, null, "customAlign", + return WSUtil.align(sequences, confTcoffee, log, "customAlign", getLimit("")); } @@ -116,7 +115,7 @@ public class TcoffeeWS implements MsaWS { ConfiguredExecutable confTcoffee = init(sequences); confTcoffee.addParameters(preset.getOptions()); Limit limit = getLimit(preset.getName()); - return WSUtil.align(sequences, confTcoffee, null, "presetAlign", limit); + return WSUtil.align(sequences, confTcoffee, log, "presetAlign", limit); } @SuppressWarnings("unchecked") diff --git a/webservices/compbio/ws/server/WSUtil.java b/webservices/compbio/ws/server/WSUtil.java index fb96de8..7341989 100644 --- a/webservices/compbio/ws/server/WSUtil.java +++ b/webservices/compbio/ws/server/WSUtil.java @@ -38,6 +38,8 @@ import compbio.metadata.Limit; import compbio.metadata.LimitExceededException; import compbio.metadata.Option; import compbio.metadata.ResultNotAvailableException; +import compbio.ws.client.Services; +import compbio.ws.client.ServicesUtil; public final class WSUtil { @@ -106,9 +108,19 @@ public final class WSUtil { compbio.runner.Util.writeInput(sequences, confExec); AsyncExecutor engine = Configurator.getAsyncEngine(confExec); String jobId = engine.submitJob(confExec); + reportUsage(confExec, logger); return jobId; } + static void reportUsage(ConfiguredExecutable confExec, Logger logger) { + if (GAUtils.IS_GA_ENABLED) { + Services service = ServicesUtil.getServiceByRunner(confExec + .getExecutable().getClass()); + GAUtils.reportUsage(service); + logger.info("Reporting GA usage for " + service); + } + } + public static String analize(List sequences, ConfiguredExecutable confExec, Logger log, String method, Limit limit) throws JobSubmissionException { @@ -120,7 +132,7 @@ public final class WSUtil { compbio.runner.Util.writeInput(sequences, confExec); AsyncExecutor engine = Configurator.getAsyncEngine(confExec); String jobId = engine.submitJob(confExec); - + reportUsage(confExec, log); return jobId; }