This container does two things:
Runs as a server with REST endpoint to query flight data from NM
Periodically downloads flight data for a specified airport and stores it to a postgres db
Both functions can be used independently of each other. So it is also possible to use the container only for periodic querying of the flight data. If you don't want so store the flight data into the database, you can skip the database configuration. Just set AUTO_DOWNL=0 in the .env file.
Sources: https://github.com/wadti/b2b-client-rest/tree/main/b2b-client-rest/b2b-client-rest
To set up the database and a pgadmin, run
$ docker compose up
with a docker-compose.yml containing:
version: '3'
services:
postgres:
container_name: pg
image: postgres:9.6
hostname: postgres
ports:
- "5432:5342"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: flightsByAerodrome
volumes:
- postgres-data:/var/lib/postgresql/data
restart: unless-stopped
pgAdmin:
container_name: pgadmin
image: dpage/pgadmin4:latest
ports:
- "8080:80"
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: TopSecret
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION: 'True'
PGADMIN_CONFIG_CONSOLE_LOG_LEVEL: 10
volumes:
postgres-data:
This will pull and start a postgres database and pgadmin container, already configured for the use for this container.
To find out the IP address of the database container run:
$ docker inspect pg | grep IPAddress
You'll need this to set up the address in the .env file.
The container needs to be started up with a .env file. This file must contain:
B2B_FLAVOUR=PREOPS
B2B_CERT_FORMAT=pfx
B2B_CERT=/cert/<YourCert>.p12
B2B_CERT_PASSPHRASE=<YourPassPhrase>
B2B_AERODROME=<ICAO code of airport>
B2B_REST_PORT=<restPort>
AUTO_DOWNL=0
AUTO_CRON=6,36 * * * *
AUTO_TIMESP=30
PGUSER=<pgUser>
PGHOST=172.xxx.xxx.xxx
PGPASSWORD=<pgPw>
PGDATABASE=<pgDB>
PGPORT=<pgPort>
The B2B_FLAVOUR sets if you want to use PREOPS or OPS data. All env vars wit CERT defines the authentication.
B2B_AERODROME sets the aerodrome, from which you want to download the flight data periodically. B2B_REST_PORT sets the port where you can query the flight data for a given aerodrome via REST (default: 3000). PG_USER, PG_PASSWORD, PG_DATABASE and PG_PORT are set automatically set via docker-compose.yml. If you need to do any changes, make sure, to also update these env vars there!
You'll need to have a valid NMB2B certificate and, to run this container. The passphrase needs to be provided in the .env file (B2B_CERT_PASSPHRASE).
The certificate is passed to the container via a docker volume. To set up a docker volume, run:
$ docker volume create cert
$ docker volume inspect cert
Copy your certificate to the Mountpoint you see after inspect.
To run the container, start it via docker run:
$ docker run --mount source=cert,destination=/cert --net=host --env-file=../.env wudti/b2b-client-rest:latest
The container is now up and running and should look something like this:
yarn run v1.22.18
$ node --openssl-legacy-provider src/index.js
NMB2B client running on port 3000
Started: Thu Apr 14 2022 11:27:52 GMT+0000 (Coordinated Universal Time)
Auto downloader running for LSZH
---------------------------------
--openssl-legacy-provider as parameter is only needed when you are running the client in a node 17 container. The parameter is specified in package.json.
To query flightsByAerodrome, you'll need to pass three arguments:
from and to specify the time window you want to query.
On the host system, you can test the REST endpoint by opening you browser and enter a query that should look something like this:
http://foo.bar:3000/LSZH/2022-04-13T14:46:09.000Z/2022-04-13T16:46:09.000Z
0.1 returns a JSON, >=0.2 returns an XML.
http://foo.bar:3000/flightsByRegulationCategory
Returns a JSON -like object, summarizing how many flights are affected by regulation category.
e.g.
[["ARRIVAL","1"],["ENROUTE","72"]]
Missing categories are not returned (DEPARTURE in this case).
http://foo.bar:3000/knownRegulations
Returns sum of distinct regulations by category.
e.g.
[["ARRIVAL","1"],["ENROUTE","23"]]
SQL query:
SELECT mostpenalisingregulationlocationcategory, COUNT(DISTINCT mostpenalisingregulation)
FROM(SELECT mostpenalisingregulation, mostpenalisingregulationlocationcategory
FROM flightsbyaerodrome.flights AS flights
JOIN flightsbyaerodrome.meta AS meta
ON flights.requestid = meta.requestid
WHERE now() BETWEEN effectivetrafficwindowfrom AND effectivetrafficwindowto
AND aerodrome = 'EHAM'
AND mostpenalisingregulation IS NOT NULL
AND requestreceptiontime = (SELECT MAX(requestreceptiontime)
FROM flightsbyaerodrome.meta
WHERE aerodrome = 'EHAM')) AS regulations
GROUP BY mostpenalisingregulationlocationcategory;
Returns a JSON object containing the NMs response with the users subscriptions
NOTE: Subscription ID is hardcoded
Resumes a given subscription (Paused --> Active)
NOTE: Subscription ID is hardcoded
Pauses a given subscription (Active --> Paused)
NOTE: Subscription ID is hardcoded, not finished!
This will connect to the AMQP queue (PREOPS) and retrive the subscription data
Flight data requested with REST is returned as JSON, no input validation
Flight data requested with REST is now returned as XML, no input validation
Added REGEX input validation for ICAO code and timestamps in REST request
Added flag to toggle auto download of flight data, AUTO_DOWNL=[0|1] can now be set in .env (Default = 0).
Added cron string AUTO_CRON as env var to configure download intervals.
Added AUTO_TIMESP as env var to configure the length of the requested time window [minutes]. Time span requested = Now until (Now + AUTO_TIMESP)
Added aerodrome column to meta table
Fixed bug with AUTO_TIMESP
Added REST /knownRegulations, this returns all currently effective regulations stored in the database aggregated for statistical reasons as JSON.
Fixed bugs with REST endpoint
Added REST functionality for PubSub Services (Subscriptions hard coded)
Content type
Image
Digest
Size
68 MB
Last updated
over 4 years ago
docker pull wudti/b2b-client-rest:0.9.1