Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -39,18 +38,18 @@
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.apache.zeppelin.utils.InterpreterBindingUtils;
import org.quartz.CronExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.zeppelin.annotation.ZeppelinApi;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.notebook.Note;
import org.apache.zeppelin.notebook.Notebook;
import org.apache.zeppelin.notebook.NotebookAuthorization;
import org.apache.zeppelin.notebook.Paragraph;
import org.apache.zeppelin.rest.message.CronRequest;
import org.apache.zeppelin.rest.message.InterpreterSettingListForNoteBind;
import org.apache.zeppelin.types.InterpreterSettingsList;
import org.apache.zeppelin.rest.message.NewNotebookRequest;
import org.apache.zeppelin.rest.message.NewParagraphRequest;
import org.apache.zeppelin.rest.message.RunParagraphWithParametersRequest;
Expand Down Expand Up @@ -186,29 +185,9 @@ public Response bind(@PathParam("noteId") String noteId, String req) throws IOEx
@Path("interpreter/bind/{noteId}")
@ZeppelinApi
public Response bind(@PathParam("noteId") String noteId) {
List<InterpreterSettingListForNoteBind> settingList = new LinkedList<>();

List<InterpreterSetting> selectedSettings = notebook.getBindedInterpreterSettings(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));
}
}
List<InterpreterSettingsList> settingList =
InterpreterBindingUtils.getInterpreterBindings(notebook, noteId);
notebookServer.broadcastInterpreterBindings(noteId, settingList);
return new JsonResponse<>(Status.OK, "", settingList).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@
*/
package org.apache.zeppelin.socket;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;

import javax.servlet.http.HttpServletRequest;

import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.display.AngularObject;
Expand All @@ -37,13 +28,12 @@
import org.apache.zeppelin.helium.ApplicationEventListener;
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.user.AuthenticationInfo;
import org.apache.zeppelin.interpreter.InterpreterOutput;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
import org.apache.zeppelin.notebook.*;
import org.apache.zeppelin.notebook.repo.NotebookRepo;
import org.apache.zeppelin.notebook.repo.NotebookRepo.Revision;
Expand All @@ -53,13 +43,23 @@
import org.apache.zeppelin.scheduler.Job.Status;
import org.apache.zeppelin.server.ZeppelinServer;
import org.apache.zeppelin.ticket.TicketContainer;
import org.apache.zeppelin.types.InterpreterSettingsList;
import org.apache.zeppelin.user.AuthenticationInfo;
import org.apache.zeppelin.utils.InterpreterBindingUtils;
import org.apache.zeppelin.utils.SecurityUtils;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
* Zeppelin websocket service.
*/
Expand Down Expand Up @@ -234,6 +234,12 @@ public void onMessage(NotebookSocket conn, String msg) {
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;
}
Expand Down Expand Up @@ -411,6 +417,29 @@ public void unicastUpdateNotebookJobInfo(NotebookSocket conn, Message fromMessag
.put("notebookRunningJobs", response)));
}

public void saveInterpreterBindings(NotebookSocket conn, Message fromMessage) {
String noteId = (String) fromMessage.data.get("noteID");
try {
List<String> settingIdList = gson.fromJson(String.valueOf(
fromMessage.data.get("selectedSettingIds")), new TypeToken<ArrayList<String>>() {
}.getType());
notebook().bindInterpretersToNote(noteId, settingIdList);
broadcastInterpreterBindings(noteId,
InterpreterBindingUtils.getInterpreterBindings(notebook(), noteId));
} catch (Exception e) {
LOG.error("Error while saving interpreter bindings", e);
}
}

public void getInterpreterBindings(NotebookSocket conn, Message fromMessage)
throws IOException {
String noteID = (String) fromMessage.data.get("noteID");
List<InterpreterSettingsList> settingList =
InterpreterBindingUtils.getInterpreterBindings(notebook(), noteID);
conn.send(serializeMessage(new Message(OP.INTERPRETER_BINDINGS)
.put("interpreterBindings", settingList)));
}

public List<Map<String, String>> generateNotebooksInfo(boolean needsReload,
AuthenticationInfo subject) {

Expand Down Expand Up @@ -450,6 +479,12 @@ public void broadcastNote(Note note) {
broadcast(note.id(), new Message(OP.NOTE).put("note", note));
}

public void broadcastInterpreterBindings(String noteId,
List settingList) {
broadcast(noteId, new Message(OP.INTERPRETER_BINDINGS)
.put("interpreterBindings", settingList));
}

public void broadcastNoteList(AuthenticationInfo subject) {
List<Map<String, String>> notesInfo = generateNotebooksInfo(false, subject);
broadcastAll(new Message(OP.NOTES_INFO).put("notes", notesInfo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.zeppelin.rest.message;
package org.apache.zeppelin.types;

import java.util.List;

Expand All @@ -24,13 +24,13 @@
/**
* InterpreterSetting information for binding
*/
public class InterpreterSettingListForNoteBind {
public class InterpreterSettingsList {
private String id;
private String name;
private boolean selected;
private List<InterpreterInfo> interpreters;

public InterpreterSettingListForNoteBind(String id, String name,
public InterpreterSettingsList(String id, String name,
List<InterpreterInfo> interpreters, boolean selected) {
this.id = id;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.zeppelin.utils;

import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.notebook.Notebook;
import org.apache.zeppelin.types.InterpreterSettingsList;

import java.util.LinkedList;
import java.util.List;

/**
* Utils for interpreter bindings
*/
public class InterpreterBindingUtils {
public static List<InterpreterSettingsList> getInterpreterBindings(Notebook notebook,
String noteId) {
List<InterpreterSettingsList> settingList = new LinkedList<>();
List<InterpreterSetting> selectedSettings =
notebook.getBindedInterpreterSettings(noteId);
for (InterpreterSetting setting : selectedSettings) {
settingList.add(new InterpreterSettingsList(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 InterpreterSettingsList(setting.getId(), setting.getName(),
setting.getInterpreterInfos(), false));
}
}

return settingList;
}
}
38 changes: 11 additions & 27 deletions zeppelin-web/src/app/notebook/notebook.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,23 +449,14 @@ 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);
}
});
var getInterpreterBindings = function() {
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;
Expand All @@ -490,7 +481,7 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
}
$scope.showSetting = true;
}
};
});

$scope.interpreterSelectionListeners = {
accept: function(sourceItemHandleScope, destSortableScope) {return true;},
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
});

$scope.$on('$destroy', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}});
}

};
Expand Down
3 changes: 2 additions & 1 deletion zeppelin-web/test/spec/controllers/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('Controller: NotebookCtrl', function() {

var websocketMsgSrvMock = {
getNotebook: function() {},
listRevisionHistory: function() {}
listRevisionHistory: function() {},
getInterpreterBindings: function() {}
};

var baseUrlSrvMock = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ public static enum OP {
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;
Expand Down