ZEPPELIN-1254 Make get and save Interpreter bindings calls via websocket

This commit is contained in:
Renjith Kamath 2016-07-29 18:28:31 +05:30
parent 848dbd0302
commit 97bfd7d8c2
6 changed files with 79 additions and 28 deletions

View file

@ -39,6 +39,7 @@ import org.apache.zeppelin.helium.HeliumPackage;
import org.apache.zeppelin.interpreter.InterpreterGroup;
import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.rest.message.InterpreterSettingListForNoteBind;
import org.apache.zeppelin.user.AuthenticationInfo;
import org.apache.zeppelin.interpreter.InterpreterOutput;
import org.apache.zeppelin.interpreter.InterpreterResult;
@ -234,6 +235,12 @@ public class NotebookServer extends WebSocketServlet implements
case LIST_UPDATE_NOTEBOOK_JOBS:
unicastUpdateNotebookJobInfo(conn, messagereceived);
break;
case GET_INTERPRETER_BINDINGS:
getInterpreterBindings(conn, messagereceived);
break;
case SAVE_INTERPRETER_BINDINGS:
saveInterpreterBindings(conn, messagereceived);
break;
default:
break;
}
@ -411,6 +418,48 @@ public class NotebookServer extends WebSocketServlet implements
.put("notebookRunningJobs", response)));
}
public void saveInterpreterBindings(NotebookSocket conn, Message fromMessage) {
try {
List<String> settingIdList = gson.fromJson(String.valueOf(
fromMessage.data.get("selectedSettingIds")), new TypeToken<ArrayList<String>>() {
}.getType());
notebook().bindInterpretersToNote((String) fromMessage.data.get("noteID"), settingIdList);
} catch (Exception e) {
LOG.error("Error while saving interpreter bindings", e);
}
}
public void getInterpreterBindings(NotebookSocket conn, Message fromMessage)
throws IOException {
List<InterpreterSettingListForNoteBind> settingList = new LinkedList<>();
List<InterpreterSetting> selectedSettings =
notebook().getBindedInterpreterSettings((String) fromMessage.data.get("noteID"));
for (InterpreterSetting setting : selectedSettings) {
settingList.add(new InterpreterSettingListForNoteBind(setting.getId(), setting.getName(),
setting.getInterpreterInfos(), true));
}
List<InterpreterSetting> availableSettings = notebook().getInterpreterFactory().get();
for (InterpreterSetting setting : availableSettings) {
boolean selected = false;
for (InterpreterSetting selectedSetting : selectedSettings) {
if (selectedSetting.getId().equals(setting.getId())) {
selected = true;
break;
}
}
if (!selected) {
settingList.add(new InterpreterSettingListForNoteBind(setting.getId(), setting.getName(),
setting.getInterpreterInfos(), false));
}
}
conn.send(serializeMessage(new Message(OP.INTERPRETER_BINDINGS)
.put("interpreterBindings", settingList)));
}
public List<Map<String, String>> generateNotebooksInfo(boolean needsReload,
AuthenticationInfo subject) {

View file

@ -450,22 +450,13 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
};
var getInterpreterBindings = function(callback) {
$http.get(baseUrlSrv.getRestApiBase() + '/notebook/interpreter/bind/' + $scope.note.id).
success(function(data, status, headers, config) {
$scope.interpreterBindings = data.body;
$scope.interpreterBindingsOrig = angular.copy($scope.interpreterBindings); // to check dirty
if (callback) {
callback();
}
}).
error(function(data, status, headers, config) {
if (status !== 0) {
console.log('Error %o %o', status, data.message);
}
});
websocketMsgSrv.getInterpreterBindings($scope.note.id);
};
var getInterpreterBindingsCallBack = function() {
$scope.$on('interpreterBindings', function(event, data) {
$scope.interpreterBindings = data.interpreterBindings;
$scope.interpreterBindingsOrig = angular.copy($scope.interpreterBindings); // to check dirty
var selected = false;
var key;
var setting;
@ -490,7 +481,7 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
}
$scope.showSetting = true;
}
};
});
$scope.interpreterSelectionListeners = {
accept: function(sourceItemHandleScope, destSortableScope) {return true;},
@ -530,16 +521,9 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
selectedSettingIds.push(setting.id);
}
}
$http.put(baseUrlSrv.getRestApiBase() + '/notebook/interpreter/bind/' + $scope.note.id,
selectedSettingIds).
success(function(data, status, headers, config) {
console.log('Interpreter binding %o saved', selectedSettingIds);
$scope.showSetting = false;
}).
error(function(data, status, headers, config) {
console.log('Error %o %o', status, data.message);
});
websocketMsgSrv.saveInterpreterBindings($scope.note.id, selectedSettingIds);
console.log('Interpreter bindings %o saved', selectedSettingIds);
$scope.showSetting = false;
};
$scope.toggleSetting = function() {
@ -983,7 +967,7 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
}
initializeLookAndFeel();
//open interpreter binding setting when there're none selected
getInterpreterBindings(getInterpreterBindingsCallBack);
getInterpreterBindings(); //getInterpreterBindings(getInterpreterBindingsCallBack);
});
$scope.$on('$destroy', function() {

View file

@ -113,6 +113,8 @@ angular.module('zeppelinWebApp').factory('websocketEvents',
$rootScope.$broadcast('listRevisionHistory', data);
} else if (op === 'NOTE_REVISION') {
$rootScope.$broadcast('noteRevision', data);
} else if (op === 'INTERPRETER_BINDINGS') {
$rootScope.$broadcast('interpreterBindings', data);
}
});

View file

@ -196,6 +196,15 @@ angular.module('zeppelinWebApp').service('websocketMsgSrv', function($rootScope,
unsubscribeJobManager: function() {
websocketEvents.sendNewEvent({op: 'UNSUBSCRIBE_JOBMANAGER'});
},
getInterpreterBindings: function(noteID) {
websocketEvents.sendNewEvent({op: 'GET_INTERPRETER_BINDINGS', data: {noteID: noteID}});
},
saveInterpreterBindings: function(noteID, selectedSettingIds) {
websocketEvents.sendNewEvent({op: 'SAVE_INTERPRETER_BINDINGS',
data: {noteID: noteID, selectedSettingIds: selectedSettingIds}});
}
};

View file

@ -7,7 +7,8 @@ describe('Controller: NotebookCtrl', function() {
var websocketMsgSrvMock = {
getNotebook: function() {},
listRevisionHistory: function() {}
listRevisionHistory: function() {},
getInterpreterBindings: function() {}
};
var baseUrlSrvMock = {

View file

@ -127,8 +127,14 @@ public class Message {
APP_STATUS_CHANGE, // [s-c] on app status change
LIST_NOTEBOOK_JOBS, // [c-s] get notebook job management infomations
LIST_UPDATE_NOTEBOOK_JOBS // [c-s] get job management informations for until unixtime
LIST_UPDATE_NOTEBOOK_JOBS, // [c-s] get job management informations for until unixtime
// @param unixTime
GET_INTERPRETER_BINDINGS, // [c-s] get interpreter bindings
// @param noteID
SAVE_INTERPRETER_BINDINGS, // [c-s] save interpreter bindings
// @param noteID
// @param selectedSettingIds
INTERPRETER_BINDINGS // [s-c] interpreter bindings
}
public OP op;