예제 #1
0
func (m DefaultManager) AddRegistry(registry *shipyard.Registry) error {

	if err := registry.InitRegistryClient(); err != nil {
		return err
	}

	// TODO: consider not doing a test on adding the record, perhaps have a pingRegistry route that does this through API.
	if err := m.PingRegistry(registry); err != nil {
		log.Error(err)
		return ErrCannotPingRegistry
	}

	if _, err := r.Table(tblNameRegistries).Insert(registry).RunWrite(m.session); err != nil {
		return err
	}
	m.logEvent("add-registry", fmt.Sprintf("name=%s endpoint=%s", registry.Name, registry.Addr), []string{"registry"})

	return nil
}
예제 #2
0
func (m DefaultManager) RegistryByAddress(addr string) (*shipyard.Registry, error) {
	res, err := r.Table(tblNameRegistries).Filter(map[string]string{"addr": addr}).Run(m.session)
	defer res.Close()
	if err != nil {
		return nil, err
	}
	if res.IsNil() {
		log.Debugf("Could not find registry with address %s", addr)
		return nil, ErrRegistryDoesNotExist
	}
	var reg *shipyard.Registry
	if err := res.One(&reg); err != nil {
		return nil, err
	}

	if err := reg.InitRegistryClient(); err != nil {
		log.Error(err)
		return reg, err
	}

	return reg, nil
}
예제 #3
0
func (m DefaultManager) Registry(id string) (*shipyard.Registry, error) {
	res, err := r.Table(tblNameRegistries).Filter(map[string]string{"id": id}).Run(m.session)
	defer res.Close()
	if err != nil {
		return nil, err

	}
	if res.IsNil() {
		return nil, ErrRegistryDoesNotExist
	}
	var reg *shipyard.Registry
	if err := res.One(&reg); err != nil {
		return nil, err
	}

	if err := reg.InitRegistryClient(); err != nil {
		log.Errorf("%s", err.Error())
		return reg, err
	}

	return reg, nil
}