Package com.redwood.scheduler.api.job
Class JobForecaster
- java.lang.Object
-
- com.redwood.scheduler.api.job.JobForecaster
-
- All Implemented Interfaces:
JobForecastContext
,JobForecasterComp
public class JobForecaster extends Object implements JobForecastContext, JobForecasterComp
Job forecasting.
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<ForecastJob>
FORECASTJOBCOMPARATOR
-
Constructor Summary
Constructors Constructor Description JobForecaster()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RWIterable<ForecastJob>
forecast(SchedulerSession session, DateTimeZone at)
Create forecast jobs for all active job groups at the specified date.ForecastJob
forecastChildJobs(SchedulerSession session, Long jobId)
For job chains, the job chain run will be simulated.RWIterable<ForecastJob>
forecastJobs(SchedulerSession session, DateTimeZone begin, DateTimeZone end, List<Long> jobUniqueIds)
Create forecast jobs for all active job groups at the specified date range.Map<Long,ForecastJob>
forecastJobs(SchedulerSession session, DateTimeZone begin, DateTimeZone end, List<Long> jobUniqueIds, long maxForecastCount)
Create forecast jobs for all active job groups at the specified date range.static String
forecastJobToString(ForecastJob fj)
Get a string representation of a forecasted job.Collection<Throwable>
getExceptions()
Get the exceptions that occurred during forecasting.static List<Long>
getJobsForProcessServers(SchedulerSession session, List<Long> processServerIds, DateTimeZone jobsFrom, DateTimeZone jobsTo, boolean includeMaintenanceJobs)
A helper function for a request to forecast the jobs in a set of process servers where the scheduled start time of the jobs are in a certain time range.static List<Long>
getJobsForQueues(SchedulerSession session, List<Long> queueIds, DateTimeZone jobsFrom, DateTimeZone jobsTo, boolean includeMaintenanceJobs)
A helper function for a request to forecast the jobs in a set of queues where the scheduled start time of the jobs are in a certain time range.static List<Long>
getJobsForRelatedEntity(SchedulerSession session, String entityType, List<Long> entityIds, DateTimeZone jobsFrom, DateTimeZone jobsTo, boolean includeMaintenanceJobs)
A helper function for a request to forecast the jobs in a set of entities (queues, process servers) where the scheduled start time of the jobs are in a certain time range.boolean
includeExistingJobs()
Are existing jobs included in the result or only return the forecasts when forecasting the jobs in a job group.void
setIncludeExistingJobs(boolean newIncludeExistingJobs)
Include existing jobs or not.
-
-
-
Field Detail
-
FORECASTJOBCOMPARATOR
public static final Comparator<ForecastJob> FORECASTJOBCOMPARATOR
-
-
Method Detail
-
forecastJobToString
public static String forecastJobToString(ForecastJob fj)
Get a string representation of a forecasted job.- Parameters:
fj
- the forecasted job.- Returns:
- a string representation.
-
forecast
public RWIterable<ForecastJob> forecast(SchedulerSession session, DateTimeZone at) throws SchedulerAPIException
Create forecast jobs for all active job groups at the specified date.- Specified by:
forecast
in interfaceJobForecasterComp
- Parameters:
session
- in which to forecast.at
- is the date and time to forecast.- Returns:
- iterator with ForecastJobs
- Throws:
SchedulerAPIException
- if errors are encountered while computing the ForecastJobs.
-
forecastJobs
public RWIterable<ForecastJob> forecastJobs(SchedulerSession session, DateTimeZone begin, DateTimeZone end, List<Long> jobUniqueIds) throws SchedulerAPIException
Create forecast jobs for all active job groups at the specified date range. If jobUniqueIds is null, all jobs in the system will be forecast. Note that forecasts cannot be persisted.- Specified by:
forecastJobs
in interfaceJobForecasterComp
- Parameters:
session
- in which to forecast.begin
- of the forecast period; an empty list will be returned if not specified.end
- of the forecast period; an empty list will be returned if not specified.jobUniqueIds
- is an optional list of Long or UniqueIdObjects, containing the uniqueIds for the jobs to forecast.- Returns:
- iterator with ForecastJobs.
- Throws:
SchedulerAPIException
- if errors are encountered while computing the ForecastJobs.
-
forecastJobs
public Map<Long,ForecastJob> forecastJobs(SchedulerSession session, DateTimeZone begin, DateTimeZone end, List<Long> jobUniqueIds, long maxForecastCount)
Create forecast jobs for all active job groups at the specified date range. If no jobUniqueIds are specified, all jobs in the system will be forecast. Note that forecasts cannot be persisted. No more than maxForecastCount items will be returned. The algorithm is such, that the forecasts will be limited in time, not in job groups. There are no missing forecasts between the first and the last returned forecast job.- Parameters:
session
- in which to forecast.begin
- of the forecast period; an empty list will be returned if not specified.end
- of the forecast period; if not specified, forecast period is at begin date.jobUniqueIds
- is an optional list of Long or UniqueIdObjects, containing the uniqueIds for the jobs to forecast.maxForecastCount
- is the maximum number of forecast jobs to be returned.- Returns:
- map with ForecastJobs, keyed by their unique id.
-
forecastChildJobs
public ForecastJob forecastChildJobs(SchedulerSession session, Long jobId)
For job chains, the job chain run will be simulated.- Parameters:
session
- in which to forecast.jobId
- to forecast- Returns:
- the forecastJob for jobId with child jobs filled.
-
getJobsForQueues
public static List<Long> getJobsForQueues(SchedulerSession session, List<Long> queueIds, DateTimeZone jobsFrom, DateTimeZone jobsTo, boolean includeMaintenanceJobs) throws SchedulerAPIException
A helper function for a request to forecast the jobs in a set of queues where the scheduled start time of the jobs are in a certain time range. For each job group, only one job is added to the list.- Parameters:
session
- to execute the query inqueueIds
- are the uniqueIds of the queues which jobs must be forecastjobsFrom
- optional start of the time range for the jobsjobsTo
- optional end of the time range for the jobsincludeMaintenanceJobs
- is true if the maintenance jobs must be forecast as well; if false, the maintenance jobs will be excluded from the result- Returns:
- a list of jobUniqueIds that must be forecast
- Throws:
SchedulerAPIException
- if errors are encountered while computing the list of jobs.
-
getJobsForProcessServers
public static List<Long> getJobsForProcessServers(SchedulerSession session, List<Long> processServerIds, DateTimeZone jobsFrom, DateTimeZone jobsTo, boolean includeMaintenanceJobs) throws SchedulerAPIException
A helper function for a request to forecast the jobs in a set of process servers where the scheduled start time of the jobs are in a certain time range. For each job group, only one job is added to the list.- Parameters:
session
- to execute the query inprocessServerIds
- are the uniqueIds of the process servers which jobs must be forecastjobsFrom
- optional start of the time range for the jobsjobsTo
- optional end of the time range for the jobsincludeMaintenanceJobs
- is true if the maintenance jobs must be forecast as well; if false, the maintenance jobs will be excluded from the result- Returns:
- a list of jobUniqueIds that must be forecast
- Throws:
SchedulerAPIException
- if errors are encountered while computing the list of jobs.
-
getJobsForRelatedEntity
public static List<Long> getJobsForRelatedEntity(SchedulerSession session, String entityType, List<Long> entityIds, DateTimeZone jobsFrom, DateTimeZone jobsTo, boolean includeMaintenanceJobs) throws SchedulerAPIException
A helper function for a request to forecast the jobs in a set of entities (queues, process servers) where the scheduled start time of the jobs are in a certain time range. For each job group, only one job is added to the list.- Parameters:
session
- to execute the query inentityType
- object type of the entityentityIds
- are the uniqueIds of the entities for which jobs must be forecastjobsFrom
- optional start of the time range for the jobsjobsTo
- optional end of the time range for the jobsincludeMaintenanceJobs
- is true if the maintenance jobs must be forecast as well; if false, the maintenance jobs will be excluded from the result- Returns:
- a list of jobUniqueIds that must be forecast
- Throws:
SchedulerAPIException
- if errors are encountered while computing the list of jobs.
-
getExceptions
public Collection<Throwable> getExceptions()
Description copied from interface:JobForecastContext
Get the exceptions that occurred during forecasting.- Specified by:
getExceptions
in interfaceJobForecastContext
- Returns:
- exceptions that occurred during forecasting.
-
includeExistingJobs
public boolean includeExistingJobs()
Description copied from interface:JobForecastContext
Are existing jobs included in the result or only return the forecasts when forecasting the jobs in a job group. Does not apply to forecasting the child jobs of a job.- Specified by:
includeExistingJobs
in interfaceJobForecastContext
- Returns:
- the value.
-
setIncludeExistingJobs
public void setIncludeExistingJobs(boolean newIncludeExistingJobs)
Include existing jobs or not.- Parameters:
newIncludeExistingJobs
- new value.
-
-