@Override
  protected Integer doExecute() throws Exception {
    final Map<String, Scheduler> schedulerMap =
        (Map<String, Scheduler>) appCtx.getBean("schedulerMap");
    System.out.println(
        ansi()
            .render(
                "@|negative_on %3s|%-20s|%-15s|%-3s|%-3s|%-3s|%-25s|@",
                "№", "Name/Tenant", "Instance ID", "Cur", "Job", "Trg", "Store"));
    int i = 0;
    for (Entry<String, Scheduler> entry : schedulerMap.entrySet()) {
      //			final String tenantId = entry.getKey();
      final Scheduler scheduler = entry.getValue();
      final Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.anyJobGroup());
      final List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
      final Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.anyTriggerGroup());

      final String startedAnsi = scheduler.isStarted() ? "@|bold,green ▶|@‎" : "@|bold,red ◼|@";
      System.out.println(
          ansi()
              .render(
                  "@|bold,black %3d||@"
                      + startedAnsi
                      + "%-19s@|bold,black ||@%-15s@|bold,black ||@%3d@|bold,black ||@%3d@|bold,black ||@%3d@|bold,black ||@%-25s",
                  ++i,
                  scheduler.getSchedulerName(),
                  scheduler.getSchedulerInstanceId(),
                  executingJobs.size(),
                  jobKeys.size(),
                  triggerKeys.size(),
                  scheduler.getMetaData().getJobStoreClass().getSimpleName()));
    }
    System.out.println(ansi().render("@|bold,yellow %d|@ Schedulers", schedulerMap.size()));
    return schedulerMap.size();
  }
示例#2
0
 /** 停止作业. */
 public void stopJob() {
   try {
     for (JobExecutionContext each : scheduler.getCurrentlyExecutingJobs()) {
       if (each.getJobInstance() instanceof AbstractElasticJob) {
         ((AbstractElasticJob) each.getJobInstance()).stop();
       }
     }
     scheduler.pauseAll();
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
 }
示例#3
0
  @Test
  public void testShutdownWithoutWaitIsUnclean() throws Exception {
    CyclicBarrier barrier = new CyclicBarrier(2);
    Scheduler scheduler = createScheduler("testShutdownWithoutWaitIsUnclean", 8);
    try {
      scheduler.getContext().put(BARRIER, barrier);
      scheduler.start();
      scheduler.addJob(
          newJob().ofType(UncleanShutdownJob.class).withIdentity("job").storeDurably().build(),
          false);
      scheduler.scheduleJob(newTrigger().forJob("job").startNow().build());
      while (scheduler.getCurrentlyExecutingJobs().isEmpty()) {
        Thread.sleep(50);
      }
    } finally {
      scheduler.shutdown(false);
    }

    barrier.await(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);

    Thread jobThread = (Thread) scheduler.getContext().get(JOB_THREAD);
    jobThread.join(TimeUnit.SECONDS.toMillis(TEST_TIMEOUT_SECONDS));
  }
示例#4
0
 @Test
 public void testShutdownWithWaitIsClean() throws Exception {
   final AtomicBoolean shutdown = new AtomicBoolean(false);
   List<Long> jobExecTimestamps = Collections.synchronizedList(new ArrayList<Long>());
   CyclicBarrier barrier = new CyclicBarrier(2);
   final Scheduler scheduler = createScheduler("testShutdownWithWaitIsClean", 8);
   try {
     scheduler.getContext().put(BARRIER, barrier);
     scheduler.getContext().put(DATE_STAMPS, jobExecTimestamps);
     scheduler.start();
     scheduler.addJob(
         newJob().ofType(TestJobWithSync.class).withIdentity("job").storeDurably().build(), false);
     scheduler.scheduleJob(newTrigger().forJob("job").startNow().build());
     while (scheduler.getCurrentlyExecutingJobs().isEmpty()) {
       Thread.sleep(50);
     }
   } finally {
     Thread t =
         new Thread() {
           @Override
           public void run() {
             try {
               scheduler.shutdown(true);
               shutdown.set(true);
             } catch (SchedulerException ex) {
               throw new RuntimeException(ex);
             }
           }
         };
     t.start();
     Thread.sleep(1000);
     assertFalse(shutdown.get());
     barrier.await(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
     t.join();
   }
 }
  @RequestMapping("/listCurrentScheduledJobs")
  public ModelMap listScheduledJobs(HttpServletRequest request, HttpServletResponse response)
      throws SchedulerException {
    Locale locale = LocaleResolver.getLocale(request);
    ResourceBundleProvider.updateLocale(locale);
    ModelMap gridMap = new ModelMap();
    String[] triggerNames;

    boolean showMoreLink = false;
    if (request.getParameter("showMoreLink") != null) {
      showMoreLink = Boolean.parseBoolean(request.getParameter("showMoreLink").toString());
    } else {
      showMoreLink = true;
    }
    request.setAttribute("showMoreLink", showMoreLink + "");

    // request.setAttribute("studySubjectId",studySubjectId);
    /*SubjectIdSDVFactory tableFactory = new SubjectIdSDVFactory();
     * @RequestParam("studySubjectId") int studySubjectId,*/
    request.setAttribute("imagePathPrefix", "../");

    ArrayList<String> pageMessages = (ArrayList<String>) request.getAttribute("pageMessages");
    if (pageMessages == null) {
      pageMessages = new ArrayList<String>();
    }

    request.setAttribute("pageMessages", pageMessages);

    List<JobExecutionContext> listCurrentJobs = new ArrayList<JobExecutionContext>();
    listCurrentJobs = scheduler.getCurrentlyExecutingJobs();
    Iterator<JobExecutionContext> itCurrentJobs = listCurrentJobs.iterator();
    List<String> currentJobList = new ArrayList<String>();
    while (itCurrentJobs.hasNext()) {
      JobExecutionContext temp = itCurrentJobs.next();
      currentJobList.add(temp.getTrigger().getJobName() + temp.getTrigger().getGroup());
    }

    String[] triggerGroups = scheduler.getTriggerGroupNames();
    List<SimpleTrigger> simpleTriggers = new ArrayList<SimpleTrigger>();
    int index1 = 0;
    for (String triggerGroup : triggerGroups) {
      logger.debug("Group: " + triggerGroup + " contains the following triggers");
      triggerNames = scheduler.getTriggerNames(triggerGroup);

      for (String triggerName : triggerNames) {
        int state = scheduler.getTriggerState(triggerName, triggerGroup);
        logger.debug("- " + triggerName);
        if (state != Trigger.STATE_PAUSED) {
          simpleTriggers.add(
              index1, (SimpleTrigger) scheduler.getTrigger(triggerName, triggerGroup));
          index1++;
        }
      }
    }

    List<ScheduledJobs> jobsScheduled = new ArrayList<ScheduledJobs>();

    int index = 0;

    for (SimpleTrigger st : simpleTriggers) {
      boolean isExecuting = currentJobList.contains(st.getJobName() + st.getGroup());

      ScheduledJobs jobs = new ScheduledJobs();

      ExtractPropertyBean epBean = null;
      if (st.getJobDataMap() != null) {
        epBean = (ExtractPropertyBean) st.getJobDataMap().get(EP_BEAN);
      }

      if (epBean != null) {
        StringBuilder checkbox = new StringBuilder();
        checkbox.append("<input style='margin-right: 5px' type='checkbox'/>");

        StringBuilder actions = new StringBuilder("<table><tr><td>");
        if (isExecuting) {
          actions.append("&nbsp;");
        } else {
          String contextPath = request.getContextPath();
          StringBuilder jsCodeString =
              new StringBuilder("this.form.method='GET'; this.form.action='")
                  .append(contextPath)
                  .append("/pages/cancelScheduledJob")
                  .append("';")
                  .append("this.form.theJobName.value='")
                  .append(st.getJobName())
                  .append("';")
                  .append("this.form.theJobGroupName.value='")
                  .append(st.getJobGroup())
                  .append("';")
                  .append("this.form.theTriggerName.value='")
                  .append(st.getName())
                  .append("';")
                  .append("this.form.theTriggerGroupName.value='")
                  .append(st.getGroup())
                  .append("';")
                  .append("this.form.submit();");

          actions
              .append("<td><input type=\"submit\" class=\"button\" value=\"Cancel Job\" ")
              .append("name=\"cancelJob\" onclick=\"")
              .append(jsCodeString.toString())
              .append("\" />");
        }

        actions.append("</td></tr></table>");

        jobs.setCheckbox(checkbox.toString());
        jobs.setDatasetId(epBean.getDatasetName());
        String fireTime =
            st.getStartTime() != null ? longFormat(locale).format(st.getStartTime()) : "";
        jobs.setFireTime(fireTime);
        if (st.getNextFireTime() != null) {
          jobs.setScheduledFireTime(longFormat(locale).format(st.getNextFireTime()));
        }
        jobs.setExportFileName(epBean.getExportFileName()[0]);
        jobs.setAction(actions.toString());
        jobs.setJobStatus(isExecuting ? "Currently Executing" : "Scheduled");
        jobsScheduled.add(index, jobs);
        index++;
      }
    }
    logger.debug("totalRows" + index);

    request.setAttribute("totalJobs", index);

    request.setAttribute("jobs", jobsScheduled);

    TableFacade facade = scheduledJobTableFactory.createTable(request, response);
    String sdvMatrix = facade.render();
    gridMap.addAttribute(SCHEDULED_TABLE_ATTRIBUTE, sdvMatrix);
    return gridMap;
  }