use of org.pentaho.platform.web.http.api.resources.SchedulerResource in project pentaho-platform by pentaho.
the class SolutionImportHandler method importSchedules.
protected void importSchedules(List<JobScheduleRequest> scheduleList) throws PlatformImportException {
if (CollectionUtils.isNotEmpty(scheduleList)) {
SchedulerResource schedulerResource = new SchedulerResource();
schedulerResource.pause();
for (JobScheduleRequest jobScheduleRequest : scheduleList) {
boolean jobExists = false;
List<Job> jobs = getAllJobs(schedulerResource);
if (jobs != null) {
// paramRequest to map<String, Serializable>
Map<String, Serializable> mapParamsRequest = new HashMap<>();
for (JobScheduleParam paramRequest : jobScheduleRequest.getJobParameters()) {
mapParamsRequest.put(paramRequest.getName(), paramRequest.getValue());
}
for (Job job : jobs) {
if ((mapParamsRequest.get(RESERVEDMAPKEY_LINEAGE_ID) != null) && (mapParamsRequest.get(RESERVEDMAPKEY_LINEAGE_ID).equals(job.getJobParams().get(RESERVEDMAPKEY_LINEAGE_ID)))) {
jobExists = true;
}
if (overwriteFile && jobExists) {
JobRequest jobRequest = new JobRequest();
jobRequest.setJobId(job.getJobId());
schedulerResource.removeJob(jobRequest);
jobExists = false;
break;
}
}
}
if (!jobExists) {
try {
Response response = createSchedulerJob(schedulerResource, jobScheduleRequest);
if (response.getStatus() == Response.Status.OK.getStatusCode()) {
if (response.getEntity() != null) {
// get the schedule job id from the response and add it to the import session
ImportSession.getSession().addImportedScheduleJobId(response.getEntity().toString());
}
}
} catch (Exception e) {
// the space(s)
if (jobScheduleRequest.getInputFile().contains(" ") || jobScheduleRequest.getOutputFile().contains(" ")) {
log.info("Could not import schedule, attempting to replace spaces with underscores and retrying: " + jobScheduleRequest.getInputFile());
File inFile = new File(jobScheduleRequest.getInputFile());
File outFile = new File(jobScheduleRequest.getOutputFile());
String inputFileName = inFile.getParent() + RepositoryFile.SEPARATOR + inFile.getName().replaceAll(" ", "_");
String outputFileName = outFile.getParent() + RepositoryFile.SEPARATOR + outFile.getName().replaceAll(" ", "_");
jobScheduleRequest.setInputFile(inputFileName);
jobScheduleRequest.setOutputFile(outputFileName);
try {
if (File.separator != RepositoryFile.SEPARATOR) {
// on windows systems, the backslashes will result in the file not being found in the repository
jobScheduleRequest.setInputFile(inputFileName.replace(File.separator, RepositoryFile.SEPARATOR));
jobScheduleRequest.setOutputFile(outputFileName.replace(File.separator, RepositoryFile.SEPARATOR));
}
Response response = createSchedulerJob(schedulerResource, jobScheduleRequest);
if (response.getStatus() == Response.Status.OK.getStatusCode()) {
if (response.getEntity() != null) {
// get the schedule job id from the response and add it to the import session
ImportSession.getSession().addImportedScheduleJobId(response.getEntity().toString());
}
}
} catch (Exception ex) {
// log it and keep going. we should stop processing all schedules just because one fails.
log.error(Messages.getInstance().getString("SolutionImportHandler.ERROR_0001_ERROR_CREATING_SCHEDULE", e.getMessage()), ex);
}
} else {
// log it and keep going. we should stop processing all schedules just because one fails.
log.error(Messages.getInstance().getString("SolutionImportHandler.ERROR_0001_ERROR_CREATING_SCHEDULE", e.getMessage()));
}
}
} else {
log.info(Messages.getInstance().getString("DefaultImportHandler.ERROR_0009_OVERWRITE_CONTENT", jobScheduleRequest.toString()));
}
}
schedulerResource.start();
}
}
use of org.pentaho.platform.web.http.api.resources.SchedulerResource in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method mockSchedulerPause.
private void mockSchedulerPause() {
SchedulerResource schedulerResource = new SchedulerResource();
new NonStrictExpectations(SchedulerResource.class) {
{
schedulerResource.pause();
times = 1;
schedulerResource.start();
times = 1;
schedulerResource.getAllJobs();
result = null;
}
};
}
Aggregations