Skip to content

Commit

Permalink
Update openapi generator plugin (major)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Aug 30, 2024
1 parent 85ea236 commit 9e50b1c
Show file tree
Hide file tree
Showing 30 changed files with 248 additions and 219 deletions.
28 changes: 12 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ dependencies {
implementation(libs.netty.codec.http)
implementation(variantOf(libs.netty.transport.native.epoll) { classifier("linux-x86_64") })
implementation(libs.openCsv)
implementation(libs.jackson.databind.nullable)
}

/* ******************** OpenAPI ******************** */
Expand Down Expand Up @@ -159,24 +160,22 @@ dependencies {
}

val generateHivemqOpenApi by tasks.registering(GenerateTask::class) {
group = "hivemq"
group = "openapi"
generatorName = "java"
inputSpec = hivemqOpenApi.singleFile.path
inputSpec = hivemqOpenApi.elements.map { it.single().asFile.path }
val outputDir = layout.buildDirectory.dir("tmp/$name")
this.outputDir = outputDir.map { it.asFile.absolutePath }
cleanupOutput = true

apiPackage = "com.hivemq.cli.openapi.hivemq"
modelPackage = "com.hivemq.cli.openapi.hivemq"
configOptions.put("dateLibrary", "java8")
modelNamePrefix = "HivemqOpenapi"
configOptions.put("hideGenerationTimestamp", "true")

inputs.file(hivemqOpenApi.elements.map { it.first() }).withPropertyName("inputSpec")
.withPathSensitivity(PathSensitivity.NONE)
val outputSrcDir = layout.buildDirectory.dir("generated/openapi/hivemq/java")
outputs.dir(outputSrcDir).withPropertyName("outputSrcDir")
outputs.cacheIf { true }
doFirst {
outputDir.get().asFile.deleteRecursively()
}

doLast {
outputSrcDir.get().asFile.deleteRecursively()
outputDir.get().asFile.resolve("src/main/java").copyRecursively(outputSrcDir.get().asFile)
Expand All @@ -185,24 +184,21 @@ val generateHivemqOpenApi by tasks.registering(GenerateTask::class) {
}

val generateSwarmOpenApi by tasks.registering(GenerateTask::class) {
group = "swarm"
group = "openapi"
generatorName = "java"
inputSpec = swarmOpenApi.singleFile.path
inputSpec = swarmOpenApi.elements.map { it.single().asFile.path }
val outputDir = layout.buildDirectory.dir("tmp/$name")
this.outputDir = outputDir.map { it.asFile.absolutePath }
cleanupOutput = true

apiPackage = "com.hivemq.cli.openapi.swarm"
modelPackage = "com.hivemq.cli.openapi.swarm"
configOptions.put("dateLibrary", "java8")
configOptions.put("hideGenerationTimestamp", "true")

inputs.file(swarmOpenApi.elements.map { it.first() }).withPropertyName("inputSpec")
.withPathSensitivity(PathSensitivity.NONE)
val outputSrcDir = layout.buildDirectory.dir("generated/openapi/swarm/java")
outputs.dir(outputSrcDir).withPropertyName("outputSrcDir")
outputs.cacheIf { true }
doFirst {
outputDir.get().asFile.deleteRecursively()
}

doLast {
outputSrcDir.get().asFile.deleteRecursively()
val path = apiPackage.get().replace('.', '/')
Expand Down
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ guava = "33.3.0-jre"
hivemq-communityEditionEmbedded = "2024.7"
hivemq-mqttClient = "1.3.3"
hivemq-testcontainer = "2.0.0"
jackson-databind-nullable = "0.2.6"
javaNative = "21.0.2"
javax-annotation-api = "1.3.2"
jetbrains-annotations = "24.1.0"
Expand All @@ -26,7 +27,7 @@ netty = "4.1.112.Final"
okhttp = "4.12.0"
openCsv = "5.9"
picocli = "4.7.6"
swagger-annotations = "1.6.14"
swagger-annotations = "2.2.22"
testcontainers = "1.20.1"
tinylog = "2.7.0"

Expand All @@ -48,6 +49,7 @@ hivemq-communityEditionEmbedded = { module = "com.hivemq:hivemq-community-editio
hivemq-enterprise = { module = "com.hivemq:hivemq-enterprise" }
hivemq-mqttClient = { module = "com.hivemq:hivemq-mqtt-client", version.ref = "hivemq-mqttClient" }
hivemq-swarm = { module = "com.hivemq:hivemq-swarm" }
jackson-databind-nullable = { module = "org.openapitools:jackson-databind-nullable", version.ref = "jackson-databind-nullable" }
javax-annotation-api = { module = "javax.annotation:javax.annotation-api", version.ref = "javax-annotation-api" }
jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" }
jline = { module = "org.jline:jline", version.ref = "jline" }
Expand All @@ -67,7 +69,7 @@ openCsv = { module = "com.opencsv:opencsv", version.ref = "openCsv" }
picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "picocli" }
picocli-shellJline = { module = "info.picocli:picocli-shell-jline3", version.ref = "picocli" }
swagger-annotations = { module = "io.swagger:swagger-annotations", version.ref = "swagger-annotations" }
swagger-annotations = { module = "io.swagger.core.v3:swagger-annotations", version.ref = "swagger-annotations" }
testcontainers = { module = "org.testcontainers:testcontainers", version.ref = "testcontainers" }
testcontainers-hivemq = { module = "org.testcontainers:hivemq", version.ref = "testcontainers" }
testcontainers-junitJupiter = { module = "org.testcontainers:junit-jupiter", version.ref = "testcontainers" }
Expand All @@ -84,5 +86,5 @@ launch4j = { id = "edu.sc.seis.launch4j", version = "3.0.6" }
license = { id = "com.github.hierynomus.license", version = "0.16.1" }
nebula-ospackage = { id = "com.netflix.nebula.ospackage", version = "11.10.0" }
oci = { id = "io.github.sgtsilvio.gradle.oci", version = "0.15.1" }
openapi-generator = { id = "org.openapi.generator", version = "4.3.1" } # >= 5.0.0 breaks the tasks
openapi-generator = { id = "org.openapi.generator", version = "7.8.0" }
shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package com.hivemq.cli.commands.hivemq.export.clients;

import com.hivemq.cli.openapi.hivemq.CertificateInformation;
import com.hivemq.cli.openapi.hivemq.ClientDetails;
import com.hivemq.cli.openapi.hivemq.ClientRestrictions;
import com.hivemq.cli.openapi.hivemq.ConnectionDetails;
import com.hivemq.cli.openapi.hivemq.ProxyInformation;
import com.hivemq.cli.openapi.hivemq.TLV;
import com.hivemq.cli.openapi.hivemq.TlsInformation;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiCertificateInformation;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiClientDetails;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiClientRestrictions;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiConnectionDetails;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiProxyInformation;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiTLV;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiTlsInformation;
import com.opencsv.CSVWriter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -79,14 +79,14 @@ public class ClientDetailsCsvWriterTask implements Runnable {

private final @NotNull AtomicLong writtenClientDetails = new AtomicLong(0);
private final @NotNull CompletableFuture<Void> clientDetailsFuture;
private final @NotNull BlockingQueue<ClientDetails> clientDetailsQueue;
private final @NotNull BlockingQueue<HivemqOpenapiClientDetails> clientDetailsQueue;
private final @NotNull File file;
private final @NotNull CSVWriter csvWriter;
private final @NotNull BufferedWriter bufferedFileWriter;

public ClientDetailsCsvWriterTask(
final @NotNull CompletableFuture<Void> clientDetailsFuture,
final @NotNull BlockingQueue<ClientDetails> clientDetailsQueue,
final @NotNull BlockingQueue<HivemqOpenapiClientDetails> clientDetailsQueue,
final @NotNull File file,
final char lineSeparator,
final char quoteCharacter,
Expand Down Expand Up @@ -116,7 +116,7 @@ public void run() {

while (!clientDetailsFuture.isDone() || !clientDetailsQueue.isEmpty()) {

final ClientDetails clientDetails = clientDetailsQueue.poll(50, TimeUnit.MILLISECONDS);
final HivemqOpenapiClientDetails clientDetails = clientDetailsQueue.poll(50, TimeUnit.MILLISECONDS);

if (clientDetails != null) {
writeRow(clientDetails);
Expand All @@ -139,7 +139,7 @@ private void writeHeader() {
csvWriter.writeNext(EXPORT_CSV_HEADER);
}

private void writeRow(final @NotNull ClientDetails clientDetails) {
private void writeRow(final @NotNull HivemqOpenapiClientDetails clientDetails) {
final List<String> row = new ArrayList<>();
row.add(clientDetails.getId());
row.add(toCsvString(clientDetails.getConnected()));
Expand All @@ -148,21 +148,21 @@ private void writeRow(final @NotNull ClientDetails clientDetails) {
row.add(toCsvString(clientDetails.getMessageQueueSize()));
row.add(toCsvString(clientDetails.getWillPresent()));

final ClientRestrictions restrictions = clientDetails.getRestrictions();
final HivemqOpenapiClientRestrictions restrictions = clientDetails.getRestrictions();
addRestrictions(row, restrictions);

final ConnectionDetails connectionDetails = clientDetails.getConnection();
final HivemqOpenapiConnectionDetails connectionDetails = clientDetails.getConnection();
addConnectionDetails(row, connectionDetails);

csvWriter.writeNext(row.toArray(new String[]{}));
}

private void addConnectionDetails(
final @NotNull List<String> row, final @Nullable ConnectionDetails connectionDetails) {
final @NotNull List<String> row, final @Nullable HivemqOpenapiConnectionDetails connectionDetails) {
if (connectionDetails != null) {
row.add(connectionDetails.getSourceIp());

final ProxyInformation proxyInformation = connectionDetails.getProxyInformation();
final HivemqOpenapiProxyInformation proxyInformation = connectionDetails.getProxyInformation();
addProxyInformation(row, proxyInformation);

row.add(connectionDetails.getMqttVersion());
Expand All @@ -180,7 +180,7 @@ private void addConnectionDetails(

row.add(toCsvString(connectionDetails.getCleanStart()));

final TlsInformation tlsInformation = connectionDetails.getTlsInformation();
final HivemqOpenapiTlsInformation tlsInformation = connectionDetails.getTlsInformation();
addTlsInformation(row, tlsInformation);
} else {
row.add(null); // Ip
Expand All @@ -196,12 +196,14 @@ private void addConnectionDetails(
}
}

private void addTlsInformation(final @NotNull List<String> row, final @Nullable TlsInformation tlsInformation) {
private void addTlsInformation(
final @NotNull List<String> row, final @Nullable HivemqOpenapiTlsInformation tlsInformation) {
if (tlsInformation != null) {
row.add(tlsInformation.getCipherSuite());
row.add(tlsInformation.getTlsVersion());

final CertificateInformation certificateInformation = tlsInformation.getCertificateInformation();
final HivemqOpenapiCertificateInformation certificateInformation =
tlsInformation.getCertificateInformation();
addCertificateInformation(row, certificateInformation);
} else {
row.add(null); // cipherSuite
Expand All @@ -211,7 +213,8 @@ private void addTlsInformation(final @NotNull List<String> row, final @Nullable
}

private void addCertificateInformation(
final @NotNull List<String> row, final @Nullable CertificateInformation certificateInformation) {
final @NotNull List<String> row,
final @Nullable HivemqOpenapiCertificateInformation certificateInformation) {
if (certificateInformation != null) {
row.add(certificateInformation.getCommonName());
row.add(certificateInformation.getOrganization());
Expand All @@ -234,17 +237,17 @@ private void addCertificateInformation(
}

private void addProxyInformation(
final @NotNull List<String> row, final @Nullable ProxyInformation proxyInformation) {
final @NotNull List<String> row, final @Nullable HivemqOpenapiProxyInformation proxyInformation) {
if (proxyInformation != null) {
row.add(proxyInformation.getSourceIp());
row.add(toCsvString(proxyInformation.getSourcePort()));
row.add(proxyInformation.getDestinationIp());
row.add(toCsvString(proxyInformation.getDestinationPort()));

final List<TLV> tlvs = proxyInformation.getTlvs();
final List<HivemqOpenapiTLV> tlvs = proxyInformation.getTlvs();
if (tlvs != null) {
final StringBuilder sb = new StringBuilder();
for (final TLV tlv : tlvs) {
for (final HivemqOpenapiTLV tlv : tlvs) {
sb.append(tlv.getKey()).append("=");
final String value = tlv.getValue();
if (value != null) {
Expand All @@ -265,7 +268,8 @@ private void addProxyInformation(
}
}

private void addRestrictions(final @NotNull List<String> row, final @Nullable ClientRestrictions restrictions) {
private void addRestrictions(
final @NotNull List<String> row, final @Nullable HivemqOpenapiClientRestrictions restrictions) {
if (restrictions != null) {
row.add(toCsvString(restrictions.getMaxMessageSize()));
row.add(toCsvString(restrictions.getMaxQueueSize()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.hivemq.cli.openapi.ApiCallback;
import com.hivemq.cli.openapi.ApiException;
import com.hivemq.cli.openapi.hivemq.ClientDetails;
import com.hivemq.cli.openapi.hivemq.ClientItem;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiClientDetails;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiClientItem;
import com.hivemq.cli.openapi.hivemq.MqttClientsApi;
import org.jetbrains.annotations.NotNull;
import org.tinylog.Logger;
Expand All @@ -40,15 +40,15 @@ public class ClientDetailsRetrieverTask implements Runnable {
private final @NotNull MqttClientsApi mqttClientsApi;
private final @NotNull CompletableFuture<Void> clientIdsFuture;
private final @NotNull BlockingQueue<String> clientIdsQueue;
private final @NotNull BlockingQueue<ClientDetails> clientDetailsQueue;
private final @NotNull BlockingQueue<HivemqOpenapiClientDetails> clientDetailsQueue;
private final @NotNull Semaphore clientDetailsInProgress;
private final @NotNull AtomicBoolean failed = new AtomicBoolean(false);

public ClientDetailsRetrieverTask(
final @NotNull MqttClientsApi mqttClientsApi,
final @NotNull CompletableFuture<Void> clientIdsFuture,
final @NotNull BlockingQueue<String> clientIdsQueue,
final @NotNull BlockingQueue<ClientDetails> clientDetailsQueue) {
final @NotNull BlockingQueue<HivemqOpenapiClientDetails> clientDetailsQueue) {
this.mqttClientsApi = mqttClientsApi;
this.clientIdsFuture = clientIdsFuture;
this.clientIdsQueue = clientIdsQueue;
Expand Down Expand Up @@ -83,14 +83,14 @@ public void run() {
Logger.debug("Finished retrieving client details");
}

private static class ClientItemApiCallback implements ApiCallback<ClientItem> {
private static class ClientItemApiCallback implements ApiCallback<HivemqOpenapiClientItem> {

private final @NotNull BlockingQueue<ClientDetails> clientDetailsQueue;
private final @NotNull BlockingQueue<HivemqOpenapiClientDetails> clientDetailsQueue;
private final @NotNull Semaphore clientDetailsInProgress;
private final @NotNull AtomicBoolean failed;

public ClientItemApiCallback(
final @NotNull BlockingQueue<ClientDetails> clientDetailsQueue,
final @NotNull BlockingQueue<HivemqOpenapiClientDetails> clientDetailsQueue,
final @NotNull Semaphore clientDetailsInProgress,
final @NotNull AtomicBoolean failed) {
this.clientDetailsQueue = clientDetailsQueue;
Expand All @@ -100,10 +100,10 @@ public ClientItemApiCallback(

@Override
public void onSuccess(
final @NotNull ClientItem result,
final @NotNull HivemqOpenapiClientItem result,
final int statusCode,
final @NotNull Map<String, List<String>> responseHeaders) {
final ClientDetails clientDetails = result.getClient();
final HivemqOpenapiClientDetails clientDetails = result.getClient();
if (clientDetails != null) {
try {
clientDetailsQueue.put(clientDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.hivemq.cli.commands.hivemq.export.clients;

import com.hivemq.cli.openapi.hivemq.Client;
import com.hivemq.cli.openapi.hivemq.ClientList;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiClient;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiClientList;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiPaginationCursor;
import com.hivemq.cli.openapi.hivemq.MqttClientsApi;
import com.hivemq.cli.openapi.hivemq.PaginationCursor;
import org.jetbrains.annotations.NotNull;
import org.tinylog.Logger;

Expand Down Expand Up @@ -50,14 +50,14 @@ public void run() {
String nextCursor = null;
try {
while (hasNextCursor) {
final ClientList clientList;
final HivemqOpenapiClientList clientList;
clientList = mqttClientsApi.getAllMqttClients(2500, nextCursor);
final List<Client> clients = clientList.getItems();
final PaginationCursor links = clientList.getLinks();
final List<HivemqOpenapiClient> clients = clientList.getItems();
final HivemqOpenapiPaginationCursor links = clientList.getLinks();

if (clients != null) {
receivedClientIds += clients.size();
for (final Client client : clients) {
for (final HivemqOpenapiClient client : clients) {
if (client.getId() != null) {
clientIdsQueue.put(client.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.google.gson.JsonParser;
import com.hivemq.cli.MqttCLIMain;
import com.hivemq.cli.openapi.ApiException;
import com.hivemq.cli.openapi.hivemq.ClientDetails;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiClientDetails;
import com.hivemq.cli.openapi.hivemq.MqttClientsApi;
import com.hivemq.cli.rest.HiveMQRestService;
import com.hivemq.cli.utils.LoggerUtils;
Expand Down Expand Up @@ -162,7 +162,8 @@ public ExportClientsCommand() {
// Setup rest service and queues
final MqttClientsApi mqttClientsApi = new HiveMQRestService().getMqttClientsApi(url, rateLimit);
final BlockingQueue<String> clientIdsQueue = new LinkedBlockingQueue<>(CLIENT_IDS_QUEUE_LIMIT);
final BlockingQueue<ClientDetails> clientDetailsQueue = new LinkedBlockingQueue<>(CLIENT_DETAILS_QUEUE_LIMIT);
final BlockingQueue<HivemqOpenapiClientDetails> clientDetailsQueue =
new LinkedBlockingQueue<>(CLIENT_DETAILS_QUEUE_LIMIT);

Logger.info("Starting export of client details for HiveMQ at {}", url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.hivemq.cli.converters.FunctionTypeConverter;
import com.hivemq.cli.hivemq.scripts.CreateScriptTask;
import com.hivemq.cli.openapi.hivemq.DataHubScriptsApi;
import com.hivemq.cli.openapi.hivemq.Script;
import com.hivemq.cli.openapi.hivemq.HivemqOpenapiScript;
import com.hivemq.cli.rest.HiveMQRestService;
import org.jetbrains.annotations.NotNull;
import org.tinylog.Logger;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class ScriptCreateCommand implements Callable<Integer> {
required = true,
converter = FunctionTypeConverter.class,
description = "The function type")
private @NotNull Script.FunctionTypeEnum functionType;
private @NotNull HivemqOpenapiScript.FunctionTypeEnum functionType;

@SuppressWarnings("unused")
@CommandLine.Option(names = {"--print-version"},
Expand Down
Loading

0 comments on commit 9e50b1c

Please sign in to comment.