Author: bleny Date: 2010-07-23 12:49:51 +0000 (Fri, 23 Jul 2010) New Revision: 3093 Log: bugfix, tous les jobs sont soumis avec la version courrante de isis, application soumise une seule fois au d?\195?\169marrage du d?\195?\169mon 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:07:37 UTC (rev 3092) +++ isis-fish/branches/3.3.0.4-disworksupport/src/main/java/fr/ifremer/isisfish/simulator/launcher/DisworkSimulatorLauncher.java 2010-07-23 12:49:51 UTC (rev 3093) @@ -39,6 +39,7 @@ 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 DisworkDaemon disworkDaemon; @@ -55,63 +56,78 @@ // isis is used on caparmor or as diswork application if (disworkDaemon == null) { - DisworkConfig config = new DisworkConfig(); - config.setBootstrapIp(IsisFish.config.getDisworkBootstrapIp()); - config.setBootstrapPort(IsisFish.config.getDisworkBootstrapPort()); - config.setUsedPort(IsisFish.config.getDisworkPort()); - - config.setActivityStrategy("unlimited"); - config.setHttpFrontendPort(8081); - try { - disworkDaemon = new DisworkDaemon(config); - } catch (DisworkException e) { - log.error("unable to boot diswork FS"); - closed = true; - throw new RemoteException("unable to boot diswork FS", e); - } - - // retrieving all jobs submitted to this daemon last time isis was run - try { - for (JobDescription job : getDaemon().getAllJobs(ISIS_APPLICATION_NAME)) { - jobs.put(job.getJobName(), job); - } - log.debug(jobs.size() + " jobs retrieved from diswork"); - } catch (DisworkException e) { - log.error("unable to boot diswork FS"); - throw new RuntimeException("unable to boot diswork FS", e); - } } return disworkDaemon; } - protected synchronized void submitIsisApplication(String isisVersion) { - // method is synchronized so two submission at the same time - // will not upload isis twice - log.info("submitting isis-fish " + isisVersion + " to diswork"); - String isisDownloadUrlOption = IsisFish.config.getDisworkIsisDownloadURL(); + protected static void initDaemon() throws RemoteException { + DisworkConfig config = new DisworkConfig(); + config.setBootstrapIp(IsisFish.config.getDisworkBootstrapIp()); + config.setBootstrapPort(IsisFish.config.getDisworkBootstrapPort()); + config.setUsedPort(IsisFish.config.getDisworkPort()); + + config.setActivityStrategy("unlimited"); + config.setHttpFrontendPort(8081); + try { + disworkDaemon = new DisworkDaemon(config); + } catch (DisworkException e) { + log.error("unable to boot diswork FS"); + closed = true; + throw new RemoteException("unable to boot diswork FS", e); + } + // retrieving all jobs submitted to this daemon last time isis was run + try { + for (JobDescription job : disworkDaemon.getAllJobs(ISIS_APPLICATION_NAME)) { + jobs.put(job.getJobName(), job); + } + log.debug(jobs.size() + " jobs retrieved from diswork"); + } catch (DisworkException e) { + log.error("unable to boot diswork FS"); + throw new RuntimeException("unable to boot diswork FS", e); + } + + + // now, checks if isis-fish in the current version is available on + // diswork for other nodes. If not, application is downloader 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 URL isisDownloadUrl = null; InputStream applicationData = null; try { - isisDownloadUrl = new URL(isisDownloadUrlOption); - log.debug("downloading isis from " + isisDownloadUrl); - applicationData = isisDownloadUrl.openStream(); - getDaemon().submitApplication(ISIS_APPLICATION_NAME, - isisVersion, - applicationData); - - // 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 - } catch (MalformedURLException e) { - log.error("isis can't be downloaded from " + isisDownloadUrlOption - + " malformed URL", e); - } catch (IOException e) { - log.error("unable to download data from " + isisDownloadUrl, e); - IOUtils.closeQuietly(applicationData); + // submitting isis-fish application + if (disworkDaemon.isApplicationAvailable(ISIS_APPLICATION_NAME, + ISIS_APPLICATION_VERSION)) { + log.info("isis-fish " + ISIS_APPLICATION_VERSION + + " is already available on diswork"); + } else { + log.info("submitting isis-fish " + ISIS_APPLICATION_VERSION + + " to diswork"); + String isisDownloadUrlOption = + IsisFish.config.getDisworkIsisDownloadURL(); + + try { + isisDownloadUrl = new URL(isisDownloadUrlOption); + log.debug("downloading isis from " + isisDownloadUrl); + applicationData = isisDownloadUrl.openStream(); + getDaemon().submitApplication(ISIS_APPLICATION_NAME, + ISIS_APPLICATION_VERSION, + applicationData); + } catch (MalformedURLException e) { + log.error("isis can't be downloaded from " + + isisDownloadUrlOption + " malformed URL", e); + } catch (IOException e) { + log.error("unable to download data from " + isisDownloadUrl, e); + IOUtils.closeQuietly(applicationData); + } + } } catch (DisworkException e) { - log.error("unable to submit application to daemon", e); + log.error("unable to check application availability or to submit " + + "application to daemon", e); } } @@ -137,12 +153,9 @@ String simulationId = simulationItem.getControl().getId(); jobDescription.setJobName(simulationId); - // upload isis application to diswork in current version and set it - // as the application for this job - String isisVersion = simulationItem.getParameter().getIsisFishVersion(); - simulationItem.getControl().setText("uploading isis " + isisVersion); - submitIsisApplication(isisVersion); - jobDescription.setApplication(ISIS_APPLICATION_NAME, isisVersion); + // set isis current version as the application for this job + jobDescription.setApplication(ISIS_APPLICATION_NAME, + ISIS_APPLICATION_VERSION); // setting input data InputStream simulationZipData; @@ -166,8 +179,8 @@ jobDescription.addOutput(standardOutputName); // generating the command-line for this job - String isisJarPath = "isis-fish-" + isisVersion + "%sep" + "isis-fish-" + - isisVersion + ".jar"; + String isisJarPath = "isis-fish-" + ISIS_APPLICATION_VERSION + "%sep" + + "isis-fish-" + ISIS_APPLICATION_VERSION + ".jar"; String commandLine = "%java -Xmx2500M -jar" + " " + isisJarPath + " --option launch.ui false" @@ -268,7 +281,7 @@ if (jobDescription == null) { log.error("unknow Id" + control.getId()); } else { - log.info("updating control for " + jobDescription); + log.debug("updating control for " + jobDescription); try { if (getDaemon().isFinished(jobDescription)) { // downloads the results @@ -277,7 +290,15 @@ // in this dir, look for the control file File controlFile = new File(resultDir, SimulationStorage.CONTROL_FILENAME); log.debug("control file is " + controlFile.getAbsolutePath()); - SimulationStorage.readControl(controlFile, control, "stop"); + if (controlFile.exists()) { + SimulationStorage.readControl(controlFile, control, "stop"); + } else { + // job failed, no result file downloaded so no control file + log.info(jobDescription + " is failed, see " + + resultDir.getAbsolutePath() + + "content to know why"); + control.setStopSimulationRequest(true); + } } } catch (DisworkException e) { log.error("error while retrieving status|results for job", e); @@ -293,7 +314,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"); } @@ -322,9 +343,9 @@ /** must be called when IsisFish is being closed */ public static void close() throws RemoteException { closed = true; - if (getDaemon() != null) { + if (disworkDaemon != null) { try { - getDaemon().close(); + disworkDaemon.close(); } catch (DisworkException e) { throw new RemoteException("unable to close daemon", e); }