@@ -2,6 +2,7 @@ package tableflow
22
33import (
44 "fmt"
5+ "strings"
56
67 "github.com/spf13/cobra"
78
@@ -31,12 +32,15 @@ func (c *command) newTopicUpdateCommand() *cobra.Command {
3132
3233 cmd .Flags ().String ("retention-ms" , "" , "Specify the Tableflow table retention time in milliseconds." )
3334 cmd .Flags ().String ("table-formats" , "" , "Specify the table formats, one of DELTA or ICEBERG." )
34- cmd . Flags (). String ( "record-failure-strategy" , "SUSPEND" , "Specify the record failure strategy, one of SUSPEND or SKIP." )
35+ addErrorHandlingFlags ( cmd )
3536
3637 pcmd .AddContextFlag (cmd , c .CLICommand )
3738 pcmd .AddEnvironmentFlag (cmd , c .AuthenticatedCLICommand )
3839 pcmd .AddOutputFlag (cmd )
3940
41+ // Deprecated
42+ cmd .Flags ().String ("record-failure-strategy" , "" , "DEPRECATED: Specify the record failure strategy, one of SUSPEND or SKIP." )
43+
4044 return cmd
4145}
4246
@@ -67,6 +71,16 @@ func (c *command) update(cmd *cobra.Command, args []string) error {
6771 return err
6872 }
6973
74+ errorHandling , err := cmd .Flags ().GetString ("error-handling" )
75+ if err != nil {
76+ return err
77+ }
78+
79+ logTarget , err := cmd .Flags ().GetString ("log-target" )
80+ if err != nil {
81+ return err
82+ }
83+
7084 topicUpdate := tableflowv1.TableflowV1TableflowTopicUpdate {
7185 Spec : & tableflowv1.TableflowV1TableflowTopicSpecUpdate {
7286 Environment : & tableflowv1.GlobalObjectReference {Id : environmentId },
@@ -87,6 +101,48 @@ func (c *command) update(cmd *cobra.Command, args []string) error {
87101 topicUpdate .Spec .Config .SetRecordFailureStrategy (recordFailureStrategy )
88102 }
89103
104+ if cmd .Flags ().Changed ("error-handling" ) {
105+ if strings .ToUpper (errorHandling ) == suspend {
106+ topicUpdate .Spec .Config .ErrorHandling = & tableflowv1.TableflowV1TableFlowTopicConfigsSpecErrorHandlingOneOf {
107+ TableflowV1ErrorHandlingSuspend : & tableflowv1.TableflowV1ErrorHandlingSuspend {
108+ Mode : suspend ,
109+ },
110+ }
111+ } else if strings .ToUpper (errorHandling ) == skip {
112+ topicUpdate .Spec .Config .ErrorHandling = & tableflowv1.TableflowV1TableFlowTopicConfigsSpecErrorHandlingOneOf {
113+ TableflowV1ErrorHandlingSkip : & tableflowv1.TableflowV1ErrorHandlingSkip {
114+ Mode : skip ,
115+ },
116+ }
117+ } else if strings .ToUpper (errorHandling ) == log {
118+ topicUpdate .Spec .Config .ErrorHandling = & tableflowv1.TableflowV1TableFlowTopicConfigsSpecErrorHandlingOneOf {
119+ TableflowV1ErrorHandlingLog : & tableflowv1.TableflowV1ErrorHandlingLog {
120+ Mode : log ,
121+ },
122+ }
123+ if cmd .Flags ().Changed ("log-target" ) {
124+ topicUpdate .Spec .Config .ErrorHandling .TableflowV1ErrorHandlingLog .SetTarget (logTarget )
125+ }
126+ }
127+ }
128+
129+ if cmd .Flags ().Changed ("log-target" ) && ! cmd .Flags ().Changed ("error-handling" ) {
130+ // We must check for the edge case where the current error handling mode is *not* LOG, but the user is trying to update the log target anyway
131+ // We should not assume that the user wants to change the mode to LOG, so we check the current mode and do nothing if it is not LOG
132+ currentTopic , err := c .V2Client .GetTableflowTopic (environmentId , cluster .GetId (), args [0 ])
133+ if err != nil {
134+ return err
135+ }
136+ if strings .ToUpper (currentTopic .GetSpec ().Config .GetErrorHandling ().TableflowV1ErrorHandlingLog .GetMode ()) == log {
137+ topicUpdate .Spec .Config .ErrorHandling = & tableflowv1.TableflowV1TableFlowTopicConfigsSpecErrorHandlingOneOf {
138+ TableflowV1ErrorHandlingLog : & tableflowv1.TableflowV1ErrorHandlingLog {
139+ Mode : log ,
140+ Target : tableflowv1 .PtrString (logTarget ),
141+ },
142+ }
143+ }
144+ }
145+
90146 topic , err := c .V2Client .UpdateTableflowTopic (args [0 ], topicUpdate )
91147 if err != nil {
92148 return fmt .Errorf ("Error with updating Tableflow topic: %w" , err )
0 commit comments