Author: bleny Date: 2010-07-23 15:22:40 +0200 (Fri, 23 Jul 2010) New Revision: 109 Url: http://nuiton.org/repositories/revision/diswork/109 Log: ajout isApplicationAvailable ?\195?\160 l'API + test Modified: trunk/diswork-daemon/src/main/java/org/nuiton/diswork/daemon/DisworkDaemon.java trunk/diswork-daemon/src/test/java/org/nuiton/diswork/daemon/DisworkDaemonTest.java Modified: trunk/diswork-daemon/src/main/java/org/nuiton/diswork/daemon/DisworkDaemon.java =================================================================== --- trunk/diswork-daemon/src/main/java/org/nuiton/diswork/daemon/DisworkDaemon.java 2010-07-23 09:10:52 UTC (rev 108) +++ trunk/diswork-daemon/src/main/java/org/nuiton/diswork/daemon/DisworkDaemon.java 2010-07-23 13:22:40 UTC (rev 109) @@ -401,6 +401,28 @@ /* ** public methods for use of the daemon */ + /** true if a node already submitted this application on diswork */ + public boolean isApplicationAvailable(String applicationName, + String applicationVersion) + throws DisworkException { + if (applicationName == null) { + throw new NullPointerException("application name is null"); + } + if (applicationVersion == null) { + throw new NullPointerException("application version can't be null"); + } + + String path = getPathForDependency(applicationName, applicationVersion); + + Boolean result = null; + try { + result = fileSystem.exists(path); + } catch (DisworkFileSystemException e) { + throw new DisworkException("unable to access file-system", e); + } + return result; + } + /** * Provide an application to all nodes. Once provided, all nodes will be * able to perform a job with this application. @@ -524,7 +546,19 @@ throw new NullPointerException("job is null"); } - + // if an application is declared is used, check it is available + if (jobDescription.getApplicationName() != null) { + if ( ! isApplicationAvailable(jobDescription.getApplicationName(), + jobDescription.getApplicationVersion())) { + throw new DisworkException("job require a dependency " + + jobDescription.getApplicationName() + "-" + + jobDescription.getApplicationVersion() + + " that is not available"); + } + } else { + log.debug("no dependency specified for " + jobDescription); + } + // check all dependencies are provided for (String name : jobDescription.getInput()) { if (!jobDescription.getInputData().containsKey(name) && @@ -550,22 +584,6 @@ // create both job path and sub-directory .diswork fileSystem.createDirectories( getPathForJob(jobDescription) + "/" + ".diswork"); - - if (jobDescription.applicationName != null) { - String dependencyPath = getPathForDependency( - jobDescription.getApplicationName(), - jobDescription.getApplicationVersion()); - log.info("looking for " + dependencyPath); - - if (!fileSystem.exists(dependencyPath)) { - throw new DisworkException("job require a dependency " + - jobDescription.getApplicationName() + "-" + - jobDescription.getApplicationVersion() - + " that is not available"); - } - } else { - log.debug("no dependency specified for " + jobDescription); - } String jobDir = getPathForJob(jobDescription); @@ -807,7 +825,7 @@ String line; while ((line = in.readLine()) != null) { if (!line.equals("")) { - log.debug("reading line" + line); + log.debug("reading line " + line); String[] keyValue = line.split("\t"); String key = keyValue[0]; Long value = Long.parseLong(keyValue[1]); Modified: trunk/diswork-daemon/src/test/java/org/nuiton/diswork/daemon/DisworkDaemonTest.java =================================================================== --- trunk/diswork-daemon/src/test/java/org/nuiton/diswork/daemon/DisworkDaemonTest.java 2010-07-23 09:10:52 UTC (rev 108) +++ trunk/diswork-daemon/src/test/java/org/nuiton/diswork/daemon/DisworkDaemonTest.java 2010-07-23 13:22:40 UTC (rev 109) @@ -24,18 +24,19 @@ */ package org.nuiton.diswork.daemon; -import org.apache.commons.io.IOUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.InputStream; import java.net.URL; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.apache.commons.io.IOUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class DisworkDaemonTest { @@ -89,6 +90,16 @@ // close raise errors due to DHT doesn't manage peer leaving } } + + @Test + public void applicationManagement() throws Exception { + // this application has been submitted + assertTrue(daemon.isApplicationAvailable("fake-app", "1.0")); + + // those have not been submitted + assertFalse(daemon.isApplicationAvailable("unknow_app", "1.0")); + assertFalse(daemon.isApplicationAvailable("fake-app", "1.1")); + } @Test public void simpleSubmit() throws Exception {