Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kafka Dev UI Fixes #30135

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const api = '/q/dev/io.quarkus.quarkus-kafka-client/kafka-admin';
export const api = () => {
let path = window.location.pathname
return path.replace('/kafka-dev-ui', '/kafka-admin')
}
export const ui = 'kafka-ui';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {api} from "../config.js"

export function doPost(data, successCallback, errorCallback) {
$.ajax({
url: api,
url: api(),
type: 'POST',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public void handlePost(RoutingContext event) {
endResponse(event, BAD_REQUEST, "Request body is null");
return;
}
var body = event.body().asJsonObject();
var webUtils = kafkaWebUiUtils();
var body = webUtils.fromJson(event.body().buffer());
if (body == null) {
endResponse(event, BAD_REQUEST, "Request JSON body is null");
return;
Expand All @@ -34,7 +35,6 @@ public void handlePost(RoutingContext event) {
var message = "OK";
var error = "";

var webUtils = kafkaWebUiUtils();
var adminClient = kafkaAdminClient();

boolean res = false;
Expand All @@ -50,7 +50,7 @@ public void handlePost(RoutingContext event) {
res = true;
break;
case "createTopic":
var topicCreateRq = event.body().asPojo(KafkaCreateTopicRequest.class);
var topicCreateRq = webUtils.fromJson(event.body().buffer(), KafkaCreateTopicRequest.class);
res = adminClient.createTopic(topicCreateRq);
message = webUtils.toJson(webUtils.getTopics());
break;
Expand All @@ -64,17 +64,17 @@ public void handlePost(RoutingContext event) {
res = true;
break;
case "topicMessages":
var msgRequest = event.body().asPojo(KafkaMessagesRequest.class);
var msgRequest = webUtils.fromJson(event.body().buffer(), KafkaMessagesRequest.class);
message = webUtils.toJson(webUtils.getMessages(msgRequest));
res = true;
break;
case "getOffset":
var request = event.body().asPojo(KafkaOffsetRequest.class);
var request = webUtils.fromJson(event.body().buffer(), KafkaOffsetRequest.class);
message = webUtils.toJson(webUtils.getOffset(request));
res = true;
break;
case "createMessage":
var rq = event.body().asPojo(KafkaMessageCreateRequest.class);
var rq = webUtils.fromJson(event.body().buffer(), KafkaMessageCreateRequest.class);
webUtils.createMessage(rq);
message = "{}";
res = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static io.quarkus.kafka.client.runtime.ui.util.ConsumerFactory.createConsumer;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -21,19 +23,23 @@
import org.apache.kafka.common.Node;
import org.apache.kafka.common.TopicPartition;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;

import io.netty.buffer.ByteBufInputStream;
import io.quarkus.kafka.client.runtime.KafkaAdminClient;
import io.quarkus.kafka.client.runtime.ui.model.Order;
import io.quarkus.kafka.client.runtime.ui.model.request.KafkaMessageCreateRequest;
import io.quarkus.kafka.client.runtime.ui.model.request.KafkaMessagesRequest;
import io.quarkus.kafka.client.runtime.ui.model.request.KafkaOffsetRequest;
import io.quarkus.kafka.client.runtime.ui.model.response.*;
import io.smallrye.common.annotation.Identifier;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;

@Singleton
public class KafkaUiUtils {
Expand Down Expand Up @@ -229,9 +235,22 @@ public String toJson(Object o) {
try {
res = objectMapper.writeValueAsString(o);
} catch (JsonProcessingException ex) {
//FIXME:
res = "";
}
return res;
}

public JsonObject fromJson(Buffer buffer) {
return new JsonObject(fromJson(buffer, Map.class));
}

public <T> T fromJson(Buffer buffer, Class<T> type) {
try {
JsonParser parser = objectMapper.createParser((InputStream) new ByteBufInputStream(buffer.getByteBuf()));
return objectMapper.readValue(parser, type);
} catch (IOException e) {
return null;
}
}

}
5 changes: 5 additions & 0 deletions integration-tests/devmode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<artifactId>quarkus-grpc-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kafka-client-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-qute-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.test.devconsole;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

/**
* Note that this test cannot be placed under the relevant {@code -deployment} module because then the DEV UI processor would
* not be able to locate the template resources correctly.
*/
public class DevConsoleKafkaSmokeTest {

@RegisterExtension
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
.withApplicationRoot(
(jar) -> jar.addAsResource(new StringAsset("quarkus.http.root-path=testing"), "application.properties"));

@Test
public void testServices() {
RestAssured.get("testing/q/dev/io.quarkus.quarkus-kafka-client/kafka-dev-ui")
.then()
.statusCode(200).body(Matchers.containsString("Kafka Dev UI"));
}

}