Skip to content

Commit 6865319

Browse files
committed
cmd/relui, cmd/relworker: remove pubsub and datastore
This will make room for a new workflow definition, and a new datastore. For golang/go#47401 Change-Id: I4bdc8a9a0ed2c5a3743284d0f267b838dddec8aa Reviewed-on: https://go-review.googlesource.com/c/build/+/340430 Trust: Alexander Rakoczy <[email protected]> Run-TryBot: Alexander Rakoczy <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent f740ced commit 6865319

File tree

8 files changed

+7
-238
lines changed

8 files changed

+7
-238
lines changed

cmd/relui/main.go

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,17 @@
99
package main
1010

1111
import (
12-
"context"
13-
"flag"
14-
"io/ioutil"
1512
"log"
1613
"net/http"
1714
"os"
18-
"path/filepath"
1915

20-
"cloud.google.com/go/datastore"
21-
"cloud.google.com/go/pubsub"
22-
"github.com/golang/protobuf/proto"
23-
"github.com/googleapis/google-cloud-go-testing/datastore/dsiface"
24-
reluipb "golang.org/x/build/cmd/relui/protos"
25-
"google.golang.org/grpc/codes"
26-
"google.golang.org/grpc/status"
27-
)
28-
29-
var (
30-
projectID = flag.String("project-id", os.Getenv("PUBSUB_PROJECT_ID"), "Pubsub project ID for communicating with workers. Uses PUBSUB_PROJECT_ID if unset.")
31-
topicID = flag.String("topic-id", "relui-development", "Pubsub topic ID for communicating with workers.")
16+
"golang.org/x/build/internal/datastore/fake"
3217
)
3318

3419
func main() {
35-
flag.Parse()
36-
ctx := context.Background()
37-
dsc, err := datastore.NewClient(ctx, *projectID)
38-
if err != nil {
39-
log.Fatalf("datastore.NewClient(_, %q) = _, %v, wanted no error", *projectID, err)
40-
}
41-
d := &dsStore{client: dsiface.AdaptClient(dsc)}
20+
d := &dsStore{client: &fake.Client{}}
4221
s := &server{
43-
configs: loadWorkflowConfig("./workflows"),
44-
store: d,
45-
topic: getTopic(ctx),
22+
store: d,
4623
}
4724
http.Handle("/workflows/create", http.HandlerFunc(s.createWorkflowHandler))
4825
http.Handle("/workflows/new", http.HandlerFunc(s.newWorkflowHandler))
@@ -55,44 +32,3 @@ func main() {
5532
log.Printf("Listening on :" + port)
5633
log.Fatal(http.ListenAndServe(":"+port, http.DefaultServeMux))
5734
}
58-
59-
// getTopic creates and returns a pubsub topic from the project specified in projectId, which is to be used for
60-
// communicating with relui workers.
61-
//
62-
// It is safe to call if a topic already exists. A reference to the topic will be returned.
63-
func getTopic(ctx context.Context) *pubsub.Topic {
64-
client, err := pubsub.NewClient(ctx, *projectID)
65-
if err != nil {
66-
log.Fatalf("pubsub.NewClient(_, %q) = %v, wanted no error", *projectID, err)
67-
}
68-
_, err = client.CreateTopic(ctx, *topicID)
69-
if err != nil && status.Code(err) != codes.AlreadyExists {
70-
log.Fatalf("client.CreateTopic(_, %q) = %v, wanted no error", *topicID, err)
71-
}
72-
return client.Topic(*topicID)
73-
}
74-
75-
// loadWorkflowConfig loads Workflow configuration files from dir. It expects all files to be in textproto format.
76-
func loadWorkflowConfig(dir string) []*reluipb.Workflow {
77-
fs, err := filepath.Glob(filepath.Join(relativeFile(dir), "*.textpb"))
78-
if err != nil {
79-
log.Fatalf("Error perusing %q for configuration", filepath.Join(dir, "*.textpb"))
80-
}
81-
if len(fs) == 0 {
82-
log.Println("No workflow configuration found.")
83-
}
84-
var ws []*reluipb.Workflow
85-
for _, f := range fs {
86-
b, err := ioutil.ReadFile(f)
87-
if err != nil {
88-
log.Printf("ioutil.ReadFile(%q) = _, %v, wanted no error", f, err)
89-
}
90-
w := new(reluipb.Workflow)
91-
if err = proto.UnmarshalText(string(b), w); err != nil {
92-
log.Printf("Error unmarshalling Workflow from %q: %v", f, err)
93-
continue
94-
}
95-
ws = append(ws, w)
96-
}
97-
return ws
98-
}

cmd/relui/web.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"path"
2020
"path/filepath"
2121

22-
"cloud.google.com/go/pubsub"
2322
"github.com/golang/protobuf/proto"
2423
"github.com/google/uuid"
2524
reluipb "golang.org/x/build/cmd/relui/protos"
@@ -56,9 +55,6 @@ type server struct {
5655

5756
// store is for persisting application state.
5857
store store
59-
60-
// topic is for communicating with relui workers.
61-
topic *pubsub.Topic
6258
}
6359

6460
type homeResponse struct {
@@ -119,24 +115,11 @@ func (s *server) createWorkflowHandler(w http.ResponseWriter, r *http.Request) {
119115
}
120116

121117
func (s *server) startTaskHandler(w http.ResponseWriter, r *http.Request) {
122-
wf := s.store.Workflow(r.PostFormValue("workflow.id"))
123118
bt := s.store.BuildableTask(r.PostFormValue("workflow.id"), r.PostFormValue("task.id"))
124119
if bt == nil {
125120
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
126121
return
127122
}
128-
res := s.topic.Publish(r.Context(), &pubsub.Message{
129-
Data: []byte((&reluipb.StartBuildableTaskRequest{
130-
WorkflowId: wf.GetId(),
131-
BuildableTaskId: bt.GetId(),
132-
BuildableTaskType: bt.GetTaskType(),
133-
}).String()),
134-
})
135-
if _, err := res.Get(r.Context()); err != nil {
136-
log.Printf("Error publishing task start: %v", err)
137-
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
138-
return
139-
}
140123
http.Redirect(w, r, "/", http.StatusSeeOther)
141124
}
142125

cmd/relui/web_test.go

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package main
99

1010
import (
11-
"context"
1211
"embed"
1312
"io/ioutil"
1413
"net/http"
@@ -17,12 +16,8 @@ import (
1716
"strings"
1817
"testing"
1918

20-
"cloud.google.com/go/pubsub"
21-
"cloud.google.com/go/pubsub/pstest"
2219
reluipb "golang.org/x/build/cmd/relui/protos"
2320
"golang.org/x/build/internal/datastore/fake"
24-
"google.golang.org/api/option"
25-
"google.golang.org/grpc"
2621
)
2722

2823
// testStatic is our static web server content.
@@ -182,41 +177,8 @@ func TestServerCreateWorkflowHandler(t *testing.T) {
182177
}
183178
}
184179

185-
// newPSTest creates a new pstest.Server and returns a pubsub.Client connected to it and the server.
186-
//
187-
// cleanup will close the client, connection, and test server.
188-
func newPSTest(ctx context.Context, t *testing.T) (c *pubsub.Client, s *pstest.Server, cleanup func()) {
189-
t.Helper()
190-
s = pstest.NewServer()
191-
conn, err := grpc.DialContext(ctx, s.Addr, grpc.WithInsecure())
192-
if err != nil {
193-
s.Close()
194-
t.Fatalf("grpc.DialContext(_, %q, %v) = _, %v, wanted no error", s.Addr, grpc.WithInsecure(), err)
195-
}
196-
c, err = pubsub.NewClient(ctx, "relui-test", option.WithGRPCConn(conn))
197-
if err != nil {
198-
s.Close()
199-
conn.Close()
200-
t.Fatalf("pubsub.NewClient(_, %q, %v) = _, %v, wanted no error", "relui-test", option.WithGRPCConn(conn), err)
201-
}
202-
return c, s, func() {
203-
c.Close()
204-
conn.Close()
205-
s.Close()
206-
}
207-
}
208-
209180
func TestServerStartTaskHandler(t *testing.T) {
210-
ctx, cancel := context.WithCancel(context.Background())
211-
defer cancel()
212-
client, pssrv, cleanup := newPSTest(ctx, t)
213-
defer cleanup()
214-
topic, err := client.CreateTopic(ctx, "relui-test-topic")
215-
if err != nil {
216-
t.Fatalf("client.CreateTopic(_, %q) = _, %v", "relui-test-topic", err)
217-
}
218-
219-
s := server{store: &dsStore{client: &fake.Client{}}, topic: topic}
181+
s := server{store: &dsStore{client: &fake.Client{}}}
220182
wf := &reluipb.Workflow{
221183
Id: "someworkflow",
222184
Name: "test_workflow",
@@ -226,14 +188,9 @@ func TestServerStartTaskHandler(t *testing.T) {
226188
Id: "sometask",
227189
}},
228190
}
229-
if s.store.AddWorkflow(wf) != nil {
191+
if err := s.store.AddWorkflow(wf); err != nil {
230192
t.Fatalf("store.AddWorkflow(%v) = %v, wanted no error", wf, err)
231193
}
232-
want := &reluipb.StartBuildableTaskRequest{
233-
WorkflowId: "someworkflow",
234-
BuildableTaskId: "sometask",
235-
BuildableTaskType: "TestTask",
236-
}
237194
params := url.Values{"workflow.id": []string{"someworkflow"}, "task.id": []string{"sometask"}}
238195
req := httptest.NewRequest(http.MethodPost, "/tasks/start", strings.NewReader(params.Encode()))
239196
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
@@ -248,13 +205,6 @@ func TestServerStartTaskHandler(t *testing.T) {
248205
if resp.Header.Get("Location") != "/" {
249206
t.Errorf("resp.Header.Get(%q) = %q, wanted %q", "Location", resp.Header.Get("Location"), "/")
250207
}
251-
if len(pssrv.Messages()) != 1 {
252-
t.Fatalf("len(pssrv.Messages()) = %d, wanted %d", len(pssrv.Messages()), 1)
253-
}
254-
msg := pssrv.Messages()[0]
255-
if string(msg.Data) != want.String() {
256-
t.Errorf("msg.Data = %q, wanted %q", string(msg.Data), "hello world")
257-
}
258208
}
259209

260210
func TestStartTaskHandlerErrors(t *testing.T) {
@@ -278,27 +228,11 @@ func TestStartTaskHandlerErrors(t *testing.T) {
278228
params: url.Values{"workflow.id": []string{"someworkflow"}, "task.id": []string{"notexist"}},
279229
wantCode: http.StatusNotFound,
280230
},
281-
{
282-
desc: "pubsub publish failure",
283-
params: url.Values{"workflow.id": []string{"someworkflow"}, "task.id": []string{"sometask"}},
284-
wantCode: http.StatusInternalServerError,
285-
},
286231
}
287232
for _, c := range cases {
288233
t.Run(c.desc, func(t *testing.T) {
289-
ctx, cancel := context.WithCancel(context.Background())
290-
defer cancel()
291-
client, pssrv, cleanup := newPSTest(ctx, t)
292-
defer cleanup()
293-
topic, err := client.CreateTopic(ctx, "relui-test-topic")
294-
if err != nil {
295-
t.Fatalf("client.CreateTopic(_, %q) = _, %v", "relui-test-topic", err)
296-
}
297-
// Simulate pubsub failure by stopping publishing.
298-
topic.Stop()
299-
300-
s := server{store: &dsStore{client: &fake.Client{}}, topic: topic}
301-
if s.store.AddWorkflow(wf) != nil {
234+
s := server{store: &dsStore{client: &fake.Client{}}}
235+
if err := s.store.AddWorkflow(wf); err != nil {
302236
t.Fatalf("store.AddWorkflow(%v) = %v, wanted no error", wf, err)
303237
}
304238
req := httptest.NewRequest(http.MethodPost, "/tasks/start", strings.NewReader(c.params.Encode()))
@@ -311,9 +245,6 @@ func TestStartTaskHandlerErrors(t *testing.T) {
311245
if resp.StatusCode != c.wantCode {
312246
t.Errorf("resp.StatusCode = %d, wanted %d", resp.StatusCode, c.wantCode)
313247
}
314-
if len(pssrv.Messages()) != 0 {
315-
t.Fatalf("len(pssrv.Messages()) = %d, wanted %d", len(pssrv.Messages()), 0)
316-
}
317248
})
318249
}
319250
}

cmd/relui/workflows/local_go_release.textpb

Lines changed: 0 additions & 13 deletions
This file was deleted.

cmd/relworker/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

cmd/relworker/main.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
cloud.google.com/go v0.65.0
77
cloud.google.com/go/bigquery v1.8.0
88
cloud.google.com/go/datastore v1.1.0
9-
cloud.google.com/go/pubsub v1.3.1
109
cloud.google.com/go/storage v1.10.0
1110
contrib.go.opencensus.io/exporter/prometheus v0.3.0
1211
contrib.go.opencensus.io/exporter/stackdriver v0.13.5

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1
2929
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
3030
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
3131
cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA=
32-
cloud.google.com/go/pubsub v1.3.1 h1:ukjixP1wl0LpnZ6LWtZJ0mX5tBmjp1f8Sqer8Z2OMUU=
3332
cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU=
3433
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
3534
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=

0 commit comments

Comments
 (0)