Quartz trigger doesn't fire when using JobStoreTX - quartz-scheduler

I am configuring Quartz for my application under IBM Liberty Profile. When I used the default RAMJobStore. The trigger was fired and the scheduled job ran. Here are the codes:
JobDetail job = JobBuilder.newJob(QuartzBatchJobs.class).build();
Trigger trigger = TriggerBuilder.newTrigger().startNow().build();
try {
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
} catch (Exception e) {
System.out.println(e.toString());
}
However, when I switched to jdbcjobstore JobStoreTX and ran the application, all the quartz tables were updated but the trigger itself wasn't fired and the job didn't run. Here is my quartz.properties:
org.quartz.threadPool.threadCount = 10
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.dataSource=quartzRepo
org.quartz.dataSource.quartzRepo.jndiURL=jdbc/quartzRepo
Here is the server.xml of Liberty Profile for data source.
<dataSource id="quartzRepo" jndiName="jdbc/quartzRepo" type="javax.sql.XADataSource" isolationLevel="TRANSACTION_READ_COMMITTED">
<jdbcDriver libraryRef="DB2Jcc4Lib" />
<properties.db2.jcc currentSchema="qrtz" databaseName="localdb2" password="${jdbc.quartzRepo.password}" portNumber="50000" serverName="localhost" user="${jdbc.quartzRepo.user}" driverType="4" />
</dataSource>
Could you guys please give me some suggestions on this issue? Thanks!

Related

ejb 2 FinderException table or view does not exist

I'm working with an existing database and EJB 2.x application.
My task is to migrate the app from WebSphere 8 over to JBOSS EAP 6.4
After many days of fighting with this thing, everything seemed to be working until we started trying to use some of the beans. There are beans that end with "Mgr". For example, there is a SiteMgr bean and a Site bean. Right now, all of the Mgr beans work, but not the rest.
If you couldn't tell already, I'm not an EJB 2 Guru. Here is code that errors out:
/**
* getSessionContext
*/
public SiteVO getSite(int siteId) {
SiteLocal siteLocal;
try {
siteLocal = getSiteHome().findByPrimaryKey(new SiteKey(siteId));
} catch (FinderException e) {
throw new EJBException(e);
}
return siteLocal.getSiteVO();
}
So, when I try to findByPrimaryKey I get javax.ejb.FinderException, with the following cause:
java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
Drilling into that a bit more, here is the cause:
Error : 942, Position : 27, Sql = SELECT t0_Site.siteId FROM SITE t0_Site WHERE t0_Site.siteId=:1 , OriginalSql = SELECT t0_Site.siteId FROM SITE t0_Site WHERE t0_Site.siteId=?, Error Msg = ORA-00942: table or view does not exist
The database contains a table named APP_SITES and the WebSphere app probably figures that out using some files that appear to be specific to WebSphere.
There is appdb70.dbm and Map.mapxmi
These files are very long. I will provide some example text that is specific to the above example.
ejb-jar.xml
<entity id="Site">
<ejb-name>Site</ejb-name>
<local-home>com.app.site.entity.SiteLocalHome</local-home>
<local>com.app.site.entity.SiteLocal</local>
<ejb-class>com.app.site.entity.SiteBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.app.site.entity.SiteKey</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Site</abstract-schema-name>
<cmp-field id="CMPAttribute_1087249279390">
<field-name>siteId</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1087249281781">
<field-name>siteName</field-name>
</cmp-field>
...
Map.mapxmi
<ejbrdbmapping:EjbRdbDocumentRoot xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:OracleModel="http:///com/ibm/db/models/oracle/oracle.ecore"
xmlns:SQLConstraints="http:///org/eclipse/datatools/modelbase/sql/constraints.ecore"
xmlns:SQLTables="http:///org/eclipse/datatools/modelbase/sql/tables.ecore" xmlns:ejb="ejb.xmi"
xmlns:ejbrdbmapping="ejbrdbmapping.xmi" xmlns:Mapping="Mapping.xmi" xmi:id="EjbRdbDocumentRoot_1289312938455" topToBottom="true" commandStack="">
<helper xmi:type="ejbrdbmapping:RdbSchemaProperies" xmi:id="RdbSchemaProperies_1289312938455" primitivesDocument="ORACLE_V11"/>
<nested xmi:type="ejbrdbmapping:RDBEjbMapper" xmi:id="RDBEjbMapper_1289313262395">
<helper xmi:type="ejbrdbmapping:PrimaryTableStrategy" xmi:id="PrimaryTableStrategy_1289313262395">
<table xmi:type="OracleModel:OracleTable" href="META-INF/backends/ORACLE_V11_3/acapdb70.dbm#_q0x58OwNEd-LtOpsZa3J5w"/>
</helper>
<nested xmi:type="ejbrdbmapping:RDBEjbFieldMapper" xmi:id="RDBEjbFieldMapper_1289315290408">
<inputs xmi:type="ejb:CMPAttribute" href="META-INF/ejb-jar.xml#CMPAttribute_1087249279390"/>
<outputs xmi:type="SQLTables:Column" href="META-INF/backends/ORACLE_V11_3/acapdb70.dbm#_q0x58ewNEd-LtOpsZa3J5w"/>
<typeMapping xmi:type="ejbrdbmapping:RDBEjbFieldMapper" href="JavatoORACLE_V11TypeMaps.V7.xmi#int-NUMBER"/>
</nested>
<nested xmi:type="ejbrdbmapping:RDBEjbFieldMapper" xmi:id="RDBEjbFieldMapper_1289315290409">
<inputs xmi:type="ejb:CMPAttribute" href="META-INF/ejb-jar.xml#CMPAttribute_1087249285656"/>
<outputs xmi:type="SQLTables:Column" href="META-INF/backends/ORACLE_V11_3/acapdb70.dbm#_q0x5-ewNEd-LtOpsZa3J5w"/>
<typeMapping xmi:type="ejbrdbmapping:RDBEjbFieldMapper" href="JavatoORACLE_V11TypeMaps.V7.xmi#String-VARCHAR"/>
</nested>
appdb70.dbm (contains WAY too much data to post...)
<?xml version="1.0" encoding="UTF-8"?>
<!--xtools2_universal_type_manager-->
<xmi:XMI xmlns:datamodelversion="http://www.ibm.com/com.ibm.datatools.core/model/7.5.1.1" xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:OracleModel="http:///com/ibm/db/models/oracle/oracle.ecore" xmlns:SQLConstraints="http:///org/eclipse/datatools/modelbase/sql/constraints.ecore" xmlns:SQLDataTypes="http:///org/eclipse/datatools/modelbase/sql/datatypes.ecore" xmlns:SQLExpressions="http:///org/eclipse/datatools/modelbase/sql/expressions.ecore" xmlns:SQLSchema="http:///org/eclipse/datatools/modelbase/sql/schema.ecore" xmlns:SQLStatements="http:///org/eclipse/datatools/modelbase/sql/statements.ecore" xmlns:SQLTables="http:///org/eclipse/datatools/modelbase/sql/tables.ecore">
<OracleModel:OracleDatabase xmi:id="_WPDywewNEd-LtOpsZa3J5w" name="APPdb70" vendor="Oracle" version="11" schemas="_WQG7oOwNEd-LtOpsZa3J5w"/>
<SQLSchema:Schema xmi:id="_WQG7oOwNEd-LtOpsZa3J5w" name="APPWDB" triggers="_q0VNoOwNEd-LtOpsZa3J5w ..." database="_WPDywewNEd-LtOpsZa3J5w"/>
<SQLTables:Trigger xmi:id="_q0VNoOwNEd-LtOpsZa3J5w" name="APP_APPOINTMENT_D_TRG" schema="_WQG7oOwNEd-LtOpsZa3J5w" subjectTable="_q0VNpuwNEd-LtOpsZa3J5w" ...>
<dependencies xmi:id="_q0VNoewNEd-LtOpsZa3J5w" targetEnd="_q07ry-wNEd-LtOpsZa3J5w"/>
<dependencies xmi:id="_q0VNouwNEd-LtOpsZa3J5w" targetEnd="_q0e_b-wNEd-LtOpsZa3J5w"/>
<dependencies xmi:id="_q0VNo-wNEd-LtOpsZa3J5w" targetEnd="_q0VNpuwNEd-LtOpsZa3J5w"/>
<dependencies xmi:id="_q0VNpOwNEd-LtOpsZa3J5w" targetEnd="_q0VN_OwNEd-LtOpsZa3J5w"/>
<actionStatement xsi:type="SQLStatements:SQLStatementDefault" ..."/>
</SQLTables:Trigger>
<OracleModel:OracleTable xmi:id="_q0VNpuwNEd-LtOpsZa3J5w" name="APP_APPOINTMENT" schema="_WQG7oOwNEd-LtOpsZa3J5w" triggers="_q0VNoOwNEd-LtOpsZa3J5w ...>
<columns xmi:id="_q0VNp-wNEd-LtOpsZa3J5w" name="APPT_ID" nullable="false">
<containedType xsi:type="SQLDataTypes:FixedPrecisionDataType" xmi:id="_q0VNqOwNEd-LtOpsZa3J5w" name="NUMBER" primitiveType="NUMERIC"/>
</columns>
<columns xmi:id="_q0VNqewNEd-LtOpsZa3J5w" name="RMKS_TX">
<containedType xsi:type="SQLDataTypes:CharacterStringDataType" xmi:id="_q0VNquwNEd-LtOpsZa3J5w" name="VARCHAR2" primitiveType="CHARACTER_VARYING" length="200"/>
</columns>
Notice that you can find "CMPAttribute_1087249279390" in multiple files. JBOSS does not seem to make use of these extra files.
I'm not sure what to do at this point. I figured out everything else, but I can't seem to get around this. Any fix that gets the beans to work would be appreciated!

how to unwrap PostgreSQL connection from the IBM WSJdbc41Connection

I have been trying to unwrap PostgreSQL connection from the IBM JNDI (WebSphere liberty ) and have had no luck please any help with that :
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup("jdbc/indi");
Connection cnx = dataSource.getConnection();
I get this exception :
java.lang.ClassCastException:
com.ibm.ws.rsadapter.jdbc.v41.WSJdbc41Connection cannot be cast to
org.postgresql.PGConnection
I tried :
if(cnx.isWrapperFor(PGConnectionPoolDataSource.class)) {
//unwrap
}
if (cnx.isWrapperFor(org.postgresql.ds.jdbc4.AbstractJdbc4SimpleDataSource.class)) {
//unwrap
}
if (cnx.isWrapperFor(org.postgresql.core.v3.ConnectionFactoryImpl.class)) {
//unwrap
}
if (cnx.isWrapperFor(org.postgresql.jdbc2.AbstractJdbc2Connection.class)) {
//unwrap
}
if (cnx.isWrapperFor(org.postgresql.jdbc3.AbstractJdbc3Connection.class)) {
//unwrap
}
Thanks
If you would like to unwrap a JDBC object (DataSource, Connection, etc) to a vendor-specific interface, the JDBC driver in the configured <datSource> must be available to the application classloader. The configuration will look something like this:
<application location="oraclejdbcfat.war" >
<!-- expose the 'DBLib' containing the JDBC driver jar to the app classloader -->
<classloader commonLibraryRef="DBLib"/>
</application>
<library id="DBLib">
<fileset dir="${server.config.dir}/postgresql/" includes="*.jar"/>
</library>
<dataSource jndiName="jdbc/myDS">
<jdbcDriver libraryRef="DBLib"/>
<properties .../>
</dataSource>
From there, you can unwrap the object in the same way you were doing before, namely:
DataSource ds = InitialContext.doLookup("jdbc/myDS");
Connection conn = ds.getConnection();
PGConnection pgConn = conn.unwrap(org.postgresql.PGConnection.class);
Also, there is an enableConnectionCasting boolean attribute on <dataSource> configuration which will automatically call unwrap for you upon getConnection().
<dataSource jndiName="jdbc/myDS" enableConnectionCasting="true">
Then the java code is a bit simpler:
DataSource ds = InitialContext.lookup("jdbc/indi");
PGConnection pgConn = (PGConnection) ds.getConnection();

Cannot find datasource in Java Adapter in IBM MobileFirst

I have created a DataSource in MobileFirst server.xml:
<dataSource jndiName="jdbc/QAIWDB2">
<jdbcDriver libraryRef="DB2Lib"/>
<properties databaseName="QAIWPRD" password="pass" portNumber="99999" serverName="xyz.com" user="user"/>
</dataSource>
When I am trying to access it from a Java Adpater I am getting an error while deploying the adapter
Adapter deployment failed: An object could not be obtained for name
jdbc/QAIWDB2.
The code in Java Adapter is
static DataSource ds = null;
static Context ctx = null;
public static void init() throws NamingException {
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("jdbc/QAIWDB2");
}
Try the DB2 JNDI definition proposal mentioned in this answer: https://stackoverflow.com/a/17851124/1530814.
Of course, change the values to yours...
<dataSource jndiName="jdbc/db2" type="javax.sql.DataSource">
<jdbcDriver>
<library>
<fileset dir="/usr/lib/java/ibm-db2-universal-driver" includes="db2jcc4.jar, db2jcc_license_cisuz.jar, db2jcc_license_cu.jar"/>
</library>
</jdbcDriver>
<properties databaseName="DB2T" portNumber="21020" serverName="db2t.lvm.de password=" ... " user=" ... "/>
</dataSource>

Quartz.NET scheduling

I am new to this Quartz.NET thing and I have some questions about it cause it don't seem to work as I want to.
Question 1: I am defining simple IJobDetail and ITrigger. [SOLVED]
NameValueCollection config = ConfigurationManager.GetSection("quartz") as NameValueCollection;
ISchedulerFactory schedFact = new StdSchedulerFactory(config);
IScheduler scheduler = schedFact.GetScheduler();
try
{
scheduler.Start();
IJobDetail job = JobBuilder.Create<HelloJobTestScheduling>()
.WithIdentity("job1", "group1")
.Build();
DateTimeOffset endDate = DateTime.Now.AddMinutes(5);
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.WithRepeatCount(2))
.EndAt(endDate)
.Build();
scheduler.ScheduleJob(job, trigger);
}
catch(SchedulerException se)
{
Console.WriteLine(se);
}
finally
{
scheduler.Shutdown();
}
HelloJobTestScheduling
public void Execute(IJobExecutionContext context)
{
JobKey key = context.JobDetail.Key;
JobDataMap dataMap = context.JobDetail.JobDataMap;
string connectionString = #"Data Source=localhost\dejan;Initial Catalog=QuartzTest;Integrated Security=True";
string query = "INSERT INTO test (id, datetime) " +
"VALUES (#id, #datetime) ";
// create connection and command
using (SqlConnection cn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(query, cn))
{
// define parameters and their values
cmd.Parameters.Add("#id", SqlDbType.Int).Value = "1";
cmd.Parameters.Add("#datetime", SqlDbType.DateTime).Value = DateTime.Now;
// open connection, execute INSERT, close connection
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
}
App.config
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<quartz>
<add key="quartz.scheduler.instanceName" value="MyScheduler" />
<add key="quartz.scheduler.instanceId" value="AUTO" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
<add key="quartz.threadPool.threadCount" value="30"/>
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.dataSource" value="default" />
<add key="quartz.dataSource.default.connectionString" value="Data Source=localhost\dejan;Initial Catalog=QuartzTest;Integrated Security=True" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.clustered" value="false" />
<!--<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />-->
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" />
<add key="quartz.dataSource.default.provider" value="SqlServer-20" />
<add key="quartz.jobStore.useProperties" value="false" />
</quartz>
What this job actually does in reality is this: inserting only one row in the database, and after that it won't do anything. It waits to the .endAt and shows in console that the scheduler is closed. What is wrong with my code?
Note: I have all the required database tables for the scheduler to work in the background.
Question 2: Why this CRON is not recognized?
.WithCronSchedule("0 1 0 ? * ?")
Visual Studio error says:
'?' can only be specified for Day-of-Month -OR- Day-of-Week.
Cron expressions in Quartz.Net are made up of 7 sub-expressions:
Seconds
Minutes
Hours
Day-of-Month
Month
Day-of-Week
Year (optional field)
The last one is optional.
Your cron expression is not valid.
If you want to run to execute something every minute the right one is: 0 0/1 * 1/1 * ? *
I would advice you to use this tool to generate your cron expressions.
It's easier.
Question 1 is solved. Just a short note, my mistake was that I close the scheduler too early in finally. If I comment that lane, everything works good.
But, I still need help about Question 2.

How to connect JBoss 7.1.1 remoting -jmx via java code?

I have a JBoss 7.1.1 server, for which I want to write jmx client. As far I understood, jboss 7.1.1 is not using typical rmi based jmx and they have given a layer of remoting-jmx over native management. I am using following code:
JMXServiceURL address = new JMXServiceURL("service:jmx:remoting-jmx://localhost:9999");
Map env = JMXConnectorConfig.getEnvironment(paramtbl);
JMXConnector connector = JMXConnectorFactory.connect(address, env);
But it is giving following exception:
java.net.MalformedURLException: Unsupported protocol: remoting-jmx
I googled it and the following thread seems relevant:
https://community.jboss.org/thread/204653?tstart=0
It asks to add jboss's libraries to my classpath. I tried that also but still getting same exception.
I got the same exception when trying to get a JmxServiceUrl.
Make sure that in your standalone.xml you have the following:
<subsystem xmlns="urn:jboss:domain:jmx:1.1">
<show-model value="true"/>
<remoting-connector use-management-endpoint="true" />
</subsystem>
And you should include in project classpath the jar named: jboss-client.jar, it can be found in JBOSS_DIRECTORY/bin/client. In fact, the JMX client must include that jar in its classpath.
This tip fixed the problem for me..Hope it will be helpful for you
Tried to do the same from Arquillian test on JBoss AS7 and finally had to use:
import org.jboss.remotingjmx.RemotingConnectorProvider;
RemotingConnectorProvider s = new RemotingConnectorProvider();
JMXConnector connector = s.newJMXConnector(url, credentials);
connector.connect();
Could not have "module name="org.jboss.remoting-jmx" services="import"" working
Also works with
environment.put("jmx.remote.protocol.provider.pkgs", "org.jboss.remotingjmx");
JMXConnector connector = JMXConnectorFactory.connect(url, environment);
connector.connect();
I used this code to connect to JBoss in a remote server
ModelControllerClient client = null;
try {
client = createClient(InetAddress.getByName("172.16.73.12"), 9999,
"admin", "pass", "ManagementRealm");
}
catch (UnknownHostException e) {
e.printStackTrace();
}
Where createClient is a method I wrote -
private ModelControllerClient createClient(final InetAddress host,
final int port, final String username, final String password,
final String securityRealmName) {
final CallbackHandler callbackHandler = new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback current : callbacks) {
if (current instanceof NameCallback) {
NameCallback ncb = (NameCallback) current;
ncb.setName(username);
} else if (current instanceof PasswordCallback) {
PasswordCallback pcb = (PasswordCallback) current;
pcb.setPassword(password.toCharArray());
} else if (current instanceof RealmCallback) {
RealmCallback rcb = (RealmCallback) current;
rcb.setText(rcb.getDefaultText());
} else {
throw new UnsupportedCallbackException(current);
}
}
}
};
return ModelControllerClient.Factory
.create(host, port, callbackHandler);
}
For more information on how to read the data obtained from Server or for the complete project using Java/Google visualizer API (to show the statistics in Graph after every 10 secs) , Please refer to this tutorial -
http://javacodingtutorial.blogspot.com/2014/05/reading-jboss-memory-usage-using-java.html
Add the following to your jboss-deployment-structure
<dependencies>
<module name="org.jboss.remoting3.remoting-jmx" services="import"/>
</dependencies>
Activate JMX remoting subsystem by adding following entry in standalone.xml
<subsystem xmlns="urn:jboss:domain:ee:1.1">
<!-- Activate JMX remoting -->
<global-modules>
<module name="org.jboss.remoting-jmx" slot="main"/>
</global-modules>
...
</subsystem>
It seems like "jboss-client.jar" is not available at run-time for JMX connection, So make sure that you have added "jboss-client.jar" in the class path.
And also you are using deprecated protocol "remoting-jmx" instead of "remote".
i.e, "service:jmx:remote://localhost:9999"
Hope it helps.