Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add postgres support #21

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,23 @@ connection:
# Represents password, which will be used to decode operations.
password: "test123"

# Represents section used for ObjectStorage API Server temporate storage configuration.
temporate-storage:
# Represents format used for content to be saved.
format: "zip"
# Represents section used for ObjectStorage API Server internal database configuration.
internal-storage:
# Represents provider selected for ObjectStorage internal database. Supported providers are "sqlite3" and "postgres" only.
provider: "sqlite3"

# Represents host for the previously selected ObjectStorage internal database provider, works only for "postgres".
# host: "localhost:5432"

# Represents username for the previously selected ObjectStorage internal database provider.
username: "objectstorage_user"

# Represents password for the previously selected ObjectStorage internal database provider.
password: "objectstorage_password"

# Represents section used for ObjectStorage API Server temporate storage configuration. Same compression will be
# used to upload files to the configured cloud providers.
temporate-storage:
# Represents frequency of scheduled operations processing.
frequency: "*/5 * * * * ?"

Expand All @@ -118,10 +130,13 @@ backup:
# Represents frequency of backup operation for selected provider.
frequency: "0 */5 * * * ?"

# Represents the highest amount of downloaded backup content versions per each workspace.
max-versions: 5

# Represents section used for ObjectStorage API Server diagnostics configuration.
diagnostics:
# Enables diagnostics functionality.
enabled: false
enabled: true

# Represents section used for ObjectStorage diagnostics metrics configuration.
metrics:
Expand All @@ -144,6 +159,9 @@ diagnostics:
port: 8121
```

In the **~/.objectstorage/internal/database** directory there will be located internal database data, if **sqlite3**
option is selected as target database.

### Diagnostics dashboard

For **ObjectStorage API Server** configuration the following section should be modified:
4 changes: 4 additions & 0 deletions api-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<groupId>io.quarkiverse.jdbc</groupId>
<artifactId>quarkus-jdbc-sqlite</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-jwt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,55 @@ public static class Security {
@JsonProperty("connection")
public Connection connection;

/**
* Represents ObjectStorage internal storage configuration used for internal database setup.
*/
@Getter
public static class InternalStorage {
/**
* Represents all supported providers, which can be used by ObjectStorage internal storage.
*/
@Getter
public enum Provider {
@JsonProperty("sqlite3")
SQLITE3("sqlite3"),

@JsonProperty("postgres")
POSTGRES("postgres");

private final String value;

Provider(String value) {
this.value = value;
}

public String toString() {
return value;
}
}

@Valid
@NotNull
@JsonProperty("provider")
public Provider provider;

@JsonProperty("host")
public String host;

@NotNull
@JsonProperty("username")
public String username;

@NotNull
@JsonProperty("password")
public String password;
}

@Valid
@NotNull
@JsonProperty("internal-storage")
public InternalStorage internalStorage;

/**
* Represents ObjectStorage API Server configuration used for temporate storage setup.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class PropertiesEntity {
@ConfigProperty(name = "quarkus.http.port")
Integer applicationPort;

@ConfigProperty(name = "database.name")
String databaseName;

@ConfigProperty(name = "liquibase.sqlite3.config")
String liquibaseSqlite3Config;

@ConfigProperty(name = "liquibase.postgres.config")
String liquibasePostgresConfig;

@ConfigProperty(name = "content.root.notation")
String contentRootNotation;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.objectstorage.exception;

import java.io.IOException;
import java.util.Arrays;
import java.util.Formatter;

/**
* Represents exception used when configuration file database properties are missing.
*/
public class ConfigDatabasePropertiesMissingException extends IOException {
public ConfigDatabasePropertiesMissingException() {
this("");
}

public ConfigDatabasePropertiesMissingException(Object... message) {
super(
new Formatter()
.format("Config file database properties are missing: %s", Arrays.stream(message).toArray())
.toString());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void insert(Integer provider, Integer secret, String root) throws Reposit
try {
repositoryExecutor.performQuery(query);

} catch (QueryExecutionFailureException | QueryEmptyResultException e) {
} catch (QueryExecutionFailureException e) {
throw new RepositoryOperationFailureException(e.getMessage());
}
}
Expand Down Expand Up @@ -77,12 +77,29 @@ public ContentEntity findByProviderAndSecret(Integer provider, Integer secret) t
throw new RepositoryOperationFailureException(e.getMessage());
}

Integer id;
String root;

try {
id = resultSet.getInt("id");
root = resultSet.getString("root");
if (resultSet.next()) {
try {
Integer id = resultSet.getInt("id");
String root = resultSet.getString("root");

try {
resultSet.close();
} catch (SQLException e) {
throw new RepositoryOperationFailureException(e.getMessage());
}

return ContentEntity.of(id, provider, secret, root);
} catch (SQLException e1) {
try {
resultSet.close();
} catch (SQLException e2) {
throw new RepositoryOperationFailureException(e2.getMessage());
}

throw new RepositoryOperationFailureException(e1.getMessage());
}
}
} catch (SQLException e1) {
try {
resultSet.close();
Expand All @@ -99,7 +116,7 @@ public ContentEntity findByProviderAndSecret(Integer provider, Integer secret) t
throw new RepositoryOperationFailureException(e.getMessage());
}

return ContentEntity.of(id, provider, secret, root);
return null;
}

/**
Expand Down Expand Up @@ -167,7 +184,7 @@ public void deleteByProviderAndSecret(Integer provider, Integer secret) throws R
provider,
secret));

} catch (QueryExecutionFailureException | QueryEmptyResultException e) {
} catch (QueryExecutionFailureException e) {
throw new RepositoryOperationFailureException(e.getMessage());
}
}
Expand Down
Loading
Loading