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

JasmineGraph Frontend Shell #254

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
30072a0
frontend input length issue fixed
ChandiH Sep 4, 2024
96d2a53
implent ui-frontend list command
ChandiH Sep 4, 2024
8ab59bd
seperated frontend common function
ChandiH Sep 17, 2024
1608554
remove duplicate code
ChandiH Sep 17, 2024
9f6f668
remove duplicate code
ChandiH Sep 17, 2024
36ba3d6
remove duplicate code
ChandiH Sep 17, 2024
1af1815
change volatile variable to atomic
ChandiH Sep 17, 2024
d06d9fb
Merge remote-tracking branch 'upstream/master' into feature/frontend
ChandiH Sep 17, 2024
7ee9c07
fix review comment and add graph upload command in ui frontend
ChandiH Sep 29, 2024
d4f1457
fix review comment and add graph upload command in ui frontend
ChandiH Sep 29, 2024
921104b
fix lint issue
ChandiH Sep 29, 2024
c9f6eaa
add remove graph command in ui-frontend
ChandiH Oct 8, 2024
fac0a9b
triangle count
ChandiH Oct 15, 2024
c8e9bc6
Merge remote-tracking branch 'upstream/master' into feature/frontend
ChandiH Nov 26, 2024
ed03fbd
Merge branch 'master' into feature/frontend
miyurud Dec 24, 2024
b64d1b0
Fixed style issues
ChandiH Dec 26, 2024
1295ad2
Fixed style issues
ChandiH Dec 26, 2024
4391838
Fixed style issues
ChandiH Dec 26, 2024
a150caa
Fixed style issues
ChandiH Dec 26, 2024
3c1ca59
Merge remote-tracking branch 'origin' into feature/frontend
ChandiH Jan 2, 2025
c3f376a
Add break statement to list_command
ChandiH Jan 2, 2025
0f647bf
Add gcovr option to ignore parse errors in CodeCoverage.cmake
ChandiH Jan 2, 2025
47f6067
add test cases for frontend-ui
ChandiH Jan 2, 2025
2cbee17
update test cases for rmgr and lst commands in integration tests
ChandiH Jan 2, 2025
55b8797
update expected response in lst command test case
ChandiH Jan 2, 2025
9bbed41
add shutdown server test case to integration tests
ChandiH Jan 2, 2025
ebea06b
format response in lst command test case for improved readability
ChandiH Jan 2, 2025
3f155d1
refactor integration tests by removing redundant logging and commente…
ChandiH Jan 2, 2025
fdc97f6
Remove cout in JamineGraphFrontEnd.cpp
ChandiH Jan 13, 2025
f392d9c
Add meaningful variable name
ChandiH Jan 13, 2025
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ set(SOURCES src/backend/JasmineGraphBackend.cpp
src/streamingdb/StreamingSQLiteDBInterface.cpp
src/frontend/core/executor/impl/PageRankExecutor.cpp
src/util/dbinterface/DBInterface.cpp
src/frontend/ui/JasmineGraphFrontEndUIProtocol.h
src/frontend/ui/JasmineGraphFrontEndUIProtocol.cpp
src/frontend/ui/JasmineGraphFrontEndUI.cpp
src/frontend/ui/JasmineGraphFrontEndUI.h
src/frontend/core/common/JasmineGraphFrontendCommon.cpp
src/frontend/core/common/JasmineGraphFrontendCommon.h
)

if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
Expand Down
265 changes: 27 additions & 238 deletions src/frontend/JasmineGraphFrontEnd.cpp

Large diffs are not rendered by default.

24 changes: 1 addition & 23 deletions src/frontend/JasmineGraphFrontEnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,12 @@ class JasmineGraphFrontEnd {

int run();

static bool graphExists(std::string basic_string, SQLiteDBInterface *sqlite);

static bool modelExists(std::string basic_string, SQLiteDBInterface *sqlite);

static bool graphExistsByID(std::string id, SQLiteDBInterface *sqlite);

static bool modelExistsByID(std::string id, SQLiteDBInterface *sqlite);

static void removeGraph(std::string graphID, SQLiteDBInterface *sqlite, std::string masterIP);

static void getAndUpdateUploadTime(std::string graphID, SQLiteDBInterface *sqlite);

static bool isGraphActiveAndTrained(std::string graphID, SQLiteDBInterface *sqlite);

static map<long, long> getOutDegreeDistributionHashMap(map<long, unordered_set<long>> graphMap);

static bool isGraphActive(string graphID, SQLiteDBInterface *sqlite);

static int getUid();

static long getSLAForGraphId(SQLiteDBInterface *sqlite, PerformanceSQLiteDBInterface *perfSqlite,
std::string graphId, std::string command, std::string category);

static void scheduleStrianJobs(JobRequest &jobDetails, std::priority_queue<JobRequest> &jobQueue,
JobScheduler *jobScheduler, bool *strian_exist);

static int getRunningHighPriorityTaskCount();
static bool areRunningJobsForSameGraph();

static bool strian_exit;
std::map<std::string, std::atomic<bool>> *streamsState;
std::map<std::string, std::thread> streamingThreads;
Expand Down
1 change: 0 additions & 1 deletion src/frontend/JasmineGraphFrontEndProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ const string SLA = "sla";
const string COMMAND = "command";
const string PRIORITY = "priority(>=1)";
const string INVALID_FORMAT = "Invalid message format";

251 changes: 251 additions & 0 deletions src/frontend/core/common/JasmineGraphFrontendCommon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/**
Copyright 2019 JasminGraph Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "JasmineGraphFrontendCommon.h"
#include "../../JasmineGraphFrontEndProtocol.h"
#include "../../../server/JasmineGraphServer.h"
#include "../../../util/logger/Logger.h"

Logger common_logger;

/**
* This method checks if a graph exists in JasmineGraph.
* This method uses the unique path of the graph.
* @param basic_string
* @param dummyPt
* @return
*/
bool JasmineGraphFrontEndCommon::graphExists(string path, SQLiteDBInterface *sqlite) {
bool result = true;
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
string stmt = "SELECT COUNT( * ) FROM graph WHERE upload_path LIKE '" + path +
"' AND graph_status_idgraph_status = '" + to_string(Conts::GRAPH_STATUS::OPERATIONAL) + "';";
std::vector<vector<pair<string, string>>> v = sqlite->runSelect(stmt);
int count = std::stoi(v[0][0].second);
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
if (count == 0) {
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
result = false;
}
return result;
}

/**
* This method checks if an accessible graph exists in JasmineGraph with the same unique ID.
* @param id
* @param dummyPt
* @return
*/
bool JasmineGraphFrontEndCommon::graphExistsByID(string id, SQLiteDBInterface *sqlite) {
bool result = true;
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
string stmt = "SELECT COUNT( * ) FROM graph WHERE idgraph = " + id;
std::vector<vector<pair<string, string>>> v = sqlite->runSelect(stmt);
int count = std::stoi(v[0][0].second);
ChandiH marked this conversation as resolved.
Show resolved Hide resolved

if (count == 0) {
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
result = false;
}

return result;
}

/**
* This method removes a graph from JasmineGraph
*/
void JasmineGraphFrontEndCommon::removeGraph(std::string graphID, SQLiteDBInterface *sqlite, std::string masterIP) {
vector<pair<string, string>> hostHasPartition;
vector<vector<pair<string, string>>> hostPartitionResults = sqlite->runSelect(
"SELECT name, partition_idpartition FROM worker_has_partition INNER JOIN worker ON "
"worker_has_partition.worker_idworker = worker.idworker WHERE partition_graph_idgraph = " +
graphID + ";");
for (vector<vector<pair<string, string>>>::iterator i = hostPartitionResults.begin();
i != hostPartitionResults.end(); ++i) {
int count = 0;
string hostname;
string partitionID;
for (std::vector<pair<string, string>>::iterator j = (i->begin()); j != i->end(); ++j) {
if (count == 0) {
hostname = j->second;
} else {
partitionID = j->second;
hostHasPartition.push_back(pair<string, string>(hostname, partitionID));
}
count++;
}
}
for (std::vector<pair<string, string>>::iterator j = (hostHasPartition.begin()); j != hostHasPartition.end(); ++j) {
cout << "HOST ID : " << j->first << " Partition ID : " << j->second << endl;
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
}
sqlite->runUpdate("UPDATE graph SET graph_status_idgraph_status = " + to_string(Conts::GRAPH_STATUS::DELETING) +
" WHERE idgraph = " + graphID);

JasmineGraphServer::removeGraph(hostHasPartition, graphID, masterIP);

sqlite->runUpdate("DELETE FROM worker_has_partition WHERE partition_graph_idgraph = " + graphID);
sqlite->runUpdate("DELETE FROM partition WHERE graph_idgraph = " + graphID);
sqlite->runUpdate("DELETE FROM graph WHERE idgraph = " + graphID);
}

/**
* This method checks whether the graph is active and trained
* @param graphID
* @param dummyPt
* @return
*/
bool JasmineGraphFrontEndCommon::isGraphActiveAndTrained(std::string graphID, SQLiteDBInterface *sqlite) {
bool result = true;
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
string stmt = "SELECT COUNT( * ) FROM graph WHERE idgraph LIKE '" + graphID +
"' AND graph_status_idgraph_status = '" + to_string(Conts::GRAPH_STATUS::OPERATIONAL) +
"' AND train_status = '" + (Conts::TRAIN_STATUS::TRAINED) + "';";
std::vector<vector<pair<string, string>>> v = sqlite->runSelect(stmt);
int count = std::stoi(v[0][0].second);
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
if (count == 0) {
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
result = false;
}
return result;
}

/**
* This method checks whether the graph is active
* @param graphID
* @param dummyPt
* @return
*/
bool JasmineGraphFrontEndCommon::isGraphActive(std::string graphID, SQLiteDBInterface *sqlite) {
bool result = false;
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
string stmt = "SELECT COUNT( * ) FROM graph WHERE idgraph LIKE '" + graphID +
"' AND graph_status_idgraph_status = '" + to_string(Conts::GRAPH_STATUS::OPERATIONAL) + "';";
std::vector<vector<pair<string, string>>> v = sqlite->runSelect(stmt);
int count = std::stoi(v[0][0].second);
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
if (count != 0) {
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
result = true;
}
return result;
}

bool JasmineGraphFrontEndCommon::modelExistsByID(string id, SQLiteDBInterface *sqlite) {
bool result = true;
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
string stmt = "SELECT COUNT( * ) FROM model WHERE idmodel = " + id +
" and model_status_idmodel_status = " + to_string(Conts::GRAPH_STATUS::OPERATIONAL);
std::vector<vector<pair<string, string>>> v = sqlite->runSelect(stmt);
int count = std::stoi(v[0][0].second);

if (count == 0) {
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
result = false;
}

return result;
}

bool JasmineGraphFrontEndCommon::modelExists(string path, SQLiteDBInterface *sqlite) {
bool result = true;
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
string stmt = "SELECT COUNT( * ) FROM model WHERE upload_path LIKE '" + path +
"' AND model_status_idmodel_status = '" + to_string(Conts::GRAPH_STATUS::OPERATIONAL) + "';";
std::vector<vector<pair<string, string>>> v = sqlite->runSelect(stmt);
int count = std::stoi(v[0][0].second);
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
if (count == 0) {
ChandiH marked this conversation as resolved.
Show resolved Hide resolved
result = false;
}
return result;
}

void JasmineGraphFrontEndCommon::getAndUpdateUploadTime(std::string graphID, SQLiteDBInterface *sqlite) {
struct tm tm;
vector<vector<pair<string, string>>> uploadStartFinishTimes =
sqlite->runSelect("SELECT upload_start_time,upload_end_time FROM graph WHERE idgraph = '" + graphID + "'");
string startTime = uploadStartFinishTimes[0][0].second;
string endTime = uploadStartFinishTimes[0][1].second;
string sTime = startTime.substr(startTime.size() - 14, startTime.size() - 5);
string eTime = endTime.substr(startTime.size() - 14, startTime.size() - 5);
strptime(sTime.c_str(), "%H:%M:%S", &tm);
time_t start = mktime(&tm);
strptime(eTime.c_str(), "%H:%M:%S", &tm);
time_t end = mktime(&tm);
double difTime = difftime(end, start);
sqlite->runUpdate("UPDATE graph SET upload_time = " + to_string(difTime) + " WHERE idgraph = " + graphID);
common_logger.info("Upload time updated in the database");
}

map<long, long> JasmineGraphFrontEndCommon::getOutDegreeDistributionHashMap(map<long, unordered_set<long>> graphMap) {
map<long, long> distributionHashMap;

for (map<long, unordered_set<long>>::iterator it = graphMap.begin(); it != graphMap.end(); ++it) {
long distribution = (it->second).size();
distributionHashMap[it->first] = distribution;
}
return distributionHashMap;
}

int JasmineGraphFrontEndCommon::getUid() {
static std::atomic<std::uint32_t> uid{0};
return ++uid;
}

long JasmineGraphFrontEndCommon::getSLAForGraphId(SQLiteDBInterface *sqlite, PerformanceSQLiteDBInterface *perfSqlite,
std::string graphId, std::string command, std::string category) {
long graphSLAValue = 0;

string sqlStatement =
"SELECT worker_idworker, name,ip,user,server_port,server_data_port,partition_idpartition "
"FROM worker_has_partition INNER JOIN worker ON worker_has_partition.worker_idworker=worker.idworker "
"WHERE partition_graph_idgraph=" +
graphId + ";";

std::vector<vector<pair<string, string>>> results = sqlite->runSelect(sqlStatement);

int partitionCount = results.size();

string graphSlaQuery =
"select graph_sla.sla_value from graph_sla,sla_category where graph_sla.id_sla_category=sla_category.id "
"and sla_category.command='" +
command + "' and sla_category.category='" + category +
"' and "
"graph_sla.graph_id='" +
graphId + "' and graph_sla.partition_count='" + std::to_string(partitionCount) + "';";

std::vector<vector<pair<string, string>>> slaResults = perfSqlite->runSelect(graphSlaQuery);

if (slaResults.size() > 0) {
string currentSlaString = slaResults[0][0].second;
long graphSLAValue = atol(currentSlaString.c_str());
}

return graphSLAValue;
}

std::vector<std::vector<std::pair<std::string, std::string>>> JasmineGraphFrontEndCommon::getGraphData(SQLiteDBInterface *sqlite) {
return sqlite->runSelect("SELECT idgraph, name, upload_path, graph_status_idgraph_status FROM graph;");
}

bool JasmineGraphFrontEndCommon::checkServerBusy(std::atomic<int> *currentFESession, int connFd) {
if (*currentFESession >= Conts::MAX_FE_SESSIONS) {
if (!Utils::send_str_wrapper(connFd, "JasmineGraph server is busy. Please try again later.")) {
common_logger.error("Error writing to socket");
}
close(connFd);
return true;
}
(*currentFESession)++; // Increment only if not busy
return false;
}

std::string JasmineGraphFrontEndCommon::readAndProcessInput(int connFd, char* data, int &failCnt) {
std::string line = Utils::read_str_wrapper(connFd, data, FRONTEND_DATA_LENGTH, true);
if (line.empty()) {
failCnt++;
if (failCnt > 4) {
return "";
}
sleep(1);
} else {
failCnt = 0;
}
return Utils::trim_copy(line);
}
56 changes: 56 additions & 0 deletions src/frontend/core/common/JasmineGraphFrontendCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
Copyright 2019 JasminGraph Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef JASMINEGRAPHFRONTENDCOMMON_H
#define JASMINEGRAPHFRONTENDCOMMON_H

#include <map>
#include <thread>

#include "../../../metadb/SQLiteDBInterface.h"
#include "../../../query/algorithms/triangles/Triangles.h"

class JasmineGraphFrontEndCommon {
public:
static bool graphExists(std::string basic_string, SQLiteDBInterface *sqlite);

static bool graphExistsByID(std::string id, SQLiteDBInterface *sqlite);

static void removeGraph(std::string graphID, SQLiteDBInterface *sqlite, std::string masterIP);

static bool isGraphActive(string graphID, SQLiteDBInterface *sqlite);

static bool modelExists(std::string basic_string, SQLiteDBInterface *sqlite);

static bool modelExistsByID(std::string id, SQLiteDBInterface *sqlite);

static void getAndUpdateUploadTime(std::string graphID, SQLiteDBInterface *sqlite);

static bool isGraphActiveAndTrained(std::string graphID, SQLiteDBInterface *sqlite);

static map<long, long> getOutDegreeDistributionHashMap(map<long, unordered_set<long>> graphMap);

static int getUid();

static long getSLAForGraphId(SQLiteDBInterface *sqlite, PerformanceSQLiteDBInterface *perfSqlite,
std::string graphId, std::string command, std::string category);

// Method to execute SQL query and return results
static std::vector<std::vector<std::pair<std::string, std::string>>> getGraphData(SQLiteDBInterface *sqlite);

static bool checkServerBusy(std::atomic<int> *currentFESession, int connFd);

static std::string readAndProcessInput(int connFd, char* data, int &failCnt);
};

#endif //JASMINEGRAPHFRONTENDCOMMON_H
Loading
Loading