// NewMasterParticipation is part of the topo.Server interface
2753
func (c *Conn) NewMasterParticipation(name, id string) (topo.MasterParticipation, error) {
	c.factory.mu.Lock()
	defer c.factory.mu.Unlock()

	// Make sure the global path exists.
	electionPath := path.Join(electionsPath, name)
	if n := c.factory.getOrCreatePath(c.cell, electionPath); n == nil {
		return nil, topo.NewError(topo.NoNode, electionPath)
	}

	return &cMasterParticipation{
		c:    c,
		name: name,
		id:   id,
		stop: make(chan struct{}),
		done: make(chan struct{}),
	}, nil
}
1061791
func NewMasterCountEndpointReconciler(masterCount int, endpointClient corev1client.EndpointsGetter) EndpointReconciler {
	return &masterCountEndpointReconciler{
		masterCount:    masterCount,
		endpointClient: endpointClient,
	}
}
914760
func ChangeMasterTo(slaveEndpoint, masterEndpoint string, useGTID bool) error {
	var slaveInst, masterInst *Instance
	var exists bool
	var host, portStr string
	var err error
	var port int
	if slaveInst, exists = connectionPool[slaveEndpoint]; !exists {
		return errNotRegistered
	}
	if masterInst, exists = connectionPool[masterEndpoint]; !exists {
		return errNotRegistered
	}
	if host, portStr, err = net.SplitHostPort(masterEndpoint); err != nil {
		return err
	}
	if port, err = strconv.Atoi(portStr); err != nil {
		return err
	}
	if useGTID {
		_, err = slaveInst.connection.Exec("CHANGE MASTER TO MASTER_HOST=?, MASTER_PORT=?, MASTER_USER=?, MASTER_PASSWORD=?, MASTER_AUTO_POSITION=1",
			host, port, masterInst.replUser, masterInst.replPassword)
	} else if masterSt, e := GetMasterStatus(masterEndpoint); e != nil {
		return e
	} else {
		_, err = slaveInst.connection.Exec("CHANGE MASTER TO MASTER_HOST=?, MASTER_PORT=?, MASTER_USER=?, MASTER_PASSWORD=?, MASTER_LOG_FILE=?, MASTER_LOG_POS=?",
			host, port, masterInst.replUser, masterInst.replPassword, masterSt.File, masterSt.Position)
	}
	return err
}
771651
func (ref *SyncProducer) SendMsgToPartition(topic string, partition int32, key sarama.Encoder, msg sarama.Encoder) (*ProducerMessage, error) {
	if msg == nil {
		err := errors.New("nil message can not be sent")
		ref.Error(err)
		return nil, err
	}
	message := &sarama.ProducerMessage{
		Topic:     topic,
		Partition: partition,
		Value:     msg,
		Key:       key,
	}

	partition, offset, err := ref.Producer.SendMessage(message)
	pmsg := &ProducerMessage{
		Topic:     message.Topic,
		Key:       message.Key,
		Value:     message.Value,
		Metadata:  message.Metadata,
		Offset:    offset,
		Partition: partition,
	}
	if err != nil {
		return pmsg, err
	}

	ref.Debugf("message sent: %s", pmsg)
	return pmsg, nil
}
252796
func (zs *Server) NewMasterParticipation(name, id string) (topo.MasterParticipation, error) {
	ctx := context.TODO()

	zkPath := path.Join(zs.root, electionsPath, name)

	// Create the toplevel directory, OK if it exists already.
	// We will create the parent directory as well, but not more.
	if _, err := CreateRecursive(ctx, zs.conn, zkPath, nil, 0, zk.WorldACL(PermDirectory), 1); err != nil && err != zk.ErrNodeExists {
		return nil, convertError(err, zkPath)
	}

	result := &zkMasterParticipation{
		zs:   zs,
		name: name,
		id:   []byte(id),
		done: make(chan struct{}),
	}
	result.stopCtx, result.stopCtxCancel = context.WithCancel(context.Background())
	return result, nil
}
495058
func (m GatewayIDMetadata) ToProto() *pb.Metadata {
	return &pb.Metadata{
		Metadata: &pb.Metadata_GatewayID{
			GatewayID: m.GatewayID,
		},
	}
}
1221022
func NewPartition(pool Pool, buffers ...Buffer) Buffer {
	return &partition{
		Pool: pool,
		List: buffers,
	}
}
290071
func (s *VirtualMachineService) NewAddNicToVirtualMachineParams(networkid string, virtualmachineid string) *AddNicToVirtualMachineParams {
	p := &AddNicToVirtualMachineParams{}
	p.p = make(map[string]interface{})
	p.p["networkid"] = networkid
	p.p["virtualmachineid"] = virtualmachineid
	return p
}
1242964
func (cmt *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
	mentions := markup.FindAllMentions(cmt.Content)
	if err = updateIssueMentions(e, cmt.IssueID, mentions); err != nil {
		return fmt.Errorf("UpdateIssueMentions [%d]: %v", cmt.IssueID, err)
	}

	switch opType {
	case ACTION_COMMENT_ISSUE:
		issue.Content = cmt.Content
	case ACTION_CLOSE_ISSUE:
		issue.Content = fmt.Sprintf("Closed #%d", issue.Index)
	case ACTION_REOPEN_ISSUE:
		issue.Content = fmt.Sprintf("Reopened #%d", issue.Index)
	}
	if err = mailIssueCommentToParticipants(issue, cmt.Poster, mentions); err != nil {
		log.Error(2, "mailIssueCommentToParticipants: %v", err)
	}

	return nil
}
1036971
func (this *FcmClient) NewFcmMsgTo(to string, body interface{}) *FcmClient {
	this.Message.To = to
	this.Message.Data = body

	return this
}
1059490
func (session *ProxySession) AddParticipant(req ParticipantRequest) (response Participant, exception *Exception, err error) {

	twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants")

	res, err := session.twilio.post(participantFormValues(req), twilioUrl)
	if err != nil {
		return response, exception, err
	}
	defer res.Body.Close()

	responseBody, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return response, exception, err
	}

	if res.StatusCode != http.StatusCreated {
		exception = new(Exception)
		err = json.Unmarshal(responseBody, exception)

		// We aren't checking the error because we don't actually care.
		// It's going to be passed to the client either way.
		return response, exception, err
	}

	err = json.Unmarshal(responseBody, &response)
	return response, exception, err

}
1346316
func NewMasterDetector(zkurls string, options ...detector.Option) (*MasterDetector, error) {
	zkHosts, zkPath, err := parseZk(zkurls)
	if err != nil {
		log.Fatalln("Failed to parse url", err)
		return nil, err
	}

	detector := &MasterDetector{
		minDetectorCyclePeriod: defaultMinDetectorCyclePeriod,
		done:   make(chan struct{}),
		cancel: func() {},
	}

	detector.bootstrapFunc = func(client ZKInterface, _ <-chan struct{}) (ZKInterface, error) {
		if client == nil {
			return connect2(zkHosts, zkPath)
		}
		return client, nil
	}

	// apply options last so that they can override default behavior
	for _, opt := range options {
		opt(detector)
	}

	log.V(2).Infoln("Created new detector to watch", zkHosts, zkPath)
	return detector, nil
}
1088731
func (ref *AsyncProducer) SendMsgToPartition(topic string, partition int32, key Encoder, msg Encoder, metadata interface{}) {
	if msg == nil {
		return
	}

	message := &sarama.ProducerMessage{
		Topic:     topic,
		Partition: partition,
		Key:       key,
		Value:     msg,
		Metadata:  metadata,
	}

	ref.Producer.Input() <- message

	ref.Debugf("message sent: %s", message)

	return
}
968635
func (mp *consulMasterParticipation) GetCurrentMasterID(ctx context.Context) (string, error) {
	electionPath := path.Join(mp.s.root, electionsPath, mp.name)
	pair, _, err := mp.s.kv.Get(electionPath, nil)
	if err != nil {
		return "", err
	}
	if pair == nil {
		return "", nil
	}
	return string(pair.Value), nil
}
559620
func (l *s3Objects) NewMultipartUpload(ctx context.Context, bucket string, object string, o minio.ObjectOptions) (uploadID string, err error) {
	// Create PutObject options
	opts := miniogo.PutObjectOptions{UserMetadata: o.UserDefined, ServerSideEncryption: o.ServerSideEncryption}
	uploadID, err = l.Client.NewMultipartUpload(bucket, object, opts)
	if err != nil {
		return uploadID, minio.ErrorRespToObjectError(err, bucket, object)
	}
	return uploadID, nil
}
1314032
func (st *StatsConn) NewMasterParticipation(name, id string) (MasterParticipation, error) {
	startTime := time.Now()
	statsKey := []string{"NewMasterParticipation", st.cell}
	defer topoStatsConnTimings.Record(statsKey, startTime)
	res, err := st.conn.NewMasterParticipation(name, id)
	if err != nil {
		topoStatsConnErrors.Add(statsKey, int64(1))
		return res, err
	}
	return res, err
}
764550
func (s *RelationalDatabase) SetMasterEndpoint(v *RelationalDatabaseEndpoint) *RelationalDatabase {
	s.MasterEndpoint = v
	return s
}