// CheckServiceTasksInStateWithError returns the number of tasks with a matching state,
// and optional message substring.
557149
func (d *Daemon) CheckServiceTasksInStateWithError(service string, state swarm.TaskState, errorMessage string) func(*check.C) (interface{}, check.CommentInterface) {
	return func(c *check.C) (interface{}, check.CommentInterface) {
		tasks := d.GetServiceTasks(c, service)
		var count int
		for _, task := range tasks {
			if task.Status.State == state {
				if errorMessage == "" || strings.Contains(task.Status.Err, errorMessage) {
					count++
				}
			}
		}
		return count, nil
	}
}
770668
func (c *Client) ErrorWithStackSkipWithExtras(level string, err error, skip int, extras map[string]interface{}) {
	c.ErrorWithStackSkipWithExtrasAndContext(context.TODO(), level, err, skip, extras)
}
165364
func WithError(msg string, err error) {
	p := problem.FromError(err)
	if p != nil {
		WithProblem(msg, p)
	}
	displayError(msg, err)
	os.Exit(Software)
}
231697
func (o *DestroyOneDefault) WithStatusCode(code int) *DestroyOneDefault {
	o._statusCode = code
	return o
}
965506
func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.StateResponse, error) {
	log.G(ctx).Debugf("State: %s: %s", r.ID, r.ExecID)

	s.mu.Lock()
	defer s.mu.Unlock()

	var p *process
	var err error
	if p, err = s.getProcessLocked(r.ID, r.ExecID); err != nil {
		return nil, err
	}

	var tstatus string

	// This is a container
	if p.cid == p.id {
		rhcs := s.newRunhcs()
		cs, err := rhcs.State(ctx, p.id)
		if err != nil {
			return nil, err
		}
		tstatus = cs.Status
	} else {
		if p.started {
			tstatus = "running"
		} else {
			tstatus = "created"
		}
	}

	status := task.StatusUnknown
	switch tstatus {
	case "created":
		status = task.StatusCreated
	case "running":
		status = task.StatusRunning
	case "stopped":
		status = task.StatusStopped
	case "paused":
		status = task.StatusPaused
	}
	pe := p.stat()
	return &taskAPI.StateResponse{
		ID:         p.id,
		Bundle:     p.bundle,
		Pid:        pe.pid,
		Status:     status,
		Stdin:      p.stdin,
		Stdout:     p.stdout,
		Stderr:     p.stderr,
		Terminal:   p.terminal,
		ExitStatus: pe.exitStatus,
		ExitedAt:   pe.exitedAt,
	}, nil
}
615678
func (actor Actor) ServiceExistsWithName(serviceName string) (bool, Warnings, error) {
	services, warnings, err := actor.CloudControllerClient.GetServices(ccv2.Filter{
		Type:     constant.LabelFilter,
		Operator: constant.EqualOperator,
		Values:   []string{serviceName},
	})
	if err != nil {
		return false, Warnings(warnings), err
	}

	if len(services) == 0 {
		return false, Warnings(warnings), nil
	}

	return true, Warnings(warnings), nil
}
47961
func (o *GetAccountDefault) WithStatusCode(code int) *GetAccountDefault {
	o._statusCode = code
	return o
}
651078
func (c *InstanceCache) withState(ctx context.Context, now time.Time, f func(*messages.InstanceCache)) {
	state := &messages.InstanceCache{}

	start := clock.Now(ctx)
	defer func() {
		totalTime := clock.Since(ctx, start)
		if totalTime > 2*time.Second {
			logging.Warningf(
				ctx, "cipd: instance cache state update took %s (%d entries)",
				totalTime, len(state.Entries))
		}
	}()

	c.stateLock.Lock()
	defer c.stateLock.Unlock()

	c.readState(ctx, state, now)
	f(state)
	if err := c.saveState(ctx, state); err != nil {
		logging.Warningf(ctx, "cipd: could not save instance cache - %s", err)
	}
}
15195
func WithTaskService(taskService tasks.TasksClient) ServicesOpt {
	return func(s *services) {
		s.taskService = taskService
	}
}
30220
func (o *GetTaskCommentsParams) WithSince(since *strfmt.DateTime) *GetTaskCommentsParams {
	o.SetSince(since)
	return o
}
1005378
func (h *ActivityWorker) HandleWithRecovery(handler func(*swf.PollForActivityTaskOutput)) func(*swf.PollForActivityTaskOutput) {
	return func(resp *swf.PollForActivityTaskOutput) {
		defer func() {
			var anErr error
			if r := recover(); r != nil {
				file, line, name := panicinfo.LocatePanic(r)
				if err, ok := r.(error); ok && err != nil {
					anErr = err
				} else {
					anErr = errors.New("panic in activity with nil error")
				}
				Log.Printf("component=activity at=activity-panic-recovery-error func=%q file=\"%s:%d\" error=%q", name, file, line, r)
				h.fail(resp, anErr)
			}
		}()
		handler(resp)

	}
}
624882
func (c *Client) RequestErrorWithStackSkip(level string, r *http.Request, err error, skip int) {
	c.RequestErrorWithStackSkipWithExtras(level, r, err, skip, noExtras)
}
1052390
func (o *LogoutUserDefault) WithStatusCode(code int) *LogoutUserDefault {
	o._statusCode = code
	return o
}
1191081
func ServiceWithInit(b *bool) func(*swarmtypes.ServiceSpec) {
	return func(spec *swarmtypes.ServiceSpec) {
		ensureContainerSpec(spec)
		spec.TaskTemplate.ContainerSpec.Init = b
	}
}
376765
func (o *CreateUsersWithArrayInputDefault) WithStatusCode(code int) *CreateUsersWithArrayInputDefault {
	o._statusCode = code
	return o
}
535696
func (o *CreateDefault) WithStatusCode(code int) *CreateDefault {
	o._statusCode = code
	return o
}
594025
func (o *UploadTaskFileDefault) WithStatusCode(code int) *UploadTaskFileDefault {
	o._statusCode = code
	return o
}