Search in sources :

Example 1 with IBackgroundExecutionStreamProvider

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

the class QuartzSchedulerIT method fireJobCompletedTest.

@Test
public void fireJobCompletedTest() throws Exception {
    final IAction actionBean = mock(IAction.class);
    final String actionUser = "actionUser";
    final ISchedulerListener schedulerListener = mock(ISchedulerListener.class);
    scheduler.addListener(schedulerListener);
    final Map<String, Serializable> params = new HashMap<>();
    final IBackgroundExecutionStreamProvider streamProvider = mock(IBackgroundExecutionStreamProvider.class);
    scheduler.fireJobCompleted(actionBean, actionUser, params, streamProvider);
    verify(schedulerListener, times(1)).jobCompleted(eq(actionBean), eq(actionUser), eq(params), eq(streamProvider));
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ISchedulerListener(org.pentaho.platform.api.scheduler2.ISchedulerListener) Test(org.junit.Test)

Example 2 with IBackgroundExecutionStreamProvider

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

the class QuartzSchedulerIT method createJobTest.

@Test
public void createJobTest() throws Exception {
    String actionId = "actionId";
    ComplexJobTrigger trigger = getComplexJobTrigger();
    IBackgroundExecutionStreamProvider outputStreamProvider = mock(IBackgroundExecutionStreamProvider.class);
    final Job job = scheduler.createJob(JOB_NAME, actionId, null, trigger, outputStreamProvider);
    assertNotNull(job);
    assertEquals(Job.JobState.NORMAL, job.getState());
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
    assertEquals(actionId, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
    assertEquals(outputStreamProvider, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
    assertNotNull(job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
    assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
    assertEquals(USER_NAME, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 3 with IBackgroundExecutionStreamProvider

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

the class QuartzSchedulerIT method createJobTest_ForUser.

@Test
public void createJobTest_ForUser() throws Exception {
    String actionId = "actionId";
    ComplexJobTrigger trigger = getComplexJobTrigger();
    IBackgroundExecutionStreamProvider outputStreamProvider = mock(IBackgroundExecutionStreamProvider.class);
    Map<String, Serializable> paramMap = new HashMap<>();
    paramMap.put(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER, "ninja");
    final Job job = scheduler.createJob(JOB_NAME, paramMap, trigger, outputStreamProvider);
    assertNotNull(job);
    assertEquals("ninja", job.getUserName());
    assertEquals(Job.JobState.NORMAL, job.getState());
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 4 with IBackgroundExecutionStreamProvider

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

the class QuartzScheduler method createJob.

/**
 * {@inheritDoc}
 */
public Job createJob(String jobName, Class<? extends IAction> action, Map<String, Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider) throws SchedulerException {
    if (action == null) {
        // $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_ACTIONCLASS, action.getName());
    Job ret = createJob(jobName, jobParams, trigger, outputStreamProvider);
    ret.setSchedulableClass(action.getName());
    return ret;
}
Also used : Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job)

Example 5 with IBackgroundExecutionStreamProvider

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

the class DefaultActionInvoker method invokeActionImpl.

/**
 * Invokes the provided {@link IAction} as the provided {@code actionUser}.
 *
 * @param actionBean the {@link IAction} being invoked
 * @param actionUser The user invoking the {@link IAction}
 * @param params     the {@link Map} or parameters needed to invoke the {@link IAction}
 * @return the {@link IActionInvokeStatus} object containing information about the action invocation
 * @throws Exception when the {@code IAction} cannot be invoked for some reason.
 */
protected IActionInvokeStatus invokeActionImpl(final IAction actionBean, final String actionUser, final Map<String, Serializable> params) throws Exception {
    final String workItemUid = ActionUtil.extractUid(params);
    if (actionBean == null || params == null) {
        final String failureMessage = Messages.getInstance().getCantInvokeNullAction();
        WorkItemLifecycleEventUtil.publish(workItemUid, params, WorkItemLifecyclePhase.FAILED, failureMessage);
        throw new ActionInvocationException(failureMessage);
    }
    WorkItemLifecycleEventUtil.publish(workItemUid, params, WorkItemLifecyclePhase.IN_PROGRESS);
    if (logger.isDebugEnabled()) {
        logger.debug(Messages.getInstance().getRunningInBackgroundLocally(actionBean.getClass().getName(), params));
    }
    // set the locale, if not already set
    if (params.get(LocaleHelper.USER_LOCALE_PARAM) == null || StringUtils.isEmpty(params.get(LocaleHelper.USER_LOCALE_PARAM).toString())) {
        params.put(LocaleHelper.USER_LOCALE_PARAM, LocaleHelper.getLocale());
    }
    // remove the scheduling infrastructure properties
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONCLASS);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONID);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_ACTIONUSER);
    // build the stream provider
    final IBackgroundExecutionStreamProvider streamProvider = getStreamProvider(params);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_STREAMPROVIDER);
    ActionUtil.removeKeyFromMap(params, ActionUtil.INVOKER_UIPASSPARAM);
    final ActionRunner actionBeanRunner = new ActionRunner(actionBean, actionUser, params, streamProvider);
    final IActionInvokeStatus status = new ActionInvokeStatus();
    status.setStreamProvider(streamProvider);
    boolean requiresUpdate = false;
    try {
        if ((StringUtil.isEmpty(actionUser)) || (actionUser.equals("system session"))) {
            // $NON-NLS-1$
            // For now, don't try to run quartz jobs as authenticated if the user
            // that created the job is a system user. See PPP-2350
            requiresUpdate = SecurityHelper.getInstance().runAsAnonymous(actionBeanRunner);
        } else {
            requiresUpdate = SecurityHelper.getInstance().runAsUser(actionUser, actionBeanRunner);
        }
    } catch (final Throwable t) {
        WorkItemLifecycleEventUtil.publish(workItemUid, params, WorkItemLifecyclePhase.FAILED, t.toString());
        status.setThrowable(t);
    }
    status.setRequiresUpdate(requiresUpdate);
    // Set the execution Status
    status.setExecutionStatus(actionBean.isExecutionSuccessful());
    return status;
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) IActionInvokeStatus(org.pentaho.platform.api.action.IActionInvokeStatus) ActionInvokeStatus(org.pentaho.platform.action.ActionInvokeStatus) IActionInvokeStatus(org.pentaho.platform.api.action.IActionInvokeStatus) ActionInvocationException(org.pentaho.platform.api.action.ActionInvocationException)

Aggregations

IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)13 Serializable (java.io.Serializable)12 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 IAction (org.pentaho.platform.api.action.IAction)4 Job (org.pentaho.platform.api.scheduler2.Job)4 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)3 RepositoryFileStreamProvider (org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ActionInvocationException (org.pentaho.platform.api.action.ActionInvocationException)2 IActionInvokeStatus (org.pentaho.platform.api.action.IActionInvokeStatus)2 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)2 ISecurityHelper (org.pentaho.platform.api.engine.ISecurityHelper)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2