Skip to content

Commit

Permalink
Merge pull request #16 from ao/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ao authored Nov 2, 2021
2 parents a2710f4 + b6dbb9a commit 279e9a8
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 112 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openjdk:8
COPY ./target/Serengeti-1.2-SNAPSHOT-jar-with-dependencies.jar /tmp
COPY ./target/Serengeti-1.3-SNAPSHOT-jar-with-dependencies.jar /tmp
WORKDIR /tmp
EXPOSE 1985
#ENTRYPOINT ["java","gl.ao.serengeti.Serengeti"]
CMD java -jar Serengeti-1.2-SNAPSHOT-jar-with-dependencies.jar
#ENTRYPOINT ["java","Serengeti"]
CMD java -jar Serengeti-1.3-SNAPSHOT-jar-with-dependencies.jar
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Yes, of course you can!

`+ Application`

Set the `classpath` to `Serengeti` and the `Main class` to `gl.ao.serengeti.Serengeti`
Set the `classpath` to `Serengeti` and the `Main class` to `Serengeti`

`Run the application!`

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>gl.ao.serengeti</groupId>
<groupId>ms.ao.serengeti</groupId>
<artifactId>Serengeti</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.3-SNAPSHOT</version>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down Expand Up @@ -35,7 +35,7 @@
<!-- <manifest>-->
<!-- <addClasspath>true</addClasspath>-->
<!-- <classpathPrefix>lib/</classpathPrefix>-->
<!-- <mainClass>gl.ao.serengeti.Serengeti</mainClass>-->
<!-- <mainClass>Serengeti</mainClass>-->
<!-- </manifest>-->
<!-- </archive>-->
<!-- </configuration>-->
Expand All @@ -47,7 +47,7 @@
<configuration>
<archive>
<manifest>
<mainClass>gl.ao.serengeti.Serengeti</mainClass>
<mainClass>ms.ao.serengeti.Serengeti</mainClass>
</manifest>
</archive>
<descriptorRefs>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package gl.ao.serengeti;
package ms.ao.serengeti;

import gl.ao.serengeti.helpers.Globals;
import gl.ao.serengeti.helpers.ShutdownHandler;
import gl.ao.serengeti.network.Network;
import gl.ao.serengeti.server.Server;
import gl.ao.serengeti.storage.Storage;
import gl.ao.serengeti.storage.StorageReshuffle;
import gl.ao.serengeti.storage.StorageScheduler;
import gl.ao.serengeti.ui.Interactive;
import ms.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.helpers.ShutdownHandler;
import ms.ao.serengeti.network.Network;
import ms.ao.serengeti.server.Server;
import ms.ao.serengeti.storage.Storage;
import ms.ao.serengeti.storage.StorageReshuffle;
import ms.ao.serengeti.storage.StorageScheduler;
import ms.ao.serengeti.ui.Interactive;

import java.io.BufferedReader;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gl.ao.serengeti.data;
package ms.ao.serengeti.data;

public class DatabaseObjectData {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gl.ao.serengeti.helpers;
package ms.ao.serengeti.helpers;

import java.io.IOException;
import java.io.ObjectOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gl.ao.serengeti.helpers;
package ms.ao.serengeti.helpers;

import gl.ao.serengeti.Serengeti;
import ms.ao.serengeti.Serengeti;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package gl.ao.serengeti.helpers;
package ms.ao.serengeti.helpers;

import gl.ao.serengeti.helpers.Globals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.NotSerializableException;
import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package gl.ao.serengeti.helpers;
package ms.ao.serengeti.helpers;

import ms.ao.serengeti.Serengeti;

public class ShutdownHandler {

Expand All @@ -13,7 +15,7 @@ public ShutdownHandler() {

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("Safe Shutdown Initiated..");
if (gl.ao.serengeti.Serengeti.storageScheduler.performPersistToDisk()) {
if (Serengeti.storageScheduler.performPersistToDisk()) {
System.out.println("Safe Shutdown Completed Succesfully");
}
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gl.ao.serengeti.network;
package ms.ao.serengeti.network;

import gl.ao.serengeti.Serengeti;
import gl.ao.serengeti.helpers.Globals;
import gl.ao.serengeti.storage.Storage;
import ms.ao.serengeti.Serengeti;
import ms.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.storage.Storage;
import org.json.JSONArray;
import org.json.JSONObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gl.ao.serengeti.query;
package ms.ao.serengeti.query;

import gl.ao.serengeti.Serengeti;
import gl.ao.serengeti.storage.StorageResponseObject;
import ms.ao.serengeti.Serengeti;
import ms.ao.serengeti.storage.StorageResponseObject;
import org.json.JSONObject;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package gl.ao.serengeti.query;
package ms.ao.serengeti.query;

import gl.ao.serengeti.Serengeti;
import gl.ao.serengeti.helpers.Globals;
import gl.ao.serengeti.schema.TableReplicaObject;
import gl.ao.serengeti.schema.TableStorageObject;
import gl.ao.serengeti.storage.Storage;
import ms.ao.serengeti.Serengeti;
import ms.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.schema.TableReplicaObject;
import ms.ao.serengeti.schema.TableStorageObject;
import ms.ao.serengeti.storage.Storage;
import org.json.JSONObject;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gl.ao.serengeti.query;
package ms.ao.serengeti.query;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gl.ao.serengeti.schema;
package ms.ao.serengeti.schema;

import gl.ao.serengeti.data.DatabaseObjectData;
import gl.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.helpers.Globals;

import java.io.*;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gl.ao.serengeti.schema;
package ms.ao.serengeti.schema;

import gl.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.helpers.Globals;
import org.json.JSONObject;

import java.io.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gl.ao.serengeti.schema;
package ms.ao.serengeti.schema;

import gl.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.helpers.Globals;
import org.json.JSONObject;

import java.io.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gl.ao.serengeti.server;
package ms.ao.serengeti.server;

import java.io.*;
import java.lang.management.ManagementFactory;
Expand All @@ -16,13 +16,13 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import gl.ao.serengeti.Serengeti;
import gl.ao.serengeti.network.Network;
import gl.ao.serengeti.ui.Dashboard;
import gl.ao.serengeti.ui.Interactive;
import gl.ao.serengeti.helpers.Globals;
import gl.ao.serengeti.query.QueryEngine;
import gl.ao.serengeti.query.QueryLog;
import ms.ao.serengeti.Serengeti;
import ms.ao.serengeti.network.Network;
import ms.ao.serengeti.ui.Dashboard;
import ms.ao.serengeti.ui.Interactive;
import ms.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.query.QueryEngine;
import ms.ao.serengeti.query.QueryLog;
import org.json.JSONArray;
import org.json.JSONObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gl.ao.serengeti.server;
package ms.ao.serengeti.server;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package gl.ao.serengeti.storage;

import gl.ao.serengeti.Serengeti;
import gl.ao.serengeti.query.QueryLog;
import gl.ao.serengeti.schema.DatabaseObject;
import gl.ao.serengeti.helpers.Globals;
import gl.ao.serengeti.schema.TableReplicaObject;
import gl.ao.serengeti.schema.TableStorageObject;
package ms.ao.serengeti.storage;

import ms.ao.serengeti.Serengeti;
import ms.ao.serengeti.query.QueryLog;
import ms.ao.serengeti.schema.DatabaseObject;
import ms.ao.serengeti.helpers.Globals;
import ms.ao.serengeti.schema.TableReplicaObject;
import ms.ao.serengeti.schema.TableStorageObject;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.io.FilenameFilter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -140,7 +139,7 @@ public List<String> select(String db, String table, String selectWhat, String co
List<String> list = new ArrayList<>();
Set<String> uuids = new HashSet<String>();

JSONArray array = gl.ao.serengeti.Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
JSONArray array = Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
put("type", "SelectRespond");
put("selectWhat", selectWhat);
put("db", db);
Expand Down Expand Up @@ -189,7 +188,7 @@ public StorageResponseObject insert(String db, String table, JSONObject json, bo
if (!tableExists(db, table)) createTable(db, table);
createTablePathIfNotExists(db, table);

JSONObject _nodes = gl.ao.serengeti.Serengeti.network.getPrimarySecondary();
JSONObject _nodes = Serengeti.network.getPrimarySecondary();
String _node_primary_id = _nodes.getJSONObject("primary").getString("id");
String _node_primary_ip = _nodes.getJSONObject("primary").getString("ip");
String _node_secondary_id = _nodes.getJSONObject("secondary").getString("id");
Expand All @@ -205,12 +204,12 @@ public StorageResponseObject insert(String db, String table, JSONObject json, bo
put("json", json);
put("type", "ReplicateInsertObject");
}}.toString();
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(_node_primary_id, _node_primary_ip, _jsonInsertReplicate);
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(_node_secondary_id, _node_secondary_ip, _jsonInsertReplicate);
Serengeti.network.communicateQueryLogSingleNode(_node_primary_id, _node_primary_ip, _jsonInsertReplicate);
Serengeti.network.communicateQueryLogSingleNode(_node_secondary_id, _node_secondary_ip, _jsonInsertReplicate);


// tell all nodes about where the replicated data is stored
gl.ao.serengeti.Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
put("type", "TableReplicaObjectInsertOrReplace");
put("db", db);
put("table", table);
Expand Down Expand Up @@ -261,9 +260,9 @@ public boolean update(String db, String table, String update_key, String update_
JSONObject _nodes = tro.getRowReplica(_row_id);

String _node_primary_id = _nodes.getString("primary");
String _node_primary_ip = gl.ao.serengeti.Serengeti.network.getIPFromUUID(_node_primary_id);
String _node_primary_ip = Serengeti.network.getIPFromUUID(_node_primary_id);
String _node_secondary_id = _nodes.getString("secondary");
String _node_secondary_ip = gl.ao.serengeti.Serengeti.network.getIPFromUUID(_node_secondary_id);
String _node_secondary_ip = Serengeti.network.getIPFromUUID(_node_secondary_id);

JSONObject _json = new JSONObject() {{
put("update_key", update_key);
Expand All @@ -280,8 +279,8 @@ public boolean update(String db, String table, String update_key, String update_
put("json", _json);
put("type", "ReplicateUpdateObject");
}}.toString();
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(_node_primary_id, _node_primary_ip, _jsonUpdateReplicate);
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(_node_secondary_id, _node_secondary_ip, _jsonUpdateReplicate);
Serengeti.network.communicateQueryLogSingleNode(_node_primary_id, _node_primary_ip, _jsonUpdateReplicate);
Serengeti.network.communicateQueryLogSingleNode(_node_secondary_id, _node_secondary_ip, _jsonUpdateReplicate);

return true;
}
Expand Down Expand Up @@ -318,9 +317,9 @@ public boolean delete(String db, String table, String where_col, String where_va
JSONObject _nodes = tro.getRowReplica(_row_id);

String _node_primary_id = _nodes.getString("primary");
String _node_primary_ip = gl.ao.serengeti.Serengeti.network.getIPFromUUID(_node_primary_id);
String _node_primary_ip = Serengeti.network.getIPFromUUID(_node_primary_id);
String _node_secondary_id = _nodes.getString("secondary");
String _node_secondary_ip = gl.ao.serengeti.Serengeti.network.getIPFromUUID(_node_secondary_id);
String _node_secondary_ip = Serengeti.network.getIPFromUUID(_node_secondary_id);

JSONObject _json = new JSONObject() {{
put("where_col", where_col);
Expand All @@ -335,11 +334,11 @@ public boolean delete(String db, String table, String where_col, String where_va
put("json", _json);
put("type", "ReplicateDeleteObject");
}}.toString();
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(_node_primary_id, _node_primary_ip, _jsonDeleteReplicate);
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(_node_secondary_id, _node_secondary_ip, _jsonDeleteReplicate);
Serengeti.network.communicateQueryLogSingleNode(_node_primary_id, _node_primary_ip, _jsonDeleteReplicate);
Serengeti.network.communicateQueryLogSingleNode(_node_secondary_id, _node_secondary_ip, _jsonDeleteReplicate);

// tell all nodes about where the replicated data is stored
gl.ao.serengeti.Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
put("type", "TableReplicaObjectDelete");
put("db", db);
put("table", table);
Expand Down Expand Up @@ -385,7 +384,7 @@ public boolean createDatabase(String db, boolean isReplicationAction) {
Files.write(file, data);

//create directory path if not exists
gl.ao.serengeti.Serengeti.storage.createDatabasePathIfNotExists(db);
Serengeti.storage.createDatabasePathIfNotExists(db);

loadMetaDatabasesToMemory();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gl.ao.serengeti.storage;
package ms.ao.serengeti.storage;

import ms.ao.serengeti.Serengeti;
import org.json.JSONObject;

import java.util.Arrays;
Expand All @@ -16,15 +17,15 @@ public void queueLostNode(JSONObject node) {
new Thread(() -> {
try {
Thread.sleep(10000);
boolean nodeIsOnline = gl.ao.serengeti.Serengeti.network.nodeIsOnline(json.getString("ip"));
boolean nodeIsOnline = Serengeti.network.nodeIsOnline(json.getString("ip"));

if (!nodeIsOnline) {
// find out if we need to move any local data to another node
for (String tableKey: Storage.tableReplicaObjects.keySet()) {
for (String rowKey: Storage.tableReplicaObjects.get(tableKey).row_replicas.keySet()) {
String strRow = Storage.tableReplicaObjects.get(tableKey).row_replicas.get(rowKey);
JSONObject jsonRow = new JSONObject(strRow);
JSONObject prisec = gl.ao.serengeti.Serengeti.network.getPrimarySecondary();
JSONObject prisec = Serengeti.network.getPrimarySecondary();
String newPrimaryId = ((JSONObject)prisec.get("primary")).getString("id");
String newPrimaryIp = ((JSONObject)prisec.get("primary")).getString("ip");
String newSecondaryId = ((JSONObject)prisec.get("secondary")).getString("id");
Expand Down Expand Up @@ -55,16 +56,16 @@ public void queueLostNode(JSONObject node) {
}}.toString();

if (found.equals("primary")) {
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(newPrimaryId, newPrimaryIp, _jsonReplaceReplicate);
Serengeti.network.communicateQueryLogSingleNode(newPrimaryId, newPrimaryIp, _jsonReplaceReplicate);
row_replica = Storage.tableReplicaObjects.get(tableKey).updateNewPrimary(rowKey, newPrimaryId);
} else if (found.equals("secondary")) {
gl.ao.serengeti.Serengeti.network.communicateQueryLogSingleNode(newPrimaryId, newPrimaryIp, _jsonReplaceReplicate);
Serengeti.network.communicateQueryLogSingleNode(newPrimaryId, newPrimaryIp, _jsonReplaceReplicate);
row_replica = Storage.tableReplicaObjects.get(tableKey).updateNewSecondary(rowKey, newSecondaryId);
}

if (row_replica != null) {
final JSONObject row_replica_final = row_replica;
gl.ao.serengeti.Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
Serengeti.network.communicateQueryLogAllNodes(new JSONObject() {{
put("type", "TableReplicaObjectInsertOrReplace");
put("db", databaseName);
put("table", tableName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gl.ao.serengeti.storage;
package ms.ao.serengeti.storage;

import java.util.HashMap;
import java.util.Map;
Expand Down
Loading

0 comments on commit 279e9a8

Please sign in to comment.