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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
131,900 | hashicorp/nomad | api/operator.go | SchedulerCASConfiguration | func (op *Operator) SchedulerCASConfiguration(conf *SchedulerConfiguration, q *WriteOptions) (*SchedulerSetConfigurationResponse, *WriteMeta, error) {
var out SchedulerSetConfigurationResponse
wm, err := op.c.write("/v1/operator/scheduler/configuration?cas="+strconv.FormatUint(conf.ModifyIndex, 10), conf, &out, q)
i... | go | func (op *Operator) SchedulerCASConfiguration(conf *SchedulerConfiguration, q *WriteOptions) (*SchedulerSetConfigurationResponse, *WriteMeta, error) {
var out SchedulerSetConfigurationResponse
wm, err := op.c.write("/v1/operator/scheduler/configuration?cas="+strconv.FormatUint(conf.ModifyIndex, 10), conf, &out, q)
i... | [
"func",
"(",
"op",
"*",
"Operator",
")",
"SchedulerCASConfiguration",
"(",
"conf",
"*",
"SchedulerConfiguration",
",",
"q",
"*",
"WriteOptions",
")",
"(",
"*",
"SchedulerSetConfigurationResponse",
",",
"*",
"WriteMeta",
",",
"error",
")",
"{",
"var",
"out",
"S... | // SchedulerCASConfiguration is used to perform a Check-And-Set update on the
// Scheduler configuration. The ModifyIndex value will be respected. Returns
// true on success or false on failures. | [
"SchedulerCASConfiguration",
"is",
"used",
"to",
"perform",
"a",
"Check",
"-",
"And",
"-",
"Set",
"update",
"on",
"the",
"Scheduler",
"configuration",
".",
"The",
"ModifyIndex",
"value",
"will",
"be",
"respected",
".",
"Returns",
"true",
"on",
"success",
"or",... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/operator.go#L168-L176 |
131,901 | hashicorp/nomad | api/raw.go | Response | func (raw *Raw) Response(endpoint string, q *QueryOptions) (io.ReadCloser, error) {
return raw.c.rawQuery(endpoint, q)
} | go | func (raw *Raw) Response(endpoint string, q *QueryOptions) (io.ReadCloser, error) {
return raw.c.rawQuery(endpoint, q)
} | [
"func",
"(",
"raw",
"*",
"Raw",
")",
"Response",
"(",
"endpoint",
"string",
",",
"q",
"*",
"QueryOptions",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"return",
"raw",
".",
"c",
".",
"rawQuery",
"(",
"endpoint",
",",
"q",
")",
"\n",
... | // Response is used to make a GET request against an endpoint and returns the
// response body | [
"Response",
"is",
"used",
"to",
"make",
"a",
"GET",
"request",
"against",
"an",
"endpoint",
"and",
"returns",
"the",
"response",
"body"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/raw.go#L24-L26 |
131,902 | hashicorp/nomad | drivers/shared/executor/resource_container_linux.go | executorCleanup | func (rc *resourceContainerContext) executorCleanup() error {
rc.cgLock.Lock()
defer rc.cgLock.Unlock()
if err := DestroyCgroup(rc.groups, os.Getpid()); err != nil {
return err
}
return nil
} | go | func (rc *resourceContainerContext) executorCleanup() error {
rc.cgLock.Lock()
defer rc.cgLock.Unlock()
if err := DestroyCgroup(rc.groups, os.Getpid()); err != nil {
return err
}
return nil
} | [
"func",
"(",
"rc",
"*",
"resourceContainerContext",
")",
"executorCleanup",
"(",
")",
"error",
"{",
"rc",
".",
"cgLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rc",
".",
"cgLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"DestroyCgroup",
"(",
... | // cleanup removes this host's Cgroup from within an Executor's context | [
"cleanup",
"removes",
"this",
"host",
"s",
"Cgroup",
"from",
"within",
"an",
"Executor",
"s",
"context"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/drivers/shared/executor/resource_container_linux.go#L18-L25 |
131,903 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | SetPolicy | func (r *RestartTracker) SetPolicy(policy *structs.RestartPolicy) {
r.lock.Lock()
defer r.lock.Unlock()
r.policy = policy
} | go | func (r *RestartTracker) SetPolicy(policy *structs.RestartPolicy) {
r.lock.Lock()
defer r.lock.Unlock()
r.policy = policy
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"SetPolicy",
"(",
"policy",
"*",
"structs",
".",
"RestartPolicy",
")",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"policy",
... | // SetPolicy updates the policy used to determine restarts. | [
"SetPolicy",
"updates",
"the",
"policy",
"used",
"to",
"determine",
"restarts",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L52-L56 |
131,904 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | GetPolicy | func (r *RestartTracker) GetPolicy() *structs.RestartPolicy {
r.lock.Lock()
defer r.lock.Unlock()
return r.policy.Copy()
} | go | func (r *RestartTracker) GetPolicy() *structs.RestartPolicy {
r.lock.Lock()
defer r.lock.Unlock()
return r.policy.Copy()
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"GetPolicy",
"(",
")",
"*",
"structs",
".",
"RestartPolicy",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"r",
".",
"policy",
... | // GetPolicy returns a copy of the policy used to determine restarts. | [
"GetPolicy",
"returns",
"a",
"copy",
"of",
"the",
"policy",
"used",
"to",
"determine",
"restarts",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L59-L63 |
131,905 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | SetStartError | func (r *RestartTracker) SetStartError(err error) *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
r.startErr = err
r.failure = true
return r
} | go | func (r *RestartTracker) SetStartError(err error) *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
r.startErr = err
r.failure = true
return r
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"SetStartError",
"(",
"err",
"error",
")",
"*",
"RestartTracker",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"startErr",
"=",... | // SetStartError is used to mark the most recent start error. If starting was
// successful the error should be nil. | [
"SetStartError",
"is",
"used",
"to",
"mark",
"the",
"most",
"recent",
"start",
"error",
".",
"If",
"starting",
"was",
"successful",
"the",
"error",
"should",
"be",
"nil",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L67-L73 |
131,906 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | SetExitResult | func (r *RestartTracker) SetExitResult(res *drivers.ExitResult) *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
r.exitRes = res
r.failure = true
return r
} | go | func (r *RestartTracker) SetExitResult(res *drivers.ExitResult) *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
r.exitRes = res
r.failure = true
return r
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"SetExitResult",
"(",
"res",
"*",
"drivers",
".",
"ExitResult",
")",
"*",
"RestartTracker",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
... | // SetExitResult is used to mark the most recent wait result. | [
"SetExitResult",
"is",
"used",
"to",
"mark",
"the",
"most",
"recent",
"wait",
"result",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L76-L82 |
131,907 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | SetRestartTriggered | func (r *RestartTracker) SetRestartTriggered(failure bool) *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
if failure {
r.failure = true
} else {
r.restartTriggered = true
}
return r
} | go | func (r *RestartTracker) SetRestartTriggered(failure bool) *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
if failure {
r.failure = true
} else {
r.restartTriggered = true
}
return r
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"SetRestartTriggered",
"(",
"failure",
"bool",
")",
"*",
"RestartTracker",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"failure",
"{... | // SetRestartTriggered is used to mark that the task has been signalled to be
// restarted. Setting the failure to true restarts according to the restart
// policy. When failure is false the task is restarted without considering the
// restart policy. | [
"SetRestartTriggered",
"is",
"used",
"to",
"mark",
"that",
"the",
"task",
"has",
"been",
"signalled",
"to",
"be",
"restarted",
".",
"Setting",
"the",
"failure",
"to",
"true",
"restarts",
"according",
"to",
"the",
"restart",
"policy",
".",
"When",
"failure",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L88-L97 |
131,908 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | SetKilled | func (r *RestartTracker) SetKilled() *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
r.killed = true
return r
} | go | func (r *RestartTracker) SetKilled() *RestartTracker {
r.lock.Lock()
defer r.lock.Unlock()
r.killed = true
return r
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"SetKilled",
"(",
")",
"*",
"RestartTracker",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"killed",
"=",
"true",
"\n",
"retu... | // SetKilled is used to mark that the task has been killed. | [
"SetKilled",
"is",
"used",
"to",
"mark",
"that",
"the",
"task",
"has",
"been",
"killed",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L100-L105 |
131,909 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | GetReason | func (r *RestartTracker) GetReason() string {
r.lock.Lock()
defer r.lock.Unlock()
return r.reason
} | go | func (r *RestartTracker) GetReason() string {
r.lock.Lock()
defer r.lock.Unlock()
return r.reason
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"GetReason",
"(",
")",
"string",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"r",
".",
"reason",
"\n",
"}"
] | // GetReason returns a human-readable description for the last state returned by
// GetState. | [
"GetReason",
"returns",
"a",
"human",
"-",
"readable",
"description",
"for",
"the",
"last",
"state",
"returned",
"by",
"GetState",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L109-L113 |
131,910 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | GetCount | func (r *RestartTracker) GetCount() int {
r.lock.Lock()
defer r.lock.Unlock()
return r.count
} | go | func (r *RestartTracker) GetCount() int {
r.lock.Lock()
defer r.lock.Unlock()
return r.count
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"GetCount",
"(",
")",
"int",
"{",
"r",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"r",
".",
"count",
"\n",
"}"
] | // GetCount returns the current restart count | [
"GetCount",
"returns",
"the",
"current",
"restart",
"count"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L116-L120 |
131,911 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | getDelay | func (r *RestartTracker) getDelay() time.Duration {
end := r.startTime.Add(r.policy.Interval)
now := time.Now()
return end.Sub(now)
} | go | func (r *RestartTracker) getDelay() time.Duration {
end := r.startTime.Add(r.policy.Interval)
now := time.Now()
return end.Sub(now)
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"getDelay",
"(",
")",
"time",
".",
"Duration",
"{",
"end",
":=",
"r",
".",
"startTime",
".",
"Add",
"(",
"r",
".",
"policy",
".",
"Interval",
")",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n"... | // getDelay returns the delay time to enter the next interval. | [
"getDelay",
"returns",
"the",
"delay",
"time",
"to",
"enter",
"the",
"next",
"interval",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L222-L226 |
131,912 | hashicorp/nomad | client/allocrunner/taskrunner/restarts/restarts.go | jitter | func (r *RestartTracker) jitter() time.Duration {
// Get the delay and ensure it is valid.
d := r.policy.Delay.Nanoseconds()
if d == 0 {
d = 1
}
j := float64(r.rand.Int63n(d)) * jitter
return time.Duration(d + int64(j))
} | go | func (r *RestartTracker) jitter() time.Duration {
// Get the delay and ensure it is valid.
d := r.policy.Delay.Nanoseconds()
if d == 0 {
d = 1
}
j := float64(r.rand.Int63n(d)) * jitter
return time.Duration(d + int64(j))
} | [
"func",
"(",
"r",
"*",
"RestartTracker",
")",
"jitter",
"(",
")",
"time",
".",
"Duration",
"{",
"// Get the delay and ensure it is valid.",
"d",
":=",
"r",
".",
"policy",
".",
"Delay",
".",
"Nanoseconds",
"(",
")",
"\n",
"if",
"d",
"==",
"0",
"{",
"d",
... | // jitter returns the delay time plus a jitter. | [
"jitter",
"returns",
"the",
"delay",
"time",
"plus",
"a",
"jitter",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/restarts/restarts.go#L229-L238 |
131,913 | hashicorp/nomad | nomad/node_endpoint.go | constructNodeServerInfoResponse | func (n *Node) constructNodeServerInfoResponse(snap *state.StateSnapshot, reply *structs.NodeUpdateResponse) error {
reply.LeaderRPCAddr = string(n.srv.raft.Leader())
// Reply with config information required for future RPC requests
reply.Servers = make([]*structs.NodeServerInfo, 0, len(n.srv.localPeers))
for _, v... | go | func (n *Node) constructNodeServerInfoResponse(snap *state.StateSnapshot, reply *structs.NodeUpdateResponse) error {
reply.LeaderRPCAddr = string(n.srv.raft.Leader())
// Reply with config information required for future RPC requests
reply.Servers = make([]*structs.NodeServerInfo, 0, len(n.srv.localPeers))
for _, v... | [
"func",
"(",
"n",
"*",
"Node",
")",
"constructNodeServerInfoResponse",
"(",
"snap",
"*",
"state",
".",
"StateSnapshot",
",",
"reply",
"*",
"structs",
".",
"NodeUpdateResponse",
")",
"error",
"{",
"reply",
".",
"LeaderRPCAddr",
"=",
"string",
"(",
"n",
".",
... | // updateNodeUpdateResponse assumes the n.srv.peerLock is held for reading. | [
"updateNodeUpdateResponse",
"assumes",
"the",
"n",
".",
"srv",
".",
"peerLock",
"is",
"held",
"for",
"reading",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L213-L246 |
131,914 | hashicorp/nomad | nomad/node_endpoint.go | Deregister | func (n *Node) Deregister(args *structs.NodeDeregisterRequest, reply *structs.NodeUpdateResponse) error {
if done, err := n.srv.forward("Node.Deregister", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "deregister"}, time.Now())
// Check node permissions
if aclObj... | go | func (n *Node) Deregister(args *structs.NodeDeregisterRequest, reply *structs.NodeUpdateResponse) error {
if done, err := n.srv.forward("Node.Deregister", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "deregister"}, time.Now())
// Check node permissions
if aclObj... | [
"func",
"(",
"n",
"*",
"Node",
")",
"Deregister",
"(",
"args",
"*",
"structs",
".",
"NodeDeregisterRequest",
",",
"reply",
"*",
"structs",
".",
"NodeUpdateResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"n",
".",
"srv",
".",
"forward",
"(... | // Deregister is used to remove a client from the cluster. If a client should
// just be made unavailable for scheduling, a status update is preferred. | [
"Deregister",
"is",
"used",
"to",
"remove",
"a",
"client",
"from",
"the",
"cluster",
".",
"If",
"a",
"client",
"should",
"just",
"be",
"made",
"unavailable",
"for",
"scheduling",
"a",
"status",
"update",
"is",
"preferred",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L250-L320 |
131,915 | hashicorp/nomad | nomad/node_endpoint.go | transitionedToReady | func transitionedToReady(newStatus, oldStatus string) bool {
initToReady := oldStatus == structs.NodeStatusInit && newStatus == structs.NodeStatusReady
terminalToReady := oldStatus == structs.NodeStatusDown && newStatus == structs.NodeStatusReady
return initToReady || terminalToReady
} | go | func transitionedToReady(newStatus, oldStatus string) bool {
initToReady := oldStatus == structs.NodeStatusInit && newStatus == structs.NodeStatusReady
terminalToReady := oldStatus == structs.NodeStatusDown && newStatus == structs.NodeStatusReady
return initToReady || terminalToReady
} | [
"func",
"transitionedToReady",
"(",
"newStatus",
",",
"oldStatus",
"string",
")",
"bool",
"{",
"initToReady",
":=",
"oldStatus",
"==",
"structs",
".",
"NodeStatusInit",
"&&",
"newStatus",
"==",
"structs",
".",
"NodeStatusReady",
"\n",
"terminalToReady",
":=",
"old... | // transitionedToReady is a helper that takes a nodes new and old status and
// returns whether it has transitioned to ready. | [
"transitionedToReady",
"is",
"a",
"helper",
"that",
"takes",
"a",
"nodes",
"new",
"and",
"old",
"status",
"and",
"returns",
"whether",
"it",
"has",
"transitioned",
"to",
"ready",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L445-L449 |
131,916 | hashicorp/nomad | nomad/node_endpoint.go | Evaluate | func (n *Node) Evaluate(args *structs.NodeEvaluateRequest, reply *structs.NodeUpdateResponse) error {
if done, err := n.srv.forward("Node.Evaluate", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "evaluate"}, time.Now())
// Check node write permissions
if aclObj, ... | go | func (n *Node) Evaluate(args *structs.NodeEvaluateRequest, reply *structs.NodeUpdateResponse) error {
if done, err := n.srv.forward("Node.Evaluate", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "evaluate"}, time.Now())
// Check node write permissions
if aclObj, ... | [
"func",
"(",
"n",
"*",
"Node",
")",
"Evaluate",
"(",
"args",
"*",
"structs",
".",
"NodeEvaluateRequest",
",",
"reply",
"*",
"structs",
".",
"NodeUpdateResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"n",
".",
"srv",
".",
"forward",
"(",
... | // Evaluate is used to force a re-evaluation of the node | [
"Evaluate",
"is",
"used",
"to",
"force",
"a",
"re",
"-",
"evaluation",
"of",
"the",
"node"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L633-L684 |
131,917 | hashicorp/nomad | nomad/node_endpoint.go | GetNode | func (n *Node) GetNode(args *structs.NodeSpecificRequest,
reply *structs.SingleNodeResponse) error {
if done, err := n.srv.forward("Node.GetNode", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "get_node"}, time.Now())
// Check node read permissions
if aclObj, er... | go | func (n *Node) GetNode(args *structs.NodeSpecificRequest,
reply *structs.SingleNodeResponse) error {
if done, err := n.srv.forward("Node.GetNode", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "get_node"}, time.Now())
// Check node read permissions
if aclObj, er... | [
"func",
"(",
"n",
"*",
"Node",
")",
"GetNode",
"(",
"args",
"*",
"structs",
".",
"NodeSpecificRequest",
",",
"reply",
"*",
"structs",
".",
"SingleNodeResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"n",
".",
"srv",
".",
"forward",
"(",
... | // GetNode is used to request information about a specific node | [
"GetNode",
"is",
"used",
"to",
"request",
"information",
"about",
"a",
"specific",
"node"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L687-L756 |
131,918 | hashicorp/nomad | nomad/node_endpoint.go | GetAllocs | func (n *Node) GetAllocs(args *structs.NodeSpecificRequest,
reply *structs.NodeAllocsResponse) error {
if done, err := n.srv.forward("Node.GetAllocs", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "get_allocs"}, time.Now())
// Check node read and namespace job re... | go | func (n *Node) GetAllocs(args *structs.NodeSpecificRequest,
reply *structs.NodeAllocsResponse) error {
if done, err := n.srv.forward("Node.GetAllocs", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "get_allocs"}, time.Now())
// Check node read and namespace job re... | [
"func",
"(",
"n",
"*",
"Node",
")",
"GetAllocs",
"(",
"args",
"*",
"structs",
".",
"NodeSpecificRequest",
",",
"reply",
"*",
"structs",
".",
"NodeAllocsResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"n",
".",
"srv",
".",
"forward",
"(",
... | // GetAllocs is used to request allocations for a specific node | [
"GetAllocs",
"is",
"used",
"to",
"request",
"allocations",
"for",
"a",
"specific",
"node"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L759-L845 |
131,919 | hashicorp/nomad | nomad/node_endpoint.go | batchUpdate | func (n *Node) batchUpdate(future *structs.BatchFuture, updates []*structs.Allocation, evals []*structs.Evaluation) {
// Group pending evals by jobID to prevent creating unnecessary evals
evalsByJobId := make(map[structs.NamespacedID]struct{})
var trimmedEvals []*structs.Evaluation
for _, eval := range evals {
na... | go | func (n *Node) batchUpdate(future *structs.BatchFuture, updates []*structs.Allocation, evals []*structs.Evaluation) {
// Group pending evals by jobID to prevent creating unnecessary evals
evalsByJobId := make(map[structs.NamespacedID]struct{})
var trimmedEvals []*structs.Evaluation
for _, eval := range evals {
na... | [
"func",
"(",
"n",
"*",
"Node",
")",
"batchUpdate",
"(",
"future",
"*",
"structs",
".",
"BatchFuture",
",",
"updates",
"[",
"]",
"*",
"structs",
".",
"Allocation",
",",
"evals",
"[",
"]",
"*",
"structs",
".",
"Evaluation",
")",
"{",
"// Group pending eval... | // batchUpdate is used to update all the allocations | [
"batchUpdate",
"is",
"used",
"to",
"update",
"all",
"the",
"allocations"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L1081-L1145 |
131,920 | hashicorp/nomad | nomad/node_endpoint.go | List | func (n *Node) List(args *structs.NodeListRequest,
reply *structs.NodeListResponse) error {
if done, err := n.srv.forward("Node.List", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "list"}, time.Now())
// Check node read permissions
if aclObj, err := n.srv.Resol... | go | func (n *Node) List(args *structs.NodeListRequest,
reply *structs.NodeListResponse) error {
if done, err := n.srv.forward("Node.List", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "client", "list"}, time.Now())
// Check node read permissions
if aclObj, err := n.srv.Resol... | [
"func",
"(",
"n",
"*",
"Node",
")",
"List",
"(",
"args",
"*",
"structs",
".",
"NodeListRequest",
",",
"reply",
"*",
"structs",
".",
"NodeListResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"n",
".",
"srv",
".",
"forward",
"(",
"\"",
"... | // List is used to list the available nodes | [
"List",
"is",
"used",
"to",
"list",
"the",
"available",
"nodes"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/node_endpoint.go#L1148-L1202 |
131,921 | hashicorp/nomad | command/agent/http.go | NewHTTPServer | func NewHTTPServer(agent *Agent, config *Config) (*HTTPServer, error) {
// Start the listener
lnAddr, err := net.ResolveTCPAddr("tcp", config.normalizedAddrs.HTTP)
if err != nil {
return nil, err
}
ln, err := config.Listener("tcp", lnAddr.IP.String(), lnAddr.Port)
if err != nil {
return nil, fmt.Errorf("faile... | go | func NewHTTPServer(agent *Agent, config *Config) (*HTTPServer, error) {
// Start the listener
lnAddr, err := net.ResolveTCPAddr("tcp", config.normalizedAddrs.HTTP)
if err != nil {
return nil, err
}
ln, err := config.Listener("tcp", lnAddr.IP.String(), lnAddr.Port)
if err != nil {
return nil, fmt.Errorf("faile... | [
"func",
"NewHTTPServer",
"(",
"agent",
"*",
"Agent",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"HTTPServer",
",",
"error",
")",
"{",
"// Start the listener",
"lnAddr",
",",
"err",
":=",
"net",
".",
"ResolveTCPAddr",
"(",
"\"",
"\"",
",",
"config",
"."... | // NewHTTPServer starts new HTTP server over the agent | [
"NewHTTPServer",
"starts",
"new",
"HTTP",
"server",
"over",
"the",
"agent"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L60-L111 |
131,922 | hashicorp/nomad | command/agent/http.go | Shutdown | func (s *HTTPServer) Shutdown() {
if s != nil {
s.logger.Debug("shutting down http server")
s.listener.Close()
<-s.listenerCh // block until http.Serve has returned.
}
} | go | func (s *HTTPServer) Shutdown() {
if s != nil {
s.logger.Debug("shutting down http server")
s.listener.Close()
<-s.listenerCh // block until http.Serve has returned.
}
} | [
"func",
"(",
"s",
"*",
"HTTPServer",
")",
"Shutdown",
"(",
")",
"{",
"if",
"s",
"!=",
"nil",
"{",
"s",
".",
"logger",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"s",
".",
"listener",
".",
"Close",
"(",
")",
"\n",
"<-",
"s",
".",
"listenerCh",
... | // Shutdown is used to shutdown the HTTP server | [
"Shutdown",
"is",
"used",
"to",
"shutdown",
"the",
"HTTP",
"server"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L131-L137 |
131,923 | hashicorp/nomad | command/agent/http.go | setIndex | func setIndex(resp http.ResponseWriter, index uint64) {
resp.Header().Set("X-Nomad-Index", strconv.FormatUint(index, 10))
} | go | func setIndex(resp http.ResponseWriter, index uint64) {
resp.Header().Set("X-Nomad-Index", strconv.FormatUint(index, 10))
} | [
"func",
"setIndex",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"index",
"uint64",
")",
"{",
"resp",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"FormatUint",
"(",
"index",
",",
"10",
")",
")",
"\n",
"}"
] | // setIndex is used to set the index response header | [
"setIndex",
"is",
"used",
"to",
"set",
"the",
"index",
"response",
"header"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L348-L350 |
131,924 | hashicorp/nomad | command/agent/http.go | setLastContact | func setLastContact(resp http.ResponseWriter, last time.Duration) {
lastMsec := uint64(last / time.Millisecond)
resp.Header().Set("X-Nomad-LastContact", strconv.FormatUint(lastMsec, 10))
} | go | func setLastContact(resp http.ResponseWriter, last time.Duration) {
lastMsec := uint64(last / time.Millisecond)
resp.Header().Set("X-Nomad-LastContact", strconv.FormatUint(lastMsec, 10))
} | [
"func",
"setLastContact",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"last",
"time",
".",
"Duration",
")",
"{",
"lastMsec",
":=",
"uint64",
"(",
"last",
"/",
"time",
".",
"Millisecond",
")",
"\n",
"resp",
".",
"Header",
"(",
")",
".",
"Set",
"(",... | // setLastContact is used to set the last contact header | [
"setLastContact",
"is",
"used",
"to",
"set",
"the",
"last",
"contact",
"header"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L362-L365 |
131,925 | hashicorp/nomad | command/agent/http.go | setMeta | func setMeta(resp http.ResponseWriter, m *structs.QueryMeta) {
setIndex(resp, m.Index)
setLastContact(resp, m.LastContact)
setKnownLeader(resp, m.KnownLeader)
} | go | func setMeta(resp http.ResponseWriter, m *structs.QueryMeta) {
setIndex(resp, m.Index)
setLastContact(resp, m.LastContact)
setKnownLeader(resp, m.KnownLeader)
} | [
"func",
"setMeta",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"m",
"*",
"structs",
".",
"QueryMeta",
")",
"{",
"setIndex",
"(",
"resp",
",",
"m",
".",
"Index",
")",
"\n",
"setLastContact",
"(",
"resp",
",",
"m",
".",
"LastContact",
")",
"\n",
"... | // setMeta is used to set the query response meta data | [
"setMeta",
"is",
"used",
"to",
"set",
"the",
"query",
"response",
"meta",
"data"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L368-L372 |
131,926 | hashicorp/nomad | command/agent/http.go | parseConsistency | func parseConsistency(req *http.Request, b *structs.QueryOptions) {
query := req.URL.Query()
if _, ok := query["stale"]; ok {
b.AllowStale = true
}
} | go | func parseConsistency(req *http.Request, b *structs.QueryOptions) {
query := req.URL.Query()
if _, ok := query["stale"]; ok {
b.AllowStale = true
}
} | [
"func",
"parseConsistency",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"b",
"*",
"structs",
".",
"QueryOptions",
")",
"{",
"query",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"query",
"[",
"\"",
"\"",
"]... | // parseConsistency is used to parse the ?stale query params. | [
"parseConsistency",
"is",
"used",
"to",
"parse",
"the",
"?stale",
"query",
"params",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L407-L412 |
131,927 | hashicorp/nomad | command/agent/http.go | parsePrefix | func parsePrefix(req *http.Request, b *structs.QueryOptions) {
query := req.URL.Query()
if prefix := query.Get("prefix"); prefix != "" {
b.Prefix = prefix
}
} | go | func parsePrefix(req *http.Request, b *structs.QueryOptions) {
query := req.URL.Query()
if prefix := query.Get("prefix"); prefix != "" {
b.Prefix = prefix
}
} | [
"func",
"parsePrefix",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"b",
"*",
"structs",
".",
"QueryOptions",
")",
"{",
"query",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"if",
"prefix",
":=",
"query",
".",
"Get",
"(",
"\"",
"\"",
"... | // parsePrefix is used to parse the ?prefix query param | [
"parsePrefix",
"is",
"used",
"to",
"parse",
"the",
"?prefix",
"query",
"param"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L415-L420 |
131,928 | hashicorp/nomad | command/agent/http.go | parseRegion | func (s *HTTPServer) parseRegion(req *http.Request, r *string) {
if other := req.URL.Query().Get("region"); other != "" {
*r = other
} else if *r == "" {
*r = s.agent.config.Region
}
} | go | func (s *HTTPServer) parseRegion(req *http.Request, r *string) {
if other := req.URL.Query().Get("region"); other != "" {
*r = other
} else if *r == "" {
*r = s.agent.config.Region
}
} | [
"func",
"(",
"s",
"*",
"HTTPServer",
")",
"parseRegion",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"r",
"*",
"string",
")",
"{",
"if",
"other",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"other",... | // parseRegion is used to parse the ?region query param | [
"parseRegion",
"is",
"used",
"to",
"parse",
"the",
"?region",
"query",
"param"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L423-L429 |
131,929 | hashicorp/nomad | command/agent/http.go | parseNamespace | func parseNamespace(req *http.Request, n *string) {
if other := req.URL.Query().Get("namespace"); other != "" {
*n = other
} else if *n == "" {
*n = structs.DefaultNamespace
}
} | go | func parseNamespace(req *http.Request, n *string) {
if other := req.URL.Query().Get("namespace"); other != "" {
*n = other
} else if *n == "" {
*n = structs.DefaultNamespace
}
} | [
"func",
"parseNamespace",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"n",
"*",
"string",
")",
"{",
"if",
"other",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"other",
"!=",
"\"",
"\"",
"{",
"*",
... | // parseNamespace is used to parse the ?namespace parameter | [
"parseNamespace",
"is",
"used",
"to",
"parse",
"the",
"?namespace",
"parameter"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L432-L438 |
131,930 | hashicorp/nomad | command/agent/http.go | parseToken | func (s *HTTPServer) parseToken(req *http.Request, token *string) {
if other := req.Header.Get("X-Nomad-Token"); other != "" {
*token = other
return
}
} | go | func (s *HTTPServer) parseToken(req *http.Request, token *string) {
if other := req.Header.Get("X-Nomad-Token"); other != "" {
*token = other
return
}
} | [
"func",
"(",
"s",
"*",
"HTTPServer",
")",
"parseToken",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"token",
"*",
"string",
")",
"{",
"if",
"other",
":=",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"other",
"!=",
"\"",
"\"",
... | // parseToken is used to parse the X-Nomad-Token param | [
"parseToken",
"is",
"used",
"to",
"parse",
"the",
"X",
"-",
"Nomad",
"-",
"Token",
"param"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L441-L446 |
131,931 | hashicorp/nomad | command/agent/http.go | parse | func (s *HTTPServer) parse(resp http.ResponseWriter, req *http.Request, r *string, b *structs.QueryOptions) bool {
s.parseRegion(req, r)
s.parseToken(req, &b.AuthToken)
parseConsistency(req, b)
parsePrefix(req, b)
parseNamespace(req, &b.Namespace)
return parseWait(resp, req, b)
} | go | func (s *HTTPServer) parse(resp http.ResponseWriter, req *http.Request, r *string, b *structs.QueryOptions) bool {
s.parseRegion(req, r)
s.parseToken(req, &b.AuthToken)
parseConsistency(req, b)
parsePrefix(req, b)
parseNamespace(req, &b.Namespace)
return parseWait(resp, req, b)
} | [
"func",
"(",
"s",
"*",
"HTTPServer",
")",
"parse",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
",",
"r",
"*",
"string",
",",
"b",
"*",
"structs",
".",
"QueryOptions",
")",
"bool",
"{",
"s",
".",
"parseRegion",... | // parse is a convenience method for endpoints that need to parse multiple flags | [
"parse",
"is",
"a",
"convenience",
"method",
"for",
"endpoints",
"that",
"need",
"to",
"parse",
"multiple",
"flags"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L449-L456 |
131,932 | hashicorp/nomad | command/agent/http.go | parseWriteRequest | func (s *HTTPServer) parseWriteRequest(req *http.Request, w *structs.WriteRequest) {
parseNamespace(req, &w.Namespace)
s.parseToken(req, &w.AuthToken)
s.parseRegion(req, &w.Region)
} | go | func (s *HTTPServer) parseWriteRequest(req *http.Request, w *structs.WriteRequest) {
parseNamespace(req, &w.Namespace)
s.parseToken(req, &w.AuthToken)
s.parseRegion(req, &w.Region)
} | [
"func",
"(",
"s",
"*",
"HTTPServer",
")",
"parseWriteRequest",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"w",
"*",
"structs",
".",
"WriteRequest",
")",
"{",
"parseNamespace",
"(",
"req",
",",
"&",
"w",
".",
"Namespace",
")",
"\n",
"s",
".",
"pars... | // parseWriteRequest is a convenience method for endpoints that need to parse a
// write request. | [
"parseWriteRequest",
"is",
"a",
"convenience",
"method",
"for",
"endpoints",
"that",
"need",
"to",
"parse",
"a",
"write",
"request",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L460-L464 |
131,933 | hashicorp/nomad | command/agent/http.go | wrapCORS | func wrapCORS(f func(http.ResponseWriter, *http.Request)) http.Handler {
return allowCORS.Handler(http.HandlerFunc(f))
} | go | func wrapCORS(f func(http.ResponseWriter, *http.Request)) http.Handler {
return allowCORS.Handler(http.HandlerFunc(f))
} | [
"func",
"wrapCORS",
"(",
"f",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
")",
"http",
".",
"Handler",
"{",
"return",
"allowCORS",
".",
"Handler",
"(",
"http",
".",
"HandlerFunc",
"(",
"f",
")",
")",
"\n",
"}"
] | // wrapCORS wraps a HandlerFunc in allowCORS and returns a http.Handler | [
"wrapCORS",
"wraps",
"a",
"HandlerFunc",
"in",
"allowCORS",
"and",
"returns",
"a",
"http",
".",
"Handler"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/http.go#L467-L469 |
131,934 | hashicorp/nomad | command/agent/config_parse.go | ParseConfigFile | func ParseConfigFile(path string) (*Config, error) {
path, err := filepath.Abs(path)
if err != nil {
return nil, err
}
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
config, err := ParseConfig(f)
if err != nil {
return nil, err
}
return config, nil
} | go | func ParseConfigFile(path string) (*Config, error) {
path, err := filepath.Abs(path)
if err != nil {
return nil, err
}
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
config, err := ParseConfig(f)
if err != nil {
return nil, err
}
return config, nil
} | [
"func",
"ParseConfigFile",
"(",
"path",
"string",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"path",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\... | // ParseConfigFile parses the given path as a config file. | [
"ParseConfigFile",
"parses",
"the",
"given",
"path",
"as",
"a",
"config",
"file",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/config_parse.go#L22-L40 |
131,935 | hashicorp/nomad | command/agent/config_parse.go | ParseConfig | func ParseConfig(r io.Reader) (*Config, error) {
// Copy the reader into an in-memory buffer first since HCL requires it.
var buf bytes.Buffer
if _, err := io.Copy(&buf, r); err != nil {
return nil, err
}
// Parse the buffer
root, err := hcl.Parse(buf.String())
if err != nil {
return nil, fmt.Errorf("error ... | go | func ParseConfig(r io.Reader) (*Config, error) {
// Copy the reader into an in-memory buffer first since HCL requires it.
var buf bytes.Buffer
if _, err := io.Copy(&buf, r); err != nil {
return nil, err
}
// Parse the buffer
root, err := hcl.Parse(buf.String())
if err != nil {
return nil, fmt.Errorf("error ... | [
"func",
"ParseConfig",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"// Copy the reader into an in-memory buffer first since HCL requires it.",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".... | // ParseConfig parses the config from the given io.Reader.
//
// Due to current internal limitations, the entire contents of the
// io.Reader will be copied into memory first before parsing. | [
"ParseConfig",
"parses",
"the",
"config",
"from",
"the",
"given",
"io",
".",
"Reader",
".",
"Due",
"to",
"current",
"internal",
"limitations",
"the",
"entire",
"contents",
"of",
"the",
"io",
".",
"Reader",
"will",
"be",
"copied",
"into",
"memory",
"first",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/config_parse.go#L46-L72 |
131,936 | hashicorp/nomad | api/agent.go | populateCache | func (a *Agent) populateCache(self *AgentSelf) {
if a.nodeName == "" {
a.nodeName = self.Member.Name
}
if a.datacenter == "" {
if val, ok := self.Config["Datacenter"]; ok {
a.datacenter, _ = val.(string)
}
}
if a.region == "" {
if val, ok := self.Config["Region"]; ok {
a.region, _ = val.(string)
}
... | go | func (a *Agent) populateCache(self *AgentSelf) {
if a.nodeName == "" {
a.nodeName = self.Member.Name
}
if a.datacenter == "" {
if val, ok := self.Config["Datacenter"]; ok {
a.datacenter, _ = val.(string)
}
}
if a.region == "" {
if val, ok := self.Config["Region"]; ok {
a.region, _ = val.(string)
}
... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"populateCache",
"(",
"self",
"*",
"AgentSelf",
")",
"{",
"if",
"a",
".",
"nodeName",
"==",
"\"",
"\"",
"{",
"a",
".",
"nodeName",
"=",
"self",
".",
"Member",
".",
"Name",
"\n",
"}",
"\n",
"if",
"a",
".",
"d... | // populateCache is used to insert various pieces of static
// data into the agent handle. This is used during subsequent
// lookups for the same data later on to save the round trip. | [
"populateCache",
"is",
"used",
"to",
"insert",
"various",
"pieces",
"of",
"static",
"data",
"into",
"the",
"agent",
"handle",
".",
"This",
"is",
"used",
"during",
"subsequent",
"lookups",
"for",
"the",
"same",
"data",
"later",
"on",
"to",
"save",
"the",
"r... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L59-L73 |
131,937 | hashicorp/nomad | api/agent.go | NodeName | func (a *Agent) NodeName() (string, error) {
// Return from cache if we have it
if a.nodeName != "" {
return a.nodeName, nil
}
// Query the node name
_, err := a.Self()
return a.nodeName, err
} | go | func (a *Agent) NodeName() (string, error) {
// Return from cache if we have it
if a.nodeName != "" {
return a.nodeName, nil
}
// Query the node name
_, err := a.Self()
return a.nodeName, err
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"NodeName",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Return from cache if we have it",
"if",
"a",
".",
"nodeName",
"!=",
"\"",
"\"",
"{",
"return",
"a",
".",
"nodeName",
",",
"nil",
"\n",
"}",
"\n\n",
... | // NodeName is used to query the Nomad agent for its node name. | [
"NodeName",
"is",
"used",
"to",
"query",
"the",
"Nomad",
"agent",
"for",
"its",
"node",
"name",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L76-L85 |
131,938 | hashicorp/nomad | api/agent.go | Datacenter | func (a *Agent) Datacenter() (string, error) {
// Return from cache if we have it
if a.datacenter != "" {
return a.datacenter, nil
}
// Query the agent for the DC
_, err := a.Self()
return a.datacenter, err
} | go | func (a *Agent) Datacenter() (string, error) {
// Return from cache if we have it
if a.datacenter != "" {
return a.datacenter, nil
}
// Query the agent for the DC
_, err := a.Self()
return a.datacenter, err
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Datacenter",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Return from cache if we have it",
"if",
"a",
".",
"datacenter",
"!=",
"\"",
"\"",
"{",
"return",
"a",
".",
"datacenter",
",",
"nil",
"\n",
"}",
"\n\... | // Datacenter is used to return the name of the datacenter which
// the agent is a member of. | [
"Datacenter",
"is",
"used",
"to",
"return",
"the",
"name",
"of",
"the",
"datacenter",
"which",
"the",
"agent",
"is",
"a",
"member",
"of",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L89-L98 |
131,939 | hashicorp/nomad | api/agent.go | Region | func (a *Agent) Region() (string, error) {
// Return from cache if we have it
if a.region != "" {
return a.region, nil
}
// Query the agent for the region
_, err := a.Self()
return a.region, err
} | go | func (a *Agent) Region() (string, error) {
// Return from cache if we have it
if a.region != "" {
return a.region, nil
}
// Query the agent for the region
_, err := a.Self()
return a.region, err
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Region",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Return from cache if we have it",
"if",
"a",
".",
"region",
"!=",
"\"",
"\"",
"{",
"return",
"a",
".",
"region",
",",
"nil",
"\n",
"}",
"\n\n",
"// Qu... | // Region is used to look up the region the agent is in. | [
"Region",
"is",
"used",
"to",
"look",
"up",
"the",
"region",
"the",
"agent",
"is",
"in",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L101-L110 |
131,940 | hashicorp/nomad | api/agent.go | Join | func (a *Agent) Join(addrs ...string) (int, error) {
// Accumulate the addresses
v := url.Values{}
for _, addr := range addrs {
v.Add("address", addr)
}
// Send the join request
var resp joinResponse
_, err := a.client.write("/v1/agent/join?"+v.Encode(), nil, &resp, nil)
if err != nil {
return 0, fmt.Error... | go | func (a *Agent) Join(addrs ...string) (int, error) {
// Accumulate the addresses
v := url.Values{}
for _, addr := range addrs {
v.Add("address", addr)
}
// Send the join request
var resp joinResponse
_, err := a.client.write("/v1/agent/join?"+v.Encode(), nil, &resp, nil)
if err != nil {
return 0, fmt.Error... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Join",
"(",
"addrs",
"...",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Accumulate the addresses",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{... | // Join is used to instruct a server node to join another server
// via the gossip protocol. Multiple addresses may be specified.
// We attempt to join all of the hosts in the list. Returns the
// number of nodes successfully joined and any error. If one or
// more nodes have a successful result, no error is returned. | [
"Join",
"is",
"used",
"to",
"instruct",
"a",
"server",
"node",
"to",
"join",
"another",
"server",
"via",
"the",
"gossip",
"protocol",
".",
"Multiple",
"addresses",
"may",
"be",
"specified",
".",
"We",
"attempt",
"to",
"join",
"all",
"of",
"the",
"hosts",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L117-L134 |
131,941 | hashicorp/nomad | api/agent.go | Members | func (a *Agent) Members() (*ServerMembers, error) {
var resp *ServerMembers
// Query the known members
_, err := a.client.query("/v1/agent/members", &resp, nil)
if err != nil {
return nil, err
}
return resp, nil
} | go | func (a *Agent) Members() (*ServerMembers, error) {
var resp *ServerMembers
// Query the known members
_, err := a.client.query("/v1/agent/members", &resp, nil)
if err != nil {
return nil, err
}
return resp, nil
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Members",
"(",
")",
"(",
"*",
"ServerMembers",
",",
"error",
")",
"{",
"var",
"resp",
"*",
"ServerMembers",
"\n\n",
"// Query the known members",
"_",
",",
"err",
":=",
"a",
".",
"client",
".",
"query",
"(",
"\"",
... | // Members is used to query all of the known server members | [
"Members",
"is",
"used",
"to",
"query",
"all",
"of",
"the",
"known",
"server",
"members"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L137-L146 |
131,942 | hashicorp/nomad | api/agent.go | ForceLeave | func (a *Agent) ForceLeave(node string) error {
_, err := a.client.write("/v1/agent/force-leave?node="+node, nil, nil, nil)
return err
} | go | func (a *Agent) ForceLeave(node string) error {
_, err := a.client.write("/v1/agent/force-leave?node="+node, nil, nil, nil)
return err
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"ForceLeave",
"(",
"node",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"a",
".",
"client",
".",
"write",
"(",
"\"",
"\"",
"+",
"node",
",",
"nil",
",",
"nil",
",",
"nil",
")",
"\n",
"return",
"err",
... | // ForceLeave is used to eject an existing node from the cluster. | [
"ForceLeave",
"is",
"used",
"to",
"eject",
"an",
"existing",
"node",
"from",
"the",
"cluster",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L149-L152 |
131,943 | hashicorp/nomad | api/agent.go | Servers | func (a *Agent) Servers() ([]string, error) {
var resp []string
_, err := a.client.query("/v1/agent/servers", &resp, nil)
if err != nil {
return nil, err
}
return resp, nil
} | go | func (a *Agent) Servers() ([]string, error) {
var resp []string
_, err := a.client.query("/v1/agent/servers", &resp, nil)
if err != nil {
return nil, err
}
return resp, nil
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Servers",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"resp",
"[",
"]",
"string",
"\n",
"_",
",",
"err",
":=",
"a",
".",
"client",
".",
"query",
"(",
"\"",
"\"",
",",
"&",
"resp",
... | // Servers is used to query the list of servers on a client node. | [
"Servers",
"is",
"used",
"to",
"query",
"the",
"list",
"of",
"servers",
"on",
"a",
"client",
"node",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L155-L162 |
131,944 | hashicorp/nomad | api/agent.go | SetServers | func (a *Agent) SetServers(addrs []string) error {
// Accumulate the addresses
v := url.Values{}
for _, addr := range addrs {
v.Add("address", addr)
}
_, err := a.client.write("/v1/agent/servers?"+v.Encode(), nil, nil, nil)
return err
} | go | func (a *Agent) SetServers(addrs []string) error {
// Accumulate the addresses
v := url.Values{}
for _, addr := range addrs {
v.Add("address", addr)
}
_, err := a.client.write("/v1/agent/servers?"+v.Encode(), nil, nil, nil)
return err
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"SetServers",
"(",
"addrs",
"[",
"]",
"string",
")",
"error",
"{",
"// Accumulate the addresses",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"v",
".",
... | // SetServers is used to update the list of servers on a client node. | [
"SetServers",
"is",
"used",
"to",
"update",
"the",
"list",
"of",
"servers",
"on",
"a",
"client",
"node",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L165-L174 |
131,945 | hashicorp/nomad | api/agent.go | ListKeys | func (a *Agent) ListKeys() (*KeyringResponse, error) {
var resp KeyringResponse
_, err := a.client.query("/v1/agent/keyring/list", &resp, nil)
if err != nil {
return nil, err
}
return &resp, nil
} | go | func (a *Agent) ListKeys() (*KeyringResponse, error) {
var resp KeyringResponse
_, err := a.client.query("/v1/agent/keyring/list", &resp, nil)
if err != nil {
return nil, err
}
return &resp, nil
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"ListKeys",
"(",
")",
"(",
"*",
"KeyringResponse",
",",
"error",
")",
"{",
"var",
"resp",
"KeyringResponse",
"\n",
"_",
",",
"err",
":=",
"a",
".",
"client",
".",
"query",
"(",
"\"",
"\"",
",",
"&",
"resp",
",... | // ListKeys returns the list of installed keys | [
"ListKeys",
"returns",
"the",
"list",
"of",
"installed",
"keys"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L177-L184 |
131,946 | hashicorp/nomad | api/agent.go | InstallKey | func (a *Agent) InstallKey(key string) (*KeyringResponse, error) {
args := KeyringRequest{
Key: key,
}
var resp KeyringResponse
_, err := a.client.write("/v1/agent/keyring/install", &args, &resp, nil)
return &resp, err
} | go | func (a *Agent) InstallKey(key string) (*KeyringResponse, error) {
args := KeyringRequest{
Key: key,
}
var resp KeyringResponse
_, err := a.client.write("/v1/agent/keyring/install", &args, &resp, nil)
return &resp, err
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"InstallKey",
"(",
"key",
"string",
")",
"(",
"*",
"KeyringResponse",
",",
"error",
")",
"{",
"args",
":=",
"KeyringRequest",
"{",
"Key",
":",
"key",
",",
"}",
"\n",
"var",
"resp",
"KeyringResponse",
"\n",
"_",
",... | // InstallKey installs a key in the keyrings of all the serf members | [
"InstallKey",
"installs",
"a",
"key",
"in",
"the",
"keyrings",
"of",
"all",
"the",
"serf",
"members"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L187-L194 |
131,947 | hashicorp/nomad | api/agent.go | Health | func (a *Agent) Health() (*AgentHealthResponse, error) {
req, err := a.client.newRequest("GET", "/v1/agent/health")
if err != nil {
return nil, err
}
var health AgentHealthResponse
_, resp, err := a.client.doRequest(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
// Always try to decode th... | go | func (a *Agent) Health() (*AgentHealthResponse, error) {
req, err := a.client.newRequest("GET", "/v1/agent/health")
if err != nil {
return nil, err
}
var health AgentHealthResponse
_, resp, err := a.client.doRequest(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
// Always try to decode th... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Health",
"(",
")",
"(",
"*",
"AgentHealthResponse",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"a",
".",
"client",
".",
"newRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"n... | // Health queries the agent's health | [
"Health",
"queries",
"the",
"agent",
"s",
"health"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/agent.go#L217-L238 |
131,948 | hashicorp/nomad | client/client.go | init | func (c *Client) init() error {
// Ensure the state dir exists if we have one
if c.config.StateDir != "" {
if err := os.MkdirAll(c.config.StateDir, 0700); err != nil {
return fmt.Errorf("failed creating state dir: %s", err)
}
} else {
// Otherwise make a temp directory to use.
p, err := ioutil.TempDir(""... | go | func (c *Client) init() error {
// Ensure the state dir exists if we have one
if c.config.StateDir != "" {
if err := os.MkdirAll(c.config.StateDir, 0700); err != nil {
return fmt.Errorf("failed creating state dir: %s", err)
}
} else {
// Otherwise make a temp directory to use.
p, err := ioutil.TempDir(""... | [
"func",
"(",
"c",
"*",
"Client",
")",
"init",
"(",
")",
"error",
"{",
"// Ensure the state dir exists if we have one",
"if",
"c",
".",
"config",
".",
"StateDir",
"!=",
"\"",
"\"",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"c",
".",
"config",
... | // init is used to initialize the client and perform any setup
// needed before we begin starting its various components. | [
"init",
"is",
"used",
"to",
"initialize",
"the",
"client",
"and",
"perform",
"any",
"setup",
"needed",
"before",
"we",
"begin",
"starting",
"its",
"various",
"components",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L477-L545 |
131,949 | hashicorp/nomad | client/client.go | reloadTLSConnections | func (c *Client) reloadTLSConnections(newConfig *nconfig.TLSConfig) error {
var tlsWrap tlsutil.RegionWrapper
if newConfig != nil && newConfig.EnableRPC {
tw, err := tlsutil.NewTLSConfiguration(newConfig, true, true)
if err != nil {
return err
}
twWrap, err := tw.OutgoingTLSWrapper()
if err != nil {
... | go | func (c *Client) reloadTLSConnections(newConfig *nconfig.TLSConfig) error {
var tlsWrap tlsutil.RegionWrapper
if newConfig != nil && newConfig.EnableRPC {
tw, err := tlsutil.NewTLSConfiguration(newConfig, true, true)
if err != nil {
return err
}
twWrap, err := tw.OutgoingTLSWrapper()
if err != nil {
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"reloadTLSConnections",
"(",
"newConfig",
"*",
"nconfig",
".",
"TLSConfig",
")",
"error",
"{",
"var",
"tlsWrap",
"tlsutil",
".",
"RegionWrapper",
"\n",
"if",
"newConfig",
"!=",
"nil",
"&&",
"newConfig",
".",
"EnableRPC",... | // reloadTLSConnections allows a client to reload its TLS configuration on the
// fly | [
"reloadTLSConnections",
"allows",
"a",
"client",
"to",
"reload",
"its",
"TLS",
"configuration",
"on",
"the",
"fly"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L549-L578 |
131,950 | hashicorp/nomad | client/client.go | Reload | func (c *Client) Reload(newConfig *config.Config) error {
shouldReloadTLS, err := tlsutil.ShouldReloadRPCConnections(c.config.TLSConfig, newConfig.TLSConfig)
if err != nil {
c.logger.Error("error parsing TLS configuration", "error", err)
return err
}
if shouldReloadTLS {
return c.reloadTLSConnections(newConf... | go | func (c *Client) Reload(newConfig *config.Config) error {
shouldReloadTLS, err := tlsutil.ShouldReloadRPCConnections(c.config.TLSConfig, newConfig.TLSConfig)
if err != nil {
c.logger.Error("error parsing TLS configuration", "error", err)
return err
}
if shouldReloadTLS {
return c.reloadTLSConnections(newConf... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Reload",
"(",
"newConfig",
"*",
"config",
".",
"Config",
")",
"error",
"{",
"shouldReloadTLS",
",",
"err",
":=",
"tlsutil",
".",
"ShouldReloadRPCConnections",
"(",
"c",
".",
"config",
".",
"TLSConfig",
",",
"newConfig... | // Reload allows a client to reload its configuration on the fly | [
"Reload",
"allows",
"a",
"client",
"to",
"reload",
"its",
"configuration",
"on",
"the",
"fly"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L581-L593 |
131,951 | hashicorp/nomad | client/client.go | GetConfig | func (c *Client) GetConfig() *config.Config {
c.configLock.Lock()
defer c.configLock.Unlock()
return c.configCopy
} | go | func (c *Client) GetConfig() *config.Config {
c.configLock.Lock()
defer c.configLock.Unlock()
return c.configCopy
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetConfig",
"(",
")",
"*",
"config",
".",
"Config",
"{",
"c",
".",
"configLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"configLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"configCopy",
... | // GetConfig returns the config of the client | [
"GetConfig",
"returns",
"the",
"config",
"of",
"the",
"client"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L602-L606 |
131,952 | hashicorp/nomad | client/client.go | Shutdown | func (c *Client) Shutdown() error {
c.shutdownLock.Lock()
defer c.shutdownLock.Unlock()
if c.shutdown {
c.logger.Info("already shutdown")
return nil
}
c.logger.Info("shutting down")
// Stop renewing tokens and secrets
if c.vaultClient != nil {
c.vaultClient.Stop()
}
// Stop Garbage collector
c.garbag... | go | func (c *Client) Shutdown() error {
c.shutdownLock.Lock()
defer c.shutdownLock.Unlock()
if c.shutdown {
c.logger.Info("already shutdown")
return nil
}
c.logger.Info("shutting down")
// Stop renewing tokens and secrets
if c.vaultClient != nil {
c.vaultClient.Stop()
}
// Stop Garbage collector
c.garbag... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Shutdown",
"(",
")",
"error",
"{",
"c",
".",
"shutdownLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"shutdownLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"shutdown",
"{",
"c",
".",
"logge... | // Shutdown is used to tear down the client | [
"Shutdown",
"is",
"used",
"to",
"tear",
"down",
"the",
"client"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L641-L690 |
131,953 | hashicorp/nomad | client/client.go | SignalAllocation | func (c *Client) SignalAllocation(allocID, task, signal string) error {
ar, err := c.getAllocRunner(allocID)
if err != nil {
return err
}
return ar.Signal(task, signal)
} | go | func (c *Client) SignalAllocation(allocID, task, signal string) error {
ar, err := c.getAllocRunner(allocID)
if err != nil {
return err
}
return ar.Signal(task, signal)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SignalAllocation",
"(",
"allocID",
",",
"task",
",",
"signal",
"string",
")",
"error",
"{",
"ar",
",",
"err",
":=",
"c",
".",
"getAllocRunner",
"(",
"allocID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",... | // SignalAllocation sends a signal to the tasks within an allocation.
// If the provided task is empty, then every allocation will be signalled.
// If a task is provided, then only an exactly matching task will be signalled. | [
"SignalAllocation",
"sends",
"a",
"signal",
"to",
"the",
"tasks",
"within",
"an",
"allocation",
".",
"If",
"the",
"provided",
"task",
"is",
"empty",
"then",
"every",
"allocation",
"will",
"be",
"signalled",
".",
"If",
"a",
"task",
"is",
"provided",
"then",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L713-L720 |
131,954 | hashicorp/nomad | client/client.go | CollectAllocation | func (c *Client) CollectAllocation(allocID string) bool {
return c.garbageCollector.Collect(allocID)
} | go | func (c *Client) CollectAllocation(allocID string) bool {
return c.garbageCollector.Collect(allocID)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CollectAllocation",
"(",
"allocID",
"string",
")",
"bool",
"{",
"return",
"c",
".",
"garbageCollector",
".",
"Collect",
"(",
"allocID",
")",
"\n",
"}"
] | // CollectAllocation garbage collects a single allocation on a node. Returns
// true if alloc was found and garbage collected; otherwise false. | [
"CollectAllocation",
"garbage",
"collects",
"a",
"single",
"allocation",
"on",
"a",
"node",
".",
"Returns",
"true",
"if",
"alloc",
"was",
"found",
"and",
"garbage",
"collected",
";",
"otherwise",
"false",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L724-L726 |
131,955 | hashicorp/nomad | client/client.go | Node | func (c *Client) Node() *structs.Node {
c.configLock.RLock()
defer c.configLock.RUnlock()
return c.configCopy.Node
} | go | func (c *Client) Node() *structs.Node {
c.configLock.RLock()
defer c.configLock.RUnlock()
return c.configCopy.Node
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Node",
"(",
")",
"*",
"structs",
".",
"Node",
"{",
"c",
".",
"configLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"configLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"configCopy",
"."... | // Node returns the locally registered node | [
"Node",
"returns",
"the",
"locally",
"registered",
"node"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L751-L755 |
131,956 | hashicorp/nomad | client/client.go | ValidateMigrateToken | func (c *Client) ValidateMigrateToken(allocID, migrateToken string) bool {
if !c.config.ACLEnabled {
return true
}
return structs.CompareMigrateToken(allocID, c.secretNodeID(), migrateToken)
} | go | func (c *Client) ValidateMigrateToken(allocID, migrateToken string) bool {
if !c.config.ACLEnabled {
return true
}
return structs.CompareMigrateToken(allocID, c.secretNodeID(), migrateToken)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ValidateMigrateToken",
"(",
"allocID",
",",
"migrateToken",
"string",
")",
"bool",
"{",
"if",
"!",
"c",
".",
"config",
".",
"ACLEnabled",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"structs",
".",
"CompareM... | // ValidateMigrateToken verifies that a token is for a specific client and
// allocation, and has been created by a trusted party that has privileged
// knowledge of the client's secret identifier | [
"ValidateMigrateToken",
"verifies",
"that",
"a",
"token",
"is",
"for",
"a",
"specific",
"client",
"and",
"allocation",
"and",
"has",
"been",
"created",
"by",
"a",
"trusted",
"party",
"that",
"has",
"privileged",
"knowledge",
"of",
"the",
"client",
"s",
"secret... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L847-L853 |
131,957 | hashicorp/nomad | client/client.go | GetAllocFS | func (c *Client) GetAllocFS(allocID string) (allocdir.AllocDirFS, error) {
ar, err := c.getAllocRunner(allocID)
if err != nil {
return nil, err
}
return ar.GetAllocDir(), nil
} | go | func (c *Client) GetAllocFS(allocID string) (allocdir.AllocDirFS, error) {
ar, err := c.getAllocRunner(allocID)
if err != nil {
return nil, err
}
return ar.GetAllocDir(), nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetAllocFS",
"(",
"allocID",
"string",
")",
"(",
"allocdir",
".",
"AllocDirFS",
",",
"error",
")",
"{",
"ar",
",",
"err",
":=",
"c",
".",
"getAllocRunner",
"(",
"allocID",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // GetAllocFS returns the AllocFS interface for the alloc dir of an allocation | [
"GetAllocFS",
"returns",
"the",
"AllocFS",
"interface",
"for",
"the",
"alloc",
"dir",
"of",
"an",
"allocation"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L856-L863 |
131,958 | hashicorp/nomad | client/client.go | GetAllocState | func (c *Client) GetAllocState(allocID string) (*arstate.State, error) {
ar, err := c.getAllocRunner(allocID)
if err != nil {
return nil, err
}
return ar.AllocState(), nil
} | go | func (c *Client) GetAllocState(allocID string) (*arstate.State, error) {
ar, err := c.getAllocRunner(allocID)
if err != nil {
return nil, err
}
return ar.AllocState(), nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetAllocState",
"(",
"allocID",
"string",
")",
"(",
"*",
"arstate",
".",
"State",
",",
"error",
")",
"{",
"ar",
",",
"err",
":=",
"c",
".",
"getAllocRunner",
"(",
"allocID",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // GetAllocState returns a copy of an allocation's state on this client. It
// returns either an AllocState or an unknown allocation error. | [
"GetAllocState",
"returns",
"a",
"copy",
"of",
"an",
"allocation",
"s",
"state",
"on",
"this",
"client",
".",
"It",
"returns",
"either",
"an",
"AllocState",
"or",
"an",
"unknown",
"allocation",
"error",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L867-L874 |
131,959 | hashicorp/nomad | client/client.go | GetServers | func (c *Client) GetServers() []string {
endpoints := c.servers.GetServers()
res := make([]string, len(endpoints))
for i := range endpoints {
res[i] = endpoints[i].String()
}
sort.Strings(res)
return res
} | go | func (c *Client) GetServers() []string {
endpoints := c.servers.GetServers()
res := make([]string, len(endpoints))
for i := range endpoints {
res[i] = endpoints[i].String()
}
sort.Strings(res)
return res
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetServers",
"(",
")",
"[",
"]",
"string",
"{",
"endpoints",
":=",
"c",
".",
"servers",
".",
"GetServers",
"(",
")",
"\n",
"res",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"endpoints",
")",
")"... | // GetServers returns the list of nomad servers this client is aware of. | [
"GetServers",
"returns",
"the",
"list",
"of",
"nomad",
"servers",
"this",
"client",
"is",
"aware",
"of",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L877-L885 |
131,960 | hashicorp/nomad | client/client.go | SetServers | func (c *Client) SetServers(in []string) (int, error) {
return c.setServersImpl(in, false)
} | go | func (c *Client) SetServers(in []string) (int, error) {
return c.setServersImpl(in, false)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetServers",
"(",
"in",
"[",
"]",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"c",
".",
"setServersImpl",
"(",
"in",
",",
"false",
")",
"\n",
"}"
] | // SetServers sets a new list of nomad servers to connect to. As long as one
// server is resolvable no error is returned. | [
"SetServers",
"sets",
"a",
"new",
"list",
"of",
"nomad",
"servers",
"to",
"connect",
"to",
".",
"As",
"long",
"as",
"one",
"server",
"is",
"resolvable",
"no",
"error",
"is",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L889-L891 |
131,961 | hashicorp/nomad | client/client.go | setServersImpl | func (c *Client) setServersImpl(in []string, force bool) (int, error) {
var mu sync.Mutex
var wg sync.WaitGroup
var merr multierror.Error
endpoints := make([]*servers.Server, 0, len(in))
wg.Add(len(in))
for _, s := range in {
go func(srv string) {
defer wg.Done()
addr, err := resolveServer(srv)
if er... | go | func (c *Client) setServersImpl(in []string, force bool) (int, error) {
var mu sync.Mutex
var wg sync.WaitGroup
var merr multierror.Error
endpoints := make([]*servers.Server, 0, len(in))
wg.Add(len(in))
for _, s := range in {
go func(srv string) {
defer wg.Done()
addr, err := resolveServer(srv)
if er... | [
"func",
"(",
"c",
"*",
"Client",
")",
"setServersImpl",
"(",
"in",
"[",
"]",
"string",
",",
"force",
"bool",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"mu",
"sync",
".",
"Mutex",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"var",
"me... | // setServersImpl sets a new list of nomad servers to connect to. If force is
// set, we add the server to the internal serverlist even if the server could not
// be pinged. An error is returned if no endpoints were valid when non-forcing.
//
// Force should be used when setting the servers from the initial configurati... | [
"setServersImpl",
"sets",
"a",
"new",
"list",
"of",
"nomad",
"servers",
"to",
"connect",
"to",
".",
"If",
"force",
"is",
"set",
"we",
"add",
"the",
"server",
"to",
"the",
"internal",
"serverlist",
"even",
"if",
"the",
"server",
"could",
"not",
"be",
"pin... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L899-L950 |
131,962 | hashicorp/nomad | client/client.go | restoreState | func (c *Client) restoreState() error {
if c.config.DevMode {
return nil
}
//XXX REMOVED! make a note in backward compat / upgrading doc
// COMPAT: Remove in 0.7.0
// 0.6.0 transitioned from individual state files to a single bolt-db.
// The upgrade path is to:
// Check if old state exists
// If so, restor... | go | func (c *Client) restoreState() error {
if c.config.DevMode {
return nil
}
//XXX REMOVED! make a note in backward compat / upgrading doc
// COMPAT: Remove in 0.7.0
// 0.6.0 transitioned from individual state files to a single bolt-db.
// The upgrade path is to:
// Check if old state exists
// If so, restor... | [
"func",
"(",
"c",
"*",
"Client",
")",
"restoreState",
"(",
")",
"error",
"{",
"if",
"c",
".",
"config",
".",
"DevMode",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"//XXX REMOVED! make a note in backward compat / upgrading doc",
"// COMPAT: Remove in 0.7.0",
"// 0.6.0 ... | // restoreState is used to restore our state from the data dir
// If there are errors restoring a specific allocation it is marked
// as failed whenever possible. | [
"restoreState",
"is",
"used",
"to",
"restore",
"our",
"state",
"from",
"the",
"data",
"dir",
"If",
"there",
"are",
"errors",
"restoring",
"a",
"specific",
"allocation",
"it",
"is",
"marked",
"as",
"failed",
"whenever",
"possible",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L955-L1038 |
131,963 | hashicorp/nomad | client/client.go | saveState | func (c *Client) saveState() error {
var wg sync.WaitGroup
var l sync.Mutex
var mErr multierror.Error
runners := c.getAllocRunners()
wg.Add(len(runners))
for id, ar := range runners {
go func(id string, ar AllocRunner) {
err := c.stateDB.PutAllocation(ar.Alloc())
if err != nil {
c.logger.Error("error... | go | func (c *Client) saveState() error {
var wg sync.WaitGroup
var l sync.Mutex
var mErr multierror.Error
runners := c.getAllocRunners()
wg.Add(len(runners))
for id, ar := range runners {
go func(id string, ar AllocRunner) {
err := c.stateDB.PutAllocation(ar.Alloc())
if err != nil {
c.logger.Error("error... | [
"func",
"(",
"c",
"*",
"Client",
")",
"saveState",
"(",
")",
"error",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"var",
"l",
"sync",
".",
"Mutex",
"\n",
"var",
"mErr",
"multierror",
".",
"Error",
"\n",
"runners",
":=",
"c",
".",
"getAllocRunne... | // saveState is used to snapshot our state into the data dir. | [
"saveState",
"is",
"used",
"to",
"snapshot",
"our",
"state",
"into",
"the",
"data",
"dir",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1051-L1073 |
131,964 | hashicorp/nomad | client/client.go | getAllocRunners | func (c *Client) getAllocRunners() map[string]AllocRunner {
c.allocLock.RLock()
defer c.allocLock.RUnlock()
runners := make(map[string]AllocRunner, len(c.allocs))
for id, ar := range c.allocs {
runners[id] = ar
}
return runners
} | go | func (c *Client) getAllocRunners() map[string]AllocRunner {
c.allocLock.RLock()
defer c.allocLock.RUnlock()
runners := make(map[string]AllocRunner, len(c.allocs))
for id, ar := range c.allocs {
runners[id] = ar
}
return runners
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"getAllocRunners",
"(",
")",
"map",
"[",
"string",
"]",
"AllocRunner",
"{",
"c",
".",
"allocLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"allocLock",
".",
"RUnlock",
"(",
")",
"\n",
"runners",
":=",
... | // getAllocRunners returns a snapshot of the current set of alloc runners. | [
"getAllocRunners",
"returns",
"a",
"snapshot",
"of",
"the",
"current",
"set",
"of",
"alloc",
"runners",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1076-L1084 |
131,965 | hashicorp/nomad | client/client.go | NumAllocs | func (c *Client) NumAllocs() int {
n := 0
c.allocLock.RLock()
for _, a := range c.allocs {
if !a.IsDestroyed() {
n++
}
}
c.allocLock.RUnlock()
return n
} | go | func (c *Client) NumAllocs() int {
n := 0
c.allocLock.RLock()
for _, a := range c.allocs {
if !a.IsDestroyed() {
n++
}
}
c.allocLock.RUnlock()
return n
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"NumAllocs",
"(",
")",
"int",
"{",
"n",
":=",
"0",
"\n",
"c",
".",
"allocLock",
".",
"RLock",
"(",
")",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"c",
".",
"allocs",
"{",
"if",
"!",
"a",
".",
"IsDestroye... | // NumAllocs returns the number of un-GC'd allocs this client has. Used to
// fulfill the AllocCounter interface for the GC. | [
"NumAllocs",
"returns",
"the",
"number",
"of",
"un",
"-",
"GC",
"d",
"allocs",
"this",
"client",
"has",
".",
"Used",
"to",
"fulfill",
"the",
"AllocCounter",
"interface",
"for",
"the",
"GC",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1088-L1098 |
131,966 | hashicorp/nomad | client/client.go | nodeID | func (c *Client) nodeID() (id, secret string, err error) {
var hostID string
hostInfo, err := host.Info()
if !c.config.NoHostUUID && err == nil {
if hashed, ok := helper.HashUUID(hostInfo.HostID); ok {
hostID = hashed
}
}
if hostID == "" {
// Generate a random hostID if no constant ID is available on
/... | go | func (c *Client) nodeID() (id, secret string, err error) {
var hostID string
hostInfo, err := host.Info()
if !c.config.NoHostUUID && err == nil {
if hashed, ok := helper.HashUUID(hostInfo.HostID); ok {
hostID = hashed
}
}
if hostID == "" {
// Generate a random hostID if no constant ID is available on
/... | [
"func",
"(",
"c",
"*",
"Client",
")",
"nodeID",
"(",
")",
"(",
"id",
",",
"secret",
"string",
",",
"err",
"error",
")",
"{",
"var",
"hostID",
"string",
"\n",
"hostInfo",
",",
"err",
":=",
"host",
".",
"Info",
"(",
")",
"\n",
"if",
"!",
"c",
"."... | // nodeID restores, or generates if necessary, a unique node ID and SecretID.
// The node ID is, if available, a persistent unique ID. The secret ID is a
// high-entropy random UUID. | [
"nodeID",
"restores",
"or",
"generates",
"if",
"necessary",
"a",
"unique",
"node",
"ID",
"and",
"SecretID",
".",
"The",
"node",
"ID",
"is",
"if",
"available",
"a",
"persistent",
"unique",
"ID",
".",
"The",
"secret",
"ID",
"is",
"a",
"high",
"-",
"entropy... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1103-L1162 |
131,967 | hashicorp/nomad | client/client.go | setupNode | func (c *Client) setupNode() error {
node := c.config.Node
if node == nil {
node = &structs.Node{}
c.config.Node = node
}
// Generate an ID and secret for the node
id, secretID, err := c.nodeID()
if err != nil {
return fmt.Errorf("node ID setup failed: %v", err)
}
node.ID = id
node.SecretID = secretID
... | go | func (c *Client) setupNode() error {
node := c.config.Node
if node == nil {
node = &structs.Node{}
c.config.Node = node
}
// Generate an ID and secret for the node
id, secretID, err := c.nodeID()
if err != nil {
return fmt.Errorf("node ID setup failed: %v", err)
}
node.ID = id
node.SecretID = secretID
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"setupNode",
"(",
")",
"error",
"{",
"node",
":=",
"c",
".",
"config",
".",
"Node",
"\n",
"if",
"node",
"==",
"nil",
"{",
"node",
"=",
"&",
"structs",
".",
"Node",
"{",
"}",
"\n",
"c",
".",
"config",
".",
... | // setupNode is used to setup the initial node | [
"setupNode",
"is",
"used",
"to",
"setup",
"the",
"initial",
"node"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1165-L1214 |
131,968 | hashicorp/nomad | client/client.go | updateNetworks | func updateNetworks(ns structs.Networks, up structs.Networks, c *config.Config) structs.Networks {
if c.NetworkInterface == "" {
ns = up
} else {
// if a network is configured, use only that network
// use the fingerprinted data
for _, n := range up {
if c.NetworkInterface == n.Device {
ns = []*structs... | go | func updateNetworks(ns structs.Networks, up structs.Networks, c *config.Config) structs.Networks {
if c.NetworkInterface == "" {
ns = up
} else {
// if a network is configured, use only that network
// use the fingerprinted data
for _, n := range up {
if c.NetworkInterface == n.Device {
ns = []*structs... | [
"func",
"updateNetworks",
"(",
"ns",
"structs",
".",
"Networks",
",",
"up",
"structs",
".",
"Networks",
",",
"c",
"*",
"config",
".",
"Config",
")",
"structs",
".",
"Networks",
"{",
"if",
"c",
".",
"NetworkInterface",
"==",
"\"",
"\"",
"{",
"ns",
"=",
... | // updateNetworks preserves manually configured network options, but
// applies fingerprint updates | [
"updateNetworks",
"preserves",
"manually",
"configured",
"network",
"options",
"but",
"applies",
"fingerprint",
"updates"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1290-L1309 |
131,969 | hashicorp/nomad | client/client.go | retryIntv | func (c *Client) retryIntv(base time.Duration) time.Duration {
if c.config.DevMode {
return devModeRetryIntv
}
return base + lib.RandomStagger(base)
} | go | func (c *Client) retryIntv(base time.Duration) time.Duration {
if c.config.DevMode {
return devModeRetryIntv
}
return base + lib.RandomStagger(base)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"retryIntv",
"(",
"base",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"if",
"c",
".",
"config",
".",
"DevMode",
"{",
"return",
"devModeRetryIntv",
"\n",
"}",
"\n",
"return",
"base",
"+",
"lib",
".... | // retryIntv calculates a retry interval value given the base | [
"retryIntv",
"calculates",
"a",
"retry",
"interval",
"value",
"given",
"the",
"base"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1312-L1317 |
131,970 | hashicorp/nomad | client/client.go | registerAndHeartbeat | func (c *Client) registerAndHeartbeat() {
// Register the node
c.retryRegisterNode()
// Start watching changes for node changes
go c.watchNodeUpdates()
// Start watching for emitting node events
go c.watchNodeEvents()
// Setup the heartbeat timer, for the initial registration
// we want to do this quickly. W... | go | func (c *Client) registerAndHeartbeat() {
// Register the node
c.retryRegisterNode()
// Start watching changes for node changes
go c.watchNodeUpdates()
// Start watching for emitting node events
go c.watchNodeEvents()
// Setup the heartbeat timer, for the initial registration
// we want to do this quickly. W... | [
"func",
"(",
"c",
"*",
"Client",
")",
"registerAndHeartbeat",
"(",
")",
"{",
"// Register the node",
"c",
".",
"retryRegisterNode",
"(",
")",
"\n\n",
"// Start watching changes for node changes",
"go",
"c",
".",
"watchNodeUpdates",
"(",
")",
"\n\n",
"// Start watchi... | // registerAndHeartbeat is a long lived goroutine used to register the client
// and then start heartbeating to the server. | [
"registerAndHeartbeat",
"is",
"a",
"long",
"lived",
"goroutine",
"used",
"to",
"register",
"the",
"client",
"and",
"then",
"start",
"heartbeating",
"to",
"the",
"server",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1321-L1371 |
131,971 | hashicorp/nomad | client/client.go | getHeartbeatRetryIntv | func (c *Client) getHeartbeatRetryIntv(err error) time.Duration {
if c.config.DevMode {
return devModeRetryIntv
}
// Collect the useful heartbeat info
c.heartbeatLock.Lock()
haveHeartbeated := c.haveHeartbeated
last := c.lastHeartbeat
ttl := c.heartbeatTTL
c.heartbeatLock.Unlock()
// If we haven't even suc... | go | func (c *Client) getHeartbeatRetryIntv(err error) time.Duration {
if c.config.DevMode {
return devModeRetryIntv
}
// Collect the useful heartbeat info
c.heartbeatLock.Lock()
haveHeartbeated := c.haveHeartbeated
last := c.lastHeartbeat
ttl := c.heartbeatTTL
c.heartbeatLock.Unlock()
// If we haven't even suc... | [
"func",
"(",
"c",
"*",
"Client",
")",
"getHeartbeatRetryIntv",
"(",
"err",
"error",
")",
"time",
".",
"Duration",
"{",
"if",
"c",
".",
"config",
".",
"DevMode",
"{",
"return",
"devModeRetryIntv",
"\n",
"}",
"\n\n",
"// Collect the useful heartbeat info",
"c",
... | // getHeartbeatRetryIntv is used to retrieve the time to wait before attempting
// another heartbeat. | [
"getHeartbeatRetryIntv",
"is",
"used",
"to",
"retrieve",
"the",
"time",
"to",
"wait",
"before",
"attempting",
"another",
"heartbeat",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1375-L1421 |
131,972 | hashicorp/nomad | client/client.go | periodicSnapshot | func (c *Client) periodicSnapshot() {
// Create a snapshot timer
snapshot := time.After(stateSnapshotIntv)
for {
select {
case <-snapshot:
snapshot = time.After(stateSnapshotIntv)
if err := c.saveState(); err != nil {
c.logger.Error("error saving state", "error", err)
}
case <-c.shutdownCh:
r... | go | func (c *Client) periodicSnapshot() {
// Create a snapshot timer
snapshot := time.After(stateSnapshotIntv)
for {
select {
case <-snapshot:
snapshot = time.After(stateSnapshotIntv)
if err := c.saveState(); err != nil {
c.logger.Error("error saving state", "error", err)
}
case <-c.shutdownCh:
r... | [
"func",
"(",
"c",
"*",
"Client",
")",
"periodicSnapshot",
"(",
")",
"{",
"// Create a snapshot timer",
"snapshot",
":=",
"time",
".",
"After",
"(",
"stateSnapshotIntv",
")",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"snapshot",
":",
"snapshot",
"=",
... | // periodicSnapshot is a long lived goroutine used to periodically snapshot the
// state of the client | [
"periodicSnapshot",
"is",
"a",
"long",
"lived",
"goroutine",
"used",
"to",
"periodically",
"snapshot",
"the",
"state",
"of",
"the",
"client"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1425-L1441 |
131,973 | hashicorp/nomad | client/client.go | watchNodeEvents | func (c *Client) watchNodeEvents() {
// batchEvents stores events that have yet to be published
var batchEvents []*structs.NodeEvent
timer := stoppedTimer()
defer timer.Stop()
for {
select {
case event := <-c.triggerEmitNodeEvent:
if l := len(batchEvents); l <= structs.MaxRetainedNodeEvents {
batchEve... | go | func (c *Client) watchNodeEvents() {
// batchEvents stores events that have yet to be published
var batchEvents []*structs.NodeEvent
timer := stoppedTimer()
defer timer.Stop()
for {
select {
case event := <-c.triggerEmitNodeEvent:
if l := len(batchEvents); l <= structs.MaxRetainedNodeEvents {
batchEve... | [
"func",
"(",
"c",
"*",
"Client",
")",
"watchNodeEvents",
"(",
")",
"{",
"// batchEvents stores events that have yet to be published",
"var",
"batchEvents",
"[",
"]",
"*",
"structs",
".",
"NodeEvent",
"\n\n",
"timer",
":=",
"stoppedTimer",
"(",
")",
"\n",
"defer",
... | // watchNodeEvents is a handler which receives node events and on a interval
// and submits them in batch format to the server | [
"watchNodeEvents",
"is",
"a",
"handler",
"which",
"receives",
"node",
"events",
"and",
"on",
"a",
"interval",
"and",
"submits",
"them",
"in",
"batch",
"format",
"to",
"the",
"server"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1491-L1521 |
131,974 | hashicorp/nomad | client/client.go | retryRegisterNode | func (c *Client) retryRegisterNode() {
for {
err := c.registerNode()
if err == nil {
// Registered!
return
}
if err == noServersErr {
c.logger.Debug("registration waiting on servers")
c.triggerDiscovery()
} else {
c.logger.Error("error registering", "error", err)
}
select {
case <-c.rpc... | go | func (c *Client) retryRegisterNode() {
for {
err := c.registerNode()
if err == nil {
// Registered!
return
}
if err == noServersErr {
c.logger.Debug("registration waiting on servers")
c.triggerDiscovery()
} else {
c.logger.Error("error registering", "error", err)
}
select {
case <-c.rpc... | [
"func",
"(",
"c",
"*",
"Client",
")",
"retryRegisterNode",
"(",
")",
"{",
"for",
"{",
"err",
":=",
"c",
".",
"registerNode",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// Registered!",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"noServersEr... | // retryRegisterNode is used to register the node or update the registration and
// retry in case of failure. | [
"retryRegisterNode",
"is",
"used",
"to",
"register",
"the",
"node",
"or",
"update",
"the",
"registration",
"and",
"retry",
"in",
"case",
"of",
"failure",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1535-L1556 |
131,975 | hashicorp/nomad | client/client.go | registerNode | func (c *Client) registerNode() error {
node := c.Node()
req := structs.NodeRegisterRequest{
Node: node,
WriteRequest: structs.WriteRequest{Region: c.Region()},
}
var resp structs.NodeUpdateResponse
if err := c.RPC("Node.Register", &req, &resp); err != nil {
return err
}
// Update the node status ... | go | func (c *Client) registerNode() error {
node := c.Node()
req := structs.NodeRegisterRequest{
Node: node,
WriteRequest: structs.WriteRequest{Region: c.Region()},
}
var resp structs.NodeUpdateResponse
if err := c.RPC("Node.Register", &req, &resp); err != nil {
return err
}
// Update the node status ... | [
"func",
"(",
"c",
"*",
"Client",
")",
"registerNode",
"(",
")",
"error",
"{",
"node",
":=",
"c",
".",
"Node",
"(",
")",
"\n",
"req",
":=",
"structs",
".",
"NodeRegisterRequest",
"{",
"Node",
":",
"node",
",",
"WriteRequest",
":",
"structs",
".",
"Wri... | // registerNode is used to register the node or update the registration | [
"registerNode",
"is",
"used",
"to",
"register",
"the",
"node",
"or",
"update",
"the",
"registration"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1559-L1586 |
131,976 | hashicorp/nomad | client/client.go | updateNodeStatus | func (c *Client) updateNodeStatus() error {
start := time.Now()
req := structs.NodeUpdateStatusRequest{
NodeID: c.NodeID(),
Status: structs.NodeStatusReady,
WriteRequest: structs.WriteRequest{Region: c.Region()},
}
var resp structs.NodeUpdateResponse
if err := c.RPC("Node.UpdateStatus", &req, &re... | go | func (c *Client) updateNodeStatus() error {
start := time.Now()
req := structs.NodeUpdateStatusRequest{
NodeID: c.NodeID(),
Status: structs.NodeStatusReady,
WriteRequest: structs.WriteRequest{Region: c.Region()},
}
var resp structs.NodeUpdateResponse
if err := c.RPC("Node.UpdateStatus", &req, &re... | [
"func",
"(",
"c",
"*",
"Client",
")",
"updateNodeStatus",
"(",
")",
"error",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"req",
":=",
"structs",
".",
"NodeUpdateStatusRequest",
"{",
"NodeID",
":",
"c",
".",
"NodeID",
"(",
")",
",",
"Statu... | // updateNodeStatus is used to heartbeat and update the status of the node | [
"updateNodeStatus",
"is",
"used",
"to",
"heartbeat",
"and",
"update",
"the",
"status",
"of",
"the",
"node"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1589-L1658 |
131,977 | hashicorp/nomad | client/client.go | AllocStateUpdated | func (c *Client) AllocStateUpdated(alloc *structs.Allocation) {
if alloc.Terminated() {
// Terminated, mark for GC if we're still tracking this alloc
// runner. If it's not being tracked that means the server has
// already GC'd it (see removeAlloc).
ar, err := c.getAllocRunner(alloc.ID)
if err == nil {
... | go | func (c *Client) AllocStateUpdated(alloc *structs.Allocation) {
if alloc.Terminated() {
// Terminated, mark for GC if we're still tracking this alloc
// runner. If it's not being tracked that means the server has
// already GC'd it (see removeAlloc).
ar, err := c.getAllocRunner(alloc.ID)
if err == nil {
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"AllocStateUpdated",
"(",
"alloc",
"*",
"structs",
".",
"Allocation",
")",
"{",
"if",
"alloc",
".",
"Terminated",
"(",
")",
"{",
"// Terminated, mark for GC if we're still tracking this alloc",
"// runner. If it's not being tracked ... | // AllocStateUpdated asynchronously updates the server with the current state
// of an allocations and its tasks. | [
"AllocStateUpdated",
"asynchronously",
"updates",
"the",
"server",
"with",
"the",
"current",
"state",
"of",
"an",
"allocations",
"and",
"its",
"tasks",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1662-L1692 |
131,978 | hashicorp/nomad | client/client.go | allocSync | func (c *Client) allocSync() {
staggered := false
syncTicker := time.NewTicker(allocSyncIntv)
updates := make(map[string]*structs.Allocation)
for {
select {
case <-c.shutdownCh:
syncTicker.Stop()
return
case alloc := <-c.allocUpdates:
// Batch the allocation updates until the timer triggers.
updat... | go | func (c *Client) allocSync() {
staggered := false
syncTicker := time.NewTicker(allocSyncIntv)
updates := make(map[string]*structs.Allocation)
for {
select {
case <-c.shutdownCh:
syncTicker.Stop()
return
case alloc := <-c.allocUpdates:
// Batch the allocation updates until the timer triggers.
updat... | [
"func",
"(",
"c",
"*",
"Client",
")",
"allocSync",
"(",
")",
"{",
"staggered",
":=",
"false",
"\n",
"syncTicker",
":=",
"time",
".",
"NewTicker",
"(",
"allocSyncIntv",
")",
"\n",
"updates",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"structs",
... | // allocSync is a long lived function that batches allocation updates to the
// server. | [
"allocSync",
"is",
"a",
"long",
"lived",
"function",
"that",
"batches",
"allocation",
"updates",
"to",
"the",
"server",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1696-L1741 |
131,979 | hashicorp/nomad | client/client.go | updateNodeLocked | func (c *Client) updateNodeLocked() {
// Update the config copy.
node := c.config.Node.Copy()
c.configCopy.Node = node
select {
case c.triggerNodeUpdate <- struct{}{}:
// Node update goroutine was released to execute
default:
// Node update goroutine was already running
}
} | go | func (c *Client) updateNodeLocked() {
// Update the config copy.
node := c.config.Node.Copy()
c.configCopy.Node = node
select {
case c.triggerNodeUpdate <- struct{}{}:
// Node update goroutine was released to execute
default:
// Node update goroutine was already running
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"updateNodeLocked",
"(",
")",
"{",
"// Update the config copy.",
"node",
":=",
"c",
".",
"config",
".",
"Node",
".",
"Copy",
"(",
")",
"\n",
"c",
".",
"configCopy",
".",
"Node",
"=",
"node",
"\n\n",
"select",
"{",
... | // updateNode updates the Node copy and triggers the client to send the updated
// Node to the server. This should be done while the caller holds the
// configLock lock. | [
"updateNode",
"updates",
"the",
"Node",
"copy",
"and",
"triggers",
"the",
"client",
"to",
"send",
"the",
"updated",
"Node",
"to",
"the",
"server",
".",
"This",
"should",
"be",
"done",
"while",
"the",
"caller",
"holds",
"the",
"configLock",
"lock",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1934-L1945 |
131,980 | hashicorp/nomad | client/client.go | watchNodeUpdates | func (c *Client) watchNodeUpdates() {
var hasChanged bool
timer := stoppedTimer()
defer timer.Stop()
for {
select {
case <-timer.C:
c.logger.Debug("state changed, updating node and re-registering")
c.retryRegisterNode()
hasChanged = false
case <-c.triggerNodeUpdate:
if hasChanged {
continue
... | go | func (c *Client) watchNodeUpdates() {
var hasChanged bool
timer := stoppedTimer()
defer timer.Stop()
for {
select {
case <-timer.C:
c.logger.Debug("state changed, updating node and re-registering")
c.retryRegisterNode()
hasChanged = false
case <-c.triggerNodeUpdate:
if hasChanged {
continue
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"watchNodeUpdates",
"(",
")",
"{",
"var",
"hasChanged",
"bool",
"\n\n",
"timer",
":=",
"stoppedTimer",
"(",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"ti... | // watchNodeUpdates blocks until it is edge triggered. Once triggered,
// it will update the client node copy and re-register the node. | [
"watchNodeUpdates",
"blocks",
"until",
"it",
"is",
"edge",
"triggered",
".",
"Once",
"triggered",
"it",
"will",
"update",
"the",
"client",
"node",
"copy",
"and",
"re",
"-",
"register",
"the",
"node",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1949-L1971 |
131,981 | hashicorp/nomad | client/client.go | runAllocs | func (c *Client) runAllocs(update *allocUpdates) {
// Get the existing allocs
c.allocLock.RLock()
existing := make(map[string]uint64, len(c.allocs))
for id, ar := range c.allocs {
existing[id] = ar.Alloc().AllocModifyIndex
}
c.allocLock.RUnlock()
// Diff the existing and updated allocations
diff := diffAlloc... | go | func (c *Client) runAllocs(update *allocUpdates) {
// Get the existing allocs
c.allocLock.RLock()
existing := make(map[string]uint64, len(c.allocs))
for id, ar := range c.allocs {
existing[id] = ar.Alloc().AllocModifyIndex
}
c.allocLock.RUnlock()
// Diff the existing and updated allocations
diff := diffAlloc... | [
"func",
"(",
"c",
"*",
"Client",
")",
"runAllocs",
"(",
"update",
"*",
"allocUpdates",
")",
"{",
"// Get the existing allocs",
"c",
".",
"allocLock",
".",
"RLock",
"(",
")",
"\n",
"existing",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"uint64",
",",
... | // runAllocs is invoked when we get an updated set of allocations | [
"runAllocs",
"is",
"invoked",
"when",
"we",
"get",
"an",
"updated",
"set",
"of",
"allocations"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L1974-L2026 |
131,982 | hashicorp/nomad | client/client.go | makeFailedAlloc | func makeFailedAlloc(add *structs.Allocation, err error) *structs.Allocation {
stripped := new(structs.Allocation)
stripped.ID = add.ID
stripped.NodeID = add.NodeID
stripped.ClientStatus = structs.AllocClientStatusFailed
stripped.ClientDescription = fmt.Sprintf("Unable to add allocation due to error: %v", err)
/... | go | func makeFailedAlloc(add *structs.Allocation, err error) *structs.Allocation {
stripped := new(structs.Allocation)
stripped.ID = add.ID
stripped.NodeID = add.NodeID
stripped.ClientStatus = structs.AllocClientStatusFailed
stripped.ClientDescription = fmt.Sprintf("Unable to add allocation due to error: %v", err)
/... | [
"func",
"makeFailedAlloc",
"(",
"add",
"*",
"structs",
".",
"Allocation",
",",
"err",
"error",
")",
"*",
"structs",
".",
"Allocation",
"{",
"stripped",
":=",
"new",
"(",
"structs",
".",
"Allocation",
")",
"\n",
"stripped",
".",
"ID",
"=",
"add",
".",
"... | // makeFailedAlloc creates a stripped down version of the allocation passed in
// with its status set to failed and other fields needed for the server to be
// able to examine deployment and task states | [
"makeFailedAlloc",
"creates",
"a",
"stripped",
"down",
"version",
"of",
"the",
"allocation",
"passed",
"in",
"with",
"its",
"status",
"set",
"to",
"failed",
"and",
"other",
"fields",
"needed",
"for",
"the",
"server",
"to",
"be",
"able",
"to",
"examine",
"dep... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2031-L2071 |
131,983 | hashicorp/nomad | client/client.go | removeAlloc | func (c *Client) removeAlloc(allocID string) {
c.allocLock.Lock()
defer c.allocLock.Unlock()
ar, ok := c.allocs[allocID]
if !ok {
if _, ok := c.invalidAllocs[allocID]; ok {
// Removing from invalid allocs map if present
delete(c.invalidAllocs, allocID)
} else {
// Alloc is unknown, log a warning.
c... | go | func (c *Client) removeAlloc(allocID string) {
c.allocLock.Lock()
defer c.allocLock.Unlock()
ar, ok := c.allocs[allocID]
if !ok {
if _, ok := c.invalidAllocs[allocID]; ok {
// Removing from invalid allocs map if present
delete(c.invalidAllocs, allocID)
} else {
// Alloc is unknown, log a warning.
c... | [
"func",
"(",
"c",
"*",
"Client",
")",
"removeAlloc",
"(",
"allocID",
"string",
")",
"{",
"c",
".",
"allocLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"allocLock",
".",
"Unlock",
"(",
")",
"\n\n",
"ar",
",",
"ok",
":=",
"c",
".",
"allocs... | // removeAlloc is invoked when we should remove an allocation because it has
// been removed by the server. | [
"removeAlloc",
"is",
"invoked",
"when",
"we",
"should",
"remove",
"an",
"allocation",
"because",
"it",
"has",
"been",
"removed",
"by",
"the",
"server",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2075-L2100 |
131,984 | hashicorp/nomad | client/client.go | updateAlloc | func (c *Client) updateAlloc(update *structs.Allocation) {
ar, err := c.getAllocRunner(update.ID)
if err != nil {
c.logger.Warn("cannot update nonexistent alloc", "alloc_id", update.ID)
return
}
// Update local copy of alloc
if err := c.stateDB.PutAllocation(update); err != nil {
c.logger.Error("error persi... | go | func (c *Client) updateAlloc(update *structs.Allocation) {
ar, err := c.getAllocRunner(update.ID)
if err != nil {
c.logger.Warn("cannot update nonexistent alloc", "alloc_id", update.ID)
return
}
// Update local copy of alloc
if err := c.stateDB.PutAllocation(update); err != nil {
c.logger.Error("error persi... | [
"func",
"(",
"c",
"*",
"Client",
")",
"updateAlloc",
"(",
"update",
"*",
"structs",
".",
"Allocation",
")",
"{",
"ar",
",",
"err",
":=",
"c",
".",
"getAllocRunner",
"(",
"update",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"lo... | // updateAlloc is invoked when we should update an allocation | [
"updateAlloc",
"is",
"invoked",
"when",
"we",
"should",
"update",
"an",
"allocation"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2103-L2117 |
131,985 | hashicorp/nomad | client/client.go | addAlloc | func (c *Client) addAlloc(alloc *structs.Allocation, migrateToken string) error {
c.allocLock.Lock()
defer c.allocLock.Unlock()
// Check if we already have an alloc runner
if _, ok := c.allocs[alloc.ID]; ok {
c.logger.Debug("dropping duplicate add allocation request", "alloc_id", alloc.ID)
return nil
}
// I... | go | func (c *Client) addAlloc(alloc *structs.Allocation, migrateToken string) error {
c.allocLock.Lock()
defer c.allocLock.Unlock()
// Check if we already have an alloc runner
if _, ok := c.allocs[alloc.ID]; ok {
c.logger.Debug("dropping duplicate add allocation request", "alloc_id", alloc.ID)
return nil
}
// I... | [
"func",
"(",
"c",
"*",
"Client",
")",
"addAlloc",
"(",
"alloc",
"*",
"structs",
".",
"Allocation",
",",
"migrateToken",
"string",
")",
"error",
"{",
"c",
".",
"allocLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"allocLock",
".",
"Unlock",
"(... | // addAlloc is invoked when we should add an allocation | [
"addAlloc",
"is",
"invoked",
"when",
"we",
"should",
"add",
"an",
"allocation"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2120-L2188 |
131,986 | hashicorp/nomad | client/client.go | setupVaultClient | func (c *Client) setupVaultClient() error {
var err error
c.vaultClient, err = vaultclient.NewVaultClient(c.config.VaultConfig, c.logger, c.deriveToken)
if err != nil {
return err
}
if c.vaultClient == nil {
c.logger.Error("failed to create vault client")
return fmt.Errorf("failed to create vault client")
... | go | func (c *Client) setupVaultClient() error {
var err error
c.vaultClient, err = vaultclient.NewVaultClient(c.config.VaultConfig, c.logger, c.deriveToken)
if err != nil {
return err
}
if c.vaultClient == nil {
c.logger.Error("failed to create vault client")
return fmt.Errorf("failed to create vault client")
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"setupVaultClient",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"c",
".",
"vaultClient",
",",
"err",
"=",
"vaultclient",
".",
"NewVaultClient",
"(",
"c",
".",
"config",
".",
"VaultConfig",
",",
"c",
".",
... | // setupVaultClient creates an object to periodically renew tokens and secrets
// with vault. | [
"setupVaultClient",
"creates",
"an",
"object",
"to",
"periodically",
"renew",
"tokens",
"and",
"secrets",
"with",
"vault",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2192-L2208 |
131,987 | hashicorp/nomad | client/client.go | emitStats | func (c *Client) emitStats() {
// Determining NodeClass to be emitted
var emittedNodeClass string
if emittedNodeClass = c.Node().NodeClass; emittedNodeClass == "" {
emittedNodeClass = "none"
}
// Assign labels directly before emitting stats so the information expected
// is ready
c.baseLabels = []metrics.Labe... | go | func (c *Client) emitStats() {
// Determining NodeClass to be emitted
var emittedNodeClass string
if emittedNodeClass = c.Node().NodeClass; emittedNodeClass == "" {
emittedNodeClass = "none"
}
// Assign labels directly before emitting stats so the information expected
// is ready
c.baseLabels = []metrics.Labe... | [
"func",
"(",
"c",
"*",
"Client",
")",
"emitStats",
"(",
")",
"{",
"// Determining NodeClass to be emitted",
"var",
"emittedNodeClass",
"string",
"\n",
"if",
"emittedNodeClass",
"=",
"c",
".",
"Node",
"(",
")",
".",
"NodeClass",
";",
"emittedNodeClass",
"==",
"... | // emitStats collects host resource usage stats periodically | [
"emitStats",
"collects",
"host",
"resource",
"usage",
"stats",
"periodically"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2450-L2489 |
131,988 | hashicorp/nomad | client/client.go | setGaugeForMemoryStats | func (c *Client) setGaugeForMemoryStats(nodeID string, hStats *stats.HostStats) {
if !c.config.DisableTaggedMetrics {
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "total"}, float32(hStats.Memory.Total), c.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "available"}, f... | go | func (c *Client) setGaugeForMemoryStats(nodeID string, hStats *stats.HostStats) {
if !c.config.DisableTaggedMetrics {
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "total"}, float32(hStats.Memory.Total), c.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "host", "memory", "available"}, f... | [
"func",
"(",
"c",
"*",
"Client",
")",
"setGaugeForMemoryStats",
"(",
"nodeID",
"string",
",",
"hStats",
"*",
"stats",
".",
"HostStats",
")",
"{",
"if",
"!",
"c",
".",
"config",
".",
"DisableTaggedMetrics",
"{",
"metrics",
".",
"SetGaugeWithLabels",
"(",
"[... | // setGaugeForMemoryStats proxies metrics for memory specific statistics | [
"setGaugeForMemoryStats",
"proxies",
"metrics",
"for",
"memory",
"specific",
"statistics"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2492-L2506 |
131,989 | hashicorp/nomad | client/client.go | setGaugeForCPUStats | func (c *Client) setGaugeForCPUStats(nodeID string, hStats *stats.HostStats) {
for _, cpu := range hStats.CPU {
if !c.config.DisableTaggedMetrics {
labels := append(c.baseLabels, metrics.Label{
Name: "cpu",
Value: cpu.CPU,
})
metrics.SetGaugeWithLabels([]string{"client", "host", "cpu", "total"}, f... | go | func (c *Client) setGaugeForCPUStats(nodeID string, hStats *stats.HostStats) {
for _, cpu := range hStats.CPU {
if !c.config.DisableTaggedMetrics {
labels := append(c.baseLabels, metrics.Label{
Name: "cpu",
Value: cpu.CPU,
})
metrics.SetGaugeWithLabels([]string{"client", "host", "cpu", "total"}, f... | [
"func",
"(",
"c",
"*",
"Client",
")",
"setGaugeForCPUStats",
"(",
"nodeID",
"string",
",",
"hStats",
"*",
"stats",
".",
"HostStats",
")",
"{",
"for",
"_",
",",
"cpu",
":=",
"range",
"hStats",
".",
"CPU",
"{",
"if",
"!",
"c",
".",
"config",
".",
"Di... | // setGaugeForCPUStats proxies metrics for CPU specific statistics | [
"setGaugeForCPUStats",
"proxies",
"metrics",
"for",
"CPU",
"specific",
"statistics"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2509-L2530 |
131,990 | hashicorp/nomad | client/client.go | setGaugeForDiskStats | func (c *Client) setGaugeForDiskStats(nodeID string, hStats *stats.HostStats) {
for _, disk := range hStats.DiskStats {
if !c.config.DisableTaggedMetrics {
labels := append(c.baseLabels, metrics.Label{
Name: "disk",
Value: disk.Device,
})
metrics.SetGaugeWithLabels([]string{"client", "host", "disk... | go | func (c *Client) setGaugeForDiskStats(nodeID string, hStats *stats.HostStats) {
for _, disk := range hStats.DiskStats {
if !c.config.DisableTaggedMetrics {
labels := append(c.baseLabels, metrics.Label{
Name: "disk",
Value: disk.Device,
})
metrics.SetGaugeWithLabels([]string{"client", "host", "disk... | [
"func",
"(",
"c",
"*",
"Client",
")",
"setGaugeForDiskStats",
"(",
"nodeID",
"string",
",",
"hStats",
"*",
"stats",
".",
"HostStats",
")",
"{",
"for",
"_",
",",
"disk",
":=",
"range",
"hStats",
".",
"DiskStats",
"{",
"if",
"!",
"c",
".",
"config",
".... | // setGaugeForDiskStats proxies metrics for disk specific statistics | [
"setGaugeForDiskStats",
"proxies",
"metrics",
"for",
"disk",
"specific",
"statistics"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2533-L2556 |
131,991 | hashicorp/nomad | client/client.go | emitHostStats | func (c *Client) emitHostStats() {
nodeID := c.NodeID()
hStats := c.hostStatsCollector.Stats()
c.setGaugeForMemoryStats(nodeID, hStats)
c.setGaugeForUptime(hStats)
c.setGaugeForCPUStats(nodeID, hStats)
c.setGaugeForDiskStats(nodeID, hStats)
} | go | func (c *Client) emitHostStats() {
nodeID := c.NodeID()
hStats := c.hostStatsCollector.Stats()
c.setGaugeForMemoryStats(nodeID, hStats)
c.setGaugeForUptime(hStats)
c.setGaugeForCPUStats(nodeID, hStats)
c.setGaugeForDiskStats(nodeID, hStats)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"emitHostStats",
"(",
")",
"{",
"nodeID",
":=",
"c",
".",
"NodeID",
"(",
")",
"\n",
"hStats",
":=",
"c",
".",
"hostStatsCollector",
".",
"Stats",
"(",
")",
"\n\n",
"c",
".",
"setGaugeForMemoryStats",
"(",
"nodeID",... | // emitHostStats pushes host resource usage stats to remote metrics collection sinks | [
"emitHostStats",
"pushes",
"host",
"resource",
"usage",
"stats",
"to",
"remote",
"metrics",
"collection",
"sinks"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2646-L2654 |
131,992 | hashicorp/nomad | client/client.go | emitClientMetrics | func (c *Client) emitClientMetrics() {
nodeID := c.NodeID()
c.setGaugeForAllocationStats(nodeID)
// Emit allocation metrics
blocked, migrating, pending, running, terminal := 0, 0, 0, 0, 0
for _, ar := range c.getAllocRunners() {
switch ar.AllocState().ClientStatus {
case structs.AllocClientStatusPending:
... | go | func (c *Client) emitClientMetrics() {
nodeID := c.NodeID()
c.setGaugeForAllocationStats(nodeID)
// Emit allocation metrics
blocked, migrating, pending, running, terminal := 0, 0, 0, 0, 0
for _, ar := range c.getAllocRunners() {
switch ar.AllocState().ClientStatus {
case structs.AllocClientStatusPending:
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"emitClientMetrics",
"(",
")",
"{",
"nodeID",
":=",
"c",
".",
"NodeID",
"(",
")",
"\n\n",
"c",
".",
"setGaugeForAllocationStats",
"(",
"nodeID",
")",
"\n\n",
"// Emit allocation metrics",
"blocked",
",",
"migrating",
","... | // emitClientMetrics emits lower volume client metrics | [
"emitClientMetrics",
"emits",
"lower",
"volume",
"client",
"metrics"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2657-L2697 |
131,993 | hashicorp/nomad | client/client.go | allAllocs | func (c *Client) allAllocs() map[string]*structs.Allocation {
ars := c.getAllocRunners()
allocs := make(map[string]*structs.Allocation, len(ars))
for _, ar := range ars {
a := ar.Alloc()
allocs[a.ID] = a
}
return allocs
} | go | func (c *Client) allAllocs() map[string]*structs.Allocation {
ars := c.getAllocRunners()
allocs := make(map[string]*structs.Allocation, len(ars))
for _, ar := range ars {
a := ar.Alloc()
allocs[a.ID] = a
}
return allocs
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"allAllocs",
"(",
")",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"Allocation",
"{",
"ars",
":=",
"c",
".",
"getAllocRunners",
"(",
")",
"\n",
"allocs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
... | // allAllocs returns all the allocations managed by the client | [
"allAllocs",
"returns",
"all",
"the",
"allocations",
"managed",
"by",
"the",
"client"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2764-L2772 |
131,994 | hashicorp/nomad | client/client.go | GetTaskEventHandler | func (c *Client) GetTaskEventHandler(allocID, taskName string) drivermanager.EventHandler {
c.allocLock.RLock()
defer c.allocLock.RUnlock()
if ar, ok := c.allocs[allocID]; ok {
return ar.GetTaskEventHandler(taskName)
}
return nil
} | go | func (c *Client) GetTaskEventHandler(allocID, taskName string) drivermanager.EventHandler {
c.allocLock.RLock()
defer c.allocLock.RUnlock()
if ar, ok := c.allocs[allocID]; ok {
return ar.GetTaskEventHandler(taskName)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetTaskEventHandler",
"(",
"allocID",
",",
"taskName",
"string",
")",
"drivermanager",
".",
"EventHandler",
"{",
"c",
".",
"allocLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"allocLock",
".",
"RUnlock",
"... | // GetTaskEventHandler returns an event handler for the given allocID and task name | [
"GetTaskEventHandler",
"returns",
"an",
"event",
"handler",
"for",
"the",
"given",
"allocID",
"and",
"task",
"name"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2775-L2782 |
131,995 | hashicorp/nomad | client/client.go | Go | func (g *group) Go(f func()) {
g.wg.Add(1)
go func() {
defer g.wg.Done()
f()
}()
} | go | func (g *group) Go(f func()) {
g.wg.Add(1)
go func() {
defer g.wg.Done()
f()
}()
} | [
"func",
"(",
"g",
"*",
"group",
")",
"Go",
"(",
"f",
"func",
"(",
")",
")",
"{",
"g",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"g",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"f",
"(",
")",
"\n",
... | // Go starts f in a goroutine and must be called before Wait. | [
"Go",
"starts",
"f",
"in",
"a",
"goroutine",
"and",
"must",
"be",
"called",
"before",
"Wait",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/client.go#L2791-L2797 |
131,996 | hashicorp/nomad | nomad/worker.go | NewWorker | func NewWorker(srv *Server) (*Worker, error) {
w := &Worker{
srv: srv,
logger: srv.logger.ResetNamed("worker"),
start: time.Now(),
}
w.pauseCond = sync.NewCond(&w.pauseLock)
go w.run()
return w, nil
} | go | func NewWorker(srv *Server) (*Worker, error) {
w := &Worker{
srv: srv,
logger: srv.logger.ResetNamed("worker"),
start: time.Now(),
}
w.pauseCond = sync.NewCond(&w.pauseLock)
go w.run()
return w, nil
} | [
"func",
"NewWorker",
"(",
"srv",
"*",
"Server",
")",
"(",
"*",
"Worker",
",",
"error",
")",
"{",
"w",
":=",
"&",
"Worker",
"{",
"srv",
":",
"srv",
",",
"logger",
":",
"srv",
".",
"logger",
".",
"ResetNamed",
"(",
"\"",
"\"",
")",
",",
"start",
... | // NewWorker starts a new worker associated with the given server | [
"NewWorker",
"starts",
"a",
"new",
"worker",
"associated",
"with",
"the",
"given",
"server"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/worker.go#L75-L84 |
131,997 | hashicorp/nomad | nomad/worker.go | SetPause | func (w *Worker) SetPause(p bool) {
w.pauseLock.Lock()
w.paused = p
w.pauseLock.Unlock()
if !p {
w.pauseCond.Broadcast()
}
} | go | func (w *Worker) SetPause(p bool) {
w.pauseLock.Lock()
w.paused = p
w.pauseLock.Unlock()
if !p {
w.pauseCond.Broadcast()
}
} | [
"func",
"(",
"w",
"*",
"Worker",
")",
"SetPause",
"(",
"p",
"bool",
")",
"{",
"w",
".",
"pauseLock",
".",
"Lock",
"(",
")",
"\n",
"w",
".",
"paused",
"=",
"p",
"\n",
"w",
".",
"pauseLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"p",
"{",
... | // SetPause is used to pause or unpause a worker | [
"SetPause",
"is",
"used",
"to",
"pause",
"or",
"unpause",
"a",
"worker"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/worker.go#L87-L94 |
131,998 | hashicorp/nomad | nomad/worker.go | checkPaused | func (w *Worker) checkPaused() {
w.pauseLock.Lock()
for w.paused {
w.pauseCond.Wait()
}
w.pauseLock.Unlock()
} | go | func (w *Worker) checkPaused() {
w.pauseLock.Lock()
for w.paused {
w.pauseCond.Wait()
}
w.pauseLock.Unlock()
} | [
"func",
"(",
"w",
"*",
"Worker",
")",
"checkPaused",
"(",
")",
"{",
"w",
".",
"pauseLock",
".",
"Lock",
"(",
")",
"\n",
"for",
"w",
".",
"paused",
"{",
"w",
".",
"pauseCond",
".",
"Wait",
"(",
")",
"\n",
"}",
"\n",
"w",
".",
"pauseLock",
".",
... | // checkPaused is used to park the worker when paused | [
"checkPaused",
"is",
"used",
"to",
"park",
"the",
"worker",
"when",
"paused"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/worker.go#L97-L103 |
131,999 | hashicorp/nomad | nomad/worker.go | run | func (w *Worker) run() {
for {
// Dequeue a pending evaluation
eval, token, waitIndex, shutdown := w.dequeueEvaluation(dequeueTimeout)
if shutdown {
return
}
// Check for a shutdown
if w.srv.IsShutdown() {
w.logger.Error("nacking eval because the server is shutting down", "eval", log.Fmt("%#v", eval... | go | func (w *Worker) run() {
for {
// Dequeue a pending evaluation
eval, token, waitIndex, shutdown := w.dequeueEvaluation(dequeueTimeout)
if shutdown {
return
}
// Check for a shutdown
if w.srv.IsShutdown() {
w.logger.Error("nacking eval because the server is shutting down", "eval", log.Fmt("%#v", eval... | [
"func",
"(",
"w",
"*",
"Worker",
")",
"run",
"(",
")",
"{",
"for",
"{",
"// Dequeue a pending evaluation",
"eval",
",",
"token",
",",
"waitIndex",
",",
"shutdown",
":=",
"w",
".",
"dequeueEvaluation",
"(",
"dequeueTimeout",
")",
"\n",
"if",
"shutdown",
"{"... | // run is the long-lived goroutine which is used to run the worker | [
"run",
"is",
"the",
"long",
"-",
"lived",
"goroutine",
"which",
"is",
"used",
"to",
"run",
"the",
"worker"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/worker.go#L106-L138 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.