Author: chatellier Date: 2009-02-18 13:10:43 +0000 (Wed, 18 Feb 2009) New Revision: 1830 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java Log: Manage: - onlyexport - plan dependant in saved simulation list Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-02-18 11:33:03 UTC (rev 1829) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-02-18 13:10:43 UTC (rev 1830) @@ -25,7 +25,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.rmi.RemoteException; +import java.util.Collection; import java.util.Date; +import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.SortedMap; @@ -36,7 +38,11 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.util.FileUtil; +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.AnalysePlanStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.AnalysePlan; import fr.ifremer.isisfish.simulator.SimulationControl; import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.launcher.SimulationJob.PostAction; @@ -72,11 +78,18 @@ * Saved in $HOME/.isis-simulations-3 */ protected File monitorFile; + + /** + * Separator used in monitor file. + * + * Can't be "," + */ + protected static final String MONITORFILESEPARATOR = "/"; /** * Liste des simulations en cours, * Le format est défini ainsi : - * id=launcher,datedelancement,export,plandependant + * id=launcher/datedelancement/onlyexport/exports/plandependant/plans */ protected Properties properties = new Properties(); @@ -153,11 +166,13 @@ // 1 = date // 2 = export // 3 = plan dependent - String[] simulationInfos = simulationInfo.split(","); + String[] simulationInfos = simulationInfo.split(MONITORFILESEPARATOR); String simulationLauncher = simulationInfos[0]; String simulationDate = simulationInfos[1]; - String simulationExport = simulationInfos[2]; - String simulationPlan = simulationInfos[3]; + String simulationOnlyExport = simulationInfos[2]; + String simulationExports = simulationInfos[3]; + String simulationUseAnalysePlan = simulationInfos[4]; + String simulationPlans = simulationInfos[5]; if (log.isInfoEnabled()) { log.info("Restart monitoring of " + simulationId); @@ -171,14 +186,40 @@ // re add simulation in try { + // launcher SimulatorLauncher launcher = (SimulatorLauncher) Class.forName( simulationLauncher).newInstance(); SimulationParameter params = new SimulationParameter(); - params.setUseAnalysePlan("true" - .equalsIgnoreCase(simulationPlan)); - params.setOnlyExport("true".equalsIgnoreCase(simulationExport)); - + // UseAnalysePlan + params.setUseAnalysePlan("true".equalsIgnoreCase(simulationUseAnalysePlan)); + // plans + String[] planList = simulationPlans.split(","); + for (String name : planList) { + if (name != null && !name.isEmpty()) { + try { + AnalysePlan plan = AnalysePlanStorage.getAnalysePlan(name).getNewAnalysePlanInstance(); + params.getAnalysePlans().add(plan); + } catch (IsisFishException eee) { + if (log.isWarnEnabled()) { + log.warn("Can't find plan: " + name, eee); + } + } + } + } + // OnlyExport + params.setOnlyExport("true".equalsIgnoreCase(simulationOnlyExport)); + // exports + String[] exportList = simulationExports.split(","); + for (String name : exportList) { + if (name != null && !name.isEmpty()) { + params.getExportNames().add(name); + } + } + + // FIXME needed + params.setExportDirectory(IsisFish.config.getDefaultExportDirectory().toString()); + service.submitForCheckOnly(simulationId, params, launcher, 0); } catch (ClassNotFoundException e) { if (log.isErrorEnabled()) { @@ -200,15 +241,24 @@ String monitorKey = job.getId(); SimulatorLauncher launcher = job.getLauncher(); - + SimulationParameter params = job.getItem().getParameter(); + // 0 = launcher - String monitorValue = job.getLauncher().getClass().getName(); + String monitorValue = launcher.getClass().getName(); // 1 = date - monitorValue += "," + System.currentTimeMillis(); - // 2 = export - monitorValue += "," + job.getItem().getParameter().getOnlyExport(); - // 3 = plan dependent - monitorValue += "," + job.getItem().getParameter().getUseAnalysePlan(); + monitorValue += MONITORFILESEPARATOR + System.currentTimeMillis(); + // 2 = onlyexport + monitorValue += MONITORFILESEPARATOR + params.getOnlyExport(); + // 3 = exports + monitorValue += MONITORFILESEPARATOR + collectionToString(params.getExportNames()); + // 4 = plan dependent + monitorValue += MONITORFILESEPARATOR + params.getUseAnalysePlan(); + // 5 = plan dependent + String planList = ""; + for (AnalysePlan plan : params.getAnalysePlans()) { + planList += AnalysePlanStorage.getName(plan) + ","; + } + monitorValue += MONITORFILESEPARATOR + planList; properties.put(monitorKey, monitorValue); try { @@ -306,7 +356,7 @@ // always remove this simulation from map checkMap.remove(date); - // if not finished, re-add it at + // if not finished, re-add it at end if (jobIsFinished) { doPostSimulationOperation(job, launcher); } else { @@ -317,11 +367,6 @@ checkMap.put(nextJobDate, job); } - // finally, schedule, next check - /*if (!checkMap.isEmpty()) { - Date nextDate = checkMap.firstKey(); - checkScheduler.schedule(this, nextDate); - }*/ } else { //checkScheduler.schedule(this, date); if (log.isDebugEnabled()) { @@ -349,8 +394,8 @@ SimulationControl control = job.getItem().getControl(); // log - if (log.isInfoEnabled()) { - log.info("Checking simulation progression : " + control.getId()); + if (log.isDebugEnabled()) { + log.debug("Checking simulation progression : " + control.getId()); log.debug(" with launcher = " + launcher); } @@ -359,8 +404,11 @@ launcher.updateControl(service, control); // by default, Progress = ProgressMax = 0 + // WARNING this condition is VERY important + // and set by end of + // fr.ifremer.isisfish.simulator.launcher.InProcessSimulatorLauncher#localSimulateSameThread(SimulationControl, SimulationStorage) if (control.getProgress() > 0 - && control.getProgress() >= control.getProgressMax() - 1) { + && control.getProgress() >= control.getProgressMax()) { simulationEnded = true; } } catch (RemoteException e) { @@ -458,24 +506,26 @@ if (param.getOnlyExport()) { // pour les plan dependant il faut le faire apres toutes // les simulations donc pas ici - // FIXME fix parent job test - if (/*getParentJob() == null || */param.getUseAnalysePlan() + if (job.getParentJob() == null || param.getUseAnalysePlan() && param.isIndependentPlan()) { // log if (log.isDebugEnabled()) { - log - .debug("Export \"onlyExport\" : deleting simulation"); + log.debug("Export \"onlyExport\" : deleting simulation"); } simulation.delete(false); } else { // log if (log.isDebugEnabled()) { - log - .debug("Not onlyExport options : not delete simulation"); + log.debug("OnlyExport options true, but plan dependant : not delete simulation"); } } + } else { + // log + if (log.isDebugEnabled()) { + log.debug("OnlyExport options not set : not delete simulation"); + } } } catch (Exception eee) { if (log.isErrorEnabled()) { @@ -493,4 +543,25 @@ } } } + + /** + * Convertit une collection de string, en une chaine + * séparée par des ",". + * + * @param collection collection to convert + * @return string + */ + protected static String collectionToString(Collection<String> collection) { + String str = ""; + + Iterator<String> it = collection.iterator(); + while(it.hasNext()) { + str += it.next(); + if(it.hasNext()) { + str += ","; + } + } + + return str; + } }
participants (1)
-
chatellier@users.labs.libre-entreprise.org