コード例 #1
0
func (r *ConsulAdapter) Register(service *bridge.Service) error {
	registration := new(consulapi.AgentServiceRegistration)
	registration.ID = service.ID
	registration.Name = service.Name
	registration.Port = service.Port
	registration.Tags = service.Tags
	registration.Address = service.IP
	registration.Check = r.buildCheck(service)
	if r.servicePrefix != "" {
		kv := r.client.KV()
		addr := service.IP + ":" + strconv.Itoa(service.Port)
		host_path := r.servicePrefix + "/" + "nodes/" + service.ID + "/"
		service_path := r.servicePrefix + "/" + "services/" + service.Name + "/" + service.ID + "/"
		_, err := kv.Put(&consulapi.KVPair{Key: host_path + "URI", Value: []byte(addr)}, nil)
		if err != nil {
			return (err)
		}
		_, err = kv.Put(&consulapi.KVPair{Key: service_path + "URI", Value: []byte(addr)}, nil)
		if err != nil {
			return (err)
		}
		for k, v := range service.Attrs {
			_, err := kv.Put(&consulapi.KVPair{Key: host_path + k, Value: []byte(v)}, nil)
			if err != nil {
				return (err)
			}
			_, err = kv.Put(&consulapi.KVPair{Key: service_path + k, Value: []byte(v)}, nil)
			if err != nil {
				return (err)
			}
		}
	}
	return r.client.Agent().ServiceRegister(registration)
}
コード例 #2
0
ファイル: services.go プロジェクト: colebrumley/consulctl
func SetService(c *cli.Context) {
	// Get client
	cfg, err := NewAppConfig(c)
	if err != nil {
		log.Errorf("Failed to get client: %v", err)
		return
	}

	reg := new(api.AgentServiceRegistration)

	for _, arg := range append(c.Args().Tail(), c.Args().First()) {
		split := strings.SplitN(arg, "=", 2)
		switch strings.ToLower(split[0]) {
		case "address":
			reg.Address = split[1]
		case "name":
			reg.Name = split[1]
		case "id":
			reg.ID = split[1]
		case "port":
			port, _ := strconv.ParseInt(split[1], 10, 32)
			reg.Port = int(port)
		case "tags":
			tags := strings.Split(split[1], ",")
			reg.Tags = tags
		}
	}

	err = cfg.client.Agent().ServiceRegister(reg)
	if err != nil {
		log.Errorf("%v\n", err)
		return
	}
	log.Println("Success")
}
コード例 #3
0
ファイル: hipache.go プロジェクト: kainz/registrator
// the types are so close yet SO DIFFERENT
func updateConsulTags(agent *consulapi.Agent, svc *consulapi.AgentService) error {
	registration := new(consulapi.AgentServiceRegistration)
	registration.Name = svc.Service
	registration.ID = svc.ID
	registration.Tags = svc.Tags
	registration.Port = svc.Port
	registration.Address = svc.Address
	return agent.ServiceRegister(registration)
}
コード例 #4
0
ファイル: consul.go プロジェクト: Marmelatze/registrator
func (r *ConsulAdapter) Register(service *bridge.Service) error {
	registration := new(consulapi.AgentServiceRegistration)
	registration.ID = service.ID
	registration.Name = service.Name
	registration.Port = service.Port
	registration.Tags = service.Tags
	registration.Address = service.IP
	registration.Checks = r.buildChecks(service)
	return r.client.Agent().ServiceRegister(registration)
}
コード例 #5
0
ファイル: registrator.go プロジェクト: zufangzi/chaos
func register() {
	registration := new(consulApi.AgentServiceRegistration)
	registration.ID = serviceId
	registration.Name = serviceName
	registration.Port, _ = strconv.Atoi(servicePort)
	registration.Tags = serviceTags
	registration.Address = serviceIp
	// TODO build Check latter
	log.Println("ID is: ", registration.ID)
	log.Println("Name is: ", registration.Name)
	log.Println("Port is: ", registration.Port)
	log.Println("Tags is: ", registration.Tags)
	log.Println("Address is: ", registration.Address)
	consulClient.Agent().ServiceRegister(registration)
}
コード例 #6
0
ファイル: consul.go プロジェクト: Dexels/registrator
func (r *ConsulAdapter) Register(service *bridge.Service) error {
	registration := new(consulapi.AgentServiceRegistration)
	registration.ID = service.ID
	registration.Name = service.Name
	registration.Port = service.Port
	registration.Tags = service.Tags
	registration.Address = service.IP
	registration.Check = r.buildCheck(service)
	if r.servicePrefix != "" {
		kv := r.client.KV()
		for k, v := range service.Attrs {
			pair := &consulapi.KVPair{Key: r.servicePrefix + "/" + service.ID + "/" + k, Value: []byte(v)}
			_, err := kv.Put(pair, nil)
			if err != nil {
				panic(err)
			}
		}
	}
	return r.client.Agent().ServiceRegister(registration)
}
コード例 #7
0
func (r *Adapter) Register(group *types.ServiceGroup) error {
	for _, service := range group.Services {
		if r.dryRun {
			log.WithFields(log.Fields{
				"prefix": "consul",
				"ip":     group.IP,
				"id":     service.ID,
				"name":   service.Name,
				"port":   service.ExposedPort,
			}).Info("[dry-run] Would register service")
			continue
		}

		log.WithFields(log.Fields{
			"prefix": "consul",
			"ip":     group.IP,
			"id":     service.ID,
			"name":   service.Name,
			"port":   service.ExposedPort,
		}).Info("Registering service")

		registration := new(consulAPI.AgentServiceRegistration)
		registration.Address = group.IP
		registration.ID = service.ID
		registration.Name = service.Name
		registration.Tags = service.Tags
		registration.Port = service.ExposedPort

		err := r.client.Agent().ServiceRegister(registration)
		if err != nil {
			return err
		}
	}

	return nil
}
コード例 #8
0
				Expect(checks).To(HaveKeyWithValue(checkID,
					&api.AgentCheck{
						Node:        "0",
						CheckID:     checkID,
						Name:        "Service '" + serviceName + "' check",
						Status:      "passing",
						Notes:       "",
						Output:      "",
						ServiceID:   serviceID,
						ServiceName: serviceName,
					}))
			})

			Context("when the service does not have an ID", func() {
				BeforeEach(func() {
					registration.ID = ""
				})

				It("registers the check using the service name in the check id", func() {
					checks, err := consulClient.Agent().Checks()
					Expect(err).NotTo(HaveOccurred())
					checkID := "service:" + serviceName
					Expect(checks).To(HaveKeyWithValue(checkID,
						&api.AgentCheck{
							Node:        "0",
							CheckID:     checkID,
							Name:        "Service '" + serviceName + "' check",
							Status:      "passing",
							Notes:       "",
							Output:      "",
							ServiceID:   serviceName,