Skip to content

Commit 4fa81ca

Browse files
committed
[strimzi#434] fix: after review - partitions and replication_factor parameters set optional
Signed-off-by: ilkerkocatepe <[email protected]>
1 parent d50cb87 commit 4fa81ca

File tree

7 files changed

+44
-36
lines changed

7 files changed

+44
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
88546893f4a6b52b04e3729153f4faea9356730c8facc0930093aa956530d184
1+
bf9a3ec3619b7fe86b6473ec93bb17c589dff7935eacd41636ea071274110d55

documentation/book/api/index.adoc

+7-7
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ Creates a topic with given topic name.
23142314
|Name| Description| Required| Default| Pattern
23152315

23162316
| topicname
2317-
| Name of the topic to send records to or retrieve metadata from.
2317+
| Name of the topic will be created.
23182318
| X
23192319
| null
23202320
|
@@ -2331,14 +2331,14 @@ Creates a topic with given topic name.
23312331
|Name| Description| Required| Default| Pattern
23322332

23332333
| partitions
2334-
| Number of partitions for the topic.
2335-
| X
2334+
| Number of partitions for the topic. (Optional)
2335+
| -
23362336
| null
23372337
|
23382338

23392339
| replication_factor
2340-
| Replication factor for the topic.
2341-
| X
2340+
| Replication factor for the topic. (Optional)
2341+
| -
23422342
| null
23432343
|
23442344

@@ -2369,7 +2369,7 @@ Creates a topic with given topic name.
23692369

23702370

23712371
| 404
2372-
| The specified topic was not found.
2372+
| The path was not found.
23732373
| <<Error>>
23742374

23752375
|===
@@ -2645,7 +2645,7 @@ Retrieves the metadata about a given topic.
26452645

26462646

26472647
| 404
2648-
| The specified topic was not found.
2648+
| The path topic was not found.
26492649
| <<Error>>
26502650

26512651
|===

src/main/java/io/strimzi/kafka/bridge/KafkaBridgeAdmin.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
import org.apache.logging.log4j.LogManager;
1818
import org.apache.logging.log4j.Logger;
1919

20-
import java.util.Collections;
21-
import java.util.List;
22-
import java.util.Map;
23-
import java.util.Properties;
24-
import java.util.Set;
20+
import java.util.*;
2521
import java.util.concurrent.CompletableFuture;
2622
import java.util.concurrent.CompletionStage;
2723

@@ -94,7 +90,7 @@ public CompletionStage<Set<String>> listTopics() {
9490
* @param replicationFactor replication factor
9591
* @return a CompletionStage Void
9692
*/
97-
public CompletionStage<Void> createTopic(String topicName, int partitions, short replicationFactor) {
93+
public CompletionStage<Void> createTopic(String topicName, Optional<Integer> partitions, Optional<Short> replicationFactor) {
9894
LOGGER.trace("Create topic thread {}", Thread.currentThread());
9995
LOGGER.info("Create topic {}, partitions {}, replicationFactor {}", topicName, partitions, replicationFactor);
10096
CompletableFuture<Void> promise = new CompletableFuture<>();

src/main/java/io/strimzi/kafka/bridge/http/HttpAdminBridgeEndpoint.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@
2828
import org.apache.logging.log4j.LogManager;
2929
import org.apache.logging.log4j.Logger;
3030

31-
import java.util.Collection;
32-
import java.util.HashSet;
33-
import java.util.List;
34-
import java.util.Map;
35-
import java.util.Set;
31+
import java.util.*;
3632
import java.util.concurrent.CompletableFuture;
3733
import java.util.concurrent.CompletionStage;
3834

@@ -184,8 +180,10 @@ public void doGetTopic(RoutingContext routingContext) {
184180
*/
185181
public void doCreateTopic(RoutingContext routingContext) {
186182
String topicName = routingContext.pathParam("topicname");
187-
int partitions = Integer.parseInt(routingContext.queryParams().get("partitions"));
188-
short replicationFactor = Short.parseShort(routingContext.queryParams().get("replication_factor"));
183+
Optional<Integer> partitions = Optional.ofNullable(routingContext.queryParams().get("partitions"))
184+
.map(Integer::valueOf);
185+
Optional<Short> replicationFactor = Optional.ofNullable(routingContext.queryParams().get("replication_factor"))
186+
.map(Short::valueOf);
189187

190188
this.kafkaBridgeAdmin.createTopic(topicName, partitions, replicationFactor)
191189
.whenComplete(((topic, exception) -> {

src/main/resources/openapi.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@
615615
}
616616
},
617617
"404": {
618-
"description": "The specified topic was not found.",
618+
"description": "The path topic was not found.",
619619
"content": {
620620
"application/vnd.kafka.v2+json": {
621621
"schema": {
@@ -772,7 +772,7 @@
772772
}
773773
},
774774
"404": {
775-
"description": "The specified topic was not found.",
775+
"description": "The path was not found.",
776776
"content": {
777777
"application/vnd.kafka.v2+json": {
778778
"schema": {
@@ -782,7 +782,7 @@
782782
"response": {
783783
"value": {
784784
"error_code": 404,
785-
"message": "The specified topic was not found."
785+
"message": "The path was not found."
786786
}
787787
}
788788
}
@@ -795,7 +795,7 @@
795795
{
796796
"name": "topicname",
797797
"in": "path",
798-
"description": "Name of the topic to send records to or retrieve metadata from.",
798+
"description": "Name of the topic will be created.",
799799
"required": true,
800800
"schema": {
801801
"type": "string"
@@ -804,17 +804,17 @@
804804
{
805805
"name": "partitions",
806806
"in": "query",
807-
"description": "Number of partitions for the topic.",
808-
"required": true,
807+
"description": "Number of partitions for the topic. (Optional)",
808+
"required": false,
809809
"schema": {
810810
"type": "integer"
811811
}
812812
},
813813
{
814814
"name": "replication_factor",
815815
"in": "query",
816-
"description": "Replication factor for the topic.",
817-
"required": true,
816+
"description": "Replication factor for the topic. (Optional)",
817+
"required": false,
818818
"schema": {
819819
"type": "integer"
820820
}

src/main/resources/openapiv2.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,15 @@
701701
}
702702
},
703703
"404": {
704-
"description": "The specified topic was not found.",
704+
"description": "The path was not found.",
705705
"schema": {
706706
"$ref": "#/definitions/Error"
707707
},
708708
"examples": {
709709
"response": {
710710
"value": {
711711
"error_code": 404,
712-
"message": "The specified topic was not found."
712+
"message": "The path was not found."
713713
}
714714
}
715715
}
@@ -720,7 +720,7 @@
720720
{
721721
"name": "topicname",
722722
"in": "path",
723-
"description": "Name of the topic to send records to or retrieve metadata from.",
723+
"description": "Name of the topic will be created.",
724724
"required": true,
725725
"schema": {
726726
"type": "string"
@@ -729,17 +729,17 @@
729729
{
730730
"name": "partitions",
731731
"in": "query",
732-
"description": "Number of partitions for the topic.",
733-
"required": true,
732+
"description": "Number of partitions for the topic. (Optional)",
733+
"required": false,
734734
"schema": {
735735
"type": "integer"
736736
}
737737
},
738738
{
739739
"name": "replication_factor",
740740
"in": "query",
741-
"description": "Replication factor for the topic.",
742-
"required": true,
741+
"description": "Replication factor for the topic. (Optional)",
742+
"required": false,
743743
"schema": {
744744
"type": "integer"
745745
}

src/test/java/io/strimzi/kafka/bridge/http/AdminClientIT.java

+14
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void setupTopic(VertxTestContext context, String topic, int partitions, int coun
218218

219219
@Test
220220
void createTopicTest(VertxTestContext context) {
221+
// create topic test with 1 partition and 1 replication factor
221222
baseService()
222223
.postRequest("/admin/topics/" + topic)
223224
.addQueryParam("partitions", "1")
@@ -231,5 +232,18 @@ void createTopicTest(VertxTestContext context) {
231232
});
232233
context.completeNow();
233234
});
235+
236+
// create topic test without partitions and replication factor
237+
baseService()
238+
.postRequest("/admin/topics/" + topic)
239+
.as(BodyCodec.jsonArray())
240+
.send(ar -> {
241+
context.verify(() -> {
242+
assertThat(ar.succeeded(), is(true));
243+
HttpResponse<JsonArray> response = ar.result();
244+
assertThat(response.statusCode(), is(HttpResponseStatus.OK.code()));
245+
});
246+
context.completeNow();
247+
});
234248
}
235249
}

0 commit comments

Comments
 (0)