Search in sources :

Example 6 with ManagedInterpreterGroup

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

the class SessionManagerService method stopSession.

/**
 * Remove and stop this session.
 * 1. Stop associated interpreter process (InterpreterGroup)
 * 2. Remove associated session note
 *
 * @param sessionId
 */
public void stopSession(String sessionId) throws Exception {
    SessionInfo sessionInfo = this.sessions.remove(sessionId);
    if (sessionInfo == null) {
        throw new Exception("No such session: " + sessionId);
    }
    // stop the associated interpreter process
    ManagedInterpreterGroup interpreterGroup = this.interpreterSettingManager.getInterpreterGroupById(sessionId);
    if (interpreterGroup == null) {
        LOGGER.info("No interpreterGroup for session: {}", sessionId);
        return;
    }
    interpreterGroup.getInterpreterSetting().closeInterpreters(sessionId);
    // remove associated session note
    notebook.removeNote(sessionInfo.getNoteId(), AuthenticationInfo.ANONYMOUS);
}
Also used : SessionInfo(org.apache.zeppelin.common.SessionInfo) IOException(java.io.IOException) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup)

Example 7 with ManagedInterpreterGroup

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

the class NotebookServiceTest method setUp.

@Before
public void setUp() throws Exception {
    notebookDir = Files.createTempDirectory("notebookDir").toAbsolutePath().toFile();
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
    ZeppelinConfiguration zeppelinConfiguration = ZeppelinConfiguration.create();
    NotebookRepo notebookRepo = new VFSNotebookRepo();
    notebookRepo.init(zeppelinConfiguration);
    InterpreterSettingManager mockInterpreterSettingManager = mock(InterpreterSettingManager.class);
    InterpreterFactory mockInterpreterFactory = mock(InterpreterFactory.class);
    Interpreter mockInterpreter = mock(Interpreter.class);
    when(mockInterpreterFactory.getInterpreter(any(), any())).thenReturn(mockInterpreter);
    when(mockInterpreter.interpret(eq("invalid_code"), any())).thenReturn(new InterpreterResult(Code.ERROR, "failed"));
    when(mockInterpreter.interpret(eq("1+1"), any())).thenReturn(new InterpreterResult(Code.SUCCESS, "succeed"));
    doCallRealMethod().when(mockInterpreter).getScheduler();
    when(mockInterpreter.getFormType()).thenReturn(FormType.NATIVE);
    ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
    when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
    InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
    when(mockInterpreterSetting.isUserAuthorized(any())).thenReturn(true);
    when(mockInterpreterGroup.getInterpreterSetting()).thenReturn(mockInterpreterSetting);
    when(mockInterpreterSetting.getStatus()).thenReturn(InterpreterSetting.Status.READY);
    Credentials credentials = new Credentials();
    NoteManager noteManager = new NoteManager(notebookRepo, zeppelinConfiguration);
    AuthorizationService authorizationService = new AuthorizationService(noteManager, zeppelinConfiguration);
    notebook = new Notebook(zeppelinConfiguration, authorizationService, notebookRepo, noteManager, mockInterpreterFactory, mockInterpreterSettingManager, credentials, null);
    searchService = new LuceneSearch(zeppelinConfiguration, notebook);
    QuartzSchedulerService schedulerService = new QuartzSchedulerService(zeppelinConfiguration, notebook);
    schedulerService.waitForFinishInit();
    notebookService = new NotebookService(notebook, authorizationService, zeppelinConfiguration, schedulerService);
    String interpreterName = "test";
    when(mockInterpreterSetting.getName()).thenReturn(interpreterName);
    when(mockInterpreterSettingManager.getDefaultInterpreterSetting()).thenReturn(mockInterpreterSetting);
}
Also used : NotebookRepo(org.apache.zeppelin.notebook.repo.NotebookRepo) VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) Interpreter(org.apache.zeppelin.interpreter.Interpreter) Notebook(org.apache.zeppelin.notebook.Notebook) QuartzSchedulerService(org.apache.zeppelin.notebook.scheduler.QuartzSchedulerService) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) LuceneSearch(org.apache.zeppelin.search.LuceneSearch) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) NoteManager(org.apache.zeppelin.notebook.NoteManager) Credentials(org.apache.zeppelin.user.Credentials) Before(org.junit.Before)

Example 8 with ManagedInterpreterGroup

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

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

the class Paragraph method getInterpreterContext.

private InterpreterContext getInterpreterContext() {
    AngularObjectRegistry registry = null;
    ResourcePool resourcePool = null;
    String replName = null;
    if (this.interpreter != null) {
        registry = this.interpreter.getInterpreterGroup().getAngularObjectRegistry();
        resourcePool = this.interpreter.getInterpreterGroup().getResourcePool();
        InterpreterSetting interpreterSetting = ((ManagedInterpreterGroup) interpreter.getInterpreterGroup()).getInterpreterSetting();
        replName = interpreterSetting.getName();
    }
    Credentials credentials = note.getCredentials();
    if (subject != null) {
        UserCredentials userCredentials;
        try {
            userCredentials = credentials.getUserCredentials(subject.getUser());
        } catch (IOException e) {
            LOGGER.warn("Unable to get Usercredentials. Working with empty UserCredentials", e);
            userCredentials = new UserCredentials();
        }
        subject.setUserCredentials(userCredentials);
    }
    return InterpreterContext.builder().setNoteId(note.getId()).setNoteName(note.getName()).setParagraphId(getId()).setReplName(replName).setParagraphTitle(title).setParagraphText(text).setAuthenticationInfo(subject).setLocalProperties(localProperties).setConfig(config).setGUI(settings).setNoteGUI(getNoteGui()).setAngularObjectRegistry(registry).setResourcePool(resourcePool).build();
}
Also used : InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) ResourcePool(org.apache.zeppelin.resource.ResourcePool) UserCredentials(org.apache.zeppelin.user.UserCredentials) IOException(java.io.IOException) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) UserCredentials(org.apache.zeppelin.user.UserCredentials) Credentials(org.apache.zeppelin.user.Credentials) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup)

Example 10 with ManagedInterpreterGroup

use of org.apache.zeppelin.interpreter.ManagedInterpreterGroup 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)

Aggregations

ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)12 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)7 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)6 Interpreter (org.apache.zeppelin.interpreter.Interpreter)5 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)4 InterpreterNotFoundException (org.apache.zeppelin.interpreter.InterpreterNotFoundException)4 Credentials (org.apache.zeppelin.user.Credentials)4 UserCredentials (org.apache.zeppelin.user.UserCredentials)4 IOException (java.io.IOException)3 ResourcePool (org.apache.zeppelin.resource.ResourcePool)3 ArrayList (java.util.ArrayList)2 SessionInfo (org.apache.zeppelin.common.SessionInfo)2 AngularObject (org.apache.zeppelin.display.AngularObject)2 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)2 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)2 Notebook (org.apache.zeppelin.notebook.Notebook)2 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 TypeToken (com.google.gson.reflect.TypeToken)1