Exemple #1
0
func (e *Etcd) GetServices() ([]string, error) {
	servicePath := path.Join(TycoonDir)
	goption := new(client.GetOptions)
	goption.Recursive = true

	Response, err := e.client.Get(context.Background(), servicePath, goption)
	log.Debugf("etcdclient.GetServices():GetServices On etcd Respone %+v", Response)
	if err != nil {
		return nil, err
	}
	nodes := Response.Node.Nodes
	// Unmarshal
	servicesName := make([]string, 0)
	for index := range nodes {
		nodekey := nodes[index].Key
		nodekey = strings.Replace(nodekey, TycoonDir, "", 1)
		servicesName = append(servicesName, nodekey)
	}
	return servicesName, nil
}
Exemple #2
0
func (e *Etcd) GetService(serviceName string) (*service.Service, error) {
	s := new(service.Service)
	servicePath := path.Join(TycoonDir, serviceName)

	goption := new(client.GetOptions)
	goption.Recursive = true

	// etcd get
	Response, err := e.client.Get(context.Background(), servicePath, goption)
	log.Debugf("etcdclient.GetService():GetService On etcd Respone %+v", Response)
	if err != nil {
		return s, err
	}
	nodes := Response.Node.Nodes

	// Unmarshal
	for index := range nodes {
		if nodes[index].Key == servicePath+"/ServiceConfig" {
			sc, err := service.UnmarshalYaml([]byte(nodes[index].Value))
			if err != nil {
				return s, err
			}
			s.ServiceConfig = *sc
		}
		if nodes[index].Key == servicePath+"/ContainerIds" {
			idnodes := nodes[index].Nodes
			ids := make([]string, 0)
			for ids_index := range idnodes {
				ids = append(ids, idnodes[ids_index].Value)
			}
			s.ContainersIds = ids
		}
	}

	return s, err
}