Skip to content

Commit 42d2bdb

Browse files
committed
MODHAADM-141 Vertx 5, Okapi 7, folio-vertx-lib 4
Initial changes required for upgrading to vertx 5, including applying the validating handler used in vertx lib 4 though applying non-validating for post/put of plain text and XML, since validation of those seems unsupported by vertx/openapi so far .
1 parent 268f327 commit 42d2bdb

18 files changed

Lines changed: 633 additions & 489 deletions

pom.xml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<version>1.4.2-SNAPSHOT</version>
77
<properties>
88
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
9-
<folio-vertx-lib.version>3.4.0</folio-vertx-lib.version>
10-
<okapi.version>6.2.1</okapi.version>
11-
<vertx.version>4.5.14</vertx.version>
9+
<folio-vertx-lib.version>4.0.0</folio-vertx-lib.version>
10+
<okapi.version>7.0.0</okapi.version>
11+
<vertx.version>5.0.2</vertx.version>
1212
</properties>
1313
<dependencyManagement>
1414
<dependencies>
@@ -36,11 +36,6 @@
3636
<artifactId>okapi-testing</artifactId>
3737
<version>${okapi.version}</version>
3838
</dependency>
39-
<dependency>
40-
<groupId>com.ongres.scram</groupId>
41-
<artifactId>client</artifactId>
42-
<version>2.1</version>
43-
</dependency>
4439
<dependency>
4540
<groupId>org.z3950.zing</groupId>
4641
<artifactId>cql-java</artifactId>
@@ -108,19 +103,19 @@
108103
</dependency>
109104
<dependency>
110105
<groupId>io.vertx</groupId>
111-
<artifactId>vertx-web</artifactId>
106+
<artifactId>vertx-launcher-application</artifactId>
112107
</dependency>
113108
<dependency>
114109
<groupId>io.vertx</groupId>
115-
<artifactId>vertx-web-openapi</artifactId>
110+
<artifactId>vertx-web</artifactId>
116111
</dependency>
117112
<dependency>
118113
<groupId>io.vertx</groupId>
119-
<artifactId>vertx-rx-java2</artifactId>
114+
<artifactId>vertx-web-openapi-router</artifactId>
120115
</dependency>
121116
<dependency>
122117
<groupId>io.vertx</groupId>
123-
<artifactId>vertx-web-api-contract</artifactId>
118+
<artifactId>vertx-rx-java2</artifactId>
124119
</dependency>
125120
<dependency>
126121
<groupId>io.vertx</groupId>
@@ -167,6 +162,16 @@
167162
<artifactId>netty-tcnative-boringssl-static</artifactId>
168163
<scope>runtime</scope>
169164
</dependency>
165+
<dependency>
166+
<groupId>org.apache.commons</groupId>
167+
<artifactId>commons-lang3</artifactId>
168+
<version>3.18.0</version>
169+
</dependency>
170+
<dependency>
171+
<groupId>com.ongres.scram</groupId>
172+
<artifactId>client</artifactId>
173+
<version>2.1</version>
174+
</dependency>
170175
<!-- Test dependencies -->
171176
<dependency>
172177
<groupId>junit</groupId>
@@ -220,6 +225,20 @@
220225
</plugins>
221226
</pluginManagement>
222227
<plugins>
228+
<plugin>
229+
<groupId>org.folio</groupId>
230+
<artifactId>openapi-deref-plugin</artifactId>
231+
<version>4.0.0</version>
232+
<executions>
233+
<execution>
234+
<id>dereference-harvester-admin</id>
235+
<goals>
236+
<goal>dereference</goal>
237+
</goals>
238+
<phase>generate-resources</phase>
239+
</execution>
240+
</executions>
241+
</plugin>
223242
<plugin>
224243
<groupId>org.apache.maven.plugins</groupId>
225244
<artifactId>maven-compiler-plugin</artifactId>
@@ -254,7 +273,7 @@
254273
<configuration>
255274
<useSystemClassLoader>false</useSystemClassLoader>
256275
<environmentVariables>
257-
<harvester_protocal>http</harvester_protocal>
276+
<harvester_protocol>http</harvester_protocol>
258277
<harvester_host>localhost</harvester_host>
259278
<harvester_port>8080</harvester_port>
260279
<acl_filter_by_tenant>false</acl_filter_by_tenant>
@@ -376,7 +395,7 @@
376395
<transformers>
377396
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
378397
<manifestEntries>
379-
<Main-Class>io.vertx.core.Launcher</Main-Class>
398+
<Main-Class>org.folio.okapi.common.MainLauncher</Main-Class>
380399
<Main-Verticle>org.folio.harvesteradmin.MainVerticle</Main-Verticle>
381400
<Multi-Release>true</Multi-Release>
382401
</manifestEntries>

src/main/java/org/folio/harvesteradmin/MainVerticle.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414

1515
public class MainVerticle extends AbstractVerticle {
16+
private static final String MODULE = "mod-harvester-admin";
17+
1618
@Override
1719
public void start(Promise<Void> promise) {
1820

19-
TenantPgPool.setModule("mod-harvester-admin"); // Postgres - schema separation
21+
TenantPgPool.setModule(MODULE); // Postgres - schema separation
2022

2123
// listening port
2224
final int port = Integer.parseInt(Config.getSysConf("http.port", "port", "8081", config()));
@@ -30,11 +32,12 @@ public void start(Promise<Void> promise) {
3032
};
3133
HttpServerOptions so = new HttpServerOptions()
3234
.setHandle100ContinueAutomatically(true);
33-
RouterCreator.mountAll(vertx, routerCreators)
35+
RouterCreator.mountAll(vertx, routerCreators, MODULE)
3436
.compose(router ->
3537
vertx.createHttpServer(so)
3638
.requestHandler(router)
37-
.listen(port).mapEmpty())
39+
.listen(port)
40+
.mapEmpty())
3841
.<Void>mapEmpty()
3942
.onComplete(promise);
4043
}

src/main/java/org/folio/harvesteradmin/legacydata/JobLauncher.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import static org.folio.okapi.common.HttpResponse.responseJson;
55
import static org.folio.okapi.common.HttpResponse.responseText;
66

7-
import io.vertx.core.Vertx;
87
import io.vertx.core.json.JsonObject;
9-
import io.vertx.ext.web.RoutingContext;
8+
import org.folio.harvesteradmin.service.AdminRequest;
9+
1010
import java.text.SimpleDateFormat;
1111
import java.util.Date;
1212
import java.util.TimeZone;
@@ -27,8 +27,8 @@ public class JobLauncher extends LegacyHarvesterStorage {
2727
/**
2828
* Constructor.
2929
*/
30-
public JobLauncher(Vertx vertx, String tenant) {
31-
super(vertx, tenant);
30+
public JobLauncher(AdminRequest adminRequest) {
31+
super(adminRequest.vertx(), adminRequest.tenant());
3232

3333
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
3434
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -37,45 +37,45 @@ public JobLauncher(Vertx vertx, String tenant) {
3737
/**
3838
* Starts a harvest job.
3939
*/
40-
public void startJob(RoutingContext routingContext) {
40+
public void startJob(AdminRequest adminRequest) {
4141

42-
String harvestableId = routingContext.request().getParam("id");
42+
String harvestableId = adminRequest.pathParam("id");
4343
getConfigRecordById(HARVESTER_HARVESTABLES_PATH, harvestableId).onComplete(lookUp -> {
4444
if (lookUp.succeeded()) {
4545
if (lookUp.result().wasNotFound()) {
46-
responseText(routingContext, NOT_FOUND).end(
46+
responseText(adminRequest.routingContext(), NOT_FOUND).end(
4747
"Did not find a harvest configuration with ID " + harvestableId
4848
+ ". No job started.");
4949
} else if (lookUp.result().wasOK() && lookUp.result().jsonObject()
5050
.getString("currentStatus").equals("RUNNING")) {
51-
responseText(routingContext, BAD_REQUEST).end(
51+
responseText(adminRequest.routingContext(), BAD_REQUEST).end(
5252
"A job with this configuration is already running " + lookUp.result().jsonObject()
5353
.getString("name"));
5454
} else if (lookUp.result().wasOK()) {
5555
JsonObject harvestConfig = lookUp.result().jsonObject().copy();
5656
harvestConfig.put(PROP_HARVEST_IMMEDIATELY, TRUE);
5757
harvestConfig.put(PROP_LAST_UPDATED, dateFormat.format(new Date()));
58-
putConfigRecord(routingContext, HARVESTER_HARVESTABLES_PATH, harvestConfig,
58+
putConfigRecord(adminRequest, HARVESTER_HARVESTABLES_PATH, harvestConfig,
5959
harvestableId).onComplete(putResponse -> {
6060
if (putResponse.succeeded()) {
6161
JsonObject responseOk = new JsonObject();
6262
responseOk.put(PROP_HARVESTABLE_ID, harvestableId);
6363
responseOk.put(PROP_NAME, harvestConfig.getString("name"));
6464
responseOk.put(PROP_INITIATED, harvestConfig.getString(PROP_LAST_UPDATED));
65-
responseJson(routingContext, OK).end(responseOk.encodePrettily());
65+
responseJson(adminRequest.routingContext(), OK).end(responseOk.encodePrettily());
6666
} else {
67-
responseText(routingContext, INTERNAL_SERVER_ERROR).end(
67+
responseText(adminRequest.routingContext(), INTERNAL_SERVER_ERROR).end(
6868
"An error occurred when trying to start job " + harvestableId + ": "
6969
+ putResponse.cause().getMessage());
7070
}
7171
});
7272
} else {
73-
responseText(routingContext, lookUp.result().statusCode()).end(
73+
responseText(adminRequest.routingContext(), lookUp.result().statusCode()).end(
7474
"A problem occurred when looking for the job to start:" + lookUp.result()
7575
.errorMessage());
7676
}
7777
} else {
78-
responseText(routingContext, INTERNAL_SERVER_ERROR).end(
78+
responseText(adminRequest.routingContext(), INTERNAL_SERVER_ERROR).end(
7979
"Could not look up harvest configuration. Job not started.");
8080
}
8181
});
@@ -84,43 +84,43 @@ public void startJob(RoutingContext routingContext) {
8484
/**
8585
* Stops a harvest job.
8686
*/
87-
public void stopJob(RoutingContext routingContext) {
88-
String harvestableId = routingContext.request().getParam("id");
87+
public void stopJob(AdminRequest adminRequest) {
88+
String harvestableId = adminRequest.pathParam("id");
8989
getConfigRecordById(HARVESTER_HARVESTABLES_PATH, harvestableId).onComplete(lookUp -> {
9090
if (lookUp.succeeded()) {
9191
if (lookUp.result().wasNotFound()) {
92-
responseText(routingContext, NOT_FOUND).end(
92+
responseText(adminRequest.routingContext(), NOT_FOUND).end(
9393
"Did not find a harvest configuration with ID " + harvestableId
9494
+ ". No job stopped.");
9595
} else if (lookUp.result().wasOK() && !lookUp.result().jsonObject()
9696
.getString("currentStatus").equals("RUNNING")) {
97-
responseText(routingContext, BAD_REQUEST).end(
97+
responseText(adminRequest.routingContext(), BAD_REQUEST).end(
9898
"This configuration has no running job, cannot stop it. " + lookUp.result()
9999
.jsonObject().getString("name"));
100100
} else if (lookUp.result().wasOK()) {
101101
JsonObject harvestConfig = lookUp.result().jsonObject().copy();
102102
harvestConfig.put(PROP_LAST_UPDATED, dateFormat.format(new Date()));
103-
putConfigRecord(routingContext, HARVESTER_HARVESTABLES_PATH, harvestConfig,
103+
putConfigRecord(adminRequest, HARVESTER_HARVESTABLES_PATH, harvestConfig,
104104
harvestableId).onComplete(putResponse -> {
105105
if (putResponse.succeeded()) {
106106
JsonObject responseOk = new JsonObject();
107107
responseOk.put(PROP_HARVESTABLE_ID, harvestableId);
108108
responseOk.put(PROP_NAME, harvestConfig.getString("name"));
109109
responseOk.put(PROP_INITIATED, harvestConfig.getString(PROP_LAST_UPDATED));
110-
responseJson(routingContext, OK).end(responseOk.encodePrettily());
110+
responseJson(adminRequest.routingContext(), OK).end(responseOk.encodePrettily());
111111
} else {
112-
responseText(routingContext, INTERNAL_SERVER_ERROR).end(
112+
responseText(adminRequest.routingContext(), INTERNAL_SERVER_ERROR).end(
113113
"An error occurred when trying to stop job using " + harvestableId + ": "
114114
+ putResponse.cause().getMessage());
115115
}
116116
});
117117
} else {
118-
responseText(routingContext, lookUp.result().statusCode()).end(
118+
responseText(adminRequest.routingContext(), lookUp.result().statusCode()).end(
119119
"A problem occurred when looking for the job to stop:" + lookUp.result()
120120
.errorMessage());
121121
}
122122
} else {
123-
responseText(routingContext, INTERNAL_SERVER_ERROR).end(
123+
responseText(adminRequest.routingContext(), INTERNAL_SERVER_ERROR).end(
124124
"Could not look up harvest configuration. No job stopped.");
125125
}
126126
});

0 commit comments

Comments
 (0)