From c5386e5a29ca8aea47ab4c006f28c2b03cca109b Mon Sep 17 00:00:00 2001
From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com>
Date: Sun, 6 Oct 2024 09:16:56 +1100
Subject: [PATCH 1/4] fix(database): extend db transaction timeout limit
---
backend/pom.xml | 4 ++++
.../src/main/resources/application.properties | 17 +++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/backend/pom.xml b/backend/pom.xml
index 5fa7348..0de9cd0 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -92,6 +92,10 @@
io.quarkus
quarkus-hibernate-orm-panache
+
+ io.quarkus
+ quarkus-smallrye-metrics
+
diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties
index ded64f1..b6a16de 100644
--- a/backend/src/main/resources/application.properties
+++ b/backend/src/main/resources/application.properties
@@ -2,7 +2,7 @@ quarkus.http.port=${PORT:8080}
# The solver runs only for 5 seconds to avoid a HTTP timeout in this simple implementation.
# It's recommended to run for at least 5 minutes ("5m") otherwise.
-quarkus.timefold.solver.termination.spent-limit=5s
+quarkus.timefold.solver.termination.spent-limit=6s
quarkus.http.cors=true
quarkus.http.cors.origins=*
quarkus.http.cors.methods=GET,POST,PUT,DELETE,OPTIONS
@@ -15,4 +15,17 @@ quarkus.datasource.password = ${QUARKUS_DATASOURCE_PASSWORD}
quarkus.datasource.jdbc.url = ${QUARKUS_DATASOURCE_JDBC_URL}
# drop and create the database at startup (use `update` to only update the schema)
-quarkus.hibernate-orm.database.generation = create-drop
\ No newline at end of file
+quarkus.hibernate-orm.database.generation = create-drop
+
+# datasource metrics
+quarkus.datasource.metrics.enabled=true
+quarkus.datasource.jdbc.enable-metrics=true
+
+# datasource log leak
+quarkus.datasource.jdbc.log-leak-detection=true
+
+# transaction timeout
+quarkus.transaction-manager.default-transaction-timeout=320s
+
+# debugger for large/complex db transactions
+quarkus.log.category."com.arjuna".level=DEBUG
\ No newline at end of file
From 6f01a0de3e8096038a0e317c640a50a05bf53b79 Mon Sep 17 00:00:00 2001
From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com>
Date: Sun, 6 Oct 2024 11:43:14 +1100
Subject: [PATCH 2/4] chore(database): add metrics logging and enable logfiles
---
.gitignore | 3 ++-
backend/.gitignore | 3 +++
backend/pom.xml | 14 +++++++++++---
.../src/main/java/org/acme/TimetableResource.java | 2 --
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
index 0e47db9..ffc496a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,5 @@
*.sw?
# env variables
-.env
\ No newline at end of file
+.env
+**/logs/
\ No newline at end of file
diff --git a/backend/.gitignore b/backend/.gitignore
index b1e5177..0780498 100644
--- a/backend/.gitignore
+++ b/backend/.gitignore
@@ -43,3 +43,6 @@ nb-configuration.xml
/.quarkus/cli/plugins/
# TLS Certificates
.certs/
+
+# logs
+**/logs/
\ No newline at end of file
diff --git a/backend/pom.xml b/backend/pom.xml
index 0de9cd0..e7a8180 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -52,6 +52,10 @@
ai.timefold.solver
timefold-solver-quarkus-jackson
+
+ io.quarkus
+ quarkus-agroal
+
io.quarkus
quarkus-junit5
@@ -93,8 +97,12 @@
quarkus-hibernate-orm-panache
- io.quarkus
- quarkus-smallrye-metrics
+ io.quarkus
+ quarkus-smallrye-metrics
+
+
+ io.quarkus
+ quarkus-narayana-jta
@@ -131,4 +139,4 @@
-
\ No newline at end of file
+
diff --git a/backend/src/main/java/org/acme/TimetableResource.java b/backend/src/main/java/org/acme/TimetableResource.java
index a28d45f..47bff24 100644
--- a/backend/src/main/java/org/acme/TimetableResource.java
+++ b/backend/src/main/java/org/acme/TimetableResource.java
@@ -72,9 +72,7 @@ public Unit handleUnit(Unit unit) {
public void findByCampusAndDelete(String campusName) {
List timetables = Timetable.listAll();
for (Timetable timetable : timetables) {
- System.out.println("CHECKING NOW\n");
if (campusName.equals(timetable.campusName)) {
- System.out.println("SMTH HAS BEEN DELETED WOOOO\n");
timetable.delete();
}
}
From d86a3db8b21fe2bb712253c985266b0c8a22621d Mon Sep 17 00:00:00 2001
From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com>
Date: Sun, 6 Oct 2024 11:41:35 +1100
Subject: [PATCH 3/4] fix(database): :bug: remove storage of students in Unit
class
---
.../src/main/java/org/acme/domain/Unit.java | 9 ++-
.../src/main/resources/application.properties | 55 +++++++++++++++++--
2 files changed, 57 insertions(+), 7 deletions(-)
diff --git a/backend/src/main/java/org/acme/domain/Unit.java b/backend/src/main/java/org/acme/domain/Unit.java
index 095599e..8bc6d00 100644
--- a/backend/src/main/java/org/acme/domain/Unit.java
+++ b/backend/src/main/java/org/acme/domain/Unit.java
@@ -10,6 +10,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
+import jakarta.persistence.Transient;
import java.time.DayOfWeek;
import java.time.Duration;
@@ -45,10 +46,13 @@ public class Unit extends PanacheEntity {
public LocalTime startTime;
// TODO: change unit to be the owner, rather than the student being owner
+ @Transient
@JsonIgnoreProperties("units")
@ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
public List students;
+ public int studentSize;
+
/*
* currently each unit only has 1 'slot' on the timetable, so it can only
* be associated with one room, but in the final product, we would most
@@ -90,6 +94,7 @@ public Unit(int unitID, String name, String course, Duration duration, List
Date: Sun, 6 Oct 2024 16:01:39 +1100
Subject: [PATCH 4/4] refactor(rooms): add campus attribute to Room class
---
.../src/main/java/org/acme/TimetableResource.java | 6 +++---
backend/src/main/java/org/acme/domain/Room.java | 14 ++++++++++----
.../solver/TimetableConstraintProviderTest.java | 6 +++---
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/backend/src/main/java/org/acme/TimetableResource.java b/backend/src/main/java/org/acme/TimetableResource.java
index 47bff24..1256789 100644
--- a/backend/src/main/java/org/acme/TimetableResource.java
+++ b/backend/src/main/java/org/acme/TimetableResource.java
@@ -93,9 +93,9 @@ public Timetable solveExample() throws ExecutionException, InterruptedException
Student h = new Student("h");
Student i = new Student("i");
- Room r1 = new Room("Room1", 2, true);
- Room r2 = new Room("Room2", 4, false);
- Room r3 = new Room("Room3", 4, false);
+ Room r1 = new Room("Room1", "building A", "campus A", 2, true);
+ Room r2 = new Room("Room2", "building B", "campus A", 4, false);
+ Room r3 = new Room("Room3", "building A", "campus B", 4, false);
Unit u1 = new Unit(1, "1", "Course A", Duration.ofHours(2), List.of(a, b), true);
Unit u2 = new Unit(2, "2", "Course A", Duration.ofHours(2), List.of(a, c, d, e), true);
diff --git a/backend/src/main/java/org/acme/domain/Room.java b/backend/src/main/java/org/acme/domain/Room.java
index 2e0fa31..883e39e 100644
--- a/backend/src/main/java/org/acme/domain/Room.java
+++ b/backend/src/main/java/org/acme/domain/Room.java
@@ -27,6 +27,8 @@ public class Room extends PanacheEntity {
public String buildingId;
+ public String campus;
+
public int capacity;
public boolean isLab;
@@ -53,12 +55,16 @@ public Room() {
/**
* Creates a room with its ID and capacity.
*
- * @param id The room’s id.
- * @param capacity The room's capacity.
- * @param isLab Whether the room is a laboratory.
+ * @param id The room’s id.
+ * @param buildingId The building that the room belongs to.
+ * @param buildingId The campus that the room belongs to.
+ * @param capacity The room's capacity.
+ * @param isLab Whether the room is a laboratory.
*/
- public Room(String id, int capacity, boolean isLab) {
+ public Room(String id, String buildingId, String campus, int capacity, boolean isLab) {
this.roomCode = id;
+ this.buildingId = buildingId;
+ this.campus = campus;
this.capacity = capacity;
this.isLab = isLab;
}
diff --git a/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java b/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java
index 74a8011..979e96e 100644
--- a/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java
+++ b/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java
@@ -15,9 +15,9 @@
@QuarkusTest
public class TimetableConstraintProviderTest {
- private static final Room ROOM1 = new Room("1", 2, true);
- private static final Room ROOM2 = new Room("2", 2, false);
- private static final Room ROOM3 = new Room("3", 2, true);
+ private static final Room ROOM1 = new Room("1", "building A", "campus A", 2, true);
+ private static final Room ROOM2 = new Room("2", "building B", "campus A", 2, false);
+ private static final Room ROOM3 = new Room("3", "building A", "campus B", 2, true);
private static final Student STUDENT1 = new Student("student1");
private static final Student STUDENT2 = new Student("student2");
private static final Student STUDENT3 = new Student("student3");