// <endpointsMap> is updated by this function (based on the given changes).
// <changes> map is cleared after applying them.
775862
func (proxier *Proxier) updateEndpointsMap() (result updateEndpointMapResult) {
	result.staleEndpoints = make(map[endpointServicePair]bool)
	result.staleServiceNames = make(map[proxy.ServicePortName]bool)

	var endpointsMap proxyEndpointsMap = proxier.endpointsMap
	var changes *endpointsChangeMap = &proxier.endpointsChanges

	func() {
		changes.lock.Lock()
		defer changes.lock.Unlock()
		for _, change := range changes.items {
			endpointsMap.unmerge(change.previous, proxier.serviceMap)
			endpointsMap.merge(change.current, proxier.serviceMap)
		}
		changes.items = make(map[types.NamespacedName]*endpointsChange)
	}()

	// TODO: If this will appear to be computationally expensive, consider
	// computing this incrementally similarly to endpointsMap.
	result.hcEndpoints = make(map[types.NamespacedName]int)
	localIPs := getLocalIPs(endpointsMap)
	for nsn, ips := range localIPs {
		result.hcEndpoints[nsn] = len(ips)
	}

	return result
}
489944
func (s *ElasticsearchDomainStatus) SetEndpoints(v map[string]*string) *ElasticsearchDomainStatus {
	s.Endpoints = v
	return s
}
376076
func (s *Container) SetEndpoint(v string) *Container {
	s.Endpoint = &v
	return s
}
101504
func ValidateEndpoints(endpoints *api.Endpoints) field.ErrorList {
	allErrs := ValidateObjectMeta(&endpoints.ObjectMeta, true, ValidateEndpointsName, field.NewPath("metadata"))
	allErrs = append(allErrs, validateEndpointSubsets(endpoints.Subsets, field.NewPath("subsets"))...)
	return allErrs
}
619133
func UpdateEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) (interface{}, error) {

	var epUpdReq UpdateEndpointRequest

	// Get object from the request
	err := json.NewDecoder(r.Body).Decode(&epUpdReq)

	if err != nil {
		log.Errorf("Error decoding EndpointUpdateRequest. Err %v", err)
		return nil, err
	}

	log.Infof("Received EndpointUpdateRequest {%+v}", epUpdReq)

	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		return nil, err
	}

	if epUpdReq.Event == "start" {
		//Received container start event from netplugin. Check if the Provider
		//matches any service and perform service provider update if there is a matching
		//service.

		epCfg := &mastercfg.CfgEndpointState{}
		epCfg.StateDriver = stateDriver

		nwCfg := &mastercfg.CfgNetworkState{}
		nwCfg.StateDriver = stateDriver
		//check if networkname is epg name or network name
		key := mastercfg.GetNwCfgKey(epUpdReq.Network, epUpdReq.Tenant)
		err := nwCfg.Read(key)
		if err != nil {
			if !strings.Contains(err.Error(), "key not found") {
				return nil, err
			}
			//If network is not found then networkname is epg
			epgCfg := &mastercfg.EndpointGroupState{}
			epgCfg.StateDriver = stateDriver
			key = mastercfg.GetEndpointGroupKey(epUpdReq.Network, epUpdReq.Tenant)
			err := epgCfg.Read(key)
			if err != nil {
				return nil, err
			}
			//get the network associated with the endpoint group
			key = mastercfg.GetNwCfgKey(epgCfg.NetworkName, epUpdReq.Tenant)
		}

		epCfg.ID = getEpName(key, &intent.ConfigEP{Container: epUpdReq.EndpointID})

		err = epCfg.Read(epCfg.ID)
		if err != nil {
			return nil, err
		}

		provider := &mastercfg.Provider{}
		provider.IPAddress = epUpdReq.IPAddress
		provider.Tenant = epUpdReq.Tenant
		provider.Network = epUpdReq.Network
		provider.ContainerID = epUpdReq.ContainerID
		provider.Labels = make(map[string]string)

		if epCfg.Labels == nil {
			//endpoint cfg doesnt have labels
			epCfg.Labels = make(map[string]string)
		}

		for k, v := range epUpdReq.Labels {
			provider.Labels[k] = v
			epCfg.Labels[k] = v
		}
		provider.EpIDKey = epCfg.ID
		//maintain the containerId in endpointstat for recovery
		epCfg.ContainerID = epUpdReq.ContainerID
		epCfg.EPCommonName = epUpdReq.EPCommonName

		err = epCfg.Write()
		if err != nil {
			log.Errorf("error writing ep config. Error: %s", err)
			return nil, err
		}

		providerID := getProviderID(provider)
		providerDbID := getProviderDbID(provider)
		if providerID == "" || providerDbID == "" {
			return nil, fmt.Errorf("invalid ProviderID from providerInfo:{%v}", provider)
		}

		//update provider db
		mastercfg.SvcMutex.Lock()
		mastercfg.ProviderDb[providerDbID] = provider

		for serviceID, service := range mastercfg.ServiceLBDb {
			count := 0
			if service.Tenant == epUpdReq.Tenant {
				for key, value := range epUpdReq.Labels {
					if val := service.Selectors[key]; val == value {
						count++
					}

					if count == len(service.Selectors) {
						//Container corresponds to the service since it
						//matches all service Selectors
						mastercfg.ProviderDb[providerDbID].Services =
							append(mastercfg.ProviderDb[providerDbID].Services, serviceID)
							//Update ServiceDB
						mastercfg.ServiceLBDb[serviceID].Providers[providerID] = provider

						serviceLbState := &mastercfg.CfgServiceLBState{}
						serviceLbState.StateDriver = stateDriver
						err = serviceLbState.Read(serviceID)
						if err != nil {
							mastercfg.SvcMutex.Unlock()
							return nil, err
						}
						serviceLbState.Providers[providerID] = provider
						serviceLbState.Write()
						SvcProviderUpdate(serviceID, false)
						break
					}
				}
			}
		}
		mastercfg.SvcMutex.Unlock()

	} else if epUpdReq.Event == "die" {
		//Received a container die event. If it was a service provider -
		//clear the provider db and the service db and change the etcd state

		providerDbID := epUpdReq.ContainerID
		if providerDbID == "" {
			return nil, fmt.Errorf("invalid containerID in UpdateEndpointRequest:(nil)")
		}

		mastercfg.SvcMutex.Lock()
		provider := mastercfg.ProviderDb[providerDbID]
		if provider == nil {
			mastercfg.SvcMutex.Unlock()
			// It is not a provider . Ignore event
			return nil, nil
		}

		for _, serviceID := range provider.Services {
			service := mastercfg.ServiceLBDb[serviceID]
			providerID := getProviderID(provider)
			if providerID == "" {
				mastercfg.SvcMutex.Unlock()
				return nil, fmt.Errorf("invalid ProviderID from providerInfo:{%v}", provider)
			}
			if service.Providers[providerID] != nil {
				delete(service.Providers, providerID)

				serviceLbState := &mastercfg.CfgServiceLBState{}
				serviceLbState.StateDriver = stateDriver
				err = serviceLbState.Read(serviceID)
				if err != nil {
					mastercfg.SvcMutex.Unlock()
					return nil, err
				}
				delete(serviceLbState.Providers, providerID)
				serviceLbState.Write()
				delete(mastercfg.ProviderDb, providerDbID)
				SvcProviderUpdate(serviceID, false)

			}
		}
		mastercfg.SvcMutex.Unlock()

	}

	epUpdResp := &UpdateEndpointResponse{
		IPAddress: epUpdReq.IPAddress,
	}
	return epUpdResp, nil
}
404821
func (c *endpointCache) Endpoints() ([]endpoint.Endpoint, error) {
	// in the steady state we're going to have many goroutines calling Endpoints()
	// concurrently, so to minimize contention we use a shared R-lock.
	c.mtx.RLock()

	if c.err == nil || c.timeNow().Before(c.invalidateDeadline) {
		defer c.mtx.RUnlock()
		return c.endpoints, nil
	}

	c.mtx.RUnlock()

	// in case of an error, switch to an exclusive lock.
	c.mtx.Lock()
	defer c.mtx.Unlock()

	// re-check condition due to a race between RUnlock() and Lock().
	if c.err == nil || c.timeNow().Before(c.invalidateDeadline) {
		return c.endpoints, nil
	}

	c.updateCache(nil) // close any remaining active endpoints
	return nil, c.err
}
1164501
func (a *Client) PatchEndpointID(params *PatchEndpointIDParams) (*PatchEndpointIDOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewPatchEndpointIDParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "PatchEndpointID",
		Method:             "PATCH",
		PathPattern:        "/endpoint/{id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &PatchEndpointIDReader{formats: a.formats},
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	return result.(*PatchEndpointIDOK), nil

}
990602
func (s *ElasticsearchAction) SetEndpoint(v string) *ElasticsearchAction {
	s.Endpoint = &v
	return s
}
264144
func (c *client) updateSmap(sub *subscription, delta int32) {
	key := keyFromSub(sub)

	c.mu.Lock()
	n := c.leaf.smap[key]
	// We will update if its a queue, if count is zero (or negative), or we were 0 and are N > 0.
	update := sub.queue != nil || n == 0 || n+delta <= 0
	n += delta
	if n > 0 {
		c.leaf.smap[key] = n
	} else {
		delete(c.leaf.smap, key)
	}
	if update {
		c.sendLeafNodeSubUpdate(key, n)
	}
	c.mu.Unlock()
}
819744
func endpoints(members discovery.Members) [][]string {
	var currView [][]string
	for _, member := range members {
		ep := member.Endpoint
		epi := member.InternalEndpoint
		var endPoints []string
		if ep != epi {
			endPoints = append(endPoints, ep, epi)
		} else {
			endPoints = append(endPoints, ep)
		}
		currView = append(currView, endPoints)
	}
	return currView
}
106266
func maps(e CtEndpoint, ipv4, ipv6 bool) []*Map {
	result := make([]*Map, 0, mapCount)
	if e == nil {
		if ipv4 {
			result = append(result, NewMap(MapNameTCP4Global, MapTypeIPv4TCPGlobal))
			result = append(result, NewMap(MapNameAny4Global, MapTypeIPv4AnyGlobal))
		}
		if ipv6 {
			result = append(result, NewMap(MapNameTCP6Global, MapTypeIPv6TCPGlobal))
			result = append(result, NewMap(MapNameAny6Global, MapTypeIPv6AnyGlobal))
		}
	} else {
		if ipv4 {
			result = append(result, NewMap(bpf.LocalMapName(MapNameTCP4, uint16(e.GetID())),
				MapTypeIPv4TCPLocal))
			result = append(result, NewMap(bpf.LocalMapName(MapNameAny4, uint16(e.GetID())),
				MapTypeIPv4AnyLocal))
		}
		if ipv6 {
			result = append(result, NewMap(bpf.LocalMapName(MapNameTCP6, uint16(e.GetID())),
				MapTypeIPv6TCPLocal))
			result = append(result, NewMap(bpf.LocalMapName(MapNameAny6, uint16(e.GetID())),
				MapTypeIPv6AnyLocal))
		}
	}
	return result
}
204913
func (s *RemoteApplication) Endpoints() ([]Endpoint, error) {
	return remoteEndpointDocsToEndpoints(s.Name(), s.doc.Endpoints), nil
}
760248
func DefaultEndpointBindingsForCharm(charmMeta *charm.Meta) map[string]string {
	allRelations := charmMeta.CombinedRelations()
	bindings := make(map[string]string, len(allRelations)+len(charmMeta.ExtraBindings))
	for name := range allRelations {
		bindings[name] = environs.DefaultSpaceName
	}
	for name := range charmMeta.ExtraBindings {
		bindings[name] = environs.DefaultSpaceName
	}
	return bindings
}
1246467
func (a *Application) EndpointBindings() (map[string]string, error) {
	// We don't need the TxnRevno below.
	bindings, _, err := readEndpointBindings(a.st, a.globalKey())
	if err != nil && !errors.IsNotFound(err) {
		return nil, errors.Trace(err)
	}
	if bindings == nil {
		bindings, err = a.defaultEndpointBindings()
		if err != nil {
			return nil, errors.Trace(err)
		}
	}
	return bindings, nil
}
1163985
func (e *Endpoint) DeleteMapsLocked() []error {
	var errors []error

	maps := map[string]string{
		"config": e.BPFConfigMapPath(),
		"policy": e.PolicyMapPathLocked(),
		"calls":  e.CallsMapPathLocked(),
		"egress": e.BPFIpvlanMapPath(),
	}
	for name, path := range maps {
		if err := os.RemoveAll(path); err != nil {
			errors = append(errors, fmt.Errorf("unable to remove %s map file %s: %s", name, path, err))
		}
	}

	if e.ConntrackLocalLocked() {
		// Remove local connection tracking maps
		for _, m := range ctmap.LocalMaps(e, option.Config.EnableIPv4, option.Config.EnableIPv6) {
			ctPath, err := m.Path()
			if err == nil {
				err = os.RemoveAll(ctPath)
			}
			if err != nil {
				errors = append(errors, fmt.Errorf("unable to remove CT map %s: %s", ctPath, err))
			}
		}
	}

	// Remove handle_policy() tail call entry for EP
	if err := policymap.RemoveGlobalMapping(uint32(e.ID)); err != nil {
		errors = append(errors, fmt.Errorf("unable to remove endpoint from global policy map: %s", err))
	}

	return errors
}
434645
func (s *SourceRegion) SetEndpoint(v string) *SourceRegion {
	s.Endpoint = &v
	return s
}
432497
func (v *version) Endpoints() EndpointsInformer {
	return &endpointsInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}