/** @see FlowService#executeJob(String, String, String, long, long, String) */ @Override public Job executeJob( Credentials credentials, String token, String name, String description, long flowInstanceId, long userId, String userEmail) { FlowDao flowDao = daoFactory.getFlowDao(); JobDao jobDao = daoFactory.getJobDao(); Flow flowInstance = flowDao.findById(flowInstanceId, false); Job job = new Job(); job.setToken(token); job.setName(name); job.setDescription(description); job.setFlow(flowInstance); job.setOwnerId(userId); job.setOwnerEmail(userEmail); SimpleCredentials simpleCreds = (SimpleCredentials) credentials; String serializedCreds = simpleCreds.getUserID() + ":" + new String(simpleCreds.getPassword()); job.setCredentials(serializedCreds); jobDao.makePersistent(job); jobScheduler.scheduleJob(job); job.setJobStatus(JobStatus.SCHEDULED); job.setScheduleTimestamp(new Date()); jobDao.makePersistent(job); jobStatusMonitor.start(job, notificationCreator); return job; }
@PostConstruct public void init() { logger.info("Initializing NEMA Flow Service..."); notificationCreator = new JobStatusNotificationCreator(daoFactory); try { headServer = meandreServerProxyFactory.getServerProxyInstance(flowServiceConfig.getHeadConfig(), true); } catch (MeandreServerException e) { throw new RuntimeException("Could not instantiate head server.", e); } flowServiceConfig.addChangeListener(this); // Any jobs marked as scheduled in the database will be put back in the // queue for execution. JobDao jobDao = daoFactory.getJobDao(); List<Job> scheduledJobs; try { Session session = jobDao.getSessionFactory().openSession(); jobDao.startManagedSession(session); scheduledJobs = jobDao.getJobsByStatus(Job.JobStatus.SCHEDULED); jobDao.endManagedSession(); session.close(); } catch (HibernateException e) { throw new RuntimeException("Problem searching for scheduled jobs" + " in the database.", e); } if (scheduledJobs != null && scheduledJobs.size() > 0) { logger.info( scheduledJobs.size() + " scheduled jobs found in the " + "database. Jobs will be rescheduled for execution."); } for (Job job : scheduledJobs) { jobScheduler.scheduleJob(job); jobStatusMonitor.start(job, notificationCreator); } }