diff --git a/src/cpp/BUILD b/src/cpp/BUILD index 389dda6..ed6f644 100644 --- a/src/cpp/BUILD +++ b/src/cpp/BUILD @@ -73,3 +73,13 @@ cc_binary( ], ) + +cc_binary( + name = "link_creation_agent_client", + srcs = [], + defines = ["BAZEL_BUILD"], + linkstatic = 1, + deps = [ + "//main:link_creation_agent_client_main_lib", + ], +) diff --git a/src/cpp/link_creation_agent/Makefile b/src/cpp/link_creation_agent/Makefile index 94c2de9..f39cd9a 100644 --- a/src/cpp/link_creation_agent/Makefile +++ b/src/cpp/link_creation_agent/Makefile @@ -4,9 +4,12 @@ build_docs: build: cd ../../ && bash scripts/build.sh && cd - -run: +run_server: cd ../../ && bash scripts/container_tty.sh ./bin/link_creation_server ${OPTIONS} && cd - +run_client: + cd ../../ && bash scripts/container_tty.sh ./bin/link_creation_agent_client ${OPTIONS} && cd - + tests: cd ../../ && bash scripts/unit_tests.sh && cd - \ No newline at end of file diff --git a/src/cpp/link_creation_agent/README.md b/src/cpp/link_creation_agent/README.md index ebe96ec..2b777d5 100644 --- a/src/cpp/link_creation_agent/README.md +++ b/src/cpp/link_creation_agent/README.md @@ -103,6 +103,13 @@ requests_buffer_file = ./buffer * das_client_id: IP + port of DAS to add links * requests_buffer_file: path to request buffer, where are stored all requests that repeat + +#### Running client + +``` +make run_client OPTIONS="localhost:1010 localhost:9080 LINK_TEMPLATE Expression 3 NODE Symbol Similarity VARIABLE V1 VARIABLE V2 LINK_CREATE Similarity 2 1 VARIABLE V1 VARIABLE V2 CUSTOM_FIELD truth_value 2 CUSTOM_FIELD mean 2 count 10 avg 0.9 confidence 0.9 10 0 test false" +``` + If successful, you should see a message like this: ``` @@ -110,4 +117,4 @@ Starting server SynchronousGRPC listening on localhost:9080 SynchronousGRPC listening on localhost:9001 SynchronousGRPC listening on localhost:9090 -``` \ No newline at end of file +``` diff --git a/src/cpp/link_creation_agent/das_link_creation_node.cc b/src/cpp/link_creation_agent/das_link_creation_node.cc index f6988b3..3c550b0 100644 --- a/src/cpp/link_creation_agent/das_link_creation_node.cc +++ b/src/cpp/link_creation_agent/das_link_creation_node.cc @@ -4,7 +4,13 @@ using namespace link_creation_agent; using namespace std; using namespace distributed_algorithm_node; -LinkCreationNode::LinkCreationNode(const string& node_id) : StarNode(node_id) {} +LinkCreationNode::LinkCreationNode(const string& node_id) : StarNode(node_id) { + is_server = true; +} + +LinkCreationNode::LinkCreationNode(const string& node_id, const string& server_id) : StarNode(node_id, server_id) { + is_server = false; +} LinkCreationNode::~LinkCreationNode() { shutting_down = true; @@ -33,6 +39,12 @@ shared_ptr LinkCreationNode::message_factory(string& command, vector(command, args); } + +void LinkCreationNode::send_message(vector args) { + cout << "Sending message" << endl; + send(CREATE_LINK, args, server_id); +} + LinkCreationRequest::LinkCreationRequest(string command, vector& args) { this->command = command; this->args = args; @@ -42,4 +54,6 @@ void LinkCreationRequest::act(shared_ptr node) { auto link_node = dynamic_pointer_cast(node); string request; link_node->add_request(this->args); -} \ No newline at end of file +} + + diff --git a/src/cpp/link_creation_agent/das_link_creation_node.h b/src/cpp/link_creation_agent/das_link_creation_node.h index 74974b4..451574e 100644 --- a/src/cpp/link_creation_agent/das_link_creation_node.h +++ b/src/cpp/link_creation_agent/das_link_creation_node.h @@ -15,6 +15,13 @@ class LinkCreationNode : public StarNode { * @param node_id ID of this node in the network. */ LinkCreationNode(const string& node_id); + /** + * @brief Client constructor + * @param node_id ID of this node in the network. + * @param server_id ID of a server. + */ + LinkCreationNode(const string& node_id, const string& server_id);; + /** * Destructor */ @@ -45,10 +52,13 @@ class LinkCreationNode : public StarNode { */ virtual shared_ptr message_factory(string& command, vector& args); + void send_message(vector args); + private: Queue> request_queue; const string CREATE_LINK = "create_link"; // DAS Node command bool shutting_down = false; + bool is_server = true; }; /** @@ -60,6 +70,8 @@ class LinkCreationRequest : public Message { vector args; LinkCreationRequest(string command, vector& args); void act(shared_ptr node); + string server_id; + string client_id; }; /** diff --git a/src/cpp/main/BUILD b/src/cpp/main/BUILD index 7be1ec4..e700acf 100644 --- a/src/cpp/main/BUILD +++ b/src/cpp/main/BUILD @@ -57,3 +57,11 @@ cc_library( ], ) +cc_library( + name = "link_creation_agent_client_main_lib", + srcs = ["link_creation_agent_client_main.cc"], + deps = [ + "//link_creation_agent:link_creation_agent_lib", + + ], +) diff --git a/src/cpp/main/link_creation_agent_client_main.cc b/src/cpp/main/link_creation_agent_client_main.cc new file mode 100644 index 0000000..afeab4a --- /dev/null +++ b/src/cpp/main/link_creation_agent_client_main.cc @@ -0,0 +1,44 @@ +#include + +#include +#include +#include + +#include "das_link_creation_node.h" +using namespace link_creation_agent; +using namespace std; + +void ctrl_c_handler(int) { + std::cout << "Stopping client..." << std::endl; + std::cout << "Done." << std::endl; + exit(0); +} + + +int main(int argc, char* argv[]) { + string help = R""""( + Usage: link_creation_agent CLIENT_HOST:CLIENT_PORT SERVER_HOST:SERVER_PORT REQUEST+ + + Requests must be in the following format: + QUERY, LINK_TEMPLATE, MAX_RESULTS, REPEAT, CONTEXT, UPDATE_ATTENTION_BROKER + MAX_RESULTS and REPEAT are optional, the default value for MAX_RESULTS is 1000 and for REPEAT is 1 + )""""; + + if ((argc < 4)) { + cerr << help << endl; + } + signal(SIGINT, &ctrl_c_handler); + + string client_id = string(argv[1]); + string server_id = string(argv[2]); + + vector request; + for (int i = 3; i < argc; i++) { + request.push_back(argv[i]); + } + + auto client = new LinkCreationNode(client_id, server_id); + client->send_message(request); + + return 0; +} diff --git a/src/scripts/bazel_build.sh b/src/scripts/bazel_build.sh index 4fa2d0c..16c6c16 100755 --- a/src/scripts/bazel_build.sh +++ b/src/scripts/bazel_build.sh @@ -8,6 +8,8 @@ BAZELISK_BUILD_CMD="${BAZELISK_CMD} build --jobs ${JOBS} --enable_bzlmod" cd $CPP_WORKSPACE_DIR \ && $BAZELISK_BUILD_CMD //:link_creation_server \ && mv bazel-bin/link_creation_server $BIN_DIR \ +&& $BAZELISK_BUILD_CMD //:link_creation_agent_client \ +&& mv bazel-bin/link_creation_agent_client $BIN_DIR \ && $BAZELISK_BUILD_CMD //:word_query \ && mv bazel-bin/word_query $BIN_DIR \ && $BAZELISK_BUILD_CMD //:attention_broker_service \