try {
try {
this.setLogger(new SOSSchedulerLogger(spooler_log));
params = getParameters();
schedulerParams = getSchedulerParameterAsProperties(params);
checkParallel = sosString.parseToBoolean(sosString.parseToString(schedulerParams.get("check_parallel")));
parallelTransfer = sosString.parseToBoolean(sosString.parseToString(schedulerParams.get("parallel")));
}
catch (Exception e) {
rc = false;
e.printStackTrace(System.err);
throw (new Exception("could not process job parameters: " + e));
}
try { // to check parameters
if (checkParallel) {
boolean bSuccess = true;
String[] paramNames = sosString.parseToString(spooler.variables().names()).split(";");
for (int i = 0; i < paramNames.length; i++) {
if (paramNames[i].startsWith("ftp_check_receive_" + normalize(spooler_task.order().id()) + ".")) {
if (sosString.parseToString(spooler.var(paramNames[i])).equals("0")) {
// Anzahl der Wiederholung merken
String sRetry = sosString.parseToString(spooler.variables().var("cur_transfer_retry" + normalize(spooler_task.order().id())));
int retry = sRetry.length() == 0 ? 0 : Integer.parseInt(sRetry);
--retry;
spooler.variables().set_var("cur_transfer_retry" + normalize(spooler_task.order().id()), String.valueOf(retry));
if (retry == 0) {
getLogger().debug("terminated cause max order setback reached: " + paramNames[i]);
spooler.variables().set_var("terminated_cause_max_order_setback_" + normalize(spooler_task.order().id()), "1");
return false;
}
getLogger().debug("launch setback: " + parallelTransferCheckRetry + " * " + parallelTransferCheckSetback);
spooler_task.order().setback();
return false;
}
else
if (sosString.parseToString(spooler.var(paramNames[i])).equals("1")) {
getLogger().debug("successfully terminated: " + paramNames[i]);
}
else
if (sosString.parseToString(spooler.var(paramNames[i])).equals("2")) {
bSuccess = false;
getLogger().debug("terminated with error : " + paramNames[i]);
}
}
}
return bSuccess;
}
else
if (schedulerParams.get("parent_order_id") != null) {
// Hauptauftrag wurde wegen Erreichens von ftp_parallel_check_retry beendet -> die restlichen Unterauftr�ge sollen
// nicht durchlaufen
String state = spooler.variables().var(
"terminated_cause_max_order_setback_" + normalize(sosString.parseToString(schedulerParams.get("ftp_parent_order_id"))));
if (state.equals("1"))
return false;
}
if (sosString.parseToString(schedulerParams.get("file_path")).length() > 0) {
isFilePath = true;
}
else {
isFilePath = false;
}
}
catch (Exception e) {
rc = false;
e.printStackTrace(System.err);
throw (new Exception("invalid or insufficient parameters: " + e));
}
try { // to process ftp
Vector<String> filelist = null;
String remoteDir = sosString.parseToString(schedulerParams.get("remoteDir"));
// parallel Transfer
if (parallelTransfer && !isFilePath) {
// nur die filelist holen um Parallelen transfer zu erm�glichen
schedulerParams.put("skip_transfer", "yes");
createIncludeConfigurationFile("sos/net/sosftp/Configuration.xml", "sos.net.sosftp.Configuration.xml");// Alle
// Parametern
// sind hier
// auch g�ltig
SOSConfiguration con = new SOSConfiguration(null, schedulerParams, sosString.parseToString(schedulerParams.get("settings")),
sosString.parseToString(schedulerParams.get("profile")),
// "sos/net/sosftp/Configuration.xml",
"sos/scheduler/ftp/SOSFTPConfiguration.xml", new SOSSchedulerLogger(spooler_log));
con.checkConfigurationItems();
SOSFTPCommandReceive ftpCommand = new SOSFTPCommandReceive(con, new SOSSchedulerLogger(spooler_log));
ftpCommand.setSchedulerJob(this);
rc = ftpCommand.transfer();
filelist = ftpCommand.getFilelist();
Iterator<String> iterator = filelist.iterator();
if (spooler_job.order_queue() == null) {
// parallel Transfer for standalone Job
while (iterator.hasNext()) {
String fileName = sosString.parseToString(iterator.next());
String fileSpec = schedulerParams.containsKey(conVarname_file_spec) ? sosString.parseToString(schedulerParams.get(conVarname_file_spec))
: ".*";
Pattern pattern = Pattern.compile(fileSpec, 0);
Matcher matcher = pattern.matcher(fileName);
if (matcher.find()) {
Variable_set newParams = params;
newParams.set_var(conVarname_ftp_file_path, (remoteDir.endsWith("/") || remoteDir.endsWith("\\") ? remoteDir : remoteDir + "/")
+ fileName);
spooler_log.info("launching job for parallel transfer with parameter: ftp_file_path "
+ (remoteDir.endsWith("/") || remoteDir.endsWith("\\") ? remoteDir : remoteDir + "/") + fileName);
spooler.job(spooler_task.job().name()).start(params);
}
}
return false;
}
else {
// parallel Transfer for order job
while (iterator.hasNext()) {
String fileName = (String) iterator.next();
String fileSpec = schedulerParams.containsKey("file_spec") ? sosString.parseToString(schedulerParams.get("file_spec")) : ".*";
Pattern pattern = Pattern.compile(fileSpec, 0);
Matcher matcher = pattern.matcher(fileName);
if (matcher.find()) {
Variable_set newParams = spooler.create_variable_set();
if (spooler_task.params() != null)
newParams.merge(params);
newParams.set_var(conVarname_ftp_file_path, (remoteDir.endsWith("/") || remoteDir.endsWith("\\") ? remoteDir : remoteDir + "/")
+ fileName);
newParams.set_var("ftp_parent_order_id", spooler_task.order().id());
newParams.set_var("ftp_order_self_destruct", "1");
Order newOrder = spooler.create_order();
newOrder.set_state(spooler_task.order().state());
newOrder.set_params(newParams);
spooler_task.order().job_chain().add_order(newOrder);
getLogger().info(
"launching order for parallel transfer with parameter: ftp_file_path "
+ (remoteDir.endsWith("/") || remoteDir.endsWith("\\") ? remoteDir : remoteDir + "/") + fileName);
spooler.variables().set_var("ftp_order", normalize(spooler_task.order().id()) + "." + normalize(newOrder.id()) + "." + "0");
spooler.variables().set_var("ftp_check_receive_" + normalize(spooler_task.order().id()) + "." + normalize(newOrder.id()), "0");
}
}
// am aktuellen Auftrag speichern, dass im Wiederholungsfall per setback() nicht erneut Auftr�ge erzeugt werden
// sollen, sondern dass deren Erledigungszustand gepr�ft wird:
spooler_task.order().params().set_var(conVarname_ftp_check_parallel, "yes");
spooler_job.set_delay_order_after_setback(1, parallelTransferCheckSetback);
spooler_job.set_max_order_setbacks(parallelTransferCheckRetry);
spooler_task.order().setback();
spooler.variables().set_var("cur_transfer_retry" + normalize(spooler_task.order().id()), String.valueOf(parallelTransferCheckRetry));
return false;
}
}
// kb 2011-04-27 no more longer needed due to too much trouble with this file / concept
// createIncludeConfigurationFile("sos/net/sosftp/Configuration.xml", "sos.net.sosftp.Configuration.xml");// Alle Parametern
// sind hier auch
// g�ltig
SOSConfiguration con = new SOSConfiguration(null, schedulerParams, sosString.parseToString(schedulerParams.get("settings")),
sosString.parseToString(schedulerParams.get("profile")),
// "sos/net/sosftp/Configuration.xml",
"sos/scheduler/ftp/SOSFTPConfiguration.xml", new SOSSchedulerLogger(spooler_log));
con.checkConfigurationItems();
sos.net.sosftp.SOSFTPCommandReceive ftpCommand = new sos.net.sosftp.SOSFTPCommandReceive(con, new SOSSchedulerLogger(spooler_log));
ftpCommand.setSchedulerJob(this);
rc = ftpCommand.transfer();
createOrderParameter(ftpCommand);