use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.
the class FileSystemRecoveryStorageTest method testSingleInterpreterProcess.
@Test
public void testSingleInterpreterProcess() throws InterpreterException, IOException {
InterpreterSetting interpreterSetting = interpreterSettingManager.getByName("test");
interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
Interpreter interpreter1 = interpreterSetting.getDefaultInterpreter("user1", note1Id);
RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1;
InterpreterContext context1 = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
remoteInterpreter1.interpret("hello", context1);
assertEquals(1, interpreterSettingManager.getRecoveryStorage().restore().size());
interpreterSetting.close();
assertEquals(0, interpreterSettingManager.getRecoveryStorage().restore().size());
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.
the class NotebookTest method testAutoRestartInterpreterAfterSchedule.
// @Test
public void testAutoRestartInterpreterAfterSchedule() throws InterruptedException, IOException, InterpreterNotFoundException {
// create a note and a paragraph
String noteId = notebook.createNote("note1", anonymous);
// use write lock, because we are overwrite the note configuration
notebook.processNote(noteId, note -> {
Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Map<String, Object> config = new HashMap<>();
p.setConfig(config);
p.setText("%mock1 sleep 1000");
Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p2.setConfig(config);
p2.setText("%mock2 sleep 500");
// set cron scheduler, once a second
config = note.getConfig();
config.put("enabled", true);
config.put("cron", "1/3 * * * * ?");
config.put("releaseresource", true);
note.setConfig(config);
return null;
});
schedulerService.refreshCron(noteId);
ExecutionContext executionContext = new ExecutionContext(anonymous.getUser(), noteId, "test");
RemoteInterpreter mock1 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock1", executionContext);
RemoteInterpreter mock2 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock2", executionContext);
// wait until interpreters are started
while (!mock1.isOpened() || !mock2.isOpened()) {
Thread.yield();
}
// wait until interpreters are closed
while (mock1.isOpened() || mock2.isOpened()) {
Thread.yield();
}
// remove cron scheduler.
// use write lock because config is overwritten
notebook.processNote(noteId, note -> {
Map<String, Object> config = note.getConfig();
config.put("cron", null);
note.setConfig(config);
return null;
});
schedulerService.refreshCron(noteId);
// make sure all paragraph has been executed
notebook.processNote(noteId, note -> {
for (Paragraph p : note.getParagraphs()) {
assertNotNull(p);
}
return null;
});
notebook.removeNote(noteId, anonymous);
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.
the class InterpreterFactoryTest method testGetFactory.
@Test
public void testGetFactory() throws InterpreterException {
assertTrue(interpreterFactory.getInterpreter("", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("", new ExecutionContext("user1", "note1", "test"));
// EchoInterpreter is the default interpreter because test is the default interpreter group
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
assertTrue(interpreterFactory.getInterpreter("double_echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("double_echo", new ExecutionContext("user1", "note1", "test"));
assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName());
assertTrue(interpreterFactory.getInterpreter("test", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test", new ExecutionContext("user1", "note1", "test"));
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
assertTrue(interpreterFactory.getInterpreter("test2", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2", new ExecutionContext("user1", "note1", "test"));
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
assertTrue(interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContext("user1", "note1", "test"));
assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName());
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.
the class RemoteSchedulerTest method test.
@Test
public void test() throws Exception {
final RemoteInterpreter intpA = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", note1Id, "mock");
intpA.open();
Scheduler scheduler = intpA.getScheduler();
Job<Object> job = new Job<Object>("jobId", "jobName", null) {
Object results;
@Override
public Object getReturn() {
return results;
}
@Override
public int progress() {
return 0;
}
@Override
public Map<String, Object> info() {
return null;
}
@Override
protected Object jobRun() throws Throwable {
intpA.interpret("1000", InterpreterContext.builder().setNoteId("noteId").setParagraphId("jobId").setResourcePool(new LocalResourcePool("pool1")).build());
return "1000";
}
@Override
protected boolean jobAbort() {
return false;
}
@Override
public void setResult(Object results) {
this.results = results;
}
};
scheduler.submit(job);
int cycles = 0;
while (!job.isRunning() && cycles < MAX_WAIT_CYCLES) {
LOGGER.info("Status:" + job.getStatus());
Thread.sleep(TICK_WAIT);
cycles++;
}
assertTrue(job.isRunning());
Thread.sleep(5 * TICK_WAIT);
cycles = 0;
while (!job.isTerminated() && cycles < MAX_WAIT_CYCLES) {
Thread.sleep(TICK_WAIT);
cycles++;
}
assertTrue(job.isTerminated());
intpA.close();
schedulerSvc.removeScheduler("test");
}
use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.
the class ConfInterpreterTest method testRunningAfterOtherInterpreter.
@Test
public void testRunningAfterOtherInterpreter() throws InterpreterException {
assertTrue(interpreterFactory.getInterpreter("test.conf", executionContext) instanceof ConfInterpreter);
ConfInterpreter confInterpreter = (ConfInterpreter) interpreterFactory.getInterpreter("test.conf", executionContext);
InterpreterContext context = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test", executionContext);
InterpreterResult result = remoteInterpreter.interpret("hello world", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code);
result = confInterpreter.interpret("property_1\tnew_value\nnew_property\tdummy_value", context);
assertEquals(InterpreterResult.Code.ERROR, result.code);
}
Aggregations