// Provide returns the result of executing the constructor with argument values resolved from a dependency graph
552
func (p provider) Provide(g Graph) reflect.Value {
	fnType := reflect.TypeOf(p.constructor)

	argCount := fnType.NumIn()
	if fnType.IsVariadic() {
		argCount = len(p.argPtrs)
	}

	args := make([]reflect.Value, argCount, argCount)
	var inType reflect.Type
	for i := 0; i < argCount; i++ {
		arg := g.Resolve(p.argPtrs[i])
		argType := arg.Type()

		if i < fnType.NumIn() {
			inType = fnType.In(i)
		} else {
			inType = fnType.In(fnType.NumIn() - 1)
		}

		if inType.Kind() == reflect.Slice {
			inType = inType.Elem()
		}

		if !argType.AssignableTo(inType) {
			if !argType.ConvertibleTo(inType) {
				panic(fmt.Sprintf(
					"arg %d of type %q cannot be assigned or converted to type %q for provider constructor (%s)",
					i, argType, inType, p.constructor,
				))
			}
			arg = arg.Convert(inType)
		}
		args[i] = arg
	}

	return reflect.ValueOf(p.constructor).Call(args)[0]
}
1327165
func (e *ControlleeExpectations) Fulfilled() bool {
	// TODO: think about why this line being atomic doesn't matter
	return atomic.LoadInt64(&e.add) <= 0 && atomic.LoadInt64(&e.del) <= 0
}
757125
func (*Projects) Ensure(c context.Context, req *projects.EnsureRequest) (*projects.Config, error) {
	if req.GetId() == "" {
		return nil, status.Errorf(codes.InvalidArgument, "ID is required")
	}
	p := &model.Project{
		ID:     req.Id,
		Config: *req.Project,
	}
	if err := datastore.Put(c, p); err != nil {
		return nil, errors.Annotate(err, "failed to store project").Err()
	}
	return &p.Config, nil
}
1297311
func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.Pool) error {
	ctx := log.With(context.Background(), log.Str(log.ProviderName, "acme"))

	p.pool = pool

	p.watchCertificate(ctx)
	p.watchNewDomains(ctx)

	p.configurationChan = configurationChan
	p.refreshCertificates()

	p.deleteUnnecessaryDomains(ctx)
	for i := 0; i < len(p.Domains); i++ {
		domain := p.Domains[i]
		safe.Go(func() {
			if _, err := p.resolveCertificate(ctx, domain, true); err != nil {
				log.WithoutContext().WithField(log.ProviderName, "acme").
					Errorf("Unable to obtain ACME certificate for domains %q : %v", strings.Join(domain.ToStrArray(), ","), err)
			}
		})
	}

	p.renewCertificates(ctx)

	ticker := time.NewTicker(24 * time.Hour)
	pool.Go(func(stop chan bool) {
		for {
			select {
			case <-ticker.C:
				p.renewCertificates(ctx)
			case <-stop:
				ticker.Stop()
				return
			}
		}
	})

	return nil
}
953435
func (c *Client) Consume(arg crossmodel.ConsumeApplicationArgs) (string, error) {
	var consumeRes params.ErrorResults
	args := params.ConsumeApplicationArgs{
		Args: []params.ConsumeApplicationArg{{
			ApplicationOfferDetails: arg.Offer,
			ApplicationAlias:        arg.ApplicationAlias,
			Macaroon:                arg.Macaroon,
		}},
	}
	if arg.ControllerInfo != nil {
		args.Args[0].ControllerInfo = &params.ExternalControllerInfo{
			ControllerTag: arg.ControllerInfo.ControllerTag.String(),
			Alias:         arg.ControllerInfo.Alias,
			Addrs:         arg.ControllerInfo.Addrs,
			CACert:        arg.ControllerInfo.CACert,
		}
	}
	err := c.facade.FacadeCall("Consume", args, &consumeRes)
	if err != nil {
		return "", errors.Trace(err)
	}
	if resultLen := len(consumeRes.Results); resultLen != 1 {
		return "", errors.Errorf("expected 1 result, got %d", resultLen)
	}
	if err := consumeRes.Results[0].Error; err != nil {
		return "", errors.Trace(err)
	}
	localName := arg.Offer.OfferName
	if arg.ApplicationAlias != "" {
		localName = arg.ApplicationAlias
	}
	return localName, nil
}
1276045
func (p ProviderAggregator) Provide(configurationChan chan<- config.Message, pool *safe.Pool) error {
	if p.fileProvider != nil {
		launchProvider(configurationChan, pool, p.fileProvider)
	}

	for _, prd := range p.providers {
		prd := prd
		safe.Go(func() {
			launchProvider(configurationChan, pool, prd)
		})
	}
	return nil
}
458485
func (svc *googleService) provision() error {
	zone, err := svc.service.Zones.Get(svc.vm.Project, svc.vm.Zone).Do()
	if err != nil {
		return err
	}

	machineType, err := svc.service.MachineTypes.Get(svc.vm.Project, zone.Name, svc.vm.MachineType).Do()
	if err != nil {
		return err
	}

	network, err := svc.service.Networks.Get(svc.vm.Project, svc.vm.Network).Do()
	if err != nil {
		return err
	}

	// validate network
	if !network.AutoCreateSubnetworks && len(network.Subnetworks) > 0 {
		// Network appears to be in "custom" mode, so a subnetwork is required
		// libretto doesn't handle the network creation
		if svc.vm.Subnetwork == "" {
			return fmt.Errorf("a subnetwork must be specified")
		}
	}

	subnetworkSelfLink := ""
	if svc.vm.Subnetwork != "" {
		subnetwork, err := svc.service.Subnetworks.Get(svc.vm.Project, svc.vm.region(), svc.vm.Subnetwork).Do()
		if err != nil {
			return err
		}
		subnetworkSelfLink = subnetwork.SelfLink
	}

	accessconfig := googlecloud.AccessConfig{
		Name: "External NAT for Libretto",
		Type: "ONE_TO_ONE_NAT",
	}

	md := svc.getSSHKey()

	disks, err := svc.createDisks()
	if err != nil {
		return err
	}

	instance := &googlecloud.Instance{
		Name:        svc.vm.Name,
		Description: svc.vm.Description,
		Disks:       disks,
		MachineType: machineType.SelfLink,
		Metadata: &googlecloud.Metadata{
			Items: []*googlecloud.MetadataItems{
				{
					Key:   "sshKeys",
					Value: &md,
				},
			},
		},
		NetworkInterfaces: []*googlecloud.NetworkInterface{
			{
				AccessConfigs: []*googlecloud.AccessConfig{
					&accessconfig,
				},
				Network:    network.SelfLink,
				Subnetwork: subnetworkSelfLink,
				NetworkIP:  svc.vm.PrivateIPAddress,
			},
		},
		Scheduling: &googlecloud.Scheduling{
			Preemptible: svc.vm.Preemptible,
		},
		ServiceAccounts: []*googlecloud.ServiceAccount{
			{
				Email:  "default",
				Scopes: svc.vm.Scopes,
			},
		},
		Tags: &googlecloud.Tags{
			Items: svc.vm.Tags,
		},
	}

	op, err := svc.service.Instances.Insert(svc.vm.Project, zone.Name, instance).Do()
	if err != nil {
		return err
	}

	if err = svc.waitForOperationReady(op.Name); err != nil {
		return err
	}

	_, err = svc.getInstance()
	return err
}
67187
func (f *fetcher) deliver(ctx context.Context, ch Chunk) {
	f.deliverOnce.Do(func() {
		f.chunk = ch
		// closing the deliveredC channel will terminate ongoing requests
		close(f.deliveredC)
		log.Trace("n.getFetcher close deliveredC", "ref", ch.Address())
	})
}
568365
func (suite *Suite) Require() *require.Assertions {
	if suite.require == nil {
		suite.require = require.New(suite.T())
	}
	return suite.require
}
906001
func (*Config) Ensure(c context.Context, req *config.EnsureRequest) (*config.Config, error) {
	if req.GetId() == "" {
		return nil, status.Errorf(codes.InvalidArgument, "ID is required")
	}
	cfg := &model.Config{
		ID:     req.Id,
		Config: *req.Config,
	}
	if err := datastore.Put(c, cfg); err != nil {
		return nil, errors.Annotate(err, "failed to store config").Err()
	}
	return &cfg.Config, nil
}
1203264
func (p *defaultProvisioner) Provision(ctx context.Context, appName, os, arch string, paths Paths) (err error) {
	// Retrieve provision status
	var s ProvisionStatus
	if s, err = p.ProvisionStatus(paths); err != nil {
		err = errors.Wrap(err, "retrieving provisioning status failed")
		return
	}
	defer p.updateProvisionStatus(paths, &s)

	// Provision astilectron
	if err = p.provisionAstilectron(ctx, paths, s); err != nil {
		err = errors.Wrap(err, "provisioning astilectron failed")
		return
	}
	s.Astilectron = &ProvisionStatusPackage{Version: VersionAstilectron}

	// Provision electron
	if err = p.provisionElectron(ctx, paths, s, appName, os, arch); err != nil {
		err = errors.Wrap(err, "provisioning electron failed")
		return
	}
	s.Electron[provisionStatusElectronKey(os, arch)] = &ProvisionStatusPackage{Version: VersionElectron}
	return
}
136327
func Get(provider common.Provider, creds *common.Credentials, endpoint string) (objx.Map, error) {

	client, clientErr := provider.GetClient(creds)

	if clientErr != nil {
		return nil, clientErr
	}

	response, responseErr := client.Get(endpoint)

	if responseErr != nil {
		return nil, responseErr
	}

	body, bodyErr := ioutil.ReadAll(response.Body)

	if bodyErr != nil {
		return nil, bodyErr
	}

	defer response.Body.Close()

	codecs := services.NewWebCodecService()
	codec, getCodecErr := codecs.GetCodec(response.Header.Get("Content-Type"))

	if getCodecErr != nil {
		return nil, getCodecErr
	}

	var data objx.Map
	unmarshalErr := codec.Unmarshal(body, &data)

	if unmarshalErr != nil {
		return nil, unmarshalErr
	}

	return data, nil

}
16900
func (jt *jointab) Procure(bldr builder, col *sqlparser.ColName, to int) string {
	from, joinVar := jt.Lookup(col)
	// If joinVar is empty, generate a unique name.
	if joinVar == "" {
		suffix := ""
		i := 0
		for {
			if !col.Qualifier.IsEmpty() {
				joinVar = col.Qualifier.Name.CompliantName() + "_" + col.Name.CompliantName() + suffix
			} else {
				joinVar = col.Name.CompliantName() + suffix
			}
			if _, ok := jt.vars[joinVar]; !ok {
				break
			}
			i++
			suffix = strconv.Itoa(i)
		}
		jt.vars[joinVar] = struct{}{}
		jt.refs[col.Metadata.(*column)] = joinVar
	}
	bldr.SupplyVar(from, to, col, joinVar)
	return joinVar
}
372646
func (rm *retrieveManager) deliver(peer distPeer, msg *Msg) error {
	rm.lock.RLock()
	req, ok := rm.sentReqs[msg.ReqID]
	rm.lock.RUnlock()

	if ok {
		return req.deliver(peer, msg)
	}
	return errResp(ErrUnexpectedResponse, "reqID = %v", msg.ReqID)
}
1112228
func (vm *VM) Provision() error {
	if vm.MockProvision != nil {
		return vm.MockProvision()
	}
	return lvm.ErrNotImplemented
}
26824
func require(required []string, parser lineParser) lineParser {
	f := func(ctx *parseContext, cmd string, args []string) (node, error) {
		n, err := parser(ctx, cmd, args)
		if err == nil {
			requiredMap := make(map[string]bool)
			for _, r := range required {
				requiredMap[r] = false //hasn't been found yet
			}

			for _, previousNode := range ctx.nodes {
				if _, found := requiredMap[previousNode.cmd]; found {
					requiredMap[previousNode.cmd] = true
				}
			}
			for key, found := range requiredMap {
				if !found {
					ctx.addErrorf("line %d: %s depends on %s", ctx.lineNum, cmd, key)
				}
			}
		}
		return n, err
	}
	return f
}
999358
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
	return p.updateConfig(configurationChan, pool, time.Duration(p.RefreshSeconds))
}