Skip to content

Commit

Permalink
Kafka topic management: (#837)
Browse files Browse the repository at this point in the history
- fix UpdateTopic
- add Godo examples
- make various request/response clarifications

Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>
  • Loading branch information
dweinshenker and andrewsomething authored Oct 16, 2023
1 parent 604eca4 commit b0a1e19
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ responses:

x-codeSamples:
- $ref: 'examples/curl/databases_create_topic.yml'
- $ref: 'examples/go/databases_create_topic.yml'

security:
- bearer_auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ responses:

x-codeSamples:
- $ref: 'examples/curl/databases_delete_topic.yml'
- $ref: 'examples/go/databases_delete_topic.yml'

security:
- bearer_auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ responses:

x-codeSamples:
- $ref: 'examples/curl/databases_get_topic.yml'
- $ref: 'examples/go/databases_get_topic.yml'

security:
- bearer_auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ responses:

x-codeSamples:
- $ref: 'examples/curl/databases_list_topics.yml'
- $ref: 'examples/go/databases_list_topics.yml'

security:
- bearer_auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ requestBody:
schema:
allOf:
- $ref: 'models/kafka_topic_update.yml'
required:
- topic
example:
topic:
name: customer-events
partitions: 3
replication: 2
config:
retention_bytes: -1
retention_ms: 100000
partitions: 3
replication: 2
config:
retention_bytes: -1
retention_ms: 100000

responses:
'200':
Expand All @@ -53,6 +49,7 @@ responses:

x-codeSamples:
- $ref: 'examples/curl/databases_update_topic.yml'
- $ref: 'examples/go/databases_update_topic.yml'

security:
- bearer_auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ source: |-
curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"topic":{"name":"customer-events", "partition_count":3, "replication_factor": 3, "config": {"retentionMS": 1000000}}}' \
-d '{"partition_count":3, "replication_factor": 3, "config": {"retentionMS": 1000000}}' \
"https://api.digitalocean.com/v2/databases/9cc10173-e9ea-4176-9dbc-a4cee4c4ff30/topics/customer-events"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
lang: Go
source: |-
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
createRequest := &DatabaseCreateTopicRequest{
Name: "events",
PartitionCount: 3,
ReplicationFactor: 2,
Config: &TopicConfig{
RetentionMS: 60000,
}
},
cluster, _, err := client.Databases.CreateTopic(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30", createRequest)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
lang: Go
source: |-
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
topicName := "events"
_, err := client.Databases.DeleteTopic(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30", topicName)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
lang: Go
source: |-
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
topicName := "events"
user, _, err := client.Databases.GetTopic(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30", topicName)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
lang: Go
source: |-
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
replicas, _, err := client.Databases.ListTopics(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30", nil)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
lang: Go
source: |-
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
topicName := "events"
updateRequest := &DatabaseUpdateTopicRequest{
PartitionCount: 3,
ReplicationFactor: 2,
Config: &TopicConfig{
RetentionMS: 60000,
},
}
_, err := client.Databases.UpdateTopic(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30", topicName, updateRequest)
}
16 changes: 10 additions & 6 deletions specification/resources/databases/models/kafka_topic_update.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
type: object

properties:
topic:
allOf:
- $ref: './kafka_topic_base.yml'
- properties:
config:
$ref: './kafka_topic_config.yml'
replication_factor:
type: integer
example: 2
description: The number of nodes to replicate data across the cluster.
partition_count:
type: integer
example: 3
description: The number of partitions available for the topic. On update, this value can only be increased.
config:
$ref: './kafka_topic_config.yml'
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ properties:
$ref: './kafka_topic_partition.yml'

config:
$ref: './kafka_topic_config.yml'

required:
- name
$ref: './kafka_topic_config.yml'

0 comments on commit b0a1e19

Please sign in to comment.