From 621d9e5c413e561293d7484b93882d985b3fe15f Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Sat, 24 Mar 2012 02:27:47 -0500 Subject: Removed unnecessary pki folder. Previously the source code was located inside a pki folder. This folder was created during svn migration and is no longer needed. This folder has now been removed and the contents have been moved up one level. Ticket #131 --- .../com/netscape/certsrv/jobs/EJobsException.java | 77 ++++++++++ .../common/src/com/netscape/certsrv/jobs/IJob.java | 106 ++++++++++++++ .../src/com/netscape/certsrv/jobs/IJobCron.java | 42 ++++++ .../com/netscape/certsrv/jobs/IJobsScheduler.java | 162 +++++++++++++++++++++ .../src/com/netscape/certsrv/jobs/JobPlugin.java | 72 +++++++++ .../com/netscape/certsrv/jobs/JobsResources.java | 43 ++++++ 6 files changed, 502 insertions(+) create mode 100644 base/common/src/com/netscape/certsrv/jobs/EJobsException.java create mode 100644 base/common/src/com/netscape/certsrv/jobs/IJob.java create mode 100644 base/common/src/com/netscape/certsrv/jobs/IJobCron.java create mode 100644 base/common/src/com/netscape/certsrv/jobs/IJobsScheduler.java create mode 100644 base/common/src/com/netscape/certsrv/jobs/JobPlugin.java create mode 100644 base/common/src/com/netscape/certsrv/jobs/JobsResources.java (limited to 'base/common/src/com/netscape/certsrv/jobs') diff --git a/base/common/src/com/netscape/certsrv/jobs/EJobsException.java b/base/common/src/com/netscape/certsrv/jobs/EJobsException.java new file mode 100644 index 000000000..cc0923ae7 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/jobs/EJobsException.java @@ -0,0 +1,77 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.jobs; + +import com.netscape.certsrv.base.EBaseException; + +/** + * A class represents a jobs exception. + *

+ * + * @version $Revision$, $Date$ + */ +public class EJobsException extends EBaseException { + + /** + * + */ + private static final long serialVersionUID = 4542243534794168088L; + /** + * Identity resource class name. + */ + private static final String JOBS_RESOURCES = JobsResources.class.getName(); + + /** + * Constructs a Job Scheduler exception + *

+ */ + public EJobsException(String msgFormat) { + super(msgFormat); + } + + /** + * Constructs a Identity exception. + *

+ */ + public EJobsException(String msgFormat, String param) { + super(msgFormat, param); + } + + /** + * Constructs a Identity exception. + *

+ */ + public EJobsException(String msgFormat, Exception e) { + super(msgFormat, e); + } + + /** + * Constructs a Identity exception. + *

+ */ + public EJobsException(String msgFormat, Object params[]) { + super(msgFormat, params); + } + + /** + * Retrieves bundle name. + */ + protected String getBundleName() { + return JOBS_RESOURCES; + } +} diff --git a/base/common/src/com/netscape/certsrv/jobs/IJob.java b/base/common/src/com/netscape/certsrv/jobs/IJob.java new file mode 100644 index 000000000..5584d68ff --- /dev/null +++ b/base/common/src/com/netscape/certsrv/jobs/IJob.java @@ -0,0 +1,106 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.jobs; + +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.base.ISubsystem; + +/** + * An interface to be implemented from for a job to be scheduled by + * the Jobs Scheduler. + * + * @version $Revision$, $Date$ + */ +public interface IJob { + + /** + * Initialize from the configuration file. + * + * @param id String name of this instance + * @param implName string name of this implementation + * @param config configuration store for this instance + * @exception EBaseException any initilization failure + */ + public void init(ISubsystem owner, String id, String implName, + IConfigStore config) throws EBaseException; + + /** + * tells if the job is enabled + * + * @return a boolean value indicating whether the job is enabled + * or not + */ + public boolean isEnabled(); + + /** + * set instance id. + * + * @param id String id of the instance + */ + public void setId(String id); + + /** + * get instance id. + * + * @return a String identifier + */ + public String getId(); + + /** + * get cron string associated with this job + * + * @return a JobCron object that represents the schedule of this job + */ + public IJobCron getJobCron(); + + /** + * Returns a list of configuration parameter names. + * The list is passed to the configuration console so instances of + * this implementation can be configured through the console. + * + * @return String array of configuration parameter names. + */ + public String[] getConfigParams(); + + /** + * gets the plugin name of this job. + * + * @return a String that is the name of this implementation + */ + public String getImplName(); + + /** + * Gets the configuration substore used by this job + * + * @return configuration store + */ + public IConfigStore getConfigStore(); + + /** + * Request the job to stop gracefully. The job may not stop immediately. + */ + public void stop(); + + /** + * Check whether the job has been asked to stop. Long running jobs should call + * this method occasionally inside the run() method and exit gracefully if it + * returns true. + */ + public boolean isStopped(); +} diff --git a/base/common/src/com/netscape/certsrv/jobs/IJobCron.java b/base/common/src/com/netscape/certsrv/jobs/IJobCron.java new file mode 100644 index 000000000..f161b5e8d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/jobs/IJobCron.java @@ -0,0 +1,42 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.jobs; + +/** + * class representing one Job cron information + *

+ * here, an "item" refers to one of the 5 fields in a cron string; "element" refers to any comma-deliminated element in + * an "item"...which includes both numbers and '-' separated ranges. A cron string in the configuration takes the + * following format: minute (0-59), hour (0-23), day of the month (1-31), month of the year (1-12), day of the week + * (0-6 with 0=Sunday) + *

+ * e.g. jobsScheduler.job.rnJob1.cron=30 11,23 * * 1-5 In this example, the job "rnJob1" will be executed from Monday + * through Friday, at 11:30am and 11:30pm. + *

+ * + * @version $Revision$, $Date$ + */ +public interface IJobCron { + /** + * constant that represents the configuration parameter + * "cron" for the job that this JobCron is associated with. The + * value of which should conform to the cron format specified above. + */ + public static final String PROP_CRON = "cron"; + +} diff --git a/base/common/src/com/netscape/certsrv/jobs/IJobsScheduler.java b/base/common/src/com/netscape/certsrv/jobs/IJobsScheduler.java new file mode 100644 index 000000000..f4184853d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/jobs/IJobsScheduler.java @@ -0,0 +1,162 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.jobs; + +import java.util.Hashtable; + +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.ISubsystem; + +/** + * An interface that represents the job scheduler component. A JobScheduler + * is a daemon thread that handles scheduled jobs like cron would + * do with different jobs. This daemon wakes up at a pre-configured + * interval to see + * if there is any job to be done, if so, a thread is created to execute + * the job(s). + *

+ * The interval jobsScheduler.interval in the configuration is specified as number of minutes. If not set, the + * default is 1 minute. Note that the cron specification for each job CAN NOT be finer than the granularity of the + * Scheduler daemon interval. For example, if the daemon interval is set to 5 minute, a job cron for every minute at 7am + * on each Tuesday (e.g. * 7 * * 2) will result in the execution of the job thread only once every 5 minutes during that + * hour. The inteval value is recommended at 1 minute, setting it otherwise has the potential of forever missing the + * beat. Use with caution. + * + * @version $Revision$, $Date$ + */ +public interface IJobsScheduler extends ISubsystem { + /** + * The ID of this component + */ + public final static String ID = "jobsScheduler"; + + /** + * constant that represents the configuration parameter + * "enabled" for this component in CMS.cfg. The value of which + * tells CMS whether the JobsScheduler is enabled or not + */ + public static final String PROP_ENABLED = "enabled"; + + /** + * constant that represents the configuration parameter + * "interval" for this component in CMS.cfg. The value of which + * tells CMS the interval that the JobsScheduler thread should + * wake up and look for jobs to execute + */ + public static final String PROP_INTERVAL = "interval"; + + /** + * constant that represents the configuration parameter + * "class" for this component in CMS.cfg. The values of which are + * the actual implementation classes + */ + public static final String PROP_CLASS = "class"; + + /** + * constant that represents the configuration parameter + * "job" for this component in CMS.cfg. The values of which gives + * configuration information specific to one single job instance. + * There may be multiple jobs served by the jobsScheduler + */ + public static final String PROP_JOB = "job"; + + /** + * constant that represents the configuration parameter + * "impl" for this component in CMS.cfg. The values of which are + * actual plugin implementation(s) + */ + public static final String PROP_IMPL = "impl"; + + /** + * constant that represents the configuration parameter + * "pluginName" for this component in CMS.cfg. The value of which + * gives the pluginName for the job it associates with + */ + public static final String PROP_PLUGIN = "pluginName"; + + /** + * Retrieves all the job implementations. + * + * @return a Hashtable of available job plugin implementations + */ + public Hashtable getPlugins(); + + /** + * Retrieves all the job instances. + * + * @return a Hashtable of job instances + */ + public Hashtable getInstances(); + + /** + * Retrieves the configuration parameters of the given + * implementation. It is used to return to the Console for + * configuration + * + * @param implName the pulubin implementation name + * @return a String array of required configuration parameters of + * the given implementation. + * @exception EJobsException when job plugin implementation can + * not be found, instantiation is impossible, permission problem + * with the class. + */ + public String[] getConfigParams(String implName) + throws EJobsException; + + /** + * Writes a message to the system log. + * + * @param level an integer representing the log message level. + * Depending on the configuration set by the administrator, this + * value is a determining factor for whether this message will be + * actually logged or not. The lower the level, the higher the + * priority, and the higher chance it will be logged. + * @param msg the message to be written. Ideally should call + * CMS.getLogMessage() to get the localizable message + * from the log properties file. + */ + public void log(int level, String msg); + + /** + * Sets daemon's wakeup interval. + * + * @param minutes time in minutes that is to be the frequency of + * JobsScheduler wakeup call. + */ + public void setInterval(int minutes); + + /** + * Starts up the JobsScheduler daemon. Usually called from the + * initialization method when it's successfully initialized. + */ + public void startDaemon(); + + /** + * Creates a job cron. Each job is associated with a "cron" which + * specifies the rule of frequency that this job should be + * executed (e.g. every Sunday at midnight). This method is + * called by each job at initialization time. + * + * @param cs the string that represents the cron. See IJobCron + * for detail of the format. + * @return IJobCron an IJobCron + * @exception EBaseException when the cron string, cs, can not be + * parsed correctly + */ + public IJobCron createJobCron(String cs) throws EBaseException; +} diff --git a/base/common/src/com/netscape/certsrv/jobs/JobPlugin.java b/base/common/src/com/netscape/certsrv/jobs/JobPlugin.java new file mode 100644 index 000000000..46a1b6d7e --- /dev/null +++ b/base/common/src/com/netscape/certsrv/jobs/JobPlugin.java @@ -0,0 +1,72 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.jobs; + +/** + * This class represents a job plugin registered with the + * JobScheduler. A Job plugin can be instantiated into a Job instance + * and scheduled by the JobScheduler to run at a scheduled interval + *

+ * + * @version $Revision$, $Date$ + */ +public class JobPlugin { + /** + * The plugin name of this job + */ + protected String mId = null; + /** + * The Java class name of this job plugin. + * e.g. com.netscape.cms.RenewalNotificationJob + */ + protected String mClassPath = null; + + /* + * Seems to be unused, should be removed + */ + // protected Class mClass = null; + + /** + * Constructor for a Job plugin. + * + * @param id job plugin name + * @param classPath the Java class name of this job plugin + */ + public JobPlugin(String id, String classPath) { + mId = id; + mClassPath = classPath; + } + + /** + * get the job plugin name + * + * @return the name of this job plugin + */ + public String getId() { + return mId; + } + + /** + * get the Java class name + * + * @return the Java class name of this plugin + */ + public String getClassPath() { + return mClassPath; + } +} diff --git a/base/common/src/com/netscape/certsrv/jobs/JobsResources.java b/base/common/src/com/netscape/certsrv/jobs/JobsResources.java new file mode 100644 index 000000000..ec33137cf --- /dev/null +++ b/base/common/src/com/netscape/certsrv/jobs/JobsResources.java @@ -0,0 +1,43 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.jobs; + +import java.util.ListResourceBundle; + +/** + * A class represents a resource bundle for the + * Jobs package + * + * @version $Revision$, $Date$ + */ +public class JobsResources extends ListResourceBundle { + + /** + * Returns the content of this resource. + */ + public Object[][] getContents() { + return contents; + } + + /** + * Constants. The suffix represents the number of + * possible parameters. + */ + + static final Object[][] contents = {}; +} -- cgit