[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/release] Add build revision field to documents.



commit 0f28ea28f53542b13beedd3d8255c0dfeccd7aec
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Tue Sep 19 10:06:35 2017 +0000

    Add build revision field to documents.
    
    Implements task-23778.
---
 CHANGELOG.md                                       |  2 ++
 build.xml                                          |  2 +-
 .../torproject/onionoo/server/ResponseBuilder.java | 24 ++++++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9a171d..b7b379c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@
    - Only set the "running" field in a bridge's details document to
      true if the bridge is both contained in the last known bridge
      network status and has the "Running" flag assigned there.
+   - Add build_revision to documents, if available.
+   - Update to metrics-lib 2.1.1.
 
  * Minor changes
    - Remove placeholder page on index.html.
diff --git a/build.xml b/build.xml
index c8a4173..72f3ecc 100644
--- a/build.xml
+++ b/build.xml
@@ -11,7 +11,7 @@
   <property name="onionoo.protocol.version" value="4.1"/>
   <property name="release.version"
             value="${onionoo.protocol.version}-1.5.0-dev"/>
-  <property name="metricslibversion" value="2.1.0"/>
+  <property name="metricslibversion" value="2.1.1"/>
   <property name="jetty.version" value="-9.2.21.v20170120" />
   <property name="warfile"
             value="onionoo-${release.version}.war"/>
diff --git a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
index efa02c3..6b6b8ee 100644
--- a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
+++ b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
@@ -18,16 +18,37 @@ import com.google.gson.GsonBuilder;
 
 import org.apache.commons.lang3.StringUtils;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 
 public class ResponseBuilder {
 
+  private static final Logger logger =
+      LoggerFactory.getLogger(ResponseBuilder.class);
+
   private DocumentStore documentStore;
+  private String buildRevision;
 
+  /** Initialize document store and the build revision. */
   public ResponseBuilder() {
     this.documentStore = DocumentStoreFactory.getDocumentStore();
+    Properties buildProperties = new Properties();
+    try (InputStream is = getClass().getClassLoader()
+        .getResourceAsStream("onionoo.buildrevision.properties")) {
+      buildProperties.load(is);
+      buildRevision = buildProperties.getProperty("onionoo.build.revision",
+          null);
+    } catch (Exception ex) {
+      // We create documents anyway: only log a warning.
+      logger.warn("No build revision available.", ex);
+      buildRevision = null;
+    }
   }
 
   private String resourceType;
@@ -112,6 +133,9 @@ public class ResponseBuilder {
       this.write(pw, "\"next_major_version_scheduled\":\"%s\",\n",
           NEXT_MAJOR_VERSION_SCHEDULED);
     }
+    if (null != buildRevision) {
+      this.write(pw, "\"build_revision\":\"%s\",\n", buildRevision);
+    }
     this.write(pw, "\"relays_published\":\"%s\",\n",
         this.relaysPublishedString);
     if (this.relaysSkipped > 0) {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits