Search in sources :

Example 6 with InterpreterNotFoundException

use of org.apache.zeppelin.interpreter.InterpreterNotFoundException in project zeppelin by apache.

the class Paragraph method completion.

public List<InterpreterCompletion> completion(String buffer, int cursor) {
    setText(buffer);
    try {
        this.interpreter = getBindedInterpreter();
    } catch (InterpreterNotFoundException e) {
        LOGGER.debug("Unable to get completion because there's no interpreter bind to it", e);
        return new ArrayList<>();
    }
    cursor = calculateCursorPosition(buffer, cursor);
    InterpreterContext interpreterContext = getInterpreterContext();
    try {
        return this.interpreter.completion(this.scriptText, cursor, interpreterContext);
    } catch (InterpreterException e) {
        LOGGER.warn("Fail to get completion", e);
        return new ArrayList<>();
    }
}
Also used : InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext)

Example 7 with InterpreterNotFoundException

use of org.apache.zeppelin.interpreter.InterpreterNotFoundException in project zeppelin by apache.

the class Paragraph method recover.

public void recover() {
    try {
        LOGGER.info("Recovering paragraph: {}", getId());
        this.interpreter = getBindedInterpreter();
        InterpreterSetting interpreterSetting = ((ManagedInterpreterGroup) interpreter.getInterpreterGroup()).getInterpreterSetting();
        Map<String, Object> config = interpreterSetting.getConfig(interpreter.getClassName());
        mergeConfig(config);
        if (shouldSkipRunParagraph()) {
            LOGGER.info("Skip to run blank paragraph. {}", getId());
            setStatus(Job.Status.FINISHED);
            return;
        }
        setStatus(Status.READY);
        localProperties.put("isRecover", "true");
        for (List<Interpreter> sessions : this.interpreter.getInterpreterGroup().values()) {
            for (Interpreter intp : sessions) {
                // exclude ConfInterpreter
                if (intp instanceof RemoteInterpreter) {
                    ((RemoteInterpreter) intp).setOpened(true);
                }
            }
        }
        if (getConfig().get("enabled") == null || (Boolean) getConfig().get("enabled")) {
            setAuthenticationInfo(getAuthenticationInfo());
            interpreter.getScheduler().submit(this);
        }
    } catch (InterpreterNotFoundException e) {
        InterpreterResult intpResult = new InterpreterResult(InterpreterResult.Code.ERROR, String.format("Interpreter %s not found", this.intpText));
        setReturn(intpResult, e);
        setStatus(Job.Status.ERROR);
    } catch (Throwable e) {
        InterpreterResult intpResult = new InterpreterResult(InterpreterResult.Code.ERROR, "Unexpected exception: " + ExceptionUtils.getStackTrace(e));
        setReturn(intpResult, e);
        setStatus(Job.Status.ERROR);
    }
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) AngularObject(org.apache.zeppelin.display.AngularObject) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter)

Example 8 with InterpreterNotFoundException

use of org.apache.zeppelin.interpreter.InterpreterNotFoundException in project zeppelin by apache.

the class Note method getBindedInterpreterSettings.

public List<InterpreterSetting> getBindedInterpreterSettings(List<String> userAndRoles) {
    // use LinkedHashSet because order matters, the first one represent the default interpreter setting.
    Set<InterpreterSetting> settings = new LinkedHashSet<>();
    // add the default interpreter group
    InterpreterSetting defaultIntpSetting = interpreterSettingManager.getByName(getDefaultInterpreterGroup());
    if (defaultIntpSetting != null) {
        settings.add(defaultIntpSetting);
    }
    // add the interpreter setting with the same group of default interpreter group
    if (defaultIntpSetting != null) {
        for (InterpreterSetting intpSetting : interpreterSettingManager.get()) {
            if (intpSetting.getGroup().equals(defaultIntpSetting.getGroup())) {
                if (intpSetting.isUserAuthorized(userAndRoles)) {
                    settings.add(intpSetting);
                }
            }
        }
    }
    // add interpreter group used by each paragraph
    for (Paragraph p : getParagraphs()) {
        try {
            Interpreter intp = p.getBindedInterpreter();
            InterpreterSetting interpreterSetting = ((ManagedInterpreterGroup) intp.getInterpreterGroup()).getInterpreterSetting();
            if (interpreterSetting.isUserAuthorized(userAndRoles)) {
                settings.add(interpreterSetting);
            }
        } catch (InterpreterNotFoundException e) {
        // ignore this
        }
    }
    return new ArrayList<>(settings);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup)

Example 9 with InterpreterNotFoundException

use of org.apache.zeppelin.interpreter.InterpreterNotFoundException in project zeppelin by apache.

the class ZeppelinSparkClusterTest method testAngularObjects.

@Test
public void testAngularObjects() throws IOException, InterpreterNotFoundException {
    assumeTrue("Hadoop version mismatch, skip test", isHadoopVersionMatch());
    String noteId = null;
    try {
        noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous);
        TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
            Paragraph p1 = note.addNewParagraph(anonymous);
            // add local angular object
            p1.setText("%spark z.angularBind(\"name\", \"world\")");
            note.run(p1.getId(), true);
            assertEquals(Status.FINISHED, p1.getStatus());
            // angular object is saved to InterpreterGroup's AngularObjectRegistry
            List<AngularObject> angularObjects;
            try {
                angularObjects = p1.getBindedInterpreter().getInterpreterGroup().getAngularObjectRegistry().getAll(note.getId(), null);
                assertEquals(1, angularObjects.size());
                assertEquals("name", angularObjects.get(0).getName());
                assertEquals("world", angularObjects.get(0).get());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            // angular object is saved to note as well.
            try {
                angularObjects = note.getAngularObjects(p1.getBindedInterpreter().getInterpreterGroup().getId());
                assertEquals(1, angularObjects.size());
                assertEquals("name", angularObjects.get(0).getName());
                assertEquals("world", angularObjects.get(0).get());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            // remove local angular object
            Paragraph p2 = note.addNewParagraph(anonymous);
            p2.setText("%spark z.angularUnbind(\"name\")");
            note.run(p2.getId(), true);
            assertEquals(Status.FINISHED, p2.getStatus());
            try {
                angularObjects = p1.getBindedInterpreter().getInterpreterGroup().getAngularObjectRegistry().getAll(note.getId(), null);
                assertEquals(0, angularObjects.size());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            try {
                angularObjects = note.getAngularObjects(p1.getBindedInterpreter().getInterpreterGroup().getId());
                assertEquals(0, angularObjects.size());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            // add global angular object
            Paragraph p3 = note.addNewParagraph(anonymous);
            p3.setText("%spark z.angularBindGlobal(\"name2\", \"world2\")");
            note.run(p3.getId(), true);
            assertEquals(Status.FINISHED, p3.getStatus());
            List<AngularObject> globalAngularObjects;
            try {
                globalAngularObjects = p3.getBindedInterpreter().getInterpreterGroup().getAngularObjectRegistry().getAll(null, null);
                assertEquals(1, globalAngularObjects.size());
                assertEquals("name2", globalAngularObjects.get(0).getName());
                assertEquals("world2", globalAngularObjects.get(0).get());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            // global angular object is not saved to note
            try {
                angularObjects = note.getAngularObjects(p1.getBindedInterpreter().getInterpreterGroup().getId());
                assertEquals(0, angularObjects.size());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            // remove global angular object
            Paragraph p4 = note.addNewParagraph(anonymous);
            p4.setText("%spark z.angularUnbindGlobal(\"name2\")");
            note.run(p4.getId(), true);
            assertEquals(Status.FINISHED, p4.getStatus());
            try {
                globalAngularObjects = p4.getBindedInterpreter().getInterpreterGroup().getAngularObjectRegistry().getAll(note.getId(), null);
                assertEquals(0, globalAngularObjects.size());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            // global angular object is not saved to note
            try {
                angularObjects = note.getAngularObjects(p1.getBindedInterpreter().getInterpreterGroup().getId());
                assertEquals(0, angularObjects.size());
            } catch (InterpreterNotFoundException e) {
                fail();
            }
            return null;
        });
    } finally {
        if (null != noteId) {
            TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
        }
    }
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) AngularObject(org.apache.zeppelin.display.AngularObject) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 10 with InterpreterNotFoundException

use of org.apache.zeppelin.interpreter.InterpreterNotFoundException in project zeppelin by apache.

the class Helium method suggestApp.

public HeliumPackageSuggestion suggestApp(Paragraph paragraph) {
    HeliumPackageSuggestion suggestion = new HeliumPackageSuggestion();
    Interpreter intp = null;
    try {
        intp = paragraph.getBindedInterpreter();
    } catch (InterpreterNotFoundException e) {
        return suggestion;
    }
    ResourcePool resourcePool = intp.getInterpreterGroup().getResourcePool();
    ResourceSet allResources;
    if (resourcePool != null) {
        if (resourcePool instanceof DistributedResourcePool) {
            allResources = ((DistributedResourcePool) resourcePool).getAll(true);
        } else {
            allResources = resourcePool.getAll();
        }
    } else {
        allResources = interpreterSettingManager.getAllResources();
    }
    for (List<HeliumPackageSearchResult> pkgs : allPackages.values()) {
        for (HeliumPackageSearchResult pkg : pkgs) {
            if (pkg.getPkg().getType() == HeliumType.APPLICATION && pkg.isEnabled()) {
                ResourceSet resources = ApplicationLoader.findRequiredResourceSet(pkg.getPkg().getResources(), paragraph.getNote().getId(), paragraph.getId(), allResources);
                if (resources == null) {
                    continue;
                } else {
                    suggestion.addAvailablePackage(pkg);
                }
                break;
            }
        }
    }
    suggestion.sort();
    return suggestion;
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) ResourcePool(org.apache.zeppelin.resource.ResourcePool) DistributedResourcePool(org.apache.zeppelin.resource.DistributedResourcePool) ResourceSet(org.apache.zeppelin.resource.ResourceSet) DistributedResourcePool(org.apache.zeppelin.resource.DistributedResourcePool)

Aggregations

InterpreterNotFoundException (org.apache.zeppelin.interpreter.InterpreterNotFoundException)10 Interpreter (org.apache.zeppelin.interpreter.Interpreter)5 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)5 AngularObject (org.apache.zeppelin.display.AngularObject)4 ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)3 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)2 Paragraph (org.apache.zeppelin.notebook.Paragraph)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)1 ExecutionContext (org.apache.zeppelin.interpreter.ExecutionContext)1 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)1 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)1 RemoteAngularObject (org.apache.zeppelin.interpreter.remote.RemoteAngularObject)1 RemoteInterpreter (org.apache.zeppelin.interpreter.remote.RemoteInterpreter)1 Note (org.apache.zeppelin.notebook.Note)1