From c53336f1d4daccc6fff2e85d0ca86e634d37f334 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 15 Mar 2022 08:39:17 +0100 Subject: [PATCH 1/2] prepare for 1.3.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d7a50792..3023cdd9 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ jar - 1.3-rc3 + 1.3.1-SNAPSHOT ${sebserver-version} ${sebserver-version} UTF-8 From 9cc020712a97e8627f7c793ec23e76d56428148e Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 23 Mar 2022 12:31:56 +0100 Subject: [PATCH 2/2] added some cleanup after exam finished --- .../servicelayer/dao/ClientConnectionDAO.java | 7 +++++ .../dao/impl/ClientConnectionDAOImpl.java | 28 +++++++++++++++++++ .../session/ExamSessionService.java | 7 +++++ .../session/impl/ExamSessionControlTask.java | 5 ++++ .../session/impl/ExamSessionServiceImpl.java | 16 +++++++++++ 5 files changed, 63 insertions(+) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ClientConnectionDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ClientConnectionDAO.java index 200f641f..3dcd593c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ClientConnectionDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ClientConnectionDAO.java @@ -15,6 +15,7 @@ import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import ch.ethz.seb.sebserver.gbl.model.EntityKey; +import ch.ethz.seb.sebserver.gbl.model.exam.Exam; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientConnectionRecord; @@ -180,4 +181,10 @@ public interface ClientConnectionDAO extends * @return Result refer to the relevant VDI pair connection if exists or to an error if not */ Result getVDIPairCompanion(Long examId, String clientName); + /** Deletes all client indicator value entries within the client_indicator table for a given exam. + * + * @param exam the Exam to delete all currently registered indicator value entries + * @return Result refer to the given Exam or to an error when happened. */ + Result deleteClientIndicatorValues(Exam exam); + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java index 69f050a1..009fae8a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java @@ -32,6 +32,7 @@ import ch.ethz.seb.sebserver.gbl.api.API.BulkActionType; import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.model.EntityDependency; import ch.ethz.seb.sebserver.gbl.model.EntityKey; +import ch.ethz.seb.sebserver.gbl.model.exam.Exam; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; @@ -694,6 +695,33 @@ public class ClientConnectionDAOImpl implements ClientConnectionDAO { }); } + @Override + @Transactional + public Result deleteClientIndicatorValues(final Exam exam) { + return Result.tryCatch(() -> { + + final List clientConnections = this.clientConnectionRecordMapper.selectIdsByExample() + .where( + ClientConnectionRecordDynamicSqlSupport.examId, + SqlBuilder.isEqualTo(exam.id)) + .build() + .execute(); + + if (clientConnections == null || clientConnections.isEmpty()) { + return exam; + } + + this.clientIndicatorRecordMapper.deleteByExample() + .where( + ClientIndicatorRecordDynamicSqlSupport.clientConnectionId, + SqlBuilder.isIn(clientConnections)) + .build() + .execute(); + + return exam; + }); + } + private Result recordById(final Long id) { return Result.tryCatch(() -> { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java index e66ebdaa..7091a992 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java @@ -182,6 +182,13 @@ public interface ExamSessionService { * @return Result refer to the collection of connection tokens or to an error when happened. */ Result> getActiveConnectionTokens(Long examId); + /** Called to notify that the given exam has just been finished. + * This cleanup all exam session caches for the given exam and also cleanup session based stores on the persistent. + * + * @param exam the Exam that has just been finished + * @return Result refer to the finished exam or to an error when happened. */ + Result notifyExamFinished(final Exam exam); + /** Use this to check if the current cached running exam is up to date * and if not to flush the cache. * diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java index 5aa76dd7..c5d335c2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java @@ -29,6 +29,7 @@ import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.WebserviceInfo; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamProctoringRoomService; +import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamSessionService; import ch.ethz.seb.sebserver.webservice.servicelayer.session.SEBClientConnectionService; @Service @@ -42,6 +43,7 @@ public class ExamSessionControlTask implements DisposableBean { private final ExamUpdateHandler examUpdateHandler; private final ExamProctoringRoomService examProcotringRoomService; private final WebserviceInfo webserviceInfo; + private final ExamSessionService examSessionService; private final Long examTimePrefix; private final Long examTimeSuffix; @@ -54,6 +56,7 @@ public class ExamSessionControlTask implements DisposableBean { final ExamUpdateHandler examUpdateHandler, final ExamProctoringRoomService examProcotringRoomService, final WebserviceInfo webserviceInfo, + final ExamSessionService examSessionService, @Value("${sebserver.webservice.api.exam.time-prefix:3600000}") final Long examTimePrefix, @Value("${sebserver.webservice.api.exam.time-suffix:3600000}") final Long examTimeSuffix, @Value("${sebserver.webservice.api.exam.update-interval:1 * * * * *}") final String examTaskCron, @@ -63,6 +66,7 @@ public class ExamSessionControlTask implements DisposableBean { this.sebClientConnectionService = sebClientConnectionService; this.examUpdateHandler = examUpdateHandler; this.webserviceInfo = webserviceInfo; + this.examSessionService = examSessionService; this.examTimePrefix = examTimePrefix; this.examTimeSuffix = examTimeSuffix; this.examTaskCron = examTaskCron; @@ -185,6 +189,7 @@ public class ExamSessionControlTask implements DisposableBean { .filter(exam -> exam.endTime != null && exam.endTime.plus(this.examTimeSuffix).isBefore(now)) .flatMap(exam -> Result.skipOnError(this.examUpdateHandler.setFinished(exam, updateId))) .flatMap(exam -> Result.skipOnError(this.examProcotringRoomService.disposeRoomsForExam(exam))) + .flatMap(exam -> Result.skipOnError(this.examSessionService.notifyExamFinished(exam))) .collect(Collectors.toMap(Exam::getId, Exam::getName)); if (!updated.isEmpty()) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java index c172a014..4240119e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java @@ -393,6 +393,22 @@ public class ExamSessionServiceImpl implements ExamSessionService { .getActiveConnctionTokens(examId); } + @Override + public Result notifyExamFinished(final Exam exam) { + return Result.tryCatch(() -> { + if (!isExamRunning(exam.id)) { + this.flushCache(exam); + if (this.distributedSetup) { + this.clientConnectionDAO + .deleteClientIndicatorValues(exam) + .getOrThrow(); + } + } + + return exam; + }); + } + @Override public Result updateExamCache(final Long examId) {