JobManager { public boolean deleteJob(LGJob job) { if (job.getStatus() == LGJob.STATUS_PROCESSING) { log.error("Delete Failed: job is in processing state."+job.getJobId()); return false; } open(); JOB_DAO.delete(job); return true; } JobManager(); static void close(); static void open(); static void addJob(LGJob job); static LGJob getJob(String jobId); HashMap<String, LGJob> getJobs(JSONArray jobIds); boolean deleteJob(LGJob job); boolean deleteDBValues(String jobId); static boolean doesJobExist(String jobId); boolean doesJobExist(LGJob job); boolean updateJobConfig(LGJob job, JSONObject config); static boolean setStatus(LGJob job, int status); static boolean setStatus(LGJob job, int newStatus, String reason, boolean force); static LGJob setEndTime(LGJob job); static LGJob setStartTime(LGJob job); List<LGJob> getAllActive(); List<LGJob> getAllProcessing(); List<LGJob> getAllNew(); List<LGJob> getAllError(); static boolean updateJobIfFinished(LGJob job); static void setJobFinished(LGJob job); boolean hasJobExpired(LGJob lg); static void addTaskToJob(LGJob job, LGTask task); static void updateJobHistorySuccess(LGJob job, String taskId, CoordinatorBolt.MetricData md); static void updateJobHistorySuccess(LGJob job, String taskId, int graphChanges, int maxGraphId, int numberOfNewTasksCreated, int currentId); static void updateJobHistoryFailed(String jobId, String taskId); static void updateJobHistory(LGJob job, LGJobHistory history); static void updateGraphActivity(LGJob job, int graphActivity); static void updateMaxGraphSizeErrorsForJob(String jobId, LGJobError error); static void updateErrorsForJob(LGJob job, LGJobError error); void updateErrorsForTask(LGJob job, String taskId, LGJobError error); static void removeErrorsForJobByTaskId(LGJob job, String taskId); static void updateJobTaskStatus(LGJob job, String taskId, int status); static void updateTaskToCompleted(LGJob job, String taskId); static void updateTaskToFailed(LGJob job, String taskId); static void updateTaskToDropped(LGJob job, String taskId); static LGTask getTask(String taskId); List<LGJob> getAllByStatus(String status); List<LGJob> getAllByDateRange(Date beforeDate, Date afterDate); List<LGJob> getAll(); List<LGJob> getAllByStatusAndReason(String status, String reason); List<LGJob> getAllByDays(int fdays, int tdays); List<LGJob> getAllByOlderThanDays(int days); List<LGJob> getAllByMins(int mins, int tomins); List<LGJob> getAllByAge(int days); List<LGJob> getAllLimitFields(String id, String status, String reason); List<LGJob> getLast(int count); JSONArray getAllJobsThatHaveDbValueKeyJSONArray(String dbValue); LGdbValue getDbValuesByJobIdandKey(String jobId, String key); LGdbValue getDbValuesByJobId(String jobId); static void main(final String[] args);  }
@Test public void testJobConfig() { JobManager jm = new JobManager(); MorphiaService ms = new MorphiaService(); LGJobDAOImpl dao = new LGJobDAOImpl(LGJob.class, ms.getDatastore()); String jobId = UUID.randomUUID().toString(); ArrayList<String> alist = new ArrayList(); alist.add("HelloWorld"); alist.add("PlusBang"); alist.add("HelloWorldPython"); alist.add("LongRunningTestAdapter"); alist.add("LongRunningPython"); JSONObject jobConfig = new JSONObject(); jobConfig.put("job_id",jobId); jobConfig.put("ttl",300); jobConfig.put("depth",3); jobConfig.put("description","test job"); LGPayload lgp = new LGPayload(jobConfig); LGJob testJob = new LGJob(jobId, alist, jobConfig); dao.save(testJob); LGJob lookup = dao.getByJobId(jobId); assertEquals(lookup.getDepth(), 3); assertEquals(lookup.getDescription(), "test job"); assertEquals(lookup.getTTL(),300); jm.deleteJob(lookup); }
@Test public void testJobTTL() { JobManager jm = new JobManager(); MorphiaService ms = new MorphiaService(); LGJobDAOImpl dao = new LGJobDAOImpl(LGJob.class, ms.getDatastore()); String jobId = UUID.randomUUID().toString(); ArrayList<String> alist = new ArrayList(); alist.add("HelloWorld"); alist.add("PlusBang"); alist.add("HelloWorldPython"); alist.add("LongRunningTestAdapter"); alist.add("LongRunningPython"); JSONObject jobConfig = new JSONObject(); jobConfig.put("job_id",jobId); jobConfig.put("ttl",-300); jobConfig.put("depth",3); jobConfig.put("description","test job for TTL"); LGPayload lgp = new LGPayload(jobConfig); LGJob testJob = new LGJob(jobId, alist, jobConfig); dao.save(testJob); LGJob lookup = dao.getByJobId(jobId); jm.deleteJob(lookup); }