From ecdc99903729b22357137eaee75c8f25d04a1330 Mon Sep 17 00:00:00 2001 From: thiagowhispher Date: Tue, 24 Nov 2020 11:01:44 -0300 Subject: [PATCH 1/3] Some more files/folders added --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index caa835f..ac36f60 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ *.log* nohup.out saps-catalog.iml +.classpath +.project +.settings/ From b72ec95ac7dda35afa1a92da56384ed059eb8f16 Mon Sep 17 00:00:00 2001 From: thiagowhispher Date: Tue, 24 Nov 2020 11:02:00 -0300 Subject: [PATCH 2/3] Added dependencies of spotless and google-java-format --- pom.xml | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a2d146f..474621b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,51 @@ + + com.diffplug.spotless + spotless-maven-plugin + 2.6.1 + + + + + + + + + *.md + .gitignore + + + + + + true + 4 + + + + + + + + + + 1.7 + + + + + + /* (C)$YEAR */ + + + + org.apache.maven.plugins maven-compiler-plugin @@ -96,8 +141,8 @@ local-maven-repo file:///${project.basedir}/local-maven-repo - @@ -270,5 +315,11 @@ saps-common 0.0.1-SNAPSHOT + + + com.diffplug.spotless + spotless-maven-plugin + 2.6.1 + From 490658d2eba82f74c9229be6132339a3a2bc7a94 Mon Sep 17 00:00:00 2001 From: thiagowhispher Date: Tue, 24 Nov 2020 11:02:13 -0300 Subject: [PATCH 3/3] Refactored code according to Google Java Style --- README.md | 52 +- src/main/java/saps/catalog/core/Catalog.java | 219 +++-- .../core/exceptions/CatalogException.java | 9 +- .../exceptions/TaskNotFoundException.java | 11 +- .../exceptions/UserNotFoundException.java | 9 +- .../saps/catalog/core/jdbc/JDBCCatalog.java | 918 ++++++++++-------- .../core/jdbc/JDBCCatalogConstants.java | 463 +++++---- .../catalog/core/jdbc/JDBCCatalogUtil.java | 87 +- .../jdbc/exceptions/JDBCCatalogException.java | 11 +- .../saps/catalog/core/retry/CatalogUtils.java | 420 ++++---- .../core/retry/catalog/AddNewTask.java | 100 +- .../core/retry/catalog/AddNewUser.java | 52 +- .../core/retry/catalog/AddTimestampRetry.java | 32 +- .../core/retry/catalog/CatalogRetry.java | 3 +- .../core/retry/catalog/GetAllTasks.java | 22 +- .../core/retry/catalog/GetProcessedTasks.java | 66 +- .../catalog/GetProcessingTasksRetry.java | 28 +- .../core/retry/catalog/GetTaskById.java | 25 +- .../core/retry/catalog/GetTasksRetry.java | 28 +- .../catalog/core/retry/catalog/GetUser.java | 37 +- .../retry/catalog/RemoveTimestampRetry.java | 26 +- .../core/retry/catalog/UpdateTaskRetry.java | 31 +- .../exceptions/CatalogRetryException.java | 9 +- 23 files changed, 1493 insertions(+), 1165 deletions(-) diff --git a/README.md b/README.md index 86044c6..b2197da 100644 --- a/README.md +++ b/README.md @@ -5,41 +5,41 @@ The Service Catalog component mantains the state of the tasks submitted to the S ## Dependencies In an apt-based Linux distro, type the below commands to install PostgreSQL packages. - ```bash - sudo apt-get update - sudo apt-get install -y postgresql - ``` +```bash +sudo apt-get update +sudo apt-get install -y postgresql +``` ## Configure To configure SAPS catalog, first create an user, defined by a name (```catalog_user```) and password (```catalog_passwd```). In addition, create a database (```catalog_db_name```). Fill the variables and run below commands: - ``` - sudo su - su postgres - catalog_user= - catalog_db_name= - catalog_passwd= - psql -c "CREATE USER $catalog_user WITH PASSWORD '$catalog_passwd';" - psql -c "CREATE DATABASE $catalog_db_name OWNER $catalog_user;" - psql -c "GRANT ALL PRIVILEGES ON DATABASE $catalog_db_name TO $catalog_user;" - exit - ``` +``` +sudo su +su postgres +catalog_user= +catalog_db_name= +catalog_passwd= +psql -c "CREATE USER $catalog_user WITH PASSWORD '$catalog_passwd';" +psql -c "CREATE DATABASE $catalog_db_name OWNER $catalog_user;" +psql -c "GRANT ALL PRIVILEGES ON DATABASE $catalog_db_name TO $catalog_user;" +exit +``` Once the database was created, you need to grant access to external clients. For that, we need to know which version of Postgres is installed. -Run command below to check the posgresql version: - ``` - ls /etc/postgresql - ``` +Run command below to check the posgresql version: +``` +ls /etc/postgresql +``` Run commands below to grant access to external clients: - ``` - installed_version= - sed -i 's/peer/md5/g' /etc/postgresql/$installed_version/main/pg_hba.conf - bash -c 'echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/$installed_version/main/pg_hba.conf' - sudo sed -i "$ a\listen_addresses = '*'" /etc/postgresql/$installed_version/main/postgresql.conf - sudo service postgresql restart - ``` +``` +installed_version= +sed -i 's/peer/md5/g' /etc/postgresql/$installed_version/main/pg_hba.conf +bash -c 'echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/$installed_version/main/pg_hba.conf' +sudo sed -i "$ a\listen_addresses = '*'" /etc/postgresql/$installed_version/main/postgresql.conf +sudo service postgresql restart +``` ## Test To verify whether the deploy was successful, one can try opening a connection (assuming it is accessible via the ```$catalog_ip_address``` IP address) to it from another machine (it is necessary to have PostgreSQL installed), using the below command: diff --git a/src/main/java/saps/catalog/core/Catalog.java b/src/main/java/saps/catalog/core/Catalog.java index 001846f..381610a 100644 --- a/src/main/java/saps/catalog/core/Catalog.java +++ b/src/main/java/saps/catalog/core/Catalog.java @@ -1,9 +1,9 @@ +/* (C)2020 */ package saps.catalog.core; import java.sql.Timestamp; import java.util.Date; import java.util.List; - import saps.catalog.core.exceptions.CatalogException; import saps.catalog.core.exceptions.TaskNotFoundException; import saps.catalog.core.exceptions.UserNotFoundException; @@ -13,97 +13,128 @@ public interface Catalog { - //FIXME: maybe, refactor related information into a separated data structured, e.g.: - // satellite data: dataset, region and date. - // - SAPS schema: taskID, priority, userEmail. - // - versions of the processing step algorithms: inputdownloadingPhaseTag, preprocessingPhaseTag and processingPhaseTag.
- // - Docker: digestInputdownloading, digestPreprocessing and digestProcessing. - //FIXME: by manel. I think we can use an UUID instead of the taskId string - //FIXME: by manel. I think we can use an ENUM instead of the dataset string - - //FIXME: verify and doc the high priority (0 or 31?) - - //FIXME: by manel. do we really need this *phaseTag parameters? - - /** - * It adds a new Task into this {@code Catalog}.
- * - * @param taskId an unique identifier for the SAPS task. - * @param dataset it is the type of data set associated with the new task to be created. Their values ​​can be:
- * -- landsat_5: indicates that the task is related to the LANDSAT 5 satellite - * (https://www.usgs.gov/land-resources/nli/landsat/landsat-5)
- * -- landsat_7: indicates that the task is related to the LANDSAT 7 satellite - * (https://www.usgs.gov/land-resources/nli/landsat/landsat-7)
- * -- landsat_8: indicates that the task is related with the LANDSAT 8 satellite data set - * (https://www.usgs.gov/land-resources/nli/landsat/landsat-8)
- * @param region is the location of the satellite data following the global notation system for Landsat data (WRS: - * https://landsat.gsfc.nasa.gov/the-worldwide-reference-system), following the PPPRRR form, where PPP - * is a length-3 to the path number and RRR is a length-3 to the row number. - * @param date is the date on which the satellite data was collected following the YYYY/MM/DD format. - * @param priority is an integer in the [0, 31] range that indicates the priority of task processing. - * @param user it is the email of the user that has submitted the task - * @param inputdownloadingPhaseTag is the version of the algorithm that will be used in the task's inputdownloading step - * @param digestInputdownloading is the version of the algorithm that will be used in the task's preprocessing step - * @param preprocessingPhaseTag is the version of the algorithm that will be used in the task's processing step - * @param digestPreprocessing is the immutable identifier (digest) of the Docker image of the version defined - * in the inputdownloading step (inputdownloadingPhaseTag) - * @param processingPhaseTag is the immutable identifier (digest) of the Docker image of the version defined - * in the preprocessing step (preprocessingPhaseTag) - * @param digestProcessing is the immutable identifier (digest) of the Docker image of the version defined - * in the processing step (processingPhaseTag) - * - * @return the new {@code SapsImage} created and added to this {@code Catalog}. - * - * @throws CatalogException if any unexpected behavior occurs. - */ - SapsImage addTask(String taskId, String dataset, String region, Date date, int priority, String user, - String inputdownloadingPhaseTag, String digestInputdownloading, String preprocessingPhaseTag, - String digestPreprocessing, String processingPhaseTag, String digestProcessing) throws CatalogException; - - void addStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) throws CatalogException; - - //FIXME: by manel. we want to know the possible values of the parameters. which ones are mandatory? can we use - // null or an empty strings? - - //FIXME: what if the user is added twice? - - /** - * It adds a new user to this {@code Catalog}. - * - * @param userEmail user email used for authentication on the SAPS platform - * @param userName user name on the SAPS platform - * @param userPass user password used for authentication on the SAPS platform - * @param isEnable informs if the user is able to authenticate on the SAPS platform - * @param userNotify informs the user about their tasks by email - * @param adminRole informs if the user is an administrator of the SAPS platform - * - * @throws CatalogException if any unexpected behavior occurs. - * - */ - void addUser(String userEmail, String userName, String userPass, boolean isEnable, boolean userNotify, - boolean adminRole) throws CatalogException; - - //FIXME: i think we should throw an exception when there is no imageTask in the Catalog - void updateImageTask(SapsImage imageTask) throws CatalogException; - - //FIXME: we should explain we return an empty list in some cases - /** - * @return - * @throws CatalogException - */ - List getAllTasks() throws CatalogException; - - List getTasksByState(ImageTaskState... tasksStates) throws CatalogException; - - SapsImage getTaskById(String taskId) throws CatalogException, TaskNotFoundException; - - //FIXME: what if the userEmail is null? empty string? (doc it) - SapsUser getUserByEmail(String userEmail) throws CatalogException, UserNotFoundException; - - //FIXME: what if the taskId does not exist in the catalog - void removeStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) throws CatalogException; - - //FIXME: it may return an empty list, right? doc-it - List filterTasks(ImageTaskState state, String region, Date initDate, Date endDate, String inputdownloadingTag, - String preprocessingTag, String processingTag) throws CatalogException; + // FIXME: maybe, refactor related information into a separated data structured, e.g.: + // satellite data: dataset, region and date. + // - SAPS schema: taskID, priority, userEmail. + // - versions of the processing step algorithms: inputdownloadingPhaseTag, preprocessingPhaseTag + // and processingPhaseTag.
+ // - Docker: digestInputdownloading, digestPreprocessing and digestProcessing. + // FIXME: by manel. I think we can use an UUID instead of the taskId string + // FIXME: by manel. I think we can use an ENUM instead of the dataset string + + // FIXME: verify and doc the high priority (0 or 31?) + + // FIXME: by manel. do we really need this *phaseTag parameters? + + /** + * It adds a new Task into this {@code Catalog}.
+ * + * @param taskId an unique identifier for the SAPS task. + * @param dataset it is the type of data set associated with the new task to be created. Their + * values ​​can be:
+ * -- landsat_5: indicates that the task is related to the LANDSAT 5 satellite + * (https://www.usgs.gov/land-resources/nli/landsat/landsat-5)
+ * -- landsat_7: indicates that the task is related to the LANDSAT 7 satellite + * (https://www.usgs.gov/land-resources/nli/landsat/landsat-7)
+ * -- landsat_8: indicates that the task is related with the LANDSAT 8 satellite data set + * (https://www.usgs.gov/land-resources/nli/landsat/landsat-8)
+ * @param region is the location of the satellite data following the global notation system for + * Landsat data (WRS: https://landsat.gsfc.nasa.gov/the-worldwide-reference-system), following + * the PPPRRR form, where PPP is a length-3 to the path number and RRR is a length-3 to the + * row number. + * @param date is the date on which the satellite data was collected following the YYYY/MM/DD + * format. + * @param priority is an integer in the [0, 31] range that indicates the priority of task + * processing. + * @param user it is the email of the user that has submitted the task + * @param inputdownloadingPhaseTag is the version of the algorithm that will be used in the task's + * inputdownloading step + * @param digestInputdownloading is the version of the algorithm that will be used in the task's + * preprocessing step + * @param preprocessingPhaseTag is the version of the algorithm that will be used in the task's + * processing step + * @param digestPreprocessing is the immutable identifier (digest) of the Docker image of the + * version defined in the inputdownloading step (inputdownloadingPhaseTag) + * @param processingPhaseTag is the immutable identifier (digest) of the Docker image of the + * version defined in the preprocessing step (preprocessingPhaseTag) + * @param digestProcessing is the immutable identifier (digest) of the Docker image of the version + * defined in the processing step (processingPhaseTag) + * @return the new {@code SapsImage} created and added to this {@code Catalog}. + * @throws CatalogException if any unexpected behavior occurs. + */ + SapsImage addTask( + String taskId, + String dataset, + String region, + Date date, + int priority, + String user, + String inputdownloadingPhaseTag, + String digestInputdownloading, + String preprocessingPhaseTag, + String digestPreprocessing, + String processingPhaseTag, + String digestProcessing) + throws CatalogException; + + void addStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) + throws CatalogException; + + // FIXME: by manel. we want to know the possible values of the parameters. which ones are + // mandatory? can we use + // null or an empty strings? + + // FIXME: what if the user is added twice? + + /** + * It adds a new user to this {@code Catalog}. + * + * @param userEmail user email used for authentication on the SAPS platform + * @param userName user name on the SAPS platform + * @param userPass user password used for authentication on the SAPS platform + * @param isEnable informs if the user is able to authenticate on the SAPS platform + * @param userNotify informs the user about their tasks by email + * @param adminRole informs if the user is an administrator of the SAPS platform + * @throws CatalogException if any unexpected behavior occurs. + */ + void addUser( + String userEmail, + String userName, + String userPass, + boolean isEnable, + boolean userNotify, + boolean adminRole) + throws CatalogException; + + // FIXME: i think we should throw an exception when there is no imageTask in the Catalog + void updateImageTask(SapsImage imageTask) throws CatalogException; + + // FIXME: we should explain we return an empty list in some cases + /** + * @return + * @throws CatalogException + */ + List getAllTasks() throws CatalogException; + + List getTasksByState(ImageTaskState... tasksStates) throws CatalogException; + + SapsImage getTaskById(String taskId) throws CatalogException, TaskNotFoundException; + + // FIXME: what if the userEmail is null? empty string? (doc it) + SapsUser getUserByEmail(String userEmail) throws CatalogException, UserNotFoundException; + + // FIXME: what if the taskId does not exist in the catalog + void removeStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) + throws CatalogException; + + // FIXME: it may return an empty list, right? doc-it + List filterTasks( + ImageTaskState state, + String region, + Date initDate, + Date endDate, + String inputdownloadingTag, + String preprocessingTag, + String processingTag) + throws CatalogException; } diff --git a/src/main/java/saps/catalog/core/exceptions/CatalogException.java b/src/main/java/saps/catalog/core/exceptions/CatalogException.java index ed3cbf7..847088b 100644 --- a/src/main/java/saps/catalog/core/exceptions/CatalogException.java +++ b/src/main/java/saps/catalog/core/exceptions/CatalogException.java @@ -1,10 +1,11 @@ +/* (C)2020 */ package saps.catalog.core.exceptions; public class CatalogException extends RuntimeException { - private static final long serialVersionUID = -2520888793776997437L; + private static final long serialVersionUID = -2520888793776997437L; - public CatalogException(String msg) { - super(msg); - } + public CatalogException(String msg) { + super(msg); + } } diff --git a/src/main/java/saps/catalog/core/exceptions/TaskNotFoundException.java b/src/main/java/saps/catalog/core/exceptions/TaskNotFoundException.java index 83d0b66..4954107 100644 --- a/src/main/java/saps/catalog/core/exceptions/TaskNotFoundException.java +++ b/src/main/java/saps/catalog/core/exceptions/TaskNotFoundException.java @@ -1,10 +1,11 @@ +/* (C)2020 */ package saps.catalog.core.exceptions; public class TaskNotFoundException extends RuntimeException { - private static final long serialVersionUID = -2520888793776997437L; + private static final long serialVersionUID = -2520888793776997437L; - public TaskNotFoundException(String msg) { - super(msg); - } -} \ No newline at end of file + public TaskNotFoundException(String msg) { + super(msg); + } +} diff --git a/src/main/java/saps/catalog/core/exceptions/UserNotFoundException.java b/src/main/java/saps/catalog/core/exceptions/UserNotFoundException.java index 126960d..a7ebec5 100644 --- a/src/main/java/saps/catalog/core/exceptions/UserNotFoundException.java +++ b/src/main/java/saps/catalog/core/exceptions/UserNotFoundException.java @@ -1,10 +1,11 @@ +/* (C)2020 */ package saps.catalog.core.exceptions; public class UserNotFoundException extends RuntimeException { - private static final long serialVersionUID = -2520888793776997437L; + private static final long serialVersionUID = -2520888793776997437L; - public UserNotFoundException(String msg) { - super(msg); - } + public UserNotFoundException(String msg) { + super(msg); + } } diff --git a/src/main/java/saps/catalog/core/jdbc/JDBCCatalog.java b/src/main/java/saps/catalog/core/jdbc/JDBCCatalog.java index 9d8f1d3..b5fb427 100644 --- a/src/main/java/saps/catalog/core/jdbc/JDBCCatalog.java +++ b/src/main/java/saps/catalog/core/jdbc/JDBCCatalog.java @@ -1,3 +1,4 @@ +/* (C)2020 */ package saps.catalog.core.jdbc; import java.sql.Connection; @@ -9,9 +10,9 @@ import java.util.Date; import java.util.List; import java.util.Properties; - import org.apache.commons.dbcp2.BasicDataSource; import org.apache.log4j.Logger; +import saps.catalog.core.Catalog; import saps.catalog.core.exceptions.CatalogException; import saps.catalog.core.exceptions.TaskNotFoundException; import saps.catalog.core.exceptions.UserNotFoundException; @@ -21,480 +22,535 @@ import saps.common.core.model.enums.ImageTaskState; import saps.common.utils.SapsPropertiesUtil; -import saps.catalog.core.Catalog; - public class JDBCCatalog implements Catalog { - private static final Logger LOGGER = Logger.getLogger(JDBCCatalog.class); - - private final BasicDataSource connectionPool; - - public JDBCCatalog(Properties properties) throws CatalogException { - if (!checkProperties(properties)) - throw new CatalogException("Error on validate the file. Missing properties for start JDBC Catalog."); - - String dbIP = properties.getProperty(JDBCCatalogConstants.Database.IP); - String dbPort = properties.getProperty(JDBCCatalogConstants.Database.PORT); - String dbURLPrefix = properties.getProperty(JDBCCatalogConstants.Database.URL_PREFIX); - String dbUserName = properties.getProperty(JDBCCatalogConstants.Database.USERNAME); - String dbUserPass = properties.getProperty(JDBCCatalogConstants.Database.PASSWORD); - String dbDrive = properties.getProperty(JDBCCatalogConstants.Database.DRIVER); - String dbName = properties.getProperty(JDBCCatalogConstants.Database.NAME); - - LOGGER.info("Creating connection pool for Catalog " + dbIP + ":" + dbPort); - this.connectionPool = createConnectionPool(dbURLPrefix, dbIP, dbPort, dbUserName, dbUserPass, - dbDrive, dbName); - - LOGGER.info("Creating (if not exists) tables for SAPS schema"); - createTable(); - - LOGGER.info("JDBC Catalog class created"); + private static final Logger LOGGER = Logger.getLogger(JDBCCatalog.class); + + private final BasicDataSource connectionPool; + + public JDBCCatalog(Properties properties) throws CatalogException { + if (!checkProperties(properties)) + throw new CatalogException( + "Error on validate the file. Missing properties for start JDBC Catalog."); + + String dbIP = properties.getProperty(JDBCCatalogConstants.Database.IP); + String dbPort = properties.getProperty(JDBCCatalogConstants.Database.PORT); + String dbURLPrefix = properties.getProperty(JDBCCatalogConstants.Database.URL_PREFIX); + String dbUserName = properties.getProperty(JDBCCatalogConstants.Database.USERNAME); + String dbUserPass = properties.getProperty(JDBCCatalogConstants.Database.PASSWORD); + String dbDrive = properties.getProperty(JDBCCatalogConstants.Database.DRIVER); + String dbName = properties.getProperty(JDBCCatalogConstants.Database.NAME); + + LOGGER.info("Creating connection pool for Catalog " + dbIP + ":" + dbPort); + this.connectionPool = + createConnectionPool(dbURLPrefix, dbIP, dbPort, dbUserName, dbUserPass, dbDrive, dbName); + + LOGGER.info("Creating (if not exists) tables for SAPS schema"); + createTable(); + + LOGGER.info("JDBC Catalog class created"); + } + + private boolean checkProperties(Properties properties) { + String[] propertiesSet = { + JDBCCatalogConstants.Database.IP, + JDBCCatalogConstants.Database.USERNAME, + JDBCCatalogConstants.Database.PASSWORD, + JDBCCatalogConstants.Database.DRIVER, + JDBCCatalogConstants.Database.NAME + }; + + return SapsPropertiesUtil.checkProperties(properties, propertiesSet); + } + + private void createTable() throws CatalogException { + + Connection connection = null; + Statement statement = null; + + try { + connection = getConnection(); + statement = connection.createStatement(); + + statement.execute(JDBCCatalogConstants.CreateTable.USERS); + statement.execute(JDBCCatalogConstants.CreateTable.TASKS); + statement.execute(JDBCCatalogConstants.CreateTable.TIMESTAMPS); + statement.execute(JDBCCatalogConstants.CreateTable.NOTIFY); + statement.execute(JDBCCatalogConstants.CreateTable.DEPLOY_CONFIG); + statement.execute(JDBCCatalogConstants.CreateTable.PROVENANCE_DATA); + + statement.close(); + } catch (SQLException e) { + LOGGER.error("Error while initializing DataStore", e); + throw new CatalogException("Error while initializing DataStore"); + } finally { + close(statement, connection); } - - private boolean checkProperties(Properties properties) { - String[] propertiesSet = { - JDBCCatalogConstants.Database.IP, - JDBCCatalogConstants.Database.USERNAME, - JDBCCatalogConstants.Database.PASSWORD, - JDBCCatalogConstants.Database.DRIVER, - JDBCCatalogConstants.Database.NAME - }; - - return SapsPropertiesUtil.checkProperties(properties, propertiesSet); + } + + private BasicDataSource createConnectionPool( + String dbURLPrefix, + String dbIP, + String dbPort, + String dbUserName, + String dbUserPass, + String dbDriver, + String dbName) { + String url = dbURLPrefix + dbIP + ":" + dbPort + "/" + dbName; + + LOGGER.debug("Catalog URL: " + url); + + BasicDataSource pool = new BasicDataSource(); + pool.setUsername(dbUserName); + pool.setPassword(dbUserPass); + pool.setDriverClassName(dbDriver); + pool.setUrl(url); + pool.setInitialSize(1); + + return pool; + } + + public Connection getConnection() throws CatalogException { + try { + return connectionPool.getConnection(); + } catch (SQLException e) { + LOGGER.error("Error while getting a new connection from the connection pool", e); + throw new CatalogException("Error while getting a new connection from the connection pool"); } + } - private void createTable() throws CatalogException { - - Connection connection = null; - Statement statement = null; + protected void close(Statement statement, Connection conn) { + close(statement); - try { - connection = getConnection(); - statement = connection.createStatement(); - - statement.execute(JDBCCatalogConstants.CreateTable.USERS); - statement.execute(JDBCCatalogConstants.CreateTable.TASKS); - statement.execute(JDBCCatalogConstants.CreateTable.TIMESTAMPS); - statement.execute(JDBCCatalogConstants.CreateTable.NOTIFY); - statement.execute(JDBCCatalogConstants.CreateTable.DEPLOY_CONFIG); - statement.execute(JDBCCatalogConstants.CreateTable.PROVENANCE_DATA); - - statement.close(); - } catch (SQLException e) { - LOGGER.error("Error while initializing DataStore", e); - throw new CatalogException("Error while initializing DataStore"); - } finally { - close(statement, connection); + if (conn != null) { + try { + if (!conn.isClosed()) { + conn.close(); } + } catch (SQLException e) { + LOGGER.error("Couldn't close connection", e); + } } + } - private BasicDataSource createConnectionPool(String dbURLPrefix, String dbIP, String dbPort, - String dbUserName, String dbUserPass, String dbDriver, String dbName) { - String url = dbURLPrefix + dbIP + ":" + dbPort + "/" + dbName; - - LOGGER.debug("Catalog URL: " + url); - - BasicDataSource pool = new BasicDataSource(); - pool.setUsername(dbUserName); - pool.setPassword(dbUserPass); - pool.setDriverClassName(dbDriver); - pool.setUrl(url); - pool.setInitialSize(1); - - return pool; - } - - public Connection getConnection() throws CatalogException { - try { - return connectionPool.getConnection(); - } catch (SQLException e) { - LOGGER.error("Error while getting a new connection from the connection pool", e); - throw new CatalogException("Error while getting a new connection from the connection pool"); + private void close(Statement statement) { + if (statement != null) { + try { + if (!statement.isClosed()) { + statement.close(); } + } catch (SQLException e) { + LOGGER.error("Couldn't close statement", e); + } } - - protected void close(Statement statement, Connection conn) { - close(statement); - - if (conn != null) { - try { - if (!conn.isClosed()) { - conn.close(); - } - } catch (SQLException e) { - LOGGER.error("Couldn't close connection", e); - } - } + } + + private java.sql.Date javaDateToSqlDate(Date date) { + return new java.sql.Date(date.getTime()); + } + + @Override + public SapsImage addTask( + String taskId, + String dataset, + String region, + Date date, + int priority, + String user, + String inputdownloadingPhaseTag, + String digestInputdownloading, + String preprocessingPhaseTag, + String digestPreprocessing, + String processingPhaseTag, + String digestProcessing) + throws CatalogException { + Timestamp now = new Timestamp(System.currentTimeMillis()); + SapsImage task = + new SapsImage( + taskId, + dataset, + region, + date, + ImageTaskState.CREATED, + SapsImage.NONE_ARREBOL_JOB_ID, + SapsImage.NONE_FEDERATION_MEMBER, + priority, + user, + inputdownloadingPhaseTag, + digestInputdownloading, + preprocessingPhaseTag, + digestPreprocessing, + processingPhaseTag, + digestProcessing, + now, + now, + SapsImage.AVAILABLE, + SapsImage.NON_EXISTENT_DATA); + + if (task.getTaskId() == null || task.getTaskId().isEmpty()) { + LOGGER.error("Task with empty id."); + throw new IllegalArgumentException("Task with empty id."); } - - private void close(Statement statement) { - if (statement != null) { - try { - if (!statement.isClosed()) { - statement.close(); - } - } catch (SQLException e) { - LOGGER.error("Couldn't close statement", e); - } - } + if (task.getDataset() == null || task.getDataset().isEmpty()) { + LOGGER.error("Task with empty dataset."); + throw new IllegalArgumentException("Task with empty dataset."); } - - private java.sql.Date javaDateToSqlDate(Date date) { - return new java.sql.Date(date.getTime()); + if (task.getImageDate() == null) { + LOGGER.error("Task must have a date."); + throw new IllegalArgumentException("Task must have a date."); } - - @Override - public SapsImage addTask(String taskId, String dataset, String region, Date date, int priority, String user, - String inputdownloadingPhaseTag, String digestInputdownloading, String preprocessingPhaseTag, - String digestPreprocessing, String processingPhaseTag, String digestProcessing) throws CatalogException { - Timestamp now = new Timestamp(System.currentTimeMillis()); - SapsImage task = new SapsImage(taskId, dataset, region, date, ImageTaskState.CREATED, - SapsImage.NONE_ARREBOL_JOB_ID, SapsImage.NONE_FEDERATION_MEMBER, priority, user, - inputdownloadingPhaseTag, digestInputdownloading, preprocessingPhaseTag, digestPreprocessing, - processingPhaseTag, digestProcessing, now, now, SapsImage.AVAILABLE, SapsImage.NON_EXISTENT_DATA); - - if (task.getTaskId() == null || task.getTaskId().isEmpty()) { - LOGGER.error("Task with empty id."); - throw new IllegalArgumentException("Task with empty id."); - } - if (task.getDataset() == null || task.getDataset().isEmpty()) { - LOGGER.error("Task with empty dataset."); - throw new IllegalArgumentException("Task with empty dataset."); - } - if (task.getImageDate() == null) { - LOGGER.error("Task must have a date."); - throw new IllegalArgumentException("Task must have a date."); - } - if (task.getUser() == null || task.getUser().isEmpty()) { - LOGGER.error("Task must have a user."); - throw new IllegalArgumentException("Task must have a user."); - } - - LOGGER.info("Adding image task " + task.getTaskId() + " with priority " + task.getPriority()); - LOGGER.info(task.toString()); - - PreparedStatement insertStatement = null; - Connection connection = null; - - try { - connection = getConnection(); - - insertStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Insert.TASK); - insertStatement.setString(1, task.getTaskId()); - insertStatement.setString(2, task.getDataset()); - insertStatement.setString(3, task.getRegion()); - insertStatement.setDate(4, javaDateToSqlDate(task.getImageDate())); - insertStatement.setString(5, task.getState().getValue()); - insertStatement.setString(6, task.getArrebolJobId()); - insertStatement.setString(7, task.getFederationMember()); - insertStatement.setInt(8, task.getPriority()); - insertStatement.setString(9, task.getUser()); - insertStatement.setString(10, task.getInputdownloadingTag()); - insertStatement.setString(11, task.getDigestInputdownloading()); - insertStatement.setString(12, task.getPreprocessingTag()); - insertStatement.setString(13, task.getDigestPreprocessing()); - insertStatement.setString(14, task.getProcessingTag()); - insertStatement.setString(15, task.getDigestProcessing()); - insertStatement.setTimestamp(16, task.getCreationTime()); - insertStatement.setTimestamp(17, task.getUpdateTime()); - insertStatement.setString(18, task.getStatus()); - insertStatement.setString(19, task.getError()); - insertStatement.setQueryTimeout(300); - - insertStatement.execute(); - } catch (SQLException e) { - throw new CatalogException("Error while insert a new task"); - } finally { - close(insertStatement, connection); - } - - return task; + if (task.getUser() == null || task.getUser().isEmpty()) { + LOGGER.error("Task must have a user."); + throw new IllegalArgumentException("Task must have a user."); } - @Override - public void addStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) throws CatalogException { - if (taskId == null || taskId.isEmpty() || state == null) { - LOGGER.error("Task id or state was null."); - throw new IllegalArgumentException("Task id or state was null."); - } - LOGGER.info("Adding task " + taskId + " state " + state.getValue() + " with timestamp " + timestamp - + " into Catalogue"); - - PreparedStatement insertStatement = null; - Connection connection = null; - - try { - connection = getConnection(); - - insertStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Insert.TIMESTAMP); - insertStatement.setString(1, taskId); - insertStatement.setString(2, state.getValue()); - insertStatement.setQueryTimeout(300); - - insertStatement.execute(); - } catch (SQLException e) { - throw new CatalogException("Error while add a new state change time"); - } finally { - close(insertStatement, connection); - } + LOGGER.info("Adding image task " + task.getTaskId() + " with priority " + task.getPriority()); + LOGGER.info(task.toString()); + + PreparedStatement insertStatement = null; + Connection connection = null; + + try { + connection = getConnection(); + + insertStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Insert.TASK); + insertStatement.setString(1, task.getTaskId()); + insertStatement.setString(2, task.getDataset()); + insertStatement.setString(3, task.getRegion()); + insertStatement.setDate(4, javaDateToSqlDate(task.getImageDate())); + insertStatement.setString(5, task.getState().getValue()); + insertStatement.setString(6, task.getArrebolJobId()); + insertStatement.setString(7, task.getFederationMember()); + insertStatement.setInt(8, task.getPriority()); + insertStatement.setString(9, task.getUser()); + insertStatement.setString(10, task.getInputdownloadingTag()); + insertStatement.setString(11, task.getDigestInputdownloading()); + insertStatement.setString(12, task.getPreprocessingTag()); + insertStatement.setString(13, task.getDigestPreprocessing()); + insertStatement.setString(14, task.getProcessingTag()); + insertStatement.setString(15, task.getDigestProcessing()); + insertStatement.setTimestamp(16, task.getCreationTime()); + insertStatement.setTimestamp(17, task.getUpdateTime()); + insertStatement.setString(18, task.getStatus()); + insertStatement.setString(19, task.getError()); + insertStatement.setQueryTimeout(300); + + insertStatement.execute(); + } catch (SQLException e) { + throw new CatalogException("Error while insert a new task"); + } finally { + close(insertStatement, connection); } - @Override - public void addUser(String userEmail, String userName, String userPass, boolean isEnable, boolean userNotify, - boolean adminRole) throws CatalogException { - - LOGGER.info("Adding user " + userName + " into DB"); - if (userName == null || userName.isEmpty() || userPass == null || userPass.isEmpty()) { - throw new IllegalArgumentException("Unable to create user with empty name or password."); - } + return task; + } - PreparedStatement insertStatement = null; - Connection connection = null; - - try { - connection = getConnection(); - - insertStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Insert.USER); - insertStatement.setString(1, userEmail); - insertStatement.setString(2, userName); - insertStatement.setString(3, userPass); - insertStatement.setBoolean(4, isEnable); - insertStatement.setBoolean(5, userNotify); - insertStatement.setBoolean(6, adminRole); - insertStatement.setQueryTimeout(300); - - insertStatement.execute(); - } catch (SQLException e) { - throw new CatalogException("Error while try add a new user"); - } finally { - close(insertStatement, connection); - } + @Override + public void addStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) + throws CatalogException { + if (taskId == null || taskId.isEmpty() || state == null) { + LOGGER.error("Task id or state was null."); + throw new IllegalArgumentException("Task id or state was null."); + } + LOGGER.info( + "Adding task " + + taskId + + " state " + + state.getValue() + + " with timestamp " + + timestamp + + " into Catalogue"); + + PreparedStatement insertStatement = null; + Connection connection = null; + + try { + connection = getConnection(); + + insertStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Insert.TIMESTAMP); + insertStatement.setString(1, taskId); + insertStatement.setString(2, state.getValue()); + insertStatement.setQueryTimeout(300); + + insertStatement.execute(); + } catch (SQLException e) { + throw new CatalogException("Error while add a new state change time"); + } finally { + close(insertStatement, connection); + } + } + + @Override + public void addUser( + String userEmail, + String userName, + String userPass, + boolean isEnable, + boolean userNotify, + boolean adminRole) + throws CatalogException { + + LOGGER.info("Adding user " + userName + " into DB"); + if (userName == null || userName.isEmpty() || userPass == null || userPass.isEmpty()) { + throw new IllegalArgumentException("Unable to create user with empty name or password."); } - @Override - public void updateImageTask(SapsImage imagetask) throws CatalogException { - if (imagetask == null) { - LOGGER.error("Trying to update null image task."); - throw new IllegalArgumentException("Trying to update null image task."); - } + PreparedStatement insertStatement = null; + Connection connection = null; + + try { + connection = getConnection(); + + insertStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Insert.USER); + insertStatement.setString(1, userEmail); + insertStatement.setString(2, userName); + insertStatement.setString(3, userPass); + insertStatement.setBoolean(4, isEnable); + insertStatement.setBoolean(5, userNotify); + insertStatement.setBoolean(6, adminRole); + insertStatement.setQueryTimeout(300); + + insertStatement.execute(); + } catch (SQLException e) { + throw new CatalogException("Error while try add a new user"); + } finally { + close(insertStatement, connection); + } + } - PreparedStatement updateStatement = null; - Connection connection = null; - - try { - connection = getConnection(); - - updateStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Update.TASK); - updateStatement.setString(1, imagetask.getState().getValue()); - updateStatement.setString(2, imagetask.getStatus()); - updateStatement.setString(3, imagetask.getError()); - updateStatement.setString(4, imagetask.getArrebolJobId()); - updateStatement.setString(5, imagetask.getTaskId()); - updateStatement.setQueryTimeout(300); - - updateStatement.execute(); - } catch (SQLException e) { - throw new CatalogException("Error while try updates task"); - } finally { - close(updateStatement, connection); - } + @Override + public void updateImageTask(SapsImage imagetask) throws CatalogException { + if (imagetask == null) { + LOGGER.error("Trying to update null image task."); + throw new IllegalArgumentException("Trying to update null image task."); } - @Override - public List getAllTasks() throws CatalogException { - Statement statement = null; - Connection conn = null; - try { - conn = getConnection(); - statement = conn.createStatement(); - statement.setQueryTimeout(300); - - statement.execute(JDBCCatalogConstants.Queries.Select.TASKS); - ResultSet rs = statement.getResultSet(); - return JDBCCatalogUtil.extractSapsTasks(rs); - } catch (SQLException e) { - throw new CatalogException("Error while select all tasks"); - } catch (JDBCCatalogException e ) { - throw new CatalogException("Error while extract all tasks"); - } finally { - close(statement, conn); - } + PreparedStatement updateStatement = null; + Connection connection = null; + + try { + connection = getConnection(); + + updateStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Update.TASK); + updateStatement.setString(1, imagetask.getState().getValue()); + updateStatement.setString(2, imagetask.getStatus()); + updateStatement.setString(3, imagetask.getError()); + updateStatement.setString(4, imagetask.getArrebolJobId()); + updateStatement.setString(5, imagetask.getTaskId()); + updateStatement.setQueryTimeout(300); + + updateStatement.execute(); + } catch (SQLException e) { + throw new CatalogException("Error while try updates task"); + } finally { + close(updateStatement, connection); } + } + + @Override + public List getAllTasks() throws CatalogException { + Statement statement = null; + Connection conn = null; + try { + conn = getConnection(); + statement = conn.createStatement(); + statement.setQueryTimeout(300); + + statement.execute(JDBCCatalogConstants.Queries.Select.TASKS); + ResultSet rs = statement.getResultSet(); + return JDBCCatalogUtil.extractSapsTasks(rs); + } catch (SQLException e) { + throw new CatalogException("Error while select all tasks"); + } catch (JDBCCatalogException e) { + throw new CatalogException("Error while extract all tasks"); + } finally { + close(statement, conn); + } + } - @Override - public SapsUser getUserByEmail(String userEmail) throws CatalogException, UserNotFoundException { + @Override + public SapsUser getUserByEmail(String userEmail) throws CatalogException, UserNotFoundException { - if (userEmail == null || userEmail.isEmpty()) { - LOGGER.error("Invalid userEmail " + userEmail); - return null; - } - PreparedStatement selectStatement = null; - Connection connection = null; - - try { - connection = getConnection(); - - selectStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Select.USER); - selectStatement.setString(1, userEmail); - selectStatement.setQueryTimeout(300); - - selectStatement.execute(); - - ResultSet rs = selectStatement.getResultSet(); - if (rs.next()) { - SapsUser sebalUser = JDBCCatalogUtil.extractSapsUser(rs); - return sebalUser; - } - rs.close(); - throw new UserNotFoundException("There is no user with email"); - } catch (SQLException e) { - throw new CatalogException("Error while getting user by email"); - } catch (JDBCCatalogException e ) { - throw new CatalogException("Error while extract user"); - } finally { - close(selectStatement, connection); - } + if (userEmail == null || userEmail.isEmpty()) { + LOGGER.error("Invalid userEmail " + userEmail); + return null; } - - @Override - public List getTasksByState(ImageTaskState... tasksStates) throws CatalogException { - if (tasksStates == null) { - LOGGER.error("A state must be given"); - throw new IllegalArgumentException("Can't recover tasks. State was null."); - } - PreparedStatement selectStatement = null; - Connection connection = null; - try { - connection = getConnection(); - - String query = buildTaskByStateQuery(tasksStates.length); - selectStatement = connection.prepareStatement(query); - selectStatement.setQueryTimeout(300); - - for (int i = 0; i < tasksStates.length; i++) { - selectStatement.setString(i + 1, tasksStates[i].getValue()); - } - - selectStatement.execute(); - - ResultSet rs = selectStatement.getResultSet(); - List imageDatas = JDBCCatalogUtil.extractSapsTasks(rs); - rs.close(); - return imageDatas; - } catch (SQLException e) { - throw new CatalogException("Error while getting task by state"); - } catch (JDBCCatalogException e ) { - throw new CatalogException("Error while extract all tasks"); - } finally { - close(selectStatement, connection); - } + PreparedStatement selectStatement = null; + Connection connection = null; + + try { + connection = getConnection(); + + selectStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Select.USER); + selectStatement.setString(1, userEmail); + selectStatement.setQueryTimeout(300); + + selectStatement.execute(); + + ResultSet rs = selectStatement.getResultSet(); + if (rs.next()) { + SapsUser sebalUser = JDBCCatalogUtil.extractSapsUser(rs); + return sebalUser; + } + rs.close(); + throw new UserNotFoundException("There is no user with email"); + } catch (SQLException e) { + throw new CatalogException("Error while getting user by email"); + } catch (JDBCCatalogException e) { + throw new CatalogException("Error while extract user"); + } finally { + close(selectStatement, connection); } + } - private String buildTaskByStateQuery(int states) { - StringBuilder query = new StringBuilder(JDBCCatalogConstants.Queries.Select.TASKS + " WHERE state in ("); - for(int i = 0; i < states; i++) { - if(i == states - 1) { - query.append("?) "); - } - else { - query.append("?,"); - } - } - query.append("ORDER BY priority asc"); - return query.toString(); + @Override + public List getTasksByState(ImageTaskState... tasksStates) throws CatalogException { + if (tasksStates == null) { + LOGGER.error("A state must be given"); + throw new IllegalArgumentException("Can't recover tasks. State was null."); } + PreparedStatement selectStatement = null; + Connection connection = null; + try { + connection = getConnection(); + + String query = buildTaskByStateQuery(tasksStates.length); + selectStatement = connection.prepareStatement(query); + selectStatement.setQueryTimeout(300); + + for (int i = 0; i < tasksStates.length; i++) { + selectStatement.setString(i + 1, tasksStates[i].getValue()); + } + + selectStatement.execute(); + + ResultSet rs = selectStatement.getResultSet(); + List imageDatas = JDBCCatalogUtil.extractSapsTasks(rs); + rs.close(); + return imageDatas; + } catch (SQLException e) { + throw new CatalogException("Error while getting task by state"); + } catch (JDBCCatalogException e) { + throw new CatalogException("Error while extract all tasks"); + } finally { + close(selectStatement, connection); + } + } + + private String buildTaskByStateQuery(int states) { + StringBuilder query = + new StringBuilder(JDBCCatalogConstants.Queries.Select.TASKS + " WHERE state in ("); + for (int i = 0; i < states; i++) { + if (i == states - 1) { + query.append("?) "); + } else { + query.append("?,"); + } + } + query.append("ORDER BY priority asc"); + return query.toString(); + } + + @Override + public SapsImage getTaskById(String taskId) throws CatalogException, TaskNotFoundException { + if (taskId == null) { + LOGGER.error("Invalid image task " + taskId); + throw new IllegalArgumentException("Invalid image task " + taskId); + } + PreparedStatement selectStatement = null; + Connection connection = null; - @Override - public SapsImage getTaskById(String taskId) throws CatalogException, TaskNotFoundException { - if (taskId == null) { - LOGGER.error("Invalid image task " + taskId); - throw new IllegalArgumentException("Invalid image task " + taskId); - } - PreparedStatement selectStatement = null; - Connection connection = null; - - try { - connection = getConnection(); + try { + connection = getConnection(); - selectStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Select.TASK); - selectStatement.setString(1, taskId); - selectStatement.setQueryTimeout(300); + selectStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Select.TASK); + selectStatement.setString(1, taskId); + selectStatement.setQueryTimeout(300); - selectStatement.execute(); + selectStatement.execute(); - ResultSet rs = selectStatement.getResultSet(); - List imageDatas = JDBCCatalogUtil.extractSapsTasks(rs); + ResultSet rs = selectStatement.getResultSet(); + List imageDatas = JDBCCatalogUtil.extractSapsTasks(rs); - if (imageDatas.size() == 0) - throw new TaskNotFoundException("There is no task with id"); + if (imageDatas.size() == 0) throw new TaskNotFoundException("There is no task with id"); - rs.close(); - return imageDatas.get(0); - } catch (SQLException e) { - throw new CatalogException("Error while getting task by id"); - } catch (JDBCCatalogException e ) { - throw new CatalogException("Error while extract all tasks"); - } finally { - close(selectStatement, connection); - } + rs.close(); + return imageDatas.get(0); + } catch (SQLException e) { + throw new CatalogException("Error while getting task by id"); + } catch (JDBCCatalogException e) { + throw new CatalogException("Error while extract all tasks"); + } finally { + close(selectStatement, connection); } + } - @Override - public void removeStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) throws CatalogException { + @Override + public void removeStateChangeTime(String taskId, ImageTaskState state, Timestamp timestamp) + throws CatalogException { - LOGGER.info("Removing task " + taskId + " state " + state.getValue() + " with timestamp " + timestamp); - if (taskId == null || taskId.isEmpty() || state == null) { - LOGGER.error("Invalid task " + taskId + " or state " + state.getValue()); - throw new IllegalArgumentException("Invalid task " + taskId); - } + LOGGER.info( + "Removing task " + taskId + " state " + state.getValue() + " with timestamp " + timestamp); + if (taskId == null || taskId.isEmpty() || state == null) { + LOGGER.error("Invalid task " + taskId + " or state " + state.getValue()); + throw new IllegalArgumentException("Invalid task " + taskId); + } - PreparedStatement removeStatement = null; - Connection connection = null; + PreparedStatement removeStatement = null; + Connection connection = null; - try { - connection = getConnection(); + try { + connection = getConnection(); - removeStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Delete.TIMESTAMP); - removeStatement.setString(1, taskId); - removeStatement.setString(2, state.getValue()); - removeStatement.setTimestamp(3, timestamp); - removeStatement.setQueryTimeout(300); + removeStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Delete.TIMESTAMP); + removeStatement.setString(1, taskId); + removeStatement.setString(2, state.getValue()); + removeStatement.setTimestamp(3, timestamp); + removeStatement.setQueryTimeout(300); - removeStatement.execute(); - } catch (SQLException e) { - throw new CatalogException("Error while removes state change time"); - } finally { - close(removeStatement, connection); - } + removeStatement.execute(); + } catch (SQLException e) { + throw new CatalogException("Error while removes state change time"); + } finally { + close(removeStatement, connection); } - - @Override - public List filterTasks(ImageTaskState state, String region, Date initDate, Date endDate, String inputGathering, - String preprocessingTag, String processingTag) throws CatalogException { - PreparedStatement queryStatement = null; - Connection connection = null; - - try { - connection = getConnection(); - - queryStatement = connection.prepareStatement(JDBCCatalogConstants.Queries.Select.FILTER_TASKS); - queryStatement.setString(1, state.getValue()); - queryStatement.setString(2, region); - queryStatement.setDate(3, javaDateToSqlDate(initDate)); - queryStatement.setDate(4, javaDateToSqlDate(endDate)); - queryStatement.setString(5, preprocessingTag); - queryStatement.setString(6, inputGathering); - queryStatement.setString(7, processingTag); - queryStatement.setQueryTimeout(300); - - ResultSet result = queryStatement.executeQuery(); - return JDBCCatalogUtil.extractSapsTasks(result); - } catch (SQLException e) { - throw new CatalogException("Error while getting tasks by filters"); - } catch (JDBCCatalogException e ) { - throw new CatalogException("Error while extract all tasks"); - } finally { - close(queryStatement, connection); - } + } + + @Override + public List filterTasks( + ImageTaskState state, + String region, + Date initDate, + Date endDate, + String inputGathering, + String preprocessingTag, + String processingTag) + throws CatalogException { + PreparedStatement queryStatement = null; + Connection connection = null; + + try { + connection = getConnection(); + + queryStatement = + connection.prepareStatement(JDBCCatalogConstants.Queries.Select.FILTER_TASKS); + queryStatement.setString(1, state.getValue()); + queryStatement.setString(2, region); + queryStatement.setDate(3, javaDateToSqlDate(initDate)); + queryStatement.setDate(4, javaDateToSqlDate(endDate)); + queryStatement.setString(5, preprocessingTag); + queryStatement.setString(6, inputGathering); + queryStatement.setString(7, processingTag); + queryStatement.setQueryTimeout(300); + + ResultSet result = queryStatement.executeQuery(); + return JDBCCatalogUtil.extractSapsTasks(result); + } catch (SQLException e) { + throw new CatalogException("Error while getting tasks by filters"); + } catch (JDBCCatalogException e) { + throw new CatalogException("Error while extract all tasks"); + } finally { + close(queryStatement, connection); } + } } diff --git a/src/main/java/saps/catalog/core/jdbc/JDBCCatalogConstants.java b/src/main/java/saps/catalog/core/jdbc/JDBCCatalogConstants.java index 73ae776..5634042 100644 --- a/src/main/java/saps/catalog/core/jdbc/JDBCCatalogConstants.java +++ b/src/main/java/saps/catalog/core/jdbc/JDBCCatalogConstants.java @@ -1,193 +1,326 @@ +/* (C)2020 */ package saps.catalog.core.jdbc; public class JDBCCatalogConstants { - public final class Database { - public static final String USERNAME = "datastore_username"; - public static final String PASSWORD = "datastore_password"; - public static final String DRIVER = "datastore_driver"; - public static final String URL_PREFIX = "datastore_url_prefix"; - public static final String NAME = "datastore_name"; - public static final String IP = "datastore_ip"; - public static final String PORT = "datastore_port"; - } + public final class Database { + public static final String USERNAME = "datastore_username"; + public static final String PASSWORD = "datastore_password"; + public static final String DRIVER = "datastore_driver"; + public static final String URL_PREFIX = "datastore_url_prefix"; + public static final String NAME = "datastore_name"; + public static final String IP = "datastore_ip"; + public static final String PORT = "datastore_port"; + } - public final class TablesName { - public static final String TASKS = "TASKS"; - public static final String TIMESTAMPS = "TIMESTAMPS"; - public static final String USERS = "USERS"; - public static final String NOTIFY = "NOTIFY"; - public static final String DEPLOY_CONFIG = "DEPLOY_CONFIG"; - public static final String PROVENANCE_DATA = "PROVENANCE_DATA"; - } + public final class TablesName { + public static final String TASKS = "TASKS"; + public static final String TIMESTAMPS = "TIMESTAMPS"; + public static final String USERS = "USERS"; + public static final String NOTIFY = "NOTIFY"; + public static final String DEPLOY_CONFIG = "DEPLOY_CONFIG"; + public static final String PROVENANCE_DATA = "PROVENANCE_DATA"; + } - public final class Tables { - public final class Task { - public static final String ID = "task_id"; - public static final String PRIORITY = "priority"; - public static final String FEDERATION_MEMBER = "federation_member"; - public static final String STATE = "state"; - public static final String CREATION_TIME = "creation_time"; - public static final String UPDATED_TIME = "updated_time"; - public static final String STATUS = "status"; - public static final String ERROR_MSG = "error_msg"; - public static final String ARREBOL_JOB_ID = "arrebol_job_id"; - - public final class Image { - public static final String DATASET = "dataset"; - public static final String REGION = "region"; - public static final String DATE = "image_date"; - } - - public final class Algorithms { - public final class Inputdownloading { - public static final String TAG = "inputdownloading_tag"; - public static final String DIGEST = "inputdownloading_digest"; - } - - public final class Preprocessing { - public static final String TAG = "preprocessing_tag"; - public static final String DIGEST = "preprocessing_digest"; - } - - public final class Processing { - public static final String TAG = "processing_tag"; - public static final String DIGEST = "processing_digest"; - } - } - } + public final class Tables { + public final class Task { + public static final String ID = "task_id"; + public static final String PRIORITY = "priority"; + public static final String FEDERATION_MEMBER = "federation_member"; + public static final String STATE = "state"; + public static final String CREATION_TIME = "creation_time"; + public static final String UPDATED_TIME = "updated_time"; + public static final String STATUS = "status"; + public static final String ERROR_MSG = "error_msg"; + public static final String ARREBOL_JOB_ID = "arrebol_job_id"; - public final class User { - public static final String EMAIL = "user_email"; - public static final String NAME = "user_name"; - public static final String PASSWORD = "user_password"; - public static final String ENABLE = "active"; - public static final String NOTIFY = "user_notify"; - public static final String ADMIN_ROLE = "admin_role"; - } + public final class Image { + public static final String DATASET = "dataset"; + public static final String REGION = "region"; + public static final String DATE = "image_date"; + } - public final class Notify { - public static final String SUBMISSION_ID = "submission_id"; + public final class Algorithms { + public final class Inputdownloading { + public static final String TAG = "inputdownloading_tag"; + public static final String DIGEST = "inputdownloading_digest"; } - public final class DeployConfig { - public static final String NFS_SERVER_IP = "nfs_ip"; - public static final String NFS_SERVER_SSH_PORT = "nfs_ssh_port"; - public static final String NFS_SERVER_PORT = "nfs_port"; + public final class Preprocessing { + public static final String TAG = "preprocessing_tag"; + public static final String DIGEST = "preprocessing_digest"; } - public final class ProvenanceData { - public static final String INPUT_METADATA = "input_metadata"; - public static final String INPUT_OPERATING_SYSTEM = "input_operating_system"; - public static final String INPUT_KERNEL_VERSION = "input_kernel_version"; - public static final String PREPROCESSING_METADATA = "preprocessing_metadata"; - public static final String PREPROCESSING_OPERATING_SYSTEM = "preprocessing_operating_system"; - public static final String PREPROCESSING_KERNEL_VERSION = "preprocessing_kernel_version"; - public static final String OUTPUT_METADATA = "output_metadata"; - public static final String OUTPUT_OPERATING_SYSTEM = "output_operating_system"; - public static final String OUTPUT_KERNEL_VERSION = "output_kernel_version"; + public final class Processing { + public static final String TAG = "processing_tag"; + public static final String DIGEST = "processing_digest"; } + } + } + + public final class User { + public static final String EMAIL = "user_email"; + public static final String NAME = "user_name"; + public static final String PASSWORD = "user_password"; + public static final String ENABLE = "active"; + public static final String NOTIFY = "user_notify"; + public static final String ADMIN_ROLE = "admin_role"; } - public final class Queries { + public final class Notify { + public static final String SUBMISSION_ID = "submission_id"; + } + + public final class DeployConfig { + public static final String NFS_SERVER_IP = "nfs_ip"; + public static final String NFS_SERVER_SSH_PORT = "nfs_ssh_port"; + public static final String NFS_SERVER_PORT = "nfs_port"; + } - public final class Insert { - public static final String TASK = "INSERT INTO " + JDBCCatalogConstants.TablesName.TASKS - + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + public final class ProvenanceData { + public static final String INPUT_METADATA = "input_metadata"; + public static final String INPUT_OPERATING_SYSTEM = "input_operating_system"; + public static final String INPUT_KERNEL_VERSION = "input_kernel_version"; + public static final String PREPROCESSING_METADATA = "preprocessing_metadata"; + public static final String PREPROCESSING_OPERATING_SYSTEM = "preprocessing_operating_system"; + public static final String PREPROCESSING_KERNEL_VERSION = "preprocessing_kernel_version"; + public static final String OUTPUT_METADATA = "output_metadata"; + public static final String OUTPUT_OPERATING_SYSTEM = "output_operating_system"; + public static final String OUTPUT_KERNEL_VERSION = "output_kernel_version"; + } + } - public static final String TIMESTAMP = "INSERT INTO " + JDBCCatalogConstants.TablesName.TIMESTAMPS - + " VALUES(?, ?, now())"; + public final class Queries { - public static final String USER = "INSERT INTO " + JDBCCatalogConstants.TablesName.USERS + " VALUES(?, ?, ?, ?, ?, ?)"; - } + public final class Insert { + public static final String TASK = + "INSERT INTO " + + JDBCCatalogConstants.TablesName.TASKS + + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - public final class Update { - public static final String TASK = "UPDATE " + JDBCCatalogConstants.TablesName.TASKS + " SET " + JDBCCatalogConstants.Tables.Task.STATE + " = ?, " - + JDBCCatalogConstants.Tables.Task.UPDATED_TIME + " = now(), " + JDBCCatalogConstants.Tables.Task.STATUS + " = ?, " + JDBCCatalogConstants.Tables.Task.ERROR_MSG + " = ?, " + JDBCCatalogConstants.Tables.Task.ARREBOL_JOB_ID - + " = ? " + "WHERE " + JDBCCatalogConstants.Tables.Task.ID + " = ?"; - } + public static final String TIMESTAMP = + "INSERT INTO " + JDBCCatalogConstants.TablesName.TIMESTAMPS + " VALUES(?, ?, now())"; - public final class Select { - public static final String TASKS = "SELECT * FROM " + JDBCCatalogConstants.TablesName.TASKS; + public static final String USER = + "INSERT INTO " + JDBCCatalogConstants.TablesName.USERS + " VALUES(?, ?, ?, ?, ?, ?)"; + } - public static final String USER = "SELECT * FROM " + JDBCCatalogConstants.TablesName.USERS + " WHERE " + JDBCCatalogConstants.Tables.User.EMAIL - + " = ?"; + public final class Update { + public static final String TASK = + "UPDATE " + + JDBCCatalogConstants.TablesName.TASKS + + " SET " + + JDBCCatalogConstants.Tables.Task.STATE + + " = ?, " + + JDBCCatalogConstants.Tables.Task.UPDATED_TIME + + " = now(), " + + JDBCCatalogConstants.Tables.Task.STATUS + + " = ?, " + + JDBCCatalogConstants.Tables.Task.ERROR_MSG + + " = ?, " + + JDBCCatalogConstants.Tables.Task.ARREBOL_JOB_ID + + " = ? " + + "WHERE " + + JDBCCatalogConstants.Tables.Task.ID + + " = ?"; + } - public static final String TASKS_BY_STATE_ORDER_BY_PRIORITY_ASC = "SELECT * FROM " + JDBCCatalogConstants.TablesName.TASKS + " WHERE " + Tables.Task.STATE + " = ? ORDER BY " - + JDBCCatalogConstants.Tables.Task.PRIORITY + " ASC"; + public final class Select { + public static final String TASKS = "SELECT * FROM " + JDBCCatalogConstants.TablesName.TASKS; - public static final String TASK = "SELECT * FROM " + JDBCCatalogConstants.TablesName.TASKS + " WHERE " + JDBCCatalogConstants.Tables.Task.ID - + " = ?"; + public static final String USER = + "SELECT * FROM " + + JDBCCatalogConstants.TablesName.USERS + + " WHERE " + + JDBCCatalogConstants.Tables.User.EMAIL + + " = ?"; - public static final String FILTER_TASKS = "SELECT * FROM " + JDBCCatalogConstants.TablesName.TASKS + " WHERE " + JDBCCatalogConstants.Tables.Task.STATE - + " = ? AND " + JDBCCatalogConstants.Tables.Task.Image.REGION + " = ? AND " + JDBCCatalogConstants.Tables.Task.Image.DATE + " BETWEEN ? AND ? AND " + JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.TAG - + " = ? AND " + JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.TAG + " = ? AND " + JDBCCatalogConstants.Tables.Task.Algorithms.Processing.TAG + " = ?"; - } + public static final String TASKS_BY_STATE_ORDER_BY_PRIORITY_ASC = + "SELECT * FROM " + + JDBCCatalogConstants.TablesName.TASKS + + " WHERE " + + Tables.Task.STATE + + " = ? ORDER BY " + + JDBCCatalogConstants.Tables.Task.PRIORITY + + " ASC"; - public final class Delete { - public static final String TIMESTAMP = "DELETE FROM " + JDBCCatalogConstants.TablesName.TIMESTAMPS + " WHERE " + JDBCCatalogConstants.Tables.Task.ID - + " = ? AND " + JDBCCatalogConstants.Tables.Task.STATE + " = ? AND " + JDBCCatalogConstants.Tables.Task.UPDATED_TIME + " = ?"; - } + public static final String TASK = + "SELECT * FROM " + + JDBCCatalogConstants.TablesName.TASKS + + " WHERE " + + JDBCCatalogConstants.Tables.Task.ID + + " = ?"; + + public static final String FILTER_TASKS = + "SELECT * FROM " + + JDBCCatalogConstants.TablesName.TASKS + + " WHERE " + + JDBCCatalogConstants.Tables.Task.STATE + + " = ? AND " + + JDBCCatalogConstants.Tables.Task.Image.REGION + + " = ? AND " + + JDBCCatalogConstants.Tables.Task.Image.DATE + + " BETWEEN ? AND ? AND " + + JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.TAG + + " = ? AND " + + JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.TAG + + " = ? AND " + + JDBCCatalogConstants.Tables.Task.Algorithms.Processing.TAG + + " = ?"; } - public final class CreateTable { - public static final String USERS = "CREATE TABLE IF NOT EXISTS " + JDBCCatalogConstants.TablesName.USERS + "(" + - JDBCCatalogConstants.Tables.User.EMAIL + " VARCHAR(255) PRIMARY KEY, " + - JDBCCatalogConstants.Tables.User.NAME + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.User.PASSWORD + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.User.ENABLE + " BOOLEAN, " + - JDBCCatalogConstants.Tables.User.NOTIFY + " BOOLEAN, " + - JDBCCatalogConstants.Tables.User.ADMIN_ROLE + " BOOLEAN )"; - - public static final String TASKS = "CREATE TABLE IF NOT EXISTS " + JDBCCatalogConstants.TablesName.TASKS + "(" + - JDBCCatalogConstants.Tables.Task.ID + " VARCHAR(255) PRIMARY KEY, " + - JDBCCatalogConstants.Tables.Task.Image.DATASET + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.Image.REGION + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.Image.DATE + " DATE, " + - JDBCCatalogConstants.Tables.Task.STATE + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.ARREBOL_JOB_ID + " VARCHAR(100)," + - JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.Task.PRIORITY + " INTEGER, " + - JDBCCatalogConstants.Tables.User.EMAIL + " VARCHAR(255) REFERENCES " + JDBCCatalogConstants.TablesName.USERS + "(" + JDBCCatalogConstants.Tables.User.EMAIL + "), " + - JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.TAG + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.DIGEST + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.TAG + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.DIGEST + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.Task.Algorithms.Processing.TAG + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.Algorithms.Processing.DIGEST + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.Task.CREATION_TIME + " TIMESTAMP, " + - JDBCCatalogConstants.Tables.Task.UPDATED_TIME + " TIMESTAMP, " + - JDBCCatalogConstants.Tables.Task.STATUS + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.Task.ERROR_MSG + " VARCHAR(255) )"; - - public static final String TIMESTAMPS = "CREATE TABLE IF NOT EXISTS " + JDBCCatalogConstants.TablesName.TIMESTAMPS + "(" + - JDBCCatalogConstants.Tables.Task.ID + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.Task.STATE + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.UPDATED_TIME + " TIMESTAMP )"; - - public static final String NOTIFY = "CREATE TABLE IF NOT EXISTS " + JDBCCatalogConstants.TablesName.NOTIFY + "(" + - JDBCCatalogConstants.Tables.Notify.SUBMISSION_ID + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.Task.ID + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.User.EMAIL + " VARCHAR(255), " + - " PRIMARY KEY(" + JDBCCatalogConstants.Tables.Notify.SUBMISSION_ID + ", " + JDBCCatalogConstants.Tables.Task.ID + ", " + JDBCCatalogConstants.Tables.User.EMAIL + ") )"; - - public static final String DEPLOY_CONFIG = "CREATE TABLE IF NOT EXISTS " + JDBCCatalogConstants.TablesName.DEPLOY_CONFIG + "(" + - JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_IP + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_SSH_PORT + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_PORT + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER + " VARCHAR(255), " + - " PRIMARY KEY(" + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_IP + ", " + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_SSH_PORT + ", " + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_PORT + ", " + JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER + ") )"; - - public static final String PROVENANCE_DATA = "CREATE TABLE IF NOT EXISTS " + JDBCCatalogConstants.TablesName.PROVENANCE_DATA + "(" + - JDBCCatalogConstants.Tables.Task.ID + " VARCHAR(255) PRIMARY KEY, " + - JDBCCatalogConstants.Tables.ProvenanceData.INPUT_METADATA + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.ProvenanceData.INPUT_OPERATING_SYSTEM + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.ProvenanceData.INPUT_KERNEL_VERSION + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.ProvenanceData.PREPROCESSING_METADATA + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.ProvenanceData.PREPROCESSING_OPERATING_SYSTEM + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.ProvenanceData.PREPROCESSING_KERNEL_VERSION + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.ProvenanceData.OUTPUT_METADATA + " VARCHAR(255), " + - JDBCCatalogConstants.Tables.ProvenanceData.OUTPUT_OPERATING_SYSTEM + " VARCHAR(100), " + - JDBCCatalogConstants.Tables.ProvenanceData.OUTPUT_KERNEL_VERSION + " VARCHAR(100) )"; + public final class Delete { + public static final String TIMESTAMP = + "DELETE FROM " + + JDBCCatalogConstants.TablesName.TIMESTAMPS + + " WHERE " + + JDBCCatalogConstants.Tables.Task.ID + + " = ? AND " + + JDBCCatalogConstants.Tables.Task.STATE + + " = ? AND " + + JDBCCatalogConstants.Tables.Task.UPDATED_TIME + + " = ?"; } -} + } + public final class CreateTable { + public static final String USERS = + "CREATE TABLE IF NOT EXISTS " + + JDBCCatalogConstants.TablesName.USERS + + "(" + + JDBCCatalogConstants.Tables.User.EMAIL + + " VARCHAR(255) PRIMARY KEY, " + + JDBCCatalogConstants.Tables.User.NAME + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.User.PASSWORD + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.User.ENABLE + + " BOOLEAN, " + + JDBCCatalogConstants.Tables.User.NOTIFY + + " BOOLEAN, " + + JDBCCatalogConstants.Tables.User.ADMIN_ROLE + + " BOOLEAN )"; + + public static final String TASKS = + "CREATE TABLE IF NOT EXISTS " + + JDBCCatalogConstants.TablesName.TASKS + + "(" + + JDBCCatalogConstants.Tables.Task.ID + + " VARCHAR(255) PRIMARY KEY, " + + JDBCCatalogConstants.Tables.Task.Image.DATASET + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.Image.REGION + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.Image.DATE + + " DATE, " + + JDBCCatalogConstants.Tables.Task.STATE + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.ARREBOL_JOB_ID + + " VARCHAR(100)," + + JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.Task.PRIORITY + + " INTEGER, " + + JDBCCatalogConstants.Tables.User.EMAIL + + " VARCHAR(255) REFERENCES " + + JDBCCatalogConstants.TablesName.USERS + + "(" + + JDBCCatalogConstants.Tables.User.EMAIL + + "), " + + JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.TAG + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.DIGEST + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.TAG + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.DIGEST + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.Task.Algorithms.Processing.TAG + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.Algorithms.Processing.DIGEST + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.Task.CREATION_TIME + + " TIMESTAMP, " + + JDBCCatalogConstants.Tables.Task.UPDATED_TIME + + " TIMESTAMP, " + + JDBCCatalogConstants.Tables.Task.STATUS + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.Task.ERROR_MSG + + " VARCHAR(255) )"; + + public static final String TIMESTAMPS = + "CREATE TABLE IF NOT EXISTS " + + JDBCCatalogConstants.TablesName.TIMESTAMPS + + "(" + + JDBCCatalogConstants.Tables.Task.ID + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.Task.STATE + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.UPDATED_TIME + + " TIMESTAMP )"; + + public static final String NOTIFY = + "CREATE TABLE IF NOT EXISTS " + + JDBCCatalogConstants.TablesName.NOTIFY + + "(" + + JDBCCatalogConstants.Tables.Notify.SUBMISSION_ID + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.Task.ID + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.User.EMAIL + + " VARCHAR(255), " + + " PRIMARY KEY(" + + JDBCCatalogConstants.Tables.Notify.SUBMISSION_ID + + ", " + + JDBCCatalogConstants.Tables.Task.ID + + ", " + + JDBCCatalogConstants.Tables.User.EMAIL + + ") )"; + + public static final String DEPLOY_CONFIG = + "CREATE TABLE IF NOT EXISTS " + + JDBCCatalogConstants.TablesName.DEPLOY_CONFIG + + "(" + + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_IP + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_SSH_PORT + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_PORT + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER + + " VARCHAR(255), " + + " PRIMARY KEY(" + + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_IP + + ", " + + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_SSH_PORT + + ", " + + JDBCCatalogConstants.Tables.DeployConfig.NFS_SERVER_PORT + + ", " + + JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER + + ") )"; + + public static final String PROVENANCE_DATA = + "CREATE TABLE IF NOT EXISTS " + + JDBCCatalogConstants.TablesName.PROVENANCE_DATA + + "(" + + JDBCCatalogConstants.Tables.Task.ID + + " VARCHAR(255) PRIMARY KEY, " + + JDBCCatalogConstants.Tables.ProvenanceData.INPUT_METADATA + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.ProvenanceData.INPUT_OPERATING_SYSTEM + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.ProvenanceData.INPUT_KERNEL_VERSION + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.ProvenanceData.PREPROCESSING_METADATA + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.ProvenanceData.PREPROCESSING_OPERATING_SYSTEM + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.ProvenanceData.PREPROCESSING_KERNEL_VERSION + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.ProvenanceData.OUTPUT_METADATA + + " VARCHAR(255), " + + JDBCCatalogConstants.Tables.ProvenanceData.OUTPUT_OPERATING_SYSTEM + + " VARCHAR(100), " + + JDBCCatalogConstants.Tables.ProvenanceData.OUTPUT_KERNEL_VERSION + + " VARCHAR(100) )"; + } +} diff --git a/src/main/java/saps/catalog/core/jdbc/JDBCCatalogUtil.java b/src/main/java/saps/catalog/core/jdbc/JDBCCatalogUtil.java index 61ee131..16c8090 100644 --- a/src/main/java/saps/catalog/core/jdbc/JDBCCatalogUtil.java +++ b/src/main/java/saps/catalog/core/jdbc/JDBCCatalogUtil.java @@ -1,47 +1,66 @@ +/* (C)2020 */ package saps.catalog.core.jdbc; -import saps.catalog.core.jdbc.exceptions.JDBCCatalogException; -import saps.common.core.model.SapsImage; -import saps.common.core.model.SapsUser; -import saps.common.core.model.enums.ImageTaskState; - import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import saps.catalog.core.jdbc.exceptions.JDBCCatalogException; +import saps.common.core.model.SapsImage; +import saps.common.core.model.SapsUser; +import saps.common.core.model.enums.ImageTaskState; public class JDBCCatalogUtil { - public static SapsUser extractSapsUser(ResultSet rs) throws JDBCCatalogException { - SapsUser sebalUser = null; - try { - sebalUser = new SapsUser(rs.getString(JDBCCatalogConstants.Tables.User.EMAIL), rs.getString(JDBCCatalogConstants.Tables.User.NAME), - rs.getString(JDBCCatalogConstants.Tables.User.PASSWORD), rs.getBoolean(JDBCCatalogConstants.Tables.User.ENABLE), rs.getBoolean(JDBCCatalogConstants.Tables.User.NOTIFY), - rs.getBoolean(JDBCCatalogConstants.Tables.User.ADMIN_ROLE)); - } catch (SQLException e) { - throw new JDBCCatalogException("Error while extract user", e); - } - - return sebalUser; + public static SapsUser extractSapsUser(ResultSet rs) throws JDBCCatalogException { + SapsUser sebalUser = null; + try { + sebalUser = + new SapsUser( + rs.getString(JDBCCatalogConstants.Tables.User.EMAIL), + rs.getString(JDBCCatalogConstants.Tables.User.NAME), + rs.getString(JDBCCatalogConstants.Tables.User.PASSWORD), + rs.getBoolean(JDBCCatalogConstants.Tables.User.ENABLE), + rs.getBoolean(JDBCCatalogConstants.Tables.User.NOTIFY), + rs.getBoolean(JDBCCatalogConstants.Tables.User.ADMIN_ROLE)); + } catch (SQLException e) { + throw new JDBCCatalogException("Error while extract user", e); } - public static List extractSapsTasks(ResultSet rs) throws JDBCCatalogException { - List imageTasks = new ArrayList<>(); - while (true) { - try { - if (!rs.next()) break; - imageTasks.add(new SapsImage(rs.getString(JDBCCatalogConstants.Tables.Task.ID), rs.getString(JDBCCatalogConstants.Tables.Task.Image.DATASET), rs.getString(JDBCCatalogConstants.Tables.Task.Image.REGION), - rs.getDate(JDBCCatalogConstants.Tables.Task.Image.DATE), ImageTaskState.getStateFromStr(rs.getString(JDBCCatalogConstants.Tables.Task.STATE)), - rs.getString(JDBCCatalogConstants.Tables.Task.ARREBOL_JOB_ID), rs.getString(JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER), rs.getInt(JDBCCatalogConstants.Tables.Task.PRIORITY), - rs.getString(JDBCCatalogConstants.Tables.User.EMAIL), rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.TAG), - rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.DIGEST), rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.TAG), - rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.DIGEST), rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Processing.TAG), rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Processing.DIGEST), - rs.getTimestamp(JDBCCatalogConstants.Tables.Task.CREATION_TIME), rs.getTimestamp(JDBCCatalogConstants.Tables.Task.UPDATED_TIME), - rs.getString(JDBCCatalogConstants.Tables.Task.STATUS), rs.getString(JDBCCatalogConstants.Tables.Task.ERROR_MSG))); - } catch (SQLException e) { - throw new JDBCCatalogException("Error while extract task", e); - } - } - return imageTasks; + return sebalUser; + } + + public static List extractSapsTasks(ResultSet rs) throws JDBCCatalogException { + List imageTasks = new ArrayList<>(); + while (true) { + try { + if (!rs.next()) break; + imageTasks.add( + new SapsImage( + rs.getString(JDBCCatalogConstants.Tables.Task.ID), + rs.getString(JDBCCatalogConstants.Tables.Task.Image.DATASET), + rs.getString(JDBCCatalogConstants.Tables.Task.Image.REGION), + rs.getDate(JDBCCatalogConstants.Tables.Task.Image.DATE), + ImageTaskState.getStateFromStr( + rs.getString(JDBCCatalogConstants.Tables.Task.STATE)), + rs.getString(JDBCCatalogConstants.Tables.Task.ARREBOL_JOB_ID), + rs.getString(JDBCCatalogConstants.Tables.Task.FEDERATION_MEMBER), + rs.getInt(JDBCCatalogConstants.Tables.Task.PRIORITY), + rs.getString(JDBCCatalogConstants.Tables.User.EMAIL), + rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.TAG), + rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Inputdownloading.DIGEST), + rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.TAG), + rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Preprocessing.DIGEST), + rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Processing.TAG), + rs.getString(JDBCCatalogConstants.Tables.Task.Algorithms.Processing.DIGEST), + rs.getTimestamp(JDBCCatalogConstants.Tables.Task.CREATION_TIME), + rs.getTimestamp(JDBCCatalogConstants.Tables.Task.UPDATED_TIME), + rs.getString(JDBCCatalogConstants.Tables.Task.STATUS), + rs.getString(JDBCCatalogConstants.Tables.Task.ERROR_MSG))); + } catch (SQLException e) { + throw new JDBCCatalogException("Error while extract task", e); + } } + return imageTasks; + } } diff --git a/src/main/java/saps/catalog/core/jdbc/exceptions/JDBCCatalogException.java b/src/main/java/saps/catalog/core/jdbc/exceptions/JDBCCatalogException.java index c2193b2..73eab3b 100644 --- a/src/main/java/saps/catalog/core/jdbc/exceptions/JDBCCatalogException.java +++ b/src/main/java/saps/catalog/core/jdbc/exceptions/JDBCCatalogException.java @@ -1,11 +1,12 @@ +/* (C)2020 */ package saps.catalog.core.jdbc.exceptions; -//FIXME Remove this class +// FIXME Remove this class public class JDBCCatalogException extends Exception { - private static final long serialVersionUID = -2520888793776997437L; + private static final long serialVersionUID = -2520888793776997437L; - public JDBCCatalogException(String msg, Exception e) { - super(msg, e); - } + public JDBCCatalogException(String msg, Exception e) { + super(msg, e); + } } diff --git a/src/main/java/saps/catalog/core/retry/CatalogUtils.java b/src/main/java/saps/catalog/core/retry/CatalogUtils.java index ff849c4..2f70316 100644 --- a/src/main/java/saps/catalog/core/retry/CatalogUtils.java +++ b/src/main/java/saps/catalog/core/retry/CatalogUtils.java @@ -1,14 +1,13 @@ +/* (C)2020 */ package saps.catalog.core.retry; import java.util.Date; import java.util.List; - import org.apache.log4j.Logger; -import saps.common.core.model.SapsImage; -import saps.common.core.model.SapsUser; -import saps.common.core.model.enums.ImageTaskState; +import saps.catalog.core.Catalog; import saps.catalog.core.retry.catalog.AddNewTask; import saps.catalog.core.retry.catalog.AddNewUser; +import saps.catalog.core.retry.catalog.AddTimestampRetry; import saps.catalog.core.retry.catalog.CatalogRetry; import saps.catalog.core.retry.catalog.GetAllTasks; import saps.catalog.core.retry.catalog.GetProcessedTasks; @@ -17,185 +16,244 @@ import saps.catalog.core.retry.catalog.GetTasksRetry; import saps.catalog.core.retry.catalog.GetUser; import saps.catalog.core.retry.catalog.UpdateTaskRetry; -import saps.catalog.core.retry.catalog.AddTimestampRetry; import saps.catalog.core.retry.catalog.exceptions.CatalogRetryException; - -import saps.catalog.core.Catalog; +import saps.common.core.model.SapsImage; +import saps.common.core.model.SapsUser; +import saps.common.core.model.enums.ImageTaskState; public class CatalogUtils { - private static final Logger LOGGER = Logger.getLogger(CatalogUtils.class); - private static final int CATALOG_DEFAULT_SLEEP_SECONDS = 5; - - /** - * This function tries countless times to successfully execute the passed - * function. - * - * @param Return type - * @param function Function passed for execute - * @param sleepInSeconds Time sleep in seconds (case fail) - * @param message Information message about function passed - * @return Function return - */ - @SuppressWarnings("unchecked") - private static T retry(CatalogRetry function, int sleepInSeconds, String message) { - LOGGER.info( - "[Retry Catalog function] Trying " + message + " using " + sleepInSeconds + " seconds with time sleep"); - - while (true) { - try { - return (T) function.run(); - } catch (CatalogRetryException e) { - LOGGER.error("Failed while " + message, e); - } - - try { - LOGGER.info("Sleeping for " + sleepInSeconds + " seconds"); - Thread.sleep(Long.valueOf(sleepInSeconds) * 1000); - } catch (InterruptedException e) { - LOGGER.error("Failed while " + message, e); - } - } - } - - /** - * This function gets tasks in specific state in Catalog. - * - * @param imageStore catalog component - * @param state specific state for get tasks - * @return tasks in specific state - */ - public static List getTasks(Catalog imageStore, ImageTaskState state) { - return retry(new GetTasksRetry(imageStore, state), CATALOG_DEFAULT_SLEEP_SECONDS, - "gets tasks with " + state.getValue() + " state"); - } - - /** - * This function updates task state in catalog component. - * - * @param imageStore catalog component - * @param task task to be updated - * @return boolean representation reporting success (true) or failure (false) in - * update state task in catalog - */ - public static boolean updateState(Catalog imageStore, SapsImage task) { - return retry(new UpdateTaskRetry(imageStore, task), CATALOG_DEFAULT_SLEEP_SECONDS, - "update task [" + task.getTaskId() + " state]"); - } - - /** - * This function gets tasks in processing state in catalog component. - * - * @param imageStore catalog component - * @param message information message - * @return processing tasks list - */ - public static List getProcessingTasks(Catalog imageStore, String message) { - return retry(new GetProcessingTasksRetry(imageStore), CATALOG_DEFAULT_SLEEP_SECONDS, message); - } - - /** - * This function add new tuple in time stamp table and updates task time stamp. - * @param imageStore catalog component - * @param task task to be update - */ - public static void addTimestampTask(Catalog imageStore, SapsImage task) { - retry(new AddTimestampRetry(imageStore, task), CATALOG_DEFAULT_SLEEP_SECONDS, - "add timestamp to task [" + task.getTaskId() + "]"); - } - - /** - * This function adds new user. - * - * @param imageStore catalog component - * @param userEmail user email - * @param userName user name - * @param userPass user password - * @param userState user state - * @param userNotify user notify - * @param adminRole administrator role - * @param message information message - */ - public static void addNewUser(Catalog imageStore, String userEmail, String userName, String userPass, - boolean userState, boolean userNotify, boolean adminRole, String message) { - retry(new AddNewUser(imageStore, userEmail, userName, userPass, userState, userNotify, adminRole), - CATALOG_DEFAULT_SLEEP_SECONDS, message); - } - - /** - * This function gets user information. - * - * @param imageStore catalog component - * @param userEmail user email - * @param message information message - */ - public static SapsUser getUser(Catalog imageStore, String userEmail, String message) { - return retry(new GetUser(imageStore, userEmail), CATALOG_DEFAULT_SLEEP_SECONDS, message); - } - - /** - * This function adds new task. - * - * @param imageStore catalog component - * @param taskId task id - * @param dataset task dataset - * @param region task region - * @param date task region - * @param priority task priority - * @param userEmail user email that is creating task - * @param inputdownloadingPhaseTag inputdownloading phase tag - * @param preprocessingPhaseTag preprocessing phase tag - * @param processingPhaseTag processing phase tag - * @param message information message - * @return new SAPS image - */ - public static SapsImage addNewTask(Catalog imageStore, String taskId, String dataset, String region, - Date date, int priority, String userEmail, String inputdownloadingPhaseTag, String digestInputdownloading, - String preprocessingPhaseTag, String digestPreprocessing, String processingPhaseTag, - String digestProcessing, String message) { - return retry(new AddNewTask(imageStore, taskId, dataset, region, date, priority, userEmail, - inputdownloadingPhaseTag, digestInputdownloading, preprocessingPhaseTag, digestPreprocessing, - processingPhaseTag, digestProcessing), CATALOG_DEFAULT_SLEEP_SECONDS, message); - } - - /** - * This function gets a specific task with id. - * - * @param taskId task id to be searched - * @return SAPS image with task id informed - */ - public static SapsImage getTaskById(Catalog imageStore, String taskId, String message) { - return retry(new GetTaskById(imageStore, taskId), CATALOG_DEFAULT_SLEEP_SECONDS, message); - } - - /** - * This function gets archived task. - * - * @param imageStore catalog component - * @param region task region - * @param initDate initial date - * @param endDate end date - * @param inputdownloadingPhaseTag inputdownloading phase tag - * @param preprocessingPhaseTag preprocessing phase tag - * @param processingPhaseTag processing phase tag - * @param message information message - * @return SAPS image list with archived state - */ - public static List getProcessedTasks(Catalog imageStore, String region, Date initDate, - Date endDate, String inputdownloadingPhaseTag, String preprocessingPhaseTag, String processingPhaseTag, - String message) { - - return retry(new GetProcessedTasks(imageStore, region, initDate, endDate, inputdownloadingPhaseTag, - preprocessingPhaseTag, processingPhaseTag), CATALOG_DEFAULT_SLEEP_SECONDS, message); - } - - /** - * This function get all tasks. - * - * @param imageStore catalog component - * @return SAPS image list - */ - public static List getAllTasks(Catalog imageStore, String message) { - return retry(new GetAllTasks(imageStore), CATALOG_DEFAULT_SLEEP_SECONDS, message); - } + private static final Logger LOGGER = Logger.getLogger(CatalogUtils.class); + private static final int CATALOG_DEFAULT_SLEEP_SECONDS = 5; + + /** + * This function tries countless times to successfully execute the passed function. + * + * @param Return type + * @param function Function passed for execute + * @param sleepInSeconds Time sleep in seconds (case fail) + * @param message Information message about function passed + * @return Function return + */ + @SuppressWarnings("unchecked") + private static T retry(CatalogRetry function, int sleepInSeconds, String message) { + LOGGER.info( + "[Retry Catalog function] Trying " + + message + + " using " + + sleepInSeconds + + " seconds with time sleep"); + + while (true) { + try { + return (T) function.run(); + } catch (CatalogRetryException e) { + LOGGER.error("Failed while " + message, e); + } + + try { + LOGGER.info("Sleeping for " + sleepInSeconds + " seconds"); + Thread.sleep(Long.valueOf(sleepInSeconds) * 1000); + } catch (InterruptedException e) { + LOGGER.error("Failed while " + message, e); + } + } + } + + /** + * This function gets tasks in specific state in Catalog. + * + * @param imageStore catalog component + * @param state specific state for get tasks + * @return tasks in specific state + */ + public static List getTasks(Catalog imageStore, ImageTaskState state) { + return retry( + new GetTasksRetry(imageStore, state), + CATALOG_DEFAULT_SLEEP_SECONDS, + "gets tasks with " + state.getValue() + " state"); + } + + /** + * This function updates task state in catalog component. + * + * @param imageStore catalog component + * @param task task to be updated + * @return boolean representation reporting success (true) or failure (false) in update state task + * in catalog + */ + public static boolean updateState(Catalog imageStore, SapsImage task) { + return retry( + new UpdateTaskRetry(imageStore, task), + CATALOG_DEFAULT_SLEEP_SECONDS, + "update task [" + task.getTaskId() + " state]"); + } + + /** + * This function gets tasks in processing state in catalog component. + * + * @param imageStore catalog component + * @param message information message + * @return processing tasks list + */ + public static List getProcessingTasks(Catalog imageStore, String message) { + return retry(new GetProcessingTasksRetry(imageStore), CATALOG_DEFAULT_SLEEP_SECONDS, message); + } + + /** + * This function add new tuple in time stamp table and updates task time stamp. + * + * @param imageStore catalog component + * @param task task to be update + */ + public static void addTimestampTask(Catalog imageStore, SapsImage task) { + retry( + new AddTimestampRetry(imageStore, task), + CATALOG_DEFAULT_SLEEP_SECONDS, + "add timestamp to task [" + task.getTaskId() + "]"); + } + + /** + * This function adds new user. + * + * @param imageStore catalog component + * @param userEmail user email + * @param userName user name + * @param userPass user password + * @param userState user state + * @param userNotify user notify + * @param adminRole administrator role + * @param message information message + */ + public static void addNewUser( + Catalog imageStore, + String userEmail, + String userName, + String userPass, + boolean userState, + boolean userNotify, + boolean adminRole, + String message) { + retry( + new AddNewUser(imageStore, userEmail, userName, userPass, userState, userNotify, adminRole), + CATALOG_DEFAULT_SLEEP_SECONDS, + message); + } + + /** + * This function gets user information. + * + * @param imageStore catalog component + * @param userEmail user email + * @param message information message + */ + public static SapsUser getUser(Catalog imageStore, String userEmail, String message) { + return retry(new GetUser(imageStore, userEmail), CATALOG_DEFAULT_SLEEP_SECONDS, message); + } + + /** + * This function adds new task. + * + * @param imageStore catalog component + * @param taskId task id + * @param dataset task dataset + * @param region task region + * @param date task region + * @param priority task priority + * @param userEmail user email that is creating task + * @param inputdownloadingPhaseTag inputdownloading phase tag + * @param preprocessingPhaseTag preprocessing phase tag + * @param processingPhaseTag processing phase tag + * @param message information message + * @return new SAPS image + */ + public static SapsImage addNewTask( + Catalog imageStore, + String taskId, + String dataset, + String region, + Date date, + int priority, + String userEmail, + String inputdownloadingPhaseTag, + String digestInputdownloading, + String preprocessingPhaseTag, + String digestPreprocessing, + String processingPhaseTag, + String digestProcessing, + String message) { + return retry( + new AddNewTask( + imageStore, + taskId, + dataset, + region, + date, + priority, + userEmail, + inputdownloadingPhaseTag, + digestInputdownloading, + preprocessingPhaseTag, + digestPreprocessing, + processingPhaseTag, + digestProcessing), + CATALOG_DEFAULT_SLEEP_SECONDS, + message); + } + + /** + * This function gets a specific task with id. + * + * @param taskId task id to be searched + * @return SAPS image with task id informed + */ + public static SapsImage getTaskById(Catalog imageStore, String taskId, String message) { + return retry(new GetTaskById(imageStore, taskId), CATALOG_DEFAULT_SLEEP_SECONDS, message); + } + + /** + * This function gets archived task. + * + * @param imageStore catalog component + * @param region task region + * @param initDate initial date + * @param endDate end date + * @param inputdownloadingPhaseTag inputdownloading phase tag + * @param preprocessingPhaseTag preprocessing phase tag + * @param processingPhaseTag processing phase tag + * @param message information message + * @return SAPS image list with archived state + */ + public static List getProcessedTasks( + Catalog imageStore, + String region, + Date initDate, + Date endDate, + String inputdownloadingPhaseTag, + String preprocessingPhaseTag, + String processingPhaseTag, + String message) { + + return retry( + new GetProcessedTasks( + imageStore, + region, + initDate, + endDate, + inputdownloadingPhaseTag, + preprocessingPhaseTag, + processingPhaseTag), + CATALOG_DEFAULT_SLEEP_SECONDS, + message); + } + + /** + * This function get all tasks. + * + * @param imageStore catalog component + * @return SAPS image list + */ + public static List getAllTasks(Catalog imageStore, String message) { + return retry(new GetAllTasks(imageStore), CATALOG_DEFAULT_SLEEP_SECONDS, message); + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/AddNewTask.java b/src/main/java/saps/catalog/core/retry/catalog/AddNewTask.java index deb8e77..e8c4f51 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/AddNewTask.java +++ b/src/main/java/saps/catalog/core/retry/catalog/AddNewTask.java @@ -1,51 +1,69 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import java.util.Date; - -import saps.common.core.model.SapsImage; - import saps.catalog.core.Catalog; +import saps.common.core.model.SapsImage; public class AddNewTask implements CatalogRetry { - private Catalog imageStore; - private String taskId; - private String dataset; - private String region; - private Date date; - private int priority; - private String userEmail; - private String inputdownloadingPhaseTag; - private String digestInputdownloading; - private String preprocessingPhaseTag; - private String digestPreprocessing; - private String processingPhaseTag; - private String digestProcessing; - - public AddNewTask(Catalog imageStore, String taskId, String dataset, String region, Date date, int priority, - String userEmail, String inputdownloadingPhaseTag, String digestInputdownloading, - String preprocessingPhaseTag, String digestPreprocessing, String processingPhaseTag, - String digestProcessing) { - this.imageStore = imageStore; - this.taskId = taskId; - this.dataset = dataset; - this.region = region; - this.date = date; - this.priority = priority; - this.userEmail = userEmail; - this.inputdownloadingPhaseTag = inputdownloadingPhaseTag; - this.digestInputdownloading = digestInputdownloading; - this.preprocessingPhaseTag = preprocessingPhaseTag; - this.digestPreprocessing = digestPreprocessing; - this.processingPhaseTag = processingPhaseTag; - this.digestProcessing = digestProcessing; - } + private Catalog imageStore; + private String taskId; + private String dataset; + private String region; + private Date date; + private int priority; + private String userEmail; + private String inputdownloadingPhaseTag; + private String digestInputdownloading; + private String preprocessingPhaseTag; + private String digestPreprocessing; + private String processingPhaseTag; + private String digestProcessing; - @Override - public SapsImage run(){ - return imageStore.addTask(taskId, dataset, region, date, priority, userEmail, inputdownloadingPhaseTag, - digestInputdownloading, preprocessingPhaseTag, digestPreprocessing, processingPhaseTag, - digestProcessing); - } + public AddNewTask( + Catalog imageStore, + String taskId, + String dataset, + String region, + Date date, + int priority, + String userEmail, + String inputdownloadingPhaseTag, + String digestInputdownloading, + String preprocessingPhaseTag, + String digestPreprocessing, + String processingPhaseTag, + String digestProcessing) { + this.imageStore = imageStore; + this.taskId = taskId; + this.dataset = dataset; + this.region = region; + this.date = date; + this.priority = priority; + this.userEmail = userEmail; + this.inputdownloadingPhaseTag = inputdownloadingPhaseTag; + this.digestInputdownloading = digestInputdownloading; + this.preprocessingPhaseTag = preprocessingPhaseTag; + this.digestPreprocessing = digestPreprocessing; + this.processingPhaseTag = processingPhaseTag; + this.digestProcessing = digestProcessing; + } + @Override + public SapsImage run() { + return imageStore.addTask( + taskId, + dataset, + region, + date, + priority, + userEmail, + inputdownloadingPhaseTag, + digestInputdownloading, + preprocessingPhaseTag, + digestPreprocessing, + processingPhaseTag, + digestProcessing); + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/AddNewUser.java b/src/main/java/saps/catalog/core/retry/catalog/AddNewUser.java index 84d70fb..89c4bfc 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/AddNewUser.java +++ b/src/main/java/saps/catalog/core/retry/catalog/AddNewUser.java @@ -1,32 +1,38 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import saps.catalog.core.Catalog; public class AddNewUser implements CatalogRetry { - private Catalog imageStore; - private String userEmail; - private String userName; - private String userPass; - private boolean isEnable; - private boolean userNotify; - private boolean adminRole; + private Catalog imageStore; + private String userEmail; + private String userName; + private String userPass; + private boolean isEnable; + private boolean userNotify; + private boolean adminRole; - public AddNewUser(Catalog imageStore, String userEmail, String userName, String userPass, boolean isEnable, - boolean userNotify, boolean adminRole) { - this.imageStore = imageStore; - this.userEmail = userEmail; - this.userName = userName; - this.userPass = userPass; - this.isEnable = isEnable; - this.userNotify = userNotify; - this.adminRole = adminRole; - } - - @Override - public Void run(){ - imageStore.addUser(userEmail, userName, userPass, isEnable, userNotify, adminRole); - return null; - } + public AddNewUser( + Catalog imageStore, + String userEmail, + String userName, + String userPass, + boolean isEnable, + boolean userNotify, + boolean adminRole) { + this.imageStore = imageStore; + this.userEmail = userEmail; + this.userName = userName; + this.userPass = userPass; + this.isEnable = isEnable; + this.userNotify = userNotify; + this.adminRole = adminRole; + } + @Override + public Void run() { + imageStore.addUser(userEmail, userName, userPass, isEnable, userNotify, adminRole); + return null; + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/AddTimestampRetry.java b/src/main/java/saps/catalog/core/retry/catalog/AddTimestampRetry.java index aa4cda0..cd7dd89 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/AddTimestampRetry.java +++ b/src/main/java/saps/catalog/core/retry/catalog/AddTimestampRetry.java @@ -1,25 +1,23 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; -import saps.common.core.model.SapsImage; - import saps.catalog.core.Catalog; +import saps.common.core.model.SapsImage; -public class AddTimestampRetry implements CatalogRetry{ +public class AddTimestampRetry implements CatalogRetry { - private Catalog imageStore; - private SapsImage task; + private Catalog imageStore; + private SapsImage task; - public AddTimestampRetry(Catalog imageStore, SapsImage task) { - this.imageStore = imageStore; - this.task = task; - } - - @Override - public Void run(){ - task.setUpdateTime(imageStore.getTaskById(task.getTaskId()).getUpdateTime()); - imageStore.addStateChangeTime(task.getTaskId(), task.getState(), task.getUpdateTime()); - return null; - } - + public AddTimestampRetry(Catalog imageStore, SapsImage task) { + this.imageStore = imageStore; + this.task = task; + } + @Override + public Void run() { + task.setUpdateTime(imageStore.getTaskById(task.getTaskId()).getUpdateTime()); + imageStore.addStateChangeTime(task.getTaskId(), task.getState(), task.getUpdateTime()); + return null; + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/CatalogRetry.java b/src/main/java/saps/catalog/core/retry/catalog/CatalogRetry.java index fc25008..3812552 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/CatalogRetry.java +++ b/src/main/java/saps/catalog/core/retry/catalog/CatalogRetry.java @@ -1,8 +1,9 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import saps.catalog.core.retry.catalog.exceptions.CatalogRetryException; public interface CatalogRetry { - T run() throws CatalogRetryException; + T run() throws CatalogRetryException; } diff --git a/src/main/java/saps/catalog/core/retry/catalog/GetAllTasks.java b/src/main/java/saps/catalog/core/retry/catalog/GetAllTasks.java index 5025fe4..5b17870 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/GetAllTasks.java +++ b/src/main/java/saps/catalog/core/retry/catalog/GetAllTasks.java @@ -1,22 +1,20 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import java.util.List; - -import saps.common.core.model.SapsImage; - import saps.catalog.core.Catalog; +import saps.common.core.model.SapsImage; public class GetAllTasks implements CatalogRetry> { - private Catalog imageStore; - - public GetAllTasks(Catalog imageStore) { - this.imageStore = imageStore; - } + private Catalog imageStore; - @Override - public List run() { - return imageStore.getAllTasks(); - } + public GetAllTasks(Catalog imageStore) { + this.imageStore = imageStore; + } + @Override + public List run() { + return imageStore.getAllTasks(); + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/GetProcessedTasks.java b/src/main/java/saps/catalog/core/retry/catalog/GetProcessedTasks.java index 1ce7c6c..c6991ec 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/GetProcessedTasks.java +++ b/src/main/java/saps/catalog/core/retry/catalog/GetProcessedTasks.java @@ -1,38 +1,48 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import java.util.Date; import java.util.List; - +import saps.catalog.core.Catalog; import saps.common.core.model.SapsImage; import saps.common.core.model.enums.ImageTaskState; -import saps.catalog.core.Catalog; - public class GetProcessedTasks implements CatalogRetry> { - private Catalog imageStore; - private String region; - private Date initDate; - private Date endDate; - private String inputdownloadingPhaseTag; - private String preprocessingPhaseTag; - private String processingPhaseTag; - - public GetProcessedTasks(Catalog imageStore, String region, Date initDate, Date endDate, - String inputdownloadingPhaseTag, String preprocessingPhaseTag, String processingPhaseTag) { - this.imageStore = imageStore; - this.region = region; - this.initDate = initDate; - this.endDate = endDate; - this.inputdownloadingPhaseTag = inputdownloadingPhaseTag; - this.preprocessingPhaseTag = preprocessingPhaseTag; - this.processingPhaseTag = processingPhaseTag; - } - - @Override - public List run(){ - return imageStore.filterTasks(ImageTaskState.ARCHIVED, region, initDate, endDate, inputdownloadingPhaseTag, preprocessingPhaseTag, - processingPhaseTag); - } - + private Catalog imageStore; + private String region; + private Date initDate; + private Date endDate; + private String inputdownloadingPhaseTag; + private String preprocessingPhaseTag; + private String processingPhaseTag; + + public GetProcessedTasks( + Catalog imageStore, + String region, + Date initDate, + Date endDate, + String inputdownloadingPhaseTag, + String preprocessingPhaseTag, + String processingPhaseTag) { + this.imageStore = imageStore; + this.region = region; + this.initDate = initDate; + this.endDate = endDate; + this.inputdownloadingPhaseTag = inputdownloadingPhaseTag; + this.preprocessingPhaseTag = preprocessingPhaseTag; + this.processingPhaseTag = processingPhaseTag; + } + + @Override + public List run() { + return imageStore.filterTasks( + ImageTaskState.ARCHIVED, + region, + initDate, + endDate, + inputdownloadingPhaseTag, + preprocessingPhaseTag, + processingPhaseTag); + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/GetProcessingTasksRetry.java b/src/main/java/saps/catalog/core/retry/catalog/GetProcessingTasksRetry.java index 45b78c2..236264d 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/GetProcessingTasksRetry.java +++ b/src/main/java/saps/catalog/core/retry/catalog/GetProcessingTasksRetry.java @@ -1,24 +1,24 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import java.util.List; - +import saps.catalog.core.Catalog; import saps.common.core.model.SapsImage; import saps.common.core.model.enums.ImageTaskState; -import saps.catalog.core.Catalog; - -public class GetProcessingTasksRetry implements CatalogRetry>{ +public class GetProcessingTasksRetry implements CatalogRetry> { - private Catalog imageStore; + private Catalog imageStore; - public GetProcessingTasksRetry(Catalog imageStore) { - this.imageStore = imageStore; - } - - @Override - public List run(){ - ImageTaskState[] states = {ImageTaskState.DOWNLOADING, ImageTaskState.PREPROCESSING, ImageTaskState.RUNNING}; - return imageStore.getTasksByState(states); - } + public GetProcessingTasksRetry(Catalog imageStore) { + this.imageStore = imageStore; + } + @Override + public List run() { + ImageTaskState[] states = { + ImageTaskState.DOWNLOADING, ImageTaskState.PREPROCESSING, ImageTaskState.RUNNING + }; + return imageStore.getTasksByState(states); + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/GetTaskById.java b/src/main/java/saps/catalog/core/retry/catalog/GetTaskById.java index 018b977..2b3ad39 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/GetTaskById.java +++ b/src/main/java/saps/catalog/core/retry/catalog/GetTaskById.java @@ -1,22 +1,21 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; -import saps.common.core.model.SapsImage; - import saps.catalog.core.Catalog; +import saps.common.core.model.SapsImage; public class GetTaskById implements CatalogRetry { - private Catalog imageStore; - private String taskId; - - public GetTaskById(Catalog imageStore, String taskId) { - this.imageStore = imageStore; - this.taskId = taskId; - } + private Catalog imageStore; + private String taskId; - @Override - public SapsImage run() { - return imageStore.getTaskById(taskId); - } + public GetTaskById(Catalog imageStore, String taskId) { + this.imageStore = imageStore; + this.taskId = taskId; + } + @Override + public SapsImage run() { + return imageStore.getTaskById(taskId); + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/GetTasksRetry.java b/src/main/java/saps/catalog/core/retry/catalog/GetTasksRetry.java index 1264cfe..0023509 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/GetTasksRetry.java +++ b/src/main/java/saps/catalog/core/retry/catalog/GetTasksRetry.java @@ -1,25 +1,23 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import java.util.List; - +import saps.catalog.core.Catalog; import saps.common.core.model.SapsImage; import saps.common.core.model.enums.ImageTaskState; -import saps.catalog.core.Catalog; +public class GetTasksRetry implements CatalogRetry> { -public class GetTasksRetry implements CatalogRetry>{ + private Catalog imageStore; + private ImageTaskState[] states; - private Catalog imageStore; - private ImageTaskState[] states; - - public GetTasksRetry(Catalog imageStore, ImageTaskState state) { - this.imageStore = imageStore; - this.states = new ImageTaskState[]{state}; - } - - @Override - public List run() { - return imageStore.getTasksByState(states); - } + public GetTasksRetry(Catalog imageStore, ImageTaskState state) { + this.imageStore = imageStore; + this.states = new ImageTaskState[] {state}; + } + @Override + public List run() { + return imageStore.getTasksByState(states); + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/GetUser.java b/src/main/java/saps/catalog/core/retry/catalog/GetUser.java index 81356f0..583f3be 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/GetUser.java +++ b/src/main/java/saps/catalog/core/retry/catalog/GetUser.java @@ -1,31 +1,30 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; import org.apache.log4j.Logger; +import saps.catalog.core.Catalog; import saps.catalog.core.exceptions.CatalogException; import saps.catalog.core.exceptions.UserNotFoundException; import saps.common.core.model.SapsUser; -import saps.catalog.core.Catalog; - public class GetUser implements CatalogRetry { - private Catalog imageStore; - private String userEmail; - public static final Logger LOGGER = Logger.getLogger(GetUser.class); - - public GetUser(Catalog imageStore, String userEmail) { - this.imageStore = imageStore; - this.userEmail = userEmail; - } + private Catalog imageStore; + private String userEmail; + public static final Logger LOGGER = Logger.getLogger(GetUser.class); - @Override - public SapsUser run() { - try { - return imageStore.getUserByEmail(userEmail); - } catch (CatalogException | UserNotFoundException e) { - LOGGER.error("Error while gets user by email.", e); - } - return null; - } + public GetUser(Catalog imageStore, String userEmail) { + this.imageStore = imageStore; + this.userEmail = userEmail; + } + @Override + public SapsUser run() { + try { + return imageStore.getUserByEmail(userEmail); + } catch (CatalogException | UserNotFoundException e) { + LOGGER.error("Error while gets user by email.", e); + } + return null; + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/RemoveTimestampRetry.java b/src/main/java/saps/catalog/core/retry/catalog/RemoveTimestampRetry.java index 69658aa..c483751 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/RemoveTimestampRetry.java +++ b/src/main/java/saps/catalog/core/retry/catalog/RemoveTimestampRetry.java @@ -1,21 +1,21 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; -import saps.common.core.model.SapsImage; - import saps.catalog.core.Catalog; +import saps.common.core.model.SapsImage; public class RemoveTimestampRetry implements CatalogRetry { - private Catalog imageStore; - private SapsImage task; + private Catalog imageStore; + private SapsImage task; - public RemoveTimestampRetry(Catalog imageStore, SapsImage task) { - this.imageStore = imageStore; - this.task = task; - } + public RemoveTimestampRetry(Catalog imageStore, SapsImage task) { + this.imageStore = imageStore; + this.task = task; + } - @Override - public Void run(){ - imageStore.removeStateChangeTime(task.getTaskId(), task.getState(), task.getUpdateTime()); - return null; - } + @Override + public Void run() { + imageStore.removeStateChangeTime(task.getTaskId(), task.getState(), task.getUpdateTime()); + return null; + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/UpdateTaskRetry.java b/src/main/java/saps/catalog/core/retry/catalog/UpdateTaskRetry.java index cb2378c..d8e7727 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/UpdateTaskRetry.java +++ b/src/main/java/saps/catalog/core/retry/catalog/UpdateTaskRetry.java @@ -1,24 +1,23 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog; -import saps.common.core.model.SapsImage; - import saps.catalog.core.Catalog; +import saps.common.core.model.SapsImage; -public class UpdateTaskRetry implements CatalogRetry{ +public class UpdateTaskRetry implements CatalogRetry { - private Catalog imageStore; - private SapsImage task; + private Catalog imageStore; + private SapsImage task; - public UpdateTaskRetry(Catalog imageStore, SapsImage task) { - this.imageStore = imageStore; - this.task = task; - } - - @Override - public Boolean run() { - task.setUpdateTime(imageStore.getTaskById(task.getTaskId()).getUpdateTime()); - imageStore.updateImageTask(task); - return true; - } + public UpdateTaskRetry(Catalog imageStore, SapsImage task) { + this.imageStore = imageStore; + this.task = task; + } + @Override + public Boolean run() { + task.setUpdateTime(imageStore.getTaskById(task.getTaskId()).getUpdateTime()); + imageStore.updateImageTask(task); + return true; + } } diff --git a/src/main/java/saps/catalog/core/retry/catalog/exceptions/CatalogRetryException.java b/src/main/java/saps/catalog/core/retry/catalog/exceptions/CatalogRetryException.java index 61a1c74..48693f2 100644 --- a/src/main/java/saps/catalog/core/retry/catalog/exceptions/CatalogRetryException.java +++ b/src/main/java/saps/catalog/core/retry/catalog/exceptions/CatalogRetryException.java @@ -1,10 +1,11 @@ +/* (C)2020 */ package saps.catalog.core.retry.catalog.exceptions; public class CatalogRetryException extends RuntimeException { - private static final long serialVersionUID = -2520888793776997437L; + private static final long serialVersionUID = -2520888793776997437L; - public CatalogRetryException(String msg) { - super(msg); - } + public CatalogRetryException(String msg) { + super(msg); + } }