From 39c25bbc8a69330d3db5b4493f60c3ec53edf166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anett=20H=C3=BCbner?= Date: Fri, 6 Jan 2023 22:17:05 +0100 Subject: [PATCH 1/6] traffic analysis with postgres --- deployment/helm/hackathon/README.md | 25 ++-- deployment/localenv-docker-compose.yml | 118 +++++++----------- deployment/postgreslocal-docker-compose.yml | 44 +++++++ persistence/pom.xml | 15 +-- .../entity/TrafficRecordEntity.java | 69 +++++----- .../entity/TrafficRecorderEntity.java | 34 +++-- .../repository/TrafficRecorderRepository.java | 4 - .../serializer/ZonedDateTimeDeserializer.java | 16 +++ .../serializer/ZonedDateTimeSerializer.java | 19 +++ .../resources/db/migration/V1_0__init.sql | 54 ++++---- .../src/test/resources/application.properties | 2 + .../src/test/resources/db/test/V1_0__init.sql | 54 ++++---- .../src/test/resources/application.properties | 2 +- 13 files changed, 268 insertions(+), 188 deletions(-) create mode 100644 deployment/postgreslocal-docker-compose.yml create mode 100644 persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeDeserializer.java create mode 100644 persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeSerializer.java diff --git a/deployment/helm/hackathon/README.md b/deployment/helm/hackathon/README.md index 4b21c91..e67d808 100644 --- a/deployment/helm/hackathon/README.md +++ b/deployment/helm/hackathon/README.md @@ -1,28 +1,21 @@ -# Helm chart for City.OS -This is the Helm chart to deploy City.OS app. +# Helm chart for TrafficAnalysis -## TL;DR; +This is the Helm chart to deploy traffic analysis app. -The following command deploys City.OS + MariaDB and authentication with Keycloak + PostrgeSQL. +The following command deploys the app + MariaDB as well as a preconfigured Grafana. Copy values.yaml and adapt to your target environment needs. This expects a running cert manager - you are able to run it without, but do not delete tls values. Please change hostname in your custom values - localhost does not work. (No also not on your dev machine :)). ```console $ helm install release-name . -f your-customvalues.yaml ``` -Please change hostname in your custom values - localhost does not work. (No also not your dev machine :)) For more details how to use Helm please refer to Helm [docs](https://helm.sh/docs/). +A running keycloak is expected. In fact it is supposed, that for every deployment you choose a proper context path, such that multiple versions of this software can be deployed to the same Kubernetes clsuter and the same domain. -## Intro -Copy values.yaml and adapt to your target environment needs. This chart expects a running cert manager, so make sure your Kubernetes (K3s,...) has a running instance. +This Helm chart also requires a pull secret to pull latest image from Github. Secret name is exptected as `github-pull-secret`. Create secret like below: -Also note that Keycloak is not deployed under its default context path. In fact it is supposed, that for every deployment you choose a proper context path, such that multiple versions of this software can be deployed to the same Kubernetes clsuter and the same domain. - -This Helm chart also requires a pull secret to pull latest image from Github. Secret name is exptected as `github-pull-secret`, see below for an example. - -## Examples - -### Pull Secret -If you don't know, how to create secrets in Kubernetes, please google how to do so. +``` +kubectl create secret docker-registry github-pull-secret --docker-server=ghcr.io --docker-username=<> --docker-password=<> --docker-email=<> --namespace=city +``` +That should the following secret: -Sample: ```YAML kind: Secret type: kubernetes.io/dockerconfigjson diff --git a/deployment/localenv-docker-compose.yml b/deployment/localenv-docker-compose.yml index c54f2ee..f14be40 100644 --- a/deployment/localenv-docker-compose.yml +++ b/deployment/localenv-docker-compose.yml @@ -1,96 +1,73 @@ version: "3.9" services: - - phpmyadmin: - image: phpmyadmin/phpmyadmin:latest - ports: - - 8082:80 - environment: - MYSQL_USER: root - MYSQL_PASSWORD: root - MYSQL_DATABASE: hackathon - networks: - - backend - - grafana: - image: grafana/grafana-oss:9.0.2 - ports: - - 3001:3001 - networks: - - backend - volumes: - - grafana-data:/var/lib/grafana - environment: - GF_RENDERING_SERVER_URL: http://renderer:8081/render - GF_RENDERING_CALLBACK_URL: http://grafana:3001/ - GF_LOG_FILTERS: rendering:debug - GF_SERVER_HTTP_PORT: 3001 - - renderer: - image: grafana/grafana-image-renderer:latest - networks: - - backend - ports: - - 3002:8081 - db: - image: mariadb:latest - restart: on-failure + postgres: + container_name: hackathon-db + image: postgres:latest environment: - MYSQL_DATABASE: 'hackathon' - # So you don't have to use root, but you can if you like - MYSQL_USER: 'hackathon' - # You can use whatever password you like - MYSQL_PASSWORD: 'hackathon' - # Root password for local debugging - MYSQL_ROOT_PASSWORD: 'root' - # Password for root access - MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' - ports: - # : < MySQL Port running inside container> - - '3306:3306' + POSTGRES_DB: hackathon + POSTGRES_USER: hackathon + POSTGRES_PASSWORD: hackathon + PGDATA: /var/lib/postgresql/data healthcheck: - test: ["CMD", "mysql" ,"-h", "localhost", "-P", "3306", "-u", "root", "-e", "select 1", "hackathon"] + test: ['CMD-SHELL', 'pg_isready -U hackathon'] # <<<--- interval: 5s timeout: 60s retries: 30 volumes: - - hackathonv2-db-data:/var/lib/mysql - networks: # Networks to join (Services on the same network can communicate with each other using their name) + - hackathon-db:/var/lib/postgresql/data + ports: + - "5433:5432" + networks: - backend + restart: unless-stopped + + pgadmin: + container_name: pgadmin_container + image: dpage/pgadmin4 + environment: + PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org + PGADMIN_DEFAULT_PASSWORD: admin + PGADMIN_CONFIG_SERVER_MODE: 'False' + volumes: + - hackathon-pgadmin:/var/lib/pgadmin + ports: + - "5050:80" + networks: + - backend + restart: unless-stopped - db-keycloak: - image: mariadb:latest + hackathon-db-keycloak: + image: postgres:latest restart: on-failure environment: - MYSQL_DATABASE: 'keycloak' - MYSQL_USER: 'keycloak' - MYSQL_PASSWORD: 'keycloak' - MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' - MYSQL_TCP_PORT: 3307 + POSTGRES_DB: 'keycloak' + POSTGRES_USER: 'keycloak' + POSTGRES_PASSWORD: 'keycloak' + PGDATA: /var/lib/postgresql/data healthcheck: - test: ["CMD", "mysql" ,"-h", "localhost", "-P", "3307", "-u", "root", "-e", "select 1", "keycloak"] + test: ['CMD-SHELL', 'pg_isready -U keycloak'] interval: 5s timeout: 60s retries: 30 volumes: - - keycloak-db-data:/var/lib/mysql + - hackathon-keycloak-db:/var/lib/postgresql/data networks: - backend - keycloak: + hackathon-keycloak: image: jboss/keycloak volumes: - ./keycloak/imports:/opt/jboss/keycloak/imports - ./keycloak/local-test-users.json:/opt/jboss/keycloak/standalone/configuration/keycloak-add-user.json depends_on: - db-keycloak: + hackathon-db-keycloak: condition: service_healthy restart: on-failure environment: KEYCLOAK_IMPORT: /opt/jboss/keycloak/imports/realm.json - DB_VENDOR: mariadb - DB_ADDR: db-keycloak - DB_PORT: 3307 + DB_VENDOR: postgres + DB_ADDR: hackathon-db-keycloak + DB_PORT: 5432 DB_USER: 'keycloak' DB_PASSWORD: 'keycloak' PROXY_ADDRESS_FORWARDING: 'true' @@ -101,12 +78,11 @@ services: networks: - backend -# Names our volume -volumes: - hackathonv2-db-data: - keycloak-db-data: - grafana-data: - - # Networks to be created to facilitate communication between containers networks: backend: + +volumes: + hackathon-db: + hackathon-pgadmin: + hackathon-keycloak-db: + diff --git a/deployment/postgreslocal-docker-compose.yml b/deployment/postgreslocal-docker-compose.yml new file mode 100644 index 0000000..f2db336 --- /dev/null +++ b/deployment/postgreslocal-docker-compose.yml @@ -0,0 +1,44 @@ +version: "3.9" +services: + postgres: + container_name: hackathon-db + image: postgres:latest + environment: + POSTGRES_DB: hackathon + POSTGRES_USER: hackathon + POSTGRES_PASSWORD: hackathon + PGDATA: /var/lib/postgresql/data + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U hackathon'] # <<<--- + interval: 5s + timeout: 60s + retries: 30 + volumes: + - hackathon-db:/var/lib/postgresql/data + ports: + - "5433:5432" + networks: + - backend + restart: unless-stopped + + pgadmin: + container_name: pgadmin_container + image: dpage/pgadmin4 + environment: + PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org + PGADMIN_DEFAULT_PASSWORD: admin + PGADMIN_CONFIG_SERVER_MODE: 'False' + volumes: + - hackathon-pgadmin:/var/lib/pgadmin + ports: + - "5050:80" + networks: + - backend + restart: unless-stopped + +networks: + backend: + +volumes: + hackathon-db: + hackathon-pgadmin: \ No newline at end of file diff --git a/persistence/pom.xml b/persistence/pom.xml index bbc55fb..00a575c 100644 --- a/persistence/pom.xml +++ b/persistence/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 de.digiweek @@ -25,14 +27,10 @@ test - org.mariadb.jdbc - mariadb-java-client + org.postgresql + postgresql runtime - - org.flywaydb - flyway-mysql - org.flywaydb flyway-core @@ -55,5 +53,4 @@ springdoc-openapi-security - - + \ No newline at end of file diff --git a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java index ecb3e24..34ef997 100644 --- a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java +++ b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java @@ -1,61 +1,74 @@ package de.digiweek.persistence.entity; import com.fasterxml.jackson.annotation.JsonFilter; - import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.xml.bind.annotation.XmlRootElement; + +import java.time.ZonedDateTime; +import de.digiweek.persistence.serializer.ZonedDateTimeSerializer; +import de.digiweek.persistence.serializer.ZonedDateTimeDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import javax.persistence.CascadeType; /** * TrafficRecord Entity class */ +@XmlRootElement @Entity -@Table(name = "TRAFFICRECORD") +@Table(name = "trafficrecord") public class TrafficRecordEntity extends AbstractEntity { - // date // entity fields - @Column(name = "RECORDDATE") - private Date recordDate; + @Column(name="recorddate") + @JsonSerialize(using = ZonedDateTimeSerializer.class) + @JsonDeserialize(using = ZonedDateTimeDeserializer.class) + private ZonedDateTime recordDate; + - @Column(name = "WEEKDAY") + @Column(name = "weekday") private Integer weekday; - // bool - @Column(name = "WEEKEND") - private Boolean weekend; - // bool - @Column(name = "HOLIDAY") + @Column(name = "holiday") private Boolean holiday; - // bool - @Column(name = "VACATIONLOWERSAXONY") + + @Column(name = "vacationlowersaxony") private Boolean vacationLowerSaxony; - // bool - @Column(name = "PLANTHOLIDAY") + + @Column(name = "weekend") + private Boolean weekend; + + + @Column(name = "plantholiday") private Boolean plantHoliday; - @Column(name = "CARCOUNT") + + @Column(name = "carcount") private Integer carCount; + // entity relations @JsonFilter("filterId") @ManyToOne - @JoinColumn(name = "TRAFFICRECORDER_ID") + @JoinColumn(name = "trafficrecorder_id") private TrafficRecorderEntity trafficRecorder; // entity fields getters and setters - public Date getRecordDate() { + public ZonedDateTime getRecordDate() { return recordDate; } - public void setRecordDate(Date recordDate) { + public void setRecordDate(ZonedDateTime recordDate) { this.recordDate = recordDate; } @@ -67,14 +80,6 @@ public void setWeekday(Integer weekday) { this.weekday = weekday; } - public Boolean getWeekend() { - return weekend; - } - - public void setWeekend(Boolean weekend) { - this.weekend = weekend; - } - public Boolean getHoliday() { return holiday; } @@ -91,6 +96,14 @@ public void setVacationLowerSaxony(Boolean vacationLowerSaxony) { this.vacationLowerSaxony = vacationLowerSaxony; } + public Boolean getWeekend() { + return weekend; + } + + public void setWeekend(Boolean weekend) { + this.weekend = weekend; + } + public Boolean getPlantHoliday() { return plantHoliday; } diff --git a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java index 714c996..c16fb4f 100644 --- a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java +++ b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java @@ -9,39 +9,55 @@ import javax.persistence.Enumerated; import javax.persistence.OneToMany; import javax.persistence.Table; +import javax.xml.bind.annotation.XmlRootElement; + +import java.time.ZonedDateTime; +import de.digiweek.persistence.serializer.ZonedDateTimeSerializer; +import de.digiweek.persistence.serializer.ZonedDateTimeDeserializer; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import javax.persistence.CascadeType; /** * TrafficRecorder Entity class */ +@XmlRootElement @Entity -@Table(name = "TRAFFICRECORDER") +@Table(name = "trafficrecorder") public class TrafficRecorderEntity extends AbstractEntity { // entity fields - @Column(name = "EXTERNALID") + @Column(name = "externalid") private String externalId; + @Enumerated(EnumType.STRING) - @Column(name = "CITYDIRECTION") + @Column(name = "citydirection") private CityDirection cityDirection; - @Column(name = "NEIGHBOR") + + @Column(name = "neighbor") private String neighbor; - @Column(name = "SPECIALTY") + + @Column(name = "specialty") private String specialty; - @Column(name = "LOCATION") + + @Column(name = "location") private String location; - @Column(name = "LATITUDE") + + @Column(name = "latitude") private BigDecimal latitude; - @Column(name = "LONGITUDE") + + @Column(name = "longitude") private BigDecimal longitude; + // entity relations - @JsonFilter("filterIdDayCount") + @JsonFilter("filterId") @OneToMany(mappedBy = "trafficRecorder") private Set trafficRecord; diff --git a/persistence/src/main/java/de/digiweek/persistence/repository/TrafficRecorderRepository.java b/persistence/src/main/java/de/digiweek/persistence/repository/TrafficRecorderRepository.java index 6209490..2f1f374 100644 --- a/persistence/src/main/java/de/digiweek/persistence/repository/TrafficRecorderRepository.java +++ b/persistence/src/main/java/de/digiweek/persistence/repository/TrafficRecorderRepository.java @@ -1,10 +1,7 @@ package de.digiweek.persistence.repository; -import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; - import de.digiweek.persistence.entity.TrafficRecorderEntity; /** @@ -13,5 +10,4 @@ @Repository public interface TrafficRecorderRepository extends JpaRepository { - public TrafficRecorderEntity findOneByExternalId(String externalId); } diff --git a/persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeDeserializer.java b/persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeDeserializer.java new file mode 100644 index 0000000..3e75f5a --- /dev/null +++ b/persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeDeserializer.java @@ -0,0 +1,16 @@ +package de.digiweek.persistence.serializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; +import java.time.ZonedDateTime; + +public class ZonedDateTimeDeserializer extends JsonDeserializer { + + @Override + public ZonedDateTime deserialize(JsonParser arg0, DeserializationContext arg1) throws IOException { + return ZonedDateTime.parse(arg0.getText()); + } +} diff --git a/persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeSerializer.java b/persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeSerializer.java new file mode 100644 index 0000000..89f1191 --- /dev/null +++ b/persistence/src/main/java/de/digiweek/persistence/serializer/ZonedDateTimeSerializer.java @@ -0,0 +1,19 @@ +package de.digiweek.persistence.serializer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import java.io.IOException; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class ZonedDateTimeSerializer extends JsonSerializer { + + @Override + public void serialize(ZonedDateTime date, JsonGenerator jgen, SerializerProvider provider) throws IOException { + jgen.writeString(date != null ? ZonedDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC")) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")) : null); + } +} diff --git a/persistence/src/main/resources/db/migration/V1_0__init.sql b/persistence/src/main/resources/db/migration/V1_0__init.sql index 2eb6c02..887779f 100644 --- a/persistence/src/main/resources/db/migration/V1_0__init.sql +++ b/persistence/src/main/resources/db/migration/V1_0__init.sql @@ -1,32 +1,36 @@ -CREATE TABLE `TRAFFICRECORDER` +CREATE SEQUENCE IF NOT EXISTS "trafficrecorder_id_seq"; + +CREATE TABLE "trafficrecorder" ( - `EXTERNALID` varchar(255), - `CITYDIRECTION` varchar(255), - `NEIGHBOR` varchar(255), - `SPECIALTY` varchar(255), - `LOCATION` varchar(255), - `LATITUDE` decimal(22,19), - `LONGITUDE` decimal(22,19), - `ID` bigint NOT NULL AUTO_INCREMENT, - PRIMARY KEY (`ID`) + "externalid" VARCHAR(255), + "citydirection" VARCHAR(255), + "neighbor" VARCHAR(255), + "specialty" VARCHAR(255), + "location" VARCHAR(255), + "latitude" DECIMAL(19,2), + "longitude" DECIMAL(19,2), + "id" BIGINT NOT NULL DEFAULT nextval('trafficrecorder_id_seq'), + CONSTRAINT "trafficrecorder_pkey" PRIMARY KEY ("id") ); -CREATE TABLE `TRAFFICRECORD` +CREATE SEQUENCE IF NOT EXISTS "trafficrecord_id_seq"; + +CREATE TABLE "trafficrecord" ( - `RECORDDATE` datetime, - `WEEKDAY` integer, - `WEEKEND` tinyint(1), - `HOLIDAY` tinyint(1), - `VACATIONLOWERSAXONY` tinyint(1), - `PLANTHOLIDAY` tinyint(1), - `CARCOUNT` integer, - `TRAFFICRECORDER_ID` bigint, - `ID` bigint NOT NULL AUTO_INCREMENT, - PRIMARY KEY (`ID`) + "recorddate" DATE, + "weekday" INTEGER, + "holiday" BOOLEAN, + "vacationlowersaxony" BOOLEAN, + "weekend" BOOLEAN, + "plantholiday" BOOLEAN, + "carcount" INTEGER, + "trafficrecorder_id" BIGINT, + "id" BIGINT NOT NULL DEFAULT nextval('trafficrecord_id_seq'), + CONSTRAINT "trafficrecord_pkey" PRIMARY KEY ("id") ); -ALTER TABLE `TRAFFICRECORD` - ADD CONSTRAINT `FK_TRAFFICRECORD_TRAFFICRECORDER` - FOREIGN KEY (`TRAFFICRECORDER_ID`) - REFERENCES `TRAFFICRECORDER` (`ID`); +ALTER TABLE "trafficrecord" + ADD CONSTRAINT "fk_trafficrecord_trafficrecorder" + FOREIGN KEY ("trafficrecorder_id") + REFERENCES "trafficrecorder" ("id"); diff --git a/persistence/src/test/resources/application.properties b/persistence/src/test/resources/application.properties index f25963d..72bec09 100644 --- a/persistence/src/test/resources/application.properties +++ b/persistence/src/test/resources/application.properties @@ -2,3 +2,5 @@ spring.flyway.baselineOnMigrate=true spring.flyway.locations=classpath:db/test spring.flyway.encoding=UTF-8 spring.flyway.placeholder-replacement=false +spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL +spring.flyway.url=${spring.datasource.url} \ No newline at end of file diff --git a/persistence/src/test/resources/db/test/V1_0__init.sql b/persistence/src/test/resources/db/test/V1_0__init.sql index 97a9167..887779f 100644 --- a/persistence/src/test/resources/db/test/V1_0__init.sql +++ b/persistence/src/test/resources/db/test/V1_0__init.sql @@ -1,32 +1,36 @@ -CREATE TABLE `TRAFFICRECORDER` +CREATE SEQUENCE IF NOT EXISTS "trafficrecorder_id_seq"; + +CREATE TABLE "trafficrecorder" ( - `EXTERNALID` varchar(255), - `CITYDIRECTION` varchar(255), - `NEIGHBOR` varchar(255), - `SPECIALTY` varchar(255), - `LOCATION` varchar(255), - `LATITUDE` decimal(19,2), - `LONGITUDE` decimal(19,2), - `ID` bigint NOT NULL AUTO_INCREMENT, - PRIMARY KEY (`ID`) + "externalid" VARCHAR(255), + "citydirection" VARCHAR(255), + "neighbor" VARCHAR(255), + "specialty" VARCHAR(255), + "location" VARCHAR(255), + "latitude" DECIMAL(19,2), + "longitude" DECIMAL(19,2), + "id" BIGINT NOT NULL DEFAULT nextval('trafficrecorder_id_seq'), + CONSTRAINT "trafficrecorder_pkey" PRIMARY KEY ("id") ); -CREATE TABLE `TRAFFICRECORD` +CREATE SEQUENCE IF NOT EXISTS "trafficrecord_id_seq"; + +CREATE TABLE "trafficrecord" ( - `RECORDDATE` varchar(255), - `WEEKDAY` integer, - `WEEKEND` varchar(255), - `HOLIDAY` varchar(255), - `VACATIONLOWERSAXONY` varchar(255), - `PLANTHOLIDAY` varchar(255), - `CARCOUNT` integer, - `TRAFFICRECORDER_ID` bigint, - `ID` bigint NOT NULL AUTO_INCREMENT, - PRIMARY KEY (`ID`) + "recorddate" DATE, + "weekday" INTEGER, + "holiday" BOOLEAN, + "vacationlowersaxony" BOOLEAN, + "weekend" BOOLEAN, + "plantholiday" BOOLEAN, + "carcount" INTEGER, + "trafficrecorder_id" BIGINT, + "id" BIGINT NOT NULL DEFAULT nextval('trafficrecord_id_seq'), + CONSTRAINT "trafficrecord_pkey" PRIMARY KEY ("id") ); -ALTER TABLE `TRAFFICRECORD` - ADD CONSTRAINT `FK_TRAFFICRECORD_TRAFFICRECORDER` - FOREIGN KEY (`TRAFFICRECORDER_ID`) - REFERENCES `TRAFFICRECORDER` (`ID`); +ALTER TABLE "trafficrecord" + ADD CONSTRAINT "fk_trafficrecord_trafficrecorder" + FOREIGN KEY ("trafficrecorder_id") + REFERENCES "trafficrecorder" ("id"); diff --git a/rest/src/test/resources/application.properties b/rest/src/test/resources/application.properties index 7fb1437..64cfd84 100644 --- a/rest/src/test/resources/application.properties +++ b/rest/src/test/resources/application.properties @@ -10,7 +10,7 @@ management.endpoints.web.exposure.include=* management.info.git.mode=full # h2 -spring.datasource.url=jdbc:h2:mem:hackathon;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL +spring.datasource.url=jdbc:h2:mem:hackathon;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL spring.datasource.driverClassName=org.h2.Driver spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.show-sql=true From e362be6808562e2ff6909be7cbabb161778f375f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anett=20H=C3=BCbner?= Date: Fri, 6 Jan 2023 22:23:51 +0100 Subject: [PATCH 2/6] deleted not needed imports --- .../entity/TrafficRecordEntity.java | 28 ++++--------------- .../entity/TrafficRecorderEntity.java | 14 ---------- ...rafficRecordControllerIntegrationTest.java | 23 +++++---------- ...fficRecorderControllerIntegrationTest.java | 24 ++++++---------- 4 files changed, 21 insertions(+), 68 deletions(-) diff --git a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java index 34ef997..29b05ba 100644 --- a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java +++ b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecordEntity.java @@ -1,22 +1,15 @@ package de.digiweek.persistence.entity; -import com.fasterxml.jackson.annotation.JsonFilter; import java.util.Date; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; import javax.xml.bind.annotation.XmlRootElement; -import java.time.ZonedDateTime; -import de.digiweek.persistence.serializer.ZonedDateTimeSerializer; -import de.digiweek.persistence.serializer.ZonedDateTimeDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import javax.persistence.CascadeType; +import com.fasterxml.jackson.annotation.JsonFilter; /** * TrafficRecord Entity class @@ -27,36 +20,27 @@ public class TrafficRecordEntity extends AbstractEntity { // entity fields - @Column(name="recorddate") - @JsonSerialize(using = ZonedDateTimeSerializer.class) - @JsonDeserialize(using = ZonedDateTimeDeserializer.class) - private ZonedDateTime recordDate; - + @Column(name = "recorddate") + private Date recordDate; @Column(name = "weekday") private Integer weekday; - @Column(name = "holiday") private Boolean holiday; - @Column(name = "vacationlowersaxony") private Boolean vacationLowerSaxony; - @Column(name = "weekend") private Boolean weekend; - @Column(name = "plantholiday") private Boolean plantHoliday; - @Column(name = "carcount") private Integer carCount; - // entity relations @JsonFilter("filterId") @ManyToOne @@ -64,11 +48,11 @@ public class TrafficRecordEntity extends AbstractEntity { private TrafficRecorderEntity trafficRecorder; // entity fields getters and setters - public ZonedDateTime getRecordDate() { + public Date getRecordDate() { return recordDate; } - public void setRecordDate(ZonedDateTime recordDate) { + public void setRecordDate(Date recordDate) { this.recordDate = recordDate; } diff --git a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java index c16fb4f..ac929ec 100644 --- a/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java +++ b/persistence/src/main/java/de/digiweek/persistence/entity/TrafficRecorderEntity.java @@ -11,13 +11,6 @@ import javax.persistence.Table; import javax.xml.bind.annotation.XmlRootElement; -import java.time.ZonedDateTime; -import de.digiweek.persistence.serializer.ZonedDateTimeSerializer; -import de.digiweek.persistence.serializer.ZonedDateTimeDeserializer; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import javax.persistence.CascadeType; - /** * TrafficRecorder Entity class */ @@ -30,32 +23,25 @@ public class TrafficRecorderEntity extends AbstractEntity { @Column(name = "externalid") private String externalId; - @Enumerated(EnumType.STRING) @Column(name = "citydirection") private CityDirection cityDirection; - @Column(name = "neighbor") private String neighbor; - @Column(name = "specialty") private String specialty; - @Column(name = "location") private String location; - @Column(name = "latitude") private BigDecimal latitude; - @Column(name = "longitude") private BigDecimal longitude; - // entity relations @JsonFilter("filterId") @OneToMany(mappedBy = "trafficRecorder") diff --git a/rest/src/test/java/de/digiweek/rest/integration/TrafficRecordControllerIntegrationTest.java b/rest/src/test/java/de/digiweek/rest/integration/TrafficRecordControllerIntegrationTest.java index 22651bc..30bfe5d 100644 --- a/rest/src/test/java/de/digiweek/rest/integration/TrafficRecordControllerIntegrationTest.java +++ b/rest/src/test/java/de/digiweek/rest/integration/TrafficRecordControllerIntegrationTest.java @@ -1,18 +1,9 @@ package de.digiweek.rest.integration; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.json.JacksonTester; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; import de.digiweek.persistence.entity.TrafficRecordEntity; import de.digiweek.rest.controller.TrafficRecordController; @@ -46,19 +37,19 @@ public String getRestPath() { return restpath; } - //implement tests here + // implement tests here @Test public void canRetrieveById() throws Exception { -// TrafficRecordEntity entityToTest = readFromFile(data + "trafficrecord.json"); -// when(appService.findById(0L)).thenReturn(entityToTest); + // TrafficRecordEntity entityToTest = readFromFile(data + "trafficrecord.json"); + // when(appService.findById(0L)).thenReturn(entityToTest); -// MockHttpServletResponse response = retrieveById(0L); + // MockHttpServletResponse response = retrieveById(0L); // then -// assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); -// assertThat(response.getContentAsString()) -// .isEqualTo(jsonAppDto.write(dto).getJson()); + // assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); + // assertThat(response.getContentAsString()) + // .isEqualTo(jsonAppDto.write(dto).getJson()); } } diff --git a/rest/src/test/java/de/digiweek/rest/integration/TrafficRecorderControllerIntegrationTest.java b/rest/src/test/java/de/digiweek/rest/integration/TrafficRecorderControllerIntegrationTest.java index ee66372..1922b55 100644 --- a/rest/src/test/java/de/digiweek/rest/integration/TrafficRecorderControllerIntegrationTest.java +++ b/rest/src/test/java/de/digiweek/rest/integration/TrafficRecorderControllerIntegrationTest.java @@ -1,18 +1,9 @@ package de.digiweek.rest.integration; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.json.JacksonTester; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockHttpServletResponse; import de.digiweek.persistence.entity.TrafficRecorderEntity; import de.digiweek.rest.controller.TrafficRecorderController; @@ -46,19 +37,20 @@ public String getRestPath() { return restpath; } - //implement tests here + // implement tests here @Test public void canRetrieveById() throws Exception { -// TrafficRecorderEntity entityToTest = readFromFile(data + "trafficrecorder.json"); -// when(appService.findById(0L)).thenReturn(entityToTest); + // TrafficRecorderEntity entityToTest = readFromFile(data + + // "trafficrecorder.json"); + // when(appService.findById(0L)).thenReturn(entityToTest); -// MockHttpServletResponse response = retrieveById(0L); + // MockHttpServletResponse response = retrieveById(0L); // then -// assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); -// assertThat(response.getContentAsString()) -// .isEqualTo(jsonAppDto.write(dto).getJson()); + // assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); + // assertThat(response.getContentAsString()) + // .isEqualTo(jsonAppDto.write(dto).getJson()); } } From 4dc6889c9458c83761471635cc646123525d9fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anett=20H=C3=BCbner?= Date: Sun, 8 Jan 2023 18:54:28 +0100 Subject: [PATCH 3/6] corrected testcases --- .../src/main/resources/application.properties | 11 ++-- deployment/helm/hackathon/Chart.yaml | 4 +- .../helm/hackathon/templates/deployment.yaml | 8 +-- deployment/helm/hackathon/templates/pv.yaml | 2 +- deployment/helm/hackathon/values.yaml | 12 ++-- .../DatabasePhysicalNamingStrategy.java | 10 ++-- .../src/main/resources/application.properties | 1 + .../resources/db/migration/V1_0__init.sql | 30 +++++----- .../db/migration/V1_1__unique_external_id.sql | 2 +- .../src/test/resources/application.properties | 6 +- .../resources/db/dummydata/dummy_data_v2.sql | 59 +++++++++++-------- .../src/test/resources/application.properties | 2 +- .../impl/TrafficRecordServiceTest.java | 2 - .../impl/TrafficRecorderServiceTest.java | 7 +-- .../src/test/resources/application.properties | 3 + 15 files changed, 86 insertions(+), 73 deletions(-) create mode 100644 service/src/test/resources/application.properties diff --git a/application/src/main/resources/application.properties b/application/src/main/resources/application.properties index d453de7..76ace94 100644 --- a/application/src/main/resources/application.properties +++ b/application/src/main/resources/application.properties @@ -15,14 +15,15 @@ management.endpoints.web.exposure.include=* # show full git properties management.info.git.mode=full -# MySQL +# Postgres spring.datasource.hikari.connection-timeout=10000 -spring.datasource.driver-class-name=org.mariadb.jdbc.Driver -spring.datasource.url=jdbc:mariadb://localhost:3306/hackathon?useLegacyDatetimeCode=false&serverTimezone=CET -spring.jpa.hibernate.naming.physical-strategy=de.digiweek.persistence.config.DatabasePhysicalNamingStrategy +#spring.datasource.driver-class-name=org.postgresql.Driver +spring.datasource.url=jdbc:postgresql://localhost:5433/hackathon?useLegacyDatetimeCode=false&serverTimezone=CET #spring.jpa.hibernate.ddl-auto=create spring.datasource.username=hackathon spring.datasource.password=hackathon +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +#spring.jpa.hibernate.ddl-auto=create # Flyway spring.flyway.user=${spring.datasource.username} @@ -48,4 +49,4 @@ keycloak.public-client=true keycloak.enabled=true spring.servlet.multipart.max-file-size=128MB -spring.servlet.multipart.max-request-size=128MB \ No newline at end of file +spring.servlet.multipart.max-request-size=128MB diff --git a/deployment/helm/hackathon/Chart.yaml b/deployment/helm/hackathon/Chart.yaml index bb16cad..e2ef013 100644 --- a/deployment/helm/hackathon/Chart.yaml +++ b/deployment/helm/hackathon/Chart.yaml @@ -23,8 +23,8 @@ version: 2.2.1 appVersion: v2.2.1 dependencies: - - name: mariadb - version: 11.0.13 + - name: postgresql + version: 15.1.0 repository: https://charts.bitnami.com/bitnami - name: grafana version: 6.32.11 diff --git a/deployment/helm/hackathon/templates/deployment.yaml b/deployment/helm/hackathon/templates/deployment.yaml index dd20752..eab2923 100644 --- a/deployment/helm/hackathon/templates/deployment.yaml +++ b/deployment/helm/hackathon/templates/deployment.yaml @@ -28,8 +28,8 @@ spec: securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} initContainers: - - name: wait4mariadb - image: "{{ .Values.initContainers.wait4mariadb.image }}:{{ .Values.initContainers.wait4mariadb.tag }}" + - name: wait4postgres + image: "{{ .Values.initContainers.wait4postgres.image }}:{{ .Values.initContainers.wait4postgres.tag }}" resources: {{- toYaml .Values.initContainers.resources | nindent 12 }} securityContext: @@ -37,7 +37,7 @@ spec: command: - 'sh' - '-c' - - 'until nslookup {{ .Release.Name }}-mariadb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done' + - 'until nslookup {{ .Release.Name }}-postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done' - name: checkkeycloak image: "{{ .Values.initContainers.curl.image }}:{{ .Values.initContainers.curl.tag }}" command: ['sh', '-c', 'while [ `curl -Lk --write-out "%{http_code}\n" --silent --output /dev/null "{{ .Values.global.keycloak.authServerUrl }}"` -ne 200 ]; do sleep 2; done'] @@ -50,7 +50,7 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: SPRING_DATASOURCE_URL - value: jdbc:mariadb://{{ .Release.Name }}-mariadb:{{ .Values.mariadb.primary.service.ports.mysql }}/{{ .Values.mariadb.auth.database }}?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false + value: jdbc:postgresql://{{ .Release.Name }}-postgres:{{ .Values.mariadb.primary.service.ports.postgresql }}/{{ .Values.postgresql.auth.database }}?useLegacyDatetimeCode=false&serverTimezone=CET - name: SPRING_DATASOURCE_USERNAME value: {{ .Values.mariadb.auth.username }} - name: SPRING_DATASOURCE_PASSWORD diff --git a/deployment/helm/hackathon/templates/pv.yaml b/deployment/helm/hackathon/templates/pv.yaml index 452c342..8d44d00 100644 --- a/deployment/helm/hackathon/templates/pv.yaml +++ b/deployment/helm/hackathon/templates/pv.yaml @@ -11,5 +11,5 @@ spec: accessModes: - ReadWriteOnce hostPath: - path: "/opt/local-pv/{{ $fullName }}-mariadb" + path: "/opt/local-pv/{{ $fullName }}-postgres" {{- end }} diff --git a/deployment/helm/hackathon/values.yaml b/deployment/helm/hackathon/values.yaml index eee3de1..7b3afa1 100644 --- a/deployment/helm/hackathon/values.yaml +++ b/deployment/helm/hackathon/values.yaml @@ -26,7 +26,7 @@ autoscaling: enabled: false initContainers: - wait4mariadb: + wait4postgres: image: busybox tag: latest curl: @@ -67,16 +67,16 @@ ingress: run-batch stop-embedded-server -mariadb: +postgresql: auth: - rootPassword: root + postgresPassword: root database: hackathon username: hackathon password: hackathon primary: service: ports: - mysql: 3308 + postgresql: 5432 grafana: ingress: @@ -91,9 +91,9 @@ grafana: apiVersion: 1 datasources: - name: hackathon-db - type: mysql + type: postgresql uid: "DUcTla6nk" - url: "{{ tpl .Release.Name . }}-mariadb:3308" + url: "{{ tpl .Release.Name . }}-postgres:5432" user: hackathon database: hackathon secureJsonData: diff --git a/persistence/src/main/java/de/digiweek/persistence/config/DatabasePhysicalNamingStrategy.java b/persistence/src/main/java/de/digiweek/persistence/config/DatabasePhysicalNamingStrategy.java index 9cbb923..111973f 100644 --- a/persistence/src/main/java/de/digiweek/persistence/config/DatabasePhysicalNamingStrategy.java +++ b/persistence/src/main/java/de/digiweek/persistence/config/DatabasePhysicalNamingStrategy.java @@ -13,7 +13,7 @@ public Identifier toPhysicalCatalogName(final Identifier identifier, final JdbcE @Override public Identifier toPhysicalColumnName(final Identifier identifier, final JdbcEnvironment jdbcEnv) { - return toUpperSnakeCase(identifier); + return toLowerSnakeCase(identifier); } @Override @@ -23,20 +23,20 @@ public Identifier toPhysicalSchemaName(final Identifier identifier, final JdbcEn @Override public Identifier toPhysicalSequenceName(final Identifier identifier, final JdbcEnvironment jdbcEnv) { - return toUpperSnakeCase(identifier); + return toLowerSnakeCase(identifier); } @Override public Identifier toPhysicalTableName(final Identifier identifier, final JdbcEnvironment jdbcEnv) { - return toUpperSnakeCase(identifier); + return toLowerSnakeCase(identifier); } - private Identifier toUpperSnakeCase(final Identifier identifier) { + private Identifier toLowerSnakeCase(final Identifier identifier) { final String regex = "([a-z])([A-Z])"; final String replacement = "$1_$2"; final String upperSnakeIdentifier = identifier.getText() .replaceAll(regex, replacement) - .toUpperCase(); + .toLowerCase(); return Identifier.toIdentifier(upperSnakeIdentifier); } } diff --git a/persistence/src/main/resources/application.properties b/persistence/src/main/resources/application.properties index 74f5089..41c0022 100644 --- a/persistence/src/main/resources/application.properties +++ b/persistence/src/main/resources/application.properties @@ -2,3 +2,4 @@ spring.flyway.baselineOnMigrate=true spring.flyway.locations=classpath:db/migration spring.flyway.encoding=UTF-8 spring.flyway.placeholder-replacement=false + diff --git a/persistence/src/main/resources/db/migration/V1_0__init.sql b/persistence/src/main/resources/db/migration/V1_0__init.sql index 887779f..649ad94 100644 --- a/persistence/src/main/resources/db/migration/V1_0__init.sql +++ b/persistence/src/main/resources/db/migration/V1_0__init.sql @@ -2,13 +2,13 @@ CREATE SEQUENCE IF NOT EXISTS "trafficrecorder_id_seq"; CREATE TABLE "trafficrecorder" ( - "externalid" VARCHAR(255), - "citydirection" VARCHAR(255), - "neighbor" VARCHAR(255), - "specialty" VARCHAR(255), - "location" VARCHAR(255), - "latitude" DECIMAL(19,2), - "longitude" DECIMAL(19,2), + "externalid" VARCHAR(255) DEFAULT NULL, + "citydirection" VARCHAR(255) DEFAULT NULL, + "neighbor" VARCHAR(255) DEFAULT NULL, + "specialty" VARCHAR(255) DEFAULT NULL, + "location" VARCHAR(255) DEFAULT NULL, + "latitude" DECIMAL(22,19) DEFAULT NULL, + "longitude" DECIMAL(22,19) DEFAULT NULL, "id" BIGINT NOT NULL DEFAULT nextval('trafficrecorder_id_seq'), CONSTRAINT "trafficrecorder_pkey" PRIMARY KEY ("id") ); @@ -17,14 +17,14 @@ CREATE SEQUENCE IF NOT EXISTS "trafficrecord_id_seq"; CREATE TABLE "trafficrecord" ( - "recorddate" DATE, - "weekday" INTEGER, - "holiday" BOOLEAN, - "vacationlowersaxony" BOOLEAN, - "weekend" BOOLEAN, - "plantholiday" BOOLEAN, - "carcount" INTEGER, - "trafficrecorder_id" BIGINT, + "recorddate" DATE DEFAULT NULL, + "weekday" INTEGER DEFAULT NULL, + "holiday" BOOLEAN DEFAULT NULL, + "vacationlowersaxony" BOOLEAN DEFAULT NULL, + "weekend" BOOLEAN DEFAULT NULL, + "plantholiday" BOOLEAN DEFAULT NULL, + "carcount" INTEGER DEFAULT NULL, + "trafficrecorder_id" BIGINT DEFAULT NULL, "id" BIGINT NOT NULL DEFAULT nextval('trafficrecord_id_seq'), CONSTRAINT "trafficrecord_pkey" PRIMARY KEY ("id") ); diff --git a/persistence/src/main/resources/db/migration/V1_1__unique_external_id.sql b/persistence/src/main/resources/db/migration/V1_1__unique_external_id.sql index d2edce5..0bfe7ab 100644 --- a/persistence/src/main/resources/db/migration/V1_1__unique_external_id.sql +++ b/persistence/src/main/resources/db/migration/V1_1__unique_external_id.sql @@ -1 +1 @@ -ALTER TABLE TRAFFICRECORDER ADD UNIQUE (EXTERNALID); \ No newline at end of file +ALTER TABLE "trafficrecorder" ADD UNIQUE ("externalid"); \ No newline at end of file diff --git a/persistence/src/test/resources/application.properties b/persistence/src/test/resources/application.properties index 72bec09..6202dc7 100644 --- a/persistence/src/test/resources/application.properties +++ b/persistence/src/test/resources/application.properties @@ -2,5 +2,7 @@ spring.flyway.baselineOnMigrate=true spring.flyway.locations=classpath:db/test spring.flyway.encoding=UTF-8 spring.flyway.placeholder-replacement=false -spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL -spring.flyway.url=${spring.datasource.url} \ No newline at end of file +spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;MODE=PostgreSQL +spring.jpa.hibernate.naming.physical-strategy=de.digiweek.persistence.config.DatabasePhysicalNamingStrategy +spring.flyway.url=${spring.datasource.url} +spring.jpa.show-sql=true \ No newline at end of file diff --git a/persistence/src/test/resources/db/dummydata/dummy_data_v2.sql b/persistence/src/test/resources/db/dummydata/dummy_data_v2.sql index b11df17..73e88ee 100644 --- a/persistence/src/test/resources/db/dummydata/dummy_data_v2.sql +++ b/persistence/src/test/resources/db/dummydata/dummy_data_v2.sql @@ -27,6 +27,8 @@ SET time_zone = "+00:00"; -- Table structure for table `flyway_schema_history` -- +CREATE SEQUENCE IF NOT EXISTS "trafficrecord_id_seq"; + CREATE TABLE `flyway_schema_history` ( `installed_rank` int(11) NOT NULL, `version` varchar(50) DEFAULT NULL, @@ -38,7 +40,7 @@ CREATE TABLE `flyway_schema_history` ( `installed_on` timestamp NOT NULL DEFAULT current_timestamp(), `execution_time` int(11) NOT NULL, `success` tinyint(1) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +); -- -- Dumping data for table `flyway_schema_history` @@ -54,23 +56,27 @@ INSERT INTO `flyway_schema_history` (`installed_rank`, `version`, `description`, -- Table structure for table `TRAFFICRECORD` -- -CREATE TABLE `TRAFFICRECORD` ( - `RECORDDATE` datetime DEFAULT NULL, - `WEEKDAY` int(11) DEFAULT NULL, - `WEEKEND` tinyint(1) DEFAULT NULL, - `HOLIDAY` tinyint(1) DEFAULT NULL, - `VACATIONLOWERSAXONY` tinyint(1) DEFAULT NULL, - `PLANTHOLIDAY` tinyint(1) DEFAULT NULL, - `CARCOUNT` int(11) DEFAULT NULL, - `TRAFFICRECORDER_ID` bigint(20) DEFAULT NULL, - `ID` bigint(20) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE SEQUENCE IF NOT EXISTS "trafficrecord_id_seq"; + +CREATE TABLE "trafficrecord" +( + "recorddate" DATE DEFAULT NULL, + "weekday" INTEGER DEFAULT NULL, + "holiday" BOOLEAN DEFAULT NULL, + "vacationlowersaxony" BOOLEAN DEFAULT NULL, + "weekend" BOOLEAN DEFAULT NULL, + "plantholiday" BOOLEAN DEFAULT NULL, + "carcount" INTEGER DEFAULT NULL, + "trafficrecorder_id" BIGINT DEFAULT NULL, + "id" BIGINT NOT NULL DEFAULT nextval('trafficrecord_id_seq'), + CONSTRAINT "trafficrecord_pkey" PRIMARY KEY ("id") +); -- -- Dumping data for table `TRAFFICRECORD` -- -INSERT INTO `TRAFFICRECORD` (`RECORDDATE`, `WEEKDAY`, `WEEKEND`, `HOLIDAY`, `VACATIONLOWERSAXONY`, `PLANTHOLIDAY`, `CARCOUNT`, `TRAFFICRECORDER_ID`, `ID`) VALUES +INSERT INTO `trafficrecord` (`recorddate`, `weekday`, `weekend`, `holiday`, `vacationlowersaxony`, `plantholiday`, `carcount`, `trafficrecorder_id`, `id`) VALUES ('2020-05-01 00:00:00', 2, 1, 1, 1, 1, 38, 1, 4), ('2020-05-02 00:00:00', 2, 1, 1, 1, 1, 60, 1, 5), ('2020-05-03 00:00:00', 2, 1, 1, 1, 1, 99, 1, 6), @@ -230,25 +236,28 @@ INSERT INTO `TRAFFICRECORD` (`RECORDDATE`, `WEEKDAY`, `WEEKEND`, `HOLIDAY`, `VAC -- -------------------------------------------------------- -- --- Table structure for table `TRAFFICRECORDER` +-- Table structure for table `trafficrecorder` -- -CREATE TABLE `TRAFFICRECORDER` ( - `EXTERNALID` varchar(255) DEFAULT NULL, - `CITYDIRECTION` varchar(255) DEFAULT NULL, - `NEIGHBOR` varchar(255) DEFAULT NULL, - `SPECIALTY` varchar(255) DEFAULT NULL, - `LOCATION` varchar(255) DEFAULT NULL, - `LATITUDE` decimal(22,19) DEFAULT NULL, - `LONGITUDE` decimal(22,19) DEFAULT NULL, - `ID` bigint(20) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE SEQUENCE IF NOT EXISTS "trafficrecorder_id_seq"; + +CREATE TABLE `trafficrecorder` ( + `externalid` varchar(255) DEFAULT NULL, + `citydirection` varchar(255) DEFAULT NULL, + `neighbor` varchar(255) DEFAULT NULL, + `specialty` varchar(255) DEFAULT NULL, + `location` varchar(255) DEFAULT NULL, + `latitude` decimal(22,19) DEFAULT NULL, + `longitude` decimal(22,19) DEFAULT NULL, + "id" BIGINT NOT NULL DEFAULT nextval('trafficrecorder_id_seq'), + CONSTRAINT "trafficrecorder_pkey" PRIMARY KEY ("id") +); -- -- Dumping data for table `TRAFFICRECORDER` -- -INSERT INTO `TRAFFICRECORDER` (`EXTERNALID`, `CITYDIRECTION`, `NEIGHBOR`, `SPECIALTY`, `LOCATION`, `LATITUDE`, `LONGITUDE`, `ID`) VALUES +INSERT INTO `trafficrecorder` (`externalid`, `citydirection`, `neighbor`, `specialty`, `location`, `latitude`, `longitude`, `id`) VALUES ('216_Z2C', 'in', 'neighbor', 'specialty', 'location', '23.32', '50.21', 1), ('302_Z1A', 'in', 'neighbor', 'specialty', 'location', '23.32', '50.21', 2), ('310_Z2C', 'in', 'neighbor', 'specialty', 'location', '23.32', '50.21', 3), diff --git a/rest/src/test/resources/application.properties b/rest/src/test/resources/application.properties index 64cfd84..eeae57b 100644 --- a/rest/src/test/resources/application.properties +++ b/rest/src/test/resources/application.properties @@ -10,7 +10,7 @@ management.endpoints.web.exposure.include=* management.info.git.mode=full # h2 -spring.datasource.url=jdbc:h2:mem:hackathon;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL +spring.datasource.url=jdbc:h2:mem:hackathon;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;MODE=PostgreSQL spring.datasource.driverClassName=org.h2.Driver spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.show-sql=true diff --git a/service/src/test/java/de/digiweek/service/impl/TrafficRecordServiceTest.java b/service/src/test/java/de/digiweek/service/impl/TrafficRecordServiceTest.java index f2425df..d03702d 100644 --- a/service/src/test/java/de/digiweek/service/impl/TrafficRecordServiceTest.java +++ b/service/src/test/java/de/digiweek/service/impl/TrafficRecordServiceTest.java @@ -21,8 +21,6 @@ @SpringBootTest() @Transactional -@TestPropertySource(properties = { - "spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL" }) public class TrafficRecordServiceTest { @Autowired diff --git a/service/src/test/java/de/digiweek/service/impl/TrafficRecorderServiceTest.java b/service/src/test/java/de/digiweek/service/impl/TrafficRecorderServiceTest.java index 1568b67..cf02454 100644 --- a/service/src/test/java/de/digiweek/service/impl/TrafficRecorderServiceTest.java +++ b/service/src/test/java/de/digiweek/service/impl/TrafficRecorderServiceTest.java @@ -20,8 +20,6 @@ @SpringBootTest() @Transactional -@TestPropertySource(properties = { - "spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL" }) class TrafficRecorderServiceTest { @Autowired @@ -37,8 +35,9 @@ public void testLoadTrafficRecordersJson() throws IOException { } private static String loadFile(String resourceName) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(TrafficRecorderServiceTest.class.getClassLoader().getResourceAsStream(resourceName))); - + BufferedReader reader = new BufferedReader(new InputStreamReader( + TrafficRecorderServiceTest.class.getClassLoader().getResourceAsStream(resourceName))); + StringBuilder stringBuilder = new StringBuilder(); int lastChar = -1; do { diff --git a/service/src/test/resources/application.properties b/service/src/test/resources/application.properties new file mode 100644 index 0000000..a53dc90 --- /dev/null +++ b/service/src/test/resources/application.properties @@ -0,0 +1,3 @@ +spring.jpa.show-sql=true +spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;MODE=PostgreSQL +spring.jpa.hibernate.naming.physical-strategy=de.digiweek.persistence.config.DatabasePhysicalNamingStrategy From 118db16f486a27d807261e861f52f20c114b534f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anett=20H=C3=BCbner?= Date: Tue, 17 Jan 2023 00:05:49 +0100 Subject: [PATCH 4/6] corrected helm chart --- deployment/helm/hackathon/Chart.yaml | 2 +- deployment/helm/hackathon/templates/deployment.yaml | 8 ++++---- deployment/helm/hackathon/templates/pv.yaml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deployment/helm/hackathon/Chart.yaml b/deployment/helm/hackathon/Chart.yaml index e2ef013..84f3329 100644 --- a/deployment/helm/hackathon/Chart.yaml +++ b/deployment/helm/hackathon/Chart.yaml @@ -24,7 +24,7 @@ appVersion: v2.2.1 dependencies: - name: postgresql - version: 15.1.0 + version: 12.1.9 repository: https://charts.bitnami.com/bitnami - name: grafana version: 6.32.11 diff --git a/deployment/helm/hackathon/templates/deployment.yaml b/deployment/helm/hackathon/templates/deployment.yaml index eab2923..7b3e0c3 100644 --- a/deployment/helm/hackathon/templates/deployment.yaml +++ b/deployment/helm/hackathon/templates/deployment.yaml @@ -37,7 +37,7 @@ spec: command: - 'sh' - '-c' - - 'until nslookup {{ .Release.Name }}-postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done' + - 'until nslookup {{ .Release.Name }}-postgresql.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done' - name: checkkeycloak image: "{{ .Values.initContainers.curl.image }}:{{ .Values.initContainers.curl.tag }}" command: ['sh', '-c', 'while [ `curl -Lk --write-out "%{http_code}\n" --silent --output /dev/null "{{ .Values.global.keycloak.authServerUrl }}"` -ne 200 ]; do sleep 2; done'] @@ -50,11 +50,11 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: SPRING_DATASOURCE_URL - value: jdbc:postgresql://{{ .Release.Name }}-postgres:{{ .Values.mariadb.primary.service.ports.postgresql }}/{{ .Values.postgresql.auth.database }}?useLegacyDatetimeCode=false&serverTimezone=CET + value: jdbc:postgresql://{{ .Release.Name }}-postgres:{{ .Values.postgresql.primary.service.ports.postgresql }}/{{ .Values.postgresql.auth.database }}?useLegacyDatetimeCode=false&serverTimezone=CET - name: SPRING_DATASOURCE_USERNAME - value: {{ .Values.mariadb.auth.username }} + value: {{ .Values.postgresql.auth.username }} - name: SPRING_DATASOURCE_PASSWORD - value: {{ .Values.mariadb.auth.password }} + value: {{ .Values.postgresql.auth.password }} - name: SERVER_SERVLET_CONTEXT_PATH value: /{{ include "app.fullname" . }} - name: KEYCLOAK_AUTH-SERVER-URL diff --git a/deployment/helm/hackathon/templates/pv.yaml b/deployment/helm/hackathon/templates/pv.yaml index 8d44d00..49a5a19 100644 --- a/deployment/helm/hackathon/templates/pv.yaml +++ b/deployment/helm/hackathon/templates/pv.yaml @@ -1,4 +1,4 @@ -{{- if .Values.mariadb.localstorage -}} +{{- if .Values.postgresql.localstorage -}} {{- $fullName := include "app.fullname" . -}} apiVersion: v1 kind: PersistentVolume From 0c121168dd5b5e0aafc31494c814d209bedf96c4 Mon Sep 17 00:00:00 2001 From: github-hackathon Date: Wed, 18 Jan 2023 17:19:54 +0000 Subject: [PATCH 5/6] chore(release): 2.2.2-1 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e75d87c..8fa2c79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.2.2-1](https://github.com/chtew/hackathon-digiweek-wob/compare/v2.2.2-0...v2.2.2-1) (2023-01-18) + ### [2.2.2-0](https://github.com/chtew/hackathon-digiweek-wob/compare/v2.2.1...v2.2.2-0) (2022-08-13) ### [2.2.1](https://github.com/chtew/hackathon-digiweek-wob/compare/v2.2.0...v2.2.1) (2022-08-06) From 24b331deb3f5f886d432c1f69dfeaddce853fbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anett=20H=C3=BCbner?= Date: Mon, 23 Jan 2023 17:49:36 +0100 Subject: [PATCH 6/6] corrected tag version --- deployment/helm/hackathon/templates/deployment.yaml | 2 +- deployment/helm/hackathon/values.yaml | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/deployment/helm/hackathon/templates/deployment.yaml b/deployment/helm/hackathon/templates/deployment.yaml index 7b3e0c3..529d977 100644 --- a/deployment/helm/hackathon/templates/deployment.yaml +++ b/deployment/helm/hackathon/templates/deployment.yaml @@ -50,7 +50,7 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: SPRING_DATASOURCE_URL - value: jdbc:postgresql://{{ .Release.Name }}-postgres:{{ .Values.postgresql.primary.service.ports.postgresql }}/{{ .Values.postgresql.auth.database }}?useLegacyDatetimeCode=false&serverTimezone=CET + value: jdbc:postgresql://{{ .Release.Name }}-postgresql:{{ .Values.postgresql.primary.service.ports.postgresql }}/{{ .Values.postgresql.auth.database }}?useLegacyDatetimeCode=false&serverTimezone=CET - name: SPRING_DATASOURCE_USERNAME value: {{ .Values.postgresql.auth.username }} - name: SPRING_DATASOURCE_PASSWORD diff --git a/deployment/helm/hackathon/values.yaml b/deployment/helm/hackathon/values.yaml index 7b3afa1..645a0f2 100644 --- a/deployment/helm/hackathon/values.yaml +++ b/deployment/helm/hackathon/values.yaml @@ -8,7 +8,7 @@ replicaCount: 1 image: repository: ghcr.io/chtew/hackathon-digiweek-wob - tag: "v2.2.1" + tag: "v2.2.2-1" pullPolicy: Always imagePullSecrets: @@ -127,15 +127,12 @@ grafana: GF_AUTH_GENERIC_OAUTH_ALLOW_SIGN_UP: 'true' GF_AUTH_GENERIC_OAUTH_NAME: 'OAuth' GF_AUTH_GENERIC_OAUTH_CLIENT_ID: 'citydashboard' - GF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH: 'Viewer' + GF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH: 'Admin' GF_AUTH_GENERIC_OAUTH_SCOPES: 'openid profile email' GF_AUTH_GENERIC_OAUTH_TOKEN_URL: 'http://anett-xmg-fusion-15-xfu15l19/cityos-auth/realms/citydashboard/protocol/openid-connect/token' GF_AUTH_GENERIC_OAUTH_AUTH_URL: 'http://anett-xmg-fusion-15-xfu15l19/cityos-auth/realms/citydashboard/protocol/openid-connect/auth' GF_AUTH_GENERIC_OAUTH_API_URL: 'http://anett-xmg-fusion-15-xfu15l19/cityos-auth/realms/citydashboard/protocol/openid-connect/userinfo' - GF_AUTH_BASIC_ENABLED: 'false' + GF_AUTH_BASIC_ENABLED: 'true' GF_SECURITY_ALLOW_EMBEDDING: 'true' GF_AUTH_ANONYMOUS_ORG_ROLE: 'Admin' - GF_AUTH_ANONYMOUS_ENABLED: 'false' - - - + GF_AUTH_ANONYMOUS_ENABLED: 'true'