Skip to content

Commit a815a97

Browse files
toothrotcagedmantis
andcommitted
cmd/relui: generate uuid for workflow and task instances
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]>
1 parent fac8f1e commit a815a97

File tree

7 files changed

+78
-33
lines changed

7 files changed

+78
-33
lines changed

cmd/relui/protos/relui.pb.go

Lines changed: 51 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/relui/protos/relui.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ message Workflow {
1616

1717
// params are parameters provided when creating a workflow.
1818
map<string, string> params = 3;
19+
20+
// id is a unique identifier generated by relui when a workflow is created.
21+
string id = 4;
1922
}
2023

2124
message BuildableTask {
@@ -39,6 +42,9 @@ message BuildableTask {
3942
// task_type is a unique type for a task, such as FetchGerritSource. Types are used by task runners to identify
4043
// how to execute a task.
4144
string task_type = 6;
45+
46+
// id is a unique identifier generated by relui when a buildable task is created.
47+
string id = 7;
4248
}
4349

4450
// LocalStorage is the persisted data of relui. It is used in development mode for saving application state.

cmd/relui/templates/home.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ <h4 class="WorkflowList-sectionTitle">Tasks</h4>
1919
<li class="TaskList-item">
2020
<span class="TaskList-itemTitle">{{$task.Name}}</span>
2121
Status: {{$task.Status}}
22+
ID: {{$task.Id}}
2223
</li>
2324
{{end}}
2425
<li class="TaskList-item">

cmd/relui/web.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"cloud.google.com/go/pubsub"
1919
"github.com/golang/protobuf/proto"
20+
"github.com/google/uuid"
2021
reluipb "golang.org/x/build/cmd/relui/protos"
2122
)
2223

@@ -108,6 +109,10 @@ func (s *server) createWorkflowHandler(w http.ResponseWriter, r *http.Request) {
108109
if wf.GetParams() == nil {
109110
wf.Params = map[string]string{}
110111
}
112+
wf.Id = uuid.New().String()
113+
for _, t := range wf.GetBuildableTasks() {
114+
t.Id = uuid.New().String()
115+
}
111116
wf.Params["GitObject"] = ref
112117
if err := s.store.AddWorkflow(wf); err != nil {
113118
log.Printf("Error adding workflow: s.store.AddWorkflow(%v) = %v", wf, err)

cmd/relui/web_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ func TestServerNewWorkflowHandler(t *testing.T) {
106106
}
107107

108108
func TestServerCreateWorkflowHandler(t *testing.T) {
109-
config := []*reluipb.Workflow{{Name: "test_workflow"}}
109+
config := []*reluipb.Workflow{
110+
{
111+
Name: "test_workflow",
112+
BuildableTasks: []*reluipb.BuildableTask{{Name: "test_task"}},
113+
},
114+
}
110115
cases := []struct {
111116
desc string
112117
params url.Values
@@ -157,6 +162,12 @@ func TestServerCreateWorkflowHandler(t *testing.T) {
157162
if diff := cmp.Diff(c.wantParams, s.store.Workflows()[0].GetParams()); diff != "" {
158163
t.Errorf("s.Store.Workflows()[0].Params() mismatch (-want, +got):\n%s", diff)
159164
}
165+
if s.store.Workflows()[0].GetId() == "" {
166+
t.Errorf("s.Store.Workflows[0].GetId() = %q, wanted not empty", s.store.Workflows()[0].GetId())
167+
}
168+
if s.store.Workflows()[0].GetBuildableTasks()[0].GetId() == "" {
169+
t.Errorf("s.Store.Workflows[0].GetBuildableTasks()[0].GetId() = %q, wanted not empty", s.store.Workflows()[0].GetId())
170+
}
160171
})
161172
}
162173
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/google/go-cmp v0.4.0
2121
github.com/google/go-github v17.0.0+incompatible
2222
github.com/google/go-querystring v1.0.0 // indirect
23+
github.com/google/uuid v1.1.2
2324
github.com/googleapis/gax-go/v2 v2.0.5
2425
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
2526
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hf
112112
github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
113113
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
114114
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
115+
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
116+
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
115117
github.com/googleapis/gax-go/v2 v2.0.4 h1:hU4mGcQI4DaAYW+IbTun+2qEZVFxK0ySjQLTbS0VQKc=
116118
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
117119
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=

0 commit comments

Comments
 (0)