# medis-etl-service Camel based app that is used to pullforms submissions from CHEFS via API, convert them into a set of CSV files for futher upload and loading into Oracle DB. # Local Development ## Building the Docker Image To build the docker image, use the following command: Docker configuration file: [docker/Dockerfile](docker/Dockerfile) ```shell # pwd is the repository root docker build . --file docker/Dockerfile -t etl:latest ``` ## Running the Docker Image To run the image use the following command: ```shell docker run --name etl -P -d etl:latest ``` # Maintenance ## Upgrading Camel The [Camel documentation](https://camel.apache.org/manual/camel-upgrade-recipes-tool.html) offers a `mvn` command to perform the desired upgrade. The command is: ``` $ mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ -Drewrite.recipeArtifactCoordinates=org.apache.camel.upgrade:camel-upgrade-recipes:"$CAMEL_VERSION_NUMBER" \ -Drewrite.activeRecipes=org.apache.camel.upgrade.CamelMigrationRecipe ``` ## Testing The Upgrade ### Prerequisites It is recommended to create a docker image with the old version of camel and a second image with the new version of camel. It is easier to compare data when data can be fetched from each version at the same time. The volume of requests and files can be overwhelming. To assist, the following scripts were created and placed in `scripts/test`: * [`endpoint-test.sh`](scripts/test/endpoint-test.sh) * [`compare-dirs.sh`](scripts/test/compare-dirs.sh) Details about the scripts are available at [Endpoint Testing](#endpoint-testing) and [File Testing](#file-testing). ### Testing Typically, testing will consist of performing the following on each unique endpoint in the ETL Bruno collection: 1. Run the [`endpoint-test.sh`](scripts/test/endpoint-test.sh) script 2. Verify the only difference in the responses is the file names of the generated files 3. Run [`compare-dirs.sh`](scripts/test/compare-dirs.sh) to compare the directory with the files generated by the old version of the application and the new version of the application 4. Verify the number of **matches** is the same as the number of **files** ### Appendix #### Endpoint Testing The endpoint testing script assumes you are testing a service listening on localhost. It then takes two ports as the first two arguments. One port should be for the ETL service using the old camel version and the second port should be for the ETL service using the new camel version. The third argument is the endpoint that will be hit. The script hits the same endpoint on both services. The fourth and final argument is a JSON object. The script assumes this is a POST request with a JSON body and the object passed here will be sent as the request's body for both services. An example of using the endpoint: Script file: [scripts/test/endpoint-test.sh](scripts/test/endpoint-test.sh) ```shell scripts/test/endpoint-test.sh 32687 32987 /path/endpoint '{"key": "value"}' ``` Note that the ports in this scenario are being forwarded using Docker. The ports being used for the services running in docker may vary depending on each developer's configuration. Feel free to update the script as issues/bugs are encountered. #### File Testing The ETL service produces txt files which contain CSV formatted data. The [`compare-dirs.sh`](scripts/test/compare-dirs.sh) script takes all of the txt files in the two provided directories and ensures that each file has a matching file in the other directory. If the script reports that all files match, then both directories contain txt files with identical content (not identical names because each txt file gets the date and unique hash appended to its name). The script removes columns which contain randomly generated ids. These ids vary between subsequent hits against the same endpoint. Therefore, it does not make sense for them to match between two instances of the ETL service running different versions of camel. An example of using the script: Script file: [scripts/test/compare-dirs.sh](scripts/test/compare-dirs.sh) ```shell scripts/test/compare-dirs.sh directory/a directory/b ``` Feel free to update the script as issues/bugs are encountered. #### Testing File Contents It is possible to run SQL queries on CSV files but that limits queries to only one file at a time as opposed to all records. To solve this, you can import the csv file data into a local postgresql instance. First fill out the [`scripts/debugging/.env.template`](scripts/debugging/.env.template) file with any value you would like and then rename it to `scripts/debugging/.env`. Then use [`scripts/debugging/docker-compose.yml`](scripts/debugging/docker-compose.yml) to spin up a local postgresql instance: ```shell # With pwd as scripts/debugging. docker compose up ``` To import the records: 1. Make sure you have captured the desired files as `.txt` files in the `unencrypted` directory. 2. Place a symlink called `unencrypted` to the desired `unencrypted` directory inside the `scripts/debugging` directory. 3. Change the `.txt` file extension to `.csv` for all the report files. 4. Finally, run the [`scripts/debugging/insert-records.sh`](scripts/debugging/insert-records.sh) script to import the records. Please note this testing method is still a work in progress and may be buggy. Please update as you see fit.