Kinetic C/C++ Client
 All Classes Functions Variables Pages
status_code.cc
1 /*
2  * kinetic-cpp-client
3  * Copyright (C) 2014 Seagate Technology.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #include "kinetic/status_code.h"
22 
23 namespace kinetic {
24 
25 using com::seagate::kinetic::client::proto::Command_Status_StatusCode;
26 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_INVALID_STATUS_CODE;
27 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_HMAC_FAILURE;
28 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_NOT_AUTHORIZED;
29 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_NOT_FOUND;
30 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_INTERNAL_ERROR;
31 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_HEADER_REQUIRED;
32 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_SUCCESS;
33 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_VERSION_FAILURE;
34 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_VERSION_MISMATCH;
35 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_SERVICE_BUSY;
36 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_EXPIRED;
37 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_DATA_ERROR;
38 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_PERM_DATA_ERROR;
39 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_REMOTE_CONNECTION_ERROR;
40 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_NO_SPACE;
41 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_NO_SUCH_HMAC_ALGORITHM;
42 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_INVALID_REQUEST;
43 using com::seagate::kinetic::client::proto::Command_Status_StatusCode_NESTED_OPERATION_ERRORS;
44 
45 StatusCode ConvertFromProtoStatus(Command_Status_StatusCode status) {
46  switch (status) {
47  case Command_Status_StatusCode_SUCCESS:
48  return StatusCode::OK;
49  case Command_Status_StatusCode_HMAC_FAILURE:
50  return StatusCode::REMOTE_HMAC_ERROR;
51  case Command_Status_StatusCode_NOT_AUTHORIZED:
52  return StatusCode::REMOTE_NOT_AUTHORIZED;
53  case Command_Status_StatusCode_VERSION_FAILURE:
54  return StatusCode::REMOTE_CLUSTER_VERSION_MISMATCH;
55  case Command_Status_StatusCode_INTERNAL_ERROR:
56  return StatusCode::REMOTE_INTERNAL_ERROR;
57  case Command_Status_StatusCode_HEADER_REQUIRED:
58  return StatusCode::REMOTE_HEADER_REQUIRED;
59  case Command_Status_StatusCode_NOT_FOUND:
60  return StatusCode::REMOTE_NOT_FOUND;
61  case Command_Status_StatusCode_VERSION_MISMATCH:
62  return StatusCode::REMOTE_VERSION_MISMATCH;
63  case Command_Status_StatusCode_SERVICE_BUSY:
64  return StatusCode::REMOTE_SERVICE_BUSY;
65  case Command_Status_StatusCode_EXPIRED:
66  return StatusCode::REMOTE_EXPIRED;
67  case Command_Status_StatusCode_DATA_ERROR:
68  return StatusCode::REMOTE_DATA_ERROR;
69  case Command_Status_StatusCode_PERM_DATA_ERROR:
70  return StatusCode::REMOTE_PERM_DATA_ERROR;
71  case Command_Status_StatusCode_REMOTE_CONNECTION_ERROR:
72  return StatusCode::REMOTE_REMOTE_CONNECTION_ERROR;
73  case Command_Status_StatusCode_NO_SPACE:
74  return StatusCode::REMOTE_NO_SPACE;
75  case Command_Status_StatusCode_NO_SUCH_HMAC_ALGORITHM:
76  return StatusCode::REMOTE_NO_SUCH_HMAC_ALGORITHM;
77  case Command_Status_StatusCode_INVALID_REQUEST:
78  return StatusCode::REMOTE_INVALID_REQUEST;
79  case Command_Status_StatusCode_INVALID_STATUS_CODE:
80  return StatusCode::CLIENT_INTERNAL_ERROR;
81  case Command_Status_StatusCode_NESTED_OPERATION_ERRORS:
82  return StatusCode::REMOTE_NESTED_OPERATION_ERRORS;
83  default:
84  return StatusCode::REMOTE_OTHER_ERROR;
85  }
86 }
87 
88 Command_Status_StatusCode ConvertToProtoStatus(StatusCode status) {
89  switch (status) {
90  case StatusCode::OK:
91  return Command_Status_StatusCode_SUCCESS;
92  case StatusCode::REMOTE_HMAC_ERROR:
93  return Command_Status_StatusCode_HMAC_FAILURE;
94  case StatusCode::REMOTE_NOT_AUTHORIZED:
95  return Command_Status_StatusCode_NOT_AUTHORIZED;
96  case StatusCode::REMOTE_CLUSTER_VERSION_MISMATCH:
97  return Command_Status_StatusCode_VERSION_FAILURE;
98  case StatusCode::REMOTE_INTERNAL_ERROR:
99  return Command_Status_StatusCode_INTERNAL_ERROR;
100  case StatusCode::REMOTE_HEADER_REQUIRED:
101  return Command_Status_StatusCode_HEADER_REQUIRED;
102  case StatusCode::REMOTE_NOT_FOUND:
103  return Command_Status_StatusCode_NOT_FOUND;
104  case StatusCode::REMOTE_VERSION_MISMATCH:
105  return Command_Status_StatusCode_VERSION_MISMATCH;
106  case StatusCode::REMOTE_SERVICE_BUSY:
107  return Command_Status_StatusCode_SERVICE_BUSY;
108  case StatusCode::REMOTE_EXPIRED:
109  return Command_Status_StatusCode_EXPIRED;
110  case StatusCode::REMOTE_DATA_ERROR:
111  return Command_Status_StatusCode_DATA_ERROR;
112  case StatusCode::REMOTE_PERM_DATA_ERROR:
113  return Command_Status_StatusCode_PERM_DATA_ERROR;
114  case StatusCode::REMOTE_REMOTE_CONNECTION_ERROR:
115  return Command_Status_StatusCode_REMOTE_CONNECTION_ERROR;
116  case StatusCode::REMOTE_NO_SPACE:
117  return Command_Status_StatusCode_NO_SPACE;
118  case StatusCode::REMOTE_NO_SUCH_HMAC_ALGORITHM:
119  return Command_Status_StatusCode_NO_SUCH_HMAC_ALGORITHM;
120  case StatusCode::REMOTE_INVALID_REQUEST:
121  return Command_Status_StatusCode_INVALID_REQUEST;
122  case StatusCode::REMOTE_NESTED_OPERATION_ERRORS:
123  return Command_Status_StatusCode_NESTED_OPERATION_ERRORS;
124  default:
125  return Command_Status_StatusCode_INTERNAL_ERROR;
126  }
127 }
128 
129 } // namespace kinetic