33{
34 void KubernetesDriver ::
35 testInvariant () const
36 {
38 }
39
40
41
42 KubernetesDriver ::
43 KubernetesDriver ()
44 {
46 }
47
48
49
50 ::StatusCode KubernetesDriver ::
51 doManagerStep (Detail::ManagerData& data) const
52 {
54 using namespace msgEventLoop;
55 ANA_CHECK (BatchDriver::doManagerStep (data));
57 {
58 case Detail::ManagerStep::batchScriptVar:
59 {
60 data.batchSkipReleaseSetup =
true;
61 }
62 break;
63
64 case Detail::ManagerStep::submitJob:
65 case Detail::ManagerStep::doResubmit:
66 {
67 const std::string dockerImage {
68 data.options.castString(Job::optDockerImage)};
69
70 const std::string dockerOptions {
71 data.options.castString(Job::optDockerOptions)};
72 if (!dockerOptions.empty())
73 {
76 ANA_MSG_WARNING (
"instead you need to provide your own kubernetes config file");
77 }
78
80 const std::string batchSetupFile {
81 data.options.castString(Job::optBatchSetupFile,
"EventLoop/kubernetes_setup.yml")};
82
83
85 const std::string batchConfigFile {
86 data.options.castString(Job::optBatchConfigFile,
"EventLoop/kubernetes_job.yml")};
87 std::string baseConfig;
88 {
90 baseConfig = std::string (std::istreambuf_iterator<char>(
file),
91 std::istreambuf_iterator<char>() );
92 }
93 baseConfig =
RCU::substitute (baseConfig,
"%%DOCKERIMAGE%%", dockerImage);
95
96 std::ostringstream basedirName;
97 basedirName <<
data.submitDir <<
"/tmp";
99 {
100 if (gSystem->MakeDirectory (basedirName.str().c_str()) != 0)
101 {
102 ANA_MSG_ERROR (
"failed to create directory " << basedirName.str());
103 return StatusCode::FAILURE;
104 }
105 }
106
107 const std::string jobFilePath {
data.submitDir +
"/job.yml"};
108 {
110 std::ofstream jobFile (jobFilePath.c_str());
111 if (!batchSetupFile.empty())
112 {
114 std::string setupConfig {std::istreambuf_iterator<char>(
file),
115 std::istreambuf_iterator<char>()};
116 setupConfig =
RCU::substitute (setupConfig,
"%%DOCKERIMAGE%%", dockerImage);
118 jobFile << setupConfig;
120 }
121
122 for (std::size_t jobIndex :
data.batchJobIndices)
123 {
125 dirName << basedirName.str() <<
"/" << jobIndex;
126 if (gSystem->MakeDirectory (
dirName.str().c_str()) != 0)
127 {
129 return StatusCode::FAILURE;
130 }
131
132 if (first)
134 else
135 jobFile << "---\n";
136
137 std::string myConfig = baseConfig;
138 myConfig =
RCU::substitute (myConfig,
"%%JOBINDEX%%", std::to_string (jobIndex));
140 command <<
data.submitDir <<
"/submit/run " << jobIndex;
142
143 jobFile << myConfig << "\n";
144 }
145 }
146
147 std::ostringstream
cmd;
148 cmd <<
"kubectl create -f " << jobFilePath;
150 data.submitted =
true;
151 }
152 break;
153
154 default:
155 break;
156 }
157 return ::StatusCode::SUCCESS;
158 }
159}
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
std::string PathResolverFindDataFile(const std::string &logical_file_name)
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
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...