Repository: incubator-livy
Updated Branches:
  refs/heads/master 412ccc8fc -> 624bb07b2


Minor. Fix deprecated conf warning log issue

```
./livy-sshao-server.out.5:17/05/08 16:50:44 WARN LivyConf: The configuration 
key livy.spark.deployMode has been deprecated as of Livy 0.4 and may be removed 
in the future. Please use the new key livy.spark.deploy-mode instead.
./livy-sshao-server.out.5:17/05/08 16:50:45 WARN LivyConf: The configuration 
key livy.spark.scalaVersion has been deprecated as of Livy 0.4 and may be 
removed in the future. Please use the new key livy.spark.scala-version instead.
./livy-sshao-server.out.5:17/05/08 16:51:04 WARN RSCConf: The configuration key 
livy.rsc.driver_class has been deprecated as of Livy 0.4 and may be removed in 
the future. Please use the new key livy.rsc.driver-class instead.
```

This log is incorrect even if we use new configuration key. This is mainly 
because the logic in logDeprecationWarning to check alternative configurations 
is not correct.

Author: jerryshao <ss...@hortonworks.com>

Closes #13 from jerryshao/fix-log.


Project: http://git-wip-us.apache.org/repos/asf/incubator-livy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-livy/commit/624bb07b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-livy/tree/624bb07b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-livy/diff/624bb07b

Branch: refs/heads/master
Commit: 624bb07b29a7734645d3e8565d3436ab38ff07f6
Parents: 412ccc8
Author: jerryshao <ss...@hortonworks.com>
Authored: Thu Jul 6 10:27:45 2017 +0800
Committer: jerryshao <ss...@hortonworks.com>
Committed: Thu Jul 6 10:27:45 2017 +0800

----------------------------------------------------------------------
 .../apache/livy/client/common/ClientConf.java   | 42 +++++++++++++++-----
 1 file changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/624bb07b/client-common/src/main/java/org/apache/livy/client/common/ClientConf.java
----------------------------------------------------------------------
diff --git 
a/client-common/src/main/java/org/apache/livy/client/common/ClientConf.java 
b/client-common/src/main/java/org/apache/livy/client/common/ClientConf.java
index 52fcb6b..dfeff7e 100644
--- a/client-common/src/main/java/org/apache/livy/client/common/ClientConf.java
+++ b/client-common/src/main/java/org/apache/livy/client/common/ClientConf.java
@@ -17,10 +17,7 @@
 
 package org.apache.livy.client.common;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
@@ -213,11 +210,11 @@ public abstract class ClientConf<T extends ClientConf>
 
   /** Logs a warning message if the given config key is deprecated. */
   private void logDeprecationWarning(String key) {
-    DeprecatedConf altConfs = getConfigsWithAlternatives().get(key);
-    if (altConfs != null) {
-      LOG.warn("The configuration key " + altConfs.key() + " has been 
deprecated as of Livy "
-        + altConfs.version() + " and may be removed in the future. Please use 
the new key "
-        + key + " instead.");
+    ConfPair altConf = allAlternativeKeys().get(key);
+    if (altConf != null) {
+      LOG.warn("The configuration key " + key + " has been deprecated as of 
Livy "
+        + altConf.depConf.version() + " and may be removed in the future. 
Please use the new key "
+        + altConf.newKey + " instead.");
       return;
     }
 
@@ -235,6 +232,33 @@ public abstract class ClientConf<T extends ClientConf>
   /** Maps deprecated key to DeprecatedConf with the same key. */
   protected abstract Map<String, DeprecatedConf> getDeprecatedConfigs();
 
+  private static class ConfPair {
+    final String newKey;
+    final DeprecatedConf depConf;
+
+    ConfPair(String key, DeprecatedConf conf) {
+      this.newKey = key;
+      this.depConf = conf;
+    }
+  }
+  private volatile Map<String, ConfPair> altToNewKeyMap = null;
+
+  private Map<String, ConfPair> allAlternativeKeys() {
+    if (altToNewKeyMap == null) {
+      synchronized (this) {
+        if (altToNewKeyMap == null) {
+          Map<String, ConfPair> configs = new HashMap<>();
+          for (String e : getConfigsWithAlternatives().keySet()) {
+            DeprecatedConf depConf = getConfigsWithAlternatives().get(e);
+            configs.put(depConf.key(), new ConfPair(e, depConf));
+          }
+          altToNewKeyMap = Collections.unmodifiableMap(configs);
+        }
+      }
+    }
+    return altToNewKeyMap;
+  }
+
   public static interface DeprecatedConf {
 
     /** The key in the configuration file. */

Reply via email to