@Override public String toString() { return "Trigger Id: " + getTriggerId() + ", Description: " + getDescription(); }
@Override public void updateTrigger(final Trigger t) throws TriggerLoaderException { logger.info("Updating trigger " + t.getTriggerId() + " into db."); t.setLastModifyTime(System.currentTimeMillis()); updateTrigger(t, this.defaultEncodingType); }
public void updateTrigger(final Trigger t) throws TriggerManagerException { logger.info("Updating trigger " + t + " in TriggerManager"); synchronized (this.syncObj) { this.runnerThread.deleteTrigger(triggerIdMap.get(t.getTriggerId())); this.runnerThread.addTrigger(t); triggerIdMap.put(t.getTriggerId(), t); try { this.triggerLoader.updateTrigger(t); } catch (final TriggerLoaderException e) { throw new TriggerManagerException(e); } } }
@Override public synchronized void removeTrigger(final Trigger s) throws TriggerLoaderException { this.triggers.remove(s.getTriggerId()); }
@Override public void removeTrigger(final Trigger s) throws TriggerLoaderException { this.triggers.remove(s.getTriggerId()); }
@Override public void updateTrigger(final Trigger t) throws TriggerLoaderException { this.triggers.put(t.getTriggerId(), t); }
public void insertTrigger(final Trigger t) throws TriggerManagerException { logger.info("Inserting trigger " + t + " in TriggerManager"); synchronized (this.syncObj) { try { this.triggerLoader.addTrigger(t); } catch (final TriggerLoaderException e) { throw new TriggerManagerException(e); } this.runnerThread.addTrigger(t); triggerIdMap.put(t.getTriggerId(), t); } }
@Override public void removeTrigger(final Trigger t) throws TriggerLoaderException { logger.info("Removing trigger " + t.toString() + " from db."); try { final int removes = this.dbOperator.update(REMOVE_TRIGGER, t.getTriggerId()); if (removes == 0) { throw new TriggerLoaderException("No trigger has been removed."); } } catch (final SQLException ex) { throw new TriggerLoaderException("Remove trigger " + t.getTriggerId() + " from db failed. ", ex); } }
@Override public void start() throws TriggerManagerException { try { // expect loader to return valid triggers final List<Trigger> triggers = this.triggerLoader.loadTriggers(); for (final Trigger t : triggers) { this.runnerThread.addTrigger(t); triggerIdMap.put(t.getTriggerId(), t); } } catch (final Exception e) { logger.error(e); throw new TriggerManagerException(e); } this.runnerThread.start(); }
public void removeTrigger(final Trigger t) throws TriggerManagerException { logger.info("Removing trigger " + t + " from TriggerManager"); synchronized (this.syncObj) { this.runnerThread.deleteTrigger(t); triggerIdMap.remove(t.getTriggerId()); try { t.stopCheckers(); this.triggerLoader.removeTrigger(t); } catch (final TriggerLoaderException e) { throw new TriggerManagerException(e); } } }
@Override public void addTrigger(final Trigger t) throws TriggerLoaderException { t.setTriggerId(this.idIndex++); this.triggers.put(t.getTriggerId(), t); }
@Override public synchronized void updateTrigger(final Trigger t) throws TriggerLoaderException { t.setLastModifyTime(System.currentTimeMillis()); this.triggers.put(t.getTriggerId(), t); }
@Override public synchronized void addTrigger(final Trigger t) throws TriggerLoaderException { t.setTriggerId(this.triggerCount); t.setLastModifyTime(System.currentTimeMillis()); this.triggers.put(t.getTriggerId(), t); this.triggerCount++; }
/** * TODO: Don't understand why we need synchronized here. */ @Override public synchronized void addTrigger(final Trigger t) throws TriggerLoaderException { logger.info("Inserting trigger " + t.toString() + " into db."); final SQLTransaction<Long> insertAndGetLastID = transOperator -> { transOperator.update(ADD_TRIGGER, DateTime.now().getMillis()); // This commit must be called in order to unlock trigger table and have last insert ID. transOperator.getConnection().commit(); return transOperator.getLastInsertId(); }; try { final long id = this.dbOperator.transaction(insertAndGetLastID); t.setTriggerId((int) id); updateTrigger(t); logger.info("uploaded trigger " + t.getDescription()); } catch (final SQLException ex) { logger.error("Adding Trigger " + t.getTriggerId() + " failed."); throw new TriggerLoaderException("trigger id is not properly created.", ex); } }
private void updateTrigger(final Trigger t, final EncodingType encType) throws TriggerLoaderException { final String json = JSONUtils.toJSON(t.toJson()); byte[] data = null; try { final byte[] stringData = json.getBytes("UTF-8"); data = stringData; if (encType == EncodingType.GZIP) { data = GZIPUtils.gzipBytes(stringData); } logger.debug( "NumChars: " + json.length() + " UTF-8:" + stringData.length + " Gzip:" + data.length); } catch (final IOException e) { logger.error("Trigger encoding fails", e); throw new TriggerLoaderException("Error encoding the trigger " + t.toString(), e); } try { final int updates = this.dbOperator .update(UPDATE_TRIGGER, t.getSource(), t.getLastModifyTime(), encType.getNumVal(), data, t.getTriggerId()); if (updates == 0) { throw new TriggerLoaderException("No trigger has been updated."); } } catch (final SQLException ex) { logger.error("Updating Trigger " + t.getTriggerId() + " failed."); throw new TriggerLoaderException("DB Trigger update failed. ", ex); } }
@Override public void insertSchedule(final Schedule s) throws ScheduleManagerException { final Trigger t = scheduleToTrigger(s); try { this.triggerManager.insertTrigger(t, t.getSubmitUser()); s.setScheduleId(t.getTriggerId()); } catch (final TriggerManagerException e) { throw new ScheduleManagerException("Failed to insert new schedule!", e); } }
} else { logger.info("NextCheckTime did not change. Setting status to expired for trigger" + t.getTriggerId()); t.setStatus(TriggerStatus.EXPIRED);
@Test public void testRemoveTriggers() throws Exception { final Trigger t1 = createTrigger("testProj1", "testFlow1", "source1"); final Trigger t2 = createTrigger("testProj2", "testFlow2", "source2"); this.loader.addTrigger(t1); this.loader.addTrigger(t2); List<Trigger> ts = this.loader.loadTriggers(); assertTrue(ts.size() == 2); this.loader.removeTrigger(t2); ts = this.loader.loadTriggers(); assertTrue(ts.size() == 1); assertTrue(ts.get(0).getTriggerId() == t1.getTriggerId()); }
private void checkAllTriggers() throws TriggerManagerException { // sweep through the rest of them for (final Trigger t : this.triggers) { try { TriggerManager.this.scannerStage = "Checking for trigger " + t.getTriggerId(); if (t.getStatus().equals(TriggerStatus.READY)) { /** * Prior to this change, expiration condition should never be called though * we have some related code here. ExpireCondition used the same BasicTimeChecker * as triggerCondition do. As a consequence, we need to figure out a way to distinguish * the previous ExpireCondition and this commit's ExpireCondition. */ if (t.getExpireCondition().getExpression().contains("EndTimeChecker") && t .expireConditionMet()) { onTriggerPause(t); } else if (t.triggerConditionMet()) { onTriggerTrigger(t); } } if (t.getStatus().equals(TriggerStatus.EXPIRED) && t.getSource().equals("azkaban")) { removeTrigger(t); } else { t.updateNextCheckTime(); } } catch (final Throwable th) { //skip this trigger, moving on to the next one logger.error("Failed to process trigger with id : " + t, th); } } }
@Test public void testAddTrigger() throws Exception { final Trigger t1 = createTrigger("testProj1", "testFlow1", "source1"); final Trigger t2 = createTrigger("testProj2", "testFlow2", "source2"); this.loader.addTrigger(t1); List<Trigger> ts = this.loader.loadTriggers(); assertTrue(ts.size() == 1); final Trigger t3 = ts.get(0); assertTrue(t3.getSource().equals("source1")); this.loader.addTrigger(t2); ts = this.loader.loadTriggers(); assertTrue(ts.size() == 2); for (final Trigger t : ts) { if (t.getTriggerId() == t2.getTriggerId()) { t.getSource().equals(t2.getSource()); } } }