// GetServices finds the list of services and their endpoints from etcd.
// This operation is akin to a set a known good at regular intervals.
GetServices finds the list of services and their endpoints from etcd.
This operation is akin to a set a known good at regular intervals.
// GetServices finds the list of services and their endpoints from etcd . // This operation is akin to a set a known good at regular intervals .
func (s ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error) {
	response, err := s.client.Get(registryRoot+"/specs", true, false)
	if err != nil {
		if tools.IsEtcdNotFound(err) {
			glog.V(4).Infof("Failed to get the key %s: %v", registryRoot, err)
		} else {
			glog.Errorf("Failed to contact etcd for key %s: %v", registryRoot, err)
		}
		return []api.Service{}, []api.Endpoints{}, err
	}
	if response.Node.Dir == true {
		retServices := make([]api.Service, len(response.Node.Nodes))
		retEndpoints := make([]api.Endpoints, len(response.Node.Nodes))
		for i, node := range response.Node.Nodes {
			var svc api.Service
			err = latest.Codec.DecodeInto([]byte(node.Value), &svc)
			if err != nil {
				glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err)
				continue
			}
			retServices[i] = svc
			endpoints, err := s.GetEndpoints(svc.ID)
			if err != nil {
				if tools.IsEtcdNotFound(err) {
					glog.V(4).Infof("Unable to get endpoints for %s : %v", svc.ID, err)
				}
				glog.Errorf("Couldn't get endpoints for %s : %v skipping", svc.ID, err)
				endpoints = api.Endpoints{}
			} else {
				glog.V(3).Infof("Got service: %s on localport %d mapping to: %s", svc.ID, svc.Port, endpoints)
			}
			retEndpoints[i] = endpoints
		}
		return retServices, retEndpoints, err
	}
	return nil, nil, fmt.Errorf("did not get the root of the registry %s", registryRoot)
}
func ( s ConfigSourceEtcd ) GetServices ( ) ( [ ] api . Service , [ ] api . Endpoints , error ) { response , err := s . client . Get ( registryRoot + " " , true , false ) if err != nil { if tools . IsEtcdNotFound ( err ) { glog . V ( 4 ) . Infof ( " " , registryRoot , err ) } else { glog . Errorf ( " " , registryRoot , err ) } return [ ] api . Service { } , [ ] api . Endpoints { } , err } if response . Node . Dir == true { retServices := make ( [ ] api . Service , len ( response . Node . Nodes ) ) retEndpoints := make ( [ ] api . Endpoints , len ( response . Node . Nodes ) ) for i , node := range response . Node . Nodes { var svc api . Service err = latest . Codec . DecodeInto ( [ ] byte ( node . Value ) , & svc ) if err != nil { glog . Errorf ( " " , node . Value , err ) continue } retServices [ i ] = svc endpoints , err := s . GetEndpoints ( svc . ID ) if err != nil { if tools . IsEtcdNotFound ( err ) { glog . V ( 4 ) . Infof ( " " , svc . ID , err ) } glog . Errorf ( " " , svc . ID , err ) endpoints = api . Endpoints { } } else { glog . V ( 3 ) . Infof ( " " , svc . ID , svc . Port , endpoints ) } retEndpoints [ i ] = endpoints } return retServices , retEndpoints , err } return nil , nil , fmt . Errorf ( " " , registryRoot ) }
GetServices finds the list of services and their endpoints from etcd.
GetServices finds the list of services and their endpoints from etcd .
// Ok, so we have directories, this list should be the list // of services. Find the local port to listen on and remote endpoints // and create a Service entry for it.