/**
* Verarbeitung
*/
public boolean spooler_process() {
Order order = null;
HashMap orderAttributes = new HashMap();
boolean rc = false;
try {
this.setLogger(new SOSSchedulerLogger(spooler_log));
if (!this.getOrderIterator().hasNext()) {
this.getLogger().info("no more orders found in queue");
return false;
}
orderAttributes = (HashMap) this.getOrderIterator().next();
if (orderAttributes.isEmpty()) {
this.getLogger().warn("no order attributes found in queue");
return false;
}
if (orderAttributes.get("job_chain")==null || orderAttributes.get("job_chain").toString().length()==0)
orderAttributes.put("job_chain", jobChainName);
// Job Chain ist evtl. nicht vorhanden
if ( !this.spooler.job_chain_exists(orderAttributes.get("job_chain").toString())) {
this.getLogger().warn("no job chain found for this order: " + orderAttributes.get("job_chain").toString());
}
boolean deleted=false;
if(orderAttributes.get("deleted")!= null){
String sDeleted = orderAttributes.get("deleted").toString();
deleted = !(sDeleted.trim().equals("0"));
}
boolean suspended=false;
if(orderAttributes.get("suspended")!= null){
String sSuspended = orderAttributes.get("suspended").toString();
suspended = !(sSuspended.trim().equals("0"));
}
if (deleted){
getLogger().debug6("deleted=1, deleting order...");
getConnection().execute("DELETE FROM "+JobSchedulerManagedObject.getTableManagedUserJobs()+
" WHERE \"ID\"="+orderAttributes.get("id").toString());
getConnection().commit();
String answer = spooler.execute_xml("<remove_order job_chain=\""+orderAttributes.get("job_chain").toString()+
"\" order=\""+orderAttributes.get("id").toString()+"\" />");
}else {
if (suspended){
getLogger().debug6("suspended=1, deactivating order...");
String answer = spooler.execute_xml("<remove_order job_chain=\""+orderAttributes.get("job_chain").toString()+
"\" order=\""+orderAttributes.get("id").toString()+"\" />");
getConnection().executeUpdate("UPDATE " + JobSchedulerManagedObject.getTableManagedUserJobs() +
" SET \"UPDATED\"=0 WHERE \"ID\"="+orderAttributes.get("id").toString());
getConnection().commit();
return orderIterator.hasNext();
}
// do not add orders if job chain exceeds setting for order queue length
if ( this.getMaxOrderCount() > 0 ) {
if ( spooler.job_chain(orderAttributes.get("job_chain").toString()).order_count() >= this.getMaxOrderCount() ) {
this.getLogger().info(".. current order [" + orderAttributes.get("id").toString() +
"] skipped: order queue length [" +
spooler.job_chain(orderAttributes.get("job_chain").toString()).order_count() +
"] exceeds maximum size [" + this.getMaxOrderCount() + "]");
return this.orderIterator.hasNext();
}
}
String command =orderAttributes.get("action").toString();
String runTime = orderAttributes.get("run_time").toString();
String hexCommand = JobSchedulerManagedObject.toHexString(command.getBytes("US-ASCII"));
order = spooler.create_order();
order.set_id(orderAttributes.get("id").toString()); // Auftragsnummer
order.set_state("0"); // Reihenfolge in der Jobkette
order.set_priority(Integer.parseInt(orderAttributes.get("priority").toString()));
if (orderAttributes.get("title") != null)
order.set_title(orderAttributes.get("title").toString()); // Auftragstitel
sos.spooler.Variable_set orderData = spooler.create_variable_set();
orderData.set_var("command", hexCommand);
orderData.set_var("scheduler_order_schema", orderAttributes.get("schema").toString());
orderData.set_var("scheduler_order_user_name", orderAttributes.get("user_name").toString());
orderData.set_var("scheduler_order_is_user_job","1");
if(orderAttributes.get("params")!=null){
String paramsXml = orderAttributes.get("params").toString();
if (paramsXml.length()>0){
Variable_set paramsSet = spooler.create_variable_set();
paramsSet.set_xml(paramsXml);
orderData.merge(paramsSet);
}
}
order.set_payload(orderData);
if (runTime!=null && runTime.length()>0){
if (isOver(runTime)){
try{
getLogger().debug3("Order "+order.id()+" was not executed at specified runtime. Calculating new runtime.");
} catch (Exception e){}
JobSchedulerManagedDatabaseJob.updateRunTime(order, getLogger(), getConnection());
runTime = getConnection().getSingleValue("SELECT \"RUN_TIME\" FROM "+
JobSchedulerManagedObject.getTableManagedUserJobs()+ " WHERE \"ID\"=" +
order.id());
if (runTime==null || runTime.length()==0){
return orderIterator.hasNext();
}
}
getLogger().debug3("Setting order run_time:"+runTime);
order.run_time().set_xml(runTime);
}
rc = !(spooler_task.job().order_queue() == null);
/*if (rc == false) {
this.getLogger().warn("no order in queue");
return rc;
}*/
try { // to add the order
//String answer = spooler.execute_xml("<remove_order job_chain=\""+orderAttributes.get("job_chain").toString()+
// "\" order=\""+order.id()+"\" />");
//if(answer.toLowerCase().indexOf("error")>0) throw new Exception(answer);
//spooler.job_chain(orderAttributes.get("job_chain").toString()).add_order(order);
spooler.job_chain(orderAttributes.get("job_chain").toString()).add_or_replace_order(order);
}
catch (Exception e) {
// ignore this error, scheduler cares for repeated orders
this.getLogger().debug6("an ignorable error occurred while removing and adding order: " +
e.getMessage());
this.getLogger().debug6("will try to add order on next run.");
return orderIterator.hasNext();
}
getConnection().executeUpdate("UPDATE " + JobSchedulerManagedObject.getTableManagedUserJobs() +
" SET \"UPDATED\"=0 WHERE \"ID\"="+orderAttributes.get("id").toString());
getConnection().commit();
this.getLogger().info( "order [" + orderAttributes.get("id").toString() +
"] added to job chain [" + orderAttributes.get("job_chain").toString() + "]: " +
order.title() );
}
return orderIterator.hasNext();
}
catch (Exception e) {
spooler_log.warn("error occurred processing managed user job" + ((order != null) ? " [" + order.id() + "]" : "") + ": " + e.getMessage());
spooler_task.end();
return false;
}
finally {
try { if (this.getConnection() != null) this.getConnection().rollback(); } catch (Exception ex) {} // ignore this errror