Pause a job if it's present.
@param jobName
@param groupName
@return true if job has been paused, no if job doesn't exist.
@throws SchedulerException
515031
public synchronized boolean pauseJobIfPresent(final String jobName, final String groupName)
      throws SchedulerException {
    if (ifJobExist(jobName, groupName)) {
      this.scheduler.pauseJob(new JobKey(jobName, groupName));
      return true;
    } else {
      return false;
    }
  }
350633
@Override
	public void changeTriggerState(String groupName, String jobName, final String triggerGroup, final String triggerName) throws SchedulerException {
		if (!config.isChangetTriggerStateAllowed()) {
			LOGGER.warn("not allowed to change any trigger state");
			return;
		}
		Trigger triggerFound = findTrigger(groupName, jobName, triggerGroup, triggerName);
		
		if (null != triggerFound) {
			// pause only the one trigger of job
			changeTriggerState(triggerFound);
			if (LOGGER.isDebugEnabled())
				LOGGER.debug(String.format("pausing trigger for group: %s, job: %s, trigger: %s ", groupName, jobName,
						triggerName));
		} else {
			if (LOGGER.isDebugEnabled())
				LOGGER.debug(String.format("pausing all triggers for group: %s, job: %s", groupName, jobName));
			List<? extends Trigger> triggers = scheduler.getTriggersOfJob(new JobKey(jobName, groupName));
			for (Trigger trigger : triggers) {
				// pause all triggers of job
				changeTriggerState(trigger);
			}
		}
	}
537673
public synchronized boolean unscheduleJob(final String jobName, final String groupName) throws
      SchedulerException {
    return this.scheduler.deleteJob(new JobKey(jobName, groupName));
  }
1172928
public void pauseJob(JobKey jobKey, T jedis) throws JobPersistenceException {
        for (OperableTrigger trigger : getTriggersForJob(jobKey, jedis)) {
            pauseTrigger(trigger.getKey(), jedis);
        }
    }
1065582
public boolean isRestartScheduled() {
        for (UpdateCenterJob job : getJobs()) {
            if (job instanceof RestartJenkinsJob) {
                RestartJenkinsJob.RestartJenkinsJobStatus status = ((RestartJenkinsJob) job).status;
                if (status instanceof RestartJenkinsJob.Pending
                        || status instanceof RestartJenkinsJob.Running) {
                    return true;
                }
            }
        }
        return false;
    }
1273081
public boolean unscheduleJob (final TriggerKey triggerKey) throws SchedulerException
  {
    validateState ();

    if (m_aResources.getJobStore ().removeTrigger (triggerKey))
    {
      notifySchedulerThread (0L);
      notifySchedulerListenersUnscheduled (triggerKey);
    }
    else
    {
      return false;
    }

    return true;
  }
1152658
public void setJobName (final String jobName)
  {
    if (jobName == null || jobName.trim ().length () == 0)
    {
      throw new IllegalArgumentException ("Job name cannot be null or empty.");
    }

    m_sJobName = jobName;
  }
1263295
public ScheduleJobDescriptor findScheduleJobDescriptor(String jarFilePath, String group, String name) {
        List<JobDescriptor> jobDescriptorList = jobDescriptorListMap.get(jarFilePath);
        if (jobDescriptorList == null) {
            throw new NiubiException(new IllegalStateException("job descriptor list can't be null."));
        }
        for (JobDescriptor jobDescriptorInner : jobDescriptorList) {
            if (jobDescriptorInner.group().equals(group) && jobDescriptorInner.name().equals(name)) {
                return new DefaultScheduleJobDescriptor(jobDescriptorInner);
            }
        }
        throw new NiubiException(new RuntimeException("can't find SchedulerJobDescriptor for [" + group + "." + name + "]"));
    }
413548
@Override
    public Collection<String> resumeJobs(GroupMatcher<JobKey> matcher, JedisCluster jedis) throws JobPersistenceException {
        Set<String> resumedJobGroups = new HashSet<>();
        if (matcher.getCompareWithOperator() == StringMatcher.StringOperatorName.EQUALS) {
            final String jobGroupSetKey = redisSchema.jobGroupSetKey(new JobKey("", matcher.getCompareToValue()));
            Long unpauseResponse = jedis.srem(redisSchema.pausedJobGroupsSet(), jobGroupSetKey);
            Set<String> jobsResponse = jedis.smembers(jobGroupSetKey);
            if (unpauseResponse > 0) {
                resumedJobGroups.add(redisSchema.jobGroup(jobGroupSetKey));
            }
            for (String job : jobsResponse) {
                resumeJob(redisSchema.jobKey(job), jedis);
            }
        } else {
            for (final String jobGroupSetKey : jedis.smembers(redisSchema.jobGroupsSet())) {
                if (matcher.getCompareWithOperator().evaluate(redisSchema.jobGroup(jobGroupSetKey), matcher.getCompareToValue())) {
                    resumedJobGroups.addAll(resumeJobs(GroupMatcher.jobGroupEquals(redisSchema.jobGroup(jobGroupSetKey)), jedis));
                }
            }
        }
        return resumedJobGroups;
    }
1002450
@Override
	public void executeJob(String groupName, String jobName) throws SchedulerException {
		if (!config.isExecuteJobAllowed()) {
			LOGGER.warn("not allowed to execute any job");
			return;
		}
		scheduler.triggerJob(new JobKey(jobName, groupName));
	}
505735
public Observable<ClusterInner> getByResourceGroupAsync(String resourceGroupName, String clusterName) {
        return getByResourceGroupWithServiceResponseAsync(resourceGroupName, clusterName).map(new Func1<ServiceResponse<ClusterInner>, ClusterInner>() {
            @Override
            public ClusterInner call(ServiceResponse<ClusterInner> response) {
                return response.body();
            }
        });
    }
895956
@Override
	public boolean removeTrigger(String groupName, String jobName, final String triggerGroup, final String triggerName) throws SchedulerException {
		if (!config.isRemoveTriggerAllowed()) {
			LOGGER.warn("not allowed to remove any trigger");
			return false;
		}
		Trigger triggerFound = findTrigger(groupName, jobName, triggerGroup, triggerName);
		if (null != triggerFound) {
			return scheduler.unscheduleJob(triggerFound.getKey());
		}
		return false;
	}
208815
@Override
    public void pauseTrigger(TriggerKey triggerKey, Jedis jedis) throws JobPersistenceException {
        final String triggerHashKey = redisSchema.triggerHashKey(triggerKey);
        Pipeline pipe = jedis.pipelined();
        Response<Boolean> exists = pipe.exists(triggerHashKey);
        Response<Double> completedScore = pipe.zscore(redisSchema.triggerStateKey(RedisTriggerState.COMPLETED), triggerHashKey);
        Response<String> nextFireTimeResponse = pipe.hget(triggerHashKey, TRIGGER_NEXT_FIRE_TIME);
        Response<Double> blockedScore = pipe.zscore(redisSchema.triggerStateKey(RedisTriggerState.BLOCKED), triggerHashKey);
        pipe.sync();

        if(!exists.get()){
            return;
        }
        if(completedScore.get() != null){
            // doesn't make sense to pause a completed trigger
            return;
        }

        final long nextFireTime = nextFireTimeResponse.get() == null
                || nextFireTimeResponse.get().isEmpty() ? -1 : Long.parseLong(nextFireTimeResponse.get());
        if(blockedScore.get() != null){
            setTriggerState(RedisTriggerState.PAUSED_BLOCKED, (double) nextFireTime, triggerHashKey, jedis);
        }
        else{
            setTriggerState(RedisTriggerState.PAUSED, (double) nextFireTime, triggerHashKey, jedis);
        }
    }
777287
public boolean deleteJob (final JobKey jobKey) throws SchedulerException
  {
    validateState ();

    boolean result = false;

    final ICommonsList <? extends ITrigger> triggers = getTriggersOfJob (jobKey);
    for (final ITrigger trigger : triggers)
    {
      if (!unscheduleJob (trigger.getKey ()))
      {
        final StringBuilder sb = new StringBuilder ().append ("Unable to unschedule trigger [")
                                                     .append (trigger.getKey ())
                                                     .append ("] while deleting job [")
                                                     .append (jobKey)
                                                     .append ("]");
        throw new SchedulerException (sb.toString ());
      }
      result = true;
    }

    result = m_aResources.getJobStore ().removeJob (jobKey) || result;
    if (result)
    {
      notifySchedulerThread (0L);
      notifySchedulerListenersJobDeleted (jobKey);
    }
    return result;
  }
1053511
@Override
    public void resumeTrigger(TriggerKey triggerKey, JedisCluster jedis) throws JobPersistenceException {
        final String triggerHashKey = redisSchema.triggerHashKey(triggerKey);
        Boolean exists = jedis.sismember(redisSchema.triggersSet(), triggerHashKey);
        Double isPaused = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.PAUSED), triggerHashKey);
        Double isPausedBlocked = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.PAUSED_BLOCKED), triggerHashKey);

        if (!exists) {
            // Trigger does not exist.  Nothing to do.
            return;
        }
        if (isPaused == null && isPausedBlocked == null) {
            // Trigger is not paused. Nothing to do.
            return;
        }
        OperableTrigger trigger = retrieveTrigger(triggerKey, jedis);
        final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
        final Date nextFireTime = trigger.getNextFireTime();

        if (nextFireTime != null) {
            if (isBlockedJob(jobHashKey, jedis)) {
                setTriggerState(RedisTriggerState.BLOCKED, (double) nextFireTime.getTime(), triggerHashKey, jedis);
            } else {
                setTriggerState(RedisTriggerState.WAITING, (double) nextFireTime.getTime(), triggerHashKey, jedis);
            }
        }
        applyMisfire(trigger, jedis);
    }
284839
private boolean scheduleRolloutGroup(final JpaRollout rollout, final JpaRolloutGroup group) {
        final long targetsInGroup = rolloutTargetGroupRepository.countByRolloutGroup(group);
        final long countOfActions = actionRepository.countByRolloutAndRolloutGroup(rollout, group);

        long actionsLeft = targetsInGroup - countOfActions;
        if (actionsLeft > 0) {
            actionsLeft -= createActionsForRolloutGroup(rollout, group);
        }

        if (actionsLeft <= 0) {
            group.setStatus(RolloutGroupStatus.SCHEDULED);
            rolloutGroupRepository.save(group);
            return true;
        }
        return false;
    }
556433
private CmsGroup checkGroup(String groupName) {

        try {
            return getCms().readGroup(groupName);
        } catch (CmsException e) {
            throw new CmsIllegalArgumentException(e.getMessageContainer());
        }
    }