use of org.ligoj.app.plugin.vm.model.VmSchedule in project plugin-vm by ligoj.
the class VmScheduleResource method update.
/**
* Update an existing schedule.
*
* @param subscription
* The target subscription. The subscription cannot be changed for a schedule.
* @param schedule
* The schedule to save or update. The CRON expression may be either in the 5 either in 6 parts. The
* optional 6th corresponds to the "seconds" and will be prepended to the expression to conform to Quartz
* format.
* @throws SchedulerException
* When the schedule cannot be done by Quartz.
*/
@PUT
@Transactional
public void update(@PathParam("subscription") final int subscription, final VmScheduleVo schedule) throws SchedulerException {
// Check the schedule is related to the subscription
final VmSchedule entity = checkOwnership(subscription, schedule.getId());
// Persist the new schedules for each provided CRON
checkAndSave(subscription, schedule, entity);
// Remove current schedules from the Quartz memory
unscheduleQuartz(schedule.getId());
persistTrigger(checkAndSave(subscription, schedule, entity));
}
use of org.ligoj.app.plugin.vm.model.VmSchedule in project plugin-vm by ligoj.
the class VmResource method writeSchedules.
/**
* Write all schedules.
*/
private void writeSchedules(final OutputStream output, Collection<VmSchedule> schedules, final Map<Integer, VmExecution> lastExecutions) throws IOException {
final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss");
final Date now = DateUtils.newCalendar().getTime();
writer.write("subscription;project;projectKey;projectName;node;cron;operation;lastDateHMS;lastTimestamp;lastOperation;vm;lastTrigger;lastSucceed;lastStatusText;lastErrorText;nextDateHMS;nextTimestamp");
for (final VmSchedule schedule : schedules) {
// The last execution of the related schedule
final VmExecution execution = lastExecutions.get(schedule.getSubscription().getId());
writeCommon(writer, schedule.getSubscription());
writer.write(';');
writer.write(schedule.getCron());
writer.write(';');
writer.write(schedule.getOperation().name());
if (execution == null) {
writer.write(";;;;;;;;");
} else {
// Last execution
writeExecutionStatus(writer, execution, df);
}
// Next execution
try {
final Date next = new CronExpression(schedule.getCron()).getNextValidTimeAfter(now);
writer.write(';');
writer.write(df.format(next));
writer.write(';');
writer.write(String.valueOf(next.getTime()));
} catch (final ParseException pe) {
// Non blocking error
log.error("Invalid CRON expression {}", schedule.getCron());
writer.write(";ERROR;ERROR");
}
}
// Ensure buffer is flushed
writer.flush();
}
Aggregations