Search in sources :

Example 11 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method saveInterpreterBindings.

public void saveInterpreterBindings(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    List<InterpreterSettingsList> settingList = new ArrayList<>();
    String noteId = (String) fromMessage.data.get("noteId");
    // use write lock, because defaultInterpreterGroup is overwritten
    getNotebook().processNote(noteId, note -> {
        if (note != null) {
            List<String> settingIdList = gson.fromJson(String.valueOf(fromMessage.data.get("selectedSettingIds")), new TypeToken<ArrayList<String>>() {
            }.getType());
            if (!settingIdList.isEmpty()) {
                note.setDefaultInterpreterGroup(settingIdList.get(0));
                getNotebook().saveNote(note, context.getAutheInfo());
            }
            List<InterpreterSetting> bindedSettings = note.getBindedInterpreterSettings(new ArrayList<>(context.getUserAndRoles()));
            for (InterpreterSetting setting : bindedSettings) {
                settingList.add(new InterpreterSettingsList(setting.getId(), setting.getName(), setting.getInterpreterInfos(), true));
            }
        }
        return null;
    });
    conn.send(serializeMessage(new Message(OP.INTERPRETER_BINDINGS).put("interpreterBindings", settingList)));
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) InterpreterSettingsList(org.apache.zeppelin.types.InterpreterSettingsList) TypeToken(com.google.gson.reflect.TypeToken) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) ArrayList(java.util.ArrayList)

Example 12 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method updateNoteAngularObject.

private void updateNoteAngularObject(String noteId, AngularObject angularObject, String interpreterGroupId) throws IOException {
    List<InterpreterSetting> intpSettings = getNotebook().processNote(noteId, note -> note.getBindedInterpreterSettings(new ArrayList<>(authorizationService.getOwners(note.getId()))));
    if (intpSettings.isEmpty()) {
        return;
    }
    connectionManager.broadcast(noteId, new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", angularObject).put("interpreterGroupId", interpreterGroupId).put("noteId", noteId).put("paragraphId", angularObject.getParagraphId()));
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) ArrayList(java.util.ArrayList)

Example 13 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method removeParagraph.

private void removeParagraph(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    final String paragraphId = (String) fromMessage.get("id");
    String noteId = connectionManager.getAssociatedNoteId(conn);
    getNotebookService().removeParagraph(noteId, paragraphId, context, new WebSocketServiceCallback<Paragraph>(conn) {

        @Override
        public void onSuccess(Paragraph p, ServiceContext context) throws IOException {
            super.onSuccess(p, context);
            connectionManager.broadcast(p.getNote().getId(), new Message(OP.PARAGRAPH_REMOVED).put("id", p.getId()));
        }
    });
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) IOException(java.io.IOException) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 14 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method moveParagraph.

private void moveParagraph(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    final String paragraphId = (String) fromMessage.get("id");
    final int newIndex = (int) Double.parseDouble(fromMessage.get("index").toString());
    String noteId = connectionManager.getAssociatedNoteId(conn);
    getNotebookService().moveParagraph(noteId, paragraphId, newIndex, context, new WebSocketServiceCallback<Paragraph>(conn) {

        @Override
        public void onSuccess(Paragraph result, ServiceContext context) throws IOException {
            super.onSuccess(result, context);
            connectionManager.broadcast(result.getNote().getId(), new Message(OP.PARAGRAPH_MOVED).put("id", paragraphId).put("index", newIndex));
        }
    });
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) IOException(java.io.IOException) ServerEndpoint(javax.websocket.server.ServerEndpoint) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 15 with Message

use of org.apache.zeppelin.common.Message in project zeppelin by apache.

the class NotebookServer method broadcastUpdateNoteJobInfo.

public void broadcastUpdateNoteJobInfo(Note note, long lastUpdateUnixTime) throws IOException {
    ServiceContext context = new ServiceContext(new AuthenticationInfo(), authorizationService.getOwners(note.getId()));
    getJobManagerService().getNoteJobInfoByUnixTime(lastUpdateUnixTime, context, new WebSocketServiceCallback<List<JobManagerService.NoteJobInfo>>(null) {

        @Override
        public void onSuccess(List<JobManagerService.NoteJobInfo> notesJobInfo, ServiceContext context) throws IOException {
            super.onSuccess(notesJobInfo, context);
            Map<String, Object> response = new HashMap<>();
            response.put("lastResponseUnixTime", System.currentTimeMillis());
            response.put("jobs", notesJobInfo);
            connectionManager.broadcast(JobManagerServiceType.JOB_MANAGER_PAGE.getKey(), new Message(OP.LIST_UPDATE_NOTE_JOBS).put("noteRunningJobs", response));
        }

        @Override
        public void onFailure(Exception ex, ServiceContext context) throws IOException {
            LOG.warn(ex.getMessage());
        }
    });
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) IOException(java.io.IOException) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) URISyntaxException(java.net.URISyntaxException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ServiceException(org.apache.zeppelin.interpreter.thrift.ServiceException) List(java.util.List) InterpreterSettingsList(org.apache.zeppelin.types.InterpreterSettingsList) ArrayList(java.util.ArrayList) JobManagerService(org.apache.zeppelin.service.JobManagerService) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

Message (org.apache.zeppelin.common.Message)49 OnMessage (javax.websocket.OnMessage)31 ClusterMessage (org.apache.zeppelin.cluster.event.ClusterMessage)31 IOException (java.io.IOException)18 ServiceContext (org.apache.zeppelin.service.ServiceContext)18 Paragraph (org.apache.zeppelin.notebook.Paragraph)12 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 AngularObject (org.apache.zeppelin.display.AngularObject)10 Test (org.junit.Test)10 Mockito.anyString (org.mockito.Mockito.anyString)10 UnknownHostException (java.net.UnknownHostException)8 TException (org.apache.thrift.TException)8 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)8 Note (org.apache.zeppelin.notebook.Note)8 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)7 HashMap (java.util.HashMap)6 List (java.util.List)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)6