static void sendEndMessage(JobInstance ji) { try { String message = "The Job number " + ji.getId() + " finished correctly\n\n" + "Job description:\n" + "\n" + "- Parent: " + ji.getParentId() + "\n" + "- User name: " + ji.getUserName() + "\n" + "- Session ID: " + ji.getSessionID() + "\n" + "\n" + "Best regards,\n"; sendMessage(ji.getEmail(), "[JQM] Job: " + ji.getId() + " ENDED", message, "mail/default"); } catch (Exception e) { jqmlogger.warn("Could not send email. Job has nevertheless run correctly", e); } }
@Override public String keyword1() { return this.ji.getKeyword1(); }
@Override public String getKeyword2() { return this.ji.getKeyword2(); }
/** * Create an History object from a {@link JobInstance}. * */ public static void create(DbConn cnx, JobInstance ji, State finalState, Calendar endDate) { JobDef jd = ji.getJD(); Node n = ji.getNode(); Queue q = ji.getQ(); if (endDate == null) { cnx.runUpdate("history_insert", ji.getId(), jd.getApplication(), jd.getApplicationName(), ji.getAttributionDate(), ji.getEmail(), ji.getCreationDate(), ji.getExecutionDate(), jd.isHighlander(), ji.getApplication(), ji.getKeyword1(), ji.getKeyword2(), ji.getKeyword3(), ji.getModule(), jd.getKeyword1(), jd.getKeyword2(), jd.getKeyword3(), jd.getModule(), n == null ? null : n.getName(), ji.getParentId(), ji.getProgress(), q == null ? null : q.getName(), 0, ji.getSessionID(), finalState.toString(), ji.getUserName(), ji.getJdId(), n == null ? null : n.getId(), ji.getQueue(), ji.isFromSchedule(), ji.getPriority()); } else { cnx.runUpdate("history_insert_with_end_date", ji.getId(), jd.getApplication(), jd.getApplicationName(), ji.getAttributionDate(), ji.getEmail(), endDate, ji.getCreationDate(), ji.getExecutionDate(), jd.isHighlander(), ji.getApplication(), ji.getKeyword1(), ji.getKeyword2(), ji.getKeyword3(), ji.getModule(), jd.getKeyword1(), jd.getKeyword2(), jd.getKeyword3(), jd.getModule(), n.getName(), ji.getParentId(), ji.getProgress(), q.getName(), 0, ji.getSessionID(), finalState.toString(), ji.getUserName(), ji.getJdId(), ji.getNode().getId(), ji.getQueue(), ji.isFromSchedule(), ji.getPriority()); } }
pb.directory(new File(this.ji.getNode().getRepo())); pb.redirectErrorStream(false); env.put("JQM_JD_APPLICATION_NAME", this.ji.getJD().getApplicationName()); env.put("JQM_JD_KEYWORD_1", this.ji.getJD().getKeyword1() != null ? this.ji.getJD().getKeyword1() : ""); env.put("JQM_JD_KEYWORD_2", this.ji.getJD().getKeyword2() != null ? this.ji.getJD().getKeyword2() : ""); env.put("JQM_JD_KEYWORD_3", this.ji.getJD().getKeyword3() != null ? this.ji.getJD().getKeyword3() : ""); env.put("JQM_JD_MODULE", this.ji.getJD().getModule() != null ? this.ji.getJD().getModule() : null); env.put("JQM_JD_PRIORITY", this.ji.getJD().getPriority() != null ? this.ji.getJD().getPriority().toString() : "0"); env.put("JQM_JI_ID", this.ji.getId() + ""); env.put("JQM_JI_KEYWORD_1", this.ji.getKeyword1() != null ? this.ji.getKeyword1() : ""); env.put("JQM_JI_KEYWORD_2", this.ji.getKeyword2() != null ? this.ji.getKeyword2() : ""); env.put("JQM_JI_KEYWORD_3", this.ji.getKeyword3() != null ? this.ji.getKeyword3() : ""); env.put("JQM_JI_MODULE", this.ji.getModule() != null ? this.ji.getModule() : ""); env.put("JQM_JI_USER_NAME", this.ji.getUserName() != null ? this.ji.getUserName() : ""); env.put("JQM_JI_PARENT_ID", this.ji.getParentId() + ""); env.put("JQM_JI_TEMP_DIR", this.tmpDir.getAbsolutePath()); env.put("JQM_JI_DELIVERY_DIR", this.deliveryDir.getAbsolutePath()); env.put("JQM_NODE_NAME", this.ji.getNode().getName()); env.put("JQM_NODE_APPLICATION_ROOT", this.ji.getNode().getRepo()); env.put("JQM_NODE_LOG_LEVEL", this.ji.getNode().getRootLogLevel()); env.put("JQM_Q_NAME", this.ji.getQ().getName()); env.putAll(ji.getEnvVarCache()); jqmlogger.debug("Starting process for shell payload " + this.ji.getId() + " - arguments: " + args.toString());
@Override public Integer getId() { return this.job.getId(); }
@Override public Integer enqueue(String applicationName, String user, String mail, String sessionId, String application, String module, String keyword1, String keyword2, String keyword3, Map<String, String> parameters) { JobRequest jr = new JobRequest(applicationName, user, mail); jr.setApplicationName(applicationName); jr.setUser(user == null ? ji.getUserName() : user); jr.setEmail(mail); jr.setSessionID(sessionId == null ? this.ji.getSessionID() : sessionId); jr.setApplication(application == null ? this.ji.getJD().getApplication() : application); jr.setModule(module == null ? this.ji.getJD().getModule() : module); jr.setKeyword1(keyword1); jr.setKeyword2(keyword2); jr.setKeyword3(keyword3); jr.setParentID(this.ji.getId()); if (parameters != null) { jr.setParameters(parameters); } return getJqmClient().enqueue(jr); }
@Override public String applicationName() { return this.ji.getJD().getApplicationName(); }
@Override public Integer addDeliverable(String path, String fileLabel) { DbConn cnx = Helpers.getNewDbSession(); try { String outputRoot = this.ji.getNode().getDlRepo(); String ext = FilenameUtils.getExtension(path); String relDestPath = ji.getJD().getApplicationName() + "/" + ji.getId() + "/" + UUID.randomUUID() + "." + ext; String absDestPath = FilenameUtils.concat(outputRoot, relDestPath); String fileName = FilenameUtils.getName(path); jqmlogger.debug("A deliverable is added. Stored as " + absDestPath + ". Initial name: " + fileName); FileUtils.moveFile(new File(path), new File(absDestPath)); cnx.commit(); int res = Helpers.createDeliverable(relDestPath, fileName, fileLabel, this.ji.getId(), cnx); cnx.commit(); return res; } catch (IOException e) { throw new JqmClientException(e); } finally { Helpers.closeQuietly(cnx); } }
public RunningExternalJobInstance(DbConn cnx, JobInstance job, QueuePoller qp) { this.jobId = job.getId(); this.ji = job; this.qp = qp; opts = job.getJD().getJavaOpts() == null ? GlobalParameter.getParameter(cnx, "defaultExternalOpts", "-Xms32m -Xmx128m -XX:MaxPermSize=64m") : job.getJD().getJavaOpts(); killCheckPeriodMs = Integer.parseInt(GlobalParameter.getParameter(cnx, "internalPollingPeriodMs", "1000")); logFile = "./logs"; logFile = FilenameUtils.concat(logFile, StringUtils.leftPad("" + jobId, 10, "0") + ".log"); }
@Override public File getWorkDir() { File f = new File(FilenameUtils.concat(ji.getNode().getTmpDirectory(), Integer.toString(this.ji.getId()))); if (!f.isDirectory()) { try { FileUtils.forceMkdir(f); } catch (Exception e) { throw new JqmRuntimeException("Could not create work directory", e); } } return f; }
/** * Returns all the URL that should be inside the classpath. This includes the jar itself if any. * * @throws JqmPayloadException */ private URL[] getClasspath(JobInstance ji, JobRunnerCallback cb) throws JqmPayloadException { switch (ji.getJD().getPathType()) { case MAVEN: return mavenResolver.resolve(ji); case MEMORY: return new URL[0]; case FS: default: return fsResolver.getLibraries(ji.getNode(), ji.getJD()); } }
@Override public Long getRunTimeSeconds() { if (this.ji.getExecutionDate() == null) { DbConn cnx = Helpers.getNewDbSession(); this.ji.setExecutionDate(cnx.runSelectSingle("ji_select_execution_date_by_id", Calendar.class, this.ji.getId())); cnx.close(); } if (this.ji.getExecutionDate() == null) { return 0L; } return (Calendar.getInstance().getTimeInMillis() - this.ji.getExecutionDate().getTimeInMillis()) / 1000; }
@Override public String sessionID() { return this.ji.getSessionID(); }
@Override public String getKeyword3() { return this.ji.getKeyword3(); }
@Override public String getUser() { return this.ji.getUserName(); }
@Override public Calendar getEnqueueDate() { return this.ji.getCreationDate(); }
@Override public String getModule() { return this.ji.getModule(); }