示例#1
0
文件: service.go 项目: elleFlorio/gru
func List() []string {
	names := []string{}
	services := cfg.GetServices()

	for _, service := range services {
		names = append(names, service.Name)
	}

	return names
}
示例#2
0
文件: service.go 项目: elleFlorio/gru
func GetServiceByType(sType string) []cfg.Service {
	byType := make([]cfg.Service, 0)
	services := cfg.GetServices()

	for i := 0; i < len(services); i++ {
		if services[i].Type == sType {
			byType = append(byType, services[i])
		}
	}

	return byType
}
示例#3
0
// /gru/v1/services
func GetInfoServices(w http.ResponseWriter, r *http.Request) {
	services := cfg.GetServices()

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	if err := json.NewEncoder(w).Encode(services); err != nil {
		log.WithFields(log.Fields{
			"status":  "http response",
			"request": "GetInfoServices",
			"error":   err,
		}).Errorln("API Server")
	}
}
示例#4
0
func TestUpdateServices(t *testing.T) {
	defer cfg.CleanServices()
	cfg.SetServices(CreateMockServices())
	newService := cfg.Service{
		Name:  "newService",
		Type:  "mockService",
		Image: "noImage",
	}
	newServices := []cfg.Service{newService}

	cfg.SetServices(newServices)
	assert.Len(t, cfg.GetServices(), 1, "services should have lenght = 1 after the update")
	assert.Contains(t, List(), "newService", "services should contain service 'newService' after the update")
}
示例#5
0
func TestAddServices(t *testing.T) {
	defer cfg.CleanServices()
	cfg.SetServices(CreateMockServices())

	newService := cfg.Service{
		Name:  "newService",
		Type:  "mockService",
		Image: "noImage",
	}
	newServices := []cfg.Service{newService}

	cfg.AddServices(newServices)
	assert.Contains(t, cfg.GetServices(), newService, "services should contain the added service")
}
示例#6
0
文件: service.go 项目: elleFlorio/gru
func getServiceBy(field string, value string) (*cfg.Service, error) {
	services := cfg.GetServices()
	for i := 0; i < len(services); i++ {
		switch field {
		case "name":
			if services[i].Name == value {
				return &services[i], nil
			}
		case "image":
			if services[i].Image == value {
				return &services[i], nil
			}
		case "id":
			instances := services[i].Instances.All
			for _, instance := range instances {
				if instance == value {
					return &services[i], nil
				}
			}
		}
	}

	return nil, ErrNoSuchService
}