use of org.opennms.netmgt.config.provisiond.RequisitionDef in project opennms by OpenNMS.
the class ImportSchedulerIT method createJobAndVerifyImportJobFactoryIsRegistered.
@Test
public void createJobAndVerifyImportJobFactoryIsRegistered() throws SchedulerException, InterruptedException {
RequisitionDef def = m_dao.getDefs().get(0);
JobDetail detail = new JobDetailImpl("test", ImportScheduler.JOB_GROUP, ImportJob.class, false, false);
detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource());
detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
class MyBoolWrapper {
volatile Boolean m_called = false;
public Boolean getCalled() {
return m_called;
}
public void setCalled(Boolean called) {
m_called = called;
}
}
final MyBoolWrapper callTracker = new MyBoolWrapper();
m_importScheduler.getScheduler().getListenerManager().addTriggerListener(new TriggerListener() {
@Override
public String getName() {
return "TestTriggerListener";
}
@Override
public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
LOG.info("triggerComplete called on trigger listener");
callTracker.setCalled(true);
}
@Override
public void triggerFired(Trigger trigger, JobExecutionContext context) {
LOG.info("triggerFired called on trigger listener");
Job jobInstance = context.getJobInstance();
if (jobInstance instanceof ImportJob) {
Assert.assertNotNull(((ImportJob) jobInstance).getProvisioner());
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.URL));
Assert.assertEquals("dns://localhost/localhost", context.getJobDetail().getJobDataMap().get(ImportJob.URL));
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.RESCAN_EXISTING));
Assert.assertEquals("dbonly", context.getJobDetail().getJobDataMap().get(ImportJob.RESCAN_EXISTING));
}
callTracker.setCalled(true);
}
@Override
public void triggerMisfired(Trigger trigger) {
LOG.info("triggerMisFired called on trigger listener");
callTracker.setCalled(true);
}
@Override
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
LOG.info("vetoJobExecution called on trigger listener");
callTracker.setCalled(true);
return false;
}
});
Calendar testCal = Calendar.getInstance();
testCal.add(Calendar.SECOND, 5);
SimpleTriggerImpl trigger = new SimpleTriggerImpl("test", ImportScheduler.JOB_GROUP, testCal.getTime());
m_importScheduler.getScheduler().scheduleJob(detail, trigger);
m_importScheduler.start();
int callCheck = 0;
while (!callTracker.getCalled() && callCheck++ < 2) {
Thread.sleep(5000);
}
//TODO: need to fix the interrupted exception that occurs in the provisioner
}
use of org.opennms.netmgt.config.provisiond.RequisitionDef in project opennms by OpenNMS.
the class ImportScheduler method buildImportSchedule.
/**
* <p>buildImportSchedule</p>
*/
protected void buildImportSchedule() {
synchronized (m_lock) {
Iterator<RequisitionDef> it = m_configDao.getDefs().iterator();
while (it.hasNext()) {
RequisitionDef def = it.next();
JobDetail detail = null;
CronTriggerImpl trigger = null;
try {
detail = new JobDetailImpl(def.getImportName().orElse(null), JOB_GROUP, ImportJob.class, false, false);
detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource());
detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
trigger = new CronTriggerImpl(def.getImportName().orElse(null), JOB_GROUP, def.getCronSchedule().orElse(null));
trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
getScheduler().scheduleJob(detail, trigger);
} catch (ParseException e) {
LOG.error("buildImportSchedule: {}", e.getLocalizedMessage(), e);
} catch (SchedulerException e) {
LOG.error("buildImportSchedule: {}", e.getLocalizedMessage(), e);
}
}
}
printCurrentSchedule();
}
Aggregations