Added option in UI

This commit is contained in:
Jongyoul Lee 2016-08-03 00:10:18 +09:00
parent ccbedc17b4
commit 8589545ee3
9 changed files with 63 additions and 23 deletions

View file

@ -54,6 +54,7 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.xml.PrettyPrinter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@ -1509,7 +1510,7 @@ public class NotebookServer extends WebSocketServlet implements
LOG.info("Job {} is finished", job.getId());
try {
//TODO(khalid): may change interface for JobListener and pass subject from interpreter
note.persist(null);
note.persist(job instanceof Paragraph ? ((Paragraph) job).getAuthenticationInfo() : null);
} catch (IOException e) {
LOG.error(e.toString(), e);
}

View file

@ -37,23 +37,31 @@ limitations under the License.
<div>
<h5>Option</h5>
<span class="checkbox input-group">
<label><input type="checkbox" style="width:0%;height:0%" id="perNote" ng-model="newInterpreterSetting.option.perNote"/>
perNote </label>
</span>
<span class="checkbox input-group">
<label><input type="checkbox" style="width:0%;height:0%" id="perUser" ng-model="newInterpreterSetting.option.perUser"/>
perUser</label>
</span>
<span class="btn-group">
<button type="button" class="btn btn-default btn-xs dropdown-toggle"
data-toggle="dropdown">
{{getSessionOption(setting.id)}} <span class="caret"></span>
{{getSessionOption(newInterpreterSetting.id)}} <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a style="cursor:pointer"
tooltip="Single interpreter instance are shared across notes"
ng-click="setSessionOption(setting.id, 'shared')">
ng-click="setSessionOption(newInterpreterSetting.id, 'shared')">
shared
</a>
</li>
<li>
<a style="cursor:pointer"
tooltip="Separate Interpreter instance for each note"
ng-click="setSessionOption(setting.id, 'scoped')">
ng-click="setSessionOption(newInterpreterSetting.id, 'scoped')">
scoped
</a>
</li>
@ -66,7 +74,6 @@ limitations under the License.
</li>
</ul>
</span>
<span>Interpreter for note</span>
</div>
<div class="row interpreter" style="margin-top: 5px;">

View file

@ -141,9 +141,18 @@ limitations under the License.
</span>
</div>
</div>
<div class="row interpreter">
<div class="col-md-12">
<h5>Option</h5>
<span class="checkbox input-group">
<label><input type="checkbox" style="width:0%;height:0%" id="perNote" ng-model="setting.option.perNote" ng-disabled="!valueform.$visible"/>
perNote </label>
</span>
<span class="checkbox input-group">
<label><input type="checkbox" style="width:0%;height:0%" id="perUser" ng-model="setting.option.perUser" ng-disabled="!valueform.$visible"/>
perUser</label>
</span>
<span class="btn-group">
<button type="button" class="btn btn-default btn-xs dropdown-toggle"
data-toggle="dropdown"

View file

@ -700,9 +700,9 @@ public class InterpreterFactory implements InterpreterGroupFactory {
public void removeInterpretersForNote(InterpreterSetting interpreterSetting, String user,
String noteId) {
if (interpreterSetting.getOption().isPerNoteProcess()) {
if (interpreterSetting.getOption().isProcess()) {
interpreterSetting.closeAndRemoveInterpreterGroup(noteId);
} else if (interpreterSetting.getOption().isPerNoteSession()) {
} else if (interpreterSetting.getOption().isSession()) {
InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup(user, noteId);
String key = getInterpreterInstanceKey(user, noteId, interpreterSetting);
interpreterGroup.close(key);
@ -1134,13 +1134,14 @@ public class InterpreterFactory implements InterpreterGroupFactory {
}
private String getInterpreterInstanceKey(String user, String noteId, InterpreterSetting setting) {
InterpreterOption option = setting.getOption();
String key;
if (setting.getOption().isExistingProcess()) {
key = user + ":" + Constants.EXISTING_PROCESS;
} else if (setting.getOption().isPerNoteSession() || setting.getOption().isPerNoteProcess()) {
key = user + ":" + noteId;
if (option.isExistingProcess()) {
key = Constants.EXISTING_PROCESS;
} else if (option.isSession() || option.isProcess()) {
key = (option.isPerUser() ? user : "") + ":" + (option.isPerNote() ? noteId : "");
} else {
key = user + ":" + SHARED_SESSION;
key = SHARED_SESSION;
}
logger.debug("Interpreter instance key: {}", key);

View file

@ -26,6 +26,10 @@ public class InterpreterOption {
boolean remote;
String host = null;
int port = -1;
boolean perNote;
boolean perUser;
boolean perNoteSession;
boolean perNoteProcess;
@ -33,6 +37,22 @@ public class InterpreterOption {
boolean setPermission;
List<String> users;
public boolean isPerNote() {
return perNote;
}
public void setPerNote(boolean perNote) {
this.perNote = perNote;
}
public boolean isPerUser() {
return perUser;
}
public void setPerUser(boolean perUser) {
this.perUser = perUser;
}
public boolean isExistingProcess() {
return isExistingProcess;
}

View file

@ -107,13 +107,14 @@ public class InterpreterSetting {
}
private String getInterpreterProcessKey(String user, String noteId) {
InterpreterOption option = getOption();
String key;
if (getOption().isExistingProcess) {
key = user + ":" + Constants.EXISTING_PROCESS;
} else if (getOption().isPerNoteProcess()) {
key = user + ":" + noteId;
key = Constants.EXISTING_PROCESS;
} else if (getOption().isProcess()) {
key = (option.isPerUser() ? user : "") + ":" + (option.isPerNote() ? noteId : "");
} else {
key = user + ":" + SHARED_PROCESS;
key = SHARED_PROCESS;
}
logger.debug("getInterpreterProcessKey: {}", key);

View file

@ -499,6 +499,7 @@ public class Note implements Serializable, ParagraphJobListener {
throw intpException;
}
if (p.getConfig().get("enabled") == null || (Boolean) p.getConfig().get("enabled")) {
p.setAuthenticationInfo(p.getAuthenticationInfo());
intp.getScheduler().submit(p);
}
}

View file

@ -96,10 +96,10 @@ public class NoteInterpreterLoaderTest {
@Test
public void testNoteSession() throws IOException {
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNoteSession(true);
factory.getInterpreterSettings("noteA").get(0).getOption().setSession(true);
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNoteSession(true);
factory.getInterpreterSettings("noteB").get(0).getOption().setSession(true);
// interpreters are not created before accessing it
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
@ -129,10 +129,10 @@ public class NoteInterpreterLoaderTest {
@Test
public void testNotePerInterpreterProcess() throws IOException {
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNoteProcess(true);
factory.getInterpreterSettings("noteA").get(0).getOption().setProcess(true);
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNoteProcess(true);
factory.getInterpreterSettings("noteB").get(0).getOption().setProcess(true);
// interpreters are not created before accessing it
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));

View file

@ -694,7 +694,7 @@ public class NotebookTest implements JobListenerFactory{
// restart interpreter with per note session enabled
for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNoteSession(true);
setting.getOption().setSession(true);
notebook.getInterpreterFactory().restart(setting.getId());
}
@ -739,7 +739,7 @@ public class NotebookTest implements JobListenerFactory{
// restart interpreter with per note session enabled
for (InterpreterSetting setting : notebook.getInterpreterFactory().getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNoteSession(true);
setting.getOption().setSession(true);
notebook.getInterpreterFactory().restart(setting.getId());
}
@ -766,7 +766,7 @@ public class NotebookTest implements JobListenerFactory{
// restart interpreter with per note session enabled
for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNoteSession(true);
setting.getOption().setSession(true);
notebook.getInterpreterFactory().restart(setting.getId());
}