Merge "core: Remove old profiles and make new profiles parse flags for runtime."
diff --git a/lib/signals/signals_test.go b/lib/signals/signals_test.go
index 83f3438..af499a8 100644
--- a/lib/signals/signals_test.go
+++ b/lib/signals/signals_test.go
@@ -22,7 +22,7 @@
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/lib/testutil"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
vflag "v.io/core/veyron/security/flag"
"v.io/core/veyron/services/mgmt/device"
)
@@ -40,7 +40,7 @@
modules.RegisterChild("handleDefaultsIgnoreChan", "", handleDefaultsIgnoreChan)
}
-func stopLoop(ctx *context.T, stdin io.Reader, ch chan<- struct{}) {
+func stopLoop(stop func(), stdin io.Reader, ch chan<- struct{}) {
scanner := bufio.NewScanner(stdin)
for scanner.Scan() {
switch scanner.Text() {
@@ -48,7 +48,7 @@
close(ch)
return
case "stop":
- veyron2.GetAppCycle(ctx).Stop()
+ stop()
}
}
}
@@ -57,7 +57,7 @@
ctx, shutdown := veyron2.Init()
closeStopLoop := make(chan struct{})
- go stopLoop(ctx, stdin, closeStopLoop)
+ go stopLoop(veyron2.GetAppCycle(ctx).Stop, stdin, closeStopLoop)
wait := ShutdownOnSignals(ctx, signals...)
fmt.Fprintf(stdout, "ready\n")
fmt.Fprintf(stdout, "received signal %s\n", <-wait)
@@ -85,7 +85,7 @@
defer shutdown()
closeStopLoop := make(chan struct{})
- go stopLoop(ctx, stdin, closeStopLoop)
+ go stopLoop(veyron2.GetAppCycle(ctx).Stop, stdin, closeStopLoop)
ShutdownOnSignals(ctx)
fmt.Fprintf(stdout, "ready\n")
<-closeStopLoop
@@ -352,7 +352,7 @@
}
ch := make(chan string)
var ep []naming.Endpoint
- if ep, err = server.Listen(profiles.LocalListenSpec); err != nil {
+ if ep, err = server.Listen(veyron2.GetListenSpec(ctx)); err != nil {
t.Fatalf("Got error: %v", err)
}
if err := server.Serve("", device.ConfigServer(&configServer{ch}), vflag.NewAuthorizerOrDie()); err != nil {
diff --git a/profiles/chrome/chrome.go b/profiles/chrome/chrome.go
deleted file mode 100644
index ef9235e..0000000
--- a/profiles/chrome/chrome.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Package chrome implements a profile for use within Chrome, in particular
-// for use by Chrome extensions.
-package chrome
-
-import (
- "v.io/core/veyron2"
- "v.io/core/veyron2/config"
- "v.io/core/veyron2/ipc"
- "v.io/core/veyron2/options"
-
- "v.io/core/veyron/profiles/internal/platform"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh_nacl"
- _ "v.io/core/veyron/runtimes/google/rt"
-)
-
-var ListenSpec = ipc.ListenSpec{}
-
-type chrome struct{}
-
-// New returns a new instance of a Profile for use within chrome, in particular
-// chrome extensions etc should use.
-func New() veyron2.Profile {
- return &chrome{}
-}
-
-func (*chrome) Name() string {
- return "chrome"
-}
-
-func (*chrome) Runtime() (string, []veyron2.ROpt) {
- return veyron2.GoogleRuntimeName, []veyron2.ROpt{options.PreferredProtocols{"wsh", "ws"}}
-}
-
-func (*chrome) Platform() *veyron2.Platform {
- p, _ := platform.Platform()
- return p
-}
-
-func (c *chrome) Init(rt veyron2.Runtime, _ *config.Publisher) (veyron2.AppCycle, error) {
- veyron2.GetLogger(rt.NewContext()).VI(1).Infof("%s", c)
- return nil, nil
-}
-
-func (*chrome) Cleanup() {}
-
-func (c *chrome) String() string {
- return "chrome profile on " + c.Platform().String()
-}
diff --git a/profiles/chrome/chromeinit.go b/profiles/chrome/chromeinit.go
index 804ae73..9fad3ae 100644
--- a/profiles/chrome/chromeinit.go
+++ b/profiles/chrome/chromeinit.go
@@ -3,25 +3,38 @@
package chrome
import (
+ "flag"
+
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc/stream"
+ "v.io/core/veyron2/vlog"
+ "v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/websocket"
+ "v.io/core/veyron/profiles/internal"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
+ _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh_nacl"
grt "v.io/core/veyron/runtimes/google/rt"
)
+var commonFlags *flags.Flags
+
func init() {
veyron2.RegisterProfileInit(Init)
stream.RegisterUnknownProtocol("wsh", websocket.Dial, websocket.Listener)
+ commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime)
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- runtime, ctx, shutdown, err := grt.Init(ctx, nil, nil, nil, nil)
+ if err := internal.ParseFlags(commonFlags); err != nil {
+ return nil, nil, nil, err
+ }
+
+ runtime, ctx, shutdown, err := grt.Init(ctx, nil, nil, nil, commonFlags.RuntimeFlags(), nil)
if err != nil {
return nil, nil, shutdown, err
}
- runtime.GetLogger(ctx).VI(1).Infof("Initializing chrome profile.")
+ vlog.Log.VI(1).Infof("Initializing chrome profile.")
return runtime, ctx, shutdown, nil
}
diff --git a/profiles/gce/init.go b/profiles/gce/init.go
deleted file mode 100644
index 2882a08..0000000
--- a/profiles/gce/init.go
+++ /dev/null
@@ -1,77 +0,0 @@
-// +build linux
-
-// Package gce provides a Profile for Google Compute Engine and should be
-// used by binaries that only ever expect to be run on GCE.
-package gce
-
-import (
- "fmt"
- "net"
-
- "v.io/core/veyron2"
- "v.io/core/veyron2/config"
- "v.io/core/veyron2/ipc"
-
- "v.io/core/veyron/lib/appcycle"
- "v.io/core/veyron/lib/netstate"
- "v.io/core/veyron/profiles/internal/gce"
- "v.io/core/veyron/profiles/internal/platform"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
- _ "v.io/core/veyron/runtimes/google/rt"
-)
-
-var (
- // ListenSpec is an initialized instance of ipc.ListenSpec that can
- // be used with ipc.Listen.
- ListenSpec ipc.ListenSpec
-)
-
-type profile struct {
- ac *appcycle.AppCycle
-}
-
-func (p *profile) Name() string {
- return "GCE"
-}
-
-func (p *profile) Runtime() (string, []veyron2.ROpt) {
- return "", nil
-}
-
-func (p *profile) Platform() *veyron2.Platform {
- pstr, _ := platform.Platform()
- return pstr
-}
-
-func (p *profile) String() string {
- return "net " + p.Platform().String()
-}
-
-func (p *profile) Init(veyron2.Runtime, *config.Publisher) (veyron2.AppCycle, error) {
- if !gce.RunningOnGCE() {
- return nil, fmt.Errorf("GCE profile used on a non-GCE system")
- }
-
- lf := commonFlags.ListenFlags()
- ListenSpec = ipc.ListenSpec{
- Addrs: ipc.ListenAddrs(lf.Addrs),
- Proxy: lf.ListenProxy,
- }
-
- p.ac = appcycle.New()
-
- if ip, err := gce.ExternalIPAddress(); err != nil {
- return p.ac, err
- } else {
- ListenSpec.AddressChooser = func(network string, addrs []ipc.Address) ([]ipc.Address, error) {
- return []ipc.Address{&netstate.AddrIfc{&net.IPAddr{IP: ip}, "gce-nat", nil}}, nil
- }
- }
- return p.ac, nil
-}
-
-func (p *profile) Cleanup() {
- p.ac.Shutdown()
-}
diff --git a/profiles/gce/initx.go b/profiles/gce/initx.go
index b344955..191e8cf 100644
--- a/profiles/gce/initx.go
+++ b/profiles/gce/initx.go
@@ -8,7 +8,6 @@
"flag"
"fmt"
"net"
- "os"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
@@ -20,6 +19,7 @@
"v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/netstate"
"v.io/core/veyron/lib/websocket"
+ "v.io/core/veyron/profiles/internal"
"v.io/core/veyron/profiles/internal/gce"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
@@ -27,25 +27,25 @@
grt "v.io/core/veyron/runtimes/google/rt"
)
-var (
- commonFlags *flags.Flags
-)
+var commonFlags *flags.Flags
func init() {
- commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Listen)
veyron2.RegisterProfileInit(Init)
stream.RegisterUnknownProtocol("wsh", websocket.HybridDial, websocket.HybridListener)
+ commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime, flags.Listen)
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- vlog.Log.VI(1).Infof("Initializing GCE profile.")
if !gce.RunningOnGCE() {
return nil, nil, nil, fmt.Errorf("GCE profile used on a non-GCE system")
}
+ if err := internal.ParseFlags(commonFlags); err != nil {
+ return nil, nil, nil, err
+ }
+
ac := appcycle.New()
- commonFlags.Parse(os.Args[1:], nil)
lf := commonFlags.ListenFlags()
listenSpec := ipc.ListenSpec{
Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -60,11 +60,13 @@
}
}
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, nil)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, commonFlags.RuntimeFlags(), nil)
if err != nil {
return nil, nil, shutdown, err
}
+ vlog.Log.VI(1).Infof("Initializing GCE profile.")
+
profileShutdown := func() {
ac.Shutdown()
shutdown()
diff --git a/profiles/generic.go b/profiles/generic.go
deleted file mode 100644
index 20af927..0000000
--- a/profiles/generic.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package profiles
-
-import (
- "v.io/core/veyron2"
- "v.io/core/veyron2/config"
- "v.io/core/veyron2/ipc"
-
- "v.io/core/veyron/lib/appcycle"
- "v.io/core/veyron/profiles/internal"
- "v.io/core/veyron/profiles/internal/platform"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
- _ "v.io/core/veyron/runtimes/google/rt"
-)
-
-// LocalListenSpec is a ListenSpec for 127.0.0.1.
-var LocalListenSpec = ipc.ListenSpec{
- Addrs: ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}},
- AddressChooser: internal.IPAddressChooser,
-}
-
-type generic struct{ ac *appcycle.AppCycle }
-
-var _ veyron2.Profile = (*generic)(nil)
-
-// New returns a new instance of a very generic Profile. It can be used
-// as a default by Runtime implementations, in unit tests etc.
-func New() veyron2.Profile {
- return &generic{}
-}
-
-func (*generic) Name() string {
- return "generic"
-}
-
-func (*generic) Runtime() (string, []veyron2.ROpt) {
- return veyron2.GoogleRuntimeName, nil
-}
-
-func (*generic) Platform() *veyron2.Platform {
- pstr, _ := platform.Platform()
- return pstr
-}
-
-func (g *generic) Init(rt veyron2.Runtime, _ *config.Publisher) (veyron2.AppCycle, error) {
- veyron2.GetLogger(rt.NewContext()).VI(1).Infof("%s", g)
- g.ac = appcycle.New()
- return g.ac, nil
-}
-
-func (g *generic) Cleanup() {
- g.ac.Shutdown()
-}
-
-func (g *generic) String() string {
- return "generic profile on " + g.Platform().String()
-}
diff --git a/profiles/genericinit.go b/profiles/genericinit.go
index 95f28a5..695ebfc 100644
--- a/profiles/genericinit.go
+++ b/profiles/genericinit.go
@@ -1,12 +1,16 @@
package profiles
import (
+ "flag"
+
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/ipc/stream"
+ "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/appcycle"
+ "v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/websocket"
"v.io/core/veyron/profiles/internal"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
@@ -15,12 +19,19 @@
grt "v.io/core/veyron/runtimes/google/rt"
)
+var commonFlags *flags.Flags
+
func init() {
veyron2.RegisterProfileInit(Init)
stream.RegisterUnknownProtocol("wsh", websocket.HybridDial, websocket.HybridListener)
+ commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime)
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
+ if err := internal.ParseFlags(commonFlags); err != nil {
+ return nil, nil, nil, err
+ }
+
ac := appcycle.New()
runtime, ctx, shutdown, err := grt.Init(ctx,
@@ -30,11 +41,12 @@
Addrs: ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}},
AddressChooser: internal.IPAddressChooser,
},
+ commonFlags.RuntimeFlags(),
nil)
if err != nil {
return nil, nil, nil, err
}
- runtime.GetLogger(ctx).VI(1).Infof("Initializing generic profile.")
+ vlog.Log.VI(1).Infof("Initializing generic profile.")
profileShutdown := func() {
ac.Shutdown()
diff --git a/profiles/internal/util.go b/profiles/internal/util.go
index 66c6ac8..ac8a062 100644
--- a/profiles/internal/util.go
+++ b/profiles/internal/util.go
@@ -2,13 +2,42 @@
import (
"fmt"
+ "os"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/vlog"
+ "v.io/core/veyron/lib/exec"
+ "v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/netstate"
)
+// ParseFlags parses all registered flags taking into account overrides from other
+// configuration and environment variables. It must be called by the profile and
+// flags.RuntimeFlags() must be passed to the runtime initialization function. The
+// profile can use or modify the flags as it pleases.
+func ParseFlags(f *flags.Flags) error {
+ handle, err := exec.GetChildHandle()
+ switch err {
+ case exec.ErrNoVersion:
+ // The process has not been started through the veyron exec
+ // library. No further action is needed.
+ case nil:
+ // The process has been started through the veyron exec
+ // library.
+ default:
+ return err
+ }
+
+ // Parse runtime flags.
+ var config map[string]string
+ if handle != nil {
+ config = handle.Config.Dump()
+ }
+ f.Parse(os.Args[1:], config)
+ return nil
+}
+
// IPAddressChooser returns the preferred IP address, which is,
// a public IPv4 address, then any non-loopback IPv4, then a public
// IPv6 address and finally any non-loopback/link-local IPv6
diff --git a/profiles/profiles_test.go b/profiles/profiles_test.go
deleted file mode 100644
index fc38e4d..0000000
--- a/profiles/profiles_test.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package profiles_test
-
-import (
- "os"
- "testing"
-
- "v.io/core/veyron/profiles"
-)
-
-func TestGeneric(t *testing.T) {
- p := profiles.New()
-
- if got, want := p.Name(), "generic"; got != want {
- t.Errorf("got %q, want %q", got, want)
- }
- hostname, _ := os.Hostname()
- if got, want := p.Platform().Node, hostname; got != want {
- t.Errorf("got %q, want %q", got, want)
- }
-}
diff --git a/profiles/roaming/net_watcher.go b/profiles/roaming/net_watcher.go
index 607bcd4..2784430 100644
--- a/profiles/roaming/net_watcher.go
+++ b/profiles/roaming/net_watcher.go
@@ -17,7 +17,7 @@
ctx, shutdown := veyron2.Init()
defer shutdown()
- profileName := veyron2.GetProfile(ctx).Name()
+ profileName := "roaming"
fmt.Println("Profile: ", profileName)
accessible, err := netstate.GetAccessibleIPs()
diff --git a/profiles/roaming/roaming.go b/profiles/roaming/roaming.go
deleted file mode 100644
index b4acfb5..0000000
--- a/profiles/roaming/roaming.go
+++ /dev/null
@@ -1,185 +0,0 @@
-// +build linux darwin
-
-// Package roaming provides a network-aware Profile that provides appropriate
-// options and configuration for a variety of network configurations, including
-// being behind 1-1 NATs, using dhcp and auto-configuration for being on
-// Google Compute Engine.
-//
-// The config.Publisher mechanism is used for communicating networking
-// settings to the ipc.Server implementation of the runtime and publishes
-// the Settings it expects.
-package roaming
-
-import (
- "v.io/core/veyron2"
- "v.io/core/veyron2/config"
- "v.io/core/veyron2/ipc"
-
- "v.io/core/veyron/lib/appcycle"
- "v.io/core/veyron/lib/netconfig"
- "v.io/core/veyron/lib/netstate"
- "v.io/core/veyron/profiles/internal"
- "v.io/core/veyron/profiles/internal/platform"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
- _ "v.io/core/veyron/runtimes/google/rt"
- "v.io/core/veyron/services/mgmt/debug"
-
- // TODO(cnicolaou,ashankar): move this into flags.
- sflag "v.io/core/veyron/security/flag"
-)
-
-var (
- // ListenSpec is an initialized instance of ipc.ListenSpec that can
- // be used with ipc.Listen.
- ListenSpec ipc.ListenSpec
-)
-
-type profile struct {
- gce string
- ac *appcycle.AppCycle
- cleanupCh, watcherCh chan struct{}
-}
-
-func New() veyron2.Profile {
- return &profile{}
-}
-
-func (p *profile) Platform() *veyron2.Platform {
- pstr, _ := platform.Platform()
- return pstr
-}
-
-func (p *profile) Name() string {
- return "roaming" + p.gce
-}
-
-func (p *profile) Runtime() (string, []veyron2.ROpt) {
- return veyron2.GoogleRuntimeName, nil
-}
-
-func (p *profile) String() string {
- return p.Name() + " " + p.Platform().String()
-}
-
-func (p *profile) Init(rt veyron2.Runtime, publisher *config.Publisher) (veyron2.AppCycle, error) {
- log := veyron2.GetLogger(rt.NewContext())
-
- rt.ConfigureReservedName(debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie()))
-
- lf := commonFlags.ListenFlags()
- ListenSpec = ipc.ListenSpec{
- Addrs: ipc.ListenAddrs(lf.Addrs),
- Proxy: lf.ListenProxy,
- }
-
- p.ac = appcycle.New()
-
- // Our address is private, so we test for running on GCE and for its
- // 1:1 NAT configuration.
- if !internal.HasPublicIP(log) {
- if addr := internal.GCEPublicAddress(log); addr != nil {
- ListenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
- return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
- }
- p.gce = "+gce"
- return p.ac, nil
- }
- }
-
- // Create stream in Init function to avoid a race between any
- // goroutines started here and consumers started after Init returns.
- ch := make(chan config.Setting)
- stop, err := publisher.CreateStream(SettingsStreamName, SettingsStreamName, ch)
- if err != nil {
- log.Errorf("failed to create publisher: %s", err)
- p.ac.Shutdown()
- return nil, err
- }
-
- prev, err := netstate.GetAccessibleIPs()
- if err != nil {
- log.VI(2).Infof("failed to determine network state")
- p.ac.Shutdown()
- return nil, err
- }
-
- // Start the dhcp watcher.
- watcher, err := netconfig.NewNetConfigWatcher()
- if err != nil {
- log.VI(2).Infof("Failed to get new config watcher: %s", err)
- p.ac.Shutdown()
- return nil, err
- }
-
- p.cleanupCh = make(chan struct{})
- p.watcherCh = make(chan struct{})
-
- ListenSpec.StreamPublisher = publisher
- ListenSpec.StreamName = SettingsStreamName
- ListenSpec.AddressChooser = internal.IPAddressChooser
-
- go monitorNetworkSettings(rt, watcher, prev, stop, p.cleanupCh, p.watcherCh, ch, ListenSpec)
- return p.ac, nil
-}
-
-func (p *profile) Cleanup() {
- if p.cleanupCh != nil {
- close(p.cleanupCh)
- }
- if p.ac != nil {
- p.ac.Shutdown()
- }
- if p.watcherCh != nil {
- <-p.watcherCh
- }
-}
-
-// monitorNetworkSettings will monitor network configuration changes and
-// publish subsequent Settings to reflect any changes detected.
-func monitorNetworkSettings(rt veyron2.Runtime, watcher netconfig.NetConfigWatcher, prev netstate.AddrList, pubStop, cleanup <-chan struct{},
- watcherLoop chan<- struct{}, ch chan<- config.Setting, listenSpec ipc.ListenSpec) {
- defer close(ch)
-
- log := veyron2.GetLogger(rt.NewContext())
-
- // TODO(cnicolaou): add support for listening on multiple network addresses.
-
-done:
- for {
- select {
- case <-watcher.Channel():
- cur, err := netstate.GetAccessibleIPs()
- if err != nil {
- log.Errorf("failed to read network state: %s", err)
- continue
- }
- removed := netstate.FindRemoved(prev, cur)
- added := netstate.FindAdded(prev, cur)
- log.VI(2).Infof("Previous: %d: %s", len(prev), prev)
- log.VI(2).Infof("Current : %d: %s", len(cur), cur)
- log.VI(2).Infof("Added : %d: %s", len(added), added)
- log.VI(2).Infof("Removed : %d: %s", len(removed), removed)
- if len(removed) == 0 && len(added) == 0 {
- log.VI(2).Infof("Network event that lead to no address changes since our last 'baseline'")
- continue
- }
- if len(removed) > 0 {
- log.VI(2).Infof("Sending removed: %s", removed)
- ch <- ipc.NewRmAddrsSetting(removed)
- }
- // We will always send the best currently available address
- if chosen, err := listenSpec.AddressChooser(listenSpec.Addrs[0].Protocol, cur); err == nil && chosen != nil {
- ch <- ipc.NewAddAddrsSetting(chosen)
- }
- prev = cur
- case <-cleanup:
- break done
- case <-pubStop:
- goto done
- }
- }
- watcher.Stop()
- close(watcherLoop)
-}
diff --git a/profiles/roaming/roaminginit.go b/profiles/roaming/roaminginit.go
index e09d5f0..bc2cb4b 100644
--- a/profiles/roaming/roaminginit.go
+++ b/profiles/roaming/roaminginit.go
@@ -12,7 +12,6 @@
import (
"flag"
- "os"
"v.io/core/veyron2"
"v.io/core/veyron2/config"
@@ -22,7 +21,6 @@
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/appcycle"
- "v.io/core/veyron/lib/exec"
"v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/netconfig"
"v.io/core/veyron/lib/netstate"
@@ -42,52 +40,36 @@
SettingsStreamName = "roaming"
)
-var (
- commonFlags *flags.Flags
-)
+var commonFlags *flags.Flags
func init() {
- commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Listen)
veyron2.RegisterProfileInit(Init)
stream.RegisterUnknownProtocol("wsh", websocket.HybridDial, websocket.HybridListener)
+ commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime, flags.Listen)
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- log := vlog.Log
-
- handle, err := exec.GetChildHandle()
- switch err {
- case exec.ErrNoVersion:
- // The process has not been started through the veyron exec
- // library. No further action is needed.
- case nil:
- // The process has been started through the veyron exec
- // library.
- default:
+ if err := internal.ParseFlags(commonFlags); err != nil {
return nil, nil, nil, err
}
- var execConfig map[string]string
- if handle != nil {
- execConfig = handle.Config.Dump()
- }
- commonFlags.Parse(os.Args[1:], execConfig)
+
lf := commonFlags.ListenFlags()
listenSpec := ipc.ListenSpec{
Addrs: ipc.ListenAddrs(lf.Addrs),
Proxy: lf.ListenProxy,
}
- reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
+ reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir(), sflag.NewAuthorizerOrDie())
ac := appcycle.New()
// Our address is private, so we test for running on GCE and for its
// 1:1 NAT configuration.
- if !internal.HasPublicIP(log) {
- if addr := internal.GCEPublicAddress(log); addr != nil {
+ if !internal.HasPublicIP(vlog.Log) {
+ if addr := internal.GCEPublicAddress(vlog.Log); addr != nil {
listenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
}
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {
return nil, nil, shutdown, err
}
@@ -130,7 +112,7 @@
listenSpec.StreamName = SettingsStreamName
listenSpec.AddressChooser = internal.IPAddressChooser
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {
return nil, nil, shutdown, err
}
diff --git a/profiles/static/static.go b/profiles/static/static.go
deleted file mode 100644
index 4ed8d39..0000000
--- a/profiles/static/static.go
+++ /dev/null
@@ -1,92 +0,0 @@
-// Package static provides a network-aware Profile that provides appropriate
-// options and configuration for a variety of network configurations, including
-// being behind 1-1 NATs, but without the ability to respond to dhcp changes.
-package static
-
-import (
- "v.io/core/veyron2"
- "v.io/core/veyron2/config"
- "v.io/core/veyron2/ipc"
-
- "v.io/core/veyron/lib/appcycle"
- "v.io/core/veyron/lib/netstate"
- "v.io/core/veyron/profiles/internal"
- "v.io/core/veyron/profiles/internal/platform"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
- _ "v.io/core/veyron/runtimes/google/rt"
- "v.io/core/veyron/services/mgmt/debug"
-
- // TODO(cnicolaou,ashankar): move this into flags.
- sflag "v.io/core/veyron/security/flag"
-)
-
-var (
- // ListenSpec is an initialized instance of ipc.ListenSpec that can
- // be used with ipc.Listen.
- ListenSpec ipc.ListenSpec
-)
-
-type static struct {
- gce string
- ac *appcycle.AppCycle
-}
-
-// New returns a new instance of a very static Profile. It can be used
-// as a default by Runtime implementations, in unit tests etc.
-func New() veyron2.Profile {
- return &static{}
-}
-
-func (p *static) Name() string {
- return "static" + p.gce
-}
-
-func (p *static) Runtime() (string, []veyron2.ROpt) {
- return "google", nil
-}
-
-func (*static) Platform() *veyron2.Platform {
- pstr, _ := platform.Platform()
- return pstr
-}
-
-func (p *static) Init(rt veyron2.Runtime, _ *config.Publisher) (veyron2.AppCycle, error) {
- log := veyron2.GetLogger(rt.NewContext())
-
- rt.ConfigureReservedName(debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie()))
-
- lf := commonFlags.ListenFlags()
- ListenSpec = ipc.ListenSpec{
- Addrs: ipc.ListenAddrs(lf.Addrs),
- Proxy: lf.ListenProxy,
- }
-
- p.ac = appcycle.New()
-
- // Our address is private, so we test for running on GCE and for its
- // 1:1 NAT configuration. GCEPublicAddress returns a non-nil addr
- // if we are indeed running on GCE.
- if !internal.HasPublicIP(log) {
- if addr := internal.GCEPublicAddress(log); addr != nil {
- ListenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
- return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
- }
- p.gce = "+gce"
- return p.ac, nil
- }
- }
- ListenSpec.AddressChooser = internal.IPAddressChooser
- return p.ac, nil
-}
-
-func (p *static) Cleanup() {
- if p.ac != nil {
- p.ac.Shutdown()
- }
-}
-
-func (p *static) String() string {
- return "static profile on " + p.Platform().String()
-}
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index 7536850..a2dba6b 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -2,7 +2,6 @@
import (
"flag"
- "os"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
@@ -11,7 +10,6 @@
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/appcycle"
- "v.io/core/veyron/lib/exec"
"v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/netstate"
"v.io/core/veyron/lib/websocket"
@@ -26,52 +24,36 @@
sflag "v.io/core/veyron/security/flag"
)
-var (
- commonFlags *flags.Flags
-)
+var commonFlags *flags.Flags
func init() {
- commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Listen)
veyron2.RegisterProfileInit(Init)
stream.RegisterUnknownProtocol("wsh", websocket.HybridDial, websocket.HybridListener)
+ commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime, flags.Listen)
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- log := vlog.Log
-
- handle, err := exec.GetChildHandle()
- switch err {
- case exec.ErrNoVersion:
- // The process has not been started through the veyron exec
- // library. No further action is needed.
- case nil:
- // The process has been started through the veyron exec
- // library.
- default:
+ if err := internal.ParseFlags(commonFlags); err != nil {
return nil, nil, nil, err
}
- var execConfig map[string]string
- if handle != nil {
- execConfig = handle.Config.Dump()
- }
- commonFlags.Parse(os.Args[1:], execConfig)
+
lf := commonFlags.ListenFlags()
listenSpec := ipc.ListenSpec{
Addrs: ipc.ListenAddrs(lf.Addrs),
Proxy: lf.ListenProxy,
}
- reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
+ reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir(), sflag.NewAuthorizerOrDie())
ac := appcycle.New()
// Our address is private, so we test for running on GCE and for its 1:1 NAT
// configuration. GCEPublicAddress returns a non-nil addr if we are running on GCE.
- if !internal.HasPublicIP(log) {
- if addr := internal.GCEPublicAddress(log); addr != nil {
+ if !internal.HasPublicIP(vlog.Log) {
+ if addr := internal.GCEPublicAddress(vlog.Log); addr != nil {
listenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
}
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {
return nil, nil, nil, err
}
@@ -84,7 +66,7 @@
}
listenSpec.AddressChooser = internal.IPAddressChooser
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {
return nil, nil, shutdown, err
}
diff --git a/runtimes/fake/runtime.go b/runtimes/fake/runtime.go
index df58a25..baa6386 100644
--- a/runtimes/fake/runtime.go
+++ b/runtimes/fake/runtime.go
@@ -50,10 +50,6 @@
return l
}
-func (r *Runtime) GetProfile(ctx *context.T) veyron2.Profile {
- panic("unimplemented")
-}
-
func (r *Runtime) GetAppCycle(ctx *context.T) veyron2.AppCycle {
panic("unimplemented")
}
diff --git a/runtimes/google/ipc/benchmark/bmserver/main.go b/runtimes/google/ipc/benchmark/bmserver/main.go
index 416762c..85e915d 100644
--- a/runtimes/google/ipc/benchmark/bmserver/main.go
+++ b/runtimes/google/ipc/benchmark/bmserver/main.go
@@ -3,7 +3,7 @@
import (
"v.io/core/veyron/lib/signals"
- "v.io/core/veyron/profiles/roaming"
+ _ "v.io/core/veyron/profiles/roaming"
"v.io/core/veyron/runtimes/google/ipc/benchmark"
"v.io/core/veyron2"
@@ -14,7 +14,7 @@
ctx, shutdown := veyron2.Init()
defer shutdown()
- addr, stop := benchmark.StartServer(ctx, roaming.ListenSpec)
+ addr, stop := benchmark.StartServer(ctx, veyron2.GetListenSpec(ctx))
vlog.Infof("Listening on %s", addr)
defer stop()
<-signals.ShutdownOnSignals(ctx)
diff --git a/runtimes/google/ipc/benchmark/glob/glob_test.go b/runtimes/google/ipc/benchmark/glob/glob_test.go
index c8f1cf4..e79a9fe 100644
--- a/runtimes/google/ipc/benchmark/glob/glob_test.go
+++ b/runtimes/google/ipc/benchmark/glob/glob_test.go
@@ -11,7 +11,7 @@
"v.io/core/veyron2/security"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
func TestNothing(t *testing.T) {
@@ -83,7 +83,7 @@
if err != nil {
return "", nil, fmt.Errorf("failed to start server: %v", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
return "", nil, fmt.Errorf("failed to listen: %v", err)
}
diff --git a/runtimes/google/ipc/client_test.go b/runtimes/google/ipc/client_test.go
index d9ebb6a..22d61a0 100644
--- a/runtimes/google/ipc/client_test.go
+++ b/runtimes/google/ipc/client_test.go
@@ -21,7 +21,7 @@
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/lib/modules/core"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
inaming "v.io/core/veyron/runtimes/google/naming"
)
@@ -201,7 +201,7 @@
done := make(chan struct{})
deferFn := func() { close(done); server.Stop() }
- eps, err := server.Listen(profiles.LocalListenSpec)
+ eps, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/runtimes/google/ipc/glob_test.go b/runtimes/google/ipc/glob_test.go
index cb50932..926bbe6 100644
--- a/runtimes/google/ipc/glob_test.go
+++ b/runtimes/google/ipc/glob_test.go
@@ -15,7 +15,7 @@
"v.io/core/veyron/lib/glob"
"v.io/core/veyron/lib/testutil"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
func startServer(ctx *context.T, tree *node) (string, func(), error) {
@@ -23,7 +23,7 @@
if err != nil {
return "", nil, fmt.Errorf("failed to start debug server: %v", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
return "", nil, fmt.Errorf("failed to listen: %v", err)
}
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index 0f98e6a..cba1d30 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -15,7 +15,7 @@
"v.io/core/veyron/lib/testutil"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
func init() { testutil.Init() }
@@ -25,7 +25,7 @@
if err != nil {
return "", nil, fmt.Errorf("failed to start sig server: %v", err)
}
- eps, err := server.Listen(profiles.LocalListenSpec)
+ eps, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
return "", nil, fmt.Errorf("failed to listen: %v", err)
}
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index 29c4932..855225e 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -18,7 +18,7 @@
"v.io/core/veyron/lib/testutil"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/runtimes/google/naming/namespace"
vsecurity "v.io/core/veyron/security"
service "v.io/core/veyron/services/mounttable/lib"
@@ -184,7 +184,7 @@
}
// Add a mount table server.
// Start serving on a loopback address.
- eps, err := s.Listen(profiles.LocalListenSpec)
+ eps, err := s.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
boom(t, "Failed to Listen: %s", err)
}
diff --git a/runtimes/google/rt/ipc_test.go b/runtimes/google/rt/ipc_test.go
index 8dee8a4..95d73be 100644
--- a/runtimes/google/rt/ipc_test.go
+++ b/runtimes/google/rt/ipc_test.go
@@ -14,7 +14,7 @@
"v.io/core/veyron/lib/testutil"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron2/vdl"
"v.io/core/veyron2/verror"
)
@@ -97,7 +97,7 @@
if err != nil {
return nil, "", err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
return nil, "", err
}
diff --git a/runtimes/google/rt/mgmt_test.go b/runtimes/google/rt/mgmt_test.go
index f99ab44..572de13 100644
--- a/runtimes/google/rt/mgmt_test.go
+++ b/runtimes/google/rt/mgmt_test.go
@@ -21,7 +21,7 @@
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/lib/testutil"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
vflag "v.io/core/veyron/security/flag"
"v.io/core/veyron/services/mgmt/device"
)
@@ -310,7 +310,7 @@
}
ch := make(chan string)
var eps []naming.Endpoint
- if eps, err = server.Listen(profiles.LocalListenSpec); err != nil {
+ if eps, err = server.Listen(veyron2.GetListenSpec(ctx)); err != nil {
t.Fatalf("Got error: %v", err)
}
if err := server.Serve("", device.ConfigServer(&configServer{ch}), vflag.NewAuthorizerOrDie()); err != nil {
diff --git a/runtimes/google/rt/runtimex.go b/runtimes/google/rt/runtimex.go
index 80706d5..6a707cc 100644
--- a/runtimes/google/rt/runtimex.go
+++ b/runtimes/google/rt/runtimex.go
@@ -1,7 +1,6 @@
package rt
import (
- "flag"
"fmt"
"os"
"os/signal"
@@ -52,14 +51,6 @@
type vtraceDependency struct{}
-// TODO(suharshs,mattr): Panic instead of flagsOnce after the transition to veyron.Init is completed.
-var flagsOnce sync.Once
-var runtimeFlags *flags.Flags
-
-func init() {
- runtimeFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime)
-}
-
type depSet struct {
count int
cond *sync.Cond
@@ -79,7 +70,8 @@
}
// TODO(mattr,suharshs): Decide if ROpts would be better than this.
-func Init(ctx *context.T, appCycle veyron2.AppCycle, protocols []string, listenSpec *ipc.ListenSpec, reservedDispatcher ipc.Dispatcher, dispatcherOpts ...ipc.ServerOpt) (*RuntimeX, *context.T, veyron2.Shutdown, error) {
+func Init(ctx *context.T, appCycle veyron2.AppCycle, protocols []string, listenSpec *ipc.ListenSpec, flags flags.RuntimeFlags,
+ reservedDispatcher ipc.Dispatcher, dispatcherOpts ...ipc.ServerOpt) (*RuntimeX, *context.T, veyron2.Shutdown, error) {
r := &RuntimeX{deps: make(map[interface{}]*depSet)}
r.newDepSetLocked(r)
@@ -95,16 +87,6 @@
return nil, nil, nil, err
}
- // Parse runtime flags.
- flagsOnce.Do(func() {
- var config map[string]string
- if handle != nil {
- config = handle.Config.Dump()
- }
- runtimeFlags.Parse(os.Args[1:], config)
- })
- flags := runtimeFlags.RuntimeFlags()
-
r.initLogging(ctx)
ctx = context.WithValue(ctx, loggerKey, vlog.Log)
@@ -490,23 +472,6 @@
return logger
}
-// SetProfile sets the profile used to create this runtime.
-// TODO(suharshs, mattr): Determine if this is needed by functions after the new
-// profile init function is in use. This will probably be easy to do because:
-// Name is used in tests only.
-// Platform is used for String representaions of a Profile.
-// String is unused.
-// Cleanup is used in rt.Cleanup and can probably be replaced by a cancelfunc returned
-// by the new profile initialization function.
-func (*RuntimeX) SetProfile(ctx *context.T, profile veyron2.Profile) *context.T {
- return context.WithValue(ctx, profileKey, profile)
-}
-
-func (*RuntimeX) GetProfile(ctx *context.T) veyron2.Profile {
- profile, _ := ctx.Value(profileKey).(veyron2.Profile)
- return profile
-}
-
func (*RuntimeX) GetAppCycle(ctx *context.T) veyron2.AppCycle {
appCycle, _ := ctx.Value(appCycleKey).(veyron2.AppCycle)
return appCycle
diff --git a/runtimes/google/rt/runtimex_test.go b/runtimes/google/rt/runtimex_test.go
index 6562b52..b505d9a 100644
--- a/runtimes/google/rt/runtimex_test.go
+++ b/runtimes/google/rt/runtimex_test.go
@@ -6,6 +6,7 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
+ "v.io/core/veyron/lib/flags"
tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/runtimes/google/rt"
"v.io/core/veyron/security"
@@ -14,7 +15,7 @@
// InitForTest creates a context for use in a test.
func InitForTest(t *testing.T) (*rt.RuntimeX, *context.T, veyron2.Shutdown) {
ctx, cancel := context.WithCancel(nil)
- r, ctx, shutdown, err := rt.Init(ctx, nil, nil, nil, nil)
+ r, ctx, shutdown, err := rt.Init(ctx, nil, nil, nil, flags.RuntimeFlags{}, nil)
if err != nil {
t.Fatal(err)
}
diff --git a/runtimes/google/rt/shutdown_servers_test.go b/runtimes/google/rt/shutdown_servers_test.go
index 37320fe..f841f31 100644
--- a/runtimes/google/rt/shutdown_servers_test.go
+++ b/runtimes/google/rt/shutdown_servers_test.go
@@ -17,7 +17,7 @@
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/lib/signals"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
func init() {
@@ -35,7 +35,7 @@
if err != nil {
vlog.Fatalf("r.NewServer error: %s", err)
}
- if _, err := server.Listen(profiles.LocalListenSpec); err != nil {
+ if _, err := server.Listen(veyron2.GetListenSpec(ctx)); err != nil {
vlog.Fatalf("server.Listen error: %s", err)
}
if err := server.Serve("", &dummy{}, nil); err != nil {
diff --git a/runtimes/google/vtrace/vtrace_test.go b/runtimes/google/vtrace/vtrace_test.go
index 7e12d89..61f46c6 100644
--- a/runtimes/google/vtrace/vtrace_test.go
+++ b/runtimes/google/vtrace/vtrace_test.go
@@ -5,6 +5,7 @@
"strings"
"testing"
+ "v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/ipc/stream"
@@ -13,34 +14,19 @@
"v.io/core/veyron2/vlog"
"v.io/core/veyron2/vtrace"
- "v.io/core/veyron/lib/flags"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
iipc "v.io/core/veyron/runtimes/google/ipc"
"v.io/core/veyron/runtimes/google/ipc/stream/manager"
tnaming "v.io/core/veyron/runtimes/google/testing/mocks/naming"
- ivtrace "v.io/core/veyron/runtimes/google/vtrace"
)
-// We need a special way to create contexts for tests. We
-// can't create a real runtime in the runtime implementation
-// so we use a fake one that panics if used. The runtime
-// implementation should not ever use the Runtime from a context.
-func testContext() *context.T {
- var ctx *context.T
- ctx, err := ivtrace.Init(ctx, flags.VtraceFlags{CacheSize: 100})
- if err != nil {
- panic(err)
- }
- return ctx
-}
-
func TestNewFromContext(t *testing.T) {
- c0 := testContext()
+ c0, shutdown := veyron2.Init()
+ defer shutdown()
c1, s1 := vtrace.SetNewSpan(c0, "s1")
c2, s2 := vtrace.SetNewSpan(c1, "s2")
c3, s3 := vtrace.SetNewSpan(c2, "s3")
expected := map[*context.T]vtrace.Span{
- c0: nil,
c1: s1,
c2: s2,
c3: s3,
@@ -101,14 +87,14 @@
return nil
}
-func makeTestServer(ns naming.Namespace, name, child string, forceCollect bool) (*testServer, error) {
+func makeTestServer(ctx *context.T, ns naming.Namespace, name, child string, forceCollect bool) (*testServer, error) {
sm := manager.InternalNew(naming.FixedRoutingID(0x111111111))
- ctx := testContext()
s, err := iipc.InternalNewServer(ctx, sm, ns, nil)
if err != nil {
return nil, err
}
- if _, err := s.Listen(profiles.LocalListenSpec); err != nil {
+
+ if _, err := s.Listen(veyron2.GetListenSpec(ctx)); err != nil {
return nil, err
}
@@ -212,14 +198,15 @@
if err != nil {
t.Error(err)
}
-
- c1, err := makeTestServer(ns, "c1", "c2", force1)
+ ctx1, _ := vtrace.SetNewTrace(ctx)
+ c1, err := makeTestServer(ctx1, ns, "c1", "c2", force1)
if err != nil {
t.Fatal("Can't start server:", err)
}
defer c1.stop()
- c2, err := makeTestServer(ns, "c2", "", force2)
+ ctx2, _ := vtrace.SetNewTrace(ctx)
+ c2, err := makeTestServer(ctx2, ns, "c2", "", force2)
if err != nil {
t.Fatal("Can't start server:", err)
}
@@ -241,7 +228,9 @@
// TestCancellationPropagation tests that cancellation propogates along an
// RPC call chain without user intervention.
func TestTraceAcrossRPCs(t *testing.T) {
- ctx, span := vtrace.SetNewSpan(testContext(), "")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, span := vtrace.SetNewSpan(ctx, "")
vtrace.ForceCollect(ctx)
span.Annotate("c0-begin")
@@ -263,7 +252,9 @@
// TestCancellationPropagationLateForce tests that cancellation propogates along an
// RPC call chain when tracing is initiated by someone deep in the call chain.
func TestTraceAcrossRPCsLateForce(t *testing.T) {
- ctx, span := vtrace.SetNewSpan(testContext(), "")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, span := vtrace.SetNewSpan(ctx, "")
span.Annotate("c0-begin")
runCallChain(t, ctx, false, true)
diff --git a/services/mgmt/build/impl/impl_test.go b/services/mgmt/build/impl/impl_test.go
index 7c2d84d..dd1573e 100644
--- a/services/mgmt/build/impl/impl_test.go
+++ b/services/mgmt/build/impl/impl_test.go
@@ -13,7 +13,7 @@
"v.io/core/veyron2/services/mgmt/build"
"v.io/core/veyron/lib/testutil"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
func init() {
@@ -52,9 +52,10 @@
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ l := veyron2.GetListenSpec(ctx)
+ endpoints, err := server.Listen(l)
if err != nil {
- t.Fatalf("Listen(%s) failed: %v", profiles.LocalListenSpec, err)
+ t.Fatalf("Listen(%s) failed: %v", l, err)
}
unpublished := ""
if err := server.Serve(unpublished, build.BuilderServer(NewBuilderService(gobin, goroot)), nil); err != nil {
diff --git a/services/mgmt/debug/dispatcher_test.go b/services/mgmt/debug/dispatcher_test.go
index ab7560b..f1a7017 100644
--- a/services/mgmt/debug/dispatcher_test.go
+++ b/services/mgmt/debug/dispatcher_test.go
@@ -24,7 +24,7 @@
libstats "v.io/core/veyron/lib/stats"
"v.io/core/veyron/lib/testutil"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
// startDebugServer starts a debug server.
@@ -68,7 +68,7 @@
t.Fatalf("ioutil.WriteFile failed: %v", err)
}
- endpoint, stop, err := startDebugServer(ctx, profiles.LocalListenSpec, workdir)
+ endpoint, stop, err := startDebugServer(ctx, veyron2.GetListenSpec(ctx), workdir)
if err != nil {
t.Fatalf("StartDebugServer failed: %v", err)
}
diff --git a/services/mgmt/lib/binary/impl_test.go b/services/mgmt/lib/binary/impl_test.go
index 42db6a4..36d1070 100644
--- a/services/mgmt/lib/binary/impl_test.go
+++ b/services/mgmt/lib/binary/impl_test.go
@@ -15,7 +15,7 @@
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/testutil"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/binary/impl"
)
@@ -52,9 +52,10 @@
if err != nil {
t.Fatalf("NewDispatcher() failed: %v\n", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ l := veyron2.GetListenSpec(ctx)
+ endpoints, err := server.Listen(l)
if err != nil {
- t.Fatalf("Listen(%s) failed: %v", profiles.LocalListenSpec, err)
+ t.Fatalf("Listen(%s) failed: %v", l, err)
}
suffix := ""
if err := server.ServeDispatcher(suffix, dispatcher); err != nil {
diff --git a/services/mgmt/logreader/impl/logfile_test.go b/services/mgmt/logreader/impl/logfile_test.go
index f4adfc9..62e3b78 100644
--- a/services/mgmt/logreader/impl/logfile_test.go
+++ b/services/mgmt/logreader/impl/logfile_test.go
@@ -6,7 +6,7 @@
"path"
"testing"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/logreader/impl"
"v.io/core/veyron2"
@@ -25,7 +25,7 @@
t.Fatalf("NewServer failed: %v", err)
return nil, "", err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("Listen failed: %v", err)
return nil, "", err
diff --git a/services/mgmt/profile/impl/impl_test.go b/services/mgmt/profile/impl/impl_test.go
index a7dcb40..cc27ee4 100644
--- a/services/mgmt/profile/impl/impl_test.go
+++ b/services/mgmt/profile/impl/impl_test.go
@@ -10,7 +10,7 @@
"v.io/core/veyron2/naming"
"v.io/core/veyron2/services/mgmt/build"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/profile"
"v.io/core/veyron/services/mgmt/repository"
)
@@ -50,9 +50,10 @@
if err != nil {
t.Fatalf("NewDispatcher() failed: %v", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ l := veyron2.GetListenSpec(ctx)
+ endpoints, err := server.Listen(l)
if err != nil {
- t.Fatalf("Listen(%s) failed: %v", profiles.LocalListenSpec, err)
+ t.Fatalf("Listen(%s) failed: %v", l, err)
}
endpoint := endpoints[0]
if err := server.ServeDispatcher("", dispatcher); err != nil {
@@ -128,9 +129,10 @@
if err != nil {
t.Fatalf("NewDispatcher() failed: %v", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ l := veyron2.GetListenSpec(ctx)
+ endpoints, err := server.Listen(l)
if err != nil {
- t.Fatalf("Listen(%s) failed: %v", profiles.LocalListenSpec, err)
+ t.Fatalf("Listen(%s) failed: %v", l, err)
}
endpoint := endpoints[0]
if err := server.ServeDispatcher("", dispatcher); err != nil {
@@ -167,9 +169,9 @@
if err != nil {
t.Fatalf("NewDispatcher() failed: %v", err)
}
- endpoints, err = server.Listen(profiles.LocalListenSpec)
+ endpoints, err = server.Listen(l)
if err != nil {
- t.Fatalf("Listen(%s) failed: %v", profiles.LocalListenSpec, err)
+ t.Fatalf("Listen(%s) failed: %v", l, err)
}
if err = server.ServeDispatcher("", dispatcher); err != nil {
t.Fatalf("Serve failed: %v", err)
diff --git a/services/mgmt/stats/impl/stats_test.go b/services/mgmt/stats/impl/stats_test.go
index f972e83..493f454 100644
--- a/services/mgmt/stats/impl/stats_test.go
+++ b/services/mgmt/stats/impl/stats_test.go
@@ -16,7 +16,7 @@
libstats "v.io/core/veyron/lib/stats"
"v.io/core/veyron/lib/stats/histogram"
"v.io/core/veyron/lib/testutil"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
istats "v.io/core/veyron/services/mgmt/stats"
"v.io/core/veyron/services/mgmt/stats/impl"
)
@@ -35,7 +35,7 @@
t.Fatalf("NewServer failed: %v", err)
return "", nil
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("Listen failed: %v", err)
return "", nil
diff --git a/services/mgmt/vtrace/impl/vtrace_test.go b/services/mgmt/vtrace/impl/vtrace_test.go
index 3bd0324..7a4d5f8 100644
--- a/services/mgmt/vtrace/impl/vtrace_test.go
+++ b/services/mgmt/vtrace/impl/vtrace_test.go
@@ -8,7 +8,7 @@
service "v.io/core/veyron2/services/mgmt/vtrace"
"v.io/core/veyron2/vtrace"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/vtrace/impl"
)
@@ -20,7 +20,7 @@
if err != nil {
t.Fatalf("Could not create server: %s", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("Listen failed: %s", err)
}
diff --git a/services/mounttable/lib/mounttable_test.go b/services/mounttable/lib/mounttable_test.go
index 06a8120..a82aa46 100644
--- a/services/mounttable/lib/mounttable_test.go
+++ b/services/mounttable/lib/mounttable_test.go
@@ -21,7 +21,7 @@
"v.io/core/veyron/lib/testutil"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
// Simulate different processes with different runtimes.
@@ -264,7 +264,7 @@
boom(t, "NewMountTable: %v", err)
}
// Start serving on a loopback address.
- eps, err := server.Listen(profiles.LocalListenSpec)
+ eps, err := server.Listen(veyron2.GetListenSpec(rootCtx))
if err != nil {
boom(t, "Failed to Listen mount table: %s", err)
}
@@ -282,7 +282,7 @@
boom(t, "r.NewServer: %s", err)
}
// Start serving on a loopback address.
- eps, err := server.Listen(profiles.LocalListenSpec)
+ eps, err := server.Listen(veyron2.GetListenSpec(rootCtx))
if err != nil {
boom(t, "Failed to Listen mount table: %s", err)
}
diff --git a/services/mounttable/lib/neighborhood_test.go b/services/mounttable/lib/neighborhood_test.go
index b22e724..9290c77 100644
--- a/services/mounttable/lib/neighborhood_test.go
+++ b/services/mounttable/lib/neighborhood_test.go
@@ -13,7 +13,7 @@
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/testutil"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
func init() { testutil.Init() }
@@ -37,7 +37,7 @@
defer server.Stop()
// Start serving on a loopback address.
- eps, err := server.Listen(profiles.LocalListenSpec)
+ eps, err := server.Listen(veyron2.GetListenSpec(rootCtx))
if err != nil {
boom(t, "Failed to Listen mount table: %s", err)
}
diff --git a/tools/application/impl_test.go b/tools/application/impl_test.go
index 4bd9452..de607ae 100644
--- a/tools/application/impl_test.go
+++ b/tools/application/impl_test.go
@@ -17,7 +17,7 @@
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/repository"
)
@@ -97,7 +97,7 @@
t.Errorf("NewServer failed: %v", err)
return nil, nil, err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Errorf("Listen failed: %v", err)
return nil, nil, err
diff --git a/tools/binary/impl_test.go b/tools/binary/impl_test.go
index 28b62b2..0015ddf 100644
--- a/tools/binary/impl_test.go
+++ b/tools/binary/impl_test.go
@@ -22,7 +22,7 @@
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
type server struct {
@@ -101,7 +101,7 @@
t.Errorf("NewServer failed: %v", err)
return nil, nil, err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Errorf("Listen failed: %v", err)
return nil, nil, err
diff --git a/tools/build/impl_test.go b/tools/build/impl_test.go
index 76e1a13..d2550e6 100644
--- a/tools/build/impl_test.go
+++ b/tools/build/impl_test.go
@@ -15,7 +15,7 @@
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
type mock struct{}
@@ -44,9 +44,10 @@
if err != nil {
t.Fatalf("NewServer failed: %v", err)
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ l := veyron2.GetListenSpec(ctx)
+ endpoints, err := server.Listen(l)
if err != nil {
- t.Fatalf("Listen(%s) failed: %v", profiles.LocalListenSpec, err)
+ t.Fatalf("Listen(%s) failed: %v", l, err)
}
unpublished := ""
if err := server.Serve(unpublished, build.BuilderServer(&mock{}), nil); err != nil {
diff --git a/tools/mgmt/device/devicemanager_mock_test.go b/tools/mgmt/device/devicemanager_mock_test.go
index 859613b..7501383 100644
--- a/tools/mgmt/device/devicemanager_mock_test.go
+++ b/tools/mgmt/device/devicemanager_mock_test.go
@@ -14,7 +14,7 @@
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/vlog"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
type mockDeviceInvoker struct {
@@ -169,7 +169,7 @@
t.Errorf("NewServer failed: %v", err)
return nil, nil, err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Errorf("Listen failed: %v", err)
stopServer(t, server)