Skip to content
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

Log with worker and thread id. Improve getJasmineGraphProperty(). Remove unnecessary docker mounts when testing. #6

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 55 additions & 30 deletions src/server/JasmineGraphServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,40 +326,65 @@ void JasmineGraphServer::startRemoteWorkers(std::vector<int> workerPortsVector,
popen(serverStartScript.c_str(),"r");
}
} else if (profile == "docker") {
std::string image_tag;
char *env_testing = getenv("TESTING");
if (env_testing == NULL || strcasecmp(env_testing, "true") != 0) {
image_tag = "latest";
} else {
image_tag = "test";
}
bool is_testing = (env_testing != NULL && strcasecmp(env_testing, "true") == 0);
for (int i =0 ; i < workerPortsVector.size() ; i++) {
if (masterHost == host || host == "localhost") {
serverStartScript = "docker run -v " + instanceDataFolder + ":" + instanceDataFolder +
" -v " + aggregateDataFolder + ":" + aggregateDataFolder +
" -v " + nmonFileLocation + ":" + nmonFileLocation +
" -v " + graphsagelocation + ":" + graphsagelocation +
" -v " + instanceDataFolder + "/" + to_string(i) + "/logs" + ":" + "/home/ubuntu/software/jasminegraph/logs" + " -p " +
std::to_string(workerPortsVector.at(i)) + ":" +
std::to_string(workerPortsVector.at(i)) + " -p " +
std::to_string(workerDataPortsVector.at(i)) + ":" +
std::to_string(workerDataPortsVector.at(i)) + " jasminegraph:" + image_tag + " --MODE 2 --HOST_NAME " + host +
" --MASTERIP " + masterHost + " --SERVER_PORT " +
std::to_string(workerPortsVector.at(i)) + " --SERVER_DATA_PORT " +
std::to_string(workerDataPortsVector.at(i)) + " --ENABLE_NMON " + enableNmon;
if (is_testing) {
serverStartScript = "docker run -p " +
std::to_string(workerPortsVector.at(i)) + ":" +
std::to_string(workerPortsVector.at(i)) + " -p " +
std::to_string(workerDataPortsVector.at(i)) + ":" +
std::to_string(workerDataPortsVector.at(i)) +
" -e WORKER_ID=" + to_string(i) +
" jasminegraph:test --MODE 2 --HOST_NAME " + host +
" --MASTERIP " + masterHost + " --SERVER_PORT " +
std::to_string(workerPortsVector.at(i)) + " --SERVER_DATA_PORT " +
std::to_string(workerDataPortsVector.at(i)) + " --ENABLE_NMON " + enableNmon;
} else {
serverStartScript = "docker run -v " + instanceDataFolder + ":" + instanceDataFolder +
" -v " + aggregateDataFolder + ":" + aggregateDataFolder +
" -v " + nmonFileLocation + ":" + nmonFileLocation +
" -v " + graphsagelocation + ":" + graphsagelocation +
" -v " + instanceDataFolder + "/" + to_string(i) + "/logs" + ":" + "/home/ubuntu/software/jasminegraph/logs" + " -p " +
std::to_string(workerPortsVector.at(i)) + ":" +
std::to_string(workerPortsVector.at(i)) + " -p " +
std::to_string(workerDataPortsVector.at(i)) + ":" +
std::to_string(workerDataPortsVector.at(i)) +
" -e WORKER_ID=" + to_string(i) +
" jasminegraph:latest --MODE 2 --HOST_NAME " + host +
" --MASTERIP " + masterHost + " --SERVER_PORT " +
std::to_string(workerPortsVector.at(i)) + " --SERVER_DATA_PORT " +
std::to_string(workerDataPortsVector.at(i)) + " --ENABLE_NMON " + enableNmon;
}
} else {
serverStartScript = "docker -H ssh://" + host + " run -v " + instanceDataFolder + ":" + instanceDataFolder +
" -v " + aggregateDataFolder + ":" + aggregateDataFolder +
" -v " + nmonFileLocation + ":" + nmonFileLocation +
" -v " + graphsagelocation + ":" + graphsagelocation +
" -v " + instanceDataFolder + "/" + to_string(i) + "/logs" + ":" + "/home/ubuntu/software/jasminegraph/logs" + " -p " +
std::to_string(workerPortsVector.at(i)) + ":" +
std::to_string(workerPortsVector.at(i)) + " -p " +
std::to_string(workerDataPortsVector.at(i)) + ":" +
std::to_string(workerDataPortsVector.at(i)) + " jasminegraph:" + image_tag + " --MODE 2 --HOST_NAME " + host +
" --MASTERIP " + masterHost + " --SERVER_PORT " +
std::to_string(workerPortsVector.at(i)) + " --SERVER_DATA_PORT " +
std::to_string(workerDataPortsVector.at(i)) + " --ENABLE_NMON " + enableNmon;
if (is_testing) {
serverStartScript = "docker -H ssh://" + host + " run -p " +
std::to_string(workerPortsVector.at(i)) + ":" +
std::to_string(workerPortsVector.at(i)) + " -p " +
std::to_string(workerDataPortsVector.at(i)) + ":" +
std::to_string(workerDataPortsVector.at(i)) +
" -e WORKER_ID=" + to_string(i) +
" jasminegraph:test --MODE 2 --HOST_NAME " + host +
" --MASTERIP " + masterHost + " --SERVER_PORT " +
std::to_string(workerPortsVector.at(i)) + " --SERVER_DATA_PORT " +
std::to_string(workerDataPortsVector.at(i)) + " --ENABLE_NMON " + enableNmon;
} else {
serverStartScript = "docker -H ssh://" + host + " run -v " + instanceDataFolder + ":" + instanceDataFolder +
" -v " + aggregateDataFolder + ":" + aggregateDataFolder +
" -v " + nmonFileLocation + ":" + nmonFileLocation +
" -v " + graphsagelocation + ":" + graphsagelocation +
" -v " + instanceDataFolder + "/" + to_string(i) + "/logs" + ":" + "/home/ubuntu/software/jasminegraph/logs" + " -p " +
std::to_string(workerPortsVector.at(i)) + ":" +
std::to_string(workerPortsVector.at(i)) + " -p " +
std::to_string(workerDataPortsVector.at(i)) + ":" +
std::to_string(workerDataPortsVector.at(i)) +
" -e WORKER_ID=" + to_string(i) +
" jasminegraph:latest --MODE 2 --HOST_NAME " + host +
" --MASTERIP " + masterHost + " --SERVER_PORT " +
std::to_string(workerPortsVector.at(i)) + " --SERVER_DATA_PORT " +
std::to_string(workerDataPortsVector.at(i)) + " --ENABLE_NMON " + enableNmon;
}
}
server_logger.log(serverStartScript, "info");
popen(serverStartScript.c_str(),"r");
Expand Down
32 changes: 19 additions & 13 deletions src/util/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ limitations under the License.
using namespace std;
Logger util_logger;

unordered_map<std::string, std::string> Utils::propertiesMap;

map<std::string, std::string> Utils::getBatchUploadFileList(std::string file) {
std::vector<std::string> batchUploadFileContent = getFileContent(file);
std::vector<std::string>::iterator iterator1 = batchUploadFileContent.begin();
Expand Down Expand Up @@ -81,24 +83,28 @@ std::vector<std::string> Utils::getFileContent(std::string file) {
};

std::string Utils::getJasmineGraphProperty(std::string key) {
std::vector<std::string>::iterator it;
vector<std::string> vec = getFileContent("conf/jasminegraph-server.properties");
it = vec.begin();

for (it = vec.begin(); it < vec.end(); it++) {
std::string item = *it;
if (item.length() > 0 && !(item.rfind("#", 0) == 0)) {
std::vector<std::string> vec2 = split(item, '=');
if (vec2.at(0).compare(key) == 0) {
if (item.substr(item.length() - 1, item.length()).compare("=") != 0) {
return vec2.at(1);
if (Utils::propertiesMap.empty()) {
std::vector<std::string>::iterator it;
vector<std::string> vec = getFileContent("conf/jasminegraph-server.properties");
it = vec.begin();

for (it = vec.begin(); it < vec.end(); it++) {
std::string item = *it;
if (item.length() > 0 && !(item.rfind("#", 0) == 0)) {
std::vector<std::string> vec2 = split(item, '=');
if (vec2.size() == 2){
Utils::propertiesMap[vec2.at(0)] = vec2.at(1);
} else {
return " ";
Utils::propertiesMap[vec2.at(0)] = string(" ");
}
}
}
}

unordered_map<std::string,std::string>::iterator it = Utils::propertiesMap.find(key);
if(it != Utils::propertiesMap.end())
{
return it->second;
}
return NULL;
}

Expand Down
8 changes: 7 additions & 1 deletion src/util/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ limitations under the License.
#include <fstream>
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
//#include "../frontend/JasmineGraphFrontEnd.h"
#include <string.h>
#include <arpa/inet.h>
#include <string.h>

#include <algorithm>

#include "../metadb/SQLiteDBInterface.h"
#include "../performancedb/PerformanceSQLiteDBInterface.h"
#include "Conts.h"

using std::map;
using std::unordered_map;

class Utils {
private:
static unordered_map<std::string, std::string> propertiesMap;

public:
struct worker {
std::string workerID;
Expand Down
19 changes: 19 additions & 0 deletions src/util/logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,33 @@ limitations under the License.

#include "Logger.h"

#include <pthread.h>
#include <spdlog/sinks/daily_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include <stdlib.h>

#include <iostream>

using namespace std;

static string get_worker_name();

auto logger = spdlog::stdout_color_mt("logger");
auto daily_logger = spdlog::daily_logger_mt("JasmineGraph", "logs/server_logs.log", 00, 01);
string worker_name = get_worker_name();

static string get_worker_name() {
char *worker_id = getenv("WORKER_ID");
if (worker_id) {
return string("WORKER ") + string(worker_id);
}
return string("MASTER");
}

void Logger::log(std::string message, const std::string log_type) {
pthread_t tid = pthread_self();
message = "[" + worker_name + " : " + to_string(tid) + "] " + message;
if (log_type.compare("info") == 0) {
daily_logger->info(message);
logger->info(message);
Expand Down