id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
133,400 | hashicorp/nomad | drivers/docker/stats.go | newStatsChanPipe | func newStatsChanPipe() (*usageSender, <-chan *structs.TaskResourceUsage) {
destCh := make(chan *cstructs.TaskResourceUsage, 1)
return &usageSender{
destCh: destCh,
}, destCh
} | go | func newStatsChanPipe() (*usageSender, <-chan *structs.TaskResourceUsage) {
destCh := make(chan *cstructs.TaskResourceUsage, 1)
return &usageSender{
destCh: destCh,
}, destCh
} | [
"func",
"newStatsChanPipe",
"(",
")",
"(",
"*",
"usageSender",
",",
"<-",
"chan",
"*",
"structs",
".",
"TaskResourceUsage",
")",
"{",
"destCh",
":=",
"make",
"(",
"chan",
"*",
"cstructs",
".",
"TaskResourceUsage",
",",
"1",
")",
"\n",
"return",
"&",
"usa... | // newStatsChanPipe returns a chan wrapped in a struct that supports concurrent
// sending and closing, and the receiver end of the chan. | [
"newStatsChanPipe",
"returns",
"a",
"chan",
"wrapped",
"in",
"a",
"struct",
"that",
"supports",
"concurrent",
"sending",
"and",
"closing",
"and",
"the",
"receiver",
"end",
"of",
"the",
"chan",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/drivers/docker/stats.go#L37-L43 |
133,401 | hashicorp/nomad | drivers/docker/stats.go | send | func (u *usageSender) send(tru *cstructs.TaskResourceUsage) {
u.mu.Lock()
defer u.mu.Unlock()
if u.closed {
return
}
select {
case u.destCh <- tru:
default:
// Backpressure caused missed interval
}
} | go | func (u *usageSender) send(tru *cstructs.TaskResourceUsage) {
u.mu.Lock()
defer u.mu.Unlock()
if u.closed {
return
}
select {
case u.destCh <- tru:
default:
// Backpressure caused missed interval
}
} | [
"func",
"(",
"u",
"*",
"usageSender",
")",
"send",
"(",
"tru",
"*",
"cstructs",
".",
"TaskResourceUsage",
")",
"{",
"u",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"u",
".",
"closed",
... | // send resource usage to the receiver unless the chan is already full or
// closed. | [
"send",
"resource",
"usage",
"to",
"the",
"receiver",
"unless",
"the",
"chan",
"is",
"already",
"full",
"or",
"closed",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/drivers/docker/stats.go#L47-L60 |
133,402 | hashicorp/nomad | drivers/docker/stats.go | close | func (u *usageSender) close() {
u.mu.Lock()
defer u.mu.Unlock()
if u.closed {
// already closed
return
}
u.closed = true
close(u.destCh)
} | go | func (u *usageSender) close() {
u.mu.Lock()
defer u.mu.Unlock()
if u.closed {
// already closed
return
}
u.closed = true
close(u.destCh)
} | [
"func",
"(",
"u",
"*",
"usageSender",
")",
"close",
"(",
")",
"{",
"u",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"u",
".",
"closed",
"{",
"// already closed",
"return",
"\n",
"}",
"... | // close resource usage. Any further sends will be dropped. | [
"close",
"resource",
"usage",
".",
"Any",
"further",
"sends",
"will",
"be",
"dropped",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/drivers/docker/stats.go#L63-L74 |
133,403 | hashicorp/nomad | drivers/docker/stats.go | Stats | func (h *taskHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error) {
select {
case <-h.doneCh:
return nil, nstructs.NewRecoverableError(fmt.Errorf("container stopped"), false)
default:
}
destCh, recvCh := newStatsChanPipe()
go h.collectStats(ctx, destCh, interva... | go | func (h *taskHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error) {
select {
case <-h.doneCh:
return nil, nstructs.NewRecoverableError(fmt.Errorf("container stopped"), false)
default:
}
destCh, recvCh := newStatsChanPipe()
go h.collectStats(ctx, destCh, interva... | [
"func",
"(",
"h",
"*",
"taskHandle",
")",
"Stats",
"(",
"ctx",
"context",
".",
"Context",
",",
"interval",
"time",
".",
"Duration",
")",
"(",
"<-",
"chan",
"*",
"cstructs",
".",
"TaskResourceUsage",
",",
"error",
")",
"{",
"select",
"{",
"case",
"<-",
... | // Stats starts collecting stats from the docker daemon and sends them on the
// returned channel. | [
"Stats",
"starts",
"collecting",
"stats",
"from",
"the",
"docker",
"daemon",
"and",
"sends",
"them",
"on",
"the",
"returned",
"channel",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/drivers/docker/stats.go#L78-L88 |
133,404 | hashicorp/nomad | drivers/docker/stats.go | collectStats | func (h *taskHandle) collectStats(ctx context.Context, destCh *usageSender, interval time.Duration) {
defer destCh.close()
// backoff and retry used if the docker stats API returns an error
var backoff time.Duration
var retry int
// loops until doneCh is closed
for {
if backoff > 0 {
select {
case <-time... | go | func (h *taskHandle) collectStats(ctx context.Context, destCh *usageSender, interval time.Duration) {
defer destCh.close()
// backoff and retry used if the docker stats API returns an error
var backoff time.Duration
var retry int
// loops until doneCh is closed
for {
if backoff > 0 {
select {
case <-time... | [
"func",
"(",
"h",
"*",
"taskHandle",
")",
"collectStats",
"(",
"ctx",
"context",
".",
"Context",
",",
"destCh",
"*",
"usageSender",
",",
"interval",
"time",
".",
"Duration",
")",
"{",
"defer",
"destCh",
".",
"close",
"(",
")",
"\n\n",
"// backoff and retry... | // collectStats starts collecting resource usage stats of a docker container | [
"collectStats",
"starts",
"collecting",
"resource",
"usage",
"stats",
"of",
"a",
"docker",
"container"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/drivers/docker/stats.go#L91-L140 |
133,405 | hashicorp/nomad | command/agent/operator_endpoint.go | OperatorRaftConfiguration | func (s *HTTPServer) OperatorRaftConfiguration(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != "GET" {
resp.WriteHeader(http.StatusMethodNotAllowed)
return nil, nil
}
var args structs.GenericRequest
if done := s.parse(resp, req, &args.Region, &args.QueryOptions); done {
r... | go | func (s *HTTPServer) OperatorRaftConfiguration(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != "GET" {
resp.WriteHeader(http.StatusMethodNotAllowed)
return nil, nil
}
var args structs.GenericRequest
if done := s.parse(resp, req, &args.Region, &args.QueryOptions); done {
r... | [
"func",
"(",
"s",
"*",
"HTTPServer",
")",
"OperatorRaftConfiguration",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"req",
".",
"Method",
"!=",
"\"",... | // OperatorRaftConfiguration is used to inspect the current Raft configuration.
// This supports the stale query mode in case the cluster doesn't have a leader. | [
"OperatorRaftConfiguration",
"is",
"used",
"to",
"inspect",
"the",
"current",
"Raft",
"configuration",
".",
"This",
"supports",
"the",
"stale",
"query",
"mode",
"in",
"case",
"the",
"cluster",
"doesn",
"t",
"have",
"a",
"leader",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/operator_endpoint.go#L31-L48 |
133,406 | hashicorp/nomad | command/agent/operator_endpoint.go | OperatorSchedulerConfiguration | func (s *HTTPServer) OperatorSchedulerConfiguration(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
// Switch on the method
switch req.Method {
case "GET":
return s.schedulerGetConfig(resp, req)
case "PUT", "POST":
return s.schedulerUpdateConfig(resp, req)
default:
return nil, CodedErro... | go | func (s *HTTPServer) OperatorSchedulerConfiguration(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
// Switch on the method
switch req.Method {
case "GET":
return s.schedulerGetConfig(resp, req)
case "PUT", "POST":
return s.schedulerUpdateConfig(resp, req)
default:
return nil, CodedErro... | [
"func",
"(",
"s",
"*",
"HTTPServer",
")",
"OperatorSchedulerConfiguration",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// Switch on the method",
"switch",
"re... | // OperatorSchedulerConfiguration is used to inspect the current Scheduler configuration.
// This supports the stale query mode in case the cluster doesn't have a leader. | [
"OperatorSchedulerConfiguration",
"is",
"used",
"to",
"inspect",
"the",
"current",
"Scheduler",
"configuration",
".",
"This",
"supports",
"the",
"stale",
"query",
"mode",
"in",
"case",
"the",
"cluster",
"doesn",
"t",
"have",
"a",
"leader",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/agent/operator_endpoint.go#L214-L226 |
133,407 | hashicorp/nomad | nomad/structs/errors.go | IsErrNoRegionPath | func IsErrNoRegionPath(err error) bool {
return err != nil && strings.Contains(err.Error(), errNoRegionPath)
} | go | func IsErrNoRegionPath(err error) bool {
return err != nil && strings.Contains(err.Error(), errNoRegionPath)
} | [
"func",
"IsErrNoRegionPath",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"errNoRegionPath",
")",
"\n",
"}"
] | // IsErrNoRegionPath returns whether the error is due to there being no path to
// the given region. | [
"IsErrNoRegionPath",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"there",
"being",
"no",
"path",
"to",
"the",
"given",
"region",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L46-L48 |
133,408 | hashicorp/nomad | nomad/structs/errors.go | IsErrTokenNotFound | func IsErrTokenNotFound(err error) bool {
return err != nil && strings.Contains(err.Error(), errTokenNotFound)
} | go | func IsErrTokenNotFound(err error) bool {
return err != nil && strings.Contains(err.Error(), errTokenNotFound)
} | [
"func",
"IsErrTokenNotFound",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"errTokenNotFound",
")",
"\n",
"}"
] | // IsErrTokenNotFound returns whether the error is due to the passed token not
// being resolvable. | [
"IsErrTokenNotFound",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"the",
"passed",
"token",
"not",
"being",
"resolvable",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L52-L54 |
133,409 | hashicorp/nomad | nomad/structs/errors.go | IsErrNoNodeConn | func IsErrNoNodeConn(err error) bool {
return err != nil && strings.Contains(err.Error(), errNoNodeConn)
} | go | func IsErrNoNodeConn(err error) bool {
return err != nil && strings.Contains(err.Error(), errNoNodeConn)
} | [
"func",
"IsErrNoNodeConn",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"errNoNodeConn",
")",
"\n",
"}"
] | // IsErrNoNodeConn returns whether the error is due to there being no path to
// the given node. | [
"IsErrNoNodeConn",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"there",
"being",
"no",
"path",
"to",
"the",
"given",
"node",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L64-L66 |
133,410 | hashicorp/nomad | nomad/structs/errors.go | IsErrUnknownMethod | func IsErrUnknownMethod(err error) bool {
return err != nil && strings.Contains(err.Error(), errUnknownMethod)
} | go | func IsErrUnknownMethod(err error) bool {
return err != nil && strings.Contains(err.Error(), errUnknownMethod)
} | [
"func",
"IsErrUnknownMethod",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"errUnknownMethod",
")",
"\n",
"}"
] | // IsErrUnknownMethod returns whether the error is due to the operation not
// being allowed due to lack of permissions. | [
"IsErrUnknownMethod",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"the",
"operation",
"not",
"being",
"allowed",
"due",
"to",
"lack",
"of",
"permissions",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L70-L72 |
133,411 | hashicorp/nomad | nomad/structs/errors.go | IsErrUnknownAllocation | func IsErrUnknownAllocation(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownAllocationPrefix)
} | go | func IsErrUnknownAllocation(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownAllocationPrefix)
} | [
"func",
"IsErrUnknownAllocation",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"ErrUnknownAllocationPrefix",
")",
"\n",
"}"
] | // IsErrUnknownAllocation returns whether the error is due to an unknown
// allocation. | [
"IsErrUnknownAllocation",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"an",
"unknown",
"allocation",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L104-L106 |
133,412 | hashicorp/nomad | nomad/structs/errors.go | IsErrUnknownNode | func IsErrUnknownNode(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownNodePrefix)
} | go | func IsErrUnknownNode(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownNodePrefix)
} | [
"func",
"IsErrUnknownNode",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"ErrUnknownNodePrefix",
")",
"\n",
"}"
] | // IsErrUnknownNode returns whether the error is due to an unknown
// node. | [
"IsErrUnknownNode",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"an",
"unknown",
"node",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L110-L112 |
133,413 | hashicorp/nomad | nomad/structs/errors.go | IsErrUnknownJob | func IsErrUnknownJob(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownJobPrefix)
} | go | func IsErrUnknownJob(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownJobPrefix)
} | [
"func",
"IsErrUnknownJob",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"ErrUnknownJobPrefix",
")",
"\n",
"}"
] | // IsErrUnknownJob returns whether the error is due to an unknown
// job. | [
"IsErrUnknownJob",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"an",
"unknown",
"job",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L116-L118 |
133,414 | hashicorp/nomad | nomad/structs/errors.go | IsErrUnknownEvaluation | func IsErrUnknownEvaluation(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownEvaluationPrefix)
} | go | func IsErrUnknownEvaluation(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownEvaluationPrefix)
} | [
"func",
"IsErrUnknownEvaluation",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"ErrUnknownEvaluationPrefix",
")",
"\n",
"}"
] | // IsErrUnknownEvaluation returns whether the error is due to an unknown
// evaluation. | [
"IsErrUnknownEvaluation",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"an",
"unknown",
"evaluation",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L122-L124 |
133,415 | hashicorp/nomad | nomad/structs/errors.go | IsErrUnknownDeployment | func IsErrUnknownDeployment(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownDeploymentPrefix)
} | go | func IsErrUnknownDeployment(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrUnknownDeploymentPrefix)
} | [
"func",
"IsErrUnknownDeployment",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"ErrUnknownDeploymentPrefix",
")",
"\n",
"}"
] | // IsErrUnknownDeployment returns whether the error is due to an unknown
// deployment. | [
"IsErrUnknownDeployment",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"an",
"unknown",
"deployment",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L128-L130 |
133,416 | hashicorp/nomad | nomad/structs/errors.go | IsErrUnknownNomadVersion | func IsErrUnknownNomadVersion(err error) bool {
return err != nil && strings.Contains(err.Error(), errUnknownNomadVersion)
} | go | func IsErrUnknownNomadVersion(err error) bool {
return err != nil && strings.Contains(err.Error(), errUnknownNomadVersion)
} | [
"func",
"IsErrUnknownNomadVersion",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"errUnknownNomadVersion",
")",
"\n",
"}"
] | // IsErrUnknownNomadVersion returns whether the error is due to Nomad being
// unable to determine the version of a node. | [
"IsErrUnknownNomadVersion",
"returns",
"whether",
"the",
"error",
"is",
"due",
"to",
"Nomad",
"being",
"unable",
"to",
"determine",
"the",
"version",
"of",
"a",
"node",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/structs/errors.go#L134-L136 |
133,417 | hashicorp/nomad | nomad/client_alloc_endpoint.go | Signal | func (a *ClientAllocations) Signal(args *structs.AllocSignalRequest, reply *structs.GenericResponse) error {
// We only allow stale reads since the only potentially stale information is
// the Node registration and the cost is fairly high for adding another hope
// in the forwarding chain.
args.QueryOptions.AllowSt... | go | func (a *ClientAllocations) Signal(args *structs.AllocSignalRequest, reply *structs.GenericResponse) error {
// We only allow stale reads since the only potentially stale information is
// the Node registration and the cost is fairly high for adding another hope
// in the forwarding chain.
args.QueryOptions.AllowSt... | [
"func",
"(",
"a",
"*",
"ClientAllocations",
")",
"Signal",
"(",
"args",
"*",
"structs",
".",
"AllocSignalRequest",
",",
"reply",
"*",
"structs",
".",
"GenericResponse",
")",
"error",
"{",
"// We only allow stale reads since the only potentially stale information is",
"/... | // Signal is used to send a signal to an allocation on a client. | [
"Signal",
"is",
"used",
"to",
"send",
"a",
"signal",
"to",
"an",
"allocation",
"on",
"a",
"client",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/client_alloc_endpoint.go#L69-L122 |
133,418 | hashicorp/nomad | helper/args/args.go | ReplaceEnv | func ReplaceEnv(arg string, environments ...map[string]string) string {
return envRe.ReplaceAllStringFunc(arg, func(arg string) string {
stripped := arg[2 : len(arg)-1]
for _, env := range environments {
if value, ok := env[stripped]; ok {
return value
}
}
return arg
})
} | go | func ReplaceEnv(arg string, environments ...map[string]string) string {
return envRe.ReplaceAllStringFunc(arg, func(arg string) string {
stripped := arg[2 : len(arg)-1]
for _, env := range environments {
if value, ok := env[stripped]; ok {
return value
}
}
return arg
})
} | [
"func",
"ReplaceEnv",
"(",
"arg",
"string",
",",
"environments",
"...",
"map",
"[",
"string",
"]",
"string",
")",
"string",
"{",
"return",
"envRe",
".",
"ReplaceAllStringFunc",
"(",
"arg",
",",
"func",
"(",
"arg",
"string",
")",
"string",
"{",
"stripped",
... | // ReplaceEnv takes an arg and replaces all occurrences of environment variables.
// If the variable is found in the passed map it is replaced, otherwise the
// original string is returned. | [
"ReplaceEnv",
"takes",
"an",
"arg",
"and",
"replaces",
"all",
"occurrences",
"of",
"environment",
"variables",
".",
"If",
"the",
"variable",
"is",
"found",
"in",
"the",
"passed",
"map",
"it",
"is",
"replaced",
"otherwise",
"the",
"original",
"string",
"is",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/args/args.go#L12-L23 |
133,419 | hashicorp/nomad | helper/args/args.go | ReplaceEnvWithPlaceHolder | func ReplaceEnvWithPlaceHolder(arg string, placeholder string) string {
return envRe.ReplaceAllString(arg, placeholder)
} | go | func ReplaceEnvWithPlaceHolder(arg string, placeholder string) string {
return envRe.ReplaceAllString(arg, placeholder)
} | [
"func",
"ReplaceEnvWithPlaceHolder",
"(",
"arg",
"string",
",",
"placeholder",
"string",
")",
"string",
"{",
"return",
"envRe",
".",
"ReplaceAllString",
"(",
"arg",
",",
"placeholder",
")",
"\n",
"}"
] | // ReplaceEnvWithPlaceHolder replaces all occurrences of environment variables with the placeholder string. | [
"ReplaceEnvWithPlaceHolder",
"replaces",
"all",
"occurrences",
"of",
"environment",
"variables",
"with",
"the",
"placeholder",
"string",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/args/args.go#L26-L28 |
133,420 | hashicorp/nomad | e2e/cli/command/run.go | goArgs | func (opts *runOpts) goArgs() []string {
a := []string{
"test",
"-json",
}
if opts.run != "" {
a = append(a, "-run=TestE2E/"+opts.run)
}
a = append(a, []string{
"github.com/hashicorp/nomad/e2e",
"-env=" + opts.env,
"-env.provider=" + opts.provider,
}...)
if opts.slow {
a = append(a, "-slow")
}
... | go | func (opts *runOpts) goArgs() []string {
a := []string{
"test",
"-json",
}
if opts.run != "" {
a = append(a, "-run=TestE2E/"+opts.run)
}
a = append(a, []string{
"github.com/hashicorp/nomad/e2e",
"-env=" + opts.env,
"-env.provider=" + opts.provider,
}...)
if opts.slow {
a = append(a, "-slow")
}
... | [
"func",
"(",
"opts",
"*",
"runOpts",
")",
"goArgs",
"(",
")",
"[",
"]",
"string",
"{",
"a",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"}",
"\n\n",
"if",
"opts",
".",
"run",
"!=",
"\"",
"\"",
"{",
"a",
"=",
"append",
"... | // goArgs returns the list of arguments passed to the go command to start the
// e2e test framework | [
"goArgs",
"returns",
"the",
"list",
"of",
"arguments",
"passed",
"to",
"the",
"go",
"command",
"to",
"start",
"the",
"e2e",
"test",
"framework"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/e2e/cli/command/run.go#L231-L255 |
133,421 | hashicorp/nomad | e2e/cli/command/run.go | goEnv | func (opts *runOpts) goEnv() []string {
env := append(os.Environ(), "NOMAD_E2E=1")
if opts.nomadAddr != "" {
env = append(env, "NOMAD_ADDR="+opts.nomadAddr)
}
if opts.consulAddr != "" {
env = append(env, fmt.Sprintf("%s=%s", capi.HTTPAddrEnvName, opts.consulAddr))
}
if opts.vaultAddr != "" {
env = append(en... | go | func (opts *runOpts) goEnv() []string {
env := append(os.Environ(), "NOMAD_E2E=1")
if opts.nomadAddr != "" {
env = append(env, "NOMAD_ADDR="+opts.nomadAddr)
}
if opts.consulAddr != "" {
env = append(env, fmt.Sprintf("%s=%s", capi.HTTPAddrEnvName, opts.consulAddr))
}
if opts.vaultAddr != "" {
env = append(en... | [
"func",
"(",
"opts",
"*",
"runOpts",
")",
"goEnv",
"(",
")",
"[",
"]",
"string",
"{",
"env",
":=",
"append",
"(",
"os",
".",
"Environ",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"opts",
".",
"nomadAddr",
"!=",
"\"",
"\"",
"{",
"env",
"=",
"... | // goEnv returns the list of environment variabled passed to the go command to start
// the e2e test framework | [
"goEnv",
"returns",
"the",
"list",
"of",
"environment",
"variabled",
"passed",
"to",
"the",
"go",
"command",
"to",
"start",
"the",
"e2e",
"test",
"framework"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/e2e/cli/command/run.go#L259-L272 |
133,422 | hashicorp/nomad | command/job_run.go | parseCheckIndex | func parseCheckIndex(input string) (uint64, bool, error) {
if input == "" {
return 0, false, nil
}
u, err := strconv.ParseUint(input, 10, 64)
return u, true, err
} | go | func parseCheckIndex(input string) (uint64, bool, error) {
if input == "" {
return 0, false, nil
}
u, err := strconv.ParseUint(input, 10, 64)
return u, true, err
} | [
"func",
"parseCheckIndex",
"(",
"input",
"string",
")",
"(",
"uint64",
",",
"bool",
",",
"error",
")",
"{",
"if",
"input",
"==",
"\"",
"\"",
"{",
"return",
"0",
",",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"u",
",",
"err",
":=",
"strconv",
".",
"... | // parseCheckIndex parses the check-index flag and returns the index, whether it
// was set and potentially an error during parsing. | [
"parseCheckIndex",
"parses",
"the",
"check",
"-",
"index",
"flag",
"and",
"returns",
"the",
"index",
"whether",
"it",
"was",
"set",
"and",
"potentially",
"an",
"error",
"during",
"parsing",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/job_run.go#L273-L280 |
133,423 | hashicorp/nomad | plugins/drivers/plugin.go | Serve | func Serve(d DriverPlugin, logger hclog.Logger) {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: base.Handshake,
Plugins: map[string]plugin.Plugin{
base.PluginTypeBase: &base.PluginBase{Impl: d},
base.PluginTypeDriver: &PluginDriver{impl: d, logger: logger},
},
GRPCServer: plugin.DefaultGRPCServer,... | go | func Serve(d DriverPlugin, logger hclog.Logger) {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: base.Handshake,
Plugins: map[string]plugin.Plugin{
base.PluginTypeBase: &base.PluginBase{Impl: d},
base.PluginTypeDriver: &PluginDriver{impl: d, logger: logger},
},
GRPCServer: plugin.DefaultGRPCServer,... | [
"func",
"Serve",
"(",
"d",
"DriverPlugin",
",",
"logger",
"hclog",
".",
"Logger",
")",
"{",
"plugin",
".",
"Serve",
"(",
"&",
"plugin",
".",
"ServeConfig",
"{",
"HandshakeConfig",
":",
"base",
".",
"Handshake",
",",
"Plugins",
":",
"map",
"[",
"string",
... | // Serve is used to serve a driverplugin | [
"Serve",
"is",
"used",
"to",
"serve",
"a",
"driverplugin"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/drivers/plugin.go#L52-L62 |
133,424 | hashicorp/nomad | drivers/shared/executor/executor_windows.go | shutdownProcess | func (e *UniversalExecutor) shutdownProcess(_ os.Signal, proc *os.Process) error {
if err := sendCtrlBreak(proc.Pid); err != nil {
return fmt.Errorf("executor shutdown error: %v", err)
}
e.logger.Debug("sent Ctrl-Break to process", "pid", proc.Pid)
return nil
} | go | func (e *UniversalExecutor) shutdownProcess(_ os.Signal, proc *os.Process) error {
if err := sendCtrlBreak(proc.Pid); err != nil {
return fmt.Errorf("executor shutdown error: %v", err)
}
e.logger.Debug("sent Ctrl-Break to process", "pid", proc.Pid)
return nil
} | [
"func",
"(",
"e",
"*",
"UniversalExecutor",
")",
"shutdownProcess",
"(",
"_",
"os",
".",
"Signal",
",",
"proc",
"*",
"os",
".",
"Process",
")",
"error",
"{",
"if",
"err",
":=",
"sendCtrlBreak",
"(",
"proc",
".",
"Pid",
")",
";",
"err",
"!=",
"nil",
... | // Send the process a Ctrl-Break event, allowing it to shutdown by itself
// before being Terminate. | [
"Send",
"the",
"process",
"a",
"Ctrl",
"-",
"Break",
"event",
"allowing",
"it",
"to",
"shutdown",
"by",
"itself",
"before",
"being",
"Terminate",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/drivers/shared/executor/executor_windows.go#L62-L69 |
133,425 | hashicorp/nomad | plugins/serve.go | Serve | func Serve(f PluginFactory) {
logger := log.New(&log.LoggerOptions{
Level: log.Trace,
JSONFormat: true,
})
plugin := f(logger)
switch p := plugin.(type) {
case device.DevicePlugin:
device.Serve(p, logger)
case drivers.DriverPlugin:
drivers.Serve(p, logger)
default:
fmt.Println("Unsupported plugin... | go | func Serve(f PluginFactory) {
logger := log.New(&log.LoggerOptions{
Level: log.Trace,
JSONFormat: true,
})
plugin := f(logger)
switch p := plugin.(type) {
case device.DevicePlugin:
device.Serve(p, logger)
case drivers.DriverPlugin:
drivers.Serve(p, logger)
default:
fmt.Println("Unsupported plugin... | [
"func",
"Serve",
"(",
"f",
"PluginFactory",
")",
"{",
"logger",
":=",
"log",
".",
"New",
"(",
"&",
"log",
".",
"LoggerOptions",
"{",
"Level",
":",
"log",
".",
"Trace",
",",
"JSONFormat",
":",
"true",
",",
"}",
")",
"\n\n",
"plugin",
":=",
"f",
"(",... | // Serve is used to serve a new Nomad plugin | [
"Serve",
"is",
"used",
"to",
"serve",
"a",
"new",
"Nomad",
"plugin"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/serve.go#L15-L30 |
133,426 | hashicorp/nomad | scheduler/util.go | materializeTaskGroups | func materializeTaskGroups(job *structs.Job) map[string]*structs.TaskGroup {
out := make(map[string]*structs.TaskGroup)
if job.Stopped() {
return out
}
for _, tg := range job.TaskGroups {
for i := 0; i < tg.Count; i++ {
name := fmt.Sprintf("%s.%s[%d]", job.Name, tg.Name, i)
out[name] = tg
}
}
return ... | go | func materializeTaskGroups(job *structs.Job) map[string]*structs.TaskGroup {
out := make(map[string]*structs.TaskGroup)
if job.Stopped() {
return out
}
for _, tg := range job.TaskGroups {
for i := 0; i < tg.Count; i++ {
name := fmt.Sprintf("%s.%s[%d]", job.Name, tg.Name, i)
out[name] = tg
}
}
return ... | [
"func",
"materializeTaskGroups",
"(",
"job",
"*",
"structs",
".",
"Job",
")",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"TaskGroup",
"{",
"out",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"TaskGroup",
")",
"\n",
"if",
"j... | // materializeTaskGroups is used to materialize all the task groups
// a job requires. This is used to do the count expansion. | [
"materializeTaskGroups",
"is",
"used",
"to",
"materialize",
"all",
"the",
"task",
"groups",
"a",
"job",
"requires",
".",
"This",
"is",
"used",
"to",
"do",
"the",
"count",
"expansion",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L22-L35 |
133,427 | hashicorp/nomad | scheduler/util.go | diffSystemAllocs | func diffSystemAllocs(job *structs.Job, nodes []*structs.Node, taintedNodes map[string]*structs.Node,
allocs []*structs.Allocation, terminalAllocs map[string]*structs.Allocation) *diffResult {
// Build a mapping of nodes to all their allocs.
nodeAllocs := make(map[string][]*structs.Allocation, len(allocs))
for _, ... | go | func diffSystemAllocs(job *structs.Job, nodes []*structs.Node, taintedNodes map[string]*structs.Node,
allocs []*structs.Allocation, terminalAllocs map[string]*structs.Allocation) *diffResult {
// Build a mapping of nodes to all their allocs.
nodeAllocs := make(map[string][]*structs.Allocation, len(allocs))
for _, ... | [
"func",
"diffSystemAllocs",
"(",
"job",
"*",
"structs",
".",
"Job",
",",
"nodes",
"[",
"]",
"*",
"structs",
".",
"Node",
",",
"taintedNodes",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"Node",
",",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Alloc... | // diffSystemAllocs is like diffAllocs however, the allocations in the
// diffResult contain the specific nodeID they should be allocated on.
//
// job is the job whose allocs is going to be diff-ed.
// nodes is a list of nodes in ready state.
// taintedNodes is an index of the nodes which are either down or in drain m... | [
"diffSystemAllocs",
"is",
"like",
"diffAllocs",
"however",
"the",
"allocations",
"in",
"the",
"diffResult",
"contain",
"the",
"specific",
"nodeID",
"they",
"should",
"be",
"allocated",
"on",
".",
"job",
"is",
"the",
"job",
"whose",
"allocs",
"is",
"going",
"to... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L176-L220 |
133,428 | hashicorp/nomad | scheduler/util.go | readyNodesInDCs | func readyNodesInDCs(state State, dcs []string) ([]*structs.Node, map[string]int, error) {
// Index the DCs
dcMap := make(map[string]int, len(dcs))
for _, dc := range dcs {
dcMap[dc] = 0
}
// Scan the nodes
ws := memdb.NewWatchSet()
var out []*structs.Node
iter, err := state.Nodes(ws)
if err != nil {
retu... | go | func readyNodesInDCs(state State, dcs []string) ([]*structs.Node, map[string]int, error) {
// Index the DCs
dcMap := make(map[string]int, len(dcs))
for _, dc := range dcs {
dcMap[dc] = 0
}
// Scan the nodes
ws := memdb.NewWatchSet()
var out []*structs.Node
iter, err := state.Nodes(ws)
if err != nil {
retu... | [
"func",
"readyNodesInDCs",
"(",
"state",
"State",
",",
"dcs",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"structs",
".",
"Node",
",",
"map",
"[",
"string",
"]",
"int",
",",
"error",
")",
"{",
"// Index the DCs",
"dcMap",
":=",
"make",
"(",
"map",
... | // readyNodesInDCs returns all the ready nodes in the given datacenters and a
// mapping of each data center to the count of ready nodes. | [
"readyNodesInDCs",
"returns",
"all",
"the",
"ready",
"nodes",
"in",
"the",
"given",
"datacenters",
"and",
"a",
"mapping",
"of",
"each",
"data",
"center",
"to",
"the",
"count",
"of",
"ready",
"nodes",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L224-L262 |
133,429 | hashicorp/nomad | scheduler/util.go | retryMax | func retryMax(max int, cb func() (bool, error), reset func() bool) error {
attempts := 0
for attempts < max {
done, err := cb()
if err != nil {
return err
}
if done {
return nil
}
// Check if we should reset the number attempts
if reset != nil && reset() {
attempts = 0
} else {
attempts++... | go | func retryMax(max int, cb func() (bool, error), reset func() bool) error {
attempts := 0
for attempts < max {
done, err := cb()
if err != nil {
return err
}
if done {
return nil
}
// Check if we should reset the number attempts
if reset != nil && reset() {
attempts = 0
} else {
attempts++... | [
"func",
"retryMax",
"(",
"max",
"int",
",",
"cb",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
",",
"reset",
"func",
"(",
")",
"bool",
")",
"error",
"{",
"attempts",
":=",
"0",
"\n",
"for",
"attempts",
"<",
"max",
"{",
"done",
",",
"err",
... | // retryMax is used to retry a callback until it returns success or
// a maximum number of attempts is reached. An optional reset function may be
// passed which is called after each failed iteration. If the reset function is
// set and returns true, the number of attempts is reset back to max. | [
"retryMax",
"is",
"used",
"to",
"retry",
"a",
"callback",
"until",
"it",
"returns",
"success",
"or",
"a",
"maximum",
"number",
"of",
"attempts",
"is",
"reached",
".",
"An",
"optional",
"reset",
"function",
"may",
"be",
"passed",
"which",
"is",
"called",
"a... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L268-L290 |
133,430 | hashicorp/nomad | scheduler/util.go | progressMade | func progressMade(result *structs.PlanResult) bool {
return result != nil && (len(result.NodeUpdate) != 0 ||
len(result.NodeAllocation) != 0 || result.Deployment != nil ||
len(result.DeploymentUpdates) != 0)
} | go | func progressMade(result *structs.PlanResult) bool {
return result != nil && (len(result.NodeUpdate) != 0 ||
len(result.NodeAllocation) != 0 || result.Deployment != nil ||
len(result.DeploymentUpdates) != 0)
} | [
"func",
"progressMade",
"(",
"result",
"*",
"structs",
".",
"PlanResult",
")",
"bool",
"{",
"return",
"result",
"!=",
"nil",
"&&",
"(",
"len",
"(",
"result",
".",
"NodeUpdate",
")",
"!=",
"0",
"||",
"len",
"(",
"result",
".",
"NodeAllocation",
")",
"!=... | // progressMade checks to see if the plan result made allocations or updates.
// If the result is nil, false is returned. | [
"progressMade",
"checks",
"to",
"see",
"if",
"the",
"plan",
"result",
"made",
"allocations",
"or",
"updates",
".",
"If",
"the",
"result",
"is",
"nil",
"false",
"is",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L294-L298 |
133,431 | hashicorp/nomad | scheduler/util.go | taintedNodes | func taintedNodes(state State, allocs []*structs.Allocation) (map[string]*structs.Node, error) {
out := make(map[string]*structs.Node)
for _, alloc := range allocs {
if _, ok := out[alloc.NodeID]; ok {
continue
}
ws := memdb.NewWatchSet()
node, err := state.NodeByID(ws, alloc.NodeID)
if err != nil {
... | go | func taintedNodes(state State, allocs []*structs.Allocation) (map[string]*structs.Node, error) {
out := make(map[string]*structs.Node)
for _, alloc := range allocs {
if _, ok := out[alloc.NodeID]; ok {
continue
}
ws := memdb.NewWatchSet()
node, err := state.NodeByID(ws, alloc.NodeID)
if err != nil {
... | [
"func",
"taintedNodes",
"(",
"state",
"State",
",",
"allocs",
"[",
"]",
"*",
"structs",
".",
"Allocation",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"Node",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"map",
"[",
"string",
"]"... | // taintedNodes is used to scan the allocations and then check if the
// underlying nodes are tainted, and should force a migration of the allocation.
// All the nodes returned in the map are tainted. | [
"taintedNodes",
"is",
"used",
"to",
"scan",
"the",
"allocations",
"and",
"then",
"check",
"if",
"the",
"underlying",
"nodes",
"are",
"tainted",
"and",
"should",
"force",
"a",
"migration",
"of",
"the",
"allocation",
".",
"All",
"the",
"nodes",
"returned",
"in... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L303-L326 |
133,432 | hashicorp/nomad | scheduler/util.go | shuffleNodes | func shuffleNodes(nodes []*structs.Node) {
n := len(nodes)
for i := n - 1; i > 0; i-- {
j := rand.Intn(i + 1)
nodes[i], nodes[j] = nodes[j], nodes[i]
}
} | go | func shuffleNodes(nodes []*structs.Node) {
n := len(nodes)
for i := n - 1; i > 0; i-- {
j := rand.Intn(i + 1)
nodes[i], nodes[j] = nodes[j], nodes[i]
}
} | [
"func",
"shuffleNodes",
"(",
"nodes",
"[",
"]",
"*",
"structs",
".",
"Node",
")",
"{",
"n",
":=",
"len",
"(",
"nodes",
")",
"\n",
"for",
"i",
":=",
"n",
"-",
"1",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"j",
":=",
"rand",
".",
"Intn",
"(",... | // shuffleNodes randomizes the slice order with the Fisher-Yates algorithm | [
"shuffleNodes",
"randomizes",
"the",
"slice",
"order",
"with",
"the",
"Fisher",
"-",
"Yates",
"algorithm"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L329-L335 |
133,433 | hashicorp/nomad | scheduler/util.go | tasksUpdated | func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) bool {
a := jobA.LookupTaskGroup(taskGroup)
b := jobB.LookupTaskGroup(taskGroup)
// If the number of tasks do not match, clearly there is an update
if len(a.Tasks) != len(b.Tasks) {
return true
}
// Check ephemeral disk
if !reflect.DeepEqual(a.Ephe... | go | func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) bool {
a := jobA.LookupTaskGroup(taskGroup)
b := jobB.LookupTaskGroup(taskGroup)
// If the number of tasks do not match, clearly there is an update
if len(a.Tasks) != len(b.Tasks) {
return true
}
// Check ephemeral disk
if !reflect.DeepEqual(a.Ephe... | [
"func",
"tasksUpdated",
"(",
"jobA",
",",
"jobB",
"*",
"structs",
".",
"Job",
",",
"taskGroup",
"string",
")",
"bool",
"{",
"a",
":=",
"jobA",
".",
"LookupTaskGroup",
"(",
"taskGroup",
")",
"\n",
"b",
":=",
"jobB",
".",
"LookupTaskGroup",
"(",
"taskGroup... | // tasksUpdated does a diff between task groups to see if the
// tasks, their drivers, environment variables or config have updated. The
// inputs are the task group name to diff and two jobs to diff. | [
"tasksUpdated",
"does",
"a",
"diff",
"between",
"task",
"groups",
"to",
"see",
"if",
"the",
"tasks",
"their",
"drivers",
"environment",
"variables",
"or",
"config",
"have",
"updated",
".",
"The",
"inputs",
"are",
"the",
"task",
"group",
"name",
"to",
"diff",... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L340-L415 |
133,434 | hashicorp/nomad | scheduler/util.go | networkPortMap | func networkPortMap(n *structs.NetworkResource) map[string]int {
m := make(map[string]int, len(n.DynamicPorts)+len(n.ReservedPorts))
for _, p := range n.ReservedPorts {
m[p.Label] = p.Value
}
for _, p := range n.DynamicPorts {
m[p.Label] = -1
}
return m
} | go | func networkPortMap(n *structs.NetworkResource) map[string]int {
m := make(map[string]int, len(n.DynamicPorts)+len(n.ReservedPorts))
for _, p := range n.ReservedPorts {
m[p.Label] = p.Value
}
for _, p := range n.DynamicPorts {
m[p.Label] = -1
}
return m
} | [
"func",
"networkPortMap",
"(",
"n",
"*",
"structs",
".",
"NetworkResource",
")",
"map",
"[",
"string",
"]",
"int",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"n",
".",
"DynamicPorts",
")",
"+",
"len",
"(",
"n",
... | // networkPortMap takes a network resource and returns a map of port labels to
// values. The value for dynamic ports is disregarded even if it is set. This
// makes this function suitable for comparing two network resources for changes. | [
"networkPortMap",
"takes",
"a",
"network",
"resource",
"and",
"returns",
"a",
"map",
"of",
"port",
"labels",
"to",
"values",
".",
"The",
"value",
"for",
"dynamic",
"ports",
"is",
"disregarded",
"even",
"if",
"it",
"is",
"set",
".",
"This",
"makes",
"this",... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L420-L429 |
133,435 | hashicorp/nomad | scheduler/util.go | setStatus | func setStatus(logger log.Logger, planner Planner,
eval, nextEval, spawnedBlocked *structs.Evaluation,
tgMetrics map[string]*structs.AllocMetric, status, desc string,
queuedAllocs map[string]int, deploymentID string) error {
logger.Debug("setting eval status", "status", status)
newEval := eval.Copy()
newEval.Sta... | go | func setStatus(logger log.Logger, planner Planner,
eval, nextEval, spawnedBlocked *structs.Evaluation,
tgMetrics map[string]*structs.AllocMetric, status, desc string,
queuedAllocs map[string]int, deploymentID string) error {
logger.Debug("setting eval status", "status", status)
newEval := eval.Copy()
newEval.Sta... | [
"func",
"setStatus",
"(",
"logger",
"log",
".",
"Logger",
",",
"planner",
"Planner",
",",
"eval",
",",
"nextEval",
",",
"spawnedBlocked",
"*",
"structs",
".",
"Evaluation",
",",
"tgMetrics",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"AllocMetric",
",... | // setStatus is used to update the status of the evaluation | [
"setStatus",
"is",
"used",
"to",
"update",
"the",
"status",
"of",
"the",
"evaluation"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L432-L454 |
133,436 | hashicorp/nomad | scheduler/util.go | evictAndPlace | func evictAndPlace(ctx Context, diff *diffResult, allocs []allocTuple, desc string, limit *int) bool {
n := len(allocs)
for i := 0; i < n && i < *limit; i++ {
a := allocs[i]
ctx.Plan().AppendStoppedAlloc(a.Alloc, desc, "")
diff.place = append(diff.place, a)
}
if n <= *limit {
*limit -= n
return false
}
... | go | func evictAndPlace(ctx Context, diff *diffResult, allocs []allocTuple, desc string, limit *int) bool {
n := len(allocs)
for i := 0; i < n && i < *limit; i++ {
a := allocs[i]
ctx.Plan().AppendStoppedAlloc(a.Alloc, desc, "")
diff.place = append(diff.place, a)
}
if n <= *limit {
*limit -= n
return false
}
... | [
"func",
"evictAndPlace",
"(",
"ctx",
"Context",
",",
"diff",
"*",
"diffResult",
",",
"allocs",
"[",
"]",
"allocTuple",
",",
"desc",
"string",
",",
"limit",
"*",
"int",
")",
"bool",
"{",
"n",
":=",
"len",
"(",
"allocs",
")",
"\n",
"for",
"i",
":=",
... | // evictAndPlace is used to mark allocations for evicts and add them to the
// placement queue. evictAndPlace modifies both the diffResult and the
// limit. It returns true if the limit has been reached. | [
"evictAndPlace",
"is",
"used",
"to",
"mark",
"allocations",
"for",
"evicts",
"and",
"add",
"them",
"to",
"the",
"placement",
"queue",
".",
"evictAndPlace",
"modifies",
"both",
"the",
"diffResult",
"and",
"the",
"limit",
".",
"It",
"returns",
"true",
"if",
"t... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L571-L584 |
133,437 | hashicorp/nomad | scheduler/util.go | taskGroupConstraints | func taskGroupConstraints(tg *structs.TaskGroup) tgConstrainTuple {
c := tgConstrainTuple{
constraints: make([]*structs.Constraint, 0, len(tg.Constraints)),
drivers: make(map[string]struct{}),
}
c.constraints = append(c.constraints, tg.Constraints...)
for _, task := range tg.Tasks {
c.drivers[task.Driver... | go | func taskGroupConstraints(tg *structs.TaskGroup) tgConstrainTuple {
c := tgConstrainTuple{
constraints: make([]*structs.Constraint, 0, len(tg.Constraints)),
drivers: make(map[string]struct{}),
}
c.constraints = append(c.constraints, tg.Constraints...)
for _, task := range tg.Tasks {
c.drivers[task.Driver... | [
"func",
"taskGroupConstraints",
"(",
"tg",
"*",
"structs",
".",
"TaskGroup",
")",
"tgConstrainTuple",
"{",
"c",
":=",
"tgConstrainTuple",
"{",
"constraints",
":",
"make",
"(",
"[",
"]",
"*",
"structs",
".",
"Constraint",
",",
"0",
",",
"len",
"(",
"tg",
... | // taskGroupConstraints collects the constraints, drivers and resources required by each
// sub-task to aggregate the TaskGroup totals | [
"taskGroupConstraints",
"collects",
"the",
"constraints",
"drivers",
"and",
"resources",
"required",
"by",
"each",
"sub",
"-",
"task",
"to",
"aggregate",
"the",
"TaskGroup",
"totals"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L597-L610 |
133,438 | hashicorp/nomad | scheduler/util.go | desiredUpdates | func desiredUpdates(diff *diffResult, inplaceUpdates,
destructiveUpdates []allocTuple) map[string]*structs.DesiredUpdates {
desiredTgs := make(map[string]*structs.DesiredUpdates)
for _, tuple := range diff.place {
name := tuple.TaskGroup.Name
des, ok := desiredTgs[name]
if !ok {
des = &structs.DesiredUpdat... | go | func desiredUpdates(diff *diffResult, inplaceUpdates,
destructiveUpdates []allocTuple) map[string]*structs.DesiredUpdates {
desiredTgs := make(map[string]*structs.DesiredUpdates)
for _, tuple := range diff.place {
name := tuple.TaskGroup.Name
des, ok := desiredTgs[name]
if !ok {
des = &structs.DesiredUpdat... | [
"func",
"desiredUpdates",
"(",
"diff",
"*",
"diffResult",
",",
"inplaceUpdates",
",",
"destructiveUpdates",
"[",
"]",
"allocTuple",
")",
"map",
"[",
"string",
"]",
"*",
"structs",
".",
"DesiredUpdates",
"{",
"desiredTgs",
":=",
"make",
"(",
"map",
"[",
"stri... | // desiredUpdates takes the diffResult as well as the set of inplace and
// destructive updates and returns a map of task groups to their set of desired
// updates. | [
"desiredUpdates",
"takes",
"the",
"diffResult",
"as",
"well",
"as",
"the",
"set",
"of",
"inplace",
"and",
"destructive",
"updates",
"and",
"returns",
"a",
"map",
"of",
"task",
"groups",
"to",
"their",
"set",
"of",
"desired",
"updates",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L615-L686 |
133,439 | hashicorp/nomad | scheduler/util.go | adjustQueuedAllocations | func adjustQueuedAllocations(logger log.Logger, result *structs.PlanResult, queuedAllocs map[string]int) {
if result == nil {
return
}
for _, allocations := range result.NodeAllocation {
for _, allocation := range allocations {
// Ensure that the allocation is newly created. We check that
// the CreateInd... | go | func adjustQueuedAllocations(logger log.Logger, result *structs.PlanResult, queuedAllocs map[string]int) {
if result == nil {
return
}
for _, allocations := range result.NodeAllocation {
for _, allocation := range allocations {
// Ensure that the allocation is newly created. We check that
// the CreateInd... | [
"func",
"adjustQueuedAllocations",
"(",
"logger",
"log",
".",
"Logger",
",",
"result",
"*",
"structs",
".",
"PlanResult",
",",
"queuedAllocs",
"map",
"[",
"string",
"]",
"int",
")",
"{",
"if",
"result",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"for... | // adjustQueuedAllocations decrements the number of allocations pending per task
// group based on the number of allocations successfully placed | [
"adjustQueuedAllocations",
"decrements",
"the",
"number",
"of",
"allocations",
"pending",
"per",
"task",
"group",
"based",
"on",
"the",
"number",
"of",
"allocations",
"successfully",
"placed"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L690-L715 |
133,440 | hashicorp/nomad | scheduler/util.go | genericAllocUpdateFn | func genericAllocUpdateFn(ctx Context, stack Stack, evalID string) allocUpdateType {
return func(existing *structs.Allocation, newJob *structs.Job, newTG *structs.TaskGroup) (ignore, destructive bool, updated *structs.Allocation) {
// Same index, so nothing to do
if existing.Job.JobModifyIndex == newJob.JobModifyI... | go | func genericAllocUpdateFn(ctx Context, stack Stack, evalID string) allocUpdateType {
return func(existing *structs.Allocation, newJob *structs.Job, newTG *structs.TaskGroup) (ignore, destructive bool, updated *structs.Allocation) {
// Same index, so nothing to do
if existing.Job.JobModifyIndex == newJob.JobModifyI... | [
"func",
"genericAllocUpdateFn",
"(",
"ctx",
"Context",
",",
"stack",
"Stack",
",",
"evalID",
"string",
")",
"allocUpdateType",
"{",
"return",
"func",
"(",
"existing",
"*",
"structs",
".",
"Allocation",
",",
"newJob",
"*",
"structs",
".",
"Job",
",",
"newTG",... | // genericAllocUpdateFn is a factory for the scheduler to create an allocUpdateType
// function to be passed into the reconciler. The factory takes objects that
// exist only in the scheduler context and returns a function that can be used
// by the reconciler to make decisions about how to update an allocation. The
//... | [
"genericAllocUpdateFn",
"is",
"a",
"factory",
"for",
"the",
"scheduler",
"to",
"create",
"an",
"allocUpdateType",
"function",
"to",
"be",
"passed",
"into",
"the",
"reconciler",
".",
"The",
"factory",
"takes",
"objects",
"that",
"exist",
"only",
"in",
"the",
"s... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/util.go#L747-L839 |
133,441 | hashicorp/nomad | client/fingerprint/env_gce.go | NewEnvGCEFingerprint | func NewEnvGCEFingerprint(logger log.Logger) Fingerprint {
// Read the internal metadata URL from the environment, allowing test files to
// provide their own
metadataURL := os.Getenv("GCE_ENV_URL")
if metadataURL == "" {
metadataURL = DEFAULT_GCE_URL
}
// assume 2 seconds is enough time for inside GCE network... | go | func NewEnvGCEFingerprint(logger log.Logger) Fingerprint {
// Read the internal metadata URL from the environment, allowing test files to
// provide their own
metadataURL := os.Getenv("GCE_ENV_URL")
if metadataURL == "" {
metadataURL = DEFAULT_GCE_URL
}
// assume 2 seconds is enough time for inside GCE network... | [
"func",
"NewEnvGCEFingerprint",
"(",
"logger",
"log",
".",
"Logger",
")",
"Fingerprint",
"{",
"// Read the internal metadata URL from the environment, allowing test files to",
"// provide their own",
"metadataURL",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"i... | // NewEnvGCEFingerprint is used to create a fingerprint from GCE metadata | [
"NewEnvGCEFingerprint",
"is",
"used",
"to",
"create",
"a",
"fingerprint",
"from",
"GCE",
"metadata"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fingerprint/env_gce.go#L64-L83 |
133,442 | hashicorp/nomad | nomad/plan_apply_not_ent.go | refreshIndex | func refreshIndex(snap *state.StateSnapshot) (uint64, error) {
allocIndex, err := snap.Index("allocs")
if err != nil {
return 0, err
}
nodeIndex, err := snap.Index("nodes")
if err != nil {
return 0, err
}
return maxUint64(nodeIndex, allocIndex), nil
} | go | func refreshIndex(snap *state.StateSnapshot) (uint64, error) {
allocIndex, err := snap.Index("allocs")
if err != nil {
return 0, err
}
nodeIndex, err := snap.Index("nodes")
if err != nil {
return 0, err
}
return maxUint64(nodeIndex, allocIndex), nil
} | [
"func",
"refreshIndex",
"(",
"snap",
"*",
"state",
".",
"StateSnapshot",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"allocIndex",
",",
"err",
":=",
"snap",
".",
"Index",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
","... | // refreshIndex returns the index the scheduler should refresh to as the maximum
// of both the allocation and node tables. | [
"refreshIndex",
"returns",
"the",
"index",
"the",
"scheduler",
"should",
"refresh",
"to",
"as",
"the",
"maximum",
"of",
"both",
"the",
"allocation",
"and",
"node",
"tables",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply_not_ent.go#L12-L22 |
133,443 | hashicorp/nomad | nomad/plan_apply_not_ent.go | evaluatePlanQuota | func evaluatePlanQuota(snap *state.StateSnapshot, plan *structs.Plan) (bool, error) {
return false, nil
} | go | func evaluatePlanQuota(snap *state.StateSnapshot, plan *structs.Plan) (bool, error) {
return false, nil
} | [
"func",
"evaluatePlanQuota",
"(",
"snap",
"*",
"state",
".",
"StateSnapshot",
",",
"plan",
"*",
"structs",
".",
"Plan",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // evaluatePlanQuota returns whether the plan would be over quota | [
"evaluatePlanQuota",
"returns",
"whether",
"the",
"plan",
"would",
"be",
"over",
"quota"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply_not_ent.go#L25-L27 |
133,444 | hashicorp/nomad | client/allocrunner/taskrunner/state/state.go | Canonicalize | func (s *LocalState) Canonicalize() {
if s.Hooks == nil {
// Hooks is nil, create it
s.Hooks = make(map[string]*HookState)
} else {
for k, v := range s.Hooks {
// Remove invalid nil entries from Hooks map
if v == nil {
delete(s.Hooks, k)
}
}
}
} | go | func (s *LocalState) Canonicalize() {
if s.Hooks == nil {
// Hooks is nil, create it
s.Hooks = make(map[string]*HookState)
} else {
for k, v := range s.Hooks {
// Remove invalid nil entries from Hooks map
if v == nil {
delete(s.Hooks, k)
}
}
}
} | [
"func",
"(",
"s",
"*",
"LocalState",
")",
"Canonicalize",
"(",
")",
"{",
"if",
"s",
".",
"Hooks",
"==",
"nil",
"{",
"// Hooks is nil, create it",
"s",
".",
"Hooks",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"HookState",
")",
"\n",
"}",
"else"... | // Canonicalize ensures LocalState is in a consistent state by initializing
// Hooks and ensuring no HookState's are nil. Useful for cleaning unmarshalled
// state which may be in an unknown state. | [
"Canonicalize",
"ensures",
"LocalState",
"is",
"in",
"a",
"consistent",
"state",
"by",
"initializing",
"Hooks",
"and",
"ensuring",
"no",
"HookState",
"s",
"are",
"nil",
".",
"Useful",
"for",
"cleaning",
"unmarshalled",
"state",
"which",
"may",
"be",
"in",
"an"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/state/state.go#L30-L42 |
133,445 | hashicorp/nomad | client/allocrunner/taskrunner/state/state.go | Copy | func (s *LocalState) Copy() *LocalState {
if s == nil {
return nil
}
// Create a copy
c := &LocalState{
Hooks: make(map[string]*HookState, len(s.Hooks)),
DriverNetwork: s.DriverNetwork.Copy(),
TaskHandle: s.TaskHandle.Copy(),
}
// Copy the hook state
for h, state := range s.Hooks {
c.Hooks... | go | func (s *LocalState) Copy() *LocalState {
if s == nil {
return nil
}
// Create a copy
c := &LocalState{
Hooks: make(map[string]*HookState, len(s.Hooks)),
DriverNetwork: s.DriverNetwork.Copy(),
TaskHandle: s.TaskHandle.Copy(),
}
// Copy the hook state
for h, state := range s.Hooks {
c.Hooks... | [
"func",
"(",
"s",
"*",
"LocalState",
")",
"Copy",
"(",
")",
"*",
"LocalState",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Create a copy",
"c",
":=",
"&",
"LocalState",
"{",
"Hooks",
":",
"make",
"(",
"map",
"[",
"stri... | // Copy LocalState. Returns nil if nil. | [
"Copy",
"LocalState",
".",
"Returns",
"nil",
"if",
"nil",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/state/state.go#L45-L63 |
133,446 | hashicorp/nomad | client/allocrunner/taskrunner/state/state.go | Copy | func (h *HookState) Copy() *HookState {
if h == nil {
return nil
}
c := new(HookState)
*c = *h
c.Data = helper.CopyMapStringString(h.Data)
c.Env = helper.CopyMapStringString(h.Env)
return c
} | go | func (h *HookState) Copy() *HookState {
if h == nil {
return nil
}
c := new(HookState)
*c = *h
c.Data = helper.CopyMapStringString(h.Data)
c.Env = helper.CopyMapStringString(h.Env)
return c
} | [
"func",
"(",
"h",
"*",
"HookState",
")",
"Copy",
"(",
")",
"*",
"HookState",
"{",
"if",
"h",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"c",
":=",
"new",
"(",
"HookState",
")",
"\n",
"*",
"c",
"=",
"*",
"h",
"\n",
"c",
".",
"Data",... | // Copy HookState. Returns nil if its nil. | [
"Copy",
"HookState",
".",
"Returns",
"nil",
"if",
"its",
"nil",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/state/state.go#L79-L89 |
133,447 | hashicorp/nomad | helper/fields/data.go | Validate | func (d *FieldData) Validate() error {
var result *multierror.Error
// Scan for missing required fields
for field, schema := range d.Schema {
if schema.Required {
_, ok := d.Raw[field]
if !ok {
result = multierror.Append(result, fmt.Errorf(
"field %q is required", field))
}
}
}
// Validate ... | go | func (d *FieldData) Validate() error {
var result *multierror.Error
// Scan for missing required fields
for field, schema := range d.Schema {
if schema.Required {
_, ok := d.Raw[field]
if !ok {
result = multierror.Append(result, fmt.Errorf(
"field %q is required", field))
}
}
}
// Validate ... | [
"func",
"(",
"d",
"*",
"FieldData",
")",
"Validate",
"(",
")",
"error",
"{",
"var",
"result",
"*",
"multierror",
".",
"Error",
"\n\n",
"// Scan for missing required fields",
"for",
"field",
",",
"schema",
":=",
"range",
"d",
".",
"Schema",
"{",
"if",
"sche... | // Validate cycles through the raw data and validates conversions in the schema.
// It also checks for the existence and value of required fields. | [
"Validate",
"cycles",
"through",
"the",
"raw",
"data",
"and",
"validates",
"conversions",
"in",
"the",
"schema",
".",
"It",
"also",
"checks",
"for",
"the",
"existence",
"and",
"value",
"of",
"required",
"fields",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/fields/data.go#L18-L61 |
133,448 | hashicorp/nomad | helper/fields/data.go | getPrimitive | func (d *FieldData) getPrimitive(
k string, schema *FieldSchema) (interface{}, bool, error) {
raw, ok := d.Raw[k]
if !ok {
return nil, false, nil
}
switch schema.Type {
case TypeBool:
var result bool
if err := mapstructure.Decode(raw, &result); err != nil {
return nil, true, err
}
return result, tru... | go | func (d *FieldData) getPrimitive(
k string, schema *FieldSchema) (interface{}, bool, error) {
raw, ok := d.Raw[k]
if !ok {
return nil, false, nil
}
switch schema.Type {
case TypeBool:
var result bool
if err := mapstructure.Decode(raw, &result); err != nil {
return nil, true, err
}
return result, tru... | [
"func",
"(",
"d",
"*",
"FieldData",
")",
"getPrimitive",
"(",
"k",
"string",
",",
"schema",
"*",
"FieldSchema",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
",",
"error",
")",
"{",
"raw",
",",
"ok",
":=",
"d",
".",
"Raw",
"[",
"k",
"]",
"\n",
... | // getPrimitive tries to convert the raw value of a field to its data type as
// defined in the schema. It does strict type checking, so the value will need
// to be able to convert to the appropriate type directly. | [
"getPrimitive",
"tries",
"to",
"convert",
"the",
"raw",
"value",
"of",
"a",
"field",
"to",
"its",
"data",
"type",
"as",
"defined",
"in",
"the",
"schema",
".",
"It",
"does",
"strict",
"type",
"checking",
"so",
"the",
"value",
"will",
"need",
"to",
"be",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/fields/data.go#L123-L169 |
133,449 | hashicorp/nomad | plugins/shared/structs/attribute.go | Comparable | func (u *Unit) Comparable(o *Unit) bool {
if u == nil || o == nil {
return false
}
return u.Base == o.Base
} | go | func (u *Unit) Comparable(o *Unit) bool {
if u == nil || o == nil {
return false
}
return u.Base == o.Base
} | [
"func",
"(",
"u",
"*",
"Unit",
")",
"Comparable",
"(",
"o",
"*",
"Unit",
")",
"bool",
"{",
"if",
"u",
"==",
"nil",
"||",
"o",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"u",
".",
"Base",
"==",
"o",
".",
"Base",
"\n",
"}... | // Comparable returns if two units are comparable | [
"Comparable",
"returns",
"if",
"two",
"units",
"are",
"comparable"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L48-L54 |
133,450 | hashicorp/nomad | plugins/shared/structs/attribute.go | ParseAttribute | func ParseAttribute(input string) *Attribute {
ll := len(input)
if ll == 0 {
return &Attribute{String: helper.StringToPtr(input)}
}
// Check if the string is a number ending with potential units
var unit string
numeric := input
if unicode.IsLetter(rune(input[ll-1])) {
// Try suffix matching
for _, u := ra... | go | func ParseAttribute(input string) *Attribute {
ll := len(input)
if ll == 0 {
return &Attribute{String: helper.StringToPtr(input)}
}
// Check if the string is a number ending with potential units
var unit string
numeric := input
if unicode.IsLetter(rune(input[ll-1])) {
// Try suffix matching
for _, u := ra... | [
"func",
"ParseAttribute",
"(",
"input",
"string",
")",
"*",
"Attribute",
"{",
"ll",
":=",
"len",
"(",
"input",
")",
"\n",
"if",
"ll",
"==",
"0",
"{",
"return",
"&",
"Attribute",
"{",
"String",
":",
"helper",
".",
"StringToPtr",
"(",
"input",
")",
"}"... | // ParseAttribute takes a string and parses it into an attribute, pulling out
// units if they are specified as a suffix on a number. | [
"ParseAttribute",
"takes",
"a",
"string",
"and",
"parses",
"it",
"into",
"an",
"attribute",
"pulling",
"out",
"units",
"if",
"they",
"are",
"specified",
"as",
"a",
"suffix",
"on",
"a",
"number",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L58-L101 |
133,451 | hashicorp/nomad | plugins/shared/structs/attribute.go | NewIntAttribute | func NewIntAttribute(i int64, unit string) *Attribute {
return &Attribute{
Int: helper.Int64ToPtr(i),
Unit: unit,
}
} | go | func NewIntAttribute(i int64, unit string) *Attribute {
return &Attribute{
Int: helper.Int64ToPtr(i),
Unit: unit,
}
} | [
"func",
"NewIntAttribute",
"(",
"i",
"int64",
",",
"unit",
"string",
")",
"*",
"Attribute",
"{",
"return",
"&",
"Attribute",
"{",
"Int",
":",
"helper",
".",
"Int64ToPtr",
"(",
"i",
")",
",",
"Unit",
":",
"unit",
",",
"}",
"\n",
"}"
] | // NewIntergerAttribute returns a new integer attribute. The unit is not checked
// to be valid. | [
"NewIntergerAttribute",
"returns",
"a",
"new",
"integer",
"attribute",
".",
"The",
"unit",
"is",
"not",
"checked",
"to",
"be",
"valid",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L138-L143 |
133,452 | hashicorp/nomad | plugins/shared/structs/attribute.go | NewFloatAttribute | func NewFloatAttribute(f float64, unit string) *Attribute {
return &Attribute{
Float: helper.Float64ToPtr(f),
Unit: unit,
}
} | go | func NewFloatAttribute(f float64, unit string) *Attribute {
return &Attribute{
Float: helper.Float64ToPtr(f),
Unit: unit,
}
} | [
"func",
"NewFloatAttribute",
"(",
"f",
"float64",
",",
"unit",
"string",
")",
"*",
"Attribute",
"{",
"return",
"&",
"Attribute",
"{",
"Float",
":",
"helper",
".",
"Float64ToPtr",
"(",
"f",
")",
",",
"Unit",
":",
"unit",
",",
"}",
"\n",
"}"
] | // NewFloatAttribute returns a new float attribute. The unit is not checked to
// be valid. | [
"NewFloatAttribute",
"returns",
"a",
"new",
"float",
"attribute",
".",
"The",
"unit",
"is",
"not",
"checked",
"to",
"be",
"valid",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L147-L152 |
133,453 | hashicorp/nomad | plugins/shared/structs/attribute.go | GetString | func (a *Attribute) GetString() (value string, ok bool) {
if a.String == nil {
return "", false
}
return *a.String, true
} | go | func (a *Attribute) GetString() (value string, ok bool) {
if a.String == nil {
return "", false
}
return *a.String, true
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"GetString",
"(",
")",
"(",
"value",
"string",
",",
"ok",
"bool",
")",
"{",
"if",
"a",
".",
"String",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"*",
"a",
".",
"St... | // GetString returns the string value of the attribute or false if the attribute
// doesn't contain a string. | [
"GetString",
"returns",
"the",
"string",
"value",
"of",
"the",
"attribute",
"or",
"false",
"if",
"the",
"attribute",
"doesn",
"t",
"contain",
"a",
"string",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L156-L162 |
133,454 | hashicorp/nomad | plugins/shared/structs/attribute.go | GetBool | func (a *Attribute) GetBool() (value bool, ok bool) {
if a.Bool == nil {
return false, false
}
return *a.Bool, true
} | go | func (a *Attribute) GetBool() (value bool, ok bool) {
if a.Bool == nil {
return false, false
}
return *a.Bool, true
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"GetBool",
"(",
")",
"(",
"value",
"bool",
",",
"ok",
"bool",
")",
"{",
"if",
"a",
".",
"Bool",
"==",
"nil",
"{",
"return",
"false",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"*",
"a",
".",
"Bool",
",",... | // GetBool returns the boolean value of the attribute or false if the attribute
// doesn't contain a boolean. | [
"GetBool",
"returns",
"the",
"boolean",
"value",
"of",
"the",
"attribute",
"or",
"false",
"if",
"the",
"attribute",
"doesn",
"t",
"contain",
"a",
"boolean",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L166-L172 |
133,455 | hashicorp/nomad | plugins/shared/structs/attribute.go | GetInt | func (a *Attribute) GetInt() (value int64, ok bool) {
if a.Int == nil {
return 0, false
}
return *a.Int, true
} | go | func (a *Attribute) GetInt() (value int64, ok bool) {
if a.Int == nil {
return 0, false
}
return *a.Int, true
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"GetInt",
"(",
")",
"(",
"value",
"int64",
",",
"ok",
"bool",
")",
"{",
"if",
"a",
".",
"Int",
"==",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"*",
"a",
".",
"Int",
",",
"tr... | // GetInt returns the integer value of the attribute or false if the attribute
// doesn't contain a integer. | [
"GetInt",
"returns",
"the",
"integer",
"value",
"of",
"the",
"attribute",
"or",
"false",
"if",
"the",
"attribute",
"doesn",
"t",
"contain",
"a",
"integer",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L176-L182 |
133,456 | hashicorp/nomad | plugins/shared/structs/attribute.go | GetFloat | func (a *Attribute) GetFloat() (value float64, ok bool) {
if a.Float == nil {
return 0.0, false
}
return *a.Float, true
} | go | func (a *Attribute) GetFloat() (value float64, ok bool) {
if a.Float == nil {
return 0.0, false
}
return *a.Float, true
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"GetFloat",
"(",
")",
"(",
"value",
"float64",
",",
"ok",
"bool",
")",
"{",
"if",
"a",
".",
"Float",
"==",
"nil",
"{",
"return",
"0.0",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"*",
"a",
".",
"Float",
... | // GetFloat returns the float value of the attribute or false if the attribute
// doesn't contain a float. | [
"GetFloat",
"returns",
"the",
"float",
"value",
"of",
"the",
"attribute",
"or",
"false",
"if",
"the",
"attribute",
"doesn",
"t",
"contain",
"a",
"float",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L186-L192 |
133,457 | hashicorp/nomad | plugins/shared/structs/attribute.go | Copy | func (a *Attribute) Copy() *Attribute {
if a == nil {
return nil
}
ca := &Attribute{
Unit: a.Unit,
}
if a.Float != nil {
ca.Float = helper.Float64ToPtr(*a.Float)
}
if a.Int != nil {
ca.Int = helper.Int64ToPtr(*a.Int)
}
if a.Bool != nil {
ca.Bool = helper.BoolToPtr(*a.Bool)
}
if a.String != nil {
... | go | func (a *Attribute) Copy() *Attribute {
if a == nil {
return nil
}
ca := &Attribute{
Unit: a.Unit,
}
if a.Float != nil {
ca.Float = helper.Float64ToPtr(*a.Float)
}
if a.Int != nil {
ca.Int = helper.Int64ToPtr(*a.Int)
}
if a.Bool != nil {
ca.Bool = helper.BoolToPtr(*a.Bool)
}
if a.String != nil {
... | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"Copy",
"(",
")",
"*",
"Attribute",
"{",
"if",
"a",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"ca",
":=",
"&",
"Attribute",
"{",
"Unit",
":",
"a",
".",
"Unit",
",",
"}",
"\n\n",
"if",
"a",
... | // Copy returns a copied version of the attribute | [
"Copy",
"returns",
"a",
"copied",
"version",
"of",
"the",
"attribute"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L195-L218 |
133,458 | hashicorp/nomad | plugins/shared/structs/attribute.go | GoString | func (a *Attribute) GoString() string {
if a == nil {
return "nil attribute"
}
var b strings.Builder
if a.Float != nil {
b.WriteString(fmt.Sprintf("%v", *a.Float))
} else if a.Int != nil {
b.WriteString(fmt.Sprintf("%v", *a.Int))
} else if a.Bool != nil {
b.WriteString(fmt.Sprintf("%v", *a.Bool))
} else... | go | func (a *Attribute) GoString() string {
if a == nil {
return "nil attribute"
}
var b strings.Builder
if a.Float != nil {
b.WriteString(fmt.Sprintf("%v", *a.Float))
} else if a.Int != nil {
b.WriteString(fmt.Sprintf("%v", *a.Int))
} else if a.Bool != nil {
b.WriteString(fmt.Sprintf("%v", *a.Bool))
} else... | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"GoString",
"(",
")",
"string",
"{",
"if",
"a",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"var",
"b",
"strings",
".",
"Builder",
"\n",
"if",
"a",
".",
"Float",
"!=",
"nil",
"{",
"b",
"."... | // GoString returns a string representation of the attribute | [
"GoString",
"returns",
"a",
"string",
"representation",
"of",
"the",
"attribute"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L221-L242 |
133,459 | hashicorp/nomad | plugins/shared/structs/attribute.go | Validate | func (a *Attribute) Validate() error {
if a.Unit != "" {
if _, ok := UnitIndex[a.Unit]; !ok {
return fmt.Errorf("unrecognized unit %q", a.Unit)
}
// Check only int/float set
if a.String != nil || a.Bool != nil {
return fmt.Errorf("unit can not be specified on a boolean or string attribute")
}
}
// ... | go | func (a *Attribute) Validate() error {
if a.Unit != "" {
if _, ok := UnitIndex[a.Unit]; !ok {
return fmt.Errorf("unrecognized unit %q", a.Unit)
}
// Check only int/float set
if a.String != nil || a.Bool != nil {
return fmt.Errorf("unit can not be specified on a boolean or string attribute")
}
}
// ... | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"a",
".",
"Unit",
"!=",
"\"",
"\"",
"{",
"if",
"_",
",",
"ok",
":=",
"UnitIndex",
"[",
"a",
".",
"Unit",
"]",
";",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Error... | // Validate checks if the attribute is valid | [
"Validate",
"checks",
"if",
"the",
"attribute",
"is",
"valid"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L245-L279 |
133,460 | hashicorp/nomad | plugins/shared/structs/attribute.go | Comparable | func (a *Attribute) Comparable(b *Attribute) bool {
if a == nil || b == nil {
return false
}
// First use the units to decide if comparison is possible
aUnit := a.getTypedUnit()
bUnit := b.getTypedUnit()
if aUnit != nil && bUnit != nil {
return aUnit.Comparable(bUnit)
} else if aUnit != nil && bUnit == nil ... | go | func (a *Attribute) Comparable(b *Attribute) bool {
if a == nil || b == nil {
return false
}
// First use the units to decide if comparison is possible
aUnit := a.getTypedUnit()
bUnit := b.getTypedUnit()
if aUnit != nil && bUnit != nil {
return aUnit.Comparable(bUnit)
} else if aUnit != nil && bUnit == nil ... | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"Comparable",
"(",
"b",
"*",
"Attribute",
")",
"bool",
"{",
"if",
"a",
"==",
"nil",
"||",
"b",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// First use the units to decide if comparison is possible",
"aUn... | // Comparable returns whether the two attributes are comparable | [
"Comparable",
"returns",
"whether",
"the",
"two",
"attributes",
"are",
"comparable"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L282-L312 |
133,461 | hashicorp/nomad | plugins/shared/structs/attribute.go | comparator | func (a *Attribute) comparator() compareFn {
if a.Bool != nil {
return a.boolComparator
}
if a.String != nil {
return a.stringComparator
}
if a.Int != nil || a.Float != nil {
return a.numberComparator
}
return nullComparator
} | go | func (a *Attribute) comparator() compareFn {
if a.Bool != nil {
return a.boolComparator
}
if a.String != nil {
return a.stringComparator
}
if a.Int != nil || a.Float != nil {
return a.numberComparator
}
return nullComparator
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"comparator",
"(",
")",
"compareFn",
"{",
"if",
"a",
".",
"Bool",
"!=",
"nil",
"{",
"return",
"a",
".",
"boolComparator",
"\n",
"}",
"\n",
"if",
"a",
".",
"String",
"!=",
"nil",
"{",
"return",
"a",
".",
"s... | // comparator returns the comparator function for the attribute | [
"comparator",
"returns",
"the",
"comparator",
"function",
"for",
"the",
"attribute"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L328-L340 |
133,462 | hashicorp/nomad | plugins/shared/structs/attribute.go | boolComparator | func (a *Attribute) boolComparator(b *Attribute) (int, bool) {
if *a.Bool == *b.Bool {
return 0, true
}
return 1, true
} | go | func (a *Attribute) boolComparator(b *Attribute) (int, bool) {
if *a.Bool == *b.Bool {
return 0, true
}
return 1, true
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"boolComparator",
"(",
"b",
"*",
"Attribute",
")",
"(",
"int",
",",
"bool",
")",
"{",
"if",
"*",
"a",
".",
"Bool",
"==",
"*",
"b",
".",
"Bool",
"{",
"return",
"0",
",",
"true",
"\n",
"}",
"\n\n",
"return... | // boolComparator compares two boolean attributes | [
"boolComparator",
"compares",
"two",
"boolean",
"attributes"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L343-L349 |
133,463 | hashicorp/nomad | plugins/shared/structs/attribute.go | stringComparator | func (a *Attribute) stringComparator(b *Attribute) (int, bool) {
return strings.Compare(*a.String, *b.String), true
} | go | func (a *Attribute) stringComparator(b *Attribute) (int, bool) {
return strings.Compare(*a.String, *b.String), true
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"stringComparator",
"(",
"b",
"*",
"Attribute",
")",
"(",
"int",
",",
"bool",
")",
"{",
"return",
"strings",
".",
"Compare",
"(",
"*",
"a",
".",
"String",
",",
"*",
"b",
".",
"String",
")",
",",
"true",
"\... | // stringComparator compares two string attributes | [
"stringComparator",
"compares",
"two",
"string",
"attributes"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L352-L354 |
133,464 | hashicorp/nomad | plugins/shared/structs/attribute.go | numberComparator | func (a *Attribute) numberComparator(b *Attribute) (int, bool) {
// If they are both integers we do perfect precision comparisons
if a.Int != nil && b.Int != nil {
return a.intComparator(b)
}
// Push both into the float space
af := a.getBigFloat()
bf := b.getBigFloat()
if af == nil || bf == nil {
return 0, ... | go | func (a *Attribute) numberComparator(b *Attribute) (int, bool) {
// If they are both integers we do perfect precision comparisons
if a.Int != nil && b.Int != nil {
return a.intComparator(b)
}
// Push both into the float space
af := a.getBigFloat()
bf := b.getBigFloat()
if af == nil || bf == nil {
return 0, ... | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"numberComparator",
"(",
"b",
"*",
"Attribute",
")",
"(",
"int",
",",
"bool",
")",
"{",
"// If they are both integers we do perfect precision comparisons",
"if",
"a",
".",
"Int",
"!=",
"nil",
"&&",
"b",
".",
"Int",
"!... | // numberComparator compares two number attributes, having either Int or Float
// set. | [
"numberComparator",
"compares",
"two",
"number",
"attributes",
"having",
"either",
"Int",
"or",
"Float",
"set",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L358-L372 |
133,465 | hashicorp/nomad | plugins/shared/structs/attribute.go | intComparator | func (a *Attribute) intComparator(b *Attribute) (int, bool) {
ai := a.getInt()
bi := b.getInt()
if ai == bi {
return 0, true
} else if ai < bi {
return -1, true
} else {
return 1, true
}
} | go | func (a *Attribute) intComparator(b *Attribute) (int, bool) {
ai := a.getInt()
bi := b.getInt()
if ai == bi {
return 0, true
} else if ai < bi {
return -1, true
} else {
return 1, true
}
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"intComparator",
"(",
"b",
"*",
"Attribute",
")",
"(",
"int",
",",
"bool",
")",
"{",
"ai",
":=",
"a",
".",
"getInt",
"(",
")",
"\n",
"bi",
":=",
"b",
".",
"getInt",
"(",
")",
"\n\n",
"if",
"ai",
"==",
... | // intComparator compares two integer attributes. | [
"intComparator",
"compares",
"two",
"integer",
"attributes",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L375-L386 |
133,466 | hashicorp/nomad | plugins/shared/structs/attribute.go | getBigFloat | func (a *Attribute) getBigFloat() *big.Float {
f := new(big.Float)
f.SetPrec(floatPrecision)
if a.Int != nil {
f.SetInt64(*a.Int)
} else if a.Float != nil {
f.SetFloat64(*a.Float)
} else {
return nil
}
// Get the unit
u := a.getTypedUnit()
// If there is no unit just return the float
if u == nil {
r... | go | func (a *Attribute) getBigFloat() *big.Float {
f := new(big.Float)
f.SetPrec(floatPrecision)
if a.Int != nil {
f.SetInt64(*a.Int)
} else if a.Float != nil {
f.SetFloat64(*a.Float)
} else {
return nil
}
// Get the unit
u := a.getTypedUnit()
// If there is no unit just return the float
if u == nil {
r... | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"getBigFloat",
"(",
")",
"*",
"big",
".",
"Float",
"{",
"f",
":=",
"new",
"(",
"big",
".",
"Float",
")",
"\n",
"f",
".",
"SetPrec",
"(",
"floatPrecision",
")",
"\n",
"if",
"a",
".",
"Int",
"!=",
"nil",
"... | // getBigFloat returns a big.Float representation of the attribute, converting
// the value to the base unit if a unit is specified. | [
"getBigFloat",
"returns",
"a",
"big",
".",
"Float",
"representation",
"of",
"the",
"attribute",
"converting",
"the",
"value",
"to",
"the",
"base",
"unit",
"if",
"a",
"unit",
"is",
"specified",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L400-L431 |
133,467 | hashicorp/nomad | plugins/shared/structs/attribute.go | getInt | func (a *Attribute) getInt() int64 {
if a.Int == nil {
return 0
}
i := *a.Int
// Get the unit
u := a.getTypedUnit()
// If there is no unit just return the int
if u == nil {
return i
}
if u.InverseMultiplier {
i /= u.Multiplier
} else {
i *= u.Multiplier
}
return i
} | go | func (a *Attribute) getInt() int64 {
if a.Int == nil {
return 0
}
i := *a.Int
// Get the unit
u := a.getTypedUnit()
// If there is no unit just return the int
if u == nil {
return i
}
if u.InverseMultiplier {
i /= u.Multiplier
} else {
i *= u.Multiplier
}
return i
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"getInt",
"(",
")",
"int64",
"{",
"if",
"a",
".",
"Int",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"i",
":=",
"*",
"a",
".",
"Int",
"\n\n",
"// Get the unit",
"u",
":=",
"a",
".",
"getTypedUnit",... | // getInt returns an int representation of the attribute, converting
// the value to the base unit if a unit is specified. | [
"getInt",
"returns",
"an",
"int",
"representation",
"of",
"the",
"attribute",
"converting",
"the",
"value",
"to",
"the",
"base",
"unit",
"if",
"a",
"unit",
"is",
"specified",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/shared/structs/attribute.go#L435-L457 |
133,468 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner_hooks.go | initHooks | func (tr *TaskRunner) initHooks() {
hookLogger := tr.logger.Named("task_hook")
task := tr.Task()
tr.logmonHookConfig = newLogMonHookConfig(task.Name, tr.taskDir.LogDir)
// Add the hook resources
tr.hookResources = &hookResources{}
// Create the task directory hook. This is run first to ensure the
// directory... | go | func (tr *TaskRunner) initHooks() {
hookLogger := tr.logger.Named("task_hook")
task := tr.Task()
tr.logmonHookConfig = newLogMonHookConfig(task.Name, tr.taskDir.LogDir)
// Add the hook resources
tr.hookResources = &hookResources{}
// Create the task directory hook. This is run first to ensure the
// directory... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"initHooks",
"(",
")",
"{",
"hookLogger",
":=",
"tr",
".",
"logger",
".",
"Named",
"(",
"\"",
"\"",
")",
"\n",
"task",
":=",
"tr",
".",
"Task",
"(",
")",
"\n\n",
"tr",
".",
"logmonHookConfig",
"=",
"newLog... | // initHooks intializes the tasks hooks. | [
"initHooks",
"intializes",
"the",
"tasks",
"hooks",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner_hooks.go#L48-L105 |
133,469 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner_hooks.go | poststart | func (tr *TaskRunner) poststart() error {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running poststart hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished poststart hooks", "end", end, "duration", end.Sub(start))
}()
}
handle := tr.getDriverHandle()
n... | go | func (tr *TaskRunner) poststart() error {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running poststart hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished poststart hooks", "end", end, "duration", end.Sub(start))
}()
}
handle := tr.getDriverHandle()
n... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"poststart",
"(",
")",
"error",
"{",
"if",
"tr",
".",
"logger",
".",
"IsTrace",
"(",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"tr",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
","... | // poststart is used to run the runners poststart hooks. | [
"poststart",
"is",
"used",
"to",
"run",
"the",
"runners",
"poststart",
"hooks",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner_hooks.go#L234-L286 |
133,470 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner_hooks.go | exited | func (tr *TaskRunner) exited() error {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running exited hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished exited hooks", "end", end, "duration", end.Sub(start))
}()
}
var merr multierror.Error
for _, hook := ... | go | func (tr *TaskRunner) exited() error {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running exited hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished exited hooks", "end", end, "duration", end.Sub(start))
}()
}
var merr multierror.Error
for _, hook := ... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"exited",
"(",
")",
"error",
"{",
"if",
"tr",
".",
"logger",
".",
"IsTrace",
"(",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"tr",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
",",
... | // exited is used to run the exited hooks before a task is stopped. | [
"exited",
"is",
"used",
"to",
"run",
"the",
"exited",
"hooks",
"before",
"a",
"task",
"is",
"stopped",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner_hooks.go#L289-L330 |
133,471 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner_hooks.go | stop | func (tr *TaskRunner) stop() error {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running stop hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished stop hooks", "end", end, "duration", end.Sub(start))
}()
}
var merr multierror.Error
for _, hook := range ... | go | func (tr *TaskRunner) stop() error {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running stop hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished stop hooks", "end", end, "duration", end.Sub(start))
}()
}
var merr multierror.Error
for _, hook := range ... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"stop",
"(",
")",
"error",
"{",
"if",
"tr",
".",
"logger",
".",
"IsTrace",
"(",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"tr",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
",",
"... | // stop is used to run the stop hooks. | [
"stop",
"is",
"used",
"to",
"run",
"the",
"stop",
"hooks",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner_hooks.go#L333-L381 |
133,472 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner_hooks.go | preKill | func (tr *TaskRunner) preKill() {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running pre kill hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished pre kill hooks", "end", end, "duration", end.Sub(start))
}()
}
for _, hook := range tr.runnerHooks {
kil... | go | func (tr *TaskRunner) preKill() {
if tr.logger.IsTrace() {
start := time.Now()
tr.logger.Trace("running pre kill hooks", "start", start)
defer func() {
end := time.Now()
tr.logger.Trace("finished pre kill hooks", "end", end, "duration", end.Sub(start))
}()
}
for _, hook := range tr.runnerHooks {
kil... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"preKill",
"(",
")",
"{",
"if",
"tr",
".",
"logger",
".",
"IsTrace",
"(",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"tr",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
",",
"\"",
"... | // preKill is used to run the runners preKill hooks
// preKill hooks contain logic that must be executed before
// a task is killed or restarted | [
"preKill",
"is",
"used",
"to",
"run",
"the",
"runners",
"preKill",
"hooks",
"preKill",
"hooks",
"contain",
"logic",
"that",
"must",
"be",
"executed",
"before",
"a",
"task",
"is",
"killed",
"or",
"restarted"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner_hooks.go#L441-L481 |
133,473 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner_hooks.go | shutdownHooks | func (tr *TaskRunner) shutdownHooks() {
for _, hook := range tr.runnerHooks {
sh, ok := hook.(interfaces.ShutdownHook)
if !ok {
continue
}
name := sh.Name()
// Time the update hook
var start time.Time
if tr.logger.IsTrace() {
start = time.Now()
tr.logger.Trace("running shutdown hook", "name", ... | go | func (tr *TaskRunner) shutdownHooks() {
for _, hook := range tr.runnerHooks {
sh, ok := hook.(interfaces.ShutdownHook)
if !ok {
continue
}
name := sh.Name()
// Time the update hook
var start time.Time
if tr.logger.IsTrace() {
start = time.Now()
tr.logger.Trace("running shutdown hook", "name", ... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"shutdownHooks",
"(",
")",
"{",
"for",
"_",
",",
"hook",
":=",
"range",
"tr",
".",
"runnerHooks",
"{",
"sh",
",",
"ok",
":=",
"hook",
".",
"(",
"interfaces",
".",
"ShutdownHook",
")",
"\n",
"if",
"!",
"ok"... | // shutdownHooks is called when the TaskRunner is gracefully shutdown but the
// task is not being stopped or garbage collected. | [
"shutdownHooks",
"is",
"called",
"when",
"the",
"TaskRunner",
"is",
"gracefully",
"shutdown",
"but",
"the",
"task",
"is",
"not",
"being",
"stopped",
"or",
"garbage",
"collected",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner_hooks.go#L485-L508 |
133,474 | hashicorp/nomad | nomad/search_endpoint_oss.go | getEnterpriseResourceIter | func getEnterpriseResourceIter(context structs.Context, _ *acl.ACL, namespace, prefix string, ws memdb.WatchSet, state *state.StateStore) (memdb.ResultIterator, error) {
// If we have made it here then it is an error since we have exhausted all
// open source contexts.
return nil, fmt.Errorf("context must be one of ... | go | func getEnterpriseResourceIter(context structs.Context, _ *acl.ACL, namespace, prefix string, ws memdb.WatchSet, state *state.StateStore) (memdb.ResultIterator, error) {
// If we have made it here then it is an error since we have exhausted all
// open source contexts.
return nil, fmt.Errorf("context must be one of ... | [
"func",
"getEnterpriseResourceIter",
"(",
"context",
"structs",
".",
"Context",
",",
"_",
"*",
"acl",
".",
"ACL",
",",
"namespace",
",",
"prefix",
"string",
",",
"ws",
"memdb",
".",
"WatchSet",
",",
"state",
"*",
"state",
".",
"StateStore",
")",
"(",
"me... | // getEnterpriseResourceIter is used to retrieve an iterator over an enterprise
// only table. | [
"getEnterpriseResourceIter",
"is",
"used",
"to",
"retrieve",
"an",
"iterator",
"over",
"an",
"enterprise",
"only",
"table",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/search_endpoint_oss.go#L32-L36 |
133,475 | hashicorp/nomad | nomad/search_endpoint_oss.go | anySearchPerms | func anySearchPerms(aclObj *acl.ACL, namespace string, context structs.Context) bool {
if aclObj == nil {
return true
}
nodeRead := aclObj.AllowNodeRead()
jobRead := aclObj.AllowNsOp(namespace, acl.NamespaceCapabilityReadJob)
if !nodeRead && !jobRead {
return false
}
// Reject requests that explicitly spec... | go | func anySearchPerms(aclObj *acl.ACL, namespace string, context structs.Context) bool {
if aclObj == nil {
return true
}
nodeRead := aclObj.AllowNodeRead()
jobRead := aclObj.AllowNsOp(namespace, acl.NamespaceCapabilityReadJob)
if !nodeRead && !jobRead {
return false
}
// Reject requests that explicitly spec... | [
"func",
"anySearchPerms",
"(",
"aclObj",
"*",
"acl",
".",
"ACL",
",",
"namespace",
"string",
",",
"context",
"structs",
".",
"Context",
")",
"bool",
"{",
"if",
"aclObj",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"nodeRead",
":=",
"aclObj",
... | // anySearchPerms returns true if the provided ACL has access to any
// capabilities required for prefix searching. Returns true if aclObj is nil. | [
"anySearchPerms",
"returns",
"true",
"if",
"the",
"provided",
"ACL",
"has",
"access",
"to",
"any",
"capabilities",
"required",
"for",
"prefix",
"searching",
".",
"Returns",
"true",
"if",
"aclObj",
"is",
"nil",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/search_endpoint_oss.go#L40-L65 |
133,476 | hashicorp/nomad | nomad/search_endpoint_oss.go | searchContexts | func searchContexts(aclObj *acl.ACL, namespace string, context structs.Context) []structs.Context {
var all []structs.Context
switch context {
case structs.All:
all = make([]structs.Context, len(allContexts))
copy(all, allContexts)
default:
all = []structs.Context{context}
}
// If ACLs aren't enabled retu... | go | func searchContexts(aclObj *acl.ACL, namespace string, context structs.Context) []structs.Context {
var all []structs.Context
switch context {
case structs.All:
all = make([]structs.Context, len(allContexts))
copy(all, allContexts)
default:
all = []structs.Context{context}
}
// If ACLs aren't enabled retu... | [
"func",
"searchContexts",
"(",
"aclObj",
"*",
"acl",
".",
"ACL",
",",
"namespace",
"string",
",",
"context",
"structs",
".",
"Context",
")",
"[",
"]",
"structs",
".",
"Context",
"{",
"var",
"all",
"[",
"]",
"structs",
".",
"Context",
"\n\n",
"switch",
... | // searchContexts returns the contexts the aclObj is valid for. If aclObj is
// nil all contexts are returned. | [
"searchContexts",
"returns",
"the",
"contexts",
"the",
"aclObj",
"is",
"valid",
"for",
".",
"If",
"aclObj",
"is",
"nil",
"all",
"contexts",
"are",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/search_endpoint_oss.go#L69-L102 |
133,477 | hashicorp/nomad | plugins/drivers/driver.go | Copy | func (d *DriverNetwork) Copy() *DriverNetwork {
if d == nil {
return nil
}
pm := make(map[string]int, len(d.PortMap))
for k, v := range d.PortMap {
pm[k] = v
}
return &DriverNetwork{
PortMap: pm,
IP: d.IP,
AutoAdvertise: d.AutoAdvertise,
}
} | go | func (d *DriverNetwork) Copy() *DriverNetwork {
if d == nil {
return nil
}
pm := make(map[string]int, len(d.PortMap))
for k, v := range d.PortMap {
pm[k] = v
}
return &DriverNetwork{
PortMap: pm,
IP: d.IP,
AutoAdvertise: d.AutoAdvertise,
}
} | [
"func",
"(",
"d",
"*",
"DriverNetwork",
")",
"Copy",
"(",
")",
"*",
"DriverNetwork",
"{",
"if",
"d",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"pm",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"d",
".",
"Port... | // Copy a DriverNetwork struct. If it is nil, nil is returned. | [
"Copy",
"a",
"DriverNetwork",
"struct",
".",
"If",
"it",
"is",
"nil",
"nil",
"is",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/drivers/driver.go#L379-L392 |
133,478 | hashicorp/nomad | plugins/drivers/driver.go | Hash | func (d *DriverNetwork) Hash() []byte {
if d == nil {
return []byte{}
}
h := md5.New()
io.WriteString(h, d.IP)
io.WriteString(h, strconv.FormatBool(d.AutoAdvertise))
for k, v := range d.PortMap {
io.WriteString(h, k)
io.WriteString(h, strconv.Itoa(v))
}
return h.Sum(nil)
} | go | func (d *DriverNetwork) Hash() []byte {
if d == nil {
return []byte{}
}
h := md5.New()
io.WriteString(h, d.IP)
io.WriteString(h, strconv.FormatBool(d.AutoAdvertise))
for k, v := range d.PortMap {
io.WriteString(h, k)
io.WriteString(h, strconv.Itoa(v))
}
return h.Sum(nil)
} | [
"func",
"(",
"d",
"*",
"DriverNetwork",
")",
"Hash",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"d",
"==",
"nil",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",
"\n",
"}",
"\n",
"h",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
"io",
".",
"WriteString",
... | // Hash the contents of a DriverNetwork struct to detect changes. If it is nil,
// an empty slice is returned. | [
"Hash",
"the",
"contents",
"of",
"a",
"DriverNetwork",
"struct",
"to",
"detect",
"changes",
".",
"If",
"it",
"is",
"nil",
"an",
"empty",
"slice",
"is",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/plugins/drivers/driver.go#L396-L408 |
133,479 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | handleTaskExitResult | func (tr *TaskRunner) handleTaskExitResult(result *drivers.ExitResult) (retryWait bool) {
if result == nil {
return false
}
if result.Err == bstructs.ErrPluginShutdown {
dn := tr.Task().Driver
tr.logger.Debug("driver plugin has shutdown; attempting to recover task", "driver", dn)
// Initialize a new driver... | go | func (tr *TaskRunner) handleTaskExitResult(result *drivers.ExitResult) (retryWait bool) {
if result == nil {
return false
}
if result.Err == bstructs.ErrPluginShutdown {
dn := tr.Task().Driver
tr.logger.Debug("driver plugin has shutdown; attempting to recover task", "driver", dn)
// Initialize a new driver... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"handleTaskExitResult",
"(",
"result",
"*",
"drivers",
".",
"ExitResult",
")",
"(",
"retryWait",
"bool",
")",
"{",
"if",
"result",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"result",
".",
"... | // handleTaskExitResult handles the results returned by the task exiting. If
// retryWait is true, the caller should attempt to wait on the task again since
// it has not actually finished running. This can happen if the driver plugin
// has exited. | [
"handleTaskExitResult",
"handles",
"the",
"results",
"returned",
"by",
"the",
"task",
"exiting",
".",
"If",
"retryWait",
"is",
"true",
"the",
"caller",
"should",
"attempt",
"to",
"wait",
"on",
"the",
"task",
"again",
"since",
"it",
"has",
"not",
"actually",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L513-L546 |
133,480 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | emitExitResultEvent | func (tr *TaskRunner) emitExitResultEvent(result *drivers.ExitResult) {
event := structs.NewTaskEvent(structs.TaskTerminated).
SetExitCode(result.ExitCode).
SetSignal(result.Signal).
SetOOMKilled(result.OOMKilled).
SetExitMessage(result.Err)
tr.EmitEvent(event)
if result.OOMKilled && !tr.clientConfig.Disab... | go | func (tr *TaskRunner) emitExitResultEvent(result *drivers.ExitResult) {
event := structs.NewTaskEvent(structs.TaskTerminated).
SetExitCode(result.ExitCode).
SetSignal(result.Signal).
SetOOMKilled(result.OOMKilled).
SetExitMessage(result.Err)
tr.EmitEvent(event)
if result.OOMKilled && !tr.clientConfig.Disab... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"emitExitResultEvent",
"(",
"result",
"*",
"drivers",
".",
"ExitResult",
")",
"{",
"event",
":=",
"structs",
".",
"NewTaskEvent",
"(",
"structs",
".",
"TaskTerminated",
")",
".",
"SetExitCode",
"(",
"result",
".",
... | // emitExitResultEvent emits a TaskTerminated event for an ExitResult. | [
"emitExitResultEvent",
"emits",
"a",
"TaskTerminated",
"event",
"for",
"an",
"ExitResult",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L549-L561 |
133,481 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | shouldRestart | func (tr *TaskRunner) shouldRestart() (bool, time.Duration) {
// Determine if we should restart
state, when := tr.restartTracker.GetState()
reason := tr.restartTracker.GetReason()
switch state {
case structs.TaskKilled:
// Never restart an explicitly killed task. Kill method handles
// updating the server.
t... | go | func (tr *TaskRunner) shouldRestart() (bool, time.Duration) {
// Determine if we should restart
state, when := tr.restartTracker.GetState()
reason := tr.restartTracker.GetReason()
switch state {
case structs.TaskKilled:
// Never restart an explicitly killed task. Kill method handles
// updating the server.
t... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"shouldRestart",
"(",
")",
"(",
"bool",
",",
"time",
".",
"Duration",
")",
"{",
"// Determine if we should restart",
"state",
",",
"when",
":=",
"tr",
".",
"restartTracker",
".",
"GetState",
"(",
")",
"\n",
"reaso... | // shouldRestart determines whether the task should be restarted and updates
// the task state unless the task is killed or terminated. | [
"shouldRestart",
"determines",
"whether",
"the",
"task",
"should",
"be",
"restarted",
"and",
"updates",
"the",
"task",
"state",
"unless",
"the",
"task",
"is",
"killed",
"or",
"terminated",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L580-L604 |
133,482 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | initDriver | func (tr *TaskRunner) initDriver() error {
driver, err := tr.driverManager.Dispense(tr.Task().Driver)
if err != nil {
return err
}
tr.driver = driver
schema, err := tr.driver.TaskConfigSchema()
if err != nil {
return err
}
spec, diag := hclspecutils.Convert(schema)
if diag.HasErrors() {
return multierro... | go | func (tr *TaskRunner) initDriver() error {
driver, err := tr.driverManager.Dispense(tr.Task().Driver)
if err != nil {
return err
}
tr.driver = driver
schema, err := tr.driver.TaskConfigSchema()
if err != nil {
return err
}
spec, diag := hclspecutils.Convert(schema)
if diag.HasErrors() {
return multierro... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"initDriver",
"(",
")",
"error",
"{",
"driver",
",",
"err",
":=",
"tr",
".",
"driverManager",
".",
"Dispense",
"(",
"tr",
".",
"Task",
"(",
")",
".",
"Driver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // initDriver retrives the DriverPlugin from the plugin loader for this task | [
"initDriver",
"retrives",
"the",
"DriverPlugin",
"from",
"the",
"plugin",
"loader",
"for",
"this",
"task"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L695-L719 |
133,483 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | handleKill | func (tr *TaskRunner) handleKill() *drivers.ExitResult {
// Run the pre killing hooks
tr.preKill()
// Tell the restart tracker that the task has been killed so it doesn't
// attempt to restart it.
tr.restartTracker.SetKilled()
// Check it is running
handle := tr.getDriverHandle()
if handle == nil {
return n... | go | func (tr *TaskRunner) handleKill() *drivers.ExitResult {
// Run the pre killing hooks
tr.preKill()
// Tell the restart tracker that the task has been killed so it doesn't
// attempt to restart it.
tr.restartTracker.SetKilled()
// Check it is running
handle := tr.getDriverHandle()
if handle == nil {
return n... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"handleKill",
"(",
")",
"*",
"drivers",
".",
"ExitResult",
"{",
"// Run the pre killing hooks",
"tr",
".",
"preKill",
"(",
")",
"\n\n",
"// Tell the restart tracker that the task has been killed so it doesn't",
"// attempt to res... | // handleKill is used to handle the a request to kill a task. It will return
// the handle exit result if one is available and store any error in the task
// runner killErr value. | [
"handleKill",
"is",
"used",
"to",
"handle",
"the",
"a",
"request",
"to",
"kill",
"a",
"task",
".",
"It",
"will",
"return",
"the",
"handle",
"exit",
"result",
"if",
"one",
"is",
"available",
"and",
"store",
"any",
"error",
"in",
"the",
"task",
"runner",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L724-L766 |
133,484 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | killTask | func (tr *TaskRunner) killTask(handle *DriverHandle) error {
// Cap the number of times we attempt to kill the task.
var err error
for i := 0; i < killFailureLimit; i++ {
if err = handle.Kill(); err != nil {
if err == drivers.ErrTaskNotFound {
tr.logger.Warn("couldn't find task to kill", "task_id", handle.I... | go | func (tr *TaskRunner) killTask(handle *DriverHandle) error {
// Cap the number of times we attempt to kill the task.
var err error
for i := 0; i < killFailureLimit; i++ {
if err = handle.Kill(); err != nil {
if err == drivers.ErrTaskNotFound {
tr.logger.Warn("couldn't find task to kill", "task_id", handle.I... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"killTask",
"(",
"handle",
"*",
"DriverHandle",
")",
"error",
"{",
"// Cap the number of times we attempt to kill the task.",
"var",
"err",
"error",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"killFailureLimit",
";",
... | // killTask kills the task handle. In the case that killing fails,
// killTask will retry with an exponential backoff and will give up at a
// given limit. Returns an error if the task could not be killed. | [
"killTask",
"kills",
"the",
"task",
"handle",
".",
"In",
"the",
"case",
"that",
"killing",
"fails",
"killTask",
"will",
"retry",
"with",
"an",
"exponential",
"backoff",
"and",
"will",
"give",
"up",
"at",
"a",
"given",
"limit",
".",
"Returns",
"an",
"error"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L771-L794 |
133,485 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | persistLocalState | func (tr *TaskRunner) persistLocalState() error {
tr.stateLock.RLock()
defer tr.stateLock.RUnlock()
return tr.stateDB.PutTaskRunnerLocalState(tr.allocID, tr.taskName, tr.localState)
} | go | func (tr *TaskRunner) persistLocalState() error {
tr.stateLock.RLock()
defer tr.stateLock.RUnlock()
return tr.stateDB.PutTaskRunnerLocalState(tr.allocID, tr.taskName, tr.localState)
} | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"persistLocalState",
"(",
")",
"error",
"{",
"tr",
".",
"stateLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tr",
".",
"stateLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"tr",
".",
"stateDB",
".",
"Put... | // persistLocalState persists local state to disk synchronously. | [
"persistLocalState",
"persists",
"local",
"state",
"to",
"disk",
"synchronously",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L797-L802 |
133,486 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | buildTaskConfig | func (tr *TaskRunner) buildTaskConfig() *drivers.TaskConfig {
task := tr.Task()
alloc := tr.Alloc()
invocationid := uuid.Generate()[:8]
taskResources := tr.taskResources
env := tr.envBuilder.Build()
return &drivers.TaskConfig{
ID: fmt.Sprintf("%s/%s/%s", alloc.ID, task.Name, invocationid),
Name: ... | go | func (tr *TaskRunner) buildTaskConfig() *drivers.TaskConfig {
task := tr.Task()
alloc := tr.Alloc()
invocationid := uuid.Generate()[:8]
taskResources := tr.taskResources
env := tr.envBuilder.Build()
return &drivers.TaskConfig{
ID: fmt.Sprintf("%s/%s/%s", alloc.ID, task.Name, invocationid),
Name: ... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"buildTaskConfig",
"(",
")",
"*",
"drivers",
".",
"TaskConfig",
"{",
"task",
":=",
"tr",
".",
"Task",
"(",
")",
"\n",
"alloc",
":=",
"tr",
".",
"Alloc",
"(",
")",
"\n",
"invocationid",
":=",
"uuid",
".",
"... | // buildTaskConfig builds a drivers.TaskConfig with an unique ID for the task.
// The ID is unique for every invocation, it is built from the alloc ID, task
// name and 8 random characters. | [
"buildTaskConfig",
"builds",
"a",
"drivers",
".",
"TaskConfig",
"with",
"an",
"unique",
"ID",
"for",
"the",
"task",
".",
"The",
"ID",
"is",
"unique",
"for",
"every",
"invocation",
"it",
"is",
"built",
"from",
"the",
"alloc",
"ID",
"task",
"name",
"and",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L807-L837 |
133,487 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | Restore | func (tr *TaskRunner) Restore() error {
ls, ts, err := tr.stateDB.GetTaskRunnerState(tr.allocID, tr.taskName)
if err != nil {
return err
}
if ls != nil {
ls.Canonicalize()
tr.localState = ls
}
if ts != nil {
ts.Canonicalize()
tr.state = ts
}
// If a TaskHandle was persisted, ensure it is valid or d... | go | func (tr *TaskRunner) Restore() error {
ls, ts, err := tr.stateDB.GetTaskRunnerState(tr.allocID, tr.taskName)
if err != nil {
return err
}
if ls != nil {
ls.Canonicalize()
tr.localState = ls
}
if ts != nil {
ts.Canonicalize()
tr.state = ts
}
// If a TaskHandle was persisted, ensure it is valid or d... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"Restore",
"(",
")",
"error",
"{",
"ls",
",",
"ts",
",",
"err",
":=",
"tr",
".",
"stateDB",
".",
"GetTaskRunnerState",
"(",
"tr",
".",
"allocID",
",",
"tr",
".",
"taskName",
")",
"\n",
"if",
"err",
"!=",
... | // Restore task runner state. Called by AllocRunner.Restore after NewTaskRunner
// but before Run so no locks need to be acquired. | [
"Restore",
"task",
"runner",
"state",
".",
"Called",
"by",
"AllocRunner",
".",
"Restore",
"after",
"NewTaskRunner",
"but",
"before",
"Run",
"so",
"no",
"locks",
"need",
"to",
"be",
"acquired",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L841-L864 |
133,488 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | restoreHandle | func (tr *TaskRunner) restoreHandle(taskHandle *drivers.TaskHandle, net *drivers.DriverNetwork) (success bool) {
// Ensure handle is well-formed
if taskHandle.Config == nil {
return true
}
if err := tr.driver.RecoverTask(taskHandle); err != nil {
if tr.TaskState().State != structs.TaskStateRunning {
// Reco... | go | func (tr *TaskRunner) restoreHandle(taskHandle *drivers.TaskHandle, net *drivers.DriverNetwork) (success bool) {
// Ensure handle is well-formed
if taskHandle.Config == nil {
return true
}
if err := tr.driver.RecoverTask(taskHandle); err != nil {
if tr.TaskState().State != structs.TaskStateRunning {
// Reco... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"restoreHandle",
"(",
"taskHandle",
"*",
"drivers",
".",
"TaskHandle",
",",
"net",
"*",
"drivers",
".",
"DriverNetwork",
")",
"(",
"success",
"bool",
")",
"{",
"// Ensure handle is well-formed",
"if",
"taskHandle",
".... | // restoreHandle ensures a TaskHandle is valid by calling Driver.RecoverTask
// and sets the driver handle. If the TaskHandle is not valid, DestroyTask is
// called. | [
"restoreHandle",
"ensures",
"a",
"TaskHandle",
"is",
"valid",
"by",
"calling",
"Driver",
".",
"RecoverTask",
"and",
"sets",
"the",
"driver",
"handle",
".",
"If",
"the",
"TaskHandle",
"is",
"not",
"valid",
"DestroyTask",
"is",
"called",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L869-L903 |
133,489 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | UpdateState | func (tr *TaskRunner) UpdateState(state string, event *structs.TaskEvent) {
tr.stateLock.Lock()
defer tr.stateLock.Unlock()
if event != nil {
tr.logger.Trace("setting task state", "state", state, "event", event.Type)
// Append the event
tr.appendEvent(event)
}
// Update the state
if err := tr.updateState... | go | func (tr *TaskRunner) UpdateState(state string, event *structs.TaskEvent) {
tr.stateLock.Lock()
defer tr.stateLock.Unlock()
if event != nil {
tr.logger.Trace("setting task state", "state", state, "event", event.Type)
// Append the event
tr.appendEvent(event)
}
// Update the state
if err := tr.updateState... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"UpdateState",
"(",
"state",
"string",
",",
"event",
"*",
"structs",
".",
"TaskEvent",
")",
"{",
"tr",
".",
"stateLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tr",
".",
"stateLock",
".",
"Unlock",
"(",
")",... | // UpdateState sets the task runners allocation state and triggers a server
// update. | [
"UpdateState",
"sets",
"the",
"task",
"runners",
"allocation",
"state",
"and",
"triggers",
"a",
"server",
"update",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L907-L927 |
133,490 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | updateStateImpl | func (tr *TaskRunner) updateStateImpl(state string) error {
// Update the task state
oldState := tr.state.State
taskState := tr.state
taskState.State = state
// Handle the state transition.
switch state {
case structs.TaskStateRunning:
// Capture the start time if it is just starting
if oldState != structs... | go | func (tr *TaskRunner) updateStateImpl(state string) error {
// Update the task state
oldState := tr.state.State
taskState := tr.state
taskState.State = state
// Handle the state transition.
switch state {
case structs.TaskStateRunning:
// Capture the start time if it is just starting
if oldState != structs... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"updateStateImpl",
"(",
"state",
"string",
")",
"error",
"{",
"// Update the task state",
"oldState",
":=",
"tr",
".",
"state",
".",
"State",
"\n",
"taskState",
":=",
"tr",
".",
"state",
"\n",
"taskState",
".",
"S... | // updateStateImpl updates the in-memory task state and persists to disk. | [
"updateStateImpl",
"updates",
"the",
"in",
"-",
"memory",
"task",
"state",
"and",
"persists",
"to",
"disk",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L930-L976 |
133,491 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | appendEvent | func (tr *TaskRunner) appendEvent(event *structs.TaskEvent) error {
// Ensure the event is populated with human readable strings
event.PopulateEventDisplayMessage()
// Propagate failure from event to task state
if event.FailsTask {
tr.state.Failed = true
}
// XXX This seems like a super awkward spot for this?... | go | func (tr *TaskRunner) appendEvent(event *structs.TaskEvent) error {
// Ensure the event is populated with human readable strings
event.PopulateEventDisplayMessage()
// Propagate failure from event to task state
if event.FailsTask {
tr.state.Failed = true
}
// XXX This seems like a super awkward spot for this?... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"appendEvent",
"(",
"event",
"*",
"structs",
".",
"TaskEvent",
")",
"error",
"{",
"// Ensure the event is populated with human readable strings",
"event",
".",
"PopulateEventDisplayMessage",
"(",
")",
"\n\n",
"// Propagate fail... | // appendEvent to task's event slice. Caller must acquire stateLock. | [
"appendEvent",
"to",
"task",
"s",
"event",
"slice",
".",
"Caller",
"must",
"acquire",
"stateLock",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L1018-L1044 |
133,492 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | Update | func (tr *TaskRunner) Update(update *structs.Allocation) {
task := update.LookupTask(tr.taskName)
if task == nil {
// This should not happen and likely indicates a bug in the
// server or client.
tr.logger.Error("allocation update is missing task; killing",
"group", update.TaskGroup)
te := structs.NewTaskE... | go | func (tr *TaskRunner) Update(update *structs.Allocation) {
task := update.LookupTask(tr.taskName)
if task == nil {
// This should not happen and likely indicates a bug in the
// server or client.
tr.logger.Error("allocation update is missing task; killing",
"group", update.TaskGroup)
te := structs.NewTaskE... | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"Update",
"(",
"update",
"*",
"structs",
".",
"Allocation",
")",
"{",
"task",
":=",
"update",
".",
"LookupTask",
"(",
"tr",
".",
"taskName",
")",
"\n",
"if",
"task",
"==",
"nil",
"{",
"// This should not happen ... | // Update the running allocation with a new version received from the server.
// Calls Update hooks asynchronously with Run.
//
// This method is safe for calling concurrently with Run and does not modify
// the passed in allocation. | [
"Update",
"the",
"running",
"allocation",
"with",
"a",
"new",
"version",
"received",
"from",
"the",
"server",
".",
"Calls",
"Update",
"hooks",
"asynchronously",
"with",
"Run",
".",
"This",
"method",
"is",
"safe",
"for",
"calling",
"concurrently",
"with",
"Run"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L1056-L1077 |
133,493 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | Shutdown | func (tr *TaskRunner) Shutdown() {
tr.logger.Trace("shutting down")
tr.shutdownCtxCancel()
<-tr.WaitCh()
// Run shutdown hooks to cleanup
tr.shutdownHooks()
// Persist once more
tr.persistLocalState()
} | go | func (tr *TaskRunner) Shutdown() {
tr.logger.Trace("shutting down")
tr.shutdownCtxCancel()
<-tr.WaitCh()
// Run shutdown hooks to cleanup
tr.shutdownHooks()
// Persist once more
tr.persistLocalState()
} | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"Shutdown",
"(",
")",
"{",
"tr",
".",
"logger",
".",
"Trace",
"(",
"\"",
"\"",
")",
"\n",
"tr",
".",
"shutdownCtxCancel",
"(",
")",
"\n\n",
"<-",
"tr",
".",
"WaitCh",
"(",
")",
"\n\n",
"// Run shutdown hooks... | // Shutdown TaskRunner gracefully without affecting the state of the task.
// Shutdown blocks until the main Run loop exits. | [
"Shutdown",
"TaskRunner",
"gracefully",
"without",
"affecting",
"the",
"state",
"of",
"the",
"task",
".",
"Shutdown",
"blocks",
"until",
"the",
"main",
"Run",
"loop",
"exits",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L1094-L1105 |
133,494 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | UpdateStats | func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage) {
tr.resourceUsageLock.Lock()
tr.resourceUsage = ru
tr.resourceUsageLock.Unlock()
if ru != nil {
tr.emitStats(ru)
}
} | go | func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage) {
tr.resourceUsageLock.Lock()
tr.resourceUsage = ru
tr.resourceUsageLock.Unlock()
if ru != nil {
tr.emitStats(ru)
}
} | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"UpdateStats",
"(",
"ru",
"*",
"cstructs",
".",
"TaskResourceUsage",
")",
"{",
"tr",
".",
"resourceUsageLock",
".",
"Lock",
"(",
")",
"\n",
"tr",
".",
"resourceUsage",
"=",
"ru",
"\n",
"tr",
".",
"resourceUsageL... | // UpdateStats updates and emits the latest stats from the driver. | [
"UpdateStats",
"updates",
"and",
"emits",
"the",
"latest",
"stats",
"from",
"the",
"driver",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L1124-L1131 |
133,495 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | emitStats | func (tr *TaskRunner) emitStats(ru *cstructs.TaskResourceUsage) {
if !tr.clientConfig.PublishAllocationMetrics {
return
}
if ru.ResourceUsage.MemoryStats != nil {
tr.setGaugeForMemory(ru)
}
if ru.ResourceUsage.CpuStats != nil {
tr.setGaugeForCPU(ru)
}
} | go | func (tr *TaskRunner) emitStats(ru *cstructs.TaskResourceUsage) {
if !tr.clientConfig.PublishAllocationMetrics {
return
}
if ru.ResourceUsage.MemoryStats != nil {
tr.setGaugeForMemory(ru)
}
if ru.ResourceUsage.CpuStats != nil {
tr.setGaugeForCPU(ru)
}
} | [
"func",
"(",
"tr",
"*",
"TaskRunner",
")",
"emitStats",
"(",
"ru",
"*",
"cstructs",
".",
"TaskResourceUsage",
")",
"{",
"if",
"!",
"tr",
".",
"clientConfig",
".",
"PublishAllocationMetrics",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"ru",
".",
"ResourceUsage... | // emitStats emits resource usage stats of tasks to remote metrics collector
// sinks | [
"emitStats",
"emits",
"resource",
"usage",
"stats",
"of",
"tasks",
"to",
"remote",
"metrics",
"collector",
"sinks"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L1192-L1204 |
133,496 | hashicorp/nomad | client/allocrunner/taskrunner/task_runner.go | appendTaskEvent | func appendTaskEvent(state *structs.TaskState, event *structs.TaskEvent, capacity int) {
if state.Events == nil {
state.Events = make([]*structs.TaskEvent, 1, capacity)
state.Events[0] = event
return
}
// If we hit capacity, then shift it.
if len(state.Events) == capacity {
old := state.Events
state.Even... | go | func appendTaskEvent(state *structs.TaskState, event *structs.TaskEvent, capacity int) {
if state.Events == nil {
state.Events = make([]*structs.TaskEvent, 1, capacity)
state.Events[0] = event
return
}
// If we hit capacity, then shift it.
if len(state.Events) == capacity {
old := state.Events
state.Even... | [
"func",
"appendTaskEvent",
"(",
"state",
"*",
"structs",
".",
"TaskState",
",",
"event",
"*",
"structs",
".",
"TaskEvent",
",",
"capacity",
"int",
")",
"{",
"if",
"state",
".",
"Events",
"==",
"nil",
"{",
"state",
".",
"Events",
"=",
"make",
"(",
"[",
... | // appendTaskEvent updates the task status by appending the new event. | [
"appendTaskEvent",
"updates",
"the",
"task",
"status",
"by",
"appending",
"the",
"new",
"event",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/task_runner.go#L1207-L1222 |
133,497 | hashicorp/nomad | client/allocrunner/taskrunner/driver_handle.go | NewDriverHandle | func NewDriverHandle(driver drivers.DriverPlugin, taskID string, task *structs.Task, net *drivers.DriverNetwork) *DriverHandle {
return &DriverHandle{
driver: driver,
net: net,
taskID: taskID,
task: task,
}
} | go | func NewDriverHandle(driver drivers.DriverPlugin, taskID string, task *structs.Task, net *drivers.DriverNetwork) *DriverHandle {
return &DriverHandle{
driver: driver,
net: net,
taskID: taskID,
task: task,
}
} | [
"func",
"NewDriverHandle",
"(",
"driver",
"drivers",
".",
"DriverPlugin",
",",
"taskID",
"string",
",",
"task",
"*",
"structs",
".",
"Task",
",",
"net",
"*",
"drivers",
".",
"DriverNetwork",
")",
"*",
"DriverHandle",
"{",
"return",
"&",
"DriverHandle",
"{",
... | // NewDriverHandle returns a handle for task operations on a specific task | [
"NewDriverHandle",
"returns",
"a",
"handle",
"for",
"task",
"operations",
"on",
"a",
"specific",
"task"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/driver_handle.go#L13-L20 |
133,498 | hashicorp/nomad | client/stats/cpu.go | NewCpuStats | func NewCpuStats() *CpuStats {
numCpus := runtime.NumCPU()
cpuStats := &CpuStats{
totalCpus: numCpus,
}
return cpuStats
} | go | func NewCpuStats() *CpuStats {
numCpus := runtime.NumCPU()
cpuStats := &CpuStats{
totalCpus: numCpus,
}
return cpuStats
} | [
"func",
"NewCpuStats",
"(",
")",
"*",
"CpuStats",
"{",
"numCpus",
":=",
"runtime",
".",
"NumCPU",
"(",
")",
"\n",
"cpuStats",
":=",
"&",
"CpuStats",
"{",
"totalCpus",
":",
"numCpus",
",",
"}",
"\n",
"return",
"cpuStats",
"\n",
"}"
] | // NewCpuStats returns a cpu stats calculator | [
"NewCpuStats",
"returns",
"a",
"cpu",
"stats",
"calculator"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/stats/cpu.go#L19-L25 |
133,499 | hashicorp/nomad | client/stats/cpu.go | Percent | func (c *CpuStats) Percent(cpuTime float64) float64 {
now := time.Now()
if c.prevCpuTime == 0.0 {
// invoked first time
c.prevCpuTime = cpuTime
c.prevTime = now
return 0.0
}
timeDelta := now.Sub(c.prevTime).Nanoseconds()
ret := c.calculatePercent(c.prevCpuTime, cpuTime, timeDelta)
c.prevCpuTime = cpuTim... | go | func (c *CpuStats) Percent(cpuTime float64) float64 {
now := time.Now()
if c.prevCpuTime == 0.0 {
// invoked first time
c.prevCpuTime = cpuTime
c.prevTime = now
return 0.0
}
timeDelta := now.Sub(c.prevTime).Nanoseconds()
ret := c.calculatePercent(c.prevCpuTime, cpuTime, timeDelta)
c.prevCpuTime = cpuTim... | [
"func",
"(",
"c",
"*",
"CpuStats",
")",
"Percent",
"(",
"cpuTime",
"float64",
")",
"float64",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"if",
"c",
".",
"prevCpuTime",
"==",
"0.0",
"{",
"// invoked first time",
"c",
".",
"prevCpuTime",
"="... | // Percent calculates the cpu usage percentage based on the current cpu usage
// and the previous cpu usage where usage is given as time in nanoseconds spend
// in the cpu | [
"Percent",
"calculates",
"the",
"cpu",
"usage",
"percentage",
"based",
"on",
"the",
"current",
"cpu",
"usage",
"and",
"the",
"previous",
"cpu",
"usage",
"where",
"usage",
"is",
"given",
"as",
"time",
"in",
"nanoseconds",
"spend",
"in",
"the",
"cpu"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/stats/cpu.go#L30-L45 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.