ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoop
Root
KubernetesDriver.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
//
9
// includes
10
//
11
12
#include <
EventLoop/KubernetesDriver.h
>
13
14
#include <fstream>
15
#include <sstream>
16
#include <TSystem.h>
17
#include <
AsgMessaging/StatusCode.h
>
18
#include <
EventLoop/Job.h
>
19
#include <
EventLoop/ManagerData.h
>
20
#include <
EventLoop/MessageCheck.h
>
21
#include <
PathResolver/PathResolver.h
>
22
#include <
RootCoreUtils/Assert.h
>
23
#include <
RootCoreUtils/ShellExec.h
>
24
#include <
RootCoreUtils/StringUtil.h
>
25
26
//
27
// method implementations
28
//
29
30
ClassImp
(
EL::KubernetesDriver
)
31
32
namespace
EL
33
{
34
void
KubernetesDriver ::
35
testInvariant ()
const
36
{
37
RCU_INVARIANT
(
this
!= 0);
38
}
39
40
41
42
KubernetesDriver ::
43
KubernetesDriver ()
44
{
45
RCU_NEW_INVARIANT
(
this
);
46
}
47
48
49
50
::StatusCode
KubernetesDriver ::
51
doManagerStep (Detail::ManagerData& data)
const
52
{
53
RCU_READ_INVARIANT
(
this
);
54
using namespace
msgEventLoop;
55
ANA_CHECK
(
BatchDriver::doManagerStep
(data));
56
switch
(data.step)
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
{
74
ANA_MSG_WARNING
(
"you specified docker options for kubernetes driver"
);
75
ANA_MSG_WARNING
(
"this is not supported in this way"
);
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
{
89
std::ifstream
file
(
PathResolverFindDataFile
(batchConfigFile).c_str());
90
baseConfig = std::string (std::istreambuf_iterator<char>(
file
),
91
std::istreambuf_iterator<char>() );
92
}
93
baseConfig =
RCU::substitute
(baseConfig,
"%%DOCKERIMAGE%%"
, dockerImage);
94
baseConfig =
RCU::substitute
(baseConfig,
"%%SUBMITDIR%%"
, data.submitDir);
95
96
std::ostringstream basedirName;
97
basedirName << data.submitDir <<
"/tmp"
;
98
if
(!data.resubmit)
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
{
109
bool
first {
true
};
110
std::ofstream jobFile (jobFilePath.c_str());
111
if
(!batchSetupFile.empty())
112
{
113
std::ifstream
file
(
PathResolverFindDataFile
(batchSetupFile).c_str());
114
std::string setupConfig {std::istreambuf_iterator<char>(
file
),
115
std::istreambuf_iterator<char>()};
116
setupConfig =
RCU::substitute
(setupConfig,
"%%DOCKERIMAGE%%"
, dockerImage);
117
setupConfig =
RCU::substitute
(setupConfig,
"%%SUBMITDIR%%"
, data.submitDir);
118
jobFile << setupConfig;
119
first =
false
;
120
}
121
122
for
(std::size_t jobIndex : data.batchJobIndices)
123
{
124
std::ostringstream dirName;
125
dirName << basedirName.str() <<
"/"
<< jobIndex;
126
if
(gSystem->MakeDirectory (dirName.str().c_str()) != 0)
127
{
128
ANA_MSG_ERROR
(
"failed to create directory "
<< dirName.str());
129
return
StatusCode::FAILURE;
130
}
131
132
if
(first)
133
first =
false
;
134
else
135
jobFile <<
"---\n"
;
136
137
std::string myConfig = baseConfig;
138
myConfig =
RCU::substitute
(myConfig,
"%%JOBINDEX%%"
, std::to_string (jobIndex));
139
std::ostringstream command;
140
command << data.submitDir <<
"/submit/run "
<< jobIndex;
141
myConfig =
RCU::substitute
(myConfig,
"%%COMMAND%%"
, command.str());
142
143
jobFile << myConfig <<
"\n"
;
144
}
145
}
146
147
std::ostringstream cmd;
148
cmd <<
"kubectl create -f "
<< jobFilePath;
149
RCU::Shell::exec
(cmd.str());
150
data.submitted =
true
;
151
}
152
break
;
153
154
default
:
155
break
;
156
}
157
return ::StatusCode::SUCCESS;
158
}
159
}
Assert.h
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition
Assert.h:189
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
StatusCode.h
Job.h
ClassImp
ClassImp(EL::KubernetesDriver) namespace EL
Definition
KubernetesDriver.cxx:30
KubernetesDriver.h
ManagerData.h
PathResolver.h
PathResolverFindDataFile
std::string PathResolverFindDataFile(const std::string &logical_file_name)
Definition
PathResolver.cxx:320
MessageCheck.h
ShellExec.h
StringUtil.h
EL::BatchDriver::doManagerStep
virtual::StatusCode doManagerStep(Detail::ManagerData &data) const override
EL::Job::optDockerOptions
static const std::string optDockerOptions
any extra options we may want to pass to docker
Definition
Job.h:523
EL::Job::optBatchConfigFile
static const std::string optBatchConfigFile
the job submission configuration file (used by some drivers that need more complex configuration)
Definition
Job.h:527
EL::Job::optDockerImage
static const std::string optDockerImage
this is the name of the docker image, when using docker with a supported batch driver
Definition
Job.h:520
EL::Job::optBatchSetupFile
static const std::string optBatchSetupFile
the job submission setup file.
Definition
Job.h:532
EL::KubernetesDriver
a Driver to run on Kubernetes
Definition
KubernetesDriver.h:22
EL::Detail::ManagerStep::doResubmit
@ doResubmit
call the actual doResubmit method
Definition
ManagerStep.h:116
EL::Detail::ManagerStep::submitJob
@ submitJob
do the actual job submission
Definition
ManagerStep.h:92
EL::Detail::ManagerStep::batchScriptVar
@ batchScriptVar
create the variables needed for the batch-run script
Definition
ManagerStep.h:83
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
RCU::Shell::exec
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
Definition
ShellExec.cxx:27
RCU::substitute
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...
Definition
StringUtil.cxx:14
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0