// Leaders (leadership.Reader) returns all application leaders in the
// current model according to state.
175352
func (r legacyLeadershipReader) Leaders() (map[string]string, error) {
	l, err := r.st.ApplicationLeaders()
	return l, errors.Trace(err)
}
299878
func (s *Store) Leader() string {
	if s.raft == nil {
		return ""
	}
	return s.raft.Leader()
}
316780
func (w *upgradeSeriesWorker) unpinLeaders() error {
	results, err := w.UnpinMachineApplications()
	if err != nil {
		return errors.Trace(err)
	}

	var lastErr error
	for app, err := range results {
		if err == nil {
			w.logger.Infof("unpinned leader for application %q", app)
			continue
		}
		w.logger.Errorf("failed to unpin leader for application %q: %s", app, err.Error())
		lastErr = err
	}

	if lastErr == nil {
		w.leadersPinned = false
		return nil
	}
	return errors.Trace(lastErr)
}
63193
func (c *Client) GetStateFromLeader() (*State, error) {
	resp, err := c.GetHTTPResponseFromLeader(c.GetURLForStateFilePid)
	return c.parseStateResponse(resp, err)
}
828403
func (lsa *LeadershipSettingsAccessor) Read(bulkArgs params.Entities) (params.GetLeadershipSettingsBulkResults, error) {

	requireAppName, err := lsa.callerApplication()
	if err != nil {
		return params.GetLeadershipSettingsBulkResults{}, err
	}
	results := make([]params.GetLeadershipSettingsResult, len(bulkArgs.Entities))

	for i, arg := range bulkArgs.Entities {
		result := &results[i]

		// TODO(fwereade): we shoudn't assume a ApplicationTag: we should
		// use an actual auth func to determine permissions.
		applicationTag, err := names.ParseApplicationTag(arg.Tag)
		if err != nil {
			result.Error = common.ServerError(err)
			continue
		}

		appName := applicationTag.Id()
		if appName != requireAppName {
			result.Error = common.ServerError(common.ErrPerm)
			continue
		}

		settings, err := lsa.getSettingsFn(appName)
		if err != nil {
			result.Error = common.ServerError(err)
			continue
		}

		result.Settings = settings
	}

	return params.GetLeadershipSettingsBulkResults{results}, nil
}
68743
func (m *leadershipService) ClaimLeadership(args params.ClaimLeadershipBulkParams) (params.ClaimLeadershipBulkResults, error) {

	results := make([]params.ErrorResult, len(args.Params))
	for pIdx, p := range args.Params {

		result := &results[pIdx]
		applicationTag, unitTag, err := parseApplicationAndUnitTags(p.ApplicationTag, p.UnitTag)
		if err != nil {
			result.Error = common.ServerError(err)
			continue
		}
		duration := time.Duration(p.DurationSeconds * float64(time.Second))
		if duration > MaxLeaseRequest || duration < MinLeaseRequest {
			result.Error = common.ServerError(errors.New("invalid duration"))
			continue
		}

		// In the future, situations may arise wherein units will make
		// leadership claims for other units. For now, units can only
		// claim leadership for themselves, for their own service.
		authTag := m.authorizer.GetAuthTag()
		canClaim := false
		switch authTag.(type) {
		case names.UnitTag:
			canClaim = m.authorizer.AuthOwner(unitTag) && m.authMember(applicationTag)
		case names.ApplicationTag:
			canClaim = m.authorizer.AuthOwner(applicationTag)
		}
		if !canClaim {
			result.Error = common.ServerError(common.ErrPerm)
			continue
		}
		if err = m.claimer.ClaimLeadership(applicationTag.Id(), unitTag.Id(), duration); err != nil {
			result.Error = common.ServerError(err)
		}
	}

	return params.ClaimLeadershipBulkResults{results}, nil
}
416532
func (e *SyncedEnforcer) GetAllRoles() []string {
	e.m.RLock()
	defer e.m.RUnlock()
	return e.Enforcer.GetAllRoles()
}
180030
func (st *State) LeadershipClaimer() leadership.Claimer {
	return leadershipClaimer{
		lazyLeaseClaimer{func() (lease.Claimer, error) {
			manager := st.workers.leadershipManager()
			return manager.Claimer(applicationLeadershipNamespace, st.modelUUID())
		}},
	}
}
22321
func (c *Client) GetStateSummaryFromLeader() (*State, error) {
	resp, err := c.GetHTTPResponseFromLeader(c.GetURLForStateSummaryFilePid)
	return c.parseStateResponse(resp, err)
}
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
}
871760
func (ctx *facadeContext) LeadershipClaimer(modelUUID string) (leadership.Claimer, error) {
	if ctx.r.shared.featureEnabled(feature.LegacyLeases) {
		if modelUUID != ctx.State().ModelUUID() {
			return nil, errors.Errorf("can't get leadership claimer for different model with legacy lease manager")
		}
		return ctx.State().LeadershipClaimer(), nil
	}
	claimer, err := ctx.r.shared.leaseManager.Claimer(
		lease.ApplicationLeadershipNamespace,
		modelUUID,
	)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return leadershipClaimer{claimer}, nil
}
548379
func (m leadershipPinner) PinLeadership(applicationName string, entity string) error {
	return errors.Trace(m.pinner.Pin(applicationName, entity))
}
208029
func (s *Status) Leader(args *structs.GenericRequest, reply *string) error {
	if args.Region == "" {
		args.Region = s.srv.config.Region
	}
	if done, err := s.srv.forward("Status.Leader", args, args, reply); done {
		return err
	}

	leader := string(s.srv.raft.Leader())
	if leader != "" {
		*reply = leader
	} else {
		*reply = ""
	}
	return nil
}
1344728
func (gp *EpgPolicy) ReadAll() ([]core.State, error) {
	return gp.StateDriver.ReadAllState(policyConfigPathPrefix, gp, json.Unmarshal)
}
1016198
func (m leadershipChecker) LeadershipCheck(applicationName, unitName string) leadership.Token {
	token := m.checker.Token(applicationName, unitName)
	return leadershipToken{
		applicationName: applicationName,
		unitName:        unitName,
		token:           token,
	}
}
1108183
func (n *Node) doRaftLeader(conn redcon.Conn, cmd redcon.Command) (interface{}, error) {
	if len(cmd.Args) != 1 {
		return nil, ErrWrongNumberOfArguments
	}
	leader := n.raft.Leader()
	if leader == "" {
		conn.WriteNull()
	} else {
		conn.WriteBulkString(leader)
	}
	return nil, nil
}
204784
func (s *EndpointGroupState) ReadAll() ([]core.State, error) {
	return s.StateDriver.ReadAllState(epGroupConfigPathPrefix, s, json.Unmarshal)
}