示例#1
0
文件: monitor.go 项目: elleFlorio/gru
func updateSystemInstances(services []string) {
	cfg.ClearNodeInstances()
	instances := cfg.GetNodeInstances()
	for _, name := range services {
		service, _ := srv.GetServiceByName(name)
		instances.All = append(instances.All, service.Instances.All...)
		instances.Pending = append(instances.Pending, service.Instances.Pending...)
		instances.Running = append(instances.Running, service.Instances.Running...)
		instances.Stopped = append(instances.Stopped, service.Instances.Stopped...)
		instances.Paused = append(instances.Paused, service.Instances.Paused...)
	}
}
示例#2
0
func TestUpdateSystemInstances(t *testing.T) {
	defer resetMockServices()
	list := srv.List()

	updateSystemInstances(list)

	srv1, _ := srv.GetServiceByName("service1")
	srv2, _ := srv.GetServiceByName("service2")
	tot_all := len(srv1.Instances.All) + len(srv2.Instances.All)
	tot_pen := len(srv1.Instances.Pending) + len(srv2.Instances.Pending)
	tot_run := len(srv1.Instances.Running) + len(srv2.Instances.Running)
	tot_stop := len(srv1.Instances.Stopped) + len(srv2.Instances.Stopped)
	tot_pause := len(srv1.Instances.Paused) + len(srv2.Instances.Paused)

	instances := cfg.GetNodeInstances()
	assert.Len(t, instances.All, tot_all)
	assert.Len(t, instances.Pending, tot_pen)
	assert.Len(t, instances.Running, tot_run)
	assert.Len(t, instances.Stopped, tot_stop)
	assert.Len(t, instances.Paused, tot_pause)
}