Search in sources :

Example 16 with AngularObject

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

the class Note method deleteAngularObject.

/**
 * Delete the note AngularObject.
 */
public void deleteAngularObject(String intpGroupId, String noteId, String paragraphId, String name) {
    if (angularObjects.containsKey(intpGroupId)) {
        // Delete existing AngularObject
        Iterator<AngularObject> iter = angularObjects.get(intpGroupId).iterator();
        while (iter.hasNext()) {
            String noteIdCandidate = "";
            String paragraphIdCandidate = "";
            String nameCandidate = "";
            Object object = iter.next();
            if (object instanceof AngularObject) {
                AngularObject ao = (AngularObject) object;
                noteIdCandidate = ao.getNoteId();
                paragraphIdCandidate = ao.getParagraphId();
                nameCandidate = ao.getName();
            } else if (object instanceof RemoteAngularObject) {
                RemoteAngularObject rao = (RemoteAngularObject) object;
                noteIdCandidate = rao.getNoteId();
                paragraphIdCandidate = rao.getParagraphId();
                nameCandidate = rao.getName();
            } else {
                continue;
            }
            if (StringUtils.equals(noteId, noteIdCandidate) && StringUtils.equals(paragraphId, paragraphIdCandidate) && StringUtils.equals(name, nameCandidate)) {
                iter.remove();
            }
        }
    }
}
Also used : RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) AngularObject(org.apache.zeppelin.display.AngularObject)

Example 17 with AngularObject

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

the class Notebook method loadNoteFromRepo.

@SuppressWarnings("rawtypes")
public Note loadNoteFromRepo(String id, AuthenticationInfo subject) {
    Note note = null;
    try {
        // note can be safely returned here, because it's just broadcasted in json later on
        note = processNote(id, n -> n);
    } catch (IOException e) {
        LOGGER.error("Fail to get note: {}", id, e);
        return null;
    }
    if (note == null) {
        return null;
    }
    // Manually inject ALL dependencies, as DI constructor was NOT used
    note.setCredentials(this.credentials);
    note.setInterpreterFactory(replFactory);
    note.setInterpreterSettingManager(interpreterSettingManager);
    note.setParagraphJobListener(this.paragraphJobListener);
    note.setCronSupported(getConf());
    if (note.getDefaultInterpreterGroup() == null) {
        note.setDefaultInterpreterGroup(conf.getString(ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT));
    }
    Map<String, SnapshotAngularObject> angularObjectSnapshot = new HashMap<>();
    // restore angular object --------------
    Date lastUpdatedDate = new Date(0);
    for (Paragraph p : note.getParagraphs()) {
        p.setNote(note);
        if (p.getDateFinished() != null && lastUpdatedDate.before(p.getDateFinished())) {
            lastUpdatedDate = p.getDateFinished();
        }
    }
    Map<String, List<AngularObject>> savedObjects = note.getAngularObjects();
    if (savedObjects != null) {
        for (Entry<String, List<AngularObject>> intpGroupNameEntry : savedObjects.entrySet()) {
            String intpGroupName = intpGroupNameEntry.getKey();
            List<AngularObject> objectList = intpGroupNameEntry.getValue();
            for (AngularObject object : objectList) {
                SnapshotAngularObject snapshot = angularObjectSnapshot.get(object.getName());
                if (snapshot == null || snapshot.getLastUpdate().before(lastUpdatedDate)) {
                    angularObjectSnapshot.put(object.getName(), new SnapshotAngularObject(intpGroupName, object, lastUpdatedDate));
                }
            }
        }
    }
    note.setNoteEventListeners(this.noteEventListeners);
    for (Entry<String, SnapshotAngularObject> angularObjectSnapshotEntry : angularObjectSnapshot.entrySet()) {
        String name = angularObjectSnapshotEntry.getKey();
        SnapshotAngularObject snapshot = angularObjectSnapshotEntry.getValue();
        List<InterpreterSetting> settings = interpreterSettingManager.get();
        for (InterpreterSetting setting : settings) {
            InterpreterGroup intpGroup = setting.getInterpreterGroup(note.getExecutionContext());
            if (intpGroup != null && intpGroup.getId().equals(snapshot.getIntpGroupId())) {
                AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
                String noteId = snapshot.getAngularObject().getNoteId();
                String paragraphId = snapshot.getAngularObject().getParagraphId();
                // at this point, remote interpreter process is not created.
                // so does not make sense add it to the remote.
                // 
                // therefore instead of addAndNotifyRemoteProcess(), need to use add()
                // that results add angularObject only in ZeppelinServer side not remoteProcessSide
                registry.add(name, snapshot.getAngularObject().get(), noteId, paragraphId);
            }
        }
    }
    return note;
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) NoteNode(org.apache.zeppelin.notebook.NoteManager.NoteNode) Date(java.util.Date) NotebookRepoSync(org.apache.zeppelin.notebook.repo.NotebookRepoSync) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) NotebookRepo(org.apache.zeppelin.notebook.repo.NotebookRepo) SchedulerException(org.quartz.SchedulerException) Map(java.util.Map) ConfVars(org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars) Folder(org.apache.zeppelin.notebook.NoteManager.Folder) Job(org.apache.zeppelin.scheduler.Job) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) NotebookRepoWithVersionControl(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) LinkedList(java.util.LinkedList) AngularObject(org.apache.zeppelin.display.AngularObject) Revision(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) Credentials(org.apache.zeppelin.user.Credentials) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) Collectors(java.util.stream.Collectors) List(java.util.List) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) Entry(java.util.Map.Entry) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException) Date(java.util.Date) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 18 with AngularObject

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

the class Paragraph method extractVariablesFromAngularRegistry.

String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) {
    final String noteId = this.getNote().getId();
    final String paragraphId = this.getId();
    final Set<String> keys = new HashSet<>(inputs.keySet());
    for (String varName : keys) {
        final AngularObject paragraphScoped = angularRegistry.get(varName, noteId, paragraphId);
        final AngularObject noteScoped = angularRegistry.get(varName, noteId, null);
        final AngularObject angularObject = paragraphScoped != null ? paragraphScoped : noteScoped;
        if (angularObject != null) {
            inputs.remove(varName);
            final String pattern = "[$][{]\\s*" + varName + "\\s*(?:=[^}]+)?[}]";
            scriptBody = scriptBody.replaceAll(pattern, angularObject.get().toString());
        }
    }
    return scriptBody;
}
Also used : AngularObject(org.apache.zeppelin.display.AngularObject) HashSet(java.util.HashSet)

Example 19 with AngularObject

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

the class Note method addOrUpdateAngularObject.

/**
 * Add or update the note AngularObject.
 */
public void addOrUpdateAngularObject(String intpGroupId, AngularObject angularObject) {
    List<AngularObject> angularObjectList;
    if (!angularObjects.containsKey(intpGroupId)) {
        angularObjectList = new ArrayList<>();
        angularObjects.put(intpGroupId, angularObjectList);
    } else {
        angularObjectList = angularObjects.get(intpGroupId);
        // Delete existing AngularObject
        Iterator<AngularObject> iter = angularObjectList.iterator();
        while (iter.hasNext()) {
            String noteId = "";
            String paragraphId = "";
            String name = "";
            Object object = iter.next();
            if (object instanceof AngularObject) {
                AngularObject ao = (AngularObject) object;
                noteId = ao.getNoteId();
                paragraphId = ao.getParagraphId();
                name = ao.getName();
            } else if (object instanceof RemoteAngularObject) {
                RemoteAngularObject rao = (RemoteAngularObject) object;
                noteId = rao.getNoteId();
                paragraphId = rao.getParagraphId();
                name = rao.getName();
            } else {
                continue;
            }
            if (StringUtils.equals(noteId, angularObject.getNoteId()) && StringUtils.equals(paragraphId, angularObject.getParagraphId()) && StringUtils.equals(name, angularObject.getName())) {
                iter.remove();
            }
        }
    }
    angularObjectList.add(angularObject);
}
Also used : RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) AngularObject(org.apache.zeppelin.display.AngularObject)

Example 20 with AngularObject

use of org.apache.zeppelin.display.AngularObject in project SSM by Intel-bigdata.

the class RemoteInterpreter method pushAngularObjectRegistryToRemote.

/**
 * Push local angular object registry to
 * remote interpreter. This method should be
 * call ONLY inside the init() method
 */
void pushAngularObjectRegistryToRemote(Client client) throws TException {
    final AngularObjectRegistry angularObjectRegistry = this.getInterpreterGroup().getAngularObjectRegistry();
    if (angularObjectRegistry != null && angularObjectRegistry.getRegistry() != null) {
        final Map<String, Map<String, AngularObject>> registry = angularObjectRegistry.getRegistry();
        logger.info("Push local angular object registry from ZeppelinServer to" + " remote interpreter group {}", this.getInterpreterGroup().getId());
        final java.lang.reflect.Type registryType = new TypeToken<Map<String, Map<String, AngularObject>>>() {
        }.getType();
        Gson gson = new Gson();
        client.angularRegistryPush(gson.toJson(registry, registryType));
    }
}
Also used : Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

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