//! Type of the job.
/*! There are three supported types:
- "command" : execute #job_file script without %SALOME environment
+ - "command_salome" : execute #job_file script within %SALOME environment
+ (salome shell) but the %SALOME application is not
+ launched
- "python_salome" : execute #job_file python script by %SALOME
- "yacs_file" : execute #job_file by YACS module as a xml YACS schema
*/
SALOME_Launcher_Handler.cxx
Launcher_Job.cxx
Launcher_Job_Command.cxx
+ Launcher_Job_CommandSALOME.cxx
Launcher_Job_SALOME.cxx
Launcher_Job_PythonSALOME.cxx
Launcher_Job_YACSFile.cxx
Launcher.hxx
Launcher_Job.hxx
Launcher_Job_Command.hxx
+ Launcher_Job_CommandSALOME.hxx
Launcher_Job_PythonSALOME.hxx
Launcher_Job_SALOME.hxx
Launcher_Job_YACSFile.hxx
#include <sstream>
-Launcher::Job_Command::Job_Command() {_job_type = "command";}
+const char Launcher::Job_Command::TYPE_NAME[] = "command";
+
+Launcher::Job_Command::Job_Command()
+{
+ _job_type = Launcher::Job_Command::TYPE_NAME;
+}
Launcher::Job_Command::~Job_Command() {}
std::string::size_type last = _env_file.find_last_of("/");
launch_script_stream << ". ./" << _env_file.substr(last+1) << std::endl;
}
- launch_script_stream << "./" << _job_file_name_complete << std::endl;
+ launch_script_stream << runCommandString() << std::endl;
// Return
launch_script_stream.flush();
chmod(_job_file.c_str(), 0x1ED);
return launch_script;
}
+
+std::string Launcher::Job_Command::runCommandString()
+{
+ std::ostringstream result;
+ result << "./" << _job_file_name_complete;
+ return result.str();
+}
#endif
virtual void update_job();
+ static const char TYPE_NAME[];
+
#ifdef WITH_LIBBATCH
protected:
std::string buildCommandScript(Batch::Parametre params, std::string launch_date);
+ virtual std::string runCommandString();
#endif
};
}
--- /dev/null
+// Copyright (C) 2009-2017 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// Author: André RIBES - EDF R&D
+//
+#include "Launcher_Job_CommandSALOME.hxx"
+
+#ifdef WITH_LIBBATCH
+#include <libbatch/Constants.hxx>
+#endif
+
+#include <sstream>
+
+const char Launcher::Job_CommandSALOME::TYPE_NAME[] = "command_salome";
+
+Launcher::Job_CommandSALOME::Job_CommandSALOME()
+{
+ _job_type = Launcher::Job_CommandSALOME::TYPE_NAME;
+}
+
+Launcher::Job_CommandSALOME::~Job_CommandSALOME() {}
+
+
+#ifdef WITH_LIBBATCH
+
+std::string Launcher::Job_CommandSALOME::runCommandString()
+{
+ std::ostringstream result;
+ result << _resource_definition.AppliPath
+ << "/salome shell ./"
+ << _job_file_name_complete;
+ return result.str();
+}
+#endif
--- /dev/null
+// Copyright (C) 2009-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// Author: André RIBES - EDF R&D
+//
+#ifndef _LAUNCHER_JOB_COMMAND_SALOME_HXX_
+#define _LAUNCHER_JOB_COMMAND_SALOME_HXX_
+
+#include "Launcher_Job_Command.hxx"
+#include "Launcher.hxx"
+
+#ifdef WITH_LIBBATCH
+#include <libbatch/Job.hxx>
+#endif
+
+namespace Launcher
+{
+ class LAUNCHER_EXPORT Job_CommandSALOME : virtual public Launcher::Job_Command
+ {
+ public:
+ Job_CommandSALOME();
+ virtual ~Job_CommandSALOME();
+ static const char TYPE_NAME[];
+
+#ifdef WITH_LIBBATCH
+ protected:
+ virtual std::string runCommandString();
+#endif
+ };
+}
+
+#endif
//
#include "Launcher_Job_PythonSALOME.hxx"
+const char Launcher::Job_PythonSALOME::TYPE_NAME[] = "python_salome";
-Launcher::Job_PythonSALOME::Job_PythonSALOME() {_job_type = "python_salome";}
+Launcher::Job_PythonSALOME::Job_PythonSALOME()
+{
+ _job_type = Launcher::Job_PythonSALOME::TYPE_NAME;
+}
Launcher::Job_PythonSALOME::~Job_PythonSALOME() {}
virtual void setJobFile(const std::string & job_file);
virtual void addJobTypeSpecificScript(std::ofstream & launch_script_stream);
+ static const char TYPE_NAME[];
};
}
#include "Launcher_Job_YACSFile.hxx"
#include <sstream>
+const char Launcher::Job_YACSFile::TYPE_NAME[] = "yacs_file";
Launcher::Job_YACSFile::Job_YACSFile()
{
- _job_type = "yacs_file";
+ _job_type = Launcher::Job_YACSFile::TYPE_NAME;
_dumpState = -1;
_yacsDriverOptions = "";
}
virtual void addJobTypeSpecificScript(std::ofstream & launch_script_stream);
virtual void checkSpecificParameters();
+ static const char TYPE_NAME[];
+
protected:
int _dumpState;
std::string _yacsDriverOptions;
#include "Launcher_XML_Persistence.hxx"
#include "Launcher_Job_Command.hxx"
+#include "Launcher_Job_CommandSALOME.hxx"
#include "Launcher_Job_YACSFile.hxx"
#include "Launcher_Job_PythonSALOME.hxx"
string job_type = getAttrValue(job_node, "type");
if (job_type.empty())
throw LauncherException(string("Invalid job \"") + job_name + "\": type is not defined");
- if (job_type == "command")
+ if (job_type == Launcher::Job_Command::TYPE_NAME)
new_job = new Launcher::Job_Command();
- else if (job_type == "yacs_file")
+ else if (job_type == Launcher::Job_CommandSALOME::TYPE_NAME)
+ new_job = new Launcher::Job_CommandSALOME();
+ else if (job_type == Launcher::Job_YACSFile::TYPE_NAME)
new_job = new Launcher::Job_YACSFile();
- else if (job_type == "python_salome")
+ else if (job_type == Launcher::Job_PythonSALOME::TYPE_NAME)
new_job = new Launcher::Job_PythonSALOME();
else
{
#include "Launcher_Job_Command.hxx"
#include "Launcher_Job_YACSFile.hxx"
#include "Launcher_Job_PythonSALOME.hxx"
+#include "Launcher_Job_CommandSALOME.hxx"
#include "utilities.h"
{
std::string job_type = job_parameters.job_type.in();
- if (job_type != "command" && job_type != "yacs_file" && job_type != "python_salome")
- {
- std::string message("SALOME_Launcher::createJob: bad job type: ");
- message += job_type;
- THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
- }
-
Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
- if (job_type == "command")
+ if (job_type == Launcher::Job_Command::TYPE_NAME)
new_job = new Launcher::Job_Command();
- else if (job_type == "yacs_file")
+ else if (job_type == Launcher::Job_CommandSALOME::TYPE_NAME)
+ new_job = new Launcher::Job_CommandSALOME();
+ else if (job_type == Launcher::Job_YACSFile::TYPE_NAME)
new_job = new Launcher::Job_YACSFile();
- else if (job_type == "python_salome")
+ else if (job_type == Launcher::Job_PythonSALOME::TYPE_NAME)
new_job = new Launcher::Job_PythonSALOME();
+ else
+ {
+ std::string message("SALOME_Launcher::createJob: bad job type: ");
+ message += job_type;
+ THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
+ }
// Name
new_job->setJobName(job_parameters.job_name.in());
self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
"it works!\n")
+ #################################
+ # test of command salome job type
+ #################################
+ def test_command_salome(self):
+ case_test_dir = os.path.join(TestCompo.test_dir, "command_salome")
+ mkdir_p(case_test_dir)
+
+ # job script
+ data_file = "in.txt"
+ script_file = "myEnvScript.py"
+ script_text = """#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os,sys
+# verify import salome
+import salome
+
+text_result = os.getenv("ENV_TEST_VAR","")
+
+f = open('result.txt', 'w')
+f.write(text_result)
+f.close()
+
+in_f = open("in.txt", "r")
+in_text = in_f.read()
+in_f.close()
+
+os.mkdir("copie")
+f = open(os.path.join("copie",'copie.txt'), 'w')
+f.write(in_text)
+f.close()
+"""
+ abs_script_file = os.path.join(case_test_dir, script_file)
+ f = open(abs_script_file, "w")
+ f.write(script_text)
+ f.close()
+ os.chmod(abs_script_file, 0o755)
+
+ #environement script
+ env_file = "myEnv.sh"
+ env_text = """export ENV_TEST_VAR="expected"
+"""
+ f = open(os.path.join(case_test_dir, env_file), "w")
+ f.write(env_text)
+ f.close()
+
+ # write data file
+ f = open(os.path.join(case_test_dir, data_file), "w")
+ f.write("to be copied")
+ f.close()
+
+ # job params
+ local_result_dir = os.path.join(case_test_dir, "result_comsalome_job-")
+ job_params = self.create_JobParameters()
+ job_params.job_type = "command_salome"
+ job_params.job_file = script_file
+ job_params.env_file = env_file
+ job_params.in_files = [data_file]
+ job_params.out_files = ["result.txt", "copie"]
+ job_params.local_directory = case_test_dir
+
+ # create and launch the job
+ launcher = salome.naming_service.Resolve('/SalomeLauncher')
+ resManager= salome.lcc.getResourcesManager()
+
+ for resource in self.ressources:
+ print "Testing command salome job on ", resource
+ job_params.result_directory = local_result_dir + resource
+ job_params.job_name = "CommandSalomeJob_" + resource
+ job_params.resource_required.name = resource
+
+ # use the working directory of the resource
+ resParams = resManager.GetResourceDefinition(resource)
+ wd = os.path.join(resParams.working_directory,
+ "CommandSalomeJob" + self.suffix)
+ job_params.work_directory = wd
+
+ job_id = launcher.createJob(job_params)
+ launcher.launchJob(job_id)
+ # wait for the end of the job
+ jobState = launcher.getJobState(job_id)
+ print "Job %d state: %s" % (job_id,jobState)
+ while jobState != "FINISHED" and jobState != "FAILED" :
+ time.sleep(3)
+ jobState = launcher.getJobState(job_id)
+ print "Job %d state: %s" % (job_id,jobState)
+ pass
+
+ # verify the results
+ self.assertEqual(jobState, "FINISHED")
+ launcher.getJobResults(job_id, "")
+ self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
+ "expected")
+ self.verifyFile(os.path.join(job_params.result_directory,
+ "copie",'copie.txt'),
+ "to be copied")
+
+ # verify getJobWorkFile
+ mydir = os.path.join(case_test_dir, "work_dir" + resource)
+ success = launcher.getJobWorkFile(job_id, "result.txt", mydir)
+ self.assertEqual(success, True)
+ self.verifyFile(os.path.join(mydir, "result.txt"), "expected")
+
+ success = launcher.getJobWorkFile(job_id, "copie", mydir)
+ self.assertEqual(success, True)
+ self.verifyFile(os.path.join(mydir, "copie", "copie.txt"),
+ "to be copied")
+ pass
+ pass
+ pass
+
if __name__ == '__main__':
# creat study
import salome