core: Remove the NewStreamManager and Namespace methods of Runtime.
This is part of the runtimeX migration.
Change-Id: Ib2efd74513b54f8fb06ca78e1016f2b11d9c3ce8
diff --git a/lib/modules/core/mounttable.go b/lib/modules/core/mounttable.go
index f6d4294..fc71b66 100644
--- a/lib/modules/core/mounttable.go
+++ b/lib/modules/core/mounttable.go
@@ -6,6 +6,7 @@
"os"
"strings"
+ "v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
"v.io/core/veyron2/rt"
@@ -82,17 +83,19 @@
}
defer r.Cleanup()
+ ctx := r.NewContext()
+
details := false
args = args[1:] // skip over command name
if len(args) > 0 && args[0] == "-l" {
details = true
args = args[1:]
}
- ns := r.Namespace()
+ ns := veyron2.GetNamespace(ctx)
entry := 0
output := ""
for _, pattern := range args {
- ch, err := ns.Glob(r.NewContext(), pattern)
+ ch, err := ns.Glob(ctx, pattern)
if err != nil {
return err
}
diff --git a/lib/modules/core/proxy.go b/lib/modules/core/proxy.go
index a78c358..4f706b3 100644
--- a/lib/modules/core/proxy.go
+++ b/lib/modules/core/proxy.go
@@ -6,6 +6,7 @@
"os"
"time"
+ "v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/rt"
@@ -46,7 +47,8 @@
fmt.Fprintf(stdout, "PROXY_NAME=%s\n", pname)
if expected > 0 {
defer r.Cleanup()
- pub := publisher.New(r.NewContext(), r.Namespace(), time.Minute)
+ ctx := r.NewContext()
+ pub := publisher.New(ctx, veyron2.GetNamespace(ctx), time.Minute)
defer pub.WaitForStop()
defer pub.Stop()
pub.AddServer(pname, false)
diff --git a/runtimes/google/ipc/client_test.go b/runtimes/google/ipc/client_test.go
index adf18d8..46b4360 100644
--- a/runtimes/google/ipc/client_test.go
+++ b/runtimes/google/ipc/client_test.go
@@ -11,7 +11,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/rt"
verror "v.io/core/veyron2/verror2"
@@ -25,7 +24,7 @@
)
var r veyron2.Runtime
-var client ipc.Client
+var gctx *context.T
func init() {
modules.RegisterChild("ping", "<name>", childPing)
@@ -33,9 +32,8 @@
if r, err = rt.New(); err != nil {
panic(err)
}
- client = veyron2.GetClient(r.NewContext())
-
- r.Namespace().CacheCtl(naming.DisableCache(true))
+ gctx = r.NewContext()
+ veyron2.GetNamespace(gctx).CacheCtl(naming.DisableCache(true))
}
func testArgs(args ...string) []string {
@@ -43,8 +41,9 @@
return append(targs, args...)
}
-func runMountTable(t *testing.T, r veyron2.Runtime) (*modules.Shell, func()) {
- sh, err := modules.NewShell(r.Principal())
+func runMountTable(t *testing.T, ctx *context.T) (*modules.Shell, func()) {
+ principal := veyron2.GetPrincipal(ctx)
+ sh, err := modules.NewShell(principal)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -61,7 +60,7 @@
t.Fatalf("%s", rootSession.Error())
}
sh.SetVar(consts.NamespaceRootPrefix, rootName)
- if err = r.Namespace().SetRoots(rootName); err != nil {
+ if err = veyron2.GetNamespace(ctx).SetRoots(rootName); err != nil {
t.Fatalf("unexpected error setting namespace roots: %s", err)
}
@@ -93,7 +92,7 @@
}
func numServers(t *testing.T, name string) int {
- servers, err := r.Namespace().Resolve(r.NewContext(), name)
+ servers, err := veyron2.GetNamespace(gctx).Resolve(gctx, name)
if err != nil {
return 0
}
@@ -103,7 +102,7 @@
// TODO(cnicolaou): figure out how to test and see what the internals
// of tryCall are doing - e.g. using stats counters.
func TestMultipleEndpoints(t *testing.T) {
- sh, fn := runMountTable(t, r)
+ sh, fn := runMountTable(t, gctx)
defer fn()
srv, err := sh.Start(core.EchoServerCommand, nil, testArgs("echoServer", "echoServer")...)
if err != nil {
@@ -121,12 +120,11 @@
runClient(t, sh)
// Create a fake set of 100 entries in the mount table
- ctx := r.NewContext()
for i := 0; i < 100; i++ {
// 203.0.113.0 is TEST-NET-3 from RFC5737
ep := naming.FormatEndpoint("tcp", fmt.Sprintf("203.0.113.%d:443", i))
n := naming.JoinAddressName(ep, "")
- if err := r.Namespace().Mount(ctx, "echoServer", n, time.Hour); err != nil {
+ if err := veyron2.GetNamespace(gctx).Mount(gctx, "echoServer", n, time.Hour); err != nil {
t.Fatalf("unexpected error: %s", err)
}
}
@@ -153,8 +151,9 @@
}
func TestTimeoutCall(t *testing.T) {
- ctx, _ := context.WithTimeout(r.NewContext(), 100*time.Millisecond)
+ ctx, _ := context.WithTimeout(gctx, 100*time.Millisecond)
name := naming.JoinAddressName(naming.FormatEndpoint("tcp", "203.0.113.10:443"), "")
+ client := veyron2.GetClient(ctx)
_, err := client.StartCall(ctx, name, "echo", []interface{}{"args don't matter"})
if !verror.Is(err, verror.Timeout.ID) {
t.Fatalf("wrong error: %s", err)
@@ -163,7 +162,7 @@
func childPing(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
name := args[1]
- call, err := client.StartCall(r.NewContext(), name, "Ping", nil)
+ call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Ping", nil)
if err != nil {
fmt.Errorf("unexpected error: %s", err)
}
@@ -179,8 +178,8 @@
return nil
}
-func initServer(t *testing.T, r veyron2.Runtime) (string, func()) {
- server, err := r.NewServer()
+func initServer(t *testing.T, ctx *context.T) (string, func()) {
+ server, err := veyron2.NewServer(ctx)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -219,10 +218,10 @@
}
func TestTimeoutResponse(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
- ctx, _ := context.WithTimeout(r.NewContext(), 100*time.Millisecond)
- call, err := client.StartCall(ctx, name, "Sleep", nil)
+ ctx, _ := context.WithTimeout(gctx, 100*time.Millisecond)
+ call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
if err != nil {
testForVerror(t, err, verror.Timeout, verror.BadProtocol)
return
@@ -233,17 +232,17 @@
}
func TestArgsAndResponses(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
- call, err := client.StartCall(r.NewContext(), name, "Sleep", []interface{}{"too many args"})
+ call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Sleep", []interface{}{"too many args"})
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
verr := call.Finish(&err)
testForVerror(t, verr, verror.BadProtocol)
- call, err = client.StartCall(r.NewContext(), name, "Ping", nil)
+ call, err = veyron2.GetClient(gctx).StartCall(gctx, name, "Ping", nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -260,7 +259,7 @@
// The server and client use different runtimes and hence different
// principals and without any shared blessings the server will deny
// access to the client
- name, fn := initServer(t, r1)
+ name, fn := initServer(t, r1.NewContext())
defer fn()
ctx2 := r2.NewContext()
@@ -274,11 +273,11 @@
}
func TestCancelledBeforeFinish(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
- ctx, cancel := context.WithCancel(r.NewContext())
- call, err := client.StartCall(ctx, name, "Sleep", nil)
+ ctx, cancel := context.WithCancel(gctx)
+ call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -290,11 +289,11 @@
}
func TestCancelledDuringFinish(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
- ctx, cancel := context.WithCancel(r.NewContext())
- call, err := client.StartCall(ctx, name, "Sleep", nil)
+ ctx, cancel := context.WithCancel(gctx)
+ call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -309,7 +308,7 @@
}
func TestRendezvous(t *testing.T) {
- sh, fn := runMountTable(t, r)
+ sh, fn := runMountTable(t, gctx)
defer fn()
name := "echoServer"
@@ -326,7 +325,7 @@
}
go startServer()
- call, err := client.StartCall(r.NewContext(), name, "Echo", []interface{}{"hello"})
+ call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Echo", []interface{}{"hello"})
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -343,10 +342,10 @@
}
func TestCallback(t *testing.T) {
- sh, fn := runMountTable(t, r)
+ sh, fn := runMountTable(t, gctx)
defer fn()
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
srv, err := sh.Start("ping", nil, name)
@@ -360,12 +359,12 @@
}
func TestStreamTimeout(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
want := 10
- ctx, _ := context.WithTimeout(r.NewContext(), 300*time.Millisecond)
- call, err := client.StartCall(ctx, name, "Source", []interface{}{want})
+ ctx, _ := context.WithTimeout(gctx, 300*time.Millisecond)
+ call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Source", []interface{}{want})
if err != nil {
if !verror.Is(err, verror.Timeout.ID) && !verror.Is(err, verror.BadProtocol.ID) {
t.Fatalf("verror should be a timeout or badprotocol, not %s: stack %s",
@@ -393,11 +392,10 @@
}
func TestStreamAbort(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
- ctx := r.NewContext()
- call, err := client.StartCall(ctx, name, "Sink", nil)
+ call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Sink", nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -431,11 +429,11 @@
}
func TestNoServersAvailable(t *testing.T) {
- _, fn := runMountTable(t, r)
+ _, fn := runMountTable(t, gctx)
defer fn()
name := "noservers"
- ctx, _ := context.WithTimeout(r.NewContext(), 300*time.Millisecond)
- call, verr := client.StartCall(ctx, name, "Sleep", nil)
+ ctx, _ := context.WithTimeout(gctx, 300*time.Millisecond)
+ call, verr := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
if verr != nil {
testForVerror(t, verr, verror.Timeout, verror.BadProtocol, verror.NoExist)
return
@@ -445,12 +443,12 @@
}
func TestNoMountTable(t *testing.T) {
- r.Namespace().SetRoots()
+ veyron2.GetNamespace(gctx).SetRoots()
name := "a_mount_table_entry"
// If there is no mount table, then we'll get a NoServers error message.
- ctx, _ := context.WithTimeout(r.NewContext(), 300*time.Millisecond)
- _, verr := client.StartCall(ctx, name, "Sleep", nil)
+ ctx, _ := context.WithTimeout(gctx, 300*time.Millisecond)
+ _, verr := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
testForVerror(t, verr, verror.NoServers)
}
diff --git a/runtimes/google/ipc/resolve_test.go b/runtimes/google/ipc/resolve_test.go
index 962b9b5..3b3c2cd 100644
--- a/runtimes/google/ipc/resolve_test.go
+++ b/runtimes/google/ipc/resolve_test.go
@@ -5,6 +5,7 @@
"testing"
"time"
+ "v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/rt"
@@ -38,17 +39,19 @@
t.Fatalf("rt.New failed: %s", err)
}
defer runtime.Cleanup()
- ns := runtime.Namespace()
+ ctx := runtime.NewContext()
+
+ ns := veyron2.GetNamespace(ctx)
ns.SetRoots(root)
proxyEp, _ := inaming.NewEndpoint("proxy.v.io:123")
proxyEpStr := proxyEp.String()
proxyAddr := naming.JoinAddressName(proxyEpStr, "")
- if err := ns.Mount(runtime.NewContext(), "proxy", proxyAddr, time.Hour); err != nil {
+ if err := ns.Mount(ctx, "proxy", proxyAddr, time.Hour); err != nil {
t.Fatalf("ns.Mount failed: %s", err)
}
- server, err := runtime.NewServer()
+ server, err := veyron2.NewServer(ctx)
if err != nil {
t.Fatalf("runtime.NewServer failed: %s", err)
}
diff --git a/runtimes/google/ipc/simple_test.go b/runtimes/google/ipc/simple_test.go
index 986678b..39b1147 100644
--- a/runtimes/google/ipc/simple_test.go
+++ b/runtimes/google/ipc/simple_test.go
@@ -67,7 +67,7 @@
}
func TestSimpleRPC(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
client := veyron2.GetClient(r.NewContext())
@@ -87,7 +87,7 @@
}
func TestSimpleStreaming(t *testing.T) {
- name, fn := initServer(t, r)
+ name, fn := initServer(t, gctx)
defer fn()
ctx := r.NewContext()
diff --git a/services/mgmt/application/impl/acl_test.go b/services/mgmt/application/impl/acl_test.go
index 0efba13..736e67e 100644
--- a/services/mgmt/application/impl/acl_test.go
+++ b/services/mgmt/application/impl/acl_test.go
@@ -50,7 +50,7 @@
panic(err)
}
globalCtx = globalRT.NewContext()
- globalRT.Namespace().CacheCtl(naming.DisableCache(true))
+ veyron2.GetNamespace(globalCtx).CacheCtl(naming.DisableCache(true))
}
// TestHelperProcess is the entrypoint for the modules commands in a
@@ -98,7 +98,7 @@
storedir, cleanup := mgmttest.SetupRootDir(t, "application")
defer cleanup()
- otherRT := mgmttest.NewRuntime(t, globalRT)
+ otherRT := mgmttest.NewRuntime(t, globalCtx)
defer otherRT.Cleanup()
otherCtx := otherRT.NewContext()
@@ -228,7 +228,7 @@
storedir, cleanup := mgmttest.SetupRootDir(t, "application")
defer cleanup()
- otherRT := mgmttest.NewRuntime(t, globalRT)
+ otherRT := mgmttest.NewRuntime(t, globalCtx)
defer otherRT.Cleanup()
otherCtx := otherRT.NewContext()
idp := tsecurity.NewIDProvider("root")
diff --git a/services/mgmt/debug/dispatcher_test.go b/services/mgmt/debug/dispatcher_test.go
index 3c2c3a7..2036d94 100644
--- a/services/mgmt/debug/dispatcher_test.go
+++ b/services/mgmt/debug/dispatcher_test.go
@@ -168,10 +168,12 @@
// Glob from the root.
{
- ns := runtime.Namespace()
- ns.SetRoots(naming.JoinAddressName(endpoint, "debug"))
ctx, cancel := context.WithTimeout(runtime.NewContext(), 10*time.Second)
defer cancel()
+
+ ns := veyron2.GetNamespace(ctx)
+ ns.SetRoots(naming.JoinAddressName(endpoint, "debug"))
+
c, err := ns.Glob(ctx, "logs/...")
if err != nil {
t.Errorf("ns.Glob failed: %v", err)
diff --git a/services/mgmt/device/impl/app_service.go b/services/mgmt/device/impl/app_service.go
index aebe580..1591a29 100644
--- a/services/mgmt/device/impl/app_service.go
+++ b/services/mgmt/device/impl/app_service.go
@@ -883,7 +883,7 @@
// For now, use the namespace roots of the device manager runtime to
// pass to the app.
- if err = i.run(veyron2.RuntimeFromContext(call.Context()).Namespace().Roots(), instanceDir, systemName); err != nil {
+ if err = i.run(veyron2.GetNamespace(call.Context()).Roots(), instanceDir, systemName); err != nil {
// TODO(caprita): We should call cleanupDir here, but we don't
// in order to not lose the logs for the instance (so we can
// debug why run failed). Clean this up.
@@ -931,7 +931,7 @@
if startSystemName != systemName {
return verror2.Make(verror2.NoAccess, call.Context(), "Not allowed to resume an application under a different system name.")
}
- return i.run(veyron2.RuntimeFromContext(call.Context()).Namespace().Roots(), instanceDir, systemName)
+ return i.run(veyron2.GetNamespace(call.Context()).Roots(), instanceDir, systemName)
}
func stopAppRemotely(ctx *context.T, appVON string) error {
diff --git a/services/mgmt/device/impl/impl_test.go b/services/mgmt/device/impl/impl_test.go
index 838e1eb..641bdcd 100644
--- a/services/mgmt/device/impl/impl_test.go
+++ b/services/mgmt/device/impl/impl_test.go
@@ -786,9 +786,9 @@
*envelope = envelopeFromShell(sh, nil, appCmd, "google naps", "trapp")
deviceStub := device.DeviceClient("dm/device")
- claimantRT := mgmttest.NewRuntime(t, globalRT, options.RuntimePrincipal{tsecurity.NewPrincipal("claimant")})
+ claimantRT := mgmttest.NewRuntime(t, globalCtx, options.RuntimePrincipal{tsecurity.NewPrincipal("claimant")})
defer claimantRT.Cleanup()
- otherRT := mgmttest.NewRuntime(t, globalRT, options.RuntimePrincipal{tsecurity.NewPrincipal("other")})
+ otherRT := mgmttest.NewRuntime(t, globalCtx, options.RuntimePrincipal{tsecurity.NewPrincipal("other")})
defer otherRT.Cleanup()
octx := otherRT.NewContext()
@@ -848,7 +848,7 @@
// The two "processes"/runtimes which will act as IPC clients to
// the devicemanager process.
selfRT = globalRT
- otherRT = mgmttest.NewRuntime(t, globalRT)
+ otherRT = mgmttest.NewRuntime(t, globalCtx)
)
defer otherRT.Cleanup()
octx := otherRT.NewContext()
@@ -1241,7 +1241,7 @@
// The two "processes"/runtimes which will act as IPC clients to
// the devicemanager process.
selfRT = globalRT
- otherRT = mgmttest.NewRuntime(t, globalRT)
+ otherRT = mgmttest.NewRuntime(t, globalCtx)
)
defer otherRT.Cleanup()
// By default, selfRT and otherRT will have blessings generated based on
@@ -1344,7 +1344,7 @@
// The two "processes"/runtimes which will act as IPC clients to
// the devicemanager process.
selfRT = globalRT
- otherRT = mgmttest.NewRuntime(t, globalRT)
+ otherRT = mgmttest.NewRuntime(t, globalCtx)
)
defer otherRT.Cleanup()
diff --git a/services/mgmt/device/impl/util_test.go b/services/mgmt/device/impl/util_test.go
index 593b6e6..b6817c7 100644
--- a/services/mgmt/device/impl/util_test.go
+++ b/services/mgmt/device/impl/util_test.go
@@ -44,7 +44,7 @@
// resolveExpectNotFound verifies that the given name is not in the mounttable.
func resolveExpectNotFound(t *testing.T, name string) {
- if results, err := globalRT.Namespace().Resolve(globalRT.NewContext(), name); err == nil {
+ if results, err := veyron2.GetNamespace(globalCtx).Resolve(globalRT.NewContext(), name); err == nil {
t.Fatalf(testutil.FormatLogLine(2, "Resolve(%v) succeeded with results %v when it was expected to fail", name, results))
} else if expectErr := naming.ErrNoSuchName.ID; !verror2.Is(err, expectErr) {
t.Fatalf(testutil.FormatLogLine(2, "Resolve(%v) failed with error %v, expected error ID %v", name, err, expectErr))
@@ -53,7 +53,7 @@
// resolve looks up the given name in the mounttable.
func resolve(t *testing.T, name string, replicas int) []string {
- results, err := globalRT.Namespace().Resolve(globalRT.NewContext(), name)
+ results, err := veyron2.GetNamespace(globalCtx).Resolve(globalCtx, name)
if err != nil {
t.Fatalf("Resolve(%v) failed: %v", name, err)
}
diff --git a/services/mgmt/lib/testutil/modules.go b/services/mgmt/lib/testutil/modules.go
index 8b801e5..219c1ae 100644
--- a/services/mgmt/lib/testutil/modules.go
+++ b/services/mgmt/lib/testutil/modules.go
@@ -127,12 +127,13 @@
}
// NewRuntime makes an instance of the runtime.
-func NewRuntime(t *testing.T, ort veyron2.Runtime, opts ...veyron2.ROpt) veyron2.Runtime {
+func NewRuntime(t *testing.T, octx *context.T, opts ...veyron2.ROpt) veyron2.Runtime {
runtime, err := rt.New(opts...)
if err != nil {
t.Fatalf("rt.New() failed: %v", err)
}
- runtime.Namespace().SetRoots(ort.Namespace().Roots()[0])
+ ctx := runtime.NewContext()
+ veyron2.GetNamespace(ctx).SetRoots(veyron2.GetNamespace(octx).Roots()[0])
return runtime
}
diff --git a/services/proxy/proxyd/main.go b/services/proxy/proxyd/main.go
index bb5f660..1f0f177 100644
--- a/services/proxy/proxyd/main.go
+++ b/services/proxy/proxyd/main.go
@@ -9,6 +9,7 @@
"strings"
"time"
+ "v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
@@ -36,19 +37,20 @@
vlog.Fatalf("Could not initialize runtime: %s", err)
}
defer r.Cleanup()
+ ctx := r.NewContext()
rid, err := naming.NewRoutingID()
if err != nil {
vlog.Fatal(err)
}
- proxy, err := proxy.New(rid, r.Principal(), *protocol, *address, *pubAddress)
+ proxy, err := proxy.New(rid, veyron2.GetPrincipal(ctx), *protocol, *address, *pubAddress)
if err != nil {
vlog.Fatal(err)
}
defer proxy.Shutdown()
if len(*name) > 0 {
- publisher := publisher.New(r.NewContext(), r.Namespace(), time.Minute)
+ publisher := publisher.New(ctx, veyron2.GetNamespace(ctx), time.Minute)
defer publisher.WaitForStop()
defer publisher.Stop()
ep := naming.JoinAddressName(proxy.Endpoint().String(), "")
diff --git a/tools/debug/impl.go b/tools/debug/impl.go
index e895973..e85ad2a 100644
--- a/tools/debug/impl.go
+++ b/tools/debug/impl.go
@@ -15,6 +15,7 @@
"v.io/core/veyron/lib/signals"
"v.io/core/veyron/services/mgmt/pprof/client"
istats "v.io/core/veyron/services/mgmt/stats"
+ "v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/services/mgmt/logreader"
@@ -192,7 +193,7 @@
defer wg.Done()
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
- c, err := runtime.Namespace().Glob(ctx, pattern)
+ c, err := veyron2.GetNamespace(ctx).Glob(ctx, pattern)
if err != nil {
errors <- fmt.Errorf("%s: %v", pattern, err)
return
diff --git a/tools/mounttable/impl.go b/tools/mounttable/impl.go
index 39bd34e..be3df84 100644
--- a/tools/mounttable/impl.go
+++ b/tools/mounttable/impl.go
@@ -27,8 +27,11 @@
}
func runGlob(cmd *cmdline.Command, args []string) error {
+ ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ defer cancel()
+
if len(args) == 1 {
- roots := runtime.Namespace().Roots()
+ roots := veyron2.GetNamespace(ctx).Roots()
if len(roots) == 0 {
return errors.New("no namespace root")
}
@@ -37,8 +40,7 @@
if expected, got := 2, len(args); expected != got {
return cmd.UsageErrorf("glob: incorrect number of arguments, expected %d, got %d", expected, got)
}
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
- defer cancel()
+
name, pattern := args[0], args[1]
client := veyron2.GetClient(ctx)
call, err := client.StartCall(ctx, name, ipc.GlobMethod, []interface{}{pattern}, options.NoResolve{})
diff --git a/tools/namespace/impl.go b/tools/namespace/impl.go
index d50e2c2..b2df4db 100644
--- a/tools/namespace/impl.go
+++ b/tools/namespace/impl.go
@@ -4,6 +4,7 @@
"fmt"
"time"
+ "v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/vlog"
@@ -27,9 +28,12 @@
return cmd.UsageErrorf("glob: incorrect number of arguments, expected %d, got %d", expected, got)
}
pattern := args[0]
- ns := runtime.Namespace()
+
ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
defer cancel()
+
+ ns := veyron2.GetNamespace(ctx)
+
c, err := ns.Glob(ctx, pattern)
if err != nil {
vlog.Infof("ns.Glob(%q) failed: %v", pattern, err)
@@ -75,9 +79,12 @@
if err != nil {
return fmt.Errorf("TTL parse error: %v", err)
}
- ns := runtime.Namespace()
+
ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
defer cancel()
+
+ ns := veyron2.GetNamespace(ctx)
+
if err = ns.Mount(ctx, name, server, ttl); err != nil {
vlog.Infof("ns.Mount(%q, %q, %s) failed: %v", name, server, ttl, err)
return err
@@ -104,9 +111,12 @@
}
name := args[0]
server := args[1]
- ns := runtime.Namespace()
+
ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
defer cancel()
+
+ ns := veyron2.GetNamespace(ctx)
+
if err := ns.Unmount(ctx, name, server); err != nil {
vlog.Infof("ns.Unmount(%q, %q) failed: %v", name, server, err)
return err
@@ -129,9 +139,12 @@
return cmd.UsageErrorf("resolve: incorrect number of arguments, expected %d, got %d", expected, got)
}
name := args[0]
- ns := runtime.Namespace()
+
ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
defer cancel()
+
+ ns := veyron2.GetNamespace(ctx)
+
servers, err := ns.Resolve(ctx, name)
if err != nil {
vlog.Infof("ns.Resolve(%q) failed: %v", name, err)
@@ -157,9 +170,12 @@
return cmd.UsageErrorf("resolvetomt: incorrect number of arguments, expected %d, got %d", expected, got)
}
name := args[0]
- ns := runtime.Namespace()
+
ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
defer cancel()
+
+ ns := veyron2.GetNamespace(ctx)
+
e, err := ns.ResolveToMountTableX(ctx, name)
if err != nil {
vlog.Infof("ns.ResolveToMountTableX(%q) failed: %v", name, err)
diff --git a/tools/naming/simulator/driver.go b/tools/naming/simulator/driver.go
index 1b3a15b..847d224 100644
--- a/tools/naming/simulator/driver.go
+++ b/tools/naming/simulator/driver.go
@@ -17,6 +17,7 @@
"unicode"
"v.io/core/veyron2"
+ "v.io/core/veyron2/context"
"v.io/core/veyron2/rt"
"v.io/core/veyron/lib/expect"
@@ -96,6 +97,7 @@
}
var runtime veyron2.Runtime
+var ctx *context.T
func main() {
var err error
@@ -103,6 +105,7 @@
panic(err)
}
defer runtime.Cleanup()
+ ctx = runtime.NewContext()
// Subprocesses commands are run by fork/execing this binary
// so we must test to see if this instance is a subprocess or the
diff --git a/tools/naming/simulator/shell_functions.go b/tools/naming/simulator/shell_functions.go
index a2eeed0..396fe6d 100644
--- a/tools/naming/simulator/shell_functions.go
+++ b/tools/naming/simulator/shell_functions.go
@@ -5,6 +5,7 @@
"io"
"time"
+ "v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
@@ -61,8 +62,8 @@
if err != nil {
return fmt.Errorf("failed to parse time from %q", ttlstr)
}
- ns := runtime.Namespace()
- if err := ns.Mount(runtime.NewContext(), mp, server, ttl, opts...); err != nil {
+ ns := veyron2.GetNamespace(ctx)
+ if err := ns.Mount(ctx, mp, server, ttl, opts...); err != nil {
return err
}
fmt.Fprintf(stdout, "Mount(%s, %s, %s, %v)\n", mp, server, ttl, opts)
@@ -82,7 +83,7 @@
default:
return fmt.Errorf("arg must be 'on' or 'off'")
}
- runtime.Namespace().CacheCtl(naming.DisableCache(disable))
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(disable))
return nil
}
@@ -93,7 +94,7 @@
return err
}
name := args[1]
- servers, err := fn(runtime.NewContext(), name)
+ servers, err := fn(ctx, name)
if err != nil {
fmt.Fprintf(stdout, "RN=0\n")
return err
@@ -106,13 +107,13 @@
}
func resolveObject(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- return resolve(runtime.Namespace().Resolve, stdin, stdout, stderr, env, args...)
+ return resolve(veyron2.GetNamespace(ctx).Resolve, stdin, stdout, stderr, env, args...)
}
func resolveMT(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- return resolve(runtime.Namespace().ResolveToMountTable, stdin, stdout, stderr, env, args...)
+ return resolve(veyron2.GetNamespace(ctx).ResolveToMountTable, stdin, stdout, stderr, env, args...)
}
func setNamespaceRoots(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- return runtime.Namespace().SetRoots(args[1:]...)
+ return veyron2.GetNamespace(ctx).SetRoots(args[1:]...)
}