From commits-return-6659-archive-asf-public=cust-asf.ponee.io@quickstep.incubator.apache.org Mon Nov 5 08:22:46 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E0AAB180670 for ; Mon, 5 Nov 2018 08:22:43 +0100 (CET) Received: (qmail 34521 invoked by uid 500); 5 Nov 2018 07:22:42 -0000 Mailing-List: contact commits-help@quickstep.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@quickstep.incubator.apache.org Delivered-To: mailing list commits@quickstep.incubator.apache.org Received: (qmail 34512 invoked by uid 99); 5 Nov 2018 07:22:42 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2018 07:22:42 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 28892C779E for ; Mon, 5 Nov 2018 07:22:42 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -11.691 X-Spam-Level: X-Spam-Status: No, score=-11.691 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01, USER_IN_DEF_SPF_WL=-7.5] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id w1T9Yo-MjE1u for ; Mon, 5 Nov 2018 07:22:37 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id EA24D5F438 for ; Mon, 5 Nov 2018 07:22:36 +0000 (UTC) Received: (qmail 34435 invoked by uid 99); 5 Nov 2018 07:22:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2018 07:22:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DA716E048B; Mon, 5 Nov 2018 07:22:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jianqiao@apache.org To: commits@quickstep.incubator.apache.org Date: Mon, 05 Nov 2018 07:22:36 -0000 Message-Id: <1ffc5463b8f64274b8772897149967dd@git.apache.org> In-Reply-To: <6c68960fd22c4b09b173c87729b42fd4@git.apache.org> References: <6c68960fd22c4b09b173c87729b42fd4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-quickstep git commit: Add socket cli support Add socket cli support Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/29024a3e Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/29024a3e Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/29024a3e Branch: refs/heads/trace-dev Commit: 29024a3e9e092010f70c067de73f0c4cef1dd6c0 Parents: f477c5d Author: Jianqiao Zhu Authored: Mon Oct 29 23:32:47 2018 -0500 Committer: Jianqiao Zhu Committed: Mon Nov 5 01:20:39 2018 -0600 ---------------------------------------------------------------------- CMakeLists.txt | 1 + cli/CMakeLists.txt | 25 +- cli/IOInterface.hpp | 6 +- cli/LocalIO.hpp | 9 +- cli/NetworkIO.hpp | 11 +- cli/QuickstepCli.cpp | 268 ++-- cli/SocketIO.cpp | 36 + cli/SocketIO.hpp | 121 ++ cli/quickstep/NetworkCliOuterClass.java | 1388 ------------------ cli/simple_socket/CMakeLists.txt | 35 + cli/simple_socket/SimpleSocketConnection.hpp | 159 ++ cli/simple_socket/SimpleSocketContent.hpp | 75 + cli/simple_socket/SimpleSocketServer.hpp | 115 ++ query_optimizer/CMakeLists.txt | 2 + query_optimizer/QueryHandle.hpp | 9 +- relational_operators/CMakeLists.txt | 3 + relational_operators/TextScanOperator.cpp | 12 +- relational_operators/TextScanOperator.hpp | 11 +- relational_operators/WorkOrderFactory.cpp | 3 +- .../tests/TextScanOperator_unittest.cpp | 3 +- utility/StringUtil.hpp | 4 + utility/ThreadSafeQueue.hpp | 2 +- 22 files changed, 748 insertions(+), 1550 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index cb8e9f4..54a69bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -734,6 +734,7 @@ target_link_libraries(quickstep_cli_shell quickstep_cli_LineReader quickstep_cli_LocalIO quickstep_cli_PrintToScreen + quickstep_cli_SocketIO quickstep_parser_ParseStatement quickstep_parser_SqlParserWrapper quickstep_queryexecution_ForemanSingleNode http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 03c5408..d90de95 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -65,6 +65,9 @@ if (ENABLE_NETWORK_CLI) NetworkCli.proto) endif() +# Sub-directories: +add_subdirectory(simple_socket) + # Declare micro-libs and link dependencies: add_library(quickstep_cli_CommandExecutor CommandExecutor.cpp CommandExecutor.hpp) add_library(quickstep_cli_CommandExecutorUtil CommandExecutorUtil.cpp CommandExecutorUtil.hpp) @@ -74,6 +77,7 @@ add_library(quickstep_cli_DropRelation DropRelation.cpp DropRelation.hpp) add_library(quickstep_cli_Flags Flags.cpp Flags.hpp) add_library(quickstep_cli_IOInterface ../empty_src.cpp IOInterface.hpp) add_library(quickstep_cli_InputParserUtil InputParserUtil.cpp InputParserUtil.hpp) +add_library(quickstep_cli_SocketIO SocketIO.cpp SocketIO.hpp) if(USE_LINENOISE) add_library(quickstep_cli_LineReader @@ -178,7 +182,8 @@ target_link_libraries(quickstep_cli_Flags quickstep_storage_StorageConstants ${GFLAGS_LIB_NAME}) target_link_libraries(quickstep_cli_IOInterface - quickstep_utility_Macros) + quickstep_utility_Macros + quickstep_utility_StringUtil) target_link_libraries(quickstep_cli_InputParserUtil glog quickstep_utility_Macros @@ -203,7 +208,8 @@ target_link_libraries(quickstep_cli_LineReaderBuffered target_link_libraries(quickstep_cli_LocalIO quickstep_cli_LineReader quickstep_cli_IOInterface - quickstep_utility_Macros) + quickstep_utility_Macros + quickstep_utility_StringUtil) if (ENABLE_NETWORK_CLI) target_link_libraries(quickstep_cli_NetworkCli_proto ${GRPCPLUSPLUS_LIBRARIES} @@ -226,6 +232,7 @@ if (ENABLE_NETWORK_CLI) quickstep_threading_SpinSharedMutex quickstep_utility_Macros quickstep_utility_MemStream + quickstep_utility_StringUtil quickstep_utility_ThreadSafeQueue) endif() target_link_libraries(quickstep_cli_PrintToScreen @@ -241,6 +248,17 @@ target_link_libraries(quickstep_cli_PrintToScreen quickstep_types_Type quickstep_types_TypedValue quickstep_utility_Macros) +target_link_libraries(quickstep_cli_SocketIO + glog + quickstep_cli_IOInterface + quickstep_cli_LineReaderBuffered + quickstep_cli_simplesocket_SimpleSocketConnection + quickstep_cli_simplesocket_SimpleSocketContent + quickstep_cli_simplesocket_SimpleSocketServer + quickstep_utility_Macros + quickstep_utility_MemStream + quickstep_utility_StringUtil + quickstep_utility_ThreadSafeQueue) # Module all-in-one library: add_library(quickstep_cli ../empty_src.cpp CliModule.hpp) @@ -257,7 +275,8 @@ target_link_libraries(quickstep_cli quickstep_cli_LineReader quickstep_cli_LineReaderBuffered quickstep_cli_LocalIO - quickstep_cli_PrintToScreen) + quickstep_cli_PrintToScreen + quickstep_cli_SocketIO) if (ENABLE_NETWORK_CLI) target_link_libraries(quickstep_cli quickstep_cli_NetworkCli_proto http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/IOInterface.hpp ---------------------------------------------------------------------- diff --git a/cli/IOInterface.hpp b/cli/IOInterface.hpp index b9b36e1..2648e55 100644 --- a/cli/IOInterface.hpp +++ b/cli/IOInterface.hpp @@ -22,8 +22,10 @@ #include #include +#include #include "utility/Macros.hpp" +#include "utility/StringUtil.hpp" namespace quickstep { @@ -42,7 +44,7 @@ class IOHandle { /** * @return Input data. */ - virtual const std::string* data() const = 0; + virtual StringPiece data() const = 0; /** * @return A file handle for standard output. @@ -54,7 +56,7 @@ class IOHandle { */ virtual FILE* err() = 0; - virtual std::string getCommand() const = 0; + virtual std::vector getCommands() const = 0; private: DISALLOW_COPY_AND_ASSIGN(IOHandle); http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/LocalIO.hpp ---------------------------------------------------------------------- diff --git a/cli/LocalIO.hpp b/cli/LocalIO.hpp index 06fa014..86ee2bd 100644 --- a/cli/LocalIO.hpp +++ b/cli/LocalIO.hpp @@ -34,6 +34,7 @@ typedef quickstep::LineReaderLineNoise LineReaderImpl; typedef quickstep::LineReaderDumb LineReaderImpl; #endif #include "utility/Macros.hpp" +#include "utility/StringUtil.hpp" namespace quickstep { @@ -46,8 +47,8 @@ class LocalIOHandle final : public IOHandle { ~LocalIOHandle() override {} - const std::string* data() const override { - return nullptr; + StringPiece data() const override { + return StringPiece(nullptr, 0); } FILE *out() override { @@ -58,8 +59,8 @@ class LocalIOHandle final : public IOHandle { return stderr; } - std::string getCommand() const override { - return command_; + std::vector getCommands() const override { + return {command_}; } private: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/NetworkIO.hpp ---------------------------------------------------------------------- diff --git a/cli/NetworkIO.hpp b/cli/NetworkIO.hpp index f8129b5..3098c08 100644 --- a/cli/NetworkIO.hpp +++ b/cli/NetworkIO.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "cli/IOInterface.hpp" #include "cli/NetworkCli.grpc.pb.h" @@ -34,6 +35,7 @@ #include "threading/SpinSharedMutex.hpp" #include "utility/Macros.hpp" #include "utility/MemStream.hpp" +#include "utility/StringUtil.hpp" #include "utility/ThreadSafeQueue.hpp" #include "gflags/gflags.h" @@ -223,8 +225,9 @@ class NetworkIOHandle final : public IOHandle { request_state_->responseReady(out_stream_.str(), err_stream_.str()); } - const std::string* data() const override { - return &request_state_->getRequest().data(); + StringPiece data() const override { + const std::string &data = request_state_->getRequest().data(); + return StringPiece(data.c_str(), data.length()); } FILE* out() override { @@ -235,8 +238,8 @@ class NetworkIOHandle final : public IOHandle { return err_stream_.file(); } - std::string getCommand() const override { - return request_state_->getRequest().query(); + std::vector getCommands() const override { + return {request_state_->getRequest().query()}; } private: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/QuickstepCli.cpp ---------------------------------------------------------------------- diff --git a/cli/QuickstepCli.cpp b/cli/QuickstepCli.cpp index 37e366a..8588fe5 100644 --- a/cli/QuickstepCli.cpp +++ b/cli/QuickstepCli.cpp @@ -46,6 +46,7 @@ #include "cli/NetworkIO.hpp" #endif #include "cli/PrintToScreen.hpp" +#include "cli/SocketIO.hpp" #include "parser/ParseStatement.hpp" #include "parser/SqlParserWrapper.hpp" #include "query_execution/ForemanSingleNode.hpp" @@ -290,6 +291,8 @@ int main(int argc, char* argv[]) { #else LOG(FATAL) << "Quickstep must be compiled with '-D ENABLE_NETWORK_CLI=true' to use this feature."; #endif + } else if (quickstep::FLAGS_mode == "socket") { + io.reset(new quickstep::SocketIO); } else if (quickstep::FLAGS_mode == "local") { io.reset(new quickstep::LocalIO); } else { @@ -302,158 +305,161 @@ int main(int argc, char* argv[]) { #ifdef QUICKSTEP_ENABLE_GOOGLE_PROFILER bool started_profiling = false; #endif - for (;;) { - string *command_string = new string(); + bool quitting = false; + while (!quitting) { std::unique_ptr io_handle(io->getNextIOHandle()); ScopedReassignment reassign_stdout(&stdout, io_handle->out()); -// ScopedReassignment reassign_stderr(&stderr, io_handle->err()); + ScopedReassignment reassign_stderr(&stderr, io_handle->err()); + + const std::vector cmds = io_handle->getCommands(); + for (const std::string &cmd : cmds) { + string *command_string = new string(cmd); + LOG(INFO) << "Command received: " << *command_string; + if (command_string->size() == 0) { + delete command_string; + quitting = true; + break; + } - *command_string = io_handle->getCommand(); - LOG(INFO) << "Command received: " << *command_string; - if (command_string->size() == 0) { - delete command_string; - break; - } + if (quickstep::FLAGS_print_query) { + fprintf(io_handle->out(), "\n%s\n", command_string->c_str()); + } - if (quickstep::FLAGS_print_query) { - fprintf(io_handle->out(), "\n%s\n", command_string->c_str()); - } + parser_wrapper->feedNextBuffer(command_string); + + // A parse error should reset the parser. This is because the thrown quickstep + // SqlError does not do the proper reset work of the YYABORT macro. + bool reset_parser = false; + for (;;) { + ParseResult result = parser_wrapper->getNextStatement(); + const ParseStatement &statement = *result.parsed_statement; + if (result.condition == ParseResult::kSuccess) { + if (statement.getStatementType() == ParseStatement::kQuit) { + quitting = true; + break; + } else if (statement.getStatementType() == ParseStatement::kCommand) { + try { + quickstep::cli::executeCommand( + statement, + *(query_processor->getDefaultDatabase()), + main_thread_client_id, + foreman.getBusClientID(), + &bus, + &storage_manager, + query_processor.get(), + io_handle->out()); + } catch (const quickstep::SqlError &sql_error) { + fprintf(io_handle->err(), "%s", + sql_error.formatMessage(*command_string).c_str()); + reset_parser = true; + break; + } + continue; + } + // Here the statement is presumed to be a query. + const std::size_t query_id = query_processor->query_id(); + const CatalogRelation *query_result_relation = nullptr; + std::unique_ptr dag_visualizer; - parser_wrapper->feedNextBuffer(command_string); - - bool quitting = false; - // A parse error should reset the parser. This is because the thrown quickstep - // SqlError does not do the proper reset work of the YYABORT macro. - bool reset_parser = false; - for (;;) { - ParseResult result = parser_wrapper->getNextStatement(); - const ParseStatement &statement = *result.parsed_statement; - if (result.condition == ParseResult::kSuccess) { - if (statement.getStatementType() == ParseStatement::kQuit) { - quitting = true; - break; - } else if (statement.getStatementType() == ParseStatement::kCommand) { try { - quickstep::cli::executeCommand( - statement, - *(query_processor->getDefaultDatabase()), + auto query_handle = std::make_unique(query_id, + main_thread_client_id, + statement.getPriority()); + query_handle->setMemData(io_handle->data()); + query_processor->generateQueryHandle(statement, query_handle.get()); + DCHECK(query_handle->getQueryPlanMutable() != nullptr); + + if (quickstep::FLAGS_visualize_execution_dag) { + dag_visualizer = + std::make_unique(query_handle->getQueryPlan()); + } + + query_result_relation = query_handle->getQueryResultRelation(); + + start = std::chrono::steady_clock::now(); + QueryExecutionUtil::ConstructAndSendAdmitRequestMessage( main_thread_client_id, foreman.getBusClientID(), - &bus, - &storage_manager, - query_processor.get(), - io_handle->out()); + query_handle.release(), + &bus); } catch (const quickstep::SqlError &sql_error) { - fprintf(io_handle->err(), "%s", - sql_error.formatMessage(*command_string).c_str()); + switch (statement.getStatementType()) { + case ParseStatement::kDropTable: + // Quick hack for QuickGrail for cleaner log information + // since we don't have DROP TABLE IF EXISTS yet. + break; + default: + fprintf(io_handle->err(), "%s", + sql_error.formatMessage(*command_string).c_str()); + } reset_parser = true; break; } - continue; - } - // Here the statement is presumed to be a query. - const std::size_t query_id = query_processor->query_id(); - const CatalogRelation *query_result_relation = nullptr; - std::unique_ptr dag_visualizer; - - try { - auto query_handle = std::make_unique(query_id, - main_thread_client_id, - statement.getPriority()); - query_handle->setMemData(io_handle->data()); - query_processor->generateQueryHandle(statement, query_handle.get()); - DCHECK(query_handle->getQueryPlanMutable() != nullptr); - - if (quickstep::FLAGS_visualize_execution_dag) { - dag_visualizer = - std::make_unique(query_handle->getQueryPlan()); - } - query_result_relation = query_handle->getQueryResultRelation(); - - start = std::chrono::steady_clock::now(); - QueryExecutionUtil::ConstructAndSendAdmitRequestMessage( - main_thread_client_id, - foreman.getBusClientID(), - query_handle.release(), - &bus); - } catch (const quickstep::SqlError &sql_error) { - switch (statement.getStatementType()) { - case ParseStatement::kDropTable: - // Quick hack for QuickGrail for cleaner log information - // since we don't have DROP TABLE IF EXISTS yet. - break; - default: - fprintf(io_handle->err(), "%s", - sql_error.formatMessage(*command_string).c_str()); - } - reset_parser = true; - break; - } - - try { - QueryExecutionUtil::ReceiveQueryCompletionMessage( - main_thread_client_id, &bus); - end = std::chrono::steady_clock::now(); - - if (query_result_relation) { - PrintToScreen::PrintRelation(*query_result_relation, - &storage_manager, - io_handle->out()); - PrintToScreen::PrintOutputSize( - *query_result_relation, - &storage_manager, - io_handle->err()); - - DropRelation::Drop(*query_result_relation, - query_processor->getDefaultDatabase(), - &storage_manager); - } + try { + QueryExecutionUtil::ReceiveQueryCompletionMessage( + main_thread_client_id, &bus); + end = std::chrono::steady_clock::now(); + + if (query_result_relation) { + PrintToScreen::PrintRelation(*query_result_relation, + &storage_manager, + io_handle->out()); + PrintToScreen::PrintOutputSize( + *query_result_relation, + &storage_manager, + io_handle->err()); + + DropRelation::Drop(*query_result_relation, + query_processor->getDefaultDatabase(), + &storage_manager); + } - query_processor->saveCatalog(); - if (quickstep::FLAGS_display_timing) { - std::chrono::duration time_ms = end - start; - fprintf(io_handle->out(), "Time: %s ms\n", - quickstep::DoubleToStringWithSignificantDigits( - time_ms.count(), 3).c_str()); - } - if (quickstep::FLAGS_profile_and_report_workorder_perf) { - // TODO(harshad) - Allow user specified file instead of stdout. - foreman.printWorkOrderProfilingResults(query_id, stdout); - } - if (quickstep::FLAGS_visualize_execution_dag) { - const auto *profiling_stats = - foreman.getWorkOrderProfilingResults(query_id); - if (profiling_stats) { - dag_visualizer->bindProfilingStats(*profiling_stats); + query_processor->saveCatalog(); + if (quickstep::FLAGS_display_timing) { + std::chrono::duration time_ms = end - start; + fprintf(io_handle->out(), "Time: %s ms\n", + quickstep::DoubleToStringWithSignificantDigits( + time_ms.count(), 3).c_str()); + } + if (quickstep::FLAGS_profile_and_report_workorder_perf) { + // TODO(harshad) - Allow user specified file instead of stdout. + foreman.printWorkOrderProfilingResults(query_id, stdout); } - std::cerr << "\n" << dag_visualizer->toDOT() << "\n"; + if (quickstep::FLAGS_visualize_execution_dag) { + const auto *profiling_stats = + foreman.getWorkOrderProfilingResults(query_id); + if (profiling_stats) { + dag_visualizer->bindProfilingStats(*profiling_stats); + } + std::cerr << "\n" << dag_visualizer->toDOT() << "\n"; + } + } catch (const std::exception &e) { + fprintf(io_handle->err(), "QUERY EXECUTION ERROR: %s\n", e.what()); + break; + } + } else { + if (result.condition == ParseResult::kError) { + fprintf(io_handle->err(), "%s", result.error_message.c_str()); } - } catch (const std::exception &e) { - fprintf(io_handle->err(), "QUERY EXECUTION ERROR: %s\n", e.what()); + reset_parser = true; break; } - } else { - if (result.condition == ParseResult::kError) { - fprintf(io_handle->err(), "%s", result.error_message.c_str()); + #ifdef QUICKSTEP_ENABLE_GOOGLE_PROFILER + // Profile only if profile_file_name flag is set + if (!started_profiling && !quickstep::FLAGS_profile_file_name.empty()) { + started_profiling = true; + ProfilerStart(quickstep::FLAGS_profile_file_name.c_str()); } - reset_parser = true; - break; + #endif } -#ifdef QUICKSTEP_ENABLE_GOOGLE_PROFILER - // Profile only if profile_file_name flag is set - if (!started_profiling && !quickstep::FLAGS_profile_file_name.empty()) { - started_profiling = true; - ProfilerStart(quickstep::FLAGS_profile_file_name.c_str()); - } -#endif - } - if (quitting) { - break; - } else if (reset_parser) { - parser_wrapper.reset(new SqlParserWrapper()); - reset_parser = false; + if (quitting) { + break; + } else if (reset_parser) { + parser_wrapper.reset(new SqlParserWrapper()); + reset_parser = false; + } } } http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/SocketIO.cpp ---------------------------------------------------------------------- diff --git a/cli/SocketIO.cpp b/cli/SocketIO.cpp new file mode 100644 index 0000000..ea94e06 --- /dev/null +++ b/cli/SocketIO.cpp @@ -0,0 +1,36 @@ +/** + * 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. + **/ + +#include "cli/SocketIO.hpp" + +#include "gflags/gflags.h" +#include "glog/logging.h" + +namespace quickstep { + +DEFINE_int32(cli_socket_port, 3000, + "Listens for TCP connections on this port when socket mode is enabled. " + "This is only used if the cli is set to use the socket mode (-mode=socket)."); + +DEFINE_string(cli_socket_ip, "0.0.0.0", + "The ip address which the cli should open a connection on. " + "This is only used if the cli is set to use the network mode (-mode=socket). " + "Defaults to the address of localhost."); + +} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/SocketIO.hpp ---------------------------------------------------------------------- diff --git a/cli/SocketIO.hpp b/cli/SocketIO.hpp new file mode 100644 index 0000000..1570e92 --- /dev/null +++ b/cli/SocketIO.hpp @@ -0,0 +1,121 @@ +/** + * 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. + **/ + +#ifndef QUICKSTEP_CLI_SOCKET_IO_HPP_ +#define QUICKSTEP_CLI_SOCKET_IO_HPP_ + +#include +#include +#include +#include +#include +#include + +#include "cli/IOInterface.hpp" +#include "cli/LineReaderBuffered.hpp" +#include "cli/simple_socket/SimpleSocketConnection.hpp" +#include "cli/simple_socket/SimpleSocketContent.hpp" +#include "cli/simple_socket/SimpleSocketServer.hpp" +#include "utility/Macros.hpp" +#include "utility/MemStream.hpp" +#include "utility/StringUtil.hpp" +#include "utility/ThreadSafeQueue.hpp" + +#include "gflags/gflags.h" +#include "glog/logging.h" + +namespace quickstep { + +DECLARE_int32(cli_socket_port); +DECLARE_string(cli_socket_ip); + +class SocketIOHandle final : public IOHandle { + public: + explicit SocketIOHandle(SimpleSocketConnection *conn) + : conn_(conn), + request_(conn_->getRequest()) { + const auto *it = request_.get("query"); + CHECK(it != nullptr); + LineReaderBuffered line_reader; + line_reader.setBuffer(std::string(it->first, it->second)); + while (!line_reader.bufferEmpty()) { + std::string command = line_reader.getNextCommand(); + if (!command.empty()) { + commands_.emplace_back(std::move(command)); + } + } + } + + ~SocketIOHandle() override { + conn_->sendResponse(out_stream_.str(), err_stream_.str()); + } + + StringPiece data() const override { + const StringPiece *entry = request_.get("data"); + return entry == nullptr ? StringPiece(nullptr, 0) : *entry; + } + + FILE* out() override { + return out_stream_.file(); + } + + FILE* err() override { + return err_stream_.file(); + } + + std::vector getCommands() const override { + return commands_; + } + + private: + std::unique_ptr conn_; + const SimpleSocketContent &request_; + MemStream out_stream_, err_stream_; + std::vector commands_; + + DISALLOW_COPY_AND_ASSIGN(SocketIOHandle); +}; + +/** + * A network interface that uses native socket to accept commands. + */ +class SocketIO final : public IOInterface { + public: + SocketIO() + : server_(FLAGS_cli_socket_port) { + server_.start(); + } + + ~SocketIO() override { + server_.stop(); + } + + IOHandle* getNextIOHandle() override { + return new SocketIOHandle(server_.waitForConnection()); + } + + private: + SimpleSocketServer server_; + + DISALLOW_COPY_AND_ASSIGN(SocketIO); +}; + +} // namespace quickstep + +#endif // QUICKSTEP_CLI_SOCKET_IO_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/quickstep/NetworkCliOuterClass.java ---------------------------------------------------------------------- diff --git a/cli/quickstep/NetworkCliOuterClass.java b/cli/quickstep/NetworkCliOuterClass.java deleted file mode 100644 index 6f4e833..0000000 --- a/cli/quickstep/NetworkCliOuterClass.java +++ /dev/null @@ -1,1388 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: NetworkCli.proto - -package quickstep; - -public final class NetworkCliOuterClass { - private NetworkCliOuterClass() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - public interface QueryRequestOrBuilder extends - // @@protoc_insertion_point(interface_extends:quickstep.QueryRequest) - com.google.protobuf.MessageOrBuilder { - - /** - * string query = 1; - */ - java.lang.String getQuery(); - /** - * string query = 1; - */ - com.google.protobuf.ByteString - getQueryBytes(); - - /** - * string data = 2; - */ - java.lang.String getData(); - /** - * string data = 2; - */ - com.google.protobuf.ByteString - getDataBytes(); - } - /** - * Protobuf type {@code quickstep.QueryRequest} - */ - public static final class QueryRequest extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:quickstep.QueryRequest) - QueryRequestOrBuilder { - private static final long serialVersionUID = 0L; - // Use QueryRequest.newBuilder() to construct. - private QueryRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private QueryRequest() { - query_ = ""; - data_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private QueryRequest( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - query_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - data_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - quickstep.NetworkCliOuterClass.QueryRequest.class, quickstep.NetworkCliOuterClass.QueryRequest.Builder.class); - } - - public static final int QUERY_FIELD_NUMBER = 1; - private volatile java.lang.Object query_; - /** - * string query = 1; - */ - public java.lang.String getQuery() { - java.lang.Object ref = query_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - query_ = s; - return s; - } - } - /** - * string query = 1; - */ - public com.google.protobuf.ByteString - getQueryBytes() { - java.lang.Object ref = query_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - query_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATA_FIELD_NUMBER = 2; - private volatile java.lang.Object data_; - /** - * string data = 2; - */ - public java.lang.String getData() { - java.lang.Object ref = data_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - data_ = s; - return s; - } - } - /** - * string data = 2; - */ - public com.google.protobuf.ByteString - getDataBytes() { - java.lang.Object ref = data_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - data_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getQueryBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, query_); - } - if (!getDataBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, data_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getQueryBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, query_); - } - if (!getDataBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, data_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof quickstep.NetworkCliOuterClass.QueryRequest)) { - return super.equals(obj); - } - quickstep.NetworkCliOuterClass.QueryRequest other = (quickstep.NetworkCliOuterClass.QueryRequest) obj; - - boolean result = true; - result = result && getQuery() - .equals(other.getQuery()); - result = result && getData() - .equals(other.getData()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + QUERY_FIELD_NUMBER; - hash = (53 * hash) + getQuery().hashCode(); - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static quickstep.NetworkCliOuterClass.QueryRequest parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(quickstep.NetworkCliOuterClass.QueryRequest prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code quickstep.QueryRequest} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:quickstep.QueryRequest) - quickstep.NetworkCliOuterClass.QueryRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - quickstep.NetworkCliOuterClass.QueryRequest.class, quickstep.NetworkCliOuterClass.QueryRequest.Builder.class); - } - - // Construct using quickstep.NetworkCliOuterClass.QueryRequest.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - query_ = ""; - - data_ = ""; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryRequest_descriptor; - } - - public quickstep.NetworkCliOuterClass.QueryRequest getDefaultInstanceForType() { - return quickstep.NetworkCliOuterClass.QueryRequest.getDefaultInstance(); - } - - public quickstep.NetworkCliOuterClass.QueryRequest build() { - quickstep.NetworkCliOuterClass.QueryRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public quickstep.NetworkCliOuterClass.QueryRequest buildPartial() { - quickstep.NetworkCliOuterClass.QueryRequest result = new quickstep.NetworkCliOuterClass.QueryRequest(this); - result.query_ = query_; - result.data_ = data_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof quickstep.NetworkCliOuterClass.QueryRequest) { - return mergeFrom((quickstep.NetworkCliOuterClass.QueryRequest)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(quickstep.NetworkCliOuterClass.QueryRequest other) { - if (other == quickstep.NetworkCliOuterClass.QueryRequest.getDefaultInstance()) return this; - if (!other.getQuery().isEmpty()) { - query_ = other.query_; - onChanged(); - } - if (!other.getData().isEmpty()) { - data_ = other.data_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - quickstep.NetworkCliOuterClass.QueryRequest parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (quickstep.NetworkCliOuterClass.QueryRequest) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object query_ = ""; - /** - * string query = 1; - */ - public java.lang.String getQuery() { - java.lang.Object ref = query_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - query_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string query = 1; - */ - public com.google.protobuf.ByteString - getQueryBytes() { - java.lang.Object ref = query_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - query_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string query = 1; - */ - public Builder setQuery( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - query_ = value; - onChanged(); - return this; - } - /** - * string query = 1; - */ - public Builder clearQuery() { - - query_ = getDefaultInstance().getQuery(); - onChanged(); - return this; - } - /** - * string query = 1; - */ - public Builder setQueryBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - query_ = value; - onChanged(); - return this; - } - - private java.lang.Object data_ = ""; - /** - * string data = 2; - */ - public java.lang.String getData() { - java.lang.Object ref = data_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - data_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string data = 2; - */ - public com.google.protobuf.ByteString - getDataBytes() { - java.lang.Object ref = data_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - data_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string data = 2; - */ - public Builder setData( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - data_ = value; - onChanged(); - return this; - } - /** - * string data = 2; - */ - public Builder clearData() { - - data_ = getDefaultInstance().getData(); - onChanged(); - return this; - } - /** - * string data = 2; - */ - public Builder setDataBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - data_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:quickstep.QueryRequest) - } - - // @@protoc_insertion_point(class_scope:quickstep.QueryRequest) - private static final quickstep.NetworkCliOuterClass.QueryRequest DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new quickstep.NetworkCliOuterClass.QueryRequest(); - } - - public static quickstep.NetworkCliOuterClass.QueryRequest getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public QueryRequest parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new QueryRequest(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public quickstep.NetworkCliOuterClass.QueryRequest getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface QueryResponseOrBuilder extends - // @@protoc_insertion_point(interface_extends:quickstep.QueryResponse) - com.google.protobuf.MessageOrBuilder { - - /** - * string query_result = 1; - */ - java.lang.String getQueryResult(); - /** - * string query_result = 1; - */ - com.google.protobuf.ByteString - getQueryResultBytes(); - - /** - * string error_result = 2; - */ - java.lang.String getErrorResult(); - /** - * string error_result = 2; - */ - com.google.protobuf.ByteString - getErrorResultBytes(); - } - /** - * Protobuf type {@code quickstep.QueryResponse} - */ - public static final class QueryResponse extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:quickstep.QueryResponse) - QueryResponseOrBuilder { - private static final long serialVersionUID = 0L; - // Use QueryResponse.newBuilder() to construct. - private QueryResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private QueryResponse() { - queryResult_ = ""; - errorResult_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private QueryResponse( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - queryResult_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - errorResult_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - quickstep.NetworkCliOuterClass.QueryResponse.class, quickstep.NetworkCliOuterClass.QueryResponse.Builder.class); - } - - public static final int QUERY_RESULT_FIELD_NUMBER = 1; - private volatile java.lang.Object queryResult_; - /** - * string query_result = 1; - */ - public java.lang.String getQueryResult() { - java.lang.Object ref = queryResult_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - queryResult_ = s; - return s; - } - } - /** - * string query_result = 1; - */ - public com.google.protobuf.ByteString - getQueryResultBytes() { - java.lang.Object ref = queryResult_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - queryResult_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int ERROR_RESULT_FIELD_NUMBER = 2; - private volatile java.lang.Object errorResult_; - /** - * string error_result = 2; - */ - public java.lang.String getErrorResult() { - java.lang.Object ref = errorResult_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - errorResult_ = s; - return s; - } - } - /** - * string error_result = 2; - */ - public com.google.protobuf.ByteString - getErrorResultBytes() { - java.lang.Object ref = errorResult_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - errorResult_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getQueryResultBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, queryResult_); - } - if (!getErrorResultBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, errorResult_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getQueryResultBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, queryResult_); - } - if (!getErrorResultBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, errorResult_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof quickstep.NetworkCliOuterClass.QueryResponse)) { - return super.equals(obj); - } - quickstep.NetworkCliOuterClass.QueryResponse other = (quickstep.NetworkCliOuterClass.QueryResponse) obj; - - boolean result = true; - result = result && getQueryResult() - .equals(other.getQueryResult()); - result = result && getErrorResult() - .equals(other.getErrorResult()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + QUERY_RESULT_FIELD_NUMBER; - hash = (53 * hash) + getQueryResult().hashCode(); - hash = (37 * hash) + ERROR_RESULT_FIELD_NUMBER; - hash = (53 * hash) + getErrorResult().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static quickstep.NetworkCliOuterClass.QueryResponse parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(quickstep.NetworkCliOuterClass.QueryResponse prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code quickstep.QueryResponse} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:quickstep.QueryResponse) - quickstep.NetworkCliOuterClass.QueryResponseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - quickstep.NetworkCliOuterClass.QueryResponse.class, quickstep.NetworkCliOuterClass.QueryResponse.Builder.class); - } - - // Construct using quickstep.NetworkCliOuterClass.QueryResponse.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - queryResult_ = ""; - - errorResult_ = ""; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return quickstep.NetworkCliOuterClass.internal_static_quickstep_QueryResponse_descriptor; - } - - public quickstep.NetworkCliOuterClass.QueryResponse getDefaultInstanceForType() { - return quickstep.NetworkCliOuterClass.QueryResponse.getDefaultInstance(); - } - - public quickstep.NetworkCliOuterClass.QueryResponse build() { - quickstep.NetworkCliOuterClass.QueryResponse result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public quickstep.NetworkCliOuterClass.QueryResponse buildPartial() { - quickstep.NetworkCliOuterClass.QueryResponse result = new quickstep.NetworkCliOuterClass.QueryResponse(this); - result.queryResult_ = queryResult_; - result.errorResult_ = errorResult_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof quickstep.NetworkCliOuterClass.QueryResponse) { - return mergeFrom((quickstep.NetworkCliOuterClass.QueryResponse)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(quickstep.NetworkCliOuterClass.QueryResponse other) { - if (other == quickstep.NetworkCliOuterClass.QueryResponse.getDefaultInstance()) return this; - if (!other.getQueryResult().isEmpty()) { - queryResult_ = other.queryResult_; - onChanged(); - } - if (!other.getErrorResult().isEmpty()) { - errorResult_ = other.errorResult_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - quickstep.NetworkCliOuterClass.QueryResponse parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (quickstep.NetworkCliOuterClass.QueryResponse) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object queryResult_ = ""; - /** - * string query_result = 1; - */ - public java.lang.String getQueryResult() { - java.lang.Object ref = queryResult_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - queryResult_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string query_result = 1; - */ - public com.google.protobuf.ByteString - getQueryResultBytes() { - java.lang.Object ref = queryResult_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - queryResult_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string query_result = 1; - */ - public Builder setQueryResult( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - queryResult_ = value; - onChanged(); - return this; - } - /** - * string query_result = 1; - */ - public Builder clearQueryResult() { - - queryResult_ = getDefaultInstance().getQueryResult(); - onChanged(); - return this; - } - /** - * string query_result = 1; - */ - public Builder setQueryResultBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - queryResult_ = value; - onChanged(); - return this; - } - - private java.lang.Object errorResult_ = ""; - /** - * string error_result = 2; - */ - public java.lang.String getErrorResult() { - java.lang.Object ref = errorResult_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - errorResult_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string error_result = 2; - */ - public com.google.protobuf.ByteString - getErrorResultBytes() { - java.lang.Object ref = errorResult_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - errorResult_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string error_result = 2; - */ - public Builder setErrorResult( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - errorResult_ = value; - onChanged(); - return this; - } - /** - * string error_result = 2; - */ - public Builder clearErrorResult() { - - errorResult_ = getDefaultInstance().getErrorResult(); - onChanged(); - return this; - } - /** - * string error_result = 2; - */ - public Builder setErrorResultBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - errorResult_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:quickstep.QueryResponse) - } - - // @@protoc_insertion_point(class_scope:quickstep.QueryResponse) - private static final quickstep.NetworkCliOuterClass.QueryResponse DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new quickstep.NetworkCliOuterClass.QueryResponse(); - } - - public static quickstep.NetworkCliOuterClass.QueryResponse getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public QueryResponse parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new QueryResponse(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public quickstep.NetworkCliOuterClass.QueryResponse getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_quickstep_QueryRequest_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_quickstep_QueryRequest_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_quickstep_QueryResponse_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_quickstep_QueryResponse_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\020NetworkCli.proto\022\tquickstep\"+\n\014QueryRe" + - "quest\022\r\n\005query\030\001 \001(\t\022\014\n\004data\030\002 \001(\t\";\n\rQu" + - "eryResponse\022\024\n\014query_result\030\001 \001(\t\022\024\n\014err" + - "or_result\030\002 \001(\t2N\n\nNetworkCli\022@\n\tSendQue" + - "ry\022\027.quickstep.QueryRequest\032\030.quickstep." + - "QueryResponse\"\000b\006proto3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_quickstep_QueryRequest_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_quickstep_QueryRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_quickstep_QueryRequest_descriptor, - new java.lang.String[] { "Query", "Data", }); - internal_static_quickstep_QueryResponse_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_quickstep_QueryResponse_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_quickstep_QueryResponse_descriptor, - new java.lang.String[] { "QueryResult", "ErrorResult", }); - } - - // @@protoc_insertion_point(outer_class_scope) -} http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/simple_socket/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/cli/simple_socket/CMakeLists.txt b/cli/simple_socket/CMakeLists.txt new file mode 100644 index 0000000..d021a61 --- /dev/null +++ b/cli/simple_socket/CMakeLists.txt @@ -0,0 +1,35 @@ +# 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. + +# Declare micro-libs: +add_library(quickstep_cli_simplesocket_SimpleSocketConnection ../../empty_src.cpp SimpleSocketConnection.hpp) +add_library(quickstep_cli_simplesocket_SimpleSocketContent ../../empty_src.cpp SimpleSocketContent.hpp) +add_library(quickstep_cli_simplesocket_SimpleSocketServer ../../empty_src.cpp SimpleSocketServer.hpp) + +# Link dependencies: +target_link_libraries(quickstep_cli_simplesocket_SimpleSocketConnection + glog + quickstep_cli_simplesocket_SimpleSocketContent + quickstep_utility_Macros) +target_link_libraries(quickstep_cli_simplesocket_SimpleSocketContent + quickstep_utility_Macros + quickstep_utility_StringUtil) +target_link_libraries(quickstep_cli_simplesocket_SimpleSocketServer + glog + quickstep_cli_simplesocket_SimpleSocketConnection + quickstep_utility_Macros + quickstep_utility_ThreadSafeQueue) http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/simple_socket/SimpleSocketConnection.hpp ---------------------------------------------------------------------- diff --git a/cli/simple_socket/SimpleSocketConnection.hpp b/cli/simple_socket/SimpleSocketConnection.hpp new file mode 100644 index 0000000..111db6a --- /dev/null +++ b/cli/simple_socket/SimpleSocketConnection.hpp @@ -0,0 +1,159 @@ +/** + * 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. + **/ + +#ifndef QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONNECTION_HPP_ +#define QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONNECTION_HPP_ + +#include + +#include +#include +#include +#include + +#include "cli/simple_socket/SimpleSocketContent.hpp" +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +class SimpleSocketConnection { + public: + explicit SimpleSocketConnection(const int socket_fd) + : socket_fd_(socket_fd), + request_data_(nullptr) { + receiveRequest(); + } + + ~SimpleSocketConnection() { + if (request_data_ != nullptr) { + std::free(request_data_); + request_data_ = nullptr; + shutdown(socket_fd_, SHUT_RDWR); + close(socket_fd_); + } + } + + const SimpleSocketContent& getRequest() const { + return request_; + } + + void sendResponse(const std::string &stdout_str, + const std::string &stderr_str) const { + SimpleSocketContent response; + response.setField("stdout", stdout_str); + response.setField("stderr", stderr_str); + sendResponse(response); + } + + private: + void receiveRequest() { + request_data_length_ = receiveUInt64(); + request_data_ = std::malloc(request_data_length_); + receiveData(request_data_, request_data_length_); + + // Decode request data. + const std::uint64_t *size_ptr = + static_cast(request_data_); + const std::uint64_t num_fields = ntohll(*size_ptr++); + + std::vector> field_sizes; + for (std::size_t i = 0; i < num_fields; ++i) { + const std::uint64_t key_size = ntohll(*size_ptr++); + const std::uint64_t value_size = ntohll(*size_ptr++); + field_sizes.emplace_back(key_size, value_size); + } + + const char *data_ptr = reinterpret_cast(size_ptr); + for (std::size_t i = 0; i < num_fields; ++i) { + const auto &fs = field_sizes[i]; + const std::uint64_t key_size = fs.first; + const std::uint64_t value_size = fs.second; + const char *key = data_ptr; + const char *value = data_ptr + key_size; + request_.setField(key, key_size, value, value_size); + data_ptr += key_size + value_size; + } + + CHECK_EQ(static_cast(request_data_) + request_data_length_, + data_ptr); + } + + inline void receiveData(void *dst, std::size_t bytes) const { + while (bytes != 0) { + const std::size_t bytes_read = read(socket_fd_, dst, bytes); + CHECK(bytes_read != 0); + bytes -= bytes_read; + dst = static_cast(dst) + bytes_read; + } + } + + inline std::uint64_t receiveUInt64() const { + std::uint64_t code; + receiveData(&code, sizeof(std::uint64_t)); + return ntohll(code); + } + + inline void writeUInt64(const std::uint64_t value) const { + const uint64_t code = htonll(value); + write(socket_fd_, &code, sizeof(std::uint64_t)); + } + + void sendResponse(const SimpleSocketContent &response) const { + // Calculate field sizes. + std::uint64_t total_size = 0; + std::vector> field_ptrs; + std::vector> field_sizes; + for (const auto &it : response.fields()) { + const std::string &key = it.first; + const StringPiece &value = it.second; + field_ptrs.emplace_back(key.data(), value.first); + field_sizes.emplace_back(key.length(), value.second); + total_size += key.length() + value.second; + } + + const std::size_t num_fields = field_ptrs.size(); + total_size += sizeof(std::uint64_t) * (1 + 2 * num_fields); + + writeUInt64(total_size); + writeUInt64(num_fields); + for (const auto &it : field_sizes) { + writeUInt64(it.first); + writeUInt64(it.second); + } + for (std::size_t i = 0; i < num_fields; ++i) { + const auto &fp = field_ptrs[i]; + const auto &fs = field_sizes[i]; + write(socket_fd_, fp.first, fs.first); + write(socket_fd_, fp.second, fs.second); + } + } + + const int socket_fd_; + std::uint64_t request_data_length_; + void *request_data_; + SimpleSocketContent request_; + + DISALLOW_COPY_AND_ASSIGN(SimpleSocketConnection); +}; + +} // namespace quickstep + +#endif // QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONNECTION_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/29024a3e/cli/simple_socket/SimpleSocketContent.hpp ---------------------------------------------------------------------- diff --git a/cli/simple_socket/SimpleSocketContent.hpp b/cli/simple_socket/SimpleSocketContent.hpp new file mode 100644 index 0000000..2cfb7a8 --- /dev/null +++ b/cli/simple_socket/SimpleSocketContent.hpp @@ -0,0 +1,75 @@ +/** + * 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. + **/ + +#ifndef QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONTENT_HPP_ +#define QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONTENT_HPP_ + +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" +#include "utility/StringUtil.hpp" + +namespace quickstep { + +class SimpleSocketContent { + public: + SimpleSocketContent() {} + + bool contains(const std::string &key) const { + return fields_.find(key) != fields_.end(); + } + + const StringPiece* get(const std::string &key) const { + const auto it = fields_.find(key); + return it == fields_.end() ? nullptr : &it->second; + } + + void setField(const std::string &key, const std::string &value) { + storage_.emplace_back(value); + const std::string &sv = storage_.back(); + fields_.emplace(key, StringPiece(sv.c_str(), sv.length())); + } + + const std::unordered_map& fields() const { + return fields_; + } + + private: + void setField(const char *key, const std::size_t key_size, + const char *value, const std::size_t value_size) { + fields_.emplace(std::string(key, key_size), + StringPiece(value, value_size)); + } + + std::unordered_map fields_; + std::list storage_; + + friend class SimpleSocketConnection; + + DISALLOW_COPY_AND_ASSIGN(SimpleSocketContent); +}; + +} // namespace quickstep + +#endif // QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONTENT_HPP_