Search in sources :

Example 46 with Message

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

the class NotebookServer method onLoad.

@Override
public void onLoad(String noteId, String paragraphId, String appId, HeliumPackage pkg) {
    Message msg = new Message(OP.APP_LOAD).put("noteId", noteId).put("paragraphId", paragraphId).put("appId", appId).put("pkg", pkg);
    connectionManager.broadcast(noteId, msg);
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message)

Example 47 with Message

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

the class NotebookServer method angularObjectUpdated.

/**
 * 1. When angular object updated from client.
 * 2. Save AngularObject to note.
 *
 * @param conn        the web socket.
 * @param fromMessage the message.
 */
private void angularObjectUpdated(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("noteId");
    String paragraphId = (String) fromMessage.get("paragraphId");
    String interpreterGroupId = (String) fromMessage.get("interpreterGroupId");
    String varName = (String) fromMessage.get("name");
    Object varValue = fromMessage.get("value");
    String user = fromMessage.principal;
    getNotebookService().updateAngularObject(noteId, paragraphId, interpreterGroupId, varName, varValue, context, new WebSocketServiceCallback<AngularObject>(conn) {

        @Override
        public void onSuccess(AngularObject ao, ServiceContext context) throws IOException {
            super.onSuccess(ao, context);
            connectionManager.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao).put("interpreterGroupId", interpreterGroupId).put("noteId", noteId).put("paragraphId", ao.getParagraphId()), conn);
            getNotebook().processNote(noteId, note -> {
                note.addOrUpdateAngularObject(interpreterGroupId, ao);
                return null;
            });
        }
    });
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) TestUtils(org.apache.zeppelin.utils.TestUtils) Arrays(java.util.Arrays) TypeToken(com.google.gson.reflect.TypeToken) Provider(javax.inject.Provider) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) OnMessage(javax.websocket.OnMessage) GUI(org.apache.zeppelin.display.GUI) LoggerFactory(org.slf4j.LoggerFactory) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) StringUtils(org.apache.commons.lang3.StringUtils) TicketContainer(org.apache.zeppelin.ticket.TicketContainer) GsonBuilder(com.google.gson.GsonBuilder) ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute) ServiceContext(org.apache.zeppelin.service.ServiceContext) HeliumPackage(org.apache.zeppelin.helium.HeliumPackage) ParagraphInfo(org.apache.zeppelin.interpreter.thrift.ParagraphInfo) Gson(com.google.gson.Gson) Map(java.util.Map) ClusterEvent(org.apache.zeppelin.cluster.event.ClusterEvent) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) ParagraphJobListener(org.apache.zeppelin.notebook.ParagraphJobListener) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) Revision(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision) Session(javax.websocket.Session) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) NoteInfo(org.apache.zeppelin.notebook.NoteInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) JupyterUtil(org.apache.zeppelin.jupyter.JupyterUtil) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) ServerEndpoint(javax.websocket.server.ServerEndpoint) Executors(java.util.concurrent.Executors) ClusterManagerServer(org.apache.zeppelin.cluster.ClusterManagerServer) JobManagerService(org.apache.zeppelin.service.JobManagerService) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) List(java.util.List) Type(java.lang.reflect.Type) Status(org.apache.zeppelin.scheduler.Job.Status) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) MSG_ID_NOT_DEFINED(org.apache.zeppelin.common.Message.MSG_ID_NOT_DEFINED) RemoteInterpreterProcessListener(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener) CloseReason(javax.websocket.CloseReason) ClusterEventListener(org.apache.zeppelin.cluster.event.ClusterEventListener) Input(org.apache.zeppelin.display.Input) InterpreterSettingsList(org.apache.zeppelin.types.InterpreterSettingsList) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) OnOpen(javax.websocket.OnOpen) AngularObjectRegistryListener(org.apache.zeppelin.display.AngularObjectRegistryListener) IdHashes(org.apache.zeppelin.util.IdHashes) OnClose(javax.websocket.OnClose) Message(org.apache.zeppelin.common.Message) ExecutorService(java.util.concurrent.ExecutorService) OP(org.apache.zeppelin.common.Message.OP) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) NoteEventListener(org.apache.zeppelin.notebook.NoteEventListener) Paragraph(org.apache.zeppelin.notebook.Paragraph) CorsUtils(org.apache.zeppelin.utils.CorsUtils) NotebookService(org.apache.zeppelin.service.NotebookService) Logger(org.slf4j.Logger) ApplicationEventListener(org.apache.zeppelin.helium.ApplicationEventListener) SimpleServiceCallback(org.apache.zeppelin.service.SimpleServiceCallback) EndpointConfig(javax.websocket.EndpointConfig) Note(org.apache.zeppelin.notebook.Note) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Notebook(org.apache.zeppelin.notebook.Notebook) ServiceException(org.apache.zeppelin.interpreter.thrift.ServiceException) InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) ZEPPELIN_ALLOWED_ORIGINS(org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars.ZEPPELIN_ALLOWED_ORIGINS) ConfigurationService(org.apache.zeppelin.service.ConfigurationService) 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) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException)

Example 48 with Message

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

the class NotebookServer method getInterpreterBindings.

public void getInterpreterBindings(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    List<InterpreterSettingsList> settingList = new ArrayList<>();
    String noteId = (String) fromMessage.data.get("noteId");
    getNotebook().processNote(noteId, note -> {
        if (note != null) {
            List<InterpreterSetting> bindedSettings = note.getBindedInterpreterSettings(new ArrayList<>(context.getUserAndRoles()));
            for (InterpreterSetting setting : bindedSettings) {
                settingList.add(new InterpreterSettingsList(setting.getId(), setting.getName(), setting.getInterpreterInfos(), true));
            }
        }
        conn.send(serializeMessage(new Message(OP.INTERPRETER_BINDINGS).put("interpreterBindings", settingList)));
        return null;
    });
}
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) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) ArrayList(java.util.ArrayList)

Example 49 with Message

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

the class InterpreterRestApi method installInterpreter.

/**
 * Install interpreter
 */
@POST
@Path("install")
@ZeppelinApi
public Response installInterpreter(@NotNull String message) {
    LOGGER.info("Install interpreter: {}", message);
    InterpreterInstallationRequest request = InterpreterInstallationRequest.fromJson(message);
    try {
        interpreterService.installInterpreter(request, new SimpleServiceCallback<String>() {

            @Override
            public void onStart(String message, ServiceContext context) {
                Message m = new Message(OP.INTERPRETER_INSTALL_STARTED);
                Map<String, Object> data = new HashMap<>();
                data.put("result", "Starting");
                data.put("message", message);
                m.data = data;
                notebookServer.broadcast(m);
            }

            @Override
            public void onSuccess(String message, ServiceContext context) {
                Message m = new Message(OP.INTERPRETER_INSTALL_RESULT);
                Map<String, Object> data = new HashMap<>();
                data.put("result", "Succeed");
                data.put("message", message);
                m.data = data;
                notebookServer.broadcast(m);
            }

            @Override
            public void onFailure(Exception ex, ServiceContext context) {
                Message m = new Message(OP.INTERPRETER_INSTALL_RESULT);
                Map<String, Object> data = new HashMap<>();
                data.put("result", "Failed");
                data.put("message", ex.getMessage());
                m.data = data;
                notebookServer.broadcast(m);
            }
        });
    } catch (Throwable t) {
        return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, t.getMessage()).build();
    }
    return new JsonResponse<>(Status.OK).build();
}
Also used : InterpreterInstallationRequest(org.apache.zeppelin.rest.message.InterpreterInstallationRequest) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) HashMap(java.util.HashMap) Map(java.util.Map) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) IOException(java.io.IOException) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

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