id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
133,700 | hashicorp/nomad | client/allocrunner/taskrunner/lifecycle.go | Restart | func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error {
tr.logger.Trace("Restart requested", "failure", failure)
// Grab the handle
handle := tr.getDriverHandle()
// Check it is running
if handle == nil {
return ErrTaskNotRunning
}
// Emit the event since it may ta... | go | func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error {
tr.logger.Trace("Restart requested", "failure", failure)
// Grab the handle
handle := tr.getDriverHandle()
// Check it is running
if handle == nil {
return ErrTaskNotRunning
}
// Emit the event since it may ta... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"Restart",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"*",
"structs",
".",
"TaskEvent",
",",
"failure",
"bool",
")",
"error",
"{",
"tr",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
",",
"\"",
"... | // Restart a task. Returns immediately if no task is running. Blocks until
// existing task exits or passed-in context is canceled. | [
"Restart",
"a",
"task",
".",
"Returns",
"immediately",
"if",
"no",
"task",
"is",
"running",
".",
"Blocks",
"until",
"existing",
"task",
"exits",
"or",
"passed",
"-",
"in",
"context",
"is",
"canceled",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/lifecycle.go#L11-L48 |
133,701 | hashicorp/nomad | client/allocrunner/taskrunner/lifecycle.go | Kill | func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error {
tr.logger.Trace("Kill requested", "event_type", event.Type, "event_reason", event.KillReason)
// Cancel the task runner to break out of restart delay or the main run
// loop.
tr.killCtxCancel()
// Emit kill event
tr.EmitEvent(even... | go | func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error {
tr.logger.Trace("Kill requested", "event_type", event.Type, "event_reason", event.KillReason)
// Cancel the task runner to break out of restart delay or the main run
// loop.
tr.killCtxCancel()
// Emit kill event
tr.EmitEvent(even... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"Kill",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"*",
"structs",
".",
"TaskEvent",
")",
"error",
"{",
"tr",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"event",
".",
"... | // Kill a task. Blocks until task exits or context is canceled. State is set to
// dead. | [
"Kill",
"a",
"task",
".",
"Blocks",
"until",
"task",
"exits",
"or",
"context",
"is",
"canceled",
".",
"State",
"is",
"set",
"to",
"dead",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/lifecycle.go#L70-L87 |
133,702 | hashicorp/nomad | nomad/core_sched.go | NewCoreScheduler | func NewCoreScheduler(srv *Server, snap *state.StateSnapshot) scheduler.Scheduler {
s := &CoreScheduler{
srv: srv,
snap: snap,
logger: srv.logger.ResetNamed("core.sched"),
}
return s
} | go | func NewCoreScheduler(srv *Server, snap *state.StateSnapshot) scheduler.Scheduler {
s := &CoreScheduler{
srv: srv,
snap: snap,
logger: srv.logger.ResetNamed("core.sched"),
}
return s
} | [
"func",
"NewCoreScheduler",
"(",
"srv",
"*",
"Server",
",",
"snap",
"*",
"state",
".",
"StateSnapshot",
")",
"scheduler",
".",
"Scheduler",
"{",
"s",
":=",
"&",
"CoreScheduler",
"{",
"srv",
":",
"srv",
",",
"snap",
":",
"snap",
",",
"logger",
":",
"srv... | // NewCoreScheduler is used to return a new system scheduler instance | [
"NewCoreScheduler",
"is",
"used",
"to",
"return",
"a",
"new",
"system",
"scheduler",
"instance"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L32-L39 |
133,703 | hashicorp/nomad | nomad/core_sched.go | Process | func (c *CoreScheduler) Process(eval *structs.Evaluation) error {
switch eval.JobID {
case structs.CoreJobEvalGC:
return c.evalGC(eval)
case structs.CoreJobNodeGC:
return c.nodeGC(eval)
case structs.CoreJobJobGC:
return c.jobGC(eval)
case structs.CoreJobDeploymentGC:
return c.deploymentGC(eval)
case struc... | go | func (c *CoreScheduler) Process(eval *structs.Evaluation) error {
switch eval.JobID {
case structs.CoreJobEvalGC:
return c.evalGC(eval)
case structs.CoreJobNodeGC:
return c.nodeGC(eval)
case structs.CoreJobJobGC:
return c.jobGC(eval)
case structs.CoreJobDeploymentGC:
return c.deploymentGC(eval)
case struc... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"Process",
"(",
"eval",
"*",
"structs",
".",
"Evaluation",
")",
"error",
"{",
"switch",
"eval",
".",
"JobID",
"{",
"case",
"structs",
".",
"CoreJobEvalGC",
":",
"return",
"c",
".",
"evalGC",
"(",
"eval",
")"... | // Process is used to implement the scheduler.Scheduler interface | [
"Process",
"is",
"used",
"to",
"implement",
"the",
"scheduler",
".",
"Scheduler",
"interface"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L42-L57 |
133,704 | hashicorp/nomad | nomad/core_sched.go | forceGC | func (c *CoreScheduler) forceGC(eval *structs.Evaluation) error {
if err := c.jobGC(eval); err != nil {
return err
}
if err := c.evalGC(eval); err != nil {
return err
}
if err := c.deploymentGC(eval); err != nil {
return err
}
// Node GC must occur after the others to ensure the allocations are
// cleare... | go | func (c *CoreScheduler) forceGC(eval *structs.Evaluation) error {
if err := c.jobGC(eval); err != nil {
return err
}
if err := c.evalGC(eval); err != nil {
return err
}
if err := c.deploymentGC(eval); err != nil {
return err
}
// Node GC must occur after the others to ensure the allocations are
// cleare... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"forceGC",
"(",
"eval",
"*",
"structs",
".",
"Evaluation",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"jobGC",
"(",
"eval",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if... | // forceGC is used to garbage collect all eligible objects. | [
"forceGC",
"is",
"used",
"to",
"garbage",
"collect",
"all",
"eligible",
"objects",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L60-L74 |
133,705 | hashicorp/nomad | nomad/core_sched.go | jobGC | func (c *CoreScheduler) jobGC(eval *structs.Evaluation) error {
// Get all the jobs eligible for garbage collection.
ws := memdb.NewWatchSet()
iter, err := c.snap.JobsByGC(ws, true)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set th... | go | func (c *CoreScheduler) jobGC(eval *structs.Evaluation) error {
// Get all the jobs eligible for garbage collection.
ws := memdb.NewWatchSet()
iter, err := c.snap.JobsByGC(ws, true)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set th... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"jobGC",
"(",
"eval",
"*",
"structs",
".",
"Evaluation",
")",
"error",
"{",
"// Get all the jobs eligible for garbage collection.",
"ws",
":=",
"memdb",
".",
"NewWatchSet",
"(",
")",
"\n",
"iter",
",",
"err",
":=",
... | // jobGC is used to garbage collect eligible jobs. | [
"jobGC",
"is",
"used",
"to",
"garbage",
"collect",
"eligible",
"jobs",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L77-L159 |
133,706 | hashicorp/nomad | nomad/core_sched.go | jobReap | func (c *CoreScheduler) jobReap(jobs []*structs.Job, leaderACL string) error {
// Call to the leader to issue the reap
for _, req := range c.partitionJobReap(jobs, leaderACL) {
var resp structs.JobBatchDeregisterResponse
if err := c.srv.RPC("Job.BatchDeregister", req, &resp); err != nil {
c.logger.Error("batch... | go | func (c *CoreScheduler) jobReap(jobs []*structs.Job, leaderACL string) error {
// Call to the leader to issue the reap
for _, req := range c.partitionJobReap(jobs, leaderACL) {
var resp structs.JobBatchDeregisterResponse
if err := c.srv.RPC("Job.BatchDeregister", req, &resp); err != nil {
c.logger.Error("batch... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"jobReap",
"(",
"jobs",
"[",
"]",
"*",
"structs",
".",
"Job",
",",
"leaderACL",
"string",
")",
"error",
"{",
"// Call to the leader to issue the reap",
"for",
"_",
",",
"req",
":=",
"range",
"c",
".",
"partition... | // jobReap contacts the leader and issues a reap on the passed jobs | [
"jobReap",
"contacts",
"the",
"leader",
"and",
"issues",
"a",
"reap",
"on",
"the",
"passed",
"jobs"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L162-L173 |
133,707 | hashicorp/nomad | nomad/core_sched.go | partitionJobReap | func (c *CoreScheduler) partitionJobReap(jobs []*structs.Job, leaderACL string) []*structs.JobBatchDeregisterRequest {
option := &structs.JobDeregisterOptions{Purge: true}
var requests []*structs.JobBatchDeregisterRequest
submittedJobs := 0
for submittedJobs != len(jobs) {
req := &structs.JobBatchDeregisterReques... | go | func (c *CoreScheduler) partitionJobReap(jobs []*structs.Job, leaderACL string) []*structs.JobBatchDeregisterRequest {
option := &structs.JobDeregisterOptions{Purge: true}
var requests []*structs.JobBatchDeregisterRequest
submittedJobs := 0
for submittedJobs != len(jobs) {
req := &structs.JobBatchDeregisterReques... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"partitionJobReap",
"(",
"jobs",
"[",
"]",
"*",
"structs",
".",
"Job",
",",
"leaderACL",
"string",
")",
"[",
"]",
"*",
"structs",
".",
"JobBatchDeregisterRequest",
"{",
"option",
":=",
"&",
"structs",
".",
"Jo... | // partitionJobReap returns a list of JobBatchDeregisterRequests to make,
// ensuring a single request does not contain too many jobs. This is necessary
// to ensure that the Raft transaction does not become too large. | [
"partitionJobReap",
"returns",
"a",
"list",
"of",
"JobBatchDeregisterRequests",
"to",
"make",
"ensuring",
"a",
"single",
"request",
"does",
"not",
"contain",
"too",
"many",
"jobs",
".",
"This",
"is",
"necessary",
"to",
"ensure",
"that",
"the",
"Raft",
"transacti... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L178-L211 |
133,708 | hashicorp/nomad | nomad/core_sched.go | evalGC | func (c *CoreScheduler) evalGC(eval *structs.Evaluation) error {
// Iterate over the evaluations
ws := memdb.NewWatchSet()
iter, err := c.snap.Evals(ws)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set the threshold to its maximum so... | go | func (c *CoreScheduler) evalGC(eval *structs.Evaluation) error {
// Iterate over the evaluations
ws := memdb.NewWatchSet()
iter, err := c.snap.Evals(ws)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set the threshold to its maximum so... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"evalGC",
"(",
"eval",
"*",
"structs",
".",
"Evaluation",
")",
"error",
"{",
"// Iterate over the evaluations",
"ws",
":=",
"memdb",
".",
"NewWatchSet",
"(",
")",
"\n",
"iter",
",",
"err",
":=",
"c",
".",
"sna... | // evalGC is used to garbage collect old evaluations | [
"evalGC",
"is",
"used",
"to",
"garbage",
"collect",
"old",
"evaluations"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L214-L265 |
133,709 | hashicorp/nomad | nomad/core_sched.go | gcEval | func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64, allowBatch bool) (
bool, []string, error) {
// Ignore non-terminal and new evaluations
if !eval.TerminalStatus() || eval.ModifyIndex > thresholdIndex {
return false, nil, nil
}
// Create a watchset
ws := memdb.NewWatchSet()
// Lo... | go | func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64, allowBatch bool) (
bool, []string, error) {
// Ignore non-terminal and new evaluations
if !eval.TerminalStatus() || eval.ModifyIndex > thresholdIndex {
return false, nil, nil
}
// Create a watchset
ws := memdb.NewWatchSet()
// Lo... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"gcEval",
"(",
"eval",
"*",
"structs",
".",
"Evaluation",
",",
"thresholdIndex",
"uint64",
",",
"allowBatch",
"bool",
")",
"(",
"bool",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"// Ignore non-terminal an... | // gcEval returns whether the eval should be garbage collected given a raft
// threshold index. The eval disqualifies for garbage collection if it or its
// allocs are not older than the threshold. If the eval should be garbage
// collected, the associated alloc ids that should also be removed are also
// returned | [
"gcEval",
"returns",
"whether",
"the",
"eval",
"should",
"be",
"garbage",
"collected",
"given",
"a",
"raft",
"threshold",
"index",
".",
"The",
"eval",
"disqualifies",
"for",
"garbage",
"collection",
"if",
"it",
"or",
"its",
"allocs",
"are",
"not",
"older",
"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L272-L342 |
133,710 | hashicorp/nomad | nomad/core_sched.go | olderVersionTerminalAllocs | func olderVersionTerminalAllocs(allocs []*structs.Allocation, job *structs.Job) []string {
var ret []string
for _, alloc := range allocs {
if alloc.Job != nil && alloc.Job.CreateIndex < job.CreateIndex && alloc.TerminalStatus() {
ret = append(ret, alloc.ID)
}
}
return ret
} | go | func olderVersionTerminalAllocs(allocs []*structs.Allocation, job *structs.Job) []string {
var ret []string
for _, alloc := range allocs {
if alloc.Job != nil && alloc.Job.CreateIndex < job.CreateIndex && alloc.TerminalStatus() {
ret = append(ret, alloc.ID)
}
}
return ret
} | [
"func",
"olderVersionTerminalAllocs",
"(",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
",",
"job",
"*",
"structs",
".",
"Job",
")",
"[",
"]",
"string",
"{",
"var",
"ret",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"alloc",
":=",
"range",
"... | // olderVersionTerminalAllocs returns terminal allocations whose job create index
// is older than the job's create index | [
"olderVersionTerminalAllocs",
"returns",
"terminal",
"allocations",
"whose",
"job",
"create",
"index",
"is",
"older",
"than",
"the",
"job",
"s",
"create",
"index"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L346-L354 |
133,711 | hashicorp/nomad | nomad/core_sched.go | evalReap | func (c *CoreScheduler) evalReap(evals, allocs []string) error {
// Call to the leader to issue the reap
for _, req := range c.partitionEvalReap(evals, allocs) {
var resp structs.GenericResponse
if err := c.srv.RPC("Eval.Reap", req, &resp); err != nil {
c.logger.Error("eval reap failed", "error", err)
retur... | go | func (c *CoreScheduler) evalReap(evals, allocs []string) error {
// Call to the leader to issue the reap
for _, req := range c.partitionEvalReap(evals, allocs) {
var resp structs.GenericResponse
if err := c.srv.RPC("Eval.Reap", req, &resp); err != nil {
c.logger.Error("eval reap failed", "error", err)
retur... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"evalReap",
"(",
"evals",
",",
"allocs",
"[",
"]",
"string",
")",
"error",
"{",
"// Call to the leader to issue the reap",
"for",
"_",
",",
"req",
":=",
"range",
"c",
".",
"partitionEvalReap",
"(",
"evals",
",",
... | // evalReap contacts the leader and issues a reap on the passed evals and
// allocs. | [
"evalReap",
"contacts",
"the",
"leader",
"and",
"issues",
"a",
"reap",
"on",
"the",
"passed",
"evals",
"and",
"allocs",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L358-L369 |
133,712 | hashicorp/nomad | nomad/core_sched.go | partitionEvalReap | func (c *CoreScheduler) partitionEvalReap(evals, allocs []string) []*structs.EvalDeleteRequest {
var requests []*structs.EvalDeleteRequest
submittedEvals, submittedAllocs := 0, 0
for submittedEvals != len(evals) || submittedAllocs != len(allocs) {
req := &structs.EvalDeleteRequest{
WriteRequest: structs.WriteRe... | go | func (c *CoreScheduler) partitionEvalReap(evals, allocs []string) []*structs.EvalDeleteRequest {
var requests []*structs.EvalDeleteRequest
submittedEvals, submittedAllocs := 0, 0
for submittedEvals != len(evals) || submittedAllocs != len(allocs) {
req := &structs.EvalDeleteRequest{
WriteRequest: structs.WriteRe... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"partitionEvalReap",
"(",
"evals",
",",
"allocs",
"[",
"]",
"string",
")",
"[",
"]",
"*",
"structs",
".",
"EvalDeleteRequest",
"{",
"var",
"requests",
"[",
"]",
"*",
"structs",
".",
"EvalDeleteRequest",
"\n",
... | // partitionEvalReap returns a list of EvalDeleteRequest to make, ensuring a single
// request does not contain too many allocations and evaluations. This is
// necessary to ensure that the Raft transaction does not become too large. | [
"partitionEvalReap",
"returns",
"a",
"list",
"of",
"EvalDeleteRequest",
"to",
"make",
"ensuring",
"a",
"single",
"request",
"does",
"not",
"contain",
"too",
"many",
"allocations",
"and",
"evaluations",
".",
"This",
"is",
"necessary",
"to",
"ensure",
"that",
"the... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L374-L414 |
133,713 | hashicorp/nomad | nomad/core_sched.go | nodeGC | func (c *CoreScheduler) nodeGC(eval *structs.Evaluation) error {
// Iterate over the evaluations
ws := memdb.NewWatchSet()
iter, err := c.snap.Nodes(ws)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set the threshold to its maximum so... | go | func (c *CoreScheduler) nodeGC(eval *structs.Evaluation) error {
// Iterate over the evaluations
ws := memdb.NewWatchSet()
iter, err := c.snap.Nodes(ws)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set the threshold to its maximum so... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"nodeGC",
"(",
"eval",
"*",
"structs",
".",
"Evaluation",
")",
"error",
"{",
"// Iterate over the evaluations",
"ws",
":=",
"memdb",
".",
"NewWatchSet",
"(",
")",
"\n",
"iter",
",",
"err",
":=",
"c",
".",
"sna... | // nodeGC is used to garbage collect old nodes | [
"nodeGC",
"is",
"used",
"to",
"garbage",
"collect",
"old",
"nodes"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L417-L502 |
133,714 | hashicorp/nomad | nomad/core_sched.go | deploymentGC | func (c *CoreScheduler) deploymentGC(eval *structs.Evaluation) error {
// Iterate over the deployments
ws := memdb.NewWatchSet()
iter, err := c.snap.Deployments(ws)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set the threshold to it... | go | func (c *CoreScheduler) deploymentGC(eval *structs.Evaluation) error {
// Iterate over the deployments
ws := memdb.NewWatchSet()
iter, err := c.snap.Deployments(ws)
if err != nil {
return err
}
var oldThreshold uint64
if eval.JobID == structs.CoreJobForceGC {
// The GC was forced, so set the threshold to it... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"deploymentGC",
"(",
"eval",
"*",
"structs",
".",
"Evaluation",
")",
"error",
"{",
"// Iterate over the deployments",
"ws",
":=",
"memdb",
".",
"NewWatchSet",
"(",
")",
"\n",
"iter",
",",
"err",
":=",
"c",
".",
... | // deploymentGC is used to garbage collect old deployments | [
"deploymentGC",
"is",
"used",
"to",
"garbage",
"collect",
"old",
"deployments"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L505-L571 |
133,715 | hashicorp/nomad | nomad/core_sched.go | deploymentReap | func (c *CoreScheduler) deploymentReap(deployments []string) error {
// Call to the leader to issue the reap
for _, req := range c.partitionDeploymentReap(deployments) {
var resp structs.GenericResponse
if err := c.srv.RPC("Deployment.Reap", req, &resp); err != nil {
c.logger.Error("deployment reap failed", "e... | go | func (c *CoreScheduler) deploymentReap(deployments []string) error {
// Call to the leader to issue the reap
for _, req := range c.partitionDeploymentReap(deployments) {
var resp structs.GenericResponse
if err := c.srv.RPC("Deployment.Reap", req, &resp); err != nil {
c.logger.Error("deployment reap failed", "e... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"deploymentReap",
"(",
"deployments",
"[",
"]",
"string",
")",
"error",
"{",
"// Call to the leader to issue the reap",
"for",
"_",
",",
"req",
":=",
"range",
"c",
".",
"partitionDeploymentReap",
"(",
"deployments",
"... | // deploymentReap contacts the leader and issues a reap on the passed
// deployments. | [
"deploymentReap",
"contacts",
"the",
"leader",
"and",
"issues",
"a",
"reap",
"on",
"the",
"passed",
"deployments",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L575-L586 |
133,716 | hashicorp/nomad | nomad/core_sched.go | partitionDeploymentReap | func (c *CoreScheduler) partitionDeploymentReap(deployments []string) []*structs.DeploymentDeleteRequest {
var requests []*structs.DeploymentDeleteRequest
submittedDeployments := 0
for submittedDeployments != len(deployments) {
req := &structs.DeploymentDeleteRequest{
WriteRequest: structs.WriteRequest{
Reg... | go | func (c *CoreScheduler) partitionDeploymentReap(deployments []string) []*structs.DeploymentDeleteRequest {
var requests []*structs.DeploymentDeleteRequest
submittedDeployments := 0
for submittedDeployments != len(deployments) {
req := &structs.DeploymentDeleteRequest{
WriteRequest: structs.WriteRequest{
Reg... | [
"func",
"(",
"c",
"*",
"CoreScheduler",
")",
"partitionDeploymentReap",
"(",
"deployments",
"[",
"]",
"string",
")",
"[",
"]",
"*",
"structs",
".",
"DeploymentDeleteRequest",
"{",
"var",
"requests",
"[",
"]",
"*",
"structs",
".",
"DeploymentDeleteRequest",
"\n... | // partitionDeploymentReap returns a list of DeploymentDeleteRequest to make,
// ensuring a single request does not contain too many deployments. This is
// necessary to ensure that the Raft transaction does not become too large. | [
"partitionDeploymentReap",
"returns",
"a",
"list",
"of",
"DeploymentDeleteRequest",
"to",
"make",
"ensuring",
"a",
"single",
"request",
"does",
"not",
"contain",
"too",
"many",
"deployments",
".",
"This",
"is",
"necessary",
"to",
"ensure",
"that",
"the",
"Raft",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L591-L615 |
133,717 | hashicorp/nomad | nomad/core_sched.go | allocGCEligible | func allocGCEligible(a *structs.Allocation, job *structs.Job, gcTime time.Time, thresholdIndex uint64) bool {
// Not in a terminal status and old enough
if !a.TerminalStatus() || a.ModifyIndex > thresholdIndex {
return false
}
// If the allocation is still running on the client we can not garbage
// collect it.... | go | func allocGCEligible(a *structs.Allocation, job *structs.Job, gcTime time.Time, thresholdIndex uint64) bool {
// Not in a terminal status and old enough
if !a.TerminalStatus() || a.ModifyIndex > thresholdIndex {
return false
}
// If the allocation is still running on the client we can not garbage
// collect it.... | [
"func",
"allocGCEligible",
"(",
"a",
"*",
"structs",
".",
"Allocation",
",",
"job",
"*",
"structs",
".",
"Job",
",",
"gcTime",
"time",
".",
"Time",
",",
"thresholdIndex",
"uint64",
")",
"bool",
"{",
"// Not in a terminal status and old enough",
"if",
"!",
"a",... | // allocGCEligible returns if the allocation is eligible to be garbage collected
// according to its terminal status and its reschedule trackers | [
"allocGCEligible",
"returns",
"if",
"the",
"allocation",
"is",
"eligible",
"to",
"be",
"garbage",
"collected",
"according",
"to",
"its",
"terminal",
"status",
"and",
"its",
"reschedule",
"trackers"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/core_sched.go#L619-L681 |
133,718 | hashicorp/nomad | nomad/job_endpoint_oss.go | enforceSubmitJob | func (j *Job) enforceSubmitJob(override bool, job *structs.Job) (error, error) {
return nil, nil
} | go | func (j *Job) enforceSubmitJob(override bool, job *structs.Job) (error, error) {
return nil, nil
} | [
"func",
"(",
"j",
"*",
"Job",
")",
"enforceSubmitJob",
"(",
"override",
"bool",
",",
"job",
"*",
"structs",
".",
"Job",
")",
"(",
"error",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // enforceSubmitJob is used to check any Sentinel policies for the submit-job scope | [
"enforceSubmitJob",
"is",
"used",
"to",
"check",
"any",
"Sentinel",
"policies",
"for",
"the",
"submit",
"-",
"job",
"scope"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/job_endpoint_oss.go#L8-L10 |
133,719 | hashicorp/nomad | client/fingerprint/arch.go | NewArchFingerprint | func NewArchFingerprint(logger log.Logger) Fingerprint {
f := &ArchFingerprint{logger: logger.Named("arch")}
return f
} | go | func NewArchFingerprint(logger log.Logger) Fingerprint {
f := &ArchFingerprint{logger: logger.Named("arch")}
return f
} | [
"func",
"NewArchFingerprint",
"(",
"logger",
"log",
".",
"Logger",
")",
"Fingerprint",
"{",
"f",
":=",
"&",
"ArchFingerprint",
"{",
"logger",
":",
"logger",
".",
"Named",
"(",
"\"",
"\"",
")",
"}",
"\n",
"return",
"f",
"\n",
"}"
] | // NewArchFingerprint is used to create an OS fingerprint | [
"NewArchFingerprint",
"is",
"used",
"to",
"create",
"an",
"OS",
"fingerprint"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fingerprint/arch.go#L16-L19 |
133,720 | hashicorp/nomad | client/allocrunner/alloc_runner.go | NewAllocRunner | func NewAllocRunner(config *Config) (*allocRunner, error) {
alloc := config.Alloc
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg == nil {
return nil, fmt.Errorf("failed to lookup task group %q", alloc.TaskGroup)
}
ar := &allocRunner{
id: alloc.ID,
alloc: allo... | go | func NewAllocRunner(config *Config) (*allocRunner, error) {
alloc := config.Alloc
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg == nil {
return nil, fmt.Errorf("failed to lookup task group %q", alloc.TaskGroup)
}
ar := &allocRunner{
id: alloc.ID,
alloc: allo... | [
"func",
"NewAllocRunner",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"allocRunner",
",",
"error",
")",
"{",
"alloc",
":=",
"config",
".",
"Alloc",
"\n",
"tg",
":=",
"alloc",
".",
"Job",
".",
"LookupTaskGroup",
"(",
"alloc",
".",
"TaskGroup",
")",
"\n... | // NewAllocRunner returns a new allocation runner. | [
"NewAllocRunner",
"returns",
"a",
"new",
"allocation",
"runner",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L142-L190 |
133,721 | hashicorp/nomad | client/allocrunner/alloc_runner.go | Run | func (ar *allocRunner) Run() {
// Close the wait channel on return
defer close(ar.waitCh)
// Start the task state update handler
go ar.handleTaskStateUpdates()
// Start the alloc update handler
go ar.handleAllocUpdates()
// If task update chan has been closed, that means we've been shutdown.
select {
case <... | go | func (ar *allocRunner) Run() {
// Close the wait channel on return
defer close(ar.waitCh)
// Start the task state update handler
go ar.handleTaskStateUpdates()
// Start the alloc update handler
go ar.handleAllocUpdates()
// If task update chan has been closed, that means we've been shutdown.
select {
case <... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"Run",
"(",
")",
"{",
"// Close the wait channel on return",
"defer",
"close",
"(",
"ar",
".",
"waitCh",
")",
"\n\n",
"// Start the task state update handler",
"go",
"ar",
".",
"handleTaskStateUpdates",
"(",
")",
"\n\n",... | // Run the AllocRunner. Starts tasks if the alloc is non-terminal and closes
// WaitCh when it exits. Should be started in a goroutine. | [
"Run",
"the",
"AllocRunner",
".",
"Starts",
"tasks",
"if",
"the",
"alloc",
"is",
"non",
"-",
"terminal",
"and",
"closes",
"WaitCh",
"when",
"it",
"exits",
".",
"Should",
"be",
"started",
"in",
"a",
"goroutine",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L227-L261 |
133,722 | hashicorp/nomad | client/allocrunner/alloc_runner.go | shouldRun | func (ar *allocRunner) shouldRun() bool {
// Do not run allocs that are terminal
if ar.Alloc().TerminalStatus() {
ar.logger.Trace("alloc terminal; not running",
"desired_status", ar.Alloc().DesiredStatus,
"client_status", ar.Alloc().ClientStatus,
)
return false
}
// It's possible that the alloc local s... | go | func (ar *allocRunner) shouldRun() bool {
// Do not run allocs that are terminal
if ar.Alloc().TerminalStatus() {
ar.logger.Trace("alloc terminal; not running",
"desired_status", ar.Alloc().DesiredStatus,
"client_status", ar.Alloc().ClientStatus,
)
return false
}
// It's possible that the alloc local s... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"shouldRun",
"(",
")",
"bool",
"{",
"// Do not run allocs that are terminal",
"if",
"ar",
".",
"Alloc",
"(",
")",
".",
"TerminalStatus",
"(",
")",
"{",
"ar",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
",",
... | // shouldRun returns true if the alloc is in a state that the alloc runner
// should run it. | [
"shouldRun",
"returns",
"true",
"if",
"the",
"alloc",
"is",
"in",
"a",
"state",
"that",
"the",
"alloc",
"runner",
"should",
"run",
"it",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L265-L285 |
133,723 | hashicorp/nomad | client/allocrunner/alloc_runner.go | runTasks | func (ar *allocRunner) runTasks() {
for _, task := range ar.tasks {
go task.Run()
}
for _, task := range ar.tasks {
<-task.WaitCh()
}
} | go | func (ar *allocRunner) runTasks() {
for _, task := range ar.tasks {
go task.Run()
}
for _, task := range ar.tasks {
<-task.WaitCh()
}
} | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"runTasks",
"(",
")",
"{",
"for",
"_",
",",
"task",
":=",
"range",
"ar",
".",
"tasks",
"{",
"go",
"task",
".",
"Run",
"(",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"task",
":=",
"range",
"ar",
".",
... | // runTasks is used to run the task runners and block until they exit. | [
"runTasks",
"is",
"used",
"to",
"run",
"the",
"task",
"runners",
"and",
"block",
"until",
"they",
"exit",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L288-L296 |
133,724 | hashicorp/nomad | client/allocrunner/alloc_runner.go | Alloc | func (ar *allocRunner) Alloc() *structs.Allocation {
ar.allocLock.RLock()
defer ar.allocLock.RUnlock()
return ar.alloc
} | go | func (ar *allocRunner) Alloc() *structs.Allocation {
ar.allocLock.RLock()
defer ar.allocLock.RUnlock()
return ar.alloc
} | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"Alloc",
"(",
")",
"*",
"structs",
".",
"Allocation",
"{",
"ar",
".",
"allocLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"ar",
".",
"allocLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"ar",
".",
"allo... | // Alloc returns the current allocation being run by this runner as sent by the
// server. This view of the allocation does not have updated task states. | [
"Alloc",
"returns",
"the",
"current",
"allocation",
"being",
"run",
"by",
"this",
"runner",
"as",
"sent",
"by",
"the",
"server",
".",
"This",
"view",
"of",
"the",
"allocation",
"does",
"not",
"have",
"updated",
"task",
"states",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L300-L304 |
133,725 | hashicorp/nomad | client/allocrunner/alloc_runner.go | Restore | func (ar *allocRunner) Restore() error {
// Retrieve deployment status to avoid reseting it across agent
// restarts. Once a deployment status is set Nomad no longer monitors
// alloc health, so we must persist deployment state across restarts.
ds, err := ar.stateDB.GetDeploymentStatus(ar.id)
if err != nil {
ret... | go | func (ar *allocRunner) Restore() error {
// Retrieve deployment status to avoid reseting it across agent
// restarts. Once a deployment status is set Nomad no longer monitors
// alloc health, so we must persist deployment state across restarts.
ds, err := ar.stateDB.GetDeploymentStatus(ar.id)
if err != nil {
ret... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"Restore",
"(",
")",
"error",
"{",
"// Retrieve deployment status to avoid reseting it across agent",
"// restarts. Once a deployment status is set Nomad no longer monitors",
"// alloc health, so we must persist deployment state across restarts."... | // Restore state from database. Must be called after NewAllocRunner but before
// Run. | [
"Restore",
"state",
"from",
"database",
".",
"Must",
"be",
"called",
"after",
"NewAllocRunner",
"but",
"before",
"Run",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L319-L340 |
133,726 | hashicorp/nomad | client/allocrunner/alloc_runner.go | persistDeploymentStatus | func (ar *allocRunner) persistDeploymentStatus(ds *structs.AllocDeploymentStatus) {
if err := ar.stateDB.PutDeploymentStatus(ar.id, ds); err != nil {
// While any persistence errors are very bad, the worst case
// scenario for failing to persist deployment status is that if
// the agent is restarted it will moni... | go | func (ar *allocRunner) persistDeploymentStatus(ds *structs.AllocDeploymentStatus) {
if err := ar.stateDB.PutDeploymentStatus(ar.id, ds); err != nil {
// While any persistence errors are very bad, the worst case
// scenario for failing to persist deployment status is that if
// the agent is restarted it will moni... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"persistDeploymentStatus",
"(",
"ds",
"*",
"structs",
".",
"AllocDeploymentStatus",
")",
"{",
"if",
"err",
":=",
"ar",
".",
"stateDB",
".",
"PutDeploymentStatus",
"(",
"ar",
".",
"id",
",",
"ds",
")",
";",
"err... | // persistDeploymentStatus stores AllocDeploymentStatus. | [
"persistDeploymentStatus",
"stores",
"AllocDeploymentStatus",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L343-L353 |
133,727 | hashicorp/nomad | client/allocrunner/alloc_runner.go | handleTaskStateUpdates | func (ar *allocRunner) handleTaskStateUpdates() {
defer close(ar.taskStateUpdateHandlerCh)
for done := false; !done; {
select {
case <-ar.taskStateUpdatedCh:
case <-ar.waitCh:
// Run has exited, sync once more to ensure final
// states are collected.
done = true
}
ar.logger.Trace("handling task s... | go | func (ar *allocRunner) handleTaskStateUpdates() {
defer close(ar.taskStateUpdateHandlerCh)
for done := false; !done; {
select {
case <-ar.taskStateUpdatedCh:
case <-ar.waitCh:
// Run has exited, sync once more to ensure final
// states are collected.
done = true
}
ar.logger.Trace("handling task s... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"handleTaskStateUpdates",
"(",
")",
"{",
"defer",
"close",
"(",
"ar",
".",
"taskStateUpdateHandlerCh",
")",
"\n\n",
"for",
"done",
":=",
"false",
";",
"!",
"done",
";",
"{",
"select",
"{",
"case",
"<-",
"ar",
... | // handleTaskStateUpdates must be run in goroutine as it monitors
// taskStateUpdatedCh for task state update notifications and processes task
// states.
//
// Processing task state updates must be done in a goroutine as it may have to
// kill tasks which causes further task state updates. | [
"handleTaskStateUpdates",
"must",
"be",
"run",
"in",
"goroutine",
"as",
"it",
"monitors",
"taskStateUpdatedCh",
"for",
"task",
"state",
"update",
"notifications",
"and",
"processes",
"task",
"states",
".",
"Processing",
"task",
"state",
"updates",
"must",
"be",
"d... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L377-L472 |
133,728 | hashicorp/nomad | client/allocrunner/alloc_runner.go | clientAlloc | func (ar *allocRunner) clientAlloc(taskStates map[string]*structs.TaskState) *structs.Allocation {
ar.stateLock.Lock()
defer ar.stateLock.Unlock()
// store task states for AllocState to expose
ar.state.TaskStates = taskStates
a := &structs.Allocation{
ID: ar.id,
TaskStates: taskStates,
}
if d := a... | go | func (ar *allocRunner) clientAlloc(taskStates map[string]*structs.TaskState) *structs.Allocation {
ar.stateLock.Lock()
defer ar.stateLock.Unlock()
// store task states for AllocState to expose
ar.state.TaskStates = taskStates
a := &structs.Allocation{
ID: ar.id,
TaskStates: taskStates,
}
if d := a... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"clientAlloc",
"(",
"taskStates",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"TaskState",
")",
"*",
"structs",
".",
"Allocation",
"{",
"ar",
".",
"stateLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ar",
... | // clientAlloc takes in the task states and returns an Allocation populated
// with Client specific fields | [
"clientAlloc",
"takes",
"in",
"the",
"task",
"states",
"and",
"returns",
"an",
"Allocation",
"populated",
"with",
"Client",
"specific",
"fields"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L525-L579 |
133,729 | hashicorp/nomad | client/allocrunner/alloc_runner.go | getClientStatus | func getClientStatus(taskStates map[string]*structs.TaskState) (status, description string) {
var pending, running, dead, failed bool
for _, state := range taskStates {
switch state.State {
case structs.TaskStateRunning:
running = true
case structs.TaskStatePending:
pending = true
case structs.TaskState... | go | func getClientStatus(taskStates map[string]*structs.TaskState) (status, description string) {
var pending, running, dead, failed bool
for _, state := range taskStates {
switch state.State {
case structs.TaskStateRunning:
running = true
case structs.TaskStatePending:
pending = true
case structs.TaskState... | [
"func",
"getClientStatus",
"(",
"taskStates",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"TaskState",
")",
"(",
"status",
",",
"description",
"string",
")",
"{",
"var",
"pending",
",",
"running",
",",
"dead",
",",
"failed",
"bool",
"\n",
"for",
"_",... | // getClientStatus takes in the task states for a given allocation and computes
// the client status and description | [
"getClientStatus",
"takes",
"in",
"the",
"task",
"states",
"for",
"a",
"given",
"allocation",
"and",
"computes",
"the",
"client",
"status",
"and",
"description"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L583-L612 |
133,730 | hashicorp/nomad | client/allocrunner/alloc_runner.go | SetClientStatus | func (ar *allocRunner) SetClientStatus(clientStatus string) {
ar.stateLock.Lock()
defer ar.stateLock.Unlock()
ar.state.ClientStatus = clientStatus
} | go | func (ar *allocRunner) SetClientStatus(clientStatus string) {
ar.stateLock.Lock()
defer ar.stateLock.Unlock()
ar.state.ClientStatus = clientStatus
} | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"SetClientStatus",
"(",
"clientStatus",
"string",
")",
"{",
"ar",
".",
"stateLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ar",
".",
"stateLock",
".",
"Unlock",
"(",
")",
"\n",
"ar",
".",
"state",
".",
"Cli... | // SetClientStatus is a helper for forcing a specific client
// status on the alloc runner. This is used during restore errors
// when the task state can't be restored. | [
"SetClientStatus",
"is",
"a",
"helper",
"for",
"forcing",
"a",
"specific",
"client",
"status",
"on",
"the",
"alloc",
"runner",
".",
"This",
"is",
"used",
"during",
"restore",
"errors",
"when",
"the",
"task",
"state",
"can",
"t",
"be",
"restored",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L617-L621 |
133,731 | hashicorp/nomad | client/allocrunner/alloc_runner.go | AllocState | func (ar *allocRunner) AllocState() *state.State {
ar.stateLock.RLock()
state := ar.state.Copy()
ar.stateLock.RUnlock()
// If TaskStateUpdated has not been called yet, ar.state.TaskStates
// won't be set as it is not the canonical source of TaskStates.
if len(state.TaskStates) == 0 {
ar.state.TaskStates = make... | go | func (ar *allocRunner) AllocState() *state.State {
ar.stateLock.RLock()
state := ar.state.Copy()
ar.stateLock.RUnlock()
// If TaskStateUpdated has not been called yet, ar.state.TaskStates
// won't be set as it is not the canonical source of TaskStates.
if len(state.TaskStates) == 0 {
ar.state.TaskStates = make... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"AllocState",
"(",
")",
"*",
"state",
".",
"State",
"{",
"ar",
".",
"stateLock",
".",
"RLock",
"(",
")",
"\n",
"state",
":=",
"ar",
".",
"state",
".",
"Copy",
"(",
")",
"\n",
"ar",
".",
"stateLock",
"."... | // AllocState returns a copy of allocation state including a snapshot of task
// states. | [
"AllocState",
"returns",
"a",
"copy",
"of",
"allocation",
"state",
"including",
"a",
"snapshot",
"of",
"task",
"states",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L625-L646 |
133,732 | hashicorp/nomad | client/allocrunner/alloc_runner.go | Update | func (ar *allocRunner) Update(update *structs.Allocation) {
select {
// Drain queued update from the channel if possible, and check the modify
// index
case oldUpdate := <-ar.allocUpdatedCh:
// If the old update is newer than the replacement, then skip the new one
// and return. This case shouldn't happen, but ... | go | func (ar *allocRunner) Update(update *structs.Allocation) {
select {
// Drain queued update from the channel if possible, and check the modify
// index
case oldUpdate := <-ar.allocUpdatedCh:
// If the old update is newer than the replacement, then skip the new one
// and return. This case shouldn't happen, but ... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"Update",
"(",
"update",
"*",
"structs",
".",
"Allocation",
")",
"{",
"select",
"{",
"// Drain queued update from the channel if possible, and check the modify",
"// index",
"case",
"oldUpdate",
":=",
"<-",
"ar",
".",
"all... | // Update asyncronously updates the running allocation with a new version
// received from the server.
// When processing a new update, we will first attempt to drain stale updates
// from the queue, before appending the new one. | [
"Update",
"asyncronously",
"updates",
"the",
"running",
"allocation",
"with",
"a",
"new",
"version",
"received",
"from",
"the",
"server",
".",
"When",
"processing",
"a",
"new",
"update",
"we",
"will",
"first",
"attempt",
"to",
"drain",
"stale",
"updates",
"fro... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L652-L680 |
133,733 | hashicorp/nomad | client/allocrunner/alloc_runner.go | handleAllocUpdate | func (ar *allocRunner) handleAllocUpdate(update *structs.Allocation) {
// Detect Stop updates
stopping := !ar.Alloc().TerminalStatus() && update.TerminalStatus()
// Update ar.alloc
ar.setAlloc(update)
// Run update hooks if not stopping or dead
if !update.TerminalStatus() {
if err := ar.update(update); err !=... | go | func (ar *allocRunner) handleAllocUpdate(update *structs.Allocation) {
// Detect Stop updates
stopping := !ar.Alloc().TerminalStatus() && update.TerminalStatus()
// Update ar.alloc
ar.setAlloc(update)
// Run update hooks if not stopping or dead
if !update.TerminalStatus() {
if err := ar.update(update); err !=... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"handleAllocUpdate",
"(",
"update",
"*",
"structs",
".",
"Allocation",
")",
"{",
"// Detect Stop updates",
"stopping",
":=",
"!",
"ar",
".",
"Alloc",
"(",
")",
".",
"TerminalStatus",
"(",
")",
"&&",
"update",
"."... | // This method sends the updated alloc to Run for serially processing updates.
// If there is already a pending update it will be discarded and replaced by
// the latest update. | [
"This",
"method",
"sends",
"the",
"updated",
"alloc",
"to",
"Run",
"for",
"serially",
"processing",
"updates",
".",
"If",
"there",
"is",
"already",
"a",
"pending",
"update",
"it",
"will",
"be",
"discarded",
"and",
"replaced",
"by",
"the",
"latest",
"update",... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L696-L721 |
133,734 | hashicorp/nomad | client/allocrunner/alloc_runner.go | RestartTask | func (ar *allocRunner) RestartTask(taskName string, taskEvent *structs.TaskEvent) error {
tr, ok := ar.tasks[taskName]
if !ok {
return fmt.Errorf("Could not find task runner for task: %s", taskName)
}
return tr.Restart(context.TODO(), taskEvent, false)
} | go | func (ar *allocRunner) RestartTask(taskName string, taskEvent *structs.TaskEvent) error {
tr, ok := ar.tasks[taskName]
if !ok {
return fmt.Errorf("Could not find task runner for task: %s", taskName)
}
return tr.Restart(context.TODO(), taskEvent, false)
} | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"RestartTask",
"(",
"taskName",
"string",
",",
"taskEvent",
"*",
"structs",
".",
"TaskEvent",
")",
"error",
"{",
"tr",
",",
"ok",
":=",
"ar",
".",
"tasks",
"[",
"taskName",
"]",
"\n",
"if",
"!",
"ok",
"{",
... | // RestartTask signalls the task runner for the provided task to restart. | [
"RestartTask",
"signalls",
"the",
"task",
"runner",
"for",
"the",
"provided",
"task",
"to",
"restart",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L942-L949 |
133,735 | hashicorp/nomad | client/allocrunner/alloc_runner.go | RestartAll | func (ar *allocRunner) RestartAll(taskEvent *structs.TaskEvent) error {
var err *multierror.Error
for tn := range ar.tasks {
rerr := ar.RestartTask(tn, taskEvent.Copy())
if rerr != nil {
err = multierror.Append(err, rerr)
}
}
return err.ErrorOrNil()
} | go | func (ar *allocRunner) RestartAll(taskEvent *structs.TaskEvent) error {
var err *multierror.Error
for tn := range ar.tasks {
rerr := ar.RestartTask(tn, taskEvent.Copy())
if rerr != nil {
err = multierror.Append(err, rerr)
}
}
return err.ErrorOrNil()
} | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"RestartAll",
"(",
"taskEvent",
"*",
"structs",
".",
"TaskEvent",
")",
"error",
"{",
"var",
"err",
"*",
"multierror",
".",
"Error",
"\n\n",
"for",
"tn",
":=",
"range",
"ar",
".",
"tasks",
"{",
"rerr",
":=",
... | // RestartAll signalls all task runners in the allocation to restart and passes
// a copy of the task event to each restart event.
// Returns any errors in a concatenated form. | [
"RestartAll",
"signalls",
"all",
"task",
"runners",
"in",
"the",
"allocation",
"to",
"restart",
"and",
"passes",
"a",
"copy",
"of",
"the",
"task",
"event",
"to",
"each",
"restart",
"event",
".",
"Returns",
"any",
"errors",
"in",
"a",
"concatenated",
"form",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L954-L965 |
133,736 | hashicorp/nomad | client/allocrunner/alloc_runner.go | Signal | func (ar *allocRunner) Signal(taskName, signal string) error {
event := structs.NewTaskEvent(structs.TaskSignaling).SetSignalText(signal)
if taskName != "" {
tr, ok := ar.tasks[taskName]
if !ok {
return fmt.Errorf("Task not found")
}
return tr.Signal(event, signal)
}
var err *multierror.Error
for tn... | go | func (ar *allocRunner) Signal(taskName, signal string) error {
event := structs.NewTaskEvent(structs.TaskSignaling).SetSignalText(signal)
if taskName != "" {
tr, ok := ar.tasks[taskName]
if !ok {
return fmt.Errorf("Task not found")
}
return tr.Signal(event, signal)
}
var err *multierror.Error
for tn... | [
"func",
"(",
"ar",
"*",
"allocRunner",
")",
"Signal",
"(",
"taskName",
",",
"signal",
"string",
")",
"error",
"{",
"event",
":=",
"structs",
".",
"NewTaskEvent",
"(",
"structs",
".",
"TaskSignaling",
")",
".",
"SetSignalText",
"(",
"signal",
")",
"\n\n",
... | // Signal sends a signal request to task runners inside an allocation. If the
// taskName is empty, then it is sent to all tasks. | [
"Signal",
"sends",
"a",
"signal",
"request",
"to",
"task",
"runners",
"inside",
"an",
"allocation",
".",
"If",
"the",
"taskName",
"is",
"empty",
"then",
"it",
"is",
"sent",
"to",
"all",
"tasks",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/alloc_runner.go#L969-L991 |
133,737 | hashicorp/nomad | command/job_inspect.go | getJob | func getJob(client *api.Client, jobID string, version *uint64) (*api.Job, error) {
if version == nil {
job, _, err := client.Jobs().Info(jobID, nil)
return job, err
}
versions, _, _, err := client.Jobs().Versions(jobID, false, nil)
if err != nil {
return nil, err
}
for _, j := range versions {
if *j.Ver... | go | func getJob(client *api.Client, jobID string, version *uint64) (*api.Job, error) {
if version == nil {
job, _, err := client.Jobs().Info(jobID, nil)
return job, err
}
versions, _, _, err := client.Jobs().Versions(jobID, false, nil)
if err != nil {
return nil, err
}
for _, j := range versions {
if *j.Ver... | [
"func",
"getJob",
"(",
"client",
"*",
"api",
".",
"Client",
",",
"jobID",
"string",
",",
"version",
"*",
"uint64",
")",
"(",
"*",
"api",
".",
"Job",
",",
"error",
")",
"{",
"if",
"version",
"==",
"nil",
"{",
"job",
",",
"_",
",",
"err",
":=",
"... | // getJob retrieves the job optionally at a particular version. | [
"getJob",
"retrieves",
"the",
"job",
"optionally",
"at",
"a",
"particular",
"version",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/job_inspect.go#L182-L201 |
133,738 | hashicorp/nomad | command/monitor.go | newEvalState | func newEvalState() *evalState {
return &evalState{
status: structs.EvalStatusPending,
allocs: make(map[string]*allocState),
}
} | go | func newEvalState() *evalState {
return &evalState{
status: structs.EvalStatusPending,
allocs: make(map[string]*allocState),
}
} | [
"func",
"newEvalState",
"(",
")",
"*",
"evalState",
"{",
"return",
"&",
"evalState",
"{",
"status",
":",
"structs",
".",
"EvalStatusPending",
",",
"allocs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"allocState",
")",
",",
"}",
"\n",
"}"
] | // newEvalState creates and initializes a new monitorState | [
"newEvalState",
"creates",
"and",
"initializes",
"a",
"new",
"monitorState"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/monitor.go#L35-L40 |
133,739 | hashicorp/nomad | command/monitor.go | newMonitor | func newMonitor(ui cli.Ui, client *api.Client, length int) *monitor {
if colorUi, ok := ui.(*cli.ColoredUi); ok {
// Disable Info color for monitored output
ui = &cli.ColoredUi{
ErrorColor: colorUi.ErrorColor,
WarnColor: colorUi.WarnColor,
InfoColor: cli.UiColorNone,
Ui: colorUi.Ui,
}
}
m... | go | func newMonitor(ui cli.Ui, client *api.Client, length int) *monitor {
if colorUi, ok := ui.(*cli.ColoredUi); ok {
// Disable Info color for monitored output
ui = &cli.ColoredUi{
ErrorColor: colorUi.ErrorColor,
WarnColor: colorUi.WarnColor,
InfoColor: cli.UiColorNone,
Ui: colorUi.Ui,
}
}
m... | [
"func",
"newMonitor",
"(",
"ui",
"cli",
".",
"Ui",
",",
"client",
"*",
"api",
".",
"Client",
",",
"length",
"int",
")",
"*",
"monitor",
"{",
"if",
"colorUi",
",",
"ok",
":=",
"ui",
".",
"(",
"*",
"cli",
".",
"ColoredUi",
")",
";",
"ok",
"{",
"/... | // newMonitor returns a new monitor. The returned monitor will
// write output information to the provided ui. The length parameter determines
// the number of characters for identifiers in the ui. | [
"newMonitor",
"returns",
"a",
"new",
"monitor",
".",
"The",
"returned",
"monitor",
"will",
"write",
"output",
"information",
"to",
"the",
"provided",
"ui",
".",
"The",
"length",
"parameter",
"determines",
"the",
"number",
"of",
"characters",
"for",
"identifiers"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/monitor.go#L70-L92 |
133,740 | hashicorp/nomad | command/monitor.go | update | func (m *monitor) update(update *evalState) {
m.Lock()
defer m.Unlock()
existing := m.state
// Swap in the new state at the end
defer func() {
m.state = update
}()
// Check if the evaluation was triggered by a node
if existing.node == "" && update.node != "" {
m.ui.Output(fmt.Sprintf("Evaluation triggere... | go | func (m *monitor) update(update *evalState) {
m.Lock()
defer m.Unlock()
existing := m.state
// Swap in the new state at the end
defer func() {
m.state = update
}()
// Check if the evaluation was triggered by a node
if existing.node == "" && update.node != "" {
m.ui.Output(fmt.Sprintf("Evaluation triggere... | [
"func",
"(",
"m",
"*",
"monitor",
")",
"update",
"(",
"update",
"*",
"evalState",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"existing",
":=",
"m",
".",
"state",
"\n\n",
"// Swap in the new state at the e... | // update is used to update our monitor with new state. It can be
// called whether the passed information is new or not, and will
// only dump update messages when state changes. | [
"update",
"is",
"used",
"to",
"update",
"our",
"monitor",
"with",
"new",
"state",
".",
"It",
"can",
"be",
"called",
"whether",
"the",
"passed",
"information",
"is",
"new",
"or",
"not",
"and",
"will",
"only",
"dump",
"update",
"messages",
"when",
"state",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/monitor.go#L97-L163 |
133,741 | hashicorp/nomad | nomad/drainer/drainer.go | GetDrainingJobWatcher | func GetDrainingJobWatcher(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, logger log.Logger) DrainingJobWatcher {
return NewDrainingJobWatcher(ctx, limiter, state, logger)
} | go | func GetDrainingJobWatcher(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, logger log.Logger) DrainingJobWatcher {
return NewDrainingJobWatcher(ctx, limiter, state, logger)
} | [
"func",
"GetDrainingJobWatcher",
"(",
"ctx",
"context",
".",
"Context",
",",
"limiter",
"*",
"rate",
".",
"Limiter",
",",
"state",
"*",
"state",
".",
"StateStore",
",",
"logger",
"log",
".",
"Logger",
")",
"DrainingJobWatcher",
"{",
"return",
"NewDrainingJobWa... | // GetDrainingJobWatcher returns a draining job watcher | [
"GetDrainingJobWatcher",
"returns",
"a",
"draining",
"job",
"watcher"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L76-L78 |
133,742 | hashicorp/nomad | nomad/drainer/drainer.go | GetNodeWatcherFactory | func GetNodeWatcherFactory() DrainingNodeWatcherFactory {
return func(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, logger log.Logger, tracker NodeTracker) DrainingNodeWatcher {
return NewNodeDrainWatcher(ctx, limiter, state, logger, tracker)
}
} | go | func GetNodeWatcherFactory() DrainingNodeWatcherFactory {
return func(ctx context.Context, limiter *rate.Limiter, state *state.StateStore, logger log.Logger, tracker NodeTracker) DrainingNodeWatcher {
return NewNodeDrainWatcher(ctx, limiter, state, logger, tracker)
}
} | [
"func",
"GetNodeWatcherFactory",
"(",
")",
"DrainingNodeWatcherFactory",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"limiter",
"*",
"rate",
".",
"Limiter",
",",
"state",
"*",
"state",
".",
"StateStore",
",",
"logger",
"log",
".",
"Log... | // GetNodeWatcherFactory returns a DrainingNodeWatcherFactory | [
"GetNodeWatcherFactory",
"returns",
"a",
"DrainingNodeWatcherFactory"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L86-L90 |
133,743 | hashicorp/nomad | nomad/drainer/drainer.go | NewNodeDrainer | func NewNodeDrainer(c *NodeDrainerConfig) *NodeDrainer {
return &NodeDrainer{
raft: c.Raft,
logger: c.Logger.Named("drain"),
jobFactory: c.JobFactory,
nodeFactory: c.NodeFactory,
deadlineNotifierFactory: c.DrainDeadlineFactory,
queryLimiter: ... | go | func NewNodeDrainer(c *NodeDrainerConfig) *NodeDrainer {
return &NodeDrainer{
raft: c.Raft,
logger: c.Logger.Named("drain"),
jobFactory: c.JobFactory,
nodeFactory: c.NodeFactory,
deadlineNotifierFactory: c.DrainDeadlineFactory,
queryLimiter: ... | [
"func",
"NewNodeDrainer",
"(",
"c",
"*",
"NodeDrainerConfig",
")",
"*",
"NodeDrainer",
"{",
"return",
"&",
"NodeDrainer",
"{",
"raft",
":",
"c",
".",
"Raft",
",",
"logger",
":",
"c",
".",
"Logger",
".",
"Named",
"(",
"\"",
"\"",
")",
",",
"jobFactory",... | // NewNodeDrainer returns a new new node drainer. The node drainer is
// responsible for marking allocations on draining nodes with a desired
// migration transition, updating the drain strategy on nodes when they are
// complete and creating evaluations for the system to react to these changes. | [
"NewNodeDrainer",
"returns",
"a",
"new",
"new",
"node",
"drainer",
".",
"The",
"node",
"drainer",
"is",
"responsible",
"for",
"marking",
"allocations",
"on",
"draining",
"nodes",
"with",
"a",
"desired",
"migration",
"transition",
"updating",
"the",
"drain",
"str... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L173-L185 |
133,744 | hashicorp/nomad | nomad/drainer/drainer.go | SetEnabled | func (n *NodeDrainer) SetEnabled(enabled bool, state *state.StateStore) {
n.l.Lock()
defer n.l.Unlock()
// If we are starting now or have a new state, init state and start the
// run loop
n.enabled = enabled
if enabled {
n.flush(state)
go n.run(n.ctx)
} else if !enabled && n.exitFn != nil {
n.exitFn()
}
... | go | func (n *NodeDrainer) SetEnabled(enabled bool, state *state.StateStore) {
n.l.Lock()
defer n.l.Unlock()
// If we are starting now or have a new state, init state and start the
// run loop
n.enabled = enabled
if enabled {
n.flush(state)
go n.run(n.ctx)
} else if !enabled && n.exitFn != nil {
n.exitFn()
}
... | [
"func",
"(",
"n",
"*",
"NodeDrainer",
")",
"SetEnabled",
"(",
"enabled",
"bool",
",",
"state",
"*",
"state",
".",
"StateStore",
")",
"{",
"n",
".",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"n",
".",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"// If ... | // SetEnabled will start or stop the node draining goroutine depending on the
// enabled boolean. | [
"SetEnabled",
"will",
"start",
"or",
"stop",
"the",
"node",
"draining",
"goroutine",
"depending",
"on",
"the",
"enabled",
"boolean",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L189-L202 |
133,745 | hashicorp/nomad | nomad/drainer/drainer.go | run | func (n *NodeDrainer) run(ctx context.Context) {
for {
select {
case <-n.ctx.Done():
return
case nodes := <-n.deadlineNotifier.NextBatch():
n.handleDeadlinedNodes(nodes)
case req := <-n.jobWatcher.Drain():
n.handleJobAllocDrain(req)
case allocs := <-n.jobWatcher.Migrated():
n.handleMigratedAllocs... | go | func (n *NodeDrainer) run(ctx context.Context) {
for {
select {
case <-n.ctx.Done():
return
case nodes := <-n.deadlineNotifier.NextBatch():
n.handleDeadlinedNodes(nodes)
case req := <-n.jobWatcher.Drain():
n.handleJobAllocDrain(req)
case allocs := <-n.jobWatcher.Migrated():
n.handleMigratedAllocs... | [
"func",
"(",
"n",
"*",
"NodeDrainer",
")",
"run",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"n",
".",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"\n",
"case",
"nodes",
":=",
"<-",
"n",
".",
"dea... | // run is a long lived event handler that receives changes from the relevant
// watchers and takes action based on them. | [
"run",
"is",
"a",
"long",
"lived",
"event",
"handler",
"that",
"receives",
"changes",
"from",
"the",
"relevant",
"watchers",
"and",
"takes",
"action",
"based",
"on",
"them",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L225-L238 |
133,746 | hashicorp/nomad | nomad/drainer/drainer.go | handleDeadlinedNodes | func (n *NodeDrainer) handleDeadlinedNodes(nodes []string) {
// Retrieve the set of allocations that will be force stopped.
var forceStop []*structs.Allocation
n.l.RLock()
for _, node := range nodes {
draining, ok := n.nodes[node]
if !ok {
n.logger.Debug("skipping untracked deadlined node", "node_id", node)
... | go | func (n *NodeDrainer) handleDeadlinedNodes(nodes []string) {
// Retrieve the set of allocations that will be force stopped.
var forceStop []*structs.Allocation
n.l.RLock()
for _, node := range nodes {
draining, ok := n.nodes[node]
if !ok {
n.logger.Debug("skipping untracked deadlined node", "node_id", node)
... | [
"func",
"(",
"n",
"*",
"NodeDrainer",
")",
"handleDeadlinedNodes",
"(",
"nodes",
"[",
"]",
"string",
")",
"{",
"// Retrieve the set of allocations that will be force stopped.",
"var",
"forceStop",
"[",
"]",
"*",
"structs",
".",
"Allocation",
"\n",
"n",
".",
"l",
... | // handleDeadlinedNodes handles a set of nodes reaching their drain deadline.
// The handler detects the remaining allocations on the nodes and immediately
// marks them for migration. | [
"handleDeadlinedNodes",
"handles",
"a",
"set",
"of",
"nodes",
"reaching",
"their",
"drain",
"deadline",
".",
"The",
"handler",
"detects",
"the",
"remaining",
"allocations",
"on",
"the",
"nodes",
"and",
"immediately",
"marks",
"them",
"for",
"migration",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L243-L279 |
133,747 | hashicorp/nomad | nomad/drainer/drainer.go | handleJobAllocDrain | func (n *NodeDrainer) handleJobAllocDrain(req *DrainRequest) {
index, err := n.batchDrainAllocs(req.Allocs)
req.Resp.Respond(index, err)
} | go | func (n *NodeDrainer) handleJobAllocDrain(req *DrainRequest) {
index, err := n.batchDrainAllocs(req.Allocs)
req.Resp.Respond(index, err)
} | [
"func",
"(",
"n",
"*",
"NodeDrainer",
")",
"handleJobAllocDrain",
"(",
"req",
"*",
"DrainRequest",
")",
"{",
"index",
",",
"err",
":=",
"n",
".",
"batchDrainAllocs",
"(",
"req",
".",
"Allocs",
")",
"\n",
"req",
".",
"Resp",
".",
"Respond",
"(",
"index"... | // handleJobAllocDrain handles marking a set of allocations as having a desired
// transition to drain. The handler blocks till the changes to the allocation
// have occurred. | [
"handleJobAllocDrain",
"handles",
"marking",
"a",
"set",
"of",
"allocations",
"as",
"having",
"a",
"desired",
"transition",
"to",
"drain",
".",
"The",
"handler",
"blocks",
"till",
"the",
"changes",
"to",
"the",
"allocation",
"have",
"occurred",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L284-L287 |
133,748 | hashicorp/nomad | nomad/drainer/drainer.go | handleMigratedAllocs | func (n *NodeDrainer) handleMigratedAllocs(allocs []*structs.Allocation) {
// Determine the set of nodes that were effected
nodes := make(map[string]struct{})
for _, alloc := range allocs {
nodes[alloc.NodeID] = struct{}{}
}
var done []string
var remainingAllocs []*structs.Allocation
// For each node, check ... | go | func (n *NodeDrainer) handleMigratedAllocs(allocs []*structs.Allocation) {
// Determine the set of nodes that were effected
nodes := make(map[string]struct{})
for _, alloc := range allocs {
nodes[alloc.NodeID] = struct{}{}
}
var done []string
var remainingAllocs []*structs.Allocation
// For each node, check ... | [
"func",
"(",
"n",
"*",
"NodeDrainer",
")",
"handleMigratedAllocs",
"(",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
")",
"{",
"// Determine the set of nodes that were effected",
"nodes",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"... | // handleMigratedAllocs checks to see if any nodes can be considered done
// draining based on the set of allocations that have migrated because of an
// ongoing drain for a job. | [
"handleMigratedAllocs",
"checks",
"to",
"see",
"if",
"any",
"nodes",
"can",
"be",
"considered",
"done",
"draining",
"based",
"on",
"the",
"set",
"of",
"allocations",
"that",
"have",
"migrated",
"because",
"of",
"an",
"ongoing",
"drain",
"for",
"a",
"job",
".... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L292-L353 |
133,749 | hashicorp/nomad | nomad/drainer/drainer.go | batchDrainAllocs | func (n *NodeDrainer) batchDrainAllocs(allocs []*structs.Allocation) (uint64, error) {
// Add this to the batch
n.batcher.Lock()
n.batcher.updates = append(n.batcher.updates, allocs...)
// Start a new batch if none
future := n.batcher.updateFuture
if future == nil {
future = structs.NewBatchFuture()
n.batche... | go | func (n *NodeDrainer) batchDrainAllocs(allocs []*structs.Allocation) (uint64, error) {
// Add this to the batch
n.batcher.Lock()
n.batcher.updates = append(n.batcher.updates, allocs...)
// Start a new batch if none
future := n.batcher.updateFuture
if future == nil {
future = structs.NewBatchFuture()
n.batche... | [
"func",
"(",
"n",
"*",
"NodeDrainer",
")",
"batchDrainAllocs",
"(",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"// Add this to the batch",
"n",
".",
"batcher",
".",
"Lock",
"(",
")",
"\n",
"n",
".... | // batchDrainAllocs is used to batch the draining of allocations. It will block
// until the batch is complete. | [
"batchDrainAllocs",
"is",
"used",
"to",
"batch",
"the",
"draining",
"of",
"allocations",
".",
"It",
"will",
"block",
"until",
"the",
"batch",
"is",
"complete",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L357-L388 |
133,750 | hashicorp/nomad | nomad/drainer/drainer.go | drainAllocs | func (n *NodeDrainer) drainAllocs(future *structs.BatchFuture, allocs []*structs.Allocation) {
// Compute the effected jobs and make the transition map
jobs := make(map[string]*structs.Allocation, 4)
transitions := make(map[string]*structs.DesiredTransition, len(allocs))
for _, alloc := range allocs {
transitions... | go | func (n *NodeDrainer) drainAllocs(future *structs.BatchFuture, allocs []*structs.Allocation) {
// Compute the effected jobs and make the transition map
jobs := make(map[string]*structs.Allocation, 4)
transitions := make(map[string]*structs.DesiredTransition, len(allocs))
for _, alloc := range allocs {
transitions... | [
"func",
"(",
"n",
"*",
"NodeDrainer",
")",
"drainAllocs",
"(",
"future",
"*",
"structs",
".",
"BatchFuture",
",",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
")",
"{",
"// Compute the effected jobs and make the transition map",
"jobs",
":=",
"make",
"... | // drainAllocs is a non batch, marking of the desired transition to migrate for
// the set of allocations. It will also create the necessary evaluations for the
// affected jobs. | [
"drainAllocs",
"is",
"a",
"non",
"batch",
"marking",
"of",
"the",
"desired",
"transition",
"to",
"migrate",
"for",
"the",
"set",
"of",
"allocations",
".",
"It",
"will",
"also",
"create",
"the",
"necessary",
"evaluations",
"for",
"the",
"affected",
"jobs",
".... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/drainer/drainer.go#L393-L429 |
133,751 | hashicorp/nomad | devices/gpu/nvidia/device.go | NewNvidiaDevice | func NewNvidiaDevice(log log.Logger) *NvidiaDevice {
nvmlClient, err := nvml.NewNvmlClient()
logger := log.Named(pluginName)
if err != nil && err.Error() != nvml.UnavailableLib.Error() {
logger.Error("unable to initialize Nvidia driver", "reason", err)
}
return &NvidiaDevice{
logger: logger,
devices: ... | go | func NewNvidiaDevice(log log.Logger) *NvidiaDevice {
nvmlClient, err := nvml.NewNvmlClient()
logger := log.Named(pluginName)
if err != nil && err.Error() != nvml.UnavailableLib.Error() {
logger.Error("unable to initialize Nvidia driver", "reason", err)
}
return &NvidiaDevice{
logger: logger,
devices: ... | [
"func",
"NewNvidiaDevice",
"(",
"log",
"log",
".",
"Logger",
")",
"*",
"NvidiaDevice",
"{",
"nvmlClient",
",",
"err",
":=",
"nvml",
".",
"NewNvmlClient",
"(",
")",
"\n",
"logger",
":=",
"log",
".",
"Named",
"(",
"pluginName",
")",
"\n",
"if",
"err",
"!... | // NewNvidiaDevice returns a new nvidia device plugin. | [
"NewNvidiaDevice",
"returns",
"a",
"new",
"nvidia",
"device",
"plugin",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/devices/gpu/nvidia/device.go#L102-L115 |
133,752 | hashicorp/nomad | devices/gpu/nvidia/device.go | Reserve | func (d *NvidiaDevice) Reserve(deviceIDs []string) (*device.ContainerReservation, error) {
if len(deviceIDs) == 0 {
return &device.ContainerReservation{}, nil
}
// Due to the asynchronous nature of NvidiaPlugin, there is a possibility
// of race condition
//
// Timeline:
// 1 - fingerprint reports that GPU wi... | go | func (d *NvidiaDevice) Reserve(deviceIDs []string) (*device.ContainerReservation, error) {
if len(deviceIDs) == 0 {
return &device.ContainerReservation{}, nil
}
// Due to the asynchronous nature of NvidiaPlugin, there is a possibility
// of race condition
//
// Timeline:
// 1 - fingerprint reports that GPU wi... | [
"func",
"(",
"d",
"*",
"NvidiaDevice",
")",
"Reserve",
"(",
"deviceIDs",
"[",
"]",
"string",
")",
"(",
"*",
"device",
".",
"ContainerReservation",
",",
"error",
")",
"{",
"if",
"len",
"(",
"deviceIDs",
")",
"==",
"0",
"{",
"return",
"&",
"device",
".... | // Reserve returns information on how to mount given devices.
// Assumption is made that nomad server is responsible for correctness of
// GPU allocations, handling tricky cases such as double-allocation of single GPU | [
"Reserve",
"returns",
"information",
"on",
"how",
"to",
"mount",
"given",
"devices",
".",
"Assumption",
"is",
"made",
"that",
"nomad",
"server",
"is",
"responsible",
"for",
"correctness",
"of",
"GPU",
"allocations",
"handling",
"tricky",
"cases",
"such",
"as",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/devices/gpu/nvidia/device.go#L168-L201 |
133,753 | hashicorp/nomad | devices/gpu/nvidia/device.go | Stats | func (d *NvidiaDevice) Stats(ctx context.Context, interval time.Duration) (<-chan *device.StatsResponse, error) {
outCh := make(chan *device.StatsResponse)
go d.stats(ctx, outCh, interval)
return outCh, nil
} | go | func (d *NvidiaDevice) Stats(ctx context.Context, interval time.Duration) (<-chan *device.StatsResponse, error) {
outCh := make(chan *device.StatsResponse)
go d.stats(ctx, outCh, interval)
return outCh, nil
} | [
"func",
"(",
"d",
"*",
"NvidiaDevice",
")",
"Stats",
"(",
"ctx",
"context",
".",
"Context",
",",
"interval",
"time",
".",
"Duration",
")",
"(",
"<-",
"chan",
"*",
"device",
".",
"StatsResponse",
",",
"error",
")",
"{",
"outCh",
":=",
"make",
"(",
"ch... | // Stats streams statistics for the detected devices. | [
"Stats",
"streams",
"statistics",
"for",
"the",
"detected",
"devices",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/devices/gpu/nvidia/device.go#L204-L208 |
133,754 | hashicorp/nomad | nomad/structs/config/sentinel.go | Merge | func (a *SentinelConfig) Merge(b *SentinelConfig) *SentinelConfig {
result := *a
if len(b.Imports) > 0 {
result.Imports = append(result.Imports, b.Imports...)
}
return &result
} | go | func (a *SentinelConfig) Merge(b *SentinelConfig) *SentinelConfig {
result := *a
if len(b.Imports) > 0 {
result.Imports = append(result.Imports, b.Imports...)
}
return &result
} | [
"func",
"(",
"a",
"*",
"SentinelConfig",
")",
"Merge",
"(",
"b",
"*",
"SentinelConfig",
")",
"*",
"SentinelConfig",
"{",
"result",
":=",
"*",
"a",
"\n",
"if",
"len",
"(",
"b",
".",
"Imports",
")",
">",
"0",
"{",
"result",
".",
"Imports",
"=",
"appe... | // Merge is used to merge two Sentinel configs together. The settings from the input always take precedence. | [
"Merge",
"is",
"used",
"to",
"merge",
"two",
"Sentinel",
"configs",
"together",
".",
"The",
"settings",
"from",
"the",
"input",
"always",
"take",
"precedence",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/config/sentinel.go#L17-L23 |
133,755 | hashicorp/nomad | command/agent/retry_join.go | Validate | func (r *retryJoiner) Validate(config *Config) error {
// If retry_join is defined for the server, ensure that deprecated
// fields and the server_join stanza are not both set
if config.Server != nil && config.Server.ServerJoin != nil && len(config.Server.ServerJoin.RetryJoin) != 0 {
if len(config.Server.RetryJoi... | go | func (r *retryJoiner) Validate(config *Config) error {
// If retry_join is defined for the server, ensure that deprecated
// fields and the server_join stanza are not both set
if config.Server != nil && config.Server.ServerJoin != nil && len(config.Server.ServerJoin.RetryJoin) != 0 {
if len(config.Server.RetryJoi... | [
"func",
"(",
"r",
"*",
"retryJoiner",
")",
"Validate",
"(",
"config",
"*",
"Config",
")",
"error",
"{",
"// If retry_join is defined for the server, ensure that deprecated",
"// fields and the server_join stanza are not both set",
"if",
"config",
".",
"Server",
"!=",
"nil",... | // Validate ensures that the configuration passes validity checks for the
// retry_join stanza. If the configuration is not valid, returns an error that
// will be displayed to the operator, otherwise nil. | [
"Validate",
"ensures",
"that",
"the",
"configuration",
"passes",
"validity",
"checks",
"for",
"the",
"retry_join",
"stanza",
".",
"If",
"the",
"configuration",
"is",
"not",
"valid",
"returns",
"an",
"error",
"that",
"will",
"be",
"displayed",
"to",
"the",
"ope... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/retry_join.go#L61-L94 |
133,756 | hashicorp/nomad | command/agent/retry_join.go | RetryJoin | func (r *retryJoiner) RetryJoin(serverJoin *ServerJoin) {
if len(serverJoin.RetryJoin) == 0 {
return
}
attempt := 0
addrsToJoin := strings.Join(serverJoin.RetryJoin, " ")
r.logger.Info("starting retry join", "servers", addrsToJoin)
standardLogger := r.logger.StandardLogger(&log.StandardLoggerOptions{InferLev... | go | func (r *retryJoiner) RetryJoin(serverJoin *ServerJoin) {
if len(serverJoin.RetryJoin) == 0 {
return
}
attempt := 0
addrsToJoin := strings.Join(serverJoin.RetryJoin, " ")
r.logger.Info("starting retry join", "servers", addrsToJoin)
standardLogger := r.logger.StandardLogger(&log.StandardLoggerOptions{InferLev... | [
"func",
"(",
"r",
"*",
"retryJoiner",
")",
"RetryJoin",
"(",
"serverJoin",
"*",
"ServerJoin",
")",
"{",
"if",
"len",
"(",
"serverJoin",
".",
"RetryJoin",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"attempt",
":=",
"0",
"\n\n",
"addrsToJoin",
":=... | // retryJoin is used to handle retrying a join until it succeeds or all retries
// are exhausted. | [
"retryJoin",
"is",
"used",
"to",
"handle",
"retrying",
"a",
"join",
"until",
"it",
"succeeds",
"or",
"all",
"retries",
"are",
"exhausted",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/retry_join.go#L98-L157 |
133,757 | hashicorp/nomad | scheduler/propertyset.go | NewPropertySet | func NewPropertySet(ctx Context, job *structs.Job) *propertySet {
p := &propertySet{
ctx: ctx,
jobID: job.ID,
namespace: job.Namespace,
existingValues: make(map[string]uint64),
logger: ctx.Logger().Named("property_set"),
}
return p
} | go | func NewPropertySet(ctx Context, job *structs.Job) *propertySet {
p := &propertySet{
ctx: ctx,
jobID: job.ID,
namespace: job.Namespace,
existingValues: make(map[string]uint64),
logger: ctx.Logger().Named("property_set"),
}
return p
} | [
"func",
"NewPropertySet",
"(",
"ctx",
"Context",
",",
"job",
"*",
"structs",
".",
"Job",
")",
"*",
"propertySet",
"{",
"p",
":=",
"&",
"propertySet",
"{",
"ctx",
":",
"ctx",
",",
"jobID",
":",
"job",
".",
"ID",
",",
"namespace",
":",
"job",
".",
"N... | // NewPropertySet returns a new property set used to guarantee unique property
// values for new allocation placements. | [
"NewPropertySet",
"returns",
"a",
"new",
"property",
"set",
"used",
"to",
"guarantee",
"unique",
"property",
"values",
"for",
"new",
"allocation",
"placements",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L56-L66 |
133,758 | hashicorp/nomad | scheduler/propertyset.go | SetTGConstraint | func (p *propertySet) SetTGConstraint(constraint *structs.Constraint, taskGroup string) {
p.setConstraint(constraint, taskGroup)
} | go | func (p *propertySet) SetTGConstraint(constraint *structs.Constraint, taskGroup string) {
p.setConstraint(constraint, taskGroup)
} | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"SetTGConstraint",
"(",
"constraint",
"*",
"structs",
".",
"Constraint",
",",
"taskGroup",
"string",
")",
"{",
"p",
".",
"setConstraint",
"(",
"constraint",
",",
"taskGroup",
")",
"\n",
"}"
] | // SetTGConstraint is used to parameterize the property set for a
// distinct_property constraint set at the task group level. The inputs are the
// constraint and the task group name. | [
"SetTGConstraint",
"is",
"used",
"to",
"parameterize",
"the",
"property",
"set",
"for",
"a",
"distinct_property",
"constraint",
"set",
"at",
"the",
"task",
"group",
"level",
".",
"The",
"inputs",
"are",
"the",
"constraint",
"and",
"the",
"task",
"group",
"name... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L77-L79 |
133,759 | hashicorp/nomad | scheduler/propertyset.go | setConstraint | func (p *propertySet) setConstraint(constraint *structs.Constraint, taskGroup string) {
var allowedCount uint64
// Determine the number of allowed allocations with the property.
if v := constraint.RTarget; v != "" {
c, err := strconv.ParseUint(v, 10, 64)
if err != nil {
p.errorBuilding = fmt.Errorf("failed to... | go | func (p *propertySet) setConstraint(constraint *structs.Constraint, taskGroup string) {
var allowedCount uint64
// Determine the number of allowed allocations with the property.
if v := constraint.RTarget; v != "" {
c, err := strconv.ParseUint(v, 10, 64)
if err != nil {
p.errorBuilding = fmt.Errorf("failed to... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"setConstraint",
"(",
"constraint",
"*",
"structs",
".",
"Constraint",
",",
"taskGroup",
"string",
")",
"{",
"var",
"allowedCount",
"uint64",
"\n",
"// Determine the number of allowed allocations with the property.",
"if",
"v... | // setConstraint is a shared helper for setting a job or task group constraint. | [
"setConstraint",
"is",
"a",
"shared",
"helper",
"for",
"setting",
"a",
"job",
"or",
"task",
"group",
"constraint",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L82-L98 |
133,760 | hashicorp/nomad | scheduler/propertyset.go | SetTargetAttribute | func (p *propertySet) SetTargetAttribute(targetAttribute string, taskGroup string) {
p.setTargetAttributeWithCount(targetAttribute, 0, taskGroup)
} | go | func (p *propertySet) SetTargetAttribute(targetAttribute string, taskGroup string) {
p.setTargetAttributeWithCount(targetAttribute, 0, taskGroup)
} | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"SetTargetAttribute",
"(",
"targetAttribute",
"string",
",",
"taskGroup",
"string",
")",
"{",
"p",
".",
"setTargetAttributeWithCount",
"(",
"targetAttribute",
",",
"0",
",",
"taskGroup",
")",
"\n",
"}"
] | // SetTargetAttribute is used to populate this property set without also storing allowed count
// This is used when evaluating spread stanzas | [
"SetTargetAttribute",
"is",
"used",
"to",
"populate",
"this",
"property",
"set",
"without",
"also",
"storing",
"allowed",
"count",
"This",
"is",
"used",
"when",
"evaluating",
"spread",
"stanzas"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L102-L104 |
133,761 | hashicorp/nomad | scheduler/propertyset.go | setTargetAttributeWithCount | func (p *propertySet) setTargetAttributeWithCount(targetAttribute string, allowedCount uint64, taskGroup string) {
// Store that this is for a task group
if taskGroup != "" {
p.taskGroup = taskGroup
}
// Store the constraint
p.targetAttribute = targetAttribute
p.allowedCount = allowedCount
// Determine the ... | go | func (p *propertySet) setTargetAttributeWithCount(targetAttribute string, allowedCount uint64, taskGroup string) {
// Store that this is for a task group
if taskGroup != "" {
p.taskGroup = taskGroup
}
// Store the constraint
p.targetAttribute = targetAttribute
p.allowedCount = allowedCount
// Determine the ... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"setTargetAttributeWithCount",
"(",
"targetAttribute",
"string",
",",
"allowedCount",
"uint64",
",",
"taskGroup",
"string",
")",
"{",
"// Store that this is for a task group",
"if",
"taskGroup",
"!=",
"\"",
"\"",
"{",
"p",
... | // setTargetAttributeWithCount is a shared helper for setting a job or task group attribute and allowedCount
// allowedCount can be zero when this is used in evaluating spread stanzas | [
"setTargetAttributeWithCount",
"is",
"a",
"shared",
"helper",
"for",
"setting",
"a",
"job",
"or",
"task",
"group",
"attribute",
"and",
"allowedCount",
"allowedCount",
"can",
"be",
"zero",
"when",
"this",
"is",
"used",
"in",
"evaluating",
"spread",
"stanzas"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L108-L128 |
133,762 | hashicorp/nomad | scheduler/propertyset.go | populateExisting | func (p *propertySet) populateExisting() {
// Retrieve all previously placed allocations
ws := memdb.NewWatchSet()
allocs, err := p.ctx.State().AllocsByJob(ws, p.namespace, p.jobID, false)
if err != nil {
p.errorBuilding = fmt.Errorf("failed to get job's allocations: %v", err)
p.logger.Error("failed to get job'... | go | func (p *propertySet) populateExisting() {
// Retrieve all previously placed allocations
ws := memdb.NewWatchSet()
allocs, err := p.ctx.State().AllocsByJob(ws, p.namespace, p.jobID, false)
if err != nil {
p.errorBuilding = fmt.Errorf("failed to get job's allocations: %v", err)
p.logger.Error("failed to get job'... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"populateExisting",
"(",
")",
"{",
"// Retrieve all previously placed allocations",
"ws",
":=",
"memdb",
".",
"NewWatchSet",
"(",
")",
"\n",
"allocs",
",",
"err",
":=",
"p",
".",
"ctx",
".",
"State",
"(",
")",
"."... | // populateExisting is a helper shared when setting the constraint to populate
// the existing values. | [
"populateExisting",
"is",
"a",
"helper",
"shared",
"when",
"setting",
"the",
"constraint",
"to",
"populate",
"the",
"existing",
"values",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L132-L155 |
133,763 | hashicorp/nomad | scheduler/propertyset.go | PopulateProposed | func (p *propertySet) PopulateProposed() {
// Reset the proposed properties
p.proposedValues = make(map[string]uint64)
p.clearedValues = make(map[string]uint64)
// Gather the set of proposed stops.
var stopping []*structs.Allocation
for _, updates := range p.ctx.Plan().NodeUpdate {
stopping = append(stopping,... | go | func (p *propertySet) PopulateProposed() {
// Reset the proposed properties
p.proposedValues = make(map[string]uint64)
p.clearedValues = make(map[string]uint64)
// Gather the set of proposed stops.
var stopping []*structs.Allocation
for _, updates := range p.ctx.Plan().NodeUpdate {
stopping = append(stopping,... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"PopulateProposed",
"(",
")",
"{",
"// Reset the proposed properties",
"p",
".",
"proposedValues",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"uint64",
")",
"\n",
"p",
".",
"clearedValues",
"=",
"make",
"(",
"ma... | // PopulateProposed populates the proposed values and recomputes any cleared
// value. It should be called whenever the plan is updated to ensure correct
// results when checking an option. | [
"PopulateProposed",
"populates",
"the",
"proposed",
"values",
"and",
"recomputes",
"any",
"cleared",
"value",
".",
"It",
"should",
"be",
"called",
"whenever",
"the",
"plan",
"is",
"updated",
"to",
"ensure",
"correct",
"results",
"when",
"checking",
"an",
"option... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L160-L208 |
133,764 | hashicorp/nomad | scheduler/propertyset.go | SatisfiesDistinctProperties | func (p *propertySet) SatisfiesDistinctProperties(option *structs.Node, tg string) (bool, string) {
nValue, errorMsg, usedCount := p.UsedCount(option, tg)
if errorMsg != "" {
return false, errorMsg
}
// The property value has been used but within the number of allowed
// allocations.
if usedCount < p.allowedCou... | go | func (p *propertySet) SatisfiesDistinctProperties(option *structs.Node, tg string) (bool, string) {
nValue, errorMsg, usedCount := p.UsedCount(option, tg)
if errorMsg != "" {
return false, errorMsg
}
// The property value has been used but within the number of allowed
// allocations.
if usedCount < p.allowedCou... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"SatisfiesDistinctProperties",
"(",
"option",
"*",
"structs",
".",
"Node",
",",
"tg",
"string",
")",
"(",
"bool",
",",
"string",
")",
"{",
"nValue",
",",
"errorMsg",
",",
"usedCount",
":=",
"p",
".",
"UsedCount"... | // SatisfiesDistinctProperties checks if the option satisfies the
// distinct_property constraints given the existing placements and proposed
// placements. If the option does not satisfy the constraints an explanation is
// given. | [
"SatisfiesDistinctProperties",
"checks",
"if",
"the",
"option",
"satisfies",
"the",
"distinct_property",
"constraints",
"given",
"the",
"existing",
"placements",
"and",
"proposed",
"placements",
".",
"If",
"the",
"option",
"does",
"not",
"satisfy",
"the",
"constraints... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L214-L226 |
133,765 | hashicorp/nomad | scheduler/propertyset.go | UsedCount | func (p *propertySet) UsedCount(option *structs.Node, tg string) (string, string, uint64) {
// Check if there was an error building
if p.errorBuilding != nil {
return "", p.errorBuilding.Error(), 0
}
// Get the nodes property value
nValue, ok := getProperty(option, p.targetAttribute)
if !ok {
return nValue, ... | go | func (p *propertySet) UsedCount(option *structs.Node, tg string) (string, string, uint64) {
// Check if there was an error building
if p.errorBuilding != nil {
return "", p.errorBuilding.Error(), 0
}
// Get the nodes property value
nValue, ok := getProperty(option, p.targetAttribute)
if !ok {
return nValue, ... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"UsedCount",
"(",
"option",
"*",
"structs",
".",
"Node",
",",
"tg",
"string",
")",
"(",
"string",
",",
"string",
",",
"uint64",
")",
"{",
"// Check if there was an error building",
"if",
"p",
".",
"errorBuilding",
... | // UsedCount returns the number of times the value of the attribute being tracked by this
// property set is used across current and proposed allocations. It also returns the resolved
// attribute value for the node, and an error message if it couldn't be resolved correctly | [
"UsedCount",
"returns",
"the",
"number",
"of",
"times",
"the",
"value",
"of",
"the",
"attribute",
"being",
"tracked",
"by",
"this",
"property",
"set",
"is",
"used",
"across",
"current",
"and",
"proposed",
"allocations",
".",
"It",
"also",
"returns",
"the",
"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L231-L245 |
133,766 | hashicorp/nomad | scheduler/propertyset.go | GetCombinedUseMap | func (p *propertySet) GetCombinedUseMap() map[string]uint64 {
combinedUse := make(map[string]uint64, helper.IntMax(len(p.existingValues), len(p.proposedValues)))
for _, usedValues := range []map[string]uint64{p.existingValues, p.proposedValues} {
for propertyValue, usedCount := range usedValues {
combinedUse[pro... | go | func (p *propertySet) GetCombinedUseMap() map[string]uint64 {
combinedUse := make(map[string]uint64, helper.IntMax(len(p.existingValues), len(p.proposedValues)))
for _, usedValues := range []map[string]uint64{p.existingValues, p.proposedValues} {
for propertyValue, usedCount := range usedValues {
combinedUse[pro... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"GetCombinedUseMap",
"(",
")",
"map",
"[",
"string",
"]",
"uint64",
"{",
"combinedUse",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"uint64",
",",
"helper",
".",
"IntMax",
"(",
"len",
"(",
"p",
".",
"exist... | // GetCombinedUseMap counts how many times the property has been used by
// existing and proposed allocations. It also takes into account any stopped
// allocations | [
"GetCombinedUseMap",
"counts",
"how",
"many",
"times",
"the",
"property",
"has",
"been",
"used",
"by",
"existing",
"and",
"proposed",
"allocations",
".",
"It",
"also",
"takes",
"into",
"account",
"any",
"stopped",
"allocations"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L250-L274 |
133,767 | hashicorp/nomad | scheduler/propertyset.go | filterAllocs | func (p *propertySet) filterAllocs(allocs []*structs.Allocation, filterTerminal bool) []*structs.Allocation {
n := len(allocs)
for i := 0; i < n; i++ {
remove := false
if filterTerminal {
remove = allocs[i].TerminalStatus()
}
// If the constraint is on the task group filter the allocations to just
// th... | go | func (p *propertySet) filterAllocs(allocs []*structs.Allocation, filterTerminal bool) []*structs.Allocation {
n := len(allocs)
for i := 0; i < n; i++ {
remove := false
if filterTerminal {
remove = allocs[i].TerminalStatus()
}
// If the constraint is on the task group filter the allocations to just
// th... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"filterAllocs",
"(",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
",",
"filterTerminal",
"bool",
")",
"[",
"]",
"*",
"structs",
".",
"Allocation",
"{",
"n",
":=",
"len",
"(",
"allocs",
")",
"\n",
"... | // filterAllocs filters a set of allocations to just be those that are running
// and if the property set is operation at a task group level, for allocations
// for that task group | [
"filterAllocs",
"filters",
"a",
"set",
"of",
"allocations",
"to",
"just",
"be",
"those",
"that",
"are",
"running",
"and",
"if",
"the",
"property",
"set",
"is",
"operation",
"at",
"a",
"task",
"group",
"level",
"for",
"allocations",
"for",
"that",
"task",
"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L279-L300 |
133,768 | hashicorp/nomad | scheduler/propertyset.go | buildNodeMap | func (p *propertySet) buildNodeMap(allocs []*structs.Allocation) (map[string]*structs.Node, error) {
// Get all the nodes that have been used by the allocs
nodes := make(map[string]*structs.Node)
ws := memdb.NewWatchSet()
for _, alloc := range allocs {
if _, ok := nodes[alloc.NodeID]; ok {
continue
}
node... | go | func (p *propertySet) buildNodeMap(allocs []*structs.Allocation) (map[string]*structs.Node, error) {
// Get all the nodes that have been used by the allocs
nodes := make(map[string]*structs.Node)
ws := memdb.NewWatchSet()
for _, alloc := range allocs {
if _, ok := nodes[alloc.NodeID]; ok {
continue
}
node... | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"buildNodeMap",
"(",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"Node",
",",
"error",
")",
"{",
"// Get all the nodes that have been used by the ... | // buildNodeMap takes a list of allocations and returns a map of the nodes used
// by those allocations | [
"buildNodeMap",
"takes",
"a",
"list",
"of",
"allocations",
"and",
"returns",
"a",
"map",
"of",
"the",
"nodes",
"used",
"by",
"those",
"allocations"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L304-L322 |
133,769 | hashicorp/nomad | scheduler/propertyset.go | populateProperties | func (p *propertySet) populateProperties(allocs []*structs.Allocation, nodes map[string]*structs.Node,
properties map[string]uint64) {
for _, alloc := range allocs {
nProperty, ok := getProperty(nodes[alloc.NodeID], p.targetAttribute)
if !ok {
continue
}
properties[nProperty]++
}
} | go | func (p *propertySet) populateProperties(allocs []*structs.Allocation, nodes map[string]*structs.Node,
properties map[string]uint64) {
for _, alloc := range allocs {
nProperty, ok := getProperty(nodes[alloc.NodeID], p.targetAttribute)
if !ok {
continue
}
properties[nProperty]++
}
} | [
"func",
"(",
"p",
"*",
"propertySet",
")",
"populateProperties",
"(",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
",",
"nodes",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"Node",
",",
"properties",
"map",
"[",
"string",
"]",
"uint64",
"... | // populateProperties goes through all allocations and builds up the used
// properties from the nodes storing the results in the passed properties map. | [
"populateProperties",
"goes",
"through",
"all",
"allocations",
"and",
"builds",
"up",
"the",
"used",
"properties",
"from",
"the",
"nodes",
"storing",
"the",
"results",
"in",
"the",
"passed",
"properties",
"map",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L326-L337 |
133,770 | hashicorp/nomad | scheduler/propertyset.go | getProperty | func getProperty(n *structs.Node, property string) (string, bool) {
if n == nil || property == "" {
return "", false
}
val, ok := resolveTarget(property, n)
if !ok {
return "", false
}
nodeValue, ok := val.(string)
if !ok {
return "", false
}
return nodeValue, true
} | go | func getProperty(n *structs.Node, property string) (string, bool) {
if n == nil || property == "" {
return "", false
}
val, ok := resolveTarget(property, n)
if !ok {
return "", false
}
nodeValue, ok := val.(string)
if !ok {
return "", false
}
return nodeValue, true
} | [
"func",
"getProperty",
"(",
"n",
"*",
"structs",
".",
"Node",
",",
"property",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"if",
"n",
"==",
"nil",
"||",
"property",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\... | // getProperty is used to lookup the property value on the node | [
"getProperty",
"is",
"used",
"to",
"lookup",
"the",
"property",
"value",
"on",
"the",
"node"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/propertyset.go#L340-L355 |
133,771 | hashicorp/nomad | nomad/regions_endpoint.go | List | func (r *Region) List(args *structs.GenericRequest, reply *[]string) error {
*reply = r.srv.Regions()
return nil
} | go | func (r *Region) List(args *structs.GenericRequest, reply *[]string) error {
*reply = r.srv.Regions()
return nil
} | [
"func",
"(",
"r",
"*",
"Region",
")",
"List",
"(",
"args",
"*",
"structs",
".",
"GenericRequest",
",",
"reply",
"*",
"[",
"]",
"string",
")",
"error",
"{",
"*",
"reply",
"=",
"r",
".",
"srv",
".",
"Regions",
"(",
")",
"\n",
"return",
"nil",
"\n",... | // List is used to list all of the known regions. No leader forwarding is
// required for this endpoint because memberlist is used to populate the
// peers list we read from. | [
"List",
"is",
"used",
"to",
"list",
"all",
"of",
"the",
"known",
"regions",
".",
"No",
"leader",
"forwarding",
"is",
"required",
"for",
"this",
"endpoint",
"because",
"memberlist",
"is",
"used",
"to",
"populate",
"the",
"peers",
"list",
"we",
"read",
"from... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/regions_endpoint.go#L18-L21 |
133,772 | hashicorp/nomad | scheduler/context.go | NewEvalContext | func NewEvalContext(s State, p *structs.Plan, log log.Logger) *EvalContext {
ctx := &EvalContext{
state: s,
plan: p,
logger: log,
metrics: new(structs.AllocMetric),
}
return ctx
} | go | func NewEvalContext(s State, p *structs.Plan, log log.Logger) *EvalContext {
ctx := &EvalContext{
state: s,
plan: p,
logger: log,
metrics: new(structs.AllocMetric),
}
return ctx
} | [
"func",
"NewEvalContext",
"(",
"s",
"State",
",",
"p",
"*",
"structs",
".",
"Plan",
",",
"log",
"log",
".",
"Logger",
")",
"*",
"EvalContext",
"{",
"ctx",
":=",
"&",
"EvalContext",
"{",
"state",
":",
"s",
",",
"plan",
":",
"p",
",",
"logger",
":",
... | // NewEvalContext constructs a new EvalContext | [
"NewEvalContext",
"constructs",
"a",
"new",
"EvalContext"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L76-L84 |
133,773 | hashicorp/nomad | scheduler/context.go | NewEvalEligibility | func NewEvalEligibility() *EvalEligibility {
return &EvalEligibility{
job: make(map[string]ComputedClassFeasibility),
taskGroups: make(map[string]map[string]ComputedClassFeasibility),
tgEscapedConstraints: make(map[string]bool),
}
} | go | func NewEvalEligibility() *EvalEligibility {
return &EvalEligibility{
job: make(map[string]ComputedClassFeasibility),
taskGroups: make(map[string]map[string]ComputedClassFeasibility),
tgEscapedConstraints: make(map[string]bool),
}
} | [
"func",
"NewEvalEligibility",
"(",
")",
"*",
"EvalEligibility",
"{",
"return",
"&",
"EvalEligibility",
"{",
"job",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"ComputedClassFeasibility",
")",
",",
"taskGroups",
":",
"make",
"(",
"map",
"[",
"string",
"]",
... | // NewEvalEligibility returns an eligibility tracker for the context of an evaluation. | [
"NewEvalEligibility",
"returns",
"an",
"eligibility",
"tracker",
"for",
"the",
"context",
"of",
"an",
"evaluation",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L202-L208 |
133,774 | hashicorp/nomad | scheduler/context.go | SetJob | func (e *EvalEligibility) SetJob(job *structs.Job) {
// Determine whether the job has escaped constraints.
e.jobEscaped = len(structs.EscapedConstraints(job.Constraints)) != 0
// Determine the escaped constraints per task group.
for _, tg := range job.TaskGroups {
constraints := tg.Constraints
for _, task := r... | go | func (e *EvalEligibility) SetJob(job *structs.Job) {
// Determine whether the job has escaped constraints.
e.jobEscaped = len(structs.EscapedConstraints(job.Constraints)) != 0
// Determine the escaped constraints per task group.
for _, tg := range job.TaskGroups {
constraints := tg.Constraints
for _, task := r... | [
"func",
"(",
"e",
"*",
"EvalEligibility",
")",
"SetJob",
"(",
"job",
"*",
"structs",
".",
"Job",
")",
"{",
"// Determine whether the job has escaped constraints.",
"e",
".",
"jobEscaped",
"=",
"len",
"(",
"structs",
".",
"EscapedConstraints",
"(",
"job",
".",
... | // SetJob takes the job being evaluated and calculates the escaped constraints
// at the job and task group level. | [
"SetJob",
"takes",
"the",
"job",
"being",
"evaluated",
"and",
"calculates",
"the",
"escaped",
"constraints",
"at",
"the",
"job",
"and",
"task",
"group",
"level",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L212-L225 |
133,775 | hashicorp/nomad | scheduler/context.go | HasEscaped | func (e *EvalEligibility) HasEscaped() bool {
if e.jobEscaped {
return true
}
for _, escaped := range e.tgEscapedConstraints {
if escaped {
return true
}
}
return false
} | go | func (e *EvalEligibility) HasEscaped() bool {
if e.jobEscaped {
return true
}
for _, escaped := range e.tgEscapedConstraints {
if escaped {
return true
}
}
return false
} | [
"func",
"(",
"e",
"*",
"EvalEligibility",
")",
"HasEscaped",
"(",
")",
"bool",
"{",
"if",
"e",
".",
"jobEscaped",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"escaped",
":=",
"range",
"e",
".",
"tgEscapedConstraints",
"{",
"if",
"escaped... | // HasEscaped returns whether any of the constraints in the passed job have
// escaped computed node classes. | [
"HasEscaped",
"returns",
"whether",
"any",
"of",
"the",
"constraints",
"in",
"the",
"passed",
"job",
"have",
"escaped",
"computed",
"node",
"classes",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L229-L241 |
133,776 | hashicorp/nomad | scheduler/context.go | GetClasses | func (e *EvalEligibility) GetClasses() map[string]bool {
elig := make(map[string]bool)
// Go through the task groups.
for _, classes := range e.taskGroups {
for class, feas := range classes {
switch feas {
case EvalComputedClassEligible:
elig[class] = true
case EvalComputedClassIneligible:
// Onl... | go | func (e *EvalEligibility) GetClasses() map[string]bool {
elig := make(map[string]bool)
// Go through the task groups.
for _, classes := range e.taskGroups {
for class, feas := range classes {
switch feas {
case EvalComputedClassEligible:
elig[class] = true
case EvalComputedClassIneligible:
// Onl... | [
"func",
"(",
"e",
"*",
"EvalEligibility",
")",
"GetClasses",
"(",
")",
"map",
"[",
"string",
"]",
"bool",
"{",
"elig",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n\n",
"// Go through the task groups.",
"for",
"_",
",",
"classes",
":=",
... | // GetClasses returns the tracked classes to their eligibility, across the job
// and task groups. | [
"GetClasses",
"returns",
"the",
"tracked",
"classes",
"to",
"their",
"eligibility",
"across",
"the",
"job",
"and",
"task",
"groups",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L245-L281 |
133,777 | hashicorp/nomad | scheduler/context.go | JobStatus | func (e *EvalEligibility) JobStatus(class string) ComputedClassFeasibility {
// COMPAT: Computed node class was introduced in 0.3. Clients running < 0.3
// will not have a computed class. The safest value to return is the escaped
// case, since it disables any optimization.
if e.jobEscaped || class == "" {
return... | go | func (e *EvalEligibility) JobStatus(class string) ComputedClassFeasibility {
// COMPAT: Computed node class was introduced in 0.3. Clients running < 0.3
// will not have a computed class. The safest value to return is the escaped
// case, since it disables any optimization.
if e.jobEscaped || class == "" {
return... | [
"func",
"(",
"e",
"*",
"EvalEligibility",
")",
"JobStatus",
"(",
"class",
"string",
")",
"ComputedClassFeasibility",
"{",
"// COMPAT: Computed node class was introduced in 0.3. Clients running < 0.3",
"// will not have a computed class. The safest value to return is the escaped",
"// c... | // JobStatus returns the eligibility status of the job. | [
"JobStatus",
"returns",
"the",
"eligibility",
"status",
"of",
"the",
"job",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L284-L296 |
133,778 | hashicorp/nomad | scheduler/context.go | SetJobEligibility | func (e *EvalEligibility) SetJobEligibility(eligible bool, class string) {
if eligible {
e.job[class] = EvalComputedClassEligible
} else {
e.job[class] = EvalComputedClassIneligible
}
} | go | func (e *EvalEligibility) SetJobEligibility(eligible bool, class string) {
if eligible {
e.job[class] = EvalComputedClassEligible
} else {
e.job[class] = EvalComputedClassIneligible
}
} | [
"func",
"(",
"e",
"*",
"EvalEligibility",
")",
"SetJobEligibility",
"(",
"eligible",
"bool",
",",
"class",
"string",
")",
"{",
"if",
"eligible",
"{",
"e",
".",
"job",
"[",
"class",
"]",
"=",
"EvalComputedClassEligible",
"\n",
"}",
"else",
"{",
"e",
".",
... | // SetJobEligibility sets the eligibility status of the job for the computed
// node class. | [
"SetJobEligibility",
"sets",
"the",
"eligibility",
"status",
"of",
"the",
"job",
"for",
"the",
"computed",
"node",
"class",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L300-L306 |
133,779 | hashicorp/nomad | scheduler/context.go | TaskGroupStatus | func (e *EvalEligibility) TaskGroupStatus(tg, class string) ComputedClassFeasibility {
// COMPAT: Computed node class was introduced in 0.3. Clients running < 0.3
// will not have a computed class. The safest value to return is the escaped
// case, since it disables any optimization.
if class == "" {
return EvalC... | go | func (e *EvalEligibility) TaskGroupStatus(tg, class string) ComputedClassFeasibility {
// COMPAT: Computed node class was introduced in 0.3. Clients running < 0.3
// will not have a computed class. The safest value to return is the escaped
// case, since it disables any optimization.
if class == "" {
return EvalC... | [
"func",
"(",
"e",
"*",
"EvalEligibility",
")",
"TaskGroupStatus",
"(",
"tg",
",",
"class",
"string",
")",
"ComputedClassFeasibility",
"{",
"// COMPAT: Computed node class was introduced in 0.3. Clients running < 0.3",
"// will not have a computed class. The safest value to return is ... | // TaskGroupStatus returns the eligibility status of the task group. | [
"TaskGroupStatus",
"returns",
"the",
"eligibility",
"status",
"of",
"the",
"task",
"group",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L309-L329 |
133,780 | hashicorp/nomad | scheduler/context.go | SetTaskGroupEligibility | func (e *EvalEligibility) SetTaskGroupEligibility(eligible bool, tg, class string) {
var eligibility ComputedClassFeasibility
if eligible {
eligibility = EvalComputedClassEligible
} else {
eligibility = EvalComputedClassIneligible
}
if classes, ok := e.taskGroups[tg]; ok {
classes[class] = eligibility
} el... | go | func (e *EvalEligibility) SetTaskGroupEligibility(eligible bool, tg, class string) {
var eligibility ComputedClassFeasibility
if eligible {
eligibility = EvalComputedClassEligible
} else {
eligibility = EvalComputedClassIneligible
}
if classes, ok := e.taskGroups[tg]; ok {
classes[class] = eligibility
} el... | [
"func",
"(",
"e",
"*",
"EvalEligibility",
")",
"SetTaskGroupEligibility",
"(",
"eligible",
"bool",
",",
"tg",
",",
"class",
"string",
")",
"{",
"var",
"eligibility",
"ComputedClassFeasibility",
"\n",
"if",
"eligible",
"{",
"eligibility",
"=",
"EvalComputedClassEli... | // SetTaskGroupEligibility sets the eligibility status of the task group for the
// computed node class. | [
"SetTaskGroupEligibility",
"sets",
"the",
"eligibility",
"status",
"of",
"the",
"task",
"group",
"for",
"the",
"computed",
"node",
"class",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/context.go#L333-L346 |
133,781 | rakyll/hey | requester/now_windows.go | now | func now() time.Duration {
var now int64
syscall.Syscall(queryPerformanceCounterProc.Addr(), 1, uintptr(unsafe.Pointer(&now)), 0, 0)
return time.Duration(now) * time.Second / (time.Duration(qpcFrequency) * time.Nanosecond)
} | go | func now() time.Duration {
var now int64
syscall.Syscall(queryPerformanceCounterProc.Addr(), 1, uintptr(unsafe.Pointer(&now)), 0, 0)
return time.Duration(now) * time.Second / (time.Duration(qpcFrequency) * time.Nanosecond)
} | [
"func",
"now",
"(",
")",
"time",
".",
"Duration",
"{",
"var",
"now",
"int64",
"\n",
"syscall",
".",
"Syscall",
"(",
"queryPerformanceCounterProc",
".",
"Addr",
"(",
")",
",",
"1",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"now",
")",
"... | // now returns time.Duration using queryPerformanceCounter | [
"now",
"returns",
"time",
".",
"Duration",
"using",
"queryPerformanceCounter"
] | 01803349acd49d756dafa2cb6ac5b5bfc141fc3b | https://github.com/rakyll/hey/blob/01803349acd49d756dafa2cb6ac5b5bfc141fc3b/requester/now_windows.go#L24-L28 |
133,782 | rakyll/hey | requester/now_windows.go | queryPerformanceFrequency | func queryPerformanceFrequency() int64 {
var freq int64
r1, _, _ := syscall.Syscall(queryPerformanceFrequencyProc.Addr(), 1, uintptr(unsafe.Pointer(&freq)), 0, 0)
if r1 == 0 {
panic("call failed")
}
return freq
} | go | func queryPerformanceFrequency() int64 {
var freq int64
r1, _, _ := syscall.Syscall(queryPerformanceFrequencyProc.Addr(), 1, uintptr(unsafe.Pointer(&freq)), 0, 0)
if r1 == 0 {
panic("call failed")
}
return freq
} | [
"func",
"queryPerformanceFrequency",
"(",
")",
"int64",
"{",
"var",
"freq",
"int64",
"\n",
"r1",
",",
"_",
",",
"_",
":=",
"syscall",
".",
"Syscall",
"(",
"queryPerformanceFrequencyProc",
".",
"Addr",
"(",
")",
",",
"1",
",",
"uintptr",
"(",
"unsafe",
".... | // queryPerformanceFrequency returns frequency in ticks per second | [
"queryPerformanceFrequency",
"returns",
"frequency",
"in",
"ticks",
"per",
"second"
] | 01803349acd49d756dafa2cb6ac5b5bfc141fc3b | https://github.com/rakyll/hey/blob/01803349acd49d756dafa2cb6ac5b5bfc141fc3b/requester/now_windows.go#L40-L47 |
133,783 | rakyll/hey | requester/requester.go | Init | func (b *Work) Init() {
b.initOnce.Do(func() {
b.results = make(chan *result, min(b.C*1000, maxResult))
b.stopCh = make(chan struct{}, b.C)
})
} | go | func (b *Work) Init() {
b.initOnce.Do(func() {
b.results = make(chan *result, min(b.C*1000, maxResult))
b.stopCh = make(chan struct{}, b.C)
})
} | [
"func",
"(",
"b",
"*",
"Work",
")",
"Init",
"(",
")",
"{",
"b",
".",
"initOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"b",
".",
"results",
"=",
"make",
"(",
"chan",
"*",
"result",
",",
"min",
"(",
"b",
".",
"C",
"*",
"1000",
",",
"maxResu... | // Init initializes internal data-structures | [
"Init",
"initializes",
"internal",
"data",
"-",
"structures"
] | 01803349acd49d756dafa2cb6ac5b5bfc141fc3b | https://github.com/rakyll/hey/blob/01803349acd49d756dafa2cb6ac5b5bfc141fc3b/requester/requester.go#L107-L112 |
133,784 | rakyll/hey | requester/requester.go | Run | func (b *Work) Run() {
b.Init()
b.start = now()
b.report = newReport(b.writer(), b.results, b.Output, b.N)
// Run the reporter first, it polls the result channel until it is closed.
go func() {
runReporter(b.report)
}()
b.runWorkers()
b.Finish()
} | go | func (b *Work) Run() {
b.Init()
b.start = now()
b.report = newReport(b.writer(), b.results, b.Output, b.N)
// Run the reporter first, it polls the result channel until it is closed.
go func() {
runReporter(b.report)
}()
b.runWorkers()
b.Finish()
} | [
"func",
"(",
"b",
"*",
"Work",
")",
"Run",
"(",
")",
"{",
"b",
".",
"Init",
"(",
")",
"\n",
"b",
".",
"start",
"=",
"now",
"(",
")",
"\n",
"b",
".",
"report",
"=",
"newReport",
"(",
"b",
".",
"writer",
"(",
")",
",",
"b",
".",
"results",
... | // Run makes all the requests, prints the summary. It blocks until
// all work is done. | [
"Run",
"makes",
"all",
"the",
"requests",
"prints",
"the",
"summary",
".",
"It",
"blocks",
"until",
"all",
"work",
"is",
"done",
"."
] | 01803349acd49d756dafa2cb6ac5b5bfc141fc3b | https://github.com/rakyll/hey/blob/01803349acd49d756dafa2cb6ac5b5bfc141fc3b/requester/requester.go#L116-L126 |
133,785 | grpc-ecosystem/grpc-gateway | runtime/marshal_httpbodyproto.go | SetHTTPBodyMarshaler | func SetHTTPBodyMarshaler(serveMux *ServeMux) {
serveMux.marshalers.mimeMap[MIMEWildcard] = &HTTPBodyMarshaler{
Marshaler: &JSONPb{OrigName: true},
}
} | go | func SetHTTPBodyMarshaler(serveMux *ServeMux) {
serveMux.marshalers.mimeMap[MIMEWildcard] = &HTTPBodyMarshaler{
Marshaler: &JSONPb{OrigName: true},
}
} | [
"func",
"SetHTTPBodyMarshaler",
"(",
"serveMux",
"*",
"ServeMux",
")",
"{",
"serveMux",
".",
"marshalers",
".",
"mimeMap",
"[",
"MIMEWildcard",
"]",
"=",
"&",
"HTTPBodyMarshaler",
"{",
"Marshaler",
":",
"&",
"JSONPb",
"{",
"OrigName",
":",
"true",
"}",
",",
... | // SetHTTPBodyMarshaler overwrite the default marshaler with the HTTPBodyMarshaler | [
"SetHTTPBodyMarshaler",
"overwrite",
"the",
"default",
"marshaler",
"with",
"the",
"HTTPBodyMarshaler"
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/runtime/marshal_httpbodyproto.go#L8-L12 |
133,786 | grpc-ecosystem/grpc-gateway | runtime/marshal_httpbodyproto.go | ContentTypeFromMessage | func (h *HTTPBodyMarshaler) ContentTypeFromMessage(v interface{}) string {
if httpBody, ok := v.(*httpbody.HttpBody); ok {
return httpBody.GetContentType()
}
return h.Marshaler.ContentType()
} | go | func (h *HTTPBodyMarshaler) ContentTypeFromMessage(v interface{}) string {
if httpBody, ok := v.(*httpbody.HttpBody); ok {
return httpBody.GetContentType()
}
return h.Marshaler.ContentType()
} | [
"func",
"(",
"h",
"*",
"HTTPBodyMarshaler",
")",
"ContentTypeFromMessage",
"(",
"v",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"httpBody",
",",
"ok",
":=",
"v",
".",
"(",
"*",
"httpbody",
".",
"HttpBody",
")",
";",
"ok",
"{",
"return",
"httpBody... | // ContentTypeFromMessage in case v is a google.api.HttpBody message it returns
// its specified content type otherwise fall back to the default Marshaler. | [
"ContentTypeFromMessage",
"in",
"case",
"v",
"is",
"a",
"google",
".",
"api",
".",
"HttpBody",
"message",
"it",
"returns",
"its",
"specified",
"content",
"type",
"otherwise",
"fall",
"back",
"to",
"the",
"default",
"Marshaler",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/runtime/marshal_httpbodyproto.go#L29-L34 |
133,787 | grpc-ecosystem/grpc-gateway | runtime/marshal_httpbodyproto.go | Marshal | func (h *HTTPBodyMarshaler) Marshal(v interface{}) ([]byte, error) {
if httpBody, ok := v.(*httpbody.HttpBody); ok {
return httpBody.Data, nil
}
return h.Marshaler.Marshal(v)
} | go | func (h *HTTPBodyMarshaler) Marshal(v interface{}) ([]byte, error) {
if httpBody, ok := v.(*httpbody.HttpBody); ok {
return httpBody.Data, nil
}
return h.Marshaler.Marshal(v)
} | [
"func",
"(",
"h",
"*",
"HTTPBodyMarshaler",
")",
"Marshal",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"httpBody",
",",
"ok",
":=",
"v",
".",
"(",
"*",
"httpbody",
".",
"HttpBody",
")",
";",
"ok",
... | // Marshal marshals "v" by returning the body bytes if v is a
// google.api.HttpBody message, otherwise it falls back to the default Marshaler. | [
"Marshal",
"marshals",
"v",
"by",
"returning",
"the",
"body",
"bytes",
"if",
"v",
"is",
"a",
"google",
".",
"api",
".",
"HttpBody",
"message",
"otherwise",
"it",
"falls",
"back",
"to",
"the",
"default",
"Marshaler",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/runtime/marshal_httpbodyproto.go#L38-L43 |
133,788 | grpc-ecosystem/grpc-gateway | examples/proto/examplepb/stream.pb.gw.go | RegisterStreamServiceHandler | func RegisterStreamServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterStreamServiceHandlerClient(ctx, mux, NewStreamServiceClient(conn))
} | go | func RegisterStreamServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterStreamServiceHandlerClient(ctx, mux, NewStreamServiceClient(conn))
} | [
"func",
"RegisterStreamServiceHandler",
"(",
"ctx",
"context",
".",
"Context",
",",
"mux",
"*",
"runtime",
".",
"ServeMux",
",",
"conn",
"*",
"grpc",
".",
"ClientConn",
")",
"error",
"{",
"return",
"RegisterStreamServiceHandlerClient",
"(",
"ctx",
",",
"mux",
... | // RegisterStreamServiceHandler registers the http handlers for service StreamService to "mux".
// The handlers forward requests to the grpc endpoint over "conn". | [
"RegisterStreamServiceHandler",
"registers",
"the",
"http",
"handlers",
"for",
"service",
"StreamService",
"to",
"mux",
".",
"The",
"handlers",
"forward",
"requests",
"to",
"the",
"grpc",
"endpoint",
"over",
"conn",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/examples/proto/examplepb/stream.pb.gw.go#L170-L172 |
133,789 | grpc-ecosystem/grpc-gateway | examples/server/a_bit_of_everything.go | PatchWithFieldMaskInBody | func (s *_ABitOfEverythingServer) PatchWithFieldMaskInBody(ctx context.Context, request *examples.UpdateV2Request) (*empty.Empty, error) {
// low-effort attempt to modify the field mask to only include paths for the ABE struct. Since this is only for the
// integration tests, this narrow implementaion is fine.
if re... | go | func (s *_ABitOfEverythingServer) PatchWithFieldMaskInBody(ctx context.Context, request *examples.UpdateV2Request) (*empty.Empty, error) {
// low-effort attempt to modify the field mask to only include paths for the ABE struct. Since this is only for the
// integration tests, this narrow implementaion is fine.
if re... | [
"func",
"(",
"s",
"*",
"_ABitOfEverythingServer",
")",
"PatchWithFieldMaskInBody",
"(",
"ctx",
"context",
".",
"Context",
",",
"request",
"*",
"examples",
".",
"UpdateV2Request",
")",
"(",
"*",
"empty",
".",
"Empty",
",",
"error",
")",
"{",
"// low-effort atte... | // PatchWithFieldMaskInBody differs from UpdateV2 only in that this method exposes the field mask in the request body,
// so that clients can specify their mask explicitly | [
"PatchWithFieldMaskInBody",
"differs",
"from",
"UpdateV2",
"only",
"in",
"that",
"this",
"method",
"exposes",
"the",
"field",
"mask",
"in",
"the",
"request",
"body",
"so",
"that",
"clients",
"can",
"specify",
"their",
"mask",
"explicitly"
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/examples/server/a_bit_of_everything.go#L184-L196 |
133,790 | grpc-ecosystem/grpc-gateway | runtime/errors.go | DefaultOtherErrorHandler | func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, msg string, code int) {
http.Error(w, msg, code)
} | go | func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, msg string, code int) {
http.Error(w, msg, code)
} | [
"func",
"DefaultOtherErrorHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"_",
"*",
"http",
".",
"Request",
",",
"msg",
"string",
",",
"code",
"int",
")",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"msg",
",",
"code",
")",
"\n",
"}"
] | // DefaultOtherErrorHandler is the default implementation of OtherErrorHandler.
// It simply writes a string representation of the given error into "w". | [
"DefaultOtherErrorHandler",
"is",
"the",
"default",
"implementation",
"of",
"OtherErrorHandler",
".",
"It",
"simply",
"writes",
"a",
"string",
"representation",
"of",
"the",
"given",
"error",
"into",
"w",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/runtime/errors.go#L143-L145 |
133,791 | grpc-ecosystem/grpc-gateway | examples/proto/examplepb/response_body_service.pb.gw.go | RegisterResponseBodyServiceHandler | func RegisterResponseBodyServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterResponseBodyServiceHandlerClient(ctx, mux, NewResponseBodyServiceClient(conn))
} | go | func RegisterResponseBodyServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterResponseBodyServiceHandlerClient(ctx, mux, NewResponseBodyServiceClient(conn))
} | [
"func",
"RegisterResponseBodyServiceHandler",
"(",
"ctx",
"context",
".",
"Context",
",",
"mux",
"*",
"runtime",
".",
"ServeMux",
",",
"conn",
"*",
"grpc",
".",
"ClientConn",
")",
"error",
"{",
"return",
"RegisterResponseBodyServiceHandlerClient",
"(",
"ctx",
",",... | // RegisterResponseBodyServiceHandler registers the http handlers for service ResponseBodyService to "mux".
// The handlers forward requests to the grpc endpoint over "conn". | [
"RegisterResponseBodyServiceHandler",
"registers",
"the",
"http",
"handlers",
"for",
"service",
"ResponseBodyService",
"to",
"mux",
".",
"The",
"handlers",
"forward",
"requests",
"to",
"the",
"grpc",
"endpoint",
"over",
"conn",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/examples/proto/examplepb/response_body_service.pb.gw.go#L139-L141 |
133,792 | grpc-ecosystem/grpc-gateway | codegenerator/parse_req.go | ParseRequest | func ParseRequest(r io.Reader) (*plugin.CodeGeneratorRequest, error) {
input, err := ioutil.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("failed to read code generator request: %v", err)
}
req := new(plugin.CodeGeneratorRequest)
if err = proto.Unmarshal(input, req); err != nil {
return nil, fmt.Errorf("fa... | go | func ParseRequest(r io.Reader) (*plugin.CodeGeneratorRequest, error) {
input, err := ioutil.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("failed to read code generator request: %v", err)
}
req := new(plugin.CodeGeneratorRequest)
if err = proto.Unmarshal(input, req); err != nil {
return nil, fmt.Errorf("fa... | [
"func",
"ParseRequest",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"plugin",
".",
"CodeGeneratorRequest",
",",
"error",
")",
"{",
"input",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // ParseRequest parses a code generator request from a proto Message. | [
"ParseRequest",
"parses",
"a",
"code",
"generator",
"request",
"from",
"a",
"proto",
"Message",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/codegenerator/parse_req.go#L13-L23 |
133,793 | grpc-ecosystem/grpc-gateway | runtime/fieldmask.go | FieldMaskFromRequestBody | func FieldMaskFromRequestBody(r io.Reader) (*field_mask.FieldMask, error) {
fm := &field_mask.FieldMask{}
var root interface{}
if err := json.NewDecoder(r).Decode(&root); err != nil {
if err == io.EOF {
return fm, nil
}
return nil, err
}
queue := []fieldMaskPathItem{{node: root}}
for len(queue) > 0 {
... | go | func FieldMaskFromRequestBody(r io.Reader) (*field_mask.FieldMask, error) {
fm := &field_mask.FieldMask{}
var root interface{}
if err := json.NewDecoder(r).Decode(&root); err != nil {
if err == io.EOF {
return fm, nil
}
return nil, err
}
queue := []fieldMaskPathItem{{node: root}}
for len(queue) > 0 {
... | [
"func",
"FieldMaskFromRequestBody",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"field_mask",
".",
"FieldMask",
",",
"error",
")",
"{",
"fm",
":=",
"&",
"field_mask",
".",
"FieldMask",
"{",
"}",
"\n",
"var",
"root",
"interface",
"{",
"}",
"\n",
"if",... | // FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body. | [
"FieldMaskFromRequestBody",
"creates",
"a",
"FieldMask",
"printing",
"all",
"complete",
"paths",
"from",
"the",
"JSON",
"body",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/runtime/fieldmask.go#L13-L41 |
133,794 | grpc-ecosystem/grpc-gateway | runtime/fieldmask.go | CamelCaseFieldMask | func CamelCaseFieldMask(mask *field_mask.FieldMask) {
if mask == nil || mask.Paths == nil {
return
}
var newPaths []string
for _, path := range mask.Paths {
lowerCasedParts := strings.Split(path, ".")
var camelCasedParts []string
for _, part := range lowerCasedParts {
camelCasedParts = append(camelCased... | go | func CamelCaseFieldMask(mask *field_mask.FieldMask) {
if mask == nil || mask.Paths == nil {
return
}
var newPaths []string
for _, path := range mask.Paths {
lowerCasedParts := strings.Split(path, ".")
var camelCasedParts []string
for _, part := range lowerCasedParts {
camelCasedParts = append(camelCased... | [
"func",
"CamelCaseFieldMask",
"(",
"mask",
"*",
"field_mask",
".",
"FieldMask",
")",
"{",
"if",
"mask",
"==",
"nil",
"||",
"mask",
".",
"Paths",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"var",
"newPaths",
"[",
"]",
"string",
"\n",
"for",
"_",
"... | // CamelCaseFieldMask updates the given FieldMask by converting all of its paths to CamelCase, using the same heuristic
// that's used for naming protobuf fields in Go. | [
"CamelCaseFieldMask",
"updates",
"the",
"given",
"FieldMask",
"by",
"converting",
"all",
"of",
"its",
"paths",
"to",
"CamelCase",
"using",
"the",
"same",
"heuristic",
"that",
"s",
"used",
"for",
"naming",
"protobuf",
"fields",
"in",
"Go",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/runtime/fieldmask.go#L54-L70 |
133,795 | grpc-ecosystem/grpc-gateway | examples/gateway/main.go | Run | func Run(ctx context.Context, opts Options) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
conn, err := dial(ctx, opts.GRPCServer.Network, opts.GRPCServer.Addr)
if err != nil {
return err
}
go func() {
<-ctx.Done()
if err := conn.Close(); err != nil {
glog.Errorf("Failed to close a client... | go | func Run(ctx context.Context, opts Options) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
conn, err := dial(ctx, opts.GRPCServer.Network, opts.GRPCServer.Addr)
if err != nil {
return err
}
go func() {
<-ctx.Done()
if err := conn.Close(); err != nil {
glog.Errorf("Failed to close a client... | [
"func",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"Options",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"conn",
",",
"err",
":=",
"dial",
... | // Run starts a HTTP server and blocks while running if successful.
// The server will be shutdown when "ctx" is canceled. | [
"Run",
"starts",
"a",
"HTTP",
"server",
"and",
"blocks",
"while",
"running",
"if",
"successful",
".",
"The",
"server",
"will",
"be",
"shutdown",
"when",
"ctx",
"is",
"canceled",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/examples/gateway/main.go#L34-L77 |
133,796 | grpc-ecosystem/grpc-gateway | examples/server/main.go | Run | func Run(ctx context.Context, network, address string) error {
l, err := net.Listen(network, address)
if err != nil {
return err
}
defer func() {
if err := l.Close(); err != nil {
glog.Errorf("Failed to close %s %s: %v", network, address, err)
}
}()
s := grpc.NewServer()
examples.RegisterEchoServiceSer... | go | func Run(ctx context.Context, network, address string) error {
l, err := net.Listen(network, address)
if err != nil {
return err
}
defer func() {
if err := l.Close(); err != nil {
glog.Errorf("Failed to close %s %s: %v", network, address, err)
}
}()
s := grpc.NewServer()
examples.RegisterEchoServiceSer... | [
"func",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"network",
",",
"address",
"string",
")",
"error",
"{",
"l",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"network",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err... | // Run starts the example gRPC service.
// "network" and "address" are passed to net.Listen. | [
"Run",
"starts",
"the",
"example",
"gRPC",
"service",
".",
"network",
"and",
"address",
"are",
"passed",
"to",
"net",
".",
"Listen",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/examples/server/main.go#L14-L39 |
133,797 | grpc-ecosystem/grpc-gateway | utilities/readerfactory.go | IOReaderFactory | func IOReaderFactory(r io.Reader) (func() io.Reader, error) {
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return func() io.Reader {
return bytes.NewReader(b)
}, nil
} | go | func IOReaderFactory(r io.Reader) (func() io.Reader, error) {
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return func() io.Reader {
return bytes.NewReader(b)
}, nil
} | [
"func",
"IOReaderFactory",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"func",
"(",
")",
"io",
".",
"Reader",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n... | // IOReaderFactory takes in an io.Reader and returns a function that will allow you to create a new reader that begins
// at the start of the stream | [
"IOReaderFactory",
"takes",
"in",
"an",
"io",
".",
"Reader",
"and",
"returns",
"a",
"function",
"that",
"will",
"allow",
"you",
"to",
"create",
"a",
"new",
"reader",
"that",
"begins",
"at",
"the",
"start",
"of",
"the",
"stream"
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/utilities/readerfactory.go#L11-L20 |
133,798 | grpc-ecosystem/grpc-gateway | examples/proto/examplepb/wrappers.pb.gw.go | RegisterWrappersServiceHandler | func RegisterWrappersServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterWrappersServiceHandlerClient(ctx, mux, NewWrappersServiceClient(conn))
} | go | func RegisterWrappersServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterWrappersServiceHandlerClient(ctx, mux, NewWrappersServiceClient(conn))
} | [
"func",
"RegisterWrappersServiceHandler",
"(",
"ctx",
"context",
".",
"Context",
",",
"mux",
"*",
"runtime",
".",
"ServeMux",
",",
"conn",
"*",
"grpc",
".",
"ClientConn",
")",
"error",
"{",
"return",
"RegisterWrappersServiceHandlerClient",
"(",
"ctx",
",",
"mux"... | // RegisterWrappersServiceHandler registers the http handlers for service WrappersService to "mux".
// The handlers forward requests to the grpc endpoint over "conn". | [
"RegisterWrappersServiceHandler",
"registers",
"the",
"http",
"handlers",
"for",
"service",
"WrappersService",
"to",
"mux",
".",
"The",
"handlers",
"forward",
"requests",
"to",
"the",
"grpc",
"endpoint",
"over",
"conn",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/examples/proto/examplepb/wrappers.pb.gw.go#L247-L249 |
133,799 | grpc-ecosystem/grpc-gateway | protoc-gen-grpc-gateway/descriptor/registry.go | NewRegistry | func NewRegistry() *Registry {
return &Registry{
msgs: make(map[string]*Message),
enums: make(map[string]*Enum),
files: make(map[string]*File),
pkgMap: make(map[string]string),
pkgAliases: make(map[string]string),
externalHTTPRules: make(map[string][]*... | go | func NewRegistry() *Registry {
return &Registry{
msgs: make(map[string]*Message),
enums: make(map[string]*Enum),
files: make(map[string]*File),
pkgMap: make(map[string]string),
pkgAliases: make(map[string]string),
externalHTTPRules: make(map[string][]*... | [
"func",
"NewRegistry",
"(",
")",
"*",
"Registry",
"{",
"return",
"&",
"Registry",
"{",
"msgs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Message",
")",
",",
"enums",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Enum",
")",
",",
"fi... | // NewRegistry returns a new Registry. | [
"NewRegistry",
"returns",
"a",
"new",
"Registry",
"."
] | 52a539ec166cf7380660e9c7ebde5206169d385d | https://github.com/grpc-ecosystem/grpc-gateway/blob/52a539ec166cf7380660e9c7ebde5206169d385d/protoc-gen-grpc-gateway/descriptor/registry.go#L78-L91 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.