35 void KubernetesDriver ::
36 testInvariant ()
const
52 doManagerStep (Detail::ManagerData&
data)
const
55 using namespace msgEventLoop;
59 case Detail::ManagerStep::batchScriptVar:
61 data.batchSkipReleaseSetup =
true;
65 case Detail::ManagerStep::submitJob:
66 case Detail::ManagerStep::doResubmit:
68 const std::string dockerImage {
69 data.options.castString(Job::optDockerImage)};
71 const std::string dockerOptions {
72 data.options.castString(Job::optDockerOptions)};
73 if (!dockerOptions.empty())
77 ANA_MSG_WARNING (
"instead you need to provide your own kubernetes config file");
81 const std::string batchSetupFile {
82 data.options.castString(Job::optBatchSetupFile,
"EventLoop/kubernetes_setup.yml")};
86 const std::string batchConfigFile {
87 data.options.castString(Job::optBatchConfigFile,
"EventLoop/kubernetes_job.yml")};
88 std::string baseConfig;
91 baseConfig = std::string (std::istreambuf_iterator<char>(
file),
92 std::istreambuf_iterator<char>() );
94 baseConfig =
RCU::substitute (baseConfig,
"%%DOCKERIMAGE%%", dockerImage);
97 std::ostringstream basedirName;
98 basedirName <<
data.submitDir <<
"/tmp";
101 if (gSystem->MakeDirectory (basedirName.str().c_str()) != 0)
102 RCU_THROW_MSG (
"failed to create directory " + basedirName.str());
105 const std::string jobFilePath {
data.submitDir +
"/job.yml"};
108 std::ofstream jobFile (jobFilePath.c_str());
109 if (!batchSetupFile.empty())
112 std::string setupConfig {std::istreambuf_iterator<char>(
file),
113 std::istreambuf_iterator<char>()};
114 setupConfig =
RCU::substitute (setupConfig,
"%%DOCKERIMAGE%%", dockerImage);
116 jobFile << setupConfig;
120 for (std::size_t jobIndex :
data.batchJobIndices)
122 std::ostringstream dirName;
123 dirName << basedirName.str() <<
"/" << jobIndex;
124 if (gSystem->MakeDirectory (dirName.str().c_str()) != 0)
125 RCU_THROW_MSG (
"failed to create directory " + dirName.str());
132 std::string myConfig = baseConfig;
135 command <<
data.submitDir <<
"/submit/run " << jobIndex;
138 jobFile << myConfig <<
"\n";
142 std::ostringstream
cmd;
143 cmd <<
"kubectl create -f " << jobFilePath;
145 data.submitted =
true;
152 return ::StatusCode::SUCCESS;