15954: Start websocket and keepstore.
authorTom Clegg <tom@tomclegg.ca>
Mon, 27 Jan 2020 21:10:22 +0000 (16:10 -0500)
committerTom Clegg <tom@tomclegg.ca>
Mon, 27 Jan 2020 21:10:22 +0000 (16:10 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

lib/boot/cmd.go
lib/service/cmd.go

index 361f645059c91afad3aae82392db06138bc9676a..e0e357e1ed1e9ed05dd1e0b1e1ba63916be23156 100644 (file)
@@ -179,8 +179,10 @@ func (boot *bootCommand) RunCommand(prog string, args []string, stdin io.Reader,
                {name: "health", goProg: "services/health"},
                {name: "keep-balance", goProg: "services/keep-balance", notIfTest: true},
                {name: "keepproxy", goProg: "services/keepproxy"},
+               {name: "keepstore", goProg: "services/keepstore", svc: boot.cluster.Services.Keepstore},
                {name: "keep-web", goProg: "services/keep-web"},
                {name: "railsAPI", svc: boot.cluster.Services.RailsAPI, railsApp: "services/api"},
+               {name: "ws", goProg: "services/ws"},
        } {
                cmpt := cmpt
                wg.Add(1)
@@ -202,8 +204,7 @@ func (boot *bootCommand) RunCommand(prog string, args []string, stdin io.Reader,
 func (boot *bootCommand) installGoProgram(ctx context.Context, srcpath string) error {
        boot.goMutex.Lock()
        defer boot.goMutex.Unlock()
-       env := append([]string{"GOPATH=" + boot.libPath}, os.Environ()...)
-       return boot.RunProgram(ctx, filepath.Join(boot.sourcePath, srcpath), nil, env, "go", "install")
+       return boot.RunProgram(ctx, filepath.Join(boot.sourcePath, srcpath), nil, []string{"GOPATH=" + boot.libPath}, "go", "install")
 }
 
 func (boot *bootCommand) setupRubyEnv() error {
@@ -236,7 +237,7 @@ func (boot *bootCommand) RunProgram(ctx context.Context, dir string, output io.W
                cmd.Dir = filepath.Join(boot.sourcePath, dir)
        }
        if env != nil {
-               cmd.Env = env
+               cmd.Env = append(env, os.Environ()...)
        }
        go func() {
                <-ctx.Done()
@@ -296,7 +297,23 @@ func (cmpt *component) Run(ctx context.Context, boot *bootCommand, stdout, stder
                }
        }
        if cmpt.goProg != "" {
-               return boot.RunProgram(ctx, cmpt.goProg, nil, nil, "go", "run", ".")
+               if len(cmpt.svc.InternalURLs) > 0 {
+                       // Run one for each URL
+                       var wg sync.WaitGroup
+                       for u := range cmpt.svc.InternalURLs {
+                               u := u
+                               wg.Add(1)
+                               go func() {
+                                       defer wg.Done()
+                                       boot.RunProgram(ctx, cmpt.goProg, nil, []string{"ARVADOS_SERVICE_INTERNAL_URL=" + u.String()}, "go", "run", ".")
+                               }()
+                       }
+                       wg.Wait()
+                       return nil
+               } else {
+                       // Just run one
+                       return boot.RunProgram(ctx, cmpt.goProg, nil, nil, "go", "run", ".")
+               }
        }
        if cmpt.runFunc != nil {
                return cmpt.runFunc(ctx, boot, stdout, stderr)
@@ -407,12 +424,29 @@ func (boot *bootCommand) autofillConfig(cfg *arvados.Config, log logrus.FieldLog
        if boot.clusterType != "production" {
                cluster.TLS.Insecure = true
        }
-       if boot.clusterType == "test" && len(cluster.Volumes) == 0 {
-               cluster.Volumes = map[string]arvados.Volume{
-                       "zzzzz-nyw5e-000000000000000": arvados.Volume{
-                               Driver:           "Directory",
-                               DriverParameters: json.RawMessage(fmt.Sprintf(`{"Root":%q}`, boot.tempdir+"/keep0")),
-                       },
+       if boot.clusterType == "test" {
+               port++
+               cluster.Services.Keepstore.InternalURLs[arvados.URL{Scheme: "http", Host: fmt.Sprintf("localhost:%d", port)}] = arvados.ServiceInstance{}
+
+               n := -1
+               for url := range cluster.Services.Keepstore.InternalURLs {
+                       n++
+                       datadir := fmt.Sprintf("%s/keep%d.data", boot.tempdir, n)
+                       if _, err = os.Stat(datadir + "/."); err == nil {
+                       } else if !os.IsNotExist(err) {
+                               return err
+                       } else if err = os.Mkdir(datadir, 0777); err != nil {
+                               return err
+                       }
+                       cluster.Volumes = map[string]arvados.Volume{
+                               fmt.Sprintf("zzzzz-nyw5e-%015d", n): arvados.Volume{
+                                       Driver:           "Directory",
+                                       DriverParameters: json.RawMessage(fmt.Sprintf(`{"Root":%q}`, datadir)),
+                                       AccessViaHosts: map[arvados.URL]arvados.VolumeAccess{
+                                               url: {},
+                                       },
+                               },
+                       }
                }
        }
        cfg.Clusters[cluster.ClusterID] = *cluster
index f1f3fd91dbe211a0742db03fec3052853c255b75..48912b8898c4cce944c43f3879c4a03ac25a87f8 100644 (file)
@@ -12,6 +12,7 @@ import (
        "io"
        "net"
        "net/http"
+       "net/url"
        "os"
        "strings"
 
@@ -164,6 +165,14 @@ func getListenAddr(svcs arvados.Services, prog arvados.ServiceName, log logrus.F
        if !ok {
                return arvados.URL{}, fmt.Errorf("unknown service name %q", prog)
        }
+
+       if want := os.Getenv("ARVADOS_SERVICE_INTERNAL_URL"); want == "" {
+       } else if url, err := url.Parse(want); err != nil {
+               return arvados.URL{}, fmt.Errorf("$ARVADOS_SERVICE_INTERNAL_URL (%q): %s", want, err)
+       } else {
+               return arvados.URL(*url), nil
+       }
+
        errors := []string{}
        for url := range svc.InternalURLs {
                listener, err := net.Listen("tcp", url.Host)