Commit e2e17b3e authored by Jujube Orange's avatar Jujube Orange
Browse files

Merge branch 'release/1.1.1'

parents fb135b56 c15c39d4
Pipeline #257317 canceled with stages
in 15 seconds
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
default:
cache:
paths:
- .m2/repository/
tags:
- qlf-ci.inria.fr
stages:
- build
- integration-tests
build:
image: maven:3.6.3-adoptopenjdk-11
stage: build
script:
- mvn -B -ntp -fae -DdeployAtEnd deploy
artifacts:
paths:
- "**/target/*.jar"
reports:
junit:
- "**/target/surefire-reports/TEST-*.xml"
integration-tests:
image: registry.gitlab.inria.fr/stemcovid19/tac-server/docker-image/tac-system-tests:latest
stage: integration-tests
before_script:
- export PATH="$PWD/docker-compose:$PATH"
script:
- clea up -d
- "echo 'TODO: run integration tests here' && sleep 5s && docker ps"
after_script:
- clea down
-Xms128m -Xmx256m -Djava.awt.headless=true
--settings .mvn/settings-ci.xml
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${env.CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
......@@ -3,7 +3,7 @@
<parent>
<artifactId>clea-server</artifactId>
<groupId>fr.gouv.clea</groupId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -44,8 +44,8 @@ CREATE TABLE stat_location
venue_category1 INT NOT NULL,
venue_category2 INT NOT NULL,
backward_visits BIGINT NOT NULL,
forward_visits BIGINT NOT NULL
forward_visits BIGINT NOT NULL,
CONSTRAINT statloc_pk PRIMARY KEY (period, venue_type, venue_category1, venue_category2)
);
CREATE INDEX IF NOT EXISTS statloc_period ON stat_location(period);
CREATE INDEX IF NOT EXISTS statloc_venue ON stat_location(venue_type, venue_category1, venue_category2);
......@@ -5,7 +5,7 @@
<parent>
<groupId>fr.gouv.clea</groupId>
<artifactId>clea-server</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>clea-client</artifactId>
......
-- Need for a Primary-key (cf TAC-750)
DROP INDEX statloc_period;
ALTER TABLE stat_location ADD CONSTRAINT statloc_pk PRIMARY KEY (period, venue_type,venue_category1,venue_category2);
-- Rebase flyway to v4 (v1 to v3 are already applied manually in INT, PPROD and PROD)
-- Rebase flyway to v6 (v1 to v4 are already applied manually in INT, PPROD and PROD)
-- v5 (stats reports sent from kafka will probably be apply manually
-- Next scripts to apply with flyway will be V5 and upper.
......@@ -4,7 +4,7 @@
<parent>
<groupId>fr.gouv.clea</groupId>
<artifactId>clea-server</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>clea-qr-simulator</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>fr.gouv.clea</groupId>
<artifactId>clea-server</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>clea-scoring-conf</artifactId>
......
......@@ -6,7 +6,7 @@
<parent>
<groupId>fr.gouv.clea</groupId>
<artifactId>clea-server</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>clea-venue-consumer</artifactId>
......
......@@ -3,6 +3,9 @@ package fr.gouv.clea.consumer.repository;
import fr.gouv.clea.consumer.model.StatLocation;
import fr.gouv.clea.consumer.model.StatLocationKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface IStatLocationJpaRepository extends JpaRepository<StatLocation, StatLocationKey>, StatLocationJpaRepositoryCustom {
public interface IStatLocationRepository extends JpaRepository<StatLocation, StatLocationKey> {
}
package fr.gouv.clea.consumer.repository;
import fr.gouv.clea.consumer.model.StatLocation;
public interface StatLocationJpaRepositoryCustom {
void insert(StatLocation stat);
void updateByIncrement(StatLocation stat);
}
package fr.gouv.clea.consumer.repository;
import fr.gouv.clea.consumer.model.StatLocation;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Repository
public class StatLocationJpaRepositoryCustomImpl implements StatLocationJpaRepositoryCustom{
@PersistenceContext
private EntityManager em;
/**
* @param stat object to Insert in database
* @throws DataIntegrityViolationException if stat line already exists
*/
@Override
@Transactional
public void insert(StatLocation stat) {
em.persist(stat);
em.flush();
}
/**
* Increment backward OR forward visit of an existing stat_location
* @param stat statistique with key and value to increment (+1 in backword or +1 in forward)
*/
@Override
@Transactional
public void updateByIncrement(StatLocation stat) {
em.createQuery("UPDATE StatLocation AS l "+
"SET l.backwardVisits=l.backwardVisits + :backVisits, l.forwardVisits=l.forwardVisits + :forwardVisits "+
"WHERE l.statLocationKey= :key")
.setParameter("backVisits", stat.getBackwardVisits())
.setParameter("forwardVisits", stat.getForwardVisits())
.setParameter("key", stat.getStatLocationKey())
.executeUpdate();
}
}
......@@ -4,32 +4,28 @@ import fr.gouv.clea.consumer.configuration.VenueConsumerConfiguration;
import fr.gouv.clea.consumer.model.StatLocation;
import fr.gouv.clea.consumer.model.StatLocationKey;
import fr.gouv.clea.consumer.model.Visit;
import fr.gouv.clea.consumer.repository.IStatLocationRepository;
import fr.gouv.clea.consumer.repository.IStatLocationJpaRepository;
import fr.gouv.clea.consumer.service.IStatService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Optional;
@Component
@Service
@Slf4j
@RequiredArgsConstructor
@Transactional
public class StatService implements IStatService {
private final IStatLocationRepository repository;
private final IStatLocationJpaRepository repository;
private final VenueConsumerConfiguration config;
@Autowired
public StatService(
IStatLocationRepository repository,
VenueConsumerConfiguration configuration) {
this.repository = repository;
this.config = configuration;
}
@Override
public void logStats(Visit visit) {
StatLocationKey statLocationKey = StatLocationKey.builder()
......@@ -39,16 +35,17 @@ public class StatService implements IStatService {
.venueCategory2(visit.getVenueCategory2())
.build();
Optional<StatLocation> optional = repository.findById(statLocationKey);
StatLocation statLocation;
if (optional.isEmpty()) {
statLocation = newStatLocation(statLocationKey, visit);
} else {
statLocation = updateStatLocation(optional.get(), visit);
var statLocation = newStatLocation(statLocationKey, visit);
Optional<StatLocation> optional=repository.findById(statLocationKey);
if(optional.isPresent()) {
repository.updateByIncrement(optional.get());
}else {
try {
repository.insert(statLocation);
} catch (DataIntegrityViolationException eex) {
repository.updateByIncrement(statLocation);
}
}
repository.save(statLocation);
log.info("saved stat period: {}, venueType: {} venueCategory1: {}, venueCategory2: {}, backwardVisits: {}, forwardVisits: {}",
statLocation.getStatLocationKey().getPeriod(),
statLocation.getStatLocationKey().getVenueType(),
......@@ -67,17 +64,8 @@ public class StatService implements IStatService {
.build();
}
protected StatLocation updateStatLocation(StatLocation statLocation, Visit visit) {
if (visit.isBackward()) {
statLocation.setBackwardVisits(statLocation.getBackwardVisits() + 1);
} else {
statLocation.setForwardVisits(statLocation.getForwardVisits() + 1);
}
return statLocation;
}
protected Instant getStatPeriod(Visit visit) {
long secondsToRemove = visit.getQrCodeScanTime().getEpochSecond() % config.getStatSlotDurationInSeconds();
return visit.getQrCodeScanTime().minus(secondsToRemove, ChronoUnit.SECONDS);
return visit.getQrCodeScanTime().minus(secondsToRemove, ChronoUnit.SECONDS).truncatedTo(ChronoUnit.SECONDS);
}
}
......@@ -91,10 +91,6 @@ public class VisitExpositionAggregatorService implements IVisitExpositionAggrega
* durationUnitInSeconds must be a value ensuring: 3600 % durationUnitInSeconds = 0
*/
protected int getPeriodMaxSlot(int periodDuration) {
// This check should go in venue consumer consumerConfig validation
if (Duration.ofHours(1).toSeconds() % periodDuration == 0) {
log.error("durationUnitInSeconds does not have a valid value: {}. 3600(secs) / durationUnitInSeconds has a reminder!", periodDuration);
}
if (periodDuration == 255) {
return Integer.MAX_VALUE;
}
......
......@@ -2,7 +2,7 @@ package fr.gouv.clea.consumer.service.impl;
import fr.gouv.clea.consumer.model.StatLocation;
import fr.gouv.clea.consumer.model.Visit;
import fr.gouv.clea.consumer.repository.IStatLocationRepository;
import fr.gouv.clea.consumer.repository.IStatLocationJpaRepository;
import fr.gouv.clea.consumer.service.IStatService;
import fr.inria.clea.lsp.utils.TimeUtils;
import org.apache.commons.lang3.RandomUtils;
......@@ -34,7 +34,7 @@ class StatServiceTest {
private static final long TODAY_AT_MIDNIGHT_AS_NTP = TimeUtils.ntpTimestampFromInstant(TODAY_AT_MIDNIGHT);
@Autowired
private IStatLocationRepository repository;
private IStatLocationJpaRepository repository;
@Autowired
private IStatService service;
......
......@@ -6,7 +6,7 @@
<parent>
<groupId>fr.gouv.clea</groupId>
<artifactId>clea-server</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>clea-ws-rest</artifactId>
......
......@@ -18,7 +18,7 @@
<groupId>fr.gouv.clea</groupId>
<artifactId>clea-server</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<name>clea-server</name>
<packaging>pom</packaging>
<description>Tous Anti-Covid Cluster Exposure Verification (Clea) server project</description>
......@@ -196,10 +196,6 @@
</profiles>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.inria.fr/api/v4/projects/25110/packages/maven</url>
</repository>
<repository>
<id>gitlab-maven-clea-crypto</id>
<url>https://gitlab.inria.fr/api/v4/projects/28288/packages/maven</url>
......@@ -208,19 +204,16 @@
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>${env.CI_SERVER_URL}/api/v4/projects/${env.CI_PROJECT_ID}/packages/maven</url>
<url>https://gitlab.inria.fr/api/v4/projects/29881/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>${env.CI_SERVER_URL}/api/v4/projects/${env.CI_PROJECT_ID}/packages/maven</url>
<url>https://gitlab.inria.fr/api/v4/projects/29881/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:git:${gitRepositoryUrl}</connection>
<developerConnection>scm:git:${gitRepositoryUrl}</developerConnection>
<url>${gitRepositoryUrl}</url>
<tag>clea-1.1.0</tag>
<url>https://gitlab.inria.fr/stopcovid19/clea-server</url>
</scm>
</project>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment