use of org.apache.zeppelin.client.NoteResult in project zeppelin by apache.
the class ZeppelinClientExample method main.
public static void main(String[] args) throws Exception {
ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
ZeppelinClient zClient = new ZeppelinClient(clientConfig);
String zeppelinVersion = zClient.getVersion();
System.out.println("Zeppelin version: " + zeppelinVersion);
String notePath = "/zeppelin_client_examples/note_1";
String noteId = null;
try {
noteId = zClient.createNote(notePath);
System.out.println("Created note: " + noteId);
String newNotePath = notePath + "_rename";
zClient.renameNote(noteId, newNotePath);
NoteResult renamedNoteResult = zClient.queryNoteResult(noteId);
System.out.println("Rename note: " + noteId + " name to " + renamedNoteResult.getNotePath());
String paragraphId = zClient.addParagraph(noteId, "the first paragraph", "%python print('hello world')");
ParagraphResult paragraphResult = zClient.executeParagraph(noteId, paragraphId);
System.out.println("Added new paragraph and execute it.");
System.out.println("Paragraph result: " + paragraphResult);
String paragraphId2 = zClient.addParagraph(noteId, "the second paragraph", "%python\nimport time\ntime.sleep(5)\nprint('done')");
zClient.submitParagraph(noteId, paragraphId2);
zClient.waitUtilParagraphRunning(noteId, paragraphId2);
zClient.cancelParagraph(noteId, paragraphId2);
paragraphResult = zClient.waitUtilParagraphFinish(noteId, paragraphId2);
System.out.println("Added new paragraph, submit it then cancel it");
System.out.println("Paragraph result: " + paragraphResult);
NoteResult noteResult = zClient.executeNote(noteId);
System.out.println("Execute note and the note result: " + noteResult);
zClient.submitNote(noteId);
noteResult = zClient.waitUntilNoteFinished(noteId);
System.out.println("Submit note and the note result: " + noteResult);
} finally {
if (noteId != null) {
zClient.deleteNote(noteId);
System.out.println("Note " + noteId + " is deleted");
}
}
}
use of org.apache.zeppelin.client.NoteResult in project zeppelin by apache.
the class ZeppelinClientExample2 method main.
public static void main(String[] args) throws Exception {
ClientConfig clientConfig = new ClientConfig("http://localhost:8080");
ZeppelinClient zClient = new ZeppelinClient(clientConfig);
String zeppelinVersion = zClient.getVersion();
System.out.println("Zeppelin version: " + zeppelinVersion);
// execute note 2A94M5J1Z paragraph by paragraph
try {
ParagraphResult paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150210-015259_1403135953");
System.out.println("Execute the 1st spark tutorial paragraph, paragraph result: " + paragraphResult);
paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150210-015302_1492795503");
System.out.println("Execute the 2nd spark tutorial paragraph, paragraph result: " + paragraphResult);
Map<String, String> parameters = new HashMap<>();
parameters.put("maxAge", "40");
paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150212-145404_867439529", parameters);
System.out.println("Execute the 3rd spark tutorial paragraph, paragraph result: " + paragraphResult);
parameters = new HashMap<>();
parameters.put("marital", "married");
paragraphResult = zClient.executeParagraph("2A94M5J1Z", "20150213-230422_1600658137", parameters);
System.out.println("Execute the 4th spark tutorial paragraph, paragraph result: " + paragraphResult);
} finally {
// you need to stop interpreter explicitly if you are running paragraph separately.
zClient.stopInterpreter("2A94M5J1Z", "spark");
}
// execute this whole note, this note will run under a didicated interpreter process which will be
// stopped after note execution.
Map<String, String> parameters = new HashMap<>();
parameters.put("maxAge", "40");
parameters.put("marital", "married");
NoteResult noteResult = zClient.executeNote("2A94M5J1Z", parameters);
System.out.println("Execute the spark tutorial note, note result: " + noteResult);
}
use of org.apache.zeppelin.client.NoteResult in project zeppelin by apache.
the class ZeppelinClientIntegrationTest method testSubmitNote.
@Test
public void testSubmitNote() throws Exception {
try {
zeppelinClient.submitNote("unknown_id");
fail("Should fail to submit non-existed note");
} catch (Exception e) {
assertTrue(e.getMessage(), e.getMessage().contains("No such note"));
}
String noteId = zeppelinClient.createNote("/test/note_4");
String p0Id = zeppelinClient.addParagraph(noteId, "run sh", "%sh echo 'hello world'");
zeppelinClient.submitNote(noteId);
NoteResult noteResult = zeppelinClient.waitUntilNoteFinished(noteId);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
ParagraphResult p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello world\n", p0.getResults().get(0).getData());
// update paragraph with dynamic forms
zeppelinClient.updateParagraph(noteId, p0Id, "run sh", "%sh(form=simple) sleep 5\necho 'hello ${name=abc}'");
noteResult = zeppelinClient.submitNote(noteId);
assertEquals(true, noteResult.isRunning());
noteResult = zeppelinClient.waitUntilNoteFinished(noteId);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello abc\n", p0.getResults().get(0).getData());
// execute paragraph with parameters
Map<String, String> parameters = new HashMap<>();
parameters.put("name", "zeppelin");
noteResult = zeppelinClient.executeNote(noteId, parameters);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello zeppelin\n", p0.getResults().get(0).getData());
zeppelinClient.addParagraph(noteId, "run sh", "%sh invalid_command");
zeppelinClient.addParagraph(noteId, "run sh", "%sh pwd");
zeppelinClient.submitNote(noteId, parameters);
noteResult = zeppelinClient.waitUntilNoteFinished(noteId);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(3, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello zeppelin\n", p0.getResults().get(0).getData());
ParagraphResult p1 = noteResult.getParagraphResultList().get(1);
assertEquals(Status.ERROR, p1.getStatus());
assertEquals("TEXT", p1.getResults().get(0).getType());
assertTrue(p1.getResults().get(0).getData(), p1.getResults().get(0).getData().contains("command not found"));
assertEquals("TEXT", p1.getResults().get(1).getType());
assertTrue(p1.getResults().get(1).getData(), p1.getResults().get(1).getData().contains("ExitValue"));
// p2 will be skipped because p1 fails.
ParagraphResult p2 = noteResult.getParagraphResultList().get(2);
assertEquals(Status.READY, p2.getStatus());
assertEquals(0, p2.getResults().size());
}
use of org.apache.zeppelin.client.NoteResult in project zeppelin by apache.
the class ZeppelinClientIntegrationTest method testImportNote.
@Test
public void testImportNote() throws Exception {
String noteContent = IOUtils.toString(ZeppelinClientIntegrationTest.class.getResource("/Test_Note.zpln"));
String noteId = zeppelinClient.importNote("/imported_notes/note_1", noteContent);
assertNotNull("Import note failed because returned noteId is null", noteId);
NoteResult noteResult = zeppelinClient.queryNoteResult(noteId);
assertFalse(noteResult.isRunning());
assertEquals(2, noteResult.getParagraphResultList().size());
assertEquals(1, noteResult.getParagraphResultList().get(0).getResults().size());
assertEquals("TEXT", noteResult.getParagraphResultList().get(0).getResults().get(0).getType());
assertEquals("Hello World\n", noteResult.getParagraphResultList().get(0).getResults().get(0).getData());
// import to the same notePath again
try {
zeppelinClient.importNote("/imported_notes/note_1", noteContent);
fail("Should fail to import note to the same notePath");
} catch (Exception e) {
e.printStackTrace();
assertTrue(e.getMessage(), e.getMessage().contains("Note '/imported_notes/note_1' existed"));
}
// import invalid noteContent
try {
zeppelinClient.importNote("/imported_notes/note_1", "Invalid_content");
fail("Should fail to import note with invalid note content");
} catch (Exception e) {
e.printStackTrace();
assertTrue(e.getMessage(), e.getMessage().contains("Invalid JSON"));
}
}
use of org.apache.zeppelin.client.NoteResult in project zeppelin by apache.
the class ZeppelinClientIntegrationTest method testExecuteNote.
@Test
public void testExecuteNote() throws Exception {
try {
zeppelinClient.executeNote("unknown_id");
fail("Should fail to submit non-existed note");
} catch (Exception e) {
assertTrue(e.getMessage(), e.getMessage().contains("No such note"));
}
String noteId = zeppelinClient.createNote("/test/note_3");
String p0Id = zeppelinClient.addParagraph(noteId, "run sh", "%sh echo 'hello world'");
NoteResult noteResult = zeppelinClient.executeNote(noteId, new HashMap<>());
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
ParagraphResult p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello world\n", p0.getResults().get(0).getData());
// update paragraph with dynamic forms
zeppelinClient.updateParagraph(noteId, p0Id, "run sh", "%sh(form=simple) echo 'hello ${name=abc}'");
noteResult = zeppelinClient.executeNote(noteId);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello abc\n", p0.getResults().get(0).getData());
// execute paragraph with parameters
Map<String, String> parameters = new HashMap<>();
parameters.put("name", "zeppelin");
noteResult = zeppelinClient.executeNote(noteId, parameters);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello zeppelin\n", p0.getResults().get(0).getData());
zeppelinClient.addParagraph(noteId, "run sh", "%sh invalid_command");
zeppelinClient.addParagraph(noteId, "run sh", "%sh pwd");
noteResult = zeppelinClient.executeNote(noteId, parameters);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(3, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello zeppelin\n", p0.getResults().get(0).getData());
ParagraphResult p1 = noteResult.getParagraphResultList().get(1);
assertEquals(Status.ERROR, p1.getStatus());
assertEquals("TEXT", p1.getResults().get(0).getType());
assertTrue(p1.getResults().get(0).getData(), p1.getResults().get(0).getData().contains("command not found"));
assertEquals("TEXT", p1.getResults().get(1).getType());
assertTrue(p1.getResults().get(1).getData(), p1.getResults().get(1).getData().contains("ExitValue"));
// p2 will be skipped because p1 fails.
ParagraphResult p2 = noteResult.getParagraphResultList().get(2);
assertEquals(Status.READY, p2.getStatus());
assertEquals(0, p2.getResults().size());
}
Aggregations