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;
}
}
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);
}
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;
}
}
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);
}
}
}
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);
}
Aggregations