veyron/mgmt/lib/exec: move this into veyron/lib/exec and merge veyron/lib/config with it.

Change-Id: I8c5b2d1f1a4a9d3c48b6e76e1fe5e43c93416c0d
diff --git a/services/mgmt/lib/exec/child.go b/lib/exec/child.go
similarity index 97%
rename from services/mgmt/lib/exec/child.go
rename to lib/exec/child.go
index 909c6e9..72055e4 100644
--- a/services/mgmt/lib/exec/child.go
+++ b/lib/exec/child.go
@@ -6,8 +6,6 @@
 	"io"
 	"os"
 	"sync"
-
-	"veyron.io/veyron/veyron/lib/config"
 )
 
 var (
@@ -17,7 +15,7 @@
 
 type ChildHandle struct {
 	// Config is passed down from the parent.
-	Config config.Config
+	Config Config
 	// Secret is a secret passed to the child by its parent via a
 	// trusted channel.
 	Secret string
@@ -86,7 +84,7 @@
 	if err != nil {
 		return nil, err
 	}
-	cfg := config.New()
+	cfg := NewConfig()
 	if err := cfg.MergeFrom(serializedConfig); err != nil {
 		return nil, err
 	}
diff --git a/lib/config/config.go b/lib/exec/config.go
similarity index 94%
rename from lib/config/config.go
rename to lib/exec/config.go
index ff3e44a..1045d34 100644
--- a/lib/config/config.go
+++ b/lib/exec/config.go
@@ -1,4 +1,4 @@
-package config
+package exec
 
 import (
 	"bytes"
@@ -11,9 +11,6 @@
 
 var ErrKeyNotFound = verror.NoExistf("config key not found")
 
-// TODO(caprita): Move the interface to veyron2 and integrate with
-// veyron/services/config.
-
 // Config defines a simple key-value configuration.  Keys and values are
 // strings, and a key can have exactly one value.  The client is responsible for
 // encoding structured values, or multiple values, in the provided string.
@@ -49,7 +46,7 @@
 }
 
 // New creates a new empty config.
-func New() Config {
+func NewConfig() Config {
 	return &cfg{m: make(map[string]string)}
 }
 
diff --git a/lib/config/config_test.go b/lib/exec/config_test.go
similarity index 95%
rename from lib/config/config_test.go
rename to lib/exec/config_test.go
index e22a820..dbb3475 100644
--- a/lib/config/config_test.go
+++ b/lib/exec/config_test.go
@@ -1,4 +1,4 @@
-package config
+package exec
 
 import (
 	"testing"
@@ -20,7 +20,7 @@
 
 // TestConfig checks that Set and Get work as expected.
 func TestConfig(t *testing.T) {
-	c := New()
+	c := NewConfig()
 	c.Set("foo", "bar")
 	checkPresent(t, c, "foo", "bar")
 	checkAbsent(t, c, "food")
@@ -31,14 +31,14 @@
 // TestSerialize checks that serializing the config and merging from a
 // serialized config work as expected.
 func TestSerialize(t *testing.T) {
-	c := New()
+	c := NewConfig()
 	c.Set("k1", "v1")
 	c.Set("k2", "v2")
 	s, err := c.Serialize()
 	if err != nil {
 		t.Fatalf("Failed to serialize: %v", err)
 	}
-	readC := New()
+	readC := NewConfig()
 	if err := readC.MergeFrom(s); err != nil {
 		t.Fatalf("Failed to deserialize: %v", err)
 	}
diff --git a/services/mgmt/lib/exec/doc.go b/lib/exec/doc.go
similarity index 100%
rename from services/mgmt/lib/exec/doc.go
rename to lib/exec/doc.go
diff --git a/services/mgmt/lib/exec/example_test.go b/lib/exec/example_test.go
similarity index 100%
rename from services/mgmt/lib/exec/example_test.go
rename to lib/exec/example_test.go
diff --git a/services/mgmt/lib/exec/exec_test.go b/lib/exec/exec_test.go
similarity index 98%
rename from services/mgmt/lib/exec/exec_test.go
rename to lib/exec/exec_test.go
index 399f00a..0984521 100644
--- a/services/mgmt/lib/exec/exec_test.go
+++ b/lib/exec/exec_test.go
@@ -10,10 +10,9 @@
 	"testing"
 	"time"
 
-	"veyron.io/veyron/veyron/lib/config"
+	vexec "veyron.io/veyron/veyron/lib/exec"
 	// Use mock timekeeper to avoid actually sleeping during the test.
 	"veyron.io/veyron/veyron/runtimes/google/testing/timekeeper"
-	vexec "veyron.io/veyron/veyron/services/mgmt/lib/exec"
 )
 
 // We always expect there to be exactly three open file descriptors
@@ -103,7 +102,7 @@
 func TestConfigExchange(t *testing.T) {
 	cmd := helperCommand("testConfig")
 	stderr, _ := cmd.StderrPipe()
-	cfg := config.New()
+	cfg := vexec.NewConfig()
 	cfg.Set("foo", "bar")
 	ph := vexec.NewParentHandle(cmd, vexec.ConfigOpt{cfg})
 	err := ph.Start()
diff --git a/services/mgmt/lib/exec/parent.go b/lib/exec/parent.go
similarity index 97%
rename from services/mgmt/lib/exec/parent.go
rename to lib/exec/parent.go
index 91a6147..ad93af1 100644
--- a/services/mgmt/lib/exec/parent.go
+++ b/lib/exec/parent.go
@@ -9,7 +9,6 @@
 	"syscall"
 	"time"
 
-	"veyron.io/veyron/veyron/lib/config"
 	// TODO(cnicolaou): move timekeeper out of runtimes
 	"veyron.io/veyron/veyron/runtimes/google/lib/timekeeper"
 
@@ -25,7 +24,7 @@
 // A ParentHandle is the Parent process' means of managing a single child.
 type ParentHandle struct {
 	c           *exec.Cmd
-	config      config.Config
+	config      Config
 	secret      string
 	statusRead  *os.File
 	statusWrite *os.File
@@ -42,7 +41,7 @@
 // ConfigOpt can be used to seed the parent handle with a
 // config to be passed to the child.
 type ConfigOpt struct {
-	config.Config
+	Config
 }
 
 // ExecParentHandleOpt makes ConfigOpt an instance of
@@ -67,7 +66,7 @@
 // an instance of exec.Cmd.
 func NewParentHandle(c *exec.Cmd, opts ...ParentHandleOpt) *ParentHandle {
 	c.Env = append(c.Env, versionVariable+"="+version1)
-	cfg, secret := config.New(), ""
+	cfg, secret := NewConfig(), ""
 	tk := timekeeper.RealTime()
 	for _, opt := range opts {
 		switch v := opt.(type) {
diff --git a/services/mgmt/lib/exec/shared.go b/lib/exec/shared.go
similarity index 100%
rename from services/mgmt/lib/exec/shared.go
rename to lib/exec/shared.go
diff --git a/services/mgmt/lib/exec/util.go b/lib/exec/util.go
similarity index 100%
rename from services/mgmt/lib/exec/util.go
rename to lib/exec/util.go
diff --git a/services/mgmt/lib/exec/util_test.go b/lib/exec/util_test.go
similarity index 100%
rename from services/mgmt/lib/exec/util_test.go
rename to lib/exec/util_test.go
diff --git a/lib/modules/exec.go b/lib/modules/exec.go
index e2e35db..b2a12da 100644
--- a/lib/modules/exec.go
+++ b/lib/modules/exec.go
@@ -14,8 +14,7 @@
 
 	"veyron.io/veyron/veyron2/vlog"
 
-	// TODO(cnicolaou): move this to veyron/lib.
-	vexec "veyron.io/veyron/veyron/services/mgmt/lib/exec"
+	vexec "veyron.io/veyron/veyron/lib/exec"
 )
 
 // execHandle implements both the command and Handle interfaces.
diff --git a/runtimes/google/rt/mgmt.go b/runtimes/google/rt/mgmt.go
index 86e4802..a1901f5 100644
--- a/runtimes/google/rt/mgmt.go
+++ b/runtimes/google/rt/mgmt.go
@@ -11,9 +11,9 @@
 	"veyron.io/veyron/veyron2/mgmt"
 	"veyron.io/veyron/veyron2/naming"
 
+	"veyron.io/veyron/veyron/lib/exec"
 	"veyron.io/veyron/veyron/profiles"
 	"veyron.io/veyron/veyron/runtimes/google/appcycle"
-	"veyron.io/veyron/veyron/services/mgmt/lib/exec"
 )
 
 type mgmtImpl struct {
diff --git a/runtimes/google/rt/rt.go b/runtimes/google/rt/rt.go
index 1911cc3..93e41f4 100644
--- a/runtimes/google/rt/rt.go
+++ b/runtimes/google/rt/rt.go
@@ -15,9 +15,9 @@
 	"veyron.io/veyron/veyron2/security"
 	"veyron.io/veyron/veyron2/vlog"
 
+	"veyron.io/veyron/veyron/lib/exec"
 	"veyron.io/veyron/veyron/profiles"
 	"veyron.io/veyron/veyron/runtimes/google/naming/namespace"
-	"veyron.io/veyron/veyron/services/mgmt/lib/exec"
 )
 
 type vrt struct {
diff --git a/services/mgmt/node/impl/app_invoker.go b/services/mgmt/node/impl/app_invoker.go
index ddf2701..b7e3a9a 100644
--- a/services/mgmt/node/impl/app_invoker.go
+++ b/services/mgmt/node/impl/app_invoker.go
@@ -96,10 +96,6 @@
 	"strings"
 	"time"
 
-	"veyron.io/veyron/veyron/lib/config"
-	vexec "veyron.io/veyron/veyron/services/mgmt/lib/exec"
-	iconfig "veyron.io/veyron/veyron/services/mgmt/node/config"
-
 	"veyron.io/veyron/veyron2/context"
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/mgmt"
@@ -108,6 +104,9 @@
 	"veyron.io/veyron/veyron2/services/mgmt/appcycle"
 	"veyron.io/veyron/veyron2/services/mgmt/application"
 	"veyron.io/veyron/veyron2/vlog"
+
+	vexec "veyron.io/veyron/veyron/lib/exec"
+	iconfig "veyron.io/veyron/veyron/services/mgmt/node/config"
 )
 
 // instanceInfo holds state about a running instance.
@@ -470,7 +469,7 @@
 	callbackState := i.callback
 	listener := callbackState.listenFor(mgmt.AppCycleManagerConfigKey)
 	defer listener.cleanup()
-	cfg := config.New()
+	cfg := vexec.NewConfig()
 	cfg.Set(mgmt.ParentNodeManagerConfigKey, listener.name())
 	handle := vexec.NewParentHandle(cmd, vexec.ConfigOpt{cfg})
 	defer func() {
diff --git a/services/mgmt/node/impl/callback.go b/services/mgmt/node/impl/callback.go
index 92ddf6f..46dbc21 100644
--- a/services/mgmt/node/impl/callback.go
+++ b/services/mgmt/node/impl/callback.go
@@ -3,12 +3,12 @@
 import (
 	"time"
 
-	"veyron.io/veyron/veyron/services/mgmt/lib/exec"
-	"veyron.io/veyron/veyron/services/mgmt/node"
-
 	"veyron.io/veyron/veyron2/mgmt"
 	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/vlog"
+
+	"veyron.io/veyron/veyron/lib/exec"
+	"veyron.io/veyron/veyron/services/mgmt/node"
 )
 
 // InvokeCallback provides the parent node manager with the given name (which is
diff --git a/services/mgmt/node/impl/impl_test.go b/services/mgmt/node/impl/impl_test.go
index 139c5bd..879a34a 100644
--- a/services/mgmt/node/impl/impl_test.go
+++ b/services/mgmt/node/impl/impl_test.go
@@ -16,11 +16,11 @@
 	"testing"
 	"time"
 
+	"veyron.io/veyron/veyron/lib/exec"
 	"veyron.io/veyron/veyron/lib/signals"
 	"veyron.io/veyron/veyron/lib/testutil/blackbox"
 	tsecurity "veyron.io/veyron/veyron/lib/testutil/security"
 	vsecurity "veyron.io/veyron/veyron/security"
-	"veyron.io/veyron/veyron/services/mgmt/lib/exec"
 	"veyron.io/veyron/veyron/services/mgmt/node/config"
 	"veyron.io/veyron/veyron/services/mgmt/node/impl"
 	suidhelper "veyron.io/veyron/veyron/services/mgmt/suidhelper/impl"
diff --git a/services/mgmt/node/impl/node_invoker.go b/services/mgmt/node/impl/node_invoker.go
index 965c34c..9db7b75 100644
--- a/services/mgmt/node/impl/node_invoker.go
+++ b/services/mgmt/node/impl/node_invoker.go
@@ -34,11 +34,6 @@
 	"sync"
 	"time"
 
-	"veyron.io/veyron/veyron/lib/config"
-	vexec "veyron.io/veyron/veyron/services/mgmt/lib/exec"
-	iconfig "veyron.io/veyron/veyron/services/mgmt/node/config"
-	"veyron.io/veyron/veyron/services/mgmt/profile"
-
 	"veyron.io/veyron/veyron2/context"
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/mgmt"
@@ -49,6 +44,10 @@
 	"veyron.io/veyron/veyron2/services/mgmt/binary"
 	"veyron.io/veyron/veyron2/services/mgmt/node"
 	"veyron.io/veyron/veyron2/vlog"
+
+	vexec "veyron.io/veyron/veyron/lib/exec"
+	iconfig "veyron.io/veyron/veyron/services/mgmt/node/config"
+	"veyron.io/veyron/veyron/services/mgmt/profile"
 )
 
 type updatingState struct {
@@ -167,7 +166,7 @@
 	callbackState := i.callback
 	listener := callbackState.listenFor(mgmt.ChildNodeManagerConfigKey)
 	defer listener.cleanup()
-	cfg := config.New()
+	cfg := vexec.NewConfig()
 	cfg.Set(mgmt.ParentNodeManagerConfigKey, listener.name())
 	handle := vexec.NewParentHandle(cmd, vexec.ConfigOpt{cfg})
 	// Start the child process.
diff --git a/services/mgmt/node/impl/util_test.go b/services/mgmt/node/impl/util_test.go
index 6d7e0f2..c107d42 100644
--- a/services/mgmt/node/impl/util_test.go
+++ b/services/mgmt/node/impl/util_test.go
@@ -13,10 +13,10 @@
 	"veyron.io/veyron/veyron2/verror"
 	"veyron.io/veyron/veyron2/vlog"
 
+	"veyron.io/veyron/veyron/lib/exec"
 	"veyron.io/veyron/veyron/lib/testutil/blackbox"
 	"veyron.io/veyron/veyron/lib/testutil/security"
 	"veyron.io/veyron/veyron/profiles"
-	"veyron.io/veyron/veyron/services/mgmt/lib/exec"
 	mtlib "veyron.io/veyron/veyron/services/mounttable/lib"
 )