diff --git a/bin/dsn.cmake b/bin/dsn.cmake index 62631f50bc..fee26b8e66 100644 --- a/bin/dsn.cmake +++ b/bin/dsn.cmake @@ -342,4 +342,7 @@ function(dsn_common_setup) dsn_setup_compiler_flags() dsn_setup_include_path() dsn_setup_thirdparty_libs() + + include(bin/thrift_utils.cmake) + endfunction(dsn_common_setup) diff --git a/bin/thrift_utils.cmake b/bin/thrift_utils.cmake new file mode 100644 index 0000000000..7349c852d4 --- /dev/null +++ b/bin/thrift_utils.cmake @@ -0,0 +1,76 @@ +############################################################################## +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +############################################################################## + +find_program(THRIFT_COMPILER + NAME + thrift + PATHS + ${DSN_THIRDPARTY_ROOT}/bin + NO_DEFAULT_PATH +) + +set(THRIFT_GENERATED_FILE_PATH ${CMAKE_BINARY_DIR}/thrift-gen CACHE INTERNAL "Where the thrift generated sources locate") +if(NOT EXISTS ${THRIFT_GENERATED_FILE_PATH}) + file(MAKE_DIRECTORY ${THRIFT_GENERATED_FILE_PATH}) +endif() +message(STATUS "THRIFT_GENERATED_FILE_PATH=${THRIFT_GENERATED_FILE_PATH}") +include_directories(${THRIFT_GENERATED_FILE_PATH}) + +# THRIFT_GENERATE_CPP is used to generate sources using the thrift compiler. +# +# Example: +# +# thrift_generate_cpp( +# REQUEST_META_THRIFT_SRCS +# REQUEST_META_THRIFT_HDRS +# ${CMAKE_CURRENT_SOURCE_DIR}/request_meta.thrift +# ) +# add_library( +# dsn_rpc +# ${REQUEST_META_THRIFT_SRCS} +# ... +# ) +function(THRIFT_GENERATE_CPP SRCS HDRS thrift_file) + if(NOT EXISTS ${thrift_file}) + message(FATAL_ERROR "thrift file ${thrift_file} does not exist") + endif() + + message(STATUS "THRIFT_GENERATE_CPP: ${thrift_file}") + + exec_program(${THRIFT_COMPILER} + ARGS --out ${THRIFT_GENERATED_FILE_PATH} --gen cpp ${thrift_file} + OUTPUT_VARIABLE __thrift_OUT + RETURN_VALUE THRIFT_RETURN) + if(NOT ${THRIFT_RETURN} EQUAL "0") + message(STATUS "COMMAND: ${THRIFT_COMPILER} --out ${THRIFT_GENERATED_FILE_PATH} --gen cpp ${thrift_file}") + message(FATAL_ERROR "thrift-compiler exits with " ${THRIFT_RETURN} ": " ${__thrift_OUT}) + endif() + + get_filename_component(__thrift_name ${thrift_file} NAME_WE) + + set(${SRCS}) + set(${HDRS}) + file(GLOB_RECURSE __result_src "${THRIFT_GENERATED_FILE_PATH}/${__thrift_name}*.cpp") + file(GLOB_RECURSE __result_hdr "${THRIFT_GENERATED_FILE_PATH}/${__thrift_name}*.h") + list(APPEND ${SRCS} ${__result_src}) + list(APPEND ${HDRS} ${__result_hdr}) + # Sets the variables in global scope. + set(${SRCS} ${${SRCS}} PARENT_SCOPE) + set(${HDRS} ${${HDRS}} PARENT_SCOPE) +endfunction() diff --git a/compile_thrift.py b/compile_thrift.py index bbee8afd33..ecd8ebd4fe 100755 --- a/compile_thrift.py +++ b/compile_thrift.py @@ -63,46 +63,10 @@ }, }, }, - { - "name": "nfs", - "path": "src/nfs", - "include_fix": { - "_types.h": { - "add": [""], - "remove": ["\"dsn_types.h\""] - } - } - }, { "name": "simple_kv", "path": "src/replica/storage/simple_kv" }, - { - "name": "command", - "path": "src/remote_cmd", - "file_move": { - "_types.h": "src/remote_cmd", - "_types.cpp": "src/remote_cmd" - } - }, - { - "name": "security", - "path": "src/runtime/security", - "file_move": { - "_types.h": "src/runtime/security", - "_types.cpp": "src/runtime/security" - }, - "include_fix": { - "_types.h": { - "add": [""], - "remove": ["\"dsn_types.h\""] - }, - "_types.cpp": { - "add": ["\"security_types.h\""], - "remove": ["\"security_types.h\""] - } - } - } ] diff --git a/include/dsn/cpp/serialization_helper/dsn.layer2_types.h b/include/dsn/cpp/serialization_helper/dsn.layer2_types.h index 6ba23da9a1..4898a6bc8e 100644 --- a/include/dsn/cpp/serialization_helper/dsn.layer2_types.h +++ b/include/dsn/cpp/serialization_helper/dsn.layer2_types.h @@ -44,8 +44,6 @@ class configuration_query_by_index_response; class app_info; -class thrift_request_meta_v1; - typedef struct _partition_configuration__isset { _partition_configuration__isset() @@ -438,101 +436,6 @@ inline std::ostream &operator<<(std::ostream &out, const app_info &obj) return out; } -typedef struct _thrift_request_meta_v1__isset -{ - _thrift_request_meta_v1__isset() - : app_id(false), - partition_index(false), - client_timeout(false), - client_partition_hash(false), - is_backup_request(false) - { - } - bool app_id : 1; - bool partition_index : 1; - bool client_timeout : 1; - bool client_partition_hash : 1; - bool is_backup_request : 1; -} _thrift_request_meta_v1__isset; - -class thrift_request_meta_v1 -{ -public: - thrift_request_meta_v1(const thrift_request_meta_v1 &); - thrift_request_meta_v1(thrift_request_meta_v1 &&); - thrift_request_meta_v1 &operator=(const thrift_request_meta_v1 &); - thrift_request_meta_v1 &operator=(thrift_request_meta_v1 &&); - thrift_request_meta_v1() - : app_id(0), - partition_index(0), - client_timeout(0), - client_partition_hash(0), - is_backup_request(0) - { - } - - virtual ~thrift_request_meta_v1() throw(); - int32_t app_id; - int32_t partition_index; - int32_t client_timeout; - int64_t client_partition_hash; - bool is_backup_request; - - _thrift_request_meta_v1__isset __isset; - - void __set_app_id(const int32_t val); - - void __set_partition_index(const int32_t val); - - void __set_client_timeout(const int32_t val); - - void __set_client_partition_hash(const int64_t val); - - void __set_is_backup_request(const bool val); - - bool operator==(const thrift_request_meta_v1 &rhs) const - { - if (__isset.app_id != rhs.__isset.app_id) - return false; - else if (__isset.app_id && !(app_id == rhs.app_id)) - return false; - if (__isset.partition_index != rhs.__isset.partition_index) - return false; - else if (__isset.partition_index && !(partition_index == rhs.partition_index)) - return false; - if (__isset.client_timeout != rhs.__isset.client_timeout) - return false; - else if (__isset.client_timeout && !(client_timeout == rhs.client_timeout)) - return false; - if (__isset.client_partition_hash != rhs.__isset.client_partition_hash) - return false; - else if (__isset.client_partition_hash && - !(client_partition_hash == rhs.client_partition_hash)) - return false; - if (__isset.is_backup_request != rhs.__isset.is_backup_request) - return false; - else if (__isset.is_backup_request && !(is_backup_request == rhs.is_backup_request)) - return false; - return true; - } - bool operator!=(const thrift_request_meta_v1 &rhs) const { return !(*this == rhs); } - - bool operator<(const thrift_request_meta_v1 &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(thrift_request_meta_v1 &a, thrift_request_meta_v1 &b); - -inline std::ostream &operator<<(std::ostream &out, const thrift_request_meta_v1 &obj) -{ - obj.printTo(out); - return out; -} - } // namespace #endif diff --git a/src/dsn.layer2.thrift b/src/dsn.layer2.thrift index 2e08979dad..e9a30476d0 100644 --- a/src/dsn.layer2.thrift +++ b/src/dsn.layer2.thrift @@ -76,22 +76,3 @@ struct app_info // Whether this app is executing bulk load 14:optional bool is_bulk_loading = false; } - -// Metadata field of the request in rDSN's thrift protocol (version 1). -// TODO(wutao1): add design doc of the thrift protocol. -struct thrift_request_meta_v1 -{ - // The replica's gpid. - 1:optional i32 app_id; - 2:optional i32 partition_index; - - // The timeout of this request that's set on client side. - 3:optional i32 client_timeout; - - // The hash value calculated from the hash key. - 4:optional i64 client_partition_hash; - - // Whether it is a backup request. If true, this request (only if it's a read) can be handled by - // a secondary replica, which does not guarantee strong consistency. - 5:optional bool is_backup_request; -} diff --git a/src/nfs/CMakeLists.txt b/src/nfs/CMakeLists.txt index 085cfce6d3..d5025dd8ae 100644 --- a/src/nfs/CMakeLists.txt +++ b/src/nfs/CMakeLists.txt @@ -1,8 +1,12 @@ set(MY_PROJ_NAME dsn_nfs) -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. -set(MY_PROJ_SRC "") +thrift_generate_cpp( + NFS_THRIFT_SRCS + NFS_THRIFT_HDRS + ${CMAKE_CURRENT_SOURCE_DIR}/nfs.thrift +) + +set(MY_PROJ_SRC ${NFS_THRIFT_SRCS}) # Search mode for source files under CURRENT project directory? # "GLOB_RECURSE" for recursive search diff --git a/src/nfs/nfs.thrift b/src/nfs/nfs.thrift index 7282cf08a4..fcba1b3381 100644 --- a/src/nfs/nfs.thrift +++ b/src/nfs/nfs.thrift @@ -37,9 +37,3 @@ struct get_file_size_response 2: list file_list; 3: list size_list; } - -service nfs -{ - copy_response copy(1: copy_request request); - get_file_size_response get_file_size(1: get_file_size_request request); -} diff --git a/src/nfs/nfs_types.cpp b/src/nfs/nfs_types.cpp deleted file mode 100644 index 2a3ff69174..0000000000 --- a/src/nfs/nfs_types.cpp +++ /dev/null @@ -1,799 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.9.3) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "nfs_types.h" - -#include -#include - -#include - -namespace dsn { -namespace service { - -copy_request::~copy_request() throw() {} - -void copy_request::__set_source(const ::dsn::rpc_address &val) { this->source = val; } - -void copy_request::__set_source_dir(const std::string &val) { this->source_dir = val; } - -void copy_request::__set_dst_dir(const std::string &val) { this->dst_dir = val; } - -void copy_request::__set_file_name(const std::string &val) { this->file_name = val; } - -void copy_request::__set_offset(const int64_t val) { this->offset = val; } - -void copy_request::__set_size(const int32_t val) { this->size = val; } - -void copy_request::__set_is_last(const bool val) { this->is_last = val; } - -void copy_request::__set_overwrite(const bool val) { this->overwrite = val; } - -uint32_t copy_request::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->source.read(iprot); - this->__isset.source = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->source_dir); - this->__isset.source_dir = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->dst_dir); - this->__isset.dst_dir = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->file_name); - this->__isset.file_name = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 5: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->offset); - this->__isset.offset = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 6: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->size); - this->__isset.size = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 7: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->is_last); - this->__isset.is_last = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 8: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->overwrite); - this->__isset.overwrite = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t copy_request::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("copy_request"); - - xfer += oprot->writeFieldBegin("source", ::apache::thrift::protocol::T_STRUCT, 1); - xfer += this->source.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("source_dir", ::apache::thrift::protocol::T_STRING, 2); - xfer += oprot->writeString(this->source_dir); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("dst_dir", ::apache::thrift::protocol::T_STRING, 3); - xfer += oprot->writeString(this->dst_dir); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("file_name", ::apache::thrift::protocol::T_STRING, 4); - xfer += oprot->writeString(this->file_name); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("offset", ::apache::thrift::protocol::T_I64, 5); - xfer += oprot->writeI64(this->offset); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("size", ::apache::thrift::protocol::T_I32, 6); - xfer += oprot->writeI32(this->size); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("is_last", ::apache::thrift::protocol::T_BOOL, 7); - xfer += oprot->writeBool(this->is_last); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("overwrite", ::apache::thrift::protocol::T_BOOL, 8); - xfer += oprot->writeBool(this->overwrite); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(copy_request &a, copy_request &b) -{ - using ::std::swap; - swap(a.source, b.source); - swap(a.source_dir, b.source_dir); - swap(a.dst_dir, b.dst_dir); - swap(a.file_name, b.file_name); - swap(a.offset, b.offset); - swap(a.size, b.size); - swap(a.is_last, b.is_last); - swap(a.overwrite, b.overwrite); - swap(a.__isset, b.__isset); -} - -copy_request::copy_request(const copy_request &other0) -{ - source = other0.source; - source_dir = other0.source_dir; - dst_dir = other0.dst_dir; - file_name = other0.file_name; - offset = other0.offset; - size = other0.size; - is_last = other0.is_last; - overwrite = other0.overwrite; - __isset = other0.__isset; -} -copy_request::copy_request(copy_request &&other1) -{ - source = std::move(other1.source); - source_dir = std::move(other1.source_dir); - dst_dir = std::move(other1.dst_dir); - file_name = std::move(other1.file_name); - offset = std::move(other1.offset); - size = std::move(other1.size); - is_last = std::move(other1.is_last); - overwrite = std::move(other1.overwrite); - __isset = std::move(other1.__isset); -} -copy_request ©_request::operator=(const copy_request &other2) -{ - source = other2.source; - source_dir = other2.source_dir; - dst_dir = other2.dst_dir; - file_name = other2.file_name; - offset = other2.offset; - size = other2.size; - is_last = other2.is_last; - overwrite = other2.overwrite; - __isset = other2.__isset; - return *this; -} -copy_request ©_request::operator=(copy_request &&other3) -{ - source = std::move(other3.source); - source_dir = std::move(other3.source_dir); - dst_dir = std::move(other3.dst_dir); - file_name = std::move(other3.file_name); - offset = std::move(other3.offset); - size = std::move(other3.size); - is_last = std::move(other3.is_last); - overwrite = std::move(other3.overwrite); - __isset = std::move(other3.__isset); - return *this; -} -void copy_request::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "copy_request("; - out << "source=" << to_string(source); - out << ", " - << "source_dir=" << to_string(source_dir); - out << ", " - << "dst_dir=" << to_string(dst_dir); - out << ", " - << "file_name=" << to_string(file_name); - out << ", " - << "offset=" << to_string(offset); - out << ", " - << "size=" << to_string(size); - out << ", " - << "is_last=" << to_string(is_last); - out << ", " - << "overwrite=" << to_string(overwrite); - out << ")"; -} - -copy_response::~copy_response() throw() {} - -void copy_response::__set_error(const ::dsn::error_code &val) { this->error = val; } - -void copy_response::__set_file_content(const ::dsn::blob &val) { this->file_content = val; } - -void copy_response::__set_offset(const int64_t val) { this->offset = val; } - -void copy_response::__set_size(const int32_t val) { this->size = val; } - -uint32_t copy_response::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->error.read(iprot); - this->__isset.error = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->file_content.read(iprot); - this->__isset.file_content = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->offset); - this->__isset.offset = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->size); - this->__isset.size = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t copy_response::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("copy_response"); - - xfer += oprot->writeFieldBegin("error", ::apache::thrift::protocol::T_STRUCT, 1); - xfer += this->error.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("file_content", ::apache::thrift::protocol::T_STRUCT, 2); - xfer += this->file_content.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("offset", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64(this->offset); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("size", ::apache::thrift::protocol::T_I32, 4); - xfer += oprot->writeI32(this->size); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(copy_response &a, copy_response &b) -{ - using ::std::swap; - swap(a.error, b.error); - swap(a.file_content, b.file_content); - swap(a.offset, b.offset); - swap(a.size, b.size); - swap(a.__isset, b.__isset); -} - -copy_response::copy_response(const copy_response &other4) -{ - error = other4.error; - file_content = other4.file_content; - offset = other4.offset; - size = other4.size; - __isset = other4.__isset; -} -copy_response::copy_response(copy_response &&other5) -{ - error = std::move(other5.error); - file_content = std::move(other5.file_content); - offset = std::move(other5.offset); - size = std::move(other5.size); - __isset = std::move(other5.__isset); -} -copy_response ©_response::operator=(const copy_response &other6) -{ - error = other6.error; - file_content = other6.file_content; - offset = other6.offset; - size = other6.size; - __isset = other6.__isset; - return *this; -} -copy_response ©_response::operator=(copy_response &&other7) -{ - error = std::move(other7.error); - file_content = std::move(other7.file_content); - offset = std::move(other7.offset); - size = std::move(other7.size); - __isset = std::move(other7.__isset); - return *this; -} -void copy_response::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "copy_response("; - out << "error=" << to_string(error); - out << ", " - << "file_content=" << to_string(file_content); - out << ", " - << "offset=" << to_string(offset); - out << ", " - << "size=" << to_string(size); - out << ")"; -} - -get_file_size_request::~get_file_size_request() throw() {} - -void get_file_size_request::__set_source(const ::dsn::rpc_address &val) { this->source = val; } - -void get_file_size_request::__set_dst_dir(const std::string &val) { this->dst_dir = val; } - -void get_file_size_request::__set_file_list(const std::vector &val) -{ - this->file_list = val; -} - -void get_file_size_request::__set_source_dir(const std::string &val) { this->source_dir = val; } - -void get_file_size_request::__set_overwrite(const bool val) { this->overwrite = val; } - -uint32_t get_file_size_request::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->source.read(iprot); - this->__isset.source = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->dst_dir); - this->__isset.dst_dir = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->file_list.clear(); - uint32_t _size8; - ::apache::thrift::protocol::TType _etype11; - xfer += iprot->readListBegin(_etype11, _size8); - this->file_list.resize(_size8); - uint32_t _i12; - for (_i12 = 0; _i12 < _size8; ++_i12) { - xfer += iprot->readString(this->file_list[_i12]); - } - xfer += iprot->readListEnd(); - } - this->__isset.file_list = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->source_dir); - this->__isset.source_dir = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 5: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->overwrite); - this->__isset.overwrite = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t get_file_size_request::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("get_file_size_request"); - - xfer += oprot->writeFieldBegin("source", ::apache::thrift::protocol::T_STRUCT, 1); - xfer += this->source.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("dst_dir", ::apache::thrift::protocol::T_STRING, 2); - xfer += oprot->writeString(this->dst_dir); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("file_list", ::apache::thrift::protocol::T_LIST, 3); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRING, - static_cast(this->file_list.size())); - std::vector::const_iterator _iter13; - for (_iter13 = this->file_list.begin(); _iter13 != this->file_list.end(); ++_iter13) { - xfer += oprot->writeString((*_iter13)); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("source_dir", ::apache::thrift::protocol::T_STRING, 4); - xfer += oprot->writeString(this->source_dir); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("overwrite", ::apache::thrift::protocol::T_BOOL, 5); - xfer += oprot->writeBool(this->overwrite); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(get_file_size_request &a, get_file_size_request &b) -{ - using ::std::swap; - swap(a.source, b.source); - swap(a.dst_dir, b.dst_dir); - swap(a.file_list, b.file_list); - swap(a.source_dir, b.source_dir); - swap(a.overwrite, b.overwrite); - swap(a.__isset, b.__isset); -} - -get_file_size_request::get_file_size_request(const get_file_size_request &other14) -{ - source = other14.source; - dst_dir = other14.dst_dir; - file_list = other14.file_list; - source_dir = other14.source_dir; - overwrite = other14.overwrite; - __isset = other14.__isset; -} -get_file_size_request::get_file_size_request(get_file_size_request &&other15) -{ - source = std::move(other15.source); - dst_dir = std::move(other15.dst_dir); - file_list = std::move(other15.file_list); - source_dir = std::move(other15.source_dir); - overwrite = std::move(other15.overwrite); - __isset = std::move(other15.__isset); -} -get_file_size_request &get_file_size_request::operator=(const get_file_size_request &other16) -{ - source = other16.source; - dst_dir = other16.dst_dir; - file_list = other16.file_list; - source_dir = other16.source_dir; - overwrite = other16.overwrite; - __isset = other16.__isset; - return *this; -} -get_file_size_request &get_file_size_request::operator=(get_file_size_request &&other17) -{ - source = std::move(other17.source); - dst_dir = std::move(other17.dst_dir); - file_list = std::move(other17.file_list); - source_dir = std::move(other17.source_dir); - overwrite = std::move(other17.overwrite); - __isset = std::move(other17.__isset); - return *this; -} -void get_file_size_request::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "get_file_size_request("; - out << "source=" << to_string(source); - out << ", " - << "dst_dir=" << to_string(dst_dir); - out << ", " - << "file_list=" << to_string(file_list); - out << ", " - << "source_dir=" << to_string(source_dir); - out << ", " - << "overwrite=" << to_string(overwrite); - out << ")"; -} - -get_file_size_response::~get_file_size_response() throw() {} - -void get_file_size_response::__set_error(const int32_t val) { this->error = val; } - -void get_file_size_response::__set_file_list(const std::vector &val) -{ - this->file_list = val; -} - -void get_file_size_response::__set_size_list(const std::vector &val) -{ - this->size_list = val; -} - -uint32_t get_file_size_response::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->error); - this->__isset.error = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->file_list.clear(); - uint32_t _size18; - ::apache::thrift::protocol::TType _etype21; - xfer += iprot->readListBegin(_etype21, _size18); - this->file_list.resize(_size18); - uint32_t _i22; - for (_i22 = 0; _i22 < _size18; ++_i22) { - xfer += iprot->readString(this->file_list[_i22]); - } - xfer += iprot->readListEnd(); - } - this->__isset.file_list = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->size_list.clear(); - uint32_t _size23; - ::apache::thrift::protocol::TType _etype26; - xfer += iprot->readListBegin(_etype26, _size23); - this->size_list.resize(_size23); - uint32_t _i27; - for (_i27 = 0; _i27 < _size23; ++_i27) { - xfer += iprot->readI64(this->size_list[_i27]); - } - xfer += iprot->readListEnd(); - } - this->__isset.size_list = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t get_file_size_response::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("get_file_size_response"); - - xfer += oprot->writeFieldBegin("error", ::apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32(this->error); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("file_list", ::apache::thrift::protocol::T_LIST, 2); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRING, - static_cast(this->file_list.size())); - std::vector::const_iterator _iter28; - for (_iter28 = this->file_list.begin(); _iter28 != this->file_list.end(); ++_iter28) { - xfer += oprot->writeString((*_iter28)); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("size_list", ::apache::thrift::protocol::T_LIST, 3); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_I64, - static_cast(this->size_list.size())); - std::vector::const_iterator _iter29; - for (_iter29 = this->size_list.begin(); _iter29 != this->size_list.end(); ++_iter29) { - xfer += oprot->writeI64((*_iter29)); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(get_file_size_response &a, get_file_size_response &b) -{ - using ::std::swap; - swap(a.error, b.error); - swap(a.file_list, b.file_list); - swap(a.size_list, b.size_list); - swap(a.__isset, b.__isset); -} - -get_file_size_response::get_file_size_response(const get_file_size_response &other30) -{ - error = other30.error; - file_list = other30.file_list; - size_list = other30.size_list; - __isset = other30.__isset; -} -get_file_size_response::get_file_size_response(get_file_size_response &&other31) -{ - error = std::move(other31.error); - file_list = std::move(other31.file_list); - size_list = std::move(other31.size_list); - __isset = std::move(other31.__isset); -} -get_file_size_response &get_file_size_response::operator=(const get_file_size_response &other32) -{ - error = other32.error; - file_list = other32.file_list; - size_list = other32.size_list; - __isset = other32.__isset; - return *this; -} -get_file_size_response &get_file_size_response::operator=(get_file_size_response &&other33) -{ - error = std::move(other33.error); - file_list = std::move(other33.file_list); - size_list = std::move(other33.size_list); - __isset = std::move(other33.__isset); - return *this; -} -void get_file_size_response::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "get_file_size_response("; - out << "error=" << to_string(error); - out << ", " - << "file_list=" << to_string(file_list); - out << ", " - << "size_list=" << to_string(size_list); - out << ")"; -} -} -} // namespace diff --git a/src/nfs/nfs_types.h b/src/nfs/nfs_types.h deleted file mode 100644 index 6e3964e2a9..0000000000 --- a/src/nfs/nfs_types.h +++ /dev/null @@ -1,329 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.9.3) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef nfs_TYPES_H -#define nfs_TYPES_H - -#include -#include - -#include -#include -#include -#include - -#include - -namespace dsn { -namespace service { - -class copy_request; - -class copy_response; - -class get_file_size_request; - -class get_file_size_response; - -typedef struct _copy_request__isset -{ - _copy_request__isset() - : source(false), - source_dir(false), - dst_dir(false), - file_name(false), - offset(false), - size(false), - is_last(false), - overwrite(false) - { - } - bool source : 1; - bool source_dir : 1; - bool dst_dir : 1; - bool file_name : 1; - bool offset : 1; - bool size : 1; - bool is_last : 1; - bool overwrite : 1; -} _copy_request__isset; - -class copy_request -{ -public: - copy_request(const copy_request &); - copy_request(copy_request &&); - copy_request &operator=(const copy_request &); - copy_request &operator=(copy_request &&); - copy_request() - : source_dir(), dst_dir(), file_name(), offset(0), size(0), is_last(0), overwrite(0) - { - } - - virtual ~copy_request() throw(); - ::dsn::rpc_address source; - std::string source_dir; - std::string dst_dir; - std::string file_name; - int64_t offset; - int32_t size; - bool is_last; - bool overwrite; - - _copy_request__isset __isset; - - void __set_source(const ::dsn::rpc_address &val); - - void __set_source_dir(const std::string &val); - - void __set_dst_dir(const std::string &val); - - void __set_file_name(const std::string &val); - - void __set_offset(const int64_t val); - - void __set_size(const int32_t val); - - void __set_is_last(const bool val); - - void __set_overwrite(const bool val); - - bool operator==(const copy_request &rhs) const - { - if (!(source == rhs.source)) - return false; - if (!(source_dir == rhs.source_dir)) - return false; - if (!(dst_dir == rhs.dst_dir)) - return false; - if (!(file_name == rhs.file_name)) - return false; - if (!(offset == rhs.offset)) - return false; - if (!(size == rhs.size)) - return false; - if (!(is_last == rhs.is_last)) - return false; - if (!(overwrite == rhs.overwrite)) - return false; - return true; - } - bool operator!=(const copy_request &rhs) const { return !(*this == rhs); } - - bool operator<(const copy_request &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(copy_request &a, copy_request &b); - -inline std::ostream &operator<<(std::ostream &out, const copy_request &obj) -{ - obj.printTo(out); - return out; -} - -typedef struct _copy_response__isset -{ - _copy_response__isset() : error(false), file_content(false), offset(false), size(false) {} - bool error : 1; - bool file_content : 1; - bool offset : 1; - bool size : 1; -} _copy_response__isset; - -class copy_response -{ -public: - copy_response(const copy_response &); - copy_response(copy_response &&); - copy_response &operator=(const copy_response &); - copy_response &operator=(copy_response &&); - copy_response() : offset(0), size(0) {} - - virtual ~copy_response() throw(); - ::dsn::error_code error; - ::dsn::blob file_content; - int64_t offset; - int32_t size; - - _copy_response__isset __isset; - - void __set_error(const ::dsn::error_code &val); - - void __set_file_content(const ::dsn::blob &val); - - void __set_offset(const int64_t val); - - void __set_size(const int32_t val); - - bool operator==(const copy_response &rhs) const - { - if (!(error == rhs.error)) - return false; - if (!(file_content == rhs.file_content)) - return false; - if (!(offset == rhs.offset)) - return false; - if (!(size == rhs.size)) - return false; - return true; - } - bool operator!=(const copy_response &rhs) const { return !(*this == rhs); } - - bool operator<(const copy_response &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(copy_response &a, copy_response &b); - -inline std::ostream &operator<<(std::ostream &out, const copy_response &obj) -{ - obj.printTo(out); - return out; -} - -typedef struct _get_file_size_request__isset -{ - _get_file_size_request__isset() - : source(false), dst_dir(false), file_list(false), source_dir(false), overwrite(false) - { - } - bool source : 1; - bool dst_dir : 1; - bool file_list : 1; - bool source_dir : 1; - bool overwrite : 1; -} _get_file_size_request__isset; - -class get_file_size_request -{ -public: - get_file_size_request(const get_file_size_request &); - get_file_size_request(get_file_size_request &&); - get_file_size_request &operator=(const get_file_size_request &); - get_file_size_request &operator=(get_file_size_request &&); - get_file_size_request() : dst_dir(), source_dir(), overwrite(0) {} - - virtual ~get_file_size_request() throw(); - ::dsn::rpc_address source; - std::string dst_dir; - std::vector file_list; - std::string source_dir; - bool overwrite; - - _get_file_size_request__isset __isset; - - void __set_source(const ::dsn::rpc_address &val); - - void __set_dst_dir(const std::string &val); - - void __set_file_list(const std::vector &val); - - void __set_source_dir(const std::string &val); - - void __set_overwrite(const bool val); - - bool operator==(const get_file_size_request &rhs) const - { - if (!(source == rhs.source)) - return false; - if (!(dst_dir == rhs.dst_dir)) - return false; - if (!(file_list == rhs.file_list)) - return false; - if (!(source_dir == rhs.source_dir)) - return false; - if (!(overwrite == rhs.overwrite)) - return false; - return true; - } - bool operator!=(const get_file_size_request &rhs) const { return !(*this == rhs); } - - bool operator<(const get_file_size_request &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(get_file_size_request &a, get_file_size_request &b); - -inline std::ostream &operator<<(std::ostream &out, const get_file_size_request &obj) -{ - obj.printTo(out); - return out; -} - -typedef struct _get_file_size_response__isset -{ - _get_file_size_response__isset() : error(false), file_list(false), size_list(false) {} - bool error : 1; - bool file_list : 1; - bool size_list : 1; -} _get_file_size_response__isset; - -class get_file_size_response -{ -public: - get_file_size_response(const get_file_size_response &); - get_file_size_response(get_file_size_response &&); - get_file_size_response &operator=(const get_file_size_response &); - get_file_size_response &operator=(get_file_size_response &&); - get_file_size_response() : error(0) {} - - virtual ~get_file_size_response() throw(); - int32_t error; - std::vector file_list; - std::vector size_list; - - _get_file_size_response__isset __isset; - - void __set_error(const int32_t val); - - void __set_file_list(const std::vector &val); - - void __set_size_list(const std::vector &val); - - bool operator==(const get_file_size_response &rhs) const - { - if (!(error == rhs.error)) - return false; - if (!(file_list == rhs.file_list)) - return false; - if (!(size_list == rhs.size_list)) - return false; - return true; - } - bool operator!=(const get_file_size_response &rhs) const { return !(*this == rhs); } - - bool operator<(const get_file_size_response &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(get_file_size_response &a, get_file_size_response &b); - -inline std::ostream &operator<<(std::ostream &out, const get_file_size_response &obj) -{ - obj.printTo(out); - return out; -} -} -} // namespace - -#endif diff --git a/src/remote_cmd/CMakeLists.txt b/src/remote_cmd/CMakeLists.txt index e9b45d86b6..fbff728cd3 100644 --- a/src/remote_cmd/CMakeLists.txt +++ b/src/remote_cmd/CMakeLists.txt @@ -1,6 +1,12 @@ set(MY_PROJ_NAME dsn_dist_cmd) -set(MY_PROJ_SRC "") +thrift_generate_cpp( + COMMAND_THRIFT_SRCS + COMMAND_THRIFT_HDRS + ${CMAKE_CURRENT_SOURCE_DIR}/command.thrift +) + +seT(MY_PROJ_SRC ${COMMAND_THRIFT_SRCS}) set(MY_SRC_SEARCH_MODE "GLOB") diff --git a/src/remote_cmd/command_types.cpp b/src/remote_cmd/command_types.cpp deleted file mode 100644 index c429a42f86..0000000000 --- a/src/remote_cmd/command_types.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.9.3) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "command_types.h" - -#include -#include - -#include - -namespace dsn { -namespace dist { -namespace cmd { - -command::~command() throw() {} - -void command::__set_cmd(const std::string &val) { this->cmd = val; } - -void command::__set_arguments(const std::vector &val) { this->arguments = val; } - -uint32_t command::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->cmd); - this->__isset.cmd = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_LIST) { - { - this->arguments.clear(); - uint32_t _size0; - ::apache::thrift::protocol::TType _etype3; - xfer += iprot->readListBegin(_etype3, _size0); - this->arguments.resize(_size0); - uint32_t _i4; - for (_i4 = 0; _i4 < _size0; ++_i4) { - xfer += iprot->readString(this->arguments[_i4]); - } - xfer += iprot->readListEnd(); - } - this->__isset.arguments = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t command::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("command"); - - xfer += oprot->writeFieldBegin("cmd", ::apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString(this->cmd); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("arguments", ::apache::thrift::protocol::T_LIST, 2); - { - xfer += oprot->writeListBegin(::apache::thrift::protocol::T_STRING, - static_cast(this->arguments.size())); - std::vector::const_iterator _iter5; - for (_iter5 = this->arguments.begin(); _iter5 != this->arguments.end(); ++_iter5) { - xfer += oprot->writeString((*_iter5)); - } - xfer += oprot->writeListEnd(); - } - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(command &a, command &b) -{ - using ::std::swap; - swap(a.cmd, b.cmd); - swap(a.arguments, b.arguments); - swap(a.__isset, b.__isset); -} - -command::command(const command &other6) -{ - cmd = other6.cmd; - arguments = other6.arguments; - __isset = other6.__isset; -} -command::command(command &&other7) -{ - cmd = std::move(other7.cmd); - arguments = std::move(other7.arguments); - __isset = std::move(other7.__isset); -} -command &command::operator=(const command &other8) -{ - cmd = other8.cmd; - arguments = other8.arguments; - __isset = other8.__isset; - return *this; -} -command &command::operator=(command &&other9) -{ - cmd = std::move(other9.cmd); - arguments = std::move(other9.arguments); - __isset = std::move(other9.__isset); - return *this; -} -void command::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "command("; - out << "cmd=" << to_string(cmd); - out << ", " - << "arguments=" << to_string(arguments); - out << ")"; -} -} -} -} // namespace diff --git a/src/remote_cmd/command_types.h b/src/remote_cmd/command_types.h deleted file mode 100644 index 8e7c342c8f..0000000000 --- a/src/remote_cmd/command_types.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.9.3) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef command_TYPES_H -#define command_TYPES_H - -#include - -#include -#include -#include -#include - -#include - -namespace dsn { -namespace dist { -namespace cmd { - -class command; - -typedef struct _command__isset -{ - _command__isset() : cmd(false), arguments(false) {} - bool cmd : 1; - bool arguments : 1; -} _command__isset; - -class command -{ -public: - command(const command &); - command(command &&); - command &operator=(const command &); - command &operator=(command &&); - command() : cmd() {} - - virtual ~command() throw(); - std::string cmd; - std::vector arguments; - - _command__isset __isset; - - void __set_cmd(const std::string &val); - - void __set_arguments(const std::vector &val); - - bool operator==(const command &rhs) const - { - if (!(cmd == rhs.cmd)) - return false; - if (!(arguments == rhs.arguments)) - return false; - return true; - } - bool operator!=(const command &rhs) const { return !(*this == rhs); } - - bool operator<(const command &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(command &a, command &b); - -inline std::ostream &operator<<(std::ostream &out, const command &obj) -{ - obj.printTo(out); - return out; -} -} -} -} // namespace - -#endif diff --git a/src/runtime/dsn.layer2_types.cpp b/src/runtime/dsn.layer2_types.cpp index b078062bb5..1940a0f544 100644 --- a/src/runtime/dsn.layer2_types.cpp +++ b/src/runtime/dsn.layer2_types.cpp @@ -1097,214 +1097,4 @@ void app_info::printTo(std::ostream &out) const out << ")"; } -thrift_request_meta_v1::~thrift_request_meta_v1() throw() {} - -void thrift_request_meta_v1::__set_app_id(const int32_t val) -{ - this->app_id = val; - __isset.app_id = true; -} - -void thrift_request_meta_v1::__set_partition_index(const int32_t val) -{ - this->partition_index = val; - __isset.partition_index = true; -} - -void thrift_request_meta_v1::__set_client_timeout(const int32_t val) -{ - this->client_timeout = val; - __isset.client_timeout = true; -} - -void thrift_request_meta_v1::__set_client_partition_hash(const int64_t val) -{ - this->client_partition_hash = val; - __isset.client_partition_hash = true; -} - -void thrift_request_meta_v1::__set_is_backup_request(const bool val) -{ - this->is_backup_request = val; - __isset.is_backup_request = true; -} - -uint32_t thrift_request_meta_v1::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->app_id); - this->__isset.app_id = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->partition_index); - this->__isset.partition_index = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->client_timeout); - this->__isset.client_timeout = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->client_partition_hash); - this->__isset.client_partition_hash = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 5: - if (ftype == ::apache::thrift::protocol::T_BOOL) { - xfer += iprot->readBool(this->is_backup_request); - this->__isset.is_backup_request = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t thrift_request_meta_v1::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("thrift_request_meta_v1"); - - if (this->__isset.app_id) { - xfer += oprot->writeFieldBegin("app_id", ::apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32(this->app_id); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.partition_index) { - xfer += oprot->writeFieldBegin("partition_index", ::apache::thrift::protocol::T_I32, 2); - xfer += oprot->writeI32(this->partition_index); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.client_timeout) { - xfer += oprot->writeFieldBegin("client_timeout", ::apache::thrift::protocol::T_I32, 3); - xfer += oprot->writeI32(this->client_timeout); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.client_partition_hash) { - xfer += - oprot->writeFieldBegin("client_partition_hash", ::apache::thrift::protocol::T_I64, 4); - xfer += oprot->writeI64(this->client_partition_hash); - xfer += oprot->writeFieldEnd(); - } - if (this->__isset.is_backup_request) { - xfer += oprot->writeFieldBegin("is_backup_request", ::apache::thrift::protocol::T_BOOL, 5); - xfer += oprot->writeBool(this->is_backup_request); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(thrift_request_meta_v1 &a, thrift_request_meta_v1 &b) -{ - using ::std::swap; - swap(a.app_id, b.app_id); - swap(a.partition_index, b.partition_index); - swap(a.client_timeout, b.client_timeout); - swap(a.client_partition_hash, b.client_partition_hash); - swap(a.is_backup_request, b.is_backup_request); - swap(a.__isset, b.__isset); -} - -thrift_request_meta_v1::thrift_request_meta_v1(const thrift_request_meta_v1 &other49) -{ - app_id = other49.app_id; - partition_index = other49.partition_index; - client_timeout = other49.client_timeout; - client_partition_hash = other49.client_partition_hash; - is_backup_request = other49.is_backup_request; - __isset = other49.__isset; -} -thrift_request_meta_v1::thrift_request_meta_v1(thrift_request_meta_v1 &&other50) -{ - app_id = std::move(other50.app_id); - partition_index = std::move(other50.partition_index); - client_timeout = std::move(other50.client_timeout); - client_partition_hash = std::move(other50.client_partition_hash); - is_backup_request = std::move(other50.is_backup_request); - __isset = std::move(other50.__isset); -} -thrift_request_meta_v1 &thrift_request_meta_v1::operator=(const thrift_request_meta_v1 &other51) -{ - app_id = other51.app_id; - partition_index = other51.partition_index; - client_timeout = other51.client_timeout; - client_partition_hash = other51.client_partition_hash; - is_backup_request = other51.is_backup_request; - __isset = other51.__isset; - return *this; -} -thrift_request_meta_v1 &thrift_request_meta_v1::operator=(thrift_request_meta_v1 &&other52) -{ - app_id = std::move(other52.app_id); - partition_index = std::move(other52.partition_index); - client_timeout = std::move(other52.client_timeout); - client_partition_hash = std::move(other52.client_partition_hash); - is_backup_request = std::move(other52.is_backup_request); - __isset = std::move(other52.__isset); - return *this; -} -void thrift_request_meta_v1::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "thrift_request_meta_v1("; - out << "app_id="; - (__isset.app_id ? (out << to_string(app_id)) : (out << "")); - out << ", " - << "partition_index="; - (__isset.partition_index ? (out << to_string(partition_index)) : (out << "")); - out << ", " - << "client_timeout="; - (__isset.client_timeout ? (out << to_string(client_timeout)) : (out << "")); - out << ", " - << "client_partition_hash="; - (__isset.client_partition_hash ? (out << to_string(client_partition_hash)) : (out << "")); - out << ", " - << "is_backup_request="; - (__isset.is_backup_request ? (out << to_string(is_backup_request)) : (out << "")); - out << ")"; -} - } // namespace diff --git a/src/runtime/rpc/CMakeLists.txt b/src/runtime/rpc/CMakeLists.txt index acae93f789..08da95ef1d 100644 --- a/src/runtime/rpc/CMakeLists.txt +++ b/src/runtime/rpc/CMakeLists.txt @@ -10,4 +10,12 @@ set(MY_PROJ_LIBS "") # Extra files that will be installed set(MY_BINPLACES "") +thrift_generate_cpp( + REQUEST_META_THRIFT_SRCS + REQUEST_META_THRIFT_HDRS + ${CMAKE_CURRENT_SOURCE_DIR}/request_meta.thrift +) + +set(MY_PROJ_SRC ${REQUEST_META_THRIFT_SRCS}) + dsn_add_object() diff --git a/src/runtime/rpc/request_meta.thrift b/src/runtime/rpc/request_meta.thrift new file mode 100644 index 0000000000..299d83bf4c --- /dev/null +++ b/src/runtime/rpc/request_meta.thrift @@ -0,0 +1,37 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +namespace cpp dsn + +// Metadata field of the request in rDSN's thrift protocol (version 1). +// TODO(wutao1): add design doc of the thrift protocol. +struct thrift_request_meta_v1 +{ + // The replica's gpid. + 1:optional i32 app_id; + 2:optional i32 partition_index; + + // The timeout of this request that's set on client side. + 3:optional i32 client_timeout; + + // The hash value calculated from the hash key. + 4:optional i64 client_partition_hash; + + // Whether it is a backup request. If true, this request (only if it's a read) can be handled by + // a secondary replica, which does not guarantee strong consistency. + 5:optional bool is_backup_request; +} diff --git a/src/runtime/rpc/thrift_message_parser.h b/src/runtime/rpc/thrift_message_parser.h index 730b68320f..7fa560389c 100644 --- a/src/runtime/rpc/thrift_message_parser.h +++ b/src/runtime/rpc/thrift_message_parser.h @@ -33,6 +33,8 @@ #include #include +#include "request_meta_types.h" + namespace dsn { struct request_meta_v0 diff --git a/src/runtime/security/CMakeLists.txt b/src/runtime/security/CMakeLists.txt index 47c08e80c1..3bd807b366 100644 --- a/src/runtime/security/CMakeLists.txt +++ b/src/runtime/security/CMakeLists.txt @@ -1,8 +1,12 @@ set(MY_PROJ_NAME dsn.security) -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. -set(MY_PROJ_SRC "") +thrift_generate_cpp( + SECURITY_THRIFT_SRCS + SECURITY_THRIFT_HDRS + ${CMAKE_CURRENT_SOURCE_DIR}/security.thrift +) + +set(MY_PROJ_SRC ${SECURITY_THRIFT_SRCS}) # Search mode for source files under CURRENT project directory? # "GLOB_RECURSE" for recursive search diff --git a/src/runtime/security/security_types.cpp b/src/runtime/security/security_types.cpp deleted file mode 100644 index 16143f9616..0000000000 --- a/src/runtime/security/security_types.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.9.3) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#include "security_types.h" - -#include -#include - -#include - -namespace dsn { -namespace security { - -int _knegotiation_statusValues[] = {negotiation_status::INVALID, - negotiation_status::SASL_LIST_MECHANISMS, - negotiation_status::SASL_LIST_MECHANISMS_RESP, - negotiation_status::SASL_SELECT_MECHANISMS, - negotiation_status::SASL_SELECT_MECHANISMS_RESP, - negotiation_status::SASL_INITIATE, - negotiation_status::SASL_CHALLENGE, - negotiation_status::SASL_CHALLENGE_RESP, - negotiation_status::SASL_SUCC, - negotiation_status::SASL_AUTH_DISABLE, - negotiation_status::SASL_AUTH_FAIL}; -const char *_knegotiation_statusNames[] = {"INVALID", - "SASL_LIST_MECHANISMS", - "SASL_LIST_MECHANISMS_RESP", - "SASL_SELECT_MECHANISMS", - "SASL_SELECT_MECHANISMS_RESP", - "SASL_INITIATE", - "SASL_CHALLENGE", - "SASL_CHALLENGE_RESP", - "SASL_SUCC", - "SASL_AUTH_DISABLE", - "SASL_AUTH_FAIL"}; -const std::map _negotiation_status_VALUES_TO_NAMES( - ::apache::thrift::TEnumIterator(11, _knegotiation_statusValues, _knegotiation_statusNames), - ::apache::thrift::TEnumIterator(-1, NULL, NULL)); - -negotiation_request::~negotiation_request() throw() {} - -void negotiation_request::__set_status(const negotiation_status::type val) { this->status = val; } - -void negotiation_request::__set_msg(const ::dsn::blob &val) { this->msg = val; } - -uint32_t negotiation_request::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_I32) { - int32_t ecast0; - xfer += iprot->readI32(ecast0); - this->status = (negotiation_status::type)ecast0; - this->__isset.status = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->msg.read(iprot); - this->__isset.msg = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t negotiation_request::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("negotiation_request"); - - xfer += oprot->writeFieldBegin("status", ::apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32((int32_t)this->status); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("msg", ::apache::thrift::protocol::T_STRUCT, 2); - xfer += this->msg.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(negotiation_request &a, negotiation_request &b) -{ - using ::std::swap; - swap(a.status, b.status); - swap(a.msg, b.msg); - swap(a.__isset, b.__isset); -} - -negotiation_request::negotiation_request(const negotiation_request &other1) -{ - status = other1.status; - msg = other1.msg; - __isset = other1.__isset; -} -negotiation_request::negotiation_request(negotiation_request &&other2) -{ - status = std::move(other2.status); - msg = std::move(other2.msg); - __isset = std::move(other2.__isset); -} -negotiation_request &negotiation_request::operator=(const negotiation_request &other3) -{ - status = other3.status; - msg = other3.msg; - __isset = other3.__isset; - return *this; -} -negotiation_request &negotiation_request::operator=(negotiation_request &&other4) -{ - status = std::move(other4.status); - msg = std::move(other4.msg); - __isset = std::move(other4.__isset); - return *this; -} -void negotiation_request::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "negotiation_request("; - out << "status=" << to_string(status); - out << ", " - << "msg=" << to_string(msg); - out << ")"; -} - -negotiation_response::~negotiation_response() throw() {} - -void negotiation_response::__set_status(const negotiation_status::type val) { this->status = val; } - -void negotiation_response::__set_msg(const ::dsn::blob &val) { this->msg = val; } - -uint32_t negotiation_response::read(::apache::thrift::protocol::TProtocol *iprot) -{ - - apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); - uint32_t xfer = 0; - std::string fname; - ::apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using ::apache::thrift::protocol::TProtocolException; - - while (true) { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == ::apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) { - case 1: - if (ftype == ::apache::thrift::protocol::T_I32) { - int32_t ecast5; - xfer += iprot->readI32(ecast5); - this->status = (negotiation_status::type)ecast5; - this->__isset.status = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->msg.read(iprot); - this->__isset.msg = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t negotiation_response::write(::apache::thrift::protocol::TProtocol *oprot) const -{ - uint32_t xfer = 0; - apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("negotiation_response"); - - xfer += oprot->writeFieldBegin("status", ::apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32((int32_t)this->status); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldBegin("msg", ::apache::thrift::protocol::T_STRUCT, 2); - xfer += this->msg.write(oprot); - xfer += oprot->writeFieldEnd(); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void swap(negotiation_response &a, negotiation_response &b) -{ - using ::std::swap; - swap(a.status, b.status); - swap(a.msg, b.msg); - swap(a.__isset, b.__isset); -} - -negotiation_response::negotiation_response(const negotiation_response &other6) -{ - status = other6.status; - msg = other6.msg; - __isset = other6.__isset; -} -negotiation_response::negotiation_response(negotiation_response &&other7) -{ - status = std::move(other7.status); - msg = std::move(other7.msg); - __isset = std::move(other7.__isset); -} -negotiation_response &negotiation_response::operator=(const negotiation_response &other8) -{ - status = other8.status; - msg = other8.msg; - __isset = other8.__isset; - return *this; -} -negotiation_response &negotiation_response::operator=(negotiation_response &&other9) -{ - status = std::move(other9.status); - msg = std::move(other9.msg); - __isset = std::move(other9.__isset); - return *this; -} -void negotiation_response::printTo(std::ostream &out) const -{ - using ::apache::thrift::to_string; - out << "negotiation_response("; - out << "status=" << to_string(status); - out << ", " - << "msg=" << to_string(msg); - out << ")"; -} -} -} // namespace diff --git a/src/runtime/security/security_types.h b/src/runtime/security/security_types.h deleted file mode 100644 index c797eac56b..0000000000 --- a/src/runtime/security/security_types.h +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Autogenerated by Thrift Compiler (0.9.3) - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - * @generated - */ -#ifndef security_TYPES_H -#define security_TYPES_H - -#include -#include - -#include -#include -#include -#include - -#include - -namespace dsn { -namespace security { - -struct negotiation_status -{ - enum type - { - INVALID = 0, - SASL_LIST_MECHANISMS = 1, - SASL_LIST_MECHANISMS_RESP = 2, - SASL_SELECT_MECHANISMS = 3, - SASL_SELECT_MECHANISMS_RESP = 4, - SASL_INITIATE = 5, - SASL_CHALLENGE = 6, - SASL_CHALLENGE_RESP = 7, - SASL_SUCC = 8, - SASL_AUTH_DISABLE = 9, - SASL_AUTH_FAIL = 10 - }; -}; - -extern const std::map _negotiation_status_VALUES_TO_NAMES; - -class negotiation_request; - -class negotiation_response; - -typedef struct _negotiation_request__isset -{ - _negotiation_request__isset() : status(false), msg(false) {} - bool status : 1; - bool msg : 1; -} _negotiation_request__isset; - -class negotiation_request -{ -public: - negotiation_request(const negotiation_request &); - negotiation_request(negotiation_request &&); - negotiation_request &operator=(const negotiation_request &); - negotiation_request &operator=(negotiation_request &&); - negotiation_request() : status((negotiation_status::type)0) {} - - virtual ~negotiation_request() throw(); - negotiation_status::type status; - ::dsn::blob msg; - - _negotiation_request__isset __isset; - - void __set_status(const negotiation_status::type val); - - void __set_msg(const ::dsn::blob &val); - - bool operator==(const negotiation_request &rhs) const - { - if (!(status == rhs.status)) - return false; - if (!(msg == rhs.msg)) - return false; - return true; - } - bool operator!=(const negotiation_request &rhs) const { return !(*this == rhs); } - - bool operator<(const negotiation_request &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(negotiation_request &a, negotiation_request &b); - -inline std::ostream &operator<<(std::ostream &out, const negotiation_request &obj) -{ - obj.printTo(out); - return out; -} - -typedef struct _negotiation_response__isset -{ - _negotiation_response__isset() : status(false), msg(false) {} - bool status : 1; - bool msg : 1; -} _negotiation_response__isset; - -class negotiation_response -{ -public: - negotiation_response(const negotiation_response &); - negotiation_response(negotiation_response &&); - negotiation_response &operator=(const negotiation_response &); - negotiation_response &operator=(negotiation_response &&); - negotiation_response() : status((negotiation_status::type)0) {} - - virtual ~negotiation_response() throw(); - negotiation_status::type status; - ::dsn::blob msg; - - _negotiation_response__isset __isset; - - void __set_status(const negotiation_status::type val); - - void __set_msg(const ::dsn::blob &val); - - bool operator==(const negotiation_response &rhs) const - { - if (!(status == rhs.status)) - return false; - if (!(msg == rhs.msg)) - return false; - return true; - } - bool operator!=(const negotiation_response &rhs) const { return !(*this == rhs); } - - bool operator<(const negotiation_response &) const; - - uint32_t read(::apache::thrift::protocol::TProtocol *iprot); - uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; - - virtual void printTo(std::ostream &out) const; -}; - -void swap(negotiation_response &a, negotiation_response &b); - -inline std::ostream &operator<<(std::ostream &out, const negotiation_response &obj) -{ - obj.printTo(out); - return out; -} -} -} // namespace - -#endif