コード例 #1
0
  @RequestMapping("/cancelScheduledJob")
  public String cancelScheduledJob(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("theJobName") String theJobName,
      @RequestParam("theJobGroupName") String theJobGroupName,
      @RequestParam("theTriggerName") String triggerName,
      @RequestParam("theTriggerGroupName") String triggerGroupName,
      @RequestParam("redirection") String redirection,
      ModelMap model)
      throws SchedulerException {

    scheduler.getJobDetail(theJobName, theJobGroupName);
    logger.debug("About to pause the job-->" + theJobName + "Job Group Name -->" + theJobGroupName);

    SimpleTrigger oldTrigger = (SimpleTrigger) scheduler.getTrigger(triggerName, triggerGroupName);
    if (oldTrigger != null) {
      Date startTime =
          new Date(oldTrigger.getStartTime().getTime() + oldTrigger.getRepeatInterval());
      if (triggerGroupName.equals(ExtractController.TRIGGER_GROUP_NAME)) {
        interruptQuartzJob(scheduler, theJobName, theJobGroupName);
      }

      scheduler.pauseJob(theJobName, theJobGroupName);

      SimpleTrigger newTrigger = new SimpleTrigger(triggerName, triggerGroupName);
      newTrigger.setJobName(theJobName);
      newTrigger.setJobGroup(theJobGroupName);
      newTrigger.setJobDataMap(oldTrigger.getJobDataMap());
      newTrigger.setVolatility(false);
      newTrigger.setRepeatCount(oldTrigger.getRepeatCount());
      newTrigger.setRepeatInterval(oldTrigger.getRepeatInterval());
      newTrigger.setMisfireInstruction(
          SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT);
      newTrigger.setStartTime(startTime);
      newTrigger.setRepeatInterval(oldTrigger.getRepeatInterval());

      scheduler.unscheduleJob(
          triggerName,
          triggerGroupName); // these are the jobs which are from extract data and are not not
      // required to be rescheduled.

      ArrayList<String> pageMessages = new ArrayList<String>();

      if (triggerGroupName.equals(ExtractController.TRIGGER_GROUP_NAME)) {
        scheduler.rescheduleJob(triggerName, triggerGroupName, newTrigger);

        pageMessages.add("The Job  " + theJobName + " has been cancelled");
      } else if (triggerGroupName.equals(XsltTriggerService.TRIGGER_GROUP_NAME)) {

        JobDetailBean jobDetailBean = new JobDetailBean();
        jobDetailBean.setGroup(XsltTriggerService.TRIGGER_GROUP_NAME);
        jobDetailBean.setName(newTrigger.getName());
        jobDetailBean.setJobClass(org.akaza.openclinica.job.XsltStatefulJob.class);
        jobDetailBean.setJobDataMap(newTrigger.getJobDataMap());
        jobDetailBean.setDurability(true); // need durability?
        jobDetailBean.setVolatility(false);

        scheduler.deleteJob(theJobName, theJobGroupName);
        scheduler.scheduleJob(jobDetailBean, newTrigger);
        pageMessages.add("The Job " + theJobName + "  has been rescheduled");
      }

      request.setAttribute("pageMessages", pageMessages);

      logger.debug("jobDetails>" + scheduler.getJobDetail(theJobName, theJobGroupName));
    }
    sdvUtil.forwardRequestFromController(request, response, "/pages/" + redirection);
    return null;
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
  protected SchedulerResponse getScheduledJob(Scheduler scheduler, JobKey jobKey) throws Exception {

    JobDetail jobDetail = scheduler.getJobDetail(jobKey);

    if (jobDetail == null) {
      return null;
    }

    SchedulerResponse schedulerResponse = new SchedulerResponse();

    JobDataMap jobDataMap = jobDetail.getJobDataMap();

    String description = jobDataMap.getString(SchedulerEngine.DESCRIPTION);

    schedulerResponse.setDescription(description);

    String destinationName = jobDataMap.getString(SchedulerEngine.DESTINATION_NAME);

    schedulerResponse.setDestinationName(destinationName);

    Message message = getMessage(jobDataMap);

    JobState jobState = getJobState(jobDataMap);

    message.put(SchedulerEngine.JOB_STATE, jobState);

    schedulerResponse.setMessage(message);

    StorageType storageType =
        StorageType.valueOf(jobDataMap.getString(SchedulerEngine.STORAGE_TYPE));

    schedulerResponse.setStorageType(storageType);

    String jobName = jobKey.getName();
    String groupName = jobKey.getGroup();

    TriggerKey triggerKey = new TriggerKey(jobName, groupName);

    Trigger trigger = scheduler.getTrigger(triggerKey);

    if (trigger == null) {
      schedulerResponse.setGroupName(groupName);
      schedulerResponse.setJobName(jobName);

      return schedulerResponse;
    }

    message.put(SchedulerEngine.END_TIME, trigger.getEndTime());
    message.put(SchedulerEngine.FINAL_FIRE_TIME, trigger.getFinalFireTime());
    message.put(SchedulerEngine.NEXT_FIRE_TIME, trigger.getNextFireTime());
    message.put(SchedulerEngine.PREVIOUS_FIRE_TIME, trigger.getPreviousFireTime());
    message.put(SchedulerEngine.START_TIME, trigger.getStartTime());

    if (trigger instanceof CalendarIntervalTrigger) {
      CalendarIntervalTrigger calendarIntervalTrigger = CalendarIntervalTrigger.class.cast(trigger);

      IntervalUnit intervalUnit = calendarIntervalTrigger.getRepeatIntervalUnit();

      schedulerResponse.setTrigger(
          new IntervalTrigger(
              jobName,
              groupName,
              calendarIntervalTrigger.getStartTime(),
              calendarIntervalTrigger.getEndTime(),
              calendarIntervalTrigger.getRepeatInterval(),
              TimeUnit.valueOf(intervalUnit.name())));
    } else if (trigger instanceof CronTrigger) {
      CronTrigger cronTrigger = CronTrigger.class.cast(trigger);

      schedulerResponse.setTrigger(
          new com.liferay.portal.kernel.scheduler.CronTrigger(
              jobName,
              groupName,
              cronTrigger.getStartTime(),
              cronTrigger.getEndTime(),
              cronTrigger.getCronExpression()));
    } else if (trigger instanceof SimpleTrigger) {
      SimpleTrigger simpleTrigger = SimpleTrigger.class.cast(trigger);

      schedulerResponse.setTrigger(
          new IntervalTrigger(
              jobName,
              groupName,
              simpleTrigger.getStartTime(),
              simpleTrigger.getEndTime(),
              (int) simpleTrigger.getRepeatInterval(),
              TimeUnit.MILLISECOND));
    }

    return schedulerResponse;
  }