-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support for Autonomous Database #44
Changes from all commits
d7fff69
79ef15c
e85aff9
005bf92
fbf8dac
ab910b9
355baa7
e8e9b72
9482eff
116e65d
1a7a444
8bebd4c
80f701a
64760ee
1b923e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the typical way a wallet is provided to an app? |
||
} | ||
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. |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation, also, compiler should be set in the parent pom |
||
<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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DatabaseClient should already be a bean right? |
||
|
||
/** | ||
* 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a lot more parameters for autonomous database, how does the user supply these? https://docs.oracle.com/en-us/iaas/autonomous-database/doc/create-adb.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, why would I use this method over calling the SDK directly to create an adb? |
||
.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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to leave this method unimplemented until the issue is fixed, we're returning SDK objects elsewhere but our own pojo in this case - it may cause problems later on |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this also delete any backups or other residual objects associated with the database? |
||
DeleteAutonomousDatabaseRequest deleteAutonomousDatabaseRequest = DeleteAutonomousDatabaseRequest.builder() | ||
.autonomousDatabaseId(databaseId) | ||
.build(); | ||
|
||
DeleteAutonomousDatabaseResponse response = client.deleteAutonomousDatabase(deleteAutonomousDatabaseRequest); | ||
|
||
return response; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024