// HTTPPoolContext must be used in groupcache.HTTPPool.Context.
352584
func HTTPPoolContext(req *http.Request) groupcache.Context {
	ctx, err := getContext(req)
	if err != nil {
		return nil
	}
	return ctx
}
832124
func (r *Request) WithContext(ctx context.Context) *Request {
	if ctx == nil {
		panic("nil context")
	}
	r2 := new(Request)
	*r2 = *r
	r2.ctx = ctx
	r2.HTTPRequest = r2.HTTPRequest.WithContext(ctx)
	return r2
}
842048
func (api *Client) CreateGroupContext(ctx context.Context, group string) (*Group, error) {
	values := url.Values{
		"token": {api.token},
		"name":  {group},
	}

	response, err := api.groupRequest(ctx, "groups.create", values)
	if err != nil {
		return nil, err
	}
	return &response.Group, nil
}
524996
func (d Datastore) HostContext(ctx context.Context, host *HostSystem) context.Context {
	return context.WithValue(ctx, datastoreServiceTicketHostKey{}, host)
}
1167868
func (c *GroupRequestsEventsRollupCall) Context(ctx context.Context) *GroupRequestsEventsRollupCall {
	c.ctx_ = ctx
	return c
}
823688
func (c *GroupPercentSetCall) Context(ctx context.Context) *GroupPercentSetCall {
	c.ctx_ = ctx
	return c
}
1041165
func (c *Ctx) WithContext(ctx context.Context) {
	c.request = c.request.WithContext(ctx)
}
218881
func (server *Server) SendGroupWithContext(ctx context.Context, group *tasks.Group, sendConcurrency int) ([]*result.AsyncResult, error) {
	span, _ := opentracing.StartSpanFromContext(ctx, "SendGroup", tracing.ProducerOption(), tracing.MachineryTag, tracing.WorkflowGroupTag)
	defer span.Finish()

	tracing.AnnotateSpanWithGroupInfo(span, group, sendConcurrency)

	// Make sure result backend is defined
	if server.backend == nil {
		return nil, errors.New("Result backend required")
	}

	asyncResults := make([]*result.AsyncResult, len(group.Tasks))

	var wg sync.WaitGroup
	wg.Add(len(group.Tasks))
	errorsChan := make(chan error, len(group.Tasks)*2)

	// Init group
	server.backend.InitGroup(group.GroupUUID, group.GetUUIDs())

	// Init the tasks Pending state first
	for _, signature := range group.Tasks {
		if err := server.backend.SetStatePending(signature); err != nil {
			errorsChan <- err
			continue
		}
	}

	pool := make(chan struct{}, sendConcurrency)
	go func() {
		for i := 0; i < sendConcurrency; i++ {
			pool <- struct{}{}
		}
	}()

	for i, signature := range group.Tasks {

		if sendConcurrency > 0 {
			<-pool
		}

		go func(s *tasks.Signature, index int) {
			defer wg.Done()

			// Publish task

			err := server.broker.Publish(ctx, s)

			if sendConcurrency > 0 {
				pool <- struct{}{}
			}

			if err != nil {
				errorsChan <- fmt.Errorf("Publish message error: %s", err)
				return
			}

			asyncResults[index] = result.NewAsyncResult(s, server.backend)
		}(signature, i)
	}

	done := make(chan int)
	go func() {
		wg.Wait()
		done <- 1
	}()

	select {
	case err := <-errorsChan:
		return asyncResults, err
	case <-done:
		return asyncResults, nil
	}
}
1301033
func (session *Session) WithContext(ctx context.Context) *Session {
	s := *session
	s.context = ctx
	return &s
}
963031
func NewCachingContext(baseDir string, funcs template.FuncMap) Context {
	return &cachingContext{
		baseDir: baseDir,
		mut:     new(sync.Mutex),
		cache:   make(map[filesMapKey]*template.Template),
		funcs:   funcs,
	}
}
784399
func newContext(r *http.Request, w http.ResponseWriter, api string) context.Context {
	vars := mux.Vars(r)
	bucket := vars["bucket"]
	object := vars["object"]
	prefix := vars["prefix"]

	if prefix != "" {
		object = prefix
	}
	reqInfo := &logger.ReqInfo{
		DeploymentID: w.Header().Get(responseDeploymentIDKey),
		RequestID:    w.Header().Get(responseRequestIDKey),
		RemoteHost:   handlers.GetSourceIP(r),
		UserAgent:    r.UserAgent(),
		API:          api,
		BucketName:   bucket,
		ObjectName:   object,
	}
	return logger.SetReqInfo(context.Background(), reqInfo)
}
926880
func (o *ListTasksParams) WithContext(ctx context.Context) *ListTasksParams {
	o.SetContext(ctx)
	return o
}
656406
func (s *Server) FindHostsInPool(poolID string, hostReply *[]host.Host) error {
	hosts, err := s.f.FindHostsInPool(s.context(), poolID)
	if err != nil {
		return err
	}
	*hostReply = hosts
	return nil
}
1213117
func (c *GroupRolloutGetCall) Context(ctx context.Context) *GroupRolloutGetCall {
	c.ctx_ = ctx
	return c
}
480473
func (c *TasksCountCall) Context(ctx context.Context) *TasksCountCall {
	c.ctx_ = ctx
	return c
}
1275458
func (sd StorageGroupDefinition) Context() string {
	if sd.Name != "" {
		return fmt.Sprintf("StorageGroup %#v", sd.Name)
	}
	return "unnamed Storage Group"
}
337113
func (c *Client) WithContext(ctx context.Context) *Client {
	newC := *c
	newC.ctx = ctx
	return &newC
}