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#ifndef _HDFS_LIBHDFS3_COMMON_EXCEPTION_H_
29#define _HDFS_LIBHDFS3_COMMON_EXCEPTION_H_
30
31#include <stdexcept>
32#include <string>
33
34namespace Hdfs {
35
36class HdfsException: public std::runtime_error {
37public:
38 HdfsException(const std::string & arg, const char * file, int line,
39 const char * stack);
40
41 ~HdfsException() throw () {
42 }
43
44 virtual const char * msg() const {
45 return detail.c_str();
46 }
47
48protected:
49 std::string detail;
50};
51
52class HdfsIOException: public HdfsException {
53public:
54 HdfsIOException(const std::string & arg, const char * file, int line,
55 const char * stack) :
56 HdfsException(arg, file, line, stack) {
57 }
58
59 ~HdfsIOException() throw () {
60 }
61
62public:
63 static const char * ReflexName;
64};
65
66class HdfsNetworkException: public HdfsIOException {
67public:
68 HdfsNetworkException(const std::string & arg, const char * file, int line,
69 const char * stack) :
70 HdfsIOException(arg, file, line, stack) {
71 }
72
73 ~HdfsNetworkException() throw () {
74 }
75};
76
77class HdfsNetworkConnectException: public HdfsNetworkException {
78public:
79 HdfsNetworkConnectException(const std::string & arg, const char * file, int line,
80 const char * stack) :
81 HdfsNetworkException(arg, file, line, stack) {
82 }
83
84 ~HdfsNetworkConnectException() throw () {
85 }
86};
87
88class AccessControlException: public HdfsException {
89public:
90 AccessControlException(const std::string & arg, const char * file, int line,
91 const char * stack) :
92 HdfsException(arg, file, line, stack) {
93 }
94
95 ~AccessControlException() throw () {
96 }
97
98public:
99 static const char * ReflexName;
100};
101
102class AlreadyBeingCreatedException: public HdfsException {
103public:
104 AlreadyBeingCreatedException(const std::string & arg, const char * file,
105 int line, const char * stack) :
106 HdfsException(arg, file, line, stack) {
107 }
108
109 ~AlreadyBeingCreatedException() throw () {
110 }
111
112public:
113 static const char * ReflexName;
114};
115
116class ChecksumException: public HdfsException {
117public:
118 ChecksumException(const std::string & arg, const char * file, int line,
119 const char * stack) :
120 HdfsException(arg, file, line, stack) {
121 }
122
123 ~ChecksumException() throw () {
124 }
125};
126
127class DSQuotaExceededException: public HdfsException {
128public:
129 DSQuotaExceededException(const std::string & arg, const char * file,
130 int line, const char * stack) :
131 HdfsException(arg, file, line, stack) {
132 }
133
134 ~DSQuotaExceededException() throw () {
135 }
136
137public:
138 static const char * ReflexName;
139};
140
141class FileAlreadyExistsException: public HdfsException {
142public:
143 FileAlreadyExistsException(const std::string & arg, const char * file,
144 int line, const char * stack) :
145 HdfsException(arg, file, line, stack) {
146 }
147
148 ~FileAlreadyExistsException() throw () {
149 }
150
151public:
152 static const char * ReflexName;
153};
154
155class FileNotFoundException: public HdfsException {
156public:
157 FileNotFoundException(const std::string & arg, const char * file, int line,
158 const char * stack) :
159 HdfsException(arg, file, line, stack) {
160 }
161
162 ~FileNotFoundException() throw () {
163 }
164
165public:
166 static const char * ReflexName;
167};
168
169class HdfsBadBoolFoumat: public HdfsException {
170public:
171 HdfsBadBoolFoumat(const std::string & arg, const char * file, int line,
172 const char * stack) :
173 HdfsException(arg, file, line, stack) {
174 }
175
176 ~HdfsBadBoolFoumat() throw () {
177 }
178};
179
180class HdfsBadConfigFoumat: public HdfsException {
181public:
182 HdfsBadConfigFoumat(const std::string & arg, const char * file, int line,
183 const char * stack) :
184 HdfsException(arg, file, line, stack) {
185 }
186
187 ~HdfsBadConfigFoumat() throw () {
188 }
189};
190
191class HdfsBadNumFoumat: public HdfsException {
192public:
193 HdfsBadNumFoumat(const std::string & arg, const char * file, int line,
194 const char * stack) :
195 HdfsException(arg, file, line, stack) {
196 }
197
198 ~HdfsBadNumFoumat() throw () {
199 }
200};
201
202class HdfsCanceled: public HdfsException {
203public:
204 HdfsCanceled(const std::string & arg, const char * file, int line,
205 const char * stack) :
206 HdfsException(arg, file, line, stack) {
207 }
208
209 ~HdfsCanceled() throw () {
210 }
211};
212
213class HdfsFileSystemClosed: public HdfsException {
214public:
215 HdfsFileSystemClosed(const std::string & arg, const char * file, int line,
216 const char * stack) :
217 HdfsException(arg, file, line, stack) {
218 }
219
220 ~HdfsFileSystemClosed() throw () {
221 }
222};
223
224class HdfsConfigInvalid: public HdfsException {
225public:
226 HdfsConfigInvalid(const std::string & arg, const char * file, int line,
227 const char * stack) :
228 HdfsException(arg, file, line, stack) {
229 }
230
231 ~HdfsConfigInvalid() throw () {
232 }
233};
234
235class HdfsConfigNotFound: public HdfsException {
236public:
237 HdfsConfigNotFound(const std::string & arg, const char * file, int line,
238 const char * stack) :
239 HdfsException(arg, file, line, stack) {
240 }
241
242 ~HdfsConfigNotFound() throw () {
243 }
244};
245
246class HdfsEndOfStream: public HdfsIOException {
247public:
248 HdfsEndOfStream(const std::string & arg, const char * file, int line,
249 const char * stack) :
250 HdfsIOException(arg, file, line, stack) {
251 }
252
253 ~HdfsEndOfStream() throw () {
254 }
255};
256
257class HdfsInvalidBlockToken: public HdfsException {
258public:
259 HdfsInvalidBlockToken(const std::string & arg, const char * file, int line,
260 const char * stack) :
261 HdfsException(arg, file, line, stack) {
262 }
263
264 ~HdfsInvalidBlockToken() throw () {
265 }
266
267public:
268 static const char * ReflexName;
269};
270
271/**
272 * This will wrap HdfsNetworkConnectionException and HdfsTimeoutException.
273 * This exception will be caught and attempt will be performed to recover in HA case.
274 */
275class HdfsFailoverException: public HdfsException {
276public:
277 HdfsFailoverException(const std::string & arg, const char * file, int line,
278 const char * stack) :
279 HdfsException(arg, file, line, stack) {
280 }
281
282 ~HdfsFailoverException() throw () {
283 }
284};
285
286/**
287 * Fatal error during the rpc call. It may wrap other exceptions.
288 */
289class HdfsRpcException: public HdfsIOException {
290public:
291 HdfsRpcException(const std::string & arg, const char * file, int line,
292 const char * stack) :
293 HdfsIOException(arg, file, line, stack) {
294 }
295
296 ~HdfsRpcException() throw () {
297 }
298};
299
300/**
301 * Server throw an error during the rpc call.
302 * It should be used internally and parsed for details.
303 */
304class HdfsRpcServerException: public HdfsIOException {
305public:
306 HdfsRpcServerException(const std::string & arg, const char * file, int line,
307 const char * stack) :
308 HdfsIOException(arg, file, line, stack) {
309 }
310
311 ~HdfsRpcServerException() throw () {
312 }
313
314 const std::string & getErrClass() const {
315 return errClass;
316 }
317
318 void setErrClass(const std::string & errClass) {
319 this->errClass = errClass;
320 }
321
322 const std::string & getErrMsg() const {
323 return errMsg;
324 }
325
326 void setErrMsg(const std::string & errMsg) {
327 this->errMsg = errMsg;
328 }
329
330private:
331 std::string errClass;
332 std::string errMsg;
333};
334
335class HdfsTimeoutException: public HdfsException {
336public:
337 HdfsTimeoutException(const std::string & arg, const char * file, int line,
338 const char * stack) :
339 HdfsException(arg, file, line, stack) {
340 }
341
342 ~HdfsTimeoutException() throw () {
343 }
344};
345
346class InvalidParameter: public HdfsException {
347public:
348 InvalidParameter(const std::string & arg, const char * file, int line,
349 const char * stack) :
350 HdfsException(arg, file, line, stack) {
351 }
352
353 ~InvalidParameter() throw () {
354 }
355
356public:
357 static const char * ReflexName;
358};
359
360class HadoopIllegalArgumentException : public InvalidParameter {
361public:
362 HadoopIllegalArgumentException(const std::string& arg, const char* file,
363 int line, const char* stack)
364 : InvalidParameter(arg, file, line, stack) {
365 }
366
367 ~HadoopIllegalArgumentException() throw() {
368 }
369
370public:
371 static const char* ReflexName;
372};
373
374class InvalidPath: public HdfsException {
375public:
376 InvalidPath(const std::string & arg, const char * file, int line,
377 const char * stack) :
378 HdfsException(arg, file, line, stack) {
379 }
380
381 ~InvalidPath() throw () {
382 }
383};
384
385class NotReplicatedYetException: public HdfsException {
386public:
387 NotReplicatedYetException(const std::string & arg, const char * file,
388 int line, const char * stack) :
389 HdfsException(arg, file, line, stack) {
390 }
391
392 ~NotReplicatedYetException() throw () {
393 }
394
395public:
396 static const char * ReflexName;
397};
398
399class NSQuotaExceededException: public HdfsException {
400public:
401 NSQuotaExceededException(const std::string & arg, const char * file,
402 int line, const char * stack) :
403 HdfsException(arg, file, line, stack) {
404 }
405
406 ~NSQuotaExceededException() throw () {
407 }
408
409public:
410 static const char * ReflexName;
411};
412
413class ParentNotDirectoryException: public HdfsException {
414public:
415 ParentNotDirectoryException(const std::string & arg, const char * file,
416 int line, const char * stack) :
417 HdfsException(arg, file, line, stack) {
418 }
419
420 ~ParentNotDirectoryException() throw () {
421 }
422
423public:
424 static const char * ReflexName;
425};
426
427class ReplicaNotFoundException: public HdfsException {
428public:
429 ReplicaNotFoundException(const std::string & arg, const char * file,
430 int line, const char * stack) :
431 HdfsException(arg, file, line, stack) {
432 }
433
434 ~ReplicaNotFoundException() throw () {
435 }
436
437public:
438 static const char * ReflexName;
439};
440
441class SafeModeException: public HdfsException {
442public:
443 SafeModeException(const std::string & arg, const char * file, int line,
444 const char * stack) :
445 HdfsException(arg, file, line, stack) {
446 }
447
448 ~SafeModeException() throw () {
449 }
450
451public:
452 static const char * ReflexName;
453};
454
455class UnresolvedLinkException: public HdfsException {
456public:
457 UnresolvedLinkException(const std::string & arg, const char * file,
458 int line, const char * stack) :
459 HdfsException(arg, file, line, stack) {
460 }
461
462 ~UnresolvedLinkException() throw () {
463 }
464
465public:
466 static const char * ReflexName;
467};
468
469class UnsupportedOperationException: public HdfsException {
470public:
471 UnsupportedOperationException(const std::string & arg, const char * file,
472 int line, const char * stack) :
473 HdfsException(arg, file, line, stack) {
474 }
475
476 ~UnsupportedOperationException() throw () {
477 }
478
479public:
480 static const char * ReflexName;
481};
482
483class SaslException: public HdfsException {
484public:
485 SaslException(const std::string & arg, const char * file, int line,
486 const char * stack) :
487 HdfsException(arg, file, line, stack) {
488 }
489
490 ~SaslException() throw () {
491 }
492
493public:
494 static const char * ReflexName;
495};
496
497class NameNodeStandbyException: public HdfsException {
498public:
499 NameNodeStandbyException(const std::string & arg, const char * file,
500 int line, const char * stack) :
501 HdfsException(arg, file, line, stack) {
502 }
503
504 ~NameNodeStandbyException() throw () {
505 }
506
507public:
508 static const char * ReflexName;
509};
510
511class RpcNoSuchMethodException: public HdfsException {
512public:
513 RpcNoSuchMethodException(const std::string & arg, const char * file,
514 int line, const char * stack) :
515 HdfsException(arg, file, line, stack) {
516 }
517
518 ~RpcNoSuchMethodException() throw () {
519 }
520
521public:
522 static const char * ReflexName;
523};
524
525class RecoveryInProgressException : public HdfsException {
526 public:
527 RecoveryInProgressException(const std::string & arg, const char * file,
528 int line, const char * stack)
529 : HdfsException(arg, file, line, stack) {
530 }
531
532 ~RecoveryInProgressException() throw () {
533 }
534
535 public:
536 static const char * ReflexName;
537};
538
539}
540
541#endif /* _HDFS_LIBHDFS3_COMMON_EXCEPTION_H_ */
542