From b79484d39e2612d6b10ab95035fa6678e0f36528 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Wed, 11 Sep 2024 20:15:12 +0530 Subject: [PATCH] add json output to Conclude command Signed-off-by: Harshit Gangal --- go/cmd/vtctldclient/command/transactions.go | 27 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/go/cmd/vtctldclient/command/transactions.go b/go/cmd/vtctldclient/command/transactions.go index 84459e54a50..6d14fff0c1e 100644 --- a/go/cmd/vtctldclient/command/transactions.go +++ b/go/cmd/vtctldclient/command/transactions.go @@ -58,6 +58,17 @@ var ( } ) +type ConcludeTransactionOutput struct { + Dtid string `json:"dtid"` + Message string `json:"message"` + Error string `json:"error,omitempty"` +} + +const ( + concludeSuccess = "Successfully concluded the distributed transaction" + concludeFailure = "Failed to conclude the distributed transaction" +) + func commandGetUnresolvedTransactions(cmd *cobra.Command, args []string) error { cli.FinishedParsing(cmd) @@ -74,7 +85,7 @@ func commandGetUnresolvedTransactions(cmd *cobra.Command, args []string) error { if err != nil { return err } - fmt.Printf("%s\n", data) + fmt.Println(string(data)) return nil } @@ -94,17 +105,25 @@ func commandConcludeTransaction(cmd *cobra.Command, args []string) error { Shard: shard.Name, }) } + output := ConcludeTransactionOutput{ + Dtid: dtid, + Message: concludeSuccess, + } + _, err = client.ConcludeTransaction(commandCtx, &vtctldatapb.ConcludeTransactionRequest{ Dtid: dtid, Participants: participants, }) if err != nil { - return err + output.Message = concludeFailure + output.Error = err.Error() } - fmt.Println("Successfully concluded the distributed transaction") - return nil + data, _ := cli.MarshalJSON(output) + fmt.Println(string(data)) + + return err } func init() {