// maintainRegistrations sets up any configured registrations with the underlying fsgo infrastructure.
// This method does nothing if no registrations are configured.
func (this *curatorDiscovery) maintainRegistrations() error {
	if len(this.registrations) > 0 {
		this.logger.Printf("Maintaining registrations: %s", this.registrations)
		this.serviceDiscovery = discovery.NewServiceDiscovery(this.curatorConnection, this.basePath)
		if err := this.serviceDiscovery.MaintainRegistrations(); err != nil {
			return err
		}

		if err := this.registrations.RegisterWith(this.serviceDiscovery); err != nil {
			return err
		}
	}

	return nil
}
Example #2
0
func (r *Registrations) Join(hostname, base string, configs []*hfile.CollectionConfig, wait time.Duration) {
	if hostname == "localhost" {
		log.Fatal("invalid hostname for service discovery registration:", hostname)
	}

	log.Println("Waiting to join service discovery", wait)
	time.Sleep(wait)
	log.Println("Joining service discovery...")

	r.Lock()
	defer r.Unlock()

	for _, i := range configs {
		sfunc := i.ShardFunction
		capacity := i.TotalPartitions

		if len(sfunc) < 1 {
			capacity = "1"
			sfunc = "_"
		}

		base := fmt.Sprintf("%s/%s/%s", i.ParentName, sfunc, capacity)

		disco := discovery.NewServiceDiscovery(r.zk, curator.JoinPath(Settings.discoveryPath, base))
		if err := disco.MaintainRegistrations(); err != nil {
			log.Fatal(err)
		}
		r.existing = append(r.existing, disco)

		s := discovery.NewSimpleServiceInstance(i.Partition, hostname, Settings.port)
		disco.Register(s)

		if Settings.rpcPort > 0 {
			raw := discovery.NewSimpleServiceInstance(fmt.Sprintf("%st", i.Partition), hostname, Settings.rpcPort)
			disco.Register(raw)
		}
	}
}