Author: chatellier Date: 2009-12-11 16:35:48 +0000 (Fri, 11 Dec 2009) New Revision: 2823 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/SimulationService.java Log: Add zip saving for each simulation. Now simulations can restart even after isis shutdown. 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-12-11 16:30:19 UTC (rev 2822) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-12-11 16:35:48 UTC (rev 2823) @@ -20,6 +20,8 @@ import static org.nuiton.i18n.I18n._; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -33,21 +35,19 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.SortedSet; import java.util.Timer; import java.util.TreeSet; import java.util.AbstractMap.SimpleEntry; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.util.FileUtil; -import fr.ifremer.isisfish.IsisFishException; -import fr.ifremer.isisfish.datastore.AnalysePlanStorage; +import fr.ifremer.isisfish.IsisFish; 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; @@ -55,16 +55,22 @@ import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException; /** - * Moniteur singleton pour pouvoir sauvegarder - * localement la liste des simulations démarrées et - * permettre de continuer le monitoring au relancemenent - * d'Isis. + * Moniteur singleton pour pouvoir sauvegarder localement la liste des + * simulations démarrées et permettre de continuer le monitoring au + * relancemenent d'Isis. + * + * Depuis la version 3.3, elle sauvegarde en plus les zip pour pouvoir + * relancer une simulation même si isis a été arreté entre temps. * * Cette classe n'implemente pas {@link SimulationServiceListener} * car elle ne doit pas écouter toutes les simulations, mais * seulement celle dit simple, c'est-à-dire "master plan" du plan * d'analyse. * + * Il faut bien faire attention lors du relancement des simulations a copier + * le zip a un autre endroit. Il est important d'avoir deux zip car celui + * de la sauvegarde est supprimé des que la simulation est arrete. + * * @since 3.2.0.4 * @author chatellier * @version $Revision$ @@ -74,34 +80,23 @@ */ public class SimulationMonitor extends Thread { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Class logger. */ private static Log log = LogFactory.getLog(SimulationMonitor.class); + protected static final String PROPERTIES_FILE = "monitoring.properties"; + protected static final String PROPERTY_LAUNCHER = "simulation.launcher"; + protected static final String PROPERTY_DATE = "simulation.date"; + protected static final String PROPERTY_ZIP = "simulation.zip"; + /** Instance. */ protected static SimulationMonitor instance = new SimulationMonitor(); /** * Simulation information saving file. - * - * Saved in $HOME/.isis-simulations-3 */ - protected File monitorFile; - - /** - * Separator used in monitor file. - * - * Can't be "," - */ - protected static final String MONITORFILESEPARATOR = "/"; + protected File monitorFolder; /** - * Liste des simulations en cours, - * Le format est défini ainsi : - * id=launcher/datedelancement/onlyexport/exports/plandependant/plans - */ - protected Properties properties = new Properties(); - - /** * Map to remember when a simulation have to be checked. * * Sorted on date ASC. @@ -117,27 +112,26 @@ * Constructeur. */ protected SimulationMonitor() { - // FIXME configure this path - String monitorSaveFile = System.getProperty("user.home") - + File.separator + ".isis-simulations-3"; - monitorFile = new File(monitorSaveFile); + monitorFolder = IsisFish.config.getMonitoringDirectory(); + // init monitor check map - checkSet = new TreeSet<SimpleEntry<Date, SimulationJob>>(new Comparator<SimpleEntry<Date, SimulationJob>>(){ - @Override - public int compare(SimpleEntry<Date, SimulationJob> o1, - SimpleEntry<Date, SimulationJob> o2) { - // TODO change this, it's a set with duplicated entries !!! - int result = o1.getKey().compareTo(o2.getKey()); - // with bad luck (or windows system) date can be equals :( - if (result == 0) { - result = o1.getValue().compareTo(o2.getValue()); + checkSet = new TreeSet<SimpleEntry<Date, SimulationJob>>( + new Comparator<SimpleEntry<Date, SimulationJob>>() { + @Override + public int compare(SimpleEntry<Date, SimulationJob> o1, + SimpleEntry<Date, SimulationJob> o2) { + // TODO change this, it's a set with duplicated entries !!! + int result = o1.getKey().compareTo(o2.getKey()); + // with bad luck (or windows system) date can be equals :( + if (result == 0) { + result = o1.getValue().compareTo(o2.getValue()); + } + return result; } - return result; - } - - }); + }); + // init timer checkScheduler = new Timer(); } @@ -152,183 +146,184 @@ } /** - * Reload config and read non simulation job - * into simulation service. + * Reload config and read non simulation job into simulation service. * * @param service SimulationService */ public void reloadConfig(final SimulationService service) { + // in a thread + // don't temporize UI loading + new Thread() { + public void run() { + restartSimulationProgression(service); + } + }.start(); + } - if (monitorFile.canRead()) { - InputStream is = null; - try { - is = new FileInputStream(monitorFile); - properties.load(is); + /** + * Take all simulation in loaded file. + * And add it into simulation service. + */ + protected void restartSimulationProgression(SimulationService service) { - // in a thread - // don't temporize UI loading - new Thread() { - public void run() { - restartSimulationProgression(service); - } - }.start(); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't reload monitor file", e); + File[] files = monitorFolder.listFiles(); + for (File file : files) { + // folder is composed of one folder for each simulation + if (file.isDirectory()) { + + String simulationId = file.getName(); + if (log.isInfoEnabled()) { + log.info("Restart monitoring of " + simulationId); } - } - finally { - if (is != null) { + + // FIXME date remove simulation that are older than a week ? + + File propertiesFile = new File(file, PROPERTIES_FILE); + + if (propertiesFile.isFile()) { + + InputStream propertiesFileIS = null; try { - is.close(); + propertiesFileIS = new BufferedInputStream(new FileInputStream(propertiesFile)); + Properties simulationProperties = new Properties(); + simulationProperties.load(propertiesFileIS); + + restartSimulation(service, file, simulationId, simulationProperties); } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("Can't close monitor file", e); + log.error("Can't get launcher for this simulation", + e); } + } finally { + IOUtils.closeQuietly(propertiesFileIS); } + } else { + if (log.isWarnEnabled()) { + log.warn("No " + PROPERTIES_FILE + " found in " + + file.getAbsolutePath() + + "(skipping restarting)"); + } } } } - } /** - * Take all simulation in loaded file. - * And add it into simulation service. + * Restart a single simulation. + * + * @param service simulation service + * @param simulationFolder simulation information folder + * @param simulationId simulation id + * @param propertiesFile simulation properties file + * + * @throws IOException */ - protected void restartSimulationProgression(SimulationService service) { + protected void restartSimulation(SimulationService service, + File simulationFolder, String simulationId, + Properties propertiesFile) throws IOException { - for (Map.Entry<Object, Object> entry : properties.entrySet()) { - String simulationId = (String) entry.getKey(); - String simulationInfo = (String) entry.getValue(); + try { + // launcher + String simulationLauncher = propertiesFile + .getProperty(PROPERTY_LAUNCHER); + SimulatorLauncher launcher = (SimulatorLauncher) Class.forName( + simulationLauncher).newInstance(); - // 0 = launcher - // 1 = date - // 2 = export - // 3 = plan dependent - // 4 = use analyse plan - // 5 = plans list - String[] simulationInfos = simulationInfo.split(MONITORFILESEPARATOR); - String simulationLauncher = simulationInfos[0]; - String simulationDate = simulationInfos[1]; - //String simulationOnlyExport = simulationInfos[2]; - //String simulationExports = simulationInfos[3]; - //String simulationUseAnalysePlan = simulationInfos[4]; - //String simulationPlans = ""; - //if(simulationInfos.length >= 6) { - // simulationPlans = simulationInfos[5]; - //} + // zip (copy to temp in mandatory) + String zipFileName = propertiesFile.getProperty(PROPERTY_ZIP); + File zipFile = new File(simulationFolder, zipFileName); + // + File tempZipFile = File.createTempFile( + "simulation-" + simulationId, ".zip"); + FileUtils.copyFile(zipFile, tempZipFile); + tempZipFile.deleteOnExit(); - if (log.isInfoEnabled()) { - log.info("Restart monitoring of " + simulationId); - if (log.isDebugEnabled()) { - log.debug(" launcher= " + simulationLauncher + ", date = " - + simulationDate); - } + // On construit le job. + // il faut qu'il soit suffisament valide pour pourvoir démarrer + // il contient : + // - un launcher + // - un zip (pour relancement) + // Et il est relance avec un parametre "checkonly" + SimulationParameter params = new SimulationParameter(); + SimulationControl control = new SimulationControl(simulationId); + SimulationItem item = new SimulationItem(control, params); + item.setSimulationZip(tempZipFile); // tempZipFile, important ! + SimulationJob job = new SimulationJob(service, item, 0); + job.setLauncher(launcher); + + service.submitForCheckOnly(job); + } catch (ClassNotFoundException e) { + if (log.isErrorEnabled()) { + log.error("Can't found launcher for this simulation", e); } + } catch (InstantiationException e) { + if (log.isErrorEnabled()) { + log.error("Can't get launcher for this simulation", e); + } + } catch (IllegalAccessException e) { + if (log.isErrorEnabled()) { + log.error("Can't get launcher for this simulation", e); + } + } + } - // FIXME date remove simulation that are older than a week ? + /** + * Save simulation informations for started simulations. + * + * @param job started job + */ + public synchronized void simulationStart(SimulationJob job) { - // re add simulation in - try { - // launcher - SimulatorLauncher launcher = (SimulatorLauncher) Class.forName( - simulationLauncher).newInstance(); + String simulationId = job.getId(); + File simulationMonitoringFolder = new File(monitorFolder, simulationId); + File simulationPropertiesFile = new File(simulationMonitoringFolder, PROPERTIES_FILE); - SimulationParameter params = new SimulationParameter(); - // 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); - } - }*/ + if (!simulationPropertiesFile.exists()) { + Properties simulationProperties = new Properties(); - service.submitForCheckOnly(simulationId, params, launcher, 0); - } catch (ClassNotFoundException e) { + // launcher + SimulatorLauncher launcher = job.getLauncher(); + String launcherName = launcher.getClass().getName(); + simulationProperties.setProperty(PROPERTY_LAUNCHER, launcherName); + + // date + simulationProperties.setProperty(PROPERTY_DATE, launcherName); + + // zip + File zipFile = job.getItem().getSimulationZip(); + try { + // original zip must be keeped outside monitoring folder + FileUtils.copyFileToDirectory(zipFile, simulationMonitoringFolder); + simulationProperties.setProperty(PROPERTY_ZIP, zipFile.getName()); + } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("Can't found launcher for this simulation", e); + log.error("Can't copy simulation zip", e); } - } catch (InstantiationException e) { + } + + // save property file + OutputStream out = null; + try { + out = new BufferedOutputStream(new FileOutputStream(simulationPropertiesFile)); + simulationProperties.store(out, "Simulation added : " + simulationId); + } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("Can't get launcher for this simulation", e); + log.error("Can't save monitor file", e); } - } catch (IllegalAccessException e) { - if (log.isErrorEnabled()) { - log.error("Can't get launcher for this simulation", e); - } + } finally { + IOUtils.closeQuietly(out); } - } - } - public synchronized void simulationStart(SimulationJob job) { - - String monitorKey = job.getId(); - SimulatorLauncher launcher = job.getLauncher(); - //SimulationParameter params = job.getItem().getParameter(); - - // 0 = launcher - String monitorValue = launcher.getClass().getName(); - // 1 = date - 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); - OutputStream out = null; - try { - out = new FileOutputStream(monitorFile); - properties.store(new FileOutputStream(monitorFile), - "Simulation added at " + new Date()); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't save monitor file", e); + if (log.isInfoEnabled()) { + log.info("Saving simulation " + simulationId + " as started"); } - } - finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't close monitor file", e); - } - } + } else { + if (log.isDebugEnabled()) { + log.debug("We already know information about this simulation"); + log.debug("Skip simulation information saving"); } } - if (log.isInfoEnabled()) { - log.info("Saving simulation " + monitorKey + " as started"); - } - // put interval in launcher ? Date checkDate = new Date(); // do check at start @@ -351,37 +346,20 @@ * @param job job that control the simulation */ public synchronized void simulationStop(SimulationJob job) { - String monitorKey = job.getId(); - properties.remove(monitorKey); - OutputStream out = null; + String simulationId = job.getId(); + File simulationMonitoringFolder = new File(monitorFolder, simulationId); + try { - if (properties.isEmpty()) { - monitorFile.delete(); - } else { - out = new FileOutputStream(monitorFile); - properties.store(out, "Simulation delete at " + new Date()); - - } + FileUtils.deleteDirectory(simulationMonitoringFolder); } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("Can't save monitor file", e); + log.error("Can't remove simulation informations", e); } } - finally { - try { - if (out != null) { - out.close(); - } - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't close monitor file", e); - } - } - } if (log.isInfoEnabled()) { - log.info("Saving simulation " + monitorKey + " as stopped"); + log.info("Saving simulation " + simulationId + " as stopped"); } } @@ -398,8 +376,7 @@ // quoi qu'il arrive, le thread ne doit jamais s'arreter try { waitAndCheckProgression(); - } - catch (Exception e) { + } catch (Exception e) { if (log.isErrorEnabled()) { log.error("An exception occurs durring monitoring", e); } @@ -413,7 +390,7 @@ * is reached. */ protected void waitAndCheckProgression() { - + try { Thread.sleep(1000); } catch (InterruptedException e) { @@ -468,14 +445,15 @@ long nextJobTimeMs = date.getTime() + launcher.getCheckProgressionInterval() * 1000; Date nextJobDate = new Date(nextJobTimeMs); - checkSet.add(new SimpleEntry<Date, SimulationJob>(nextJobDate, job)); + checkSet.add(new SimpleEntry<Date, SimulationJob>( + nextJobDate, job)); } } else { //checkScheduler.schedule(this, date); if (log.isDebugEnabled()) { - log.debug("Time to check not reached, skip check, " - + date + " < " + now); + log.debug("Time to check not reached, skip check, " + date + + " < " + now); } } } @@ -510,13 +488,14 @@ // WARNING this condition is VERY important // and set by end of // fr.ifremer.isisfish.simulator.launcher.InProcessSimulatorLauncher#localSimulateSameThread(SimulationControl, SimulationStorage) - + // FIXME check SimulationStorage.exists(control.getId()) condition if ((control.getProgress() > 0 - && control.getProgress() >= control.getProgressMax() && SimulationStorage.exists(control.getId()))) { + && control.getProgress() >= control.getProgressMax() && SimulationStorage + .exists(control.getId()))) { simulationEnded = true; } - + if (control.isStopSimulationRequest()) { launcher.simulationStopRequest(job); // to release one resource simulationEnded = true; @@ -545,28 +524,28 @@ SimulatorLauncher launcher) { boolean result = false; - + SimulationService service = SimulationService.getService(); SimulationControl control = job.getItem().getControl(); - + if (log.isInfoEnabled()) { log.info("Do post simulation operation for " + control.getId()); } try { - + // get storage // meme si StopSimulationRequest // force le download dans le cas de ssh SimulationStorage simulation = launcher.getSimulationStorage( service, control); - + // on ne fait de post traitement que si // la simulation n'a pas été arretée if (!control.isStopSimulationRequest()) { // post manage this storage boolean simulationAvailble = true; //exportResult(job, simulation); - + // do posts actions for (PostAction action : job.getPostActions()) { try { @@ -577,7 +556,7 @@ } } } - + // sensitivity calculator analyze result call // can't do analyze second pass if simulation // has been deleted @@ -591,103 +570,20 @@ // don't do in finally, getSimulationStorage may fail (md5 on ssh) simulationStop(job); service.fireStopEvent(job); - + result = true; - + } catch (RemoteException e) { if (log.isErrorEnabled()) { log.error("Can't get simulation results after simulation end", e); } } - + return result; } /** - * Export result, and delete simulation if "onlyExport" has - * been selected. - * - * @return <tt>true</tt> if simulation is still available (not delete by onlyExport) - * - * @deprecated there is no export anymore - */ - protected boolean exportResult(SimulationJob job, SimulationStorage simulation) { - - boolean simulationAvailble = true; - - /*SimulationParameter param = job.getItem().getParameter(); - SimulationControl control = job.getItem().getControl(); - String id = control.getId(); - - try { - // copie les exports de simulation dans le repertoire - // souhaiter par l'utilisateur - if (param.getExportNames() != null - && param.getExportNames().size() > 0) { - - // log - if (log.isDebugEnabled()) { - log.debug("Export results"); - } - - File exportDir = SimulationStorage - .getResultExportDirectory(simulation.getDirectory()); - // FIXME verifier que pour les plans on a bien tous les - // export, c-a-d que les export son fait dans un sous rep - // portant le nom de la simu - FileUtil.copyAndRenameRecursively(exportDir, new File(param - .getExportDirectory()), exportDir.getName(), id); - } else { - // log - if (log.isDebugEnabled()) { - log.debug("Not Export results : unneeded"); - } - } - } catch (Exception eee) { - if (log.isErrorEnabled()) { - log.error(_("Can't export simulation %s", id), eee); - } - } - - try { - // Si l'utilisateur souhaite seulement les exports - // on supprimer la/les simulations. - if (param.getOnlyExport()) { - // pour les plan dependant il faut le faire apres toutes - // les simulations donc pas ici - if (job.getParentJob() == null || param.getUseAnalysePlan() - && param.isIndependentPlan()) { - - // log - if (log.isDebugEnabled()) { - log.debug("Export \"onlyExport\" : deleting simulation"); - } - - simulation.delete(false); - simulationAvailble = false; - } else { - // log - if (log.isDebugEnabled()) { - 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()) { - log.error(_("Can't delete simulation %s ", id), eee); - } - }*/ - - return simulationAvailble; - } - - /** * For each finished simulation, check that all sensitivity * simulation are available (in case of sensitivity simulation only). * @@ -696,37 +592,45 @@ */ protected void analyzeSensitivityResult(SimulationJob job, SimulationStorage simulation) { - + SimulationParameter params = simulation.getParameter(); - + int numberOfSimulation = params.getNumberOfSensitivitySimulation(); - + if (numberOfSimulation > 0) { // this is a sensitivity simulation String simulationId = job.getId(); - String simulationCommonPrefix = simulationId.substring(0, simulationId.lastIndexOf("_")); - int numberFinished = getNumberOfFinishedSimulation(simulationCommonPrefix, numberOfSimulation); + String simulationCommonPrefix = simulationId.substring(0, + simulationId.lastIndexOf("_")); + int numberFinished = getNumberOfFinishedSimulation( + simulationCommonPrefix, numberOfSimulation); // si on a toutes les simulation est qu'elles sont finie // on construit la liste des simulation storage // et on l'envoie au script d'analyse de sensibilite if (numberFinished == numberOfSimulation) { - SensitivityCalculator sensitivityCalculator = params.getSensitivityCalculator(); + SensitivityCalculator sensitivityCalculator = params + .getSensitivityCalculator(); if (sensitivityCalculator != null) { if (log.isDebugEnabled()) { - log.debug("Call analyzeResult on sensitivity script " + sensitivityCalculator.getClass().getSimpleName()); + log.debug("Call analyzeResult on sensitivity script " + + sensitivityCalculator.getClass() + .getSimpleName()); } try { // get full storage list - List<SimulationStorage> simulationStorageForAnalyze = - getStorageListForSecondPass(simulationCommonPrefix, numberOfSimulation); + List<SimulationStorage> simulationStorageForAnalyze = getStorageListForSecondPass( + simulationCommonPrefix, numberOfSimulation); // build master sensitivity export directory - File masterExportDirectory = new File(SimulationStorage.getSimulationDirectory(), simulationCommonPrefix); + File masterExportDirectory = new File(SimulationStorage + .getSimulationDirectory(), + simulationCommonPrefix); // directory must already exists !!! - sensitivityCalculator.analyzeResult(simulationStorageForAnalyze, masterExportDirectory); - } - catch(SensitivityException e) { + sensitivityCalculator.analyzeResult( + simulationStorageForAnalyze, + masterExportDirectory); + } catch (SensitivityException e) { if (log.isErrorEnabled()) { log.error("Can't call analyse result", e); } @@ -735,7 +639,7 @@ } } } - + /** * Parcourt le dossier de toutes les simulation commencant par le prefix donné, * et retourne le nombre de simulation terminées. @@ -745,39 +649,40 @@ * * @return le nombre de simulation réellement terminée */ - protected int getNumberOfFinishedSimulation(String asPrefixName, int numberOfSimulation) { + protected int getNumberOfFinishedSimulation(String asPrefixName, + int numberOfSimulation) { int numberOfFinishedSimulation = 0; - + // en sens inverse, il le fera carrement moins souvent - for (int simulationIndex = numberOfSimulation - 1; simulationIndex >= 0 ; --simulationIndex) { + for (int simulationIndex = numberOfSimulation - 1; simulationIndex >= 0; --simulationIndex) { String currentId = asPrefixName + "_" + simulationIndex; if (SimulationStorage.localyExists(currentId)) { - SimulationControl currentSimulationControl = new SimulationControl(currentId); - SimulationStorage.readControl(currentId, currentSimulationControl); - + SimulationControl currentSimulationControl = new SimulationControl( + currentId); + SimulationStorage.readControl(currentId, + currentSimulationControl); + // condition for simulation "end" if (currentSimulationControl.getProgress() > 0 && currentSimulationControl.getProgress() >= currentSimulationControl.getProgressMax()) { // new finished simulation found numberOfFinishedSimulation++; - } - else { + } else { if (log.isDebugEnabled()) { log.debug("Miss simulation number = " + simulationIndex); } - + // no need to continue // if only miss one, break break; } - } - else { + } else { break; } } - + return numberOfFinishedSimulation; } @@ -791,7 +696,7 @@ * @return la liste des storages */ protected List<SimulationStorage> getStorageListForSecondPass(String asPrefixName, int numberOfSimulation) { - + // simulation start at 0 List<SimulationStorage> simulationStorageForAnalyze = new LinkedList<SimulationStorage>(); // en sens inverse, il le fera carrement moins souvent @@ -802,10 +707,10 @@ // result list is keeped sorted simulationStorageForAnalyze.add(storage); } - + return simulationStorageForAnalyze; } - + /** * Convertit une collection de string, en une chaine * séparée par des ",". @@ -815,15 +720,15 @@ */ protected static String collectionToString(Collection<String> collection) { String str = ""; - + Iterator<String> it = collection.iterator(); - while(it.hasNext()) { + while (it.hasNext()) { str += it.next(); - if(it.hasNext()) { + if (it.hasNext()) { str += ","; } } - + return str; } -} +} // SimulationMonitor Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2009-12-11 16:30:19 UTC (rev 2822) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2009-12-11 16:35:48 UTC (rev 2823) @@ -555,39 +555,6 @@ return scriptContent; } - /** - * Resoumet une simulation qui a deja été démarrée, mais - * on ne faisant que du control de monitoring. - * - * @param id - * @param param - * @param launcher - * @param priority - */ - public void submitForCheckOnly(String id, SimulationParameter param, - SimulatorLauncher launcher, int priority) { - // on l'ajoute tout de suite a la liste des simulations demandee - SimulationControl control = new SimulationControl(id); - SimulationItem item = new SimulationItem(control, param); - SimulationJob job = new SimulationJob(this, item, priority); - job.setLauncher(launcher); - fireStartEvent(job); - - job.setOnlyCheckControl(true); - - //if (param.getUseAnalysePlan() && param.isIndependentPlan()) { - // // c un plan d'analyse independant, on construit toute les sous simu - // Runnable task = new PrepareSimulationJob(this, job); - // subSimulationComputationExecutor.execute(task); - //} else { - // l'item est fini d'etre initialise, on peut l'ajouter a la queue - // sauf si c'etait un plan independant ou se seront les sous simu - // qui seront dans la queue - submit(job); - //} - - } - protected void submit(SimulationJob job) { SimulatorLauncher launcher = job.getLauncher(); // on ajoute a la queue qui utilise le launcher defini dans le job @@ -628,6 +595,18 @@ } /** + * Resoumet une simulation qui a deja été démarrée, mais + * on ne faisant que du control de monitoring. + * + * @param job job to submit + */ + public void submitForCheckOnly(SimulationJob job) { + job.setOnlyCheckControl(true); + fireStartEvent(job); + submit(job); + } + + /** * Restart a job. * * This method fire "start" event. @@ -637,6 +616,8 @@ public void restart(SimulationJob job) { // lorsqu'un job est resoumit, il redevient forcement standalone job.getItem().setStandaloneSimulation(true); + // case were we restart a reloaded job + job.setOnlyCheckControl(false); job.getItem().getControl().reset(); fireStartEvent(job);
participants (1)
-
chatellier@users.labs.libre-entreprise.org