34 void KubernetesDriver ::
35 testInvariant ()
const
49 doManagerStep (Detail::ManagerData& data)
const
52 using namespace msgEventLoop;
58 data.batchSkipReleaseSetup =
true;
65 const std::string dockerImage {
68 const std::string dockerOptions {
70 if (!dockerOptions.empty())
74 ANA_MSG_WARNING (
"instead you need to provide your own kubernetes config file");
78 const std::string batchSetupFile {
83 const std::string batchConfigFile {
85 std::string baseConfig;
90 ANA_MSG_ERROR (
"failed to find batch config file " << batchConfigFile);
91 return StatusCode::FAILURE;
93 std::ifstream
file (resolved.c_str());
96 ANA_MSG_ERROR (
"failed to open batch config file " << resolved);
97 return StatusCode::FAILURE;
99 baseConfig = std::string (std::istreambuf_iterator<char>(
file),
100 std::istreambuf_iterator<char>() );
102 baseConfig =
RCU::substitute (baseConfig,
"%%DOCKERIMAGE%%", dockerImage);
103 baseConfig =
RCU::substitute (baseConfig,
"%%SUBMITDIR%%", data.submitDir);
105 std::ostringstream basedirName;
106 basedirName << data.submitDir <<
"/tmp";
109 if (gSystem->MakeDirectory (basedirName.str().c_str()) != 0)
111 ANA_MSG_ERROR (
"failed to create directory " << basedirName.str());
112 return StatusCode::FAILURE;
116 const std::string jobFilePath {data.submitDir +
"/job.yml"};
119 std::ofstream jobFile (jobFilePath.c_str());
120 if (!batchSetupFile.empty())
123 if (resolved.empty())
125 ANA_MSG_ERROR (
"failed to find batch setup file " << batchSetupFile);
126 return StatusCode::FAILURE;
128 std::ifstream
file (resolved.c_str());
131 ANA_MSG_ERROR (
"failed to open batch setup file " << resolved);
132 return StatusCode::FAILURE;
134 std::string setupConfig {std::istreambuf_iterator<char>(
file),
135 std::istreambuf_iterator<char>()};
136 setupConfig =
RCU::substitute (setupConfig,
"%%DOCKERIMAGE%%", dockerImage);
137 setupConfig =
RCU::substitute (setupConfig,
"%%SUBMITDIR%%", data.submitDir);
138 jobFile << setupConfig;
142 for (std::size_t jobIndex : data.batchJobIndices)
144 std::ostringstream dirName;
145 dirName << basedirName.str() <<
"/" << jobIndex;
148 if (gSystem->MakeDirectory (dirName.str().c_str()) != 0 && !data.resubmit)
150 ANA_MSG_ERROR (
"failed to create directory " << dirName.str());
151 return StatusCode::FAILURE;
159 std::string myConfig = baseConfig;
160 myConfig =
RCU::substitute (myConfig,
"%%JOBINDEX%%", std::to_string (jobIndex));
161 std::ostringstream command;
165 jobFile << myConfig <<
"\n";
169 std::ostringstream cmd;
170 cmd <<
"kubectl create -f " << jobFilePath;
172 data.submitted =
true;
179 return ::StatusCode::SUCCESS;
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
ClassImp(EL::KubernetesDriver) namespace EL
std::string PathResolverFindDataFile(const std::string &logical_file_name)
virtual::StatusCode doManagerStep(Detail::ManagerData &data) const override
static const std::string optDockerOptions
any extra options we may want to pass to docker
static const std::string optBatchConfigFile
the job submission configuration file (used by some drivers that need more complex configuration)
static const std::string optDockerImage
this is the name of the docker image, when using docker with a supported batch driver
static const std::string optBatchSetupFile
the job submission setup file.
a Driver to run on Kubernetes
@ doResubmit
call the actual doResubmit method
@ submitJob
do the actual job submission
@ batchScriptVar
create the variables needed for the batch-run script
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
std::string substitute(std::string_view str, std::string_view pattern, std::string_view with)
effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substitu...