Author: chatellier Date: 2009-12-15 14:07:34 +0000 (Tue, 15 Dec 2009) New Revision: 2840 Modified: isis-fish/trunk/changelog.txt isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java Log: Improve suppression deletion algorithm (deletion > check) Reduce monitoring delay. Simulation can be deleted from caparmor even after isis restart. Modified: isis-fish/trunk/changelog.txt =================================================================== --- isis-fish/trunk/changelog.txt 2009-12-15 13:19:01 UTC (rev 2839) +++ isis-fish/trunk/changelog.txt 2009-12-15 14:07:34 UTC (rev 2840) @@ -1,5 +1,6 @@ isis-fish (3.3.0.0) stable; urgency=low + * Improve simulation stopping algorithm (now faster) * Locally save simulation zip to allow simulation restart even afer isis shutdown * In sensitivity analysis, upload only one zip to caparmor for all simulations * Add option to control number of SSH thread to use 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-15 13:19:01 UTC (rev 2839) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-12-15 14:07:34 UTC (rev 2840) @@ -29,10 +29,10 @@ import java.io.InputStream; import java.io.OutputStream; import java.rmi.RemoteException; -import java.util.Collection; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Comparator; import java.util.Date; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -83,10 +83,15 @@ /** Class logger. */ private static Log log = LogFactory.getLog(SimulationMonitor.class); + /** Simulation start date format. */ + private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + 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"; + protected static final String PROPERTY_STANDALONE = "simulation.standalone"; + protected static final String PROPERTY_LASTSIMULATION = "simulation.last"; /** Instance. */ protected static SimulationMonitor instance = new SimulationMonitor(); @@ -224,17 +229,13 @@ try { // launcher - String simulationLauncher = propertiesFile - .getProperty(PROPERTY_LAUNCHER); - SimulatorLauncher launcher = (SimulatorLauncher) Class.forName( - simulationLauncher).newInstance(); + String simulationLauncher = propertiesFile.getProperty(PROPERTY_LAUNCHER); + SimulatorLauncher launcher = (SimulatorLauncher) Class.forName(simulationLauncher).newInstance(); // 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"); + File tempZipFile = File.createTempFile("simulation-" + simulationId, ".zip"); FileUtils.copyFile(zipFile, tempZipFile); tempZipFile.deleteOnExit(); @@ -246,11 +247,18 @@ // 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 ! + + // set additionnal parameters (null safe, defaut parameter safe) + String standalone = propertiesFile.getProperty(PROPERTY_STANDALONE); + item.setStandaloneSimulation(!"false".equalsIgnoreCase(standalone)); + String lastSimulation = propertiesFile.getProperty(PROPERTY_LASTSIMULATION); + item.setLastSimulation("true".equalsIgnoreCase(lastSimulation)); + SimulationJob job = new SimulationJob(service, item, 0); job.setLauncher(launcher); - service.submitForCheckOnly(job); } catch (ClassNotFoundException e) { if (log.isErrorEnabled()) { @@ -275,6 +283,7 @@ public synchronized void simulationStart(SimulationJob job) { String simulationId = job.getId(); + SimulationItem simulationItem = job.getItem(); File simulationMonitoringFolder = new File(monitorFolder, simulationId); File simulationPropertiesFile = new File(simulationMonitoringFolder, PROPERTIES_FILE); @@ -287,10 +296,11 @@ simulationProperties.setProperty(PROPERTY_LAUNCHER, launcherName); // date - simulationProperties.setProperty(PROPERTY_DATE, launcherName); + String simulationDate = dateFormat.format(new Date()); + simulationProperties.setProperty(PROPERTY_DATE, simulationDate); // zip - File zipFile = job.getItem().getSimulationZip(); + File zipFile = simulationItem.getSimulationZip(); try { // original zip must be keeped outside monitoring folder FileUtils.copyFileToDirectory(zipFile, simulationMonitoringFolder); @@ -301,6 +311,10 @@ } } + // addtionnal infos + simulationProperties.setProperty(PROPERTY_STANDALONE, String.valueOf(simulationItem.isStandaloneSimulation())); + simulationProperties.setProperty(PROPERTY_LASTSIMULATION, String.valueOf(simulationItem.isLastSimulation())); + // save property file OutputStream out = null; try { @@ -385,25 +399,22 @@ } /** - * Wait one second, and check for first + * Wait a little time, and check for first * simulation progression, if first simulation time * is reached. */ protected void waitAndCheckProgression() { + // wait a minimum time + // 1s is to long to stop 1000 simulations try { - Thread.sleep(1000); + Thread.sleep(10); } catch (InterruptedException e) { if (log.isErrorEnabled()) { log.error("Monitor thread has been interrupted", e); } } - // log - if (log.isDebugEnabled()) { - log.debug("Simulation monitor wake up"); - } - // take first job in map if (!checkSet.isEmpty()) { SimpleEntry<Date, SimulationJob> firstEntry = checkSet.first(); @@ -482,24 +493,25 @@ // update try { - 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) - - // FIXME check SimulationStorage.exists(control.getId()) condition - if ((control.getProgress() > 0 - && control.getProgress() >= control.getProgressMax() && SimulationStorage - .exists(control.getId()))) { - simulationEnded = true; - } - if (control.isStopSimulationRequest()) { - launcher.simulationStopRequest(job); // to release one resource + launcher.simulationStopRequest(job); simulationEnded = true; } + else { + 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) + + // FIXME check SimulationStorage.exists(control.getId()) condition + if ((control.getProgress() > 0 + && control.getProgress() >= control.getProgressMax() && SimulationStorage + .exists(control.getId()))) { + simulationEnded = true; + } + } } catch (RemoteException e) { if (log.isErrorEnabled()) { log.error("Progression thread update error", e); @@ -710,25 +722,4 @@ return simulationStorageForAnalyze; } - - /** - * 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; - } } // SimulationMonitor