Exemplo n.º 1
0
func (s *Service) listen(addr skynet.BindAddr, bindWait *sync.WaitGroup) {
	var err error
	s.rpcListener, err = addr.Listen()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf(log.INFO, "%+v\n", ServiceListening{
		Addr:        &addr,
		ServiceInfo: s.ServiceInfo,
	})

	// We may have changed port due to conflict, ensure config has the correct port now
	a, _ := skynet.BindAddrFromString(addr.String())
	s.ServiceAddr.IPAddress = a.IPAddress
	s.ServiceAddr.Port = a.Port

	bindWait.Done()

	for {
		conn, err := s.rpcListener.AcceptTCP()

		if s.shuttingDown {
			break
		}

		if err != nil && !s.shuttingDown {
			log.Println(log.ERROR, "AcceptTCP failed", err)
			continue
		}
		s.connectionChan <- conn
	}
}
Exemplo n.º 2
0
// Retrieve ServiceInfo from zookeeper
func (sm *ZookeeperServiceManager) getServiceInfo(uuid string) (s skynet.ServiceInfo, err error) {
	var b []byte

	s.UUID = uuid

	reg, _, err := sm.conn.Get(path.Join("/instances", uuid, "registered"))

	if err != nil {
		return
	}

	if string(reg) == "true" {
		s.Registered = true
	} else {
		s.Registered = false
	}

	addr, _, err := sm.conn.Get(path.Join("/instances", uuid, "addr"))

	if err != nil {
		return
	}

	s.ServiceAddr, err = skynet.BindAddrFromString(string(addr))

	if err != nil {
		return
	}

	b, _, err = sm.conn.Get(path.Join("/instances", uuid, "name"))

	if err != nil {
		return
	}

	s.Name = string(b)

	b, _, err = sm.conn.Get(path.Join("/instances", uuid, "version"))

	if err != nil {
		return
	}

	s.Version = string(b)

	b, _, err = sm.conn.Get(path.Join("/instances", uuid, "region"))

	if err != nil {
		return
	}

	s.Region = string(b)

	return
}
Exemplo n.º 3
0
// we return error if anything is missing so instance adds aren't triggered before all paths have been created
func (c *InstanceCache) getServiceInfo(uuid string) (s skynet.ServiceInfo, err error) {
	s.UUID = uuid

	if name := c.cache.PathValue(path.Join(InstancesBasePath, uuid, "name")); len(name) > 0 {
		s.Name = string(name)
	} else {
		return s, errors.New("name missing for: " + uuid)
	}

	if region := c.cache.PathValue(path.Join(InstancesBasePath, uuid, "region")); len(region) > 0 {
		s.Region = string(region)
	} else {
		return s, errors.New("region missing for: " + uuid)
	}

	if version := c.cache.PathValue(path.Join(InstancesBasePath, uuid, "version")); len(version) > 0 {
		s.Version = string(version)
	} else {
		return s, errors.New("version missing for: " + uuid)
	}

	if registered := c.cache.PathValue(path.Join(InstancesBasePath, uuid, "registered")); len(registered) > 0 {
		if string(registered) == "true" {
			s.Registered = true
		} else {
			s.Registered = false
		}
	} else {
		return s, errors.New("registered missing for: " + uuid)
	}

	if addr := c.cache.PathValue(path.Join(InstancesBasePath, uuid, "addr")); len(addr) > 0 {
		s.ServiceAddr, err = skynet.BindAddrFromString(string(addr))
	} else {
		return s, errors.New("addr missing for: " + uuid)
	}

	return
}