1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "Launcher_Job_Writer.hxx"
24 #include "Launcher_Job.hxx"
26 void Launcher::addToXmlDocument(xmlNodePtr root_node, const Launcher::Job* job)
29 xmlNodePtr job_node = xmlNewChild(root_node, NULL, xmlCharStrdup("job"), NULL);
30 xmlNewProp(job_node, xmlCharStrdup("type"), xmlCharStrdup(job->getJobType().c_str()));
31 xmlNewProp(job_node, xmlCharStrdup("name"), xmlCharStrdup(job->getJobName().c_str()));
34 xmlNodePtr node = xmlNewChild(job_node, NULL, xmlCharStrdup("user_part"), NULL);
36 xmlNewChild(node, NULL, xmlCharStrdup("job_file"), xmlCharStrdup(job->getJobFile().c_str()));
37 xmlNewChild(node, NULL, xmlCharStrdup("env_file"), xmlCharStrdup(job->getEnvFile().c_str()));
38 xmlNewChild(node, NULL, xmlCharStrdup("work_directory"), xmlCharStrdup(job->getWorkDirectory().c_str()));
39 xmlNewChild(node, NULL, xmlCharStrdup("local_directory"), xmlCharStrdup(job->getLocalDirectory().c_str()));
40 xmlNewChild(node, NULL, xmlCharStrdup("result_directory"), xmlCharStrdup(job->getResultDirectory().c_str()));
42 // Parameters for COORM
43 xmlNewChild(node, NULL, xmlCharStrdup("launcher_file"), xmlCharStrdup(job->getLauncherFile().c_str()));
46 xmlNodePtr files_node = xmlNewChild(node, NULL, xmlCharStrdup("files"), NULL);
47 std::list<std::string> in_files = job->get_in_files();
48 std::list<std::string> out_files = job->get_out_files();
49 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
50 xmlNewChild(files_node, NULL, xmlCharStrdup("in_file"), xmlCharStrdup((*it).c_str()));
51 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
52 xmlNewChild(files_node, NULL, xmlCharStrdup("out_file"), xmlCharStrdup((*it).c_str()));
55 resourceParams resource_params = job->getResourceRequiredParams();
56 xmlNodePtr res_node = xmlNewChild(node, NULL, xmlCharStrdup("resource_params"), NULL);
57 xmlNewChild(res_node, NULL, xmlCharStrdup("name"), xmlCharStrdup(resource_params.name.c_str()));
58 xmlNewChild(res_node, NULL, xmlCharStrdup("hostname"), xmlCharStrdup(resource_params.hostname.c_str()));
59 xmlNewChild(res_node, NULL, xmlCharStrdup("OS"), xmlCharStrdup(resource_params.OS.c_str()));
60 std::ostringstream nb_proc_stream;
61 std::ostringstream nb_node_stream;
62 std::ostringstream nb_proc_per_node_stream;
63 std::ostringstream cpu_clock_stream;
64 std::ostringstream mem_mb_stream;
65 nb_proc_stream << resource_params.nb_proc;
66 nb_node_stream << resource_params.nb_node;
67 nb_proc_per_node_stream << resource_params.nb_proc_per_node;
68 cpu_clock_stream << resource_params.cpu_clock;
69 mem_mb_stream << resource_params.mem_mb;
70 xmlNewChild(res_node, NULL, xmlCharStrdup("nb_proc"), xmlCharStrdup(nb_proc_stream.str().c_str()));
71 xmlNewChild(res_node, NULL, xmlCharStrdup("nb_node"), xmlCharStrdup(nb_node_stream.str().c_str()));
72 xmlNewChild(res_node, NULL, xmlCharStrdup("nb_proc_per_node"), xmlCharStrdup(nb_proc_per_node_stream.str().c_str()));
73 xmlNewChild(res_node, NULL, xmlCharStrdup("cpu_clock"), xmlCharStrdup(cpu_clock_stream.str().c_str()));
74 xmlNewChild(res_node, NULL, xmlCharStrdup("mem_mb"), xmlCharStrdup(mem_mb_stream.str().c_str()));
76 xmlNewChild(node, NULL, xmlCharStrdup("maximum_duration"), xmlCharStrdup(job->getMaximumDuration().c_str()));
77 xmlNewChild(node, NULL, xmlCharStrdup("queue"), xmlCharStrdup(job->getQueue().c_str()));
78 xmlNewChild(node, NULL, xmlCharStrdup("exclusive"), xmlCharStrdup(job->getExclusiveStr().c_str()));
79 std::ostringstream mem_per_cpu_stream;
80 mem_per_cpu_stream << job->getMemPerCpu();
81 xmlNewChild(node, NULL, xmlCharStrdup("mem_per_cpu"), xmlCharStrdup(mem_per_cpu_stream.str().c_str()));
84 xmlNewChild(node, NULL, xmlCharStrdup("launcher_args"), xmlCharStrdup(job->getLauncherArgs().c_str()));
86 // Specific parameters part
87 xmlNodePtr specific_parameters_node = xmlNewChild(node, NULL, xmlCharStrdup("specific_parameters"), NULL);
88 std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
89 for(std::map<std::string, std::string>::iterator it = specific_parameters.begin(); it != specific_parameters.end(); it++)
91 xmlNodePtr specific_parameter_node = xmlNewChild(specific_parameters_node, NULL, xmlCharStrdup("specific_parameter"), NULL);
92 xmlNewChild(specific_parameter_node, NULL, xmlCharStrdup("name"), xmlCharStrdup((it->first).c_str()));
93 xmlNewChild(specific_parameter_node, NULL, xmlCharStrdup("value"), xmlCharStrdup((it->second).c_str()));
97 xmlNodePtr run_node = xmlNewChild(job_node, NULL, xmlCharStrdup("run_part"), NULL);
98 xmlNewChild(run_node, NULL, xmlCharStrdup("job_state"), xmlCharStrdup(job->getState().c_str()));
99 ParserResourcesType resource_definition = job->getResourceDefinition();
100 xmlNewChild(run_node, NULL, xmlCharStrdup("resource_choosed_name"), xmlCharStrdup(resource_definition.Name.c_str()));
103 Batch::JobId job_id = job->getBatchManagerJobId();
104 xmlNewChild(run_node, NULL, xmlCharStrdup("job_reference"), xmlCharStrdup(job_id.getReference().c_str()));