use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method addNewParagraphIfLastParagraphIsExecuted.
private void addNewParagraphIfLastParagraphIsExecuted(Note note, Paragraph p) {
// if it's the last paragraph and empty, let's add a new one
boolean isTheLastParagraph = note.isLastParagraph(p.getId());
if (!(p.getText().trim().equals(p.getMagic()) || Strings.isNullOrEmpty(p.getText())) && isTheLastParagraph) {
Paragraph newPara = note.addParagraph(p.getAuthenticationInfo());
broadcastNewParagraph(note, newPara);
}
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method onParaInfosReceived.
@Override
public void onParaInfosReceived(String noteId, String paragraphId, String interpreterSettingId, Map<String, String> metaInfos) {
Note note = notebook().getNote(noteId);
if (note != null) {
Paragraph paragraph = note.getParagraph(paragraphId);
if (paragraph != null) {
InterpreterSetting setting = notebook().getInterpreterSettingManager().get(interpreterSettingId);
setting.addNoteToPara(noteId, paragraphId);
String label = metaInfos.get("label");
String tooltip = metaInfos.get("tooltip");
List<String> keysToRemove = Arrays.asList("noteId", "paraId", "label", "tooltip");
for (String removeKey : keysToRemove) {
metaInfos.remove(removeKey);
}
paragraph.updateRuntimeInfos(label, tooltip, metaInfos, setting.getGroup(), setting.getId());
broadcast(note.getId(), new Message(OP.PARAS_INFO).put("id", paragraphId).put("infos", paragraph.getRuntimeInfos()));
}
}
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method cancelParagraph.
private void cancelParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
final String paragraphId = (String) fromMessage.get("id");
if (paragraphId == null) {
return;
}
String noteId = getOpenNoteId(conn);
if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
return;
}
final Note note = notebook.getNote(noteId);
Paragraph p = note.getParagraph(paragraphId);
p.abort();
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class NotebookServer method runAllParagraphs.
private void runAllParagraphs(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
final String noteId = (String) fromMessage.get("noteId");
if (StringUtils.isBlank(noteId)) {
return;
}
if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "run all paragraphs")) {
return;
}
List<Map<String, Object>> paragraphs = gson.fromJson(String.valueOf(fromMessage.data.get("paragraphs")), new TypeToken<List<Map<String, Object>>>() {
}.getType());
for (Map<String, Object> raw : paragraphs) {
String paragraphId = (String) raw.get("id");
if (paragraphId == null) {
continue;
}
String text = (String) raw.get("paragraph");
String title = (String) raw.get("title");
Map<String, Object> params = (Map<String, Object>) raw.get("params");
Map<String, Object> config = (Map<String, Object>) raw.get("config");
Note note = notebook.getNote(noteId);
Paragraph p = setParagraphUsingMessage(note, fromMessage, paragraphId, text, title, params, config);
persistAndExecuteSingleParagraph(conn, note, p);
}
}
use of org.apache.zeppelin.notebook.Paragraph in project zeppelin by apache.
the class MongoNotebookRepo method documentToNote.
/**
* Convert document to note
*/
private Note documentToNote(Document doc) {
// document to JSON
String json = doc.toJson();
// JSON to note
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create();
Note note = gson.fromJson(json, Note.class);
for (Paragraph p : note.getParagraphs()) {
if (p.getStatus() == Job.Status.PENDING || p.getStatus() == Job.Status.RUNNING) {
p.setStatus(Job.Status.ABORT);
}
List<ApplicationState> appStates = p.getAllApplicationStates();
if (appStates != null) {
for (ApplicationState app : appStates) {
if (app.getStatus() != ApplicationState.Status.ERROR) {
app.setStatus(ApplicationState.Status.UNLOADED);
}
}
}
}
return note;
}
Aggregations