Skip to content

Commit

Permalink
Merge pull request #291 from GoogleCloudPlatform/issue290
Browse files Browse the repository at this point in the history
feat: adds support for cancel and replay #290
  • Loading branch information
srinandan authored Oct 7, 2024
2 parents 2217583 + 577b3b0 commit 81324f5
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/client/integrations/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ func Execute(name string, content []byte) (respBody []byte, err error) {

return respBody, err
}

func Cancel(name string, executionID string, cancelReason string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetBaseIntegrationURL())
u.Path = path.Join(u.Path, "integrations", name, "executions", executionID, ":cancel")
payload := "{ \"cancelReason\":\"" + cancelReason + "\"}"
respBody, err = apiclient.HttpClient(u.String(), payload)
return respBody, err
}

func Replay(name string, executionID string, replayReason string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetBaseIntegrationURL())
u.Path = path.Join(u.Path, "integrations", name, "executions", executionID, ":replay")
payload := "{ \"replayReason\":\"" + replayReason + "\"}"
respBody, err = apiclient.HttpClient(u.String(), payload)
return respBody, err
}
60 changes: 60 additions & 0 deletions internal/cmd/integrations/cancelexec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integrations

import (
"internal/apiclient"
"internal/client/integrations"

"github.com/spf13/cobra"
)

// CancelExecCmd to list executions of an integration version
var CancelExecCmd = &cobra.Command{
Use: "cancel",
Short: "Cancels an execution of an integration",
Long: "Cancels an execution of an integration",
Args: func(cmd *cobra.Command, args []string) (err error) {
cmdProject := cmd.Flag("proj")
cmdRegion := cmd.Flag("reg")

if err = apiclient.SetRegion(cmdRegion.Value.String()); err != nil {
return err
}
return apiclient.SetProjectID(cmdProject.Value.String())
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
name := cmd.Flag("name").Value.String()
executionID := cmd.Flag("execution-id").Value.String()
cancelReason := cmd.Flag("cancel-reason").Value.String()
_, err = integrations.Cancel(name, executionID, cancelReason)
return err
},
}

func init() {
var name, executionID, cancelReason string

CancelExecCmd.Flags().StringVarP(&name, "name", "n",
"", "Integration flow name")
CancelExecCmd.Flags().StringVarP(&cancelReason, "cancel-reason", "c",
"", "Cancel Reason")
CancelExecCmd.Flags().StringVarP(&executionID, "execution-id", "e",
"", "Execution ID")

_ = CancelExecCmd.MarkFlagRequired("name")
_ = CancelExecCmd.MarkFlagRequired("cancel-reason")
_ = CancelExecCmd.MarkFlagRequired("execution-id")
}
2 changes: 2 additions & 0 deletions internal/cmd/integrations/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ var ExecCmd = &cobra.Command{
func init() {
ExecCmd.AddCommand(ListExecCmd)
ExecCmd.AddCommand(SuspendCmd)
ExecCmd.AddCommand(CancelExecCmd)
ExecCmd.AddCommand(ReplayExecCmd)
}
60 changes: 60 additions & 0 deletions internal/cmd/integrations/replayexec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integrations

import (
"internal/apiclient"
"internal/client/integrations"

"github.com/spf13/cobra"
)

// ReplayExecCmd to list executions of an integration version
var ReplayExecCmd = &cobra.Command{
Use: "replay",
Short: "Replays an execution of an integration",
Long: "Replays an execution of an integration",
Args: func(cmd *cobra.Command, args []string) (err error) {
cmdProject := cmd.Flag("proj")
cmdRegion := cmd.Flag("reg")

if err = apiclient.SetRegion(cmdRegion.Value.String()); err != nil {
return err
}
return apiclient.SetProjectID(cmdProject.Value.String())
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
name := cmd.Flag("name").Value.String()
executionID := cmd.Flag("execution-id").Value.String()
replayReason := cmd.Flag("replay-reason").Value.String()
_, err = integrations.Replay(name, executionID, replayReason)
return err
},
}

func init() {
var name, executionID, replayReason string

ReplayExecCmd.Flags().StringVarP(&name, "name", "n",
"", "Integration flow name")
ReplayExecCmd.Flags().StringVarP(&replayReason, "replay-reason", "r",
"", "Replay Reason")
ReplayExecCmd.Flags().StringVarP(&executionID, "execution-id", "e",
"", "Execution ID")

_ = ReplayExecCmd.MarkFlagRequired("name")
_ = ReplayExecCmd.MarkFlagRequired("replay-reason")
_ = ReplayExecCmd.MarkFlagRequired("execution-id")
}

0 comments on commit 81324f5

Please sign in to comment.