[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework JobContext.java, 1.5, 1.6 Reposi
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-13 23:29:32
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25409 Modified Files: Main.java Added Files: JobContext.java Repository.java Log Message: no message Index: Main.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/Main.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Main.java 13 Sep 2006 04:49:46 -0000 1.18 --- Main.java 13 Sep 2006 23:29:25 -0000 1.19 *************** *** 6,15 **** import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.config.FrameworkConfig; - import org.jmonks.batchserver.framework.config.FrameworkConfig.RepositoryConfig; import org.jmonks.batchserver.framework.config.JobConfig; import org.jmonks.batchserver.framework.config.JobConfigFactory; import org.jmonks.batchserver.framework.controller.JobController; import org.jmonks.batchserver.framework.management.JobManagementAgent; ! import org.jmonks.batchserver.framework.repository.Repository; --- 6,14 ---- import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.config.FrameworkConfig; import org.jmonks.batchserver.framework.config.JobConfig; import org.jmonks.batchserver.framework.config.JobConfigFactory; import org.jmonks.batchserver.framework.controller.JobController; import org.jmonks.batchserver.framework.management.JobManagementAgent; ! *************** *** 81,84 **** --- 80,85 ---- ErrorCode returnCode=ErrorCode.JOB_COMPLETED_SUCCESSFULLY; JobManagementAgent jobManagementAgent=null; + JobContext jobContext=null; + Main frameworkCreator=new Main(); String jobName=null; try *************** *** 114,138 **** logger.debug("Initializing the job logging"); LoggingManager.initializeJobLogging(jobName,frameworkConfig.getFrameworkLoggingConfig(), jobConfig.getJobLoggingConfig()); ! logger.debug("Initialize the repository"); ! if(frameworkConfig.getRepositoryConfig()!=null) ! { ! /** ! * Repository has been configured for this framework. ! * Initialize and clear the data transferred in the earlier run. ! */ ! Repository.createRepository(jobName, frameworkConfig.getRepositoryConfig()); ! Repository.getRepository().clearDataTransferredFromThisJob(); ! } ! logger.debug("Overriding the controller configuration properties with the command line properties."); ! jobConfig.getJobControllerConfig().overrideConfigProperties(configMap); logger.debug("Creating the job controller"); ! JobController jobController=JobController.getJobController(jobName, jobConfig.getJobControllerConfig()); logger.debug("Retrieving the management agent"); - /** - * TODO ::: This should be configurable or default service. - */ jobManagementAgent=JobManagementAgent.getJobManagementAgent(); logger.debug("Registering the controller with the management agent"); ! jobManagementAgent.start(jobName, jobController); logger.error("Kicking off the controller"); returnCode=jobController.process(); --- 115,126 ---- logger.debug("Initializing the job logging"); LoggingManager.initializeJobLogging(jobName,frameworkConfig.getFrameworkLoggingConfig(), jobConfig.getJobLoggingConfig()); ! logger.debug("Create the job context"); ! jobContext=createJobContext(jobConfig, configMap, frameworkCreator); logger.debug("Creating the job controller"); ! JobController jobController=JobController.getJobController(jobContext); logger.debug("Retrieving the management agent"); jobManagementAgent=JobManagementAgent.getJobManagementAgent(); logger.debug("Registering the controller with the management agent"); ! jobManagementAgent.start(jobContext, jobController, frameworkCreator); logger.error("Kicking off the controller"); returnCode=jobController.process(); *************** *** 142,146 **** JobStatistics jobStatistics=jobController.getJobStatistics(); logger.error(jobStatistics); ! Repository.getRepository().logStatistics(jobStatistics); } else --- 130,134 ---- JobStatistics jobStatistics=jobController.getJobStatistics(); logger.error(jobStatistics); ! jobContext.getRepository().logStatistics(jobStatistics); } else *************** *** 175,179 **** logger.debug("Unregistering the controller with the management agent"); if(jobManagementAgent!=null && jobManagementAgent.isRunning()) ! jobManagementAgent.stop(returnCode); } logger.error("Exiting process = " + returnCode); --- 163,167 ---- logger.debug("Unregistering the controller with the management agent"); if(jobManagementAgent!=null && jobManagementAgent.isRunning()) ! jobManagementAgent.stop(jobContext, returnCode, frameworkCreator); } logger.error("Exiting process = " + returnCode); *************** *** 251,253 **** --- 239,252 ---- System.exit(exitCode.getCode()); } + + private static JobContext createJobContext(JobConfig jobConfig, Map commandLineConfig, Main frameworkCreator) + { + Map contextParams=new HashMap(); + contextParams.put(JobContext.CONTEXT_PARAM_JOB_CONFIG, jobConfig); + contextParams.put(JobContext.CONTEXT_PARAM_JOB_COMMAND_LINE_CONFIG, commandLineConfig); + Repository repository=Repository.createRepository(jobConfig.getJobName(), FrameworkConfig.getInstance().getRepositoryConfig(), frameworkCreator); + contextParams.put(JobContext.CONTEXT_PARAM_REPOSITORY, repository); + JobContext jobContext=new JobContext(contextParams, frameworkCreator); + return jobContext; + } } --- NEW FILE: JobContext.java --- /* * JobContext.java * * Created on September 13, 2006, 1:18 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batchserver.framework; import java.util.Collections; import java.util.Map; import org.jmonks.batchserver.framework.config.FrameworkConfig; import org.jmonks.batchserver.framework.config.JobConfig; /** * * @author Suresh Pragada */ public class JobContext { public static final String CONTEXT_PARAM_JOB_CONFIG="job.config"; public static final String CONTEXT_PARAM_JOB_COMMAND_LINE_CONFIG="job.command.line.config"; public static final String CONTEXT_PARAM_REPOSITORY="repository"; protected JobConfig jobConfig=null; protected Repository repository=null; protected Map commandLineConfig=null; public JobContext(Map contextParams, Main contextCreator) { if(!(contextCreator instanceof Main)) throw new SecurityException("Not authorized to create the job context."); if(contextParams==null) throw new IllegalArgumentException("Context params to initialize the context cannot be null."); /** * Retrieve and add the command line config map to the context. */ if(contextParams.containsKey(JobContext.CONTEXT_PARAM_JOB_COMMAND_LINE_CONFIG)) { Object objectCommandLineConfig=contextParams.get(JobContext.CONTEXT_PARAM_JOB_COMMAND_LINE_CONFIG); if(objectCommandLineConfig instanceof Map) this.commandLineConfig=(Map)objectCommandLineConfig; else throw new IllegalArgumentException("Provided job command line configuration object to initalize job context is not valid."); } else throw new IllegalArgumentException("Missing the required job command line configuration map object in context params."); /** * Retrieve and add the job config instance to the context. */ if(contextParams.containsKey(JobContext.CONTEXT_PARAM_JOB_CONFIG)) { Object objectJobConfig=contextParams.get(JobContext.CONTEXT_PARAM_JOB_CONFIG); if(objectJobConfig instanceof JobConfig) this.jobConfig=(JobConfig)objectJobConfig; else throw new IllegalArgumentException("Provided job config object to initailize the job context is not valid."); } else throw new IllegalArgumentException("Missing the required job configuration object in context params."); /** * Retrieve and add the repository instance to the context. */ if(contextParams.containsKey(JobContext.CONTEXT_PARAM_REPOSITORY)) { Object objectRepository=contextParams.get(JobContext.CONTEXT_PARAM_REPOSITORY); if(objectRepository instanceof Repository) this.repository=(Repository)objectRepository; else throw new IllegalArgumentException("Provided repository object to initailize the job context is not valid."); } else throw new IllegalArgumentException("Missing the required repository object in context params."); } public String getJobName() { return this.jobConfig.getJobName(); } public Repository getRepository() { return this.repository; } public JobConfig getJobConfig() { return this.jobConfig; } public Map getJobCommandLineConfig() { return Collections.unmodifiableMap(this.commandLineConfig); } public FrameworkConfig getFrameworkConfig() { return FrameworkConfig.getInstance(); } } --- NEW FILE: Repository.java --- package org.jmonks.batchserver.framework; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.*; /** * <p> * Repository provides utility methods to access and use the repository maintained * by the framework. There could be differnt implementations of the repository. * Framework configuration defines which implementation should be used for this framework. * This povides utility methods to logs the job statistics and * transfer data between the jobs and register management and monitoring * information between. Repository make sure only one instance * of the implementation class will be created and it will be associated with the * job being run and all the opertions performated will be taken that job as a source job. * </p> * <p> * <i>Implementation Note : </i><br> * This declares an abstract method init with the protected access for the repository * implementors to inititalize the repository implementation. Implementors should implement * this method and make sure constructor is exist and accessible to enable the initialization of * this implementation from the factory method. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class Repository { private static Logger logger=Logger.getLogger(Repository.class); /** * Variable to hold the singleton instance of repository implementation * defined in framework configuration. */ private static Repository repository=null; /** * Name of the job associated with the repository. */ protected String jobName=null; /** * Method to initialize the repository implementation with the properties * defined in the framework configuration. * * @param configProps Configuration properties defined in <repository-config> element * in framework configuration file. * * @throws ConfigurationException If required configuration properties are missing or the values * are invalid. */ protected abstract void init(Map configProps); /** * <p> * Creates the repository instance based on the given configuration and associate * this repository instance with the given job. So all the repository opertions * performed from one job will be associated with that job only. This method * will be called by framework before kicking off the controller. Do not attempt * to call this method to create the repository from the client code. * </p> * * @throws IllegalStateException If there is an attempt is to create the repository * instance more than once. * @throws IllegalArgumentException If jobName is null to create the repository instance. * @throws ConfigurationException If required configuration properties are missing or the values * are invalid. */ public static Repository createRepository(String jobName, FrameworkConfig.RepositoryConfig repositoryConfig, Main repositoryCreator) { logger.trace("Entering createRepository"); if(!(repositoryCreator instanceof Main)) throw new SecurityException("Not authorized to create the repository."); if(repositoryConfig==null) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Repository configuration is not defined in framework configuration"); if(jobName==null || "".equals(jobName)) throw new IllegalArgumentException("Job Name cannot be null or empty to create repository instance."); String repositoryClassName=repositoryConfig.getRepositoryClassName(); if(repositoryClassName==null || "".equals(repositoryClassName)) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Repository class name is not defined in repository configuration"); logger.debug("repository class name = " + repositoryClassName); try { repository=(Repository)Class.forName(repositoryClassName).newInstance(); repository.init(repositoryConfig.getRepositoryConfigProperties()); repository.jobName=jobName; logger.debug("created the repository implemenation class"); } catch(ClassNotFoundException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } catch(InstantiationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } catch(IllegalAccessException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } logger.trace("Exiting createRepository " + (repository!=null)); return repository; } /** * <p> * Data will be sent to the specified target job. This data * will be marked with the data identifier. Target job * should use the data identifier to read the data. If there is any * data with this identifier from this job, it will be overriden. * </p> * * @param dataIdentifier Identifier to be used to exchange the data between two jobs. * @param nextJobName Name of the job this data to be send. * @param data Data that needs to be sent as the object. * * @return Returns true, if it could save the data to be sent to the next job. * * @throws IllegalArgumentException If any one of the input values is null. */ public abstract boolean sendDataToNextJob(String dataIdentifier, String nextJobName, final Object data); /** * Gets the data that has been sent to the target job from the source job * and identified by the given data identifier. * * @param dataIdentifier Identifier tied to the data wants to be read. * @param previousJobName Name of the job sent the data to this job. * * @return Returns the data, null, if it couldnt find any data. * * @throws IllegalArgumentException If any one of the input values is null. */ public abstract Object getDataFromPreviousJob(String dataIdentifier, String previousJobName); /** * <p> * This method will clear all the data that has been put up by * this job. Usually, this will be called by startp of framework, * before kicking off the controller. * </p> */ public abstract boolean clearDataTransferredFromThisJob(); /** * <p> * Registers the given job management and monitoring info with the job. * If there is any information already associated with this job, it * will be overriden. * </p> * * @param registrationInfo Information to be associated with the job. * * @return Return true, if it could assosciate this information, false, otherwise. * * @throws IllegalArgumentException If input argument registration information * value is null. */ public abstract boolean registerJobMgmtMntrInfo(final Object registrationInfo); /** * Unregisters the job management and monitoring info assosciated with the job. * * @return Return true, it it could unregister the information, false, otherwise. */ public abstract boolean unregisterJobMgmtMntrInfo(); /** * Logs the job statistics given in the form of JobStatistics object * in the repository for further use/references. * * @param statistics Job Statistics object which holds all the statistics related to that job. * * @return Returns true if statistics can be logged into repository, false, otherwise. * * @throws IllegalArgumentException If input argument job statistics is null. */ public abstract boolean logStatistics(final JobStatistics statistics); } |