// populateSources create all the graph required for the story and
// populates it with the provided data.
323059
func (s *Story) populateSources(ctx context.Context, st storage.Store, b literal.Builder) error {
	for _, src := range s.Sources {
		g, err := getGraphFromStore(ctx, st, src.ID)
		if err != nil {
			return err
		}
		var trps []*triple.Triple
		for _, trp := range src.Facts {
			t, err := triple.Parse(trp, b)
			if err != nil {
				return err
			}
			trps = append(trps, t)
		}
		if err := g.AddTriples(ctx, trps); err != nil {
			return err
		}
	}
	return nil
}
828929
func (s *EventSelector) SetDataResources(v []*DataResource) *EventSelector {
	s.DataResources = v
	return s
}
664905
func populateVolumeOptions(pluginName, pvcName string, capacityGB resource.Quantity, tags map[string]string, storageParams map[string]string, node *v1.Node, allowedTopologies []v1.TopologySelectorTerm, zonesWithNodes sets.String) (*aws.VolumeOptions, error) {
	requestGiB, err := volumehelpers.RoundUpToGiBInt(capacityGB)
	if err != nil {
		return nil, err
	}

	volumeOptions := &aws.VolumeOptions{
		CapacityGB: requestGiB,
		Tags:       tags,
	}

	// Apply Parameters (case-insensitive). We leave validation of
	// the values to the cloud provider.
	zonePresent := false
	zonesPresent := false
	var zone string
	var zones sets.String
	for k, v := range storageParams {
		switch strings.ToLower(k) {
		case "type":
			volumeOptions.VolumeType = v
		case "zone":
			zonePresent = true
			zone = v
		case "zones":
			zonesPresent = true
			zones, err = volumehelpers.ZonesToSet(v)
			if err != nil {
				return nil, fmt.Errorf("error parsing zones %s, must be strings separated by commas: %v", zones, err)
			}
		case "iopspergb":
			volumeOptions.IOPSPerGB, err = strconv.Atoi(v)
			if err != nil {
				return nil, fmt.Errorf("invalid iopsPerGB value %q, must be integer between 1 and 30: %v", v, err)
			}
		case "encrypted":
			volumeOptions.Encrypted, err = strconv.ParseBool(v)
			if err != nil {
				return nil, fmt.Errorf("invalid encrypted boolean value %q, must be true or false: %v", v, err)
			}
		case "kmskeyid":
			volumeOptions.KmsKeyID = v
		case volume.VolumeParameterFSType:
			// Do nothing but don't make this fail
		default:
			return nil, fmt.Errorf("invalid option %q for volume plugin %s", k, pluginName)
		}
	}

	volumeOptions.AvailabilityZone, err = volumehelpers.SelectZoneForVolume(zonePresent, zonesPresent, zone, zones, zonesWithNodes, node, allowedTopologies, pvcName)
	if err != nil {
		return nil, err
	}
	return volumeOptions, nil
}
631412
func (s *InputCaptions) SetCaptionSources(v []*CaptionSource) *InputCaptions {
	s.CaptionSources = v
	return s
}
1089272
func (s *ListDataSourcesOutput) SetDataSources(v []*DataSource) *ListDataSourcesOutput {
	s.DataSources = v
	return s
}
656001
func (s *SourceService) FindSources(ctx context.Context, opts influxdb.FindOptions) ([]*influxdb.Source, int, error) {
	// TODO: we'll likely want to push this operation into the database since fetching the whole list of data will likely be expensive.
	ss, _, err := s.s.FindSources(ctx, opts)
	if err != nil {
		return nil, 0, err
	}

	// This filters without allocating
	// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
	sources := ss[:0]
	for _, src := range ss {
		err := authorizeReadSource(ctx, src.OrganizationID, src.ID)
		if err != nil && influxdb.ErrorCode(err) != influxdb.EUnauthorized {
			return nil, 0, err
		}

		// TODO(desa): this is a totaly hack and needs to be fixed.
		// Specifically, we need to remove the concept of a default source.
		if src.OrganizationID.String() == bolt.DefaultSourceOrganizationID {
			sources = append(sources, src)
			continue
		}

		if influxdb.ErrorCode(err) == influxdb.EUnauthorized {
			continue
		}

		sources = append(sources, src)
	}

	return sources, len(sources), nil
}
1118821
func LoadSources(opts LoadOptions, source interface{}, others ...interface{}) (_ *File, err error) {
	sources := make([]dataSource, len(others)+1)
	sources[0], err = parseDataSource(source)
	if err != nil {
		return nil, err
	}
	for i := range others {
		sources[i+1], err = parseDataSource(others[i])
		if err != nil {
			return nil, err
		}
	}
	f := newFile(sources, opts)
	if err = f.Reload(); err != nil {
		return nil, err
	}
	return f, nil
}
1330115
func NewSource() Source {
	s := &source{
		triples: make(map[string]Triple),
	}
	s.latestSnap.Store(newGraph(0))
	return s
}
231136
func HandleResourceRequirements(params map[string]string) (api.ResourceRequirements, error) {
	result := api.ResourceRequirements{}
	limits, err := populateResourceList(params["limits"])
	if err != nil {
		return result, err
	}
	result.Limits = limits
	requests, err := populateResourceList(params["requests"])
	if err != nil {
		return result, err
	}
	result.Requests = requests
	return result, nil
}
856457
func (s *Service) Sources(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
	srcs, err := s.Store.Sources(ctx).All(ctx)
	if err != nil {
		Error(w, http.StatusInternalServerError, "Error loading sources", s.Logger)
		return
	}

	res := getSourcesResponse{
		Sources: make([]sourceResponse, len(srcs)),
	}

	sources := make([]sourceResponse, 0)
	for _, src := range srcs {
		sources = append(sources, newSourceResponse(ctx, src))
	}

	res.Sources = sources

	encodeJSON(w, http.StatusOK, res, s.Logger)
}
159836
func (s *UpdateSimulationApplicationOutput) SetSources(v []*Source) *UpdateSimulationApplicationOutput {
	s.Sources = v
	return s
}
1259989
func (s *Service) FindSources(ctx context.Context, opt platform.FindOptions) ([]*platform.Source, int, error) {
	var ds []*platform.Source
	s.sourceKV.Range(func(k, v interface{}) bool {
		d, ok := v.(*platform.Source)
		if !ok {
			return false
		}
		ds = append(ds, d)
		return true
	})
	return ds, len(ds), nil
}
1049453
func (s *CreateAppInput) SetDataSources(v []*DataSource) *CreateAppInput {
	s.DataSources = v
	return s
}
608318
func (s *CreateRobotApplicationOutput) SetSources(v []*Source) *CreateRobotApplicationOutput {
	s.Sources = v
	return s
}
1058642
func (s *DescribeInputOutput) SetSources(v []*InputSource) *DescribeInputOutput {
	s.Sources = v
	return s
}
381897
func DeployResources(args DeployResourcesArgs) (ids map[string]string, err error) {
	d := deployUploader{
		applicationID: args.ApplicationID,
		chID:          args.CharmID,
		csMac:         args.CharmStoreMacaroon,
		client:        args.Client,
		resources:     args.ResourcesMeta,
		osOpen:        func(s string) (ReadSeekCloser, error) { return os.Open(s) },
		osStat:        func(s string) error { _, err := os.Stat(s); return err },
	}

	ids, err = d.upload(args.ResourceValues, args.Revisions)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return ids, nil
}
35512
func (s *Store) Sources(ctx context.Context) chronograf.SourcesStore {
	if isServer := hasServerContext(ctx); isServer {
		return s.SourcesStore
	}
	if org, ok := hasOrganizationContext(ctx); ok {
		return organizations.NewSourcesStore(s.SourcesStore, org)
	}

	return &noop.SourcesStore{}
}