// newEvalState creates and initializes a new monitorState
3557
func newEvalState() *evalState {
	return &evalState{
		status: structs.EvalStatusPending,
		allocs: make(map[string]*allocState),
	}
}
91116
func (w *deploymentWatcher) jobEvalStatus() (latestIndex uint64, err error) {
	if err := w.queryLimiter.Wait(w.ctx); err != nil {
		return 0, err
	}

	snap, err := w.state.Snapshot()
	if err != nil {
		return 0, err
	}

	evals, err := snap.EvalsByJob(nil, w.j.Namespace, w.j.ID)
	if err != nil {
		return 0, err
	}

	// If there are no evals for the job, return zero, since we want any
	// allocation change to trigger an evaluation.
	if len(evals) == 0 {
		return 0, nil
	}

	var max uint64
	for _, eval := range evals {
		// A cancelled eval never impacts what the scheduler has saw, so do not
		// use it's indexes.
		if eval.Status == structs.EvalStatusCancelled {
			continue
		}

		// Prefer using the snapshot index. Otherwise use the create index
		if eval.SnapshotIndex != 0 && max < eval.SnapshotIndex {
			max = eval.SnapshotIndex
		} else if max < eval.CreateIndex {
			max = eval.CreateIndex
		}
	}

	return max, nil
}
788094
func CreateState(conn client.Connection, req StateRequest) error {
	logger := plog.WithFields(log.Fields{
		"hostid":     req.HostID,
		"serviceid":  req.ServiceID,
		"instanceid": req.InstanceID,
	})

	basepth := "/"
	if req.PoolID != "" {
		basepth = path.Join("/pools", req.PoolID)
	}

	t := conn.NewTransaction()

	// Prepare the host instance
	hpth := path.Join(basepth, "/hosts", req.HostID, "instances")
	err := conn.CreateIfExists(hpth, &client.Dir{})
	if err != nil && err != client.ErrNodeExists {

		logger.WithError(err).Debug("Could not initialize host path")
		return &StateError{
			Request:   req,
			Operation: "create",
			Message:   "could not initialize host path",
		}
	}

	hspth := path.Join(hpth, req.StateID())
	hsdat := &HostState{
		DesiredState: service.SVCRun,
		Scheduled:    time.Now(),
	}
	t.Create(hspth, hsdat)

	// Prepare the service instance
	sspth := path.Join(basepth, "/services", req.ServiceID, req.StateID())
	ssdat := &ServiceState{}
	t.Create(sspth, ssdat)

	cspth := path.Join(sspth, "current")
	cstate := &CurrentStateContainer{}
	cstate.Status = service.StateStopped
	t.Create(cspth, cstate)

	if err := t.Commit(); err != nil {
		logger.WithError(err).Debug("Could not commit transaction")
		return &StateError{
			Request:   req,
			Operation: "create",
			Message:   "could not commit transaction",
		}
	}

	logger.Debug("Created state")
	return nil
}
855222
func (h *QuasiNewtonHelper) UpdateState(nextPos *core.Vector, nextGrad *core.Vector) (isOptimal bool) {
	if int64(len(h.sList)) >= h.numHist {
		h.sList = h.sList[1:]
		h.yList = h.yList[1:]
		h.roList = h.roList[1:]
	}
	newS := nextPos.ElemWiseMultiplyAdd(h.curPos, -1)
	newY := nextGrad.ElemWiseMultiplyAdd(h.curGrad, -1)
	ro := newS.Dot(newY)
	h.sList = append(h.sList, newS)
	h.yList = append(h.yList, newY)
	h.roList = append(h.roList, ro)
	h.curPos = nextPos
	h.curGrad = nextGrad
	return ro == 0
}
313820
func NewWaitDynamicUntilState(stateName string, timestampPath string) *WaitDynamicUntil {
	return &WaitDynamicUntil{
		baseInnerState: baseInnerState{
			name: stateName,
			id:   rand.Int63(),
		},
		TimestampPath: timestampPath,
	}
}
513607
func NewStateFromFacade(facadeCaller base.FacadeCaller) *State {
	return &State{
		ModelWatcher:        common.NewModelWatcher(facadeCaller),
		APIAddresser:        common.NewAPIAddresser(facadeCaller),
		ControllerConfigAPI: common.NewControllerConfig(facadeCaller),
		facade:              facadeCaller,
	}
}
879601
func NewMemoryState() State {
	klog.Infof("[cpumanager] initializing new in-memory state store")
	return &stateMemory{
		assignments:   ContainerCPUAssignments{},
		defaultCPUSet: cpuset.NewCPUSet(),
	}
}
445305
func NewWaitUntilState(stateName string, waitUntil time.Time) *WaitUntil {
	return &WaitUntil{
		baseInnerState: baseInnerState{
			name: stateName,
			id:   rand.Int63(),
		},
		Timestamp: waitUntil,
	}
}
1255048
func NewState() *State {
	v := float64(VersionNumber)
	l := &State{allowHook: true, error: nil, nonYieldableCallCount: 1}
	g := &globalState{mainThread: l, registry: newTable(), version: &v, memoryErrorMessage: "not enough memory"}
	l.global = g
	l.initializeStack()
	g.registry.putAtInt(RegistryIndexMainThread, l)
	g.registry.putAtInt(RegistryIndexGlobals, newTable())
	copy(g.tagMethodNames[:], eventNames)
	return l
}
216045
func NewFailureTaskState(signature *Signature, err string) *TaskState {
	return &TaskState{
		TaskUUID: signature.UUID,
		State:    StateFailure,
		Error:    err,
	}
}
851322
func NewHistoryState(req *http.Request, resp *http.Response, dom *goquery.Document) *State {
	return &State{
		Request:  req,
		Response: resp,
		Dom:      dom,
	}
}
1369141
func NewState(caller base.APICaller, machineTag names.MachineTag) State {
	return &state{
		facade:     base.NewFacadeCaller(caller, "Reboot"),
		machineTag: machineTag,
	}
}
110354
func (_m *Facade) SetServicesCurrentState(ctx datastore.Context, currentState service.ServiceCurrentState, serviceIDs ...string) {
	_m.Called(ctx, currentState, serviceIDs)
}
1136260
func NewState() *State {
	return &State{
		store:                        store.NewNilStore(),
		monitor:                      monitor.NewNilMonitor(),
		invokeGlobalCallbacksOnFlush: true,
	}
}
14472
func translateState(azureState string) string {
	switch azureState {
	case running:
		return lvm.VMRunning
	case stopped:
		return lvm.VMHalted
	default:
		return lvm.VMUnknown
	}
}
220062
func NewBatchTaskState(stateName string,
	parameters BatchTaskParameters) *BatchTaskState {

	sns := &BatchTaskState{
		BaseTask: BaseTask{
			baseInnerState: baseInnerState{
				name: stateName,
				id:   rand.Int63(),
			},
		},
		parameters: parameters,
	}
	return sns
}
526224
func NewMockMeterStatusState(ctrl *gomock.Controller) *MockMeterStatusState {
	mock := &MockMeterStatusState{ctrl: ctrl}
	mock.recorder = &MockMeterStatusStateMockRecorder{mock}
	return mock
}