// NewLeaderElectionService returns a new LeaderElectionService
514730
func NewLeaderElectionService(adapter LeaderElectionAdapter, id string, callback leadershipCallback, config ElectionConfig) LeaderElectionService {
	if len(id) == 0 {
		panic("Empty id")
	}
	le := &leaderElectionSvcImpl{
		id:            peerID(id),
		proposals:     util.NewSet(),
		adapter:       adapter,
		stopChan:      make(chan struct{}, 1),
		interruptChan: make(chan struct{}, 1),
		logger:        util.GetLogger(util.ElectionLogger, ""),
		callback:      noopCallback,
		config:        config,
	}

	if callback != nil {
		le.callback = callback
	}

	go le.start()
	return le
}
134751
func (d *MasterDaemon) runLeader() {
	router := mux.NewRouter()

	// Create a new api controller
	apiConfig := &objApi.APIControllerConfig{
		NetForwardMode: d.NetForwardMode,
		NetInfraType:   d.NetInfraType,
	}
	d.apiController = objApi.NewAPIController(router, d.objdbClient, apiConfig)

	//Restore state from clusterStore
	d.restoreCache()

	// Register netmaster service
	d.registerService()

	// initialize policy manager
	mastercfg.InitPolicyMgr(d.stateDriver, d.ofnetMaster)

	// setup HTTP routes
	d.registerRoutes(router)

	d.startListeners(router, d.stopLeaderChan)

	log.Infof("Exiting Leader mode")
}
1151482
func NewLeaderListener(path string) *LeaderListener {
	return &LeaderListener{
		path:     path,
		mu:       &sync.Mutex{},
		watchers: make([]watcher, 0),
	}
}
476370
func NewOptionsGroupSelectBlockElement(
	optType string,
	placeholder *TextBlockObject,
	actionID string,
	optGroups ...*OptionGroupBlockObject,
) *SelectBlockElement {
	return &SelectBlockElement{
		Type:         optType,
		Placeholder:  placeholder,
		ActionID:     actionID,
		OptionGroups: optGroups,
	}
}
706592
func NewTeamService(context servicecontext.ServiceContext) service.TeamService {
	return &teamServiceImpl{base.NewBaseService(context)}
}
211279
func NewService(discovery fab.DiscoveryService) (fab.SelectionService, error) {
	return &SelectionService{discoveryService: discovery}, nil
}
852143
func NewOnboardingService() *OnboardingService {
	return &OnboardingService{
		IsOnboardingFn: func(context.Context) (bool, error) { return false, nil },
		GenerateFn: func(context.Context, *platform.OnboardingRequest) (*platform.OnboardingResults, error) {
			return nil, nil
		},
	}
}
939637
func NewSimpleElection(electionId, id string, callback func(leader string), c client.Interface) (*leaderelection.LeaderElector, error) {
	return NewElection(electionId, id, api.NamespaceDefault, 10*time.Second, callback, c)
}
239219
func (r *realisClient) CreateService(auroraJob Job, settings *aurora.JobUpdateSettings) (*aurora.Response, *aurora.StartJobUpdateResult_, error) {
	// Create a new job update object and ship it to the StartJobUpdate api
	update := NewUpdateJob(auroraJob.TaskConfig(), settings)
	update.InstanceCount(auroraJob.GetInstanceCount())

	resp, err := r.StartJobUpdate(update, "")
	if err != nil {
		return resp, nil, errors.Wrap(err, "unable to create service")
	}

	if resp.GetResult_() != nil {
		return resp, resp.GetResult_().GetStartJobUpdateResult_(), nil
	}

	return nil, nil, errors.New("results object is nil")
}
695257
func (s *Status) RegionLeader(region string) (string, error) {
	var resp string
	q := QueryOptions{Region: region}
	_, err := s.client.query("/v1/status/leader", &resp, &q)
	if err != nil {
		return "", err
	}
	return resp, nil
}
155418
func NewClusterStatsService(client *Client) *ClusterStatsService {
	return &ClusterStatsService{
		client: client,
		nodeId: make([]string, 0),
	}
}
887242
func NewIPService(client *TwilioIPMessagingClient, friendlyName string, defaultServiceRoleSid string, defaultChannelRoleSid string,
	typingIndicatorTimeout time.Duration, webhooks Webhooks) (*IPService, error) {

	timeout, err := durationToISO8601(typingIndicatorTimeout)
	if err != nil {
		return nil, err
	}

	var service *IPService

	params := url.Values{}
	params.Set("FriendlyName", friendlyName)
	params.Set("DefaultServiceRoleSid", defaultServiceRoleSid)
	params.Set("DefaultChannelRoleSid", defaultChannelRoleSid)
	params.Set("TypingIndicatonTimeout", timeout)
	if webhooks != nil {
		for k, v := range webhooks {
			params.Set(k, v)
		}
	}

	res, err := client.post(params, "/Services.json")

	if err != nil {
		return service, err
	}

	service = new(IPService)
	err = json.Unmarshal(res, service)

	return service, err
}
175352
func (r legacyLeadershipReader) Leaders() (map[string]string, error) {
	l, err := r.st.ApplicationLeaders()
	return l, errors.Trace(err)
}
88467
func NewLeadershipServiceFacade(context facade.Context) (LeadershipService, error) {
	claimer, err := context.LeadershipClaimer(context.State().ModelUUID())
	if err != nil {
		return nil, errors.Trace(err)
	}
	return NewLeadershipService(claimer, context.Auth())
}
871417
func NewLeaderElector(lec LeaderElectionConfig) (*LeaderElector, error) {
	if lec.LeaseDuration <= lec.RenewDeadline {
		return nil, fmt.Errorf("leaseDuration must be greater than renewDeadline")
	}
	if lec.RenewDeadline <= time.Duration(JitterFactor*float64(lec.RetryPeriod)) {
		return nil, fmt.Errorf("renewDeadline must be greater than retryPeriod*JitterFactor")
	}
	if lec.LeaseDuration < 1 {
		return nil, fmt.Errorf("leaseDuration must be greater than zero")
	}
	if lec.RenewDeadline < 1 {
		return nil, fmt.Errorf("renewDeadline must be greater than zero")
	}
	if lec.RetryPeriod < 1 {
		return nil, fmt.Errorf("retryPeriod must be greater than zero")
	}

	if lec.Lock == nil {
		return nil, fmt.Errorf("Lock must not be nil.")
	}
	le := LeaderElector{
		config:  lec,
		clock:   clock.RealClock{},
		metrics: globalMetricsFactory.newLeaderMetrics(),
	}
	le.metrics.leaderOff(le.config.Name)
	return &le, nil
}
311548
func (s *ServiceNode) ToNodeService() *NodeService {
	return &NodeService{
		Kind:              s.ServiceKind,
		ID:                s.ServiceID,
		Service:           s.ServiceName,
		Tags:              s.ServiceTags,
		Address:           s.ServiceAddress,
		Port:              s.ServicePort,
		Meta:              s.ServiceMeta,
		Weights:           &s.ServiceWeights,
		EnableTagOverride: s.ServiceEnableTagOverride,
		Proxy:             s.ServiceProxy,
		Connect:           s.ServiceConnect,
		RaftIndex: RaftIndex{
			CreateIndex: s.CreateIndex,
			ModifyIndex: s.ModifyIndex,
		},
	}
}
1062450
func (c *Client) EventService() EventService {
	if c.eventService != nil {
		return c.eventService
	}
	c.connMu.Lock()
	defer c.connMu.Unlock()
	return NewEventServiceFromClient(eventsapi.NewEventsClient(c.conn))
}