Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wis2download test and wis2box downloader commands to manage topics #693

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d904693
add GTS-headers using mapping csv
maaikelimper Jun 6, 2024
d9397d4
fix typo, only check gts-header when notify=true, update version
maaikelimper Jun 6, 2024
a35cadb
add more sleep and logging to tests
maaikelimper Jun 6, 2024
274e56c
fix missing key
maaikelimper Jun 6, 2024
a93b829
adding documentation
maaikelimper Jun 6, 2024
11ca57e
wis2download test and wis2box downloader commands to manage topics
maaikelimper Jun 10, 2024
0871276
flake8
maaikelimper Jun 10, 2024
374e33b
fix topic replace to deal with + and #
maaikelimper Jun 10, 2024
53a243a
replace localhost with public IP for download test to function ...
maaikelimper Jun 10, 2024
c5e2f50
get IP via hostname -I
maaikelimper Jun 10, 2024
7a0a487
count files downloaded per topic
maaikelimper Jun 10, 2024
369df59
updated docs
maaikelimper Jun 11, 2024
a53f7cb
grafana dashboard cleanup
maaikelimper Jun 11, 2024
4ed6118
updated downloaded request to align with Dave's changes
maaikelimper Jun 11, 2024
27043e9
rename to .session-info.json
maaikelimper Jun 11, 2024
73f5376
adding vector(0)
maaikelimper Jun 11, 2024
9562aff
update dashboard, build from main, align ENV with expected config
maaikelimper Jun 12, 2024
370de7a
revert __version__ change
maaikelimper Jun 13, 2024
3341e7e
if None not in
maaikelimper Jun 13, 2024
3b6d78d
Update gts-headers-in-wis2.rst
maaikelimper Jun 13, 2024
7eb14ce
Update gts-headers-in-wis2.rst
tomkralidis Jun 13, 2024
cc63b99
Merge pull request #694 from wmo-im/main
maaikelimper Jun 14, 2024
56a464a
Merge branch 'gts-headers-mapping' into downloader-add-tests-and-comm…
maaikelimper Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/tests-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ jobs:
docker version
docker compose version
python3 -V
- name: setup wis2box configuration
- name: setup wis2box configuration, replace localhost with IP on host 📦
run: |
export IP=$(hostname -I | awk '{print $1}')
cp tests/test.env wis2box.env
sed -i "s/localhost/$IP/g" wis2box.env
cat wis2box.env
python3 wis2box-ctl.py config
- name: build wis2box
Expand All @@ -39,11 +41,18 @@ jobs:
run: |
python3 wis2box-ctl.py start
python3 wis2box-ctl.py status -a
docker logs wis2box-management
- name: setup wis2box-management ⚙️
- name: show environment and check collections exist ⚙️
run: |
sleep 30
python3 wis2box-ctl.py execute wis2box environment show
curl http://localhost/oapi/collections/stations
curl http://localhost/oapi/collections/discovery-metadata
curl http://localhost/oapi/collections/messages
- name: downloader subscribe to topics
env:
SUBSCRIPTION_TOPIC: origin/a/wis2/+/data/core/#
run: |
python3 wis2box-ctl.py execute wis2box downloader add-subscription --topic $SUBSCRIPTION_TOPIC
- name: populate stations from CSV 📡
run: |
python3 wis2box-ctl.py execute wis2box metadata station publish-collection
Expand Down Expand Up @@ -176,6 +185,7 @@ jobs:
- name: sleep 30 seconds then run integration tests ⚙️
run: |
sleep 30
docker logs wis2box-management
pytest -s tests/integration
- name: run flake8 ⚙️
run: |
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ services:
<<: *logging
web-proxy:
<<: *logging
wis2-downloader:
wis2downloader:
<<: *logging

volumes:
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ services:
depends_on:
- wis2box-management

wis2-downloader:
container_name: wis2-downloader
build: ./wis2-downloader
wis2downloader:
container_name: wis2downloader
build: ./wis2downloader
env_file:
- wis2box.env
volumes:
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The user guide helps you setup your own wis2box instance.
user/getting-started
user/setup
user/data-ingest
user/gts-headers-in-wis2
user/public-services-setup
user/downloading-data

Expand Down
76 changes: 36 additions & 40 deletions docs/source/user/downloading-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,86 +11,82 @@
WIS2 Global Services include a Global Broker that provides users the ability to subscribe to data (via topics) and download to their
local environment / workstation / decision support system from the WIS2 Global Cache.

wis2-downloader
wis2downloader
---------------

wis2box enables subscribe and data download workflow the WIS2 network, by using the ``wis2-downloader`` container, inside of which runs the `wis2-downloader tool <https://github.com/wmo-im/wis2-downloader`_
wis2box enables subscribe and data download workflow the WIS2 network, by using the ``wis2downloader`` container, inside of which runs the `wis2downloader tool <https://github.com/wmo-im/wis2downloader`_

Check warning on line 17 in docs/source/user/downloading-data.rst

View workflow job for this annotation

GitHub Actions / main

Unknown target name: "wis2downloader tool <https://github.com/wmo-im/wis2downloader".

``wis2-downloader`` is a Python package that provides subscription and download capability, by connecting to pre-defined MQTT-broker.
``wis2downloader`` is a Python package that provides subscription and download capability, by connecting to pre-defined MQTT-broker.

The following environment variables are used by the ``wis2-downloader``:
The following environment variables are used by the ``wis2downloader``:

- ``DOWNLOAD_BROKER_HOST``: The hostname of the MQTT-broker to connect to. Defaults to ``globalbroker.meteo.fr``
- ``DOWNLOAD_BROKER_PORT``: The port of the MQTT-broker to connect to. Defaults to ``443`` (HTTPS for websockets)
- ``DOWNLOAD_BROKER_USERNAME``: The username to use to connect to the MQTT-broker. Defaults to ``everyone``
- ``DOWNLOAD_BROKER_PASSWORD``: The password to use to connect to the MQTT-broker. Defaults to ``everyone``
- ``DOWNLOAD_BROKER_PROTOCOL``: The protocol to use to connect to the MQTT-broker. Defaults to ``websockets``
- ``DOWNLOAD_BROKER_TRANSPORT``: ``websockets`` or ``tcp``, the transport-mechanism to use to connect to the MQTT-broker. Defaults to ``websockets``,
- ``DOWNLOAD_RETENTION_PERIOD_HOURS``: The retention period in hours for the downloaded data. Defaults to ``24``
- ``DOWNLOAD_WORKERS``: The number of download workers to use. Defaults to ``8``. Determines the number of parallel downloads.
- ``DOWNLOAD_MIN_FREE_SPACE_GB``: The minimum free space in GB to keep on the volume hosting the downloads. Defaults to ``1``.

To override the default configuration, you can set the environment variables in the wis2box.env file.

By default the wis2-downloader is not subscribed to any topics. You can add subscriptions using the API endpoint, as described below.
By default the wis2downloader is not subscribed to any topics. You can add subscriptions using the `wis2box downloader` commands, which will call the API over the internal docker network.

The files downloaded by the wis2-downloader will be saved in `${WIS2BOX_HOST_DATADIR}/downloads`, where `${WIS2BOX_HOST_DATADIR}` is the directory on your host you defined in the `wis2box.env` file.
The files downloaded by the wis2downloader will be saved in `${WIS2BOX_HOST_DATADIR}/downloads`, where `${WIS2BOX_HOST_DATADIR}` is the directory on your host you defined in the `wis2box.env` file.

Maintaining and Monitoring Subscriptions
----------------------------------------

The wis2-downloader has an API-endpoint that is proxied on the path `/wis2-downloader` on the wis2box host-url. This endpoint can be used to add, delete and list subscriptions.
The wis2downloader has an API-endpoint that can be used to add, delete and list subscriptions.

The endpoint is secured using an API token, that can be created using the 'wis2box auth' command inside the wis2box-management container as follows:
You can use the `wis2box downloader` commands to interact with the API, which will call the API over the internal docker network.

```bash
python3 wis2box.ctl.py execute wis2box auth add-token --path wis2-downloader -y
```

Record the generated token, so you can use it to authenticate requests to the API.
The next sections describe how to use the `wis2box downloader` commands to list, add and delete subscriptions.

Listing subscriptions
~~~~~~~~~~~~~~~~~~~~~

To list the active subscriptions, a GET request can be made to the `wis2-downloader/list` endpoint, making sure to pass the API token as a header:
To list the current subscriptions, you can use the following command:

```bash
curl http://localhost/wis2-downloader/list -H "Authorization: Bearer <API-token>"
```
python3 wis2box.ctl.py execute wis2box downloader list-subscriptions
```

The list of the currently active subscriptions should be returned as a JSON object.
This will return a JSON object with the current subscriptions.

Adding subscriptions
~~~~~~~~~~~~~~~~~~~~
Adding a subscription
~~~~~~~~~~~~~~~~~~~~~

Subscriptions can be added via a GET request to the `./add` endpoint that is proxied on /wis2-downloader on the wis2box host, with the following form:
To add a subscription, you can use the following command:

```bash
curl http://localhost/wis2-downloader/add?topic=<topic-name>&target=<download-directory> -H "Authorization: Bearer <API-token>"
```
python3 wis2box.ctl.py execute wis2box downloader add-subscription --topic <topic>
```

This will add a subscription to the topic you specify and return the JSON object with the current subscriptions.

- `topic` specifies the topic to subscribe to. *Special characters (+, #) must be URL encoded, i.e. `+` = `%2B`, `#` = `%23`.*
- `target` specifies the directory to save the downloads to, relative to `download_dir` from `config.json`. *If this is not provided, the directory will default to that of the topic hierarchy.*
Deleting a subscription
~~~~~~~~~~~~~~~~~~~~~~~

For example:
```bash
curl http://localhost/wis2-downloader/add?topic=cache/a/wis2/%2B/data/core/weather/%23&target=example_data -H "Authorization: Bearer <API-token>"
To delete a subscription, you can use the following command:

```
python3 wis2box.ctl.py execute wis2box downloader delete-subscription --topic <topic>
```

The list of active subscriptions after addition should be returned as a JSON object.
This will delete the subscription to the topic you specify and return the JSON object with the current subscriptions.

Deleting subscriptions
~~~~~~~~~~~~~~~~~~~~~~

Subscriptions are deleted similarly via a GET request to the `./delete` endpoint, with the following form:
```bash
curl http://<flask-host>:<flask-port>/delete?topic=<topic-name> -H "Authorization: Bearer <API-token>"
```
Managing subscriptions from outside the wis2box
----------------------------------------------

Check warning on line 82 in docs/source/user/downloading-data.rst

View workflow job for this annotation

GitHub Actions / main

Title underline too short.

Check warning on line 82 in docs/source/user/downloading-data.rst

View workflow job for this annotation

GitHub Actions / main

Title underline too short.

For example:
```bash
curl http://localhost:8080/delete?topic=cache/a/wis2/%2B/data/core/weather/%23 -H "Authorization: Bearer <API-token>"
```
The wis2downloader API-endpoint is proxied on the path `/wis2downloader` on the wis2box host-url, allowing you to interact with it using curl or other HTTP clients from any machine that can reach the wis2box host.

The list of active subscriptions after deletion should be returned as a JSON object.
The wis2box-proxy by default secures the path `/wis2downloader` with a bearer token, which can be generated using the `wis2box auth` command as follows:

```
python3 wis2box.ctl.py execute wis2box auth add-token --path wis2downloader -y
```


57 changes: 57 additions & 0 deletions docs/source/user/gts-headers-in-wis2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.. _gts-headers-in-wis2:

Optional: adding GTS headers to WIS2 notifications during the transition period
===============================================================================

Overview
--------

This section provides guidance how to add GTS headers to your WIS2 notifications.

By adding GTS headers to your WIS2 notifications, you can stop your MSS and still have your data available on the GTS during the transition period.

To enable the WIS2 to GTS Gateway to correctly identify the data to be republished on the GTS, you need to include the GTS property in the WIS2 Notification Message as follows:

.. code-block:: json

Check warning on line 15 in docs/source/user/gts-headers-in-wis2.rst

View workflow job for this annotation

GitHub Actions / main

Could not lex literal_block as "json". Highlighting skipped.

"properties": {
"gts": {
"ttaaii": "FTAE31",
"cccc": "VTBB"
}
}

wis2box can add these to WIS2 Notifications automatically, provided you specify the additional file `gts_headers_mappings.json` that contains the required information to map the GTS headers to the incoming filenames.

Note that this is optional and only required if you want to turn off the existing system responsible for sending data to the GTS during the transition period.

gts_headers_mapping.csv
-----------------------

If you want to add GTS headers to your WIS2 notifications, a CSV file is required that maps GTS headers to incoming filenames.

The CSV file should be named (exactly) `gts_headers_mapping.csv` and should be placed in the directory defined using the `WIS2BOX_HOST_DATADIR` environment variable.

The CSV should contain the following columns: `string_in_filepath`, `TTAAii`, and `CCCC`.

Example content for `gts_headers_mapping.csv`:

.. code-block:: csv

Check warning on line 39 in docs/source/user/gts-headers-in-wis2.rst

View workflow job for this annotation

GitHub Actions / main

Pygments lexer name 'csv' is not known

string_in_filepath,TTAAii,CCCC
ISMD01LIIB,ISMD01,LIBB
ISMD02LIIB,ISMD02,LIBB

In this example, whenever `ISMD01LIIB` or `ISMD02LIIB` is contained in the filepath of the incoming file,
the corresponding GTS headers will be added to the WIS2 Notification Message as a dictionary in the `properties` field:

.. code-block:: json

Check warning on line 48 in docs/source/user/gts-headers-in-wis2.rst

View workflow job for this annotation

GitHub Actions / main

Could not lex literal_block as "json". Highlighting skipped.

"properties": {
"gts": {
"ttaaii": "ISMD01",
"cccc": "LIBB"
}
}

If the `gts_headers_mapping.csv` file is not present in the directory you defined using the `WIS2BOX_HOST_DATADIR` environment variable, wis2box will not add any GTS headers to the WIS2 Notification Message.
Loading
Loading