You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2021/03/18 04:21:00 UTC
[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5257] Refactoring
of ExecutionContext
This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/branch-0.9 by this push:
new 679298a [ZEPPELIN-5257] Refactoring of ExecutionContext
679298a is described below
commit 679298a6226ef58b94e0496c8746abf9423a711b
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Sun Feb 21 00:41:11 2021 +0800
[ZEPPELIN-5257] Refactoring of ExecutionContext
### What is this PR for?
This PR is to refactoring ExecutionContext: move its creation to `Note`, because most of fields of ExecutionContext is from Note. Moving it to `Note` (Note#getExecutionContext) can help us to create consistent object (avoid missing fields)
### What type of PR is it?
[Refactoring]
### Todos
* [ ] - Task
### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-5257
### How should this be tested?
* CI pass
### 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 #4058 from zjffdu/ZEPPELIN-5257 and squashes the following commits:
84768c10b [Jeff Zhang] [ZEPPELIN-5257] Refactoring of ExecutionContext
(cherry picked from commit 85ed8e2e51e1ea10df38d4710216343efe218d60)
Signed-off-by: Jeff Zhang <zj...@apache.org>
---
.../zeppelin/integration/FlinkIntegrationTest.java | 6 +-
.../zeppelin/integration/JdbcIntegrationTest.java | 6 +-
.../zeppelin/integration/SparkIntegrationTest.java | 14 ++---
.../YarnInterpreterLauncherIntegrationTest.java | 9 +--
.../zeppelin/interpreter/ExecutionContext.java | 46 +++++++++++----
.../interpreter/ExecutionContextBuilder.java | 65 ----------------------
.../apache/zeppelin/rest/InterpreterRestApi.java | 7 +--
.../apache/zeppelin/socket/NotebookServerTest.java | 6 +-
.../zeppelin/interpreter/InterpreterSetting.java | 32 ++++++++---
.../interpreter/InterpreterSettingManager.java | 22 ++++++--
.../java/org/apache/zeppelin/notebook/Note.java | 39 ++++++++-----
.../org/apache/zeppelin/notebook/Notebook.java | 4 +-
.../org/apache/zeppelin/notebook/Paragraph.java | 23 ++------
.../interpreter/AbstractInterpreterTest.java | 6 ++
.../zeppelin/interpreter/ConfInterpreterTest.java | 8 +--
.../interpreter/InterpreterFactoryTest.java | 24 ++++----
.../interpreter/InterpreterSettingManagerTest.java | 16 ++++++
.../interpreter/InterpreterSettingTest.java | 37 +++++++++++-
.../lifecycle/TimeoutLifecycleManagerTest.java | 10 ++--
.../recovery/FileSystemRecoveryStorageTest.java | 8 +++
.../recovery/LocalRecoveryStorageTest.java | 8 +++
.../remote/RemoteAngularObjectTest.java | 5 ++
.../interpreter/remote/RemoteInterpreterTest.java | 5 ++
.../org/apache/zeppelin/notebook/NotebookTest.java | 21 +++----
.../resource/DistributedResourcePoolTest.java | 8 +++
.../zeppelin/scheduler/RemoteSchedulerTest.java | 6 ++
26 files changed, 258 insertions(+), 183 deletions(-)
diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java
index 4bd969b..1e0f61e 100644
--- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java
+++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java
@@ -23,7 +23,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse;
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
+import org.apache.zeppelin.interpreter.ExecutionContext;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
@@ -94,7 +94,7 @@ public abstract class FlinkIntegrationTest {
private void testInterpreterBasics() throws IOException, InterpreterException {
// test FlinkInterpreter
- Interpreter flinkInterpreter = interpreterFactory.getInterpreter("flink", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("flink").createExecutionContext());
+ Interpreter flinkInterpreter = interpreterFactory.getInterpreter("flink", new ExecutionContext("user1", "note1", "flink"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = flinkInterpreter.interpret("1+1", context);
@@ -119,7 +119,7 @@ public abstract class FlinkIntegrationTest {
InterpreterSetting flinkCmdInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("flink-cmd");
flinkCmdInterpreterSetting.setProperty("FLINK_HOME", flinkHome);
- Interpreter flinkCmdInterpreter = interpreterFactory.getInterpreter("flink-cmd", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("flink").createExecutionContext());
+ Interpreter flinkCmdInterpreter = interpreterFactory.getInterpreter("flink-cmd", new ExecutionContext("user1", "note1", "flink"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = flinkCmdInterpreter.interpret("info -c org.apache.flink.streaming.examples.wordcount.WordCount " + flinkHome + "/examples/streaming/WordCount.jar", context);
assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java
index 8b7ab29..a86b916 100644
--- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java
+++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java
@@ -19,7 +19,7 @@ package org.apache.zeppelin.integration;
import com.google.common.collect.Lists;
import org.apache.zeppelin.dep.Dependency;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
+import org.apache.zeppelin.interpreter.ExecutionContext;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
@@ -71,7 +71,7 @@ public class JdbcIntegrationTest {
interpreterSetting.setDependencies(Lists.newArrayList(dependency));
interpreterSettingManager.restart(interpreterSetting.getId());
interpreterSetting.waitForReady(60 * 1000);
- Interpreter jdbcInterpreter = interpreterFactory.getInterpreter("jdbc", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter jdbcInterpreter = interpreterFactory.getInterpreter("jdbc", new ExecutionContext("user1", "note1", "test"));
assertNotNull("JdbcInterpreter is null", jdbcInterpreter);
InterpreterContext context = new InterpreterContext.Builder()
@@ -90,7 +90,7 @@ public class JdbcIntegrationTest {
assertEquals("c1\tc2\n1\t2\n", interpreterResult.message().get(0).getData());
// read table_1 from python interpreter
- Interpreter pythonInterpreter = interpreterFactory.getInterpreter("python", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter pythonInterpreter = interpreterFactory.getInterpreter("python", new ExecutionContext("user1", "note1", "test"));
assertNotNull("PythonInterpreter is null", pythonInterpreter);
context = new InterpreterContext.Builder()
diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java
index a29668a..6775cac 100644
--- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java
+++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java
@@ -24,7 +24,7 @@ import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
+import org.apache.zeppelin.interpreter.ExecutionContext;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
@@ -103,7 +103,7 @@ public abstract class SparkIntegrationTest {
sparkInterpreterSetting.setProperty("spark.jars", new File("target/zeppelin-interpreter-integration-" + model.getVersion() + ".jar").getAbsolutePath());
// test SparkInterpreter
- Interpreter sparkInterpreter = interpreterFactory.getInterpreter("spark.spark", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter sparkInterpreter = interpreterFactory.getInterpreter("spark.spark", new ExecutionContext("user1", "note1", "test"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = sparkInterpreter.interpret("sc.version", context);
@@ -120,24 +120,24 @@ public abstract class SparkIntegrationTest {
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test PySparkInterpreter
- Interpreter pySparkInterpreter = interpreterFactory.getInterpreter("spark.pyspark", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter pySparkInterpreter = interpreterFactory.getInterpreter("spark.pyspark", new ExecutionContext("user1", "note1", "test"));
interpreterResult = pySparkInterpreter.interpret("sqlContext.createDataFrame([(1,'a'),(2,'b')], ['id','name']).registerTempTable('test')", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test IPySparkInterpreter
- Interpreter ipySparkInterpreter = interpreterFactory.getInterpreter("spark.ipyspark", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter ipySparkInterpreter = interpreterFactory.getInterpreter("spark.ipyspark", new ExecutionContext("user1", "note1", "test"));
interpreterResult = ipySparkInterpreter.interpret("sqlContext.table('test').show()", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test SparkSQLInterpreter
- Interpreter sqlInterpreter = interpreterFactory.getInterpreter("spark.sql", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter sqlInterpreter = interpreterFactory.getInterpreter("spark.sql", new ExecutionContext("user1", "note1", "test"));
interpreterResult = sqlInterpreter.interpret("select count(1) as c from test", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertEquals(interpreterResult.toString(), InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
assertEquals(interpreterResult.toString(), "c\n2\n", interpreterResult.message().get(0).getData());
// test SparkRInterpreter
- Interpreter sparkrInterpreter = interpreterFactory.getInterpreter("spark.r", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter sparkrInterpreter = interpreterFactory.getInterpreter("spark.r", new ExecutionContext("user1", "note1", "test"));
if (isSpark2() || isSpark3()) {
interpreterResult = sparkrInterpreter.interpret("df <- as.DataFrame(faithful)\nhead(df)", context);
} else {
@@ -255,7 +255,7 @@ public abstract class SparkIntegrationTest {
sparkSubmitInterpreterSetting.setProperty("SPARK_HOME", sparkHome);
// test SparkSubmitInterpreter
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
- Interpreter sparkSubmitInterpreter = interpreterFactory.getInterpreter("spark-submit", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter sparkSubmitInterpreter = interpreterFactory.getInterpreter("spark-submit", new ExecutionContext("user1", "note1", "test"));
InterpreterResult interpreterResult = sparkSubmitInterpreter.interpret("--class org.apache.spark.examples.SparkPi " + sparkHome + "/examples/jars/spark-examples*.jar ", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java
index 5623a25..5f7a723 100644
--- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java
+++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java
@@ -24,7 +24,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse;
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.zeppelin.dep.Dependency;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
+import org.apache.zeppelin.interpreter.ExecutionContext;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
@@ -34,6 +34,7 @@ import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.InterpreterSettingManager;
import org.apache.zeppelin.user.AuthenticationInfo;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
@@ -85,7 +86,7 @@ public class YarnInterpreterLauncherIntegrationTest {
shellInterpreterSetting.setProperty("zeppelin.interpreter.launcher", "yarn");
shellInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath());
- Interpreter shellInterpreter = interpreterFactory.getInterpreter("sh", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("sh").createExecutionContext());
+ Interpreter shellInterpreter = interpreterFactory.getInterpreter("sh", new ExecutionContext("user1", "note1", "sh"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = shellInterpreter.interpret("pwd", context);
@@ -121,7 +122,7 @@ public class YarnInterpreterLauncherIntegrationTest {
pythonInterpreterSetting.setProperty("zeppelin.interpreter.yarn.resource.memory", "512");
pythonInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath());
- Interpreter jdbcInterpreter = interpreterFactory.getInterpreter("jdbc", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter jdbcInterpreter = interpreterFactory.getInterpreter("jdbc", new ExecutionContext("user1", "note1", "test"));
assertNotNull("JdbcInterpreter is null", jdbcInterpreter);
InterpreterContext context = new InterpreterContext.Builder()
@@ -140,7 +141,7 @@ public class YarnInterpreterLauncherIntegrationTest {
assertEquals("c1\tc2\n1\t2\n", interpreterResult.message().get(0).getData());
// read table_1 from python interpreter
- Interpreter pythonInterpreter = interpreterFactory.getInterpreter("python", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ Interpreter pythonInterpreter = interpreterFactory.getInterpreter("python", new ExecutionContext("user1", "note1", "test"));
assertNotNull("PythonInterpreter is null", pythonInterpreter);
context = new InterpreterContext.Builder()
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/ExecutionContext.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/ExecutionContext.java
index 4800619..e0be28a 100644
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/ExecutionContext.java
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/ExecutionContext.java
@@ -23,48 +23,72 @@ package org.apache.zeppelin.interpreter;
*/
public class ExecutionContext {
- private final String user;
- private final String noteId;
- private final String interpreterGroupId;
- private final String defaultInterpreterGroup;
- private final boolean inIsolatedMode;
+ private String user;
+ private String noteId;
+ private String interpreterGroupId;
+ private String defaultInterpreterGroup;
+ private boolean inIsolatedMode;
// When is the execution triggered, e.g. when the cron job is triggered or when the rest api is triggered.
- private final String startTime;
+ private String startTime;
- public ExecutionContext(String user, String noteId, String interpreterGroupId, String defaultInterpreterGroup,
- boolean inIsolatedMode, String startTime) {
+ public ExecutionContext(){
+
+ }
+
+ public ExecutionContext(String user, String noteId, String defaultInterpreterGroup) {
this.user = user;
this.noteId = noteId;
- this.interpreterGroupId = interpreterGroupId;
this.defaultInterpreterGroup = defaultInterpreterGroup;
- this.inIsolatedMode = inIsolatedMode;
- this.startTime = startTime;
}
public String getUser() {
return user;
}
+ public void setUser(String user) {
+ this.user = user;
+ }
+
public String getNoteId() {
return noteId;
}
+ public void setNoteId(String noteId) {
+ this.noteId = noteId;
+ }
+
public String getInterpreterGroupId() {
return interpreterGroupId;
}
+ public void setInterpreterGroupId(String interpreterGroupId) {
+ this.interpreterGroupId = interpreterGroupId;
+ }
+
public String getDefaultInterpreterGroup() {
return defaultInterpreterGroup;
}
+ public void setDefaultInterpreterGroup(String defaultInterpreterGroup) {
+ this.defaultInterpreterGroup = defaultInterpreterGroup;
+ }
+
public boolean isInIsolatedMode() {
return inIsolatedMode;
}
+ public void setInIsolatedMode(boolean inIsolatedMode) {
+ this.inIsolatedMode = inIsolatedMode;
+ }
+
public String getStartTime() {
return startTime;
}
+ public void setStartTime(String startTime) {
+ this.startTime = startTime;
+ }
+
@Override
public String toString() {
return "ExecutionContext{" +
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/ExecutionContextBuilder.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/ExecutionContextBuilder.java
deleted file mode 100644
index 86956d2..0000000
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/ExecutionContextBuilder.java
+++ /dev/null
@@ -1,65 +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;
-
-/**
- * Builder class for ExecutionContext.
- */
-public class ExecutionContextBuilder {
- private String user;
- private String noteId;
- private String interpreterGroupId;
- private String defaultInterpreterGroup = "";
- private boolean inIsolatedMode = false;
- private String startTime = "";
-
- public ExecutionContextBuilder setUser(String user) {
- this.user = user;
- return this;
- }
-
- public ExecutionContextBuilder setNoteId(String noteId) {
- this.noteId = noteId;
- return this;
- }
-
- public ExecutionContextBuilder setDefaultInterpreterGroup(String defaultInterpreterGroup) {
- this.defaultInterpreterGroup = defaultInterpreterGroup;
- return this;
- }
-
- public ExecutionContextBuilder setInIsolatedMode(boolean inIsolatedMode) {
- this.inIsolatedMode = inIsolatedMode;
- return this;
- }
-
- public ExecutionContextBuilder setStartTime(String startTime) {
- this.startTime = startTime;
- return this;
- }
-
- public ExecutionContextBuilder setInterpreterGroupId(String interpreterGroupId) {
- this.interpreterGroupId = interpreterGroupId;
- return this;
- }
-
- public ExecutionContext createExecutionContext() {
- return new ExecutionContext(user, noteId, interpreterGroupId, defaultInterpreterGroup, inIsolatedMode, startTime);
- }
-
-}
\ No newline at end of file
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java
index e573a35..f5e4fc5 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java
@@ -23,7 +23,6 @@ import javax.inject.Singleton;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.zeppelin.annotation.ZeppelinApi;
import org.apache.zeppelin.dep.Repository;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterPropertyType;
import org.apache.zeppelin.interpreter.InterpreterSetting;
@@ -213,11 +212,7 @@ public class InterpreterRestApi {
if (authorizationService.hasRunPermission(entities, noteId) ||
authorizationService.hasWritePermission(entities, noteId) ||
authorizationService.isOwner(entities, noteId)) {
- interpreterSettingManager.restart(settingId,
- new ExecutionContextBuilder()
- .setUser(authenticationService.getPrincipal())
- .setNoteId(noteId)
- .createExecutionContext());
+ interpreterSettingManager.restart(settingId, authenticationService.getPrincipal(), noteId);
} else {
return new JsonResponse<>(Status.FORBIDDEN, "No privilege to restart interpreter")
.build();
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
index aa3fd8f..3facf7d 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
@@ -196,7 +196,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().get();
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("md")) {
- interpreterGroup = setting.getOrCreateInterpreterGroup("anonymous", "sharedProcess");
+ interpreterGroup = setting.getOrCreateInterpreterGroup("anonymous", note1.getId());
break;
}
}
@@ -269,7 +269,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
List<InterpreterSetting> settings = note1.getBindedInterpreterSettings(new ArrayList<>());
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("angular")) {
- interpreterGroup = setting.getOrCreateInterpreterGroup("anonymous", "sharedProcess");
+ interpreterGroup = setting.getOrCreateInterpreterGroup("anonymous", note1.getId());
break;
}
}
@@ -373,7 +373,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
List<InterpreterSetting> settings = notebook.getInterpreterSettingManager().get();
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("angular")) {
- interpreterGroup = setting.getOrCreateInterpreterGroup("anonymous", "sharedProcess");
+ interpreterGroup = setting.getOrCreateInterpreterGroup("anonymous", note1.getId());
break;
}
}
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java
index 2cef777..ca2f9d7 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java
@@ -45,6 +45,7 @@ import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
+import org.apache.zeppelin.notebook.Note;
import org.apache.zeppelin.plugin.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -442,7 +443,7 @@ public class InterpreterSetting {
}
public ManagedInterpreterGroup getOrCreateInterpreterGroup(String user, String noteId) {
- return getOrCreateInterpreterGroup(new ExecutionContextBuilder().setUser(user).setNoteId(noteId).createExecutionContext());
+ return getOrCreateInterpreterGroup(getExecutionContext(user, noteId));
}
public ManagedInterpreterGroup getOrCreateInterpreterGroup(ExecutionContext executionContext) {
@@ -471,7 +472,7 @@ public class InterpreterSetting {
}
public ManagedInterpreterGroup getInterpreterGroup(String user, String noteId) {
- return getInterpreterGroup(new ExecutionContextBuilder().setUser(user).setNoteId(noteId).createExecutionContext());
+ return getInterpreterGroup(getExecutionContext(user, noteId));
}
public ManagedInterpreterGroup getInterpreterGroup(ExecutionContext executionContext) {
@@ -510,11 +511,13 @@ public class InterpreterSetting {
}
public void closeInterpreters(String user, String noteId) {
- closeInterpreters(new ExecutionContextBuilder().setUser(user).setNoteId(noteId).createExecutionContext());
+ closeInterpreters(getExecutionContext(user, noteId));
}
public void closeInterpreters(String interpreterGroupId) {
- closeInterpreters(new ExecutionContextBuilder().setInterpreterGroupId(interpreterGroupId).createExecutionContext());
+ ExecutionContext executionContext = new ExecutionContext();
+ executionContext.setInterpreterGroupId(interpreterGroupId);
+ closeInterpreters(executionContext);
}
public void closeInterpreters(ExecutionContext executionContext) {
@@ -847,7 +850,7 @@ public class InterpreterSetting {
}
List<Interpreter> getOrCreateSession(String user, String noteId) {
- return getOrCreateSession(new ExecutionContextBuilder().setUser(user).setNoteId(noteId).createExecutionContext());
+ return getOrCreateSession(getExecutionContext(user, noteId));
}
List<Interpreter> getOrCreateSession(ExecutionContext executionContext) {
@@ -858,7 +861,7 @@ public class InterpreterSetting {
}
public Interpreter getDefaultInterpreter(String user, String noteId) {
- return getOrCreateSession(new ExecutionContextBuilder().setUser(user).setNoteId(noteId).createExecutionContext()).get(0);
+ return getOrCreateSession(getExecutionContext(user, noteId)).get(0);
}
public Interpreter getDefaultInterpreter(ExecutionContext executionContext) {
@@ -866,7 +869,7 @@ public class InterpreterSetting {
}
public Interpreter getInterpreter(String user, String noteId, String replName) {
- return getInterpreter(new ExecutionContextBuilder().setUser(user).setNoteId(noteId).createExecutionContext(), replName);
+ return getInterpreter(getExecutionContext(user, noteId), replName);
}
public Interpreter getInterpreter(ExecutionContext executionContext, String replName) {
@@ -1191,4 +1194,19 @@ public class InterpreterSetting {
return intpSetting;
}
+
+ private ExecutionContext getExecutionContext(String user, String noteId) {
+ try {
+ Note note = getInterpreterSettingManager().getNotebook().getNote(noteId);
+ if (note == null) {
+ throw new RuntimeException("No such note: " + noteId);
+ } else {
+ ExecutionContext context = note.getExecutionContext();
+ context.setUser(user);
+ return context;
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Fail to getExecutionContext", e);
+ }
+ }
}
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSettingManager.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSettingManager.java
index 85c0955..3bb361b 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSettingManager.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSettingManager.java
@@ -956,7 +956,17 @@ public class InterpreterSettingManager implements NoteEventListener, ClusterEven
// restart in note page
public void restart(String settingId, String user, String noteId) throws InterpreterException {
- restart(settingId, new ExecutionContextBuilder().setUser(user).setNoteId(noteId).createExecutionContext());
+ try {
+ Note note = notebook.getNote(noteId);
+ if (note == null) {
+ throw new InterpreterException("No such note: " + noteId);
+ }
+ ExecutionContext executionContext = note.getExecutionContext();
+ executionContext.setUser(user);
+ restart(settingId, executionContext);
+ } catch (IOException e) {
+ LOGGER.warn("Fail to restart interpreter", e);
+ }
}
// restart in note page
@@ -1114,8 +1124,10 @@ public class InterpreterSettingManager implements NoteEventListener, ClusterEven
Interpreter interpreter = paragraph.getInterpreter();
if (interpreter != null) {
InterpreterSetting interpreterSetting =
- ((ManagedInterpreterGroup) interpreter.getInterpreterGroup()).getInterpreterSetting();
- restart(interpreterSetting.getId(), subject.getUser(), note.getId());
+ ((ManagedInterpreterGroup) interpreter.getInterpreterGroup()).getInterpreterSetting();
+ ExecutionContext executionContext = note.getExecutionContext();
+ executionContext.setUser(subject.getUser());
+ restart(interpreterSetting.getId(), executionContext);
}
} catch (InterpreterNotFoundException e) {
@@ -1127,8 +1139,7 @@ public class InterpreterSettingManager implements NoteEventListener, ClusterEven
// remove from all interpreter instance's angular object registry
for (InterpreterSetting settings : interpreterSettings.values()) {
- InterpreterGroup interpreterGroup = settings.getInterpreterGroup(
- new ExecutionContextBuilder().setUser(subject.getUser()).setNoteId(note.getId()).createExecutionContext());
+ InterpreterGroup interpreterGroup = settings.getInterpreterGroup(note.getExecutionContext());
if (interpreterGroup != null) {
AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
if (registry instanceof RemoteAngularObjectRegistry) {
@@ -1253,5 +1264,4 @@ public class InterpreterSettingManager implements NoteEventListener, ClusterEven
ClusterManagerServer.getInstance(conf).broadcastClusterEvent(
CLUSTER_INTP_SETTING_EVENT_TOPIC, msg);
}
-
}
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
index 231b7bd..22419cd 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
@@ -30,7 +30,6 @@ import org.apache.zeppelin.display.AngularObject;
import org.apache.zeppelin.display.AngularObjectRegistry;
import org.apache.zeppelin.display.Input;
import org.apache.zeppelin.interpreter.ExecutionContext;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterGroup;
@@ -823,14 +822,7 @@ public class Note implements JsonSerializable {
if (isolated) {
LOGGER.info("Releasing interpreters used by this note: {}", id);
for (InterpreterSetting setting : getUsedInterpreterSettings()) {
- ExecutionContext executionContext = new ExecutionContextBuilder()
- .setUser(authInfo.getUser())
- .setNoteId(id)
- .setDefaultInterpreterGroup(defaultInterpreterGroup)
- .setInIsolatedMode(isolated)
- .setStartTime(getStartTime())
- .createExecutionContext();
- setting.closeInterpreters(executionContext);
+ setting.closeInterpreters(getExecutionContext());
for (Paragraph p : paragraphs) {
p.setInterpreter(null);
}
@@ -921,7 +913,7 @@ public class Note implements JsonSerializable {
}
for (InterpreterSetting setting : settings) {
- InterpreterGroup intpGroup = setting.getInterpreterGroup(new ExecutionContextBuilder().setUser(user).setNoteId(id).createExecutionContext());
+ InterpreterGroup intpGroup = setting.getInterpreterGroup(getExecutionContext());
if (intpGroup != null) {
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
angularObjects.put(intpGroup.getId(), registry.getAllWithGlobal(id));
@@ -938,10 +930,10 @@ public class Note implements JsonSerializable {
}
for (InterpreterSetting setting : settings) {
- if (setting.getInterpreterGroup(new ExecutionContextBuilder().setUser(user).setNoteId(id).createExecutionContext()) == null) {
+ if (setting.getInterpreterGroup(getExecutionContext()) == null) {
continue;
}
- InterpreterGroup intpGroup = setting.getInterpreterGroup(new ExecutionContextBuilder().setUser(user).setNoteId(id).createExecutionContext());
+ InterpreterGroup intpGroup = setting.getInterpreterGroup(getExecutionContext());
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
if (registry instanceof RemoteAngularObjectRegistry) {
@@ -1087,8 +1079,12 @@ public class Note implements JsonSerializable {
}
public boolean isIsolatedMode() {
- return Boolean.parseBoolean(
- info.getOrDefault("inIsolatedMode", "false").toString());
+ if (info == null) {
+ return false;
+ } else {
+ return Boolean.parseBoolean(
+ info.getOrDefault("inIsolatedMode", "false").toString());
+ }
}
public void setStartTime(String startTime) {
@@ -1096,7 +1092,11 @@ public class Note implements JsonSerializable {
}
public String getStartTime() {
- return info.getOrDefault("startTime", "").toString();
+ if (info == null) {
+ return null;
+ } else {
+ return info.getOrDefault("startTime", "").toString();
+ }
}
public void clearStartTime() {
@@ -1240,4 +1240,13 @@ public class Note implements JsonSerializable {
public boolean isRemoved() {
return removed;
}
+
+ public ExecutionContext getExecutionContext() {
+ ExecutionContext executionContext = new ExecutionContext();
+ executionContext.setNoteId(id);
+ executionContext.setDefaultInterpreterGroup(defaultInterpreterGroup);
+ executionContext.setInIsolatedMode(isIsolatedMode());
+ executionContext.setStartTime(getStartTime());
+ return executionContext;
+ }
}
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
index 929e923..01c43ea 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
@@ -38,7 +38,6 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.display.AngularObject;
import org.apache.zeppelin.display.AngularObjectRegistry;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterGroup;
@@ -548,8 +547,7 @@ public class Notebook {
SnapshotAngularObject snapshot = angularObjectSnapshotEntry.getValue();
List<InterpreterSetting> settings = interpreterSettingManager.get();
for (InterpreterSetting setting : settings) {
- InterpreterGroup intpGroup = setting.getInterpreterGroup(
- new ExecutionContextBuilder().setUser(subject.getUser()).setNoteId(note.getId()).createExecutionContext());
+ InterpreterGroup intpGroup = setting.getInterpreterGroup(note.getExecutionContext());
if (intpGroup != null && intpGroup.getId().equals(snapshot.getIntpGroupId())) {
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
String noteId = snapshot.getAngularObject().getNoteId();
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
index b3f1557..e3ed7ae 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
@@ -39,7 +39,6 @@ import org.apache.zeppelin.display.Input;
import org.apache.zeppelin.helium.HeliumPackage;
import org.apache.zeppelin.interpreter.Constants;
import org.apache.zeppelin.interpreter.ExecutionContext;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.Interpreter.FormType;
import org.apache.zeppelin.interpreter.InterpreterContext;
@@ -244,15 +243,9 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
}
public Interpreter getBindedInterpreter() throws InterpreterNotFoundException {
- ExecutionContext executionContext = new ExecutionContextBuilder()
- .setUser(user)
- .setNoteId(note.getId())
- .setDefaultInterpreterGroup(note.getDefaultInterpreterGroup())
- .setInIsolatedMode(note.isIsolatedMode())
- .setStartTime(note.getStartTime())
- .setInterpreterGroupId(interpreterGroupId)
- .createExecutionContext();
-
+ ExecutionContext executionContext = note.getExecutionContext();
+ executionContext.setUser(user);
+ executionContext.setInterpreterGroupId(interpreterGroupId);
return this.note.getInterpreterFactory().getInterpreter(intpText, executionContext);
}
@@ -678,13 +671,9 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
public boolean isValidInterpreter(String replName) {
try {
- ExecutionContext executionContext = new ExecutionContextBuilder()
- .setUser(user)
- .setNoteId(note.getId())
- .setDefaultInterpreterGroup(note.getDefaultInterpreterGroup())
- .setInIsolatedMode(note.isIsolatedMode())
- .setStartTime(note.getStartTime())
- .createExecutionContext();
+ ExecutionContext executionContext = note.getExecutionContext();
+ executionContext.setUser(user);
+ executionContext.setInterpreterGroupId(interpreterGroupId);
return note.getInterpreterFactory().getInterpreter(replName, executionContext) != null;
} catch (InterpreterNotFoundException e) {
return false;
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java
index 902a1a4..be46f23 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java
@@ -24,6 +24,7 @@ import org.apache.zeppelin.display.AngularObjectRegistryListener;
import org.apache.zeppelin.helium.ApplicationEventListener;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.Notebook;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
@@ -32,6 +33,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
* This class will load configuration files under
@@ -46,6 +48,7 @@ public abstract class AbstractInterpreterTest {
protected InterpreterSettingManager interpreterSettingManager;
protected InterpreterFactory interpreterFactory;
+ protected Notebook mockNotebook;
protected File zeppelinHome;
protected File interpreterDir;
protected File confDir;
@@ -79,6 +82,9 @@ public abstract class AbstractInterpreterTest {
interpreterSettingManager = new InterpreterSettingManager(conf,
mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
interpreterFactory = new InterpreterFactory(interpreterSettingManager);
+
+ mockNotebook = mock(Notebook.class);
+ interpreterSettingManager.setNotebook(mockNotebook);
}
@After
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java
index cff05d4..41f5d73 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java
@@ -18,6 +18,7 @@
package org.apache.zeppelin.interpreter;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -25,11 +26,8 @@ import static org.junit.Assert.assertTrue;
public class ConfInterpreterTest extends AbstractInterpreterTest {
- private ExecutionContext executionContext = new ExecutionContextBuilder()
- .setUser("user1")
- .setNoteId("note1")
- .setDefaultInterpreterGroup("test")
- .createExecutionContext();
+ private ExecutionContext executionContext = new ExecutionContext("user1", "note1", "test");
+
@Test
public void testCorrectConf() throws InterpreterException {
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java
index 76188b6..87d65cd 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java
@@ -29,32 +29,32 @@ public class InterpreterFactoryTest extends AbstractInterpreterTest {
@Test
public void testGetFactory() throws InterpreterException {
- assertTrue(interpreterFactory.getInterpreter("", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext()) instanceof RemoteInterpreter);
- RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ assertTrue(interpreterFactory.getInterpreter("", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
+ RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("", new ExecutionContext("user1", "note1", "test"));
// EchoInterpreter is the default interpreter because test is the default interpreter group
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
- assertTrue(interpreterFactory.getInterpreter("double_echo", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext()) instanceof RemoteInterpreter);
- remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("double_echo", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ assertTrue(interpreterFactory.getInterpreter("double_echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
+ remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("double_echo", new ExecutionContext("user1", "note1", "test"));
assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName());
- assertTrue(interpreterFactory.getInterpreter("test", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext()) instanceof RemoteInterpreter);
- remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ assertTrue(interpreterFactory.getInterpreter("test", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
+ remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test", new ExecutionContext("user1", "note1", "test"));
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
- assertTrue(interpreterFactory.getInterpreter("test2", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext()) instanceof RemoteInterpreter);
- remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ assertTrue(interpreterFactory.getInterpreter("test2", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
+ remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2", new ExecutionContext("user1", "note1", "test"));
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
- assertTrue(interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext()) instanceof RemoteInterpreter);
- remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ assertTrue(interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
+ remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContext("user1", "note1", "test"));
assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName());
}
@Test
public void testUnknownRepl1() {
try {
- interpreterFactory.getInterpreter("test.unknown_repl", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ interpreterFactory.getInterpreter("test.unknown_repl", new ExecutionContext("user1", "note1", "test"));
fail("should fail due to no such interpreter");
} catch (InterpreterNotFoundException e) {
assertEquals("No such interpreter: test.unknown_repl", e.getMessage());
@@ -64,7 +64,7 @@ public class InterpreterFactoryTest extends AbstractInterpreterTest {
@Test
public void testUnknownRepl2() {
try {
- interpreterFactory.getInterpreter("unknown_repl", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ interpreterFactory.getInterpreter("unknown_repl", new ExecutionContext("user1", "note1", "test"));
fail("should fail due to no such interpreter");
} catch (InterpreterNotFoundException e) {
assertEquals("No such interpreter: unknown_repl", e.getMessage());
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java
index af90220..fd92c30 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java
@@ -23,6 +23,9 @@ import org.apache.zeppelin.dep.Dependency;
import org.apache.zeppelin.display.AngularObjectRegistryListener;
import org.apache.zeppelin.helium.ApplicationEventListener;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
+import org.junit.Before;
import org.junit.Test;
import org.eclipse.aether.RepositoryException;
import org.eclipse.aether.repository.RemoteRepository;
@@ -38,10 +41,23 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class InterpreterSettingManagerTest extends AbstractInterpreterTest {
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Note note1 = new Note(new NoteInfo("note1", "/note_1"));
+ Note note2 = new Note(new NoteInfo("note2", "/note_2"));
+ Note note3 = new Note(new NoteInfo("note3", "/note_3"));
+ when(mockNotebook.getNote("note1")).thenReturn(note1);
+ when(mockNotebook.getNote("note2")).thenReturn(note2);
+ when(mockNotebook.getNote("note3")).thenReturn(note3);
+ }
+
@Test
public void testInitInterpreterSettingManager() throws IOException, RepositoryException {
assertEquals(6, interpreterSettingManager.get().size());
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java
index de01959..73b1886 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java
@@ -17,8 +17,13 @@
package org.apache.zeppelin.interpreter;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
+import org.apache.zeppelin.notebook.Notebook;
+import org.junit.Before;
import org.junit.Test;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -28,9 +33,29 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class InterpreterSettingTest {
+ private InterpreterSettingManager interpreterSettingManager;
+ private Notebook notebook;
+ private Note note1;
+ private Note note2;
+
+
+ @Before
+ public void setUp() throws IOException {
+ interpreterSettingManager = mock(InterpreterSettingManager.class);
+ notebook = mock(Notebook.class);
+ when(interpreterSettingManager.getNotebook()).thenReturn(notebook);
+
+ note1 = new Note(new NoteInfo("note1", "/note_1"));
+ note2 = new Note(new NoteInfo("note2", "/note_2"));
+ when(notebook.getNote("note1")).thenReturn(note1);
+ when(notebook.getNote("note2")).thenReturn(note2);
+ }
+
@Test
public void testCreateInterpreters() {
InterpreterOption interpreterOption = new InterpreterOption();
@@ -43,12 +68,14 @@ public class InterpreterSettingTest {
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
+
InterpreterSetting interpreterSetting = new InterpreterSetting.Builder()
.setId("id")
.setName("test")
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create default interpreter for user1 and note1
@@ -82,6 +109,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create default interpreter for user1 and note1
@@ -100,7 +128,7 @@ public class InterpreterSettingTest {
// only 1 session is created, this session is shared across users and notes
assertEquals(1, interpreterSetting.getAllInterpreterGroups().get(0).getSessionNum());
- interpreterSetting.closeInterpreters("note1", "user1");
+ interpreterSetting.closeInterpreters("user1", "note1");
assertEquals(0, interpreterSetting.getAllInterpreterGroups().size());
}
@@ -121,6 +149,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create interpreter for user1 and note1
@@ -160,6 +189,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create interpreter for user1 and note1
@@ -199,6 +229,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create interpreter for user1 and note1
@@ -239,6 +270,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create interpreter for user1 and note1
@@ -280,6 +312,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create interpreter for user1 and note1
@@ -335,6 +368,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create interpreter for user1 and note1
@@ -396,6 +430,7 @@ public class InterpreterSettingTest {
.setGroup("test")
.setInterpreterInfos(interpreterInfos)
.setOption(interpreterOption)
+ .setIntepreterSettingManager(interpreterSettingManager)
.create();
// create interpreter for user1 and note1
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java
index 8aa8232..e31a6f6 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java
@@ -19,7 +19,7 @@ package org.apache.zeppelin.interpreter.lifecycle;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.interpreter.AbstractInterpreterTest;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
+import org.apache.zeppelin.interpreter.ExecutionContext;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterSetting;
@@ -57,8 +57,8 @@ public class TimeoutLifecycleManagerTest extends AbstractInterpreterTest {
@Test
public void testTimeout_1() throws InterpreterException, InterruptedException, IOException {
- assertTrue(interpreterFactory.getInterpreter("test.echo", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext()) instanceof RemoteInterpreter);
- RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test.echo", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ assertTrue(interpreterFactory.getInterpreter("test.echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
+ RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test.echo", new ExecutionContext("user1", "note1", "test"));
assertFalse(remoteInterpreter.isOpened());
InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test");
assertEquals(1, interpreterSetting.getAllInterpreterGroups().size());
@@ -80,8 +80,8 @@ public class TimeoutLifecycleManagerTest extends AbstractInterpreterTest {
@Test
public void testTimeout_2() throws InterpreterException, InterruptedException, IOException {
- assertTrue(interpreterFactory.getInterpreter("test.sleep", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext()) instanceof RemoteInterpreter);
- final RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test.sleep", new ExecutionContextBuilder().setUser("user1").setNoteId("note1").setDefaultInterpreterGroup("test").createExecutionContext());
+ assertTrue(interpreterFactory.getInterpreter("test.sleep", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
+ final RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test.sleep", new ExecutionContext("user1", "note1", "test"));
// simulate how zeppelin submit paragraph
remoteInterpreter.getScheduler().submit(new Job<Object>("test-job", null) {
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java
index 924b182..f2753dd 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java
@@ -28,6 +28,8 @@ import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterOption;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -36,6 +38,7 @@ import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
public class FileSystemRecoveryStorageTest extends AbstractInterpreterTest {
@@ -48,6 +51,11 @@ public class FileSystemRecoveryStorageTest extends AbstractInterpreterTest {
recoveryDir = Files.createTempDir();
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_RECOVERY_DIR.getVarName(), recoveryDir.getAbsolutePath());
super.setUp();
+
+ Note note1 = new Note(new NoteInfo("note1", "/note_1"));
+ Note note2 = new Note(new NoteInfo("note2", "/note_2"));
+ when(mockNotebook.getNote("note1")).thenReturn(note1);
+ when(mockNotebook.getNote("note2")).thenReturn(note2);
}
@After
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/LocalRecoveryStorageTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/LocalRecoveryStorageTest.java
index a6d6e2e..a59cca9 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/LocalRecoveryStorageTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/LocalRecoveryStorageTest.java
@@ -28,6 +28,8 @@ import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterOption;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -36,6 +38,7 @@ import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
public class LocalRecoveryStorageTest extends AbstractInterpreterTest {
private File recoveryDir = null;
@@ -47,6 +50,11 @@ public class LocalRecoveryStorageTest extends AbstractInterpreterTest {
recoveryDir = Files.createTempDir();
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_RECOVERY_DIR.getVarName(), recoveryDir.getAbsolutePath());
super.setUp();
+
+ Note note1 = new Note(new NoteInfo("note1", "/note_1"));
+ Note note2 = new Note(new NoteInfo("note2", "/note_2"));
+ when(mockNotebook.getNote("note1")).thenReturn(note1);
+ when(mockNotebook.getNote("note2")).thenReturn(note2);
}
@After
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java
index 6febe66..907b8e4 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java
@@ -25,6 +25,8 @@ import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterSetting;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
import org.apache.zeppelin.resource.LocalResourcePool;
import org.junit.Before;
import org.junit.Test;
@@ -32,6 +34,7 @@ import org.junit.Test;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
public class RemoteAngularObjectTest extends AbstractInterpreterTest
implements AngularObjectRegistryListener {
@@ -48,6 +51,8 @@ public class RemoteAngularObjectTest extends AbstractInterpreterTest
@Before
public void setUp() throws Exception {
super.setUp();
+ Note note1 = new Note(new NoteInfo("note1", "/note_1"));
+ when(mockNotebook.getNote("note1")).thenReturn(note1);
onAdd = new AtomicInteger(0);
onUpdate = new AtomicInteger(0);
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
index 1759595..6d1004f 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java
@@ -32,6 +32,8 @@ import org.apache.zeppelin.interpreter.InterpreterOption;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.InterpreterSetting;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
import org.junit.Before;
import org.junit.Test;
@@ -49,6 +51,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
public class RemoteInterpreterTest extends AbstractInterpreterTest {
@@ -59,6 +62,8 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest {
public void setUp() throws Exception {
super.setUp();
interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test");
+ Note note1 = new Note(new NoteInfo("note1", "/note_1"));
+ when(mockNotebook.getNote("note1")).thenReturn(note1);
}
@Override
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
index cc775dd..c0980b4 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
@@ -22,7 +22,7 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.display.AngularObjectRegistry;
import org.apache.zeppelin.interpreter.AbstractInterpreterTest;
-import org.apache.zeppelin.interpreter.ExecutionContextBuilder;
+import org.apache.zeppelin.interpreter.ExecutionContext;
import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterGroup;
import org.apache.zeppelin.interpreter.InterpreterNotFoundException;
@@ -728,10 +728,10 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
note.setConfig(config);
schedulerService.refreshCron(note.getId());
+ ExecutionContext executionContext = new ExecutionContext(anonymous.getUser(), note.getId(), "test");
+ RemoteInterpreter mock1 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock1", executionContext);
- RemoteInterpreter mock1 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock1", new ExecutionContextBuilder().setUser(anonymous.getUser()).setNoteId(note.getId()).setDefaultInterpreterGroup("test").createExecutionContext());
-
- RemoteInterpreter mock2 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock2", new ExecutionContextBuilder().setUser(anonymous.getUser()).setNoteId(note.getId()).setDefaultInterpreterGroup("test").createExecutionContext());
+ RemoteInterpreter mock2 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock2", executionContext);
// wait until interpreters are started
while (!mock1.isOpened() || !mock2.isOpened()) {
@@ -764,8 +764,9 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
config.put("cronExecutingUser", anonymous.getUser());
config.put("releaseresource", true);
cronNote.setConfig(config);
+
RemoteInterpreter cronNoteInterpreter =
- (RemoteInterpreter) interpreterFactory.getInterpreter("mock1", new ExecutionContextBuilder().setUser(anonymous.getUser()).setNoteId(cronNote.getId()).setDefaultInterpreterGroup("test").createExecutionContext());
+ (RemoteInterpreter) interpreterFactory.getInterpreter("mock1", new ExecutionContext(anonymous.getUser(), cronNote.getId(), "test"));
// create a paragraph of the cron scheduled note.
Paragraph cronNoteParagraph = cronNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -778,7 +779,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
Note anotherNote = notebook.createNote("note1", anonymous);
RemoteInterpreter anotherNoteInterpreter =
- (RemoteInterpreter) interpreterFactory.getInterpreter("mock2", new ExecutionContextBuilder().setUser(anonymous.getUser()).setNoteId(anotherNote.getId()).setDefaultInterpreterGroup("test").createExecutionContext());
+ (RemoteInterpreter) interpreterFactory.getInterpreter("mock2", new ExecutionContext(anonymous.getUser(), anotherNote.getId(), "test"));
// create a paragraph of another note
Paragraph anotherNoteParagraph = anotherNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -942,7 +943,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
// create a note and a paragraph
Note note = notebook.createNote("note1", anonymous);
- AngularObjectRegistry registry = note.getBindedInterpreterSettings(new ArrayList<>()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ AngularObjectRegistry registry = note.getBindedInterpreterSettings(new ArrayList<>()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), note.getId())
.getAngularObjectRegistry();
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -973,7 +974,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
// create a note and a paragraph
Note note = notebook.createNote("note1", anonymous);
- AngularObjectRegistry registry = note.getBindedInterpreterSettings(new ArrayList<>()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ AngularObjectRegistry registry = note.getBindedInterpreterSettings(new ArrayList<>()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), note.getId())
.getAngularObjectRegistry();
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -1005,7 +1006,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
// create a note and a paragraph
Note note = notebook.createNote("note1", anonymous);
- AngularObjectRegistry registry = note.getBindedInterpreterSettings(new ArrayList<>()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ AngularObjectRegistry registry = note.getBindedInterpreterSettings(new ArrayList<>()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), note.getId())
.getAngularObjectRegistry();
// add local scope object
@@ -1016,7 +1017,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
// restart interpreter
interpreterSettingManager.restart(note.getBindedInterpreterSettings(new ArrayList<>()).get(0).getId());
registry = note.getBindedInterpreterSettings(new ArrayList<>()).get(0)
- .getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ .getOrCreateInterpreterGroup(anonymous.getUser(), note.getId())
.getAngularObjectRegistry();
// New InterpreterGroup will be created and its AngularObjectRegistry will be created
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java
index 8c07c2e..a390b5b 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java
@@ -23,6 +23,8 @@ import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -30,6 +32,7 @@ import org.junit.Test;
import static org.apache.zeppelin.interpreter.InterpreterOption.ISOLATED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
/**
* Unittest for DistributedResourcePool
@@ -45,6 +48,11 @@ public class DistributedResourcePoolTest extends AbstractInterpreterTest {
@Before
public void setUp() throws Exception {
super.setUp();
+ Note note1 = new Note(new NoteInfo("note1", "/note_1"));
+ Note note2 = new Note(new NoteInfo("note2", "/note_2"));
+ when(mockNotebook.getNote("note1")).thenReturn(note1);
+ when(mockNotebook.getNote("note2")).thenReturn(note2);
+
InterpreterSetting interpreterSetting = interpreterSettingManager.getByName("mock_resource_pool");
interpreterSetting.getOption().setPerNote(ISOLATED);
intp1 = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_resource_pool");
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java
index 1a7baf7..74b047e 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java
@@ -25,6 +25,8 @@ import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
import org.apache.zeppelin.interpreter.thrift.ParagraphInfo;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
import org.apache.zeppelin.resource.LocalResourcePool;
import org.apache.zeppelin.scheduler.Job.Status;
import org.junit.After;
@@ -39,6 +41,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
public class RemoteSchedulerTest extends AbstractInterpreterTest
implements RemoteInterpreterProcessListener {
@@ -52,6 +55,9 @@ public class RemoteSchedulerTest extends AbstractInterpreterTest
@Before
public void setUp() throws Exception {
super.setUp();
+ Note note1 = new Note(new NoteInfo("note1", "/note_1"));
+ when(mockNotebook.getNote("note1")).thenReturn(note1);
+
schedulerSvc = SchedulerFactory.singleton();
interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test");
}