private void validateParameter(String key, String value) { if (key == null || key.isEmpty() || key.length() > 50 || value == null || value.isEmpty() || value.length() > 1000) { throw new JqmInvalidRequestException( "Parameters key must be between 1 and 50 chaarcters, parameter values between 1 and 1000 characters"); } }
@Override public com.enioka.jqm.api.JobDef getJobDefinition(String name) { List<com.enioka.jqm.api.JobDef> res = getJobDefinitionsInternal("jd_select_by_key", name); if (res.isEmpty()) { throw new JqmInvalidRequestException("No job definition named " + name); } return res.get(0); }
@Override public void setScheduleRecurrence(int scheduleId, String cronExpression) { try { target.path("schedule/" + scheduleId + "/cron/" + cronExpression).request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void setSchedulePriority(int scheduleId, int priority) { try { target.path("schedule/" + scheduleId + "/priority/" + priority).request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public InputStream getJobLogStdErr(int jobId) { try { return target.path("ji/" + jobId + "/stderr").request().get(InputStream.class); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public InputStream getDeliverableContent(com.enioka.jqm.api.Deliverable d) { try { return target.path("ji/files").request().post(Entity.entity(d, MediaType.APPLICATION_XML), InputStream.class); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void killJob(int idJob) { try { target.path("ji/killed/" + idJob).request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void pauseRunningJob(int jobId) { try { target.path("ji/running/paused/" + jobId).request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void setJobQueuePosition(int idJob, int position) { try { target.path("ji/" + idJob + "/position/" + position).request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public com.enioka.jqm.api.JobInstance getJob(int idJob) { try { return target.path("ji/" + idJob).request().get(JobInstance.class); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException("An internal JQM error occured", e); } }
@Override public void pauseQueuedJob(int idJob) { try { target.path("ji/paused/" + idJob).request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void setScheduleQueue(int scheduleId, int queueId) { try { target.path("schedule/" + scheduleId + "/queue/" + queueId).request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public InputStream getDeliverableContent(int d) { try { return target.path("ji/files/" + d).request().get(InputStream.class); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public int enqueue(JobRequest jd) { try { return target.path("ji").request().post(Entity.entity(jd, MediaType.APPLICATION_XML), JobInstance.class).getId(); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public int getQueueEnabledCapacity(Queue q) { try { return target.path("q/" + q.getId() + "/enabled-capacity").request().get().readEntity(Integer.class); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void pauseQueue(Queue q) { try { target.path("q/" + q.getId() + "/pause").request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void clearQueue(Queue q) { try { target.path("q/" + q.getId() + "/clear").request().post(null); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
public int restartCrashedJob(int idJob) { try { return target.path("ji/crashed/" + idJob).request().delete(JobInstance.class).getId(); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public void resumeQueue(Queue q) { try { target.path("q/" + q.getId() + "/pause").request().delete(); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
@Override public List<com.enioka.jqm.api.JobInstance> getUserActiveJobs(String user) { if (user == null || user.isEmpty()) { throw new JqmInvalidRequestException("user cannot be null or empty"); } return Query.create().setUser(user).setQueryHistoryInstances(false).setQueryLiveInstances(true).addSortAsc(Sort.ID).run(); }