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));
}
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));
}
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());
}
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;
}
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;
}
Aggregations