[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework LoggingManager.java, 1.7, 1.8 Ma
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-14 23:05:19
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv10680 Modified Files: LoggingManager.java Main.java Log Message: no message Index: Main.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/Main.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Main.java 13 Sep 2006 23:29:25 -0000 1.19 --- Main.java 14 Sep 2006 23:05:13 -0000 1.20 *************** *** 12,22 **** - - - /** * <p> ! * Main class is the entry point to the batch framework. This provides ! * the methods to accept the information to identify the job and kick off the job. * The framework can be executed either through command line as an independent * program or from any other java program. The information on how to kickoff using --- 12,19 ---- /** * <p> ! * Main is the entry point to the batch framework. This provides ! * the methods to accept the information to identify the job and kicks off the job. * The framework can be executed either through command line as an independent * program or from any other java program. The information on how to kickoff using *************** *** 34,54 **** /** ! * Key name have the value of the job name in configuration map. */ public static final String JOB_NAME_KEY_NAME = "job-name"; /** ! * Restrict the temptation of creating the instance of Main. */ private Main() { } /** * <p> * This method provides the interface to execute the job from another java ! * program. This accepts the job-name and additional configuration information ! * relate to this job as a key value pairs in the map. Among the entries ! * in the map, there should be <i>job-name</i> key available with the values ! * as a name of the job to be executed. * <br><br> * <pre> --- 31,54 ---- /** ! * Name of the parameter key holds the job name in configuration map which ! * is <code>job-name</code>. */ public static final String JOB_NAME_KEY_NAME = "job-name"; /** ! * Restrict the temptation of creating the instance of Main to create ! * any resources in the framework. */ private Main() { } + /** * <p> * This method provides the interface to execute the job from another java ! * program. This accepts the job name and additional configuration information ! * relate to this job as a key value pairs in the map. Among these entries ! * in the map, there should be a <i>job-name</i> parameter key available to ! * identify the job to be executed. * <br><br> * <pre> *************** *** 58,67 **** * configMap.put("config-name2","config-value2"); * ! * ErrorCode statusCode=Main.process(configMap); ! * System.out.println("Job exited with return code : " + errorCode.toString()); * </pre> * <br><br> ! * Whatever the configuration key values passed here will override the values ! * defined in job configuration. * </p> * <br> --- 58,68 ---- * configMap.put("config-name2","config-value2"); * ! * ErrorCode exitCode=Main.process(configMap); ! * System.out.println("Job exited with return code : " + exitCode.getCode()); * </pre> * <br><br> ! * Whatever the configuration passed here can be retrived from the JobContext ! * instance passed to all the jobs either through initialize methods or process ! * methods. * </p> * <br> *************** *** 69,73 **** * @param configMap Map object consist of all the properties needed to kick off this batch job. * ! * @return Returns zero for success and non-zero for failure. * * @throws IllegalArgumentException If input configMap is null. --- 70,74 ---- * @param configMap Map object consist of all the properties needed to kick off this batch job. * ! * @return Returns ErrorCode provides the status of the batch job. * * @throws IllegalArgumentException If input configMap is null. *************** *** 91,95 **** FrameworkConfig frameworkConfig=FrameworkConfig.getInstance(); logger.debug("Initializing the framework logging"); ! LoggingManager.initializeFrameworkLogging(frameworkConfig.getFrameworkLoggingConfig()); /** * Get the job name from given configMap and start execution. --- 92,97 ---- FrameworkConfig frameworkConfig=FrameworkConfig.getInstance(); logger.debug("Initializing the framework logging"); ! LoggingManager.initializeFrameworkLogging( ! frameworkConfig.getFrameworkLoggingConfig(), frameworkCreator); /** * Get the job name from given configMap and start execution. *************** *** 104,108 **** */ logger.debug("Retrieving the configuration factory"); ! JobConfigFactory jobConfigFactory=JobConfigFactory.getJobConfigFactory(frameworkConfig.getJobConfigFactoryConfig()); logger.debug("Retrieving the job configuration"); JobConfig jobConfig=jobConfigFactory.getJobConfig(jobName); --- 106,111 ---- */ logger.debug("Retrieving the configuration factory"); ! JobConfigFactory jobConfigFactory=JobConfigFactory. ! getJobConfigFactory(frameworkConfig.getJobConfigFactoryConfig()); logger.debug("Retrieving the job configuration"); JobConfig jobConfig=jobConfigFactory.getJobConfig(jobName); *************** *** 114,118 **** */ logger.debug("Initializing the job logging"); ! LoggingManager.initializeJobLogging(jobName,frameworkConfig.getFrameworkLoggingConfig(), jobConfig.getJobLoggingConfig()); logger.debug("Create the job context"); jobContext=createJobContext(jobConfig, configMap, frameworkCreator); --- 117,122 ---- */ logger.debug("Initializing the job logging"); ! LoggingManager.initializeJobLogging(jobName,frameworkConfig. ! getFrameworkLoggingConfig(), jobConfig.getJobLoggingConfig(), frameworkCreator); logger.debug("Create the job context"); jobContext=createJobContext(jobConfig, configMap, frameworkCreator); *************** *** 173,181 **** * <p> * This method provides the interface to execute the jobs from command line. ! * This accepts the job name and additional configuration information relate * to this job as a command line parameters. Each parameter passed through * command line should be in the format <i>name=value</i>. Among these, ! * <i>job-name=process_file_abc</i> property should exist. ! * The ErrorCode's code value will be return as exit code. * </p> * <p> --- 177,185 ---- * <p> * This method provides the interface to execute the jobs from command line. ! * This accepts the job name and additional configuration information related * to this job as a command line parameters. Each parameter passed through * command line should be in the format <i>name=value</i>. Among these, ! * <i>job-name=process_file_abc</i> property should exist to identify the job ! * to kick off. The ErrorCode's code value will be returned as exit code. * </p> * <p> *************** *** 183,187 **** * java org.jmonks.batchserver.framework.Main job-name=process_file_abc config-name1=config-value1 config-name2=config-value2 * <br><br> ! * Whatever the configuration paremters passed here will override the values defined in job configuration. * </p> * --- 187,193 ---- * java org.jmonks.batchserver.framework.Main job-name=process_file_abc config-name1=config-value1 config-name2=config-value2 * <br><br> ! * Whatever the configuration paremters passed here can be retrieved using ! * the JobContext reference passed to all the jobs either using their initialize ! * methods or process methods. * </p> * *************** *** 191,194 **** --- 197,201 ---- { ErrorCode exitCode=ErrorCode.JOB_COMPLETED_SUCCESSFULLY; + Main frameworkCreator=new Main(); try { *************** *** 199,203 **** FrameworkConfig frameworkConfig=FrameworkConfig.getInstance(); logger.debug("Initializing the framework logging"); ! LoggingManager.initializeFrameworkLogging(frameworkConfig.getFrameworkLoggingConfig()); /** --- 206,211 ---- FrameworkConfig frameworkConfig=FrameworkConfig.getInstance(); logger.debug("Initializing the framework logging"); ! LoggingManager.initializeFrameworkLogging(frameworkConfig. ! getFrameworkLoggingConfig(), frameworkCreator); /** *************** *** 239,250 **** 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; --- 247,276 ---- System.exit(exitCode.getCode()); } ! ! /** ! * Creates the map to be passed to create the JobContext and passes it to the ! * JobContext and returns the created JobContext object. ! * ! * @param jobConfig Job configuration object. ! * @param invokeConfig Configuration provided at invocation time. ! * @param frameworkCreator Authorized class to the create the job context. ! * ! * @return Returns the JobContext reference. ! */ ! private static JobContext createJobContext(JobConfig jobConfig, Map invokeConfig, Main frameworkCreator) { + /** + * Create the context params map to create the JobContext instance. + */ Map contextParams=new HashMap(); contextParams.put(JobContext.CONTEXT_PARAM_JOB_CONFIG, jobConfig); ! contextParams.put(JobContext.CONTEXT_PARAM_JOB_INVOKE_CONFIG, invokeConfig); ! Repository repository=Repository.createRepository(jobConfig.getJobName(), ! FrameworkConfig.getInstance().getRepositoryConfig(), frameworkCreator); contextParams.put(JobContext.CONTEXT_PARAM_REPOSITORY, repository); + + /** + * Create the JobContext and return it. + */ JobContext jobContext=new JobContext(contextParams, frameworkCreator); return jobContext; Index: LoggingManager.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/LoggingManager.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** LoggingManager.java 6 Sep 2006 22:08:23 -0000 1.7 --- LoggingManager.java 14 Sep 2006 23:05:13 -0000 1.8 *************** *** 9,13 **** import org.apache.log4j.PatternLayout; import org.apache.log4j.RollingFileAppender; ! import org.jmonks.batchserver.framework.config.*; /** --- 9,16 ---- import org.apache.log4j.PatternLayout; import org.apache.log4j.RollingFileAppender; ! import org.jmonks.batchserver.framework.config.ConfigurationException; ! import org.jmonks.batchserver.framework.config.FrameworkConfig.FrameworkLoggingConfig; ! import org.jmonks.batchserver.framework.config.JobLoggingConfig; ! /** *************** *** 17,34 **** * which works for all the jobs and provide the facility to * use their own logging mechanism. ! * * The default logging mechanism defined at the framework will * work like this. It reads the directory to create the log files from ! * the framework logging configuration <logging-config> and creates a directory * with the "job-name" and create the log files for each run. So, the format * will be * <br><br> ! * <directory-defined-in-config>/job-name/jobname_with_timestamp.log * <br><br> ! * * If job developer would like to override this logging mechanism, they can ! * define their logging configuration in the element <job-logging-config> in batch ! * configuration file or defining entries in job_logging_config table. * </p> * @author Suresh Pragada * @version 1.0 --- 20,40 ---- * which works for all the jobs and provide the facility to * use their own logging mechanism. ! * </p> ! * <p> * The default logging mechanism defined at the framework will * work like this. It reads the directory to create the log files from ! * the framework logging configuration <logging-config> and creates a directory * with the "job-name" and create the log files for each run. So, the format * will be * <br><br> ! * <directory-defined-in-config>/job-name/jobname_with_timestamp.log * <br><br> ! * </p> ! * <p> * If job developer would like to override this logging mechanism, they can ! * define their logging configuration in the element <job-logging-config> in ! * batch job configuration file or defining entries in job_logging_config table. * </p> + * * @author Suresh Pragada * @version 1.0 *************** *** 38,42 **** { /** ! * Framework configuration file. */ public static final String FRAMEWORK_LOGGING_FILE = "batch_framework.log"; --- 44,48 ---- { /** ! * Framework configuration file which is batch_framework.log. */ public static final String FRAMEWORK_LOGGING_FILE = "batch_framework.log"; *************** *** 46,53 **** public static final String DEFAULT_MESSAGE_PATTERN = "%5p [%d{ISO8601}] [%t - %C] %m%n"; /** ! * Tells whether framework logging has been intialized or not. */ private static boolean isFrameworkLoggingInitialized=false; - /** * Private constructor to make sure LoggingManager will not be instantiated. --- 52,58 ---- public static final String DEFAULT_MESSAGE_PATTERN = "%5p [%d{ISO8601}] [%t - %C] %m%n"; /** ! * Tells whether framework logging has been already initailized or not. */ private static boolean isFrameworkLoggingInitialized=false; /** * Private constructor to make sure LoggingManager will not be instantiated. *************** *** 63,67 **** * This does the follwing steps. * <ul> ! * <li>Create the directory <directory name configured in logging config>/jobName * <li>Generates the logging file name jobName_yyyymmdd_hhmmss_ms.log * <li>Creates the Rolling File appender with the above created directory and logging file name. --- 68,72 ---- * This does the follwing steps. * <ul> ! * <li>Create the directory <directory name configured in logging config>/jobName * <li>Generates the logging file name jobName_yyyymmdd_hhmmss_ms.log * <li>Creates the Rolling File appender with the above created directory and logging file name. *************** *** 74,90 **** * @param frameworkLoggingConfig Logging configuration defined at the framework. * @param jobLoggingFramework Logging configuration defined at the job level. * ! * @throws IllegalArgumentException If input values jobName and frameworkLoggingConfig are null. * @throws ConfigurationException If logging file cannot be created at the configured directory. * </p> */ ! public static void initializeJobLogging(String jobName, FrameworkConfig.FrameworkLoggingConfig frameworkLoggingConfig,JobLoggingConfig jobLoggingConfig) { ! if(jobName==null) ! throw new IllegalArgumentException("job name cannot be null to establish the job logging service."); - if(frameworkLoggingConfig==null) - throw new IllegalArgumentException("framework logging config object cannot be null to establish the job logging service."); - File loggingDirecotry=new File(frameworkLoggingConfig.getJobLoggingDirecotry()+File.separator+jobName); LoggingManager.createDirectory(loggingDirecotry); --- 79,93 ---- * @param frameworkLoggingConfig Logging configuration defined at the framework. * @param jobLoggingFramework Logging configuration defined at the job level. + * @param loggingInitalizer Main class instance which is authorized to initailze the job logging. * ! * @throws SecurityException If any class other than Main(framework) tried to initialize the job logging. * @throws ConfigurationException If logging file cannot be created at the configured directory. * </p> */ ! public static void initializeJobLogging(String jobName, FrameworkLoggingConfig frameworkLoggingConfig,JobLoggingConfig jobLoggingConfig, Main loggingInitalizer) { ! if(!(loggingInitalizer instanceof Main)) ! throw new SecurityException("Not authorized to initialize the job logging."); File loggingDirecotry=new File(frameworkLoggingConfig.getJobLoggingDirecotry()+File.separator+jobName); LoggingManager.createDirectory(loggingDirecotry); *************** *** 129,137 **** * * @param frameworkLoggingConfig Framework logging configuration object. * * @throws ConfigurationException If logging directory cannot be created. */ ! public static synchronized void initializeFrameworkLogging(FrameworkConfig.FrameworkLoggingConfig frameworkLoggingConfig) { if(!isFrameworkLoggingInitialized) { --- 132,145 ---- * * @param frameworkLoggingConfig Framework logging configuration object. + * @param loggingInitalizer Main class instance which is authorized to initailze the logging. * + * @throws SecurityException If any class other than Main(framework) tried to initialize the framework logging. * @throws ConfigurationException If logging directory cannot be created. */ ! public static synchronized void initializeFrameworkLogging(FrameworkLoggingConfig frameworkLoggingConfig, Main loggingInitalizer) { + if(!(loggingInitalizer instanceof Main)) + throw new SecurityException("Not authorized to initialize the framework logging."); + if(!isFrameworkLoggingInitialized) { *************** *** 160,168 **** frameworkLogger.setAdditivity(true); frameworkLogger.setLevel(Level.toLevel(frameworkLoggingConfig.getFrameworkLoggingLevel())); ! isFrameworkLoggingInitialized=true; } else ! System.out.println("Framework logging has been already initialized."); } --- 168,180 ---- frameworkLogger.setAdditivity(true); frameworkLogger.setLevel(Level.toLevel(frameworkLoggingConfig.getFrameworkLoggingLevel())); ! isFrameworkLoggingInitialized=true; } else ! { ! /** ! * Framework logging has been already initialized. Ignore this call. ! */ ! } } |