@Override
  public void execute(JobExecutionContext context) throws JobExecutionException {
    BundleManagerLocal bundleManager = LookupUtil.getBundleManager();
    SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

    Subject overlord = subjectManager.getOverlord();

    PageList<BundleDeployment> deployments =
        bundleManager.findBundleDeploymentsByCriteria(overlord, getCriteriaFromContext(context));

    if (deployments.size() > 0) {
      BundleDeployment bundleDeployment = deployments.get(0);
      SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
      JobDetail jobDetail = context.getJobDetail();

      BundleDeploymentStatus bundleDeploymentStatus =
          bundleManager.determineBundleDeploymentStatus(bundleDeployment.getId());
      if (bundleDeploymentStatus.isTerminal()) {
        // delete this job, we've assigned a final status
        try {
          context.setResult(bundleDeploymentStatus); // Return status to possible listeners
          scheduler.deleteJob(jobDetail.getName(), jobDetail.getGroup());
        } catch (SchedulerException e) {
          throw new JobExecutionException(
              "Could not delete the bundle deployment completion check job for "
                  + bundleDeployment
                  + ".",
              e);
        }
      } else {
        // try again in 10s
        try {
          Trigger trigger = QuartzUtil.getFireOnceOffsetTrigger(jobDetail, 10000L);
          // just need a trigger name unique for this job
          trigger.setName(String.valueOf(System.currentTimeMillis()));
          scheduler.scheduleJob(trigger);
        } catch (SchedulerException e) {
          throw new JobExecutionException(
              "Could not schedule the bundle deployment completion check job for "
                  + bundleDeployment
                  + ".",
              e);
        }
      }
    }
  }
Beispiel #2
0
  /**
   * Starts the Quartz scheduler now. We are assured that all EJBs are deployed now, so any jobs
   * that have to be executed now will have those EJBs available.
   *
   * @throws RuntimeException
   */
  private void startScheduler() throws RuntimeException {
    log.info("Starting the scheduler...");

    try {
      schedulerBean.startQuartzScheduler();
    } catch (SchedulerException e) {
      throw new RuntimeException("Cannot start the scheduler!", e);
    }
  }
Beispiel #3
0
  /**
   * Initializes, but doesn't start, the Quartz scheduler now.
   *
   * @throws RuntimeException
   */
  private void initScheduler() throws RuntimeException {
    log.info("Initializing the scheduler....");

    try {
      schedulerBean.initQuartzScheduler();
    } catch (SchedulerException e) {
      throw new RuntimeException("Cannot initialize the scheduler!", e);
    }
  }
Beispiel #4
0
  /**
   * This will make sure all jobs that need to periodically run are scheduled.
   *
   * @throws RuntimeException if unable to schedule a job
   */
  private void scheduleJobs() throws RuntimeException {
    log.info("Scheduling asynchronous jobs...");

    /*
     * All jobs need to be set as non-volatile since a volatile job in a clustered environment is effectively
     * non-volatile;
     */

    // TODO [mazz]: make all of the intervals here configurable via something like SystemManagerBean

    serverManager.scheduleServerHeartbeat();
    cacheConsistencyManager.scheduleServerCacheReloader();
    systemManager.scheduleConfigCacheReloader();

    try {
      // Do not check until we are up at least 1 min, and every minute thereafter.
      final long initialDelay = 1000L * 60;
      final long interval = 1000L * 60;
      schedulerBean.scheduleSimpleRepeatingJob(
          SavedSearchResultCountRecalculationJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule asynchronous resource deletion job.", e);
    }

    try {
      // Do not check until we are up at least 1 min, and every 5 minutes thereafter.
      final long initialDelay = 1000L * 60;
      final long interval = 1000L * 60 * 5;
      schedulerBean.scheduleSimpleRepeatingJob(
          AsyncResourceDeleteJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule asynchronous resource deletion job.", e);
    }

    try {
      // Do not check until we are up at least 1 min, and every 5 minutes thereafter.
      final long initialDelay = 1000L * 60;
      final long interval = 1000L * 60 * 5;
      schedulerBean.scheduleSimpleRepeatingJob(
          PurgeResourceTypesJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule purge resource types job.", e);
    }

    try {
      // Do not check until we are up at least 1 min, and every 5 minutes thereafter.
      final long initialDelay = 1000L * 60;
      final long interval = 1000L * 60 * 5;
      schedulerBean.scheduleSimpleRepeatingJob(
          PurgePluginsJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule purge plugins job.", e);
    }

    // DynaGroup Auto-Recalculation Job
    try {
      // Do not check until we are up at least 1 min, and every minute thereafter.
      final long initialDelay = 1000L * 60;
      final long interval = 1000L * 60;
      schedulerBean.scheduleSimpleRepeatingJob(
          DynaGroupAutoRecalculationJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule DynaGroup auto-recalculation job.", e);
    }

    // Cluster Manager Job
    try {
      String oldJobName = "org.rhq.enterprise.server.scheduler.jobs.ClusterManagerJob";
      boolean foundAndDeleted = schedulerBean.deleteJob(oldJobName, oldJobName);
      if (foundAndDeleted) {
        log.info("Unscheduling deprecated job references for " + oldJobName + "...");
      } else {
        log.debug("No deprecated job references found for " + oldJobName + ".");
      }

      // Wait long enough to allow the Server instance jobs to start executing first.
      final long initialDelay = 1000L * 60 * 2; // 2 mins
      final long interval = 1000L * 30; // 30 secs
      schedulerBean.scheduleSimpleRepeatingJob(
          CloudManagerJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule cloud management job.", e);
    }

    // Suspected Agents Job
    try {
      // Do not check until we are up at least 10 mins, but check every 60 secs thereafter.
      final long initialDelay = 1000L * 60 * 10; // 10 mins
      final long interval = 1000L * 60; // 60 secs
      schedulerBean.scheduleSimpleRepeatingJob(
          CheckForSuspectedAgentsJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule suspected Agents job.", e);
    }

    // Timed Out Operations Job
    try {
      final long initialDelay = 1000L * 60 * 3; // 3 min
      final long interval = 1000L * 60 * 10; // 10 minutes
      schedulerBean.scheduleSimpleRepeatingJob(
          CheckForTimedOutOperationsJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule check-for-timed-out-operations job.", e);
    }

    // Timed Out Resource Configuration Update Requests Job
    // (NOTE: We don't need to check for timed out plugin Cofiguration updates, since those are
    // executed synchronously.)
    try {
      final long initialDelay = 1000L * 60 * 4; // 4 mins
      final long interval = 1000L * 60 * 10; // 10 mins
      schedulerBean.scheduleSimpleRepeatingJob(
          CheckForTimedOutConfigUpdatesJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule check-for-timed-out-configuration-update-requests job.", e);
    }

    // Timed Out Content Requests Job
    try {
      final long initialDelay = 1000L * 60 * 5; // 5 mins
      final long interval = 1000L * 60 * 15; // 15 mins
      schedulerBean.scheduleSimpleRepeatingJob(
          CheckForTimedOutContentRequestsJob.class, true, false, initialDelay, interval);
    } catch (Exception e) {
      log.error("Cannot schedule check-for-timed-out-artifact-requests job.", e);
    }

    // Data Purge Job
    try {
      // TODO [mazz]: make the data purge job's cron string configurable via SystemManagerBean
      // For Quartz cron syntax, see:
      // http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger
      String cronString = "0 0 * * * ?"; // every hour, on the hour
      schedulerBean.scheduleSimpleCronJob(DataPurgeJob.class, true, false, cronString);
    } catch (Exception e) {
      log.error("Cannot schedule data purge job.", e);
    }

    // Server Plugin Jobs
    try {
      ServerPluginServiceMBean mbean = LookupUtil.getServerPluginService();
      MasterServerPluginContainer masterPC = mbean.getMasterPluginContainer();
      masterPC.scheduleAllPluginJobs();
    } catch (Exception e) {
      log.error("Cannot schedule server plugin jobs.", e);
    }

    // Alerting Availability Duration Job (create only, nothing actually scheduled here)
    try {
      schedulerBean.scheduleTriggeredJob(AlertAvailabilityDurationJob.class, false, null);
    } catch (Exception e) {
      log.error("Cannot create alert availability duration job.", e);
    }

    return;
  }