Search in sources :

Example 26 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class RepositoryCleanerSystemListenerTest method doesNotRescheduleJob_IfFoundSame.

@Test
public void doesNotRescheduleJob_IfFoundSame() throws Exception {
    final String oldJobId = "oldJobId";
    Job oldJob = new Job();
    oldJob.setJobTrigger(Frequency.WEEKLY.createTrigger());
    oldJob.setJobId(oldJobId);
    when(scheduler.getJobs(any(IJobFilter.class))).thenReturn(Collections.singletonList(oldJob));
    prepareMp();
    listener.setExecute(Frequency.WEEKLY.getValue());
    assertTrue(listener.startup(null));
    verify(scheduler, never()).removeJob(oldJobId);
    verifyJobHaveNotCreated();
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 27 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzScheduler method getJobs.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public List<Job> getJobs(IJobFilter filter) throws SchedulerException {
    ArrayList<Job> jobs = new ArrayList<Job>();
    try {
        Scheduler scheduler = getQuartzScheduler();
        for (String groupName : scheduler.getJobGroupNames()) {
            for (String jobId : scheduler.getJobNames(groupName)) {
                for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
                    if ("MANUAL_TRIGGER".equals(trigger.getGroup())) {
                        continue;
                    }
                    Job job = new Job();
                    job.setGroupName(groupName);
                    JobDetail jobDetail = scheduler.getJobDetail(jobId, groupName);
                    if (jobDetail != null) {
                        job.setUserName(jobDetail.getGroup());
                        JobDataMap jobDataMap = jobDetail.getJobDataMap();
                        if (jobDataMap != null) {
                            Map<String, Serializable> wrappedMap = jobDataMap.getWrappedMap();
                            job.setJobParams(wrappedMap);
                        }
                    }
                    job.setJobId(jobId);
                    setJobTrigger(scheduler, job, trigger);
                    job.setJobName(QuartzJobKey.parse(jobId).getJobName());
                    setJobNextRun(job, trigger);
                    job.setLastRun(trigger.getPreviousFireTime());
                    if ((filter == null) || filter.accept(job)) {
                        jobs.add(job);
                    }
                }
            }
        }
    } catch (org.quartz.SchedulerException e) {
        throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0004_FAILED_TO_LIST_JOBS"), // $NON-NLS-1$
        e);
    }
    return jobs;
}
Also used : JobDataMap(org.quartz.JobDataMap) Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Scheduler(org.quartz.Scheduler) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) ArrayList(java.util.ArrayList) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job)

Example 28 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzScheduler method getJob.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public Job getJob(String jobId) throws SchedulerException {
    try {
        Scheduler scheduler = getQuartzScheduler();
        QuartzJobKey jobKey = QuartzJobKey.parse(jobId);
        String groupName = jobKey.getUserName();
        for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
            Job job = new Job();
            JobDetail jobDetail = scheduler.getJobDetail(jobId, groupName);
            if (jobDetail != null) {
                JobDataMap jobDataMap = jobDetail.getJobDataMap();
                if (jobDataMap != null) {
                    Map<String, Serializable> wrappedMap = jobDataMap.getWrappedMap();
                    job.setJobParams(wrappedMap);
                }
            }
            job.setJobId(jobId);
            setJobTrigger(scheduler, job, trigger);
            job.setUserName(jobDetail.getGroup());
            return job;
        }
    } catch (org.quartz.SchedulerException e) {
        throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0007_FAILED_TO_GET_JOB", jobId), // $NON-NLS-1$
        e);
    }
    return null;
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) Serializable(java.io.Serializable) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Scheduler(org.quartz.Scheduler) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) Job(org.pentaho.platform.api.scheduler2.Job)

Example 29 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method testGetJobs.

@Test
public void testGetJobs() throws SchedulerException {
    QuartzScheduler testGetJobsSchduler = new QuartzScheduler();
    Assert.assertEquals(0, testGetJobsSchduler.getJobs(null).size());
    String PARAM_KEY = "testGetJobsKey";
    jobParams.put(PARAM_KEY, "testParam1-value");
    Calendar calendar = Calendar.getInstance();
    int startingMin = calendar.get(Calendar.MINUTE);
    int startingSec = calendar.get(Calendar.SECOND) + 10;
    if (startingSec > 59) {
        startingSec = startingSec % 60;
        startingMin++;
        if (startingMin > 59) {
            startingMin = startingMin % 60;
        }
    }
    calendar.set(Calendar.MINUTE, startingMin);
    calendar.set(Calendar.SECOND, startingSec);
    SimpleJobTrigger jobTrigger = new SimpleJobTrigger(calendar.getTime(), null, 0, 0);
    testGetJobsSchduler.createJob("getJobsTestJob", TestAction.class, jobParams, jobTrigger);
    List<Job> jobs = testGetJobsSchduler.getJobs(null);
    Assert.assertEquals(1, jobs.size());
    Job theJob = jobs.get(0);
    Assert.assertTrue(theJob.getJobParams().containsKey(PARAM_KEY));
    Assert.assertTrue(theJob.getJobName().contains("getJobsTestJob"));
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Calendar(java.util.Calendar) TestQuartzScheduler(org.pentaho.platform.scheduler2.ws.test.TestQuartzScheduler) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 30 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method editJobTest.

@Test
public void editJobTest() throws SchedulerException {
    SimpleJobTrigger repeater = new SimpleJobTrigger();
    repeater.setStartTime(new Date());
    repeater.setRepeatInterval(2);
    repeater.setRepeatCount(20);
    Job job = scheduler.createJob("testName", TestAction.class, new HashMap<String, Serializable>(), repeater);
    sleep(3);
    Assert.assertTrue("Job did not run the correct number of times", TestAction.counter >= 2);
    repeater = new SimpleJobTrigger();
    repeater.setStartTime(new Date());
    repeater.setRepeatInterval(5);
    repeater.setRepeatCount(3);
    int count = TestAction.counter;
    System.out.println("updating job! " + new Date());
    scheduler.updateJob(job.getJobId(), new HashMap<String, Serializable>(), repeater);
    List<Job> jobs = scheduler.getJobs(null);
    Assert.assertEquals("Unexpected number of scheduled jobs", 1, jobs.size());
    SimpleJobTrigger simpleJobTrigger = (SimpleJobTrigger) jobs.get(0).getJobTrigger();
    Assert.assertEquals(5, simpleJobTrigger.getRepeatInterval());
    Assert.assertEquals(3, simpleJobTrigger.getRepeatCount());
    sleep(1);
    Assert.assertEquals("Job did not run the correct number of times", count + 1, TestAction.counter);
    count = TestAction.counter;
    sleep(3);
    Assert.assertEquals("Job ran unexpectedly", count, TestAction.counter);
    sleep(3);
    Assert.assertTrue("Job did not run the correct number of times", count < TestAction.counter);
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)94 Test (org.junit.Test)69 Serializable (java.io.Serializable)25 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)21 HashMap (java.util.HashMap)20 ArrayList (java.util.ArrayList)19 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)19 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)18 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)17 Date (java.util.Date)14 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)14 Job (com.google.cloud.video.transcoder.v1.Job)13 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)12 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 AudioStream (com.google.cloud.video.transcoder.v1.AudioStream)9 JobConfig (com.google.cloud.video.transcoder.v1.JobConfig)9 VideoStream (com.google.cloud.video.transcoder.v1.VideoStream)9 Map (java.util.Map)8 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)8