Service to Convert the OSW files to OSM files and OSM to OSW files. At the moment, the service does the following:
- Listens to the topic which is mentioned in
.envfile for any new message (that is triggered when a file is uploaded), exampleUPLOAD_TOPIC=osw-validation - Consumes the message and perform following checks -
- Download the file locally
- File location is in the message
data.meta.file_upload_path - Uses
osm-osw-reformatterto convert OSM file to OSW file - Upload the converted files to
oswstorage containter - Adds the
file_upload_pathanddownload_xml_urlkeys to the original message
- Publishes the result to the topic mentioned in
.envfile, exampleVALIDATION_TOPIC=osw-formatting-service
The project is built on Python with FastAPI framework. All the regular nuances for a Python project are valid for this.
| Software | Version |
|---|---|
| Python | 3.10.x |
| GDAL | 3.4.1 |
- Connecting this to cloud will need the following in the
.envfile
PROVIDER=Azure
QUEUECONNECTION=xxx
STORAGECONNECTION=xxx
FORMATTER_TOPIC=xxx
FORMATTER_SUBSCRIPTION=xxx
FORMATTER_UPLOAD_TOPIC=xxx
CONTAINER_NAME=xxx
MAX_CONCURRENT_MESSAGES=xx # Optional if not passed defaults to 2The application connect with the STORAGECONNECTION string provided in .env file and validates downloaded zipfile using python-osw-validation package.
QUEUECONNECTION is used to send out the messages and listen to messages.
MAX_CONCURRENT_MESSAGES is the maximum number of concurrent messages that the service can handle. If not provided, defaults to 2
Running the code base requires a proper Python environment set up. The following lines of code helps one establish such env named tdei-osw. replace tdei-osw with the name of your choice.
conda create -n tdei-osw python==3.10.3 gdal
conda activate tdei-osw
pip install -r requirements.txt
Alternatively one can use the setup_env.sh script provided with this repo. One can run
source ./setup_env.sh. Once run, the command creates an environment with the name tdei
If for some reason the above conda creation fails to install GDAL, please follow the procedure below.
To install the GDAL library (Geospatial Data Abstraction Library) on your system, you can follow the steps below. The specific installation process may vary depending on your operating system.
-
Linux (Ubuntu/Debian): GDAL is available in the Ubuntu and Debian repositories. You can install it using apt:
sudo apt update sudo apt install gdal-bin libgdal-dev python3-gdal -
Linux (CentOS/RHEL): On CentOS/RHEL, you can install GDAL using
yum:sudo yum install gdal -
macOS (Homebrew): If you're using Homebrew on macOS, you can install GDAL with the following command:
brew install gdal -
Windows: On Windows, you can install GDAL using the GDAL Windows binaries provided by the GIS Internals project:
- Go to the GIS Internals download page.
- Choose the GDAL version that matches your system (e.g., 32-bit or 64-bit) and download the core components.
- Install the downloaded MSI file.
- Make sure to add the GDAL bin directory to your system's PATH variable if it's not added automatically.
Follow the steps to install the python packages required for both building and running the application
-
Setup virtual environment
python3.10 -m venv .venv source .venv/bin/activate -
Install the dependencies. Run the following command in terminal on the same directory as
requirements.txt# Installing requirements pip install -r requirements.txt
- The http server by default starts with
8000port - Run server
uvicorn src.main:app --reload - By default
getcall onlocalhost:8000/healthgives a sample response - Other routes include a
pingwith get and post. Makegetorpostrequest tohttp://localhost:8000/health/ping - Once the server starts, it will start to listening the subscriber(
FORMATTER_SUBSCRIPTIONshould be in env file)
{
"messageId": "tdei_record_id",
"messageType": "workflow_identifier",
"data": {
"file_upload_path": "file_upload_path",
"tdei_project_group_id": "tdei_project_group_id"
}
} {
"messageId": "tdei_record_id",
"messageType": "workflow_identifier",
"data": {
"file_upload_path": "file_upload_path",
"tdei_project_group_id": "tdei_project_group_id",
"source_url": "file_upload_path",
"formatted_url": "uploaded_url",
"success": true/false,
"message": "message"
},
"publishedDate": "published date"
}{
"messageId": "c8c76e89f30944d2b2abd2491bd95337",
"messageType": "workflow_identifier ON_DEMAND",
"data": {
"sourceUrl": "https://tdeisamplestorage.blob.core.windows.net/osw/2023/11/c552d5d1-0719-4647-b86d-6ae9b25327b7/aff14a0d29ab4acbaef639063462e85b/naresh-som-2.zip",
"jobId": "42",
"source": "osw",
"target": "osm"
}
}{
"messageId": "c8c76e89f30944d2b2abd2491bd95337",
"messageType": "workflow_identifier ON_DEMAND",
"data": {
"sourceUrl": "https://tdeisamplestorage.blob.core.windows.net/osw/2023/11/c552d5d1-0719-4647-b86d-6ae9b25327b7/aff14a0d29ab4acbaef639063462e85b/naresh-som-2.zip",
"jobId": "42",
"source": "osw",
"target": "osm",
"formattedUrl": "https://tdeisamplestorage.blob.core.windows.net/osw/2023/11/c552d5d1-0719-4647-b86d-6ae9b25327b7/aff14a0d29ab4acbaef639063462e85b/naresh-som-2.zip",
"success": true,
"message": ""
}
}Make sure you have set up the project properly before running the tests, see above for How to Setup and Build.
- Add the new set of test inside
tests/test_harness/tests.jsonfile like -{ "Name": "Test Name", "Input_file": "test_files/osw_test_case1.json", // Input file path which you want to provide to the test "Result": true/false // Defining the test output } - Test Harness would require a valid
.envfile. - To run the test harness
python tests/test_harness/run_tests.py
.envfile is not required for Unit test cases.- To run the unit test cases
python test_report.py- Above command will run all test cases and generate the html report, in
reportsfolder at the root level.
- To run the coverage
python -m coverage run --source=src -m unittest discover -s tests/unit_tests- Above command will run all the unit test cases.
- To generate the coverage report in console
coverage report- Above command will generate the code coverage report in terminal.
- To generate the coverage report in html.
coverage html- Above command will generate the html report, and generated html would be in
htmlcovdirectory at the root level.
- NOTE : To run the
htmlorreportcoverage, 3.i) command is mandatory
.envfile is required for integration test cases.- To run the integration test cases, run the below command
python test_integration.py- Above command will run all integration test cases and generate the html report, in
reportsfolder at the root level.
This microservice deals with two topics/queues.
- upload queue from osw-validation
- formatter queue from osw-formatting-service
The incoming messages will be from the upload queue osw-upload.
The format is mentioned in osw-upload.json
The outgoing messages will be to the osw-validation topic.
The format of the message is at osw-format.json