Search in sources :

Example 76 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class DefaultSchedulerServiceTest method testGetJobsAdminUser.

@Test
public void testGetJobsAdminUser() throws Exception {
    when(policy.isAllowed(anyString())).thenReturn(true);
    when(iPentahoSessionMock.getName()).thenReturn("admin");
    defaultSchedulerService.getJobs();
    verify(iSchedulerMock).getJobs((IJobFilter) filterCaptor.capture());
    IJobFilter filter = (IJobFilter) filterCaptor.getValue();
    assertNotNull(filter);
    List<Job> testJobs = getJobs();
    List<Job> filteredJobs = new ArrayList<>();
    for (Job job : testJobs) {
        if (filter.accept(job)) {
            filteredJobs.add(job);
            assertNotEquals("BlockoutAction", job.getJobName());
        }
    }
    assertEquals(10, filteredJobs.size());
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 77 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class DefaultSchedulerServiceTest method testGetJobsNonAdminUser.

@Test
public void testGetJobsNonAdminUser() throws Exception {
    when(policy.isAllowed(anyString())).thenReturn(false);
    when(iPentahoSessionMock.getName()).thenReturn("testUser1");
    defaultSchedulerService.getJobs();
    verify(iSchedulerMock).getJobs((IJobFilter) filterCaptor.capture());
    IJobFilter filter = (IJobFilter) filterCaptor.getValue();
    assertNotNull(filter);
    List<Job> testJobs = getJobs();
    List<Job> filteredJobs = new ArrayList<>();
    for (Job job : testJobs) {
        if (filter.accept(job)) {
            filteredJobs.add(job);
        }
    }
    assertEquals(1, filteredJobs.size());
    assertEquals("testJobName1", filteredJobs.get(0).getJobName());
    assertEquals("testUser1", filteredJobs.get(0).getUserName());
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 78 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class DefaultSchedulerService method getJobs.

/**
 * {@inheritDoc}
 */
public Job[] getJobs() throws SchedulerException {
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    IPentahoSession session = PentahoSessionHolder.getSession();
    String principalName = session.getName();
    Boolean canAdminister = PentahoSystem.get(IAuthorizationPolicy.class).isAllowed(ADMIN_PERM);
    return scheduler.getJobs(job -> {
        if (canAdminister) {
            return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals(job.getJobName());
        }
        return principalName.equals(job.getUserName());
    }).toArray(new Job[0]);
}
Also used : WebService(javax.jws.WebService) IBlockoutManager(org.pentaho.platform.api.scheduler2.IBlockoutManager) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) HashMap(java.util.HashMap) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) PentahoSessionHolder(org.pentaho.platform.engine.core.system.PentahoSessionHolder) Serializable(java.io.Serializable) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) Map(java.util.Map) Log(org.apache.commons.logging.Log) Job(org.pentaho.platform.api.scheduler2.Job) LogFactory(org.apache.commons.logging.LogFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Example 79 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class DefaultSchedulerService method createJob.

private String createJob(String jobName, Map<String, ParamValue> jobParams, JobTrigger trigger) throws SchedulerException {
    // $NON-NLS-1$
    logger.debug("Creating job with schedule " + trigger.toString());
    Job job = null;
    try {
        // $NON-NLS-1$
        IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
        Map<String, Serializable> properJobParams = toProperMap(jobParams);
        scheduler.validateJobParams(properJobParams);
        job = scheduler.createJob(jobName, getDefaultActionId(), properJobParams, trigger);
    } catch (SchedulerException e) {
        // temporary error logging.. this needs to become an aspect
        logger.error(e.getMessage(), e);
        throw e;
    }
    return job.getJobId();
}
Also used : Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Example 80 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class QuartzScheduler method createJob.

/**
 * {@inheritDoc}
 */
public Job createJob(String jobName, String actionId, Map<String, Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider) throws SchedulerException {
    if (StringUtils.isEmpty(actionId)) {
        // $NON-NLS-1$
        throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0003_ACTION_IS_NULL"));
    }
    if (jobParams == null) {
        jobParams = new HashMap<String, Serializable>();
    }
    jobParams.put(RESERVEDMAPKEY_ACTIONID, actionId);
    Job ret = createJob(jobName, jobParams, trigger, outputStreamProvider);
    // $NON-NLS-1$
    ret.setSchedulableClass("");
    return ret;
}
Also used : Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job)

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 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 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)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)8 JobConfig (com.google.cloud.video.transcoder.v1.JobConfig)8 VideoStream (com.google.cloud.video.transcoder.v1.VideoStream)8 Map (java.util.Map)8 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)8