Skip to content

Commit

Permalink
[strimzi#434] feat: edits for api standards
Browse files Browse the repository at this point in the history
Signed-off-by: ilkerkocatepe <[email protected]>
  • Loading branch information
ilkerkocatepe committed Nov 19, 2024
1 parent 3f0f72e commit 1514090
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d79befc630208ffc467595a5c413954da1cb03e6212b211257c6db29e5c2ad46
e6ff5b267f241378e60e023ea1c57ccf90fd17170045b92e00e39d29bec17522
88 changes: 55 additions & 33 deletions documentation/book/api/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2292,31 +2292,32 @@ endif::internal-generation[]
[.createTopic]
==== createTopic

`POST /admin/topics/{topicname}`
`POST /admin/topics`



===== Description

Creates a topic with given topic name.
Creates a topic with given name, partitions count and replication factor.


// markup not found, no include::{specDir}admin/topics/\{topicname\}/POST/spec.adoc[opts=optional]
// markup not found, no include::{specDir}admin/topics/POST/spec.adoc[opts=optional]



===== Parameters



[cols="2,3,1,1,1"]
.Path Parameters
.Body Parameter
|===
|Name| Description| Required| Default| Pattern

| topicname
| Name of the topic will be created.
| CreateTopic
| Creates a topic with given name, partitions count and replication factor. <<CreateTopic>>
| X
| null
|
|

|===
Expand All @@ -2325,26 +2326,6 @@ Creates a topic with given topic name.



[cols="2,3,1,1,1"]
.Query Parameters
|===
|Name| Description| Required| Default| Pattern

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

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

|===


===== Return Type


Expand All @@ -2364,29 +2345,34 @@ Creates a topic with given topic name.
| Code | Message | Datatype


| 200
| No content
| 201
| Created
| <<>>


| 422
| Request body is null or it doesn&#39;t contain topic name.
| <<Error>>

|===

===== Samples


// markup not found, no include::{snippetDir}admin/topics/\{topicname\}/POST/http-request.adoc[opts=optional]
// markup not found, no include::{snippetDir}admin/topics/POST/http-request.adoc[opts=optional]


// markup not found, no include::{snippetDir}admin/topics/\{topicname\}/POST/http-response.adoc[opts=optional]
// markup not found, no include::{snippetDir}admin/topics/POST/http-response.adoc[opts=optional]



// file not found, no * wiremock data link :admin/topics/{topicname}/POST/POST.json[]
// file not found, no * wiremock data link :admin/topics/POST/POST.json[]


ifdef::internal-generation[]
===== Implementation

// markup not found, no include::{specDir}admin/topics/\{topicname\}/POST/implementation.adoc[opts=optional]
// markup not found, no include::{specDir}admin/topics/POST/implementation.adoc[opts=optional]


endif::internal-generation[]
Expand Down Expand Up @@ -3225,6 +3211,42 @@ Information about Kafka Bridge instance.



[#CreateTopic]
=== _CreateTopic_ CreateTopic




[.fields-CreateTopic]
[cols="2,1,1,2,4,1"]
|===
| Field Name| Required| Nullable | Type| Description | Format

| topic_name
|
|
| String
| Name of the topic to create.
|

| partitions_count
|
| X
| Integer
| Number of partitions for the topic.
|

| replication_factor
|
| X
| Integer
| Number of replicas for each partition.
|

|===



[#CreatedConsumer]
=== _CreatedConsumer_ CreatedConsumer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.strimzi.kafka.bridge.config.BridgeConfig;
import io.strimzi.kafka.bridge.http.converter.JsonUtils;
import io.strimzi.kafka.bridge.http.model.HttpBridgeError;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import org.apache.kafka.clients.admin.Config;
import org.apache.kafka.clients.admin.ConfigEntry;
Expand Down Expand Up @@ -179,23 +180,34 @@ public void doGetTopic(RoutingContext routingContext) {
}

/**
* Create a topic described in the HTTP request
* Create a topic with described name, partitions count and replication factor in the body of the HTTP request
*
* @param routingContext the routing context
*/
public void doCreateTopic(RoutingContext routingContext) {
String topicName = routingContext.pathParam("topicname");
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);
JsonObject jsonBody = routingContext.body().asJsonObject();

if (jsonBody.isEmpty() || jsonBody.getString("topic_name").isBlank()) {
HttpBridgeError error = new HttpBridgeError(
HttpResponseStatus.UNPROCESSABLE_ENTITY.code(),
"Request body must be a JSON object"
);
HttpUtils.sendResponse(routingContext, HttpResponseStatus.UNPROCESSABLE_ENTITY.code(),
BridgeContentType.KAFKA_JSON, JsonUtils.jsonToBytes(error.toJson()));
return;
}

this.kafkaBridgeAdmin.createTopic(topicName, partitions, replicationFactor)
String topicName = jsonBody.getString("topic_name");
Optional<Integer> partitionsCount = Optional.ofNullable(jsonBody.getInteger("partitions_count"));
Optional<Short> replicationFactor = Optional.ofNullable(jsonBody.getInteger("replication_factor"))
.map(Integer::shortValue);

this.kafkaBridgeAdmin.createTopic(topicName, partitionsCount, replicationFactor)
.whenComplete(((topic, exception) -> {
LOGGER.trace("Create topic handler thread {}", Thread.currentThread());
if (exception == null) {
ArrayNode root = JsonUtils.createArrayNode();
HttpUtils.sendResponse(routingContext, HttpResponseStatus.OK.code(),
JsonNode root = JsonUtils.createObjectNode();
HttpUtils.sendResponse(routingContext, HttpResponseStatus.CREATED.code(),
BridgeContentType.KAFKA_JSON, JsonUtils.jsonToBytes(root));
} else {
HttpBridgeError error = new HttpBridgeError(
Expand Down
94 changes: 60 additions & 34 deletions src/main/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,51 +753,51 @@
}
]
},
"/admin/topics/{topicname}": {
"/admin/topics": {
"post": {
"tags": [
"Topics"
],
"description": "Creates a topic with given topic name.",
"description": "Creates a topic with given name, partitions count and replication factor.",
"operationId": "createTopic",
"requestBody": {
"description": "Creates a topic with given name, partitions count and replication factor.",
"content": {
"application/vnd.kafka.json.v2+json": {
"schema": {
"$ref": "#/components/schemas/CreateTopic"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "No content",
"201": {
"description": "Created",
"content": {
"application/vnd.kafka.v2+json": {}
}
},
"422": {
"description": "Request body is null or it doesn't contain topic name.",
"content": {
"application/vnd.kafka.v2+json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"examples": {
"response": {
"value": {
"error_code": 422,
"message": "Request body is null or it doesn't contain topic name."
}
}
}
}
}
}
}
},
"parameters": [
{
"name": "topicname",
"in": "path",
"description": "Name of the topic will be created.",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "partitions",
"in": "query",
"description": "Number of partitions for the topic. (Optional)",
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "replication_factor",
"in": "query",
"description": "Replication factor for the topic. (Optional)",
"required": false,
"schema": {
"type": "integer"
}
}
]
}
},
"/consumers/{groupid}/instances/{name}/records": {
"get": {
Expand Down Expand Up @@ -2239,6 +2239,32 @@
}
],
"nullable" : true
},
"CreateTopic": {
"title": "CreateTopic",
"type": "object",
"properties": {
"topic_name": {
"description": "Name of the topic to create.",
"type": "string"
},
"partitions_count": {
"description": "Number of partitions for the topic.",
"type": "integer",
"nullable": true
},
"replication_factor": {
"description": "Number of replicas for each partition.",
"type": "integer",
"nullable": true
}
},
"additionalProperties": false,
"example": {
"topic_name": "my-topic",
"partitions": 3,
"replication_factor": 2
}
}
}
},
Expand Down
Loading

0 comments on commit 1514090

Please sign in to comment.