本文整理匯總了Golang中github.com/NetSys/quilt/db.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestReadContainerTransact
func TestReadContainerTransact(t *testing.T) {
conn := db.New()
conn.Transact(func(view db.Database) error {
testReadContainerTransact(t, view)
return nil
})
}
示例2: TestUpdateDBLabels
func TestUpdateDBLabels(t *testing.T) {
conn := db.New()
conn.Transact(func(view db.Database) error {
testUpdateDBLabels(t, view)
return nil
})
}
示例3: Run
// Run starts the daemon.
func (dCmd *Daemon) Run() int {
conn := db.New()
go engine.Run(conn)
go server.Run(conn, dCmd.host)
cluster.Run(conn)
return 0
}
示例4: TestACLs
func TestACLs(t *testing.T) {
conn := db.New()
code := `createDeployment({adminACL: ["1.2.3.4/32", "local"]})
.deploy([
new Machine({provider: "Amazon", role: "Master"}),
new Machine({provider: "Amazon", role: "Worker"})
]);`
myIP = func() (string, error) {
return "5.6.7.8", nil
}
updateStitch(t, conn, prog(t, code))
acl, err := selectACL(conn)
assert.Nil(t, err)
assert.Equal(t, []string{"1.2.3.4/32", "5.6.7.8/32"}, acl.Admin)
myIP = func() (string, error) {
return "", errors.New("")
}
updateStitch(t, conn, prog(t, code))
acl, err = selectACL(conn)
assert.Nil(t, err)
assert.Equal(t, []string{"1.2.3.4/32"}, acl.Admin)
}
示例5: TestPlaceContainers
func TestPlaceContainers(t *testing.T) {
t.Parallel()
conn := db.New()
conn.Transact(func(view db.Database) error {
m := view.InsertMinion()
m.PrivateIP = "1"
m.Role = db.Worker
view.Commit(m)
e := view.InsertEtcd()
e.Leader = true
view.Commit(e)
c := view.InsertContainer()
view.Commit(c)
return nil
})
conn.Transact(func(view db.Database) error {
placeContainers(view)
return nil
})
conn.Transact(func(view db.Database) error {
dbcs := view.SelectFromContainer(nil)
assert.Len(t, dbcs, 1)
assert.Equal(t, "1", dbcs[0].Minion)
return nil
})
}
示例6: TestDeploy
func TestDeploy(t *testing.T) {
conn := db.New()
s := server{dbConn: conn}
createMachineDeployment := `
{"Machines":[
{"Provider":"Amazon",
"Role":"Master",
"Size":"m4.large"
}, {"Provider":"Amazon",
"Role":"Worker",
"Size":"m4.large"
}]}`
_, err := s.Deploy(context.Background(),
&pb.DeployRequest{Deployment: createMachineDeployment})
assert.NoError(t, err)
var spec string
conn.Transact(func(view db.Database) error {
clst, err := view.GetCluster()
assert.NoError(t, err)
spec = clst.Spec
return nil
})
exp, err := stitch.FromJSON(createMachineDeployment)
assert.NoError(t, err)
actual, err := stitch.FromJSON(spec)
assert.NoError(t, err)
assert.Equal(t, exp, actual)
}
示例7: main
func main() {
// XXX Uncomment the following line to run the profiler
//runProfiler(5 * time.Minute)
log.Info("Minion Start")
log.SetFormatter(util.Formatter{})
conn := db.New()
dk := docker.New("unix:///var/run/docker.sock")
go minionServerRun(conn)
go supervisor.Run(conn, dk)
go scheduler.Run(conn)
go network.Run(conn, dk)
go etcd.Run(conn)
for range conn.Trigger(db.MinionTable).C {
conn.Transact(func(view db.Database) error {
minion, err := view.MinionSelf()
if err != nil {
return err
}
updatePolicy(view, minion.Role, minion.Spec)
return nil
})
}
}
示例8: initTest
func initTest() *testCtx {
conn := db.New()
md, dk := docker.NewMock()
ctx := testCtx{supervisor{}, fakeDocker{dk, md}, nil, conn,
conn.Trigger(db.MinionTable, db.EtcdTable)}
ctx.sv.conn = ctx.conn
ctx.sv.dk = ctx.fd.Client
ctx.conn.Transact(func(view db.Database) error {
m := view.InsertMinion()
m.Self = true
view.Commit(m)
e := view.InsertEtcd()
view.Commit(e)
return nil
})
ctx.sv.runSystemOnce()
execRun = func(name string, args ...string) error {
ctx.execs = append(ctx.execs, append([]string{name}, args...))
return nil
}
return &ctx
}
示例9: TestSort
func TestSort(t *testing.T) {
pre := `var baseMachine = new Machine({provider: "Amazon", size: "m4.large"});`
conn := db.New()
updateStitch(t, conn, prog(t, pre+`
deployment.deploy(baseMachine.asMaster().replicate(3));
deployment.deploy(baseMachine.asWorker().replicate(1));`))
conn.Transact(func(view db.Database) error {
machines := view.SelectFromMachine(func(m db.Machine) bool {
return m.Role == db.Master
})
assert.Equal(t, 3, len(machines))
machines[2].PublicIP = "a"
machines[2].PrivateIP = "b"
view.Commit(machines[2])
machines[1].PrivateIP = "c"
view.Commit(machines[1])
return nil
})
updateStitch(t, conn, prog(t, pre+`
deployment.deploy(baseMachine.asMaster().replicate(2));
deployment.deploy(baseMachine.asWorker().replicate(1));`))
conn.Transact(func(view db.Database) error {
machines := view.SelectFromMachine(func(m db.Machine) bool {
return m.Role == db.Master
})
assert.Equal(t, 2, len(machines))
for _, m := range machines {
assert.False(t, m.PublicIP == "" && m.PrivateIP == "")
}
return nil
})
updateStitch(t, conn, prog(t, pre+`
deployment.deploy(baseMachine.asMaster().replicate(1));
deployment.deploy(baseMachine.asWorker().replicate(1));`))
conn.Transact(func(view db.Database) error {
machines := view.SelectFromMachine(func(m db.Machine) bool {
return m.Role == db.Master
})
assert.Equal(t, 1, len(machines))
for _, m := range machines {
assert.False(t, m.PublicIP == "" && m.PrivateIP == "")
}
return nil
})
}
示例10: startTestWithRole
func startTestWithRole(role pb.MinionConfig_Role) db.Conn {
clientInst := &clients{make(map[string]*fakeClient), 0}
newClient = func(ip string) (client, error) {
fc := &fakeClient{clientInst, ip, pb.MinionConfig{Role: role}}
clientInst.clients[ip] = fc
clientInst.newCalls++
return fc, nil
}
return db.New()
}
示例11: TestBadDeployment
func TestBadDeployment(t *testing.T) {
conn := db.New()
s := server{dbConn: conn}
badDeployment := `{`
_, err := s.Deploy(context.Background(),
&pb.DeployRequest{Deployment: badDeployment})
assert.EqualError(t, err, "unexpected end of JSON input")
}
示例12: TestPanicBadProvider
func TestPanicBadProvider(t *testing.T) {
temp := allProviders
defer func() {
r := recover()
assert.NotNil(t, r)
allProviders = temp
}()
allProviders = []db.Provider{FakeAmazon}
conn := db.New()
newCluster(conn, "test")
}
示例13: main
func main() {
/* XXX: GRPC spews a lot of uselss log message so we tell to eat its logs.
* Once we have more sophistcated logging support, we should enable the log
* messages when in debug mode. */
grpclog.SetLogger(l_mod.New(ioutil.Discard, "", 0))
log.SetFormatter(util.Formatter{})
flag.Usage = func() {
fmt.Println("Usage: quilt [inspect <stitch> | run <stitch>" +
" | stop <namespace> | get <import_path>]" +
" [-log-level=<level> | -l=<level>]")
fmt.Println("\nWhen provided a stitch, quilt takes responsibility\n" +
"for deploying it as specified. Alternatively, quilt may be\n" +
"instructed to stop all deployments in a given namespace,\n" +
"or the default namespace if none is provided.\n")
flag.PrintDefaults()
fmt.Println(" Valid logger levels are:\n" +
" debug, info, warn, error, fatal or panic.")
}
var logLevel = flag.String("log-level", "info", "level to set logger to")
flag.StringVar(logLevel, "l", "info", "level to set logger to")
flag.Parse()
level, err := parseLogLevel(*logLevel)
if err != nil {
fmt.Println(err)
usage()
}
log.SetLevel(level)
conn := db.New()
if len(flag.Args()) != 2 {
usage()
}
switch flag.Arg(0) {
case "run":
go configLoop(conn, flag.Arg(1))
case "stop":
stop(conn, flag.Arg(1))
case "get":
getSpec(flag.Arg(1))
case "inspect":
inspect.Main(flag.Args())
return
default:
usage()
}
cluster.Run(conn)
}
示例14: TestPanicBadProvider
func TestPanicBadProvider(t *testing.T) {
temp := allProviders
defer func() {
if r := recover(); r == nil {
t.Error("newCluster did not panic on bad provider")
}
allProviders = temp
}()
allProviders = []db.Provider{FakeAmazon}
conn := db.New()
newCluster(conn, "test")
}
示例15: startTestWithRole
func startTestWithRole(role pb.MinionConfig_Role) foreman {
fm := createForeman(db.New())
clientInst := &clients{make(map[string]*fakeClient), 0}
fm.newClient = func(ip string) (client, error) {
fc := &fakeClient{clientInst, ip, pb.MinionConfig{Role: role},
pb.EtcdMembers{}}
clientInst.clients[ip] = fc
clientInst.newCalls++
return fc, nil
}
return fm
}