// Guarantees that the export will complete in sinkExportDataTimeout.
555780
func (this *sinkManager) ExportData(data *core.DataBatch) {
	var wg sync.WaitGroup
	for _, sh := range this.sinkHolders {
		wg.Add(1)
		go func(sh sinkHolder, wg *sync.WaitGroup) {
			defer wg.Done()
			glog.V(2).Infof("Pushing data to: %s", sh.sink.Name())
			select {
			case sh.dataBatchChannel <- data:
				glog.V(2).Infof("Data push completed: %s", sh.sink.Name())
				// everything ok
			case <-time.After(this.exportDataTimeout):
				glog.Warningf("Failed to push data to sink: %s", sh.sink.Name())
			}
		}(sh, &wg)
	}
	// Wait for all pushes to complete or timeout.
	wg.Wait()
}
482789
func (h *PublicPortHandler) SetExports(data []registry.ExportDetails) {
	h.exports.Set(data)
}
1084810
func (h *Histo) Export() (JSONMetric, error) {
	val, err := h.Value.GobEncode()
	if err != nil {
		return JSONMetric{}, err
	}
	return JSONMetric{
		MetricKey: MetricKey{
			Name:       h.Name,
			Type:       "histogram",
			JoinedTags: strings.Join(h.Tags, ","),
		},
		Tags:  h.Tags,
		Value: val,
	}, nil
}
52561
func dropEmptyImportDeclarations(decl ast.Decl) bool {
	switch t := decl.(type) {
	case *ast.GenDecl:
		if t.Tok != token.IMPORT {
			return false
		}
		specs := []ast.Spec{}
		for _, s := range t.Specs {
			switch spec := s.(type) {
			case *ast.ImportSpec:
				if spec.Name != nil && spec.Name.Name == "_" {
					continue
				}
				specs = append(specs, spec)
			}
		}
		if len(specs) == 0 {
			return true
		}
		t.Specs = specs
	}
	return false
}
26381
func (w *upgradeSeriesWorker) transitionPrepareComplete(unitServices map[string]string) error {
	w.logger.Infof("preparing service units for series upgrade")
	toSeries, err := w.TargetSeries()
	if err != nil {
		return errors.Trace(err)
	}
	upgrader, err := w.upgraderFactory(toSeries)
	if err != nil {
		return errors.Trace(err)
	}
	if err := upgrader.PerformUpgrade(); err != nil {
		return errors.Trace(err)
	}
	return errors.Trace(w.SetMachineStatus(model.UpgradeSeriesPrepareCompleted,
		"binaries and service files written"))
}
301630
func (f *Facade) GetServiceExportedEndpoints(ctx datastore.Context, serviceID string, children bool) ([]service.ExportedEndpoint, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.GetServiceExportedEndpoints"))

	// get all the exported endpoints and map them to their service
	alleps, err := f.serviceStore.GetAllExportedEndpoints(ctx)
	if err != nil {
		return nil, err
	}
	epmap := make(map[string][]service.ExportedEndpoint)
	for i, ep := range alleps {
		epmap[ep.ServiceID] = append(epmap[ep.ServiceID], alleps[i])
	}

	// get all the endpoints for that service
	result, ok := epmap[serviceID]
	if ok {
		delete(epmap, serviceID)
	}

	if children {
		// get the tenant id and service path to the service in order to find
		// the service's children.
		tenantID, svcPath, err := f.getServicePath(ctx, serviceID)
		if err != nil {
			return nil, err
		}

		for id, eps := range epmap {
			// add the endpoints with the matching tenant id and share the same
			// path prefix.
			tid, spth, err := f.getServicePath(ctx, id)
			if err != nil {
				return nil, err
			}
			if tid == tenantID && strings.HasPrefix(spth, svcPath+"/") {
				result = append(result, eps...)
			}
		}
	}

	return result, nil
}
491540
func NewStatsdBuffer(interval time.Duration, client Statsd) *StatsdBuffer {
	sb := &StatsdBuffer{
		flushInterval: interval,
		statsd:        client,
		eventChannel:  make(chan event.Event, 100),
		events:        make(map[string]event.Event),
		closeChannel:  make(chan closeRequest),
		Logger:        log.New(os.Stdout, "[BufferedStatsdClient] ", log.Ldate|log.Ltime),
		Verbose:       true,
	}
	go sb.collector()
	return sb
}
285940
func InitializeImportCollector(
	scheduled bool,
	cbCollectISCounts QueuedImageStreamFetcher,
) {
	registerLock.Lock()
	defer registerLock.Unlock()

	if scheduled {
		isc.cbCollectScheduledCounts = cbCollectISCounts
	} else {
		isc.cbCollectISCounts = cbCollectISCounts
	}

	if collectorRegistered {
		return
	}

	if isc.cbCollectISCounts != nil && isc.cbCollectScheduledCounts != nil {
		prometheus.MustRegister(&isc)
		collectorRegistered = true
		klog.V(4).Info("Image import controller metrics registered with prometherus")
	}
}
152080
func (ce *ContainerEndpoints) AddExport(cancel <-chan struct{}, bind zkservice.ExportBinding) {
	logger := plog.WithFields(log.Fields{
		"application": bind.Application,
		"portnumber":  bind.PortNumber,
		"protocol":    bind.Protocol,
	})

	exp := registry.ExportDetails{
		ExportBinding: bind,
		PrivateIP:     ce.state.PrivateIP,
		HostIP:        ce.state.HostIP,
		MuxPort:       ce.opts.TCPMuxPort,
		InstanceID:    ce.state.InstanceID,
	}

	logger.Debug("Registering export")
	defer logger.Debug("Unregistered export")

	for {
		select {
		case conn := <-zzk.Connect("/", zzk.GetLocalConnection):
			if conn != nil {

				logger.Debug("Received coordinator connection")
				registry.RegisterExport(cancel, conn, ce.opts.TenantID, exp)
				select {
				case <-cancel:
					return
				default:
				}
			}
		case <-cancel:
			return
		}
	}
}
841270
func (s *storeImpl) GetAllExportedEndpoints(ctx datastore.Context) ([]ExportedEndpoint, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("ServiceStore.GetAllExportedEndpoints"))
	searchRequest := newServiceDetailsElasticRequest(map[string]interface{}{
		"query": map[string]interface{}{
			"term": map[string]interface{}{
				"Endpoints.Purpose": "export",
			},
		},
		"fields": exportedEndpointFields,
		"size":   serviceDetailsLimit,
	})

	results, err := datastore.NewQuery(ctx).Execute(searchRequest)
	if err != nil {
		return nil, err
	}

	eps := []ExportedEndpoint{}
	for results.HasNext() {
		var result EndpointQueryResult
		err := results.Next(&result)
		if err != nil {
			return nil, err
		}
		endpoints := createExportedEndpoints(result)
		eps = append(eps, endpoints...)
	}

	return eps, nil
}
45281
func (oe *V1Exporter) Export(ctx context.Context, store content.Provider, desc ocispec.Descriptor, writer io.Writer) error {
	tw := tar.NewWriter(writer)
	defer tw.Close()

	records := []tarRecord{
		ociLayoutFile(""),
		ociIndexRecord(desc),
	}

	algorithms := map[string]struct{}{}
	exportHandler := func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
		records = append(records, blobRecord(store, desc))
		algorithms[desc.Digest.Algorithm().String()] = struct{}{}
		return nil, nil
	}

	childrenHandler := images.ChildrenHandler(store)

	if !oe.AllPlatforms {
		// get local default platform to fetch image manifest
		childrenHandler = images.FilterPlatforms(childrenHandler, platforms.Any(platforms.DefaultSpec()))
	}

	handlers := images.Handlers(
		childrenHandler,
		images.HandlerFunc(exportHandler),
	)

	// Walk sequentially since the number of fetchs is likely one and doing in
	// parallel requires locking the export handler
	if err := images.Walk(ctx, handlers, desc); err != nil {
		return err
	}

	if len(algorithms) > 0 {
		records = append(records, directoryRecord("blobs/", 0755))
		for alg := range algorithms {
			records = append(records, directoryRecord("blobs/"+alg+"/", 0755))
		}
	}

	return writeTar(ctx, tw, records)
}
1220574
func ResolveCacheImporterFunc(sm *session.Manager, resolverOpt resolver.ResolveOptionsFunc, rs reference.Store, is imagestore.Store) remotecache.ResolveCacheImporterFunc {

	upstream := registryremotecache.ResolveCacheImporterFunc(sm, resolverOpt)

	return func(ctx context.Context, attrs map[string]string) (remotecache.Importer, specs.Descriptor, error) {
		if dt, err := tryImportLocal(rs, is, attrs["ref"]); err == nil {
			return newLocalImporter(dt), specs.Descriptor{}, nil
		}
		return upstream(ctx, attrs)
	}
}
1105150
func isExported(f reflect.StructField) bool {
	if f.PkgPath != "" && !f.Anonymous {
		return false
	}
	return true
}
549752
func (mg *MailgunImpl) GetExport(ctx context.Context, id string) (Export, error) {
	r := newHTTPRequest(generatePublicApiUrl(mg, exportsEndpoint) + "/" + id)
	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())
	var resp Export
	err := getResponseFromJSON(ctx, r, &resp)
	return resp, err
}
1259756
func GetProcNFSDExport(mountpoint string) (*ProcNFSDExports, error) {
	// an example for mountpoint is /exports/serviced_var

	exports, err := GetProcNFSDExports()
	if err != nil {
		return nil, err
	}

	export, ok := exports[mountpoint]
	if !ok {
		return nil, ErrMountPointNotExported
	}

	return &export, nil
}
1149475
func (c *Client) GetExports(ctx context.Context) (ExportList, error) {
	return api.ExportsList(ctx, c.API)
}
57789
func (st stateAdapter) NewLastSentTracker(tag names.ModelTag, sink string) LastSentTracker {
	return state.NewLastSentLogTracker(st, tag.Id(), sink)
}