// UpdateEndpoints reconfigures the connection to use the given endpoints.
506983
func (c *clusterConnection) UpdateEndpoints(endpoints []string) error {
	if len(endpoints) == 0 {
		return driver.WithStack(driver.InvalidArgumentError{Message: "Must provide at least 1 endpoint"})
	}
	sort.Strings(endpoints)
	if strings.Join(endpoints, ",") == strings.Join(c.endpoints, ",") {
		// No changes
		return nil
	}

	// Create new connections
	servers := make([]driver.Connection, 0, len(endpoints))
	for _, ep := range endpoints {
		conn, err := c.connectionBuilder(ep)
		if err != nil {
			return driver.WithStack(err)
		}
		if c.auth != nil {
			conn, err = conn.SetAuthentication(c.auth)
			if err != nil {
				return driver.WithStack(err)
			}
		}
		servers = append(servers, conn)
	}

	// Swap connections
	c.mutex.Lock()
	defer c.mutex.Unlock()
	c.servers = servers
	c.endpoints = endpoints
	c.current = 0

	return nil
}
488929
func (s *RemoteApplication) AddEndpoints(eps []charm.Relation) error {
	newEps := make([]remoteEndpointDoc, len(eps))
	for i, ep := range eps {
		newEps[i] = remoteEndpointDoc{
			Name:      ep.Name,
			Role:      ep.Role,
			Interface: ep.Interface,
			Limit:     ep.Limit,
			Scope:     ep.Scope,
		}
	}

	model, err := s.st.Model()
	if err != nil {
		return errors.Trace(err)
	} else if model.Life() != Alive {
		return errors.Errorf("model is no longer alive")
	}

	checkCompatibleEndpoints := func(currentEndpoints []Endpoint) error {
		// Ensure there are no current endpoints with the same name as
		// any of those we want to update.
		currentEndpointNames := set.NewStrings()
		for _, ep := range currentEndpoints {
			currentEndpointNames.Add(ep.Name)
		}
		for _, r := range eps {
			if currentEndpointNames.Contains(r.Name) {
				return errors.AlreadyExistsf("endpoint %v", r.Name)
			}
		}
		return nil
	}

	currentEndpoints, err := s.Endpoints()
	if err != nil {
		return errors.Trace(err)
	}
	if err := checkCompatibleEndpoints(currentEndpoints); err != nil {
		return err
	}
	applicationID := s.st.docID(s.Name())
	buildTxn := func(attempt int) ([]txn.Op, error) {
		// If we've tried once already and failed, check that
		// model may have been destroyed.
		if attempt > 0 {
			if err := checkModelActive(s.st); err != nil {
				return nil, errors.Trace(err)
			}
			if err = s.Refresh(); err != nil {
				return nil, errors.Trace(err)
			}
			currentEndpoints, err = s.Endpoints()
			if err != nil {
				return nil, errors.Trace(err)
			}
			if err := checkCompatibleEndpoints(currentEndpoints); err != nil {
				return nil, err
			}
		}
		ops := []txn.Op{
			model.assertActiveOp(),
			{
				C:  remoteApplicationsC,
				Id: applicationID,
				Assert: bson.D{
					{"endpoints", bson.D{{
						"$not", bson.D{{
							"$elemMatch", bson.D{{
								"$in", newEps}},
						}},
					}}},
				},
				Update: bson.D{
					{"$addToSet", bson.D{{"endpoints", bson.D{{"$each", newEps}}}}},
				},
			},
		}
		return ops, nil
	}
	if err := s.st.db().Run(buildTxn); err != nil {
		return errors.Trace(err)
	}
	return s.Refresh()
}
138005
func ModifyEndpointSettings(endpointId string, request *ModifyEndpointSettingRequest) error {
	logrus.Debugf("hcn::HostComputeEndpoint::ModifyEndpointSettings id=%s", endpointId)

	endpointSettingsRequest, err := json.Marshal(request)
	if err != nil {
		return err
	}

	_, err = modifyEndpoint(endpointId, string(endpointSettingsRequest))
	if err != nil {
		return err
	}
	return nil
}
867492
func updateEndpointBindingsOp(st *State, key string, givenMap map[string]string, newMeta *charm.Meta) (txn.Op, error) {
	// Fetch existing bindings.
	existingMap, txnRevno, err := readEndpointBindings(st, key)
	if err != nil && !errors.IsNotFound(err) {
		return txn.Op{}, errors.Trace(err)
	}

	// Merge existing with given as needed.
	updatedMap, isModified, err := mergeBindings(givenMap, existingMap, newMeta)
	if err != nil {
		return txn.Op{}, errors.Trace(err)
	}

	// Validate the bindings before updating.
	if err := validateEndpointBindingsForCharm(st, updatedMap, newMeta); err != nil {
		return txn.Op{}, errors.Trace(err)
	}

	if !isModified {
		return txn.Op{}, jujutxn.ErrNoOperations
	}

	// Prepare the update operations.
	escaped := make(bson.M, len(updatedMap))
	for endpoint, space := range updatedMap {
		escaped[utils.EscapeKey(endpoint)] = space
	}

	updateOp := txn.Op{
		C:      endpointBindingsC,
		Id:     key,
		Update: bson.M{"$set": bson.M{"bindings": escaped}},
	}
	if existingMap != nil {
		// Only assert existing haven't changed when they actually exist.
		updateOp.Assert = bson.D{{"txn-revno", txnRevno}}
	}
	return updateOp, nil
}
893342
func (cp *connProducer) GetEndpoints() []string {
	cp.RLock()
	defer cp.RUnlock()
	return cp.endpoints
}
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
}
135186
func (d *OvsDriver) UpdateEndpointGroup(id string) error {
	log.Infof("Received endpoint group update for %s", id)
	var (
		err          error
		epgBandwidth int64
		sw           *OvsSwitch
	)
	//gets the EndpointGroupState object
	cfgEpGroup := &mastercfg.EndpointGroupState{}
	cfgEpGroup.StateDriver = d.oper.StateDriver
	err = cfgEpGroup.Read(id)
	if err != nil {
		return err
	}

	if cfgEpGroup.ID != "" {
		if cfgEpGroup.Bandwidth != "" {
			epgBandwidth = netutils.ConvertBandwidth(cfgEpGroup.Bandwidth)
		}

		d.oper.localEpInfoMutex.Lock()
		defer d.oper.localEpInfoMutex.Unlock()
		for _, epInfo := range d.oper.LocalEpInfo {
			if epInfo.EpgKey == id {
				log.Debugf("Applying bandwidth: %s on: %s ", cfgEpGroup.Bandwidth, epInfo.Ovsportname)
				// Find the switch based on network type
				if epInfo.BridgeType == "vxlan" {
					sw = d.switchDb["vxlan"]
				} else {
					sw = d.switchDb["vlan"]
				}

				// update the endpoint in ovs switch
				err = sw.UpdateEndpoint(epInfo.Ovsportname, cfgEpGroup.Burst, cfgEpGroup.DSCP, epgBandwidth)
				if err != nil {
					log.Errorf("Error adding bandwidth %v , err: %+v", epgBandwidth, err)
					return err
				}
			}
		}
	}
	return err
}
820680
func (s *Server) setupEndpoints() {
	containerController := controller.NewContainerController(s.container)
	characteristicsController := controller.NewCharacteristicController(s.container)
	pairingController := pair.NewPairingController(s.database)

	s.Mux.Handle("/pair-setup", endpoint.NewPairSetup(s.context, s.device, s.database, s.emitter))
	s.Mux.Handle("/pair-verify", endpoint.NewPairVerify(s.context, s.database))
	s.Mux.Handle("/accessories", endpoint.NewAccessories(containerController, s.mutex))
	s.Mux.Handle("/characteristics", endpoint.NewCharacteristics(s.context, characteristicsController, s.mutex))
	s.Mux.Handle("/pairings", endpoint.NewPairing(pairingController, s.emitter))
	s.Mux.Handle("/identify", endpoint.NewIdentify(containerController))
}
1044880
func (s *RestApi) SetEndpointConfiguration(v *EndpointConfiguration) *RestApi {
	s.EndpointConfiguration = v
	return s
}
147191
func (s *EndpointGroup) SetEndpointDescriptions(v []*EndpointDescription) *EndpointGroup {
	s.EndpointDescriptions = v
	return s
}
84988
func (s *ListEndpointGroupsOutput) SetEndpointGroups(v []*EndpointGroup) *ListEndpointGroupsOutput {
	s.EndpointGroups = v
	return s
}
555746
func (s *DeleteEndpointOutput) SetEndpoint(v *Endpoint) *DeleteEndpointOutput {
	s.Endpoint = v
	return s
}
887110
func (c *clusterConnection) Endpoints() []string {
	c.mutex.RLock()
	defer c.mutex.RUnlock()

	var result []string
	for _, s := range c.servers {
		result = append(result, s.Endpoints()...)
	}
	return result
}
1159445
func (s *EndpointRequest) SetEndpointStatus(v string) *EndpointRequest {
	s.EndpointStatus = &v
	return s
}
643679
func (s *MessageRequest) SetEndpoints(v map[string]*EndpointSendConfiguration) *MessageRequest {
	s.Endpoints = v
	return s
}
1014088
func UpdateEndpointGroup(bandwidth, groupName, tenantName string, Dscp, burst int) error {

	// Get the state driver - get the etcd driver state
	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		return err
	}

	key := mastercfg.GetEndpointGroupKey(groupName, tenantName)
	if key == "" {
		return errors.New("error finding endpointGroup key ")
	}

	// Read etcd driver
	epCfg := mastercfg.EndpointGroupState{}
	epCfg.StateDriver = stateDriver

	err = epCfg.Read(key)
	if err != nil {
		log.Errorf("Error finding endpointgroup %s. Err: %v", key, err)
		return err
	}

	//update the epGroup state
	epCfg.DSCP = Dscp
	epCfg.Bandwidth = bandwidth
	epCfg.Burst = burst

	//Write to etcd
	return epCfg.Write()
}
434645
func (s *SourceRegion) SetEndpoint(v string) *SourceRegion {
	s.Endpoint = &v
	return s
}