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,600 | hashicorp/nomad | client/fingerprint/cgroup_linux.go | FindCgroupMountpointDir | func FindCgroupMountpointDir() (string, error) {
mount, err := cgroups.FindCgroupMountpointDir()
if err != nil {
switch e := err.(type) {
case *cgroups.NotFoundError:
// It's okay if the mount point is not discovered
return "", nil
default:
// All other errors are passed back as is
return "", e
}
... | go | func FindCgroupMountpointDir() (string, error) {
mount, err := cgroups.FindCgroupMountpointDir()
if err != nil {
switch e := err.(type) {
case *cgroups.NotFoundError:
// It's okay if the mount point is not discovered
return "", nil
default:
// All other errors are passed back as is
return "", e
}
... | [
"func",
"FindCgroupMountpointDir",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"mount",
",",
"err",
":=",
"cgroups",
".",
"FindCgroupMountpointDir",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"switch",
"e",
":=",
"err",
".",
"(",
"type",
")",
... | // FindCgroupMountpointDir is used to find the cgroup mount point on a Linux
// system. | [
"FindCgroupMountpointDir",
"is",
"used",
"to",
"find",
"the",
"cgroup",
"mount",
"point",
"on",
"a",
"Linux",
"system",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fingerprint/cgroup_linux.go#L17-L30 |
133,601 | hashicorp/nomad | client/fingerprint/cgroup_linux.go | Fingerprint | func (f *CGroupFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
mount, err := f.mountPointDetector.MountPoint()
if err != nil {
f.clearCGroupAttributes(resp)
return fmt.Errorf("Failed to discover cgroup mount point: %s", err)
}
// Check if a cgroup mount point was found
if ... | go | func (f *CGroupFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
mount, err := f.mountPointDetector.MountPoint()
if err != nil {
f.clearCGroupAttributes(resp)
return fmt.Errorf("Failed to discover cgroup mount point: %s", err)
}
// Check if a cgroup mount point was found
if ... | [
"func",
"(",
"f",
"*",
"CGroupFingerprint",
")",
"Fingerprint",
"(",
"req",
"*",
"FingerprintRequest",
",",
"resp",
"*",
"FingerprintResponse",
")",
"error",
"{",
"mount",
",",
"err",
":=",
"f",
".",
"mountPointDetector",
".",
"MountPoint",
"(",
")",
"\n",
... | // Fingerprint tries to find a valid cgroup mount point | [
"Fingerprint",
"tries",
"to",
"find",
"a",
"valid",
"cgroup",
"mount",
"point"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fingerprint/cgroup_linux.go#L33-L60 |
133,602 | hashicorp/nomad | nomad/vault.go | NewVaultClient | func NewVaultClient(c *config.VaultConfig, logger log.Logger, purgeFn PurgeVaultAccessorFn) (*vaultClient, error) {
if c == nil {
return nil, fmt.Errorf("must pass valid VaultConfig")
}
if logger == nil {
return nil, fmt.Errorf("must pass valid logger")
}
v := &vaultClient{
config: c,
logger: logger.... | go | func NewVaultClient(c *config.VaultConfig, logger log.Logger, purgeFn PurgeVaultAccessorFn) (*vaultClient, error) {
if c == nil {
return nil, fmt.Errorf("must pass valid VaultConfig")
}
if logger == nil {
return nil, fmt.Errorf("must pass valid logger")
}
v := &vaultClient{
config: c,
logger: logger.... | [
"func",
"NewVaultClient",
"(",
"c",
"*",
"config",
".",
"VaultConfig",
",",
"logger",
"log",
".",
"Logger",
",",
"purgeFn",
"PurgeVaultAccessorFn",
")",
"(",
"*",
"vaultClient",
",",
"error",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
... | // NewVaultClient returns a Vault client from the given config. If the client
// couldn't be made an error is returned. | [
"NewVaultClient",
"returns",
"a",
"Vault",
"client",
"from",
"the",
"given",
"config",
".",
"If",
"the",
"client",
"couldn",
"t",
"be",
"made",
"an",
"error",
"is",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L240-L271 |
133,603 | hashicorp/nomad | nomad/vault.go | flush | func (v *vaultClient) flush() {
v.l.Lock()
defer v.l.Unlock()
v.client = nil
v.clientSys = nil
v.auth = nil
v.connEstablished = false
v.connEstablishedErr = nil
v.token = ""
v.tokenData = nil
v.revoking = make(map[*structs.VaultAccessor]time.Time)
v.childTTL = ""
v.tomb = &tomb.Tomb{}
} | go | func (v *vaultClient) flush() {
v.l.Lock()
defer v.l.Unlock()
v.client = nil
v.clientSys = nil
v.auth = nil
v.connEstablished = false
v.connEstablishedErr = nil
v.token = ""
v.tokenData = nil
v.revoking = make(map[*structs.VaultAccessor]time.Time)
v.childTTL = ""
v.tomb = &tomb.Tomb{}
} | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"flush",
"(",
")",
"{",
"v",
".",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"v",
".",
"client",
"=",
"nil",
"\n",
"v",
".",
"clientSys",
"=",
"nil",
... | // flush is used to reset the state of the vault client | [
"flush",
"is",
"used",
"to",
"reset",
"the",
"state",
"of",
"the",
"vault",
"client"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L311-L325 |
133,604 | hashicorp/nomad | nomad/vault.go | SetConfig | func (v *vaultClient) SetConfig(config *config.VaultConfig) error {
if config == nil {
return fmt.Errorf("must pass valid VaultConfig")
}
v.l.Lock()
defer v.l.Unlock()
// If reloading the same config, no-op
if v.config.IsEqual(config) {
return nil
}
// Kill any background routines
if v.running {
// St... | go | func (v *vaultClient) SetConfig(config *config.VaultConfig) error {
if config == nil {
return fmt.Errorf("must pass valid VaultConfig")
}
v.l.Lock()
defer v.l.Unlock()
// If reloading the same config, no-op
if v.config.IsEqual(config) {
return nil
}
// Kill any background routines
if v.running {
// St... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"SetConfig",
"(",
"config",
"*",
"config",
".",
"VaultConfig",
")",
"error",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"v",
".",
"l",
... | // SetConfig is used to update the Vault config being used. A temporary outage
// may occur after calling as it re-establishes a connection to Vault | [
"SetConfig",
"is",
"used",
"to",
"update",
"the",
"Vault",
"config",
"being",
"used",
".",
"A",
"temporary",
"outage",
"may",
"occur",
"after",
"calling",
"as",
"it",
"re",
"-",
"establishes",
"a",
"connection",
"to",
"Vault"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L329-L371 |
133,605 | hashicorp/nomad | nomad/vault.go | buildClient | func (v *vaultClient) buildClient() error {
// Validate we have the required fields.
if v.config.Token == "" {
return errors.New("Vault token must be set")
} else if v.config.Addr == "" {
return errors.New("Vault address must be set")
}
// Parse the TTL if it is set
if v.config.TaskTokenTTL != "" {
d, err ... | go | func (v *vaultClient) buildClient() error {
// Validate we have the required fields.
if v.config.Token == "" {
return errors.New("Vault token must be set")
} else if v.config.Addr == "" {
return errors.New("Vault address must be set")
}
// Parse the TTL if it is set
if v.config.TaskTokenTTL != "" {
d, err ... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"buildClient",
"(",
")",
"error",
"{",
"// Validate we have the required fields.",
"if",
"v",
".",
"config",
".",
"Token",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
... | // buildClient is used to build a Vault client based on the stored Vault config | [
"buildClient",
"is",
"used",
"to",
"build",
"a",
"Vault",
"client",
"based",
"on",
"the",
"stored",
"Vault",
"config"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L374-L432 |
133,606 | hashicorp/nomad | nomad/vault.go | establishConnection | func (v *vaultClient) establishConnection() {
// Create the retry timer and set initial duration to zero so it fires
// immediately
retryTimer := time.NewTimer(0)
initStatus := false
OUTER:
for {
select {
case <-v.tomb.Dying():
return
case <-retryTimer.C:
// Ensure the API is reachable
if !initStatu... | go | func (v *vaultClient) establishConnection() {
// Create the retry timer and set initial duration to zero so it fires
// immediately
retryTimer := time.NewTimer(0)
initStatus := false
OUTER:
for {
select {
case <-v.tomb.Dying():
return
case <-retryTimer.C:
// Ensure the API is reachable
if !initStatu... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"establishConnection",
"(",
")",
"{",
"// Create the retry timer and set initial duration to zero so it fires",
"// immediately",
"retryTimer",
":=",
"time",
".",
"NewTimer",
"(",
"0",
")",
"\n",
"initStatus",
":=",
"false",
... | // establishConnection is used to make first contact with Vault. This should be
// called in a go-routine since the connection is retried until the Vault Client
// is stopped or the connection is successfully made at which point the renew
// loop is started. | [
"establishConnection",
"is",
"used",
"to",
"make",
"first",
"contact",
"with",
"Vault",
".",
"This",
"should",
"be",
"called",
"in",
"a",
"go",
"-",
"routine",
"since",
"the",
"connection",
"is",
"retried",
"until",
"the",
"Vault",
"Client",
"is",
"stopped",... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L438-L488 |
133,607 | hashicorp/nomad | nomad/vault.go | renewalLoop | func (v *vaultClient) renewalLoop() {
atomic.StoreInt32(&v.renewLoopActive, 1)
defer atomic.StoreInt32(&v.renewLoopActive, 0)
// Create the renewal timer and set initial duration to zero so it fires
// immediately
authRenewTimer := time.NewTimer(0)
// Backoff is to reduce the rate we try to renew with Vault und... | go | func (v *vaultClient) renewalLoop() {
atomic.StoreInt32(&v.renewLoopActive, 1)
defer atomic.StoreInt32(&v.renewLoopActive, 0)
// Create the renewal timer and set initial duration to zero so it fires
// immediately
authRenewTimer := time.NewTimer(0)
// Backoff is to reduce the rate we try to renew with Vault und... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"renewalLoop",
"(",
")",
"{",
"atomic",
".",
"StoreInt32",
"(",
"&",
"v",
".",
"renewLoopActive",
",",
"1",
")",
"\n",
"defer",
"atomic",
".",
"StoreInt32",
"(",
"&",
"v",
".",
"renewLoopActive",
",",
"0",
"... | // renewalLoop runs the renew loop. This should only be called if we are given a
// non-root token. | [
"renewalLoop",
"runs",
"the",
"renew",
"loop",
".",
"This",
"should",
"only",
"be",
"called",
"if",
"we",
"are",
"given",
"a",
"non",
"-",
"root",
"token",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L496-L558 |
133,608 | hashicorp/nomad | nomad/vault.go | renew | func (v *vaultClient) renew() (bool, error) {
// Track how long the request takes
defer metrics.MeasureSince([]string{"nomad", "vault", "renew"}, time.Now())
// Attempt to renew the token
secret, err := v.auth.RenewSelf(v.tokenData.CreationTTL)
if err != nil {
// Check if there is a permission denied
recovera... | go | func (v *vaultClient) renew() (bool, error) {
// Track how long the request takes
defer metrics.MeasureSince([]string{"nomad", "vault", "renew"}, time.Now())
// Attempt to renew the token
secret, err := v.auth.RenewSelf(v.tokenData.CreationTTL)
if err != nil {
// Check if there is a permission denied
recovera... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"renew",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// Track how long the request takes",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"... | // renew attempts to renew our Vault token. If the renewal fails, an error is
// returned. The boolean indicates whether it's safe to attempt to renew again.
// This method updates the currentExpiration time | [
"renew",
"attempts",
"to",
"renew",
"our",
"Vault",
"token",
".",
"If",
"the",
"renewal",
"fails",
"an",
"error",
"is",
"returned",
".",
"The",
"boolean",
"indicates",
"whether",
"it",
"s",
"safe",
"to",
"attempt",
"to",
"renew",
"again",
".",
"This",
"m... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L606-L636 |
133,609 | hashicorp/nomad | nomad/vault.go | getWrappingFn | func (v *vaultClient) getWrappingFn() func(operation, path string) string {
createPath := "auth/token/create"
role := v.getRole()
if role != "" {
createPath = fmt.Sprintf("auth/token/create/%s", role)
}
return func(operation, path string) string {
// Only wrap the token create operation
if operation != "POS... | go | func (v *vaultClient) getWrappingFn() func(operation, path string) string {
createPath := "auth/token/create"
role := v.getRole()
if role != "" {
createPath = fmt.Sprintf("auth/token/create/%s", role)
}
return func(operation, path string) string {
// Only wrap the token create operation
if operation != "POS... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"getWrappingFn",
"(",
")",
"func",
"(",
"operation",
",",
"path",
"string",
")",
"string",
"{",
"createPath",
":=",
"\"",
"\"",
"\n",
"role",
":=",
"v",
".",
"getRole",
"(",
")",
"\n",
"if",
"role",
"!=",
... | // getWrappingFn returns an appropriate wrapping function for Nomad Servers | [
"getWrappingFn",
"returns",
"an",
"appropriate",
"wrapping",
"function",
"for",
"Nomad",
"Servers"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L639-L654 |
133,610 | hashicorp/nomad | nomad/vault.go | parseSelfToken | func (v *vaultClient) parseSelfToken() error {
// Try looking up the token using the self endpoint
secret, err := v.lookupSelf()
if err != nil {
return err
}
// Read and parse the fields
var data tokenData
if err := mapstructure.WeakDecode(secret.Data, &data); err != nil {
return fmt.Errorf("failed to parse... | go | func (v *vaultClient) parseSelfToken() error {
// Try looking up the token using the self endpoint
secret, err := v.lookupSelf()
if err != nil {
return err
}
// Read and parse the fields
var data tokenData
if err := mapstructure.WeakDecode(secret.Data, &data); err != nil {
return fmt.Errorf("failed to parse... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"parseSelfToken",
"(",
")",
"error",
"{",
"// Try looking up the token using the self endpoint",
"secret",
",",
"err",
":=",
"v",
".",
"lookupSelf",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\... | // parseSelfToken looks up the Vault token in Vault and parses its data storing
// it in the client. If the token is not valid for Nomads purposes an error is
// returned. | [
"parseSelfToken",
"looks",
"up",
"the",
"Vault",
"token",
"in",
"Vault",
"and",
"parses",
"its",
"data",
"storing",
"it",
"in",
"the",
"client",
".",
"If",
"the",
"token",
"is",
"not",
"valid",
"for",
"Nomads",
"purposes",
"an",
"error",
"is",
"returned",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L659-L743 |
133,611 | hashicorp/nomad | nomad/vault.go | lookupSelf | func (v *vaultClient) lookupSelf() (*vapi.Secret, error) {
// Get the initial lease duration
auth := v.client.Auth().Token()
secret, err := auth.LookupSelf()
if err == nil && secret != nil && secret.Data != nil {
return secret, nil
}
// Try looking up our token directly, even when we get an empty response,
/... | go | func (v *vaultClient) lookupSelf() (*vapi.Secret, error) {
// Get the initial lease duration
auth := v.client.Auth().Token()
secret, err := auth.LookupSelf()
if err == nil && secret != nil && secret.Data != nil {
return secret, nil
}
// Try looking up our token directly, even when we get an empty response,
/... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"lookupSelf",
"(",
")",
"(",
"*",
"vapi",
".",
"Secret",
",",
"error",
")",
"{",
"// Get the initial lease duration",
"auth",
":=",
"v",
".",
"client",
".",
"Auth",
"(",
")",
".",
"Token",
"(",
")",
"\n\n",
... | // lookupSelf is a helper function that looks up latest self lease info. | [
"lookupSelf",
"is",
"a",
"helper",
"function",
"that",
"looks",
"up",
"latest",
"self",
"lease",
"info",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L746-L766 |
133,612 | hashicorp/nomad | nomad/vault.go | getRole | func (v *vaultClient) getRole() string {
if v.config.Role != "" {
return v.config.Role
}
return v.tokenData.Role
} | go | func (v *vaultClient) getRole() string {
if v.config.Role != "" {
return v.config.Role
}
return v.tokenData.Role
} | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"getRole",
"(",
")",
"string",
"{",
"if",
"v",
".",
"config",
".",
"Role",
"!=",
"\"",
"\"",
"{",
"return",
"v",
".",
"config",
".",
"Role",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"tokenData",
".",
"Role... | // getRole returns the role name to be used when creating tokens | [
"getRole",
"returns",
"the",
"role",
"name",
"to",
"be",
"used",
"when",
"creating",
"tokens"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L769-L775 |
133,613 | hashicorp/nomad | nomad/vault.go | validateCapabilities | func (v *vaultClient) validateCapabilities(role string, root bool) error {
// Check if the token can lookup capabilities.
var mErr multierror.Error
_, _, err := v.hasCapability(vaultCapabilitiesLookupPath, vaultCapabilitiesCapability)
if err != nil {
// Check if there is a permission denied
if structs.VaultUnre... | go | func (v *vaultClient) validateCapabilities(role string, root bool) error {
// Check if the token can lookup capabilities.
var mErr multierror.Error
_, _, err := v.hasCapability(vaultCapabilitiesLookupPath, vaultCapabilitiesCapability)
if err != nil {
// Check if there is a permission denied
if structs.VaultUnre... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"validateCapabilities",
"(",
"role",
"string",
",",
"root",
"bool",
")",
"error",
"{",
"// Check if the token can lookup capabilities.",
"var",
"mErr",
"multierror",
".",
"Error",
"\n",
"_",
",",
"_",
",",
"err",
":="... | // validateCapabilities checks that Nomad's Vault token has the correct
// capabilities. | [
"validateCapabilities",
"checks",
"that",
"Nomad",
"s",
"Vault",
"token",
"has",
"the",
"correct",
"capabilities",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L779-L833 |
133,614 | hashicorp/nomad | nomad/vault.go | hasCapability | func (v *vaultClient) hasCapability(path string, required []string) (bool, []string, error) {
caps, err := v.client.Sys().CapabilitiesSelf(path)
if err != nil {
return false, nil, err
}
for _, c := range caps {
for _, r := range required {
if c == r {
return true, caps, nil
}
}
}
return false, cap... | go | func (v *vaultClient) hasCapability(path string, required []string) (bool, []string, error) {
caps, err := v.client.Sys().CapabilitiesSelf(path)
if err != nil {
return false, nil, err
}
for _, c := range caps {
for _, r := range required {
if c == r {
return true, caps, nil
}
}
}
return false, cap... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"hasCapability",
"(",
"path",
"string",
",",
"required",
"[",
"]",
"string",
")",
"(",
"bool",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"caps",
",",
"err",
":=",
"v",
".",
"client",
".",
"Sys",
"... | // hasCapability takes a path and returns whether the token has at least one of
// the required capabilities on the given path. It also returns the set of
// capabilities the token does have as well as any error that occurred. | [
"hasCapability",
"takes",
"a",
"path",
"and",
"returns",
"whether",
"the",
"token",
"has",
"at",
"least",
"one",
"of",
"the",
"required",
"capabilities",
"on",
"the",
"given",
"path",
".",
"It",
"also",
"returns",
"the",
"set",
"of",
"capabilities",
"the",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L838-L851 |
133,615 | hashicorp/nomad | nomad/vault.go | validateRole | func (v *vaultClient) validateRole(role string) error {
if role == "" {
return fmt.Errorf("Invalid empty role name")
}
// Validate the role
rsecret, err := v.client.Logical().Read(fmt.Sprintf("auth/token/roles/%s", role))
if err != nil {
return fmt.Errorf("failed to lookup role %q: %v", role, err)
}
if rsec... | go | func (v *vaultClient) validateRole(role string) error {
if role == "" {
return fmt.Errorf("Invalid empty role name")
}
// Validate the role
rsecret, err := v.client.Logical().Read(fmt.Sprintf("auth/token/roles/%s", role))
if err != nil {
return fmt.Errorf("failed to lookup role %q: %v", role, err)
}
if rsec... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"validateRole",
"(",
"role",
"string",
")",
"error",
"{",
"if",
"role",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate the role",
"rsecret",
",",
... | // validateRole contacts Vault and checks that the given Vault role is valid for
// the purposes of being used by Nomad | [
"validateRole",
"contacts",
"Vault",
"and",
"checks",
"that",
"the",
"given",
"Vault",
"role",
"is",
"valid",
"for",
"the",
"purposes",
"of",
"being",
"used",
"by",
"Nomad"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L855-L895 |
133,616 | hashicorp/nomad | nomad/vault.go | ConnectionEstablished | func (v *vaultClient) ConnectionEstablished() (bool, error) {
v.l.Lock()
defer v.l.Unlock()
return v.connEstablished, v.connEstablishedErr
} | go | func (v *vaultClient) ConnectionEstablished() (bool, error) {
v.l.Lock()
defer v.l.Unlock()
return v.connEstablished, v.connEstablishedErr
} | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"ConnectionEstablished",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"v",
".",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"l",
".",
"Unlock",
"(",
")",
"\n",
"return",
"v",
".",
"connEstabli... | // ConnectionEstablished returns whether a connection to Vault has been
// established and any error that potentially caused it to be false | [
"ConnectionEstablished",
"returns",
"whether",
"a",
"connection",
"to",
"Vault",
"has",
"been",
"established",
"and",
"any",
"error",
"that",
"potentially",
"caused",
"it",
"to",
"be",
"false"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L899-L903 |
133,617 | hashicorp/nomad | nomad/vault.go | Enabled | func (v *vaultClient) Enabled() bool {
v.l.Lock()
defer v.l.Unlock()
return v.config.IsEnabled()
} | go | func (v *vaultClient) Enabled() bool {
v.l.Lock()
defer v.l.Unlock()
return v.config.IsEnabled()
} | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"Enabled",
"(",
")",
"bool",
"{",
"v",
".",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"l",
".",
"Unlock",
"(",
")",
"\n",
"return",
"v",
".",
"config",
".",
"IsEnabled",
"(",
")",
"\n",
"}... | // Enabled returns whether the client is active | [
"Enabled",
"returns",
"whether",
"the",
"client",
"is",
"active"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L906-L910 |
133,618 | hashicorp/nomad | nomad/vault.go | LookupToken | func (v *vaultClient) LookupToken(ctx context.Context, token string) (*vapi.Secret, error) {
if !v.Enabled() {
return nil, fmt.Errorf("Vault integration disabled")
}
if !v.Active() {
return nil, fmt.Errorf("Vault client not active")
}
// Check if we have established a connection with Vault
if established, e... | go | func (v *vaultClient) LookupToken(ctx context.Context, token string) (*vapi.Secret, error) {
if !v.Enabled() {
return nil, fmt.Errorf("Vault integration disabled")
}
if !v.Active() {
return nil, fmt.Errorf("Vault client not active")
}
// Check if we have established a connection with Vault
if established, e... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"LookupToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"token",
"string",
")",
"(",
"*",
"vapi",
".",
"Secret",
",",
"error",
")",
"{",
"if",
"!",
"v",
".",
"Enabled",
"(",
")",
"{",
"return",
"nil",
... | // LookupToken takes a Vault token and does a lookup against Vault. The call is
// rate limited and may be canceled with passed context. | [
"LookupToken",
"takes",
"a",
"Vault",
"token",
"and",
"does",
"a",
"lookup",
"against",
"Vault",
".",
"The",
"call",
"is",
"rate",
"limited",
"and",
"may",
"be",
"canceled",
"with",
"passed",
"context",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1013-L1039 |
133,619 | hashicorp/nomad | nomad/vault.go | PoliciesFrom | func PoliciesFrom(s *vapi.Secret) ([]string, error) {
if s == nil {
return nil, fmt.Errorf("cannot parse nil Vault secret")
}
var data tokenData
if err := mapstructure.WeakDecode(s.Data, &data); err != nil {
return nil, fmt.Errorf("failed to parse Vault token's data block: %v", err)
}
return data.Policies, n... | go | func PoliciesFrom(s *vapi.Secret) ([]string, error) {
if s == nil {
return nil, fmt.Errorf("cannot parse nil Vault secret")
}
var data tokenData
if err := mapstructure.WeakDecode(s.Data, &data); err != nil {
return nil, fmt.Errorf("failed to parse Vault token's data block: %v", err)
}
return data.Policies, n... | [
"func",
"PoliciesFrom",
"(",
"s",
"*",
"vapi",
".",
"Secret",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"data",
... | // PoliciesFrom parses the set of policies returned by a token lookup. | [
"PoliciesFrom",
"parses",
"the",
"set",
"of",
"policies",
"returned",
"by",
"a",
"token",
"lookup",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1042-L1052 |
133,620 | hashicorp/nomad | nomad/vault.go | RevokeTokens | func (v *vaultClient) RevokeTokens(ctx context.Context, accessors []*structs.VaultAccessor, committed bool) error {
if !v.Enabled() {
return nil
}
if !v.Active() {
return fmt.Errorf("Vault client not active")
}
// Track how long the request takes
defer metrics.MeasureSince([]string{"nomad", "vault", "revoke... | go | func (v *vaultClient) RevokeTokens(ctx context.Context, accessors []*structs.VaultAccessor, committed bool) error {
if !v.Enabled() {
return nil
}
if !v.Active() {
return fmt.Errorf("Vault client not active")
}
// Track how long the request takes
defer metrics.MeasureSince([]string{"nomad", "vault", "revoke... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"RevokeTokens",
"(",
"ctx",
"context",
".",
"Context",
",",
"accessors",
"[",
"]",
"*",
"structs",
".",
"VaultAccessor",
",",
"committed",
"bool",
")",
"error",
"{",
"if",
"!",
"v",
".",
"Enabled",
"(",
")",
... | // RevokeTokens revokes the passed set of accessors. If committed is set, the
// purge function passed to the client is called. If there is an error purging
// either because of Vault failures or because of the purge function, the
// revocation is retried until the tokens TTL. | [
"RevokeTokens",
"revokes",
"the",
"passed",
"set",
"of",
"accessors",
".",
"If",
"committed",
"is",
"set",
"the",
"purge",
"function",
"passed",
"to",
"the",
"client",
"is",
"called",
".",
"If",
"there",
"is",
"an",
"error",
"purging",
"either",
"because",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1058-L1114 |
133,621 | hashicorp/nomad | nomad/vault.go | storeForRevocation | func (v *vaultClient) storeForRevocation(accessors []*structs.VaultAccessor) {
v.revLock.Lock()
now := time.Now()
for _, a := range accessors {
v.revoking[a] = now.Add(time.Duration(a.CreationTTL) * time.Second)
}
v.revLock.Unlock()
} | go | func (v *vaultClient) storeForRevocation(accessors []*structs.VaultAccessor) {
v.revLock.Lock()
now := time.Now()
for _, a := range accessors {
v.revoking[a] = now.Add(time.Duration(a.CreationTTL) * time.Second)
}
v.revLock.Unlock()
} | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"storeForRevocation",
"(",
"accessors",
"[",
"]",
"*",
"structs",
".",
"VaultAccessor",
")",
"{",
"v",
".",
"revLock",
".",
"Lock",
"(",
")",
"\n\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"for",
... | // storeForRevocation stores the passed set of accessors for revocation. It
// captures their effective TTL by storing their create TTL plus the current
// time. | [
"storeForRevocation",
"stores",
"the",
"passed",
"set",
"of",
"accessors",
"for",
"revocation",
".",
"It",
"captures",
"their",
"effective",
"TTL",
"by",
"storing",
"their",
"create",
"TTL",
"plus",
"the",
"current",
"time",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1119-L1127 |
133,622 | hashicorp/nomad | nomad/vault.go | parallelRevoke | func (v *vaultClient) parallelRevoke(ctx context.Context, accessors []*structs.VaultAccessor) error {
if !v.Enabled() {
return fmt.Errorf("Vault integration disabled")
}
if !v.Active() {
return fmt.Errorf("Vault client not active")
}
// Check if we have established a connection with Vault
if established, er... | go | func (v *vaultClient) parallelRevoke(ctx context.Context, accessors []*structs.VaultAccessor) error {
if !v.Enabled() {
return fmt.Errorf("Vault integration disabled")
}
if !v.Active() {
return fmt.Errorf("Vault client not active")
}
// Check if we have established a connection with Vault
if established, er... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"parallelRevoke",
"(",
"ctx",
"context",
".",
"Context",
",",
"accessors",
"[",
"]",
"*",
"structs",
".",
"VaultAccessor",
")",
"error",
"{",
"if",
"!",
"v",
".",
"Enabled",
"(",
")",
"{",
"return",
"fmt",
"... | // parallelRevoke revokes the passed VaultAccessors in parallel. | [
"parallelRevoke",
"revokes",
"the",
"passed",
"VaultAccessors",
"in",
"parallel",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1130-L1190 |
133,623 | hashicorp/nomad | nomad/vault.go | revokeDaemon | func (v *vaultClient) revokeDaemon() {
ticker := time.NewTicker(vaultRevocationIntv)
defer ticker.Stop()
for {
select {
case <-v.tomb.Dying():
return
case now := <-ticker.C:
if established, _ := v.ConnectionEstablished(); !established {
continue
}
v.revLock.Lock()
// Fast path
if len(v... | go | func (v *vaultClient) revokeDaemon() {
ticker := time.NewTicker(vaultRevocationIntv)
defer ticker.Stop()
for {
select {
case <-v.tomb.Dying():
return
case now := <-ticker.C:
if established, _ := v.ConnectionEstablished(); !established {
continue
}
v.revLock.Lock()
// Fast path
if len(v... | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"revokeDaemon",
"(",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"vaultRevocationIntv",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"v",
... | // revokeDaemon should be called in a goroutine and is used to periodically
// revoke Vault accessors that failed the original revocation | [
"revokeDaemon",
"should",
"be",
"called",
"in",
"a",
"goroutine",
"and",
"is",
"used",
"to",
"periodically",
"revoke",
"Vault",
"accessors",
"that",
"failed",
"the",
"original",
"revocation"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1194-L1253 |
133,624 | hashicorp/nomad | nomad/vault.go | purgeVaultAccessors | func (s *Server) purgeVaultAccessors(accessors []*structs.VaultAccessor) error {
// Commit this update via Raft
req := structs.VaultAccessorsRequest{Accessors: accessors}
_, _, err := s.raftApply(structs.VaultAccessorDeregisterRequestType, req)
return err
} | go | func (s *Server) purgeVaultAccessors(accessors []*structs.VaultAccessor) error {
// Commit this update via Raft
req := structs.VaultAccessorsRequest{Accessors: accessors}
_, _, err := s.raftApply(structs.VaultAccessorDeregisterRequestType, req)
return err
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"purgeVaultAccessors",
"(",
"accessors",
"[",
"]",
"*",
"structs",
".",
"VaultAccessor",
")",
"error",
"{",
"// Commit this update via Raft",
"req",
":=",
"structs",
".",
"VaultAccessorsRequest",
"{",
"Accessors",
":",
"acce... | // purgeVaultAccessors creates a Raft transaction to remove the passed Vault
// Accessors | [
"purgeVaultAccessors",
"creates",
"a",
"Raft",
"transaction",
"to",
"remove",
"the",
"passed",
"Vault",
"Accessors"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1257-L1262 |
133,625 | hashicorp/nomad | nomad/vault.go | setLimit | func (v *vaultClient) setLimit(l rate.Limit) {
v.l.Lock()
defer v.l.Unlock()
v.limiter = rate.NewLimiter(l, int(l))
} | go | func (v *vaultClient) setLimit(l rate.Limit) {
v.l.Lock()
defer v.l.Unlock()
v.limiter = rate.NewLimiter(l, int(l))
} | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"setLimit",
"(",
"l",
"rate",
".",
"Limit",
")",
"{",
"v",
".",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"v",
".",
"l",
".",
"Unlock",
"(",
")",
"\n",
"v",
".",
"limiter",
"=",
"rate",
".",
"NewLim... | // setLimit is used to update the rate limit | [
"setLimit",
"is",
"used",
"to",
"update",
"the",
"rate",
"limit"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1274-L1278 |
133,626 | hashicorp/nomad | nomad/vault.go | extendExpiration | func (v *vaultClient) extendExpiration(ttlSeconds int) {
v.currentExpirationLock.Lock()
v.currentExpiration = time.Now().Add(time.Duration(ttlSeconds) * time.Second)
v.currentExpirationLock.Unlock()
} | go | func (v *vaultClient) extendExpiration(ttlSeconds int) {
v.currentExpirationLock.Lock()
v.currentExpiration = time.Now().Add(time.Duration(ttlSeconds) * time.Second)
v.currentExpirationLock.Unlock()
} | [
"func",
"(",
"v",
"*",
"vaultClient",
")",
"extendExpiration",
"(",
"ttlSeconds",
"int",
")",
"{",
"v",
".",
"currentExpirationLock",
".",
"Lock",
"(",
")",
"\n",
"v",
".",
"currentExpiration",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"time"... | // extendExpiration sets the current auth token expiration record to ttLSeconds seconds from now | [
"extendExpiration",
"sets",
"the",
"current",
"auth",
"token",
"expiration",
"record",
"to",
"ttLSeconds",
"seconds",
"from",
"now"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/vault.go#L1331-L1335 |
133,627 | hashicorp/nomad | nomad/plan_apply.go | newPlanner | func newPlanner(s *Server) (*planner, error) {
// Create a plan queue
planQueue, err := NewPlanQueue()
if err != nil {
return nil, err
}
return &planner{
Server: s,
log: s.logger.Named("planner"),
planQueue: planQueue,
}, nil
} | go | func newPlanner(s *Server) (*planner, error) {
// Create a plan queue
planQueue, err := NewPlanQueue()
if err != nil {
return nil, err
}
return &planner{
Server: s,
log: s.logger.Named("planner"),
planQueue: planQueue,
}, nil
} | [
"func",
"newPlanner",
"(",
"s",
"*",
"Server",
")",
"(",
"*",
"planner",
",",
"error",
")",
"{",
"// Create a plan queue",
"planQueue",
",",
"err",
":=",
"NewPlanQueue",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
... | // newPlanner returns a new planner to be used for managing allocation plans. | [
"newPlanner",
"returns",
"a",
"new",
"planner",
"to",
"be",
"used",
"for",
"managing",
"allocation",
"plans",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L30-L42 |
133,628 | hashicorp/nomad | nomad/plan_apply.go | normalizePreemptedAlloc | func normalizePreemptedAlloc(preemptedAlloc *structs.Allocation, now int64) *structs.AllocationDiff {
return &structs.AllocationDiff{
ID: preemptedAlloc.ID,
PreemptedByAllocation: preemptedAlloc.PreemptedByAllocation,
ModifyTime: now,
}
} | go | func normalizePreemptedAlloc(preemptedAlloc *structs.Allocation, now int64) *structs.AllocationDiff {
return &structs.AllocationDiff{
ID: preemptedAlloc.ID,
PreemptedByAllocation: preemptedAlloc.PreemptedByAllocation,
ModifyTime: now,
}
} | [
"func",
"normalizePreemptedAlloc",
"(",
"preemptedAlloc",
"*",
"structs",
".",
"Allocation",
",",
"now",
"int64",
")",
"*",
"structs",
".",
"AllocationDiff",
"{",
"return",
"&",
"structs",
".",
"AllocationDiff",
"{",
"ID",
":",
"preemptedAlloc",
".",
"ID",
","... | // normalizePreemptedAlloc removes redundant fields from a preempted allocation and
// returns AllocationDiff. Since a preempted allocation is always an existing allocation,
// the struct returned by this method contains only the differential, which can be
// applied to an existing allocation, to yield the updated stru... | [
"normalizePreemptedAlloc",
"removes",
"redundant",
"fields",
"from",
"a",
"preempted",
"allocation",
"and",
"returns",
"AllocationDiff",
".",
"Since",
"a",
"preempted",
"allocation",
"is",
"always",
"an",
"existing",
"allocation",
"the",
"struct",
"returned",
"by",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L269-L275 |
133,629 | hashicorp/nomad | nomad/plan_apply.go | normalizeStoppedAlloc | func normalizeStoppedAlloc(stoppedAlloc *structs.Allocation, now int64) *structs.AllocationDiff {
return &structs.AllocationDiff{
ID: stoppedAlloc.ID,
DesiredDescription: stoppedAlloc.DesiredDescription,
ClientStatus: stoppedAlloc.ClientStatus,
ModifyTime: now,
}
} | go | func normalizeStoppedAlloc(stoppedAlloc *structs.Allocation, now int64) *structs.AllocationDiff {
return &structs.AllocationDiff{
ID: stoppedAlloc.ID,
DesiredDescription: stoppedAlloc.DesiredDescription,
ClientStatus: stoppedAlloc.ClientStatus,
ModifyTime: now,
}
} | [
"func",
"normalizeStoppedAlloc",
"(",
"stoppedAlloc",
"*",
"structs",
".",
"Allocation",
",",
"now",
"int64",
")",
"*",
"structs",
".",
"AllocationDiff",
"{",
"return",
"&",
"structs",
".",
"AllocationDiff",
"{",
"ID",
":",
"stoppedAlloc",
".",
"ID",
",",
"D... | // normalizeStoppedAlloc removes redundant fields from a stopped allocation and
// returns AllocationDiff. Since a stopped allocation is always an existing allocation,
// the struct returned by this method contains only the differential, which can be
// applied to an existing allocation, to yield the updated struct | [
"normalizeStoppedAlloc",
"removes",
"redundant",
"fields",
"from",
"a",
"stopped",
"allocation",
"and",
"returns",
"AllocationDiff",
".",
"Since",
"a",
"stopped",
"allocation",
"is",
"always",
"an",
"existing",
"allocation",
"the",
"struct",
"returned",
"by",
"this"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L281-L288 |
133,630 | hashicorp/nomad | nomad/plan_apply.go | appendNamespacedJobID | func appendNamespacedJobID(jobIDs map[structs.NamespacedID]struct{}, alloc *structs.Allocation) {
id := structs.NamespacedID{Namespace: alloc.Namespace, ID: alloc.JobID}
if _, ok := jobIDs[id]; !ok {
jobIDs[id] = struct{}{}
}
} | go | func appendNamespacedJobID(jobIDs map[structs.NamespacedID]struct{}, alloc *structs.Allocation) {
id := structs.NamespacedID{Namespace: alloc.Namespace, ID: alloc.JobID}
if _, ok := jobIDs[id]; !ok {
jobIDs[id] = struct{}{}
}
} | [
"func",
"appendNamespacedJobID",
"(",
"jobIDs",
"map",
"[",
"structs",
".",
"NamespacedID",
"]",
"struct",
"{",
"}",
",",
"alloc",
"*",
"structs",
".",
"Allocation",
")",
"{",
"id",
":=",
"structs",
".",
"NamespacedID",
"{",
"Namespace",
":",
"alloc",
".",... | // appendNamespacedJobID appends the namespaced Job ID for the alloc to the jobIDs set | [
"appendNamespacedJobID",
"appends",
"the",
"namespaced",
"Job",
"ID",
"for",
"the",
"alloc",
"to",
"the",
"jobIDs",
"set"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L291-L296 |
133,631 | hashicorp/nomad | nomad/plan_apply.go | updateAllocTimestamps | func updateAllocTimestamps(allocations []*structs.Allocation, timestamp int64) {
for _, alloc := range allocations {
if alloc.CreateTime == 0 {
alloc.CreateTime = timestamp
}
alloc.ModifyTime = timestamp
}
} | go | func updateAllocTimestamps(allocations []*structs.Allocation, timestamp int64) {
for _, alloc := range allocations {
if alloc.CreateTime == 0 {
alloc.CreateTime = timestamp
}
alloc.ModifyTime = timestamp
}
} | [
"func",
"updateAllocTimestamps",
"(",
"allocations",
"[",
"]",
"*",
"structs",
".",
"Allocation",
",",
"timestamp",
"int64",
")",
"{",
"for",
"_",
",",
"alloc",
":=",
"range",
"allocations",
"{",
"if",
"alloc",
".",
"CreateTime",
"==",
"0",
"{",
"alloc",
... | // updateAllocTimestamps sets the CreateTime and ModifyTime for the allocations
// to the timestamp provided | [
"updateAllocTimestamps",
"sets",
"the",
"CreateTime",
"and",
"ModifyTime",
"for",
"the",
"allocations",
"to",
"the",
"timestamp",
"provided"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L300-L307 |
133,632 | hashicorp/nomad | nomad/plan_apply.go | asyncPlanWait | func (p *planner) asyncPlanWait(waitCh chan struct{}, future raft.ApplyFuture,
result *structs.PlanResult, pending *pendingPlan) {
defer metrics.MeasureSince([]string{"nomad", "plan", "apply"}, time.Now())
defer close(waitCh)
// Wait for the plan to apply
if err := future.Error(); err != nil {
p.logger.Error("f... | go | func (p *planner) asyncPlanWait(waitCh chan struct{}, future raft.ApplyFuture,
result *structs.PlanResult, pending *pendingPlan) {
defer metrics.MeasureSince([]string{"nomad", "plan", "apply"}, time.Now())
defer close(waitCh)
// Wait for the plan to apply
if err := future.Error(); err != nil {
p.logger.Error("f... | [
"func",
"(",
"p",
"*",
"planner",
")",
"asyncPlanWait",
"(",
"waitCh",
"chan",
"struct",
"{",
"}",
",",
"future",
"raft",
".",
"ApplyFuture",
",",
"result",
"*",
"structs",
".",
"PlanResult",
",",
"pending",
"*",
"pendingPlan",
")",
"{",
"defer",
"metric... | // asyncPlanWait is used to apply and respond to a plan async | [
"asyncPlanWait",
"is",
"used",
"to",
"apply",
"and",
"respond",
"to",
"a",
"plan",
"async"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L310-L333 |
133,633 | hashicorp/nomad | nomad/plan_apply.go | evaluatePlan | func evaluatePlan(pool *EvaluatePool, snap *state.StateSnapshot, plan *structs.Plan, logger log.Logger) (*structs.PlanResult, error) {
defer metrics.MeasureSince([]string{"nomad", "plan", "evaluate"}, time.Now())
// Denormalize without the job
err := snap.DenormalizeAllocationsMap(plan.NodeUpdate, nil)
if err != n... | go | func evaluatePlan(pool *EvaluatePool, snap *state.StateSnapshot, plan *structs.Plan, logger log.Logger) (*structs.PlanResult, error) {
defer metrics.MeasureSince([]string{"nomad", "plan", "evaluate"}, time.Now())
// Denormalize without the job
err := snap.DenormalizeAllocationsMap(plan.NodeUpdate, nil)
if err != n... | [
"func",
"evaluatePlan",
"(",
"pool",
"*",
"EvaluatePool",
",",
"snap",
"*",
"state",
".",
"StateSnapshot",
",",
"plan",
"*",
"structs",
".",
"Plan",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"*",
"structs",
".",
"PlanResult",
",",
"error",
")",
"{... | // evaluatePlan is used to determine what portions of a plan
// can be applied if any. Returns if there should be a plan application
// which may be partial or if there was an error | [
"evaluatePlan",
"is",
"used",
"to",
"determine",
"what",
"portions",
"of",
"a",
"plan",
"can",
"be",
"applied",
"if",
"any",
".",
"Returns",
"if",
"there",
"should",
"be",
"a",
"plan",
"application",
"which",
"may",
"be",
"partial",
"or",
"if",
"there",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L338-L370 |
133,634 | hashicorp/nomad | nomad/plan_apply.go | correctDeploymentCanaries | func correctDeploymentCanaries(result *structs.PlanResult) {
// Hot path
if result.Deployment == nil || !result.Deployment.HasPlacedCanaries() {
return
}
// Build a set of all the allocations IDs that were placed
placedAllocs := make(map[string]struct{}, len(result.NodeAllocation))
for _, placed := range resul... | go | func correctDeploymentCanaries(result *structs.PlanResult) {
// Hot path
if result.Deployment == nil || !result.Deployment.HasPlacedCanaries() {
return
}
// Build a set of all the allocations IDs that were placed
placedAllocs := make(map[string]struct{}, len(result.NodeAllocation))
for _, placed := range resul... | [
"func",
"correctDeploymentCanaries",
"(",
"result",
"*",
"structs",
".",
"PlanResult",
")",
"{",
"// Hot path",
"if",
"result",
".",
"Deployment",
"==",
"nil",
"||",
"!",
"result",
".",
"Deployment",
".",
"HasPlacedCanaries",
"(",
")",
"{",
"return",
"\n",
"... | // correctDeploymentCanaries ensures that the deployment object doesn't list any
// canaries as placed if they didn't actually get placed. This could happen if
// the plan had a partial commit. | [
"correctDeploymentCanaries",
"ensures",
"that",
"the",
"deployment",
"object",
"doesn",
"t",
"list",
"any",
"canaries",
"as",
"placed",
"if",
"they",
"didn",
"t",
"actually",
"get",
"placed",
".",
"This",
"could",
"happen",
"if",
"the",
"plan",
"had",
"a",
"... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L530-L563 |
133,635 | hashicorp/nomad | nomad/plan_apply.go | evaluateNodePlan | func evaluateNodePlan(snap *state.StateSnapshot, plan *structs.Plan, nodeID string) (bool, string, error) {
// If this is an evict-only plan, it always 'fits' since we are removing things.
if len(plan.NodeAllocation[nodeID]) == 0 {
return true, "", nil
}
// Get the node itself
ws := memdb.NewWatchSet()
node, e... | go | func evaluateNodePlan(snap *state.StateSnapshot, plan *structs.Plan, nodeID string) (bool, string, error) {
// If this is an evict-only plan, it always 'fits' since we are removing things.
if len(plan.NodeAllocation[nodeID]) == 0 {
return true, "", nil
}
// Get the node itself
ws := memdb.NewWatchSet()
node, e... | [
"func",
"evaluateNodePlan",
"(",
"snap",
"*",
"state",
".",
"StateSnapshot",
",",
"plan",
"*",
"structs",
".",
"Plan",
",",
"nodeID",
"string",
")",
"(",
"bool",
",",
"string",
",",
"error",
")",
"{",
"// If this is an evict-only plan, it always 'fits' since we ar... | // evaluateNodePlan is used to evaluate the plan for a single node,
// returning if the plan is valid or if an error is encountered | [
"evaluateNodePlan",
"is",
"used",
"to",
"evaluate",
"the",
"plan",
"for",
"a",
"single",
"node",
"returning",
"if",
"the",
"plan",
"is",
"valid",
"or",
"if",
"an",
"error",
"is",
"encountered"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply.go#L567-L621 |
133,636 | hashicorp/nomad | client/allocrunner/taskrunner/service_hook.go | deregister | func (h *serviceHook) deregister() {
taskServices := h.getTaskServices()
h.consul.RemoveTask(taskServices)
// Canary flag may be getting flipped when the alloc is being
// destroyed, so remove both variations of the service
taskServices.Canary = !taskServices.Canary
h.consul.RemoveTask(taskServices)
} | go | func (h *serviceHook) deregister() {
taskServices := h.getTaskServices()
h.consul.RemoveTask(taskServices)
// Canary flag may be getting flipped when the alloc is being
// destroyed, so remove both variations of the service
taskServices.Canary = !taskServices.Canary
h.consul.RemoveTask(taskServices)
} | [
"func",
"(",
"h",
"*",
"serviceHook",
")",
"deregister",
"(",
")",
"{",
"taskServices",
":=",
"h",
".",
"getTaskServices",
"(",
")",
"\n",
"h",
".",
"consul",
".",
"RemoveTask",
"(",
"taskServices",
")",
"\n\n",
"// Canary flag may be getting flipped when the al... | // deregister services from Consul. | [
"deregister",
"services",
"from",
"Consul",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/service_hook.go#L171-L180 |
133,637 | hashicorp/nomad | client/allocrunner/taskrunner/service_hook.go | interpolateServices | func interpolateServices(taskEnv *taskenv.TaskEnv, services []*structs.Service) []*structs.Service {
// Guard against not having a valid taskEnv. This can be the case if the
// PreKilling or Exited hook is run before Poststart.
if taskEnv == nil || len(services) == 0 {
return nil
}
interpolated := make([]*struc... | go | func interpolateServices(taskEnv *taskenv.TaskEnv, services []*structs.Service) []*structs.Service {
// Guard against not having a valid taskEnv. This can be the case if the
// PreKilling or Exited hook is run before Poststart.
if taskEnv == nil || len(services) == 0 {
return nil
}
interpolated := make([]*struc... | [
"func",
"interpolateServices",
"(",
"taskEnv",
"*",
"taskenv",
".",
"TaskEnv",
",",
"services",
"[",
"]",
"*",
"structs",
".",
"Service",
")",
"[",
"]",
"*",
"structs",
".",
"Service",
"{",
"// Guard against not having a valid taskEnv. This can be the case if the",
... | // interpolateServices returns an interpolated copy of services and checks with
// values from the task's environment. | [
"interpolateServices",
"returns",
"an",
"interpolated",
"copy",
"of",
"services",
"and",
"checks",
"with",
"values",
"from",
"the",
"task",
"s",
"environment",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocrunner/taskrunner/service_hook.go#L201-L247 |
133,638 | hashicorp/nomad | client/allocdir/alloc_dir.go | NewAllocDir | func NewAllocDir(logger hclog.Logger, allocDir string) *AllocDir {
logger = logger.Named("alloc_dir")
return &AllocDir{
AllocDir: allocDir,
SharedDir: filepath.Join(allocDir, SharedAllocName),
TaskDirs: make(map[string]*TaskDir),
logger: logger,
}
} | go | func NewAllocDir(logger hclog.Logger, allocDir string) *AllocDir {
logger = logger.Named("alloc_dir")
return &AllocDir{
AllocDir: allocDir,
SharedDir: filepath.Join(allocDir, SharedAllocName),
TaskDirs: make(map[string]*TaskDir),
logger: logger,
}
} | [
"func",
"NewAllocDir",
"(",
"logger",
"hclog",
".",
"Logger",
",",
"allocDir",
"string",
")",
"*",
"AllocDir",
"{",
"logger",
"=",
"logger",
".",
"Named",
"(",
"\"",
"\"",
")",
"\n",
"return",
"&",
"AllocDir",
"{",
"AllocDir",
":",
"allocDir",
",",
"Sh... | // NewAllocDir initializes the AllocDir struct with allocDir as base path for
// the allocation directory. | [
"NewAllocDir",
"initializes",
"the",
"AllocDir",
"struct",
"with",
"allocDir",
"as",
"base",
"path",
"for",
"the",
"allocation",
"directory",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L96-L104 |
133,639 | hashicorp/nomad | client/allocdir/alloc_dir.go | Copy | func (d *AllocDir) Copy() *AllocDir {
d.mu.RLock()
defer d.mu.RUnlock()
if d == nil {
return nil
}
dcopy := &AllocDir{
AllocDir: d.AllocDir,
SharedDir: d.SharedDir,
TaskDirs: make(map[string]*TaskDir, len(d.TaskDirs)),
logger: d.logger,
}
for k, v := range d.TaskDirs {
dcopy.TaskDirs[k] = v.Cop... | go | func (d *AllocDir) Copy() *AllocDir {
d.mu.RLock()
defer d.mu.RUnlock()
if d == nil {
return nil
}
dcopy := &AllocDir{
AllocDir: d.AllocDir,
SharedDir: d.SharedDir,
TaskDirs: make(map[string]*TaskDir, len(d.TaskDirs)),
logger: d.logger,
}
for k, v := range d.TaskDirs {
dcopy.TaskDirs[k] = v.Cop... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"Copy",
"(",
")",
"*",
"AllocDir",
"{",
"d",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"d",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
... | // Copy an AllocDir and all of its TaskDirs. Returns nil if AllocDir is
// nil. | [
"Copy",
"an",
"AllocDir",
"and",
"all",
"of",
"its",
"TaskDirs",
".",
"Returns",
"nil",
"if",
"AllocDir",
"is",
"nil",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L108-L125 |
133,640 | hashicorp/nomad | client/allocdir/alloc_dir.go | NewTaskDir | func (d *AllocDir) NewTaskDir(name string) *TaskDir {
d.mu.Lock()
defer d.mu.Unlock()
td := newTaskDir(d.logger, d.AllocDir, name)
d.TaskDirs[name] = td
return td
} | go | func (d *AllocDir) NewTaskDir(name string) *TaskDir {
d.mu.Lock()
defer d.mu.Unlock()
td := newTaskDir(d.logger, d.AllocDir, name)
d.TaskDirs[name] = td
return td
} | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"NewTaskDir",
"(",
"name",
"string",
")",
"*",
"TaskDir",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"td",
":=",
"newTaskDir",
"(",
"d",
".... | // NewTaskDir creates a new TaskDir and adds it to the AllocDirs TaskDirs map. | [
"NewTaskDir",
"creates",
"a",
"new",
"TaskDir",
"and",
"adds",
"it",
"to",
"the",
"AllocDirs",
"TaskDirs",
"map",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L128-L135 |
133,641 | hashicorp/nomad | client/allocdir/alloc_dir.go | Move | func (d *AllocDir) Move(other *AllocDir, tasks []*structs.Task) error {
d.mu.RLock()
if !d.built {
// Enforce the invariant that Build is called before Move
d.mu.RUnlock()
return fmt.Errorf("unable to move to %q - alloc dir is not built", d.AllocDir)
}
// Moving is slow and only reads immutable fields, so un... | go | func (d *AllocDir) Move(other *AllocDir, tasks []*structs.Task) error {
d.mu.RLock()
if !d.built {
// Enforce the invariant that Build is called before Move
d.mu.RUnlock()
return fmt.Errorf("unable to move to %q - alloc dir is not built", d.AllocDir)
}
// Moving is slow and only reads immutable fields, so un... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"Move",
"(",
"other",
"*",
"AllocDir",
",",
"tasks",
"[",
"]",
"*",
"structs",
".",
"Task",
")",
"error",
"{",
"d",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"if",
"!",
"d",
".",
"built",
"{",
"// Enforce ... | // Move other alloc directory's shared path and local dir to this alloc dir. | [
"Move",
"other",
"alloc",
"directory",
"s",
"shared",
"path",
"and",
"local",
"dir",
"to",
"this",
"alloc",
"dir",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L223-L265 |
133,642 | hashicorp/nomad | client/allocdir/alloc_dir.go | Destroy | func (d *AllocDir) Destroy() error {
// Unmount all mounted shared alloc dirs.
var mErr multierror.Error
if err := d.UnmountAll(); err != nil {
mErr.Errors = append(mErr.Errors, err)
}
if err := os.RemoveAll(d.AllocDir); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("failed to remove alloc dir %q:... | go | func (d *AllocDir) Destroy() error {
// Unmount all mounted shared alloc dirs.
var mErr multierror.Error
if err := d.UnmountAll(); err != nil {
mErr.Errors = append(mErr.Errors, err)
}
if err := os.RemoveAll(d.AllocDir); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("failed to remove alloc dir %q:... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"Destroy",
"(",
")",
"error",
"{",
"// Unmount all mounted shared alloc dirs.",
"var",
"mErr",
"multierror",
".",
"Error",
"\n",
"if",
"err",
":=",
"d",
".",
"UnmountAll",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"m... | // Tears down previously build directory structure. | [
"Tears",
"down",
"previously",
"build",
"directory",
"structure",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L268-L284 |
133,643 | hashicorp/nomad | client/allocdir/alloc_dir.go | Build | func (d *AllocDir) Build() error {
// Make the alloc directory, owned by the nomad process.
if err := os.MkdirAll(d.AllocDir, 0755); err != nil {
return fmt.Errorf("Failed to make the alloc directory %v: %v", d.AllocDir, err)
}
// Make the shared directory and make it available to all user/groups.
if err := os.... | go | func (d *AllocDir) Build() error {
// Make the alloc directory, owned by the nomad process.
if err := os.MkdirAll(d.AllocDir, 0755); err != nil {
return fmt.Errorf("Failed to make the alloc directory %v: %v", d.AllocDir, err)
}
// Make the shared directory and make it available to all user/groups.
if err := os.... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"Build",
"(",
")",
"error",
"{",
"// Make the alloc directory, owned by the nomad process.",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"d",
".",
"AllocDir",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"retur... | // Build the directory tree for an allocation. | [
"Build",
"the",
"directory",
"tree",
"for",
"an",
"allocation",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L321-L353 |
133,644 | hashicorp/nomad | client/allocdir/alloc_dir.go | List | func (d *AllocDir) List(path string) ([]*cstructs.AllocFileInfo, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc directory")
}
p ... | go | func (d *AllocDir) List(path string) ([]*cstructs.AllocFileInfo, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc directory")
}
p ... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"List",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"*",
"cstructs",
".",
"AllocFileInfo",
",",
"error",
")",
"{",
"if",
"escapes",
",",
"err",
":=",
"structs",
".",
"PathEscapesAllocDir",
"(",
"\"",
"\"",
",",
... | // List returns the list of files at a path relative to the alloc dir | [
"List",
"returns",
"the",
"list",
"of",
"files",
"at",
"a",
"path",
"relative",
"to",
"the",
"alloc",
"dir"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L356-L379 |
133,645 | hashicorp/nomad | client/allocdir/alloc_dir.go | Stat | func (d *AllocDir) Stat(path string) (*cstructs.AllocFileInfo, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc directory")
}
p :=... | go | func (d *AllocDir) Stat(path string) (*cstructs.AllocFileInfo, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc directory")
}
p :=... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"Stat",
"(",
"path",
"string",
")",
"(",
"*",
"cstructs",
".",
"AllocFileInfo",
",",
"error",
")",
"{",
"if",
"escapes",
",",
"err",
":=",
"structs",
".",
"PathEscapesAllocDir",
"(",
"\"",
"\"",
",",
"path",
")... | // Stat returns information about the file at a path relative to the alloc dir | [
"Stat",
"returns",
"information",
"about",
"the",
"file",
"at",
"a",
"path",
"relative",
"to",
"the",
"alloc",
"dir"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L382-L402 |
133,646 | hashicorp/nomad | client/allocdir/alloc_dir.go | ReadAt | func (d *AllocDir) ReadAt(path string, offset int64) (io.ReadCloser, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc directory")
}
... | go | func (d *AllocDir) ReadAt(path string, offset int64) (io.ReadCloser, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc directory")
}
... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"ReadAt",
"(",
"path",
"string",
",",
"offset",
"int64",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"escapes",
",",
"err",
":=",
"structs",
".",
"PathEscapesAllocDir",
"(",
"\"",
"\"",
","... | // ReadAt returns a reader for a file at the path relative to the alloc dir | [
"ReadAt",
"returns",
"a",
"reader",
"for",
"a",
"file",
"at",
"the",
"path",
"relative",
"to",
"the",
"alloc",
"dir"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L405-L432 |
133,647 | hashicorp/nomad | client/allocdir/alloc_dir.go | BlockUntilExists | func (d *AllocDir) BlockUntilExists(ctx context.Context, path string) (chan error, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc d... | go | func (d *AllocDir) BlockUntilExists(ctx context.Context, path string) (chan error, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Path escapes the alloc d... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"BlockUntilExists",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
")",
"(",
"chan",
"error",
",",
"error",
")",
"{",
"if",
"escapes",
",",
"err",
":=",
"structs",
".",
"PathEscapesAllocDir",
"(",
... | // BlockUntilExists blocks until the passed file relative the allocation
// directory exists. The block can be cancelled with the passed context. | [
"BlockUntilExists",
"blocks",
"until",
"the",
"passed",
"file",
"relative",
"the",
"allocation",
"directory",
"exists",
".",
"The",
"block",
"can",
"be",
"cancelled",
"with",
"the",
"passed",
"context",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L436-L457 |
133,648 | hashicorp/nomad | client/allocdir/alloc_dir.go | ChangeEvents | func (d *AllocDir) ChangeEvents(ctx context.Context, path string, curOffset int64) (*watch.FileChanges, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Pat... | go | func (d *AllocDir) ChangeEvents(ctx context.Context, path string, curOffset int64) (*watch.FileChanges, error) {
if escapes, err := structs.PathEscapesAllocDir("", path); err != nil {
return nil, fmt.Errorf("Failed to check if path escapes alloc directory: %v", err)
} else if escapes {
return nil, fmt.Errorf("Pat... | [
"func",
"(",
"d",
"*",
"AllocDir",
")",
"ChangeEvents",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
",",
"curOffset",
"int64",
")",
"(",
"*",
"watch",
".",
"FileChanges",
",",
"error",
")",
"{",
"if",
"escapes",
",",
"err",
":=",
"s... | // ChangeEvents watches for changes to the passed path relative to the
// allocation directory. The offset should be the last read offset. The context is
// used to clean up the watch. | [
"ChangeEvents",
"watches",
"for",
"changes",
"to",
"the",
"passed",
"path",
"relative",
"to",
"the",
"allocation",
"directory",
".",
"The",
"offset",
"should",
"be",
"the",
"last",
"read",
"offset",
".",
"The",
"context",
"is",
"used",
"to",
"clean",
"up",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L462-L479 |
133,649 | hashicorp/nomad | client/allocdir/alloc_dir.go | pathEmpty | func pathEmpty(path string) (bool, error) {
f, err := os.Open(path)
if err != nil {
return false, err
}
defer f.Close()
entries, err := f.Readdir(1)
if err != nil && err != io.EOF {
return false, err
}
return len(entries) == 0, nil
} | go | func pathEmpty(path string) (bool, error) {
f, err := os.Open(path)
if err != nil {
return false, err
}
defer f.Close()
entries, err := f.Readdir(1)
if err != nil && err != io.EOF {
return false, err
}
return len(entries) == 0, nil
} | [
"func",
"pathEmpty",
"(",
"path",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",... | // pathEmpty returns true if a path exists, is listable, and is empty. If the
// path does not exist or is not listable an error is returned. | [
"pathEmpty",
"returns",
"true",
"if",
"a",
"path",
"exists",
"is",
"listable",
"and",
"is",
"empty",
".",
"If",
"the",
"path",
"does",
"not",
"exist",
"or",
"is",
"not",
"listable",
"an",
"error",
"is",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L527-L538 |
133,650 | hashicorp/nomad | client/allocdir/alloc_dir.go | createDir | func createDir(basePath, relPath string) error {
filePerms, err := splitPath(relPath)
if err != nil {
return err
}
// We are going backwards since we create the root of the directory first
// and then create the entire nested structure.
for i := len(filePerms) - 1; i >= 0; i-- {
fi := filePerms[i]
destDir ... | go | func createDir(basePath, relPath string) error {
filePerms, err := splitPath(relPath)
if err != nil {
return err
}
// We are going backwards since we create the root of the directory first
// and then create the entire nested structure.
for i := len(filePerms) - 1; i >= 0; i-- {
fi := filePerms[i]
destDir ... | [
"func",
"createDir",
"(",
"basePath",
",",
"relPath",
"string",
")",
"error",
"{",
"filePerms",
",",
"err",
":=",
"splitPath",
"(",
"relPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// We are going backwards since we c... | // createDir creates a directory structure inside the basepath. This functions
// preserves the permissions of each of the subdirectories in the relative path
// by looking up the permissions in the host. | [
"createDir",
"creates",
"a",
"directory",
"structure",
"inside",
"the",
"basepath",
".",
"This",
"functions",
"preserves",
"the",
"permissions",
"of",
"each",
"of",
"the",
"subdirectories",
"in",
"the",
"relative",
"path",
"by",
"looking",
"up",
"the",
"permissi... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L543-L565 |
133,651 | hashicorp/nomad | client/allocdir/alloc_dir.go | splitPath | func splitPath(path string) ([]fileInfo, error) {
var mode os.FileMode
fi, err := os.Stat(path)
// If the path is not present in the host then we respond with the most
// flexible permission.
uid, gid := idUnsupported, idUnsupported
if err != nil {
mode = os.ModePerm
} else {
uid, gid = getOwner(fi)
mode ... | go | func splitPath(path string) ([]fileInfo, error) {
var mode os.FileMode
fi, err := os.Stat(path)
// If the path is not present in the host then we respond with the most
// flexible permission.
uid, gid := idUnsupported, idUnsupported
if err != nil {
mode = os.ModePerm
} else {
uid, gid = getOwner(fi)
mode ... | [
"func",
"splitPath",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"fileInfo",
",",
"error",
")",
"{",
"var",
"mode",
"os",
".",
"FileMode",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
"\n\n",
"// If the path is not present in the hos... | // splitPath stats each subdirectory of a path. The first element of the array
// is the file passed to this function, and the last element is the root of the
// path. | [
"splitPath",
"stats",
"each",
"subdirectory",
"of",
"a",
"path",
".",
"The",
"first",
"element",
"of",
"the",
"array",
"is",
"the",
"file",
"passed",
"to",
"this",
"function",
"and",
"the",
"last",
"element",
"is",
"the",
"root",
"of",
"the",
"path",
"."... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/allocdir/alloc_dir.go#L580-L616 |
133,652 | hashicorp/nomad | client/fingerprint/cpu.go | NewCPUFingerprint | func NewCPUFingerprint(logger log.Logger) Fingerprint {
f := &CPUFingerprint{logger: logger.Named("cpu")}
return f
} | go | func NewCPUFingerprint(logger log.Logger) Fingerprint {
f := &CPUFingerprint{logger: logger.Named("cpu")}
return f
} | [
"func",
"NewCPUFingerprint",
"(",
"logger",
"log",
".",
"Logger",
")",
"Fingerprint",
"{",
"f",
":=",
"&",
"CPUFingerprint",
"{",
"logger",
":",
"logger",
".",
"Named",
"(",
"\"",
"\"",
")",
"}",
"\n",
"return",
"f",
"\n",
"}"
] | // NewCPUFingerprint is used to create a CPU fingerprint | [
"NewCPUFingerprint",
"is",
"used",
"to",
"create",
"a",
"CPU",
"fingerprint"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fingerprint/cpu.go#L18-L21 |
133,653 | hashicorp/nomad | command/quota.go | QuotaPredictor | func QuotaPredictor(factory ApiClientFactory) complete.Predictor {
return complete.PredictFunc(func(a complete.Args) []string {
client, err := factory()
if err != nil {
return nil
}
resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Quotas, nil)
if err != nil {
return []string{}
}
retur... | go | func QuotaPredictor(factory ApiClientFactory) complete.Predictor {
return complete.PredictFunc(func(a complete.Args) []string {
client, err := factory()
if err != nil {
return nil
}
resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Quotas, nil)
if err != nil {
return []string{}
}
retur... | [
"func",
"QuotaPredictor",
"(",
"factory",
"ApiClientFactory",
")",
"complete",
".",
"Predictor",
"{",
"return",
"complete",
".",
"PredictFunc",
"(",
"func",
"(",
"a",
"complete",
".",
"Args",
")",
"[",
"]",
"string",
"{",
"client",
",",
"err",
":=",
"facto... | // QuotaPredictor returns a quota predictor | [
"QuotaPredictor",
"returns",
"a",
"quota",
"predictor"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/quota.go#L54-L67 |
133,654 | hashicorp/nomad | nomad/deployment_endpoint.go | GetDeployment | func (d *Deployment) GetDeployment(args *structs.DeploymentSpecificRequest,
reply *structs.SingleDeploymentResponse) error {
if done, err := d.srv.forward("Deployment.GetDeployment", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "get_deployment"}, time.Now())
... | go | func (d *Deployment) GetDeployment(args *structs.DeploymentSpecificRequest,
reply *structs.SingleDeploymentResponse) error {
if done, err := d.srv.forward("Deployment.GetDeployment", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "get_deployment"}, time.Now())
... | [
"func",
"(",
"d",
"*",
"Deployment",
")",
"GetDeployment",
"(",
"args",
"*",
"structs",
".",
"DeploymentSpecificRequest",
",",
"reply",
"*",
"structs",
".",
"SingleDeploymentResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"d",
".",
"srv",
"."... | // GetDeployment is used to request information about a specific deployment | [
"GetDeployment",
"is",
"used",
"to",
"request",
"information",
"about",
"a",
"specific",
"deployment"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/deployment_endpoint.go#L23-L71 |
133,655 | hashicorp/nomad | nomad/deployment_endpoint.go | Fail | func (d *Deployment) Fail(args *structs.DeploymentFailRequest, reply *structs.DeploymentUpdateResponse) error {
if done, err := d.srv.forward("Deployment.Fail", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "fail"}, time.Now())
// Check namespace submit-job pe... | go | func (d *Deployment) Fail(args *structs.DeploymentFailRequest, reply *structs.DeploymentUpdateResponse) error {
if done, err := d.srv.forward("Deployment.Fail", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "fail"}, time.Now())
// Check namespace submit-job pe... | [
"func",
"(",
"d",
"*",
"Deployment",
")",
"Fail",
"(",
"args",
"*",
"structs",
".",
"DeploymentFailRequest",
",",
"reply",
"*",
"structs",
".",
"DeploymentUpdateResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"d",
".",
"srv",
".",
"forward"... | // Fail is used to force fail a deployment | [
"Fail",
"is",
"used",
"to",
"force",
"fail",
"a",
"deployment"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/deployment_endpoint.go#L74-L113 |
133,656 | hashicorp/nomad | nomad/deployment_endpoint.go | List | func (d *Deployment) List(args *structs.DeploymentListRequest, reply *structs.DeploymentListResponse) error {
if done, err := d.srv.forward("Deployment.List", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "list"}, time.Now())
// Check namespace read-job permis... | go | func (d *Deployment) List(args *structs.DeploymentListRequest, reply *structs.DeploymentListResponse) error {
if done, err := d.srv.forward("Deployment.List", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "list"}, time.Now())
// Check namespace read-job permis... | [
"func",
"(",
"d",
"*",
"Deployment",
")",
"List",
"(",
"args",
"*",
"structs",
".",
"DeploymentListRequest",
",",
"reply",
"*",
"structs",
".",
"DeploymentListResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"d",
".",
"srv",
".",
"forward",
... | // List returns the list of deployments in the system | [
"List",
"returns",
"the",
"list",
"of",
"deployments",
"in",
"the",
"system"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/deployment_endpoint.go#L251-L304 |
133,657 | hashicorp/nomad | nomad/deployment_endpoint.go | Allocations | func (d *Deployment) Allocations(args *structs.DeploymentSpecificRequest, reply *structs.AllocListResponse) error {
if done, err := d.srv.forward("Deployment.Allocations", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "allocations"}, time.Now())
// Check names... | go | func (d *Deployment) Allocations(args *structs.DeploymentSpecificRequest, reply *structs.AllocListResponse) error {
if done, err := d.srv.forward("Deployment.Allocations", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "allocations"}, time.Now())
// Check names... | [
"func",
"(",
"d",
"*",
"Deployment",
")",
"Allocations",
"(",
"args",
"*",
"structs",
".",
"DeploymentSpecificRequest",
",",
"reply",
"*",
"structs",
".",
"AllocListResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"d",
".",
"srv",
".",
"forw... | // Allocations returns the list of allocations that are a part of the deployment | [
"Allocations",
"returns",
"the",
"list",
"of",
"allocations",
"that",
"are",
"a",
"part",
"of",
"the",
"deployment"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/deployment_endpoint.go#L307-L349 |
133,658 | hashicorp/nomad | nomad/deployment_endpoint.go | Reap | func (d *Deployment) Reap(args *structs.DeploymentDeleteRequest,
reply *structs.GenericResponse) error {
if done, err := d.srv.forward("Deployment.Reap", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "reap"}, time.Now())
// Update via Raft
_, index, err := d... | go | func (d *Deployment) Reap(args *structs.DeploymentDeleteRequest,
reply *structs.GenericResponse) error {
if done, err := d.srv.forward("Deployment.Reap", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "deployment", "reap"}, time.Now())
// Update via Raft
_, index, err := d... | [
"func",
"(",
"d",
"*",
"Deployment",
")",
"Reap",
"(",
"args",
"*",
"structs",
".",
"DeploymentDeleteRequest",
",",
"reply",
"*",
"structs",
".",
"GenericResponse",
")",
"error",
"{",
"if",
"done",
",",
"err",
":=",
"d",
".",
"srv",
".",
"forward",
"("... | // Reap is used to cleanup terminal deployments | [
"Reap",
"is",
"used",
"to",
"cleanup",
"terminal",
"deployments"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/deployment_endpoint.go#L352-L368 |
133,659 | hashicorp/nomad | nomad/plan_apply_pool.go | NewEvaluatePool | func NewEvaluatePool(workers, bufSize int) *EvaluatePool {
p := &EvaluatePool{
workers: workers,
workerStop: make([]chan struct{}, workers),
req: make(chan evaluateRequest, bufSize),
res: make(chan evaluateResult, bufSize),
}
for i := 0; i < workers; i++ {
stopCh := make(chan struct{})
p... | go | func NewEvaluatePool(workers, bufSize int) *EvaluatePool {
p := &EvaluatePool{
workers: workers,
workerStop: make([]chan struct{}, workers),
req: make(chan evaluateRequest, bufSize),
res: make(chan evaluateResult, bufSize),
}
for i := 0; i < workers; i++ {
stopCh := make(chan struct{})
p... | [
"func",
"NewEvaluatePool",
"(",
"workers",
",",
"bufSize",
"int",
")",
"*",
"EvaluatePool",
"{",
"p",
":=",
"&",
"EvaluatePool",
"{",
"workers",
":",
"workers",
",",
"workerStop",
":",
"make",
"(",
"[",
"]",
"chan",
"struct",
"{",
"}",
",",
"workers",
... | // NewEvaluatePool returns a pool of the given size. | [
"NewEvaluatePool",
"returns",
"a",
"pool",
"of",
"the",
"given",
"size",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply_pool.go#L39-L52 |
133,660 | hashicorp/nomad | nomad/plan_apply_pool.go | SetSize | func (p *EvaluatePool) SetSize(size int) {
// Protect against a negative size
if size < 0 {
size = 0
}
// Handle an upwards resize
if size >= p.workers {
for i := p.workers; i < size; i++ {
stopCh := make(chan struct{})
p.workerStop = append(p.workerStop, stopCh)
go p.run(stopCh)
}
p.workers = si... | go | func (p *EvaluatePool) SetSize(size int) {
// Protect against a negative size
if size < 0 {
size = 0
}
// Handle an upwards resize
if size >= p.workers {
for i := p.workers; i < size; i++ {
stopCh := make(chan struct{})
p.workerStop = append(p.workerStop, stopCh)
go p.run(stopCh)
}
p.workers = si... | [
"func",
"(",
"p",
"*",
"EvaluatePool",
")",
"SetSize",
"(",
"size",
"int",
")",
"{",
"// Protect against a negative size",
"if",
"size",
"<",
"0",
"{",
"size",
"=",
"0",
"\n",
"}",
"\n\n",
"// Handle an upwards resize",
"if",
"size",
">=",
"p",
".",
"worke... | // SetSize is used to resize the worker pool | [
"SetSize",
"is",
"used",
"to",
"resize",
"the",
"worker",
"pool"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply_pool.go#L60-L84 |
133,661 | hashicorp/nomad | nomad/plan_apply_pool.go | run | func (p *EvaluatePool) run(stopCh chan struct{}) {
for {
select {
case req := <-p.req:
fit, reason, err := evaluateNodePlan(req.snap, req.plan, req.nodeID)
p.res <- evaluateResult{req.nodeID, fit, reason, err}
case <-stopCh:
return
}
}
} | go | func (p *EvaluatePool) run(stopCh chan struct{}) {
for {
select {
case req := <-p.req:
fit, reason, err := evaluateNodePlan(req.snap, req.plan, req.nodeID)
p.res <- evaluateResult{req.nodeID, fit, reason, err}
case <-stopCh:
return
}
}
} | [
"func",
"(",
"p",
"*",
"EvaluatePool",
")",
"run",
"(",
"stopCh",
"chan",
"struct",
"{",
"}",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"req",
":=",
"<-",
"p",
".",
"req",
":",
"fit",
",",
"reason",
",",
"err",
":=",
"evaluateNodePlan",
"(",
"... | // run is a long running go routine per worker | [
"run",
"is",
"a",
"long",
"running",
"go",
"routine",
"per",
"worker"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/nomad/plan_apply_pool.go#L102-L113 |
133,662 | hashicorp/nomad | api/acl.go | Delete | func (a *ACLPolicies) Delete(policyName string, q *WriteOptions) (*WriteMeta, error) {
if policyName == "" {
return nil, fmt.Errorf("missing policy name")
}
wm, err := a.client.delete("/v1/acl/policy/"+policyName, nil, q)
if err != nil {
return nil, err
}
return wm, nil
} | go | func (a *ACLPolicies) Delete(policyName string, q *WriteOptions) (*WriteMeta, error) {
if policyName == "" {
return nil, fmt.Errorf("missing policy name")
}
wm, err := a.client.delete("/v1/acl/policy/"+policyName, nil, q)
if err != nil {
return nil, err
}
return wm, nil
} | [
"func",
"(",
"a",
"*",
"ACLPolicies",
")",
"Delete",
"(",
"policyName",
"string",
",",
"q",
"*",
"WriteOptions",
")",
"(",
"*",
"WriteMeta",
",",
"error",
")",
"{",
"if",
"policyName",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf"... | // Delete is used to delete a policy | [
"Delete",
"is",
"used",
"to",
"delete",
"a",
"policy"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L41-L50 |
133,663 | hashicorp/nomad | api/acl.go | Info | func (a *ACLPolicies) Info(policyName string, q *QueryOptions) (*ACLPolicy, *QueryMeta, error) {
if policyName == "" {
return nil, nil, fmt.Errorf("missing policy name")
}
var resp ACLPolicy
wm, err := a.client.query("/v1/acl/policy/"+policyName, &resp, q)
if err != nil {
return nil, nil, err
}
return &resp,... | go | func (a *ACLPolicies) Info(policyName string, q *QueryOptions) (*ACLPolicy, *QueryMeta, error) {
if policyName == "" {
return nil, nil, fmt.Errorf("missing policy name")
}
var resp ACLPolicy
wm, err := a.client.query("/v1/acl/policy/"+policyName, &resp, q)
if err != nil {
return nil, nil, err
}
return &resp,... | [
"func",
"(",
"a",
"*",
"ACLPolicies",
")",
"Info",
"(",
"policyName",
"string",
",",
"q",
"*",
"QueryOptions",
")",
"(",
"*",
"ACLPolicy",
",",
"*",
"QueryMeta",
",",
"error",
")",
"{",
"if",
"policyName",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",... | // Info is used to query a specific policy | [
"Info",
"is",
"used",
"to",
"query",
"a",
"specific",
"policy"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L53-L63 |
133,664 | hashicorp/nomad | api/acl.go | Bootstrap | func (a *ACLTokens) Bootstrap(q *WriteOptions) (*ACLToken, *WriteMeta, error) {
var resp ACLToken
wm, err := a.client.write("/v1/acl/bootstrap", nil, &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, wm, nil
} | go | func (a *ACLTokens) Bootstrap(q *WriteOptions) (*ACLToken, *WriteMeta, error) {
var resp ACLToken
wm, err := a.client.write("/v1/acl/bootstrap", nil, &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, wm, nil
} | [
"func",
"(",
"a",
"*",
"ACLTokens",
")",
"Bootstrap",
"(",
"q",
"*",
"WriteOptions",
")",
"(",
"*",
"ACLToken",
",",
"*",
"WriteMeta",
",",
"error",
")",
"{",
"var",
"resp",
"ACLToken",
"\n",
"wm",
",",
"err",
":=",
"a",
".",
"client",
".",
"write"... | // Bootstrap is used to get the initial bootstrap token | [
"Bootstrap",
"is",
"used",
"to",
"get",
"the",
"initial",
"bootstrap",
"token"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L76-L83 |
133,665 | hashicorp/nomad | api/acl.go | List | func (a *ACLTokens) List(q *QueryOptions) ([]*ACLTokenListStub, *QueryMeta, error) {
var resp []*ACLTokenListStub
qm, err := a.client.query("/v1/acl/tokens", &resp, q)
if err != nil {
return nil, nil, err
}
return resp, qm, nil
} | go | func (a *ACLTokens) List(q *QueryOptions) ([]*ACLTokenListStub, *QueryMeta, error) {
var resp []*ACLTokenListStub
qm, err := a.client.query("/v1/acl/tokens", &resp, q)
if err != nil {
return nil, nil, err
}
return resp, qm, nil
} | [
"func",
"(",
"a",
"*",
"ACLTokens",
")",
"List",
"(",
"q",
"*",
"QueryOptions",
")",
"(",
"[",
"]",
"*",
"ACLTokenListStub",
",",
"*",
"QueryMeta",
",",
"error",
")",
"{",
"var",
"resp",
"[",
"]",
"*",
"ACLTokenListStub",
"\n",
"qm",
",",
"err",
":... | // List is used to dump all of the tokens. | [
"List",
"is",
"used",
"to",
"dump",
"all",
"of",
"the",
"tokens",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L86-L93 |
133,666 | hashicorp/nomad | api/acl.go | Create | func (a *ACLTokens) Create(token *ACLToken, q *WriteOptions) (*ACLToken, *WriteMeta, error) {
if token.AccessorID != "" {
return nil, nil, fmt.Errorf("cannot specify Accessor ID")
}
var resp ACLToken
wm, err := a.client.write("/v1/acl/token", token, &resp, q)
if err != nil {
return nil, nil, err
}
return &re... | go | func (a *ACLTokens) Create(token *ACLToken, q *WriteOptions) (*ACLToken, *WriteMeta, error) {
if token.AccessorID != "" {
return nil, nil, fmt.Errorf("cannot specify Accessor ID")
}
var resp ACLToken
wm, err := a.client.write("/v1/acl/token", token, &resp, q)
if err != nil {
return nil, nil, err
}
return &re... | [
"func",
"(",
"a",
"*",
"ACLTokens",
")",
"Create",
"(",
"token",
"*",
"ACLToken",
",",
"q",
"*",
"WriteOptions",
")",
"(",
"*",
"ACLToken",
",",
"*",
"WriteMeta",
",",
"error",
")",
"{",
"if",
"token",
".",
"AccessorID",
"!=",
"\"",
"\"",
"{",
"ret... | // Create is used to create a token | [
"Create",
"is",
"used",
"to",
"create",
"a",
"token"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L96-L106 |
133,667 | hashicorp/nomad | api/acl.go | Delete | func (a *ACLTokens) Delete(accessorID string, q *WriteOptions) (*WriteMeta, error) {
if accessorID == "" {
return nil, fmt.Errorf("missing accessor ID")
}
wm, err := a.client.delete("/v1/acl/token/"+accessorID, nil, q)
if err != nil {
return nil, err
}
return wm, nil
} | go | func (a *ACLTokens) Delete(accessorID string, q *WriteOptions) (*WriteMeta, error) {
if accessorID == "" {
return nil, fmt.Errorf("missing accessor ID")
}
wm, err := a.client.delete("/v1/acl/token/"+accessorID, nil, q)
if err != nil {
return nil, err
}
return wm, nil
} | [
"func",
"(",
"a",
"*",
"ACLTokens",
")",
"Delete",
"(",
"accessorID",
"string",
",",
"q",
"*",
"WriteOptions",
")",
"(",
"*",
"WriteMeta",
",",
"error",
")",
"{",
"if",
"accessorID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
... | // Delete is used to delete a token | [
"Delete",
"is",
"used",
"to",
"delete",
"a",
"token"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L123-L132 |
133,668 | hashicorp/nomad | api/acl.go | Info | func (a *ACLTokens) Info(accessorID string, q *QueryOptions) (*ACLToken, *QueryMeta, error) {
if accessorID == "" {
return nil, nil, fmt.Errorf("missing accessor ID")
}
var resp ACLToken
wm, err := a.client.query("/v1/acl/token/"+accessorID, &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, wm, ... | go | func (a *ACLTokens) Info(accessorID string, q *QueryOptions) (*ACLToken, *QueryMeta, error) {
if accessorID == "" {
return nil, nil, fmt.Errorf("missing accessor ID")
}
var resp ACLToken
wm, err := a.client.query("/v1/acl/token/"+accessorID, &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, wm, ... | [
"func",
"(",
"a",
"*",
"ACLTokens",
")",
"Info",
"(",
"accessorID",
"string",
",",
"q",
"*",
"QueryOptions",
")",
"(",
"*",
"ACLToken",
",",
"*",
"QueryMeta",
",",
"error",
")",
"{",
"if",
"accessorID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
... | // Info is used to query a token | [
"Info",
"is",
"used",
"to",
"query",
"a",
"token"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L135-L145 |
133,669 | hashicorp/nomad | api/acl.go | Self | func (a *ACLTokens) Self(q *QueryOptions) (*ACLToken, *QueryMeta, error) {
var resp ACLToken
wm, err := a.client.query("/v1/acl/token/self", &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, wm, nil
} | go | func (a *ACLTokens) Self(q *QueryOptions) (*ACLToken, *QueryMeta, error) {
var resp ACLToken
wm, err := a.client.query("/v1/acl/token/self", &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, wm, nil
} | [
"func",
"(",
"a",
"*",
"ACLTokens",
")",
"Self",
"(",
"q",
"*",
"QueryOptions",
")",
"(",
"*",
"ACLToken",
",",
"*",
"QueryMeta",
",",
"error",
")",
"{",
"var",
"resp",
"ACLToken",
"\n",
"wm",
",",
"err",
":=",
"a",
".",
"client",
".",
"query",
"... | // Self is used to query our own token | [
"Self",
"is",
"used",
"to",
"query",
"our",
"own",
"token"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/acl.go#L148-L155 |
133,670 | hashicorp/nomad | client/util.go | diffAllocs | func diffAllocs(existing map[string]uint64, allocs *allocUpdates) *diffResult {
// Scan the existing allocations
result := &diffResult{}
for existID, existIndex := range existing {
// Check if the alloc was updated or filtered because an update wasn't
// needed.
alloc, pulled := allocs.pulled[existID]
_, fil... | go | func diffAllocs(existing map[string]uint64, allocs *allocUpdates) *diffResult {
// Scan the existing allocations
result := &diffResult{}
for existID, existIndex := range existing {
// Check if the alloc was updated or filtered because an update wasn't
// needed.
alloc, pulled := allocs.pulled[existID]
_, fil... | [
"func",
"diffAllocs",
"(",
"existing",
"map",
"[",
"string",
"]",
"uint64",
",",
"allocs",
"*",
"allocUpdates",
")",
"*",
"diffResult",
"{",
"// Scan the existing allocations",
"result",
":=",
"&",
"diffResult",
"{",
"}",
"\n",
"for",
"existID",
",",
"existInd... | // diffAllocs is used to diff the existing and updated allocations
// to see what has happened. | [
"diffAllocs",
"is",
"used",
"to",
"diff",
"the",
"existing",
"and",
"updated",
"allocations",
"to",
"see",
"what",
"has",
"happened",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/util.go#L26-L58 |
133,671 | hashicorp/nomad | client/util.go | stoppedTimer | func stoppedTimer() *time.Timer {
timer := time.NewTimer(0)
if !timer.Stop() {
<-timer.C
}
return timer
} | go | func stoppedTimer() *time.Timer {
timer := time.NewTimer(0)
if !timer.Stop() {
<-timer.C
}
return timer
} | [
"func",
"stoppedTimer",
"(",
")",
"*",
"time",
".",
"Timer",
"{",
"timer",
":=",
"time",
".",
"NewTimer",
"(",
"0",
")",
"\n",
"if",
"!",
"timer",
".",
"Stop",
"(",
")",
"{",
"<-",
"timer",
".",
"C",
"\n",
"}",
"\n",
"return",
"timer",
"\n",
"}... | // stoppedTimer returns a timer that's stopped and wouldn't fire until
// it's reset | [
"stoppedTimer",
"returns",
"a",
"timer",
"that",
"s",
"stopped",
"and",
"wouldn",
"t",
"fire",
"until",
"it",
"s",
"reset"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/util.go#L70-L76 |
133,672 | hashicorp/nomad | command/data_format.go | DataFormat | func DataFormat(format, tmpl string) (DataFormatter, error) {
switch format {
case "json":
if len(tmpl) > 0 {
return nil, fmt.Errorf("json format does not support template option.")
}
return &JSONFormat{}, nil
case "template":
return &TemplateFormat{tmpl}, nil
}
return nil, fmt.Errorf("Unsupported forma... | go | func DataFormat(format, tmpl string) (DataFormatter, error) {
switch format {
case "json":
if len(tmpl) > 0 {
return nil, fmt.Errorf("json format does not support template option.")
}
return &JSONFormat{}, nil
case "template":
return &TemplateFormat{tmpl}, nil
}
return nil, fmt.Errorf("Unsupported forma... | [
"func",
"DataFormat",
"(",
"format",
",",
"tmpl",
"string",
")",
"(",
"DataFormatter",
",",
"error",
")",
"{",
"switch",
"format",
"{",
"case",
"\"",
"\"",
":",
"if",
"len",
"(",
"tmpl",
")",
">",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf... | // DataFormat returns the data formatter specified format. | [
"DataFormat",
"returns",
"the",
"data",
"formatter",
"specified",
"format",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/data_format.go#L26-L37 |
133,673 | hashicorp/nomad | command/data_format.go | TransformData | func (p *JSONFormat) TransformData(data interface{}) (string, error) {
var buf bytes.Buffer
enc := codec.NewEncoder(&buf, jsonHandlePretty)
err := enc.Encode(data)
if err != nil {
return "", err
}
return buf.String(), nil
} | go | func (p *JSONFormat) TransformData(data interface{}) (string, error) {
var buf bytes.Buffer
enc := codec.NewEncoder(&buf, jsonHandlePretty)
err := enc.Encode(data)
if err != nil {
return "", err
}
return buf.String(), nil
} | [
"func",
"(",
"p",
"*",
"JSONFormat",
")",
"TransformData",
"(",
"data",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"enc",
":=",
"codec",
".",
"NewEncoder",
"(",
"&",
"buf",
",",
"j... | // TransformData returns JSON format string data. | [
"TransformData",
"returns",
"JSON",
"format",
"string",
"data",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/data_format.go#L43-L52 |
133,674 | hashicorp/nomad | command/data_format.go | TransformData | func (p *TemplateFormat) TransformData(data interface{}) (string, error) {
var out io.Writer = new(bytes.Buffer)
if len(p.tmpl) == 0 {
return "", fmt.Errorf("template needs to be specified the golang templates.")
}
t, err := template.New("format").Parse(p.tmpl)
if err != nil {
return "", err
}
err = t.Exec... | go | func (p *TemplateFormat) TransformData(data interface{}) (string, error) {
var out io.Writer = new(bytes.Buffer)
if len(p.tmpl) == 0 {
return "", fmt.Errorf("template needs to be specified the golang templates.")
}
t, err := template.New("format").Parse(p.tmpl)
if err != nil {
return "", err
}
err = t.Exec... | [
"func",
"(",
"p",
"*",
"TemplateFormat",
")",
"TransformData",
"(",
"data",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"out",
"io",
".",
"Writer",
"=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"if",
"len",
"(",
... | // TransformData returns template format string data. | [
"TransformData",
"returns",
"template",
"format",
"string",
"data",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/command/data_format.go#L59-L75 |
133,675 | hashicorp/nomad | helper/pool/pool.go | NewClientCodec | func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec {
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle)
} | go | func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec {
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle)
} | [
"func",
"NewClientCodec",
"(",
"conn",
"io",
".",
"ReadWriteCloser",
")",
"rpc",
".",
"ClientCodec",
"{",
"return",
"msgpackrpc",
".",
"NewCodecFromHandle",
"(",
"true",
",",
"true",
",",
"conn",
",",
"structs",
".",
"HashiMsgpackHandle",
")",
"\n",
"}"
] | // NewClientCodec returns a new rpc.ClientCodec to be used to make RPC calls. | [
"NewClientCodec",
"returns",
"a",
"new",
"rpc",
".",
"ClientCodec",
"to",
"be",
"used",
"to",
"make",
"RPC",
"calls",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/pool/pool.go#L22-L24 |
133,676 | hashicorp/nomad | helper/pool/pool.go | NewServerCodec | func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle)
} | go | func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle)
} | [
"func",
"NewServerCodec",
"(",
"conn",
"io",
".",
"ReadWriteCloser",
")",
"rpc",
".",
"ServerCodec",
"{",
"return",
"msgpackrpc",
".",
"NewCodecFromHandle",
"(",
"true",
",",
"true",
",",
"conn",
",",
"structs",
".",
"HashiMsgpackHandle",
")",
"\n",
"}"
] | // NewServerCodec returns a new rpc.ServerCodec to be used to handle RPCs. | [
"NewServerCodec",
"returns",
"a",
"new",
"rpc",
".",
"ServerCodec",
"to",
"be",
"used",
"to",
"handle",
"RPCs",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/pool/pool.go#L27-L29 |
133,677 | hashicorp/nomad | helper/pool/pool.go | NewPool | func NewPool(logger hclog.Logger, maxTime time.Duration, maxStreams int, tlsWrap tlsutil.RegionWrapper) *ConnPool {
pool := &ConnPool{
logger: logger.StandardLogger(&hclog.StandardLoggerOptions{InferLevels: true}),
maxTime: maxTime,
maxStreams: maxStreams,
pool: make(map[string]*Conn),
limiter: ... | go | func NewPool(logger hclog.Logger, maxTime time.Duration, maxStreams int, tlsWrap tlsutil.RegionWrapper) *ConnPool {
pool := &ConnPool{
logger: logger.StandardLogger(&hclog.StandardLoggerOptions{InferLevels: true}),
maxTime: maxTime,
maxStreams: maxStreams,
pool: make(map[string]*Conn),
limiter: ... | [
"func",
"NewPool",
"(",
"logger",
"hclog",
".",
"Logger",
",",
"maxTime",
"time",
".",
"Duration",
",",
"maxStreams",
"int",
",",
"tlsWrap",
"tlsutil",
".",
"RegionWrapper",
")",
"*",
"ConnPool",
"{",
"pool",
":=",
"&",
"ConnPool",
"{",
"logger",
":",
"l... | // NewPool is used to make a new connection pool
// Maintain at most one connection per host, for up to maxTime.
// Set maxTime to 0 to disable reaping. maxStreams is used to control
// the number of idle streams allowed.
// If TLS settings are provided outgoing connections use TLS. | [
"NewPool",
"is",
"used",
"to",
"make",
"a",
"new",
"connection",
"pool",
"Maintain",
"at",
"most",
"one",
"connection",
"per",
"host",
"for",
"up",
"to",
"maxTime",
".",
"Set",
"maxTime",
"to",
"0",
"to",
"disable",
"reaping",
".",
"maxStreams",
"is",
"u... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/pool/pool.go#L161-L175 |
133,678 | hashicorp/nomad | helper/pool/pool.go | Shutdown | func (p *ConnPool) Shutdown() error {
p.Lock()
defer p.Unlock()
for _, conn := range p.pool {
conn.Close()
}
p.pool = make(map[string]*Conn)
if p.shutdown {
return nil
}
if p.connListener != nil {
close(p.connListener)
p.connListener = nil
}
p.shutdown = true
close(p.shutdownCh)
return nil
} | go | func (p *ConnPool) Shutdown() error {
p.Lock()
defer p.Unlock()
for _, conn := range p.pool {
conn.Close()
}
p.pool = make(map[string]*Conn)
if p.shutdown {
return nil
}
if p.connListener != nil {
close(p.connListener)
p.connListener = nil
}
p.shutdown = true
close(p.shutdownCh)
return nil
} | [
"func",
"(",
"p",
"*",
"ConnPool",
")",
"Shutdown",
"(",
")",
"error",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"conn",
":=",
"range",
"p",
".",
"pool",
"{",
"conn",
".",
"Close",
... | // Shutdown is used to close the connection pool | [
"Shutdown",
"is",
"used",
"to",
"close",
"the",
"connection",
"pool"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/pool/pool.go#L178-L199 |
133,679 | hashicorp/nomad | helper/pool/pool.go | ReloadTLS | func (p *ConnPool) ReloadTLS(tlsWrap tlsutil.RegionWrapper) {
p.Lock()
defer p.Unlock()
oldPool := p.pool
for _, conn := range oldPool {
conn.Close()
}
p.pool = make(map[string]*Conn)
p.tlsWrap = tlsWrap
} | go | func (p *ConnPool) ReloadTLS(tlsWrap tlsutil.RegionWrapper) {
p.Lock()
defer p.Unlock()
oldPool := p.pool
for _, conn := range oldPool {
conn.Close()
}
p.pool = make(map[string]*Conn)
p.tlsWrap = tlsWrap
} | [
"func",
"(",
"p",
"*",
"ConnPool",
")",
"ReloadTLS",
"(",
"tlsWrap",
"tlsutil",
".",
"RegionWrapper",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"oldPool",
":=",
"p",
".",
"pool",
"\n",
"for",
"_",
... | // ReloadTLS reloads TLS configuration on the fly | [
"ReloadTLS",
"reloads",
"TLS",
"configuration",
"on",
"the",
"fly"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/pool/pool.go#L202-L212 |
133,680 | hashicorp/nomad | helper/pool/pool.go | SetConnListener | func (p *ConnPool) SetConnListener(l chan<- *yamux.Session) {
p.Lock()
defer p.Unlock()
// Close the old listener
if p.connListener != nil {
close(p.connListener)
}
// Store the new listener
p.connListener = l
} | go | func (p *ConnPool) SetConnListener(l chan<- *yamux.Session) {
p.Lock()
defer p.Unlock()
// Close the old listener
if p.connListener != nil {
close(p.connListener)
}
// Store the new listener
p.connListener = l
} | [
"func",
"(",
"p",
"*",
"ConnPool",
")",
"SetConnListener",
"(",
"l",
"chan",
"<-",
"*",
"yamux",
".",
"Session",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"// Close the old listener",
"if",
"p",
".",
... | // SetConnListener is used to listen to new connections being made. The
// channel will be closed when the conn pool is closed or a new listener is set. | [
"SetConnListener",
"is",
"used",
"to",
"listen",
"to",
"new",
"connections",
"being",
"made",
".",
"The",
"channel",
"will",
"be",
"closed",
"when",
"the",
"conn",
"pool",
"is",
"closed",
"or",
"a",
"new",
"listener",
"is",
"set",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/helper/pool/pool.go#L216-L227 |
133,681 | hashicorp/nomad | scheduler/reconcile.go | Changes | func (r *reconcileResults) Changes() int {
return len(r.place) + len(r.inplaceUpdate) + len(r.stop)
} | go | func (r *reconcileResults) Changes() int {
return len(r.place) + len(r.inplaceUpdate) + len(r.stop)
} | [
"func",
"(",
"r",
"*",
"reconcileResults",
")",
"Changes",
"(",
")",
"int",
"{",
"return",
"len",
"(",
"r",
".",
"place",
")",
"+",
"len",
"(",
"r",
".",
"inplaceUpdate",
")",
"+",
"len",
"(",
"r",
".",
"stop",
")",
"\n",
"}"
] | // Changes returns the number of total changes | [
"Changes",
"returns",
"the",
"number",
"of",
"total",
"changes"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L153-L155 |
133,682 | hashicorp/nomad | scheduler/reconcile.go | NewAllocReconciler | func NewAllocReconciler(logger log.Logger, allocUpdateFn allocUpdateType, batch bool,
jobID string, job *structs.Job, deployment *structs.Deployment,
existingAllocs []*structs.Allocation, taintedNodes map[string]*structs.Node, evalID string) *allocReconciler {
return &allocReconciler{
logger: logger.Named(... | go | func NewAllocReconciler(logger log.Logger, allocUpdateFn allocUpdateType, batch bool,
jobID string, job *structs.Job, deployment *structs.Deployment,
existingAllocs []*structs.Allocation, taintedNodes map[string]*structs.Node, evalID string) *allocReconciler {
return &allocReconciler{
logger: logger.Named(... | [
"func",
"NewAllocReconciler",
"(",
"logger",
"log",
".",
"Logger",
",",
"allocUpdateFn",
"allocUpdateType",
",",
"batch",
"bool",
",",
"jobID",
"string",
",",
"job",
"*",
"structs",
".",
"Job",
",",
"deployment",
"*",
"structs",
".",
"Deployment",
",",
"exis... | // NewAllocReconciler creates a new reconciler that should be used to determine
// the changes required to bring the cluster state inline with the declared jobspec | [
"NewAllocReconciler",
"creates",
"a",
"new",
"reconciler",
"that",
"should",
"be",
"used",
"to",
"determine",
"the",
"changes",
"required",
"to",
"bring",
"the",
"cluster",
"state",
"inline",
"with",
"the",
"declared",
"jobspec"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L159-L178 |
133,683 | hashicorp/nomad | scheduler/reconcile.go | Compute | func (a *allocReconciler) Compute() *reconcileResults {
// Create the allocation matrix
m := newAllocMatrix(a.job, a.existingAllocs)
// Handle stopping unneeded deployments
a.cancelDeployments()
// If we are just stopping a job we do not need to do anything more than
// stopping all running allocs
if a.job.Sto... | go | func (a *allocReconciler) Compute() *reconcileResults {
// Create the allocation matrix
m := newAllocMatrix(a.job, a.existingAllocs)
// Handle stopping unneeded deployments
a.cancelDeployments()
// If we are just stopping a job we do not need to do anything more than
// stopping all running allocs
if a.job.Sto... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"Compute",
"(",
")",
"*",
"reconcileResults",
"{",
"// Create the allocation matrix",
"m",
":=",
"newAllocMatrix",
"(",
"a",
".",
"job",
",",
"a",
".",
"existingAllocs",
")",
"\n\n",
"// Handle stopping unneeded deplo... | // Compute reconciles the existing cluster state and returns the set of changes
// required to converge the job spec and state | [
"Compute",
"reconciles",
"the",
"existing",
"cluster",
"state",
"and",
"returns",
"the",
"set",
"of",
"changes",
"required",
"to",
"converge",
"the",
"job",
"spec",
"and",
"state"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L182-L226 |
133,684 | hashicorp/nomad | scheduler/reconcile.go | cancelDeployments | func (a *allocReconciler) cancelDeployments() {
// If the job is stopped and there is a non-terminal deployment, cancel it
if a.job.Stopped() {
if a.deployment != nil && a.deployment.Active() {
a.result.deploymentUpdates = append(a.result.deploymentUpdates, &structs.DeploymentStatusUpdate{
DeploymentID: ... | go | func (a *allocReconciler) cancelDeployments() {
// If the job is stopped and there is a non-terminal deployment, cancel it
if a.job.Stopped() {
if a.deployment != nil && a.deployment.Active() {
a.result.deploymentUpdates = append(a.result.deploymentUpdates, &structs.DeploymentStatusUpdate{
DeploymentID: ... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"cancelDeployments",
"(",
")",
"{",
"// If the job is stopped and there is a non-terminal deployment, cancel it",
"if",
"a",
".",
"job",
".",
"Stopped",
"(",
")",
"{",
"if",
"a",
".",
"deployment",
"!=",
"nil",
"&&",
... | // cancelDeployments cancels any deployment that is not needed | [
"cancelDeployments",
"cancels",
"any",
"deployment",
"that",
"is",
"not",
"needed"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L229-L270 |
133,685 | hashicorp/nomad | scheduler/reconcile.go | handleStop | func (a *allocReconciler) handleStop(m allocMatrix) {
for group, as := range m {
as = filterByTerminal(as)
untainted, migrate, lost := as.filterByTainted(a.taintedNodes)
a.markStop(untainted, "", allocNotNeeded)
a.markStop(migrate, "", allocNotNeeded)
a.markStop(lost, structs.AllocClientStatusLost, allocLost... | go | func (a *allocReconciler) handleStop(m allocMatrix) {
for group, as := range m {
as = filterByTerminal(as)
untainted, migrate, lost := as.filterByTainted(a.taintedNodes)
a.markStop(untainted, "", allocNotNeeded)
a.markStop(migrate, "", allocNotNeeded)
a.markStop(lost, structs.AllocClientStatusLost, allocLost... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"handleStop",
"(",
"m",
"allocMatrix",
")",
"{",
"for",
"group",
",",
"as",
":=",
"range",
"m",
"{",
"as",
"=",
"filterByTerminal",
"(",
"as",
")",
"\n",
"untainted",
",",
"migrate",
",",
"lost",
":=",
"... | // handleStop marks all allocations to be stopped, handling the lost case | [
"handleStop",
"marks",
"all",
"allocations",
"to",
"be",
"stopped",
"handling",
"the",
"lost",
"case"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L273-L284 |
133,686 | hashicorp/nomad | scheduler/reconcile.go | markStop | func (a *allocReconciler) markStop(allocs allocSet, clientStatus, statusDescription string) {
for _, alloc := range allocs {
a.result.stop = append(a.result.stop, allocStopResult{
alloc: alloc,
clientStatus: clientStatus,
statusDescription: statusDescription,
})
}
} | go | func (a *allocReconciler) markStop(allocs allocSet, clientStatus, statusDescription string) {
for _, alloc := range allocs {
a.result.stop = append(a.result.stop, allocStopResult{
alloc: alloc,
clientStatus: clientStatus,
statusDescription: statusDescription,
})
}
} | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"markStop",
"(",
"allocs",
"allocSet",
",",
"clientStatus",
",",
"statusDescription",
"string",
")",
"{",
"for",
"_",
",",
"alloc",
":=",
"range",
"allocs",
"{",
"a",
".",
"result",
".",
"stop",
"=",
"append... | // markStop is a helper for marking a set of allocation for stop with a
// particular client status and description. | [
"markStop",
"is",
"a",
"helper",
"for",
"marking",
"a",
"set",
"of",
"allocation",
"for",
"stop",
"with",
"a",
"particular",
"client",
"status",
"and",
"description",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L288-L296 |
133,687 | hashicorp/nomad | scheduler/reconcile.go | filterOldTerminalAllocs | func (a *allocReconciler) filterOldTerminalAllocs(all allocSet) (filtered, ignore allocSet) {
if !a.batch {
return all, nil
}
filtered = filtered.union(all)
ignored := make(map[string]*structs.Allocation)
// Ignore terminal batch jobs from older versions
for id, alloc := range filtered {
older := alloc.Job.... | go | func (a *allocReconciler) filterOldTerminalAllocs(all allocSet) (filtered, ignore allocSet) {
if !a.batch {
return all, nil
}
filtered = filtered.union(all)
ignored := make(map[string]*structs.Allocation)
// Ignore terminal batch jobs from older versions
for id, alloc := range filtered {
older := alloc.Job.... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"filterOldTerminalAllocs",
"(",
"all",
"allocSet",
")",
"(",
"filtered",
",",
"ignore",
"allocSet",
")",
"{",
"if",
"!",
"a",
".",
"batch",
"{",
"return",
"all",
",",
"nil",
"\n",
"}",
"\n\n",
"filtered",
... | // filterOldTerminalAllocs filters allocations that should be ignored since they
// are allocations that are terminal from a previous job version. | [
"filterOldTerminalAllocs",
"filters",
"allocations",
"that",
"should",
"be",
"ignored",
"since",
"they",
"are",
"allocations",
"that",
"are",
"terminal",
"from",
"a",
"previous",
"job",
"version",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L528-L546 |
133,688 | hashicorp/nomad | scheduler/reconcile.go | handleGroupCanaries | func (a *allocReconciler) handleGroupCanaries(all allocSet, desiredChanges *structs.DesiredUpdates) (canaries, newAll allocSet) {
// Stop any canary from an older deployment or from a failed one
var stop []string
// Cancel any non-promoted canaries from the older deployment
if a.oldDeployment != nil {
for _, s :... | go | func (a *allocReconciler) handleGroupCanaries(all allocSet, desiredChanges *structs.DesiredUpdates) (canaries, newAll allocSet) {
// Stop any canary from an older deployment or from a failed one
var stop []string
// Cancel any non-promoted canaries from the older deployment
if a.oldDeployment != nil {
for _, s :... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"handleGroupCanaries",
"(",
"all",
"allocSet",
",",
"desiredChanges",
"*",
"structs",
".",
"DesiredUpdates",
")",
"(",
"canaries",
",",
"newAll",
"allocSet",
")",
"{",
"// Stop any canary from an older deployment or from ... | // handleGroupCanaries handles the canaries for the group by stopping the
// unneeded ones and returning the current set of canaries and the updated total
// set of allocs for the group | [
"handleGroupCanaries",
"handles",
"the",
"canaries",
"for",
"the",
"group",
"by",
"stopping",
"the",
"unneeded",
"ones",
"and",
"returning",
"the",
"current",
"set",
"of",
"canaries",
"and",
"the",
"updated",
"total",
"set",
"of",
"allocs",
"for",
"the",
"grou... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L551-L598 |
133,689 | hashicorp/nomad | scheduler/reconcile.go | computeLimit | func (a *allocReconciler) computeLimit(group *structs.TaskGroup, untainted, destructive, migrate allocSet, canaryState bool) int {
// If there is no update strategy or deployment for the group we can deploy
// as many as the group has
if group.Update == nil || len(destructive)+len(migrate) == 0 {
return group.Coun... | go | func (a *allocReconciler) computeLimit(group *structs.TaskGroup, untainted, destructive, migrate allocSet, canaryState bool) int {
// If there is no update strategy or deployment for the group we can deploy
// as many as the group has
if group.Update == nil || len(destructive)+len(migrate) == 0 {
return group.Coun... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"computeLimit",
"(",
"group",
"*",
"structs",
".",
"TaskGroup",
",",
"untainted",
",",
"destructive",
",",
"migrate",
"allocSet",
",",
"canaryState",
"bool",
")",
"int",
"{",
"// If there is no update strategy or depl... | // computeLimit returns the placement limit for a particular group. The inputs
// are the group definition, the untainted, destructive, and migrate allocation
// set and whether we are in a canary state. | [
"computeLimit",
"returns",
"the",
"placement",
"limit",
"for",
"a",
"particular",
"group",
".",
"The",
"inputs",
"are",
"the",
"group",
"definition",
"the",
"untainted",
"destructive",
"and",
"migrate",
"allocation",
"set",
"and",
"whether",
"we",
"are",
"in",
... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L603-L643 |
133,690 | hashicorp/nomad | scheduler/reconcile.go | computePlacements | func (a *allocReconciler) computePlacements(group *structs.TaskGroup,
nameIndex *allocNameIndex, untainted, migrate allocSet, reschedule allocSet) []allocPlaceResult {
// Add rescheduled placement results
var place []allocPlaceResult
for _, alloc := range reschedule {
place = append(place, allocPlaceResult{
n... | go | func (a *allocReconciler) computePlacements(group *structs.TaskGroup,
nameIndex *allocNameIndex, untainted, migrate allocSet, reschedule allocSet) []allocPlaceResult {
// Add rescheduled placement results
var place []allocPlaceResult
for _, alloc := range reschedule {
place = append(place, allocPlaceResult{
n... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"computePlacements",
"(",
"group",
"*",
"structs",
".",
"TaskGroup",
",",
"nameIndex",
"*",
"allocNameIndex",
",",
"untainted",
",",
"migrate",
"allocSet",
",",
"reschedule",
"allocSet",
")",
"[",
"]",
"allocPlace... | // computePlacement returns the set of allocations to place given the group
// definition, the set of untainted, migrating and reschedule allocations for the group. | [
"computePlacement",
"returns",
"the",
"set",
"of",
"allocations",
"to",
"place",
"given",
"the",
"group",
"definition",
"the",
"set",
"of",
"untainted",
"migrating",
"and",
"reschedule",
"allocations",
"for",
"the",
"group",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L647-L679 |
133,691 | hashicorp/nomad | scheduler/reconcile.go | computeStop | func (a *allocReconciler) computeStop(group *structs.TaskGroup, nameIndex *allocNameIndex,
untainted, migrate, lost, canaries allocSet, canaryState bool) allocSet {
// Mark all lost allocations for stop. Previous allocation doesn't matter
// here since it is on a lost node
var stop allocSet
stop = stop.union(lost... | go | func (a *allocReconciler) computeStop(group *structs.TaskGroup, nameIndex *allocNameIndex,
untainted, migrate, lost, canaries allocSet, canaryState bool) allocSet {
// Mark all lost allocations for stop. Previous allocation doesn't matter
// here since it is on a lost node
var stop allocSet
stop = stop.union(lost... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"computeStop",
"(",
"group",
"*",
"structs",
".",
"TaskGroup",
",",
"nameIndex",
"*",
"allocNameIndex",
",",
"untainted",
",",
"migrate",
",",
"lost",
",",
"canaries",
"allocSet",
",",
"canaryState",
"bool",
")"... | // computeStop returns the set of allocations that are marked for stopping given
// the group definition, the set of allocations in various states and whether we
// are canarying. | [
"computeStop",
"returns",
"the",
"set",
"of",
"allocations",
"that",
"are",
"marked",
"for",
"stopping",
"given",
"the",
"group",
"definition",
"the",
"set",
"of",
"allocations",
"in",
"various",
"states",
"and",
"whether",
"we",
"are",
"canarying",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L684-L787 |
133,692 | hashicorp/nomad | scheduler/reconcile.go | handleDelayedReschedules | func (a *allocReconciler) handleDelayedReschedules(rescheduleLater []*delayedRescheduleInfo, all allocSet, tgName string) {
if len(rescheduleLater) == 0 {
return
}
// Sort by time
sort.Slice(rescheduleLater, func(i, j int) bool {
return rescheduleLater[i].rescheduleTime.Before(rescheduleLater[j].rescheduleTime... | go | func (a *allocReconciler) handleDelayedReschedules(rescheduleLater []*delayedRescheduleInfo, all allocSet, tgName string) {
if len(rescheduleLater) == 0 {
return
}
// Sort by time
sort.Slice(rescheduleLater, func(i, j int) bool {
return rescheduleLater[i].rescheduleTime.Before(rescheduleLater[j].rescheduleTime... | [
"func",
"(",
"a",
"*",
"allocReconciler",
")",
"handleDelayedReschedules",
"(",
"rescheduleLater",
"[",
"]",
"*",
"delayedRescheduleInfo",
",",
"all",
"allocSet",
",",
"tgName",
"string",
")",
"{",
"if",
"len",
"(",
"rescheduleLater",
")",
"==",
"0",
"{",
"r... | // handleDelayedReschedules creates batched followup evaluations with the WaitUntil field set
// for allocations that are eligible to be rescheduled later | [
"handleDelayedReschedules",
"creates",
"batched",
"followup",
"evaluations",
"with",
"the",
"WaitUntil",
"field",
"set",
"for",
"allocations",
"that",
"are",
"eligible",
"to",
"be",
"rescheduled",
"later"
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/scheduler/reconcile.go#L818-L885 |
133,693 | hashicorp/nomad | client/fs_endpoint.go | handleStreamResultError | func (f *FileSystem) handleStreamResultError(err error, code *int64, encoder *codec.Encoder) {
// Nothing to do as the conn is closed
if err == io.EOF || strings.Contains(err.Error(), "closed") {
return
}
encoder.Encode(&cstructs.StreamErrWrapper{
Error: cstructs.NewRpcError(err, code),
})
} | go | func (f *FileSystem) handleStreamResultError(err error, code *int64, encoder *codec.Encoder) {
// Nothing to do as the conn is closed
if err == io.EOF || strings.Contains(err.Error(), "closed") {
return
}
encoder.Encode(&cstructs.StreamErrWrapper{
Error: cstructs.NewRpcError(err, code),
})
} | [
"func",
"(",
"f",
"*",
"FileSystem",
")",
"handleStreamResultError",
"(",
"err",
"error",
",",
"code",
"*",
"int64",
",",
"encoder",
"*",
"codec",
".",
"Encoder",
")",
"{",
"// Nothing to do as the conn is closed",
"if",
"err",
"==",
"io",
".",
"EOF",
"||",
... | // handleStreamResultError is a helper for sending an error with a potential
// error code. The transmission of the error is ignored if the error has been
// generated by the closing of the underlying transport. | [
"handleStreamResultError",
"is",
"a",
"helper",
"for",
"sending",
"an",
"error",
"with",
"a",
"potential",
"error",
"code",
".",
"The",
"transmission",
"of",
"the",
"error",
"is",
"ignored",
"if",
"the",
"error",
"has",
"been",
"generated",
"by",
"the",
"clo... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fs_endpoint.go#L87-L96 |
133,694 | hashicorp/nomad | client/fs_endpoint.go | Stat | func (f *FileSystem) Stat(args *cstructs.FsStatRequest, reply *cstructs.FsStatResponse) error {
defer metrics.MeasureSince([]string{"client", "file_system", "stat"}, time.Now())
// Check read permissions
if aclObj, err := f.c.ResolveToken(args.QueryOptions.AuthToken); err != nil {
return err
} else if aclObj != ... | go | func (f *FileSystem) Stat(args *cstructs.FsStatRequest, reply *cstructs.FsStatResponse) error {
defer metrics.MeasureSince([]string{"client", "file_system", "stat"}, time.Now())
// Check read permissions
if aclObj, err := f.c.ResolveToken(args.QueryOptions.AuthToken); err != nil {
return err
} else if aclObj != ... | [
"func",
"(",
"f",
"*",
"FileSystem",
")",
"Stat",
"(",
"args",
"*",
"cstructs",
".",
"FsStatRequest",
",",
"reply",
"*",
"cstructs",
".",
"FsStatResponse",
")",
"error",
"{",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
... | // Stat is used to stat a file in the allocation's directory. | [
"Stat",
"is",
"used",
"to",
"stat",
"a",
"file",
"in",
"the",
"allocation",
"s",
"directory",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fs_endpoint.go#L123-L144 |
133,695 | hashicorp/nomad | client/fs_endpoint.go | logsImpl | func (f *FileSystem) logsImpl(ctx context.Context, follow, plain bool, offset int64,
origin, task, logType string,
fs allocdir.AllocDirFS, frames chan<- *sframer.StreamFrame) error {
// Create the framer
framer := sframer.NewStreamFramer(frames, streamHeartbeatRate, streamBatchWindow, streamFrameSize)
framer.Run(... | go | func (f *FileSystem) logsImpl(ctx context.Context, follow, plain bool, offset int64,
origin, task, logType string,
fs allocdir.AllocDirFS, frames chan<- *sframer.StreamFrame) error {
// Create the framer
framer := sframer.NewStreamFramer(frames, streamHeartbeatRate, streamBatchWindow, streamFrameSize)
framer.Run(... | [
"func",
"(",
"f",
"*",
"FileSystem",
")",
"logsImpl",
"(",
"ctx",
"context",
".",
"Context",
",",
"follow",
",",
"plain",
"bool",
",",
"offset",
"int64",
",",
"origin",
",",
"task",
",",
"logType",
"string",
",",
"fs",
"allocdir",
".",
"AllocDirFS",
",... | // logsImpl is used to stream the logs of a the given task. Output is sent on
// the passed frames channel and the method will return on EOF if follow is not
// true otherwise when the context is cancelled or on an error. | [
"logsImpl",
"is",
"used",
"to",
"stream",
"the",
"logs",
"of",
"a",
"the",
"given",
"task",
".",
"Output",
"is",
"sent",
"on",
"the",
"passed",
"frames",
"channel",
"and",
"the",
"method",
"will",
"return",
"on",
"EOF",
"if",
"follow",
"is",
"not",
"tr... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fs_endpoint.go#L505-L613 |
133,696 | hashicorp/nomad | client/fs_endpoint.go | streamFile | func (f *FileSystem) streamFile(ctx context.Context, offset int64, path string, limit int64,
fs allocdir.AllocDirFS, framer *sframer.StreamFramer, eofCancelCh chan error) error {
// Get the reader
file, err := fs.ReadAt(path, offset)
if err != nil {
return err
}
defer file.Close()
var fileReader io.Reader
i... | go | func (f *FileSystem) streamFile(ctx context.Context, offset int64, path string, limit int64,
fs allocdir.AllocDirFS, framer *sframer.StreamFramer, eofCancelCh chan error) error {
// Get the reader
file, err := fs.ReadAt(path, offset)
if err != nil {
return err
}
defer file.Close()
var fileReader io.Reader
i... | [
"func",
"(",
"f",
"*",
"FileSystem",
")",
"streamFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"offset",
"int64",
",",
"path",
"string",
",",
"limit",
"int64",
",",
"fs",
"allocdir",
".",
"AllocDirFS",
",",
"framer",
"*",
"sframer",
".",
"StreamFram... | // streamFile is the internal method to stream the content of a file. If limit
// is greater than zero, the stream will end once that many bytes have been
// read. eofCancelCh is used to cancel the stream if triggered while at EOF. If
// the connection is broken an EPIPE error is returned | [
"streamFile",
"is",
"the",
"internal",
"method",
"to",
"stream",
"the",
"content",
"of",
"a",
"file",
".",
"If",
"limit",
"is",
"greater",
"than",
"zero",
"the",
"stream",
"will",
"end",
"once",
"that",
"many",
"bytes",
"have",
"been",
"read",
".",
"eofC... | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fs_endpoint.go#L619-L741 |
133,697 | hashicorp/nomad | client/fs_endpoint.go | blockUntilNextLog | func blockUntilNextLog(ctx context.Context, fs allocdir.AllocDirFS, logPath, task, logType string, nextIndex int64) chan error {
nextPath := filepath.Join(logPath, fmt.Sprintf("%s.%s.%d", task, logType, nextIndex))
next := make(chan error, 1)
go func() {
eofCancelCh, err := fs.BlockUntilExists(ctx, nextPath)
if... | go | func blockUntilNextLog(ctx context.Context, fs allocdir.AllocDirFS, logPath, task, logType string, nextIndex int64) chan error {
nextPath := filepath.Join(logPath, fmt.Sprintf("%s.%s.%d", task, logType, nextIndex))
next := make(chan error, 1)
go func() {
eofCancelCh, err := fs.BlockUntilExists(ctx, nextPath)
if... | [
"func",
"blockUntilNextLog",
"(",
"ctx",
"context",
".",
"Context",
",",
"fs",
"allocdir",
".",
"AllocDirFS",
",",
"logPath",
",",
"task",
",",
"logType",
"string",
",",
"nextIndex",
"int64",
")",
"chan",
"error",
"{",
"nextPath",
":=",
"filepath",
".",
"J... | // blockUntilNextLog returns a channel that will have data sent when the next
// log index or anything greater is created. | [
"blockUntilNextLog",
"returns",
"a",
"channel",
"that",
"will",
"have",
"data",
"sent",
"when",
"the",
"next",
"log",
"index",
"or",
"anything",
"greater",
"is",
"created",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fs_endpoint.go#L745-L799 |
133,698 | hashicorp/nomad | client/fs_endpoint.go | logIndexes | func logIndexes(entries []*cstructs.AllocFileInfo, task, logType string) (indexTupleArray, error) {
var indexes []indexTuple
prefix := fmt.Sprintf("%s.%s.", task, logType)
for _, entry := range entries {
if entry.IsDir {
continue
}
// If nothing was trimmed, then it is not a match
idxStr := strings.TrimP... | go | func logIndexes(entries []*cstructs.AllocFileInfo, task, logType string) (indexTupleArray, error) {
var indexes []indexTuple
prefix := fmt.Sprintf("%s.%s.", task, logType)
for _, entry := range entries {
if entry.IsDir {
continue
}
// If nothing was trimmed, then it is not a match
idxStr := strings.TrimP... | [
"func",
"logIndexes",
"(",
"entries",
"[",
"]",
"*",
"cstructs",
".",
"AllocFileInfo",
",",
"task",
",",
"logType",
"string",
")",
"(",
"indexTupleArray",
",",
"error",
")",
"{",
"var",
"indexes",
"[",
"]",
"indexTuple",
"\n",
"prefix",
":=",
"fmt",
".",... | // logIndexes takes a set of entries and returns a indexTupleArray of
// the desired log file entries. If the indexes could not be determined, an
// error is returned. | [
"logIndexes",
"takes",
"a",
"set",
"of",
"entries",
"and",
"returns",
"a",
"indexTupleArray",
"of",
"the",
"desired",
"log",
"file",
"entries",
".",
"If",
"the",
"indexes",
"could",
"not",
"be",
"determined",
"an",
"error",
"is",
"returned",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fs_endpoint.go#L817-L841 |
133,699 | hashicorp/nomad | client/fs_endpoint.go | parseFramerErr | func parseFramerErr(err error) error {
if err == nil {
return nil
}
errMsg := err.Error()
if strings.Contains(errMsg, io.ErrClosedPipe.Error()) {
// The pipe check is for tests
return syscall.EPIPE
}
// The connection was closed by our peer
if strings.Contains(errMsg, syscall.EPIPE.Error()) || strings.C... | go | func parseFramerErr(err error) error {
if err == nil {
return nil
}
errMsg := err.Error()
if strings.Contains(errMsg, io.ErrClosedPipe.Error()) {
// The pipe check is for tests
return syscall.EPIPE
}
// The connection was closed by our peer
if strings.Contains(errMsg, syscall.EPIPE.Error()) || strings.C... | [
"func",
"parseFramerErr",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"errMsg",
":=",
"err",
".",
"Error",
"(",
")",
"\n\n",
"if",
"strings",
".",
"Contains",
"(",
"errMsg",
",",
"io",
... | // parseFramerErr takes an error and returns an error. The error will
// potentially change if it was caused by the connection being closed. | [
"parseFramerErr",
"takes",
"an",
"error",
"and",
"returns",
"an",
"error",
".",
"The",
"error",
"will",
"potentially",
"change",
"if",
"it",
"was",
"caused",
"by",
"the",
"connection",
"being",
"closed",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/client/fs_endpoint.go#L934-L959 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.