/** * Create new note. * * @return * @throws IOException */ public Note createNote(List<String> interpreterIds) throws IOException { NoteInterpreterLoader intpLoader = new NoteInterpreterLoader(replFactory); Note note = new Note(notebookRepo, intpLoader, jobListenerFactory); intpLoader.setNoteId(note.id()); synchronized (notes) { notes.put(note.id(), note); } if (interpreterIds != null) { bindInterpretersToNote(note.id(), interpreterIds); } note.persist(); return note; }
private Note loadNoteFromRepo(String id) { Note note = null; try { note = notebookRepo.get(id); } catch (IOException e) { logger.error("Failed to load " + id, e); } if (note == null) { return null; } // set NoteInterpreterLoader NoteInterpreterLoader noteInterpreterLoader = new NoteInterpreterLoader(replFactory); note.setReplLoader(noteInterpreterLoader); noteInterpreterLoader.setNoteId(note.id()); // set JobListenerFactory note.setJobListenerFactory(jobListenerFactory); // set notebookRepo note.setNotebookRepo(notebookRepo); Map<String, SnapshotAngularObject> angularObjectSnapshot = new HashMap<String, SnapshotAngularObject>(); // 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 (String intpGroupName : savedObjects.keySet()) { List<AngularObject> objectList = savedObjects.get(intpGroupName); for (AngularObject savedObject : objectList) { SnapshotAngularObject snapshot = angularObjectSnapshot.get(savedObject.getName()); if (snapshot == null || snapshot.getLastUpdate().before(lastUpdatedDate)) { angularObjectSnapshot.put( savedObject.getName(), new SnapshotAngularObject(intpGroupName, savedObject, lastUpdatedDate)); } } } } synchronized (notes) { notes.put(note.id(), note); refreshCron(note.id()); } for (String name : angularObjectSnapshot.keySet()) { SnapshotAngularObject snapshot = angularObjectSnapshot.get(name); List<InterpreterSetting> settings = replFactory.get(); for (InterpreterSetting setting : settings) { InterpreterGroup intpGroup = setting.getInterpreterGroup(); if (intpGroup.getId().equals(snapshot.getIntpGroupId())) { AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry(); String noteId = snapshot.getAngularObject().getNoteId(); // 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); } } } return note; }