Skip to content

Commit

Permalink
Add GET endpoint to Sprinkler workflows (#42)
Browse files Browse the repository at this point in the history
Add GET endpoint to Sprinkler workflows. To facilitate support use cases
with the GET response payload to be edited for new PUT requests.

Fix typos in service/control.go and README.md
  • Loading branch information
schowsf authored Sep 16, 2024
1 parent 3c04cea commit 4fc2f3a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ Start control service on a new tab, to later post a Sprinkler json workflow
go run . service control --config .sprinkler.yaml
```

Post to `http://localhost:8080/v1/workflow` a Sprinkler workflow, example payload from [ExampleWorkflow.scala](https://github.com/salesforce/spade/blob/main/spade-examples/src/main/scala/com/salesforce/mce/spade/examples/ExampleWorkflow.scala)
Put to `http://localhost:8080/v1/workflow` a Sprinkler workflow, example payload from [ExampleWorkflow.scala](https://github.com/salesforce/spade/blob/main/spade-examples/src/main/scala/com/salesforce/mce/spade/examples/ExampleWorkflow.scala)
```
{
"name": "test-workflow",
"artifact": "s3://sprinkler-salesforce-bucket/jars/test/spade-example.jar",
"command": "[\"java\", \"-cp\", \"spade-example.jar\", \"com.salesforce.mce.spade.examples.ExampleWorkflow\", \"generate\", \"--compact\"]",
"every": "60.minute",
"nextRuntime": "2023-03-22T21:00:00Z",
"nextRuntime": "2024-08-22T21:00:00Z",
"backfill": false,
"owner": "arn:aws:sns:us-east-2:444455556666:MyTopic",
"isActive": true
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "sprinkler",
Short: "Workflow scheculer built for orchard",
Short: "Workflow scheduler built for orchard",
Long: `Sprinkler CLI provides all the necessary commands to setup the database, test
orchard servers and other services to run and manage workflows for orchard
orchastration server`,
orchestration server`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
26 changes: 26 additions & 0 deletions service/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ func (ctrl *Control) deleteWorkflow(c *gin.Context) {
}
}

func (ctrl *Control) getWorkflow(c *gin.Context) {
name := c.Param("name")
var workflow table.Workflow
dbRes := ctrl.db.Model(&table.Workflow{}).
Where("name = ?", name).
Find(&workflow)

if dbRes.Error != nil || dbRes.RowsAffected == 0 {
c.JSON(http.StatusNotFound, gin.H{"Workflow not found:": fmt.Sprintf("name=%s", name)})
} else {
resp := postWorkflowReq{
Name: workflow.Name,
Artifact: workflow.Artifact,
Command: workflow.Command,
Every: workflow.Every.String(),
NextRuntime: workflow.NextRuntime,
Backfill: workflow.Backfill,
Owner: workflow.Owner,
IsActive: workflow.IsActive,
ScheduleDelayMinutes: workflow.ScheduleDelayMinutes}

c.IndentedJSON(http.StatusOK, resp)
}
}

func APIKeyAuth(key string) gin.HandlerFunc {
return func(c *gin.Context) {
k := c.GetHeader("x-api-key")
Expand All @@ -133,6 +158,7 @@ func (ctrl *Control) Run() {
{
v1.PUT("/workflow", ctrl.putWorkflow)
v1.DELETE("/workflow", ctrl.deleteWorkflow)
v1.GET("/workflow/:name", ctrl.getWorkflow)
}

r.GET("__status", func(c *gin.Context) {
Expand Down

0 comments on commit 4fc2f3a

Please sign in to comment.