You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2016/11/07 16:15:24 UTC

zeppelin git commit: ZEPPELIN-1606. Add interpreter option to interpreter-setting.json

Repository: zeppelin
Updated Branches:
  refs/heads/master 1cde24665 -> 48e92189a


ZEPPELIN-1606. Add interpreter option to interpreter-setting.json

### What is this PR for?
For livy, the default mode should be scoped per use. This PR is trying to add interpreter option to `interpreter-setting.json` to allow user to set the default mode.

### What type of PR is it?
[Improvement]

### Todos
This PR is just a short term solution. There're several followup work needs to be done.
* Refactor livy interpeter to adapt scope mode.
* Option should be interpretergroup level setting rather than interpreter level setting.
* Format of `interperter-setting.json` is not consistent with `Interpereter.json`, there's some code duplication, like `RegisteredInterpereter`,  `InterpreterInfo` and etc.
* And this PR doesn't address the issue of mode restriction, user can still change to an invalid mode manually.

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

### How should this be tested?
Outline the steps to test the PR here.

### 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: Jeff Zhang <zj...@apache.org>

Closes #1585 from zjffdu/ZEPPELIN-1606 and squashes the following commits:

a4358b4 [Jeff Zhang] remove guava from zeppelin-interpreter
26e6cc2 [Jeff Zhang] ZEPPELIN-1606. Add interpreter option to interpreter-setting.json


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

Branch: refs/heads/master
Commit: 48e92189ac5b4ba8c17ca3e6aa93e2ebc3427257
Parents: 1cde246
Author: Jeff Zhang <zj...@apache.org>
Authored: Thu Nov 3 14:26:13 2016 +0800
Committer: Lee moon soo <mo...@apache.org>
Committed: Mon Nov 7 08:15:19 2016 -0800

----------------------------------------------------------------------
 .../src/main/resources/interpreter-setting.json |  36 +++++
 .../zeppelin/interpreter/Interpreter.java       |   4 +
 .../zeppelin/interpreter/InterpreterOption.java | 146 +++++++++++++++++++
 .../interpreter/InterpreterFactory.java         |  13 +-
 .../zeppelin/interpreter/InterpreterOption.java | 145 ------------------
 5 files changed, 193 insertions(+), 151 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/48e92189/livy/src/main/resources/interpreter-setting.json
----------------------------------------------------------------------
diff --git a/livy/src/main/resources/interpreter-setting.json b/livy/src/main/resources/interpreter-setting.json
index 0c28e40..fc74281 100644
--- a/livy/src/main/resources/interpreter-setting.json
+++ b/livy/src/main/resources/interpreter-setting.json
@@ -93,6 +93,15 @@
         "description": "Whether display app info"
       }
     },
+    "option": {
+      "remote": true,
+      "port": -1,
+      "perNote": "shared",
+      "perUser": "scoped",
+      "isExistingProcess": false,
+      "setPermission": false,
+      "users": []
+    },
     "editor": {
       "language": "scala",
       "editOnDblClick": false
@@ -115,6 +124,15 @@
         "description": "Execute multiple SQL concurrently if set true."
       }
     },
+    "option": {
+      "remote": true,
+      "port": -1,
+      "perNote": "shared",
+      "perUser": "scoped",
+      "isExistingProcess": false,
+      "setPermission": false,
+      "users": []
+    },
     "editor": {
       "language": "sql",
       "editOnDblClick": false
@@ -126,6 +144,15 @@
     "className": "org.apache.zeppelin.livy.LivyPySparkInterpreter",
     "properties": {
     },
+    "option": {
+      "remote": true,
+      "port": -1,
+      "perNote": "shared",
+      "perUser": "scoped",
+      "isExistingProcess": false,
+      "setPermission": false,
+      "users": []
+    },
     "editor": {
       "language": "python",
       "editOnDblClick": false
@@ -137,6 +164,15 @@
     "className": "org.apache.zeppelin.livy.LivySparkRInterpreter",
     "properties": {
     },
+    "option": {
+      "remote": true,
+      "port": -1,
+      "perNote": "shared",
+      "perUser": "scoped",
+      "isExistingProcess": false,
+      "setPermission": false,
+      "users": []
+    },
     "editor": {
       "language": "r",
       "editOnDblClick": false

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/48e92189/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 3e32320..c068e04 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
@@ -319,6 +319,7 @@ public abstract class Interpreter {
     private Map<String, InterpreterProperty> properties;
     private Map<String, Object> editor;
     private String path;
+    private InterpreterOption option;
 
     public RegisteredInterpreter(String name, String group, String className,
         Map<String, InterpreterProperty> properties) {
@@ -376,6 +377,9 @@ public abstract class Interpreter {
       return getGroup() + "." + getName();
     }
 
+    public InterpreterOption getOption() {
+      return option;
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/48e92189/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java
----------------------------------------------------------------------
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java
new file mode 100644
index 0000000..6ab4d11
--- /dev/null
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zeppelin.interpreter;
+
+import java.util.List;
+
+/**
+ *
+ */
+public class InterpreterOption {
+  public static final transient String SHARED = "shared";
+  public static final transient String SCOPED = "scoped";
+  public static final transient String ISOLATED = "isolated";
+
+  boolean remote;
+  String host = null;
+  int port = -1;
+
+  String perNote;
+  String perUser;
+
+  boolean isExistingProcess;
+  boolean setPermission;
+  List<String> users;
+
+  public boolean isExistingProcess() {
+    return isExistingProcess;
+  }
+
+  public void setExistingProcess(boolean isExistingProcess) {
+    this.isExistingProcess = isExistingProcess;
+  }
+
+  public void setPort(int port) {
+    this.port = port;
+  }
+
+  public void setHost(String host) {
+    this.host = host;
+  }
+
+  public boolean permissionIsSet() {
+    return setPermission;
+  }
+
+  public void setUserPermission(boolean setPermission) {
+    this.setPermission = setPermission;
+  }
+
+  public List<String> getUsers() {
+    return users;
+  }
+
+  public InterpreterOption() {
+    this(false);
+  }
+
+  public InterpreterOption(boolean remote) {
+    this(remote, SHARED, SHARED);
+  }
+
+  public InterpreterOption(boolean remote, String perUser, String perNote) {
+    if (perUser == null) {
+      throw new NullPointerException("perUser can not be null.");
+    }
+    if (perNote == null) {
+      throw new NullPointerException("perNote can not be null.");
+    }
+
+    this.remote = remote;
+    this.perUser = perUser;
+    this.perNote = perNote;
+  }
+
+  public boolean isRemote() {
+    return remote;
+  }
+
+  public void setRemote(boolean remote) {
+    this.remote = remote;
+  }
+
+  public String getHost() {
+    return host;
+  }
+
+  public int getPort() {
+    return port;
+  }
+
+
+  public boolean perUserShared() {
+    return SHARED.equals(perUser);
+  }
+
+  public boolean perUserScoped() {
+    return SCOPED.equals(perUser);
+  }
+
+  public boolean perUserIsolated() {
+    return ISOLATED.equals(perUser);
+  }
+
+  public boolean perNoteShared() {
+    return SHARED.equals(perNote);
+  }
+
+  public boolean perNoteScoped() {
+    return SCOPED.equals(perNote);
+  }
+
+  public boolean perNoteIsolated() {
+    return ISOLATED.equals(perNote);
+  }
+
+  public boolean isProcess() {
+    return perUserIsolated() || perNoteIsolated();
+  }
+
+  public boolean isSession() {
+    return perUserScoped() || perNoteScoped();
+  }
+
+  public void setPerNote(String perNote) {
+    this.perNote = perNote;
+  }
+
+  public void setPerUser(String perUser) {
+    this.perUser = perUser;
+  }
+}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/48e92189/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
index 85a9254..ce740b7 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java
@@ -238,7 +238,7 @@ public class InterpreterFactory implements InterpreterGroupFactory {
       interpreterInfo =
           new InterpreterInfo(r.getClassName(), r.getName(), r.isDefaultInterpreter(),
               r.getEditor());
-      add(r.getGroup(), interpreterInfo, r.getProperties(), r.getPath());
+      add(r.getGroup(), interpreterInfo, r.getProperties(), defaultOption, r.getPath());
     }
 
     for (String settingId : interpreterSettingsRef.keySet()) {
@@ -350,9 +350,11 @@ public class InterpreterFactory implements InterpreterGroupFactory {
       InterpreterInfo interpreterInfo =
           new InterpreterInfo(registeredInterpreter.getClassName(), registeredInterpreter.getName(),
               registeredInterpreter.isDefaultInterpreter(), registeredInterpreter.getEditor());
-
+      // use defaultOption if it is not specified in interpreter-setting.json
+      InterpreterOption option = registeredInterpreter.getOption() == null ? defaultOption :
+          registeredInterpreter.getOption();
       add(registeredInterpreter.getGroup(), interpreterInfo, registeredInterpreter.getProperties(),
-          absolutePath);
+          option, absolutePath);
     }
 
   }
@@ -617,12 +619,11 @@ public class InterpreterFactory implements InterpreterGroupFactory {
   }
 
   private InterpreterSetting add(String group, InterpreterInfo interpreterInfo,
-      Map<String, InterpreterProperty> interpreterProperties, String path)
+      Map<String, InterpreterProperty> interpreterProperties, InterpreterOption option, String path)
       throws InterpreterException, IOException, RepositoryException {
     ArrayList<InterpreterInfo> infos = new ArrayList<>();
     infos.add(interpreterInfo);
-    return add(group, infos, new ArrayList<Dependency>(), defaultOption,
-        interpreterProperties, path);
+    return add(group, infos, new ArrayList<Dependency>(), option, interpreterProperties, path);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/48e92189/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java
deleted file mode 100644
index e5c0f51..0000000
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterOption.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zeppelin.interpreter;
-
-import com.google.common.base.Preconditions;
-
-import java.util.List;
-
-/**
- *
- */
-public class InterpreterOption {
-  public static final transient String SHARED = "shared";
-  public static final transient String SCOPED = "scoped";
-  public static final transient String ISOLATED = "isolated";
-
-  boolean remote;
-  String host = null;
-  int port = -1;
-
-  String perNote;
-  String perUser;
-
-  boolean isExistingProcess;
-  boolean setPermission;
-  List<String> users;
-
-  public boolean isExistingProcess() {
-    return isExistingProcess;
-  }
-
-  public void setExistingProcess(boolean isExistingProcess) {
-    this.isExistingProcess = isExistingProcess;
-  }
-
-  public void setPort(int port) {
-    this.port = port;
-  }
-
-  public void setHost(String host) {
-    this.host = host;
-  }
-
-  public boolean permissionIsSet() {
-    return setPermission;
-  }
-
-  public void setUserPermission(boolean setPermission) {
-    this.setPermission = setPermission;
-  }
-
-  public List<String> getUsers() {
-    return users;
-  }
-
-  public InterpreterOption() {
-    this(false);
-  }
-
-  public InterpreterOption(boolean remote) {
-    this(remote, SHARED, SHARED);
-  }
-
-  public InterpreterOption(boolean remote, String perUser, String perNote) {
-    Preconditions.checkNotNull(remote);
-    Preconditions.checkNotNull(perUser);
-    Preconditions.checkNotNull(perNote);
-
-    this.remote = remote;
-    this.perUser = perUser;
-    this.perNote = perNote;
-  }
-
-  public boolean isRemote() {
-    return remote;
-  }
-
-  public void setRemote(boolean remote) {
-    this.remote = remote;
-  }
-
-  public String getHost() {
-    return host;
-  }
-
-  public int getPort() {
-    return port;
-  }
-
-
-  public boolean perUserShared() {
-    return SHARED.equals(perUser);
-  }
-
-  public boolean perUserScoped() {
-    return SCOPED.equals(perUser);
-  }
-
-  public boolean perUserIsolated() {
-    return ISOLATED.equals(perUser);
-  }
-
-  public boolean perNoteShared() {
-    return SHARED.equals(perNote);
-  }
-
-  public boolean perNoteScoped() {
-    return SCOPED.equals(perNote);
-  }
-
-  public boolean perNoteIsolated() {
-    return ISOLATED.equals(perNote);
-  }
-
-  public boolean isProcess() {
-    return perUserIsolated() || perNoteIsolated();
-  }
-
-  public boolean isSession() {
-    return perUserScoped() || perNoteScoped();
-  }
-
-  public void setPerNote(String perNote) {
-    this.perNote = perNote;
-  }
-
-  public void setPerUser(String perUser) {
-    this.perUser = perUser;
-  }
-}