r3096 - isis-fish/branches/3.3.0.4-disworksupport/src/main/java/fr/ifremer/isisfish/simulator/launcher
Author: bleny Date: 2010-07-28 11:54:10 +0000 (Wed, 28 Jul 2010) New Revision: 3096 Log: corrections launcher diswork Modified: isis-fish/branches/3.3.0.4-disworksupport/src/main/java/fr/ifremer/isisfish/simulator/launcher/DisworkSimulatorLauncher.java Modified: isis-fish/branches/3.3.0.4-disworksupport/src/main/java/fr/ifremer/isisfish/simulator/launcher/DisworkSimulatorLauncher.java =================================================================== --- isis-fish/branches/3.3.0.4-disworksupport/src/main/java/fr/ifremer/isisfish/simulator/launcher/DisworkSimulatorLauncher.java 2010-07-23 12:52:09 UTC (rev 3095) +++ isis-fish/branches/3.3.0.4-disworksupport/src/main/java/fr/ifremer/isisfish/simulator/launcher/DisworkSimulatorLauncher.java 2010-07-28 11:54:10 UTC (rev 3096) @@ -25,6 +25,7 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.ZipUtil; +import fr.ifremer.isisfish.IsisConfig; import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.simulator.SimulationControl; @@ -39,10 +40,12 @@ LogFactory.getLog(DisworkSimulatorLauncher.class); protected static final String ISIS_APPLICATION_NAME = "isis-fish"; - protected static final String ISIS_APPLICATION_VERSION = IsisFish.config.getVersion(); - + protected static final String ISIS_APPLICATION_VERSION = IsisConfig.getVersion(); + protected static DisworkDaemon disworkDaemon; + /** true if an error occurs of is {@link #close()} is called + * if true, no operation are permitted */ protected static boolean closed = false; /** for each job id, the corresponding job description */ @@ -52,23 +55,28 @@ public DisworkSimulatorLauncher() {} protected synchronized static DisworkDaemon getDaemon() throws RemoteException { + // lazy creation of the daemon. Thus, daemon will not be run when // isis is used on caparmor or as diswork application - if (disworkDaemon == null) { + initDaemon(); } return disworkDaemon; } - + protected static void initDaemon() throws RemoteException { + // create a DisworkConfig according to the isis config DisworkConfig config = new DisworkConfig(); config.setBootstrapIp(IsisFish.config.getDisworkBootstrapIp()); config.setBootstrapPort(IsisFish.config.getDisworkBootstrapPort()); config.setUsedPort(IsisFish.config.getDisworkPort()); + // to be removed : config.setActivityStrategy("unlimited"); - config.setHttpFrontendPort(8081); + config.setHttpFrontendPort(9090); + + // starting the daemon try { disworkDaemon = new DisworkDaemon(config); } catch (DisworkException e) { @@ -90,12 +98,12 @@ // now, checks if isis-fish in the current version is available on - // diswork for other nodes. If not, application is downloader and + // diswork for other nodes. If not, application is downloaded and // submitted // no exception thrown below, even if it fails we can hope that // application is already available. If it's not the case, a - // exception will be raised at job submission + // exception will be raised at job submission URL isisDownloadUrl = null; InputStream applicationData = null; try { @@ -134,6 +142,7 @@ @Override public void simulate(SimulationService simulationService, SimulationItem simulationItem) throws RemoteException { + // check if daemon is available if (closed) { simulationItem.getControl().setText("unable to connect to diswork"); @@ -143,7 +152,7 @@ try { Thread.sleep(1 * 1000); } catch (InterruptedException e) { - throw new RemoteException("lancher interrupted", e); + throw new RemoteException("launcher interrupted", e); } throw new RemoteException("daemon has been closed"); } @@ -230,27 +239,39 @@ return simulationStorage; } + /** when a given job is finished, copy all results to local FS + * data are written in a temp directory, Zip result file will be + * unzipped in the expected job directory to make them available in isis + * + * @return the directory where results for this job are stored + */ protected File downloadResults(JobDescription jobDescription) throws DisworkException { OutputStream out = null; try { + // create a temp directory to store results data File tempDir = FileUtil.createTempDirectory("isis-results-" + jobDescription.getJobName(), ""); + + // for all the result file for this job Map<String, InputStream> results = getDaemon().getResults(jobDescription); for (String fileName : results.keySet()) { + + // copy data from diswork to local FS File localFile = new File(tempDir, fileName); log.debug("downloading result in " + localFile.getAbsolutePath()); out = new FileOutputStream(localFile); - // copy data from diswork to local FS IOUtils.copy(results.get(fileName), out); + // if it's the result zip, unzip it if (fileName.endsWith(".zip")) { ZipUtil.uncompress(localFile, SimulationStorage.getSimulationDirectory()); localFile.deleteOnExit(); } } + + // delete job data (job description, input and output) from diswork getDaemon().deleteJob(jobDescription); - // FileUtil.deleteRecursively(tempDir); } catch (IOException e) { log.error("unable to write results on the local FS", e); throw new RuntimeException("unable to write results on the local FS", e); @@ -267,18 +288,21 @@ SimulationControl control) throws RemoteException { if (closed) { control.setText("unable to connect to diswork"); - + // sleep a bit before throwing exception prevent infinite loop try { Thread.sleep(1 * 1000); } catch (InterruptedException e) { - throw new RemoteException("lancher interrupted", e); + throw new RemoteException("launcher interrupted", e); } throw new RemoteException("daemon has been closed"); } + getDaemon(); + JobDescription jobDescription = jobs.get(control.getId()); if (jobDescription == null) { + // there is no such job, maybe its submission has not been terminated log.error("unknow Id" + control.getId()); } else { log.debug("updating control for " + jobDescription); @@ -322,7 +346,7 @@ try { JobDescription jobDescription = jobs.get(job.getId()); if (jobDescription == null) { - log.warn(job + " is not a know job"); + log.warn(job + " is not a known job"); } else { getDaemon().deleteJob(jobDescription); }
participants (1)
-
bleny@users.labs.libre-entreprise.org