You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2016/11/01 06:02:59 UTC
zeppelin git commit: [ZEPPELIN-1061] Select default interpreter while
creating note
Repository: zeppelin
Updated Branches:
refs/heads/master ddf1bcfe4 -> 0f56337ce
[ZEPPELIN-1061] Select default interpreter while creating note
### What is this PR for?
This handles setting the default interpreter on creating a note through the zeppelin UI.
### What type of PR is it?
Feature
### Todos
NA
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1061
### How should this be tested?
- Go to the 'Create Note' dialog and provide the name with the default interpreter selected.After clicking on the Create button, the selected interpreter should be shown properly in the interpreter binding section.
- If there is no interpreter selected, then the system default will be used.
### Screenshots (if appropriate)
![zeppelin-1061](https://cloud.githubusercontent.com/assets/20789766/19378611/200d9d50-920b-11e6-930a-6fdcf67c5215.png)
### Questions:
- Does the licenses files need update? No
- Is there breaking changes for older versions? No
- Does this needs documentation? No
Author: Kavin <ka...@imaginea.com>
Closes #1520 from kavinkumarks/zeppelin-1061-create-note-default-interpreter and squashes the following commits:
adfcd85 [Kavin] Fixing the new test case failure with recent changes from master.
b086f77 [Kavin] Reset the dropdown selected value for the previous action.
a88a1d2 [Kavin] 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.
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/0f56337c
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/0f56337c
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/0f56337c
Branch: refs/heads/master
Commit: 0f56337ce3eee917e0a140dc4f3f88e6002b8753
Parents: ddf1bcf
Author: Kavin <ka...@imaginea.com>
Authored: Wed Oct 26 13:30:48 2016 +0530
Committer: Jongyoul Lee <jo...@apache.org>
Committed: Tue Nov 1 15:02:43 2016 +0900
----------------------------------------------------------------------
.../apache/zeppelin/socket/NotebookServer.java | 31 ++++++++++++++-
.../zeppelin/socket/NotebookServerTest.java | 42 ++++++++++++++++++++
.../noteName-create/note-name-dialog.html | 12 +++++-
.../noteName-create/notename.controller.js | 25 +++++++++++-
.../websocketEvents/websocketEvents.factory.js | 2 +
.../websocketEvents/websocketMsg.service.js | 14 ++++++-
.../zeppelin/notebook/socket/Message.java | 2 +
7 files changed, 122 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0f56337c/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
----------------------------------------------------------------------
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 2ddb79b..28a9ac3 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
@@ -258,6 +258,9 @@ public class NotebookServer extends WebSocketServlet implements
case EDITOR_SETTING:
getEditorSetting(conn, messagereceived);
break;
+ case GET_INTERPRETER_SETTINGS:
+ getInterpreterSettings(conn, subject);
+ break;
default:
break;
}
@@ -699,11 +702,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);
@@ -1661,5 +1680,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)));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0f56337c/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
----------------------------------------------------------------------
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 a2225ab..40e4965 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
@@ -360,6 +360,48 @@ 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());
+
+ 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(), anonymous);
+ }
+
private NotebookSocket createWebSocket() {
NotebookSocket sock = mock(NotebookSocket.class);
when(sock.getRequest()).thenReturn(mockRequest);
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0f56337c/zeppelin-web/src/components/noteName-create/note-name-dialog.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/components/noteName-create/note-name-dialog.html b/zeppelin-web/src/components/noteName-create/note-name-dialog.html
index 1f90085..fdb825a 100644
--- a/zeppelin-web/src/components/noteName-create/note-name-dialog.html
+++ b/zeppelin-web/src/components/noteName-create/note-name-dialog.html
@@ -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>
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0f56337c/zeppelin-web/src/components/noteName-create/notename.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/components/noteName-create/notename.controller.js b/zeppelin-web/src/components/noteName-create/notename.controller.js
index 604254f..2936fad 100644
--- a/zeppelin-web/src/components/noteName-create/notename.controller.js
+++ b/zeppelin-web/src/components/noteName-create/notename.controller.js
@@ -29,10 +29,17 @@
vm.notes = noteListDataFactory;
vm.websocketMsgSrv = websocketMsgSrv;
$scope.note = {};
+ $scope.interpreterSettings = {};
+ $scope.note.defaultInterpreter = null;
vm.createNote = function() {
if (!vm.clone) {
- vm.websocketMsgSrv.createNote($scope.note.notename);
+ var defaultInterpreterId = '';
+ if ($scope.note.defaultInterpreter !== null) {
+ defaultInterpreterId = $scope.note.defaultInterpreter.id;
+ }
+ vm.websocketMsgSrv.createNotebook($scope.note.notename, defaultInterpreterId);
+ $scope.note.defaultInterpreter = null;
} else {
var noteId = $routeParams.noteId;
vm.websocketMsgSrv.cloneNote(noteId, $scope.note.notename);
@@ -90,6 +97,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();
}
})();
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0f56337c/zeppelin-web/src/components/websocketEvents/websocketEvents.factory.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/components/websocketEvents/websocketEvents.factory.js b/zeppelin-web/src/components/websocketEvents/websocketEvents.factory.js
index c01b06f..71ed7d8 100644
--- a/zeppelin-web/src/components/websocketEvents/websocketEvents.factory.js
+++ b/zeppelin-web/src/components/websocketEvents/websocketEvents.factory.js
@@ -138,6 +138,8 @@
});
} else if (op === 'CONFIGURATIONS_INFO') {
$rootScope.$broadcast('configurationsInfo', data);
+ } else if (op === 'INTERPRETER_SETTINGS') {
+ $rootScope.$broadcast('interpreterSettings', data);
}
});
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0f56337c/zeppelin-web/src/components/websocketEvents/websocketMsg.service.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/components/websocketEvents/websocketMsg.service.js b/zeppelin-web/src/components/websocketEvents/websocketMsg.service.js
index fd1cc97..da75939 100644
--- a/zeppelin-web/src/components/websocketEvents/websocketMsg.service.js
+++ b/zeppelin-web/src/components/websocketEvents/websocketMsg.service.js
@@ -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'});
}
};
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0f56337c/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
index ebddd4a..d678661 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
@@ -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
}