Search in sources :

Example 6 with ServiceContext

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

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

the class NotebookServer method insertParagraph.

private String insertParagraph(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    final int index = (int) Double.parseDouble(fromMessage.get("index").toString());
    String noteId = connectionManager.getAssociatedNoteId(conn);
    Map<String, Object> config;
    if (fromMessage.get("config") != null) {
        config = (Map<String, Object>) fromMessage.get("config");
    } else {
        config = new HashMap<>();
    }
    Paragraph newPara = getNotebookService().insertParagraph(noteId, index, config, context, new WebSocketServiceCallback<Paragraph>(conn) {

        @Override
        public void onSuccess(Paragraph p, ServiceContext context) throws IOException {
            super.onSuccess(p, context);
            broadcastNewParagraph(p.getNote(), p);
        }
    });
    return newPara.getId();
}
Also used : ServiceContext(org.apache.zeppelin.service.ServiceContext) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException) ServerEndpoint(javax.websocket.server.ServerEndpoint) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 8 with ServiceContext

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

Example 9 with ServiceContext

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

the class NotebookServer method broadcastSpellExecution.

private void broadcastSpellExecution(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = connectionManager.getAssociatedNoteId(conn);
    getNotebookService().spell(noteId, fromMessage, context, new WebSocketServiceCallback<Paragraph>(conn) {

        @Override
        public void onSuccess(Paragraph p, ServiceContext context) throws IOException {
            super.onSuccess(p, context);
            // broadcast to other clients only
            connectionManager.broadcastExcept(p.getNote().getId(), new Message(OP.RUN_PARAGRAPH_USING_SPELL).put("paragraph", p), conn);
        }
    });
}
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 10 with ServiceContext

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

the class NotebookServer method updateNote.

private void updateNote(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("id");
    String name = (String) fromMessage.get("name");
    Map<String, Object> config = (Map<String, Object>) fromMessage.get("config");
    if (noteId == null) {
        return;
    }
    if (config == null) {
        return;
    }
    getNotebookService().updateNote(noteId, name, config, context, new WebSocketServiceCallback<Note>(conn) {

        @Override
        public void onSuccess(Note note, ServiceContext context) throws IOException {
            connectionManager.broadcast(note.getId(), new Message(OP.NOTE_UPDATED).put("name", name).put("config", config).put("info", note.getInfo()));
            broadcastNoteList(context.getAutheInfo(), context.getUserAndRoles());
        }
    });
}
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) 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)

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