This commit is contained in:
anhefti 2019-12-12 19:47:20 +01:00
parent 4490aa34cf
commit 76174fecad
7 changed files with 110 additions and 45 deletions

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package ch.ethz.seb.sebserver;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.webservice.WebserviceInfo;
@Lazy
@Component
public class SEBServerInit {
private static final Logger INIT_LOGGER = LoggerFactory.getLogger("SEB SERVER INIT");
private final Environment environment;
private final WebserviceInfo webserviceInfo;
private boolean initialized = false;
protected SEBServerInit(final Environment environment, final WebserviceInfo webserviceInfo) {
this.environment = environment;
this.webserviceInfo = webserviceInfo;
}
public void init() {
if (!this.initialized) {
INIT_LOGGER.info("----> ___ ___ ___ ___ ");
INIT_LOGGER.info("----> / __|| __|| _ ) / __| ___ _ _ __ __ ___ _ _ ");
INIT_LOGGER.info("----> \\__ \\| _| | _ \\ \\__ \\/ -_)| '_|\\ V // -_)| '_|");
INIT_LOGGER.info("----> |___/|___||___/ |___/\\___||_| \\_/ \\___||_| ");
INIT_LOGGER.info("---->");
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> Version: {}", this.webserviceInfo.getSebServerVersion());
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> Active profiles: {}", Arrays.toString(this.environment.getActiveProfiles()));
INIT_LOGGER.info("---->");
this.initialized = true;
}
}
}

View file

@ -14,6 +14,7 @@ import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.SEBServerInit;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
@Component
@ -22,16 +23,21 @@ public class GuiInit implements ApplicationListener<ApplicationReadyEvent> {
static final Logger INIT_LOGGER = LoggerFactory.getLogger("SEB SERVER INIT");
private final SEBServerInit sebServerInit;
protected GuiInit(final SEBServerInit sebServerInit) {
this.sebServerInit = sebServerInit;
}
@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {
INIT_LOGGER.info("----> ___ ___ ___ ___ ");
INIT_LOGGER.info("----> / __|| __|| _ ) / __| ___ _ _ __ __ ___ _ _ ");
INIT_LOGGER.info("----> \\__ \\| _| | _ \\ \\__ \\/ -_)| '_|\\ V // -_)| '_|");
INIT_LOGGER.info("----> |___/|___||___/ |___/\\___||_| \\_/ \\___||_| ");
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> **** GUI Service ****");
INIT_LOGGER.info("---->");
this.sebServerInit.init();
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> **** GUI Service starting up... ****");
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> GUI Service sucessfully successfully started up!");
INIT_LOGGER.info("---->");
}

View file

@ -22,17 +22,21 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.Domain;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData;
import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
import ch.ethz.seb.sebserver.gui.service.ResourceService;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageContext;
import ch.ethz.seb.sebserver.gui.service.page.PageMessageException;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder;
import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer;
@ -129,10 +133,22 @@ public class MonitoringRunningExam implements TemplateComposer {
actionBuilder
.newAction(ActionDefinition.MONITOR_CLIENT_CONNECTION)
.withParentEntityKey(entityKey)
.withSelect(
clientTable::getSelection,
PageAction::applySingleSelectionAsEntityKey,
EMPTY_SELECTION_TEXT_KEY)
.withExec(pageAction -> {
final Tuple<String> singleSelection = clientTable.getSingleSelection();
if (singleSelection == null) {
throw new PageMessageException(EMPTY_SELECTION_TEXT_KEY);
}
final PageAction copyOfPageAction = PageAction.copyOf(pageAction);
copyOfPageAction.withEntityKey(new EntityKey(
singleSelection._1,
EntityType.CLIENT_CONNECTION));
copyOfPageAction.withAttribute(
Domain.CLIENT_CONNECTION.ATTR_CONNECTION_TOKEN,
singleSelection._2);
return copyOfPageAction;
})
.publishIf(() -> currentUser.get().hasRole(UserRole.EXAM_SUPPORTER));
}

View file

@ -117,7 +117,9 @@ public abstract class RestCall<T> {
if (responseEntity.getStatusCode() == HttpStatus.OK) {
log.info("************* {}" + responseEntity.getBody());
if (log.isTraceEnabled()) {
log.trace("response body --> {}" + responseEntity.getBody());
}
return Result.of(RestCall.this.jsonMapper.readValue(
responseEntity.getBody(),

View file

@ -23,6 +23,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.SEBServerInit;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.EventHandlingInit;
@ -33,17 +34,20 @@ public class WebserviceInit implements ApplicationListener<ApplicationReadyEvent
static final Logger INIT_LOGGER = LoggerFactory.getLogger("SEB SERVER INIT");
private final SEBServerInit sebServerInit;
private final Environment environment;
private final WebserviceInfo webserviceInfo;
private final AdminUserInitializer adminUserInitializer;
private final ApplicationEventPublisher applicationEventPublisher;
protected WebserviceInit(
final SEBServerInit sebServerInit,
final Environment environment,
final WebserviceInfo webserviceInfo,
final AdminUserInitializer adminUserInitializer,
final ApplicationEventPublisher applicationEventPublisher) {
this.sebServerInit = sebServerInit;
this.environment = environment;
this.webserviceInfo = webserviceInfo;
this.adminUserInitializer = adminUserInitializer;
@ -53,18 +57,9 @@ public class WebserviceInit implements ApplicationListener<ApplicationReadyEvent
@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {
if (!guiProfileActive()) {
this.sebServerInit.init();
INIT_LOGGER.info("----> ___ ___ ___ ___ ");
INIT_LOGGER.info("----> / __|| __|| _ ) / __| ___ _ _ __ __ ___ _ _ ");
INIT_LOGGER.info("----> \\__ \\| _| | _ \\ \\__ \\/ -_)| '_|\\ V // -_)| '_|");
INIT_LOGGER.info("----> |___/|___||___/ |___/\\___||_| \\_/ \\___||_| ");
INIT_LOGGER.info("---->");
}
INIT_LOGGER.info("----> **** Webservice ****");
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> Starting up...");
INIT_LOGGER.info("----> **** Webservice starting up... ****");
INIT_LOGGER.info("----> ");
INIT_LOGGER.info("----> Init Database with flyway...");
@ -76,12 +71,12 @@ public class WebserviceInit implements ApplicationListener<ApplicationReadyEvent
INIT_LOGGER.info("----> ");
INIT_LOGGER.info("----> Start Services...");
INIT_LOGGER.info("----> ");
this.applicationEventPublisher.publishEvent(new EventHandlingInit(this));
INIT_LOGGER.info("----> ");
this.applicationEventPublisher.publishEvent(new EventHandlingInit(this));
INIT_LOGGER.info("----> ");
INIT_LOGGER.info("----> SEB Server successfully started up!");
INIT_LOGGER.info("---->");
INIT_LOGGER.info("----> Version: {}", this.webserviceInfo.getSebServerVersion());
try {
INIT_LOGGER.info("----> Server address: {}", this.environment.getProperty("server.address"));
@ -115,20 +110,4 @@ public class WebserviceInit implements ApplicationListener<ApplicationReadyEvent
this.webserviceInfo.getHostAddress());
}
private boolean guiProfileActive() {
final String[] activeProfiles = this.environment.getActiveProfiles();
if (activeProfiles == null) {
return false;
}
for (int i = 0; i < activeProfiles.length; i++) {
if (activeProfiles[i] != null && (activeProfiles[i].contains("gui") ||
activeProfiles[i].contains("demo"))) {
return true;
}
}
return false;
}
}

View file

@ -102,8 +102,8 @@ public class HTTPClientBot {
this.numberOfConnections = Integer.parseInt(properties.getProperty("numberOfConnections", "1"));
this.pingInterval = Long.parseLong(properties.getProperty("pingInterval", "200"));
this.establishDelay = Long.parseLong(properties.getProperty("establishDelay", "0"));
this.pingPause = Long.parseLong(properties.getProperty("pingPause", "0"));
this.pingPauseDelay = Long.parseLong(properties.getProperty("pingPauseDelay", "0"));
this.pingPause = Long.parseLong(properties.getProperty("pingPause", "10000"));
this.pingPauseDelay = Long.parseLong(properties.getProperty("pingPauseDelay", "20000"));
this.errorInterval = Long.parseLong(properties.getProperty("errorInterval", String.valueOf(TEN_SECONDS)));
// this.runtime = Long.parseLong(properties.getProperty("runtime", String.valueOf(ONE_MINUTE)));
this.runtime = Long.parseLong(properties.getProperty("runtime", String.valueOf(ONE_MINUTE)));
@ -228,11 +228,16 @@ public class HTTPClientBot {
try {
final long startTime = System.currentTimeMillis();
final long endTime = startTime + HTTPClientBot.this.runtime;
final long pingPauseStart = startTime + HTTPClientBot.this.pingPauseDelay;
final long pingPauseEnd = pingPauseStart + HTTPClientBot.this.pingPause;
long currentTime = startTime;
long lastPingTime = startTime;
long lastErrorTime = startTime;
while (currentTime < endTime) {
if (currentTime - lastPingTime >= HTTPClientBot.this.pingInterval) {
if (currentTime - lastPingTime >= HTTPClientBot.this.pingInterval &&
!(currentTime > pingPauseStart && currentTime < pingPauseEnd)) {
pingHeader.next();
sendPing(pingHeader);
lastPingTime = currentTime;

View file

@ -9,4 +9,6 @@
<root level="WARN" additivity="true">
<appender-ref ref="STDOUT" />
</root>
<Logger name="ch.ethz.seb.sebserver.HTTPClientBot" level="INFO" additivity="true" />
</configuration>