// NewSource returns a new Source.
517463
func NewSource(input SourceInput, logger log.Logger) Source {
	s := &source{
		input:  input,
		w:      NewWatchable(),
		logger: logger,
	}

	go s.run()
	return s
}
457183
func (s *SearchService) SearchSource(searchSource *SearchSource) *SearchService {
	s.searchSource = searchSource
	if s.searchSource == nil {
		s.searchSource = NewSearchSource()
	}
	return s
}
303310
func NewSource(options ...Option) *Source {
	src := &Source{
		records:     make(chan record),
		maxRetries:  3,
		concurrency: 1,
	}

	for _, opt := range options {
		opt(src)
	}
	go src.getRecords()
	return src
}
594039
func (s *sourcesImpl) AddSource(source string) {
	s.lock.Lock()
	defer s.lock.Unlock()
	s.sourcesSeen.Insert(source)
}
682923
func (s *ScrollService) SearchSource(searchSource *SearchSource) *ScrollService {
	s.ss = searchSource
	if s.ss == nil {
		s.ss = NewSearchSource()
	}
	return s
}
560468
func (m *Mux) AddSource(source io.Reader) {
	m.m.Lock()
	if m.closed {
		panic("mux: already closed")
	}
	if _, ok := m.readers[source]; ok {
		panic("mux: the io.Reader cannot be added multiple times")
	}
	m.readers[source] = bufio.NewReaderSize(source, 256)
	m.m.Unlock()
}
1340464
func NewSearchSource() *SearchSource {
	return &SearchSource{
		from:            -1,
		size:            -1,
		trackScores:     false,
		sorts:           make([]SortInfo, 0),
		sorters:         make([]Sorter, 0),
		fieldDataFields: make([]string, 0),
		scriptFields:    make([]*ScriptField, 0),
		partialFields:   make([]*PartialField, 0),
		facets:          make(map[string]Facet),
		aggregations:    make(map[string]Aggregation),
		rescores:        make([]*Rescore, 0),
		indexBoosts:     make(map[string]float64),
		stats:           make([]string, 0),
		innerHits:       make(map[string]*InnerHit),
	}
}
1315312
func NewSource(opts ...source.Option) source.Source {
	options := source.NewOptions(opts...)

	// create the client
	client, _ := api.NewClient(api.DefaultConfig())

	// get and set options
	if address := getAddress(options); address != "" {
		_ = client.SetAddress(address)
	}

	if nameSpace := getNameSpace(options); nameSpace != "" {
		client.SetNamespace(nameSpace)
	}

	if token := getToken(options); token != "" {
		client.SetToken(token)
	}

	path := getResourcePath(options)
	name := getSecretName(options)
	if name == "" {
		name = path
	}

	return &vault{
		opts:       options,
		client:     client,
		secretPath: path,
		secretName: name,
	}
}
290689
func NewSchemaSource(schemaName string, ds Source) *Schema {
	m := &Schema{
		Name:         strings.ToLower(schemaName),
		schemas:      make(map[string]*Schema),
		tableMap:     make(map[string]*Table),
		tableSchemas: make(map[string]*Schema),
		tableNames:   make([]string, 0),
		DS:           ds,
	}
	return m
}
911413
func (s *Service) UpdateSource(w http.ResponseWriter, r *http.Request) {
	id, err := paramID("id", r)
	if err != nil {
		Error(w, http.StatusUnprocessableEntity, err.Error(), s.Logger)
		return
	}

	ctx := r.Context()
	src, err := s.Store.Sources(ctx).Get(ctx, id)
	if err != nil {
		notFound(w, id, s.Logger)
		return
	}

	var req chronograf.Source
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		invalidJSON(w, s.Logger)
		return
	}

	src.Default = req.Default
	src.InsecureSkipVerify = req.InsecureSkipVerify
	if req.Name != "" {
		src.Name = req.Name
	}
	if req.Password != "" {
		src.Password = req.Password
	}
	if req.Username != "" {
		src.Username = req.Username
	}
	if req.URL != "" {
		src.URL = req.URL
	}
	// If the supplied MetaURL is different from the
	// one supplied on the request, update the value
	if req.MetaURL != src.MetaURL {
		src.MetaURL = req.MetaURL
	}
	if req.Type != "" {
		src.Type = req.Type
	}
	if req.Telegraf != "" {
		src.Telegraf = req.Telegraf
	}
	src.DefaultRP = req.DefaultRP

	defaultOrg, err := s.Store.Organizations(ctx).DefaultOrganization(ctx)
	if err != nil {
		unknownErrorWithMessage(w, err, s.Logger)
		return
	}

	if err := ValidSourceRequest(&src, defaultOrg.ID); err != nil {
		invalidData(w, err, s.Logger)
		return
	}

	dbType, err := s.tsdbType(ctx, &src)
	if err != nil {
		Error(w, http.StatusBadRequest, "Error contacting source", s.Logger)
		return
	}
	src.Type = dbType

	if err := s.Store.Sources(ctx).Update(ctx, src); err != nil {
		msg := fmt.Sprintf("Error updating source ID %d", id)
		Error(w, http.StatusInternalServerError, msg, s.Logger)
		return
	}
	encodeJSON(w, http.StatusOK, newSourceResponse(context.Background(), src), s.Logger)
}
118572
func (s *Service) DefaultSource(ctx context.Context) (*platform.Source, error) {
	// TODO(desa): make this faster by putting the default source in an index.
	srcs, _, err := s.FindSources(ctx, platform.FindOptions{})
	if err != nil {
		return nil, err
	}

	for _, src := range srcs {
		if src.Default {
			return src, nil
		}
	}
	return nil, &platform.Error{
		Code: platform.ENotFound,
		Msg:  "no default source found",
	}

}
985411
func (s *Service) CreateSource(ctx context.Context, src *influxdb.Source) error {
	err := s.kv.Update(ctx, func(tx Tx) error {
		src.ID = s.IDGenerator.ID()

		// Generating an organization id if it missing or invalid
		if !src.OrganizationID.Valid() {
			src.OrganizationID = s.IDGenerator.ID()
		}

		return s.putSource(ctx, tx, src)
	})
	if err != nil {
		return &influxdb.Error{
			Err: err,
		}
	}
	return nil
}
390512
func (arc *ConfigFactory) AddSource(source core.ConfigSource) error {
	if source == nil {
		return errors.New("source can not be nil")
	}
	if arc.initSuccess == false {
		openlogging.Warn("Plz call factory.Init() first, failed to add source: " + source.GetSourceName())
		return nil
	}

	return arc.configMgr.AddSource(source, source.GetPriority())
}
646382
func (s *Service) CreateSource(ctx context.Context, src *platform.Source) error {
	src.ID = s.IDGenerator.ID()
	if err := s.PutSource(ctx, src); err != nil {
		return &platform.Error{
			Err: err,
		}
	}
	return nil
}
1149014
func (c *Client) UpdateSource(ctx context.Context, id platform.ID, upd platform.SourceUpdate) (*platform.Source, error) {
	var s *platform.Source
	err := c.db.Update(func(tx *bolt.Tx) error {
		src, err := c.updateSource(ctx, tx, id, upd)
		if err != nil {
			return &platform.Error{
				Err: err,
				Op:  getOp(platform.OpUpdateSource),
			}
		}
		s = src
		return nil
	})

	return s, err
}
1209841
func (s *ReindexService) Source(source *ReindexSource) *ReindexService {
	s.source = source
	return s
}
141534
func (h *Client) CampaignSource(campaignSource string) *Client {
	h.campaignSource = campaignSource
	h.campaignSourceSet = true
	return h
}