diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 79433fbf..00000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "iexec-scheduler"] - path = iexec-scheduler - url = https://github.com/iExecBlockchainComputing/iexec-scheduler -[submodule "iexec-worker"] - path = iexec-worker - url = https://github.com/iExecBlockchainComputing/iexec-worker diff --git a/build.gradle b/build.gradle index b4395c88..8167b7ea 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,21 @@ +def UNIQUE_ID='hostname -f'.execute().text.trim() +def tokencommon='curl -XPOST --data name=${UNIQUE_ID} https://cc02acaa7954c9d63333b18e6d5decead7d457ac3cfddeeb:@packagecloud.io/install/repositories/iexec/common/tokens.text'.execute().text.trim() +def tokenscheduler='curl -XPOST --data name=${UNIQUE_ID} https://6f087db4a17b65a64d456e474a6b4b16b59a52d59690b70d:@packagecloud.io/install/repositories/iexec/scheduler/tokens.text'.execute().text.trim() +def tokenworker='curl -XPOST --data name=${UNIQUE_ID} https://77715138d032c32e0d60769e5ae002b18837aa67da59f966:@packagecloud.io/install/repositories/iexec/worker/tokens.text'.execute().text.trim() + apply plugin: 'java-library' repositories { mavenCentral() + maven { + url "https://packagecloud.io/priv/${tokencommon}/iexec/common/maven2" + } + maven { + url "https://packagecloud.io/priv/${tokenscheduler}/iexec/scheduler/maven2" + } + maven { + url "https://packagecloud.io/priv/${tokenworker}/iexec/worker/maven2" + } } dependencies { @@ -19,8 +33,9 @@ dependencies { compile "org.json:json:20160810" // ? https://mvnrepository.com/artifact/org.json/json compile "org.web3j:core:3.2.0" - compile project(':iexec-scheduler') - compile project(':iexec-worker') + + compile "com.iexec.scheduler:iexec-scheduler:0.1.0-SNAPSHOT" + compile "com.iexec.worker:iexec-worker:0.1.0-SNAPSHOT" api 'org.apache.commons:commons-math3:3.6.1' diff --git a/iexec-scheduler b/iexec-scheduler deleted file mode 160000 index b02de06e..00000000 --- a/iexec-scheduler +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b02de06e4f02da99fceb78186144b578153c9df9 diff --git a/iexec-worker b/iexec-worker deleted file mode 160000 index 7594644c..00000000 --- a/iexec-worker +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7594644c83064fc1bdf88a8f8fdf876e366219ba diff --git a/settings.gradle b/settings.gradle index f8206dcd..b900582d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,6 +16,3 @@ include 'services:webservice' */ rootProject.name = 'xtremweb' - -include 'iexec-scheduler' -include 'iexec-worker' diff --git a/src/main/java/xtremweb/common/HTTPLauncher.java b/src/main/java/xtremweb/common/HTTPLauncher.java index a8e15345..8f8d70a7 100644 --- a/src/main/java/xtremweb/common/HTTPLauncher.java +++ b/src/main/java/xtremweb/common/HTTPLauncher.java @@ -23,295 +23,297 @@ package xtremweb.common; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; +import com.iexec.common.ethereum.CommonConfiguration; +import com.iexec.worker.ethereum.CommonConfigurationGetter; +import com.iexec.worker.ethereum.IexecWorkerLibrary; +import xtremweb.communications.CommClient; +import xtremweb.exec.Executor; +import xtremweb.worker.WorkerPocoWatcherImpl; + +import javax.net.ssl.SSLHandshakeException; +import java.io.*; import java.net.ConnectException; import java.net.MalformedURLException; import java.net.URL; -import javax.net.ssl.SSLHandshakeException; - -import com.iexec.worker.ethereum.IexecConfigurationService; -import xtremweb.communications.CommClient; -import xtremweb.exec.Executor; -import xtremweb.worker.WorkerWatcherImpl; - /** * This launches XtremWeb from its JAR file. This first retrieve URL from config * file, if any. If the config file contains no URL, this contructs a new URL * with the server found in the config file. - * + *
* URL must be like "http://aServer/aFile.jar. Default URL is
* "http://aServer/XWHEP/download/xtremweb.jar"
*/
public final class HTTPLauncher {
- private static final int SLEEPDELAY = 2500;
- private XWConfigurator config;
-
- /**
- * This retrieves the default communication client and initializes it
- *
- * @return the default comm client
- */
- private CommClient commClient() throws ConnectException {
-
- CommClient commClient = null;
- try {
- commClient = config.defaultCommClient();
- } catch (final Exception e) {
- throw new ConnectException(e.toString());
- }
- return commClient;
- }
-
- /**
- * Creates a new HTTPLauncher
instance.
- *
- * @param a
- * a String[]
value : command line arguments which
- * specificies the config file name
- * @throws IOException
- */
- private HTTPLauncher(final String[] a) throws IOException {
-
- IexecConfigurationService.initialize("../conf/iexec-worker.yml");
- WorkerWatcherImpl workerWatcher = new WorkerWatcherImpl();
-
-
- final String[] argv = a.clone();
- CommandLineParser args = null;
- try {
- args = new CommandLineParser(argv);
- } catch (final Exception e) {
- XWTools.fatal("xtremweb.upgrade.HTTPLauncher " + e);
- }
-
- try {
- config = (XWConfigurator) args.getOption(CommandLineOptions.CONFIG);
- } catch (final Exception e) {
- XWTools.fatal("can retreive config file");
- }
-
- final Logger logger = new Logger();
-
- URL url = null;
- try {
- url = config.launcherURL();
- if ((url.getPath() == null) || (url.getPath().length() == 0)) {
- url = new URL(url.toString() + "/XWHEP/download/" + XWTools.JARFILENAME);
- }
- } catch (final MalformedURLException e) {
- logger.warn("Invalid launcher URL : " + url);
- url = null;
- }
-
- Version serverVersion = null;
- File jarFile = null;
- final File rootDir = config.getConfigFile().getParentFile().getParentFile();
- File libDir = new File(rootDir, "lib");
- if (!libDir.exists()) {
- libDir = config.getTmpDir();
- }
- File binDir = new File(rootDir, "bin");
- if (!binDir.exists()) {
- binDir = config.getTmpDir();
- }
-
- final Version version = Version.currentVersion;
- while (true) {
- logger.debug("launcherURL = " + url);
- logger.debug("Current version : " + version.toString());
-
- boolean upgrade = false;
-
- try {
- serverVersion = commClient().version();
- logger.debug("Server version : " + serverVersion);
-
- if (serverVersion != null) {
-
- final File newJarFile = new File(libDir, XWTools.JARFILENAME + "-" + serverVersion);
-
- if (!newJarFile.exists()
- && !serverVersion.toString().equals(version.toString())) {
- logger.info("Server version : " + serverVersion);
- logger.info("********** ********** **********");
- logger.info("We must upgrade");
- logger.info("********** ********** **********");
- upgrade = true;
- jarFile = null;
- jarFile = newJarFile;
- }
-
- if (newJarFile.exists()) {
- jarFile = newJarFile;
- }
- }
- } catch (final SSLHandshakeException e) {
- logger.fatal("SSL error (maybe we have received a new keystore: relaunch is then necessary) : " + e);
- } catch (final Exception e) {
- upgrade = false;
- logger.exception(e);
- }
-
- if ((upgrade) && (url != null)) {
- logger.info("Downloading xwhep JAR file");
- try (final StreamIO io = new StreamIO(null, new DataInputStream(url.openStream()), false)) {
- logger.debug("" + jarFile + ".exists() = " + jarFile.exists());
-
- io.readFileContent(jarFile);
- } catch (final FileNotFoundException e) {
- logger.fatal("Can't download " + XWTools.JARFILENAME + " : " + e);
- } catch (final Exception e) {
- logger.exception(e);
- logger.warn("Can't download " + XWTools.JARFILENAME + "; using default : " + e.toString());
- }
- } else {
- logger.info("Not downloading xwhep JAR file");
- }
-
- Executor exec = null;
- String tmpPath = null;
- String jarFilePath = null;
- String keystorePath = null;
- String configPath = null;
- String xwcp = null;
- String javacp = System.getProperty("java.class.path");
- final StringBuilder javaCmd = new StringBuilder("java ");
-
- try {
- logger.debug("00 libDir = " + libDir.getAbsolutePath());
- if (config.getProperty(XWPropertyDefs.XWCP) != null) {
- libDir = new File(config.getProperty(XWPropertyDefs.XWCP));
- if (libDir.isFile()) {
- libDir = libDir.getParentFile();
- }
- }
- logger.config("libDir = " + libDir.getAbsolutePath());
-
- if ((jarFile == null) || !jarFile.exists()) {
- jarFile = new File(libDir, XWTools.JARFILENAME);
- }
-
- logger.config("jarFile = " + jarFile.getAbsolutePath());
- Thread.sleep(SLEEPDELAY);
-
- tmpPath = config.getTmpDir().getAbsolutePath();
- jarFilePath = jarFile.getAbsolutePath();
- keystorePath = config.getProperty(XWPropertyDefs.SSLKEYSTORE);
- configPath = config.getProperty(XWPropertyDefs.CONFIGFILE);
- xwcp = config.getProperty(XWPropertyDefs.XWCP);
- if (tmpPath.endsWith("/") || tmpPath.endsWith("\\")) {
- tmpPath = tmpPath.substring(0, tmpPath.length() - 1);
- }
- if (jarFilePath.endsWith("/") || jarFilePath.endsWith("\\")) {
- jarFilePath = jarFilePath.substring(0, jarFilePath.length() - 1);
- }
- if (keystorePath.endsWith("/") || keystorePath.endsWith("\\")) {
- keystorePath = keystorePath.substring(0, keystorePath.length() - 1);
- }
- if (configPath.endsWith("/") || configPath.endsWith("\\")) {
- configPath = configPath.substring(0, configPath.length() - 1);
- }
- if (xwcp.endsWith("/") || xwcp.endsWith("\\")) {
- xwcp = xwcp.substring(0, xwcp.length() - 1);
- }
-
- if (OSEnum.getOs().isWin32()) {
- tmpPath = "\"" + tmpPath + "\"";
- jarFilePath = "\"" + jarFilePath + "\"";
- keystorePath = "\"" + keystorePath + "\"";
- configPath = "\"" + configPath + "\"";
- xwcp = "\"" + xwcp + "\"";
- }
-
- final String hwmem = System.getProperty(XWPropertyDefs.HWMEM.toString()) == "" ? ""
- : " -D" + XWPropertyDefs.HWMEM + "=" + System.getProperty(XWPropertyDefs.HWMEM.toString());
- final String log4jconf = System.getProperty(XWPropertyDefs.LOG4JCONFIGFILE.propertyName()) == null ?
- "" : " -D" + XWPropertyDefs.LOG4JCONFIGFILE.propertyName() + "=" + System.getProperty(XWPropertyDefs.LOG4JCONFIGFILE.propertyName());
- final String loglevel= System.getProperty(XWPropertyDefs.LOGGERLEVEL.propertyName()) == null ?
- "" : " -D" + XWPropertyDefs.LOGGERLEVEL.propertyName() + "=" + System.getProperty(XWPropertyDefs.LOGGERLEVEL.propertyName());
-
- final StringBuilder javaOpts = new StringBuilder(" -D" + XWPropertyDefs.CACHEDIR.propertyName() + "=" + tmpPath
- + log4jconf + loglevel
- + " -D" + XWPropertyDefs.JAVALIBPATH.propertyName() + "=" + tmpPath + hwmem
- + " -D" + XWPropertyDefs.XWCP.propertyName() + "=" + xwcp
- + " -D" + XWPropertyDefs.JAVAKEYSTORE.propertyName() + "=" + keystorePath
- + " -cp " + jarFilePath + File.pathSeparator + (javacp != null ? javacp : "")
- + " xtremweb.worker.Worker "
- + " --xwconfig " + configPath);
-
- if (OSEnum.getOs().isWin32()) {
- javaCmd.append(" -Xrs ");
- }
-
- final String serveurOpt = " -server ";
- final String cmd = javaCmd.toString() + serveurOpt + javaOpts.toString();
-
- logger.config("Executing " + cmd);
- final FileInputStream in = null;
- exec = new Executor(cmd, binDir.getAbsolutePath(), in, System.out, System.err,
- Long.parseLong(config.getProperty(XWPropertyDefs.TIMEOUT)));
- int rc = exec.startAndWait();
- XWReturnCode returnCode = XWReturnCode.fromInt(rc);
- logger.config("returnCode = " + returnCode + " (" + rc + ")");
-
- if (returnCode == XWReturnCode.RESTART) {
- continue;
- }
-
- if (returnCode != XWReturnCode.SUCCESS) {
-
- final String cmd1 = javaCmd.toString() + javaOpts.toString();
-
- logger.config("Trying to launch the worker without \"" + serveurOpt + "\" java option : " + cmd1);
- exec = new Executor(cmd1, binDir.getAbsolutePath(), in, System.out, System.err,
- Long.parseLong(config.getProperty(XWPropertyDefs.TIMEOUT)));
- rc = exec.startAndWait();
- returnCode = XWReturnCode.fromInt(rc);
- }
-
- if (returnCode == XWReturnCode.RESTART) {
- continue;
- }
-
- if (returnCode != XWReturnCode.SUCCESS) {
- XWTools.fatal("We can't launch the worker : return code = " + returnCode + " (" + rc + ")"
- + "\n(maybe URL launcher is not set properly or does not point to server version...)"
- + "\n(maybe config file is corrupted...)");
- }
- } catch (final Exception e) {
- logger.exception(e);
- logger.error(e.toString());
- } finally {
- if (exec != null) {
- try {
- logger.info("Stopping process");
- exec.stop();
- } catch (final Exception e) {
- }
- }
- exec = null;
- tmpPath = null;
- jarFilePath = null;
- keystorePath = null;
- configPath = null;
- xwcp = null;
- javacp = null;
- }
- }
- }
-
- public static void main(final String[] argv) {
- try {
- new HTTPLauncher(argv);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ private static final int SLEEPDELAY = 2500;
+ private XWConfigurator config;
+
+ /**
+ * Creates a new HTTPLauncher
instance.
+ *
+ * @param a a String[]
value : command line arguments which
+ * specificies the config file name
+ * @throws IOException
+ */
+ private HTTPLauncher(final String[] a) throws IOException {
+ /*
+ IexecWorkerLibrary.initialize("../conf/iexec-worker.yml", new CommonConfigurationGetter() {
+ @Override
+ public CommonConfiguration getCommonConfiguration(String schedulerApiUrl) {
+ final String url = schedulerApiUrl + "/commonconfiguration";
+ return new RestTemplate().getForObject(url, CommonConfiguration.class);
+ }
+ });
+ WorkerPocoWatcherImpl workerPocoWatcher = new WorkerPocoWatcherImpl();
+ */
+
+ final String[] argv = a.clone();
+ CommandLineParser args = null;
+ try {
+ args = new CommandLineParser(argv);
+ } catch (final Exception e) {
+ XWTools.fatal("xtremweb.upgrade.HTTPLauncher " + e);
+ }
+
+ try {
+ config = (XWConfigurator) args.getOption(CommandLineOptions.CONFIG);
+ } catch (final Exception e) {
+ XWTools.fatal("can retreive config file");
+ }
+
+ final Logger logger = new Logger();
+
+ URL url = null;
+ try {
+ url = config.launcherURL();
+ if ((url.getPath() == null) || (url.getPath().length() == 0)) {
+ url = new URL(url.toString() + "/XWHEP/download/" + XWTools.JARFILENAME);
+ }
+ } catch (final MalformedURLException e) {
+ logger.warn("Invalid launcher URL : " + url);
+ url = null;
+ }
+
+ Version serverVersion = null;
+ File jarFile = null;
+ final File rootDir = config.getConfigFile().getParentFile().getParentFile();
+ File libDir = new File(rootDir, "lib");
+ if (!libDir.exists()) {
+ libDir = config.getTmpDir();
+ }
+ File binDir = new File(rootDir, "bin");
+ if (!binDir.exists()) {
+ binDir = config.getTmpDir();
+ }
+
+ final Version version = Version.currentVersion;
+ while (true) {
+ logger.debug("launcherURL = " + url);
+ logger.debug("Current version : " + version.toString());
+
+ boolean upgrade = false;
+
+ try {
+ serverVersion = commClient().version();
+ logger.debug("Server version : " + serverVersion);
+
+ if (serverVersion != null) {
+
+ final File newJarFile = new File(libDir, XWTools.JARFILENAME + "-" + serverVersion);
+
+ if (!newJarFile.exists()
+ && !serverVersion.toString().equals(version.toString())) {
+ logger.info("Server version : " + serverVersion);
+ logger.info("********** ********** **********");
+ logger.info("We must upgrade");
+ logger.info("********** ********** **********");
+ upgrade = true;
+ jarFile = null;
+ jarFile = newJarFile;
+ }
+
+ if (newJarFile.exists()) {
+ jarFile = newJarFile;
+ }
+ }
+ } catch (final SSLHandshakeException e) {
+ logger.fatal("SSL error (maybe we have received a new keystore: relaunch is then necessary) : " + e);
+ } catch (final Exception e) {
+ upgrade = false;
+ logger.exception(e);
+ }
+
+ if ((upgrade) && (url != null)) {
+ logger.info("Downloading xwhep JAR file");
+ try (final StreamIO io = new StreamIO(null, new DataInputStream(url.openStream()), false)) {
+ logger.debug("" + jarFile + ".exists() = " + jarFile.exists());
+
+ io.readFileContent(jarFile);
+ } catch (final FileNotFoundException e) {
+ logger.fatal("Can't download " + XWTools.JARFILENAME + " : " + e);
+ } catch (final Exception e) {
+ logger.exception(e);
+ logger.warn("Can't download " + XWTools.JARFILENAME + "; using default : " + e.toString());
+ }
+ } else {
+ logger.info("Not downloading xwhep JAR file");
+ }
+
+ Executor exec = null;
+ String tmpPath = null;
+ String jarFilePath = null;
+ String keystorePath = null;
+ String configPath = null;
+ String xwcp = null;
+ String javacp = System.getProperty("java.class.path");
+ final StringBuilder javaCmd = new StringBuilder("java ");
+
+ try {
+ logger.debug("00 libDir = " + libDir.getAbsolutePath());
+ if (config.getProperty(XWPropertyDefs.XWCP) != null) {
+ libDir = new File(config.getProperty(XWPropertyDefs.XWCP));
+ if (libDir.isFile()) {
+ libDir = libDir.getParentFile();
+ }
+ }
+ logger.config("libDir = " + libDir.getAbsolutePath());
+
+ if ((jarFile == null) || !jarFile.exists()) {
+ jarFile = new File(libDir, XWTools.JARFILENAME);
+ }
+
+ logger.config("jarFile = " + jarFile.getAbsolutePath());
+ Thread.sleep(SLEEPDELAY);
+
+ tmpPath = config.getTmpDir().getAbsolutePath();
+ jarFilePath = jarFile.getAbsolutePath();
+ keystorePath = config.getProperty(XWPropertyDefs.SSLKEYSTORE);
+ configPath = config.getProperty(XWPropertyDefs.CONFIGFILE);
+ xwcp = config.getProperty(XWPropertyDefs.XWCP);
+ if (tmpPath.endsWith("/") || tmpPath.endsWith("\\")) {
+ tmpPath = tmpPath.substring(0, tmpPath.length() - 1);
+ }
+ if (jarFilePath.endsWith("/") || jarFilePath.endsWith("\\")) {
+ jarFilePath = jarFilePath.substring(0, jarFilePath.length() - 1);
+ }
+ if (keystorePath.endsWith("/") || keystorePath.endsWith("\\")) {
+ keystorePath = keystorePath.substring(0, keystorePath.length() - 1);
+ }
+ if (configPath.endsWith("/") || configPath.endsWith("\\")) {
+ configPath = configPath.substring(0, configPath.length() - 1);
+ }
+ if (xwcp.endsWith("/") || xwcp.endsWith("\\")) {
+ xwcp = xwcp.substring(0, xwcp.length() - 1);
+ }
+
+ if (OSEnum.getOs().isWin32()) {
+ tmpPath = "\"" + tmpPath + "\"";
+ jarFilePath = "\"" + jarFilePath + "\"";
+ keystorePath = "\"" + keystorePath + "\"";
+ configPath = "\"" + configPath + "\"";
+ xwcp = "\"" + xwcp + "\"";
+ }
+
+ final String hwmem = System.getProperty(XWPropertyDefs.HWMEM.toString()) == "" ? ""
+ : " -D" + XWPropertyDefs.HWMEM + "=" + System.getProperty(XWPropertyDefs.HWMEM.toString());
+ final String log4jconf = System.getProperty(XWPropertyDefs.LOG4JCONFIGFILE.propertyName()) == null ?
+ "" : " -D" + XWPropertyDefs.LOG4JCONFIGFILE.propertyName() + "=" + System.getProperty(XWPropertyDefs.LOG4JCONFIGFILE.propertyName());
+ final String loglevel = System.getProperty(XWPropertyDefs.LOGGERLEVEL.propertyName()) == null ?
+ "" : " -D" + XWPropertyDefs.LOGGERLEVEL.propertyName() + "=" + System.getProperty(XWPropertyDefs.LOGGERLEVEL.propertyName());
+
+ final StringBuilder javaOpts = new StringBuilder(" -D" + XWPropertyDefs.CACHEDIR.propertyName() + "=" + tmpPath
+ + log4jconf + loglevel
+ + " -D" + XWPropertyDefs.JAVALIBPATH.propertyName() + "=" + tmpPath + hwmem
+ + " -D" + XWPropertyDefs.XWCP.propertyName() + "=" + xwcp
+ + " -D" + XWPropertyDefs.JAVAKEYSTORE.propertyName() + "=" + keystorePath
+ + " -cp " + jarFilePath + File.pathSeparator + (javacp != null ? javacp : "")
+ + " xtremweb.worker.Worker "
+ + " --xwconfig " + configPath);
+
+ if (OSEnum.getOs().isWin32()) {
+ javaCmd.append(" -Xrs ");
+ }
+
+ final String serveurOpt = " -server ";
+ final String cmd = javaCmd.toString() + serveurOpt + javaOpts.toString();
+
+ logger.config("Executing " + cmd);
+ final FileInputStream in = null;
+ exec = new Executor(cmd, binDir.getAbsolutePath(), in, System.out, System.err,
+ Long.parseLong(config.getProperty(XWPropertyDefs.TIMEOUT)));
+ int rc = exec.startAndWait();
+ XWReturnCode returnCode = XWReturnCode.fromInt(rc);
+ logger.config("returnCode = " + returnCode + " (" + rc + ")");
+
+ if (returnCode == XWReturnCode.RESTART) {
+ continue;
+ }
+
+ if (returnCode != XWReturnCode.SUCCESS) {
+
+ final String cmd1 = javaCmd.toString() + javaOpts.toString();
+
+ logger.config("Trying to launch the worker without \"" + serveurOpt + "\" java option : " + cmd1);
+ exec = new Executor(cmd1, binDir.getAbsolutePath(), in, System.out, System.err,
+ Long.parseLong(config.getProperty(XWPropertyDefs.TIMEOUT)));
+ rc = exec.startAndWait();
+ returnCode = XWReturnCode.fromInt(rc);
+ }
+
+ if (returnCode == XWReturnCode.RESTART) {
+ continue;
+ }
+
+ if (returnCode != XWReturnCode.SUCCESS) {
+ XWTools.fatal("We can't launch the worker : return code = " + returnCode + " (" + rc + ")"
+ + "\n(maybe URL launcher is not set properly or does not point to server version...)"
+ + "\n(maybe config file is corrupted...)");
+ }
+ } catch (final Exception e) {
+ logger.exception(e);
+ logger.error(e.toString());
+ } finally {
+ if (exec != null) {
+ try {
+ logger.info("Stopping process");
+ exec.stop();
+ } catch (final Exception e) {
+ }
+ }
+ exec = null;
+ tmpPath = null;
+ jarFilePath = null;
+ keystorePath = null;
+ configPath = null;
+ xwcp = null;
+ javacp = null;
+ }
+ }
+ }
+
+ public static void main(final String[] argv) {
+ try {
+ new HTTPLauncher(argv);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * This retrieves the default communication client and initializes it
+ *
+ * @return the default comm client
+ */
+ private CommClient commClient() throws ConnectException {
+
+ CommClient commClient = null;
+ try {
+ commClient = config.defaultCommClient();
+ } catch (final Exception e) {
+ throw new ConnectException(e.toString());
+ }
+ return commClient;
+ }
}
diff --git a/src/main/java/xtremweb/dispatcher/Dispatcher.java b/src/main/java/xtremweb/dispatcher/Dispatcher.java
index 9db61105..510065ff 100644
--- a/src/main/java/xtremweb/dispatcher/Dispatcher.java
+++ b/src/main/java/xtremweb/dispatcher/Dispatcher.java
@@ -23,35 +23,24 @@
package xtremweb.dispatcher;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Timer;
-
-import com.iexec.scheduler.ethereum.IexecConfigurationService;
-import com.iexec.scheduler.iexechub.IexecHubService;
-import com.iexec.scheduler.iexechub.IexecHubWatcher;
-import com.iexec.scheduler.workerpool.WorkerPoolService;
+import com.iexec.scheduler.ethereum.IexecSchedulerLibrary;
import org.eclipse.jetty.server.session.SessionHandler;
-
-import xtremweb.common.CommandLineOptions;
-import xtremweb.common.CommandLineParser;
-import xtremweb.common.Logger;
-import xtremweb.common.Version;
-import xtremweb.common.XWConfigurator;
-import xtremweb.common.XWPropertyDefs;
-import xtremweb.common.XWReturnCode;
-import xtremweb.common.XWRole;
-import xtremweb.common.XWTools;
+import xtremweb.common.*;
import xtremweb.communications.AccessLogger;
import xtremweb.communications.HTTPServer;
import xtremweb.communications.TCPServer;
import xtremweb.security.PEMPublicKeyValidator;
import xtremweb.security.X509ProxyValidator;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Timer;
+
/**
* Dispatcher Implementation
* The Dispatcher is responsible for delivering task to servers
+ *
* @author V. Neri, G. Fedak
*/
@@ -61,265 +50,259 @@
public class Dispatcher {
- private final Logger logger;
-
- /**
- * The TaskSet and TaskManager
- */
- private static TaskSet tset;
-
- /**
- * Database Interface
- */
- private static DBInterface db;
-
- /** Scheduling policy */
- private static Scheduler scheduler;
-
- /**
- * This aims to validate an X509 certificate against certificate paths
- *
- * @since 7.0.0
- */
- private static X509ProxyValidator proxyValidator;
- /**
- * This aims to challenge client connections
- *
- * @since 7.5.0
- */
- private static PEMPublicKeyValidator certValidator;
-
- /** Timer */
- private static Timer timer;
-
- /**
- * This stores and tests the command line parameters
- */
- private CommandLineParser args;
- /**
- * Config as read from config file
- */
- private static XWConfigurator config;
-
- /**
- * This is the default constructor
- */
- public Dispatcher(final String a[]) {
- final String[] argv = a.clone();
- logger = new Logger(this);
- try {
- args = new CommandLineParser(argv);
- } catch (final Exception e) {
- logger.fatal("Command line error " + e);
- }
-
- XWRole.setDispatcher();
-
- try {
- setConfig((XWConfigurator) args.getOption(CommandLineOptions.CONFIG));
- } catch (final Exception e) {
- logger.fatal("can retreive config file");
- }
- }
-
- /**
- * Main function
- */
- public static void main(final String args[]) {
-
- try {
- new Dispatcher(args).go();
- } catch (final Exception e) {
- System.err.println(e.toString());
- }
- }
-
- /**
- * Main function
- */
- public void go() throws Exception {
-
- IexecConfigurationService.initialize("../conf/iexec-scheduler.yml");
- IexecHubWatcher iexecHubWatcher = new IexecHubWatcherImpl();
-
- timer = new Timer();
-
- try {
- db = new DBInterface(config);
- } catch(Exception e) {
- e.printStackTrace();
- }
-
- tset = new HashTaskSet();
- try {
- setScheduler(
- (Scheduler) (Class.forName(config.getProperty(XWPropertyDefs.SCHEDULERCLASS)).newInstance()));
- } catch (final Exception e) {
- logger.exception(e);
- logger.fatal(e.toString());
- }
-
- try {
- setProxyValidator(new X509ProxyValidator());
- } catch (final Exception e) {
- setProxyValidator(null);
- logger.exception("Can't create ProxyValidator", e);
- }
-
- try {
- getProxyValidator().setCACertificateEntries(config.getKeyStore());
- } catch (final Exception e) {
- logger.exception("Can't add CA certificates to keystore", e);
- }
-
- try {
- certValidator = new PEMPublicKeyValidator();
- } catch (final Exception e) {
- certValidator = null;
- logger.exception("Can't create PEMPublicKeyValidator", e);
- }
-
- tset.start();
- try {
- while (!tset.isReady()) {
- Thread.sleep(1000);
- logger.info("still waiting task set...");
- }
- } catch (final Exception e) {
- logger.error("exception while waiting task set...");
- }
-
- try {
-
- @SuppressWarnings("unused")
- final AccessLogger accessLogger = new AccessLogger(config.getFile(XWPropertyDefs.HOMEDIR),
- XWTools.getLocalHostName());
-
- final TCPServer tcpServer = new TCPServer();
- tcpServer.initComm(config, new TCPHandler(config));
- tcpServer.start();
-
- logger.warn("UDP server not started");
-
- if (config.http()) {
- final HTTPServer httpServer = new HTTPServer();
- // httpServer.initComm(config, new
- // HTTPHandler(config));
-
- // Handler needs HTTP session to handle openid call returns
- final SessionHandler main_sessionHandler = new SessionHandler();
- main_sessionHandler.setHandler(new HTTPHandler(config));
- httpServer.initComm(config, main_sessionHandler);
- httpServer.addHandler(HTTPHandler.PATH, main_sessionHandler);
-
- // OpenId Handler needs HTTP session
- // final SessionHandler opid_sessionHandler = new
- // SessionHandler();
- // final HTTPOpenIdHandler oh = new HTTPOpenIdHandler();
- // HTTPOpenIdHandler.setCACertificateEntries(config.getKeyStore());
- // opid_sessionHandler.setHandler(oh);
- // httpServer.addHandler(HTTPOpenIdHandler.handlerPath,
- // opid_sessionHandler);
-
- // OAuth Handler needs HTTP session
- final SessionHandler oauth_sessionHandler = new SessionHandler();
- final HTTPOAuthHandler oah = new HTTPOAuthHandler();
- oauth_sessionHandler.setHandler(oah);
- httpServer.addHandler(HTTPOAuthHandler.handlerPath, oauth_sessionHandler);
-
- if((config.getProperty(XWPropertyDefs.JWTETHSECRET) != null) &&
- (config.getProperty(XWPropertyDefs.JWTETHISSUER) != null)) {
- // JWT Handler needs HTTP session
- final SessionHandler jwt_sessionHandler = new SessionHandler();
- final HTTPJWTEthereumAuthHandler jwth = new HTTPJWTEthereumAuthHandler();
- jwt_sessionHandler.setHandler(jwth);
- httpServer.addHandler(HTTPJWTEthereumAuthHandler.handlerPath, jwt_sessionHandler);
- }
- // StatsHandler does not need HTTP session
- httpServer.addHandler(HTTPStatsHandler.PATH, new HTTPStatsHandler());
- httpServer.start();
- }
- } catch (final Exception e) {
- logger.exception(e);
- logger.fatal("Dispatcher main(): " + e);
- }
-
- final Collection