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.
working on sample & added auto-config
Signed-off-by: Mark Nelson <[email protected]>
- Loading branch information
1 parent
355baa7
commit e8e9b72
Showing
9 changed files
with
218 additions
and
0 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
54 changes: 54 additions & 0 deletions
54
...figure/src/main/java/com/oracle/cloud/spring/adb/AutonomousDatabaseAutoConfiguration.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,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; | ||
} | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
spring-cloud-oci-samples/spring-cloud-oci-adb-samples/pom.xml
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,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> |
60 changes: 60 additions & 0 deletions
60
...c/main/java/com/oracle/cloud/spring/sample/adb/springcloudociadbsample/AdbController.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,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()); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...main/java/com/oracle/cloud/spring/sample/adb/springcloudociadbsample/HelloController.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,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"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...e/cloud/spring/sample/adb/springcloudociadbsample/SpringCloudOciAdbSampleApplication.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,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); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...-cloud-oci-samples/spring-cloud-oci-adb-samples/src/main/resources/application.properties
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,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 |