-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrontendGRpcSvc.cpp
233 lines (180 loc) · 9.57 KB
/
FrontendGRpcSvc.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* @project The CERN Tape Archive (CTA)
* @copyright Copyright(C) 2021 CERN
* @copyright Copyright(C) 2021 DESY
* @license This program 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.
*
* This program 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/>.
*/
#include "FrontendGRpcSvc.h"
#include "common/log/LogLevel.hpp"
#include <common/checksum/ChecksumBlobSerDeser.hpp>
Status CtaRpcImpl::Version(::grpc::ServerContext *context, const ::google::protobuf::Empty *request,
::cta::admin::Version *response) {
response->set_cta_version(CTA_VERSION);
response->set_xrootd_ssi_protobuf_interface_version(CTA_DCACHE_VERSION);
return Status::OK;
}
Status CtaRpcImpl::Archive(::grpc::ServerContext* context, const ::cta::dcache::rpc::ArchiveRequest* request, ::cta::dcache::rpc::ArchiveResponse* response) {
cta::log::LogContext lc(*m_log);
cta::log::ScopedParamContainer sp(lc);
lc.log(cta::log::INFO, "Archive request");
sp.add("remoteHost", context->peer());
sp.add("request", "archive");
const std::string storageClass = request->file().storageclass();
lc.log(cta::log::DEBUG, "Archive request for storageClass: " + storageClass);
cta::common::dataStructures::RequesterIdentity requester;
requester.name = request->cli().user().username();
requester.group = request->cli().user().groupname();
auto instance = request->instance().name();
sp.add("instance", instance);
sp.add("username", request->cli().user().username());
sp.add("groupname", request->cli().user().groupname());
sp.add("storageClass", storageClass);
sp.add("fileID", request->file().fid());
try {
uint64_t archiveFileId = m_scheduler->checkAndGetNextArchiveFileId(instance, storageClass, requester, lc);
sp.add("archiveID", archiveFileId);
cta::common::dataStructures::ArchiveRequest archiveRequest;
cta::checksum::ProtobufToChecksumBlob(request->file().csb(), archiveRequest.checksumBlob);
archiveRequest.diskFileInfo.owner_uid = 1;
archiveRequest.diskFileInfo.gid = 1;
archiveRequest.diskFileInfo.path = "/" + request->file().fid();
archiveRequest.diskFileID = request->file().fid();
archiveRequest.fileSize = request->file().size();
archiveRequest.requester.name = request->cli().user().username();
archiveRequest.requester.group = request->cli().user().groupname();
archiveRequest.storageClass = storageClass;
archiveRequest.srcURL = request->transport().dst_url();
archiveRequest.archiveReportURL = request->transport().report_url() + "?archiveid=" + std::to_string(archiveFileId);
archiveRequest.archiveErrorReportURL = request->transport().error_report_url();
archiveRequest.creationLog.host = context->peer();
archiveRequest.creationLog.username = instance;
archiveRequest.creationLog.time = time(nullptr);
std::string reqId = m_scheduler->queueArchiveWithGivenId(archiveFileId, instance, archiveRequest, lc);
sp.add("reqId", reqId);
lc.log(cta::log::INFO, "Archive request for storageClass: " + storageClass
+ " archiveFileId: " + std::to_string(archiveFileId)
+ " RequestID: " + reqId);
response->set_fid(archiveFileId);
response->set_reqid(reqId);
} catch (cta::exception::Exception &ex) {
lc.log(cta::log::CRIT, ex.getMessageValue());
return ::grpc::Status(::grpc::StatusCode::INTERNAL, ex.getMessageValue());
}
return Status::OK;
}
Status CtaRpcImpl::Delete(::grpc::ServerContext* context, const ::cta::dcache::rpc::DeleteRequest* request, ::google::protobuf::Empty* response) {
cta::log::LogContext lc(*m_log);
cta::log::ScopedParamContainer sp(lc);
sp.add("remoteHost", context->peer());
lc.log(cta::log::DEBUG, "Delete request");
sp.add("request", "delete");
auto instance = request->instance().name();
// Unpack message
cta::common::dataStructures::DeleteArchiveRequest deleteRequest;
deleteRequest.requester.name = request->cli().user().username();
deleteRequest.requester.group = request->cli().user().groupname();
sp.add("instance", instance);
sp.add("username", request->cli().user().username());
sp.add("groupname", request->cli().user().groupname());
sp.add("fileID", request->file().fid());
deleteRequest.diskFilePath = "/" + request->file().fid();
deleteRequest.diskFileId = request->file().fid();
deleteRequest.diskInstance = instance;
// remove pending scheduler entry, if any
deleteRequest.archiveFileID = request->archiveid();
if (!request->reqid().empty()) {
deleteRequest.address = request->reqid();
}
// Delete the file from the catalogue or from the objectstore if archive request is created
cta::utils::Timer t;
try {
deleteRequest.archiveFile = m_catalogue->getArchiveFileById(deleteRequest.archiveFileID);
} catch (cta::exception::Exception &ex){
lc.log(cta::log::WARNING, "Deleted file is not in catalog.");
}
m_scheduler->deleteArchive(instance, deleteRequest, lc);
lc.log(cta::log::INFO, "archive file deleted.");
return Status::OK;
}
Status CtaRpcImpl::Retrieve(::grpc::ServerContext* context, const ::cta::dcache::rpc::RetrieveRequest* request, ::cta::dcache::rpc::RetrieveResponse *response) {
cta::log::LogContext lc(*m_log);
cta::log::ScopedParamContainer sp(lc);
sp.add("remoteHost", context->peer());
sp.add("request", "retrieve");
const std::string storageClass = request->file().storageclass();
lc.log(cta::log::DEBUG, "Retrieve request for storageClass: " + storageClass);
auto instance = request->instance().name();
sp.add("instance", instance);
sp.add("username", request->cli().user().username());
sp.add("groupname", request->cli().user().groupname());
sp.add("storageClass", storageClass);
sp.add("archiveID", request->archiveid());
sp.add("fileID", request->file().fid());
// Unpack message
cta::common::dataStructures::RetrieveRequest retrieveRequest;
retrieveRequest.requester.name = request->cli().user().username();
retrieveRequest.requester.group = request->cli().user().groupname();
retrieveRequest.dstURL = request->transport().dst_url();
retrieveRequest.errorReportURL = request->transport().error_report_url();
retrieveRequest.diskFileInfo.owner_uid = 1;
retrieveRequest.diskFileInfo.gid = 1;
retrieveRequest.diskFileInfo.path = "/" + request->file().fid();
retrieveRequest.creationLog.host = context->peer();
retrieveRequest.creationLog.username = instance;
retrieveRequest.creationLog.time = time(nullptr);
retrieveRequest.isVerifyOnly = false;
retrieveRequest.archiveFileID = request->archiveid();
sp.add("archiveID", request->archiveid());
sp.add("fileID", request->file().fid());
cta::utils::Timer t;
// Queue the request
try {
std::string reqId = m_scheduler->queueRetrieve(instance, retrieveRequest, lc);
sp.add("reqId", reqId);
lc.log(cta::log::INFO, "Retrieve request for storageClass: " + storageClass
+ " archiveFileId: " + std::to_string(retrieveRequest.archiveFileID)
+ " RequestID: " + reqId);
response->set_reqid(reqId);
} catch (cta::exception::Exception &ex){
lc.log(cta::log::CRIT, ex.getMessageValue());
return ::grpc::Status(::grpc::StatusCode::INTERNAL, ex.getMessageValue());
}
return Status::OK;
}
Status CtaRpcImpl::CancelRetrieve(::grpc::ServerContext* context, const ::cta::dcache::rpc::CancelRetrieveRequest* request, ::google::protobuf::Empty* response) {
cta::log::LogContext lc(*m_log);
cta::log::ScopedParamContainer sp(lc);
sp.add("remoteHost", context->peer());
lc.log(cta::log::DEBUG, "CancelRetrieve request");
sp.add("request", "cancel");
auto instance = request->instance().name();
// Unpack message
cta::common::dataStructures::CancelRetrieveRequest cancelRequest;
cancelRequest.requester.name = request->cli().user().username();
cancelRequest.requester.group = request->cli().user().groupname();
cancelRequest.archiveFileID = request->fid();
cancelRequest.retrieveRequestId = request->reqid();
sp.add("instance", instance);
sp.add("username", request->cli().user().username());
sp.add("groupname", request->cli().user().groupname());
sp.add("fileID", request->fid());
sp.add("schedulerJobID", request->reqid());
m_scheduler->abortRetrieve(instance, cancelRequest, lc);
lc.log(cta::log::INFO, "retrieve request canceled.");
return Status::OK;
}
CtaRpcImpl::CtaRpcImpl(cta::log::Logger *logger, std::unique_ptr<cta::catalogue::Catalogue> &catalogue, std::unique_ptr <cta::Scheduler> &scheduler):
m_catalogue(std::move(catalogue)), m_scheduler(std::move(scheduler)) {
m_log = logger;
}