beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lc...@apache.org
Subject [1/2] beam git commit: [BEAM-1871] Migrate ReleaseInfo away from Google API client GenericJson
Date Thu, 04 May 2017 14:41:22 GMT
Repository: beam
Updated Branches:
  refs/heads/master 3c5891b31 -> 98e92a0b8


[BEAM-1871] Migrate ReleaseInfo away from Google API client GenericJson


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/cc654f02
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/cc654f02
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/cc654f02

Branch: refs/heads/master
Commit: cc654f02e8670ea789aee67508c569e7547ef11f
Parents: 3c5891b
Author: Luke Cwik <lcwik@google.com>
Authored: Wed May 3 13:48:07 2017 -0700
Committer: Luke Cwik <lcwik@google.com>
Committed: Thu May 4 07:40:39 2017 -0700

----------------------------------------------------------------------
 .../beam/runners/dataflow/DataflowRunner.java   |  2 +-
 .../org/apache/beam/sdk/util/ReleaseInfo.java   | 70 +++++++++++---------
 2 files changed, 40 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/cc654f02/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
----------------------------------------------------------------------
diff --git a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
index 9e5a2fb..2b54ba7 100644
--- a/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
+++ b/runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
@@ -542,7 +542,7 @@ public class DataflowRunner extends PipelineRunner<DataflowPipelineJob>
{
         "Unable to submit a job to the Dataflow service with unset version ${pom.version}");
     System.out.println("Dataflow SDK version: " + version);
 
-    newJob.getEnvironment().setUserAgent(releaseInfo);
+    newJob.getEnvironment().setUserAgent((Map) releaseInfo.getProperties());
     // The Dataflow Service may write to the temporary directory directly, so
     // must be verified.
     if (!isNullOrEmpty(options.getGcpTempLocation())) {

http://git-wip-us.apache.org/repos/asf/beam/blob/cc654f02/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ReleaseInfo.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ReleaseInfo.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ReleaseInfo.java
index eeac557..c7e24d2 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ReleaseInfo.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ReleaseInfo.java
@@ -17,27 +17,24 @@
  */
 package org.apache.beam.sdk.util;
 
-import com.google.api.client.json.GenericJson;
-import com.google.api.client.util.Key;
+import com.google.auto.value.AutoValue;
+import com.google.common.collect.ImmutableMap;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Serializable;
+import java.util.Map;
 import java.util.Properties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Utilities for working with release information.
+ * Properties pertaining to this release of Apache Beam.
+ *
+ * <p>Properties will always include a name and version.
  */
-public final class ReleaseInfo extends GenericJson {
-  private static final Logger LOG = LoggerFactory.getLogger(ReleaseInfo.class);
-
-  private static final String PROPERTIES_PATH =
-      "/org/apache/beam/sdk/sdk.properties";
-
-  private static class LazyInit {
-    private static final ReleaseInfo INSTANCE =
-        new ReleaseInfo(PROPERTIES_PATH);
-  }
+@AutoValue
+public abstract class ReleaseInfo implements Serializable {
+  private static final String PROPERTIES_PATH = "/org/apache/beam/sdk/sdk.properties";
 
   /**
    * Returns an instance of {@link ReleaseInfo}.
@@ -46,35 +43,46 @@ public final class ReleaseInfo extends GenericJson {
     return LazyInit.INSTANCE;
   }
 
-  @Key private String name = "Apache Beam SDK for Java";
-  @Key private String version = "Unknown";
+  /**
+   * Returns an immutable map of all properties pertaining to this release.
+   */
+  public abstract Map<String, String> getProperties();
 
   /** Provides the SDK name. */
   public String getName() {
-    return name;
+    return getProperties().get("name");
   }
 
   /** Provides the SDK version. */
   public String getVersion() {
-    return version;
+    return getProperties().get("version");
   }
 
-  private ReleaseInfo(String resourcePath) {
-    Properties properties = new Properties();
+  /////////////////////////////////////////////////////////////////////////
+  private static final Logger LOG = LoggerFactory.getLogger(ReleaseInfo.class);
+  private static final String DEFAULT_NAME = "Apache Beam SDK for Java";
+  private static final String DEFAULT_VERSION = "Unknown";
 
-    try (InputStream in = ReleaseInfo.class.getResourceAsStream(PROPERTIES_PATH)) {
-      if (in == null) {
-        LOG.warn("Beam properties resource not found: {}", resourcePath);
-        return;
+  private static class LazyInit {
+    private static final ReleaseInfo INSTANCE;
+    static {
+      Properties properties = new Properties();
+      try (InputStream in = ReleaseInfo.class.getResourceAsStream(PROPERTIES_PATH)) {
+        if (in == null) {
+          LOG.warn("Beam properties resource not found: {}", PROPERTIES_PATH);
+        } else {
+          properties.load(in);
+        }
+      } catch (IOException e) {
+        LOG.warn("Error loading Beam properties resource: ", e);
       }
-
-      properties.load(in);
-    } catch (IOException e) {
-      LOG.warn("Error loading Beam properties resource: ", e);
-    }
-
-    for (String name : properties.stringPropertyNames()) {
-      put(name, properties.getProperty(name));
+      if (!properties.containsKey("name")) {
+        properties.setProperty("name", DEFAULT_NAME);
+      }
+      if (!properties.containsKey("version")) {
+        properties.setProperty("version", DEFAULT_VERSION);
+      }
+      INSTANCE = new AutoValue_ReleaseInfo(ImmutableMap.copyOf((Map) properties));
     }
   }
 }


Mime
View raw message