Search in sources :

Example 1 with ServiceContext

use of org.apache.zeppelin.service.ServiceContext in project zeppelin by apache.

the class NotebookServer method completion.

private void completion(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = connectionManager.getAssociatedNoteId(conn);
    String paragraphId = (String) fromMessage.get("id");
    String buffer = (String) fromMessage.get("buf");
    int cursor = (int) Double.parseDouble(fromMessage.get("cursor").toString());
    getNotebookService().completion(noteId, paragraphId, buffer, cursor, context, new WebSocketServiceCallback<List<InterpreterCompletion>>(conn) {

        @Override
        public void onSuccess(List<InterpreterCompletion> completions, ServiceContext context) throws IOException {
            super.onSuccess(completions, context);
            Message resp = new Message(OP.COMPLETION_LIST).put("id", paragraphId);
            resp.put("completions", completions);
            conn.send(serializeMessage(resp));
        }

        @Override
        public void onFailure(Exception ex, ServiceContext context) throws IOException {
            super.onFailure(ex, context);
            Message resp = new Message(OP.COMPLETION_LIST).put("id", paragraphId);
            resp.put("completions", new ArrayList<>());
            conn.send(serializeMessage(resp));
        }
    });
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) ArrayList(java.util.ArrayList) List(java.util.List) InterpreterSettingsList(org.apache.zeppelin.types.InterpreterSettingsList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServerEndpoint(javax.websocket.server.ServerEndpoint) 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)

Example 2 with ServiceContext

use of org.apache.zeppelin.service.ServiceContext in project zeppelin by apache.

the class NotebookServer method getEditorSetting.

private void getEditorSetting(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String paragraphId = (String) fromMessage.get("paragraphId");
    String paragraphText = (String) fromMessage.get("paragraphText");
    String noteId = connectionManager.getAssociatedNoteId(conn);
    getNotebookService().getEditorSetting(noteId, paragraphText, context, new WebSocketServiceCallback<Map<String, Object>>(conn) {

        @Override
        public void onSuccess(Map<String, Object> settings, ServiceContext context) throws IOException {
            super.onSuccess(settings, context);
            Message resp = new Message(OP.EDITOR_SETTING);
            resp.put("paragraphId", paragraphId);
            resp.put("editor", settings);
            conn.send(serializeMessage(resp));
        }

        @Override
        public void onFailure(Exception ex, ServiceContext context) {
            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) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) 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)

Example 3 with ServiceContext

use of org.apache.zeppelin.service.ServiceContext in project zeppelin by apache.

the class NotebookServer method onParagraphRemove.

@Override
public void onParagraphRemove(Paragraph p) {
    try {
        ServiceContext context = new ServiceContext(new AuthenticationInfo(), authorizationService.getOwners(p.getNote().getId()));
        getJobManagerService().getNoteJobInfoByUnixTime(System.currentTimeMillis() - 5000, context, new JobManagerServiceCallback());
    } catch (IOException e) {
        LOG.warn("can not broadcast for job manager: {}", e.getMessage(), e);
    }
}
Also used : ServiceContext(org.apache.zeppelin.service.ServiceContext) IOException(java.io.IOException) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 4 with ServiceContext

use of org.apache.zeppelin.service.ServiceContext in project zeppelin by apache.

the class NotebookServer method getNoteByRevisionForCompare.

private void getNoteByRevisionForCompare(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("noteId");
    String revisionId = (String) fromMessage.get("revisionId");
    String position = (String) fromMessage.get("position");
    getNotebookService().getNoteByRevisionForCompare(noteId, revisionId, context, new WebSocketServiceCallback<Note>(conn) {

        @Override
        public void onSuccess(Note note, ServiceContext context) throws IOException {
            super.onSuccess(note, context);
            conn.send(serializeMessage(new Message(OP.NOTE_REVISION_FOR_COMPARE).put("noteId", noteId).put("revisionId", revisionId).put("position", position).put("note", note)));
        }
    });
}
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) Note(org.apache.zeppelin.notebook.Note) IOException(java.io.IOException)

Example 5 with ServiceContext

use of org.apache.zeppelin.service.ServiceContext 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)

Aggregations

ServiceContext (org.apache.zeppelin.service.ServiceContext)21 IOException (java.io.IOException)16 Message (org.apache.zeppelin.common.Message)15 OnMessage (javax.websocket.OnMessage)11 ClusterMessage (org.apache.zeppelin.cluster.event.ClusterMessage)11 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)7 Map (java.util.Map)6 URISyntaxException (java.net.URISyntaxException)5 UnknownHostException (java.net.UnknownHostException)5 HashMap (java.util.HashMap)5 TException (org.apache.thrift.TException)5 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)5 Paragraph (org.apache.zeppelin.notebook.Paragraph)5 ForbiddenException (org.apache.zeppelin.rest.exception.ForbiddenException)5 HashSet (java.util.HashSet)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AngularObject (org.apache.zeppelin.display.AngularObject)4 Note (org.apache.zeppelin.notebook.Note)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3