Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import workflow manager #672

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions golang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
secrets.yaml
cmd/worker/worker
cmd/workflowmanager/workflowmanager
41 changes: 41 additions & 0 deletions golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Refinery Project running in Temporal Test

## Setup

### Temporal

# Run the following commands
```
git clone https://github.com/temporalio/temporal.git
cd temporal
curl -L https://github.com/temporalio/temporal/releases/latest/download/docker.tar.gz | tar -xz --strip-components 1 docker/docker-compose.yml
make bins
docker-compose up
```

# Run the following commands in a separate terminal
```
./tctl --ns refinery n re --gd false
```

### Workflow Manager
```
# In first terminal...
cd worker

# Configure secrets
cp config/secrets.example.yaml config/secrets.yaml
# Using an editor, set the secret values to the root Refinery account's cli creds

go run .

# In second terminal...
cd workflowmanager
go run .

# In third terminal...
ngrok http 3000
```

### Configuring API server to use Workflow Manager
Take the ngrok url, append `/api/v1` (ex. `https://1234.ngrok.io/api/v1`), and place it under `workflow_manager_api_url` in the config.
71 changes: 71 additions & 0 deletions golang/cmd/worker/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"context"
"io/ioutil"
"log"
"os"
"path"

"github.com/refinery-labs/refinery/golang/internal/worker"
"github.com/refinery-labs/refinery/golang/pkg/dsl"
"go.temporal.io/sdk/client"
temporalWorker "go.temporal.io/sdk/worker"

"go.uber.org/config"
)

func getConfigProvider(configDir string) config.Provider {
files, err := ioutil.ReadDir(configDir)
if err != nil {
log.Fatalln(err)
}

var filenames []string
for _, file := range files {
filenames = append(filenames, path.Join(configDir, file.Name()))
}

provider, err := config.NewYAMLProviderWithExpand(os.LookupEnv, filenames...)
if err != nil {
log.Fatalln(err)
}
return provider
}

func main() {
provider := getConfigProvider("./config")

var workerConfig worker.WorkerConfig
if err := provider.Get("workflow-manager-worker").Populate(&workerConfig); err != nil {
log.Fatalln(err)
}

// The client and worker are heavyweight objects that should be created once per process.
c, err := client.NewClient(client.Options{
HostPort: workerConfig.TemporalHostPort,
Namespace: "refinery",
})
if err != nil {
log.Fatalln("Unable to create client", err)
}
defer c.Close()

clientManager := worker.NewAwsClientManager(
workerConfig,
)

w := temporalWorker.New(c, "dsl", temporalWorker.Options{
BackgroundActivityContext: context.Background(),
})

w.RegisterWorkflow(dsl.SimpleDSLWorkflow)
w.RegisterActivity(&worker.RefineryAwsActivities{
clientManager,
})

err = w.Run(temporalWorker.InterruptCh())
if err != nil {
log.Fatalln("Unable to start worker", err)
}
}
76 changes: 76 additions & 0 deletions golang/cmd/workflowmanager/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"io/ioutil"
"log"
"os"
"path"

"go.uber.org/config"

"github.com/gofiber/fiber/v2"
"github.com/refinery-labs/refinery/golang/internal/workflowmanager"
"go.temporal.io/sdk/client"
)

func getConfigProvider(configDir string) config.Provider {
files, err := ioutil.ReadDir(configDir)
if err != nil {
log.Fatalln(err)
}

var filenames []string
for _, file := range files {
filenames = append(filenames, path.Join(configDir, file.Name()))
}

provider, err := config.NewYAMLProviderWithExpand(os.LookupEnv, filenames...)
if err != nil {
log.Fatalln(err)
}
return provider
}

func main() {
provider := getConfigProvider("./config")

var workflowManagerConfig workflowmanager.WorkflowManagerConfig
if err := provider.Get("workflow-manager").Populate(&workflowManagerConfig); err != nil {
log.Fatalln(err)
}

// The client is a heavyweight object that should be created once per process.
temporalClient, err := client.NewClient(client.Options{
HostPort: workflowManagerConfig.TemporalHostPort,
Namespace: "refinery",
})
if err != nil {
log.Fatalln("Unable to create client", err)
}

workflowStore := workflowmanager.NewPostgresqlWorkflowStore(workflowManagerConfig.DatabaseURI)

workflowManager := workflowmanager.NewTemporalWorkflowManager(temporalClient, workflowStore)

controller := &workflowmanager.Controller{
WorkflowManager: workflowManager,
TemporalClient: temporalClient,
}

app := fiber.New(fiber.Config{
DisableStartupMessage: true,
ErrorHandler: controller.ErrorHandler,
})

api := app.Group("/api")
v1 := api.Group("/v1")

v1.All("/deployment/:deploymentID/workflow/:workflowID", controller.StartWorkflow)

v1.Get("/deployment/:deploymentID", func(c *fiber.Ctx) error { return nil })
v1.Delete("/deployment/:deploymentID", controller.CancelWorkflowsForDeployment)
v1.Post("/deployment", controller.CreateWorkflowsForDeployment)
v1.Delete("/executions", controller.StopAllOpenWorkflows)

app.Listen(":3000")
}
10 changes: 10 additions & 0 deletions golang/docker/Dockerfile.workflow-manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang

ADD . /workflow-manager
WORKDIR /workflow-manager/cmd/workflowmanager

RUN go install .

ENTRYPOINT workflowmanager

EXPOSE 3000
8 changes: 8 additions & 0 deletions golang/docker/Dockerfile.workflow-manager-worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM golang

ADD . /workflow-manager-worker
WORKDIR /workflow-manager-worker/cmd/worker

RUN go install .

ENTRYPOINT worker
16 changes: 16 additions & 0 deletions golang/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/refinery-labs/refinery/golang

go 1.15

require (
github.com/ReneKroon/ttlcache/v2 v2.1.0
github.com/aws/aws-sdk-go v1.35.35
github.com/gofiber/fiber/v2 v2.2.0
github.com/google/uuid v1.1.2
github.com/lib/pq v1.8.0
github.com/mattn/go-sqlite3 v1.14.5
github.com/stretchr/testify v1.6.1
go.temporal.io/api v1.2.0
go.temporal.io/sdk v1.2.0
go.uber.org/config v1.4.0
)
Loading