Skip to content

Commit

Permalink
Refactor/move query execution (hyperledger-iroha#1246)
Browse files Browse the repository at this point in the history
* Move QueryProcessor out of model

Signed-off-by: Dumitru <[email protected]>

* Link query_execution

Signed-off-by: Dumitru <[email protected]>

* Resolve conflicts

Signed-off-by: Dumitru <[email protected]>

* Improve codestyle

Signed-off-by: Dumitru <[email protected]>

* Refactor CMakeLists.txt

Signed-off-by: Dumitru <[email protected]>
  • Loading branch information
x3medima17 authored May 3, 2018
1 parent 85b65e4 commit 039f74a
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 169 deletions.
3 changes: 1 addition & 2 deletions irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ target_link_libraries(ametsuchi
pqxx
libs_common
command_execution
boost
query_execution
shared_model_interfaces
shared_model_proto_backend
shared_model_proto_builders
shared_model_stateless_validation
)
9 changes: 9 additions & 0 deletions irohad/execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ target_link_libraries(command_execution
rxcpp
shared_model_default_builders
)

add_library(query_execution
impl/query_execution.cpp
)

target_link_libraries(query_execution
rxcpp
shared_model_default_builders
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* limitations under the License.
*/

#include "model/query_execution.hpp"
#include "execution/query_execution.hpp"

#include <boost/algorithm/string.hpp>

#include "execution/common_executor.hpp"
#include "validators/permissions.hpp"

using namespace iroha::model;
using namespace shared_model::permissions;
using namespace iroha;
using namespace iroha::ametsuchi;

// TODO: 28/03/2018 x3medima17 remove poly wrapper, IR-1011
Expand Down Expand Up @@ -271,7 +271,7 @@ QueryProcessingFactory::executeGetAccountAssets(
}

QueryProcessingFactory::QueryResponseBuilderDone
iroha::model::QueryProcessingFactory::executeGetAccountDetail(
QueryProcessingFactory::executeGetAccountDetail(
const shared_model::interface::GetAccountDetail &query) {
auto acct_detail = _wsvQuery->getAccountDetail(query.accountId());
if (not acct_detail) {
Expand All @@ -282,7 +282,7 @@ iroha::model::QueryProcessingFactory::executeGetAccountDetail(
}

QueryProcessingFactory::QueryResponseBuilderDone
iroha::model::QueryProcessingFactory::executeGetAccountAssetTransactions(
QueryProcessingFactory::executeGetAccountAssetTransactions(
const shared_model::interface::GetAccountAssetTransactions &query) {
auto acc_asset_tx = _blockQuery->getAccountAssetTransactions(
query.accountId(), query.assetId());
Expand Down Expand Up @@ -313,7 +313,7 @@ QueryProcessingFactory::executeGetAccountTransactions(
}

QueryProcessingFactory::QueryResponseBuilderDone
iroha::model::QueryProcessingFactory::executeGetTransactions(
QueryProcessingFactory::executeGetTransactions(
const shared_model::interface::GetTransactions &q,
const shared_model::interface::types::AccountIdType &accountId) {
const std::vector<shared_model::crypto::Hash> &hashes = q.transactionHashes();
Expand Down Expand Up @@ -348,7 +348,8 @@ QueryProcessingFactory::executeGetSignatories(
}

std::shared_ptr<shared_model::interface::QueryResponse>
QueryProcessingFactory::execute(const shared_model::interface::Query &query) {
QueryProcessingFactory::validateAndExecute(
const shared_model::interface::Query &query) {
const auto &query_hash = query.hash();
QueryResponseBuilderDone builder;
// TODO: 29/04/2018 x3medima18, Add visitor class, IR-1185
Expand Down
135 changes: 135 additions & 0 deletions irohad/execution/query_execution.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Copyright Soramitsu Co., Ltd. 2018 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_QUERY_EXECUTION_HPP
#define IROHA_QUERY_EXECUTION_HPP

#include "ametsuchi/block_query.hpp"
#include "ametsuchi/wsv_query.hpp"
#include "builders/protobuf/builder_templates/query_response_template.hpp"

namespace shared_model {
namespace interface {
class QueryResponse;
class Query;
} // namespace interface
} // namespace shared_model

namespace iroha {

/**
* Converting model objects to protobuf and vice versa
*/
class QueryProcessingFactory {
using QueryResponseBuilder =
shared_model::proto::TemplateQueryResponseBuilder<0>;

using QueryResponseBuilderDone =
shared_model::proto::TemplateQueryResponseBuilder<1>;

public:
/**
* Execute and validate query.
*
* @param query
* @return shared pointer to query response
*/
std::shared_ptr<shared_model::interface::QueryResponse> validateAndExecute(
const shared_model::interface::Query &query);
/**
*
* @param wsvQuery
* @param blockQuery
*/
QueryProcessingFactory(std::shared_ptr<ametsuchi::WsvQuery> wsvQuery,
std::shared_ptr<ametsuchi::BlockQuery> blockQuery);

private:
bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetAssetInfo &get_asset_info);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetRoles &get_roles);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetRolePermissions
&get_role_permissions);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetAccountAssets &get_account_assets);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetAccount &get_account);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetSignatories &get_signatories);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetAccountTransactions
&get_account_transactions);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetAccountAssetTransactions
&get_account_asset_transactions);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetAccountDetail &get_account_detail);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetTransactions &get_transactions);

QueryResponseBuilderDone executeGetAssetInfo(
const shared_model::interface::GetAssetInfo &get_asset_info);

QueryResponseBuilderDone executeGetRoles(
const shared_model::interface::GetRoles &query);

QueryResponseBuilderDone executeGetRolePermissions(
const shared_model::interface::GetRolePermissions &query);

QueryResponseBuilderDone executeGetAccountAssets(
const shared_model::interface::GetAccountAssets &query);

QueryResponseBuilderDone executeGetAccountDetail(
const shared_model::interface::GetAccountDetail &query);

QueryResponseBuilderDone executeGetAccount(
const shared_model::interface::GetAccount &query);

QueryResponseBuilderDone executeGetSignatories(
const shared_model::interface::GetSignatories &query);

QueryResponseBuilderDone executeGetAccountAssetTransactions(
const shared_model::interface::GetAccountAssetTransactions &query);

QueryResponseBuilderDone executeGetAccountTransactions(
const shared_model::interface::GetAccountTransactions &query);

QueryResponseBuilderDone executeGetTransactions(
const shared_model::interface::GetTransactions &query,
const shared_model::interface::types::AccountIdType &accountId);

std::shared_ptr<ametsuchi::WsvQuery> _wsvQuery;
std::shared_ptr<ametsuchi::BlockQuery> _blockQuery;
};

} // namespace iroha

#endif // IROHA_QUERY_EXECUTION_HPP
2 changes: 1 addition & 1 deletion irohad/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ target_link_libraries(sha3_hash
add_library(model
model_crypto_provider_impl.cpp
impl/model_operators.cpp
impl/query_execution.cpp
)

target_link_libraries(model
hash
sha3_hash
Expand Down
138 changes: 0 additions & 138 deletions irohad/model/query_execution.hpp
Original file line number Diff line number Diff line change
@@ -1,138 +0,0 @@
/**
* 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_QUERY_EXECUTION_HPP
#define IROHA_QUERY_EXECUTION_HPP

#include "ametsuchi/block_query.hpp"
#include "ametsuchi/wsv_query.hpp"
#include "builders/protobuf/builder_templates/query_response_template.hpp"

namespace shared_model {
namespace interface {
class QueryResponse;
class Query;
} // namespace interface
} // namespace shared_model

namespace iroha {
namespace model {

/**
* Converting business objects to protobuf and vice versa
*/
class QueryProcessingFactory {
using QueryResponseBuilder =
shared_model::proto::TemplateQueryResponseBuilder<0>;

using QueryResponseBuilderDone =
shared_model::proto::TemplateQueryResponseBuilder<1>;

public:
/**
* Execute and validate query.
*
* @param query
* @return
*/
std::shared_ptr<shared_model::interface::QueryResponse> execute(
const shared_model::interface::Query &query);
/**
*
* @param wsvQuery
* @param blockQuery
*/
QueryProcessingFactory(std::shared_ptr<ametsuchi::WsvQuery> wsvQuery,
std::shared_ptr<ametsuchi::BlockQuery> blockQuery);

private:
bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetAssetInfo &get_asset_info);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetRoles &get_roles);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetRolePermissions
&get_role_permissions);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetAccountAssets &get_account_assets);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetAccount &get_account);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetSignatories &get_signatories);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetAccountTransactions
&get_account_transactions);

bool validate(const shared_model::interface::Query &query,
const shared_model::interface::GetAccountAssetTransactions
&get_account_asset_transactions);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetAccountDetail &get_account_detail);

bool validate(
const shared_model::interface::Query &query,
const shared_model::interface::GetTransactions &get_transactions);

QueryResponseBuilderDone executeGetAssetInfo(
const shared_model::interface::GetAssetInfo &get_asset_info);

QueryResponseBuilderDone executeGetRoles(
const shared_model::interface::GetRoles &query);

QueryResponseBuilderDone executeGetRolePermissions(
const shared_model::interface::GetRolePermissions &query);

QueryResponseBuilderDone executeGetAccountAssets(
const shared_model::interface::GetAccountAssets &query);

QueryResponseBuilderDone executeGetAccountDetail(
const shared_model::interface::GetAccountDetail &query);

QueryResponseBuilderDone executeGetAccount(
const shared_model::interface::GetAccount &query);

QueryResponseBuilderDone executeGetSignatories(
const shared_model::interface::GetSignatories &query);

QueryResponseBuilderDone executeGetAccountAssetTransactions(
const shared_model::interface::GetAccountAssetTransactions &query);

QueryResponseBuilderDone executeGetAccountTransactions(
const shared_model::interface::GetAccountTransactions &query);

QueryResponseBuilderDone executeGetTransactions(
const shared_model::interface::GetTransactions &q,
const shared_model::interface::types::AccountIdType &accountId);

std::shared_ptr<ametsuchi::WsvQuery> _wsvQuery;
std::shared_ptr<ametsuchi::BlockQuery> _blockQuery;
};

} // namespace model
} // namespace iroha

#endif // IROHA_QUERY_EXECUTION_HPP
1 change: 0 additions & 1 deletion irohad/torii/processor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_library(processors
)

target_link_libraries(processors PUBLIC
model
rxcpp
logger
endpoint
Expand Down
8 changes: 3 additions & 5 deletions irohad/torii/processor/impl/query_processor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ namespace iroha {
const auto &sig = *qry.signatures().begin();

const auto &wsv_query = storage_->getWsvQuery();
auto qpf =
model::QueryProcessingFactory(wsv_query, storage_->getBlockQuery());
auto qpf = QueryProcessingFactory(wsv_query, storage_->getBlockQuery());
auto signatories = wsv_query->getSignatories(qry.creatorAccountId());
if (not signatories) {
return false;
Expand All @@ -90,9 +89,8 @@ namespace iroha {
}

const auto &wsv_query = storage_->getWsvQuery();
auto qpf =
model::QueryProcessingFactory(wsv_query, storage_->getBlockQuery());
auto qpf_response = qpf.execute(*qry);
auto qpf = QueryProcessingFactory(wsv_query, storage_->getBlockQuery());
auto qpf_response = qpf.validateAndExecute(*qry);
auto qry_resp =
std::static_pointer_cast<shared_model::proto::QueryResponse>(
qpf_response);
Expand Down
Loading

0 comments on commit 039f74a

Please sign in to comment.