Skip to content

Commit

Permalink
Docker file related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chinthakarukshan committed Apr 12, 2020
1 parent 7a2b07b commit 6ebfccd
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 36 deletions.
30 changes: 20 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
std::string workerIps = argv[5];
server = new JasmineGraphServer();
thread schedulerThread(SchedulerService::startScheduler);
server->run();
server->run(profile,masterIp,numberOfWorkers, workerIps);

while (server->isRunning()) {
usleep(microseconds);
Expand All @@ -74,20 +74,30 @@ int main(int argc, char *argv[]) {
main_logger.log((argv[2]),"info");
main_logger.log((argv[3]),"info");
main_logger.log((argv[4]),"info");
if (argc < 5) {
// std::cout << "Need three arguments. Use 2 <serverPort> <serverDataPort> to "
// << "start as worker ." << std::endl;
main_logger.log("Need Four arguments. Use 2 <hostName> <serverPort> <serverDataPort> to start as worker","info");
return -1;
main_logger.log((argv[5]),"info");
main_logger.log((argv[6]),"info");

if (profile == "docker") {
if (argc < 5) {
main_logger.log("Need Four arguments. Use 2 <hostName> <serverPort> <serverDataPort> to start as worker","info");
return -1;
}
} else if (profile == "native") {
if (argc < 5) {
main_logger.log("Need Four arguments. Use 2 <hostName> <serverPort> <serverDataPort> to start as worker","info");
return -1;
}
}

string hostName;
hostName = argv[2];
int serverPort = atoi(argv[3]);
int serverDataPort = atoi(argv[4]);
hostName = argv[3];
std::string masterHost = argv[4];
int serverPort = atoi(argv[5]);
int serverDataPort = atoi(argv[6]);

std::cout << "In worker mode" << std::endl;
instance = new JasmineGraphInstance();
instance->start_running(hostName, serverPort,serverDataPort);
instance->start_running(profile, hostName, masterHost, serverPort,serverDataPort);

while (instance->isRunning()) {
usleep(microseconds);
Expand Down
13 changes: 10 additions & 3 deletions run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ then
exit 1
fi
else

if [ -z "$MASTERIP" ] ;
then
echo "MASTER IP SHOULD BE SPECIFIED"
exit 1
fi

if [ -z "$SERVER_PORT" ] ;
then
echo "SERVER PORT SHOULD BE SPECIFIED"
exit 1
fi
fi

if [ -z "$SERVER_DATA_PORT" ] ;
then
Expand All @@ -63,7 +70,7 @@ fi

if [ $MODE -eq 1 ] ;
then
./JasmineGraph "docker" "$MODE $MASTERIP $WORKERS $WORKERIP
./JasmineGraph "docker" $MODE $MASTERIP $WORKERS $WORKERIP
else
./JasmineGraph "docker" "$MODE $HOST_NAME $SERVER_PORT $SERVER_DATA_PORT
./JasmineGraph "docker" $MODE $HOST_NAME $MASTERIP $SERVER_PORT $SERVER_DATA_PORT
fi
6 changes: 4 additions & 2 deletions src/server/JasmineGraphInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
void *runInstanceService(void *dummyPt) {
JasmineGraphInstance *refToInstance = (JasmineGraphInstance *) dummyPt;
refToInstance->instanceService = new JasmineGraphInstanceService();
refToInstance->instanceService->run(refToInstance->hostName, refToInstance->serverPort,
refToInstance->instanceService->run(refToInstance->profile, refToInstance->masterHostName, refToInstance->hostName, refToInstance->serverPort,
refToInstance->serverDataPort);
}

Expand All @@ -28,11 +28,13 @@ void *runFileTransferService(void *dummyPt) {
refToInstance->ftpService->run(refToInstance->serverDataPort);
}

int JasmineGraphInstance::start_running(string hostName,int serverPort, int serverDataPort) {
int JasmineGraphInstance::start_running(string profile, string hostName, string masterHost,int serverPort, int serverDataPort) {
std::cout << "Worker started" << std::endl;
std::cout << "Running the server..." << std::endl;

this->hostName = hostName;
this->profile = profile;
this->masterHostName = masterHost;
this->serverPort = serverPort;
this->serverDataPort = serverDataPort;

Expand Down
4 changes: 3 additions & 1 deletion src/server/JasmineGraphInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class JasmineGraphInstance {
map<std::string, JasmineGraphLocalStore> graphDBMapLocalStores;
public:
SQLiteDBInterface sqlite;
int start_running(string hostName, int serverPort, int serverDataPort);
int start_running(string profile, string hostName, string masterHost,int serverPort, int serverDataPort);

void registerShutdownHook();

Expand All @@ -39,6 +39,8 @@ class JasmineGraphInstance {
bool isRunning();

string hostName;
string profile;
string masterHostName;
int serverPort;
int serverDataPort;

Expand Down
6 changes: 5 additions & 1 deletion src/server/JasmineGraphInstanceService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void *instanceservicesession(void *dummyPt) {
std::map<std::string,JasmineGraphHashMapCentralStore> graphDBMapCentralStores = sessionargs->graphDBMapCentralStores;

string serverName = sessionargs->host;
string masterHost = sessionargs->masterHost;
string profile = sessionargs->profile;
int serverPort = sessionargs->port;
int serverDataPort = sessionargs->dataPort;

Expand Down Expand Up @@ -874,7 +876,7 @@ JasmineGraphInstanceService::JasmineGraphInstanceService() {

}

int JasmineGraphInstanceService::run(string host,int serverPort, int serverDataPort) {
int JasmineGraphInstanceService::run(string profile, string masterHost, string host,int serverPort, int serverDataPort) {
int listenFd;
socklen_t len;
struct sockaddr_in svrAdd;
Expand Down Expand Up @@ -930,6 +932,8 @@ int JasmineGraphInstanceService::run(string host,int serverPort, int serverDataP
instanceservicesessionargs1.connFd = connFd;
instanceservicesessionargs1.graphDBMapLocalStores = graphDBMapLocalStores;
instanceservicesessionargs1.graphDBMapCentralStores = graphDBMapCentralStores;
instanceservicesessionargs1.profile = profile;
instanceservicesessionargs1.masterHost = masterHost;
instanceservicesessionargs1.port = serverPort;
instanceservicesessionargs1.dataPort = serverDataPort;
instanceservicesessionargs1.host = host;
Expand Down
4 changes: 3 additions & 1 deletion src/server/JasmineGraphInstanceService.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void deleteGraphPartition(std::string graphID, std::string partitionID);
long countLocalTriangles(std::string graphId, std::string partitionId, std::map<std::string,JasmineGraphHashMapLocalStore> graphDBMapLocalStores, std::map<std::string,JasmineGraphHashMapCentralStore> graphDBMapCentralStores);

struct instanceservicesessionargs {
string profile;
string masterHost;
string host;
int connFd;
int port;
Expand All @@ -61,7 +63,7 @@ class JasmineGraphInstanceService {
public:
JasmineGraphInstanceService();

int run(string hostName, int serverPort, int serverDataPort);
int run(string profile, string masterHost, string hostName, int serverPort, int serverDataPort);

static bool isGraphDBExists(std::string graphId, std::string partitionId);
static bool isInstanceCentralStoreExists(std::string graphId, std::string partitionId);
Expand Down
64 changes: 48 additions & 16 deletions src/server/JasmineGraphServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ JasmineGraphServer::~JasmineGraphServer() {
sqlite.finalize();
}

int JasmineGraphServer::run() {
int JasmineGraphServer::run(std::string profile, std::string masterIp, int numberofWorkers, std::string workerIps) {
server_logger.log("Running the server...", "info");

this->sqlite = *new SQLiteDBInterface();
this->sqlite.init();
this->masterHost = masterIp;
this->profile = profile;
this->numberOfWorkers = numberofWorkers;
this->workerHosts = workerIps;
init();
addHostsToMetaDB();
updateOperationalGraphList();
Expand All @@ -79,8 +83,16 @@ void JasmineGraphServer::start_workers() {
Utils utils;
int hostListModeNWorkers = 0;
int numberOfWorkersPerHost;
std::vector<std::string> hostsList = utils.getHostList();
std::string nWorkers = utils.getJasmineGraphProperty("org.jasminegraph.server.nworkers");
std::vector<std::string> hostsList;
std::string nWorkers;
if (profile == "native") {
hostsList = utils.getHostList();
nWorkers = utils.getJasmineGraphProperty("org.jasminegraph.server.nworkers");
} else if (profile == "docker") {
hostsList = getWorkerVector(workerHosts);
nWorkers = numberOfWorkers;
}

int workerPort = Conts::JASMINEGRAPH_INSTANCE_PORT;
int workerDataPort = Conts::JASMINEGRAPH_INSTANCE_DATA_PORT;
if (utils.is_number(nWorkers)) {
Expand Down Expand Up @@ -139,7 +151,7 @@ void JasmineGraphServer::start_workers() {
server_logger.log("Starting threads for workers", "info");
for (hostListIterator = hostsList.begin(); hostListIterator < hostsList.end(); hostListIterator++) {
std::string host = *hostListIterator;
myThreads[count] = std::thread(startRemoteWorkers, workerPortsMap[host], workerDataPortsMap[host], host);
myThreads[count] = std::thread(startRemoteWorkers,workerPortsMap[host],workerDataPortsMap[host], host, profile, masterHost);
// myThreads[count].detach();
// std::cout<<"############JOINED###########"<< std::endl;
count++;
Expand All @@ -154,7 +166,7 @@ void JasmineGraphServer::start_workers() {


void JasmineGraphServer::startRemoteWorkers(std::vector<int> workerPortsVector,
std::vector<int> workerDataPortsVector, string host) {
std::vector<int> workerDataPortsVector,string host, string profile, string masterHost) {
Utils utils;
std::string executableFile;
std::string workerPath = utils.getJasmineGraphProperty("org.jasminegraph.worker.path");
Expand All @@ -173,19 +185,33 @@ void JasmineGraphServer::startRemoteWorkers(std::vector<int> workerPortsVector,
artifactPath = utils.getJasmineGraphHome();
}

copyArtifactsToWorkers(workerPath, artifactPath, host);
for (int i = 0; i < workerPortsVector.size(); i++) {
if (host.find("localhost") != std::string::npos) {
serverStartScript = executableFile + " 2 " + host + " " + std::to_string(workerPortsVector.at(i)) + " " +
std::to_string(workerDataPortsVector.at(i));
} else {
serverStartScript =
"ssh -p 22 " + host + " " + executableFile + " 2 " + host + " " +
std::to_string(workerPortsVector.at(i)) +
" " + std::to_string(workerDataPortsVector.at(i));
if (profile == "native") {
copyArtifactsToWorkers(workerPath,artifactPath,host);
for (int i =0 ; i < workerPortsVector.size() ; i++) {
if (host.find("localhost") != std::string::npos) {
serverStartScript = executableFile+" 2 "+ host +" " + std::to_string(workerPortsVector.at(i)) + " " + std::to_string(workerDataPortsVector.at(i));
} else {
serverStartScript =
"ssh -p 22 " + host + " " + executableFile + " 2 "+host+" " + std::to_string(workerPortsVector.at(i)) +
" " + std::to_string(workerDataPortsVector.at(i));
}
popen(serverStartScript.c_str(),"r");
}
} else if (profile == "docker") {
for (int i =0 ; i < workerPortsVector.size() ; i++) {
if (host.find("localhost") != std::string::npos) {
serverStartScript = executableFile+" 2 "+ host +" " + std::to_string(workerPortsVector.at(i)) + " " + std::to_string(workerDataPortsVector.at(i));
} else {
serverStartScript =
"ssh -p 22 " + host + " " + executableFile + " 2 "+host+" " + std::to_string(workerPortsVector.at(i)) +
" " + std::to_string(workerDataPortsVector.at(i));
}
serverStartScript = "docker -H ssh://root@" + host + " run jasmine_graph:latest 2 " + profile + " " + host + " " + masterHost + " " + std::to_string(workerPortsVector.at(i)) + " " + std::to_string(workerDataPortsVector.at(i));
popen(serverStartScript.c_str(),"r");
}
popen(serverStartScript.c_str(), "r");
}


}

int JasmineGraphServer::shutdown_workers() {
Expand Down Expand Up @@ -1335,3 +1361,9 @@ bool JasmineGraphServer::hasEnding(std::string const &fullString, std::string co
return false;
}
}

std::vector<std::string> JasmineGraphServer::getWorkerVector(std::string workerList) {
Utils utils;
std::vector<std::string> workerVector = utils.split(workerList,',');
return workerVector;
}
8 changes: 6 additions & 2 deletions src/server/JasmineGraphServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ using std::map;
class JasmineGraphServer {
private:
map<std::string, long> hostPlaceMap;
std::string profile;
std::string masterHost;
std::string workerHosts;
int numberOfWorkers;
int serverPort;
int serverDataPort;
std::map<std::string, std::vector<int>> workerPortsMap;
std::map<std::string, std::vector<int>> workerDataPortsMap;

static void startRemoteWorkers(std::vector<int> workerPortsVector, std::vector<int> workerDataPortsVector, std::string host);
static void startRemoteWorkers(std::vector<int> workerPortsVector, std::vector<int> workerDataPortsVector, std::string host, string profile, string masterHost);

void addHostsToMetaDB();

Expand All @@ -46,6 +49,7 @@ class JasmineGraphServer {
static void createWorkerPath (std::string workerHost, std::string workerPath);

static bool hasEnding(std::string const &fullString, std::string const &ending);
std::vector<std::string> getWorkerVector(std::string workerList);
public:
~JasmineGraphServer();

Expand All @@ -57,7 +61,7 @@ class JasmineGraphServer {

int shutdown_workers();

int run();
int run(std::string profile, std::string masterIp, int numberofWorkers, std::string workerIps);

bool isRunning();

Expand Down

0 comments on commit 6ebfccd

Please sign in to comment.