Skip to content

Commit

Permalink
add update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinshenker committed Nov 1, 2023
1 parent fd30e7e commit 1e3d7e5
Showing 1 changed file with 77 additions and 50 deletions.
127 changes: 77 additions & 50 deletions commands/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,11 +1627,34 @@ func RunDatabaseTopicCreate(c *CmdConfig) error {
PartitionCount: &pcUInt32,
Config: getDatabaseTopicConfigArgs(c),
})
return err
}

func RunDatabaseTopicUpdate(c *CmdConfig) error {
if len(c.Args) < 2 {
return doctl.NewMissingArgsErr(c.NS)
}

databaseID := c.Args[0]
topicName := c.Args[1]

pc, err := c.Doit.GetInt(c.NS, doctl.ArgDatabaseTopicPartitionCount)
if err != nil {
return err
}
pcUInt32 := uint32(pc)
rf, err := c.Doit.GetInt(c.NS, doctl.ArgDatabaseTopicReplicationFactor)
if err != nil {
return err
}
rfUInt32 := uint32(rf)

return nil
err = c.Databases().UpdateTopic(databaseID, topicName, &godo.DatabaseUpdateTopicRequest{
ReplicationFactor: &rfUInt32,
PartitionCount: &pcUInt32,
Config: getDatabaseTopicConfigArgs(c),
})
return err
}

func getDatabaseTopicConfigArgs(c *CmdConfig) *godo.TopicConfig {
Expand Down Expand Up @@ -1818,55 +1841,59 @@ This command lists the following details for each partition of a given topic in
AddBoolFlag(cmdDatabaseTopicDelete, doctl.ArgForce, doctl.ArgShortForce, false, "Deletes the kafka topic without a confirmation prompt")
cmdDatabaseTopicCreate := CmdBuilder(cmd, RunDatabaseTopicCreate, "create <database-id>", "Creates a topic for a given kafka database",
"This command creates a kafka topic for the specified kafka database cluster, giving it the specified name. Example: doctl databases topics create <cluster_uuid> <topic_name>", Writer, aliasOpt("c"))
AddIntFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicReplicationFactor, "", 2, "Specifies the number of nodes to replicate data across the kafka cluster")
AddIntFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicPartitionCount, "", 1, "Specifies the number of partitions available for the topic")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicCleanupPolicy, "", "delete",
"Specifies the retention policy to use on log segments: Possible values are 'delete', 'compact_delete', 'compact'")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicCompressionType, "", "producer",
"Specifies the compression type for a kafka topic: Possible values are 'producer', 'gzip', 'snappy', 'Iz4', 'zstd', 'uncompressed'")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicDeleteRetentionMS, "", "",
"Specifies how long (in ms) to retain delete tombstone markers for topics")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicFileDeleteDelayMS, "", "",
"Specifies the minimum time (in ms) to wait before deleting a file from the filesystem")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicFlushMessages, "", "",
"Specifies the maximum number of messages to accumulate on a log partition before messages are flushed to disk")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicFlushMS, "", "",
"Specifies the maximum time (in ms) that a message is kept in memory before being flushed to disk")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicIntervalIndexBytes, "", "",
"Specifies the number of bytes between entries being added into the offset index")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMaxCompactionLagMS, "", "",
"Specifies the maximum time (in ms) that a message will remain uncompacted. This is only applicable if the logs have compaction enabled")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMaxMessageBytes, "", "",
"Specifies the largest record batch (in bytes) that can be sent to the server. This is calculated after compression, if compression is enabled")
AddBoolFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMesssageDownConversionEnable, "", true,
"Specifies whether down-conversion of message formats is enabled to satisfy consumer requests")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMessageFormatVersion, "", "",
`Specifies the message format version used by the broker to append messages to the logs. By setting a format version, all existing messages on disk must be
smaller or equal to the specified version`)
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMessageTimestampType, "", "",
"Specifies whether to use the create time or log append time as the timestamp on a message")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMinCleanableDirtyRatio, "", "",
`Specifies the frequenty of log compaction (if enabled) in relation to duplicates present in the logs. For example, 0.5 would mean at most half of the log
could be duplicates before compaction would begin`)
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMinCompactionLagMS, "", "",
"Specifies the minimum time (in ms) that a message will remain uncompacted. This is only applicable if the logs have compaction enabled")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicMinInsyncReplicas, "", "",
"Specifies the minimum number of replicas that must ACK a write for it to be considered successful")
AddBoolFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicPreallocate, "", false,
"Specifies whether a file should be preallocated on disk when creating a new log segment")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicRetentionBytes, "", "",
"Specifies the maximum size (in bytes) before deleting messages. '-1' indicates that there is no limit")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicRetentionMS, "", "",
"Specifies the maximum time (in ms) to store a message before deleting it. '-1' indicates that there is no limit")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicSegmentBytes, "", "",
"Specifies the maximum size (in bytes) of a single log file")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicSegmentJitterMS, "", "",
"Specifies the maximum time (in ms) for random jitter that is subtracted from the scheduled segment roll time to avoid thundering herd problems")
AddStringFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicSegmentMS, "", "",
"Specifies the maximum time (in ms) to wait to force a log roll if the segment file isn't full. After this period, the log will be forced to roll")
AddBoolFlag(cmdDatabaseTopicCreate, doctl.ArgDatabaseTopicUncleanLeaderElectionEnable, "", false,
"Specifies whether to allow replicas that are not insync to be elected as leader as a last resort. This may result in data loss since those leaders are not in sync")

cmdDatabaseTopicUpdate := CmdBuilder(cmd, RunDatabaseTopicUpdate, "update <database-id>", "Updates a topic for a given kafka database",
"This command updates a kafka topic for the specified kafka database cluster. Example: doctl databases topics update <cluster_uuid> <topic_name>", Writer, aliasOpt("u"))
cmdsWithConfig := []*Command{cmdDatabaseTopicCreate, cmdDatabaseTopicUpdate}
for _, c := range cmdsWithConfig {
AddIntFlag(c, doctl.ArgDatabaseTopicReplicationFactor, "", 2, "Specifies the number of nodes to replicate data across the kafka cluster")
AddIntFlag(c, doctl.ArgDatabaseTopicPartitionCount, "", 1, "Specifies the number of partitions available for the topic")
AddStringFlag(c, doctl.ArgDatabaseTopicCleanupPolicy, "", "delete",
"Specifies the retention policy to use on log segments: Possible values are 'delete', 'compact_delete', 'compact'")
AddStringFlag(c, doctl.ArgDatabaseTopicCompressionType, "", "producer",
"Specifies the compression type for a kafka topic: Possible values are 'producer', 'gzip', 'snappy', 'Iz4', 'zstd', 'uncompressed'")
AddStringFlag(c, doctl.ArgDatabaseTopicDeleteRetentionMS, "", "",
"Specifies how long (in ms) to retain delete tombstone markers for topics")
AddStringFlag(c, doctl.ArgDatabaseTopicFileDeleteDelayMS, "", "",
"Specifies the minimum time (in ms) to wait before deleting a file from the filesystem")
AddStringFlag(c, doctl.ArgDatabaseTopicFlushMessages, "", "",
"Specifies the maximum number of messages to accumulate on a log partition before messages are flushed to disk")
AddStringFlag(c, doctl.ArgDatabaseTopicFlushMS, "", "",
"Specifies the maximum time (in ms) that a message is kept in memory before being flushed to disk")
AddStringFlag(c, doctl.ArgDatabaseTopicIntervalIndexBytes, "", "",
"Specifies the number of bytes between entries being added into the offset index")
AddStringFlag(c, doctl.ArgDatabaseTopicMaxCompactionLagMS, "", "",
"Specifies the maximum time (in ms) that a message will remain uncompacted. This is only applicable if the logs have compaction enabled")
AddStringFlag(c, doctl.ArgDatabaseTopicMaxMessageBytes, "", "",
"Specifies the largest record batch (in bytes) that can be sent to the server. This is calculated after compression, if compression is enabled")
AddBoolFlag(c, doctl.ArgDatabaseTopicMesssageDownConversionEnable, "", true,
"Specifies whether down-conversion of message formats is enabled to satisfy consumer requests")
AddStringFlag(c, doctl.ArgDatabaseTopicMessageFormatVersion, "", "",
`Specifies the message format version used by the broker to append messages to the logs. By setting a format version, all existing messages on disk must be
smaller or equal to the specified version`)
AddStringFlag(c, doctl.ArgDatabaseTopicMessageTimestampType, "", "",
"Specifies whether to use the create time or log append time as the timestamp on a message")
AddStringFlag(c, doctl.ArgDatabaseTopicMinCleanableDirtyRatio, "", "",
`Specifies the frequenty of log compaction (if enabled) in relation to duplicates present in the logs. For example, 0.5 would mean at most half of the log
could be duplicates before compaction would begin`)
AddStringFlag(c, doctl.ArgDatabaseTopicMinCompactionLagMS, "", "",
"Specifies the minimum time (in ms) that a message will remain uncompacted. This is only applicable if the logs have compaction enabled")
AddStringFlag(c, doctl.ArgDatabaseTopicMinInsyncReplicas, "", "",
"Specifies the minimum number of replicas that must ACK a write for it to be considered successful")
AddBoolFlag(c, doctl.ArgDatabaseTopicPreallocate, "", false,
"Specifies whether a file should be preallocated on disk when creating a new log segment")
AddStringFlag(c, doctl.ArgDatabaseTopicRetentionBytes, "", "",
"Specifies the maximum size (in bytes) before deleting messages. '-1' indicates that there is no limit")
AddStringFlag(c, doctl.ArgDatabaseTopicRetentionMS, "", "",
"Specifies the maximum time (in ms) to store a message before deleting it. '-1' indicates that there is no limit")
AddStringFlag(c, doctl.ArgDatabaseTopicSegmentBytes, "", "",
"Specifies the maximum size (in bytes) of a single log file")
AddStringFlag(c, doctl.ArgDatabaseTopicSegmentJitterMS, "", "",
"Specifies the maximum time (in ms) for random jitter that is subtracted from the scheduled segment roll time to avoid thundering herd problems")
AddStringFlag(c, doctl.ArgDatabaseTopicSegmentMS, "", "",
"Specifies the maximum time (in ms) to wait to force a log roll if the segment file isn't full. After this period, the log will be forced to roll")
AddBoolFlag(c, doctl.ArgDatabaseTopicUncleanLeaderElectionEnable, "", false,
"Specifies whether to allow replicas that are not insync to be elected as leader as a last resort. This may result in data loss since those leaders are not in sync")
}
return cmd
}

Expand Down

0 comments on commit 1e3d7e5

Please sign in to comment.