コード例 #1
1
  public static List<ScheduledWorkFlowJob> searchWorkflowJobs(
      String pageSize, String pageNumber, String workflowJobId, String workflowName, String status)
      throws IOException {

    String workflowsPath =
        LoaderServerConfiguration.instance().getJobFSConfig().getWorkflowJobsPath();
    File[] workflowDirs = new File(workflowsPath).listFiles();
    Arrays.sort(
        workflowDirs,
        new Comparator<File>() {
          public int compare(File f1, File f2) {
            return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
          }
        });
    ArrayList<ScheduledWorkFlowJob> result = new ArrayList<ScheduledWorkFlowJob>();
    for (File workflowDir : workflowDirs) {
      File f = new File(workflowDir.getAbsolutePath() + File.separator + "status.json");
      ScheduledWorkFlowJob scheduledWorkFlowJob =
          objectMapper.readValue(f, ScheduledWorkFlowJob.class);
      result.add(scheduledWorkFlowJob);
    }
    ArrayList<ScheduledWorkFlowJob> filter = new ArrayList<ScheduledWorkFlowJob>();
    if (!workflowJobId.equals("")) {
      for (ScheduledWorkFlowJob r : result) {
        if (r.getWorkFlowId().contains(workflowJobId)) filter.add(r);
      }
    }
    result.removeAll(filter);
    filter.clear();
    if (!workflowName.equals("")) {
      for (ScheduledWorkFlowJob r : result) {
        if (r.getWorkflowName().contains(workflowName)) filter.add(r);
      }
    }
    result.removeAll(filter);
    filter.clear();
    if (!status.equals("")) {
      for (ScheduledWorkFlowJob r : result) {
        if (r.getStatus().equals(status)) filter.add(r);
      }
    }
    result.removeAll(filter);
    filter.clear();
    int size = Integer.parseInt(pageSize);
    int numberOfPages = result.size() / size + 1;
    int startIndex = (Integer.parseInt(pageNumber) - 1) * size;
    int lastIndex = startIndex + size > result.size() ? result.size() : startIndex + size;
    return result.subList(startIndex, lastIndex);
  }
コード例 #2
0
 // both reads and writes - need to be synchronized for consistent data to be written
 public static void deleteWorkflowJob(String workflowJobId) throws IOException {
   String workflowJobPath =
       LoaderServerConfiguration.instance().getJobFSConfig().getWorkflowJobPath(workflowJobId);
   File file = new File(workflowJobPath);
   if (!file.exists())
     throw new RuntimeException("WorkflowJobId " + workflowJobId + " not found.");
   File statusFile =
       new File(
           LoaderServerConfiguration.instance()
               .getJobFSConfig()
               .getWorkflowJobStatusPath(workflowJobId));
   ScheduledWorkFlowJob workflow = objectMapper.readValue(statusFile, ScheduledWorkFlowJob.class);
   FileHelper.deleteRecursively(file);
   File workflowJobsFile =
       new File(
           LoaderServerConfiguration.instance()
               .getJobFSConfig()
               .getScheduledWorkflowJobsFile(workflow.getWorkflowName()));
   synchronized (ScheduledWorkFlowJob.class) {
     ArrayList<String> allWorkflowJobIds =
         objectMapper.readValue(workflowJobsFile, ArrayList.class);
     allWorkflowJobIds.remove(workflowJobId);
     objectMapper.writerWithDefaultPrettyPrinter().writeValue(workflowJobsFile, allWorkflowJobIds);
   }
 }