fixed ping (use SEB Server system-clock instead of SEB time sent)
This commit is contained in:
parent
5229906f69
commit
150c679f21
3 changed files with 39 additions and 12 deletions
|
@ -11,7 +11,9 @@ package ch.ethz.seb.sebserver.webservice.datalayer.checks;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -19,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||||
import ch.ethz.seb.sebserver.webservice.DBIntegrityCheck;
|
import ch.ethz.seb.sebserver.webservice.DBIntegrityCheck;
|
||||||
|
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.OrientationRecordDynamicSqlSupport;
|
||||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.OrientationRecordMapper;
|
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.OrientationRecordMapper;
|
||||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.OrientationRecord;
|
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.OrientationRecord;
|
||||||
|
|
||||||
|
@ -68,7 +71,12 @@ public class OrientationTableDuplicatesCheck implements DBIntegrityCheck {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tryFix) {
|
if (tryFix) {
|
||||||
toDelete
|
final List<Long> checkedToDelete = toDelete
|
||||||
|
.stream()
|
||||||
|
.filter(this::doubleCheck)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
checkedToDelete
|
||||||
.stream()
|
.stream()
|
||||||
.forEach(this.orientationRecordMapper::deleteByPrimaryKey);
|
.forEach(this.orientationRecordMapper::deleteByPrimaryKey);
|
||||||
return "Fixed duplicates by deletion: " + toDelete;
|
return "Fixed duplicates by deletion: " + toDelete;
|
||||||
|
@ -79,6 +87,24 @@ public class OrientationTableDuplicatesCheck implements DBIntegrityCheck {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean doubleCheck(final Long id) {
|
||||||
|
try {
|
||||||
|
final OrientationRecord selectByPrimaryKey = this.orientationRecordMapper.selectByPrimaryKey(id);
|
||||||
|
final Long count = this.orientationRecordMapper.countByExample()
|
||||||
|
.where(
|
||||||
|
OrientationRecordDynamicSqlSupport.configAttributeId,
|
||||||
|
SqlBuilder.isEqualTo(selectByPrimaryKey.getConfigAttributeId()))
|
||||||
|
.and(
|
||||||
|
OrientationRecordDynamicSqlSupport.templateId,
|
||||||
|
SqlBuilder.isEqualTo(selectByPrimaryKey.getTemplateId()))
|
||||||
|
.build()
|
||||||
|
.execute();
|
||||||
|
return count != null && count.longValue() > 1;
|
||||||
|
} catch (final Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
|
|
@ -87,7 +87,8 @@ public final class PingIntervalClientIndicator extends AbstractPingIndicator {
|
||||||
this.lastUpdate = this.distributedIndicatorValueService.lastUpdate();
|
this.lastUpdate = this.distributedIndicatorValueService.lastUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentTimeMillis - value;
|
final double res = currentTimeMillis - value;
|
||||||
|
return res >= 0.0D ? res : 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -286,23 +286,23 @@ public class ExamAPI_V1_Controller {
|
||||||
public void ping(final HttpServletRequest request, final HttpServletResponse response) {
|
public void ping(final HttpServletRequest request, final HttpServletResponse response) {
|
||||||
|
|
||||||
final String connectionToken = request.getHeader(API.EXAM_API_SEB_CONNECTION_TOKEN);
|
final String connectionToken = request.getHeader(API.EXAM_API_SEB_CONNECTION_TOKEN);
|
||||||
final String timeStampString = request.getParameter(API.EXAM_API_PING_TIMESTAMP);
|
//final String timeStampString = request.getParameter(API.EXAM_API_PING_TIMESTAMP);
|
||||||
final String pingNumString = request.getParameter(API.EXAM_API_PING_NUMBER);
|
final String pingNumString = request.getParameter(API.EXAM_API_PING_NUMBER);
|
||||||
final String instructionConfirm = request.getParameter(API.EXAM_API_PING_INSTRUCTION_CONFIRM);
|
final String instructionConfirm = request.getParameter(API.EXAM_API_PING_INSTRUCTION_CONFIRM);
|
||||||
|
|
||||||
long pingTime;
|
// long pingTime;
|
||||||
try {
|
// try {
|
||||||
pingTime = Long.parseLong(timeStampString);
|
// pingTime = Long.parseLong(timeStampString);
|
||||||
} catch (final Exception e) {
|
// } catch (final Exception e) {
|
||||||
log.error("Invalid ping request: {}", connectionToken);
|
// log.error("Invalid ping request: {}", connectionToken);
|
||||||
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
// response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
final String instruction = this.sebClientConnectionService
|
final String instruction = this.sebClientConnectionService
|
||||||
.notifyPing(
|
.notifyPing(
|
||||||
connectionToken,
|
connectionToken,
|
||||||
pingTime,
|
Utils.getMillisecondsNow(),
|
||||||
pingNumString != null ? Integer.parseInt(pingNumString) : -1,
|
pingNumString != null ? Integer.parseInt(pingNumString) : -1,
|
||||||
instructionConfirm);
|
instructionConfirm);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue