use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class NotebookRestApiTest method testRunAllParagraph_FirstFailed.
@Test
public void testRunAllParagraph_FirstFailed() throws IOException {
LOG.info("Running testRunAllParagraph_FirstFailed");
String note1Id = null;
try {
note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous);
// 2 paragraphs
// P1:
// %python
// from __future__ import print_function
// import time
// time.sleep(1)
// print(user2)
//
// P2:
// %python
// user2='abc'
// print(user2)
//
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%python from __future__ import print_function\nimport time\ntime.sleep(1)\nprint(user2)");
p2.setText("%python user2='abc'\nprint(user2)");
return null;
});
CloseableHttpResponse post = httpPost("/notebook/job/" + note1Id + "?blocking=true", "");
assertThat(post, isAllowed());
post.close();
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
Paragraph p2 = note1.getParagraph(1);
assertEquals(Job.Status.ERROR, p1.getStatus());
// p2 will be skipped because p1 is failed.
assertEquals(Job.Status.READY, p2.getStatus());
return null;
});
} finally {
// cleanup
if (null != note1Id) {
TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
}
}
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class HeliumApplicationFactoryTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
// set AppEventListener properly
for (InterpreterSetting interpreterSetting : interpreterSettingManager.get()) {
interpreterSetting.setAppEventListener(heliumAppFactory);
}
AuthorizationService authorizationService = mock(AuthorizationService.class);
notebookRepo = mock(NotebookRepo.class);
notebook = new Notebook(conf, authorizationService, notebookRepo, new NoteManager(notebookRepo, ZeppelinConfiguration.create()), interpreterFactory, interpreterSettingManager, new Credentials());
heliumAppFactory = new HeliumApplicationFactory(notebook, null);
notebook.addNotebookEventListener(heliumAppFactory);
anonymous = new AuthenticationInfo("anonymous");
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class CronJobListener method jobWasExecuted.
@Override
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String noteId = jobDataMap.getString("noteId");
Notebook notebook = (Notebook) jobDataMap.get("notebook");
String noteName = "unknown";
try {
noteName = notebook.processNote(noteId, note -> {
if (note == null) {
LOGGER.warn("Failed to get note: {}", noteId);
return "unknown";
}
return note.getName();
});
} catch (IOException e) {
LOGGER.error("Failed to get note: {}", noteId, e);
} finally {
Timer.Sample sample = cronJobTimerSamples.remove(context);
String result = StringUtils.defaultString(context.getResult().toString(), "unknown");
LOGGER.info("cron job of noteId {} executed with result {}", noteId, result);
if (sample != null) {
Tag noteIdTag = Tag.of("nodeid", noteId);
Tag nameTag = Tag.of("name", noteName);
Tag statusTag = Tag.of("result", result);
sample.stop(Metrics.timer("cronjob", Tags.of(noteIdTag, nameTag, statusTag)));
} else {
LOGGER.warn("No Timer.Sample for NoteId {} found", noteId);
}
}
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class CronJob method execute.
@Override
public void execute(JobExecutionContext context) {
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String noteId = jobDataMap.getString("noteId");
Notebook notebook = (Notebook) jobDataMap.get("notebook");
try {
notebook.processNote(noteId, note -> {
if (note == null) {
LOGGER.warn("Failed to run CronJob of note: {} because there's no such note", noteId);
context.setResult(RESULT_FAILED);
return null;
}
if (note.haveRunningOrPendingParagraphs()) {
LOGGER.warn("execution of the cron job is skipped because there is a running or pending " + "paragraph (note id: {})", note.getId());
context.setResult(RESULT_SKIPPED);
return null;
}
String cronExecutingUser = (String) note.getConfig().get("cronExecutingUser");
String cronExecutingRoles = (String) note.getConfig().get("cronExecutingRoles");
if (null == cronExecutingUser) {
cronExecutingUser = "anonymous";
}
AuthenticationInfo authenticationInfo = new AuthenticationInfo(cronExecutingUser, StringUtils.isEmpty(cronExecutingRoles) ? null : cronExecutingRoles, null);
try {
note.runAll(authenticationInfo, true, true, new HashMap<>());
context.setResult(RESULT_SUCCEEDED);
} catch (Exception e) {
context.setResult(RESULT_FAILED);
LOGGER.warn("Fail to run note: {}", note.getName(), e);
}
return null;
});
} catch (IOException e) {
LOGGER.warn("Failed to run CronJob of note: {} because fail to get it", noteId, e);
context.setResult(RESULT_FAILED);
}
}
Aggregations