Changed instanceKey and processKey for dealing with new UI

This commit is contained in:
Jongyoul Lee 2016-10-18 21:03:47 +09:00
parent d20195017c
commit 5e7da341e0
10 changed files with 107 additions and 122 deletions

View file

@ -119,4 +119,10 @@ public class SecurityUtils {
return roles;
}
/**
* Checked if shiro enabled or not
*/
public static boolean isAuthenticated() {
return org.apache.shiro.SecurityUtils.getSubject().isAuthenticated();
}
}

View file

@ -121,6 +121,8 @@ public class InterpreterFactory implements InterpreterGroupFactory {
private DependencyResolver depResolver;
private boolean shiroEnabled;
private Map<String, String> env = new HashMap<>();
private Interpreter devInterpreter;
@ -128,18 +130,18 @@ public class InterpreterFactory implements InterpreterGroupFactory {
public InterpreterFactory(ZeppelinConfiguration conf,
AngularObjectRegistryListener angularObjectRegistryListener,
RemoteInterpreterProcessListener remoteInterpreterProcessListener,
ApplicationEventListener appEventListener, DependencyResolver depResolver)
throws InterpreterException, IOException, RepositoryException {
ApplicationEventListener appEventListener, DependencyResolver depResolver,
boolean shiroEnabled) throws InterpreterException, IOException, RepositoryException {
this(conf, new InterpreterOption(true), angularObjectRegistryListener,
remoteInterpreterProcessListener, appEventListener, depResolver);
remoteInterpreterProcessListener, appEventListener, depResolver, shiroEnabled);
}
public InterpreterFactory(ZeppelinConfiguration conf, InterpreterOption defaultOption,
AngularObjectRegistryListener angularObjectRegistryListener,
RemoteInterpreterProcessListener remoteInterpreterProcessListener,
ApplicationEventListener appEventListener, DependencyResolver depResolver)
throws InterpreterException, IOException, RepositoryException {
ApplicationEventListener appEventListener, DependencyResolver depResolver,
boolean shiroEnabled) throws InterpreterException, IOException, RepositoryException {
this.conf = conf;
this.defaultOption = defaultOption;
this.angularObjectRegistryListener = angularObjectRegistryListener;
@ -147,6 +149,7 @@ public class InterpreterFactory implements InterpreterGroupFactory {
this.interpreterRepositories = depResolver.getRepos();
this.remoteInterpreterProcessListener = remoteInterpreterProcessListener;
this.appEventListener = appEventListener;
this.shiroEnabled = shiroEnabled;
String replsConf = conf.getString(ConfVars.ZEPPELIN_INTERPRETERS);
interpreterClassList = replsConf.split(",");
String groupOrder = conf.getString(ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER);
@ -700,9 +703,10 @@ public class InterpreterFactory implements InterpreterGroupFactory {
public void removeInterpretersForNote(InterpreterSetting interpreterSetting, String user,
String noteId) {
if (interpreterSetting.getOption().isProcess()) {
InterpreterOption option = interpreterSetting.getOption();
if (option.isProcess()) {
interpreterSetting.closeAndRemoveInterpreterGroup(noteId);
} else if (interpreterSetting.getOption().isSession()) {
} else if (option.isSession()) {
InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup(user, noteId);
String key = getInterpreterInstanceKey(user, noteId, interpreterSetting);
interpreterGroup.close(key);
@ -1138,8 +1142,12 @@ public class InterpreterFactory implements InterpreterGroupFactory {
String key;
if (option.isExistingProcess()) {
key = Constants.EXISTING_PROCESS;
} else if (option.isSession() || option.isProcess()) {
key = (option.isPerUser() ? user : "") + ":" + (option.isPerNote() ? noteId : "");
} else if (!(shiroEnabled && option.perUserShared()) || !option.perNoteShared()) {
if (shiroEnabled) {
key = (!option.perUserShared() ? user : "") + ":" + (!option.perNoteShared() ? noteId : "");
} else {
key = (!option.perNoteShared() ? noteId : "");
}
} else {
key = SHARED_SESSION;
}

View file

@ -17,15 +17,17 @@
package org.apache.zeppelin.interpreter;
import com.google.common.base.Preconditions;
import java.util.List;
/**
*
*/
public class InterpreterOption {
public final transient String SHARED = "shared";
public final transient String SCOPED = "scoped";
public final transient String ISOLATED = "isolated";
public static final transient String SHARED = "shared";
public static final transient String SCOPED = "scoped";
public static final transient String ISOLATED = "isolated";
boolean remote;
String host = null;
@ -34,56 +36,10 @@ public class InterpreterOption {
String perNote;
String perUser;
boolean session;
boolean process;
boolean isExistingProcess;
boolean setPermission;
List<String> users;
public boolean isGlobally() {
if (perNote != null && perNote.equals(SHARED)
&& perUser != null && perUser.equals(SHARED)) {
return true;
}
return false;
}
public boolean isPerNote() {
if (isGlobally() == true) {
return false;
}
if (perNote != null && !perNote.equals("")) {
return true;
}
return false;
}
public void setPerNote(String perNote) {
this.perNote = perNote;
}
public boolean isPerUser() {
if (isGlobally() == true) {
return false;
}
if (isPerNote() == true) {
return false;
}
if (perUser != null && !perUser.equals("")) {
return true;
}
return false;
}
public void setPerUser(String perUser) {
this.perUser = perUser;
}
public boolean isExistingProcess() {
return isExistingProcess;
}
@ -113,15 +69,21 @@ public class InterpreterOption {
}
public InterpreterOption() {
this.perNote = SCOPED;
this.perUser = SCOPED;
remote = false;
this(false);
}
public InterpreterOption(boolean remote) {
this.perNote = SCOPED;
this.perUser = SCOPED;
this(remote, SHARED, SHARED);
}
public InterpreterOption(boolean remote, String perUser, String perNote) {
Preconditions.checkNotNull(remote);
Preconditions.checkNotNull(perUser);
Preconditions.checkNotNull(perNote);
this.remote = remote;
this.perUser = perUser;
this.perNote = perNote;
}
public boolean isRemote() {
@ -132,14 +94,6 @@ public class InterpreterOption {
this.remote = remote;
}
public boolean isSession() {
return session;
}
public void setSession(boolean session) {
this.session = session;
}
public String getHost() {
return host;
}
@ -148,11 +102,44 @@ public class InterpreterOption {
return port;
}
public boolean isProcess() {
return process;
public boolean perUserShared() {
return SHARED.equals(perUser);
}
public void setProcess(boolean process) {
this.process = process;
public boolean perUserScoped() {
return SCOPED.equals(perUser);
}
public boolean perUserIsolated() {
return ISOLATED.equals(perUser);
}
public boolean perNoteShared() {
return SHARED.equals(perNote);
}
public boolean perNoteScoped() {
return SCOPED.equals(perNote);
}
public boolean perNoteIsolated() {
return ISOLATED.equals(perNote);
}
public boolean isProcess() {
return perUserIsolated() || perNoteIsolated();
}
public boolean isSession() {
return perUserScoped() || perNoteScoped();
}
public void setPerNote(String perNote) {
this.perNote = perNote;
}
public void setPerUser(String perUser) {
this.perUser = perUser;
}
}

View file

@ -112,7 +112,7 @@ public class InterpreterSetting {
if (getOption().isExistingProcess) {
key = Constants.EXISTING_PROCESS;
} else if (getOption().isProcess()) {
key = (option.isPerUser() ? user : "") + ":" + (option.isPerNote() ? noteId : "");
key = (option.perUserIsolated() ? user : "") + ":" + (option.perNoteIsolated() ? noteId : "");
} else {
key = SHARED_PROCESS;
}

View file

@ -85,7 +85,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
heliumAppFactory = new HeliumApplicationFactory();
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
factory = new InterpreterFactory(conf,
new InterpreterOption(true), null, null, heliumAppFactory, depResolver);
new InterpreterOption(true), null, null, heliumAppFactory, depResolver, false);
HashMap<String, String> env = new HashMap<String, String>();
env.put("ZEPPELIN_CLASSPATH", new File("./target/test-classes").getAbsolutePath());
factory.setEnv(env);

View file

@ -89,7 +89,7 @@ public class InterpreterFactoryTest {
conf = new ZeppelinConfiguration();
schedulerFactory = new SchedulerFactory();
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver);
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false);
context = new InterpreterContext("note", "id", "title", "text", null, null, null, null, null, null, null);
SearchService search = mock(SearchService.class);
@ -132,7 +132,7 @@ public class InterpreterFactoryTest {
@Test
public void testRemoteRepl() throws Exception {
factory = new InterpreterFactory(conf, new InterpreterOption(true), null, null, null, depResolver);
factory = new InterpreterFactory(conf, new InterpreterOption(true), null, null, null, depResolver, false);
List<InterpreterSetting> all = factory.get();
InterpreterSetting mock1Setting = null;
for (InterpreterSetting setting : all) {
@ -188,13 +188,13 @@ public class InterpreterFactoryTest {
factory.createNewSetting("new-mock1", "mock1", new LinkedList<Dependency>(), new InterpreterOption(false), new Properties());
assertEquals(numInterpreters + 1, factory.get().size());
InterpreterFactory factory2 = new InterpreterFactory(conf, null, null, null, depResolver);
InterpreterFactory factory2 = new InterpreterFactory(conf, null, null, null, depResolver, false);
assertEquals(numInterpreters + 1, factory2.get().size());
}
@Test
public void testInterpreterAliases() throws IOException, RepositoryException {
factory = new InterpreterFactory(conf, null, null, null, depResolver);
factory = new InterpreterFactory(conf, null, null, null, depResolver, false);
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true, null);
final InterpreterInfo info2 = new InterpreterInfo("className2", "name1", true, null);
factory.add("group1", new ArrayList<InterpreterInfo>(){{
@ -218,15 +218,13 @@ public class InterpreterFactoryTest {
@Test
public void testMultiUser() throws IOException, RepositoryException {
factory = new InterpreterFactory(conf, null, null, null, depResolver);
factory = new InterpreterFactory(conf, null, null, null, depResolver, true);
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true, null);
factory.add("group1", new ArrayList<InterpreterInfo>(){{
add(info1);
}}, new ArrayList<Dependency>(), new InterpreterOption(true), new Properties(), "/path1");
InterpreterOption perUserInterpreterOption = new InterpreterOption(true);
perUserInterpreterOption.setSession(true);
perUserInterpreterOption.setPerUser(perUserInterpreterOption.ISOLATED);
InterpreterOption perUserInterpreterOption = new InterpreterOption(true, InterpreterOption.ISOLATED, InterpreterOption.SHARED);
final InterpreterSetting setting1 = factory.createNewSetting("test-group1", "group1", new ArrayList<Dependency>(), perUserInterpreterOption, new Properties());
factory.setInterpreters("user1", "note", new ArrayList<String>() {{

View file

@ -60,7 +60,7 @@ public class NoteInterpreterLoaderTest {
MockInterpreter2.register("mock2", "group2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver);
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false);
}
@After
@ -95,20 +95,15 @@ public class NoteInterpreterLoaderTest {
@Test
public void testNoteSession() throws IOException {
InterpreterOption dumyInterpreterOption = new InterpreterOption();
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteA").get(0).getOption().setSession(true);
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNote(dumyInterpreterOption.SCOPED);
factory.getInterpreterSettings("noteA").get(0).getOption().setPerUser("");
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNote(InterpreterOption.SCOPED);
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteB").get(0).getOption().setSession(true);
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNote(dumyInterpreterOption.SCOPED);
factory.getInterpreterSettings("noteB").get(0).getOption().setPerUser("");
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNote(InterpreterOption.SCOPED);
// interpreters are not created before accessing it
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
factory.getInterpreter("user", "noteA", null).open();
factory.getInterpreter("user", "noteB", null).open();
@ -118,35 +113,30 @@ public class NoteInterpreterLoaderTest {
factory.getInterpreter("user", "noteB", null).getInterpreterGroup().getId()));
// interpreters are created after accessing it
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
// when
factory.closeNote("user", "noteA");
factory.closeNote("user", "noteB");
// interpreters are destroyed after close
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get(":noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get(":noteB"));
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get("noteB"));
}
@Test
public void testNotePerInterpreterProcess() throws IOException {
InterpreterOption dumyInterpreterOption = new InterpreterOption();
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteA").get(0).getOption().setProcess(true);
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNote(dumyInterpreterOption.SCOPED);
factory.getInterpreterSettings("noteA").get(0).getOption().setPerUser("");
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNote(InterpreterOption.ISOLATED);
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteB").get(0).getOption().setProcess(true);
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNote(dumyInterpreterOption.SCOPED);
factory.getInterpreterSettings("noteB").get(0).getOption().setPerUser("");
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNote(InterpreterOption.ISOLATED);
// interpreters are not created before accessing it
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
factory.getInterpreter("user", "noteA", null).open();
factory.getInterpreter("user", "noteB", null).open();
@ -157,16 +147,16 @@ public class NoteInterpreterLoaderTest {
factory.getInterpreter("user", "noteB", null).getInterpreterGroup().getId()));
// interpreters are created after accessing it
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
// when
factory.closeNote("user", "noteA");
factory.closeNote("user", "noteB");
// interpreters are destroyed after close
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
}

View file

@ -89,7 +89,7 @@ public class NotebookTest implements JobListenerFactory{
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver);
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false);
SearchService search = mock(SearchService.class);
notebookRepo = new VFSNotebookRepo(conf);
@ -210,7 +210,7 @@ public class NotebookTest implements JobListenerFactory{
Notebook notebook2 = new Notebook(
conf, notebookRepo, schedulerFactory,
new InterpreterFactory(conf, null, null, null, depResolver), this, null, null, null);
new InterpreterFactory(conf, null, null, null, depResolver, false), this, null, null, null);
assertEquals(1, notebook2.getAllNotes().size());
notebook.removeNote(note.getId(), null);
@ -698,9 +698,7 @@ public class NotebookTest implements JobListenerFactory{
// restart interpreter with per user session enabled
for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) {
setting.getOption().setSession(true);
setting.getOption().setPerNote(setting.getOption().SCOPED);
setting.getOption().setPerUser("");
notebook.getInterpreterFactory().restart(setting.getId());
}
@ -748,9 +746,7 @@ public class NotebookTest implements JobListenerFactory{
// restart interpreter with per note session enabled
for (InterpreterSetting setting : notebook.getInterpreterFactory().getInterpreterSettings(note1.getId())) {
setting.getOption().setSession(true);
setting.getOption().setPerNote(setting.getOption().SCOPED);
setting.getOption().setPerUser(setting.getOption().SCOPED);
setting.getOption().setPerNote(InterpreterOption.SCOPED);
notebook.getInterpreterFactory().restart(setting.getId());
}
@ -777,7 +773,7 @@ public class NotebookTest implements JobListenerFactory{
// restart interpreter with per note session enabled
for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) {
setting.getOption().setSession(true);
setting.getOption().setPerNote(InterpreterOption.SCOPED);
notebook.getInterpreterFactory().restart(setting.getId());
}

View file

@ -97,7 +97,7 @@ public class NotebookRepoSyncTest implements JobListenerFactory {
MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");
depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo");
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver);
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false);
search = mock(SearchService.class);
notebookRepoSync = new NotebookRepoSync(conf);

View file

@ -78,7 +78,7 @@ public class VFSNotebookRepoTest implements JobListenerFactory {
this.schedulerFactory = new SchedulerFactory();
depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo");
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver);
factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false);
SearchService search = mock(SearchService.class);
notebookRepo = new VFSNotebookRepo(conf);