Skip to content

Commit

Permalink
Merge pull request #44 from oracle/mark/adb
Browse files Browse the repository at this point in the history
Support for Autonomous Database
  • Loading branch information
markxnelson authored Jul 10, 2024
2 parents 58b4dff + 1b923e8 commit 392878a
Show file tree
Hide file tree
Showing 20 changed files with 704 additions and 3 deletions.
82 changes: 82 additions & 0 deletions docs/src/main/asciidoc/adb.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

[#autonomous-database]
== Autonomous Database

https://docs.oracle.com/en/cloud/paas/atp-cloud/index.html[Autonomous Database] is a data management service built
on self-driving Oracle Autonomous Database technology to deliver automated patching, upgrades, and tuning, including
performing all routine database maintenance tasks while the system is running, without human intervention.

Maven coordinates, using <<getting-started.adoc#bill-of-materials, Spring Cloud OCI BOM>>:

[source,xml]
----
<dependency>
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-starter-adb</artifactId>
</dependency>
----

Gradle coordinates:

[source,subs="normal"]
----
dependencies {
implementation("com.oracle.cloud.spring:spring-cloud-oci-starter-adb")
}
----

=== Using Autonomous Database

The starter automatically configures and registers an `AutnomousDb` bean in the Spring application context.
The `AutnomousDb` bean (link[Javadoc]) can be used to create an Autonomous Database, get details of an Autonomous Database,
delete an Autonomous Database and generate a wallet for an Autonomous Database.

[source,java]
----
@Autowired
private Queue queue;
public void createQueue() {
String queueId = queue.createQueue("my-queue", <<compartmentId>>, <<deadLetterQueueDeliveryCount>>, <<retentionInSeconds>>);
}
@Autowired
AutonomousDb autonomousDatabase;
public void createAutonomousDatabase() {
autonomousDatabase.createAutonomousDatabase(
databaseName, compartmentId, adminPassword, dataStorageSizeInGBs, computeCount);
}
public void getAutonomousDatabase() {
AutonomousDbDetails response = autonomousDatabase.getAutonomousDatabase(databaseId);
}
public void getAutonomousDatabaseWallet() {
GenerateAutonomousDatabaseWalletResponse response = autonomousDatabase.generateAutonomousDatabaseWallet(databaseId, password);
InputStream is = response.getInputStream();
int ContentLength = response.getContentLength();
// read the InputStream to get the wallet
}
public void deleteAutonomousDatabase() {
DeleteAutonomousDatabaseResponse response = autonomousDatabase.deleteAutonomousDatabase(databaseId);
}
----


=== Configuration

The Spring Boot Starter for Oracle Autonomous Database provides the following configuration options:

|===
^| Name ^| Description ^| Required ^| Default value
| `spring.cloud.oci.adb.enabled` | Enables the OCI Autonomous Database APIs. | No | `true`
|===


=== Sample

A sample application provided https://github.com/oracle/spring-cloud-oci/tree/main/spring-cloud-oci-samples/spring-cloud-oci-adb-sample[here] contains the examples to demonstrates the usage of OCI Spring Cloud Autonomous Database module.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Licensed under the Universal Permissive License v 1.0 as shown at https://oss.or
</scm>

<modules>
<module>spring-cloud-oci-adb</module>
<module>spring-cloud-oci-dependencies</module>
<module>spring-cloud-oci-core</module>
<module>spring-cloud-oci-autoconfigure</module>
Expand All @@ -73,7 +74,7 @@ Licensed under the Universal Permissive License v 1.0 as shown at https://oss.or
<spring-cloud-oci-dependencies.version>${project.version}</spring-cloud-oci-dependencies.version>
<spring-cloud-dependencies.version>2023.0.2</spring-cloud-dependencies.version>
<spring-boot-dependencies.version>3.2.7</spring-boot-dependencies.version>
<oci-sdk.version>3.44.0</oci-sdk.version>
<oci-sdk.version>3.44.2</oci-sdk.version>
<spring-boot-maven-plugin.version>3.2.5</spring-boot-maven-plugin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Expand Down
57 changes: 57 additions & 0 deletions spring-cloud-oci-adb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023, 2024, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>spring-cloud-oci</artifactId>
<groupId>com.oracle.cloud.spring</groupId>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>spring-cloud-oci-adb</artifactId>
<name>Spring Cloud OCI Autonomous Database Module</name>
<description>Spring Cloud OCI Autonomous Database Module</description>
<url>https://github.com/oracle/spring-cloud-oci/#spring-cloud-oci-documentation</url>

<licenses>
<license>
<name>The Universal Permissive License (UPL), Version 1.0</name>
<url>https://oss.oracle.com/licenses/upl/</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<id>oracle</id>
<name>Oracle</name>
<organizationUrl>https://www.oracle.com</organizationUrl>
</developer>
</developers>

<scm>
<url>https://github.com/oracle/spring-cloud-oci</url>
<connection>scm:git:https://github.com/oracle/spring-cloud-oci.git</connection>
<developerConnection>scm:git:[email protected]:oracle/spring-cloud-oci.git</developerConnection>
</scm>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-core</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-database</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

package com.oracle.cloud.spring.adb;

import com.oracle.bmc.database.DatabaseClient;
import com.oracle.bmc.database.model.AutonomousDatabase;
import com.oracle.bmc.database.responses.CreateAutonomousDatabaseResponse;
import com.oracle.bmc.database.responses.GenerateAutonomousDatabaseWalletResponse;
import com.oracle.bmc.database.responses.DeleteAutonomousDatabaseResponse;

/**
* Interface for OCI Autonomous Database module.
*/
public interface AutonomousDb {

/**
* Direct instance of OCI Java SDK DatabaseClient.
* @return DatabaseClient
*/
DatabaseClient getDatatbaseClient();

/**
* Create an Autonomous Database.
*
* @param databaseName Name of the Autonomous Database to be created
* @param compartmentId Compartment OCID where the Autonomous Database needs to be created
* @return CreateAutonomousDatabaseResponse
*/
CreateAutonomousDatabaseResponse createAutonomousDatabase(
String databaseName,
String compartmentId,
String adminPassword,
Integer dataStorageSizeInGBs,
Float computeCount
);

/**
* Get details of an Autonomous Database.
*
* @param databaseId OCID of the Autonomous Database to get details of
* @return GetAutonomousDatabaseResponse
*/
AutonomousDbDetails getAutonomousDatabase(String databaseId);

/**
* Generate a wallet for an Autonomous Database.
*
* @param databaseId OCID of the Autonomous Database to get generate a wallet for
* @param password Password for the wallet
* @return GenerateAutonomousDatabaseWalletResponse
*/
GenerateAutonomousDatabaseWalletResponse generateAutonomousDatabaseWallet(String databaseId, String password);

/**
* Delete an Autonomous Database.
*
* @param databaseId OCID of the Autonomous Database to be deleted
* @return DeleteAutonomousDatabaseResponse
*/
DeleteAutonomousDatabaseResponse deleteAutonomousDatabase(String databaseId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

package com.oracle.cloud.spring.adb;

public record AutonomousDbDetails (
String compartmentId,
String displayName,
String id,
String dbName,
String lifecycleState,
String timeCreated,
Float computeCount,
Integer dataStorageSizeInGBs,
String licenseModel,
String serviceConsoleUrl
) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright (c) 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

package com.oracle.cloud.spring.adb;

import com.oracle.bmc.database.DatabaseClient;
import com.oracle.bmc.database.model.AutonomousDatabase;
import com.oracle.bmc.database.model.CreateAutonomousDatabaseBase;
import com.oracle.bmc.database.model.CreateAutonomousDatabaseDetails;
import com.oracle.bmc.database.model.GenerateAutonomousDatabaseWalletDetails;
import com.oracle.bmc.database.responses.CreateAutonomousDatabaseResponse;
import com.oracle.bmc.database.responses.GetAutonomousDatabaseResponse;
import com.oracle.bmc.database.responses.GenerateAutonomousDatabaseWalletResponse;
import com.oracle.bmc.database.responses.DeleteAutonomousDatabaseResponse;
import com.oracle.bmc.database.requests.GetAutonomousDatabaseRequest;
import com.oracle.bmc.database.requests.GenerateAutonomousDatabaseWalletRequest;
import com.oracle.bmc.database.requests.CreateAutonomousDatabaseRequest;
import com.oracle.bmc.database.requests.DeleteAutonomousDatabaseRequest;

/**
* Implementation for the OCI Autonomous Database module.
*/
public class AutonomousDbImpl implements AutonomousDb {

final DatabaseClient client;

public AutonomousDbImpl(DatabaseClient client) {
this.client = client;
}

/**
* Direct instance of OCI Java SDK DatabaseClient.
* @return DatabaseClient
*/
public DatabaseClient getDatatbaseClient() {
return client;
}

/**
* Create an Autonomous Database.
*
* @param databaseName Name of the Autonomous Database to be created
* @param compartmentId Compartment OCID where the Autonomous Database needs to be created
* @return CreateAutonomousDatabaseResponse
*/
public CreateAutonomousDatabaseResponse createAutonomousDatabase(
String databaseName,
String compartmentId,
String adminPassword,
Integer dataStorageSizeInGBs,
Float computeCount
) {
CreateAutonomousDatabaseRequest createAutonomousDatabaseRequest = CreateAutonomousDatabaseRequest.builder()
.createAutonomousDatabaseDetails(CreateAutonomousDatabaseDetails.builder()
.compartmentId(compartmentId)
.dbName(databaseName)
.adminPassword(adminPassword)
.dataStorageSizeInGBs(dataStorageSizeInGBs)
.computeModel(CreateAutonomousDatabaseBase.ComputeModel.Ecpu)
.computeCount(computeCount)
.build())
.build();

CreateAutonomousDatabaseResponse response = client.createAutonomousDatabase(createAutonomousDatabaseRequest);

return response;
}

/**
* Get details of an Autonomous Database.
*
* @param databaseId OCID of the Autonomous Database to get details of
* @return GetAutonomousDatabaseResponse
*/
public AutonomousDbDetails getAutonomousDatabase(String databaseId) {
GetAutonomousDatabaseRequest getAutonomousDatabaseRequest = GetAutonomousDatabaseRequest.builder()
.autonomousDatabaseId(databaseId)
.build();

GetAutonomousDatabaseResponse response = client.getAutonomousDatabase(getAutonomousDatabaseRequest);
AutonomousDatabase adb = response.getAutonomousDatabase();

// work around the jackson deserialization issue in oci-java-sdk 3.44.2 - cannot handle explicitlySet - no filter
AutonomousDbDetails add = new AutonomousDbDetails(
adb.getCompartmentId(),
adb.getDisplayName(),
adb.getId(),
adb.getDbName(),
adb.getLifecycleState().toString(),
adb.getTimeCreated().toString(),
adb.getComputeCount(),
adb.getDataStorageSizeInGBs(),
adb.getLicenseModel().toString(),
adb.getServiceConsoleUrl()
);

return add;
}

/**
* Generate a wallet for an Autonomous Database.
*
* @param databaseId OCID of the Autonomous Database to get generate a wallet for
* @param password Password for the wallet
* @return GenerateAutonomousDatabaseWalletResponse
*/
public GenerateAutonomousDatabaseWalletResponse generateAutonomousDatabaseWallet(String databaseId, String password) {
GenerateAutonomousDatabaseWalletDetails generateAutonomousDatabaseWalletDetails = GenerateAutonomousDatabaseWalletDetails.builder()
.generateType(GenerateAutonomousDatabaseWalletDetails.GenerateType.All)
.password(password)
.isRegional(true).build();

GenerateAutonomousDatabaseWalletRequest generateAutonomousDatabaseWalletRequest = GenerateAutonomousDatabaseWalletRequest.builder()
.autonomousDatabaseId(databaseId)
.generateAutonomousDatabaseWalletDetails(generateAutonomousDatabaseWalletDetails)
.build();

GenerateAutonomousDatabaseWalletResponse response = client.generateAutonomousDatabaseWallet(generateAutonomousDatabaseWalletRequest);

return response;
}

/**
* Delete an Autonomous Database.
*
* @param databaseId OCID of the Autonomous Database to be deleted
* @return DeleteAutonomousDatabaseResponse
*/
public DeleteAutonomousDatabaseResponse deleteAutonomousDatabase(String databaseId) {
DeleteAutonomousDatabaseRequest deleteAutonomousDatabaseRequest = DeleteAutonomousDatabaseRequest.builder()
.autonomousDatabaseId(databaseId)
.build();

DeleteAutonomousDatabaseResponse response = client.deleteAutonomousDatabase(deleteAutonomousDatabaseRequest);

return response;
}

}
Loading

0 comments on commit 392878a

Please sign in to comment.