Skip to content

Commit

Permalink
traffic-a22-forecast: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Sep 19, 2023
1 parent c50134a commit b433513
Show file tree
Hide file tree
Showing 24 changed files with 770 additions and 0 deletions.
29 changes: 29 additions & 0 deletions data-collectors/traffic-a22-forecast/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Data Collector config
A22_URL=
A22_USER=
A22_PASSWORD=

SCHEDULER_CRON=0 */10 * * * *

SCHEDULER_POOL_SIZE=1


# OpenDataHub O-AUTH Keycloak configuration
# (These are standard values for local development)
OAUTH_AUTH_URI=https://auth.opendatahub.testingmachine.eu/auth
OAUTH_TOKEN_URI=https://auth.opendatahub.testingmachine.eu/auth/realms/noi/protocol/openid-connect/token
OAUTH_BASE_URI=http://localhost:8999/json
OAUTH_CLIENT_ID=odh-mobility-datacollector-bike-boxes
OAUTH_CLIENT_NAME=odh-mobility-datacollector-bike-boxes
OAUTH_CLIENT_SECRET=7bd46f8f-c296-416d-a13d-dc81e68d0830

ODH_CLIENT_STATIONTYPE=TrafficForecast
ODH_CLIENT_PROVENANCE_NAME=odh-mobility-dc-traffic-a22-forecast
ODH_CLIENT_PROVENANCE_VERSION=0.1.0
ODH_CLIENT_PROVENANCE_ORIGIN=A22
ODH_CLIENT_PERIOD=600

# Logging level and style (text or json)
LOG_LEVEL=info
LOG_STYLE=text
ROOT_LOG_LEVEL=info
154 changes: 154 additions & 0 deletions data-collectors/traffic-a22-forecast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<!--
SPDX-FileCopyrightText: NOI Techpark <[email protected]>
SPDX-License-Identifier: CC0-1.0
-->

# A22 Road weather


Application which takes A22 road weather data from a web service parses it and sends it to the opendatahub.

[![CI traffic-a22-forecast](https://github.com/noi-techpark/bdp-commons/actions/workflows/ci-traffic-a22-forecast.yml/badge.svg)](https://github.com/noi-techpark/bdp-commons/actions/workflows/ci-traffic-a22-forecast.yml)

## Table of contents

- [A22 Road weather](#a22-road-weather)
- [Table of contents](#table-of-contents)
- [Getting started](#getting-started)
- [Prerequisites](#prerequisites)
- [Source code](#source-code)
- [Build](#build)
- [Running tests](#running-tests)
- [Deployment](#deployment)
- [Information](#information)
- [Support](#support)
- [Contributing](#contributing)
- [Documentation](#documentation)
- [License](#license)

## Getting started

These instructions will get you a copy of the project up and running
on your local machine for development and testing purposes.

### Prerequisites

To build the project, the following prerequisites must be met:

- Java JDK 1.8 or higher (e.g. [OpenJDK](https://openjdk.java.net/))
- [Maven](https://maven.apache.org/) 3.x
- A postgres database with the schema intimev2 and elaboration (bdp) already installed

### Source code

Get a copy of the repository:

```bash
git clone git clone https://github.com/noi-techpark/bdp-commons
```

Change directory:

```bash
cd bdp-commons/data-collectors/traffic-a22-forecast
```

### Build

Build the project:

```bash
mvn clean package
```

## Running tests

The unit tests can be executed with the following command:

```bash
mvn clean test
```

## Deployment

This is a maven project and will produce a war that can be deployed in any j2ee container like tomcat or jetty.

Steps:

* change the file src/main/resources/META-INF/spring/application.properties. set the url, the username and the
password to connect to the A22 API to query historic values of road weather (or configure it within a CI tool)

```
url=
user=
password=
```

* optionally change frequence of elaborations in the file src/main/resources/it/bz/noi/a22/roadweather/cron.properties.
(or configure it within a CI tool)

```
schedule=0 0/10 * * * ?
```

* optionally change the origin, the provenance, the station type, the last timestamp and the scan window (in seconds) in the file
src/main/resources/it/bz/noi/a22/roadweather/a22roadweather.properties. (or configure it within a CI tool)

```
origin=A22
provenance.name=dc-
provenance.version=1.0.0-SNAPSHOT
stationtype=RWISstation
lastTimestamp=2017-01-01 00:00:00
scanWindowSeconds=604800
```

* optionally change the data types in the file src/main/resources/it/bz/noi/a22/roadweather/a22roadweatherdatatypes.propertiess.
(or configure it within a CI tool)

```
a22roadweather.datatype.temp_aria.key=temp_aria
a22roadweather.datatype.temp_aria.unit=[°C]
a22roadweather.datatype.temp_aria.description=Temperatura dell’aria
a22roadweather.datatype.temp_aria.rtype=Mean
a22roadweather.datatype.temp_aria.mapping=false
...
```

* configure the log4j.properties file as desidered

* create the war executing the following command

```
mvn clean package
```

* deploy the war to a j2ee container like tomcat or jetty


## Information

### Support

For support, please contact [[email protected]](mailto:[email protected]).

### Contributing

If you'd like to contribute, please follow the following instructions:

- Fork the repository.

- Checkout a topic branch from the `development` branch.

- Make sure the tests are passing.

- Create a pull request against the `development` branch.

### Documentation

More documentation can be found at [https://opendatahub.readthedocs.io/en/latest/index.html](https://opendatahub.readthedocs.io/en/latest/index.html).

### License

The code in this project is licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 license. See the [LICENSE.md](LICENSE.md) file for more information.
12 changes: 12 additions & 0 deletions data-collectors/traffic-a22-forecast/calls.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@host = {{$dotenv A22_URL}}
@user = {{$dotenv A22_USER}}
@password = {{$dotenv A22_PASSWORD}}


### GetPrevisioniTrafficoComplete
POST {{host}}/GetPrevisioniTrafficoComplete
User-Agent: NOI/A22TrafficForecastConnector
Content-Type: application/json
Authorization: Basic {{user}}:{{password}}
Month: 10
Year: 2023
29 changes: 29 additions & 0 deletions data-collectors/traffic-a22-forecast/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: NOI Techpark <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0

version: "3.4"

services:
app:
image: maven:3-openjdk-17-slim
env_file:
- .env
environment:
MAVEN_CONFIG: /var/maven/.m2
MAVEN_OPTS: -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:9000"
command: >
mvn
-Duser.home=/var/maven
clean
compile
spring-boot:run
ports:
- 9000:9000
- 9001:9001
volumes:
- ~/.m2/:/var/maven/.m2
- ./:/code
working_dir: /code
tty: true
network_mode: host
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
inventory = ./hosts
roles_path = ./roles
retry_files_enabled = False
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- hosts: all
vars:
ansible_python_interpreter: /usr/bin/python3
tasks:
- name: Login to GitHub Container Registry
ansible.builtin.shell:
cmd: echo "{{ docker_password }}" | docker login "{{ docker_host }}" --username "{{ docker_username }}" --password-stdin
- name: Execute Docker deployment
ansible.builtin.include_role:
name: ansible-docker-deployment
vars:
docker_deployment_project_name: '{{ project_name }}'
docker_deployment_release_name: '{{ release_name }}'
docker_deployment_release_files:
- local: ../docker-compose.run.yml
remote: docker-compose.yml
- local: ../../.env
remote: .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[test]
docker01.testingmachine.eu ansible_user='noi-techpark-bot' ansible_ssh_common_args='-o StrictHostKeyChecking=no'

[prod]
docker02.opendatahub.com ansible_user='noi-techpark-bot' ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- src: git+https://github.com/noi-techpark/ansible-docker-deployment.git
version: "2.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.4"

services:
app:
image: ${DOCKER_IMAGE}:${DOCKER_TAG}
build:
context: ../
dockerfile: infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.4"

services:
app:
image: ${DOCKER_IMAGE}:${DOCKER_TAG}
restart: unless-stopped
environment:
_JAVA_OPTIONS: ${JAVA_OPTIONS}
env_file:
- .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.m2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM maven:3-openjdk-17-slim as base
COPY target/ROOT.jar app.jar
CMD [ "java", "-jar", "app.jar" ]
83 changes: 83 additions & 0 deletions data-collectors/traffic-a22-forecast/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
SPDX-FileCopyrightText: NOI Techpark <[email protected]>
SPDX-License-Identifier: CC0-1.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.opendatahub.bdp</groupId>
<artifactId>dc-traffic-a22-forecast</artifactId>
<version>0.1.0</version>
<name>A22 traffic forecast data collector</name>

<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<finalName>ROOT</finalName>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<repositories>
<repository>
<id>maven-repo.opendatahub.com</id>
<url>https://maven-repo.opendatahub.com/release</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>it.bz.idm.bdp</groupId>
<artifactId>dc-interface</artifactId>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>${finalName}</finalName>
</build>
</project>
Loading

0 comments on commit b433513

Please sign in to comment.