Merge "veyron2/vdl: Signature cleanups."
diff --git a/profiles/chrome/chrome.go b/profiles/chrome/chrome.go
index 9d16365..ada91dd 100644
--- a/profiles/chrome/chrome.go
+++ b/profiles/chrome/chrome.go
@@ -11,6 +11,7 @@
_ "veyron.io/veyron/veyron/lib/websocket"
"veyron.io/veyron/veyron/profiles/internal/platform"
+ _ "veyron.io/veyron/veyron/runtimes/google/rt"
)
var ListenSpec = ipc.ListenSpec{}
diff --git a/runtimes/google/rt/mgmt_test.go b/runtimes/google/rt/mgmt_test.go
index cae8d50..ae621e4 100644
--- a/runtimes/google/rt/mgmt_test.go
+++ b/runtimes/google/rt/mgmt_test.go
@@ -293,10 +293,6 @@
}
func setupRemoteAppCycleMgr(t *testing.T) (veyron2.Runtime, modules.Handle, appcycle.AppCycleClientMethods, func()) {
- // We need to use the public API since stubs are used below (and they
- // refer to the global rt.R() function), but we take care to make sure
- // that the "google" runtime we are trying to test in this package is
- // the one being used.
r, _ := rt.New(profileOpt)
childcreds := security.NewVeyronCredentials(r.Principal(), appCmd)
diff --git a/services/mgmt/application/applicationd/main.go b/services/mgmt/application/applicationd/main.go
index af11153..4898ae7 100644
--- a/services/mgmt/application/applicationd/main.go
+++ b/services/mgmt/application/applicationd/main.go
@@ -23,7 +23,10 @@
if *store == "" {
vlog.Fatalf("Specify a directory for storing application envelopes using --store=<name>")
}
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ vlog.Fatalf("Could not initialize runtime: %v", err)
+ }
defer runtime.Cleanup()
server, err := runtime.NewServer()
if err != nil {
diff --git a/services/mgmt/application/impl/impl_test.go b/services/mgmt/application/impl/impl_test.go
index d8c158c..62c4e24 100644
--- a/services/mgmt/application/impl/impl_test.go
+++ b/services/mgmt/application/impl/impl_test.go
@@ -6,6 +6,7 @@
"reflect"
"testing"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/application"
@@ -19,10 +20,10 @@
// TestInterface tests that the implementation correctly implements
// the Application interface.
func TestInterface(t *testing.T) {
- ctx := rt.R().NewContext()
+ ctx := runtime.NewContext()
// Setup and start the application repository server.
- server, err := rt.R().NewServer()
+ server, err := runtime.NewServer()
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -153,12 +154,18 @@
}
}
+var runtime veyron2.Runtime
+
func init() {
- rt.Init()
+ var err error
+ runtime, err = rt.New()
+ if err != nil {
+ panic(err)
+ }
}
func TestPreserveAcrossRestarts(t *testing.T) {
- server, err := rt.R().NewServer()
+ server, err := runtime.NewServer()
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -193,12 +200,12 @@
Binary: "/veyron/name/of/binary",
}
- if err := stubV1.Put(rt.R().NewContext(), []string{"media"}, envelopeV1); err != nil {
+ if err := stubV1.Put(runtime.NewContext(), []string{"media"}, envelopeV1); err != nil {
t.Fatalf("Put() failed: %v", err)
}
// There is content here now.
- output, err := stubV1.Match(rt.R().NewContext(), []string{"media"})
+ output, err := stubV1.Match(runtime.NewContext(), []string{"media"})
if err != nil {
t.Fatalf("Match(%v) failed: %v", "media", err)
}
@@ -209,7 +216,7 @@
server.Stop()
// Setup and start a second application server in its place.
- server, err = rt.R().NewServer()
+ server, err = runtime.NewServer()
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -229,7 +236,7 @@
stubV1 = repository.ApplicationClient(naming.JoinAddressName(endpoint.String(), "search/v1"))
- output, err = stubV1.Match(rt.R().NewContext(), []string{"media"})
+ output, err = stubV1.Match(runtime.NewContext(), []string{"media"})
if err != nil {
t.Fatalf("Match(%v) failed: %v", "media", err)
}
diff --git a/services/mgmt/binary/binaryd/main.go b/services/mgmt/binary/binaryd/main.go
index 677e9e7..16ac319 100644
--- a/services/mgmt/binary/binaryd/main.go
+++ b/services/mgmt/binary/binaryd/main.go
@@ -47,8 +47,12 @@
}
func main() {
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ vlog.Fatalf("Could not initialize runtime: %v", err)
+ }
defer runtime.Cleanup()
+
root, err := impl.SetupRoot(*rootFlag)
if err != nil {
vlog.Errorf("SetupRoot(%q) failed: %v", *rootFlag, err)
diff --git a/services/mgmt/binary/impl/http_test.go b/services/mgmt/binary/impl/http_test.go
index bde93b3..84a6e99 100644
--- a/services/mgmt/binary/impl/http_test.go
+++ b/services/mgmt/binary/impl/http_test.go
@@ -8,7 +8,6 @@
"net/http"
"testing"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/repository"
"veyron.io/veyron/veyron/lib/testutil"
@@ -29,7 +28,7 @@
data[i] = testutil.RandomBytes(size)
}
mediaInfo := repository.MediaInfo{Type: "application/octet-stream"}
- if err := binary.Create(rt.R().NewContext(), int32(length), mediaInfo); err != nil {
+ if err := binary.Create(runtime.NewContext(), int32(length), mediaInfo); err != nil {
t.Fatalf("Create() failed: %v", err)
}
for i := 0; i < length; i++ {
@@ -37,7 +36,7 @@
t.FailNow()
}
}
- parts, _, err := binary.Stat(rt.R().NewContext())
+ parts, _, err := binary.Stat(runtime.NewContext())
if err != nil {
t.Fatalf("Stat() failed: %v", err)
}
@@ -70,7 +69,7 @@
t.Fatalf("Unexpected size: expected %v, got %v", expected, got)
}
}
- if err := binary.Delete(rt.R().NewContext()); err != nil {
+ if err := binary.Delete(runtime.NewContext()); err != nil {
t.Fatalf("Delete() failed: %v", err)
}
}
diff --git a/services/mgmt/binary/impl/impl_test.go b/services/mgmt/binary/impl/impl_test.go
index 35aa2e3..6f603e0 100644
--- a/services/mgmt/binary/impl/impl_test.go
+++ b/services/mgmt/binary/impl/impl_test.go
@@ -13,6 +13,7 @@
"reflect"
"testing"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/repository"
@@ -27,15 +28,21 @@
veyronPrefix = "veyron_binary_repository"
)
+var runtime veyron2.Runtime
+
func init() {
testutil.Init()
- rt.Init()
+
+ var err error
+ if runtime, err = rt.New(); err != nil {
+ panic(err)
+ }
}
// invokeUpload invokes the Upload RPC using the given client binary
// <binary> and streams the given binary <binary> to it.
func invokeUpload(t *testing.T, binary repository.BinaryClientMethods, data []byte, part int32) (error, error) {
- stream, err := binary.Upload(rt.R().NewContext(), part)
+ stream, err := binary.Upload(runtime.NewContext(), part)
if err != nil {
t.Errorf("Upload() failed: %v", err)
return nil, err
@@ -67,7 +74,7 @@
// invokeDownload invokes the Download RPC using the given client binary
// <binary> and streams binary from to it.
func invokeDownload(t *testing.T, binary repository.BinaryClientMethods, part int32) ([]byte, error, error) {
- stream, err := binary.Download(rt.R().NewContext(), part)
+ stream, err := binary.Download(runtime.NewContext(), part)
if err != nil {
t.Errorf("Download() failed: %v", err)
return nil, nil, err
@@ -107,7 +114,7 @@
vlog.Fatalf("WriteFile(%v, %v, %v) failed: %v", path, Version, perm, err)
}
// Setup and start the binary repository server.
- server, err := rt.R().NewServer()
+ server, err := runtime.NewServer()
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -162,13 +169,13 @@
size := testutil.Rand.Intn(1000 * bufferLength)
data := testutil.RandomBytes(size)
// Test the binary repository interface.
- if err := binary.Create(rt.R().NewContext(), 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+ if err := binary.Create(runtime.NewContext(), 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed: %v", err)
}
if streamErr, err := invokeUpload(t, binary, data, 0); streamErr != nil || err != nil {
t.FailNow()
}
- parts, _, err := binary.Stat(rt.R().NewContext())
+ parts, _, err := binary.Stat(runtime.NewContext())
if err != nil {
t.Fatalf("Stat() failed: %v", err)
}
@@ -188,14 +195,14 @@
if bytes.Compare(output, data) != 0 {
t.Fatalf("Unexpected output: expected %v, got %v", data, output)
}
- results, err := testutil.GlobName(rt.R().NewContext(), naming.JoinAddressName(ep, ""), "...")
+ results, err := testutil.GlobName(runtime.NewContext(), naming.JoinAddressName(ep, ""), "...")
if err != nil {
t.Fatalf("GlobName failed: %v", err)
}
if expected := []string{"", "test"}; !reflect.DeepEqual(results, expected) {
t.Errorf("Unexpected results: expected %q, got %q", expected, results)
}
- if err := binary.Delete(rt.R().NewContext()); err != nil {
+ if err := binary.Delete(runtime.NewContext()); err != nil {
t.Fatalf("Delete() failed: %v", err)
}
}
@@ -215,7 +222,7 @@
data[i] = testutil.RandomBytes(size)
}
// Test the binary repository interface.
- if err := binary.Create(rt.R().NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+ if err := binary.Create(runtime.NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed: %v", err)
}
for i := 0; i < length; i++ {
@@ -223,7 +230,7 @@
t.FailNow()
}
}
- parts, _, err := binary.Stat(rt.R().NewContext())
+ parts, _, err := binary.Stat(runtime.NewContext())
if err != nil {
t.Fatalf("Stat() failed: %v", err)
}
@@ -245,7 +252,7 @@
t.Fatalf("Unexpected size: expected %v, got %v", expected, got)
}
}
- if err := binary.Delete(rt.R().NewContext()); err != nil {
+ if err := binary.Delete(runtime.NewContext()); err != nil {
t.Fatalf("Delete() failed: %v", err)
}
}
@@ -264,13 +271,13 @@
size := testutil.Rand.Intn(1000 * bufferLength)
data[i] = testutil.RandomBytes(size)
}
- if err := binary.Create(rt.R().NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+ if err := binary.Create(runtime.NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed: %v", err)
}
// Simulate a flaky upload client that keeps uploading parts until
// finished.
for {
- parts, _, err := binary.Stat(rt.R().NewContext())
+ parts, _, err := binary.Stat(runtime.NewContext())
if err != nil {
t.Fatalf("Stat() failed: %v", err)
}
@@ -290,7 +297,7 @@
}
}
}
- if err := binary.Delete(rt.R().NewContext()); err != nil {
+ if err := binary.Delete(runtime.NewContext()); err != nil {
t.Fatalf("Delete() failed: %v", err)
}
}
@@ -309,10 +316,10 @@
data[i][j] = byte(testutil.Rand.Int())
}
}
- if err := binary.Create(rt.R().NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+ if err := binary.Create(runtime.NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed: %v", err)
}
- if err := binary.Create(rt.R().NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err == nil {
+ if err := binary.Create(runtime.NewContext(), int32(length), repository.MediaInfo{Type: "application/octet-stream"}); err == nil {
t.Fatalf("Create() did not fail when it should have")
} else if want := verror.Exists; !verror.Is(err, want) {
t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
@@ -350,10 +357,10 @@
t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
}
}
- if err := binary.Delete(rt.R().NewContext()); err != nil {
+ if err := binary.Delete(runtime.NewContext()); err != nil {
t.Fatalf("Delete() failed: %v", err)
}
- if err := binary.Delete(rt.R().NewContext()); err == nil {
+ if err := binary.Delete(runtime.NewContext()); err == nil {
t.Fatalf("Delete() did not fail when it should have")
} else if want := verror.NoExist; !verror.Is(err, want) {
t.Fatalf("Unexpected error: %v, expected error id %v", err, want)
@@ -372,14 +379,14 @@
name := naming.JoinAddressName(ep, obj)
binary := repository.BinaryClient(name)
- if err := binary.Create(rt.R().NewContext(), 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
+ if err := binary.Create(runtime.NewContext(), 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed: %v", err)
}
if streamErr, err := invokeUpload(t, binary, data, 0); streamErr != nil || err != nil {
t.FailNow()
}
}
- results, err := testutil.GlobName(rt.R().NewContext(), naming.JoinAddressName(ep, ""), "...")
+ results, err := testutil.GlobName(runtime.NewContext(), naming.JoinAddressName(ep, ""), "...")
if err != nil {
t.Fatalf("GlobName failed: %v", err)
}
diff --git a/services/mgmt/build/buildd/main.go b/services/mgmt/build/buildd/main.go
index deb5f37..e2d68ba 100644
--- a/services/mgmt/build/buildd/main.go
+++ b/services/mgmt/build/buildd/main.go
@@ -22,7 +22,10 @@
func main() {
flag.Parse()
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ vlog.Fatalf("Could not initialize runtime: %v", err)
+ }
defer runtime.Cleanup()
server, err := runtime.NewServer()
if err != nil {
diff --git a/services/mgmt/build/impl/impl_test.go b/services/mgmt/build/impl/impl_test.go
index 3878aba..27a7c49 100644
--- a/services/mgmt/build/impl/impl_test.go
+++ b/services/mgmt/build/impl/impl_test.go
@@ -8,6 +8,7 @@
"strings"
"testing"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/build"
@@ -15,9 +16,14 @@
"veyron.io/veyron/veyron/profiles"
)
+var globalRT veyron2.Runtime
+
func init() {
testutil.Init()
- rt.Init()
+ var err error
+ if globalRT, err = rt.New(); err != nil {
+ panic(err)
+ }
}
// findGoBinary returns the path to the given Go binary and
@@ -48,7 +54,7 @@
// startServer starts the build server.
func startServer(t *testing.T) (build.BuilderClientMethods, func()) {
gobin, goroot := findGoBinary(t, "go")
- server, err := rt.R().NewServer()
+ server, err := globalRT.NewServer()
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -70,7 +76,7 @@
func invokeBuild(t *testing.T, client build.BuilderClientMethods, files []build.File) ([]byte, []build.File, error) {
arch, opsys := getArch(), getOS()
- stream, err := client.Build(rt.R().NewContext(), arch, opsys)
+ stream, err := client.Build(globalRT.NewContext(), arch, opsys)
if err != nil {
t.Errorf("Build(%v, %v) failed: %v", err, arch, opsys)
return nil, nil, err
diff --git a/services/mgmt/debug/dispatcher_test.go b/services/mgmt/debug/dispatcher_test.go
index 46fd799..480de4d 100644
--- a/services/mgmt/debug/dispatcher_test.go
+++ b/services/mgmt/debug/dispatcher_test.go
@@ -50,7 +50,12 @@
}
func TestDebugServer(t *testing.T) {
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ t.Fatalf("Could not initialize runtime: %v", err)
+ }
+ defer runtime.Cleanup()
+
tracedContext := func() context.T {
ctx := runtime.NewContext()
vtrace.FromContext(ctx).Trace().ForceCollect()
@@ -163,9 +168,9 @@
// Glob from the root.
{
- ns := rt.R().Namespace()
+ ns := runtime.Namespace()
ns.SetRoots(naming.JoinAddressName(endpoint, "debug"))
- ctx, cancel := rt.R().NewContext().WithTimeout(10 * time.Second)
+ ctx, cancel := runtime.NewContext().WithTimeout(10 * time.Second)
defer cancel()
c, err := ns.Glob(ctx, "logs/...")
if err != nil {
diff --git a/services/mgmt/logreader/impl/logfile_test.go b/services/mgmt/logreader/impl/logfile_test.go
index 11a6ae1..c161d88 100644
--- a/services/mgmt/logreader/impl/logfile_test.go
+++ b/services/mgmt/logreader/impl/logfile_test.go
@@ -9,6 +9,7 @@
"veyron.io/veyron/veyron/profiles"
"veyron.io/veyron/veyron/services/mgmt/logreader/impl"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
@@ -18,8 +19,8 @@
"veyron.io/veyron/veyron2/verror"
)
-func startServer(t *testing.T, disp ipc.Dispatcher) (ipc.Server, string, error) {
- server, err := rt.R().NewServer()
+func startServer(t *testing.T, runtime veyron2.Runtime, disp ipc.Dispatcher) (ipc.Server, string, error) {
+ server, err := runtime.NewServer()
if err != nil {
t.Fatalf("NewServer failed: %v", err)
return nil, "", err
@@ -60,14 +61,18 @@
}
func TestReadLogImplNoFollow(t *testing.T) {
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ t.Fatalf("Could not initialize runtime: %v", err)
+ }
+ defer runtime.Cleanup()
workdir, err := ioutil.TempDir("", "logreadertest")
if err != nil {
t.Fatalf("ioutil.TempDir: %v", err)
}
defer os.RemoveAll(workdir)
- server, endpoint, err := startServer(t, &logFileDispatcher{workdir})
+ server, endpoint, err := startServer(t, runtime, &logFileDispatcher{workdir})
if err != nil {
t.Fatalf("startServer failed: %v", err)
}
@@ -146,14 +151,18 @@
}
func TestReadLogImplWithFollow(t *testing.T) {
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ t.Fatalf("Could not initialize runtime: %v", err)
+ }
+ defer runtime.Cleanup()
workdir, err := ioutil.TempDir("", "logreadertest")
if err != nil {
t.Fatalf("ioutil.TempDir: %v", err)
}
defer os.RemoveAll(workdir)
- server, endpoint, err := startServer(t, &logFileDispatcher{workdir})
+ server, endpoint, err := startServer(t, runtime, &logFileDispatcher{workdir})
if err != nil {
t.Fatalf("startServer failed: %v", err)
}
diff --git a/services/mgmt/node/impl/app_service.go b/services/mgmt/node/impl/app_service.go
index 4c4d43e..56f23ab 100644
--- a/services/mgmt/node/impl/app_service.go
+++ b/services/mgmt/node/impl/app_service.go
@@ -126,12 +126,12 @@
"sync"
"time"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/context"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/mgmt"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/options"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mgmt/appcycle"
"veyron.io/veyron/veyron2/services/mgmt/application"
@@ -324,7 +324,7 @@
}
// newVersion sets up the directory for a new application version.
-func newVersion(installationDir string, envelope *application.Envelope, oldVersionDir string) (string, error) {
+func newVersion(ctx context.T, installationDir string, envelope *application.Envelope, oldVersionDir string) (string, error) {
versionDir := filepath.Join(installationDir, generateVersionDirName())
if err := mkdir(versionDir); err != nil {
return "", verror2.Make(ErrOperationFailed, nil)
@@ -334,7 +334,7 @@
return "", verror2.Make(ErrOperationFailed, nil)
}
// TODO(caprita): Share binaries if already existing locally.
- if err := downloadBinary(versionDir, "bin", envelope.Binary); err != nil {
+ if err := downloadBinary(ctx, versionDir, "bin", envelope.Binary); err != nil {
return versionDir, err
}
for localPkg, pkgName := range envelope.Packages {
@@ -343,7 +343,7 @@
return versionDir, verror2.Make(ErrOperationFailed, nil)
}
path := filepath.Join(pkgDir, localPkg)
- if err := libbinary.DownloadToFile(rt.R().NewContext(), pkgName, path); err != nil {
+ if err := libbinary.DownloadToFile(ctx, pkgName, path); err != nil {
vlog.Infof("DownloadToFile(%q, %q) failed: %v", pkgName, path, err)
return versionDir, verror2.Make(ErrOperationFailed, nil)
}
@@ -365,7 +365,7 @@
}
// TODO(rjkroege): Refactor this code with the instance creation code.
-func initializeInstallationACLs(dir string, blessings []string, acl access.TaggedACLMap) error {
+func initializeInstallationACLs(principal security.Principal, dir string, blessings []string, acl access.TaggedACLMap) error {
// Add the invoker's blessings.
for _, b := range blessings {
for _, tag := range access.AllTypicalTags() {
@@ -375,14 +375,14 @@
aclDir := path.Join(dir, "acls")
aclData := path.Join(aclDir, "data")
aclSig := path.Join(aclDir, "signature")
- return writeACLs(aclData, aclSig, aclDir, acl)
+ return writeACLs(principal, aclData, aclSig, aclDir, acl)
}
func (i *appService) Install(call ipc.ServerContext, applicationVON string) (string, error) {
if len(i.suffix) > 0 {
return "", verror2.Make(ErrInvalidSuffix, call)
}
- ctx, cancel := rt.R().NewContext().WithTimeout(ipcContextTimeout)
+ ctx, cancel := call.WithTimeout(ipcContextTimeout)
defer cancel()
envelope, err := fetchAppEnvelope(ctx, applicationVON)
if err != nil {
@@ -398,7 +398,7 @@
deferrer()
}
}()
- if _, err := newVersion(installationDir, envelope, ""); err != nil {
+ if _, err := newVersion(call, installationDir, envelope, ""); err != nil {
return "", err
}
if err := saveOrigin(installationDir, applicationVON); err != nil {
@@ -411,7 +411,7 @@
// TODO(caprita,rjkroege): Should the installation ACLs really be
// seeded with the node ACL? Instead, might want to hide the nodeACL
// from the app?
- if err := initializeInstallationACLs(installationDir, call.RemoteBlessings().ForContext(call), i.nodeACL.Copy()); err != nil {
+ if err := initializeInstallationACLs(call.LocalPrincipal(), installationDir, call.RemoteBlessings().ForContext(call), i.nodeACL.Copy()); err != nil {
return "", err
}
deferrer = nil
@@ -455,21 +455,23 @@
}
// setupPrincipal sets up the instance's principal, with the right blessings.
-func setupPrincipal(instanceDir, versionDir string, call ipc.ServerContext, securityAgent *securityAgentState, info *instanceInfo) error {
+func setupPrincipal(ctx context.T, instanceDir, versionDir string, call ipc.ServerContext, securityAgent *securityAgentState, info *instanceInfo) error {
var p security.Principal
if securityAgent != nil {
// TODO(caprita): Part of the cleanup upon destroying an
// instance, we should tell the agent to drop the principal.
- handle, conn, err := securityAgent.keyMgrAgent.NewPrincipal(rt.R().NewContext(), false)
+ handle, conn, err := securityAgent.keyMgrAgent.NewPrincipal(ctx, false)
defer conn.Close()
- client, err := rt.R().NewClient(options.VCSecurityNone)
+
+ runtime := veyron2.RuntimeFromContext(ctx)
+ client, err := runtime.NewClient(options.VCSecurityNone)
if err != nil {
vlog.Errorf("NewClient() failed: %v", err)
return verror2.Make(ErrOperationFailed, nil)
}
defer client.Close()
// TODO(caprita): release the socket created by NewAgentPrincipal.
- if p, err = agent.NewAgentPrincipal(client, int(conn.Fd()), rt.R().NewContext()); err != nil {
+ if p, err = agent.NewAgentPrincipal(client, int(conn.Fd()), ctx); err != nil {
vlog.Errorf("NewAgentPrincipal() failed: %v", err)
return verror2.Make(ErrOperationFailed, nil)
}
@@ -598,7 +600,7 @@
return nil
}
-func initializeInstanceACLs(instanceDir string, blessings []string, acl access.TaggedACLMap) error {
+func initializeInstanceACLs(principal security.Principal, instanceDir string, blessings []string, acl access.TaggedACLMap) error {
for _, b := range blessings {
for _, tag := range access.AllTypicalTags() {
acl.Add(security.BlessingPattern(b), string(tag))
@@ -607,7 +609,7 @@
aclDir := path.Join(instanceDir, "acls")
aclData := path.Join(aclDir, "data")
aclSig := path.Join(aclDir, "signature")
- return writeACLs(aclData, aclSig, aclDir, acl)
+ return writeACLs(principal, aclData, aclSig, aclDir, acl)
}
// newInstance sets up the directory for a new application instance.
@@ -640,7 +642,7 @@
return instanceDir, instanceID, verror2.Make(ErrOperationFailed, call)
}
instanceInfo := new(instanceInfo)
- if err := setupPrincipal(instanceDir, versionDir, call, i.securityAgent, instanceInfo); err != nil {
+ if err := setupPrincipal(call, instanceDir, versionDir, call, i.securityAgent, instanceInfo); err != nil {
return instanceDir, instanceID, err
}
if err := saveInstanceInfo(instanceDir, instanceInfo); err != nil {
@@ -650,7 +652,7 @@
return instanceDir, instanceID, err
}
- if err := initializeInstanceACLs(instanceDir, call.RemoteBlessings().ForContext(call), i.nodeACL.Copy()); err != nil {
+ if err := initializeInstanceACLs(call.LocalPrincipal(), instanceDir, call.RemoteBlessings().ForContext(call), i.nodeACL.Copy()); err != nil {
return instanceDir, instanceID, err
}
return instanceDir, instanceID, nil
@@ -931,9 +933,9 @@
return i.run(instanceDir, systemName)
}
-func stopAppRemotely(appVON string) error {
+func stopAppRemotely(ctx context.T, appVON string) error {
appStub := appcycle.AppCycleClient(appVON)
- ctx, cancel := rt.R().NewContext().WithTimeout(ipcContextTimeout)
+ ctx, cancel := ctx.WithTimeout(ipcContextTimeout)
defer cancel()
stream, err := appStub.Stop(ctx)
if err != nil {
@@ -955,17 +957,17 @@
return nil
}
-func stop(instanceDir string) error {
+func stop(ctx context.T, instanceDir string) error {
info, err := loadInstanceInfo(instanceDir)
if err != nil {
return err
}
- return stopAppRemotely(info.AppCycleMgrName)
+ return stopAppRemotely(ctx, info.AppCycleMgrName)
}
// TODO(caprita): implement deadline for Stop.
-func (i *appService) Stop(_ ipc.ServerContext, deadline uint32) error {
+func (i *appService) Stop(ctx ipc.ServerContext, deadline uint32) error {
instanceDir, err := i.instanceDir()
if err != nil {
return err
@@ -976,14 +978,14 @@
if err := transitionInstance(instanceDir, started, stopping); err != nil {
return err
}
- if err := stop(instanceDir); err != nil {
+ if err := stop(ctx, instanceDir); err != nil {
transitionInstance(instanceDir, stopping, started)
return err
}
return transitionInstance(instanceDir, stopping, stopped)
}
-func (i *appService) Suspend(ipc.ServerContext) error {
+func (i *appService) Suspend(ctx ipc.ServerContext) error {
instanceDir, err := i.instanceDir()
if err != nil {
return err
@@ -991,7 +993,7 @@
if err := transitionInstance(instanceDir, started, suspending); err != nil {
return err
}
- if err := stop(instanceDir); err != nil {
+ if err := stop(ctx, instanceDir); err != nil {
transitionInstance(instanceDir, suspending, started)
return err
}
@@ -1018,7 +1020,7 @@
if err != nil {
return err
}
- ctx, cancel := rt.R().NewContext().WithTimeout(ipcContextTimeout)
+ ctx, cancel := call.WithTimeout(ipcContextTimeout)
defer cancel()
newEnvelope, err := fetchAppEnvelope(ctx, originVON)
if err != nil {
@@ -1048,7 +1050,7 @@
if reflect.DeepEqual(oldEnvelope, newEnvelope) {
return verror2.Make(ErrUpdateNoOp, call)
}
- versionDir, err := newVersion(installationDir, newEnvelope, oldVersionDir)
+ versionDir, err := newVersion(call, installationDir, newEnvelope, oldVersionDir)
if err != nil {
cleanupDir(versionDir, "")
return err
@@ -1248,12 +1250,12 @@
}
// TODO(rjkroege): Consider maintaining an in-memory ACL cache.
-func (i *appService) SetACL(_ ipc.ServerContext, acl access.TaggedACLMap, etag string) error {
+func (i *appService) SetACL(ctx ipc.ServerContext, acl access.TaggedACLMap, etag string) error {
dir, err := dirFromSuffix(i.suffix, i.config.Root)
if err != nil {
return err
}
- return setAppACL(i.locks, dir, acl, etag)
+ return setAppACL(ctx.LocalPrincipal(), i.locks, dir, acl, etag)
}
func (i *appService) GetACL(_ ipc.ServerContext) (acl access.TaggedACLMap, etag string, err error) {
diff --git a/services/mgmt/node/impl/callback.go b/services/mgmt/node/impl/callback.go
index 94241d9..f1423b2 100644
--- a/services/mgmt/node/impl/callback.go
+++ b/services/mgmt/node/impl/callback.go
@@ -1,8 +1,8 @@
package impl
import (
+ "veyron.io/veyron/veyron2/context"
"veyron.io/veyron/veyron2/mgmt"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/vlog"
"veyron.io/veyron/veyron/lib/exec"
@@ -11,7 +11,7 @@
// InvokeCallback provides the parent node manager with the given name (which
// is expected to be this node manager's object name).
-func InvokeCallback(name string) {
+func InvokeCallback(ctx context.T, name string) {
handle, err := exec.GetChildHandle()
switch err {
case nil:
@@ -22,7 +22,7 @@
return
}
nmClient := node.ConfigClient(callbackName)
- ctx, cancel := rt.R().NewContext().WithTimeout(ipcContextTimeout)
+ ctx, cancel := ctx.WithTimeout(ipcContextTimeout)
defer cancel()
if err := nmClient.Set(ctx, mgmt.ChildNameConfigKey, name); err != nil {
vlog.Fatalf("Set(%v, %v) failed: %v", mgmt.ChildNameConfigKey, name, err)
diff --git a/services/mgmt/node/impl/dispatcher.go b/services/mgmt/node/impl/dispatcher.go
index 45b2bd2..d5fd892 100644
--- a/services/mgmt/node/impl/dispatcher.go
+++ b/services/mgmt/node/impl/dispatcher.go
@@ -22,7 +22,6 @@
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mgmt/node"
"veyron.io/veyron/veyron2/services/mgmt/pprof"
@@ -88,7 +87,7 @@
)
// NewDispatcher is the node manager dispatcher factory.
-func NewDispatcher(config *config.State) (*dispatcher, error) {
+func NewDispatcher(principal security.Principal, config *config.State) (*dispatcher, error) {
if err := config.Validate(); err != nil {
return nil, fmt.Errorf("invalid config %v: %v", config, err)
}
@@ -121,7 +120,7 @@
}
defer sig.Close()
// read and verify the signature of the acl file
- reader, err := serialization.NewVerifyingReader(data, sig, rt.R().Principal().PublicKey())
+ reader, err := serialization.NewVerifyingReader(data, sig, principal.PublicKey())
if err != nil {
return nil, fmt.Errorf("failed to read nodemanager ACL file:%v", err)
}
@@ -129,7 +128,7 @@
if err != nil {
return nil, fmt.Errorf("failed to load nodemanager ACL:%v", err)
}
- if err := d.setACL(acl, d.etag, false /* just update etag */); err != nil {
+ if err := d.setACL(principal, acl, d.etag, false /* just update etag */); err != nil {
return nil, err
}
} else {
@@ -158,15 +157,15 @@
return
}
-func (d *dispatcher) claimNodeManager(names []string, proof security.Blessings) error {
+func (d *dispatcher) claimNodeManager(principal security.Principal, names []string, proof security.Blessings) error {
// TODO(gauthamt): Should we start trusting these identity providers?
// TODO(rjkroege): Scrub the state tree of installation and instance ACL files.
if len(names) == 0 {
vlog.Errorf("No names for claimer(%v) are trusted", proof)
return verror2.Make(ErrOperationFailed, nil)
}
- rt.R().Principal().BlessingStore().Set(proof, security.AllPrincipals)
- rt.R().Principal().BlessingStore().SetDefault(proof)
+ principal.BlessingStore().Set(proof, security.AllPrincipals)
+ principal.BlessingStore().SetDefault(proof)
// Create ACLs to transfer nodemanager permissions to the provided identity.
acl := make(access.TaggedACLMap)
for _, n := range names {
@@ -179,7 +178,7 @@
vlog.Errorf("Failed to getACL:%v", err)
return verror2.Make(ErrOperationFailed, nil)
}
- if err := d.setACL(acl, etag, true /* store ACL on disk */); err != nil {
+ if err := d.setACL(principal, acl, etag, true /* store ACL on disk */); err != nil {
vlog.Errorf("Failed to setACL:%v", err)
return verror2.Make(ErrOperationFailed, nil)
}
@@ -187,7 +186,7 @@
}
// TODO(rjkroege): Further refactor ACL-setting code.
-func setAppACL(locks aclLocks, dir string, acl access.TaggedACLMap, etag string) error {
+func setAppACL(principal security.Principal, locks aclLocks, dir string, acl access.TaggedACLMap, etag string) error {
aclpath := path.Join(dir, "acls", "data")
sigpath := path.Join(dir, "acls", "signature")
@@ -222,7 +221,7 @@
return verror.Make(access.ErrBadEtag, fmt.Sprintf("etag mismatch in:%s vers:%s", etag, curEtag))
}
- return writeACLs(aclpath, sigpath, dir, acl)
+ return writeACLs(principal, aclpath, sigpath, dir, acl)
}
func getAppACL(locks aclLocks, dir string) (access.TaggedACLMap, string, error) {
@@ -268,7 +267,7 @@
return etag, nil
}
-func writeACLs(aclFile, sigFile, dir string, acl access.TaggedACLMap) error {
+func writeACLs(principal security.Principal, aclFile, sigFile, dir string, acl access.TaggedACLMap) error {
// Create dir directory if it does not exist
os.MkdirAll(dir, os.FileMode(0700))
// Save the object to temporary data and signature files, and then move
@@ -285,7 +284,7 @@
return verror2.Make(ErrOperationFailed, nil)
}
defer os.Remove(sig.Name())
- writer, err := serialization.NewSigningWriteCloser(data, sig, rt.R().Principal(), nil)
+ writer, err := serialization.NewSigningWriteCloser(data, sig, principal, nil)
if err != nil {
vlog.Errorf("Failed to create NewSigningWriteCloser:%v", err)
return verror2.Make(ErrOperationFailed, nil)
@@ -307,7 +306,7 @@
return nil
}
-func (d *dispatcher) setACL(acl access.TaggedACLMap, etag string, writeToFile bool) error {
+func (d *dispatcher) setACL(principal security.Principal, acl access.TaggedACLMap, etag string, writeToFile bool) error {
d.mu.Lock()
defer d.mu.Unlock()
aclFile, sigFile, nodedata := d.getACLFilePaths()
@@ -316,7 +315,7 @@
return verror.Make(access.ErrBadEtag, fmt.Sprintf("etag mismatch in:%s vers:%s", etag, d.etag))
}
if writeToFile {
- if err := writeACLs(aclFile, sigFile, nodedata, acl); err != nil {
+ if err := writeACLs(principal, aclFile, sigFile, nodedata, acl); err != nil {
return err
}
}
@@ -395,7 +394,12 @@
}
suffix := naming.Join("__debug", naming.Join(components[4:]...))
remote := naming.JoinAddressName(info.AppCycleMgrName, suffix)
- return &proxyInvoker{remote, access.Debug, sigStub}, d.auth, nil
+ invoker := &proxyInvoker{
+ remote: remote,
+ access: access.Debug,
+ sigStub: sigStub,
+ }
+ return invoker, d.auth, nil
}
}
nodeACLs, _, err := d.getACL()
diff --git a/services/mgmt/node/impl/impl_test.go b/services/mgmt/node/impl/impl_test.go
index 334814b..03f9d49 100644
--- a/services/mgmt/node/impl/impl_test.go
+++ b/services/mgmt/node/impl/impl_test.go
@@ -28,6 +28,7 @@
"time"
"veyron.io/veyron/veyron2"
+ "veyron.io/veyron/veyron2/context"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
@@ -77,12 +78,18 @@
initRT()
}
+var globalRT veyron2.Runtime
+
func initRT() {
- rt.Init()
+ var err error
+ if globalRT, err = rt.New(); err != nil {
+ panic(err)
+ }
+
// Disable the cache because we will be manipulating/using the namespace
// across multiple processes and want predictable behaviour without
// relying on timeouts.
- rt.R().Namespace().CacheCtl(naming.DisableCache(true))
+ globalRT.Namespace().CacheCtl(naming.DisableCache(true))
}
// TestHelperProcess is the entrypoint for the modules commands in a
@@ -93,7 +100,7 @@
}
// TestSuidHelper is testing boilerplate for suidhelper that does not
-// invoke rt.Init() because the suidhelper is not a Veyron application.
+// create a runtime because the suidhelper is not a Veyron application.
func TestSuidHelper(t *testing.T) {
if os.Getenv("VEYRON_SUIDHELPER_TEST") != "1" {
return
@@ -138,10 +145,9 @@
}
publishName := args[0]
args = args[1:]
-
defer fmt.Fprintf(stdout, "%v terminating\n", publishName)
defer vlog.VI(1).Infof("%v terminating", publishName)
- defer rt.R().Cleanup()
+ defer globalRT.Cleanup()
server, endpoint := newServer()
defer server.Stop()
name := naming.JoinAddressName(endpoint, "")
@@ -164,18 +170,18 @@
}
configState.Root, configState.Helper, configState.Origin, configState.CurrentLink = args[0], args[1], args[2], args[3]
}
- dispatcher, err := impl.NewDispatcher(configState)
+ dispatcher, err := impl.NewDispatcher(globalRT.Principal(), configState)
if err != nil {
vlog.Fatalf("Failed to create node manager dispatcher: %v", err)
}
if err := server.ServeDispatcher(publishName, dispatcher); err != nil {
vlog.Fatalf("Serve(%v) failed: %v", publishName, err)
}
- impl.InvokeCallback(name)
+ impl.InvokeCallback(globalRT.NewContext(), name)
fmt.Fprintf(stdout, "ready:%d\n", os.Getpid())
- <-signals.ShutdownOnSignals(rt.R())
+ <-signals.ShutdownOnSignals(globalRT)
if val, present := env["PAUSE_BEFORE_STOP"]; present && val == "1" {
modules.WaitForEOF(stdin)
@@ -228,7 +234,7 @@
}
func ping() {
- if call, err := rt.R().Client().StartCall(rt.R().NewContext(), "pingserver", "Ping", []interface{}{os.Getenv(suidhelper.SavedArgs)}); err != nil {
+ if call, err := globalRT.Client().StartCall(globalRT.NewContext(), "pingserver", "Ping", []interface{}{os.Getenv(suidhelper.SavedArgs)}); err != nil {
vlog.Fatalf("StartCall failed: %v", err)
} else if err := call.Finish(); err != nil {
vlog.Fatalf("Finish failed: %v", err)
@@ -236,10 +242,9 @@
}
func cat(name, file string) (string, error) {
- runtime := rt.R()
- ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
+ ctx, cancel := globalRT.NewContext().WithTimeout(time.Minute)
defer cancel()
- call, err := runtime.Client().StartCall(ctx, name, "Cat", []interface{}{file})
+ call, err := globalRT.Client().StartCall(ctx, name, "Cat", []interface{}{file})
if err != nil {
return "", err
}
@@ -257,7 +262,7 @@
}
publishName := args[0]
- defer rt.R().Cleanup()
+ defer globalRT.Cleanup()
server, _ := newServer()
defer server.Stop()
if err := server.Serve(publishName, new(appService), nil); err != nil {
@@ -268,7 +273,7 @@
vlog.FlushLog()
ping()
- <-signals.ShutdownOnSignals(rt.R())
+ <-signals.ShutdownOnSignals(globalRT)
if err := ioutil.WriteFile("testfile", []byte("goodbye world"), 0600); err != nil {
vlog.Fatalf("Failed to write testfile: %v", err)
}
@@ -726,14 +731,14 @@
if err != nil {
t.Fatalf("rt.New() failed: %v", err)
}
- runtime.Namespace().SetRoots(rt.R().Namespace().Roots()[0])
+ runtime.Namespace().SetRoots(globalRT.Namespace().Roots()[0])
return runtime
}
-func tryInstall(rt veyron2.Runtime) error {
+func tryInstall(ctx context.T) error {
appsName := "nm//apps"
- stub := node.ApplicationClient(appsName, rt.Client())
- if _, err := stub.Install(rt.NewContext(), mockApplicationRepoName); err != nil {
+ stub := node.ApplicationClient(appsName)
+ if _, err := stub.Install(ctx, mockApplicationRepoName); err != nil {
return fmt.Errorf("Install failed: %v", err)
}
return nil
@@ -762,7 +767,7 @@
if err := ioutil.WriteFile(filepath.Join(tmpdir, "hello.txt"), []byte("Hello World!"), 0600); err != nil {
t.Fatalf("ioutil.WriteFile failed: %v", err)
}
- if err := libbinary.UploadFromDir(rt.R().NewContext(), naming.Join(name, "testpkg"), tmpdir); err != nil {
+ if err := libbinary.UploadFromDir(globalRT.NewContext(), naming.Join(name, "testpkg"), tmpdir); err != nil {
t.Fatalf("libbinary.UploadFromDir failed: %v", err)
}
return func() {
@@ -802,25 +807,27 @@
*envelope = envelopeFromShell(sh, nil, appCmd, "google naps", "trapp")
nodeStub := node.NodeClient("nm//nm")
- selfRT := rt.R()
+ selfRT := globalRT
otherRT := newRuntime(t)
defer otherRT.Cleanup()
+ octx := otherRT.NewContext()
+
// Nodemanager should have open ACLs before we claim it and so an Install from otherRT should succeed.
- if err := tryInstall(otherRT); err != nil {
- t.Fatal(err)
+ if err := tryInstall(octx); err != nil {
+ t.Fatalf("Failed to install: %s", err)
}
// Claim the nodemanager with selfRT as <defaultblessing>/mydevice
if err := nodeStub.Claim(selfRT.NewContext(), &granter{p: selfRT.Principal(), extension: "mydevice"}); err != nil {
t.Fatal(err)
}
- // Installation should succeed since rt.R() (a.k.a. selfRT) is now the
+ // Installation should succeed since globalRT (a.k.a. selfRT) is now the
// "owner" of the nodemanager.
appID := installApp(t)
// otherRT should be unable to install though, since the ACLs have changed now.
- if err := tryInstall(otherRT); err == nil {
+ if err := tryInstall(octx); err == nil {
t.Fatalf("Install should have failed from otherRT")
}
@@ -858,10 +865,11 @@
idp = tsecurity.NewIDProvider("root")
// The two "processes"/runtimes which will act as IPC clients to the
// nodemanager process.
- selfRT = rt.R()
+ selfRT = globalRT
otherRT = newRuntime(t)
)
defer otherRT.Cleanup()
+ octx := otherRT.NewContext()
// By default, selfRT and otherRT will have blessings generated based on the
// username/machine name running this process. Since these blessings will appear
// in ACLs, give them recognizable names.
@@ -914,7 +922,7 @@
t.Fatalf("getACL expected:%v(%v), got:%v(%v)", expectedACL, expectedETAG, acl, etag)
}
// Install from otherRT should fail, since it does not match the ACL.
- if err := tryInstall(otherRT); err == nil {
+ if err := tryInstall(octx); err == nil {
t.Fatalf("Install should have failed with random identity")
}
newACL := make(access.TaggedACLMap)
@@ -928,10 +936,10 @@
t.Fatal(err)
}
// Install should now fail with selfRT, which no longer matches the ACLs but succeed with otherRT, which does.
- if err := tryInstall(selfRT); err == nil {
+ if err := tryInstall(selfRT.NewContext()); err == nil {
t.Errorf("Install should have failed with selfRT since it should no longer match the ACL")
}
- if err := tryInstall(otherRT); err != nil {
+ if err := tryInstall(octx); err != nil {
t.Error(err)
}
}
@@ -1077,7 +1085,7 @@
logFileRemoveErrorFatalWarningRE := regexp.MustCompile("(ERROR|FATAL|WARNING)")
statsTrimRE := regexp.MustCompile("/stats/(ipc|system(/start-time.*)?)$")
for _, tc := range testcases {
- results, err := testutil.GlobName(rt.R().NewContext(), tc.name, tc.pattern)
+ results, err := testutil.GlobName(globalRT.NewContext(), tc.name, tc.pattern)
if err != nil {
t.Errorf("unexpected glob error for (%q, %q): %v", tc.name, tc.pattern, err)
continue
@@ -1105,7 +1113,7 @@
}
// Call Size() on the log file objects.
- files, err := testutil.GlobName(rt.R().NewContext(), "nm", "apps/google naps/"+installID+"/"+instance1ID+"/logs/*")
+ files, err := testutil.GlobName(globalRT.NewContext(), "nm", "apps/google naps/"+installID+"/"+instance1ID+"/logs/*")
if err != nil {
t.Errorf("unexpected glob error: %v", err)
}
@@ -1115,13 +1123,13 @@
for _, file := range files {
name := naming.Join("nm", file)
c := logreader.LogFileClient(name)
- if _, err := c.Size(rt.R().NewContext()); err != nil {
+ if _, err := c.Size(globalRT.NewContext()); err != nil {
t.Errorf("Size(%q) failed: %v", name, err)
}
}
// Call Value() on some of the stats objects.
- objects, err := testutil.GlobName(rt.R().NewContext(), "nm", "apps/google naps/"+installID+"/"+instance1ID+"/stats/system/start-time*")
+ objects, err := testutil.GlobName(globalRT.NewContext(), "nm", "apps/google naps/"+installID+"/"+instance1ID+"/stats/system/start-time*")
if err != nil {
t.Errorf("unexpected glob error: %v", err)
}
@@ -1131,7 +1139,7 @@
for _, obj := range objects {
name := naming.Join("nm", obj)
c := stats.StatsClient(name)
- if _, err := c.Value(rt.R().NewContext()); err != nil {
+ if _, err := c.Value(globalRT.NewContext()); err != nil {
t.Errorf("Value(%q) failed: %v", name, err)
}
}
@@ -1140,7 +1148,7 @@
{
name := "nm/apps/google naps/" + installID + "/" + instance1ID + "/pprof"
c := pprof.PProfClient(name)
- v, err := c.CmdLine(rt.R().NewContext())
+ v, err := c.CmdLine(globalRT.NewContext())
if err != nil {
t.Errorf("CmdLine(%q) failed: %v", name, err)
}
@@ -1234,7 +1242,7 @@
idp = tsecurity.NewIDProvider("root")
// The two "processes"/runtimes which will act as IPC clients to
// the nodemanager process.
- selfRT = rt.R()
+ selfRT = globalRT
otherRT = newRuntime(t)
)
defer otherRT.Cleanup()
@@ -1338,7 +1346,7 @@
idp = tsecurity.NewIDProvider("root")
// The two "processes"/runtimes which will act as IPC clients to
// the nodemanager process.
- selfRT = rt.R()
+ selfRT = globalRT
otherRT = newRuntime(t)
)
defer otherRT.Cleanup()
diff --git a/services/mgmt/node/impl/node_service.go b/services/mgmt/node/impl/node_service.go
index e99b5b3..6d0f12d 100644
--- a/services/mgmt/node/impl/node_service.go
+++ b/services/mgmt/node/impl/node_service.go
@@ -38,11 +38,11 @@
"sync"
"time"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/context"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/mgmt"
"veyron.io/veyron/veyron2/naming"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/application"
"veyron.io/veyron/veyron2/services/mgmt/binary"
"veyron.io/veyron/veyron2/services/mgmt/node"
@@ -100,7 +100,7 @@
if blessings == nil {
return verror2.Make(ErrInvalidBlessing, call)
}
- return i.disp.claimNodeManager(blessings.ForContext(call), blessings)
+ return i.disp.claimNodeManager(call.LocalPrincipal(), blessings.ForContext(call), blessings)
}
func (*nodeService) Describe(ipc.ServerContext) (node.Description, error) {
@@ -156,11 +156,12 @@
return link, scriptPath, nil
}
-func (i *nodeService) revertNodeManager() error {
+func (i *nodeService) revertNodeManager(ctx context.T) error {
if err := updateLink(i.config.Previous, i.config.CurrentLink); err != nil {
return err
}
- rt.R().AppCycle().Stop()
+ runtime := veyron2.RuntimeFromContext(ctx)
+ runtime.AppCycle().Stop()
return nil
}
@@ -338,7 +339,7 @@
return err
}
} else {
- if err := downloadBinary(workspace, "noded", envelope.Binary); err != nil {
+ if err := downloadBinary(ctx, workspace, "noded", envelope.Binary); err != nil {
return err
}
}
@@ -361,7 +362,8 @@
return err
}
- rt.R().AppCycle().Stop()
+ runtime := veyron2.RuntimeFromContext(ctx)
+ runtime.AppCycle().Stop()
deferrer = nil
return nil
}
@@ -392,7 +394,7 @@
if updatingState.testAndSetUpdating() {
return verror2.Make(ErrOperationInProgress, call)
}
- err := i.revertNodeManager()
+ err := i.revertNodeManager(call)
if err != nil {
updatingState.unsetUpdating()
}
@@ -417,7 +419,7 @@
}
func (i *nodeService) Update(call ipc.ServerContext) error {
- ctx, cancel := rt.R().NewContext().WithTimeout(ipcContextTimeout)
+ ctx, cancel := call.WithTimeout(ipcContextTimeout)
defer cancel()
updatingState := i.updating
@@ -437,8 +439,8 @@
return nil
}
-func (i *nodeService) SetACL(_ ipc.ServerContext, acl access.TaggedACLMap, etag string) error {
- return i.disp.setACL(acl, etag, true /* store ACL on disk */)
+func (i *nodeService) SetACL(ctx ipc.ServerContext, acl access.TaggedACLMap, etag string) error {
+ return i.disp.setACL(ctx.LocalPrincipal(), acl, etag, true /* store ACL on disk */)
}
func (i *nodeService) GetACL(_ ipc.ServerContext) (acl access.TaggedACLMap, etag string, err error) {
diff --git a/services/mgmt/node/impl/proxy_invoker.go b/services/mgmt/node/impl/proxy_invoker.go
index 0f87e7e..6ee62ae 100644
--- a/services/mgmt/node/impl/proxy_invoker.go
+++ b/services/mgmt/node/impl/proxy_invoker.go
@@ -4,9 +4,9 @@
"fmt"
"io"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/security/access"
"veyron.io/veyron/veyron2/vdl/vdlroot/src/signature"
)
@@ -47,7 +47,8 @@
for i, ap := range argptrs {
args[i] = ap
}
- outCall, err := rt.R().Client().StartCall(inCall, p.remote, method, args)
+ runtime := veyron2.RuntimeFromContext(inCall)
+ outCall, err := runtime.Client().StartCall(inCall, p.remote, method, args)
if err != nil {
return nil, err
}
diff --git a/services/mgmt/node/impl/proxy_invoker_test.go b/services/mgmt/node/impl/proxy_invoker_test.go
index 813e868..e1caf15 100644
--- a/services/mgmt/node/impl/proxy_invoker_test.go
+++ b/services/mgmt/node/impl/proxy_invoker_test.go
@@ -4,6 +4,7 @@
"reflect"
"testing"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
@@ -17,10 +18,14 @@
// TODO(toddw): Add tests of Signature and MethodSignature.
func TestProxyInvoker(t *testing.T) {
- r := rt.R()
+ runtime, err := rt.New()
+ if err != nil {
+ t.Fatalf("Could not initialize runtime: %v", err)
+ }
+ defer runtime.Cleanup()
// server1 is a normal server
- server1, err := r.NewServer()
+ server1, err := runtime.NewServer()
if err != nil {
t.Fatalf("NewServer: %v", err)
}
@@ -35,7 +40,7 @@
}
// server2 proxies requests to <suffix> to server1/__debug/stats/<suffix>
- server2, err := r.NewServer()
+ server2, err := runtime.NewServer()
if err != nil {
t.Fatalf("NewServer: %v", err)
}
@@ -45,6 +50,7 @@
t.Fatalf("Listen: %v", err)
}
disp := &proxyDispatcher{
+ runtime,
naming.JoinAddressName(ep1.String(), "__debug/stats"),
stats.StatsServer(nil),
}
@@ -55,12 +61,12 @@
// Call Value()
name := naming.JoinAddressName(ep2.String(), "system/start-time-rfc1123")
c := stats.StatsClient(name)
- if _, err := c.Value(r.NewContext()); err != nil {
+ if _, err := c.Value(runtime.NewContext()); err != nil {
t.Errorf("%q.Value() error: %v", name, err)
}
// Call Glob()
- results, err := testutil.GlobName(r.NewContext(), naming.JoinAddressName(ep2.String(), "system"), "start-time-*")
+ results, err := testutil.GlobName(runtime.NewContext(), naming.JoinAddressName(ep2.String(), "system"), "start-time-*")
if err != nil {
t.Fatalf("Glob failed: %v", err)
}
@@ -78,10 +84,16 @@
func (*dummy) Method(_ ipc.ServerContext) error { return nil }
type proxyDispatcher struct {
+ runtime veyron2.Runtime
remote string
sigStub signatureStub
}
func (d *proxyDispatcher) Lookup(suffix string) (interface{}, security.Authorizer, error) {
- return &proxyInvoker{naming.Join(d.remote, suffix), access.Debug, d.sigStub}, nil, nil
+ invoker := &proxyInvoker{
+ remote: naming.Join(d.remote, suffix),
+ access: access.Debug,
+ sigStub: d.sigStub,
+ }
+ return invoker, nil, nil
}
diff --git a/services/mgmt/node/impl/util.go b/services/mgmt/node/impl/util.go
index f700552..c3c2bdc 100644
--- a/services/mgmt/node/impl/util.go
+++ b/services/mgmt/node/impl/util.go
@@ -10,7 +10,6 @@
"veyron.io/veyron/veyron/services/mgmt/lib/binary"
"veyron.io/veyron/veyron2/context"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/application"
"veyron.io/veyron/veyron2/services/mgmt/repository"
"veyron.io/veyron/veyron2/verror2"
@@ -23,8 +22,8 @@
ipcContextTimeout = time.Minute
)
-func downloadBinary(workspace, fileName, name string) error {
- data, _, err := binary.Download(rt.R().NewContext(), name)
+func downloadBinary(ctx context.T, workspace, fileName, name string) error {
+ data, _, err := binary.Download(ctx, name)
if err != nil {
vlog.Errorf("Download(%v) failed: %v", name, err)
return verror2.Make(ErrOperationFailed, nil)
diff --git a/services/mgmt/node/impl/util_test.go b/services/mgmt/node/impl/util_test.go
index de14eb0..1c19f37 100644
--- a/services/mgmt/node/impl/util_test.go
+++ b/services/mgmt/node/impl/util_test.go
@@ -15,7 +15,6 @@
"veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mgmt/node"
"veyron.io/veyron/veyron2/verror"
@@ -62,13 +61,13 @@
}
func credentialsForChild(blessing string) (string, []string) {
- creds := tsecurity.NewVeyronCredentials(rt.R().Principal(), blessing)
+ creds := tsecurity.NewVeyronCredentials(globalRT.Principal(), blessing)
return creds, []string{consts.VeyronCredentials + "=" + creds}
}
// setNSRoots sets the roots for the local runtime's namespace.
func setNSRoots(t *testing.T, roots ...string) {
- if err := rt.R().Namespace().SetRoots(roots...); err != nil {
+ if err := globalRT.Namespace().SetRoots(roots...); err != nil {
t.Fatalf("%s: SetRoots(%v) failed with %v", loc(2), roots, err)
}
}
@@ -90,7 +89,7 @@
// TODO(caprita): Define a GetNamespaceRootsCommand in modules/core and
// use that?
- oldNamespaceRoots := rt.R().Namespace().Roots()
+ oldNamespaceRoots := globalRT.Namespace().Roots()
fn := func() {
vlog.VI(1).Info("------------ CLEANUP ------------")
vlog.VI(1).Info("---------------------------------")
@@ -159,7 +158,7 @@
}
func newServer() (ipc.Server, string) {
- server, err := rt.R().NewServer()
+ server, err := globalRT.NewServer()
if err != nil {
vlog.Fatalf("NewServer() failed: %v", err)
}
@@ -174,7 +173,7 @@
// resolveExpectError verifies that the given name is not in the mounttable.
func resolveExpectNotFound(t *testing.T, name string) {
- if results, err := rt.R().Namespace().Resolve(rt.R().NewContext(), name); err == nil {
+ if results, err := globalRT.Namespace().Resolve(globalRT.NewContext(), name); err == nil {
t.Fatalf("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("Resolve(%v) failed with error %v, expected error ID %v", name, err, expectErr)
@@ -183,7 +182,7 @@
// resolve looks up the given name in the mounttable.
func resolve(t *testing.T, name string, replicas int) []string {
- results, err := rt.R().Namespace().Resolve(rt.R().NewContext(), name)
+ results, err := globalRT.Namespace().Resolve(globalRT.NewContext(), name)
if err != nil {
t.Fatalf("Resolve(%v) failed: %v", name, err)
}
@@ -210,25 +209,25 @@
}
func updateNodeExpectError(t *testing.T, name string, errID verror.ID) {
- if err := nodeStub(name).Update(rt.R().NewContext()); !verror2.Is(err, errID) {
+ if err := nodeStub(name).Update(globalRT.NewContext()); !verror2.Is(err, errID) {
t.Fatalf("%s: Update(%v) expected to fail with %v, got %v instead", loc(1), name, errID, err)
}
}
func updateNode(t *testing.T, name string) {
- if err := nodeStub(name).Update(rt.R().NewContext()); err != nil {
+ if err := nodeStub(name).Update(globalRT.NewContext()); err != nil {
t.Fatalf("%s: Update(%v) failed: %v", loc(1), name, err)
}
}
func revertNodeExpectError(t *testing.T, name string, errID verror.ID) {
- if err := nodeStub(name).Revert(rt.R().NewContext()); !verror2.Is(err, errID) {
+ if err := nodeStub(name).Revert(globalRT.NewContext()); !verror2.Is(err, errID) {
t.Fatalf("%s: Revert(%v) expected to fail with %v, got %v instead", loc(1), name, errID, err)
}
}
func revertNode(t *testing.T, name string) {
- if err := nodeStub(name).Revert(rt.R().NewContext()); err != nil {
+ if err := nodeStub(name).Revert(globalRT.NewContext()); err != nil {
t.Fatalf("%s: Revert(%v) failed: %v", loc(1), name, err)
}
}
@@ -240,7 +239,7 @@
if len(opt) > 0 {
return opt[0]
} else {
- return rt.R()
+ return globalRT
}
}
@@ -328,25 +327,25 @@
}
func updateAppExpectError(t *testing.T, appID string, expectedError verror.ID) {
- if err := appStub(appID).Update(rt.R().NewContext()); err == nil || !verror2.Is(err, expectedError) {
+ if err := appStub(appID).Update(globalRT.NewContext()); err == nil || !verror2.Is(err, expectedError) {
t.Fatalf("%s: Update(%v) expected to fail with %v, got %v instead", loc(1), appID, expectedError, err)
}
}
func revertApp(t *testing.T, appID string) {
- if err := appStub(appID).Revert(rt.R().NewContext()); err != nil {
+ if err := appStub(appID).Revert(globalRT.NewContext()); err != nil {
t.Fatalf("%s: Revert(%v) failed: %v", loc(1), appID, err)
}
}
func revertAppExpectError(t *testing.T, appID string, expectedError verror.ID) {
- if err := appStub(appID).Revert(rt.R().NewContext()); err == nil || !verror2.Is(err, expectedError) {
+ if err := appStub(appID).Revert(globalRT.NewContext()); err == nil || !verror2.Is(err, expectedError) {
t.Fatalf("%s: Revert(%v) expected to fail with %v, got %v instead", loc(1), appID, expectedError, err)
}
}
func uninstallApp(t *testing.T, appID string) {
- if err := appStub(appID).Uninstall(rt.R().NewContext()); err != nil {
+ if err := appStub(appID).Uninstall(globalRT.NewContext()); err != nil {
t.Fatalf("%s: Uninstall(%v) failed: %v", loc(1), appID, err)
}
}
diff --git a/services/mgmt/node/noded/main.go b/services/mgmt/node/noded/main.go
index c40f2a9..f384663 100644
--- a/services/mgmt/node/noded/main.go
+++ b/services/mgmt/node/noded/main.go
@@ -22,7 +22,10 @@
func main() {
flag.Parse()
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ vlog.Fatalf("Could not initialize runtime: %v", err)
+ }
defer runtime.Cleanup()
if len(*installFrom) > 0 {
@@ -65,7 +68,7 @@
// TODO(caprita): We need a way to set config fields outside of the
// update mechanism (since that should ideally be an opaque
// implementation detail).
- dispatcher, err := impl.NewDispatcher(configState)
+ dispatcher, err := impl.NewDispatcher(runtime.Principal(), configState)
if err != nil {
vlog.Fatalf("Failed to create dispatcher: %v", err)
}
@@ -73,7 +76,7 @@
vlog.Fatalf("Serve(%v) failed: %v", *publishAs, err)
}
vlog.VI(0).Infof("Node manager published as: %v", *publishAs)
- impl.InvokeCallback(name)
+ impl.InvokeCallback(runtime.NewContext(), name)
// Wait until shutdown.
<-signals.ShutdownOnSignals(runtime)
diff --git a/services/mgmt/pprof/client/proxy_test.go b/services/mgmt/pprof/client/proxy_test.go
index bce0e99..2afeb05 100644
--- a/services/mgmt/pprof/client/proxy_test.go
+++ b/services/mgmt/pprof/client/proxy_test.go
@@ -24,7 +24,10 @@
}
func TestPProfProxy(t *testing.T) {
- r := rt.Init()
+ r, err := rt.New()
+ if err != nil {
+ t.Fatalf("Could not initialize runtime: %v", err)
+ }
defer r.Cleanup()
s, err := r.NewServer()
diff --git a/services/mgmt/profile/impl/impl_test.go b/services/mgmt/profile/impl/impl_test.go
index d0a4521..1de68d0 100644
--- a/services/mgmt/profile/impl/impl_test.go
+++ b/services/mgmt/profile/impl/impl_test.go
@@ -6,6 +6,7 @@
"reflect"
"testing"
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/build"
@@ -30,7 +31,6 @@
// TestInterface tests that the implementation correctly implements
// the Profile interface.
func TestInterface(t *testing.T) {
- runtime := rt.R()
ctx := runtime.NewContext()
// Setup and start the profile repository server.
@@ -104,12 +104,16 @@
}
}
+var runtime veyron2.Runtime
+
func init() {
- rt.Init()
+ var err error
+ if runtime, err = rt.New(); err != nil {
+ panic(err)
+ }
}
func TestPreserveAcrossRestarts(t *testing.T) {
- runtime := rt.R()
ctx := runtime.NewContext()
// Setup and start the profile repository server.
diff --git a/services/mgmt/profile/profiled/main.go b/services/mgmt/profile/profiled/main.go
index a811f12..bc07035 100644
--- a/services/mgmt/profile/profiled/main.go
+++ b/services/mgmt/profile/profiled/main.go
@@ -22,7 +22,10 @@
if *store == "" {
vlog.Fatalf("Specify a directory for storing profiles using --store=<name>")
}
- runtime := rt.Init()
+ runtime, err := rt.New()
+ if err != nil {
+ vlog.Fatalf("Could not initialize runtime: %v", err)
+ }
defer runtime.Cleanup()
server, err := runtime.NewServer()
if err != nil {
diff --git a/services/mgmt/root/rootd/main.go b/services/mgmt/root/rootd/main.go
index 45f9205..4688bdc 100644
--- a/services/mgmt/root/rootd/main.go
+++ b/services/mgmt/root/rootd/main.go
@@ -10,7 +10,10 @@
)
func main() {
- r := rt.Init()
+ r, err := rt.New()
+ if err != nil {
+ vlog.Fatalf("Could not initialize runtime: %v", err)
+ }
defer r.Cleanup()
server, err := r.NewServer()
if err != nil {
diff --git a/tools/mgmt/nodex/acl_impl.go b/tools/mgmt/nodex/acl_impl.go
index e9d2f7c..7296702 100644
--- a/tools/mgmt/nodex/acl_impl.go
+++ b/tools/mgmt/nodex/acl_impl.go
@@ -6,7 +6,6 @@
"fmt"
"veyron.io/lib/cmdline"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mgmt/node"
"veyron.io/veyron/veyron2/services/security/access"
@@ -30,7 +29,7 @@
}
vanaName := args[0]
- objACL, _, err := node.ApplicationClient(vanaName).GetACL(rt.R().NewContext())
+ objACL, _, err := node.ApplicationClient(vanaName).GetACL(runtime.NewContext())
if err != nil {
return fmt.Errorf("GetACL on %s failed: %v", vanaName, err)
}
@@ -96,8 +95,9 @@
}
// Set the ACLs on the specified names.
+ ctx := runtime.NewContext()
for {
- objACL, etag, err := node.ApplicationClient(vanaName).GetACL(rt.R().NewContext())
+ objACL, etag, err := node.ApplicationClient(vanaName).GetACL(ctx)
if err != nil {
return cmd.UsageErrorf("GetACL(%s) failed: %v", vanaName, err)
}
@@ -111,7 +111,7 @@
}
}
}
- switch err := node.ApplicationClient(vanaName).SetACL(rt.R().NewContext(), objACL, etag); {
+ switch err := node.ApplicationClient(vanaName).SetACL(ctx, objACL, etag); {
case err != nil && !verror.Is(err, access.ErrBadEtag):
return cmd.UsageErrorf("SetACL(%s) failed: %v", vanaName, err)
case err == nil:
diff --git a/tools/mgmt/nodex/acl_test.go b/tools/mgmt/nodex/acl_test.go
index 25aec7e..2cb3b96 100644
--- a/tools/mgmt/nodex/acl_test.go
+++ b/tools/mgmt/nodex/acl_test.go
@@ -9,14 +9,12 @@
"testing"
"veyron.io/veyron/veyron2/naming"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/security/access"
"veyron.io/veyron/veyron2/verror"
)
func TestACLGetCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
@@ -63,7 +61,6 @@
}
func TestACLSetCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
diff --git a/tools/mgmt/nodex/associate_impl.go b/tools/mgmt/nodex/associate_impl.go
index 342c35f..0b529f1 100644
--- a/tools/mgmt/nodex/associate_impl.go
+++ b/tools/mgmt/nodex/associate_impl.go
@@ -5,7 +5,6 @@
"time"
"veyron.io/lib/cmdline"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/node"
)
@@ -24,7 +23,7 @@
return cmd.UsageErrorf("list: incorrect number of arguments, expected %d, got %d", expected, got)
}
- ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+ ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
defer cancel()
assocs, err := node.NodeClient(args[0]).ListAssociations(ctx)
if err != nil {
@@ -53,7 +52,7 @@
if expected, got := 3, len(args); got < expected {
return cmd.UsageErrorf("add: incorrect number of arguments, expected at least %d, got %d", expected, got)
}
- ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+ ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
defer cancel()
return node.NodeClient(args[0]).AssociateAccount(ctx, args[2:], args[1])
}
@@ -73,7 +72,7 @@
if expected, got := 2, len(args); got < expected {
return cmd.UsageErrorf("remove: incorrect number of arguments, expected at least %d, got %d", expected, got)
}
- ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+ ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
defer cancel()
return node.NodeClient(args[0]).AssociateAccount(ctx, args[1:], "")
}
diff --git a/tools/mgmt/nodex/impl.go b/tools/mgmt/nodex/impl.go
index 3507e12..c6112f1 100644
--- a/tools/mgmt/nodex/impl.go
+++ b/tools/mgmt/nodex/impl.go
@@ -6,7 +6,6 @@
"veyron.io/lib/cmdline"
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mgmt/node"
)
@@ -27,7 +26,7 @@
return cmd.UsageErrorf("install: incorrect number of arguments, expected %d, got %d", expected, got)
}
nodeName, appName := args[0], args[1]
- appID, err := node.ApplicationClient(nodeName).Install(rt.R().NewContext(), appName)
+ appID, err := node.ApplicationClient(nodeName).Install(runtime.NewContext(), appName)
if err != nil {
return fmt.Errorf("Install failed: %v", err)
}
@@ -64,7 +63,7 @@
return cmd.UsageErrorf("start: incorrect number of arguments, expected %d, got %d", expected, got)
}
appInstallation, grant := args[0], args[1]
- appInstanceIDs, err := node.ApplicationClient(appInstallation).Start(rt.R().NewContext(), &granter{p: rt.R().Principal(), extension: grant})
+ appInstanceIDs, err := node.ApplicationClient(appInstallation).Start(runtime.NewContext(), &granter{p: runtime.Principal(), extension: grant})
if err != nil {
return fmt.Errorf("Start failed: %v", err)
}
@@ -92,7 +91,7 @@
return cmd.UsageErrorf("claim: incorrect number of arguments, expected %d, got %d", expected, got)
}
nodeName, grant := args[0], args[1]
- if err := node.NodeClient(nodeName).Claim(rt.R().NewContext(), &granter{p: rt.R().Principal(), extension: grant}); err != nil {
+ if err := node.NodeClient(nodeName).Claim(runtime.NewContext(), &granter{p: runtime.Principal(), extension: grant}); err != nil {
return fmt.Errorf("Claim failed: %v", err)
}
fmt.Fprintln(cmd.Stdout(), "Successfully claimed.")
diff --git a/tools/mgmt/nodex/impl_test.go b/tools/mgmt/nodex/impl_test.go
index 114954a..75107a3 100644
--- a/tools/mgmt/nodex/impl_test.go
+++ b/tools/mgmt/nodex/impl_test.go
@@ -13,8 +13,14 @@
"veyron.io/veyron/veyron2/verror"
)
+func init() {
+ var err error
+ if runtime, err = rt.New(); err != nil {
+ panic(err)
+ }
+}
+
func TestListCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
@@ -67,7 +73,6 @@
}
func TestAddCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
@@ -118,7 +123,6 @@
}
func TestRemoveCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
@@ -156,7 +160,6 @@
}
func TestInstallCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
@@ -213,7 +216,6 @@
}
func TestClaimCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
@@ -291,7 +293,6 @@
}
func TestStartCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
diff --git a/tools/mgmt/nodex/instance_impl.go b/tools/mgmt/nodex/instance_impl.go
index f328193..f419c22 100644
--- a/tools/mgmt/nodex/instance_impl.go
+++ b/tools/mgmt/nodex/instance_impl.go
@@ -6,7 +6,6 @@
"fmt"
"veyron.io/lib/cmdline"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/services/mgmt/node"
)
@@ -26,7 +25,7 @@
}
appName := args[0]
- if err := node.ApplicationClient(appName).Stop(rt.R().NewContext(), 5); err != nil {
+ if err := node.ApplicationClient(appName).Stop(runtime.NewContext(), 5); err != nil {
return fmt.Errorf("Stop failed: %v", err)
}
fmt.Fprintf(cmd.Stdout(), "Stop succeeded\n")
@@ -49,7 +48,7 @@
}
appName := args[0]
- if err := node.ApplicationClient(appName).Suspend(rt.R().NewContext()); err != nil {
+ if err := node.ApplicationClient(appName).Suspend(runtime.NewContext()); err != nil {
return fmt.Errorf("Suspend failed: %v", err)
}
fmt.Fprintf(cmd.Stdout(), "Suspend succeeded\n")
@@ -72,7 +71,7 @@
}
appName := args[0]
- if err := node.ApplicationClient(appName).Resume(rt.R().NewContext()); err != nil {
+ if err := node.ApplicationClient(appName).Resume(runtime.NewContext()); err != nil {
return fmt.Errorf("Resume failed: %v", err)
}
fmt.Fprintf(cmd.Stdout(), "Resume succeeded\n")
diff --git a/tools/mgmt/nodex/instance_impl_test.go b/tools/mgmt/nodex/instance_impl_test.go
index be880ea..493ffe5 100644
--- a/tools/mgmt/nodex/instance_impl_test.go
+++ b/tools/mgmt/nodex/instance_impl_test.go
@@ -7,12 +7,10 @@
"testing"
"veyron.io/veyron/veyron2/naming"
- "veyron.io/veyron/veyron2/rt"
"veyron.io/veyron/veyron2/verror"
)
func TestStopCommand(t *testing.T) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
@@ -85,7 +83,6 @@
}
func testHelper(t *testing.T, lower, upper string) {
- runtime := rt.Init()
tape := NewTape()
server, endpoint, err := startServer(t, runtime, tape)
if err != nil {
diff --git a/tools/mgmt/nodex/main.go b/tools/mgmt/nodex/main.go
index b0e270d..d82e3d7 100644
--- a/tools/mgmt/nodex/main.go
+++ b/tools/mgmt/nodex/main.go
@@ -4,12 +4,19 @@
package main
import (
+ "veyron.io/veyron/veyron2"
"veyron.io/veyron/veyron2/rt"
_ "veyron.io/veyron/veyron/profiles"
)
+var runtime veyron2.Runtime
+
func main() {
- defer rt.Init().Cleanup()
+ var err error
+ if runtime, err = rt.New(); err != nil {
+ panic(err)
+ }
+ defer runtime.Cleanup()
root().Main()
}