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);
}
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);
}
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);
}
}
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();
}
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);
}
Aggregations