diff --git a/bin/interpreter.sh b/bin/interpreter.sh index a81c8f21067..2caf4b6db9f 100755 --- a/bin/interpreter.sh +++ b/bin/interpreter.sh @@ -23,7 +23,7 @@ function usage() { echo "usage) $0 -p -d -l " } -while getopts "hp:d:l:v" o; do +while getopts "hp:d:l:v:u:" o; do case ${o} in h) usage @@ -42,6 +42,9 @@ while getopts "hp:d:l:v" o; do . "${bin}/common.sh" getZeppelinVersion ;; + u) + ZEPPELIN_SSH_COMMAND="ssh ${OPTARG}@localhost " + ;; esac done @@ -155,10 +158,11 @@ addJarInDirForIntp "${LOCAL_INTERPRETER_REPO}" CLASSPATH+=":${ZEPPELIN_INTP_CLASSPATH}" + if [[ -n "${SPARK_SUBMIT}" ]]; then - ${SPARK_SUBMIT} --class ${ZEPPELIN_SERVER} --driver-class-path "${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH}" --driver-java-options "${JAVA_INTP_OPTS}" ${SPARK_SUBMIT_OPTIONS} ${SPARK_APP_JAR} ${PORT} & + ${ZEPPELIN_SSH_COMMAND} `${SPARK_SUBMIT} --class ${ZEPPELIN_SERVER} --driver-class-path "${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH}" --driver-java-options "${JAVA_INTP_OPTS}" ${SPARK_SUBMIT_OPTIONS} ${SPARK_APP_JAR} ${PORT} &` else - ${ZEPPELIN_RUNNER} ${JAVA_INTP_OPTS} ${ZEPPELIN_INTP_MEM} -cp ${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH} ${ZEPPELIN_SERVER} ${PORT} & + ${ZEPPELIN_SSH_COMMAND} ${ZEPPELIN_RUNNER} ${JAVA_INTP_OPTS} ${ZEPPELIN_INTP_MEM} -cp ${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH} ${ZEPPELIN_SERVER} ${PORT} & fi pid=$! diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java index db740f4873a..eacbf200b06 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java @@ -17,14 +17,14 @@ package org.apache.zeppelin.interpreter.remote; -import java.util.*; - +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.thrift.TException; import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.GUI; -import org.apache.zeppelin.helium.ApplicationEventListener; import org.apache.zeppelin.display.Input; +import org.apache.zeppelin.helium.ApplicationEventListener; import org.apache.zeppelin.interpreter.*; import org.apache.zeppelin.interpreter.InterpreterResult.Type; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; @@ -36,8 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; +import java.util.*; /** * Proxy for Interpreter instance that runs on separate process @@ -59,20 +58,24 @@ public class RemoteInterpreter extends Interpreter { private int maxPoolSize; private String host; private int port; + private String userName; + private Boolean isUserImpersonate; /** * Remote interpreter and manage interpreter process */ public RemoteInterpreter(Properties property, - String noteId, - String className, - String interpreterRunner, - String interpreterPath, - String localRepoPath, - int connectTimeout, - int maxPoolSize, - RemoteInterpreterProcessListener remoteInterpreterProcessListener, - ApplicationEventListener appListener) { + String noteId, + String className, + String interpreterRunner, + String interpreterPath, + String localRepoPath, + int connectTimeout, + int maxPoolSize, + RemoteInterpreterProcessListener remoteInterpreterProcessListener, + ApplicationEventListener appListener, + String userName, + Boolean isUserImpersonate) { super(property); this.noteId = noteId; this.className = className; @@ -85,6 +88,8 @@ public RemoteInterpreter(Properties property, this.maxPoolSize = maxPoolSize; this.remoteInterpreterProcessListener = remoteInterpreterProcessListener; this.applicationEventListener = appListener; + this.userName = userName; + this.isUserImpersonate = isUserImpersonate; } @@ -100,7 +105,9 @@ public RemoteInterpreter( int connectTimeout, int maxPoolSize, RemoteInterpreterProcessListener remoteInterpreterProcessListener, - ApplicationEventListener appListener) { + ApplicationEventListener appListener, + String userName, + Boolean isUserImpersonate) { super(property); this.noteId = noteId; this.className = className; @@ -111,6 +118,8 @@ public RemoteInterpreter( this.maxPoolSize = maxPoolSize; this.remoteInterpreterProcessListener = remoteInterpreterProcessListener; this.applicationEventListener = appListener; + this.userName = userName; + this.isUserImpersonate = isUserImpersonate; } @@ -125,7 +134,9 @@ public RemoteInterpreter( Map env, int connectTimeout, RemoteInterpreterProcessListener remoteInterpreterProcessListener, - ApplicationEventListener appListener) { + ApplicationEventListener appListener, + String userName, + Boolean isUserImpersonate) { super(property); this.className = className; this.noteId = noteId; @@ -138,6 +149,8 @@ public RemoteInterpreter( this.maxPoolSize = 10; this.remoteInterpreterProcessListener = remoteInterpreterProcessListener; this.applicationEventListener = appListener; + this.userName = userName; + this.isUserImpersonate = isUserImpersonate; } private Map getEnvFromInterpreterProperty(Properties property) { @@ -205,7 +218,7 @@ public synchronized void init() { RemoteInterpreterProcess interpreterProcess = getInterpreterProcess(); final InterpreterGroup interpreterGroup = getInterpreterGroup(); - interpreterProcess.reference(interpreterGroup); + interpreterProcess.reference(interpreterGroup, userName, isUserImpersonate); interpreterProcess.setMaxPoolSize( Math.max(this.maxPoolSize, interpreterProcess.getMaxPoolSize())); String groupId = interpreterGroup.getId(); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterManagedProcess.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterManagedProcess.java index eb345338569..e843e73f116 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterManagedProcess.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterManagedProcess.java @@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.io.OutputStream; import java.util.Map; /** @@ -88,7 +87,7 @@ public int getPort() { } @Override - public void start() { + public void start(String userName, Boolean isUserImpersonate) { // start server process try { port = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(); @@ -101,6 +100,10 @@ public void start() { cmdLine.addArgument(interpreterDir, false); cmdLine.addArgument("-p", false); cmdLine.addArgument(Integer.toString(port), false); + if (isUserImpersonate && !userName.equals("anonymous") ) { + cmdLine.addArgument("-u", false); + cmdLine.addArgument(userName, false); + } cmdLine.addArgument("-l", false); cmdLine.addArgument(localRepoDir, false); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java index aef6c2bd809..be1dc3f9006 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java @@ -17,18 +17,16 @@ package org.apache.zeppelin.interpreter.remote; import com.google.gson.Gson; -import org.apache.commons.exec.*; +import org.apache.commons.exec.ExecuteWatchdog; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.thrift.TException; import org.apache.zeppelin.helium.ApplicationEventListener; -import org.apache.zeppelin.interpreter.Constants; -import org.apache.zeppelin.interpreter.InterpreterException; import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import java.util.concurrent.atomic.AtomicInteger; -import java.util.Properties; /** * Abstract class for interpreter process @@ -63,7 +61,8 @@ public RemoteInterpreterProcess( public abstract String getHost(); public abstract int getPort(); - public abstract void start(); + + public abstract void start(String userName, Boolean isUserImpersonate); public abstract void stop(); public abstract boolean isRunning(); @@ -71,10 +70,11 @@ public int getConnectTimeout() { return connectTimeout; } - public int reference(InterpreterGroup interpreterGroup) { + public int reference(InterpreterGroup interpreterGroup, String userName, + Boolean isUserImpersonate) { synchronized (referenceCount) { if (!isRunning()) { - start(); + start(userName, isUserImpersonate); } if (clientPool == null) { diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java index 42e6250e3ca..bb176bea590 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java @@ -51,7 +51,7 @@ public int getPort() { } @Override - public void start() { + public void start(String userName, Boolean isUserImpersonate) { // assume process is externally managed. nothing to do } diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java index 5def888b637..bbd5546b41f 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java @@ -74,8 +74,9 @@ public void setUp() throws Exception { env, 10 * 1000, null, - null - ); + null, + "anonymous", + false); intpGroup.put("note", new LinkedList()); intpGroup.get("note").add(intp); diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java index 74649b1e750..d2e77cc013a 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java @@ -71,7 +71,9 @@ private RemoteInterpreter createMockInterpreter() { env, 10 * 1000, this, - null); + null, + "anonymous", + false); intpGroup.get("note").add(intp); intp.setInterpreterGroup(intpGroup); diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessTest.java index 01582821308..173a6cee4aa 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessTest.java @@ -25,7 +25,6 @@ import java.util.Properties; import org.apache.thrift.TException; -import org.apache.thrift.transport.TTransportException; import org.apache.zeppelin.interpreter.Constants; import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client; @@ -46,8 +45,8 @@ public void testStartStop() { 10 * 1000, null, null); assertFalse(rip.isRunning()); assertEquals(0, rip.referenceCount()); - assertEquals(1, rip.reference(intpGroup)); - assertEquals(2, rip.reference(intpGroup)); + assertEquals(1, rip.reference(intpGroup, "anonymous", false)); + assertEquals(2, rip.reference(intpGroup, "anonymous", false)); assertEquals(true, rip.isRunning()); assertEquals(1, rip.dereference()); assertEquals(true, rip.isRunning()); @@ -61,7 +60,7 @@ public void testClientFactory() throws Exception { RemoteInterpreterManagedProcess rip = new RemoteInterpreterManagedProcess( INTERPRETER_SCRIPT, "nonexists", "fakeRepo", new HashMap(), mock(RemoteInterpreterEventPoller.class), 10 * 1000); - rip.reference(intpGroup); + rip.reference(intpGroup, "anonymous", false); assertEquals(0, rip.getNumActiveClient()); assertEquals(0, rip.getNumIdleClient()); @@ -106,7 +105,7 @@ public void testStartStopRemoteInterpreter() throws TException, InterruptedExcep , 10 * 1000); assertFalse(rip.isRunning()); assertEquals(0, rip.referenceCount()); - assertEquals(1, rip.reference(intpGroup)); + assertEquals(1, rip.reference(intpGroup, "anonymous", false)); assertEquals(true, rip.isRunning()); } } diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java index af1c4471a05..cedbf73d3c5 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java @@ -17,39 +17,33 @@ package org.apache.zeppelin.interpreter.remote; -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.thrift.transport.TTransportException; import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectRegistry; -import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterEnv; -import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService; -import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client; -import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.display.GUI; import org.apache.zeppelin.interpreter.*; import org.apache.zeppelin.interpreter.InterpreterResult.Code; import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA; import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterB; +import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterEnv; +import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client; import org.apache.zeppelin.resource.LocalResourcePool; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.scheduler.Scheduler; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.junit.Assert.*; public class RemoteInterpreterTest { @@ -90,7 +84,9 @@ private RemoteInterpreter createMockInterpreterA(Properties p, String noteId) { env, 10 * 1000, null, - null); + null, + "anonymous", + false); } private RemoteInterpreter createMockInterpreterB(Properties p) { @@ -108,7 +104,9 @@ private RemoteInterpreter createMockInterpreterB(Properties p, String noteId) { env, 10 * 1000, null, - null); + null, + "anonymous", + false); } @Test @@ -207,7 +205,9 @@ public void testRemoteSchedulerSharing() throws TTransportException, IOException env, 10 * 1000, null, - null); + null, + "anonymous", + false); intpGroup.get("note").add(intpA); @@ -223,7 +223,9 @@ public void testRemoteSchedulerSharing() throws TTransportException, IOException env, 10 * 1000, null, - null); + null, + "anonymous", + false); intpGroup.get("note").add(intpB); intpB.setInterpreterGroup(intpGroup); @@ -687,7 +689,8 @@ public void should_push_local_angular_repo_to_remote() throws Exception { //Given final Client client = Mockito.mock(Client.class); final RemoteInterpreter intr = new RemoteInterpreter(new Properties(), "noteId", - MockInterpreterA.class.getName(), "runner", "path","localRepo", env, 10 * 1000, null, null); + MockInterpreterA.class.getName(), "runner", "path", "localRepo", env, 10 * 1000, null, null, + "anonymous", false); final AngularObjectRegistry registry = new AngularObjectRegistry("spark", null); registry.add("name", "DuyHai DOAN", "nodeId", "paragraphId"); final InterpreterGroup interpreterGroup = new InterpreterGroup("groupId"); @@ -733,7 +736,9 @@ public void testEnvronmentAndPropertySet() { env, 10 * 1000, null, - null); + null, + "anonymous", + false); intpGroup.put("note", new LinkedList()); intpGroup.get("note").add(intp); diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java index 02dba20c05d..dc435f0c381 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java @@ -70,8 +70,9 @@ public void setUp() throws Exception { env, 10 * 1000, null, - null - ); + null, + "anonymous", + false); intpGroup1 = new InterpreterGroup("intpGroup1"); intpGroup1.put("note", new LinkedList()); @@ -88,8 +89,9 @@ public void setUp() throws Exception { env, 10 * 1000, null, - null - ); + null, + "anonymous", + false); intpGroup2 = new InterpreterGroup("intpGroup2"); intpGroup2.put("note", new LinkedList()); diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java index f17d88d50af..fcccfbba36d 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java @@ -81,7 +81,9 @@ public void test() throws Exception { env, 10 * 1000, this, - null); + null, + "anonymous", + false); intpGroup.put("note", new LinkedList()); intpGroup.get("note").add(intpA); @@ -170,7 +172,9 @@ public void testAbortOnPending() throws Exception { env, 10 * 1000, this, - null); + null, + "anonymous", + false); intpGroup.put("note", new LinkedList()); intpGroup.get("note").add(intpA); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index 694f08109e3..9d57e038dd7 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -20,7 +20,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; - import org.apache.commons.lang.StringUtils; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; @@ -546,7 +545,7 @@ private void sendNote(NotebookSocket conn, HashSet userAndRoles, Noteboo } addConnectionToNote(note.id(), conn); conn.send(serializeMessage(new Message(OP.NOTE).put("note", note))); - sendAllAngularObjects(note, conn); + sendAllAngularObjects(note, conn, fromMessage.principal); } else { conn.send(serializeMessage(new Message(OP.NOTE).put("note", null))); } @@ -570,7 +569,7 @@ private void sendHomeNote(NotebookSocket conn, HashSet userAndRoles, } addConnectionToNote(note.id(), conn); conn.send(serializeMessage(new Message(OP.NOTE).put("note", note))); - sendAllAngularObjects(note, conn); + sendAllAngularObjects(note, conn, fromMessage.principal); } else { removeConnectionFromAllNote(conn); conn.send(serializeMessage(new Message(OP.NOTE).put("note", null))); @@ -801,6 +800,7 @@ private void angularObjectUpdated(NotebookSocket conn, HashSet userAndRo String paragraphId = (String) fromMessage.get("paragraphId"); String interpreterGroupId = (String) fromMessage.get("interpreterGroupId"); String varName = (String) fromMessage.get("name"); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); Object varValue = fromMessage.get("value"); AngularObject ao = null; boolean global = false; @@ -810,12 +810,13 @@ private void angularObjectUpdated(NotebookSocket conn, HashSet userAndRo List settings = notebook.getInterpreterFactory() .getInterpreterSettings(note.getId()); for (InterpreterSetting setting : settings) { - if (setting.getInterpreterGroup(note.id()) == null) { + if (setting.getInterpreterGroup(note.id(), subject.getUser()) == null) { continue; } - if (interpreterGroupId.equals(setting.getInterpreterGroup(note.id()).getId())) { + if (interpreterGroupId.equals(setting.getInterpreterGroup(note.id(), + subject.getUser()).getId())) { AngularObjectRegistry angularObjectRegistry = setting - .getInterpreterGroup(note.id()).getAngularObjectRegistry(); + .getInterpreterGroup(note.id(), subject.getUser()).getAngularObjectRegistry(); // first trying to get local registry ao = angularObjectRegistry.get(varName, noteId, paragraphId); @@ -852,12 +853,13 @@ private void angularObjectUpdated(NotebookSocket conn, HashSet userAndRo List settings = notebook.getInterpreterFactory() .getInterpreterSettings(note.getId()); for (InterpreterSetting setting : settings) { - if (setting.getInterpreterGroup(n.id()) == null) { + if (setting.getInterpreterGroup(n.id(), subject.getUser()) == null) { continue; } - if (interpreterGroupId.equals(setting.getInterpreterGroup(n.id()).getId())) { + if (interpreterGroupId.equals(setting.getInterpreterGroup(n.id(), subject.getUser()) + .getId())) { AngularObjectRegistry angularObjectRegistry = setting - .getInterpreterGroup(n.id()).getAngularObjectRegistry(); + .getInterpreterGroup(n.id(), subject.getUser()).getAngularObjectRegistry(); this.broadcastExcept( n.id(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao) @@ -1376,7 +1378,7 @@ public ParagraphJobListener getParagraphJobListener(Note note) { return new ParagraphListenerImpl(this, note); } - private void sendAllAngularObjects(Note note, NotebookSocket conn) throws IOException { + private void sendAllAngularObjects(Note note, NotebookSocket conn, String user) throws IOException { List settings = notebook().getInterpreterFactory().getInterpreterSettings(note.getId()); if (settings == null || settings.size() == 0) { @@ -1384,14 +1386,14 @@ private void sendAllAngularObjects(Note note, NotebookSocket conn) throws IOExce } for (InterpreterSetting intpSetting : settings) { - AngularObjectRegistry registry = intpSetting.getInterpreterGroup(note.id()) + AngularObjectRegistry registry = intpSetting.getInterpreterGroup(note.id(), user) .getAngularObjectRegistry(); List objects = registry.getAllWithGlobal(note.id()); for (AngularObject object : objects) { conn.send(serializeMessage(new Message(OP.ANGULAR_OBJECT_UPDATE) .put("angularObject", object) .put("interpreterGroupId", - intpSetting.getInterpreterGroup(note.id()).getId()) + intpSetting.getInterpreterGroup(note.id(), "anonymous").getId()) .put("noteId", note.id()) .put("paragraphId", object.getParagraphId()) )); diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java index e92432fefaa..fe9a85508ad 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java @@ -17,10 +17,8 @@ package org.apache.zeppelin.rest; -import java.io.IOException; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; @@ -30,14 +28,16 @@ import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.server.ZeppelinServer; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; +import java.io.IOException; +import java.util.List; +import java.util.Map; import static org.junit.Assert.*; @@ -47,10 +47,13 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class InterpreterRestApiTest extends AbstractTestRestApi { Gson gson = new Gson(); + static AuthenticationInfo subject; @BeforeClass public static void init() throws Exception { AbstractTestRestApi.startUp(); + subject = new AuthenticationInfo(); + subject.setUser("anonymous"); } @AfterClass @@ -122,7 +125,7 @@ public void testSettingsCRUD() throws IOException { @Test public void testInterpreterAutoBinding() throws IOException { // create note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); // check interpreter is binded GetMethod get = httpGet("/notebook/interpreter/bind/" + note.id()); @@ -135,15 +138,16 @@ public void testInterpreterAutoBinding() throws IOException { get.releaseConnection(); //cleanup - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testInterpreterRestart() throws IOException, InterruptedException { // create new note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); note.addParagraph(); Paragraph p = note.getLastParagraph(); + p.setAuthenticationInfo(subject); Map config = p.getConfig(); config.put("enabled", true); @@ -172,13 +176,14 @@ public void testInterpreterRestart() throws IOException, InterruptedException { p = note.addParagraph(); p.setConfig(config); p.setText("%md markdown restarted"); + p.setAuthenticationInfo(subject); note.run(p.getId()); while (p.getStatus() != Status.FINISHED) { Thread.sleep(100); } assertEquals("

markdown restarted

\n", p.getResult().message()); //cleanup - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java index b06c7ca877d..5bc7a0186ab 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java @@ -27,6 +27,7 @@ import org.apache.zeppelin.notebook.NotebookAuthorization; import org.apache.zeppelin.notebook.NotebookAuthorizationInfoSaving; import org.apache.zeppelin.server.ZeppelinServer; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -48,10 +49,13 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class NotebookRestApiTest extends AbstractTestRestApi { Gson gson = new Gson(); + static AuthenticationInfo subject; @BeforeClass public static void init() throws Exception { AbstractTestRestApi.startUp(); + subject = new AuthenticationInfo(); + subject.setUser("anonymous"); } @AfterClass @@ -61,7 +65,7 @@ public static void destroy() throws Exception { @Test public void testPermissions() throws IOException { - Note note1 = ZeppelinServer.notebook.createNote(null); + Note note1 = ZeppelinServer.notebook.createNote(subject); // Set only readers String jsonRequest = "{\"readers\":[\"admin-team\"],\"owners\":[]," + "\"writers\":[]}"; @@ -84,7 +88,7 @@ public void testPermissions() throws IOException { get.releaseConnection(); - Note note2 = ZeppelinServer.notebook.createNote(null); + Note note2 = ZeppelinServer.notebook.createNote(subject); // Set only writers jsonRequest = "{\"readers\":[],\"owners\":[]," + "\"writers\":[\"admin-team\"]}"; @@ -118,14 +122,14 @@ public void testPermissions() throws IOException { assertEquals(authInfo.get("owners"), Lists.newArrayList()); get.releaseConnection(); //cleanup - ZeppelinServer.notebook.removeNote(note1.getId(), null); - ZeppelinServer.notebook.removeNote(note2.getId(), null); + ZeppelinServer.notebook.removeNote(note1.getId(), subject); + ZeppelinServer.notebook.removeNote(note2.getId(), subject); } @Test public void testGetNoteParagraphJobStatus() throws IOException { - Note note1 = ZeppelinServer.notebook.createNote(null); + Note note1 = ZeppelinServer.notebook.createNote(subject); note1.addParagraph(); String paragraphId = note1.getLastParagraph().getId(); @@ -141,7 +145,7 @@ public void testGetNoteParagraphJobStatus() throws IOException { assertEquals(paragraphStatus.get("status"), "READY"); //cleanup - ZeppelinServer.notebook.removeNote(note1.getId(), null); + ZeppelinServer.notebook.removeNote(note1.getId(), subject); } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java index 00a81066316..c1e68b8cc68 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java @@ -17,29 +17,27 @@ package org.apache.zeppelin.rest; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.lang3.StringUtils; -import org.apache.zeppelin.interpreter.InterpreterSetting; import org.apache.zeppelin.notebook.Note; import org.apache.zeppelin.notebook.Paragraph; -import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.server.ZeppelinServer; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import static org.junit.Assert.*; @@ -50,10 +48,13 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ZeppelinRestApiTest extends AbstractTestRestApi { Gson gson = new Gson(); + static AuthenticationInfo subject; @BeforeClass public static void init() throws Exception { AbstractTestRestApi.startUp(); + subject = new AuthenticationInfo(); + subject.setUser("anonymous"); } @AfterClass @@ -77,7 +78,7 @@ public void getApiRoot() throws IOException { public void testGetNotebookInfo() throws IOException { LOG.info("testGetNotebookInfo"); // Create note to get info - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); assertNotNull("can't create new note", note); note.setName("note"); Paragraph paragraph = note.addParagraph(); @@ -86,7 +87,7 @@ public void testGetNotebookInfo() throws IOException { paragraph.setConfig(config); String paragraphText = "%md This is my new paragraph in my new note"; paragraph.setText(paragraphText); - note.persist(null); + note.persist(subject); String sourceNoteID = note.getId(); GetMethod get = httpGet("/notebook/" + sourceNoteID); @@ -154,7 +155,7 @@ public void testNotebookCreateWithParagraphs() throws IOException { assertTrue("paragraph text check failed", p.getText().startsWith("text")); } // cleanup - ZeppelinServer.notebook.removeNote(newNotebookId, null); + ZeppelinServer.notebook.removeNote(newNotebookId, subject); post.releaseConnection(); } @@ -181,7 +182,7 @@ private void testNotebookCreate(String noteName) throws IOException { } assertEquals("compare note name", expectedNoteName, newNoteName); // cleanup - ZeppelinServer.notebook.removeNote(newNotebookId, null); + ZeppelinServer.notebook.removeNote(newNotebookId, subject); post.releaseConnection(); } @@ -190,7 +191,7 @@ private void testNotebookCreate(String noteName) throws IOException { public void testDeleteNote() throws IOException { LOG.info("testDeleteNote"); //Create note and get ID - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); String noteId = note.getId(); testDeleteNotebook(noteId); } @@ -206,7 +207,7 @@ public void testDeleteNoteBadId() throws IOException { @Test public void testExportNotebook() throws IOException { LOG.info("testExportNotebook"); - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); assertNotNull("can't create new note", note); note.setName("source note for export"); Paragraph paragraph = note.addParagraph(); @@ -214,7 +215,7 @@ public void testExportNotebook() throws IOException { config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - note.persist(null); + note.persist(subject); String sourceNoteID = note.getId(); // Call export Notebook REST API GetMethod get = httpGet("/notebook/export/" + sourceNoteID); @@ -228,7 +229,7 @@ public void testExportNotebook() throws IOException { String exportJSON = (String) resp.get("body"); assertNotNull("Can not find new notejson", exportJSON); LOG.info("export JSON:=" + exportJSON); - ZeppelinServer.notebook.removeNote(sourceNoteID, null); + ZeppelinServer.notebook.removeNote(sourceNoteID, subject); get.releaseConnection(); } @@ -239,7 +240,7 @@ public void testImportNotebook() throws IOException { String noteName = "source note for import"; LOG.info("testImortNotebook"); // create test notebook - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); assertNotNull("can't create new note", note); note.setName(noteName); Paragraph paragraph = note.addParagraph(); @@ -247,7 +248,8 @@ public void testImportNotebook() throws IOException { config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - note.persist(null); + paragraph.setAuthenticationInfo(subject); + note.persist(subject); String sourceNoteID = note.getId(); // get note content as JSON String oldJson = getNoteContent(sourceNoteID); @@ -265,8 +267,8 @@ public void testImportNotebook() throws IOException { assertEquals("Compare paragraphs count", note.getParagraphs().size(), newNote.getParagraphs() .size()); // cleanup - ZeppelinServer.notebook.removeNote(note.getId(), null); - ZeppelinServer.notebook.removeNote(newNote.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); + ZeppelinServer.notebook.removeNote(newNote.getId(), subject); importPost.releaseConnection(); } @@ -301,7 +303,7 @@ private void testDeleteNotebook(String notebookId) throws IOException { public void testCloneNotebook() throws IOException, CloneNotSupportedException, IllegalArgumentException { LOG.info("testCloneNotebook"); // Create note to clone - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); assertNotNull("can't create new note", note); note.setName("source note for clone"); Paragraph paragraph = note.addParagraph(); @@ -309,7 +311,7 @@ public void testCloneNotebook() throws IOException, CloneNotSupportedException, config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - note.persist(null); + note.persist(subject); String sourceNoteID = note.getId(); String noteName = "clone Note Name"; @@ -329,8 +331,8 @@ public void testCloneNotebook() throws IOException, CloneNotSupportedException, assertEquals("Compare note names", noteName, newNote.getName()); assertEquals("Compare paragraphs count", note.getParagraphs().size(), newNote.getParagraphs().size()); //cleanup - ZeppelinServer.notebook.removeNote(note.getId(), null); - ZeppelinServer.notebook.removeNote(newNote.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); + ZeppelinServer.notebook.removeNote(newNote.getId(), subject); post.releaseConnection(); } @@ -350,7 +352,7 @@ public void testListNotebooks() throws IOException { public void testNoteJobs() throws IOException, InterruptedException { LOG.info("testNoteJobs"); // Create note to run test. - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); assertNotNull("can't create new note", note); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); @@ -360,7 +362,7 @@ public void testNoteJobs() throws IOException, InterruptedException { paragraph.setConfig(config); paragraph.setText("%md This is test paragraph."); - note.persist(null); + note.persist(subject); String noteID = note.getId(); note.runAll(); @@ -398,14 +400,14 @@ public void testNoteJobs() throws IOException, InterruptedException { Thread.sleep(1000); //cleanup - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testGetNotebookJob() throws IOException, InterruptedException { LOG.info("testGetNotebookJob"); // Create note to run test. - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); assertNotNull("can't create new note", note); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); @@ -415,7 +417,8 @@ public void testGetNotebookJob() throws IOException, InterruptedException { paragraph.setConfig(config); paragraph.setText("%sh sleep 1"); - note.persist(null); + paragraph.setAuthenticationInfo(subject); + note.persist(subject); String noteID = note.getId(); note.runAll(); @@ -451,14 +454,14 @@ public void testGetNotebookJob() throws IOException, InterruptedException { } } - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testRunParagraphWithParams() throws IOException, InterruptedException { LOG.info("testRunParagraphWithParams"); // Create note to run test. - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); assertNotNull("can't create new note", note); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); @@ -468,7 +471,8 @@ public void testRunParagraphWithParams() throws IOException, InterruptedExceptio paragraph.setConfig(config); paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)"); - note.persist(null); + paragraph.setAuthenticationInfo(subject); + note.persist(subject); String noteID = note.getId(); note.runAll(); @@ -496,17 +500,18 @@ public void testRunParagraphWithParams() throws IOException, InterruptedExceptio assertEquals("world", params.get("param2")); //cleanup - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testCronJobs() throws InterruptedException, IOException{ // create a note and a paragraph - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); paragraph.setText("%md This is test paragraph."); + paragraph.setAuthenticationInfo(subject); Map config = paragraph.getConfig(); config.put("enabled", true); @@ -546,18 +551,19 @@ public void testCronJobs() throws InterruptedException, IOException{ DeleteMethod deleteCron = httpDelete("/notebook/cron/" + note.getId()); assertThat("", deleteCron, isAllowed()); deleteCron.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testRegressionZEPPELIN_527() throws IOException { - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)"); + paragraph.setAuthenticationInfo(subject); - note.persist(null); + note.persist(subject); GetMethod getNoteJobs = httpGet("/notebook/job/" + note.getId()); assertThat("test notebook jobs run:", getNoteJobs, isAllowed()); @@ -568,12 +574,12 @@ public void testRegressionZEPPELIN_527() throws IOException { assertFalse(body.get(0).containsKey("finished")); getNoteJobs.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testInsertParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); String jsonRequest = "{\"title\": \"title1\", \"text\": \"text1\"}"; PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest); @@ -608,17 +614,17 @@ public void testInsertParagraph() throws IOException { assertEquals("title2", paragraphAtIdx0.getTitle()); assertEquals("text2", paragraphAtIdx0.getText()); - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testGetParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); Paragraph p = note.addParagraph(); p.setTitle("hello"); p.setText("world"); - note.persist(null); + note.persist(subject); GetMethod get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p.getId()); LOG.info("testGetParagraph response\n" + get.getResponseBodyAsString()); @@ -637,12 +643,12 @@ public void testGetParagraph() throws IOException { assertEquals("hello", body.get("title")); assertEquals("world", body.get("text")); - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testMoveParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); Paragraph p = note.addParagraph(); p.setTitle("title1"); @@ -652,7 +658,7 @@ public void testMoveParagraph() throws IOException { p2.setTitle("title2"); p2.setText("text2"); - note.persist(null); + note.persist(subject); PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph/" + p2.getId() + "/move/" + 0, ""); assertThat("Test post method: ", post, isAllowed()); @@ -669,18 +675,18 @@ public void testMoveParagraph() throws IOException { assertThat("Test post method: ", post2, isBadRequest()); post.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test public void testDeleteParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); Paragraph p = note.addParagraph(); p.setTitle("title1"); p.setText("text1"); - note.persist(null); + note.persist(subject); DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId()); assertThat("Test delete method: ", delete, isAllowed()); @@ -690,7 +696,7 @@ public void testDeleteParagraph() throws IOException { Paragraph retrParagrah = retrNote.getParagraph(p.getId()); assertNull("paragraph should be deleted", retrParagrah); - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } @Test @@ -706,12 +712,12 @@ public void testSearch() throws IOException { String username = body.get("principal"); getSecurityTicket.releaseConnection(); - Note note1 = ZeppelinServer.notebook.createNote(null); + Note note1 = ZeppelinServer.notebook.createNote(subject); String jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 1\"}"; PostMethod postNotebookText = httpPost("/notebook/" + note1.getId() + "/paragraph", jsonRequest); postNotebookText.releaseConnection(); - Note note2 = ZeppelinServer.notebook.createNote(null); + Note note2 = ZeppelinServer.notebook.createNote(subject); jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 2\"}"; postNotebookText = httpPost("/notebook/" + note2.getId() + "/paragraph", jsonRequest); postNotebookText.releaseConnection(); @@ -753,13 +759,13 @@ public void testSearch() throws IOException { getPermission.releaseConnection(); } searchNotebook.releaseConnection(); - ZeppelinServer.notebook.removeNote(note1.getId(), null); - ZeppelinServer.notebook.removeNote(note2.getId(), null); + ZeppelinServer.notebook.removeNote(note1.getId(), subject); + ZeppelinServer.notebook.removeNote(note2.getId(), subject); } @Test public void testTitleSearch() throws IOException { - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); String jsonRequest = "{\"title\": \"testTitleSearchOfParagraph\", \"text\": \"ThisIsToTestSearchMethodWithTitle \"}"; PostMethod postNotebookText = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest); postNotebookText.releaseConnection(); @@ -780,7 +786,7 @@ public void testTitleSearch() throws IOException { } assertEquals("Paragraph title hits must be at-least one", true, numberOfTitleHits >= 1); searchNotebook.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(note.getId(), subject); } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java index 61dc6d1b928..34e0f62ca69 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java @@ -29,6 +29,7 @@ import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.server.ZeppelinServer; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -41,10 +42,13 @@ */ public class ZeppelinSparkClusterTest extends AbstractTestRestApi { Gson gson = new Gson(); + static AuthenticationInfo subject; @BeforeClass public static void init() throws Exception { AbstractTestRestApi.startUp(); + subject = new AuthenticationInfo(); + subject.setUser("anonymous"); } @AfterClass @@ -67,7 +71,7 @@ private void waitForFinish(Paragraph p) { @Test public void basicRDDTransformationAndActionTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); // run markdown paragraph, again Paragraph p = note.addParagraph(); @@ -75,17 +79,18 @@ public void basicRDDTransformationAndActionTest() throws IOException { config.put("enabled", true); p.setConfig(config); p.setText("%spark print(sc.parallelize(1 to 10).reduce(_ + _))"); + p.setAuthenticationInfo(subject); note.run(p.getId()); waitForFinish(p); assertEquals(Status.FINISHED, p.getStatus()); assertEquals("55", p.getResult().message()); - ZeppelinServer.notebook.removeNote(note.id(), null); + ZeppelinServer.notebook.removeNote(note.id(), subject); } @Test public void sparkRTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); int sparkVersion = getSparkVersionNumber(note); if (isSparkR() && sparkVersion >= 14) { // sparkr supported from 1.4.0 @@ -112,19 +117,20 @@ public void sparkRTest() throws IOException { "df <- createDataFrame(" + sqlContextName + ", localDF)\n" + "count(df)" ); + p.setAuthenticationInfo(subject); note.run(p.getId()); waitForFinish(p); System.err.println("sparkRTest=" + p.getResult().message()); assertEquals(Status.FINISHED, p.getStatus()); assertEquals("[1] 3", p.getResult().message()); } - ZeppelinServer.notebook.removeNote(note.id(), null); + ZeppelinServer.notebook.removeNote(note.id(), subject); } @Test public void pySparkTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); note.setName("note"); int sparkVersion = getSparkVersionNumber(note); @@ -135,19 +141,20 @@ public void pySparkTest() throws IOException { config.put("enabled", true); p.setConfig(config); p.setText("%pyspark print(sc.parallelize(range(1, 11)).reduce(lambda a, b: a + b))"); + p.setAuthenticationInfo(subject); // p.getRepl("org.apache.zeppelin.spark.SparkInterpreter").open(); note.run(p.getId()); waitForFinish(p); assertEquals(Status.FINISHED, p.getStatus()); assertEquals("55\n", p.getResult().message()); } - ZeppelinServer.notebook.removeNote(note.id(), null); + ZeppelinServer.notebook.removeNote(note.id(), subject); } @Test public void pySparkAutoConvertOptionTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); note.setName("note"); int sparkVersionNumber = getSparkVersionNumber(note); @@ -166,34 +173,38 @@ public void pySparkAutoConvertOptionTest() throws IOException { p.setText("%pyspark\nfrom pyspark.sql.functions import *\n" + "print(" + sqlContextName + ".range(0, 10).withColumn('uniform', rand(seed=10) * 3.14).count())"); + p.setAuthenticationInfo(subject); // p.getRepl("org.apache.zeppelin.spark.SparkInterpreter").open(); note.run(p.getId()); waitForFinish(p); assertEquals(Status.FINISHED, p.getStatus()); assertEquals("10\n", p.getResult().message()); } - ZeppelinServer.notebook.removeNote(note.id(), null); + ZeppelinServer.notebook.removeNote(note.id(), subject); } @Test public void zRunTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); Paragraph p0 = note.addParagraph(); Map config0 = p0.getConfig(); config0.put("enabled", true); p0.setConfig(config0); p0.setText("%spark z.run(1)"); + p0.setAuthenticationInfo(subject); Paragraph p1 = note.addParagraph(); Map config1 = p1.getConfig(); config1.put("enabled", true); p1.setConfig(config1); p1.setText("%spark val a=10"); + p1.setAuthenticationInfo(subject); Paragraph p2 = note.addParagraph(); Map config2 = p2.getConfig(); config2.put("enabled", true); p2.setConfig(config2); p2.setText("%spark print(a)"); + p2.setAuthenticationInfo(subject); note.run(p0.getId()); waitForFinish(p0); @@ -204,13 +215,13 @@ public void zRunTest() throws IOException { assertEquals(Status.FINISHED, p2.getStatus()); assertEquals("10", p2.getResult().message()); - ZeppelinServer.notebook.removeNote(note.id(), null); + ZeppelinServer.notebook.removeNote(note.id(), subject); } @Test public void pySparkDepLoaderTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(null); + Note note = ZeppelinServer.notebook.createNote(subject); int sparkVersionNumber = getSparkVersionNumber(note); if (isPyspark() && sparkVersionNumber >= 14) { @@ -231,6 +242,7 @@ public void pySparkDepLoaderTest() throws IOException { config.put("enabled", true); p0.setConfig(config); p0.setText("%dep z.load(\"com.databricks:spark-csv_2.11:1.2.0\")"); + p0.setAuthenticationInfo(subject); note.run(p0.getId()); waitForFinish(p0); assertEquals(Status.FINISHED, p0.getStatus()); @@ -251,6 +263,7 @@ public void pySparkDepLoaderTest() throws IOException { "from pyspark.sql import SQLContext\n" + "print(" + sqlContextName + ".read.format('com.databricks.spark.csv')" + ".load('"+ tmpFile.getAbsolutePath() +"').count())"); + p1.setAuthenticationInfo(subject); note.run(p1.getId()); waitForFinish(p1); @@ -266,6 +279,7 @@ public void pySparkDepLoaderTest() throws IOException { private int getSparkVersionNumber(Note note) { Paragraph p = note.addParagraph(); note.setName("note"); + p.setAuthenticationInfo(subject); Map config = p.getConfig(); config.put("enabled", true); p.setConfig(config); 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 01a24e2e1de..263e28ada11 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 @@ -31,6 +31,7 @@ import org.apache.zeppelin.notebook.socket.Message.OP; import org.apache.zeppelin.rest.AbstractTestRestApi; import org.apache.zeppelin.server.ZeppelinServer; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -57,6 +58,7 @@ public class NotebookServerTest extends AbstractTestRestApi { private static NotebookServer notebookServer; private static Gson gson; private HttpServletRequest mockRequest; + static AuthenticationInfo subject; @BeforeClass public static void init() throws Exception { @@ -64,6 +66,8 @@ public static void init() throws Exception { gson = new Gson(); notebook = ZeppelinServer.notebook; notebookServer = ZeppelinServer.notebookWsServer; + subject = new AuthenticationInfo(); + subject.setUser("anonymous"); } @AfterClass @@ -94,14 +98,14 @@ public void checkInvalidOrigin(){ @Test public void testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent() throws IOException { // create a notebook - Note note1 = notebook.createNote(null); + Note note1 = notebook.createNote(subject); // get reference to interpreterGroup InterpreterGroup interpreterGroup = null; List settings = notebook.getInterpreterFactory().getInterpreterSettings(note1.getId()); for (InterpreterSetting setting : settings) { if (setting.getName().equals("md")) { - interpreterGroup = setting.getInterpreterGroup("sharedProcess"); + interpreterGroup = setting.getInterpreterGroup("sharedProcess", "anonymous"); break; } } @@ -144,7 +148,7 @@ public void testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent() thr verify(sock1, times(0)).send(anyString()); verify(sock2, times(1)).send(anyString()); - notebook.removeNote(note1.getId(), null); + notebook.removeNote(note1.getId(), subject); } @Test @@ -167,7 +171,7 @@ public void testImportNotebook() throws IOException { assertNotEquals(null, notebook.getNote(note.getId())); assertEquals("Test Zeppelin notebook import", notebook.getNote(note.getId()).getName()); assertEquals("Test paragraphs import", notebook.getNote(note.getId()).getParagraphs().get(0).getText()); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), subject); } @Test diff --git a/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html b/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html index 1550126b9b7..2b020f14103 100644 --- a/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html +++ b/zeppelin-web/src/app/interpreter/interpreter-create/interpreter-create.html @@ -36,6 +36,18 @@

Create new interpreter

Option + +
+
+ + + +
+
+