-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#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"
addNode(node, "local_directory", job.getLocalDirectory());
if (!job.getResultDirectory().empty())
addNode(node, "result_directory", job.getResultDirectory());
+ if (!job.getPreCommand().empty())
+ addNode(node, "pre_command", job.getPreCommand());
// Parameters for COORM
if (!job.getLauncherFile().empty())
addNode(node, "maximum_duration", job.getMaximumDuration());
if (!job.getQueue().empty())
addNode(node, "queue", job.getQueue());
+ if (!job.getPartition().empty())
+ addNode(node, "partition", job.getPartition());
if (job.getExclusive())
addNode(node, "exclusive", job.getExclusiveStr());
if (job.getMemPerCpu() > 0)
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
{
}
else if (node_name == "env_file")
new_job->setEnvFile(getNodeContent(current_node));
+ else if (node_name == "pre_command")
+ new_job->setPreCommand(getNodeContent(current_node));
else if (node_name == "work_directory")
new_job->setWorkDirectory(getNodeContent(current_node));
else if (node_name == "local_directory")
new_job->setMaximumDuration(getNodeContent(current_node));
else if (node_name == "queue")
new_job->setQueue(getNodeContent(current_node));
+ else if (node_name == "partition")
+ new_job->setPartition(getNodeContent(current_node));
else if (node_name == "exclusive")
new_job->setExclusiveStr(getNodeContent(current_node));
else if (node_name == "mem_per_cpu")
xmlFree(xmlStrValue);
}
+Job*
+XML_Persistence::createJobFromString(const std::string& jobDump)
+{
+ xmlDocPtr doc;
+ doc = xmlReadMemory(jobDump.c_str(), (int)jobDump.length(), "noname.xml", NULL, 0); //TODO: conversion from size_t to int, possible loss of data
+ if (doc == NULL)
+ {
+ std::string error = "Error in xmlReadMemory in XML_Persistence::createJobFromString, could not parse string: " + jobDump;
+ LAUNCHER_INFOS(error);
+ throw LauncherException(error);
+ }
+
+ // Step 3: Find jobs
+ Job * result = NULL;
+ xmlNodePtr root_node = xmlDocGetRootElement(doc);
+ if (xmlStrToString(root_node->name) == "jobs")
+ {
+ xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
+ while(xmlCurrentNode != NULL && result == NULL)
+ {
+ if (xmlStrToString(xmlCurrentNode->name) == "job")
+ {
+ LAUNCHER_INFOS("A job is found");
+ result = createJobFromXmlNode(xmlCurrentNode);
+ }
+ xmlCurrentNode = xmlCurrentNode->next;
+ }
+ }
+ else
+ {
+ xmlFreeDoc(doc);
+ std::string error = "Error while parsing job dump: " + jobDump;
+ LAUNCHER_INFOS(error);
+ throw LauncherException(error);
+ }
+
+ // Clean
+ xmlFreeDoc(doc);
+ return result;
+}
+
+std::string
+XML_Persistence::dumpJob(const Job& job)
+{
+ // Initialization
+ xmlKeepBlanksDefault(0);
+ xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
+ xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
+ xmlDocSetRootElement(doc, root_node);
+ xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher job"));
+ xmlAddPrevSibling(root_node, doc_comment);
+
+ addJobToXmlDocument(root_node, job);
+
+ // Final step: write to result
+ xmlChar *xmlbuff;
+ int buffersize;
+ xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
+ std::string result;
+ if(buffersize > 0)
+ result = (const char*) xmlbuff;
+
+ // Clean
+ xmlFree(xmlbuff);
+ xmlFreeDoc(doc);
+ return result;
+}
+
}