1
0

status.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "hdfspp/status.h"
  19. #include <cassert>
  20. #include <sstream>
  21. #include <cstring>
  22. namespace hdfs {
  23. const char * kStatusAccessControlException = "org.apache.hadoop.security.AccessControlException";
  24. const char * kStatusSaslException = "javax.security.sasl.SaslException";
  25. Status::Status(int code, const char *msg1) : code_(code) {
  26. if(msg1) {
  27. msg_ = msg1;
  28. }
  29. }
  30. Status::Status(int code, const char *msg1, const char *msg2) : code_(code) {
  31. std::stringstream ss;
  32. if(msg1) {
  33. ss << msg1;
  34. if(msg2) {
  35. ss << ":" << msg2;
  36. }
  37. }
  38. msg_ = ss.str();
  39. }
  40. Status Status::OK() {
  41. return Status();
  42. }
  43. Status Status::InvalidArgument(const char *msg) {
  44. return Status(kInvalidArgument, msg);
  45. }
  46. Status Status::ResourceUnavailable(const char *msg) {
  47. return Status(kResourceUnavailable, msg);
  48. }
  49. Status Status::Unimplemented() {
  50. return Status(kUnimplemented, "");
  51. }
  52. Status Status::Exception(const char *exception_class_name, const char *error_message) {
  53. if (exception_class_name && (strcmp(exception_class_name, kStatusAccessControlException) == 0) )
  54. return Status(kPermissionDenied, error_message);
  55. else if (exception_class_name && (strcmp(exception_class_name, kStatusSaslException) == 0))
  56. return AuthenticationFailed();
  57. else
  58. return Status(kException, exception_class_name, error_message);
  59. }
  60. Status Status::Error(const char *error_message) {
  61. return Status(kAuthenticationFailed, error_message);
  62. }
  63. Status Status::AuthenticationFailed() {
  64. return Status(kAuthenticationFailed, "Authentication failed");
  65. }
  66. Status Status::Canceled() {
  67. return Status(kOperationCanceled,"Operation canceled");
  68. }
  69. std::string Status::ToString() const {
  70. if (code_ == kOk) {
  71. return "OK";
  72. }
  73. return msg_;
  74. }
  75. }