use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class SchedulerService method updateJob.
public Job updateJob(JobScheduleRequest scheduleRequest) throws IllegalAccessException, IOException, SchedulerException {
Job job = getScheduler().getJob(scheduleRequest.getJobId());
if (job != null) {
scheduleRequest.getJobParameters().add(new JobScheduleParam(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER, job.getUserName()));
}
Job newJob = createJob(scheduleRequest);
removeJob(scheduleRequest.getJobId());
return newJob;
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class SchedulerService method createJob.
public Job createJob(JobScheduleRequest scheduleRequest) throws IOException, SchedulerException, IllegalAccessException {
// Used to determine if created by a RunInBackgroundCommand
boolean runInBackground = scheduleRequest.getSimpleJobTrigger() == null && scheduleRequest.getComplexJobTrigger() == null && scheduleRequest.getCronJobTrigger() == null;
if (!runInBackground && !getPolicy().isAllowed(SchedulerAction.NAME)) {
throw new SecurityException();
}
boolean hasInputFile = !StringUtils.isEmpty(scheduleRequest.getInputFile());
RepositoryFile file = null;
if (hasInputFile) {
try {
file = getRepository().getFile(scheduleRequest.getInputFile());
} catch (UnifiedRepositoryException ure) {
hasInputFile = false;
logger.warn(ure.getMessage(), ure);
}
}
// if we have an inputfile, generate job name based on that if the name is not passed in
if (hasInputFile && StringUtils.isEmpty(scheduleRequest.getJobName())) {
// $NON-NLS-1$
scheduleRequest.setJobName(file.getName().substring(0, file.getName().lastIndexOf(".")));
} else if (!StringUtils.isEmpty(scheduleRequest.getActionClass())) {
String actionClass = scheduleRequest.getActionClass().substring(scheduleRequest.getActionClass().lastIndexOf(".") + 1);
// $NON-NLS-1$
scheduleRequest.setJobName(actionClass);
} else if (!hasInputFile && StringUtils.isEmpty(scheduleRequest.getJobName())) {
// just make up a name
// $NON-NLS-1$
scheduleRequest.setJobName("" + System.currentTimeMillis());
}
if (hasInputFile) {
if (file == null) {
logger.error("Cannot find input source file " + scheduleRequest.getInputFile() + " Aborting schedule...");
throw new SchedulerException(new ServiceException("Cannot find input source file " + scheduleRequest.getInputFile()));
}
Map<String, Serializable> metadata = getRepository().getFileMetadata(file.getId());
if (metadata.containsKey(RepositoryFile.SCHEDULABLE_KEY)) {
boolean schedulable = BooleanUtils.toBoolean((String) metadata.get(RepositoryFile.SCHEDULABLE_KEY));
if (!schedulable) {
throw new IllegalAccessException();
}
}
}
if (scheduleRequest.getTimeZone() != null) {
updateStartDateForTimeZone(scheduleRequest);
}
Job job = null;
IJobTrigger jobTrigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
HashMap<String, Serializable> parameterMap = new HashMap<>();
for (JobScheduleParam param : scheduleRequest.getJobParameters()) {
parameterMap.put(param.getName(), param.getValue());
}
if (isPdiFile(file)) {
parameterMap = handlePDIScheduling(file, parameterMap, scheduleRequest.getPdiParameters());
}
parameterMap.put(LocaleHelper.USER_LOCALE_PARAM, LocaleHelper.getLocale());
if (hasInputFile) {
SchedulerOutputPathResolver outputPathResolver = getSchedulerOutputPathResolver(scheduleRequest);
String outputFile = outputPathResolver.resolveOutputFilePath();
String actionId = SchedulerResourceUtil.resolveActionId(scheduleRequest.getInputFile());
final String inputFile = scheduleRequest.getInputFile();
parameterMap.put(ActionUtil.QUARTZ_STREAMPROVIDER_INPUT_FILE, inputFile);
job = getScheduler().createJob(scheduleRequest.getJobName(), actionId, parameterMap, jobTrigger, new RepositoryFileStreamProvider(inputFile, outputFile, getAutoCreateUniqueFilename(scheduleRequest), getAppendDateFormat(scheduleRequest)));
} else {
// need to locate actions from plugins if done this way too (but for now, we're just on main)
String actionClass = scheduleRequest.getActionClass();
try {
@SuppressWarnings("unchecked") Class<IAction> iaction = getAction(actionClass);
job = getScheduler().createJob(scheduleRequest.getJobName(), iaction, parameterMap, jobTrigger);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
return job;
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class SchedulerService method pauseJob.
public JobState pauseJob(String jobId) throws SchedulerException {
Job job = getJob(jobId);
if (isScheduleAllowed() || PentahoSessionHolder.getSession().getName().equals(job.getUserName())) {
getScheduler().pauseJob(jobId);
}
job = getJob(jobId);
return job.getState();
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class SchedulerService method resumeJob.
public JobState resumeJob(String jobId) throws SchedulerException {
Job job = getJob(jobId);
if (isScheduleAllowed() || PentahoSessionHolder.getSession().getName().equals(job.getUserName())) {
getScheduler().resumeJob(jobId);
}
job = getJob(jobId);
return job.getState();
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class ScheduleExportUtilTest method testCreateJobScheduleRequest_NoStreamProvider.
@Test
public void testCreateJobScheduleRequest_NoStreamProvider() throws Exception {
String jobName = "JOB";
Job job = mock(Job.class);
SimpleJobTrigger trigger = mock(SimpleJobTrigger.class);
when(job.getJobTrigger()).thenReturn(trigger);
when(job.getJobName()).thenReturn(jobName);
Map<String, Serializable> params = new HashMap<>();
params.put("directory", "/home/admin");
params.put("transformation", "myTransform");
HashMap<String, String> pdiParams = new HashMap<>();
pdiParams.put("pdiParam", "pdiParamValue");
params.put(ScheduleExportUtil.RUN_PARAMETERS_KEY, pdiParams);
when(job.getJobParams()).thenReturn(params);
JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
assertNotNull(jobScheduleRequest);
assertEquals(jobName, jobScheduleRequest.getJobName());
assertEquals(trigger, jobScheduleRequest.getSimpleJobTrigger());
assertEquals("/home/admin/myTransform.ktr", jobScheduleRequest.getInputFile());
assertEquals("/home/admin/myTransform*", jobScheduleRequest.getOutputFile());
assertEquals("pdiParamValue", jobScheduleRequest.getPdiParameters().get("pdiParam"));
}
Aggregations