Skip to content

Commit

Permalink
working on sample & added auto-config
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Nelson <[email protected]>
  • Loading branch information
markxnelson committed Jul 9, 2024
1 parent 355baa7 commit e8e9b72
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spring-cloud-oci-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Licensed under the Universal Permissive License v 1.0 as shown at https://oss.or
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-core</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-adb</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-storage</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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/

package com.oracle.cloud.spring.adb;

import com.oracle.bmc.Region;
import com.oracle.bmc.auth.RegionProvider;
import com.oracle.bmc.database.DatabaseClient;
import com.oracle.cloud.spring.autoconfigure.core.CredentialsProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;

import java.text.MessageFormat;

import static com.oracle.cloud.spring.autoconfigure.core.CredentialsProviderAutoConfiguration.credentialsProviderQualifier;
import static com.oracle.cloud.spring.autoconfigure.core.RegionProviderAutoConfiguration.regionProviderQualifier;

/**
* Auto-configuration for initializing the OCI Autonomous Database component.
* Depends on {@link com.oracle.cloud.spring.autoconfigure.core.CredentialsProviderAutoConfiguration} and
* {@link com.oracle.cloud.spring.autoconfigure.core.RegionProviderAutoConfiguration}
* for loading the Authentication configuration
*
* @see com.oracle.cloud.spring.adb.AutonomousDatabase
*/
@AutoConfiguration
@ConditionalOnClass({AutonomousDatabase.class})
@ConditionalOnProperty(name = "spring.cloud.oci.adb.enabled", havingValue = "true", matchIfMissing = true)
public class AutonomousDatabaseAutoConfiguration {

@Bean
@RefreshScope
@ConditionalOnMissingBean(AutonomousDatabase.class)
AutonomousDatabase getQueueImpl(DatabaseClient databaseClient) {
return new AutonomousDatabaseImpl(databaseClient);
}

@Bean
@RefreshScope
@ConditionalOnMissingBean
DatabaseClient databaseClient(@Qualifier(regionProviderQualifier) RegionProvider regionProvider,
@Qualifier(credentialsProviderQualifier)
CredentialsProvider cp) {
DatabaseClient databaseClient = DatabaseClient.builder().build(cp.getAuthenticationDetailsProvider());
if (regionProvider.getRegion() != null)databaseClient.setRegion(regionProvider.getRegion());
return databaseClient;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"type": "java.lang.Boolean",
"description": "Auto-configure OCI Cloud queue components.",
"defaultValue": true
},
{
"name": "spring.cloud.oci.adb.enabled",
"type": "java.lang.Boolean",
"description": "Auto-configure OCI Autonomous Database components.",
"defaultValue": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ com.oracle.cloud.spring.streaming.StreamingAutoConfiguration
com.oracle.cloud.spring.queue.QueueAutoConfiguration
com.oracle.cloud.spring.genai.GenAIAutoConfiguration
com.oracle.cloud.spring.vault.VaultAutoConfiguration
com.oracle.cloud.spring.adb.AutonomousDatabaseAutoConfiguration
54 changes: 54 additions & 0 deletions spring-cloud-oci-samples/spring-cloud-oci-adb-samples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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/
-->

<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">
<parent>
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-samples</artifactId>
<version>1.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.oracle.cloud.spring.sample.adb</groupId>
<artifactId>spring-cloud-oci-adb-sample</artifactId>
<name>spring-cloud-oci-adb-sample</name>
<description>spring-cloud-oci-adb-sample</description>
<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>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle.cloud.spring</groupId>
<artifactId>spring-cloud-oci-starter-adb</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.cloud.spring.sample.common</groupId>
<artifactId>spring-cloud-oci-common-samples-utils</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.cloud.spring.sample.common</groupId>
<artifactId>spring-cloud-oci-common-samples-utils</artifactId>
<type>test-jar</type>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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.sample.adb.springcloudociadbsample;

import com.oracle.bmc.database.responses.CreateAutonomousDatabaseResponse;
import com.oracle.bmc.database.responses.DeleteAutonomousDatabaseResponse;
import com.oracle.bmc.database.responses.GenerateAutonomousDatabaseWalletResponse;
import com.oracle.bmc.database.responses.GetAutonomousDatabaseResponse;
import com.oracle.cloud.spring.adb.AutonomousDatabase;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("demoapp/api/adb")
@Tag(name = "Autonomous Database APIs")
public class AdbController {

@Autowired
AutonomousDatabase autonomousDatabase;

@PostMapping
ResponseEntity<?> createAutonomousDatabase(
@Parameter(required = true, example = "databaseName") @RequestParam String databaseName,
@Parameter(required = true, example = "compartmentId") @RequestParam String compartmentId
) {
CreateAutonomousDatabaseResponse response = autonomousDatabase.createAutonomousDatabase(databaseName, compartmentId);
return ResponseEntity.accepted().body("database id : " + response.getAutonomousDatabase().getAutonomousContainerDatabaseId());
}

@GetMapping
ResponseEntity<?> getAutonomousDatabase(@Parameter(required = true, example = "databaseId") @RequestParam String databaseId) {
GetAutonomousDatabaseResponse response = autonomousDatabase.getAutonomousDatabase(databaseId);
return ResponseEntity.ok().body(response);
}

@GetMapping(value = "/wallet")
ResponseEntity<?> getAutonomousDatabaseWallet(
@Parameter(required = true, example = "databaseId") @RequestParam String databaseId,
@Parameter(required = true, example = "password") @RequestParam String password
) {
GenerateAutonomousDatabaseWalletResponse response = autonomousDatabase.generateAutonomousDatabaseWallet(databaseId, password);
return ResponseEntity.ok().body("opcRequestId fo generating wallet : " + response.getOpcRequestId());
}

@DeleteMapping
ResponseEntity<?> deleteAutonomousDatabase(@Parameter(required = true, example ="databaseId") @RequestParam String databaseId) {
DeleteAutonomousDatabaseResponse response = autonomousDatabase.deleteAutonomousDatabase(databaseId);
return ResponseEntity.ok().body("opcRequestId for deleting the database : " +response.getOpcRequestId());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.sample.adb.springcloudociadbsample;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("demoapp/api")
@Tag(name = "Hello World APIs")
public class HelloController {
@GetMapping("/")
public String hello() {
return "Hello World From Autonomus Database Service";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.sample.adb.springcloudociadbsample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringCloudOciAdbSampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudOciAdbSampleApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 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/

spring.cloud.oci.region.static = us-phoenix-1
#spring.cloud.oci.config.type = RESOURCE_PRINCIPAL

0 comments on commit e8e9b72

Please sign in to comment.