/** * Run a single paragraph. * * @param paragraphId ID of paragraph */ public void run(String paragraphId) { Paragraph p = getParagraph(paragraphId); if (p.isBlankParagraph()) { logger.info("skip to run blank paragraph. {}", p.getId()); return; } p.setListener(jobListenerFactory.getParagraphJobListener(this)); String requiredReplName = p.getRequiredReplName(); Interpreter intp = factory.getInterpreter(p.getUser(), getId(), requiredReplName); if (intp == null) { String intpExceptionMsg = p.getJobName() + "'s Interpreter " + requiredReplName + " not found"; InterpreterException intpException = new InterpreterException(intpExceptionMsg); InterpreterResult intpResult = new InterpreterResult(InterpreterResult.Code.ERROR, intpException.getMessage()); p.setReturn(intpResult, intpException); p.setStatus(Job.Status.ERROR); throw intpException; } if (p.getConfig().get("enabled") == null || (Boolean) p.getConfig().get("enabled")) { p.setAuthenticationInfo(p.getAuthenticationInfo()); intp.getScheduler().submit(p); } }
private boolean isValidInterpreter(String replName) { try { return factory.getInterpreter(user, note.getId(), replName) != null; } catch (InterpreterException e) { // ignore this exception, it would be recaught when running paragraph. return false; } }
private InterpreterSetting getInterpreterSettingById(String id) { InterpreterSetting setting = null; for (InterpreterSetting i : factory.getInterpreterSettings(note.getId())) { if (id.startsWith(i.getId())) { setting = i; break; } } return setting; }
private InterpreterContext getInterpreterContext(InterpreterOutput output) { AngularObjectRegistry registry = null; ResourcePool resourcePool = null; if (!factory.getInterpreterSettings(note.getId()).isEmpty()) { InterpreterSetting intpGroup = factory.getInterpreterSettings(note.getId()).get(0); registry = intpGroup.getInterpreterGroup(getUser(), note.getId()).getAngularObjectRegistry(); resourcePool = intpGroup.getInterpreterGroup(getUser(), note.getId()).getResourcePool(); } List<InterpreterContextRunner> runners = new LinkedList<>(); for (Paragraph p : note.getParagraphs()) { runners.add(new ParagraphRunner(note, note.getId(), p.getId())); } final Paragraph self = this; Credentials credentials = note.getCredentials(); if (authenticationInfo != null) { UserCredentials userCredentials = credentials.getUserCredentials(authenticationInfo.getUser()); authenticationInfo.setUserCredentials(userCredentials); } InterpreterContext interpreterContext = new InterpreterContext( note.getId(), getId(), getRequiredReplName(), this.getTitle(), this.getText(), this.getAuthenticationInfo(), this.getConfig(), this.settings, registry, resourcePool, runners, output); return interpreterContext; }
private void snapshotAngularObjectRegistry(String user) { angularObjects = new HashMap<>(); List<InterpreterSetting> settings = factory.getInterpreterSettings(getId()); if (settings == null || settings.size() == 0) { return; } for (InterpreterSetting setting : settings) { InterpreterGroup intpGroup = setting.getInterpreterGroup(user, id); AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry(); angularObjects.put(intpGroup.getId(), registry.getAllWithGlobal(id)); } }
public List<InterpreterCompletion> getInterpreterCompletion() { List<InterpreterCompletion> completion = new LinkedList(); for (InterpreterSetting intp : factory.getInterpreterSettings(note.getId())) { List<InterpreterInfo> intInfo = intp.getInterpreterInfos(); if (intInfo.size() > 1) { for (InterpreterInfo info : intInfo) { String name = intp.getName() + "." + info.getName(); completion.add(new InterpreterCompletion(name, name)); } } else { completion.add(new InterpreterCompletion(intp.getName(), intp.getName())); } } return completion; }
public void execute(String scriptName, String function, String arguments) { for (Script s : this) { if (s.getFile().equals(scriptName)) { if (s.getCompiledScript() == null) { InterpreterFactory.getFactory() .getScript(s.getFileName()) .invoke(s.getMain(), (Object) s.getMainArgs()); } else { try { s.getCompiledScript().eval(); } catch (ScriptException e) { e.printStackTrace(); } } } } }
private void removeAllAngularObjectInParagraph(String user, String paragraphId) { angularObjects = new HashMap<>(); List<InterpreterSetting> settings = factory.getInterpreterSettings(getId()); if (settings == null || settings.size() == 0) { return; } for (InterpreterSetting setting : settings) { InterpreterGroup intpGroup = setting.getInterpreterGroup(user, id); AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry(); if (registry instanceof RemoteAngularObjectRegistry) { // remove paragraph scope object ((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, paragraphId); // remove app scope object List<ApplicationState> appStates = getParagraph(paragraphId).getAllApplicationStates(); if (appStates != null) { for (ApplicationState app : appStates) { ((RemoteAngularObjectRegistry) registry) .removeAllAndNotifyRemoteProcess(id, app.getId()); } } } else { registry.removeAll(id, paragraphId); // remove app scope object List<ApplicationState> appStates = getParagraph(paragraphId).getAllApplicationStates(); if (appStates != null) { for (ApplicationState app : appStates) { registry.removeAll(id, app.getId()); } } } } }
private String getDefaultInterpreterName() { InterpreterSetting setting = factory.getDefaultInterpreterSetting(getId()); return null != setting ? setting.getName() : StringUtils.EMPTY; }
private boolean noteHasInterpreters() { return !factory.getInterpreterSettings(note.getId()).isEmpty(); }
public Interpreter getRepl(String name) { return factory.getInterpreter(user, note.getId(), name); }