-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#175] Client program that spawn other clients #242
Changes from 4 commits
e020010
1bf9279
eaeb0c3
3bca48b
c61e189
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,3 +196,5 @@ tags | |
|
||
src/bin | ||
src/bazel** | ||
|
||
.nogit/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "client_spawner_lib", | ||
srcs = glob(["*.cc"]), | ||
hdrs = glob(["*.h"]), | ||
includes = ["."], | ||
deps = [ | ||
"//distributed_algorithm_node:distributed_algorithm_node_lib", | ||
"//query_engine:query_engine_lib", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,43 @@ | ||||||||||||||
#include "SentinelServerNode.h" | ||||||||||||||
|
||||||||||||||
using namespace client_spawner; | ||||||||||||||
|
||||||||||||||
SentinelServerNode::SentinelServerNode(const string &node_id) : StarNode(node_id) {} | ||||||||||||||
|
||||||||||||||
SentinelServerNode::~SentinelServerNode() {} | ||||||||||||||
|
||||||||||||||
// TODO: At this point Node does nothing with the messages. | ||||||||||||||
void SentinelServerNode::storage_message(string &worker_id, string &message) { | ||||||||||||||
cout << worker_id <<" message received" << endl; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
shared_ptr<Message> SentinelServerNode::message_factory(string &command, vector<string> &args) { | ||||||||||||||
shared_ptr<Message> message = StarNode::message_factory(command, args); | ||||||||||||||
if (message) { | ||||||||||||||
return message; | ||||||||||||||
} | ||||||||||||||
if (command == WORKER_NOTIFICATION) { | ||||||||||||||
return shared_ptr<Message>(new WorkerMessage(args[0], args[1])); | ||||||||||||||
} | ||||||||||||||
return shared_ptr<Message>{}; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a change request, it's more like a tip. auto message = StarNode::message_factory(command, args); // <== here
if (message) {
return message;
}
if (command == WORKER_NOTIFICATION) {
return make_shared<WorkerMessage>(args[0], args[1]); // <== here
}
return nullptr; // <== here |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
// ================================= | ||||||||||||||
|
||||||||||||||
WorkerMessage::WorkerMessage(string &worker_id, string &msg) { | ||||||||||||||
this->worker_id = worker_id; | ||||||||||||||
this->msg = msg; | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
void WorkerMessage::act(shared_ptr<MessageFactory> node) { | ||||||||||||||
#ifdef DEBUG | ||||||||||||||
cout << "WorkerMessage::act() BEGIN" << endl; | ||||||||||||||
cout << "worker_id: " << this->worker_id << endl; | ||||||||||||||
#endif | ||||||||||||||
auto sentinel_server_node = dynamic_pointer_cast<SentinelServerNode>(node); | ||||||||||||||
sentinel_server_node->storage_message(this->worker_id, this->msg); | ||||||||||||||
#ifdef DEBUG | ||||||||||||||
cout << "WorkerMessage::act() END" << endl; | ||||||||||||||
#endif | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||
/** | ||||||
* @file sentinel_server_node.h | ||||||
* @brief Responsible for managing workers and handling their messages | ||||||
*/ | ||||||
#pragma once | ||||||
|
||||||
#include "StarNode.h" | ||||||
|
||||||
#define DEBUG | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is hard-coded but The way we are currently running the build process does not allow us to pass options to In short, you can, and should, remove this |
||||||
|
||||||
using namespace distributed_algorithm_node; | ||||||
|
||||||
|
||||||
namespace client_spawner { | ||||||
|
||||||
constexpr const char* WORKER_NOTIFICATION = "worker_notification"; | ||||||
|
||||||
class SentinelServerNode: public StarNode { | ||||||
|
||||||
public: | ||||||
SentinelServerNode(const string &node_id); | ||||||
|
||||||
~SentinelServerNode(); | ||||||
|
||||||
void storage_message(string &worker_id, string &message); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe?
Suggested change
Please set them |
||||||
|
||||||
virtual shared_ptr<Message> message_factory(string &command, vector<string> &args); | ||||||
}; | ||||||
|
||||||
class WorkerMessage: public Message { | ||||||
|
||||||
public: | ||||||
string worker_id; | ||||||
string msg; | ||||||
WorkerMessage(string &worker_id, string &msg); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
void act(shared_ptr<MessageFactory> node); | ||||||
|
||||||
}; | ||||||
|
||||||
} // namespace client_spawner | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||
#include "WorkerClientNode.h" | ||||||||||||||||||||||||||
#include "SentinelServerNode.h" | ||||||||||||||||||||||||||
#include "DASNode.h" | ||||||||||||||||||||||||||
#include "RemoteIterator.h" | ||||||||||||||||||||||||||
#include "QueryAnswer.h" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using namespace client_spawner; | ||||||||||||||||||||||||||
using namespace query_engine; | ||||||||||||||||||||||||||
using namespace query_element; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
#define MAX_QUERY_ANSWERS ((unsigned int) 1000) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
WorkerClientNode::WorkerClientNode( | ||||||||||||||||||||||||||
const string &node_id, | ||||||||||||||||||||||||||
const string &server_id, | ||||||||||||||||||||||||||
const string &das_node_server_id | ||||||||||||||||||||||||||
) : StarNode(node_id, server_id) { | ||||||||||||||||||||||||||
this->node_id = node_id; | ||||||||||||||||||||||||||
this->server_id = server_id; | ||||||||||||||||||||||||||
this->das_node_server_id = das_node_server_id; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
WorkerClientNode::~WorkerClientNode() {} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
void WorkerClientNode::execute(vector<string> &request) { | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
DASNode das_node_client(this->node_id, this->das_node_server_id); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
QueryAnswer *query_answer; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
unsigned int count = 0; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
RemoteIterator *response = das_node_client.pattern_matcher_query(request); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
vector<string> message; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
message.push_back(this->node_id); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
string query_answer_str; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
while (! response->finished()) { | ||||||||||||||||||||||||||
if ((query_answer = response->pop()) == NULL) { | ||||||||||||||||||||||||||
Utils::sleep(); | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
query_answer_str += query_answer->to_string(); | ||||||||||||||||||||||||||
query_answer_str += "\n"; | ||||||||||||||||||||||||||
if (++count == MAX_QUERY_ANSWERS) { | ||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (count == 0) { | ||||||||||||||||||||||||||
string no_match = "No match for query"; | ||||||||||||||||||||||||||
cout << no_match << endl; | ||||||||||||||||||||||||||
message.push_back(no_match); | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
cout << query_answer_str << endl; | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
message.push_back(query_answer_str); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
delete response; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
send(WORKER_NOTIFICATION, message, this->server_id); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
/** | ||||||
* @file worker_client_node.h | ||||||
* @brief Responsible for making a query | ||||||
*/ | ||||||
#pragma once | ||||||
|
||||||
#include "StarNode.h" | ||||||
|
||||||
using namespace distributed_algorithm_node; | ||||||
|
||||||
namespace client_spawner { | ||||||
|
||||||
class WorkerClientNode : public StarNode { | ||||||
|
||||||
public: | ||||||
WorkerClientNode(const string& node_id, const string& server_id, const string& das_node_server_id); | ||||||
|
||||||
~WorkerClientNode(); | ||||||
|
||||||
void execute(vector<string>& request); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
private: | ||||||
string node_id; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already defined in
Suggested change
|
||||||
string das_node_server_id; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this any different from |
||||||
}; | ||||||
|
||||||
} // namespace client_spawner |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <signal.h> | ||
|
||
#include "Utils.h" | ||
#include "DASNode.h" | ||
#include "SentinelServerNode.h" | ||
|
||
using namespace std; | ||
using namespace client_spawner; | ||
|
||
void ctrl_c_handler(int) { | ||
std::cout << "Stopping SentinelServerNode..." << std::endl; | ||
std::cout << "Done." << std::endl; | ||
exit(0); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
|
||
if (argc != 2) { | ||
cerr << "Usage: " << argv[0] << " <PORT>" << endl; | ||
exit(1); | ||
} | ||
|
||
string server_id = "localhost:" + string(argv[1]); | ||
|
||
signal(SIGINT, &ctrl_c_handler); | ||
|
||
SentinelServerNode server(server_id); | ||
|
||
cout << "############################# Sentinel Server ON ##################################" << endl; | ||
|
||
do { | ||
Utils::sleep(1000); | ||
} while (true); | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <signal.h> | ||
|
||
#include "Utils.h" | ||
#include "DASNode.h" | ||
#include "WorkerClientNode.h" | ||
|
||
using namespace std; | ||
using namespace client_spawner; | ||
|
||
void ctrl_c_handler(int) { | ||
std::cout << "Stopping WorkerClientNode..." << std::endl; | ||
std::cout << "Done." << std::endl; | ||
exit(0); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
|
||
if (argc < 4) { | ||
cerr << "Usage: " << argv[0] << " <NODE_ID> <SERVER_ID> <DAS_NODE_SERVER_ID> <QUERY_TOKENS+>" << endl; | ||
exit(1); | ||
} | ||
|
||
string node_id = string(argv[1]); | ||
string server_id = string(argv[2]); | ||
string das_node_server_id = string(argv[3]); | ||
|
||
cout << "node_id: " << node_id << endl; | ||
cout << "server_id: " << server_id << endl; | ||
cout << "das_node_server_id: " << das_node_server_id << endl; | ||
|
||
signal(SIGINT, &ctrl_c_handler); | ||
|
||
vector<string> query; | ||
|
||
for (int i = 4; i < argc; i++) { | ||
query.push_back(argv[i]); | ||
} | ||
|
||
signal(SIGINT, &ctrl_c_handler); | ||
|
||
WorkerClientNode client(node_id, server_id, das_node_server_id); | ||
|
||
client.execute(query); | ||
|
||
cout << "Worker client '" << node_id << "' done!\n" << endl; | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM das-attention-broker-builder:latest | ||
|
||
COPY bin/sentinel_server /opt/das-attention-broker/bin/sentinel_server | ||
COPY bin/worker_client /opt/das-attention-broker/bin/worker_client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on
src/scripts/docker_image_spawner_build.sh
file.