Skip to content

Commit

Permalink
Refactored code according to Google Java Style
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoyeds committed Nov 24, 2020
1 parent b72ec95 commit 490658d
Show file tree
Hide file tree
Showing 23 changed files with 1,493 additions and 1,165 deletions.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<user_name>
catalog_db_name=<db_name>
catalog_passwd=<password>
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=<user_name>
catalog_db_name=<db_name>
catalog_passwd=<password>
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=<postgres_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=<postgres_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:
Expand Down
219 changes: 125 additions & 94 deletions src/main/java/saps/catalog/core/Catalog.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.<br>
// - 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}.<br>
*
* @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:<br>
* -- landsat_5: indicates that the task is related to the LANDSAT 5 satellite
* (https://www.usgs.gov/land-resources/nli/landsat/landsat-5)<br>
* -- landsat_7: indicates that the task is related to the LANDSAT 7 satellite
* (https://www.usgs.gov/land-resources/nli/landsat/landsat-7)<br>
* -- 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)<br>
* @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<SapsImage> getAllTasks() throws CatalogException;

List<SapsImage> 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<SapsImage> 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.<br>
// - 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}.<br>
*
* @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:<br>
* -- landsat_5: indicates that the task is related to the LANDSAT 5 satellite
* (https://www.usgs.gov/land-resources/nli/landsat/landsat-5)<br>
* -- landsat_7: indicates that the task is related to the LANDSAT 7 satellite
* (https://www.usgs.gov/land-resources/nli/landsat/landsat-7)<br>
* -- 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)<br>
* @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<SapsImage> getAllTasks() throws CatalogException;

List<SapsImage> 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<SapsImage> filterTasks(
ImageTaskState state,
String region,
Date initDate,
Date endDate,
String inputdownloadingTag,
String preprocessingTag,
String processingTag)
throws CatalogException;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
public TaskNotFoundException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit 490658d

Please sign in to comment.