diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp index 8be952b69e915c974707213f837853f8b9b6a61a..74ae7627fc1a816156cea54a9ada1650c62dbec1 100644 --- a/Common/CommandLine.cpp +++ b/Common/CommandLine.cpp @@ -137,6 +137,8 @@ void GetOptions(int argc, char *argv[]) } #endif + Msg::SetExecutableName(argv[0]); + // get command line options int i = 1; while(i < argc) { @@ -160,6 +162,19 @@ void GetOptions(int argc, char *argv[]) else Msg::Fatal("Missing client name and/or address of OneLab server"); } + + //FHF + else if(!strcmp(argv[i] + 1, "lol")) { + i++; + if(argv[i] && argv[i + 1] && argv[i + 1][0] != '-'){ + Msg::LoadOnelabClient(argv[i], argv[i + 1]); + i += 2; + } + else + Msg::Fatal("Missing client name and/or address of OneLab server"); + } + // + else if(!strcmp(argv[i] + 1, "socket")) { i++; if(argv[i]) diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 820f85ff07c8235ca2f64bcf9da9e398a3dbd1fb..a68e3649bd62c27d369345ef63d13db094a8f350 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -53,6 +53,7 @@ GmshMessage *Msg::_callback = 0; std::string Msg::_commandLine; std::string Msg::_launchDate; GmshClient *Msg::_client = 0; +std::string Msg::_execName; #if defined(HAVE_ONELAB) onelab::client *Msg::_onelabClient = 0; onelab::server *onelab::server::_server = 0; @@ -708,6 +709,48 @@ void Msg::InitializeOnelab(const std::string &name, const std::string &sockname) #endif } +void Msg::LoadOnelabClient(const std::string &clientName, const std::string &sockName) +{ +#if defined(HAVE_ONELAB) + onelab::remoteNetworkClient *client = 0; + client = new onelab::remoteNetworkClient(clientName,sockName); + if(client){ + std::string action, cmd; + std::vector<onelab::string> ps; + client->get(ps,clientName+"/Action"); + if(ps.size() && ps[0].getValue().size()) + action.assign(ps[0].getValue()); + + cmd.assign(""); + if(!action.compare("compute")){ + std::vector<onelab::string> ps; + client->get(ps,clientName+"/FullCmdLine"); + if(ps.size() && ps[0].getValue().size()) + cmd.append(" " + ps[0].getValue()); + + if(cmd.size()){ + Msg::Info("Loader calls <%s>",cmd.c_str()); + SystemCall(cmd.c_str(),true); //true->blocking + } + else + Msg::Info("No full command line found for <%s>", + clientName.c_str()); + } + Msg::Info("Stopping client <%s>", clientName.c_str()); + delete client; + } + exit(1); +#endif +} + +// void Msg::SetExecutableName(const std::string &name){ +// _execName.assign(name); +// } +// std::string Msg::GetExecutableName(){ +// return _execName; +// } + + void Msg::ExchangeOnelabParameter(const std::string &key, std::vector<double> &val, std::map<std::string, std::vector<double> > &fopt, diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index 4a65a163e1d05ed0e0a275600b353a9dfc10a7e3..f6fc50b2184c67cdffce5939cc6ade3cc0e5308a 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -44,6 +44,8 @@ class Msg { static GmshClient *_client; // communication with onelab server static onelab::client *_onelabClient; + // executable name + static std::string _execName; public: Msg() {} static void Init(int argc, char **argv); @@ -83,6 +85,9 @@ class Msg { static int GetAnswer(const char *question, int defaultval, const char *zero, const char *one, const char *two=0); static void InitializeOnelab(const std::string &name, const std::string &sockname=""); + static void SetExecutableName(const std::string &name) { _execName.assign(name); } + static std::string GetExecutableName() { return _execName; } + static void LoadOnelabClient(const std::string &name, const std::string &sockName); static GmshClient *GetGmshClient(){ return _client; } static onelab::client *GetOnelabClient(){ return _onelabClient; } static void FinalizeOnelab(); @@ -90,9 +95,9 @@ class Msg { static void SetOnelabNumber(std::string name, double val, bool visible); static void SetOnelabString(std::string name, std::string val, bool visible); static void ExchangeOnelabParameter(const std::string &key, - std::vector<double> &val, - std::map<std::string, std::vector<double> > &fopt, - std::map<std::string, std::vector<std::string> > &copt); + std::vector<double> &val, + std::map<std::string, std::vector<double> > &fopt, + std::map<std::string, std::vector<std::string> > &copt); static void ImportPhysicalsAsOnelabRegions(); }; diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index b6b0070a4e98d71f157215828c32b5fb5dde72bd..92ae280a42f90fe8fcca7f125c65615c94a0ac84 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -1326,7 +1326,7 @@ int metamodel_cb(const std::string &name, const std::string &action) if(FlGui::instance()->onelab->isBusy()) FlGui::instance()->onelab->show(); else{ - initializeMetamodel(Msg::GetOnelabClient(), &flgui_wait_cb); + initializeMetamodel(Msg::GetExecutableName(),Msg::GetOnelabClient(), &flgui_wait_cb); onelab::number n("IsMetamodel", 1.); n.setVisible(false); diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index d21cfb740406090abdd54d7041769c49aa99cb26..96cb52192296a8c824f99788b5b59ab2e0846cc8 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -115,7 +115,7 @@ std::string localNetworkSolverClient::appendArguments(){ command.append(" " + getSocketSwitch() + " " + getName() + " %s"); } else - OLMsg::Fatal("buildCommandLine: Unknown Action <%s>", action.c_str()); + OLMsg::Fatal("appendArguments: Unknown Action <%s>", action.c_str()); return command; } @@ -156,9 +156,6 @@ bool localNetworkSolverClient::run() std::string command = buildCommandLine(); if(command.size()) command.append(appendArguments()); - // std::cout << "sockname=<" << sockname << ">" << std::endl; - // std::cout << "command=<" << command << ">" << std::endl; - int sock; try{ sock = server->Start(command.c_str(), sockname.c_str(), 10); @@ -337,6 +334,12 @@ bool localNetworkSolverClient::run() server->Shutdown(); delete server; OLMsg::StatusBar(2, true, "Done running '%s'", _name.c_str()); + + if(command.empty()){ + OLMsg::Info("Client disconnected: starting new connection"); + goto new_connection; + } + return true; } @@ -844,9 +847,7 @@ void EncapsulatedClient::convert() { } std::string EncapsulatedClient::buildCommandLine(){ - std::string command; - command.assign("lol"); - return command; + return OLMsg::GetLoaderName(); } void EncapsulatedClient::compute(){ @@ -866,16 +867,17 @@ void EncapsulatedClient::compute(){ } } - setAction("compute"); if(buildRmCommand(cmd)) mySystem(cmd); + // the client command line is buit and stored in a onelab parameter cmd.assign(""); if(!getWorkingDir().empty()) cmd.append("cd " + getWorkingDir() + cmdSep); cmd.append(FixWindowsPath(getCommandLine())); cmd.append(" " + getString("Arguments")); - OLMsg::SetOnelabString(getName()+"/FullCmdLine",cmd,false); + + // the encapsulating localNetworkClient is called run(); if(getList("OutputFiles",choices)){ @@ -920,8 +922,6 @@ void RemoteInterfacedClient::compute(){ syncOutputFile(getWorkingDir(),choices[i]); } - // if(getList("PostArray",choices)) - // PostArray(choices); OLMsg::Info("Client %s completed",getName().c_str()); } @@ -981,8 +981,6 @@ void RemoteNativeClient::compute(){ syncOutputFile(getWorkingDir(),choices[i]); } - // if(getList("PostArray",choices)) - // PostArray(choices); OLMsg::Info("Client %s completed",getName().c_str()); } @@ -998,6 +996,7 @@ void RemoteEncapsulatedClient::compute(){ std::vector<std::string> choices; OLMsg::Info("Computes <%s> changed=%d", getName().c_str()); + analyze(); setAction("compute"); @@ -1011,20 +1010,27 @@ void RemoteEncapsulatedClient::compute(){ mySystem(cmd); } - cmd.assign("ssh "+getRemoteHost()+" 'cd "+getRemoteDir()+"; " - +getCommandLine()+" "+getString("Arguments")+"'"); - mySystem(cmd); + // the client command line is buit and stored in a onelab parameter + cmd.assign("ssh "+getRemoteHost()); + if(!getRemoteDir().empty()) + cmd.append(" 'cd " + getRemoteDir() + ";"); + cmd.append(" "+FixWindowsPath(getCommandLine())); + cmd.append(" " + getString("Arguments") + " '"); + OLMsg::SetOnelabString(getName()+"/FullCmdLine",cmd,false); + + // the encapsulating localNetworkClient is called + run(); if(getList("OutputFiles",choices)){ for(unsigned int i = 0; i < choices.size(); i++) syncOutputFile(getWorkingDir(),choices[i]); } - // if(getList("PostArray",choices)) - // PostArray(choices); OLMsg::Info("Client %s completed",getName().c_str()); } + + // ONELAB additional TOOLS (no access to server in tools) // options for 'onelab_client' diff --git a/contrib/onelab/OnelabClients.h b/contrib/onelab/OnelabClients.h index 02d7cf386a80a5945e99d488c8a5a488d5847e72..5fcd47419ba6c78e43585859ca3fbe0a0363507a 100644 --- a/contrib/onelab/OnelabClients.h +++ b/contrib/onelab/OnelabClients.h @@ -290,7 +290,9 @@ public: class EncapsulatedClient : public localNetworkSolverClient{ public: - EncapsulatedClient(const std::string &name, const std::string &cmdl, const std::string &wdir) : localNetworkSolverClient(name,cmdl,wdir) {} + EncapsulatedClient(const std::string &name, const std::string &cmdl, const std::string &wdir) : localNetworkSolverClient(name,cmdl,wdir) { + setSocketSwitch("-lol"); + } ~EncapsulatedClient(){} std::string buildCommandLine(); diff --git a/contrib/onelab/OnelabMessage.cpp b/contrib/onelab/OnelabMessage.cpp index d5637d9caf183f350c5d6362f66784b906404a92..ae8db4afc12343c9fab4f85ccddeb49b1f0178f3 100644 --- a/contrib/onelab/OnelabMessage.cpp +++ b/contrib/onelab/OnelabMessage.cpp @@ -29,6 +29,7 @@ std::string OLMsg::_commandLine; std::string OLMsg::_launchDate; GmshClient *OLMsg::_client = 0; onelab::client *OLMsg::_onelabClient = 0; +std::string OLMsg::_loaderName; bool OLMsg::hasGmsh=false; std::set<std::string, fullNameLessThan> OLMsg::_fullNameDict; void (*OLMsg::gui_wait_fct)(double time) = 0; @@ -231,6 +232,13 @@ void (*OLMsg::GetGuiWaitFunction())(double){ return gui_wait_fct; } +// void OLMsg::SetLoaderName(const std::string &name) { +// _loaderName = name; +// } +// std::string OLMsg::GetLoaderName() { +// return _loaderName; +// } + double OLMsg::GetOnelabNumber(std::string name) { if(_onelabClient){ diff --git a/contrib/onelab/OnelabMessage.h b/contrib/onelab/OnelabMessage.h index 0daaffade98dab051ccd07e1b536ebbee8fbd503..a933b22be8a6de48e9c749b2129672f3c1f3111e 100644 --- a/contrib/onelab/OnelabMessage.h +++ b/contrib/onelab/OnelabMessage.h @@ -54,6 +54,8 @@ class OLMsg { static onelab::client *_onelabClient; // dictionnary for parameter names static std::set<std::string, fullNameLessThan> _fullNameDict; + // Loader executable name + static std::string _loaderName; // Gmsh wait function static void (*gui_wait_fct)(double time); public: @@ -96,6 +98,9 @@ class OLMsg { //static void InitClient(std::string sockname); //static void FinalizeClient(); static GmshClient *GetClient(){ return _client; } + + static void SetLoaderName(const std::string &name){ _loaderName = name; } + static std::string GetLoaderName(){ return _loaderName; } static void SetGuiWaitFunction(void (*fct)(double time)); static void (*GetGuiWaitFunction())(double); diff --git a/contrib/onelab/metamodel.cpp b/contrib/onelab/metamodel.cpp index 98a1521808e2e0bdbbe7f3e423d2636588060bbc..a70e0aba6b1ffdaacbe66185b79ba9babef76521 100644 --- a/contrib/onelab/metamodel.cpp +++ b/contrib/onelab/metamodel.cpp @@ -2,7 +2,7 @@ #include "metamodel.h" -void initializeMetamodel(onelab::client *client, void (*gui_wait_fct)(double time)) +void initializeMetamodel(const std::string &loaderName, onelab::client *client, void (*gui_wait_fct)(double time)) { //called by "metamodel_cb" //copies the Msg::_onelabClient to OLMsg::_onelabClient @@ -10,8 +10,10 @@ void initializeMetamodel(onelab::client *client, void (*gui_wait_fct)(double tim //which is a onelab::client with sone Gmsh features (merge and messages). //Initilizes also the wait function the Gmsh Gui //so that Gmsh windows may remain active during client computations. + OLMsg::SetLoaderName(loaderName); OLMsg::SetOnelabClient(client); OLMsg::SetGuiWaitFunction(gui_wait_fct); + } int metamodel(const std::string &action){ @@ -27,6 +29,7 @@ int metamodel(const std::string &action){ todo = COMPUTE; } else{ + todo = EXIT; OLMsg::Fatal("Unknown action <%s>", action.c_str()); } diff --git a/contrib/onelab/metamodel.h b/contrib/onelab/metamodel.h index 0c5c1152b8e3e0170a618d79a7b5f3edfa3b516c..981c351076719517b9a756a407e3b9238ca6b31e 100644 --- a/contrib/onelab/metamodel.h +++ b/contrib/onelab/metamodel.h @@ -3,4 +3,4 @@ namespace onelab{ class client; } int metamodel(const std::string &todo); -void initializeMetamodel(onelab::client *, void (*wait)(double time)); +void initializeMetamodel(const std::string &, onelab::client *, void (*wait)(double time));