mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Added option to select the default interpreter on creating a note and
added websocket APIs to get interpreter settings for the former.Added test cases too.
This commit is contained in:
parent
0dd04d5284
commit
a88a1d25c2
7 changed files with 121 additions and 6 deletions
|
|
@ -259,6 +259,9 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
case EDITOR_SETTING:
|
||||
getEditorSetting(conn, messagereceived);
|
||||
break;
|
||||
case GET_INTERPRETER_SETTINGS:
|
||||
getInterpreterSettings(conn, subject);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -700,11 +703,27 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
Notebook notebook, Message message)
|
||||
throws IOException {
|
||||
AuthenticationInfo subject = new AuthenticationInfo(message.principal);
|
||||
Note note = notebook.createNote(subject);
|
||||
Note note = null;
|
||||
|
||||
String defaultInterpreterId = (String) message.get("defaultInterpreterId");
|
||||
if (!StringUtils.isEmpty(defaultInterpreterId)) {
|
||||
List<String> interpreterSettingIds = new LinkedList<>();
|
||||
interpreterSettingIds.add(defaultInterpreterId);
|
||||
for (String interpreterSettingId : notebook.getInterpreterFactory().
|
||||
getDefaultInterpreterSettingList()) {
|
||||
if (!interpreterSettingId.equals(defaultInterpreterId)) {
|
||||
interpreterSettingIds.add(interpreterSettingId);
|
||||
}
|
||||
}
|
||||
note = notebook.createNote(interpreterSettingIds, subject);
|
||||
} else {
|
||||
note = notebook.createNote(subject);
|
||||
}
|
||||
|
||||
note.addParagraph(); // it's an empty note. so add one paragraph
|
||||
if (message != null) {
|
||||
String noteName = (String) message.get("name");
|
||||
if (noteName == null || noteName.isEmpty()){
|
||||
if (StringUtils.isEmpty(noteName)){
|
||||
noteName = "Note " + note.getId();
|
||||
}
|
||||
note.setName(noteName);
|
||||
|
|
@ -1662,5 +1681,13 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
conn.send(serializeMessage(resp));
|
||||
return;
|
||||
}
|
||||
|
||||
private void getInterpreterSettings(NotebookSocket conn, AuthenticationInfo subject)
|
||||
throws IOException {
|
||||
List<InterpreterSetting> availableSettings = notebook().getInterpreterFactory().get();
|
||||
conn.send(serializeMessage(new Message(OP.INTERPRETER_SETTINGS)
|
||||
.put("interpreterSettings", availableSettings)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -360,6 +360,49 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
verify(otherConn).send(mdMsg1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNoteWithDefaultInterpreterId() throws IOException {
|
||||
// create two sockets and open it
|
||||
NotebookSocket sock1 = createWebSocket();
|
||||
NotebookSocket sock2 = createWebSocket();
|
||||
|
||||
assertEquals(sock1, sock1);
|
||||
assertNotEquals(sock1, sock2);
|
||||
|
||||
notebookServer.onOpen(sock1);
|
||||
notebookServer.onOpen(sock2);
|
||||
|
||||
String noteName = "Note with millis " + System.currentTimeMillis();
|
||||
String defaultInterpreterId = "";
|
||||
List<InterpreterSetting> settings = notebook.getInterpreterFactory().get();
|
||||
if (settings.size() > 1) {
|
||||
defaultInterpreterId = settings.get(1).getId();
|
||||
}
|
||||
// create note from sock1
|
||||
notebookServer.onMessage(sock1, gson.toJson(
|
||||
new Message(OP.NEW_NOTE)
|
||||
.put("name", noteName)
|
||||
.put("defaultInterpreterId", defaultInterpreterId)));
|
||||
|
||||
// expect the events are broadcasted properly
|
||||
verify(sock1, times(2)).send(anyString());
|
||||
verify(sock2, times(1)).send(anyString());
|
||||
|
||||
Note createdNote = null;
|
||||
for (Note note : notebook.getAllNotes()) {
|
||||
if (note.getName().equals(noteName)) {
|
||||
createdNote = note;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.size() > 1) {
|
||||
assertEquals(notebook.getInterpreterFactory().getDefaultInterpreterSetting(
|
||||
createdNote.getId()).getId(), defaultInterpreterId);
|
||||
}
|
||||
notebook.removeNote(createdNote.getId(), null);
|
||||
}
|
||||
|
||||
private NotebookSocket createWebSocket() {
|
||||
NotebookSocket sock = mock(NotebookSocket.class);
|
||||
when(sock.getRequest()).thenReturn(mockRequest);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,17 @@ limitations under the License.
|
|||
<div class="form-group">
|
||||
<label for="noteName">Note Name</label> <input
|
||||
placeholder="Note name" type="text" class="form-control"
|
||||
id="noteName" ng-model="note.notename" ng-enter="notenamectrl.handleNameEnter()"/>
|
||||
id="noteName" ng-model="note.notename" ng-enter="notenamectrl.handleNameEnter()"/><br/>
|
||||
<div ng-show="!notenamectrl.clone">
|
||||
<label for="defaultInterpreter">Default Interpreter </label>
|
||||
<select ng-model="note.defaultInterpreter"
|
||||
class="selectpicker"
|
||||
name="defaultInterpreter"
|
||||
id="defaultInterpreter"
|
||||
ng-options="option.name for option in interpreterSettings">
|
||||
<option value="">--Select--</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
Use '/' to create folders. Example: /NoteDirA/Notebook1
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -29,10 +29,15 @@
|
|||
vm.notes = noteListDataFactory;
|
||||
vm.websocketMsgSrv = websocketMsgSrv;
|
||||
$scope.note = {};
|
||||
$scope.interpreterSettings = {};
|
||||
|
||||
vm.createNote = function() {
|
||||
if (!vm.clone) {
|
||||
vm.websocketMsgSrv.createNote($scope.note.notename);
|
||||
var defaultInterpreterId = '';
|
||||
if ($scope.note.defaultInterpreter !== undefined && $scope.note.defaultInterpreter !== '') {
|
||||
defaultInterpreterId = $scope.note.defaultInterpreter.id;
|
||||
}
|
||||
vm.websocketMsgSrv.createNotebook($scope.note.notename, defaultInterpreterId);
|
||||
} else {
|
||||
var noteId = $routeParams.noteId;
|
||||
vm.websocketMsgSrv.cloneNote(noteId, $scope.note.notename);
|
||||
|
|
@ -90,6 +95,22 @@
|
|||
}
|
||||
return newCloneName + ' ' + copyCount;
|
||||
};
|
||||
|
||||
vm.getInterpreterSettings = function() {
|
||||
vm.websocketMsgSrv.getInterpreterSettings();
|
||||
};
|
||||
|
||||
$scope.$on('interpreterSettings', function(event, data) {
|
||||
$scope.interpreterSettings = data.interpreterSettings;
|
||||
});
|
||||
|
||||
var init = function() {
|
||||
if (!vm.clone) {
|
||||
vm.getInterpreterSettings();
|
||||
}
|
||||
};
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -138,6 +138,8 @@
|
|||
});
|
||||
} else if (op === 'CONFIGURATIONS_INFO') {
|
||||
$rootScope.$broadcast('configurationsInfo', data);
|
||||
} else if (op === 'INTERPRETER_SETTINGS') {
|
||||
$rootScope.$broadcast('interpreterSettings', data);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,14 @@
|
|||
websocketEvents.sendNewEvent({op: 'GET_HOME_NOTE'});
|
||||
},
|
||||
|
||||
createNote: function(noteName) {
|
||||
websocketEvents.sendNewEvent({op: 'NEW_NOTE',data: {name: noteName}});
|
||||
createNotebook: function(noteName, defaultInterpreterId) {
|
||||
websocketEvents.sendNewEvent({
|
||||
op: 'NEW_NOTE',
|
||||
data: {
|
||||
name: noteName,
|
||||
defaultInterpreterId: defaultInterpreterId
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
deleteNote: function(noteId) {
|
||||
|
|
@ -223,6 +229,10 @@
|
|||
|
||||
listConfigurations: function() {
|
||||
websocketEvents.sendNewEvent({op: 'LIST_CONFIGURATIONS'});
|
||||
},
|
||||
|
||||
getInterpreterSettings: function() {
|
||||
websocketEvents.sendNewEvent({op: 'GET_INTERPRETER_SETTINGS'});
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -140,6 +140,8 @@ public class Message {
|
|||
// @param noteId
|
||||
// @param selectedSettingIds
|
||||
INTERPRETER_BINDINGS, // [s-c] interpreter bindings
|
||||
GET_INTERPRETER_SETTINGS, // [c-s] get interpreter settings
|
||||
INTERPRETER_SETTINGS, // [s-c] interpreter settings
|
||||
ERROR_INFO // [s-c] error information to be sent
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue