34{
35 void KubernetesDriver ::
36 testInvariant () const
37 {
39 }
40
41
42
43 KubernetesDriver ::
44 KubernetesDriver ()
45 {
47 }
48
49
50
51 ::StatusCode KubernetesDriver ::
52 doManagerStep (Detail::ManagerData&
data)
const
53 {
55 using namespace msgEventLoop;
58 {
59 case Detail::ManagerStep::batchScriptVar:
60 {
61 data.batchSkipReleaseSetup =
true;
62 }
63 break;
64
65 case Detail::ManagerStep::submitJob:
66 case Detail::ManagerStep::doResubmit:
67 {
68 const std::string dockerImage {
69 data.options.castString(Job::optDockerImage)};
70
71 const std::string dockerOptions {
72 data.options.castString(Job::optDockerOptions)};
73 if (!dockerOptions.empty())
74 {
77 ANA_MSG_WARNING (
"instead you need to provide your own kubernetes config file");
78 }
79
81 const std::string batchSetupFile {
82 data.options.castString(Job::optBatchSetupFile,
"EventLoop/kubernetes_setup.yml")};
83
84
86 const std::string batchConfigFile {
87 data.options.castString(Job::optBatchConfigFile,
"EventLoop/kubernetes_job.yml")};
88 std::string baseConfig;
89 {
91 baseConfig = std::string (std::istreambuf_iterator<char>(
file),
92 std::istreambuf_iterator<char>() );
93 }
94 baseConfig =
RCU::substitute (baseConfig,
"%%DOCKERIMAGE%%", dockerImage);
96
97 std::ostringstream basedirName;
98 basedirName <<
data.submitDir <<
"/tmp";
100 {
101 if (gSystem->MakeDirectory (basedirName.str().c_str()) != 0)
102 RCU_THROW_MSG (
"failed to create directory " + basedirName.str());
103 }
104
105 const std::string jobFilePath {
data.submitDir +
"/job.yml"};
106 {
108 std::ofstream jobFile (jobFilePath.c_str());
109 if (!batchSetupFile.empty())
110 {
112 std::string setupConfig {std::istreambuf_iterator<char>(
file),
113 std::istreambuf_iterator<char>()};
114 setupConfig =
RCU::substitute (setupConfig,
"%%DOCKERIMAGE%%", dockerImage);
116 jobFile << setupConfig;
118 }
119
120 for (std::size_t jobIndex :
data.batchJobIndices)
121 {
123 dirName << basedirName.str() <<
"/" << jobIndex;
124 if (gSystem->MakeDirectory (
dirName.str().c_str()) != 0)
126
127 if (first)
129 else
130 jobFile << "---\n";
131
132 std::string myConfig = baseConfig;
133 myConfig =
RCU::substitute (myConfig,
"%%JOBINDEX%%", std::to_string (jobIndex));
135 command <<
data.submitDir <<
"/submit/run " << jobIndex;
137
138 jobFile << myConfig << "\n";
139 }
140 }
141
142 std::ostringstream
cmd;
143 cmd <<
"kubectl create -f " << jobFilePath;
145 data.submitted =
true;
146 }
147 break;
148
149 default:
150 break;
151 }
152 return ::StatusCode::SUCCESS;
153 }
154}
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
char data[hepevt_bytes_allocation_ATLAS]
std::string PathResolverFindDataFile(const std::string &logical_file_name)
#define RCU_THROW_MSG(message)
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
std::string substitute(const std::string &str, const std::string &pattern, const std::string &with)
effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substitu...