Search in sources :

Example 26 with AngularObject

use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.

the class NotebookServer method pushAngularObjectToLocalRepo.

private void pushAngularObjectToLocalRepo(String noteId, String paragraphId, String varName, Object varValue, AngularObjectRegistry registry, String interpreterGroupId, NotebookSocket conn) {
    AngularObject angularObject = registry.get(varName, noteId, paragraphId);
    if (angularObject == null) {
        angularObject = registry.add(varName, varValue, noteId, paragraphId);
    } else {
        angularObject.set(varValue, true);
    }
    this.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", angularObject).put("interpreterGroupId", interpreterGroupId).put("noteId", noteId).put("paragraphId", paragraphId), conn);
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) AngularObject(org.apache.zeppelin.display.AngularObject)

Example 27 with AngularObject

use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.

the class NotebookService method updateAngularObject.

public void updateAngularObject(String noteId, String paragraphId, String interpreterGroupId, String varName, Object varValue, ServiceContext context, ServiceCallback<AngularObject> callback) throws IOException {
    String user = context.getAutheInfo().getUser();
    AngularObject ao = null;
    boolean global = false;
    // propagate change to (Remote) AngularObjectRegistry
    List<InterpreterSetting> settings = notebook.processNote(noteId, note -> {
        if (note == null) {
            return Collections.emptyList();
        } else {
            return note.getBindedInterpreterSettings(new ArrayList<>(context.getUserAndRoles()));
        }
    });
    for (InterpreterSetting setting : settings) {
        if (setting.getInterpreterGroup(user, noteId) == null) {
            continue;
        }
        if (interpreterGroupId.equals(setting.getInterpreterGroup(user, noteId).getId())) {
            AngularObjectRegistry angularObjectRegistry = setting.getInterpreterGroup(user, noteId).getAngularObjectRegistry();
            // first trying to get local registry
            ao = angularObjectRegistry.get(varName, noteId, paragraphId);
            if (ao == null) {
                // then try notebook scope registry
                ao = angularObjectRegistry.get(varName, noteId, null);
                if (ao == null) {
                    // then try global scope registry
                    ao = angularObjectRegistry.get(varName, null, null);
                    if (ao == null) {
                        LOGGER.warn("Object {} is not binded", varName);
                    } else {
                        // path from client -> server
                        ao.set(varValue, false);
                        global = true;
                    }
                } else {
                    // path from client -> server
                    ao.set(varValue, false);
                    global = false;
                }
            } else {
                ao.set(varValue, false);
                global = false;
            }
            break;
        }
    }
    callback.onSuccess(ao, context);
}
Also used : InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 28 with AngularObject

use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.

the class NotebookServer method angularObjectClientBind.

/**
 * 1. Push the given Angular variable to the target interpreter angular
 * registry given a noteId and a paragraph id.
 * 2. Save AngularObject to note.
 */
protected void angularObjectClientBind(NotebookSocket conn, Message fromMessage) throws Exception {
    String noteId = fromMessage.getType("noteId");
    String varName = fromMessage.getType("name");
    Object varValue = fromMessage.get("value");
    String paragraphId = fromMessage.getType("paragraphId");
    if (paragraphId == null) {
        throw new IllegalArgumentException("target paragraph not specified for " + "angular value bind");
    }
    getNotebook().processNote(noteId, note -> {
        if (note != null) {
            InterpreterGroup interpreterGroup;
            try {
                interpreterGroup = findInterpreterGroupForParagraph(note, paragraphId);
            } catch (Exception e) {
                LOG.error("No interpreter group found for noteId {} and paragraphId {}", noteId, paragraphId, e);
                return null;
            }
            final RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry();
            AngularObject ao = pushAngularObjectToRemoteRegistry(noteId, paragraphId, varName, varValue, registry, interpreterGroup.getId(), conn);
            note.addOrUpdateAngularObject(interpreterGroup.getId(), ao);
        }
        return null;
    });
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) 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)

Example 29 with AngularObject

use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.

the class NotebookServer method updateAngularObjectRegistry.

/**
 * Update the AngularObject object in the note to InterpreterGroup and AngularObjectRegistry.
 */
private void updateAngularObjectRegistry(NotebookSocket conn, Note note) {
    for (Paragraph paragraph : note.getParagraphs()) {
        InterpreterGroup interpreterGroup = null;
        try {
            interpreterGroup = findInterpreterGroupForParagraph(note, paragraph.getId());
        } catch (Exception e) {
            LOG.warn(e.getMessage(), e);
        }
        if (null == interpreterGroup) {
            return;
        }
        RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry();
        List<AngularObject> angularObjects = note.getAngularObjects(interpreterGroup.getId());
        for (AngularObject ao : angularObjects) {
            if (StringUtils.equals(ao.getNoteId(), note.getId()) && StringUtils.equals(ao.getParagraphId(), paragraph.getId())) {
                pushAngularObjectToRemoteRegistry(ao.getNoteId(), ao.getParagraphId(), ao.getName(), ao.get(), registry, interpreterGroup.getId(), conn);
            }
        }
    }
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObject(org.apache.zeppelin.display.AngularObject) 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) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 30 with AngularObject

use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.

the class BaseInterpreterTest method getIntpContext.

protected InterpreterContext getIntpContext() {
    final AtomicInteger onAdd = new AtomicInteger(0);
    final AtomicInteger onUpdate = new AtomicInteger(0);
    final AtomicInteger onRemove = new AtomicInteger(0);
    AngularObjectRegistry registry = new AngularObjectRegistry("intpId", new AngularObjectRegistryListener() {

        @Override
        public void onAddAngularObject(String interpreterGroupId, AngularObject angularObject) {
            onAdd.incrementAndGet();
        }

        @Override
        public void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject) {
            onUpdate.incrementAndGet();
        }

        @Override
        public void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject) {
            onRemove.incrementAndGet();
        }
    });
    AuthenticationInfo authenticationInfo = new AuthenticationInfo("user");
    return InterpreterContext.builder().setNoteId("noteId").setNoteName("noteName").setParagraphId("paragraphId").setAuthenticationInfo(authenticationInfo).setAngularObjectRegistry(registry).setInterpreterOut(new InterpreterOutput()).setIntpEventClient(mock(RemoteInterpreterEventClient.class)).build();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObjectRegistryListener(org.apache.zeppelin.display.AngularObjectRegistryListener) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Aggregations

AngularObject (org.apache.zeppelin.display.AngularObject)38 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)21 IOException (java.io.IOException)12 Map (java.util.Map)11 TException (org.apache.thrift.TException)11 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)10 List (java.util.List)8 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)8 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)8 UnknownHostException (java.net.UnknownHostException)7 HashMap (java.util.HashMap)7 Message (org.apache.zeppelin.common.Message)7 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)7 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)5 Arrays (java.util.Arrays)4 LinkedList (java.util.LinkedList)4 OP (org.apache.zeppelin.common.Message.OP)4