Skip to content

Commit

Permalink
[strimzi#434] fix: after review - partitions and replication_factor p…
Browse files Browse the repository at this point in the history
…arameters set optional

Signed-off-by: ilkerkocatepe <[email protected]>
  • Loading branch information
ilkerkocatepe committed Nov 19, 2024
1 parent d50cb87 commit 4fa81ca
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
88546893f4a6b52b04e3729153f4faea9356730c8facc0930093aa956530d184
bf9a3ec3619b7fe86b6473ec93bb17c589dff7935eacd41636ea071274110d55
14 changes: 7 additions & 7 deletions documentation/book/api/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ Creates a topic with given topic name.
|Name| Description| Required| Default| Pattern

| topicname
| Name of the topic to send records to or retrieve metadata from.
| Name of the topic will be created.
| X
| null
|
Expand All @@ -2331,14 +2331,14 @@ Creates a topic with given topic name.
|Name| Description| Required| Default| Pattern

| partitions
| Number of partitions for the topic.
| X
| Number of partitions for the topic. (Optional)
| -
| null
|

| replication_factor
| Replication factor for the topic.
| X
| Replication factor for the topic. (Optional)
| -
| null
|

Expand Down Expand Up @@ -2369,7 +2369,7 @@ Creates a topic with given topic name.


| 404
| The specified topic was not found.
| The path was not found.
| <<Error>>

|===
Expand Down Expand Up @@ -2645,7 +2645,7 @@ Retrieves the metadata about a given topic.


| 404
| The specified topic was not found.
| The path topic was not found.
| <<Error>>

|===
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/io/strimzi/kafka/bridge/KafkaBridgeAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

Expand Down Expand Up @@ -94,7 +90,7 @@ public CompletionStage<Set<String>> listTopics() {
* @param replicationFactor replication factor
* @return a CompletionStage Void
*/
public CompletionStage<Void> createTopic(String topicName, int partitions, short replicationFactor) {
public CompletionStage<Void> createTopic(String topicName, Optional<Integer> partitions, Optional<Short> replicationFactor) {
LOGGER.trace("Create topic thread {}", Thread.currentThread());
LOGGER.info("Create topic {}, partitions {}, replicationFactor {}", topicName, partitions, replicationFactor);
CompletableFuture<Void> promise = new CompletableFuture<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

Expand Down Expand Up @@ -184,8 +180,10 @@ public void doGetTopic(RoutingContext routingContext) {
*/
public void doCreateTopic(RoutingContext routingContext) {
String topicName = routingContext.pathParam("topicname");
int partitions = Integer.parseInt(routingContext.queryParams().get("partitions"));
short replicationFactor = Short.parseShort(routingContext.queryParams().get("replication_factor"));
Optional<Integer> partitions = Optional.ofNullable(routingContext.queryParams().get("partitions"))
.map(Integer::valueOf);
Optional<Short> replicationFactor = Optional.ofNullable(routingContext.queryParams().get("replication_factor"))
.map(Short::valueOf);

this.kafkaBridgeAdmin.createTopic(topicName, partitions, replicationFactor)
.whenComplete(((topic, exception) -> {
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@
}
},
"404": {
"description": "The specified topic was not found.",
"description": "The path topic was not found.",
"content": {
"application/vnd.kafka.v2+json": {
"schema": {
Expand Down Expand Up @@ -772,7 +772,7 @@
}
},
"404": {
"description": "The specified topic was not found.",
"description": "The path was not found.",
"content": {
"application/vnd.kafka.v2+json": {
"schema": {
Expand All @@ -782,7 +782,7 @@
"response": {
"value": {
"error_code": 404,
"message": "The specified topic was not found."
"message": "The path was not found."
}
}
}
Expand All @@ -795,7 +795,7 @@
{
"name": "topicname",
"in": "path",
"description": "Name of the topic to send records to or retrieve metadata from.",
"description": "Name of the topic will be created.",
"required": true,
"schema": {
"type": "string"
Expand All @@ -804,17 +804,17 @@
{
"name": "partitions",
"in": "query",
"description": "Number of partitions for the topic.",
"required": true,
"description": "Number of partitions for the topic. (Optional)",
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "replication_factor",
"in": "query",
"description": "Replication factor for the topic.",
"required": true,
"description": "Replication factor for the topic. (Optional)",
"required": false,
"schema": {
"type": "integer"
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/openapiv2.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,15 @@
}
},
"404": {
"description": "The specified topic was not found.",
"description": "The path was not found.",
"schema": {
"$ref": "#/definitions/Error"
},
"examples": {
"response": {
"value": {
"error_code": 404,
"message": "The specified topic was not found."
"message": "The path was not found."
}
}
}
Expand All @@ -720,7 +720,7 @@
{
"name": "topicname",
"in": "path",
"description": "Name of the topic to send records to or retrieve metadata from.",
"description": "Name of the topic will be created.",
"required": true,
"schema": {
"type": "string"
Expand All @@ -729,17 +729,17 @@
{
"name": "partitions",
"in": "query",
"description": "Number of partitions for the topic.",
"required": true,
"description": "Number of partitions for the topic. (Optional)",
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "replication_factor",
"in": "query",
"description": "Replication factor for the topic.",
"required": true,
"description": "Replication factor for the topic. (Optional)",
"required": false,
"schema": {
"type": "integer"
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/io/strimzi/kafka/bridge/http/AdminClientIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void setupTopic(VertxTestContext context, String topic, int partitions, int coun

@Test
void createTopicTest(VertxTestContext context) {
// create topic test with 1 partition and 1 replication factor
baseService()
.postRequest("/admin/topics/" + topic)
.addQueryParam("partitions", "1")
Expand All @@ -231,5 +232,18 @@ void createTopicTest(VertxTestContext context) {
});
context.completeNow();
});

// create topic test without partitions and replication factor
baseService()
.postRequest("/admin/topics/" + topic)
.as(BodyCodec.jsonArray())
.send(ar -> {
context.verify(() -> {
assertThat(ar.succeeded(), is(true));
HttpResponse<JsonArray> response = ar.result();
assertThat(response.statusCode(), is(HttpResponseStatus.OK.code()));
});
context.completeNow();
});
}
}

0 comments on commit 4fa81ca

Please sign in to comment.