The DownloadManager is a java jar that runs in a Docker container. It is used to download NetCDF files from Thredds
catalogues sources, such as the eReefs NCI server.
Its execution is triggered by AWS CloudWatch on regular basis. Once called, it creates a list of file to download
and download them.
It creates the list of files to download as followed:
- Find every enabled
DownloadDefinitionfound in the DatabaseDOWNLOADtable, - For each of them, download the Thredds XML catalogue to determine available files,
- Compare the list of available files with the previously downloaded files, as described in the Database
METADATAtable
Each missing / outdated NetCDF file is download as followed:
- Download the NetCDF file locally,
- Parse the NetCDF file to extract its metadata,
- Upload the file to the S3 bucket configured in the
DownloadDefinition, - Saved the extracted metadata to the Database
METADATAtable
- Checkout
ereefs-databaseproject - Compile and install the project in your local maven repository using:
mvn clean package install - Compile the
ereefs-download-managerproject using:mvn clean package - To compile and deploy the docker image, see the Docker scripts README file
-
Add some Thredds Catalogues to the Database
DOWNLOADtable.See project
ereefs-definitions -
Verify the execution using the
dryrunfeature:java -jar ereefs-download-manager-X.X-jar-with-dependencies.jar dryrun -
If you are satisfied with the output of the dry run, execute:
java -jar ereefs-download-manager-X.X-jar-with-dependencies.jar
This project can be deployed to AWS using Cloud Formation.
The cloudformation.yaml file creates the required elements for its deployment to AWS ECR
and for its execution.
The cloudformation.yaml file creates a Lambda function called ereefs-download-manager-XXXX-sns-listener
where XXXX in the name of the deployment environment.
Navigate to AWS Lambda, locate the function and click it to open its interface.
At the top right, you will see a dropdown and a Test button. If there is no test setup,
create one with the following parameters:
Create new test event
Event name: download2files
{
"Records": [
{
"Sns": {
"Message": "{ \"limit\": 2, \"dryRun\": false, \"downloadDefinitionId\": \"downloads__ereefs__gbr4_v2_daily\" }"
}
}
]
}
If you trigger this test, AWS Lambda will trigger a AWS Batch job named ereefs-download_manager_[DATETIME].
Monitor the AWS Batch job to see if it succeeds. When the task successfully terminate, 2 new files
are downloaded from each Download definitions and uploaded to S3, along with associated metadata
saved in the database.
The cloudformation.yaml file also create a CloudWatch rule named ereefs-download_manager-lambda-sns-listener-rule-XXXX
where XXXX in the name of the deployment environment.
The rule act as a cron job. It trigger the download manager periodically
by publishing a SNS message to the definitions-sns-XXXX-SNSTopicEReefsDownloadRequestTopic topic.
The Lambda function described above listen to that topic and automatically trigger a new AWS Batch job
when a message is published in that topic. The Batch job runs the DownloadManager in a docker container.
When there is new file available, the DownloadManger downloads them then publish a message in
definitions-sns-XXXX-SNSTopicEReefsDownloadCompletedTopic topic after each successful downloaded file.
Once all files are downloaded, it publishes a message in
definitions-sns-XXXX-SNSTopicEReefsAllDownloadCompletedTopic topic.
If the deployment environment is PROD, the rule is set to download all the missing / modified files, every hour.
Otherwise, the rule is set to download only 2 files per download definition and is disabled by default,
to prevent unwanted behaviour on development environments.
-
Open the
Amazon SNSpage:
Services > Application Integration > Simple Notification Service -
Open the
download-request_prodtopic -
Click on
[Publish message]button, in top right corner -
Fill the form:
Subject:DownloadManager_2021-02-22_14h42
Message body to send to the endpoint:{ "limit": -1, "dryRun": false }
Click[Publish Message]button, in the bottom right corner of the form.
