Search in sources :

Example 6 with ClusterMessage

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

the class AuthorizationService method broadcastClusterEvent.

// broadcast cluster event
private void broadcastClusterEvent(ClusterEvent event, String noteId, String user, Set<String> set) {
    if (!conf.isClusterMode()) {
        return;
    }
    ClusterMessage message = new ClusterMessage(event);
    message.put("noteId", noteId);
    message.put("user", user);
    Gson gson = new Gson();
    String json = gson.toJson(set, new TypeToken<Set<String>>() {
    }.getType());
    message.put("set", json);
    String msg = ClusterMessage.serializeMessage(message);
    ClusterManagerServer.getInstance(conf).broadcastClusterEvent(ClusterManagerServer.CLUSTER_AUTH_EVENT_TOPIC, msg);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage)

Example 7 with ClusterMessage

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

the class AuthorizationService method onClusterEvent.

@Override
public void onClusterEvent(String msg) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("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());
    try {
        switch(message.clusterEvent) {
            case SET_READERS_PERMISSIONS:
                setReaders(noteId, set, false);
                break;
            case SET_WRITERS_PERMISSIONS:
                setWriters(noteId, set, false);
                break;
            case SET_OWNERS_PERMISSIONS:
                setOwners(noteId, set, false);
                break;
            case SET_RUNNERS_PERMISSIONS:
                setRunners(noteId, set, false);
                break;
            case SET_ROLES:
                setRoles(user, set, false);
                break;
            case CLEAR_PERMISSION:
                clearPermission(noteId, false);
                break;
            default:
                LOGGER.error("Unknown clusterEvent:{}, msg:{} ", message.clusterEvent, msg);
                break;
        }
    } catch (IOException e) {
        LOGGER.warn("Fail to broadcast msg", e);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) IOException(java.io.IOException) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage)

Example 8 with ClusterMessage

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

the class InterpreterSettingManager method onClusterEvent.

@Override
public void onClusterEvent(String msg) {
    LOGGER.debug("onClusterEvent : {}", msg);
    try {
        ClusterMessage message = ClusterMessage.deserializeMessage(msg);
        String jsonIntpSetting = message.get("intpSetting");
        InterpreterSetting intpSetting = InterpreterSetting.fromJson(jsonIntpSetting);
        String id = intpSetting.getId();
        String name = intpSetting.getName();
        String group = intpSetting.getGroup();
        InterpreterOption option = intpSetting.getOption();
        HashMap<String, InterpreterProperty> properties = (HashMap<String, InterpreterProperty>) InterpreterSetting.convertInterpreterProperties(intpSetting.getProperties());
        List<Dependency> dependencies = intpSetting.getDependencies();
        switch(message.clusterEvent) {
            case CREATE_INTP_SETTING:
                inlineCreateNewSetting(name, group, dependencies, option, properties);
                break;
            case UPDATE_INTP_SETTING:
                inlineSetPropertyAndRestart(id, option, properties, dependencies, false);
                break;
            case DELETE_INTP_SETTING:
                inlineRemove(id, false);
                break;
            default:
                LOGGER.error("Unknown clusterEvent:{}, msg:{} ", message.clusterEvent, msg);
                break;
        }
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterpreterException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Dependency(org.apache.zeppelin.dep.Dependency) IOException(java.io.IOException) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage)

Example 9 with ClusterMessage

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

the class ClusterIntpSettingEventListenerTest method onClusterEvent.

@Override
public void onClusterEvent(String msg) {
    receiveMsg = msg;
    LOGGER.info("ClusterIntpSettingEventListenerTest#onClusterEvent : {}", msg);
    ClusterMessage message = ClusterMessage.deserializeMessage(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