Search in sources :

Example 36 with Interpreter

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

the class YarnInterpreterLauncherIntegrationTest method testLaunchShellInYarn.

@Test
public void testLaunchShellInYarn() throws YarnException, InterpreterException, InterruptedException {
    InterpreterSetting shellInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("sh");
    shellInterpreterSetting.setProperty("zeppelin.interpreter.launcher", "yarn");
    shellInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath());
    Interpreter shellInterpreter = interpreterFactory.getInterpreter("sh", new ExecutionContext("user1", "note1", "sh"));
    InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
    InterpreterResult interpreterResult = shellInterpreter.interpret("pwd", context);
    assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("/usercache/"));
    Thread.sleep(1000);
    // 1 yarn application launched
    GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING));
    GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
    assertEquals(1, response.getApplicationList().size());
    interpreterSettingManager.close();
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) Test(org.junit.Test)

Example 37 with Interpreter

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

the class YarnInterpreterLauncherIntegrationTest method testJdbcPython_YarnLauncher.

@Test
public void testJdbcPython_YarnLauncher() throws InterpreterException, YarnException, InterruptedException {
    InterpreterSetting jdbcInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("jdbc");
    jdbcInterpreterSetting.setProperty("default.driver", "com.mysql.jdbc.Driver");
    jdbcInterpreterSetting.setProperty("default.url", "jdbc:mysql://localhost:3306/");
    jdbcInterpreterSetting.setProperty("default.user", "root");
    jdbcInterpreterSetting.setProperty("zeppelin.interpreter.launcher", "yarn");
    jdbcInterpreterSetting.setProperty("zeppelin.interpreter.yarn.resource.memory", "512");
    jdbcInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath());
    Dependency dependency = new Dependency("mysql:mysql-connector-java:5.1.46");
    jdbcInterpreterSetting.setDependencies(Arrays.asList(dependency));
    interpreterSettingManager.restart(jdbcInterpreterSetting.getId());
    jdbcInterpreterSetting.waitForReady(60 * 1000);
    InterpreterSetting pythonInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("python");
    pythonInterpreterSetting.setProperty("zeppelin.interpreter.launcher", "yarn");
    pythonInterpreterSetting.setProperty("zeppelin.interpreter.yarn.resource.memory", "512");
    pythonInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath());
    Interpreter jdbcInterpreter = interpreterFactory.getInterpreter("jdbc", new ExecutionContext("user1", "note1", "test"));
    assertNotNull("JdbcInterpreter is null", jdbcInterpreter);
    InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").setAuthenticationInfo(AuthenticationInfo.ANONYMOUS).build();
    InterpreterResult interpreterResult = jdbcInterpreter.interpret("show databases;", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    context.getLocalProperties().put("saveAs", "table_1");
    interpreterResult = jdbcInterpreter.interpret("SELECT 1 as c1, 2 as c2;", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(1, interpreterResult.message().size());
    assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
    assertEquals("c1\tc2\n1\t2\n", interpreterResult.message().get(0).getData());
    // read table_1 from python interpreter
    Interpreter pythonInterpreter = interpreterFactory.getInterpreter("python", new ExecutionContext("user1", "note1", "test"));
    assertNotNull("PythonInterpreter is null", pythonInterpreter);
    context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").setAuthenticationInfo(AuthenticationInfo.ANONYMOUS).build();
    interpreterResult = pythonInterpreter.interpret("df=z.getAsDataFrame('table_1')\nz.show(df)", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(1, interpreterResult.message().size());
    assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
    assertEquals("c1\tc2\n1\t2\n", interpreterResult.message().get(0).getData());
    // 2 yarn application launched
    GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING));
    GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
    assertEquals(2, response.getApplicationList().size());
    interpreterSettingManager.close();
    // sleep for 5 seconds to make sure yarn apps are finished
    Thread.sleep(5 * 1000);
    request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING));
    response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
    assertEquals(0, response.getApplicationList().size());
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Dependency(org.apache.zeppelin.dep.Dependency) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) Test(org.junit.Test)

Example 38 with Interpreter

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

the class Note method runAllSync.

/**
 * Run all the paragraphs in sync(blocking) way.
 *
 * @param authInfo
 * @param isolated
 */
private void runAllSync(AuthenticationInfo authInfo, boolean isolated, Map<String, Object> params) throws Exception {
    try {
        for (Paragraph p : getParagraphs()) {
            if (!p.isEnabled()) {
                continue;
            }
            p.setAuthenticationInfo(authInfo);
            Map<String, Object> originalParams = p.settings.getParams();
            try {
                if (params != null && !params.isEmpty()) {
                    p.settings.setParams(params);
                }
                Interpreter interpreter = p.getBindedInterpreter();
                if (interpreter != null) {
                    // set interpreter property to execution.mode to be note
                    // so that it could use the correct scheduler. see ZEPPELIN-4832
                    interpreter.setProperty(".execution.mode", "note");
                    interpreter.setProperty(".noteId", id);
                }
                // Must run each paragraph in blocking way.
                if (!run(p.getId(), true)) {
                    LOGGER.warn("Skip running the remain notes because paragraph {} fails", p.getId());
                    return;
                }
            } catch (InterpreterNotFoundException e) {
            // ignore, because the following run method will fail if interpreter not found.
            } finally {
                // reset params to the original value
                p.settings.setParams(originalParams);
            }
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (isolated) {
            LOGGER.info("Releasing interpreters used by this note: {}", id);
            for (InterpreterSetting setting : getUsedInterpreterSettings()) {
                setting.closeInterpreters(getExecutionContext());
                for (Paragraph p : paragraphs) {
                    p.setInterpreter(null);
                }
            }
        }
    }
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException)

Example 39 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter 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 40 with Interpreter

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

the class Notebook method getBindedInterpreterSettings.

public List<InterpreterSetting> getBindedInterpreterSettings(String noteId) throws IOException {
    List<InterpreterSetting> interpreterSettings = new ArrayList<>();
    processNote(noteId, note -> {
        if (note != null) {
            Set<InterpreterSetting> settings = new HashSet<>();
            for (Paragraph p : note.getParagraphs()) {
                try {
                    Interpreter intp = p.getBindedInterpreter();
                    settings.add(((ManagedInterpreterGroup) intp.getInterpreterGroup()).getInterpreterSetting());
                } catch (InterpreterNotFoundException e) {
                // ignore this
                }
            }
            // add the default interpreter group
            InterpreterSetting defaultIntpSetting = interpreterSettingManager.getByName(note.getDefaultInterpreterGroup());
            if (defaultIntpSetting != null) {
                settings.add(defaultIntpSetting);
            }
            interpreterSettings.addAll(settings);
        }
        return null;
    });
    return interpreterSettings;
}
Also used : 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) HashSet(java.util.HashSet)

Aggregations

Interpreter (org.apache.zeppelin.interpreter.Interpreter)85 Test (org.junit.Test)46 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)42 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)30 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)27 LazyOpenInterpreter (org.apache.zeppelin.interpreter.LazyOpenInterpreter)26 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)21 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)21 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)20 Properties (java.util.Properties)19 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)11 ExecutionContext (org.apache.zeppelin.interpreter.ExecutionContext)11 IOException (java.io.IOException)10 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)10 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)9 WrappedInterpreter (org.apache.zeppelin.interpreter.WrappedInterpreter)7 ArrayList (java.util.ArrayList)6 InterpreterNotFoundException (org.apache.zeppelin.interpreter.InterpreterNotFoundException)6 ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)6 Before (org.junit.Before)6