private long getUnixTimeLastRunParagraph(Paragraph paragraph) { Date lastRunningDate; long lastRunningUnixTime; Date paragaraphDate = paragraph.getDateStarted(); // diff started time <-> finishied time if (paragaraphDate == null) { paragaraphDate = paragraph.getDateFinished(); } else { if (paragraph.getDateFinished() != null && paragraph.getDateFinished().after(paragaraphDate)) { paragaraphDate = paragraph.getDateFinished(); } } // finished time and started time is not exists. if (paragaraphDate == null) { paragaraphDate = paragraph.getDateCreated(); } // set last update unixtime(ms). lastRunningDate = paragaraphDate; lastRunningUnixTime = lastRunningDate.getTime(); return lastRunningUnixTime; }
private Map<String, String> populateParagraphInfo(Paragraph p) { Map<String, String> info = new HashMap<>(); info.put("id", p.getId()); info.put("status", p.getStatus().toString()); if (p.getDateStarted() != null) { info.put("started", p.getDateStarted().toString()); } if (p.getDateFinished() != null) { info.put("finished", p.getDateFinished().toString()); } if (p.getStatus().isRunning()) { info.put("progress", String.valueOf(p.progress())); } else { info.put("progress", String.valueOf(100)); } return info; }
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; }
@SuppressWarnings("rawtypes") private Note loadNoteFromRepo(String id, AuthenticationInfo subject) { Note note = null; try { note = notebookRepo.get(id, subject); } catch (IOException e) { logger.error("Failed to load " + id, e); } if (note == null) { return null; } // Manually inject ALL dependencies, as DI constructor was NOT used note.setIndex(this.notebookIndex); note.setCredentials(this.credentials); note.setInterpreterFactory(replFactory); note.setJobListenerFactory(jobListenerFactory); note.setNotebookRepo(notebookRepo); Map<String, SnapshotAngularObject> angularObjectSnapshot = new HashMap<>(); // 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 object : objectList) { SnapshotAngularObject snapshot = angularObjectSnapshot.get(object.getName()); if (snapshot == null || snapshot.getLastUpdate().before(lastUpdatedDate)) { angularObjectSnapshot.put( object.getName(), new SnapshotAngularObject(intpGroupName, object, lastUpdatedDate)); } } } } note.setNoteEventListener(this); synchronized (notes) { notes.put(note.getId(), note); refreshCron(note.getId()); } for (String name : angularObjectSnapshot.keySet()) { SnapshotAngularObject snapshot = angularObjectSnapshot.get(name); List<InterpreterSetting> settings = replFactory.get(); for (InterpreterSetting setting : settings) { InterpreterGroup intpGroup = setting.getInterpreterGroup(note.getId()); if (intpGroup.getId().equals(snapshot.getIntpGroupId())) { AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry(); String noteId = snapshot.getAngularObject().getNoteId(); String paragraphId = snapshot.getAngularObject().getParagraphId(); // 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, paragraphId); } } } return note; }