Search in sources :

Example 1 with Job

use of org.pentaho.platform.api.scheduler2.Job in project pentaho-platform by pentaho.

the class QuartzJobKey method parse.

/**
 * Parses an existing jobId into a {@link QuartzJobKey}
 *
 * @param jobId
 *          an existing jobId
 * @return a quartz job key
 * @throws SchedulerException
 */
public static QuartzJobKey parse(String jobId) throws SchedulerException {
    String delimiter = jobId.contains("\t") || jobId.isEmpty() ? "\t" : ":";
    // $NON-NLS-1$
    String[] elements = jobId.split(delimiter);
    if (elements == null || elements.length < 3) {
        throw new SchedulerException(MessageFormat.format(Messages.getInstance().getErrorString("QuartzJobKey.ERROR_0002"), // $NON-NLS-1$
        jobId));
    }
    QuartzJobKey key = new QuartzJobKey();
    key.userName = elements[0];
    key.jobName = elements[1];
    try {
        key.timeInMillis = Long.parseLong(elements[2]);
    } catch (NumberFormatException ex) {
        throw new SchedulerException(MessageFormat.format(Messages.getInstance().getErrorString("QuartzJobKey.ERROR_0002"), // $NON-NLS-1$
        jobId));
    }
    return key;
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException)

Example 2 with Job

use of org.pentaho.platform.api.scheduler2.Job in project pravega by pravega.

the class RemoteSequential method newJob.

private Job newJob(String id, String className, String methodName) {
    Map<String, String> labels = new HashMap<>(1);
    labels.put("testMethodName", methodName);
    // This can be used to set environment variables while executing the job on Metronome.
    Map<String, String> env = new HashMap<>(2);
    env.put("masterIP", System.getProperty("masterIP"));
    env.put("env2", "value102");
    Artifact art = new Artifact();
    // It caches the artifacts, disabling it for now.
    art.setCache(false);
    // jar is not executable.
    art.setExecutable(false);
    art.setExtract(false);
    art.setUri(System.getProperty("testArtifactUrl", "InvalidTestArtifactURL"));
    Restart restart = new Restart();
    // the tests are expected to finish in 2 mins, this can be changed to
    restart.setActiveDeadlineSeconds(120);
    // a higher value if required.
    restart.setPolicy("NEVER");
    Run run = new Run();
    run.setArtifacts(Collections.singletonList(art));
    run.setCmd("docker run --rm -v $(pwd):/data " + System.getProperty("dockerImageRegistry") + "/java:8 java" + " -DmasterIP=" + LoginClient.MESOS_MASTER + " -DskipServiceInstallation=" + Utils.isSkipServiceInstallationEnabled() + " -cp /data/pravega-test-system-" + System.getProperty("testVersion") + ".jar io.pravega.test.system.SingleJUnitTestRunner " + className + "#" + methodName + " > server.log 2>&1" + "; exit $?");
    // CPU shares.
    run.setCpus(0.5);
    // amount of memory required for running test in MB.
    run.setMem(512.0);
    run.setDisk(50.0);
    run.setEnv(env);
    run.setMaxLaunchDelay(3600);
    run.setRestart(restart);
    run.setUser("root");
    Job job = new Job();
    job.setId(id);
    job.setDescription(id);
    job.setLabels(labels);
    job.setRun(run);
    return job;
}
Also used : HashMap(java.util.HashMap) Run(io.pravega.test.system.framework.metronome.model.v1.Run) Restart(io.pravega.test.system.framework.metronome.model.v1.Restart) Job(io.pravega.test.system.framework.metronome.model.v1.Job) Artifact(io.pravega.test.system.framework.metronome.model.v1.Artifact)

Example 3 with Job

use of org.pentaho.platform.api.scheduler2.Job in project pentaho-platform by pentaho.

the class RepositoryCleanerSystemListenerTest method removesJobs_WhenDisabled.

@Test
public void removesJobs_WhenDisabled() throws Exception {
    final String jobId = "jobId";
    Job job = new Job();
    job.setJobId(jobId);
    when(scheduler.getJobs(any(IJobFilter.class))).thenReturn(Collections.singletonList(job));
    prepareMp();
    listener.setGcEnabled(false);
    assertTrue(listener.startup(null));
    verifyJobRemoved(jobId);
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 4 with Job

use of org.pentaho.platform.api.scheduler2.Job in project pentaho-platform by pentaho.

the class RepositoryCleanerSystemListenerTest method reschedulesJob_IfFoundDifferent.

@Test
public void reschedulesJob_IfFoundDifferent() throws Exception {
    final String oldJobId = "oldJobId";
    Job oldJob = new Job();
    oldJob.setJobTrigger(new CronJobTrigger());
    oldJob.setJobId(oldJobId);
    when(scheduler.getJobs(any(IJobFilter.class))).thenReturn(Collections.singletonList(oldJob));
    prepareMp();
    listener.setExecute(Frequency.NOW.getValue());
    assertTrue(listener.startup(null));
    verifyJobRemoved(oldJobId);
    verifyJobCreated(Frequency.NOW);
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Job(org.pentaho.platform.api.scheduler2.Job) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 5 with Job

use of org.pentaho.platform.api.scheduler2.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)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)94 Test (org.junit.Test)74 Serializable (java.io.Serializable)29 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)26 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)24 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)23 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)21 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Date (java.util.Date)17 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)15 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)14 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)14 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)13 Response (javax.ws.rs.core.Response)10 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)9 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)9 JobScheduleParam (org.pentaho.platform.web.http.api.resources.JobScheduleParam)9 CronTrigger (org.quartz.CronTrigger)9 Trigger (org.quartz.Trigger)8