Quartz trigger state is not persisting on server start - quartz-scheduler

We have a requirement to pause a job before application maintenance. We are using Quartz 2.2.1 in cluster. Database is oracle.
I have developed a screen with "Pause" functionality. I observed that "pause" works fine until I start the server again. The moment I start server, TRIGGER_STATE of QRTZ_TRIGGERS table resets to "WAITING".
Can anyone please provide a hint.
Thanks a lot in advance.
Rgds - Roy

If you have set overwriteExistingJobs=true (note that default value is false) then each time server starts, it loads the jobs/triggers from the configuration file and replaces existing ones (that have the same job/trigger names), therefore overwriting triggers and their states too as in your case.
You could try to set overwriteExistingJobs=false in the SchedulerFactoryBean. This however may not be convenient for you, since if you ever change job configuration in the server, the existing jobs with old configuration will remain in the database.
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
....
<property name="overwriteExistingJobs" value="false"/>
<property name="triggers">
<list>
....
</list>
</property>
....
</bean>

Related

JobExecution null in spring batch

I am running jobs in parallel. My job execution is always null when I use JobRepositoryFactoryBean. I need to use to use this. If I don't use this, then I will not be able to use metadata tables. Because I want to restart my job when it is not completed because of some failure reason. So, I want previous record which I will be fetching from metadata tables. And if I use MapJobRepositoryFactoryBean, the job execution is not null. But then there will not be insertion in metadata tables.
I referred this link:-
My job is always null. Can't inject a batch job with Spring Batch. Why?
But the link is not working for me.
My congifuration is
<bean id="batchScheduler" class="com.abc.BatchScheduler">
<property name="jobLauncher" ref="jobLauncher" />
<property name="jobtwo" ref="JobTwo" />
</bean>
I searched a lot. Please help me out. I am not able to proceed.

Spring Batch Integration, Email to be sent out in case of JobInstanceAlreadyCompleteException

I would like to put a hook somewhere in the following code/config to be able to spot a JobInstanceAlreadyCompleteException and then email the production support team that this occurred.
I have tried a JobExecutionListener#beforeJob() method in Spring Batch, but the JobInstanceAlreadyCompleteException is occurring before job execution.
I am using this Spring Batch Integration configuration from the documentation:
<int:channel id="inboundFileChannel"/>
<int:channel id="outboundJobRequestChannel"/>
<int:channel id="jobLaunchReplyChannel"/>
<int-file:inbound-channel-adapter id="filePoller"
channel="inboundFileChannel"
directory="file:/tmp/myfiles/"
filename-pattern="*.csv">
<int:poller fixed-rate="1000"/>
</int-file:inbound-channel-adapter>
<int:transformer input-channel="inboundFileChannel"
output-channel="outboundJobRequestChannel">
<bean class="io.spring.sbi.FileMessageToJobRequest">
<property name="job" ref="personJob"/>
<property name="fileParameterName" value="input.file.name"/>
</bean>
</int:transformer>
I want to handle JobInstanceAlreadyCompleteException in case the same CSV file name appears as the job parameter. Do I extend org.springframework.integration.handler.LoggingHandler?
I notice that class is reporting the error:
ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.messaging.MessageHandlingException: org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={input.file.name=C:\Users\csv\file2015.csv}. If you want to run this job again, change the parameters.
The ERROR org.springframework.integration.handler.LoggingHandler is done from the default errorChannel which is reached from the <poller> on your <int-file:inbound-channel-adapter>.
So, to handle it manually your just need to specify your own error-channel there a go ahead with email sending:
<int-file:inbound-channel-adapter>
<int:poller fixed-rate="1000" error-channel="sendErrorToEmailChannel"/>
</int-file:inbound-channel-adapter>
<int-mail:outbound-channel-adapter id="sendErrorToEmailChannel"/>
Of course, you will have to do some ErrorMessage transformation before sending ti over e-mail, but that is already details of the target business logic implementation.

Spring Batch: Duplicate rows after job re-run

Our Spring Batch application is, upon restart of a failed job, processing the same records again, resulting in duplicate rows, and we want to understand how to avoid this.
The Spring Integration poller which starts the batch job is configured to run every couple of hours. When it runs a second time, the job parameters will be the same, but if the previous run failed (for example, because of a DataTruncation exception), Spring Batch will not complain that the job has already completed.
At the point of failure, several hundred thousand records will already have been processed and copied fromn the source table to the destination table. When the job is run a subsequent time, the same rows will be copied to the destination table, resulting in duplicates. Therefore, it appears that the job is not being resumed, but restarted from the beginning.
The Spring Batch database is Derby (file based), this is setup when the application starts, and it appears state is not maintained between restarts of the actual application (because a job can be run again with the same parameters). However, within one application run, state is maintained. For instance, if the job completes succesfully, the next time the poller runs an exception will be thrown because a job (with those parameters) has already completed.
Our job is definition is as follows:
<batch:job id="publisherJob" >
<batch:step id="step1">
<batch:tasklet >
<batch:chunk reader="itemReader" processor="itemProcessor"
writer="itemWriter" commit-interval="${...}" />
</batch:tasklet>
<batch:listeners>
...
</batch:listeners>
</batch:job>
<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
<property name="dataSource" ref="dataSource" />
<property name="sql" value="select ${...} from ${...} where ${...}" />
<property name="rowMapper" ref="rowMapper" />
</bean>
The WHERE clause includes ORDER BY.
Our understanding was that Spring Batch would retain the state at which processing failed and proceed from that point (if the error in the source table has been fixed), therefore preventing duplicate rows. What has to be configured for this to happen?
Thanks
Spring Batch maintains state in that it remembers how many records were processed, not specifically which ones. Because of that, it's up to you to guarantee the order of the items is reproducible from run to run so that if we process 100 records in run 1 and fail, when we skip the first 100 records in run 2, those are the right 100 records to skip. You didn't provide the configuration for your JdbcCursorItemReader but my assumption is that you are not using an order by in your SQL. If you want restartability, you need some way to guarantee the order of the items. Using an order by in your SQL is the easiest way to accomplish this (there are others like using the process indicator pattern if that's needed).

Report job scheduling with custom data-source in jasper server 4.5.0

I am using Jasperserver 4.5.0 Pro. I have developed a custom data-source for some additional feature. All reports that use this custom DS get executed properly and show the correct output when executed manually. But when the same reports are scheduled using Jasper's report job scheduler, there is some problem with session initiation, and hence the reports do not get executed.
Let me explain this a bit.
For manual execution of reports -
As part of custom DS, I had to update the following 2 xmls -
viewReportFlow.xml :
I updated the action state 'runReport' to use our custom DS executer action bean method 'xmlHttpDsExecuterAction.setUpSession' to start session. Please see the below tag of runReport -
<action-state id="runReport" xmlns:b="http://www.springframework.org/schema/webflow" xmlns:xi="http://www.w3.org/2001/XInclude">
<on-entry>
<evaluate expression="xmlHttpDsExecuterAction.setUpSession"/>
</on-entry>
<evaluate expression="viewReportActionBean"/>
<transition on="success" to="reportOutput"/>
<on-exit>
<evaluate expression="xmlHttpDsExecuterPageAction.setIndex"/>
</on-exit>
viewReportBeans.xml :
I defined the executer action beans used in above flow xml here -
<bean id="xmlHttpDsExecuterAction" class="com.sigma.reporting.xmlhttpds.XmlHttpDsExecuterAction" xmlns:xsi="http://www.w 3.org/2001/XMLSchema-instance"/> <bean id="xmlHttpDsExecuterPageAction" class="com.sigma.reporting.xmlhttpds.XmlHttpDsExecuterPageAction" xmlns:xsi="http://www.w 3.org/2001/XMLSchema-instance">
<property name="requestParameterPageIndex" value="pageIndex"/>
<property name="flowAttributePageIndex" value="pageIndex"/>
<property name="xmlHttpDataSourceName" value="com.sigma.reporting.xmlhttpds.XmlHttpDsExecuterDataSourceService"/>
<property name="repository">
<ref bean="repositoryService"/>
</property>
<property name="jasperPrintName" value="jasperPrintName"/>
<property name="reportUnitObject" value="reportUnitObject"/> </bean>
For job scheduling of reports :
I want to implement similarly as above using scheduler. During my investigations, I have tried to analyze the scheduler flow, and tried to put our changes, but no luck so far. Can any one please let me know what flows are used for running reports via scheduler and also please recommend the places to configure custom DS as above?
Finally after understanding the flow of japser server scheduler i have got the solution for this.
For setting your custom data source beans and calling the function,we need to specify the bean destination in $JASPER_HOME/apache-tomcat/weaaps/jasperserver-pro/WEBINF/flows/reportJobBeans.xml and we can use this bean in reportJobFlow.xml in jobOutput tag lik this
<view-state id="jobOutput" view="modules/reportScheduling/jobOutput">
<on-entry>
<set name="flowScope.prevForm" value="'jobOutput'"/>
<evaluate expression="reportOptionsJobEditAction.setOutputReferenceData"/>
<evaluate expression="xmlHttpDsExecuterAction.setUpSession"/>
</on-entry>
</view-state>

Problem changing Database in Hibernate

i'm having a problem with hibernate and don't know exactly what's going on, i have this project at work where i connect to an Oracle 10g Database using the following settings:
Host Name: localhost
port:1521
SID:orcl
user:anfxi
password:password
Now i'm at home trying to work with the same database remotely, im connected via VPN and the database ip is now 10.73.98.230 , i imported my WAR and changed the settings in my
hibernate.cfg.xml from:
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin://localhost:1521:orcl</property>
<property name="hibernate.connection.username">anfexi</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<property name="current_session_context_class">thread</property>
to:
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin://10.73.98.230:1521:orcl</property>
<property name="hibernate.connection.username">anfexi</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<property name="current_session_context_class">thread</property>
but i keep getting this error:
ERROR [main] (SchemaValidator.java:135) - could not get database metadata
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:orcl
so it seems to be still using localhost as the DB address, i cleaned my project and rebuilt, still with no luck, is there something else that i could be missing? does the hibernate configuration gets cached in some file i have to erase or something?
EDIT
For what it may serve, i can connect using SQL developer,the problem is just hibernate still using the old localhost:1521:orcl Connection descriptor.
Thanks for your help!
Verify that the xml file you are changing in Eclipse is actually being deployed to the server. I run into problems every once in awhile where Eclipse doesn't know it needs to redeploy certain files for my webapp.
If you are using Tomcat and deploying using the workspace metadata (the default), you can check what the actual deployed WAR files look like by looking at your filesystem under:
WORKSPACE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/APPNAME/.../path/to/hibernate.cfg.xml
If you find the config file is NOT being updated, I would recommend undeploying you app in Eclipse, deleting the entire APPNAME directory in the above path, and redeploying clean.
If none of that works, do a project-wide search for "localhost" and see if there could possible be any hardcoded connections strings anywhere.
This kind of problem is usually due to the wrong configuration file being present. Maybe you have two copies of the file and you changed one but the system is using the other
Typically when building/compiling, resources get copied to a target/build folder. Check source folders and build target folders etc.
Search the file system for all files with the name hibernate.cfg.xml or with the contents localhost:1521:orcl
Check the classpath, or try explicitly putting the folder with the configuration file you want first in the classpath.
It can also be a case of some other configuration overriding your configuration, for instance a datasource filer or a persistence.xml-file. Check those if you have them as well.
How are you running your application? Through a test case, standalone console application, servlet/j2ee container?
It is unable to understand the "orcl" SID. May be the SID is present on your "localhost" but not on the server "10.73.98.230". verify you are using the correct SID available on "10.73.98.230".
Try changing this line in your config file.
<property name="hibernate.connection.url">jdbc:oracle:thin:#10.73.98.230:1521:orcl</property>
replace // with #
you can follow the link the have infomation http://www.cryer.co.uk/brian/oracle/ORA12505.htm
Hope this will help