//Register service and keep it registered.
482123
func RegisterService(name string, port int, ttl int) {
	go registerService(name, port, ttl)
}
905311
func (cp *ConsulClient) RegisterService(serviceInfo ServiceInfo) error {
	keyName := "contiv.io/service/" + serviceInfo.ServiceName + "/" +
		serviceInfo.HostAddr + ":" + strconv.Itoa(serviceInfo.Port)

	log.Infof("Registering service key: %s, value: %+v", keyName, serviceInfo)

	// if there is a previously registered service, no need to register it again..
	if cp.serviceDb[keyName] != nil {
		srvState := cp.serviceDb[keyName]
		if (srvState.ServiceName == serviceInfo.ServiceName) && (srvState.HostAddr == serviceInfo.HostAddr) &&
			(srvState.Port == serviceInfo.Port) {
			return nil
		}

		// stop and release the old key
		close(srvState.stopChan)

		// Delete the service instance
		_, err := cp.client.KV().Delete(keyName, nil)
		if err != nil {
			log.Errorf("Error deleting key %s. Err: %v", keyName, err)
			return err
		}
	}

	// JSON format the object
	jsonVal, err := json.Marshal(serviceInfo)
	if err != nil {
		log.Errorf("Json conversion error. Err %v", err)
		return err
	}

	// session configuration
	sessCfg := api.SessionEntry{
		Name:      keyName,
		Behavior:  "delete",
		LockDelay: 10 * time.Millisecond,
		TTL:       fmt.Sprintf("%ds", serviceInfo.TTL),
	}

	// Create consul session
	sessionID, _, err := cp.client.Session().CreateNoChecks(&sessCfg, nil)
	if err != nil {
		log.Errorf("Error Creating session for lock %s. Err: %v", keyName, err)
		return err
	}

	// check if the key already exists
	resp, _, err := cp.client.KV().Get(keyName, nil)
	if err != nil {
		log.Errorf("Error getting key %s. Err: %v", keyName, err)
		return err
	}

	// Delete the old key if it exists..
	if resp != nil {
		log.Infof("Deleting old service entry for key %s", keyName)
		_, err = cp.client.KV().Delete(keyName, nil)
		if err != nil {
			log.Errorf("Error deleting key %s. Err: %v", keyName, err)
			return err
		}
	}

	// Set it via consul client
	succ, _, err := cp.client.KV().Acquire(&api.KVPair{Key: keyName, Value: jsonVal, Session: sessionID}, nil)
	if err != nil {
		log.Errorf("Error setting key %s, Err: %v", keyName, err)
		return err
	}

	if !succ {
		log.Errorf("Failed to acquire key %s. Already acquired", keyName)
		return errors.New("Key already acquired")
	}

	// Run refresh in background
	stopChan := make(chan struct{})
	go cp.renewService(keyName, sessCfg.TTL, sessionID, jsonVal, stopChan)

	// Store it in DB
	cp.serviceDb[keyName] = &consulServiceState{
		ServiceName: serviceInfo.ServiceName,
		TTL:         sessCfg.TTL,
		HostAddr:    serviceInfo.HostAddr,
		Port:        serviceInfo.Port,
		SessionID:   sessionID,
		stopChan:    stopChan,
		Hostname:    serviceInfo.Hostname,
	}

	return nil
}
1302837
func Register() {
	registerMetrics.Do(func() {
		prometheus.MustRegister(zoneHealth)
		prometheus.MustRegister(zoneSize)
		prometheus.MustRegister(unhealthyNodes)
		prometheus.MustRegister(evictionsNumber)
	})
}
313784
func Register(app *gramework.App, serviceName ...string) error {
	var m Middleware
	name := os.Args[0]
	if len(serviceName) > 0 {
		name = serviceName[0]
	}

	hostname, err := os.Hostname()
	if err != nil {
		return err
	}

	m.httpReqCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "gramework_http_requests_total",
			Help: "Total count of HTTP requests processed, partitioned by code, method, path and type (HTTP/HTTPS)",
			ConstLabels: prometheus.Labels{
				"service": name,
				"node":    hostname,
			},
		},
		[]string{"code", "method", "path", "type"},
	)
	if err = prometheus.Register(m.httpReqCounter); err != nil {
		return err
	}

	m.reqDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "gramework_http_requests_duration_seconds",
			Help: "Request processing duration, partitioned by code, method, path and type (HTTP/HTTPS)",
			ConstLabels: prometheus.Labels{
				"service": name,
				"node":    hostname,
			},
		},
		[]string{"code", "method", "path", "type"},
	)

	if err = prometheus.Register(m.reqDuration); err != nil {
		return err
	}

	app.GET(string(metricsPath), gramework.NewGrameHandler(promhttp.Handler()))

	if err = app.UsePre(m.startReq); err != nil {
		return err
	}

	return app.UseAfterRequest(m.endReq)
}
937307
func Register(mock Mock) {
	if Exists(mock) {
		return
	}

	// Make ops thread safe
	mutex.Lock()
	defer mutex.Unlock()

	// Expose mock in request/response for delegation
	mock.Request().Mock = mock
	mock.Response().Mock = mock

	// Registers the mock in the global store
	mocks = append(mocks, mock)
}
1016978
func Register(scheme string, d Backend) error {
	if _, exists := backends[scheme]; exists {
		return fmt.Errorf("scheme already registered %s", scheme)
	}
	logrus.WithField("name", scheme).Debugf("Registering discovery service")
	backends[scheme] = d
	return nil
}
1257637
func Register(callback func(action interface{})) ID {
	idCounter++
	id := idCounter
	callbacks[id] = callback
	return id
}
1028751
func (tsv *TabletServer) Register() {
	for _, f := range RegisterFunctions {
		f(tsv)
	}
	tsv.registerDebugHealthHandler()
	tsv.registerQueryzHandler()
	tsv.registerStreamQueryzHandlers()
	tsv.registerTwopczHandler()
}
827251
func Register(connector *pc.Connector) {
	connector.Register((*Client)(nil), func(client pc.Client) (pc.Service, error) {
		return New(client)
	})
}
954321
func RegisterShhService(stack *node.Node, cfg *whisper.Config) {
	if err := stack.Register(func(n *node.ServiceContext) (node.Service, error) {
		return whisper.New(cfg), nil
	}); err != nil {
		Fatalf("Failed to register the Whisper service: %v", err)
	}
}
228140
func (r *RemoteService) Register(comp component.Component, opts []component.Option) error {
	s := component.NewService(comp, opts)

	if _, ok := r.services[s.Name]; ok {
		return fmt.Errorf("remote: service already defined: %s", s.Name)
	}

	if err := s.ExtractRemote(); err != nil {
		return err
	}

	r.services[s.Name] = s
	// register all remotes
	for name, remote := range s.Remotes {
		remotes[fmt.Sprintf("%s.%s", s.Name, name)] = remote
	}

	return nil
}
68759
func (r *PrefixedRegistry) Register(name string, metric interface{}) error {
	realName := r.prefix + name
	return r.underlying.Register(realName, metric)
}
1298155
func Register(r *Registration) {
	register.Lock()
	defer register.Unlock()
	if r.Type == "" {
		panic(ErrNoType)
	}
	if r.ID == "" {
		panic(ErrNoPluginID)
	}

	var last bool
	for _, requires := range r.Requires {
		if requires == "*" {
			last = true
		}
	}
	if last && len(r.Requires) != 1 {
		panic(ErrInvalidRequires)
	}

	register.r = append(register.r, r)
}
949432
func registerService(objClient objdb.API, ctrlIP, vtepIP, hostname string, vxlanUDPPort int) error {
	// netplugin service info
	srvInfo := objdb.ServiceInfo{
		ServiceName: "netplugin",
		TTL:         10,
		HostAddr:    ctrlIP,
		Port:        netpluginRPCPort1,
		Hostname:    hostname,
	}

	// Register the node with service registry
	err := objClient.RegisterService(srvInfo)
	if err != nil {
		log.Fatalf("Error registering service. Err: %v", err)
		return err
	}

	srvInfo = objdb.ServiceInfo{
		ServiceName: "netplugin",
		TTL:         10,
		HostAddr:    ctrlIP,
		Port:        netpluginRPCPort2,
		Hostname:    hostname,
	}

	// Register the node with service registry
	err = objClient.RegisterService(srvInfo)
	if err != nil {
		log.Fatalf("Error registering service. Err: %v", err)
		return err
	}

	// netplugn VTEP service info
	srvInfo = objdb.ServiceInfo{
		ServiceName: "netplugin.vtep",
		TTL:         10,
		HostAddr:    vtepIP,
		Port:        vxlanUDPPort,
		Hostname:    hostname,
	}

	// Register the node with service registry
	err = objClient.RegisterService(srvInfo)
	if err != nil {
		log.Fatalf("Error registering service. Err: %v", err)
		return err
	}

	log.Infof("Registered netplugin service with registry")
	return nil
}
1312065
func (s *Script) Register(bus *evbus.EventBus, context *context.Context) { //returns args and volumes to mount
	bus.Subscribe("artemide:start", Start)                                                  //Subscribing to artemide:start, Hello will be called
	bus.Subscribe("artemide:artifact:recipe:script:event:after_unpack", afterUnpackHandler) //Subscribing to artemide:artifact:recipe:script:event:after_unpack, the After unpack handler
}
857638
func (c *Client) Register(request *RegistrationRequest) (string, error) {
	ca, err := newCAClient(c.ctx, c.orgName)
	if err != nil {
		return "", err
	}

	var a []mspapi.Attribute
	for i := range request.Attributes {
		a = append(a, mspapi.Attribute{Name: request.Attributes[i].Name, Value: request.Attributes[i].Value, ECert: request.Attributes[i].ECert})
	}

	r := mspapi.RegistrationRequest{
		Name:           request.Name,
		Type:           request.Type,
		MaxEnrollments: request.MaxEnrollments,
		Affiliation:    request.Affiliation,
		Attributes:     a,
		CAName:         request.CAName,
		Secret:         request.Secret,
	}
	return ca.Register(&r)
}
532160
func (mgr *MockCAClient) Register(request *api.RegistrationRequest) (string, error) {
	return "", errors.New("not implemented")
}