Repository: zeppelin
Updated Branches:
  refs/heads/master c580a82ad -> 323aa1883


[ZEPPELIN-1391][Interpreters] print error while existing registedInterpreter 
with the same key but different settings

### What is this PR for?
print error while existing registedInterpreter with the same key but different 
settings.
In order to compare the property Map in the Interpreter easily,
I override the `equals` method in `InterpreterProperty` class. (and `hashCode` 
at the same time)

and I fix a small error in  `InterpreterProperty.toString()`, its result forgot 
`}` in the end.

### What type of PR is it?
Improvement

### Todos

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1391

### How should this be tested?
Existing tests.

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: WeichenXu <weichenxu...@outlook.com>

Closes #1382 from WeichenXu123/interpreter_key_error_check and squashes the 
following commits:

4ef032e [WeichenXu] print error while existing registedInterpreter with the 
same key but different settings


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

Branch: refs/heads/master
Commit: 323aa18830ce20ddd8bae25b630661548c89a97c
Parents: c580a82
Author: WeichenXu <weichenxu...@outlook.com>
Authored: Sun Aug 28 00:10:50 2016 -0700
Committer: Damien CORNEAU <cornead...@gmail.com>
Committed: Thu Sep 1 17:01:30 2016 +0900

----------------------------------------------------------------------
 .../org/apache/zeppelin/interpreter/Interpreter.java    |  6 +++++-
 .../zeppelin/interpreter/InterpreterProperty.java       | 12 ++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/323aa188/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java
 
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java
index 07f9cba..42caafd 100644
--- 
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java
+++ 
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/Interpreter.java
@@ -345,10 +345,14 @@ public abstract class Interpreter {
   }
 
   public static void register(RegisteredInterpreter registeredInterpreter) {
-    // TODO(jongyoul): Error should occur when two same interpreter key with 
different settings
     String interpreterKey = registeredInterpreter.getInterpreterKey();
     if (!registeredInterpreters.containsKey(interpreterKey)) {
       registeredInterpreters.put(interpreterKey, registeredInterpreter);
+    } else {
+      RegisteredInterpreter existInterpreter = 
registeredInterpreters.get(interpreterKey);
+      if 
(!existInterpreter.getProperties().equals(registeredInterpreter.getProperties()))
 {
+        logger.error("exist registeredInterpreter with the same key but has 
different settings.");
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/323aa188/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterProperty.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterProperty.java
 
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterProperty.java
index 5067586..c69de5d 100644
--- 
a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterProperty.java
+++ 
b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterProperty.java
@@ -70,6 +70,14 @@ public class InterpreterProperty {
     this.description = description;
   }
 
+  public int hashCode() {
+    return this.toString().hashCode();
+  }
+
+  public boolean equals(Object o) {
+    return this.toString().equals(o.toString());
+  }
+
   public String getValue() {
     if (envName != null && !envName.isEmpty()) {
       String envValue = System.getenv().get(envName);
@@ -89,7 +97,7 @@ public class InterpreterProperty {
 
   @Override
   public String toString() {
-    return String.format("{envName=%s, propertyName=%s, defaultValue=%s, 
description=%20s", envName,
-        propertyName, defaultValue, description);
+    return String.format("{envName=%s, propertyName=%s, defaultValue=%s, 
description=%20s}",
+            envName, propertyName, defaultValue, description);
   }
 }

Reply via email to