Skip to content

Commit

Permalink
Version 0.7.1
Browse files Browse the repository at this point in the history
DownloadManager:
- Added support for manually specify a list of files to download.
- Minor typo fixes in comments.
  • Loading branch information
gaellafond committed Mar 21, 2023
1 parent 54734a8 commit 7c899dd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>au.gov.aims</groupId>
<artifactId>ereefs-database</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>

<!--
*** IMPORTANT ***
Expand Down
46 changes: 45 additions & 1 deletion src/main/java/au/gov/aims/ereefs/bean/download/DownloadBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

/**
* This is a simple bean, used with the {@code ereefs-download-manager} project.
* It represent the documents found in the MongoDB collection {@code download}.
* It represents the documents found in the MongoDB collection {@code download}.
* It's describing a Download definition for a THREDDS catalogue.
*/
public class DownloadBean extends AbstractBean {
Expand All @@ -26,6 +28,7 @@ public class DownloadBean extends AbstractBean {

private String filenameTemplate;
private String filenameRegexStr;
private Set<String> files;

// List of catalogue URLs.
// NOTE: Download definitions usually contain only one catalogue URL.
Expand Down Expand Up @@ -66,6 +69,7 @@ public DownloadBean(JSONObject jsonDownload) {
this.catalogueUrls = null;
this.addCatalogueUrl(jsonDownload.optString("catalogueUrl", null), null);
this.addCatalogueUrls(jsonDownload.optJSONArray("catalogueUrls"));
this.addFiles(jsonDownload.optJSONArray("files"));
this.setOutput(jsonDownload.optJSONObject("output"));
}
}
Expand Down Expand Up @@ -387,6 +391,46 @@ public void addCatalogueUrls(JSONArray catalogueUrlsArray) {
}
}

/**
* Get the manually provided list of files to download.
* This list will be null or empty unless it has been manually set by the user.
* @return list of files, specified as a {@code JSONArray}.
*/
public Set<String> getFiles() {
return this.files;
}

/**
* Manually specify a list of files to be downloaded from the catalogue.
*
* @param jsonFiles list of files, specified as a {@code JSONArray}.
*/
public void addFiles(JSONArray jsonFiles) {
if (jsonFiles != null && !jsonFiles.isEmpty()) {
for (int i=0; i<jsonFiles.length(); i++) {
this.addFile(jsonFiles.optString(i, null));
}
}
}

/**
* Add a file to be downloaded from the catalogue.
* NOTE: Adding a file will prevent the DownloadManager from downloading
* the other files listed in the catalogue.
* @param fileStr file to download, as listed the catalogue.
*/
public void addFile(String fileStr) {
if (fileStr != null) {
fileStr = fileStr.trim();
if (!fileStr.isEmpty()) {
if (this.files == null) {
this.files = new HashSet<String>();
}
this.files.add(fileStr);
}
}
}

/**
* Return the {@link OutputBean} which describe where the files are downloaded.
* @return the {@link OutputBean}.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/au/gov/aims/ereefs/database/DatabaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public class DatabaseClient {
private static final String AUTHENTICATION_SOURCE = "admin";
private static final String VARIABLE_STORE_PREFIX_ENVIRONMENT_VARIABLE = "EXECUTION_ENVIRONMENT";

// NOTE: The database is not 100% reliable. Sometime it disconnect (example: during server backups).
// NOTE: The database is not 100% reliable. Sometimes it disconnect (example: during server backups).
// Each method that access the DB is in a loop that try to re-establish a connection to the DB
// when it fail, up to X number of times, with a sufficient delay between retry to give a chance
// when it fails, up to X number of times, with a sufficient delay between retry to give a chance
// to the DB to recover / restart.
// 10 attempts = 10 seconds + 2*10 seconds + ... + 15*10 seconds = 1200 seconds
// = 20 minutes (without considering timeout / running time of each attempts)
// = 20 minutes (without considering timeout / running time of each attempt)
private static final int DEFAULT_DB_RETRY_ATTEMPTS = 15;
private static final int DEFAULT_DB_INITIAL_DELAY_BETWEEN_ATTEMPT = 10; // in seconds

Expand Down

0 comments on commit 7c899dd

Please sign in to comment.