Ubik Batch Server Eclipse plugin
From UbikWiki
(→Using DevClassLoader during development) |
|||
(4 intermediate revisions not shown.) | |||
Line 1: |
Line 1: | ||
+ | [[Category:Ubik Batch Server]] | ||
== Features == | == Features == | ||
The Eclipse plugin enables: | The Eclipse plugin enables: | ||
Line 62: |
Line 63: | ||
* businessLibrary that contains our business objects used accross Webapp and batches | * businessLibrary that contains our business objects used accross Webapp and batches | ||
* project-batch that depends on businessLibrary project | * project-batch that depends on businessLibrary project | ||
+ | |||
+ | == Batch Skeleton Configuration Creation == | ||
+ | [[Image:batch_creation_step1.jpg]] | ||
+ | |||
+ | [[Image:batch_creation_step2.jpg]] | ||
+ | |||
+ | [[Image:batch_creation_step3.jpg]] | ||
+ | |||
+ | You have the ability to test the Cron Expression (Click on Next 20th fires): | ||
+ | |||
+ | [[Image:batch_creation_step4.jpg]] | ||
+ | |||
+ | Click on Finish button, this generates: | ||
+ | <source lang="java"> | ||
+ | // com.ubikingenierie.demo.DemoBatchThatReadsCustomer | ||
+ | package com.ubikingenierie.demo; | ||
+ | |||
+ | import java.text.ParseException; | ||
+ | import java.text.SimpleDateFormat; | ||
+ | import java.util.TimeZone; | ||
+ | |||
+ | import org.quartz.Trigger; | ||
+ | |||
+ | import salto.batch.appender.JdbcErrorAppender; | ||
+ | import salto.batch.lanceur.BatchException; | ||
+ | import salto.batch.lanceur.builder.TraitementConfiguration; | ||
+ | import salto.batch.lanceur.init.IBatchStart; | ||
+ | import salto.batch.lanceur.init.SqlBatchStart; | ||
+ | import salto.batch.linker.AbstractLinker; | ||
+ | import salto.batch.trigger.CronTrigger; | ||
+ | |||
+ | import com.ubikingenierie.console.apiconsole.BaseBatch; | ||
+ | |||
+ | /** | ||
+ | * Automatically generated class by Ubik Server Batch wizard | ||
+ | * | ||
+ | * This class must be set with the SqlBatchStart. | ||
+ | * | ||
+ | * Generated class | ||
+ | */ | ||
+ | public class DemoBatchThatReadsCustomer extends BaseBatch { | ||
+ | /** | ||
+ | * Implement this method to execute the business code on the Block of data<br/> | ||
+ | * @param data Object[] Array of Data as specified by {@link IBatchStart} | ||
+ | * @throws Exception | ||
+ | */ | ||
+ | protected void executeOnBlock(Object[] data) | ||
+ | throws Exception | ||
+ | { | ||
+ | // TODO Implement | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Called when batch is triggered.<br/>. | ||
+ | * It is called in mono-threaded mode and before data has been extracted from {@link IBatchStart}.<br/> | ||
+ | * Default implementatin is NOOP. | ||
+ | * PART OF PUBLIC API | ||
+ | * @throws Exception | ||
+ | */ | ||
+ | protected void executeBeforeData() | ||
+ | throws Exception | ||
+ | { | ||
+ | // TODO Implement | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Called when batch has finished treating all data or has encountered an error.<br/>. | ||
+ | * It is called in mono-threaded mode.<br/> | ||
+ | * Default implementatin is NOOP. | ||
+ | * @throws Exception | ||
+ | */ | ||
+ | protected void executeAfterDataEnd() | ||
+ | throws Exception | ||
+ | { | ||
+ | // TODO Implement | ||
+ | } | ||
+ | |||
+ | |||
+ | /** | ||
+ | * Method used to create a Batch configuration | ||
+ | * @return {@link TraitementConfiguration} Configuration of Batch | ||
+ | * @throws BatchException | ||
+ | */ | ||
+ | public TraitementConfiguration createConfiguration() throws BatchException | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | TraitementConfiguration configuration = new TraitementConfiguration(); | ||
+ | configuration.setGroup("com.ubikingenierie.demo"); | ||
+ | configuration.setName("DemoBatchThatReadsCustomer"); | ||
+ | configuration.setTrtClassName(DemoBatchThatReadsCustomer.class.getName()); | ||
+ | |||
+ | SqlBatchStart starter = new SqlBatchStart("jdbc/batchweb","select CLT_ID, CLT_NAME, CLT_FIRST_NAME, CLT_AGE from CUSTOMER",200,false); | ||
+ | |||
+ | // Log en base le démarrage/arrêt/erreurs | ||
+ | JdbcErrorAppender errorAppender = new JdbcErrorAppender(); | ||
+ | errorAppender.setJndiConnection("java:comp/env/jdbc/console"); | ||
+ | configuration.setBatchAppender(errorAppender); | ||
+ | |||
+ | configuration.setBatchStart(starter); | ||
+ | |||
+ | configuration.setMaxThreads(5); | ||
+ | configuration.setMinJob(1); | ||
+ | configuration.setMaxJob(10); | ||
+ | |||
+ | // use salto.batch.trigger.CronTrigger and not org.quartz.CronTrigger | ||
+ | |||
+ | SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); | ||
+ | |||
+ | CronTrigger trigger1 = new CronTrigger(); | ||
+ | |||
+ | // Initialize of mandatory attributes | ||
+ | trigger1.setJobGroup("com.ubikingenierie.demo"); | ||
+ | trigger1.setJobName("DemoBatchThatReadsCustomer"); | ||
+ | trigger1.setGroup("com.ubikingenierie.demo"); | ||
+ | trigger1.setName("DemoBatchThatReadsCustomerDailyTrigger"); | ||
+ | |||
+ | // Initialize of starting periods | ||
+ | trigger1.setCronExpression("0 0 0 1 * ?"); | ||
+ | trigger1.setStartTime(sdf.parse("11/12/2007")); | ||
+ | trigger1.setEndTime(null); | ||
+ | trigger1.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); | ||
+ | trigger1.setMisfireInstruction(2); | ||
+ | |||
+ | configuration.setTriggers(new Trigger[] { | ||
+ | trigger1 | ||
+ | |||
+ | }); | ||
+ | |||
+ | |||
+ | AbstractLinker[] linkers = new AbstractLinker[]{ | ||
+ | }; | ||
+ | configuration.setLinkers(linkers); | ||
+ | |||
+ | // Record in the scheduler | ||
+ | return configuration; | ||
+ | } | ||
+ | catch (ParseException e) { | ||
+ | throw new BatchException("Error in configuration, message="+e.getMessage(),e); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | == Authors == | ||
+ | * Philippe Mouawad | ||
+ | |||
+ | == History == | ||
+ | <pageby/> |
Current revision
Contents |
Features
The Eclipse plugin enables:
- Project Model creation
- Batch skeleton configuration creation
- Tomcat DevLoader equivalent for Batch Server
Plugin configuration
Project Creation
Right click in Navigator panel and select New > Project:
This will create a project that has the following layout:
It also creates an Eclipse Launch, to launch the server go to Debug Perspective and click on the created launch (The launch requires a JDK 5):
Using DevClassLoader during development
In most of the case you will at least have 2 projects:
- Business project (It contains no batch but rather the objects that are also used by Web Applications)
- Batch project
- Maybe common library used across your company
During development, you need to make change to the code of one of the 3 libraries, and you want you changes to be taken into account immediately. Without the Plugin, you would have to recreate the JARs of the dependent projects:
- Business project (It contains no batch but rather the objects that are also used by Web Applications)
- Maybe common library used across your company
And recreate the BAR, and finally redeploy it.
To avoid this, the plugin enables referencing external projects like:
- Business project (It contains no batch but rather the objects that are also used by Web Applications)
- Maybe common library used across your company
And also the Batch project.
Configuration:
Server configuration
Open config\config.properties file and uncomment:
BAR_CLASSLOADER_FACTORY=com.ubikingenierie.console.batch.loader.factory.DevBarClassLoaderFactory
Project configuration
To tell the server which libraries and class path to take into accound, right click on your project and click on UbikBatchPlugin classpath and check the librairies and class paths that must be added to your BAR:
In this example, we have:
- businessLibrary that contains our business objects used accross Webapp and batches
- project-batch that depends on businessLibrary project
Batch Skeleton Configuration Creation
You have the ability to test the Cron Expression (Click on Next 20th fires):
Click on Finish button, this generates:
// com.ubikingenierie.demo.DemoBatchThatReadsCustomer package com.ubikingenierie.demo; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.TimeZone; import org.quartz.Trigger; import salto.batch.appender.JdbcErrorAppender; import salto.batch.lanceur.BatchException; import salto.batch.lanceur.builder.TraitementConfiguration; import salto.batch.lanceur.init.IBatchStart; import salto.batch.lanceur.init.SqlBatchStart; import salto.batch.linker.AbstractLinker; import salto.batch.trigger.CronTrigger; import com.ubikingenierie.console.apiconsole.BaseBatch; /** * Automatically generated class by Ubik Server Batch wizard * * This class must be set with the SqlBatchStart. * * Generated class */ public class DemoBatchThatReadsCustomer extends BaseBatch { /** * Implement this method to execute the business code on the Block of data<br/> * @param data Object[] Array of Data as specified by {@link IBatchStart} * @throws Exception */ protected void executeOnBlock(Object[] data) throws Exception { // TODO Implement } /** * Called when batch is triggered.<br/>. * It is called in mono-threaded mode and before data has been extracted from {@link IBatchStart}.<br/> * Default implementatin is NOOP. * PART OF PUBLIC API * @throws Exception */ protected void executeBeforeData() throws Exception { // TODO Implement } /** * Called when batch has finished treating all data or has encountered an error.<br/>. * It is called in mono-threaded mode.<br/> * Default implementatin is NOOP. * @throws Exception */ protected void executeAfterDataEnd() throws Exception { // TODO Implement } /** * Method used to create a Batch configuration * @return {@link TraitementConfiguration} Configuration of Batch * @throws BatchException */ public TraitementConfiguration createConfiguration() throws BatchException { try { TraitementConfiguration configuration = new TraitementConfiguration(); configuration.setGroup("com.ubikingenierie.demo"); configuration.setName("DemoBatchThatReadsCustomer"); configuration.setTrtClassName(DemoBatchThatReadsCustomer.class.getName()); SqlBatchStart starter = new SqlBatchStart("jdbc/batchweb","select CLT_ID, CLT_NAME, CLT_FIRST_NAME, CLT_AGE from CUSTOMER",200,false); // Log en base le démarrage/arrêt/erreurs JdbcErrorAppender errorAppender = new JdbcErrorAppender(); errorAppender.setJndiConnection("java:comp/env/jdbc/console"); configuration.setBatchAppender(errorAppender); configuration.setBatchStart(starter); configuration.setMaxThreads(5); configuration.setMinJob(1); configuration.setMaxJob(10); // use salto.batch.trigger.CronTrigger and not org.quartz.CronTrigger SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); CronTrigger trigger1 = new CronTrigger(); // Initialize of mandatory attributes trigger1.setJobGroup("com.ubikingenierie.demo"); trigger1.setJobName("DemoBatchThatReadsCustomer"); trigger1.setGroup("com.ubikingenierie.demo"); trigger1.setName("DemoBatchThatReadsCustomerDailyTrigger"); // Initialize of starting periods trigger1.setCronExpression("0 0 0 1 * ?"); trigger1.setStartTime(sdf.parse("11/12/2007")); trigger1.setEndTime(null); trigger1.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); trigger1.setMisfireInstruction(2); configuration.setTriggers(new Trigger[] { trigger1 }); AbstractLinker[] linkers = new AbstractLinker[]{ }; configuration.setLinkers(linkers); // Record in the scheduler return configuration; } catch (ParseException e) { throw new BatchException("Error in configuration, message="+e.getMessage(),e); } } }
Authors
- Philippe Mouawad