/
SCARFTomoReconstruction.h
182 lines (148 loc) · 6.7 KB
/
SCARFTomoReconstruction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#ifndef REMOTE_SCARFTOMORECONSTRUCTION_H_
#define REMOTE_SCARFTOMORECONSTRUCTION_H_
#include "MantidAPI/Algorithm.h"
namespace Mantid {
namespace RemoteAlgorithms {
/***
Algorithm to initiate, query about, or cancel a tomographic
reconstruction job on the SCARF computer cluster at RAL.
The algorithm can be used to send different commands to the job
queue, for example: log in, log out, start a reconstruction job,
retrieve information about jobs or to cancel a job.
If the authentication is successfull, a cookie is received that is
stored internally and re-used for all subsequent interactions with
the compute resource.
Copyright © 2014-2015 ISIS Rutherford Appleton Laboratory,
NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport SCARFTomoReconstruction : public Mantid::API::Algorithm {
public:
/// Constructor
SCARFTomoReconstruction();
/// Virtual destructor
~SCARFTomoReconstruction() override {}
/// Algorithm's name
const std::string name() const override { return "SCARFTomoReconstruction"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Perform a control action on jobs running on the SCARF computer "
"cluster at RAL, STFC (http://www.scarf.rl.ac.uk/)";
}
/// Algorithm's version
int version() const override { return (1); }
/// Algorithm's category for identification
const std::string category() const override { return "Remote"; }
protected:
/// different methods (HTTP requests) to process reconstruction job commands
virtual void doLogin(const std::string &username,
const std::string &password);
virtual void doLogout(const std::string &username);
virtual bool doPing();
virtual void doSubmit(const std::string &username);
virtual void doQueryStatus(const std::string &username);
virtual void doQueryStatusById(const std::string &username,
const std::string &jobId);
virtual void doCancel(const std::string &username, const std::string &jobId);
virtual void doUploadFile(const std::string &username,
const std::string &destDir,
const std::string &filename);
virtual void doDownload(const std::string &username, const std::string &jobId,
const std::string &fname,
const std::string &localDir);
typedef std::map<std::string, std::string> StringToStringMap;
/// method that deals with the actual HTTP(S) connection (convenient to
/// mock up all inet messaging)
virtual int doSendRequestGetResponse(
const std::string &url, std::ostream &rss,
const StringToStringMap &headers = StringToStringMap(),
const std::string &method = std::string(), const std::string &body = "");
private:
void init() override;
/// Execution code
void exec() override;
// helper for the submit request
std::string buildSubmitBody(const std::string &appName,
const std::string &boundary,
const std::string &inputFile,
const std::string &inputArgs,
const std::string &jobName);
/// lower level helper to encode parameters
void encodeParam(std::string &body, const std::string &boundary,
const std::string ¶mName, const std::string ¶mVal);
/// build body as headers + file as an octet string
std::string buildUploadBody(const std::string &boundary,
const std::string &destDir,
const std::string &filename);
/// fill in output properties with job status and info
void genOutputStatusInfo(const std::string &resp,
const std::string &jobIDFilter = std::string());
/// Job sequence number (from here, nothing to do with the job id on the
/// cluster)
int jobSeqNo();
// cookie obtained after logging in
struct Token {
Token(std::string &u, std::string &t) : m_url(u), m_token_str(t){};
std::string m_url;
std::string m_token_str;
};
typedef std::pair<std::string, SCARFTomoReconstruction::Token> UsernameToken;
class Action {
public:
typedef enum {
LOGIN = 0,
LOGOUT,
SUBMIT,
QUERYSTATUS,
QUERYSTATUSBYID,
PING,
CANCEL,
UPLOAD,
DOWNLOAD,
UNDEF
} Type;
};
/// helper to filter the action given by the user
Action::Type getAction();
/// helper to fetch and save one file from the compute resource
void getOneJobFile(const std::string &jobId, const std::string &remotePath,
const std::string &localPath, const Token &t);
/// helper to fetch and save all the files for a remote job
void getAllJobFiles(const std::string &jobId, const std::string &localDir,
const Token &t);
/// check if output file is writeable, overwritten, etc.
const std::string checkDownloadOutputFile(const std::string &localPath,
const std::string &fname) const;
/// get a normal file name from a 'PAC Server*...' name
const std::string filterPACFilename(const std::string PACName) const;
/// extremely simple parser for error messages from LSF PAC
std::string extractPACErrMsg(const std::string &response) const;
// options passed to the algorithm
Action::Type m_action;
// when submitting jobs
std::string m_runnablePath;
std::string m_jobOptions;
// resource name
static const std::string m_SCARFComputeResource;
// HTTP specifics for SCARF (IBM LSF PAC)
static std::string m_acceptType;
// store for username-token pairs
static std::map<std::string, Token> m_tokenStash;
// just to generate a sequence number for jobs started using this alg.
static int m_jobSeq;
};
} // end namespace RemoteAlgorithms
} // end namespace Mantid
#endif /*REMOTE_SCARFTOMORECONSTRUCTION_H_*/