/** * Ended JI, but not OK. */ public static int getNonOkCount(DbConn cnx) { return cnx.runSelectSingle("history_select_count_notended", Integer.class); }
public ResultSet runSelect(String query_key, Object... params) { return runSelect(false, query_key, params); }
public static void deleteGlobalParameter(DbConn cnx, int id) { QueryResult qr = cnx.runUpdate("globalprm_delete_by_id", id); if (qr.nbUpdated != 1) { cnx.setRollbackOnly(); throw new JqmAdminApiUserException("no item with ID " + id); } }
public static void deleteJobDef(DbConn cnx, int id) { int countRunning = cnx.runSelectSingle("ji_select_count_by_jd", Integer.class, id); if (countRunning > 0) { throw new JqmAdminApiUserException( "cannot delete a job definition with running instances. Disable it, wait for the end of all running instances, then retry."); } cnx.runUpdate("jdprm_delete_all_for_jd", id); QueryResult qr = cnx.runUpdate("jd_delete_by_id", id); if (qr.nbUpdated != 1) { cnx.setRollbackOnly(); throw new JqmAdminApiUserException("no item with ID " + id); } }
public static int create(DbConn cnx, String login, String password_hash, String password_salt, Calendar expiration, Boolean internal, String... role_names) { QueryResult r = cnx.runUpdate("user_insert", null, expiration, null, password_salt, internal, false, login, password_hash); int newId = r.getGeneratedId(); for (String s : role_names) { cnx.runUpdate("user_add_role_by_name", newId, s); } return newId; }
public CronScheduler(JqmEngine e) { this.node = e.getNode(); DbConn cnx = Helpers.getNewDbSession(); this.schedulerKeepAlive = Integer.parseInt(GlobalParameter.getParameter(cnx, "schedulerKeepAlive", "30000")); boolean shouldStart = !Boolean.parseBoolean(GlobalParameter.getParameter(cnx, "disableScheduler", "false")); if (!shouldStart) { jqmlogger.info("Scheduling functions are disabled"); return; } try { cnx.runUpdate("w_insert", this.node.getId()); cnx.commit(); jqmlogger.debug("This node is the first scheduling node to start inside the cluster"); } catch (DatabaseException ex) { // Ignore it (UK error). It means the line already exists inside the database. } cnx.close(); // Start the thread t = new Thread(this); t.start(); }
public JqmTester addParameter(String key, String value) { RuntimeParameter.create(cnx, ji, key, value); cnx.commit(); return this; }
@Override BookingStatus bookResource(JobInstance ji, DbConn cnx) { if (!ji.getJD().isHighlander()) { // Non-highlander JI do not need anything from this RM. return BookingStatus.BOOKED; } // Lock the definition in the DB - this is a convention for highlander JI between clients and engine. ResultSet rs = cnx.runSelect(true, "jd_select_by_id", ji.getJD().getId()); // We have the lock. Check if there are already running instances. Integer runningCount = cnx.runSelectSingle("ji_select_existing_highlander_2", Integer.class, ji.getJD().getId()); if (runningCount != 0) { // Already running, so skip this JI. cnx.closeQuietly(rs); // release the lock. return BookingStatus.FAILED; } // If here, no running instance and lock is held (release by commit done in the QP, rs is closed with connection). return BookingStatus.BOOKED; } }
/** * Create the query cache (with db-specific queries) */ private void initQueries() { DbConn cnx = getConn(); adapter.prepare(p, cnx._cnx); cnx.close(); }
@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; }
@Test public void testImportJobdefWithQueue() { // Init the default queue (don't start the engine!) Helpers.updateConfiguration(cnx); XmlJobDefParser.parse("target/payloads/jqm-test-xml/xmltestnewqueue.xml", cnx); cnx.commit(); List<JobDef> jd = JobDef.select(cnx, "jd_select_all"); Assert.assertEquals(2, jd.size()); // Was the queue created (and only once)? Queue q = Queue.select_key(cnx, "NewQueue"); Assert.assertEquals("Created from a jobdef import. Description should be set later", q.getDescription()); cnx.close(); }
public static List<RUser> select(DbConn cnx, String query_key, Object... args) { List<RUser> res = new ArrayList<>(); try { ResultSet rs = cnx.runSelect(query_key, args); while (rs.next()) { RUser tmp = new RUser(); tmp.id = rs.getInt(1); tmp.login = rs.getString(2); tmp.password = rs.getString(3); tmp.hashSalt = rs.getString(4); tmp.locked = rs.getBoolean(5); tmp.expirationDate = cnx.getCal(rs, 6); tmp.creationDate = cnx.getCal(rs, 7); tmp.lastModified = cnx.getCal(rs, 8); tmp.email = rs.getString(9); tmp.freeText = rs.getString(10); tmp.internal = rs.getBoolean(11); res.add(tmp); } } catch (SQLException e) { throw new DatabaseException(e); } return res; }
/** * Close all JDBC objects related to this connection. */ public void close() { if (transac_open) { try { this._cnx.rollback(); } catch (Exception e) { // Ignore. } } for (Statement s : toClose) { closeQuietly(s); } toClose.clear(); closeQuietly(_cnx); _cnx = null; }
private static RUserDto mapUser(ResultSet rs, int colShift, DbConn cnx) { try { RUserDto tmp = new RUserDto(); tmp.setId(rs.getInt(1 + colShift)); tmp.setLogin(rs.getString(2 + colShift)); tmp.setLocked(rs.getBoolean(5 + colShift)); tmp.setExpirationDate(cnx.getCal(rs, 6 + colShift)); tmp.setCreationDate(cnx.getCal(rs, 7 + colShift)); tmp.setEmail(rs.getString(9 + colShift)); tmp.setFreeText(rs.getString(10 + colShift)); tmp.setInternal(rs.getBoolean(11 + colShift)); return tmp; } catch (SQLException e) { throw new JqmAdminApiInternalException(e); } }
public CronScheduler(JqmEngine e) { this.node = e.getNode(); DbConn cnx = Helpers.getNewDbSession(); this.schedulerKeepAlive = Integer.parseInt(GlobalParameter.getParameter(cnx, "schedulerKeepAlive", "30000")); boolean shouldStart = !Boolean.parseBoolean(GlobalParameter.getParameter(cnx, "disableScheduler", "false")); if (!shouldStart) { jqmlogger.info("Scheduling functions are disabled"); return; } try { cnx.runUpdate("w_insert", this.node.getId()); cnx.commit(); jqmlogger.debug("This node is the first scheduling node to start inside the cluster"); } catch (DatabaseException ex) { // Ignore it (UK error). It means the line already exists inside the database. } cnx.close(); // Start the thread t = new Thread(this); t.start(); }
/** * Add a new job definition (see documentation) to the database.<br> * This can be called at any time (even after engine(s) start). */ public JqmAsyncTester addJobDefinition(TestJobDefinition description) { Common.createJobDef(cnx, description, queues); cnx.commit(); return this; }
@Override BookingStatus bookResource(JobInstance ji, DbConn cnx) { if (!ji.getJD().isHighlander()) { // Non-highlander JI do not need anything from this RM. return BookingStatus.BOOKED; } // Lock the definition in the DB - this is a convention for highlander JI between clients and engine. ResultSet rs = cnx.runSelect(true, "jd_select_by_id", ji.getJD().getId()); // We have the lock. Check if there are already running instances. Integer runningCount = cnx.runSelectSingle("ji_select_existing_highlander_2", Integer.class, ji.getJD().getId()); if (runningCount != 0) { // Already running, so skip this JI. cnx.closeQuietly(rs); // release the lock. return BookingStatus.FAILED; } // If here, no running instance and lock is held (release by commit done in the QP, rs is closed with connection). return BookingStatus.BOOKED; } }
public static JobInstance run(int jobInstanceId) { jqmlogger.debug("Single runner was asked to start with ID " + jobInstanceId); DbConn cnx = Helpers.getNewDbSession(); com.enioka.jqm.model.JobInstance jr = com.enioka.jqm.model.JobInstance.select_id(cnx, jobInstanceId); cnx.close(); if (jr == null) { throw new IllegalArgumentException("There is no JobRequest by ID " + jobInstanceId); } return run(jr); }