forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add grpc response handler - Move client test to integration
- Loading branch information
Showing
11 changed files
with
190 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. | ||
* http://soramitsu.co.jp | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef IROHA_CLI_GRPC_RESPONSE_HANDLER_HPP | ||
#define IROHA_CLI_GRPC_RESPONSE_HANDLER_HPP | ||
|
||
#include "query_response_handler.hpp" | ||
#include "transaction_response_handler.hpp" | ||
#include "client.hpp" | ||
#include "logger/logger.hpp" | ||
|
||
namespace iroha_cli { | ||
class GrpcResponseHandler { | ||
public: | ||
GrpcResponseHandler(); | ||
void handle(CliClient::Response<CliClient::TxStatus> response); | ||
void handle(CliClient::Response<iroha::protocol::QueryResponse> response); | ||
private: | ||
TransactionResponseHandler tx_handler_; | ||
QueryResponseHandler query_handler_; | ||
void handleGrpcErrors(grpc::StatusCode code); | ||
// Map | ||
std::shared_ptr<spdlog::logger> log_; | ||
std::unordered_map<int, std::string> handler_map_; | ||
}; | ||
} // namespace iroha_cli | ||
|
||
#endif // IROHA_GRPC_RESPONSE_HANDLER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. | ||
* http://soramitsu.co.jp | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "grpc_response_handler.hpp" | ||
|
||
using namespace grpc; | ||
namespace iroha_cli { | ||
|
||
GrpcResponseHandler::GrpcResponseHandler() | ||
: log_(logger::log("GrpcResponseHandler")) { | ||
handler_map_[CANCELLED] = "Operation canceled"; | ||
handler_map_[UNKNOWN] = "Unknown error"; | ||
handler_map_[INVALID_ARGUMENT] = "INVALID_ARGUMENT"; | ||
handler_map_[DEADLINE_EXCEEDED] = "DEADLINE_EXCEEDED"; | ||
handler_map_[NOT_FOUND] = "NOT_FOUND"; | ||
handler_map_[ALREADY_EXISTS] = "ALREADY_EXISTS"; | ||
handler_map_[PERMISSION_DENIED] = "PERMISSION_DENIED"; | ||
handler_map_[UNAUTHENTICATED] = "UNAUTHENTICATED"; | ||
handler_map_[RESOURCE_EXHAUSTED] = "RESOURCE_EXHAUSTED"; | ||
handler_map_[FAILED_PRECONDITION] = "FAILED_PRECONDITION"; | ||
handler_map_[ABORTED] = "ABORTED"; | ||
handler_map_[OUT_OF_RANGE] = "OUT_OF_RANGE"; | ||
handler_map_[UNIMPLEMENTED] = "UNIMPLEMENTED"; | ||
handler_map_[INTERNAL] = "INTERNAL"; | ||
handler_map_[UNIMPLEMENTED] = "UNIMPLEMENTED"; | ||
handler_map_[UNAVAILABLE] = "Server is unavailable"; | ||
handler_map_[DATA_LOSS] = "DATA_LOSS"; | ||
} | ||
|
||
void GrpcResponseHandler::handle( | ||
CliClient::Response<CliClient::TxStatus> response) { | ||
if (response.status.ok()) { | ||
tx_handler_.handle(response.answer); | ||
} else { | ||
handleGrpcErrors(response.status.error_code()); | ||
} | ||
} | ||
|
||
void GrpcResponseHandler::handle( | ||
CliClient::Response<iroha::protocol::QueryResponse> response) { | ||
if (response.status.ok()) { | ||
query_handler_.handle(response.answer); | ||
} else { | ||
handleGrpcErrors(response.status.error_code()); | ||
} | ||
} | ||
|
||
void GrpcResponseHandler::handleGrpcErrors(grpc::StatusCode code) { | ||
auto it = handler_map_.find(code); | ||
if (it != handler_map_.end()) { | ||
log_->error(it->second); | ||
} else { | ||
log_->error("Handler for grpc {} not implemented", code); | ||
} | ||
} | ||
|
||
} // namespace iroha_cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ target_link_libraries(model_converters | |
optional | ||
schema | ||
logger | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test_bin) | ||
|
||
add_subdirectory(consensus) | ||
add_subdirectory(consensus) | ||
|
||
addtest(client_test client_test.cpp) | ||
target_link_libraries(client_test | ||
client | ||
processors | ||
server_runner | ||
) | ||
target_include_directories(client_test PUBLIC | ||
${PROJECT_SOURCE_DIR}/iroha-cli | ||
) |
Oops, something went wrong.