| 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 | |
| 34 | namespace Hdfs { |
| 35 | |
| 36 | class HdfsException: public std::runtime_error { |
| 37 | public: |
| 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 | |
| 48 | protected: |
| 49 | std::string detail; |
| 50 | }; |
| 51 | |
| 52 | class HdfsIOException: public HdfsException { |
| 53 | public: |
| 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 | |
| 62 | public: |
| 63 | static const char * ReflexName; |
| 64 | }; |
| 65 | |
| 66 | class HdfsNetworkException: public HdfsIOException { |
| 67 | public: |
| 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 | |
| 77 | class HdfsNetworkConnectException: public HdfsNetworkException { |
| 78 | public: |
| 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 | |
| 88 | class AccessControlException: public HdfsException { |
| 89 | public: |
| 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 | |
| 98 | public: |
| 99 | static const char * ReflexName; |
| 100 | }; |
| 101 | |
| 102 | class AlreadyBeingCreatedException: public HdfsException { |
| 103 | public: |
| 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 | |
| 112 | public: |
| 113 | static const char * ReflexName; |
| 114 | }; |
| 115 | |
| 116 | class ChecksumException: public HdfsException { |
| 117 | public: |
| 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 | |
| 127 | class DSQuotaExceededException: public HdfsException { |
| 128 | public: |
| 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 | |
| 137 | public: |
| 138 | static const char * ReflexName; |
| 139 | }; |
| 140 | |
| 141 | class FileAlreadyExistsException: public HdfsException { |
| 142 | public: |
| 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 | |
| 151 | public: |
| 152 | static const char * ReflexName; |
| 153 | }; |
| 154 | |
| 155 | class FileNotFoundException: public HdfsException { |
| 156 | public: |
| 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 | |
| 165 | public: |
| 166 | static const char * ReflexName; |
| 167 | }; |
| 168 | |
| 169 | class HdfsBadBoolFoumat: public HdfsException { |
| 170 | public: |
| 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 | |
| 180 | class HdfsBadConfigFoumat: public HdfsException { |
| 181 | public: |
| 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 | |
| 191 | class HdfsBadNumFoumat: public HdfsException { |
| 192 | public: |
| 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 | |
| 202 | class HdfsCanceled: public HdfsException { |
| 203 | public: |
| 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 | |
| 213 | class HdfsFileSystemClosed: public HdfsException { |
| 214 | public: |
| 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 | |
| 224 | class HdfsConfigInvalid: public HdfsException { |
| 225 | public: |
| 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 | |
| 235 | class HdfsConfigNotFound: public HdfsException { |
| 236 | public: |
| 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 | |
| 246 | class HdfsEndOfStream: public HdfsIOException { |
| 247 | public: |
| 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 | |
| 257 | class HdfsInvalidBlockToken: public HdfsException { |
| 258 | public: |
| 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 | |
| 267 | public: |
| 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 | */ |
| 275 | class HdfsFailoverException: public HdfsException { |
| 276 | public: |
| 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 | */ |
| 289 | class HdfsRpcException: public HdfsIOException { |
| 290 | public: |
| 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 | */ |
| 304 | class HdfsRpcServerException: public HdfsIOException { |
| 305 | public: |
| 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 | |
| 330 | private: |
| 331 | std::string errClass; |
| 332 | std::string errMsg; |
| 333 | }; |
| 334 | |
| 335 | class HdfsTimeoutException: public HdfsException { |
| 336 | public: |
| 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 | |
| 346 | class InvalidParameter: public HdfsException { |
| 347 | public: |
| 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 | |
| 356 | public: |
| 357 | static const char * ReflexName; |
| 358 | }; |
| 359 | |
| 360 | class HadoopIllegalArgumentException : public InvalidParameter { |
| 361 | public: |
| 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 | |
| 370 | public: |
| 371 | static const char* ReflexName; |
| 372 | }; |
| 373 | |
| 374 | class InvalidPath: public HdfsException { |
| 375 | public: |
| 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 | |
| 385 | class NotReplicatedYetException: public HdfsException { |
| 386 | public: |
| 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 | |
| 395 | public: |
| 396 | static const char * ReflexName; |
| 397 | }; |
| 398 | |
| 399 | class NSQuotaExceededException: public HdfsException { |
| 400 | public: |
| 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 | |
| 409 | public: |
| 410 | static const char * ReflexName; |
| 411 | }; |
| 412 | |
| 413 | class ParentNotDirectoryException: public HdfsException { |
| 414 | public: |
| 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 | |
| 423 | public: |
| 424 | static const char * ReflexName; |
| 425 | }; |
| 426 | |
| 427 | class ReplicaNotFoundException: public HdfsException { |
| 428 | public: |
| 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 | |
| 437 | public: |
| 438 | static const char * ReflexName; |
| 439 | }; |
| 440 | |
| 441 | class SafeModeException: public HdfsException { |
| 442 | public: |
| 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 | |
| 451 | public: |
| 452 | static const char * ReflexName; |
| 453 | }; |
| 454 | |
| 455 | class UnresolvedLinkException: public HdfsException { |
| 456 | public: |
| 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 | |
| 465 | public: |
| 466 | static const char * ReflexName; |
| 467 | }; |
| 468 | |
| 469 | class UnsupportedOperationException: public HdfsException { |
| 470 | public: |
| 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 | |
| 479 | public: |
| 480 | static const char * ReflexName; |
| 481 | }; |
| 482 | |
| 483 | class SaslException: public HdfsException { |
| 484 | public: |
| 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 | |
| 493 | public: |
| 494 | static const char * ReflexName; |
| 495 | }; |
| 496 | |
| 497 | class NameNodeStandbyException: public HdfsException { |
| 498 | public: |
| 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 | |
| 507 | public: |
| 508 | static const char * ReflexName; |
| 509 | }; |
| 510 | |
| 511 | class RpcNoSuchMethodException: public HdfsException { |
| 512 | public: |
| 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 | |
| 521 | public: |
| 522 | static const char * ReflexName; |
| 523 | }; |
| 524 | |
| 525 | class 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 | |