• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang unit.NewUnitState函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/coreos/fleet/unit.NewUnitState函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUnitState函数的具体用法?Golang NewUnitState怎么用?Golang NewUnitState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewUnitState函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: newFakeRegistryForSsh

func newFakeRegistryForSsh() registry.Registry {
	machines := []machine.MachineState{
		{"c31e44e1-f858-436e-933e-59c642517860", "1.2.3.4", map[string]string{"ping": "pong"}, "", resource.ResourceTuple{}},
		{"595989bb-cbb7-49ce-8726-722d6e157b4e", "5.6.7.8", map[string]string{"foo": "bar"}, "", resource.ResourceTuple{}},
		{"hello.service", "8.7.6.5", map[string]string{"foo": "bar"}, "", resource.ResourceTuple{}},
	}

	jobs := []job.Job{
		*job.NewJob("j1.service", unit.Unit{}),
		*job.NewJob("j2.service", unit.Unit{}),
		*job.NewJob("hello.service", unit.Unit{}),
	}

	states := map[string]*unit.UnitState{
		"j1.service":    unit.NewUnitState("loaded", "active", "listening", &machines[0]),
		"j2.service":    unit.NewUnitState("loaded", "inactive", "dead", &machines[1]),
		"hello.service": unit.NewUnitState("loaded", "inactive", "dead", &machines[2]),
	}

	reg := registry.NewFakeRegistry()
	reg.SetMachines(machines)
	reg.SetUnitStates(states)
	reg.SetJobs(jobs)

	return reg
}
开发者ID:Jitendrakry,项目名称:fleet,代码行数:26,代码来源:ssh_test.go


示例2: setupRegistryForStart

func setupRegistryForStart(echoAttempts int) {
	m1 := machine.MachineState{
		ID:       "c31e44e1-f858-436e-933e-59c642517860",
		PublicIP: "1.2.3.4",
		Metadata: map[string]string{"ping": "pong"},
	}
	m2 := machine.MachineState{
		ID:       "595989bb-cbb7-49ce-8726-722d6e157b4e",
		PublicIP: "5.6.7.8",
		Metadata: map[string]string{"foo": "bar"},
	}
	m3 := machine.MachineState{
		ID:       "520983A8-FB9C-4A68-B49C-CED5BB2E9D08",
		Metadata: map[string]string{"foo": "bar"},
	}

	js := unit.NewUnitState("loaded", "active", "listening", m1.ID)
	js2 := unit.NewUnitState("loaded", "inactive", "dead", m2.ID)
	js3 := unit.NewUnitState("loaded", "inactive", "dead", m2.ID)
	js4 := unit.NewUnitState("loaded", "inactive", "dead", m3.ID)

	states := map[string]*unit.UnitState{"pong.service": js, "hello.service": js2, "echo.service": js3, "private.service": js4}
	machines := []machine.MachineState{m1, m2, m3}

	reg := registry.NewFakeRegistry()
	reg.SetMachines(machines)
	reg.SetUnitStates(states)

	cAPI = &BlockedFakeRegistry{echoAttempts, *reg}
}
开发者ID:JuanCarlosM,项目名称:fleet,代码行数:30,代码来源:start_test.go


示例3: newFakeRegistryForSsh

func newFakeRegistryForSsh() registry.Registry {
	// clear machineStates for every invocation
	machineStates = nil
	machines := []machine.MachineState{
		newMachineState("c31e44e1-f858-436e-933e-59c642517860", "1.2.3.4", map[string]string{"ping": "pong"}),
		newMachineState("595989bb-cbb7-49ce-8726-722d6e157b4e", "5.6.7.8", map[string]string{"foo": "bar"}),
		newMachineState("hello.service", "8.7.6.5", map[string]string{"foo": "bar"}),
	}

	jobs := []job.Job{
		*job.NewJob("j1.service", unit.Unit{}),
		*job.NewJob("j2.service", unit.Unit{}),
		*job.NewJob("hello.service", unit.Unit{}),
	}

	states := map[string]*unit.UnitState{
		"j1.service":    unit.NewUnitState("loaded", "active", "listening", machines[0].ID),
		"j2.service":    unit.NewUnitState("loaded", "inactive", "dead", machines[1].ID),
		"hello.service": unit.NewUnitState("loaded", "inactive", "dead", machines[2].ID),
	}

	reg := registry.NewFakeRegistry()
	reg.SetMachines(machines)
	reg.SetUnitStates(states)
	reg.SetJobs(jobs)

	return reg
}
开发者ID:JuanCarlosM,项目名称:fleet,代码行数:28,代码来源:ssh_test.go


示例4: setupRegistryForStart

func setupRegistryForStart(echoAttempts int) {
	m1 := machine.MachineState{"c31e44e1-f858-436e-933e-59c642517860", "1.2.3.4", map[string]string{"ping": "pong"}, ""}
	m2 := machine.MachineState{"595989bb-cbb7-49ce-8726-722d6e157b4e", "5.6.7.8", map[string]string{"foo": "bar"}, ""}
	m3 := machine.MachineState{"520983A8-FB9C-4A68-B49C-CED5BB2E9D08", "", map[string]string{"foo": "bar"}, ""}

	js := unit.NewUnitState("loaded", "active", "listening", &m1)
	js2 := unit.NewUnitState("loaded", "inactive", "dead", &m2)
	js3 := unit.NewUnitState("loaded", "inactive", "dead", &m2)
	js4 := unit.NewUnitState("loaded", "inactive", "dead", &m3)

	states := map[string]*unit.UnitState{"pong.service": js, "hello.service": js2, "echo.service": js3, "private.service": js4}
	machines := []machine.MachineState{m1, m2, m3}

	registryCtl = BlockedTestRegistry{echoAttempts, TestRegistry{jobStates: states, machines: machines}}
}
开发者ID:rswart,项目名称:fleet,代码行数:15,代码来源:start_test.go


示例5: GetUnitState

// GetUnitState generates a UnitState object representing the
// current state of a Unit
func (m *SystemdUnitManager) GetUnitState(name string) (*unit.UnitState, error) {
	loadState, activeState, subState, err := m.getUnitStates(name)
	if err != nil {
		return nil, err
	}
	return unit.NewUnitState(loadState, activeState, subState, nil), nil
}
开发者ID:Jitendrakry,项目名称:fleet,代码行数:9,代码来源:manager.go


示例6: GetUnitState

// GetUnitState generates a UnitState object representing the
// current state of a Job's unit
func (m *SystemdManager) GetUnitState(jobName string) (*unit.UnitState, error) {
	loadState, activeState, subState, err := m.getUnitStates(jobName)
	if err != nil {
		return nil, err
	}
	ms := m.Machine.State()
	return unit.NewUnitState(loadState, activeState, subState, &ms), nil
}
开发者ID:rswart,项目名称:fleet,代码行数:10,代码来源:manager.go


示例7: translateUnitStatusEvents

func translateUnitStatusEvents(changes map[string]*dbus.UnitStatus) []event.Event {
	events := make([]event.Event, 0)
	for name, status := range changes {
		var state *unit.UnitState
		if status != nil {
			state = unit.NewUnitState(status.LoadState, status.ActiveState, status.SubState, nil)
		}
		ev := event.Event{"EventUnitStateUpdated", state, name}
		events = append(events, ev)
	}
	return events
}
开发者ID:Jitendrakry,项目名称:fleet,代码行数:12,代码来源:event.go


示例8: TestListUnitsFieldsToStrings

func TestListUnitsFieldsToStrings(t *testing.T) {
	j := newTestJobFromUnitContents(t, "")
	for _, tt := range []string{"state", "load", "active", "sub", "desc", "machine"} {
		f := listUnitsFields[tt](j, false)
		assertEqual(t, tt, "-", f)
	}

	f := listUnitsFields["unit"](j, false)
	assertEqual(t, "unit", j.Name, f)

	j = newTestJobFromUnitContents(t, `[Unit]
Description=some description`)
	d := listUnitsFields["desc"](j, false)
	assertEqual(t, "desc", "some description", d)

	for _, state := range []job.JobState{job.JobStateLoaded, job.JobStateInactive, job.JobStateLaunched} {
		j.State = &state
		f := listUnitsFields["state"](j, false)
		assertEqual(t, "state", string(state), f)
	}

	j.UnitState = unit.NewUnitState("foo", "bar", "baz", "")
	for k, want := range map[string]string{
		"load":    "foo",
		"active":  "bar",
		"sub":     "baz",
		"machine": "-",
	} {
		got := listUnitsFields[k](j, false)
		assertEqual(t, k, want, got)
	}

	j.UnitState.MachineID = "some-id"
	ms := listUnitsFields["machine"](j, true)
	assertEqual(t, "machine", "some-id", ms)

	j.UnitState.MachineID = "other-id"
	machineStates = map[string]*machine.MachineState{
		"other-id": &machine.MachineState{
			ID:       "other-id",
			PublicIP: "1.2.3.4",
		},
	}
	ms = listUnitsFields["machine"](j, true)
	assertEqual(t, "machine", "other-id/1.2.3.4", ms)

	uh := "f035b2f14edc4d23572e5f3d3d4cb4f78d0e53c3"
	j.UnitState.UnitHash = uh
	fuh := listUnitsFields["hash"](j, true)
	suh := listUnitsFields["hash"](j, false)
	assertEqual(t, "hash", uh, fuh)
	assertEqual(t, "hash", uh[:7], suh)
}
开发者ID:BillTheBest,项目名称:fleet,代码行数:53,代码来源:list_units_test.go


示例9: newTestRegistryForSsh

func newTestRegistryForSsh() registry.Registry {
	machines := []machine.MachineState{
		machine.MachineState{"c31e44e1-f858-436e-933e-59c642517860", "1.2.3.4", map[string]string{"ping": "pong"}, ""},
		machine.MachineState{"595989bb-cbb7-49ce-8726-722d6e157b4e", "5.6.7.8", map[string]string{"foo": "bar"}, ""},
		machine.MachineState{"hello.service", "8.7.6.5", map[string]string{"foo": "bar"}, ""},
	}

	jobs := []job.Job{
		*job.NewJob("j1.service", unit.Unit{}),
		*job.NewJob("j2.service", unit.Unit{}),
		*job.NewJob("hello.service", unit.Unit{}),
	}

	states := map[string]*unit.UnitState{
		"j1.service":    unit.NewUnitState("loaded", "active", "listening", &machines[0]),
		"j2.service":    unit.NewUnitState("loaded", "inactive", "dead", &machines[1]),
		"hello.service": unit.NewUnitState("loaded", "inactive", "dead", &machines[2]),
	}

	return TestRegistry{machines: machines, jobStates: states, jobs: jobs}
}
开发者ID:rswart,项目名称:fleet,代码行数:21,代码来源:ssh_test.go


示例10: TestSaveUnitState

func TestSaveUnitState(t *testing.T) {
	e := &testEtcdClient{}
	r := &EtcdRegistry{etcd: e, keyPrefix: "/fleet/"}
	j := "foo.service"
	mID := "mymachine"
	us := unit.NewUnitState("abc", "def", "ghi", mID)

	// Saving nil unit state should fail
	r.SaveUnitState(j, nil, time.Second)
	if e.sets != nil || e.deletes != nil {
		t.Logf("sets: %#v", e.sets)
		t.Logf("deletes: %#v", e.deletes)
		t.Fatalf("SaveUnitState of nil state should fail but acted unexpectedly!")
	}

	// Saving unit state with no hash should succeed for now, but should fail
	// in the future. See https://github.com/coreos/fleet/issues/720.
	//r.SaveUnitState(j, us, time.Second)
	//if len(e.sets) != 1 || e.deletes == nil {
	//	t.Logf("sets: %#v", e.sets)
	//	t.Logf("deletes: %#v", e.deletes)
	//	t.Fatalf("SaveUnitState on UnitState with no hash acted unexpectedly!")
	//}

	us.UnitHash = "quickbrownfox"
	r.SaveUnitState(j, us, time.Second)

	json := `{"loadState":"abc","activeState":"def","subState":"ghi","machineState":{"ID":"mymachine","PublicIP":"","Metadata":null,"Version":""},"unitHash":"quickbrownfox"}`
	p1 := "/fleet/state/foo.service"
	p2 := "/fleet/states/foo.service/mymachine"
	want := []action{
		action{key: p1, val: json},
		action{key: p2, val: json},
	}
	got := e.sets
	if !reflect.DeepEqual(got, want) {
		t.Errorf("bad result from SaveUnitState: \ngot\n%#v\nwant\n%#v", got, want)
	}
	if e.deletes != nil {
		t.Errorf("unexpected deletes during SaveUnitState: %#v", e.deletes)
	}
	if e.gets != nil {
		t.Errorf("unexpected gets during SaveUnitState: %#v", e.gets)
	}
}
开发者ID:ngpestelos,项目名称:fleet,代码行数:45,代码来源:unit_state_test.go


示例11: TestListUnitsFieldsToStrings

func TestListUnitsFieldsToStrings(t *testing.T) {
	j := job.NewJob("test", *unit.NewUnit(""))
	for _, tt := range []string{"state", "load", "active", "sub", "desc", "machine"} {
		f := listUnitsFields[tt](j, false)
		assertEqual(t, tt, "-", f)
	}

	f := listUnitsFields["unit"](j, false)
	assertEqual(t, "unit", "test", f)

	j = job.NewJob("test", *unit.NewUnit(`[Unit]
Description=some description`))
	d := listUnitsFields["desc"](j, false)
	assertEqual(t, "desc", "some description", d)

	for _, state := range []job.JobState{job.JobStateLoaded, job.JobStateInactive, job.JobStateLaunched} {
		j.State = &state
		f := listUnitsFields["state"](j, false)
		assertEqual(t, "state", string(state), f)
	}

	j.UnitState = unit.NewUnitState("foo", "bar", "baz", nil)
	for k, want := range map[string]string{
		"load":    "foo",
		"active":  "bar",
		"sub":     "baz",
		"machine": "-",
	} {
		got := listUnitsFields[k](j, false)
		assertEqual(t, k, want, got)
	}

	j.UnitState.MachineState = &machine.MachineState{"some-id", "1.2.3.4", nil, "", resource.ResourceTuple{}}
	ms := listUnitsFields["machine"](j, true)
	assertEqual(t, "machine", "some-id/1.2.3.4", ms)

	uh := "f035b2f14edc4d23572e5f3d3d4cb4f78d0e53c3"
	fuh := listUnitsFields["hash"](j, true)
	suh := listUnitsFields["hash"](j, false)
	assertEqual(t, "hash", uh, fuh)
	assertEqual(t, "hash", uh[:7], suh)
}
开发者ID:johnmontero,项目名称:fleet,代码行数:42,代码来源:list_units_test.go


示例12: TestGetUnitState

func TestGetUnitState(t *testing.T) {
	for i, tt := range []struct {
		res *etcd.Result // result returned from etcd
		err error        // error returned from etcd
		us  *unit.UnitState
	}{
		{
			// Unit state with no UnitHash should be OK
			res: makeResult(`{"loadState":"abc","activeState":"def","subState":"ghi","machineState":{"ID":"mymachine","PublicIP":"","Metadata":null,"Version":"","TotalResources":{"Cores":0,"Memory":0,"Disk":0},"FreeResources":{"Cores":0,"Memory":0,"Disk":0}}}`),
			err: nil,
			us:  unit.NewUnitState("abc", "def", "ghi", "mymachine"),
		},
		{
			// Unit state with UnitHash should be OK
			res: makeResult(`{"loadState":"abc","activeState":"def","subState":"ghi","machineState":{"ID":"mymachine","PublicIP":"","Metadata":null,"Version":"","TotalResources":{"Cores":0,"Memory":0,"Disk":0},"FreeResources":{"Cores":0,"Memory":0,"Disk":0}},"unitHash":"quickbrownfox"}`),
			err: nil,
			us:  &unit.UnitState{"abc", "def", "ghi", "mymachine", "quickbrownfox"},
		},
		{
			// Unit state with no MachineState should be OK
			res: makeResult(`{"loadState":"abc","activeState":"def","subState":"ghi"}`),
			err: nil,
			us:  &unit.UnitState{"abc", "def", "ghi", "", ""},
		},
		{
			// Bad unit state object should simply result in nil returned
			res: makeResult(`garbage, not good proper json`),
			err: nil,
			us:  nil,
		},
		{
			// Unknown errors should result in nil returned
			res: nil,
			err: errors.New("some random error from etcd"),
			us:  nil,
		},
		{
			// KeyNotFound should result in nil returned
			res: nil,
			err: etcd.Error{ErrorCode: etcd.ErrorKeyNotFound},
			us:  nil,
		},
	} {
		e := &testEtcdClient{
			res: tt.res,
			err: tt.err,
		}
		r := &EtcdRegistry{e, "/fleet/"}
		j := "foo.service"
		us := r.getUnitState(j)
		want := []action{
			action{key: "/fleet/state/foo.service", rec: true},
		}
		got := e.gets
		if !reflect.DeepEqual(got, want) {
			t.Errorf("case %d: bad result from GetUnitState:\ngot\n%#v\nwant\n%#v", i, got, want)
		}
		if !reflect.DeepEqual(us, tt.us) {
			t.Errorf("case %d: bad UnitState:\ngot\n%#v\nwant\n%#v", i, us, tt.us)
		}
	}
}
开发者ID:BillTheBest,项目名称:fleet,代码行数:62,代码来源:unit_state_test.go



注:本文中的github.com/coreos/fleet/unit.NewUnitState函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang unit.NewUnitStateGenerator函数代码示例发布时间:2022-05-23
下一篇:
Golang unit.NewUnitNameInfo函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap