generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from oracle/mark/adb
Support for Autonomous Database
- Loading branch information
Showing
20 changed files
with
704 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
63 changes: 63 additions & 0 deletions
63
spring-cloud-oci-adb/src/main/java/com/oracle/cloud/spring/adb/AutonomousDb.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
spring-cloud-oci-adb/src/main/java/com/oracle/cloud/spring/adb/AutonomousDbDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { } |
139 changes: 139 additions & 0 deletions
139
spring-cloud-oci-adb/src/main/java/com/oracle/cloud/spring/adb/AutonomousDbImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.