Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ build/
.run
target/
Thumbs.db
run-app.sh
11 changes: 0 additions & 11 deletions database/spring-cli/catalog/project-catalog.yml

This file was deleted.

Binary file not shown.

This file was deleted.

48 changes: 48 additions & 0 deletions spring-cli/README .md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Spring CLI integration

Spring CLI integration with a project catalog to help you create Spring Boot projects using Oracle and [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices).

## Install Spring CLI

The goal of the Spring CLI is to increase your productivity when you create new projects and when you add functionality to existing projects. [Spring CLI documentation](https://docs.spring.io/spring-cli/reference/index.html) describes how to install the CLI on various platforms.

## Add to Spring CLI

Execute the following command to add the `project-catalog` for [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices).

```shell
spring add.....
```

The Spring CLI is now aware of the [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices) integration so when building a new project (or adding to a current one) you can use the command `spring .....`

## Run the Spring CLI application locally

To run the application locally you need access to an Oracle Database (remotly or locally). Create a shell script with the following content called `run-app.sh`

```shell
#!/bin/bash
export spring_datasource_url=<URL to database>
export liquibase_datasource_username=<Liquibase database user>
export liquibase_datasource_password=<Liquibase database user password>
export spring_datasource_username=<Application database user>
export spring_datasource_password=<Application database user password>
export otel_exporter_otlp_endpoint=http://localhost:8080 # Fake URL
./mvnw spring-boot:run -Dspring-boot.run.profiles=local
```

The Spring profile `local` turns off Eureka discovery and OTLP tracing.

Execute the shell script running the following command:

```shell
source run-app.sh
```

You can see a few `WARNINGS` with this message which can be ignored:

```log
WARNING:

Liquibase detected the following invalid LIQUIBASE_* environment variables:
```
11 changes: 11 additions & 0 deletions spring-cli/catalog/project-catalog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
project-repositories:
- name: "obaas"
description: "RESTful Hello World service for Oracle Backend Microservices and AI"
url: "https://github.com/oracle/spring-cloud-oci/tree/main/spring-cli/projects/obaas"
tags:
- "obaas"
- "java-17"
- "rest"
- "web"
- "boot-3.4.x"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
== Basic Spring Web Application for Oracle Backend for Spring Boot and Microservices

This project contains a web service that can be deployed on link:https://bit.ly/oraclespringboot[Oracle Backend for Spring Boot and Microservices]
This project contains a web service that can be deployed on link:https://bit.ly/OracleAI-microservices[Oracle Backend for Microservices and AI]
and includes configuration for the well-known endpoints provided by the platform.
The web service will accept HTTP GET requests at `http://localhost:8080/greeting`.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.11</version>
<version>3.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -14,13 +14,14 @@
<version>0.0.1-SNAPSHOT</version>

<name>obaas-rest-service</name>
<description>RESTful web application for Oracle Backend for Spring Boot and Microservices</description>
<description>RESTful web application for Oracle Backend for Microservices and AI</description>

<properties>
<java.version>17</java.version>
<spring-cloud.version>2024.0.0</spring-cloud.version>
<oracle-springboot-starter.version>24.4.0</oracle-springboot-starter.version>
<liquibase.version>4.30.0</liquibase.version>
<datasource-micrometer-spring-boot.version>1.0.5</datasource-micrometer-spring-boot.version>
<liquibase.version>4.31.0</liquibase.version>
<datasource-micrometer-spring-boot.version>1.0.6</datasource-micrometer-spring-boot.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -60,21 +61,58 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>

<!-- This enables Spring Actuator which provides monitoring, metrics, etc. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- This adds metrics for data sources. -->
<dependency>
<groupId>net.ttddyy.observation</groupId>
<artifactId>datasource-micrometer-spring-boot</artifactId>
<version>${datasource-micrometer-spring-boot.version}</version>
</dependency>

<!-- Eureka client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<!-- Core module of Micrometer -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<!-- <version>${micrometer-core.version}</version>-->
</dependency>

<!-- Prometheues-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

<!-- Adds the Tracer Implementation -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>

<!-- Adds an exporter to store the traces -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>

<!-- Adds the Tracing API -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
</dependency>

<!-- Spring test support. -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -83,6 +121,18 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand All @@ -98,7 +148,6 @@
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GreetingController {
private final AtomicLong counter = new AtomicLong();

@GetMapping("/greeting")
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(), String.format(template, name));
public Greeting greeting(@RequestParam(defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(), template.formatted(name));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#
# This is an example Spring application.yaml configuration file for a
# Spring Boot application that can be deployed to Oracle Backend for
# Spring Boot and Microservices.
#
spring:
application:
name: restservice
threads:
virtual:
enabled: true
jpa:
hibernate:
ddl-auto: validate
properties:
hibernate:
dialect: org.hibernate.dialect.OracleDialect
format_sql: true
show-sql: true

# This section configures Liquibase to automate the schema and reference
# data based on the definitions under src/main/resources/db/changelog.
# Comment out this section if you do not need Liquibase.
# Note that the variables used here will be injected into the deployment
# automatically when you deploy with oractl or the IDE plugins.
liquibase:
change-log: classpath:db/changelog/controller.yaml
url: ${spring.datasource.url}
user: ${liquibase.datasource.username}
password: ${liquibase.datasource.password}
enabled: ${LIQUIBASE_ENABLED:true}

# This section configures an Oracle datasource using UCP. You can adjust
# the pool sizing parameters below in the oracleucp section.
# Note that the variables used here will be injected into the deployment
# automatically when you deploy with oractl or the IDE plugins.
datasource:
url: ${spring.datasource.url}
username: ${spring.datasource.username}
password: ${spring.datasource.password}
driver-class-name: oracle.jdbc.OracleDriver
type: oracle.ucp.jdbc.PoolDataSource
oracleucp:
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
connection-pool-name: SpringCLIConnectionPool
initial-pool-size: 15
min-pool-size: 10
max-pool-size: 30
shared: true

# This section configures service discovery using the Spring Cloud Eureka Service
# Registry that is automatically installed and configured in Oracle Backend for
# Spring Boot and Microservices. Note that it must be configured to use IP address
# not hostname since the deployment is in Kubernetes and the hostname allocated to
# pod will not match.
eureka:
instance:
hostname: ${spring.application.name}
preferIpAddress: true
client:
service-url:
defaultZone: ${eureka.service-url}
fetch-registry: true
register-with-eureka: true
enabled: false

# This section configures tracing and metrics
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: "*"
metrics:
tags:
application: ${spring.application.name}
tracing:
sampling:
probability: 1.0
info:
os:
enabled: true
env:
enabled: true
java:
enabled: true
otlp:
tracing:
endpoint: ${otel.exporter.otlp.endpoint}
export:
enabled: false

logging:
level:
root: INFO
com.example: INFO
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Spring Boot application that can be deployed to Oracle Backend for
# Spring Boot and Microservices.
#

spring:
application:
name: restservice
Expand All @@ -19,7 +18,6 @@ spring:
format_sql: true
show-sql: true


# This section configures Liquibase to automate the schema and reference
# data based on the definitions under src/main/resources/db/changelog.
# Comment out this section if you do not need Liquibase.
Expand All @@ -44,7 +42,7 @@ spring:
type: oracle.ucp.jdbc.PoolDataSource
oracleucp:
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
connection-pool-name: CustomerConnectionPool
connection-pool-name: SpringCLIConnectionPool
initial-pool-size: 15
min-pool-size: 10
max-pool-size: 30
Expand All @@ -66,7 +64,7 @@ eureka:
register-with-eureka: true
enabled: true

# This section confiugres
# This section configures tracing and metrics
management:
endpoint:
health:
Expand All @@ -91,6 +89,8 @@ management:
otlp:
tracing:
endpoint: ${otel.exporter.otlp.endpoint}
export:
enabled: true

logging:
level:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- liquibase formatted sql

-- changeset restservice:1 runAlways:true
-- changeset springcliapp:1 runAlways:true
truncate table mytable;

insert into mytable (a,b,c,d)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- liquibase formatted sql

--changeset restservice:1
--preconditions onfail:restservice_ran onerror:restservice_ran
--changeset springcliapp:1
--preconditions onfail:MARK_RAN onerror:MARK_RAN
--precondition-sql-check expectedresult:0 select count(*) from mytable where 1=2
drop table mytable;

--changeset customer:2
--changeset springcliapp:2
create table mytable (
a varchar2 (20),
b varchar2 (40),
Expand Down
Loading