Skip to content

Commit

Permalink
Merge pull request ufcg-lsd#7 from ufcg-lsd/refactor/google-style
Browse files Browse the repository at this point in the history
Refactored code based on Google style
  • Loading branch information
thiagomanel authored Dec 15, 2020
2 parents 2497e8a + 490658d commit f2383e8
Show file tree
Hide file tree
Showing 25 changed files with 1,549 additions and 1,167 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
*.log*
nohup.out
saps-catalog.iml
.classpath
.project
.settings/
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
55 changes: 53 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,51 @@

<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<!-- optional: limit format enforcement to just the files changed by
this feature branch -->
<!-- <ratchetFrom>origin/main</ratchetFrom> -->
<formats>
<!-- you can define as many formats as you want, each is independent -->
<format>
<!-- define the files to apply to -->
<includes>
<include>*.md</include>
<include>.gitignore</include>
</includes>
<!-- define the steps to apply to those files -->
<trimTrailingWhitespace />
<endWithNewline />
<indent>
<tabs>true</tabs>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
<!-- define a language-specific format -->
<java>
<!-- no need to specify files, inferred automatically, but you can
if you want -->

<!-- apply a specific flavor of google-java-format -->
<googleJavaFormat>
<version>1.7</version>
<style>GOOGLE</style>
</googleJavaFormat>

<!-- make sure every file has the following copyright header. optionally,
Spotless can set copyright years by digging through git history (see "license"
section below) -->
<licenseHeader>
<content>/* (C)$YEAR */</content> <!-- or <file>${basedir}/license-header</file> -->
</licenseHeader>
</java>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -96,8 +141,8 @@
<id>local-maven-repo</id>
<url>file:///${project.basedir}/local-maven-repo</url>
</repository>
<!-- <repository> <id>mvn.prov.toolbox.snapshots</id> <name>maven snapshot
repository for PROV toolbox</name> <url>http://openprovenance.org/java/maven-snapshots/</url>
<!-- <repository> <id>mvn.prov.toolbox.snapshots</id> <name>maven snapshot
repository for PROV toolbox</name> <url>http://openprovenance.org/java/maven-snapshots/</url>
</repository> -->
</repositories>

Expand Down Expand Up @@ -270,5 +315,11 @@
<artifactId>saps-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.6.1</version>
</dependency>
</dependencies>
</project>
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);
}
}
Loading

0 comments on commit f2383e8

Please sign in to comment.