Skip to content

Commit

Permalink
Add TLS support (#67)
Browse files Browse the repository at this point in the history
* Add TLS support

Signed-off-by: Sanjula Ganepola <[email protected]>

* Add additional constructors for DaemonServer object

Signed-off-by: Sanjula Ganepola <[email protected]>

* Fix existing tests

Signed-off-by: Sanjula Ganepola <[email protected]>

* Use custom key store and custom trust manager when CA provided

Signed-off-by: Sanjula Ganepola <[email protected]>

* Add TLS test cases

Signed-off-by: Sanjula Ganepola <[email protected]>

* Fix java doc

Signed-off-by: Sanjula Ganepola <[email protected]>

* Fix exception check

Signed-off-by: Sanjula Ganepola <[email protected]>

* Fix exception tests

Signed-off-by: Sanjula Ganepola <[email protected]>

* Fix connect test

Signed-off-by: Sanjula Ganepola <[email protected]>

* Make exception tests more generic to work on multiple systems

Signed-off-by: Sanjula Ganepola <[email protected]>

* remove test

Signed-off-by: Sanjula Ganepola <[email protected]>

* Fix checkstyle errors

Signed-off-by: Sanjula Ganepola <[email protected]>

* Temporarily log error

Signed-off-by: Sanjula Ganepola <[email protected]>

* Remove log

Signed-off-by: Sanjula Ganepola <[email protected]>

* Configure java doc plugin

Signed-off-by: Sanjula Ganepola <[email protected]>

* Use mvn clean package

Signed-off-by: Sanjula Ganepola <[email protected]>

---------

Signed-off-by: Sanjula Ganepola <[email protected]>
  • Loading branch information
SanjulaGanepola authored Dec 9, 2024
1 parent 572ea61 commit 87d0d71
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 454 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
sed -i 's/^IBMI_PORT=/IBMI_PORT=${{ secrets.IBMI_PORT }}/' ${{ env.CONFIG_PROPERTIES }}
- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn --batch-mode clean package --file pom.xml

- name: Update Dependency Graph
uses: advanced-security/maven-dependency-submission-action@v4
1 change: 1 addition & 0 deletions checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<suppress files=".*" checks="ImportOrder" />
<suppress files=".*" checks="IllegalCatch" />
<suppress files=".*" checks="HideUtilityClassConstructor" />
<suppress files=".*" checks="OperatorWrap" />
<suppress files="Test.java$" checks="LineLength" />
</suppressions>
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<doclint>all,-missing</doclint>
</configuration>
</plugin>
</plugins>
</reporting>
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/io/github/mapepire_ibmi/NoAuthTrustManager.java

This file was deleted.

156 changes: 11 additions & 145 deletions src/main/java/io/github/mapepire_ibmi/Pool.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package io.github.mapepire_ibmi;

import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;

import io.github.mapepire_ibmi.types.JobStatus;
import io.github.mapepire_ibmi.types.PoolAddOptions;
import io.github.mapepire_ibmi.types.PoolOptions;
import io.github.mapepire_ibmi.types.QueryOptions;
import io.github.mapepire_ibmi.types.QueryResult;
import io.github.mapepire_ibmi.types.exceptions.ClientException;
import io.github.mapepire_ibmi.types.exceptions.UnknownServerException;

/**
* Represents a connection pool for managing SQL jobs.
Expand Down Expand Up @@ -59,21 +50,8 @@ public Pool(PoolOptions options) {
* size.
*
* @return A CompletableFuture that resolves when all jobs have been created.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
* @throws ClientException
*/
public CompletableFuture<Void> init()
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException,
ClientException {
public CompletableFuture<Void> init() throws Exception {
if (this.options.getMaxSize() <= 0) {
throw new ClientException("Max size must be greater than 0");
} else if (this.options.getStartingSize() <= 0) {
Expand Down Expand Up @@ -126,19 +104,8 @@ public void cleanup() {
* Add a new job to the pool.
*
* @return A CompletableFuture that resolves to the new job.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public CompletableFuture<SqlJob> addJob()
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public CompletableFuture<SqlJob> addJob() throws Exception {
PoolAddOptions poolAddOptions = new PoolAddOptions();
return this.addJob(poolAddOptions);
}
Expand All @@ -148,19 +115,8 @@ public CompletableFuture<SqlJob> addJob()
*
* @param options Options for configuring an addition to the connection pool.
* @return A CompletableFuture that resolves to the new job.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public CompletableFuture<SqlJob> addJob(PoolAddOptions options)
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public CompletableFuture<SqlJob> addJob(PoolAddOptions options) throws Exception {
if (options.getExistingJob() != null) {
cleanup();
}
Expand Down Expand Up @@ -201,19 +157,8 @@ public SqlJob getReadyJob() {
* full but all jobs are busy.
*
* @return The retrieved job.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public synchronized SqlJob getJob()
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public synchronized SqlJob getJob() throws Exception {
SqlJob job = this.getReadyJob();
if (job == null) {
// This code finds a job that is busy, but has the least requests on the queue
Expand Down Expand Up @@ -241,19 +186,8 @@ public synchronized SqlJob getJob()
* otherwise, it may create a new job if the pool is not full.
*
* @return A CompletableFuture that resolves to a ready job.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public CompletableFuture<SqlJob> waitForJob()
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public CompletableFuture<SqlJob> waitForJob() throws Exception {
return this.waitForJob(false);
}

Expand All @@ -264,19 +198,8 @@ public CompletableFuture<SqlJob> waitForJob()
* @param useNewJob Whether a new job should be created even if the pool is
* full.
* @return A CompletableFuture that resolves to a ready job.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public CompletableFuture<SqlJob> waitForJob(boolean useNewJob)
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public CompletableFuture<SqlJob> waitForJob(boolean useNewJob) throws Exception {
SqlJob job = getReadyJob();

if (job == null) {
Expand All @@ -298,19 +221,8 @@ public CompletableFuture<SqlJob> waitForJob(boolean useNewJob)
* the pool.
*
* @return A CompletableFuture that resolves to a ready job or a new job.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public CompletableFuture<SqlJob> popJob()
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public CompletableFuture<SqlJob> popJob() throws Exception {
// TODO: dead code: what to do with it?
SqlJob readyJob = getReadyJob();
if (readyJob != null) {
Expand All @@ -329,19 +241,8 @@ public CompletableFuture<SqlJob> popJob()
*
* @param sql The SQL query.
* @return A new Query instance.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public Query query(String sql)
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public Query query(String sql) throws Exception {
QueryOptions queryOptions = new QueryOptions();
return this.query(sql, queryOptions);
}
Expand All @@ -352,19 +253,8 @@ public Query query(String sql)
* @param sql The SQL query.
* @param opts The options for configuring the query.
* @return A new Query instance.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public Query query(String sql, QueryOptions opts)
throws JsonMappingException, KeyManagementException, JsonProcessingException, NoSuchAlgorithmException,
InterruptedException, ExecutionException, URISyntaxException, SQLException, UnknownServerException {
public Query query(String sql, QueryOptions opts) throws Exception {
SqlJob job = this.getJob();
return job.query(sql, opts);
}
Expand All @@ -375,20 +265,8 @@ public Query query(String sql, QueryOptions opts)
* @param <T> The type of data to be returned.
* @param sql The SQL command to execute.
* @return A CompletableFuture that resolves to the query result.
* @throws ClientException
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
*/
public <T> CompletableFuture<QueryResult<T>> execute(String sql) throws JsonMappingException,
KeyManagementException, JsonProcessingException, NoSuchAlgorithmException, InterruptedException,
ExecutionException, URISyntaxException, SQLException, UnknownServerException, ClientException {
public <T> CompletableFuture<QueryResult<T>> execute(String sql) throws Exception {
QueryOptions queryOptions = new QueryOptions();
return this.execute(sql, queryOptions);
}
Expand All @@ -400,20 +278,8 @@ public <T> CompletableFuture<QueryResult<T>> execute(String sql) throws JsonMapp
* @param sql The SQL command to execute.
* @param opts The options for configuring the query.
* @return A CompletableFuture that resolves to the query result.
* @throws UnknownServerException
* @throws SQLException
* @throws URISyntaxException
* @throws ExecutionException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws JsonProcessingException
* @throws KeyManagementException
* @throws JsonMappingException
* @throws ClientException
*/
public <T> CompletableFuture<QueryResult<T>> execute(String sql, QueryOptions opts) throws JsonMappingException,
KeyManagementException, JsonProcessingException, NoSuchAlgorithmException, InterruptedException,
ExecutionException, URISyntaxException, SQLException, UnknownServerException, ClientException {
public <T> CompletableFuture<QueryResult<T>> execute(String sql, QueryOptions opts) throws Exception {
SqlJob job = this.getJob();
return job.execute(sql, opts);
}
Expand Down
Loading

0 comments on commit 87d0d71

Please sign in to comment.