@PUT
public ScheduledServiceResourceStatusResponse put(Context context, Request request, Response response, Object payload)
throws ResourceException
{
ScheduledServiceResourceResponse serviceRequest = (ScheduledServiceResourceResponse) payload;
ScheduledServiceResourceStatusResponse result = null;
if (serviceRequest != null) {
ScheduledServiceBaseResource resource = serviceRequest.getData();
try {
// currently we allow editing of:
// task name
// task schedule (even to another type)
// task params
ScheduledTask<?> task = getNexusScheduler().getTaskById(getScheduledServiceId(request));
TaskState state = task.getTaskState();
if (TaskState.RUNNING.equals(state) || TaskState.CANCELLING.equals(state)
|| TaskState.SLEEPING.equals(state)) {
throw new ResourceException(Status.CLIENT_ERROR_CONFLICT,
"Task can't be edited while it is being executed or it is in line to be executed");
}
task.setEnabled(resource.isEnabled());
task.setName(getModelName(resource));
task.setSchedule(getModelSchedule(resource));
for (Iterator<ScheduledServicePropertyResource> iter = resource.getProperties().iterator(); iter.hasNext(); ) {
ScheduledServicePropertyResource prop = iter.next();
task.getTaskParams().put(prop.getKey(), prop.getValue());
}
TaskUtils.setAlertEmail(task, resource.getAlertEmail());
TaskUtils.setId(task, resource.getId());
TaskUtils.setName(task, resource.getName());
task.reset();
// Store the changes
getNexusScheduler().updateSchedule(task);
ScheduledServiceResourceStatus resourceStatus = new ScheduledServiceResourceStatus();
resourceStatus.setResource(resource);
// Just need to update the id, as the incoming data is a POST w/ no id
resourceStatus.getResource().setId(task.getId());
resourceStatus.setResourceURI(createChildReference(request, this, task.getId()).toString());
resourceStatus.setStatus(task.getTaskState().toString());
resourceStatus.setReadableStatus(getReadableState(task.getTaskState()));
resourceStatus.setCreated(task.getScheduledAt() == null ? "n/a" : task.getScheduledAt().toString());
resourceStatus.setLastRunResult(getLastRunResult(task));
resourceStatus.setLastRunTime(task.getLastRun() == null ? "n/a" : task.getLastRun().toString());
resourceStatus.setNextRunTime(task.getNextRun() == null ? "n/a" : task.getNextRun().toString());
if (task.getScheduledAt() != null) {
resourceStatus.setCreatedInMillis(task.getScheduledAt().getTime());
}
if (task.getLastRun() != null) {
resourceStatus.setLastRunTimeInMillis(task.getLastRun().getTime());
}
if (task.getNextRun() != null) {
resourceStatus.setNextRunTimeInMillis(task.getNextRun().getTime());
}
result = new ScheduledServiceResourceStatusResponse();
result.setData(resourceStatus);
}
catch (NoSuchTaskException e) {
getLogger().warn("Unable to locate task id:" + resource.getId(), e);