1 | /******************************************************************** |
2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
3 | * All rights reserved. |
4 | * |
5 | * Author: Zhanwei Wang |
6 | ********************************************************************/ |
7 | /******************************************************************** |
8 | * 2014 - |
9 | * open source under Apache License Version 2.0 |
10 | ********************************************************************/ |
11 | /** |
12 | * Licensed to the Apache Software Foundation (ASF) under one |
13 | * or more contributor license agreements. See the NOTICE file |
14 | * distributed with this work for additional information |
15 | * regarding copyright ownership. The ASF licenses this file |
16 | * to you under the Apache License, Version 2.0 (the |
17 | * "License"); you may not use this file except in compliance |
18 | * with the License. You may obtain a copy of the License at |
19 | * |
20 | * http://www.apache.org/licenses/LICENSE-2.0 |
21 | * |
22 | * Unless required by applicable law or agreed to in writing, software |
23 | * distributed under the License is distributed on an "AS IS" BASIS, |
24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
25 | * See the License for the specific language governing permissions and |
26 | * limitations under the License. |
27 | */ |
28 | #include "ClientNamenodeProtocol.pb.h" |
29 | #include "Exception.h" |
30 | #include "ExceptionInternal.h" |
31 | #include "Namenode.h" |
32 | #include "NamenodeImpl.h" |
33 | #include "rpc/RpcCall.h" |
34 | #include "rpc/RpcClient.h" |
35 | #include "RpcHelper.h" |
36 | |
37 | #define NAMENODE_VERSION 1 |
38 | #define NAMENODE_PROTOCOL "org.apache.hadoop.hdfs.protocol.ClientProtocol" |
39 | #define DELEGATION_TOKEN_KIND "HDFS_DELEGATION_TOKEN" |
40 | |
41 | using namespace google::protobuf; |
42 | |
43 | namespace Hdfs { |
44 | namespace Internal { |
45 | |
46 | NamenodeImpl::NamenodeImpl(const char * host, const char * port, const std::string & tokenService, |
47 | const SessionConfig & c, const RpcAuth & a) : |
48 | auth(a), client(RpcClient::getClient()), conf(c), protocol( |
49 | NAMENODE_VERSION, NAMENODE_PROTOCOL, DELEGATION_TOKEN_KIND), server(tokenService, host, port) { |
50 | } |
51 | |
52 | NamenodeImpl::~NamenodeImpl() { |
53 | } |
54 | |
55 | void NamenodeImpl::invoke(const RpcCall & call) { |
56 | RpcChannel & channel = client.getChannel(auth, protocol, server, conf); |
57 | |
58 | try { |
59 | channel.invoke(call); |
60 | } catch (...) { |
61 | channel.close(false); |
62 | throw; |
63 | } |
64 | |
65 | channel.close(false); |
66 | } |
67 | |
68 | //Idempotent |
69 | void NamenodeImpl::getBlockLocations(const std::string & src, int64_t offset, |
70 | int64_t length, LocatedBlocks & lbs) /* throw (AccessControlException, |
71 | FileNotFoundException, UnresolvedLinkException, HdfsIOException) */{ |
72 | try { |
73 | GetBlockLocationsRequestProto request; |
74 | GetBlockLocationsResponseProto response; |
75 | request.set_length(length); |
76 | request.set_offset(offset); |
77 | request.set_src(src); |
78 | invoke(RpcCall(true, "getBlockLocations" , &request, &response)); |
79 | Convert(lbs, response.locations()); |
80 | } catch (const HdfsRpcServerException & e) { |
81 | UnWrapper < FileNotFoundException, |
82 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
83 | unwrapper.unwrap(__FILE__, __LINE__); |
84 | } |
85 | } |
86 | |
87 | void NamenodeImpl::create(const std::string & src, const Permission & masked, |
88 | const std::string & clientName, int flag, bool createParent, |
89 | short replication, int64_t blockSize) /* throw (AccessControlException, |
90 | AlreadyBeingCreatedException, DSQuotaExceededException, |
91 | FileAlreadyExistsException, FileNotFoundException, |
92 | NSQuotaExceededException, ParentNotDirectoryException, |
93 | UnresolvedLinkException, HdfsIOException) */{ |
94 | try { |
95 | CreateRequestProto request; |
96 | CreateResponseProto response; |
97 | request.set_blocksize(blockSize); |
98 | request.set_clientname(clientName); |
99 | request.set_createflag(flag); |
100 | request.set_createparent(createParent); |
101 | request.set_replication(replication); |
102 | request.set_src(src); |
103 | Build(masked, request.mutable_masked()); |
104 | invoke(RpcCall(false, "create" , &request, &response)); |
105 | } catch (const HdfsRpcServerException & e) { |
106 | UnWrapper < AlreadyBeingCreatedException, |
107 | DSQuotaExceededException, FileAlreadyExistsException, |
108 | FileNotFoundException, NSQuotaExceededException, |
109 | ParentNotDirectoryException, |
110 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
111 | unwrapper.unwrap(__FILE__, __LINE__); |
112 | } |
113 | } |
114 | |
115 | std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > |
116 | NamenodeImpl::append(const std::string& src, const std::string& clientName) |
117 | /* throw (AlreadyBeingCreatedException, DSQuotaExceededException, |
118 | FileNotFoundException, |
119 | UnresolvedLinkException, HdfsIOException) */ { |
120 | try { |
121 | std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > retval; |
122 | AppendRequestProto request; |
123 | AppendResponseProto response; |
124 | request.set_clientname(clientName); |
125 | request.set_src(src); |
126 | invoke(RpcCall(false, "append" , &request, &response)); |
127 | |
128 | if (response.has_block()) { |
129 | retval.first = Convert(response.block()); |
130 | } |
131 | |
132 | if (response.has_stat()) { |
133 | retval.second = shared_ptr<FileStatus>(new FileStatus); |
134 | Convert(src, *retval.second, response.stat()); |
135 | } |
136 | return retval; |
137 | } catch (const HdfsRpcServerException & e) { |
138 | UnWrapper < AlreadyBeingCreatedException, AccessControlException, |
139 | DSQuotaExceededException, FileNotFoundException, |
140 | UnresolvedLinkException, RecoveryInProgressException, |
141 | HdfsIOException > unwrapper( |
142 | e); |
143 | unwrapper.unwrap(__FILE__, __LINE__); |
144 | } |
145 | } |
146 | |
147 | //Idempotent |
148 | bool NamenodeImpl::setReplication(const std::string & src, short replication) |
149 | /* throw (DSQuotaExceededException, |
150 | FileNotFoundException, UnresolvedLinkException, |
151 | HdfsIOException) */{ |
152 | try { |
153 | SetReplicationRequestProto request; |
154 | SetReplicationResponseProto response; |
155 | request.set_src(src.c_str()); |
156 | request.set_replication(static_cast<uint32>(replication)); |
157 | invoke(RpcCall(true, "setReplication" , &request, &response)); |
158 | return response.result(); |
159 | } catch (const HdfsRpcServerException & e) { |
160 | UnWrapper < DSQuotaExceededException, |
161 | FileNotFoundException, |
162 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
163 | unwrapper.unwrap(__FILE__, __LINE__); |
164 | } |
165 | } |
166 | |
167 | //Idempotent |
168 | void NamenodeImpl::setPermission(const std::string & src, |
169 | const Permission & permission) /* throw (AccessControlException, |
170 | FileNotFoundException, |
171 | UnresolvedLinkException, HdfsIOException) */{ |
172 | try { |
173 | SetPermissionRequestProto request; |
174 | SetPermissionResponseProto response; |
175 | request.set_src(src); |
176 | Build(permission, request.mutable_permission()); |
177 | invoke(RpcCall(true, "setPermission" , &request, &response)); |
178 | } catch (const HdfsRpcServerException & e) { |
179 | UnWrapper < FileNotFoundException, |
180 | UnresolvedLinkException, HdfsIOException > unwrapper( |
181 | e); |
182 | unwrapper.unwrap(__FILE__, __LINE__); |
183 | } |
184 | } |
185 | |
186 | //Idempotent |
187 | void NamenodeImpl::setOwner(const std::string & src, |
188 | const std::string & username, const std::string & groupname) |
189 | /* throw (FileNotFoundException, |
190 | UnresolvedLinkException, HdfsIOException) */{ |
191 | try { |
192 | SetOwnerRequestProto request; |
193 | SetOwnerResponseProto response; |
194 | request.set_src(src); |
195 | |
196 | if (!username.empty()) { |
197 | request.set_username(username); |
198 | } |
199 | |
200 | if (!groupname.empty()) { |
201 | request.set_groupname(groupname); |
202 | } |
203 | |
204 | invoke(RpcCall(true, "setOwner" , &request, &response)); |
205 | } catch (const HdfsRpcServerException & e) { |
206 | UnWrapper < FileNotFoundException, |
207 | UnresolvedLinkException, HdfsIOException > unwrapper( |
208 | e); |
209 | unwrapper.unwrap(__FILE__, __LINE__); |
210 | } |
211 | } |
212 | |
213 | void NamenodeImpl::abandonBlock(const ExtendedBlock & b, |
214 | const std::string & src, const std::string & holder) |
215 | /* throw (FileNotFoundException, |
216 | UnresolvedLinkException, HdfsIOException) */{ |
217 | try { |
218 | AbandonBlockRequestProto request; |
219 | AbandonBlockResponseProto response; |
220 | request.set_holder(holder); |
221 | request.set_src(src); |
222 | Build(b, request.mutable_b()); |
223 | invoke(RpcCall(false, "abandonBlock" , &request, &response)); |
224 | } catch (const HdfsRpcServerException & e) { |
225 | UnWrapper < FileNotFoundException, |
226 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
227 | unwrapper.unwrap(__FILE__, __LINE__); |
228 | } |
229 | } |
230 | |
231 | shared_ptr<LocatedBlock> NamenodeImpl::addBlock(const std::string & src, |
232 | const std::string & clientName, const ExtendedBlock * previous, |
233 | const std::vector<DatanodeInfo> & excludeNodes) |
234 | /* throw (FileNotFoundException, |
235 | NotReplicatedYetException, |
236 | UnresolvedLinkException, HdfsIOException) */{ |
237 | try { |
238 | AddBlockRequestProto request; |
239 | AddBlockResponseProto response; |
240 | request.set_clientname(clientName); |
241 | request.set_src(src); |
242 | |
243 | if (previous) { |
244 | Build(*previous, request.mutable_previous()); |
245 | } |
246 | |
247 | if (excludeNodes.size()) { |
248 | Build(excludeNodes, request.mutable_excludenodes()); |
249 | } |
250 | |
251 | invoke(RpcCall(true, "addBlock" , &request, &response)); |
252 | return Convert(response.block()); |
253 | } catch (const HdfsRpcServerException & e) { |
254 | UnWrapper < FileNotFoundException, |
255 | NotReplicatedYetException, |
256 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
257 | unwrapper.unwrap(__FILE__, __LINE__); |
258 | } |
259 | } |
260 | |
261 | //Idempotent |
262 | shared_ptr<LocatedBlock> NamenodeImpl::getAdditionalDatanode( |
263 | const std::string & src, const ExtendedBlock & blk, |
264 | const std::vector<DatanodeInfo> & existings, |
265 | const std::vector<std::string> & storageIDs, |
266 | const std::vector<DatanodeInfo> & excludes, int numAdditionalNodes, |
267 | const std::string & clientName) |
268 | /* throw ( FileNotFoundException, |
269 | UnresolvedLinkException, HdfsIOException) */{ |
270 | try { |
271 | GetAdditionalDatanodeRequestProto request; |
272 | GetAdditionalDatanodeResponseProto response; |
273 | request.set_src(src); |
274 | Build(existings, request.mutable_existings()); |
275 | Build(storageIDs, request.mutable_existingstorageuuids()); |
276 | Build(excludes, request.mutable_excludes()); |
277 | Build(blk, request.mutable_blk()); |
278 | request.set_clientname(clientName); |
279 | request.set_numadditionalnodes(numAdditionalNodes); |
280 | invoke(RpcCall(true, "getAdditionalDatanode" , &request, &response)); |
281 | return Convert(response.block()); |
282 | } catch (const HdfsRpcServerException & e) { |
283 | UnWrapper < |
284 | FileNotFoundException, |
285 | NotReplicatedYetException, |
286 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
287 | unwrapper.unwrap(__FILE__, __LINE__); |
288 | } |
289 | } |
290 | |
291 | bool NamenodeImpl::complete(const std::string & src, |
292 | const std::string & clientName, const ExtendedBlock * last) |
293 | /* throw (FileNotFoundException, |
294 | UnresolvedLinkException, HdfsIOException) */{ |
295 | try { |
296 | CompleteRequestProto request; |
297 | CompleteResponseProto response; |
298 | request.set_clientname(clientName); |
299 | request.set_src(src); |
300 | |
301 | if (last) { |
302 | Build(*last, request.mutable_last()); |
303 | } |
304 | |
305 | invoke(RpcCall(false, "complete" , &request, &response)); |
306 | return response.result(); |
307 | } catch (const HdfsRpcServerException & e) { |
308 | UnWrapper < FileNotFoundException, |
309 | UnresolvedLinkException, HdfsIOException > unwrapper( |
310 | e); |
311 | unwrapper.unwrap(__FILE__, __LINE__); |
312 | } |
313 | } |
314 | |
315 | //Idempotent |
316 | /*void NamenodeImpl::reportBadBlocks(const std::vector<LocatedBlock> & blocks) |
317 | throw (HdfsIOException) { |
318 | try { |
319 | ReportBadBlocksRequestProto request; |
320 | ReportBadBlocksResponseProto response; |
321 | Build(blocks, request.mutable_blocks()); |
322 | invoke(RpcCall(true, "reportBadBlocks", &request, &response)); |
323 | } catch (const HdfsRpcServerException & e) { |
324 | UnWrapper<HdfsIOException> unwrapper(e); |
325 | unwrapper.unwrap(__FILE__, __LINE__); |
326 | } |
327 | }*/ |
328 | |
329 | bool NamenodeImpl::rename(const std::string & src, const std::string & dst) |
330 | /* throw (UnresolvedLinkException, HdfsIOException) */{ |
331 | try { |
332 | RenameRequestProto request; |
333 | RenameResponseProto response; |
334 | request.set_src(src); |
335 | request.set_dst(dst); |
336 | invoke(RpcCall(false, "rename" , &request, &response)); |
337 | return response.result(); |
338 | } catch (const HdfsRpcServerException & e) { |
339 | UnWrapper<UnresolvedLinkException, HdfsIOException> unwrapper(e); |
340 | unwrapper.unwrap(__FILE__, __LINE__); |
341 | } |
342 | } |
343 | |
344 | /*void NamenodeImpl::concat(const std::string & trg, |
345 | const std::vector<std::string> & srcs) throw (UnresolvedLinkException, |
346 | HdfsIOException) { |
347 | try { |
348 | ConcatRequestProto request; |
349 | ConcatResponseProto response; |
350 | request.set_trg(trg); |
351 | Build(srcs, request.mutable_srcs()); |
352 | invoke(RpcCall(false, "concat", &request, &response)); |
353 | } catch (const HdfsRpcServerException & e) { |
354 | UnWrapper<UnresolvedLinkException, HdfsIOException> unwrapper(e); |
355 | unwrapper.unwrap(__FILE__, __LINE__); |
356 | } |
357 | }*/ |
358 | |
359 | bool NamenodeImpl::truncate(const std::string & src, int64_t size, |
360 | const std::string & clientName) |
361 | /* throw (HdfsIOException, UnresolvedLinkException) */{ |
362 | try { |
363 | TruncateRequestProto request; |
364 | TruncateResponseProto response; |
365 | request.set_src(src); |
366 | request.set_newlength(size); |
367 | request.set_clientname(clientName); |
368 | invoke(RpcCall(false, "truncate" , &request, &response)); |
369 | return response.result(); |
370 | } catch (const HdfsRpcServerException& e) { |
371 | UnWrapper<AlreadyBeingCreatedException, AccessControlException, |
372 | UnresolvedLinkException, FileNotFoundException, |
373 | RecoveryInProgressException, HadoopIllegalArgumentException, |
374 | HdfsIOException> unwrapper(e); |
375 | unwrapper.unwrap(__FILE__, __LINE__); |
376 | } |
377 | } |
378 | |
379 | void NamenodeImpl::getLease(const std::string & src, |
380 | const std::string & clientName) /* throw (HdfsIOException, |
381 | UnresolvedLinkException) */{ |
382 | try { |
383 | GetLeaseRequestProto request; |
384 | GetLeaseResponseProto response; |
385 | request.set_src(src); |
386 | request.set_clientname(clientName); |
387 | invoke(RpcCall(false, "getLease" , &request, &response)); |
388 | } catch (const HdfsRpcServerException & e) { |
389 | UnWrapper<InvalidParameter, AlreadyBeingCreatedException, FileNotFoundException, UnresolvedLinkException, HdfsIOException> unwrapper(e); |
390 | unwrapper.unwrap(__FILE__, __LINE__); |
391 | } |
392 | } |
393 | |
394 | void NamenodeImpl::releaseLease(const std::string & src, |
395 | const std::string & clientName) /* throw (HdfsIOException, |
396 | UnresolvedLinkException) */{ |
397 | try { |
398 | ReleaseLeaseRequestProto request; |
399 | ReleaseLeaseResponseProto response; |
400 | request.set_src(src); |
401 | request.set_clientname(clientName); |
402 | invoke(RpcCall(false, "releaseLease" , &request, &response)); |
403 | } catch (const HdfsRpcServerException & e) { |
404 | UnWrapper<FileNotFoundException, UnresolvedLinkException, HdfsIOException> unwrapper(e); |
405 | unwrapper.unwrap(__FILE__, __LINE__); |
406 | } |
407 | } |
408 | |
409 | bool NamenodeImpl::deleteFile(const std::string & src, bool recursive) |
410 | /* throw (FileNotFoundException, |
411 | UnresolvedLinkException, HdfsIOException) */{ |
412 | try { |
413 | DeleteRequestProto request; |
414 | DeleteResponseProto response; |
415 | request.set_src(src); |
416 | request.set_recursive(recursive); |
417 | invoke(RpcCall(false, "delete" , &request, &response)); |
418 | return response.result(); |
419 | } catch (const HdfsRpcServerException & e) { |
420 | UnWrapper < FileNotFoundException, |
421 | UnresolvedLinkException, HdfsIOException > unwrapper( |
422 | e); |
423 | unwrapper.unwrap(__FILE__, __LINE__); |
424 | } |
425 | } |
426 | |
427 | //Idempotent |
428 | bool NamenodeImpl::mkdirs(const std::string & src, const Permission & masked, |
429 | bool createParent) /* throw (AccessControlException, |
430 | FileAlreadyExistsException, FileNotFoundException, |
431 | NSQuotaExceededException, ParentNotDirectoryException, |
432 | UnresolvedLinkException, HdfsIOException) */{ |
433 | try { |
434 | MkdirsRequestProto request; |
435 | MkdirsResponseProto response; |
436 | request.set_src(src); |
437 | request.set_createparent(createParent); |
438 | Build(masked, request.mutable_masked()); |
439 | invoke(RpcCall(true, "mkdirs" , &request, &response)); |
440 | return response.result(); |
441 | } catch (const HdfsRpcServerException & e) { |
442 | UnWrapper < FileAlreadyExistsException, |
443 | FileNotFoundException, NSQuotaExceededException, |
444 | ParentNotDirectoryException, |
445 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
446 | unwrapper.unwrap(__FILE__, __LINE__); |
447 | } |
448 | } |
449 | |
450 | //Idempotent |
451 | bool NamenodeImpl::getListing(const std::string & src, |
452 | const std::string & startAfter, bool needLocation, |
453 | std::vector<FileStatus> & dl) /* throw (AccessControlException, |
454 | FileNotFoundException, UnresolvedLinkException, HdfsIOException) */{ |
455 | try { |
456 | GetListingRequestProto request; |
457 | GetListingResponseProto response; |
458 | request.set_src(src); |
459 | size_t pos = startAfter.find_last_of("/" ); |
460 | |
461 | if (pos != startAfter.npos && pos != startAfter.length() - 1) { |
462 | request.set_startafter(startAfter.c_str() + pos + 1); |
463 | } else { |
464 | request.set_startafter(startAfter); |
465 | } |
466 | |
467 | request.set_needlocation(needLocation); |
468 | invoke(RpcCall(true, "getListing" , &request, &response)); |
469 | |
470 | if (response.has_dirlist()) { |
471 | const DirectoryListingProto & lists = response.dirlist(); |
472 | Convert(src, dl, lists); |
473 | return lists.remainingentries() > 0; |
474 | } |
475 | |
476 | THROW(FileNotFoundException, "%s not found." , src.c_str()); |
477 | } catch (const HdfsRpcServerException & e) { |
478 | UnWrapper < FileNotFoundException, |
479 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
480 | unwrapper.unwrap(__FILE__, __LINE__); |
481 | } |
482 | } |
483 | |
484 | //Idempotent |
485 | void NamenodeImpl::renewLease(const std::string & clientName) |
486 | /* throw (HdfsIOException) */{ |
487 | try { |
488 | RenewLeaseRequestProto request; |
489 | RenewLeaseResponseProto response; |
490 | request.set_clientname(clientName); |
491 | invoke(RpcCall(true, "renewLease" , &request, &response)); |
492 | } catch (const HdfsRpcServerException & e) { |
493 | UnWrapper<HdfsIOException> unwrapper(e); |
494 | unwrapper.unwrap(__FILE__, __LINE__); |
495 | } |
496 | } |
497 | |
498 | //Idempotent |
499 | /*bool NamenodeImpl::recoverLease(const std::string & src, |
500 | const std::string & clientName) { throw (HdfsIOException) |
501 | try { |
502 | RecoverLeaseRequestProto request; |
503 | RecoverLeaseResponseProto response; |
504 | request.set_src(src); |
505 | request.set_clientname(clientName); |
506 | invoke(RpcCall(true, "recoverLease", &request, &response)); |
507 | return response.result(); |
508 | } catch (const HdfsRpcServerException & e) { |
509 | UnWrapper<HdfsIOException> unwrapper(e); |
510 | unwrapper.unwrap(__FILE__, __LINE__); |
511 | } |
512 | |
513 | return false; |
514 | }*/ |
515 | |
516 | //Idempotent |
517 | std::vector<int64_t> NamenodeImpl::getFsStats() { /* throw (HdfsIOException) */ |
518 | try { |
519 | GetFsStatusRequestProto request; |
520 | GetFsStatsResponseProto response; |
521 | invoke(RpcCall(true, "getFsStats" , &request, &response)); |
522 | std::vector<int64_t> retval; |
523 | retval.push_back(response.capacity()); |
524 | retval.push_back(response.used()); |
525 | retval.push_back(response.remaining()); |
526 | retval.push_back(response.under_replicated()); |
527 | retval.push_back(response.corrupt_blocks()); |
528 | retval.push_back(response.missing_blocks()); |
529 | return retval; |
530 | } catch (const HdfsRpcServerException & e) { |
531 | UnWrapper < FileNotFoundException, |
532 | UnresolvedLinkException, HdfsIOException > unwrapper( |
533 | e); |
534 | unwrapper.unwrap(__FILE__, __LINE__); |
535 | } |
536 | |
537 | return std::vector<int64_t>(); |
538 | } |
539 | |
540 | /*void NamenodeImpl::metaSave(const std::string & filename) |
541 | throw (HdfsIOException) { |
542 | try { |
543 | MetaSaveRequestProto request; |
544 | MetaSaveResponseProto response; |
545 | request.set_filename(filename); |
546 | invoke(RpcCall(true, "metaSave", &request, &response)); |
547 | } catch (const HdfsRpcServerException & e) { |
548 | UnWrapper < FileNotFoundException, |
549 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
550 | unwrapper.unwrap(__FILE__, __LINE__); |
551 | } |
552 | }*/ |
553 | |
554 | //Idempotent |
555 | FileStatus NamenodeImpl::getFileInfo(const std::string & src) |
556 | /* throw (FileNotFoundException, |
557 | UnresolvedLinkException, HdfsIOException) */{ |
558 | FileStatus retval; |
559 | |
560 | try { |
561 | GetFileInfoRequestProto request; |
562 | GetFileInfoResponseProto response; |
563 | request.set_src(src); |
564 | invoke(RpcCall(true, "getFileInfo" , &request, &response)); |
565 | |
566 | if (response.has_fs()) { |
567 | Convert(src, retval, response.fs()); |
568 | retval.setPath(src.c_str()); |
569 | return retval; |
570 | } |
571 | |
572 | THROW(FileNotFoundException, "Path %s does not exist." , src.c_str()); |
573 | } catch (const HdfsRpcServerException & e) { |
574 | UnWrapper < FileNotFoundException, |
575 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
576 | unwrapper.unwrap(__FILE__, __LINE__); |
577 | } |
578 | } |
579 | |
580 | //Idempotent |
581 | /*FileStatus NamenodeImpl::getFileLinkInfo(const std::string & src) |
582 | throw (UnresolvedLinkException, HdfsIOException) { |
583 | FileStatus fileStatus; |
584 | |
585 | try { |
586 | GetFileLinkInfoRequestProto request; |
587 | GetFileLinkInfoResponseProto response; |
588 | request.set_src(src); |
589 | invoke(RpcCall(true, "getFileLinkInfo", &request, &response)); |
590 | |
591 | if (response.has_fs()) { |
592 | Convert(fileStatus, response.fs()); |
593 | return fileStatus; |
594 | } |
595 | |
596 | THROW(FileNotFoundException, "Path %s does not exist.", src.c_str()); |
597 | } catch (const HdfsRpcServerException & e) { |
598 | UnWrapper < UnresolvedLinkException, |
599 | HdfsIOException > unwrapper(e); |
600 | unwrapper.unwrap(__FILE__, __LINE__); |
601 | } |
602 | }*/ |
603 | |
604 | //Idempotent |
605 | /*ContentSummary NamenodeImpl::getContentSummary(const std::string & path) |
606 | throw (FileNotFoundException, |
607 | UnresolvedLinkException, HdfsIOException) { |
608 | ContentSummary contentSummary; |
609 | |
610 | try { |
611 | GetContentSummaryRequestProto request; |
612 | GetContentSummaryResponseProto response; |
613 | request.set_path(path); |
614 | invoke(RpcCall(true, "getContentSummary", &request, &response)); |
615 | |
616 | if (response.has_summary()) { |
617 | Convert(contentSummary, response.summary()); |
618 | return contentSummary; |
619 | } |
620 | |
621 | THROW(FileNotFoundException, "Path %s does not exist.", path.c_str()); |
622 | } catch (const HdfsRpcServerException & e) { |
623 | UnWrapper < FileNotFoundException, |
624 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
625 | unwrapper.unwrap(__FILE__, __LINE__); |
626 | } |
627 | }*/ |
628 | |
629 | //Idempotent |
630 | /*void NamenodeImpl::setQuota(const std::string & path, int64_t namespaceQuota, |
631 | int64_t diskspaceQuota) throw (AccessControlException, |
632 | FileNotFoundException, UnresolvedLinkException, HdfsIOException) { |
633 | try { |
634 | SetQuotaRequestProto request; |
635 | SetQuotaResponseProto response; |
636 | request.set_path(path); |
637 | request.set_namespacequota(namespaceQuota); |
638 | request.set_diskspacequota(diskspaceQuota); |
639 | invoke(RpcCall(true, "diskspaceQuota", &request, &response)); |
640 | } catch (const HdfsRpcServerException & e) { |
641 | UnWrapper<HdfsIOException> unwrapper(e); |
642 | unwrapper.unwrap(__FILE__, __LINE__); |
643 | } |
644 | }*/ |
645 | |
646 | //Idempotent |
647 | void NamenodeImpl::fsync(const std::string & src, const std::string & client) |
648 | /* throw (FileNotFoundException, |
649 | UnresolvedLinkException, HdfsIOException) */{ |
650 | try { |
651 | FsyncRequestProto request; |
652 | FsyncResponseProto response; |
653 | request.set_client(client); |
654 | request.set_src(src); |
655 | invoke(RpcCall(true, "fsync" , &request, &response)); |
656 | } catch (const HdfsRpcServerException & e) { |
657 | UnWrapper < FileNotFoundException, |
658 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
659 | unwrapper.unwrap(__FILE__, __LINE__); |
660 | } |
661 | } |
662 | |
663 | //Idempotent |
664 | void NamenodeImpl::setTimes(const std::string & src, int64_t mtime, |
665 | int64_t atime) /* throw (FileNotFoundException, |
666 | UnresolvedLinkException, HdfsIOException) */{ |
667 | try { |
668 | SetTimesRequestProto request; |
669 | SetTimesResponseProto response; |
670 | request.set_src(src); |
671 | request.set_mtime(mtime); |
672 | request.set_atime(atime); |
673 | invoke(RpcCall(true, "setTimes" , &request, &response)); |
674 | } catch (const HdfsRpcServerException & e) { |
675 | UnWrapper < FileNotFoundException, |
676 | UnresolvedLinkException, HdfsIOException > unwrapper(e); |
677 | unwrapper.unwrap(__FILE__, __LINE__); |
678 | } |
679 | } |
680 | |
681 | /*void NamenodeImpl::createSymlink(const std::string & target, |
682 | const std::string & link, const Permission & dirPerm, bool createParent) throw (AccessControlException, |
683 | FileAlreadyExistsException, FileNotFoundException, |
684 | ParentNotDirectoryException, |
685 | UnresolvedLinkException, HdfsIOException) { |
686 | try { |
687 | CreateSymlinkRequestProto request; |
688 | CreateSymlinkResponseProto response; |
689 | request.set_target(target); |
690 | request.set_link(link); |
691 | request.set_createparent(createParent); |
692 | Build(dirPerm, request.mutable_dirperm()); |
693 | invoke(RpcCall(true, "createSymlink", &request, &response)); |
694 | } catch (const HdfsRpcServerException & e) { |
695 | UnWrapper<FileNotFoundException, HdfsIOException> unwrapper(e); |
696 | unwrapper.unwrap(__FILE__, __LINE__); |
697 | } |
698 | }*/ |
699 | |
700 | //Idempotent |
701 | /*std::string NamenodeImpl::getLinkTarget(const std::string & path) |
702 | throw (FileNotFoundException, HdfsIOException) { |
703 | try { |
704 | GetLinkTargetRequestProto request; |
705 | GetLinkTargetResponseProto response; |
706 | request.set_path(path); |
707 | invoke(RpcCall(true, "getLinkTarget", &request, &response)); |
708 | return response.targetpath(); |
709 | } catch (const HdfsRpcServerException & e) { |
710 | UnWrapper<FileNotFoundException, HdfsIOException> unwrapper( |
711 | e); |
712 | unwrapper.unwrap(__FILE__, __LINE__); |
713 | } |
714 | }*/ |
715 | |
716 | //Idempotent |
717 | shared_ptr<LocatedBlock> NamenodeImpl::updateBlockForPipeline(const ExtendedBlock & block, |
718 | const std::string & clientName) |
719 | /* throw (HdfsIOException) */{ |
720 | try { |
721 | UpdateBlockForPipelineRequestProto request; |
722 | UpdateBlockForPipelineResponseProto response; |
723 | request.set_clientname(clientName); |
724 | Build(block, request.mutable_block()); |
725 | invoke(RpcCall(true, "updateBlockForPipeline" , &request, &response)); |
726 | return Convert(response.block()); |
727 | } catch (const HdfsRpcServerException & e) { |
728 | UnWrapper<HdfsIOException> unwrapper(e); |
729 | unwrapper.unwrap(__FILE__, __LINE__); |
730 | } |
731 | } |
732 | |
733 | void NamenodeImpl::updatePipeline(const std::string & clientName, |
734 | const ExtendedBlock & oldBlock, const ExtendedBlock & newBlock, |
735 | const std::vector<DatanodeInfo> & newNodes, |
736 | const std::vector<std::string> & storageIDs) { /* throw (HdfsIOException) */ |
737 | try { |
738 | UpdatePipelineRequestProto request; |
739 | UpdatePipelineResponseProto response; |
740 | request.set_clientname(clientName); |
741 | Build(oldBlock, request.mutable_oldblock()); |
742 | Build(newBlock, request.mutable_newblock()); |
743 | Build(newNodes, request.mutable_newnodes()); |
744 | Build(storageIDs, request.mutable_storageids()); |
745 | invoke(RpcCall(false, "updatePipeline" , &request, &response)); |
746 | } catch (const HdfsRpcServerException & e) { |
747 | UnWrapper<HdfsIOException> unwrapper(e); |
748 | unwrapper.unwrap(__FILE__, __LINE__); |
749 | } |
750 | } |
751 | |
752 | Token NamenodeImpl::getDelegationToken(const std::string & renewer) { |
753 | try { |
754 | GetDelegationTokenRequestProto request; |
755 | GetDelegationTokenResponseProto response; |
756 | request.set_renewer(renewer); |
757 | invoke(RpcCall(true, "getDelegationToken" , &request, &response)); |
758 | return Convert(response.token()); |
759 | } catch (const HdfsRpcServerException & e) { |
760 | UnWrapper<HdfsIOException> unwrapper(e); |
761 | unwrapper.unwrap(__FILE__, __LINE__); |
762 | } |
763 | } |
764 | |
765 | int64_t NamenodeImpl::renewDelegationToken(const Token & token) { |
766 | try { |
767 | RenewDelegationTokenRequestProto request; |
768 | RenewDelegationTokenResponseProto response; |
769 | Build(token, request.mutable_token()); |
770 | invoke(RpcCall(true, "renewDelegationToken" , &request, &response)); |
771 | return response.newexpirytime(); |
772 | } catch (const HdfsRpcServerException & e) { |
773 | UnWrapper<HdfsInvalidBlockToken, HdfsIOException> unwrapper(e); |
774 | unwrapper.unwrap(__FILE__, __LINE__); |
775 | } |
776 | } |
777 | |
778 | void NamenodeImpl::cancelDelegationToken(const Token & token) { |
779 | try { |
780 | CancelDelegationTokenRequestProto request; |
781 | CancelDelegationTokenResponseProto response; |
782 | Build(token, request.mutable_token()); |
783 | invoke(RpcCall(true, "cancelDelegationToken" , &request, &response)); |
784 | } catch (const HdfsRpcServerException & e) { |
785 | UnWrapper<HdfsInvalidBlockToken, HdfsIOException> unwrapper(e); |
786 | unwrapper.unwrap(__FILE__, __LINE__); |
787 | } |
788 | } |
789 | |
790 | } |
791 | } |
792 | |