Skip to content

Commit a801db3

Browse files
authored
Merge pull request #2 from petruki/main
Improved CI workflow to build, test (matrix), push server Docker img
2 parents 4f61236 + 8b9ee64 commit a801db3

20 files changed

+340
-177
lines changed

.github/workflows/docker-build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow builds and pushes the Docker image for the OJP server.
2+
name: OJP Server Docker Image Build
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
tag:
8+
description: 'Docker image tag'
9+
required: true
10+
default: 'latest'
11+
repository:
12+
description: 'Repository name'
13+
required: true
14+
default: 'rrobetti'
15+
jobs:
16+
build-docker-image:
17+
name: Build Docker Image
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Git checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up JDK 22
27+
uses: actions/setup-java@v4
28+
with:
29+
java-version: 22
30+
distribution: 'temurin'
31+
cache: maven
32+
33+
- name: Build and push Docker image
34+
env:
35+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
36+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
37+
DOCKERHUB_REPO: ${{ github.event.inputs.repository }}
38+
run: |
39+
mvn compile jib:build -pl ojp-server \
40+
-Djib.to.auth.username="${DOCKERHUB_USER}" \
41+
-Djib.to.auth.password="${DOCKERHUB_TOKEN}" \
42+
-Djib.to.image="${DOCKERHUB_REPO}/ojp:${{ github.event.inputs.tag }}" \
43+
-Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \
44+
-Djib.container.ports=1059

.github/workflows/main-docker.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow builds and pushes the Docker image for the OJP server.
2+
# It should only trigger when there are changes in the `ojp-server` or `ojp-grpc-commons` modules.
3+
name: Main OJP Server Docker Image CI
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
paths:
9+
- '.github/workflows/main-docker.yml'
10+
- 'ojp-server/**'
11+
- 'ojp-grpc-commons/**'
12+
13+
jobs:
14+
build-docker-image:
15+
name: Build Docker Image
16+
runs-on: ubuntu-latest
17+
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
18+
19+
steps:
20+
- name: Git checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Set up JDK 22
26+
uses: actions/setup-java@v4
27+
with:
28+
java-version: 22
29+
distribution: 'temurin'
30+
cache: maven
31+
32+
- name: Build and push Docker image
33+
env:
34+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
35+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
36+
DOCKERHUB_REPO: ${{ vars.DOCKERHUB_REPO }}
37+
run: |
38+
mvn compile jib:build -pl ojp-server \
39+
-Dimage="${DOCKERHUB_REPO}:latest" \
40+
-Djib.to.auth.username="${DOCKERHUB_USER}" \
41+
-Djib.to.auth.password="${DOCKERHUB_TOKEN}" \
42+
-Djib.to.image="${DOCKERHUB_REPO}/ojp:latest" \
43+
-Djib.container.mainClass="org.openjdbcproxy.grpc.server.GrpcServer" \
44+
-Djib.container.ports=1059

.github/workflows/main.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ jobs:
1414
name: Build & Test
1515
runs-on: ubuntu-latest
1616
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
java-version: [ 11, 17, 21, 22 ]
1721

1822
services:
1923
postgres:
@@ -36,18 +40,34 @@ jobs:
3640
with:
3741
fetch-depth: 0
3842

39-
- name: Set up JDK 22
43+
- name: Set up JDK 22 for ojp-server
4044
uses: actions/setup-java@v4
4145
with:
4246
java-version: 22
4347
distribution: 'temurin'
4448
cache: maven
4549

46-
- name: Build
50+
- name: Build (ojp-server)
4751
run: mvn clean install -DskipTests
4852

49-
- name: Run ojp-server
53+
- name: Test (ojp-server)
54+
run: mvn test -pl ojp-server
55+
56+
- name: Run (ojp-server)
5057
run: mvn verify -pl ojp-server -Prun-ojp-server > ojp-server.log 2>&1 &
5158

52-
- name: Run tests
53-
run: mvn test
59+
- name: Wait for ojp-server to start
60+
run: sleep 10
61+
62+
- name: Set up JDK ${{ matrix.java-version }} for ojp-grpc-commons and ojp-jdbc-driver
63+
uses: actions/setup-java@v4
64+
with:
65+
java-version: ${{ matrix.java-version }}
66+
distribution: 'temurin'
67+
cache: maven
68+
69+
- name: Build (ojp-grpc-commons, ojp-jdbc-driver)
70+
run: mvn clean install -pl ojp-grpc-commons,ojp-jdbc-driver -DskipTests
71+
72+
- name: Test (ojp-grpc-commons, ojp-jdbc-driver)
73+
run: mvn test -pl ojp-grpc-commons,ojp-jdbc-driver

ojp-grpc-commons/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
</parent>
1616

1717
<properties>
18+
<maven.compiler.source>11</maven.compiler.source>
19+
<maven.compiler.target>11</maven.compiler.target>
20+
1821
<grpc.version>1.73.0</grpc.version>
1922
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
2023
<lombok.version>1.18.38</lombok.version>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<parent>
4+
<artifactId>ojp-parent</artifactId>
5+
<groupId>org.openjdbcproxy</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
<artifactId>ojp-jdbc-driver</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<artifactId>maven-surefire-plugin</artifactId>
15+
<version>3.2.5</version>
16+
<configuration>
17+
<runOrder>alphabetical</runOrder>
18+
</configuration>
19+
</plugin>
20+
<plugin>
21+
<artifactId>maven-shade-plugin</artifactId>
22+
<version>3.5.1</version>
23+
<executions>
24+
<execution>
25+
<phase>package</phase>
26+
<goals>
27+
<goal>shade</goal>
28+
</goals>
29+
<configuration>
30+
<createDependencyReducedPom>true</createDependencyReducedPom>
31+
<transformers>
32+
<transformer />
33+
<transformer />
34+
</transformers>
35+
</configuration>
36+
</execution>
37+
</executions>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.projectlombok</groupId>
44+
<artifactId>lombok</artifactId>
45+
<version>1.18.38</version>
46+
<scope>provided</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>junit</groupId>
50+
<artifactId>junit</artifactId>
51+
<version>4.13.2</version>
52+
<scope>test</scope>
53+
<exclusions>
54+
<exclusion>
55+
<artifactId>hamcrest-core</artifactId>
56+
<groupId>org.hamcrest</groupId>
57+
</exclusion>
58+
</exclusions>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.h2database</groupId>
62+
<artifactId>h2</artifactId>
63+
<version>2.3.232</version>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter</artifactId>
69+
<version>5.12.1</version>
70+
<scope>test</scope>
71+
<exclusions>
72+
<exclusion>
73+
<artifactId>junit-jupiter-api</artifactId>
74+
<groupId>org.junit.jupiter</groupId>
75+
</exclusion>
76+
<exclusion>
77+
<artifactId>junit-jupiter-engine</artifactId>
78+
<groupId>org.junit.jupiter</groupId>
79+
</exclusion>
80+
</exclusions>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.junit.jupiter</groupId>
84+
<artifactId>junit-jupiter-params</artifactId>
85+
<version>5.12.1</version>
86+
<scope>test</scope>
87+
<exclusions>
88+
<exclusion>
89+
<artifactId>apiguardian-api</artifactId>
90+
<groupId>org.apiguardian</groupId>
91+
</exclusion>
92+
<exclusion>
93+
<artifactId>junit-jupiter-api</artifactId>
94+
<groupId>org.junit.jupiter</groupId>
95+
</exclusion>
96+
</exclusions>
97+
</dependency>
98+
</dependencies>
99+
<properties>
100+
<maven.compiler.target>11</maven.compiler.target>
101+
<slf4j.version>2.0.17</slf4j.version>
102+
<maven.compiler.source>11</maven.compiler.source>
103+
</properties>
104+
</project>

ojp-jdbc-driver/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
</parent>
1616

1717
<properties>
18+
<maven.compiler.source>11</maven.compiler.source>
19+
<maven.compiler.target>11</maven.compiler.target>
20+
1821
<slf4j.version>2.0.17</slf4j.version>
1922
</properties>
2023

ojp-jdbc-driver/src/main/java/org/openjdbcproxy/grpc/client/StatementServiceGrpcClient.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ public void onNext(LobReference lobReference) {
204204

205205
@Override
206206
public void onError(Throwable throwable) {
207-
if (throwable instanceof StatusRuntimeException sre) {
207+
if (throwable instanceof StatusRuntimeException) {
208208
try {
209+
StatusRuntimeException sre = (StatusRuntimeException) throwable;
209210
handle(sre);//To convert to SQLException if possible
210211
sfFirstLobReference.setException(sre);
211212
sfFinalLobReference.setException(sre); //When conversion to SQLException not possible
@@ -334,8 +335,8 @@ public void onCompleted() {
334335

335336
//Wait to receive at least one successful block before returning.
336337
if (!sfFirstBlockReceived.get() && errorReceived[0] != null) {
337-
if (errorReceived[0] instanceof Exception e) {
338-
throw e;
338+
if (errorReceived[0] instanceof Exception) {
339+
throw (Exception) errorReceived[0];
339340
} else {
340341
throw new RuntimeException(errorReceived[0]);
341342
}
@@ -401,9 +402,9 @@ public void onNext(SessionTerminationStatus sessionTerminationStatus) {
401402
@Override
402403
public void onError(Throwable throwable) {
403404
Throwable t = throwable;
404-
if (throwable instanceof StatusRuntimeException sre) {
405+
if (throwable instanceof StatusRuntimeException) {
405406
try {
406-
handle(sre);
407+
handle((StatusRuntimeException) throwable);
407408
} catch (SQLException e) {
408409
t = e;
409410
}

ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/LobGrpcIterator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public LobDataBlock next() {
4646
if (this.error != null) {
4747
throw new RuntimeException(this.error);
4848
}
49-
LobDataBlock block = this.blocksReceived.getFirst();
50-
this.blocksReceived.removeFirst();
49+
LobDataBlock block = this.blocksReceived.get(0);
50+
this.blocksReceived.remove(0);
5151
return block;
5252
}
5353

ojp-jdbc-driver/src/main/java/org/openjdbcproxy/jdbc/PreparedStatement.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.sql.Time;
3838
import java.sql.Timestamp;
3939
import java.util.Arrays;
40+
import java.util.ArrayList;
4041
import java.util.Calendar;
4142
import java.util.HashMap;
4243
import java.util.Iterator;
@@ -108,7 +109,7 @@ public ResultSet executeQuery() throws SQLException {
108109
this.checkClosed();
109110
log.info("Executing query for -> {}", this.sql);
110111
Iterator<OpResult> itOpResult = this.statementService
111-
.executeQuery(this.connection.getSession(), this.sql, this.paramsMap.values().stream().toList(), this.properties);
112+
.executeQuery(this.connection.getSession(), this.sql, new ArrayList<>(this.paramsMap.values()), this.properties);
112113
return new ResultSet(itOpResult, this.statementService, this);
113114
}
114115

@@ -117,7 +118,7 @@ public int executeUpdate() throws SQLException {
117118
this.checkClosed();
118119
log.info("Executing update for -> {}", this.sql);
119120
OpResult result = this.statementService.executeUpdate(this.connection.getSession(), this.sql,
120-
this.paramsMap.values().stream().toList(), this.getStatementUUID(), null);
121+
new ArrayList<>(this.paramsMap.values()), this.getStatementUUID(), null);
121122
this.connection.setSession(result.getSession());
122123
return deserialize(result.getValue().toByteArray(), Integer.class);
123124
}
@@ -129,7 +130,7 @@ public void addBatch() throws SQLException {
129130
Map<String, Object> properties = new HashMap<>();
130131
properties.put(CommonConstants.PREPARED_STATEMENT_ADD_BATCH_FLAG, Boolean.TRUE);
131132
OpResult result = this.statementService.executeUpdate(this.connection.getSession(), this.sql,
132-
this.paramsMap.values().stream().toList(), this.getStatementUUID(), properties);
133+
new ArrayList<>(this.paramsMap.values()), this.getStatementUUID(), properties);
133134
this.connection.setSession(result.getSession());
134135
if (StringUtils.isBlank(this.getStatementUUID()) && ResultType.UUID_STRING.equals(result.getType()) &&
135136
!result.getValue().isEmpty()) {
@@ -752,7 +753,7 @@ private <T> T callProxy(CallType callType, String targetName, Class<?> returnTyp
752753
);
753754
CallResourceResponse response = this.statementService.callResource(reqBuilder.build());
754755
this.connection.setSession(response.getSession());
755-
if (this.getStatementUUID() == null && !response.getResourceUUID().isBlank()) {
756+
if (this.getStatementUUID() == null && StringUtils.isNotBlank(response.getResourceUUID())) {
756757
this.setStatementUUID(response.getResourceUUID());
757758
}
758759
if (Void.class.equals(returnType)) {

0 commit comments

Comments
 (0)