use of org.apache.zeppelin.interpreter.InterpreterSettingManager in project zeppelin by apache.
the class NotebookRepoSyncTest method setUp.
@Before
public void setUp() throws Exception {
System.setProperty("zeppelin.isTest", "true");
ZEPPELIN_HOME = Files.createTempDir();
new File(ZEPPELIN_HOME, "conf").mkdirs();
String mainNotePath = ZEPPELIN_HOME.getAbsolutePath() + "/notebook";
String secNotePath = ZEPPELIN_HOME.getAbsolutePath() + "/notebook_secondary";
mainNotebookDir = new File(mainNotePath);
secNotebookDir = new File(secNotePath);
mainNotebookDir.mkdirs();
secNotebookDir.mkdirs();
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), ZEPPELIN_HOME.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.VFSNotebookRepo,org.apache.zeppelin.notebook.repo.mock.VFSNotebookRepoMock");
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_ONE_WAY_SYNC.getVarName(), "false");
System.setProperty(ConfVars.ZEPPELIN_CONFIG_FS_DIR.getVarName(), ZEPPELIN_HOME.getAbsolutePath() + "/conf");
System.setProperty(ConfVars.ZEPPELIN_PLUGINS_DIR.getVarName(), new File("../../../plugins").getAbsolutePath());
LOG.info("main Note dir : " + mainNotePath);
LOG.info("secondary note dir : " + secNotePath);
conf = ZeppelinConfiguration.create();
ConfigStorage.reset();
interpreterSettingManager = new InterpreterSettingManager(conf, mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
factory = new InterpreterFactory(interpreterSettingManager);
notebookRepoSync = new NotebookRepoSync(conf);
noteManager = new NoteManager(notebookRepoSync, conf);
authorizationService = new AuthorizationService(noteManager, conf);
credentials = new Credentials(conf);
notebook = new Notebook(conf, authorizationService, notebookRepoSync, noteManager, factory, interpreterSettingManager, credentials, null);
anonymous = new AuthenticationInfo("anonymous");
}
use of org.apache.zeppelin.interpreter.InterpreterSettingManager in project zeppelin by apache.
the class LuceneSearchTest method startUp.
@Before
public void startUp() throws IOException {
indexDir = Files.createTempDirectory("lucene").toFile();
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SEARCH_INDEX_PATH.getVarName(), indexDir.getAbsolutePath());
ZeppelinConfiguration conf = ZeppelinConfiguration.create();
noteManager = new NoteManager(new InMemoryNotebookRepo(), conf);
interpreterSettingManager = mock(InterpreterSettingManager.class);
InterpreterSetting defaultInterpreterSetting = mock(InterpreterSetting.class);
when(defaultInterpreterSetting.getName()).thenReturn("test");
when(interpreterSettingManager.getDefaultInterpreterSetting()).thenReturn(defaultInterpreterSetting);
notebook = new Notebook(conf, mock(AuthorizationService.class), mock(NotebookRepo.class), noteManager, mock(InterpreterFactory.class), interpreterSettingManager, mock(Credentials.class), null);
noteSearchService = new LuceneSearch(ZeppelinConfiguration.create(), notebook);
}
use of org.apache.zeppelin.interpreter.InterpreterSettingManager 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;
}
use of org.apache.zeppelin.interpreter.InterpreterSettingManager in project SSM by Intel-bigdata.
the class SmartZeppelinServer method init.
private void init() throws Exception {
this.depResolver = new DependencyResolver(zconf.getString(ConfVars.ZEPPELIN_INTERPRETER_LOCALREPO));
InterpreterOutput.limit = zconf.getInt(ConfVars.ZEPPELIN_INTERPRETER_OUTPUT_LIMIT);
HeliumApplicationFactory heliumApplicationFactory = new HeliumApplicationFactory();
HeliumVisualizationFactory heliumVisualizationFactory;
if (isBinaryPackage(zconf)) {
/* In binary package, zeppelin-web/src/app/visualization and zeppelin-web/src/app/tabledata
* are copied to lib/node_modules/zeppelin-vis, lib/node_modules/zeppelin-tabledata directory.
* Check zeppelin/zeppelin-distribution/src/assemble/distribution.xml to see how they're
* packaged into binary package.
*/
heliumVisualizationFactory = new HeliumVisualizationFactory(zconf, new File(zconf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO)), new File(zconf.getRelativeDir("lib/node_modules/zeppelin-tabledata")), new File(zconf.getRelativeDir("lib/node_modules/zeppelin-vis")));
} else {
heliumVisualizationFactory = new HeliumVisualizationFactory(zconf, new File(zconf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO)), // new File(zconf.getRelativeDir("zeppelin-web/src/app/visualization")));
new File(zconf.getRelativeDir("smart-zeppelin/zeppelin-web/src/app/tabledata")), new File(zconf.getRelativeDir("smart-zeppelin/zeppelin-web/src/app/visualization")));
}
this.helium = new Helium(zconf.getHeliumConfPath(), zconf.getHeliumDefaultLocalRegistryPath(), heliumVisualizationFactory, heliumApplicationFactory);
// create visualization bundle
try {
heliumVisualizationFactory.bundle(helium.getVisualizationPackagesToBundle());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
this.schedulerFactory = new SchedulerFactory();
this.interpreterSettingManager = new InterpreterSettingManager(zconf, depResolver, new InterpreterOption(true));
this.noteSearchService = new LuceneSearch();
this.notebookAuthorization = NotebookAuthorization.init(zconf);
this.credentials = new Credentials(zconf.credentialsPersist(), zconf.getCredentialsPath());
}
use of org.apache.zeppelin.interpreter.InterpreterSettingManager in project SSM by Intel-bigdata.
the class ParagraphTest method returnUnchangedResultsWithDifferentUser.
@Test
public void returnUnchangedResultsWithDifferentUser() throws Throwable {
InterpreterSettingManager mockInterpreterSettingManager = mock(InterpreterSettingManager.class);
Note mockNote = mock(Note.class);
when(mockNote.getCredentials()).thenReturn(mock(Credentials.class));
Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null, null, mockInterpreterSettingManager));
doReturn("spy").when(spyParagraph).getRequiredReplName();
Interpreter mockInterpreter = mock(Interpreter.class);
doReturn(mockInterpreter).when(spyParagraph).getRepl(anyString());
InterpreterGroup mockInterpreterGroup = mock(InterpreterGroup.class);
when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
when(mockInterpreterGroup.getId()).thenReturn("mock_id_1");
when(mockInterpreterGroup.getAngularObjectRegistry()).thenReturn(mock(AngularObjectRegistry.class));
when(mockInterpreterGroup.getResourcePool()).thenReturn(mock(ResourcePool.class));
List<InterpreterSetting> spyInterpreterSettingList = spy(Lists.<InterpreterSetting>newArrayList());
InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
InterpreterOption mockInterpreterOption = mock(InterpreterOption.class);
when(mockInterpreterSetting.getOption()).thenReturn(mockInterpreterOption);
when(mockInterpreterOption.permissionIsSet()).thenReturn(false);
when(mockInterpreterSetting.getStatus()).thenReturn(Status.READY);
when(mockInterpreterSetting.getId()).thenReturn("mock_id_1");
when(mockInterpreterSetting.getInterpreterGroup(anyString(), anyString())).thenReturn(mockInterpreterGroup);
spyInterpreterSettingList.add(mockInterpreterSetting);
when(mockNote.getId()).thenReturn("any_id");
when(mockInterpreterSettingManager.getInterpreterSettings(anyString())).thenReturn(spyInterpreterSettingList);
doReturn("spy script body").when(spyParagraph).getScriptBody();
when(mockInterpreter.getFormType()).thenReturn(FormType.NONE);
ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
doReturn(mockJobListener).when(spyParagraph).getListener();
doNothing().when(mockJobListener).onOutputUpdateAll(Mockito.<Paragraph>any(), Mockito.anyList());
InterpreterResult mockInterpreterResult = mock(InterpreterResult.class);
when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
// Actual test
List<InterpreterResultMessage> result1 = Lists.newArrayList();
result1.add(new InterpreterResultMessage(Type.TEXT, "result1"));
when(mockInterpreterResult.message()).thenReturn(result1);
AuthenticationInfo user1 = new AuthenticationInfo("user1");
spyParagraph.setAuthenticationInfo(user1);
spyParagraph.jobRun();
Paragraph p1 = spyParagraph.getUserParagraph(user1.getUser());
List<InterpreterResultMessage> result2 = Lists.newArrayList();
result2.add(new InterpreterResultMessage(Type.TEXT, "result2"));
when(mockInterpreterResult.message()).thenReturn(result2);
AuthenticationInfo user2 = new AuthenticationInfo("user2");
spyParagraph.setAuthenticationInfo(user2);
spyParagraph.jobRun();
Paragraph p2 = spyParagraph.getUserParagraph(user2.getUser());
assertNotEquals(p1.getReturn().toString(), p2.getReturn().toString());
assertEquals(p1, spyParagraph.getUserParagraph(user1.getUser()));
}
Aggregations