Search in sources :

Example 1 with ClusterMessage

use of org.apache.zeppelin.cluster.event.ClusterMessage in project zeppelin by apache.

the class NotebookServer method onClusterEvent.

@Override
public void onClusterEvent(String msg) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("onClusterEvent : {}", msg);
    }
    ClusterMessage message = ClusterMessage.deserializeMessage(msg);
    Note note = null;
    Paragraph paragraph = null;
    Set<String> userAndRoles = null;
    Map<String, Paragraph> userParagraphMap = null;
    AuthenticationInfo authenticationInfo = null;
    for (Map.Entry<String, String> entry : message.getData().entrySet()) {
        String key = entry.getKey();
        String json = entry.getValue();
        if (StringUtils.equals(key, "AuthenticationInfo")) {
            authenticationInfo = AuthenticationInfo.fromJson(json);
        } else if (StringUtils.equals(key, "Note")) {
            try {
                note = Note.fromJson(null, json);
            } catch (IOException e) {
                LOG.warn("Fail to parse note json", e);
            }
        } else if (StringUtils.equals(key, "Paragraph")) {
            paragraph = Paragraph.fromJson(json);
        } else if (StringUtils.equals(key, "Set<String>")) {
            Gson gson = new Gson();
            userAndRoles = gson.fromJson(json, new TypeToken<Set<String>>() {
            }.getType());
        } else if (StringUtils.equals(key, "Map<String, Paragraph>")) {
            Gson gson = new Gson();
            userParagraphMap = gson.fromJson(json, new TypeToken<Map<String, Paragraph>>() {
            }.getType());
        } else {
            LOG.error("Unknown key:{}, json:{}!" + key, json);
        }
    }
    switch(message.clusterEvent) {
        case BROADCAST_NOTE:
            inlineBroadcastNote(note);
            break;
        case BROADCAST_NOTE_LIST:
            try {
                getNotebook().reloadAllNotes(authenticationInfo);
                inlineBroadcastNoteList();
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
            break;
        case BROADCAST_PARAGRAPH:
            inlineBroadcastParagraph(note, paragraph, message.getMsgId());
            break;
        case BROADCAST_PARAGRAPHS:
            inlineBroadcastParagraphs(userParagraphMap, message.getMsgId());
            break;
        case BROADCAST_NEW_PARAGRAPH:
            inlineBroadcastNewParagraph(note, paragraph);
            break;
        default:
            LOG.error("Unknown clusterEvent:{}, msg:{} ", message.clusterEvent, msg);
            break;
    }
}
Also used : Gson(com.google.gson.Gson) IOException(java.io.IOException) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with ClusterMessage

use of org.apache.zeppelin.cluster.event.ClusterMessage in project zeppelin by apache.

the class NotebookServer method broadcastClusterEvent.

// broadcast ClusterEvent
private void broadcastClusterEvent(ClusterEvent event, String msgId, Object... objects) {
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    if (!conf.isClusterMode()) {
        return;
    }
    ClusterMessage clusterMessage = new ClusterMessage(event);
    clusterMessage.setMsgId(msgId);
    for (Object object : objects) {
        String json;
        if (object instanceof AuthenticationInfo) {
            json = ((AuthenticationInfo) object).toJson();
            clusterMessage.put("AuthenticationInfo", json);
        } else if (object instanceof Note) {
            json = ((Note) object).toJson();
            clusterMessage.put("Note", json);
        } else if (object instanceof Paragraph) {
            json = ((Paragraph) object).toJson();
            clusterMessage.put("Paragraph", json);
        } else if (object instanceof Set) {
            Gson gson = new Gson();
            json = gson.toJson(object);
            clusterMessage.put("Set<String>", json);
        } else if (object instanceof Map) {
            Gson gson = new Gson();
            json = gson.toJson(object);
            clusterMessage.put("Map<String, Paragraph>", json);
        } else {
            LOG.error("Unknown object type!");
        }
    }
    String msg = ClusterMessage.serializeMessage(clusterMessage);
    ClusterManagerServer.getInstance(conf).broadcastClusterEvent(ClusterManagerServer.CLUSTER_NOTE_EVENT_TOPIC, msg);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) Note(org.apache.zeppelin.notebook.Note) Gson(com.google.gson.Gson) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 3 with ClusterMessage

use of org.apache.zeppelin.cluster.event.ClusterMessage in project zeppelin by apache.

the class ClusterAuthEventListenerTest method onClusterEvent.

@Override
public void onClusterEvent(String msg) {
    receiveMsg = msg;
    LOGGER.info("ClusterAuthEventListenerTest#onClusterEvent : {}", msg);
    ClusterMessage message = ClusterMessage.deserializeMessage(msg);
    String noteId = message.get("noteId");
    String user = message.get("user");
    String jsonSet = message.get("set");
    Gson gson = new Gson();
    Set<String> set = gson.fromJson(jsonSet, new TypeToken<Set<String>>() {
    }.getType());
    switch(message.clusterEvent) {
        case SET_READERS_PERMISSIONS:
        case SET_WRITERS_PERMISSIONS:
        case SET_OWNERS_PERMISSIONS:
        case SET_RUNNERS_PERMISSIONS:
            assertNotNull(set);
            assertNotNull(noteId);
            break;
        case CLEAR_PERMISSION:
            assertNotNull(noteId);
            break;
        case SET_ROLES:
            assertNotNull(user);
            break;
        default:
            receiveMsg = null;
            fail("Unknown clusterEvent : " + message.clusterEvent);
            break;
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage)

Example 4 with ClusterMessage

use of org.apache.zeppelin.cluster.event.ClusterMessage in project zeppelin by apache.

the class ClusterNoteEventListenerTest method onClusterEvent.

@Override
public void onClusterEvent(String msg) {
    receiveMsg = msg;
    LOGGER.debug("ClusterNoteEventListenerTest#onClusterEvent : {}", msg);
    ClusterMessage message = ClusterMessage.deserializeMessage(msg);
    Note note = null;
    Paragraph paragraph = null;
    Set<String> userAndRoles = null;
    Map<String, Paragraph> userParagraphMap = null;
    AuthenticationInfo authenticationInfo = null;
    for (Map.Entry<String, String> entry : message.getData().entrySet()) {
        String key = entry.getKey();
        String json = entry.getValue();
        if (key.equals("AuthenticationInfo")) {
            authenticationInfo = AuthenticationInfo.fromJson(json);
            LOGGER.debug(authenticationInfo.toJson());
        } else if (key.equals("Note")) {
            try {
                note = Note.fromJson(null, json);
            } catch (IOException e) {
                LOGGER.warn("Fail to parse note json", e);
            }
            LOGGER.debug(note.toJson());
        } else if (key.equals("Paragraph")) {
            paragraph = Paragraph.fromJson(json);
            LOGGER.debug(paragraph.toJson());
        } else if (key.equals("Set<String>")) {
            Gson gson = new Gson();
            userAndRoles = gson.fromJson(json, new TypeToken<Set<String>>() {
            }.getType());
            LOGGER.debug(userAndRoles.toString());
        } else if (key.equals("Map<String, Paragraph>")) {
            Gson gson = new Gson();
            userParagraphMap = gson.fromJson(json, new TypeToken<Map<String, Paragraph>>() {
            }.getType());
            LOGGER.debug(userParagraphMap.toString());
        } else {
            receiveMsg = null;
            fail("Unknown clusterEvent : " + message.clusterEvent);
        }
    }
}
Also used : Gson(com.google.gson.Gson) IOException(java.io.IOException) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) TypeToken(com.google.gson.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Map(java.util.Map)

Example 5 with ClusterMessage

use of org.apache.zeppelin.cluster.event.ClusterMessage in project zeppelin by apache.

the class InterpreterSettingManager method broadcastClusterEvent.

// broadcast cluster event
private void broadcastClusterEvent(ClusterEvent event, InterpreterSetting intpSetting) {
    if (!conf.isClusterMode()) {
        return;
    }
    String jsonIntpSetting = InterpreterSetting.toJson(intpSetting);
    ClusterMessage message = new ClusterMessage(event);
    message.put("intpSetting", jsonIntpSetting);
    String msg = ClusterMessage.serializeMessage(message);
    ClusterManagerServer.getInstance(conf).broadcastClusterEvent(CLUSTER_INTP_SETTING_EVENT_TOPIC, msg);
}
Also used : ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage)

Aggregations

ClusterMessage (org.apache.zeppelin.cluster.event.ClusterMessage)9 Gson (com.google.gson.Gson)6 TypeToken (com.google.gson.reflect.TypeToken)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Note (org.apache.zeppelin.notebook.Note)3 Paragraph (org.apache.zeppelin.notebook.Paragraph)3 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)3 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)1 Dependency (org.apache.zeppelin.dep.Dependency)1 AngularObject (org.apache.zeppelin.display.AngularObject)1 ManagedObject (org.eclipse.jetty.util.annotation.ManagedObject)1