Skip to content
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
2 changes: 2 additions & 0 deletions jdk_21_maven/cs/rest/joinus/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/mvnw text eol=lf
*.cmd text eol=crlf
37 changes: 37 additions & 0 deletions jdk_21_maven/cs/rest/joinus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
target/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

# Datasets
src/main/resources/JoinUs_Dataset/Meetup/*.csv
src/main/resources/JoinUs_Dataset/dataset2_joinUs/*.csv

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip
3 changes: 3 additions & 0 deletions jdk_21_maven/cs/rest/joinus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LSMSDB Project Group 29
* The Java application code can be found under src
* The deployment setup can be found under deploy
23 changes: 23 additions & 0 deletions jdk_21_maven/cs/rest/joinus/deploy/mongodb/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
mongo:
image: mongo:8.2.4-noble
container_name: "mongo${NODE_ID}"
restart: always
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
- ./mongo-keyfile:/etc/mongo-keyfile:ro
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
RS_NAME: ${RS_NAME}
command: >
mongod
--replSet ${RS_NAME}
--bind_ip_all
--auth
--keyFile /etc/mongo-keyfile

volumes:
mongo_data:
18 changes: 18 additions & 0 deletions jdk_21_maven/cs/rest/joinus/deploy/mongodb/prune_past_events.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail

: "${MONGODB_URI:?Missing MONGODB_URI}"
: "${MONGODB_DB:?Missing MONGODB_DB}"

mongosh "$MONGODB_URI" --quiet --eval '
const dbName = process.env.MONGODB_DB;
const database = db.getSiblingDB(dbName);
const now = new Date();

for (const c of ["groups", "members"]) {
database.getCollection(c).updateMany(
{ "upcoming_events.event_time": { $lt: now } },
{ $pull: { upcoming_events: { event_time: { $lt: now } } } }
);
}
'
86 changes: 86 additions & 0 deletions jdk_21_maven/cs/rest/joinus/deploy/mongodb/rs0-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
set -euo pipefail

# ------------------------ CONFIG -------------------------
RS_NAME="rs0"
MEMBERS=("10.1.1.18:27017" "10.1.1.19:27017" "10.1.1.20:27017")

ADMIN_USER="mongodb"
ADMIN_PASS="secure_password"

CONTAINER="mongo1" # container name on VM1
# ---------------------------------------------------------

echo "[*] Checking mongod is reachable in container ${CONTAINER}..."
sudo docker exec -i "${CONTAINER}" mongosh --quiet --eval 'db.runCommand({ ping: 1 })' >/dev/null
echo "[+] mongod reachable."

echo "[*] Initiating replica set (or skipping if already initialized)..."
sudo docker exec -i "${CONTAINER}" mongosh \
-u "${ADMIN_USER}" -p "${ADMIN_PASS}" --authenticationDatabase admin --quiet --eval "
(function() {
const rsName = '${RS_NAME}';
const members = [
{ _id: 0, host: '${MEMBERS[0]}' },
{ _id: 1, host: '${MEMBERS[1]}' },
{ _id: 2, host: '${MEMBERS[2]}' },
];

function sleep(ms) { const t = Date.now(); while (Date.now() - t < ms) {} }

// If already initialized, replSetGetStatus will succeed.
try {
const st = db.adminCommand({ replSetGetStatus: 1 });
print('[+] Replica set already initialized (set=' + st.set + '). Skipping rs.initiate().');
return;
} catch (e) {
const msg = (e && e.message) ? e.message : String(e);
if (!msg.includes('NotYetInitialized') && !msg.includes('no replset config has been received')) {
print('[!] Unexpected error checking replSetGetStatus: ' + msg);
throw e;
}
}

print('[*] Running rs.initiate() for ' + rsName + ' ...');
rs.initiate({ _id: rsName, members });

// Wait until PRIMARY elected (may not be this node)
print('[*] Waiting for PRIMARY election...');
const deadline = Date.now() + 180000;
while (Date.now() < deadline) {
const hello = db.adminCommand({ hello: 1 });
if (hello.setName === rsName && hello.primary) {
print('[+] PRIMARY is: ' + hello.primary);
return;
}
sleep(1000);
}
throw new Error('Timed out waiting for PRIMARY election');
})();
"

echo "[*] Setting default write concern..."
sudo docker exec -i "${CONTAINER}" mongosh \
-u "${ADMIN_USER}" -p "${ADMIN_PASS}" --authenticationDatabase admin --quiet --eval "
(function() {
const adminDb = db.getSiblingDB('admin');

// Set default RW concern (majority writes)
print('[*] Setting default writeConcern to majority...');
const res = adminDb.runCommand({
setDefaultRWConcern: 1,
defaultWriteConcern: { w: 'majority' }
});
if (res.ok !== 1) throw new Error('setDefaultRWConcern failed: ' + JSON.stringify(res));
print('[+] Default writeConcern set.');
})();
"

echo "[*] Final replica set status (authenticated):"
sudo docker exec -it "${CONTAINER}" mongosh \
-u "${ADMIN_USER}" -p "${ADMIN_PASS}" --authenticationDatabase admin --quiet --eval "rs.status()"

echo
echo "[+] Done."
echo " App connection string example:"
echo " mongodb://${ADMIN_USER}:${ADMIN_PASS}@${MEMBERS[0]},${MEMBERS[1]},${MEMBERS[2]}?replicaSet=${RS_NAME}&authSource=admin&readPreference=nearest"
14 changes: 14 additions & 0 deletions jdk_21_maven/cs/rest/joinus/deploy/mongodb/vm1.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
NODE_ID=1

RS_NAME=rs0

# Create admin user on first init
MONGO_INITDB_ROOT_USERNAME=mongodb
MONGO_INITDB_ROOT_PASSWORD=secure_password



# Settings for prune_past_events.sh
# Ensure LF line endings to work in cron job
MONGODB_URI="mongodb://mongodb:secure_password@10.1.1.18:27017,10.1.1.19:27017,10.1.1.20:27017/?replicaSet=rs0&readPreference=primary&retryWrites=true&w=majority"
MONGODB_DB="joinUs"
6 changes: 6 additions & 0 deletions jdk_21_maven/cs/rest/joinus/deploy/mongodb/vm2.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NODE_ID=2

RS_NAME=rs0

MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
6 changes: 6 additions & 0 deletions jdk_21_maven/cs/rest/joinus/deploy/mongodb/vm3.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NODE_ID=3

RS_NAME=rs0

MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
16 changes: 16 additions & 0 deletions jdk_21_maven/cs/rest/joinus/deploy/neo4j/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
neo4j:
image: neo4j:2025.12.1
container_name: neo4j
restart: always
ports:
- "7474:7474" # HTTP (Neo4j Browser)
- "7687:7687" # Bolt
volumes:
- neo4j_data:/data
- ./import:/var/lib/neo4j/import
environment:
NEO4J_AUTH: neo4j/secure_password

volumes:
neo4j_data:
27 changes: 27 additions & 0 deletions jdk_21_maven/cs/rest/joinus/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.8"

services:
mongodb:
image: mongo:8.2.3-noble
container_name: mongodb
restart: unless-stopped
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db

neo4j:
image: neo4j:2025.12.1
container_name: neo4j
restart: unless-stopped
ports:
- "7474:7474" # HTTP (Neo4j Browser)
- "7687:7687" # Bolt
environment:
NEO4J_AUTH: neo4j/password
volumes:
- neo4j_data:/data

volumes:
mongodb_data:
neo4j_data:
Loading
Loading