Skip to content

Commit

Permalink
SEBSERV-435 improved SEB Server SPS user account sync
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Nov 28, 2023
1 parent 50456b8 commit 6a0d53c
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AsyncServiceSpringConfig implements AsyncConfigurer {

public static final String EXECUTOR_BEAN_NAME = "AsyncServiceExecutorBean";

/** This ThreadPool is used for internal long running background tasks */
/** This ThreadPool is used for internal long-running background tasks */
@Bean(name = EXECUTOR_BEAN_NAME)
public Executor threadPoolTaskExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
Expand Down Expand Up @@ -61,8 +61,8 @@ public Executor examAPIThreadPoolTaskExecutor() {
public static final String EXAM_API_PING_SERVICE_EXECUTOR_BEAN_NAME = "examAPIPingThreadPoolTaskExecutor";

/** This ThreadPool is used for ping handling in a distributed setup and shall reject
* incoming ping requests as fast as possible if there is to much load on the DB.
* We prefer to loose a shared ping update and respond to the client in time over a client request timeout */
* incoming ping requests as fast as possible if there is too much load on the DB.
* We prefer to lose a shared ping update and respond to the client in time over a client request timeout */
@Bean(name = EXAM_API_PING_SERVICE_EXECUTOR_BEAN_NAME)
public Executor examAPIPingThreadPoolTaskExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ch.ethz.seb.sebserver.gbl.model.exam;

public interface SPSAPIAccessData {

Long getExamId();

String getSpsServiceURL();

String getSpsAPIKey();

CharSequence getSpsAPISecret();

String getSpsAccountId();

CharSequence getSpsAccountPassword();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import ch.ethz.seb.sebserver.gbl.model.Domain;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ScreenProctoringSettings {
public class ScreenProctoringSettings implements SPSAPIAccessData {

public static final String ATTR_ENABLE_SCREEN_PROCTORING = "enableScreenProctoring";
public static final String ATTR_SPS_SERVICE_URL = "spsServiceURL";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Set;
import java.util.UUID;

import ch.ethz.seb.sebserver.gbl.model.exam.SPSAPIAccessData;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -329,7 +330,7 @@ public String toString() {
return builder.toString();
}

public static final class ScreenProctoringServiceBundle {
public static final class ScreenProctoringServiceBundle implements SPSAPIAccessData {

public final boolean bundled;
public final String serviceURL;
Expand Down Expand Up @@ -362,6 +363,36 @@ public ScreenProctoringServiceBundle() {
this.apiAccountPassword = null;
}

@Override
public Long getExamId() {
return null;
}

@Override
public String getSpsServiceURL() {
return serviceURL;
}

@Override
public String getSpsAPIKey() {
return clientId;
}

@Override
public CharSequence getSpsAPISecret() {
return clientSecret;
}

@Override
public String getSpsAccountId() {
return apiAccountName;
}

@Override
public CharSequence getSpsAccountPassword() {
return apiAccountPassword;
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public Result<ScreenProctoringSettings> saveScreenProctoringSettings(
if (parentEntityKey.entityType == EntityType.EXAM) {

this.screenProctoringService
.applyScreenProctoingForExam(settings.examId)
.applyScreenProctoringForExam(settings.examId)
.onError(error -> this.proctoringSettingsDAO
.disableScreenProctoring(screenProctoringSettings.examId))
.getOrThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

import java.util.Collection;

import ch.ethz.seb.sebserver.gbl.async.AsyncServiceSpringConfig;
import org.springframework.context.event.EventListener;

import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
import ch.ethz.seb.sebserver.gbl.model.exam.ScreenProctoringSettings;
import ch.ethz.seb.sebserver.gbl.model.session.ScreenProctoringGroup;
import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl.ExamDeletionEvent;
import org.springframework.scheduling.annotation.Async;

public interface ScreenProctoringService extends SessionUpdateTask {

Expand Down Expand Up @@ -45,7 +47,7 @@ default void processSessionUpdateTask() {
*
* @param examId use the screen proctoring settings of the exam with the given exam id
* @return Result refer to the given Exam or to an error when happened */
Result<Exam> applyScreenProctoingForExam(Long examId);
Result<Exam> applyScreenProctoringForExam(Long examId);

/** Get list of all screen proctoring collecting groups for a particular exam.
*
Expand All @@ -64,7 +66,7 @@ default void processSessionUpdateTask() {
@EventListener(ExamFinishedEvent.class)
void notifyExamFinished(ExamFinishedEvent event);

/** This is been called just before an Exam gets deleted on the permanent storage.
/** This is being called just before an Exam gets deleted on the permanent storage.
* This deactivates and dispose or deletes all exam relevant domain entities on the SPS service side.
*
* @param event The ExamDeletionEvent reference all PKs of Exams that are going to be deleted. */
Expand All @@ -75,8 +77,8 @@ default void processSessionUpdateTask() {
* if screen proctoring is enabled for the specified exam.
*
* @param examId The SEB Server exam identifier
* @return Result refer to the the given exam data or to an error when happened */
Result<Exam> updateExamOnScreenProctoingService(Long examId);
* @return Result refer to the given exam data or to an error when happened */
Result<Exam> updateExamOnScreenProctoringService(Long examId);

/** This is internally used to update client connections that are active but has no groups assignment yet.
* This attaches SEB client connections to proctoring group of an exam in one batch by checking for
Expand All @@ -85,4 +87,7 @@ default void processSessionUpdateTask() {
* SPS connection instruction to SEB client to connect and start sending screenshots. */
void updateClientConnections();

@Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME)
void synchronizeSPSUser(final String userUUID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Result<Set<String>> updateExamFromLMS(final Long lmsSetupId, final Map<String, E

// also update the exam on screen proctoring service if exam has screen proctoring enabled
this.screenProctoringService
.updateExamOnScreenProctoingService(exam.id)
.updateExamOnScreenProctoringService(exam.id)
.onError(error -> log
.error("Failed to update exam changes for screen proctoring"));

Expand Down
Loading

0 comments on commit 6a0d53c

Please sign in to comment.