Skip to content

Commit

Permalink
cmd/relui: generate uuid for workflow and task instances
Browse files Browse the repository at this point in the history
Sets workflow and tasks IDs when a workflow is created in the UI. These
IDs will be used in the future when operating on workflows and tasks via
the UI or API.

This ID will likely change to a datastore ID after datastore integration
is added.

For golang/go#40279

Co-authored-by: Carlos Amedee <[email protected]>
Change-Id: Ib75c00c234d156cc1bbdab8c658281f04914165b
Reviewed-on: https://go-review.googlesource.com/c/build/+/257238
Trust: Alexander Rakoczy <[email protected]>
Run-TryBot: Alexander Rakoczy <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
toothrot and cagedmantis committed Sep 25, 2020
1 parent fac8f1e commit a815a97
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 33 deletions.
83 changes: 51 additions & 32 deletions cmd/relui/protos/relui.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/relui/protos/relui.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ message Workflow {

// params are parameters provided when creating a workflow.
map<string, string> params = 3;

// id is a unique identifier generated by relui when a workflow is created.
string id = 4;
}

message BuildableTask {
Expand All @@ -39,6 +42,9 @@ message BuildableTask {
// task_type is a unique type for a task, such as FetchGerritSource. Types are used by task runners to identify
// how to execute a task.
string task_type = 6;

// id is a unique identifier generated by relui when a buildable task is created.
string id = 7;
}

// LocalStorage is the persisted data of relui. It is used in development mode for saving application state.
Expand Down
1 change: 1 addition & 0 deletions cmd/relui/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h4 class="WorkflowList-sectionTitle">Tasks</h4>
<li class="TaskList-item">
<span class="TaskList-itemTitle">{{$task.Name}}</span>
Status: {{$task.Status}}
ID: {{$task.Id}}
</li>
{{end}}
<li class="TaskList-item">
Expand Down
5 changes: 5 additions & 0 deletions cmd/relui/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"cloud.google.com/go/pubsub"
"github.com/golang/protobuf/proto"
"github.com/google/uuid"
reluipb "golang.org/x/build/cmd/relui/protos"
)

Expand Down Expand Up @@ -108,6 +109,10 @@ func (s *server) createWorkflowHandler(w http.ResponseWriter, r *http.Request) {
if wf.GetParams() == nil {
wf.Params = map[string]string{}
}
wf.Id = uuid.New().String()
for _, t := range wf.GetBuildableTasks() {
t.Id = uuid.New().String()
}
wf.Params["GitObject"] = ref
if err := s.store.AddWorkflow(wf); err != nil {
log.Printf("Error adding workflow: s.store.AddWorkflow(%v) = %v", wf, err)
Expand Down
13 changes: 12 additions & 1 deletion cmd/relui/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ func TestServerNewWorkflowHandler(t *testing.T) {
}

func TestServerCreateWorkflowHandler(t *testing.T) {
config := []*reluipb.Workflow{{Name: "test_workflow"}}
config := []*reluipb.Workflow{
{
Name: "test_workflow",
BuildableTasks: []*reluipb.BuildableTask{{Name: "test_task"}},
},
}
cases := []struct {
desc string
params url.Values
Expand Down Expand Up @@ -157,6 +162,12 @@ func TestServerCreateWorkflowHandler(t *testing.T) {
if diff := cmp.Diff(c.wantParams, s.store.Workflows()[0].GetParams()); diff != "" {
t.Errorf("s.Store.Workflows()[0].Params() mismatch (-want, +got):\n%s", diff)
}
if s.store.Workflows()[0].GetId() == "" {
t.Errorf("s.Store.Workflows[0].GetId() = %q, wanted not empty", s.store.Workflows()[0].GetId())
}
if s.store.Workflows()[0].GetBuildableTasks()[0].GetId() == "" {
t.Errorf("s.Store.Workflows[0].GetBuildableTasks()[0].GetId() = %q, wanted not empty", s.store.Workflows()[0].GetId())
}
})
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/google/go-cmp v0.4.0
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/uuid v1.1.2
github.com/googleapis/gax-go/v2 v2.0.5
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hf
github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4 h1:hU4mGcQI4DaAYW+IbTun+2qEZVFxK0ySjQLTbS0VQKc=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
Expand Down

0 comments on commit a815a97

Please sign in to comment.