Exemplo n.º 1
0
func (b *broker) Init(c *component.Component) error {
	b.Component = c
	b.InitStatus()
	err := b.Component.UpdateTokenKey()
	if err != nil {
		return err
	}
	err = b.Component.Announce()
	if err != nil {
		return err
	}
	b.Discovery.GetAll("handler") // Update cache
	var conn *grpc.ClientConn
	if b.nsCert == "" {
		conn, err = api.Dial(b.nsAddr)
	} else {
		conn, err = api.DialWithCert(b.nsAddr, b.nsCert)
	}
	if err != nil {
		return err
	}
	b.nsConn = conn
	b.ns = networkserver.NewNetworkServerClient(conn)
	b.checkPrefixAnnouncements()
	b.Component.SetStatus(component.StatusHealthy)
	return nil
}
Exemplo n.º 2
0
// Dial dials the component represented by this Announcement
func (a *Announcement) Dial() (*grpc.ClientConn, error) {
	if a.NetAddress == "" {
		return nil, errors.New("Can not dial this component")
	}
	if a.Certificate == "" {
		return api.Dial(strings.Split(a.NetAddress, ",")[0])
	}
	return api.DialWithCert(strings.Split(a.NetAddress, ",")[0], a.Certificate)
}