Skip to content

Commit

Permalink
Merge pull request #199 from FYP-Auto-Scale-JasmineGraph/master
Browse files Browse the repository at this point in the history
C++ code formatting
  • Loading branch information
miyurud authored Oct 19, 2023
2 parents 2ca54a3 + 06316e3 commit 7200979
Show file tree
Hide file tree
Showing 105 changed files with 3,543 additions and 4,078 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/code-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:

- name: cpplint check
if: ${{!contains(github.event.pull_request.labels.*.name, 'Skip cpplint Check')}}
run: cpplint --linelength=120 --filter=-build,-runtime,-readability/todo,-whitespace/todo,-readability/casting,-readability/braces,-readability/fn_size,-legal/copyright --exclude=./src/util/sqlite3/ --recursive .
run: cpplint --linelength=120 --filter=-build,-runtime,-readability/todo,-whitespace/todo,-readability/casting,-readability/braces,-readability/fn_size,-legal/copyright --recursive .

- name: pylint check
if: ${{!contains(github.event.pull_request.labels.*.name, 'Skip pylint Check')}}
run: pylint --recursive=y .
run: pylint --recursive=y .
29 changes: 16 additions & 13 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "main.h"

#include <iostream>
#include <unistd.h>
#include "main.h"

#include <future>
#include <iostream>

#include "src/server/JasmineGraphInstance.h"
#include "src/util/logger/Logger.h"
#include "src/util/scheduler/SchedulerService.h"
#include <future>

unsigned int microseconds = 10000000;
JasmineGraphServer *server;
Expand All @@ -31,47 +33,48 @@ void fnExit3(void) {
puts("Shutting down the server.");
}


int main(int argc, char *argv[]) {
atexit(fnExit3);
Utils utils;

if (argc <= 1) {
main_logger.log("\"Use argument 1 to start JasmineGraph in Master mode. Use 2 "
"<hostName> <serverPort> <serverDataPort> to start as worker","error");
main_logger.log(
"\"Use argument 1 to start JasmineGraph in Master mode. Use 2 "
"<hostName> <serverPort> <serverDataPort> to start as worker",
"error");
return -1;
}
std::cout << argc << std::endl;

int mode = atoi(argv[2]);
std::string JASMINEGRAPH_HOME = utils.getJasmineGraphHome();
std::string profile = argv[1]; //This can be either "docker" or "native"
std::string profile = argv[1]; // This can be either "docker" or "native"
std::string enableNmon = "false";

main_logger.log("Using JASMINE_GRAPH_HOME", "info");
std::cout << JASMINEGRAPH_HOME << std::endl;


if (mode == Conts::JASMINEGRAPH_RUNTIME_PROFILE_MASTER) {
std::string masterIp = argv[3];
int numberOfWorkers = atoi(argv[4]);
std::string workerIps = argv[5];
enableNmon = argv[6];
server = new JasmineGraphServer();
thread schedulerThread(SchedulerService::startScheduler);
server->run(profile,masterIp,numberOfWorkers, workerIps, enableNmon);
server->run(profile, masterIp, numberOfWorkers, workerIps, enableNmon);

while (server->isRunning()) {
usleep(microseconds);
}

schedulerThread.join();
delete server;
} else if (mode == Conts::JASMINEGRAPH_RUNTIME_PROFILE_WORKER){
main_logger.log(to_string(argc),"info");
} else if (mode == Conts::JASMINEGRAPH_RUNTIME_PROFILE_WORKER) {
main_logger.log(to_string(argc), "info");

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

Expand All @@ -84,7 +87,7 @@ int main(int argc, char *argv[]) {

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

while (instance->isRunning()) {
usleep(microseconds);
Expand Down
5 changes: 3 additions & 2 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ limitations under the License.
#ifndef JASMINEGRAPH_MAIN_H
#define JASMINEGRAPH_MAIN_H

#endif //JASMINEGRAPH_MAIN_H
#endif // JASMINEGRAPH_MAIN_H

#include <thread>

#include "src/server/JasmineGraphServer.h"
#include "src/util/Utils.h"
#include <thread>
46 changes: 21 additions & 25 deletions src/backend/JasmineGraphBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ limitations under the License.
*/

#include "JasmineGraphBackend.h"
#include "../util/Utils.h"

#include "../util/Conts.h"
#include "JasmineGraphBackendProtocol.h"
#include "../util/Utils.h"
#include "../util/logger/Logger.h"
#include "JasmineGraphBackendProtocol.h"

using namespace std;

Utils utils;
Logger backend_logger;

void *backendservicesesion(void *dummyPt) {
backendservicesessionargs *sessionargs = (backendservicesessionargs *) dummyPt;
backendservicesessionargs *sessionargs = (backendservicesessionargs *)dummyPt;
int connFd = sessionargs->connFd;
SQLiteDBInterface sqLiteDbInterface = sessionargs->sqlite;
backend_logger.log("Thread No: " + to_string(pthread_self()), "info");
Expand All @@ -35,7 +36,7 @@ void *backendservicesesion(void *dummyPt) {
read(connFd, data, 300);

string line(data);
backend_logger.log("Command received: " + line , "info");
backend_logger.log("Command received: " + line, "info");
line = utils.trim_copy(line, " \f\n\r\t\v");

if (line.compare(EXIT_BACKEND) == 0) {
Expand All @@ -52,16 +53,16 @@ void *backendservicesesion(void *dummyPt) {
string hostname(host);
Utils utils;
hostname = utils.trim_copy(hostname, " \f\n\r\t\v");
write(connFd, HOST_OK.c_str(),HOST_OK.size());
backend_logger.log("Hostname of the worker: " + hostname , "info");
write(connFd, HOST_OK.c_str(), HOST_OK.size());
backend_logger.log("Hostname of the worker: " + hostname, "info");

} else if (line.compare(ACKNOWLEGE_MASTER) == 0) {
int result_wr = write(connFd, WORKER_INFO_SEND.c_str(), WORKER_INFO_SEND.size());
if(result_wr < 0) {
if (result_wr < 0) {
backend_logger.log("Error writing to socket", "error");
}
result_wr = write(connFd, "\r\n", 2);
if(result_wr < 0) {
if (result_wr < 0) {
backend_logger.log("Error writing to socket", "error");
}

Expand All @@ -73,20 +74,18 @@ void *backendservicesesion(void *dummyPt) {
read(connFd, worker_info_data, 300);

string worker_info(worker_info_data);
worker_info.erase(std::remove(worker_info.begin(), worker_info.end(), '\n'),
worker_info.end());
worker_info.erase(std::remove(worker_info.begin(), worker_info.end(), '\r'),
worker_info.end());
worker_info.erase(std::remove(worker_info.begin(), worker_info.end(), '\n'), worker_info.end());
worker_info.erase(std::remove(worker_info.begin(), worker_info.end(), '\r'), worker_info.end());

std::vector<std::string> strArr = Utils::split(worker_info, '|');

std::string updateQuery = "update worker set status='started' where ip='" + strArr[0] + "' and server_port='" + strArr[1] + "';";
std::string updateQuery =
"update worker set status='started' where ip='" + strArr[0] + "' and server_port='" + strArr[1] + "';";

sqLiteDbInterface.runUpdate(updateQuery);
break;

}
else {
} else {
backend_logger.log("Message format not recognized", "error");
}
}
Expand All @@ -109,15 +108,15 @@ int JasmineGraphBackend::run() {
struct sockaddr_in svrAdd;
struct sockaddr_in clntAdd;

//create socket
// create socket
listenFd = socket(AF_INET, SOCK_STREAM, 0);

if (listenFd < 0) {
backend_logger.log("Cannot open socket", "error");
return 0;
}

bzero((char *) &svrAdd, sizeof(svrAdd));
bzero((char *)&svrAdd, sizeof(svrAdd));

svrAdd.sin_family = AF_INET;
svrAdd.sin_addr.s_addr = INADDR_ANY;
Expand All @@ -130,9 +129,8 @@ int JasmineGraphBackend::run() {
exit(1);
}


//bind socket
if (bind(listenFd, (struct sockaddr *) &svrAdd, sizeof(svrAdd)) < 0) {
// bind socket
if (bind(listenFd, (struct sockaddr *)&svrAdd, sizeof(svrAdd)) < 0) {
backend_logger.log("Cannot bind on port " + portNo, "error");
return 0;
}
Expand All @@ -147,8 +145,8 @@ int JasmineGraphBackend::run() {
while (noThread < workerCount) {
backend_logger.log("Backend Listening", "info");

//this is where client connects. svr will hang in this mode until client conn
int connFd = accept(listenFd, (struct sockaddr *) &clntAdd, &len);
// this is where client connects. svr will hang in this mode until client conn
int connFd = accept(listenFd, (struct sockaddr *)&clntAdd, &len);

if (connFd < 0) {
backend_logger.log("Cannot accept connection", "error");
Expand All @@ -161,9 +159,7 @@ int JasmineGraphBackend::run() {
backendservicesessionargs1.sqlite = this->sqlite;
backendservicesessionargs1.connFd = connFd;


pthread_create(&threadA[noThread], NULL, backendservicesesion,
&backendservicesessionargs1);
pthread_create(&threadA[noThread], NULL, backendservicesesion, &backendservicesessionargs1);

noThread++;
}
Expand Down
28 changes: 14 additions & 14 deletions src/backend/JasmineGraphBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,33 @@ limitations under the License.
#ifndef JASMINEGRAPH_JASMINEGRAPHBACKEND_H
#define JASMINEGRAPH_JASMINEGRAPHBACKEND_H

#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <iostream>
#include <fstream>
#include <strings.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#include <fstream>
#include <iostream>
#include <string>
#include <pthread.h>
#include <thread>
#include "../metadb/SQLiteDBInterface.h"

#include "../metadb/SQLiteDBInterface.h"

void *backendservicesesion(void *dummyPt);

class JasmineGraphBackend {
public:
public:
JasmineGraphBackend(SQLiteDBInterface db, int numberOfWorkers);

int run();

private:
private:
SQLiteDBInterface sqlite;
int workerCount;
};
Expand All @@ -49,5 +50,4 @@ struct backendservicesessionargs {
int connFd;
};


#endif //JASMINEGRAPH_JASMINEGRAPHBACKEND_H
#endif // JASMINEGRAPH_JASMINEGRAPHBACKEND_H
8 changes: 4 additions & 4 deletions src/backend/JasmineGraphBackendProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const string HANDSHAKE = "hske";
const string HANDSHAKE_OK = "hske-ok";
const string EXIT_BACKEND = "exit";
const string EXIT_ACK = "bye";
const string ACKNOWLEGE_MASTER="ack-master";
const string WORKER_INFO_SEND="worker-info";
const string HOST_OK="hst-ok";
const string UPDATE_DONE="done";
const string ACKNOWLEGE_MASTER = "ack-master";
const string WORKER_INFO_SEND = "worker-info";
const string HOST_OK = "hst-ok";
const string UPDATE_DONE = "done";
31 changes: 16 additions & 15 deletions src/backend/JasmineGraphBackendProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@ limitations under the License.

using namespace std;

extern const string HANDSHAKE; //To notify the server the host name of this worker;
extern const string HANDSHAKE_OK; //Response to say it is ready for handshaking.
extern const string OK; //To check if the status is ok
extern const string RUOK; //To check if the status is ok
extern const string IMOK; //Response to check if the status is ok
extern const string EXIT_BACKEND; //To exit from the query session
extern const string HANDSHAKE; // To notify the server the host name of this worker;
extern const string HANDSHAKE_OK; // Response to say it is ready for handshaking.
extern const string OK; // To check if the status is ok
extern const string RUOK; // To check if the status is ok
extern const string IMOK; // Response to check if the status is ok
extern const string EXIT_BACKEND; // To exit from the query session
extern const string EXIT_ACK;
extern const string SEND; //Ask the client to send some data. This is used during a comminication session with the client.
extern const string
SEND; // Ask the client to send some data. This is used during a comminication session with the client.
extern const string ERROR;
extern const string OUT_DEGREE_DISTRIBUTION_FOR_PARTITION;
extern const string IN_DEGREE_DISTRIBUTION_FOR_PARTITION; //This commad gets the in degree distribution from the external world to this partition
extern const string IN_DEGREE_DISTRIBUTION_FOR_PARTITION; // This commad gets the in degree distribution from the
// external world to this partition
extern const string WORLD_ONLY_AUTHFLOW_FOR_PARTITION;
extern const string LOCAL_TO_WORLD_AUTHFLOW_FOR_PARTITION;
extern const string WORLD_TO_LOCAL_FLOW_FROMIDS; //This command gets all the vertices connected with the external graph and their corresponding fromIDs
extern const string WORLD_TO_LOCAL_FLOW_FROMIDS; // This command gets all the vertices connected with the external
// graph and their corresponding fromIDs
extern const string DONE;
extern const string PARTITIONS_ON_HOST; //The command to get the list of partitions on particular host
extern const string ACKNOWLEGE_MASTER; // Command to acknowledge the master stating that the worker has started
extern const string PARTITIONS_ON_HOST; // The command to get the list of partitions on particular host
extern const string ACKNOWLEGE_MASTER; // Command to acknowledge the master stating that the worker has started
extern const string WORKER_INFO_SEND;
extern const string HOST_OK;
extern const string UPDATE_DONE;

class JasmineGraphBackendProtocol {

};
class JasmineGraphBackendProtocol {};

const int BACKEND_COMMAND_LENGTH = 4;
const int BACKEND_DATA_LENGTH = 300;

#endif //JASMINEGRAPH_JASMINEGRAPHBACKENDPROTOCOL_H
#endif // JASMINEGRAPH_JASMINEGRAPHBACKENDPROTOCOL_H
Loading

0 comments on commit 7200979

Please sign in to comment.