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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
docker/swarmkit | cmd/swarmctl/task/print.go | Print | func Print(tasks []*api.Task, all bool, res *common.Resolver) {
w := tabwriter.NewWriter(os.Stdout, 4, 4, 4, ' ', 0)
defer w.Flush()
common.PrintHeader(w, "Task ID", "Service", "Slot", "Image", "Desired State", "Last State", "Node")
sort.Stable(tasksBySlot(tasks))
for _, t := range tasks {
if !all && t.DesiredS... | go | func Print(tasks []*api.Task, all bool, res *common.Resolver) {
w := tabwriter.NewWriter(os.Stdout, 4, 4, 4, ' ', 0)
defer w.Flush()
common.PrintHeader(w, "Task ID", "Service", "Slot", "Image", "Desired State", "Last State", "Node")
sort.Stable(tasksBySlot(tasks))
for _, t := range tasks {
if !all && t.DesiredS... | [
"func",
"Print",
"(",
"tasks",
"[",
"]",
"*",
"api",
".",
"Task",
",",
"all",
"bool",
",",
"res",
"*",
"common",
".",
"Resolver",
")",
"{",
"w",
":=",
"tabwriter",
".",
"NewWriter",
"(",
"os",
".",
"Stdout",
",",
"4",
",",
"4",
",",
"4",
",",
... | // Print prints a list of tasks. | [
"Print",
"prints",
"a",
"list",
"of",
"tasks",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarmctl/task/print.go#L41-L63 | train |
docker/swarmkit | ca/external.go | NewExternalCATLSConfig | func NewExternalCATLSConfig(certs []tls.Certificate, rootPool *x509.CertPool) *tls.Config {
return &tls.Config{
Certificates: certs,
RootCAs: rootPool,
MinVersion: tls.VersionTLS12,
}
} | go | func NewExternalCATLSConfig(certs []tls.Certificate, rootPool *x509.CertPool) *tls.Config {
return &tls.Config{
Certificates: certs,
RootCAs: rootPool,
MinVersion: tls.VersionTLS12,
}
} | [
"func",
"NewExternalCATLSConfig",
"(",
"certs",
"[",
"]",
"tls",
".",
"Certificate",
",",
"rootPool",
"*",
"x509",
".",
"CertPool",
")",
"*",
"tls",
".",
"Config",
"{",
"return",
"&",
"tls",
".",
"Config",
"{",
"Certificates",
":",
"certs",
",",
"RootCAs... | // NewExternalCATLSConfig takes a TLS certificate and root pool and returns a TLS config that can be updated
// without killing existing connections | [
"NewExternalCATLSConfig",
"takes",
"a",
"TLS",
"certificate",
"and",
"root",
"pool",
"and",
"returns",
"a",
"TLS",
"config",
"that",
"can",
"be",
"updated",
"without",
"killing",
"existing",
"connections"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/external.go#L58-L64 | train |
docker/swarmkit | ca/external.go | NewExternalCA | func NewExternalCA(intermediates []byte, tlsConfig *tls.Config, urls ...string) *ExternalCA {
return &ExternalCA{
ExternalRequestTimeout: 5 * time.Second,
intermediates: intermediates,
urls: urls,
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
... | go | func NewExternalCA(intermediates []byte, tlsConfig *tls.Config, urls ...string) *ExternalCA {
return &ExternalCA{
ExternalRequestTimeout: 5 * time.Second,
intermediates: intermediates,
urls: urls,
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
... | [
"func",
"NewExternalCA",
"(",
"intermediates",
"[",
"]",
"byte",
",",
"tlsConfig",
"*",
"tls",
".",
"Config",
",",
"urls",
"...",
"string",
")",
"*",
"ExternalCA",
"{",
"return",
"&",
"ExternalCA",
"{",
"ExternalRequestTimeout",
":",
"5",
"*",
"time",
".",... | // NewExternalCA creates a new ExternalCA which uses the given tlsConfig to
// authenticate to any of the given URLS of CFSSL API endpoints. | [
"NewExternalCA",
"creates",
"a",
"new",
"ExternalCA",
"which",
"uses",
"the",
"given",
"tlsConfig",
"to",
"authenticate",
"to",
"any",
"of",
"the",
"given",
"URLS",
"of",
"CFSSL",
"API",
"endpoints",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/external.go#L68-L79 | train |
docker/swarmkit | ca/external.go | UpdateTLSConfig | func (eca *ExternalCA) UpdateTLSConfig(tlsConfig *tls.Config) {
eca.mu.Lock()
defer eca.mu.Unlock()
eca.client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
}
} | go | func (eca *ExternalCA) UpdateTLSConfig(tlsConfig *tls.Config) {
eca.mu.Lock()
defer eca.mu.Unlock()
eca.client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
}
} | [
"func",
"(",
"eca",
"*",
"ExternalCA",
")",
"UpdateTLSConfig",
"(",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"{",
"eca",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"eca",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"eca",
".",
"client",
... | // UpdateTLSConfig updates the HTTP Client for this ExternalCA by creating
// a new client which uses the given tlsConfig. | [
"UpdateTLSConfig",
"updates",
"the",
"HTTP",
"Client",
"for",
"this",
"ExternalCA",
"by",
"creating",
"a",
"new",
"client",
"which",
"uses",
"the",
"given",
"tlsConfig",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/external.go#L83-L92 | train |
docker/swarmkit | ca/external.go | UpdateURLs | func (eca *ExternalCA) UpdateURLs(urls ...string) {
eca.mu.Lock()
defer eca.mu.Unlock()
eca.urls = urls
} | go | func (eca *ExternalCA) UpdateURLs(urls ...string) {
eca.mu.Lock()
defer eca.mu.Unlock()
eca.urls = urls
} | [
"func",
"(",
"eca",
"*",
"ExternalCA",
")",
"UpdateURLs",
"(",
"urls",
"...",
"string",
")",
"{",
"eca",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"eca",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"eca",
".",
"urls",
"=",
"urls",
"\n",
... | // UpdateURLs updates the list of CSR API endpoints by setting it to the given urls. | [
"UpdateURLs",
"updates",
"the",
"list",
"of",
"CSR",
"API",
"endpoints",
"by",
"setting",
"it",
"to",
"the",
"given",
"urls",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/external.go#L95-L100 | train |
docker/swarmkit | ca/external.go | Sign | func (eca *ExternalCA) Sign(ctx context.Context, req signer.SignRequest) (cert []byte, err error) {
// Get the current HTTP client and list of URLs in a small critical
// section. We will use these to make certificate signing requests.
eca.mu.Lock()
urls := eca.urls
client := eca.client
intermediates := eca.inter... | go | func (eca *ExternalCA) Sign(ctx context.Context, req signer.SignRequest) (cert []byte, err error) {
// Get the current HTTP client and list of URLs in a small critical
// section. We will use these to make certificate signing requests.
eca.mu.Lock()
urls := eca.urls
client := eca.client
intermediates := eca.inter... | [
"func",
"(",
"eca",
"*",
"ExternalCA",
")",
"Sign",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"signer",
".",
"SignRequest",
")",
"(",
"cert",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// Get the current HTTP client and list of URLs in a small ... | // Sign signs a new certificate by proxying the given certificate signing
// request to an external CFSSL API server. | [
"Sign",
"signs",
"a",
"new",
"certificate",
"by",
"proxying",
"the",
"given",
"certificate",
"signing",
"request",
"to",
"an",
"external",
"CFSSL",
"API",
"server",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/external.go#L104-L135 | train |
docker/swarmkit | ca/external.go | CrossSignRootCA | func (eca *ExternalCA) CrossSignRootCA(ctx context.Context, rca RootCA) ([]byte, error) {
// ExtractCertificateRequest generates a new key request, and we want to continue to use the old
// key. However, ExtractCertificateRequest will also convert the pkix.Name to csr.Name, which we
// need in order to generate a s... | go | func (eca *ExternalCA) CrossSignRootCA(ctx context.Context, rca RootCA) ([]byte, error) {
// ExtractCertificateRequest generates a new key request, and we want to continue to use the old
// key. However, ExtractCertificateRequest will also convert the pkix.Name to csr.Name, which we
// need in order to generate a s... | [
"func",
"(",
"eca",
"*",
"ExternalCA",
")",
"CrossSignRootCA",
"(",
"ctx",
"context",
".",
"Context",
",",
"rca",
"RootCA",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// ExtractCertificateRequest generates a new key request, and we want to continue to use th... | // CrossSignRootCA takes a RootCA object, generates a CA CSR, sends a signing request with the CA CSR to the external
// CFSSL API server in order to obtain a cross-signed root | [
"CrossSignRootCA",
"takes",
"a",
"RootCA",
"object",
"generates",
"a",
"CA",
"CSR",
"sends",
"a",
"signing",
"request",
"with",
"the",
"CA",
"CSR",
"to",
"the",
"external",
"CFSSL",
"API",
"server",
"in",
"order",
"to",
"obtain",
"a",
"cross",
"-",
"signed... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/external.go#L139-L186 | train |
docker/swarmkit | api/naming/naming.go | Task | func Task(t *api.Task) string {
if t.Annotations.Name != "" {
// if set, use the container Annotations.Name field, set in the orchestrator.
return t.Annotations.Name
}
slot := fmt.Sprint(t.Slot)
if slot == "" || t.Slot == 0 {
// when no slot id is assigned, we assume that this is node-bound task.
slot = t.... | go | func Task(t *api.Task) string {
if t.Annotations.Name != "" {
// if set, use the container Annotations.Name field, set in the orchestrator.
return t.Annotations.Name
}
slot := fmt.Sprint(t.Slot)
if slot == "" || t.Slot == 0 {
// when no slot id is assigned, we assume that this is node-bound task.
slot = t.... | [
"func",
"Task",
"(",
"t",
"*",
"api",
".",
"Task",
")",
"string",
"{",
"if",
"t",
".",
"Annotations",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"// if set, use the container Annotations.Name field, set in the orchestrator.",
"return",
"t",
".",
"Annotations",
".",
"Na... | // Task returns the task name from Annotations.Name,
// and, in case Annotations.Name is missing, fallback
// to construct the name from other information. | [
"Task",
"returns",
"the",
"task",
"name",
"from",
"Annotations",
".",
"Name",
"and",
"in",
"case",
"Annotations",
".",
"Name",
"is",
"missing",
"fallback",
"to",
"construct",
"the",
"name",
"from",
"other",
"information",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/api/naming/naming.go#L19-L33 | train |
docker/swarmkit | manager/state/store/services.go | CreateService | func CreateService(tx Tx, s *api.Service) error {
// Ensure the name is not already in use.
if tx.lookup(tableService, indexName, strings.ToLower(s.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableService, s)
} | go | func CreateService(tx Tx, s *api.Service) error {
// Ensure the name is not already in use.
if tx.lookup(tableService, indexName, strings.ToLower(s.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableService, s)
} | [
"func",
"CreateService",
"(",
"tx",
"Tx",
",",
"s",
"*",
"api",
".",
"Service",
")",
"error",
"{",
"// Ensure the name is not already in use.",
"if",
"tx",
".",
"lookup",
"(",
"tableService",
",",
"indexName",
",",
"strings",
".",
"ToLower",
"(",
"s",
".",
... | // CreateService adds a new service to the store.
// Returns ErrExist if the ID is already taken. | [
"CreateService",
"adds",
"a",
"new",
"service",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/services.go#L87-L94 | train |
docker/swarmkit | manager/state/store/services.go | UpdateService | func UpdateService(tx Tx, s *api.Service) error {
// Ensure the name is either not in use or already used by this same Service.
if existing := tx.lookup(tableService, indexName, strings.ToLower(s.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != s.ID {
return ErrNameConflict
}
}
return tx.up... | go | func UpdateService(tx Tx, s *api.Service) error {
// Ensure the name is either not in use or already used by this same Service.
if existing := tx.lookup(tableService, indexName, strings.ToLower(s.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != s.ID {
return ErrNameConflict
}
}
return tx.up... | [
"func",
"UpdateService",
"(",
"tx",
"Tx",
",",
"s",
"*",
"api",
".",
"Service",
")",
"error",
"{",
"// Ensure the name is either not in use or already used by this same Service.",
"if",
"existing",
":=",
"tx",
".",
"lookup",
"(",
"tableService",
",",
"indexName",
",... | // UpdateService updates an existing service in the store.
// Returns ErrNotExist if the service doesn't exist. | [
"UpdateService",
"updates",
"an",
"existing",
"service",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"service",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/services.go#L98-L107 | train |
docker/swarmkit | manager/state/store/services.go | DeleteService | func DeleteService(tx Tx, id string) error {
return tx.delete(tableService, id)
} | go | func DeleteService(tx Tx, id string) error {
return tx.delete(tableService, id)
} | [
"func",
"DeleteService",
"(",
"tx",
"Tx",
",",
"id",
"string",
")",
"error",
"{",
"return",
"tx",
".",
"delete",
"(",
"tableService",
",",
"id",
")",
"\n",
"}"
] | // DeleteService removes a service from the store.
// Returns ErrNotExist if the service doesn't exist. | [
"DeleteService",
"removes",
"a",
"service",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"service",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/services.go#L111-L113 | train |
docker/swarmkit | manager/state/store/services.go | GetService | func GetService(tx ReadTx, id string) *api.Service {
s := tx.get(tableService, id)
if s == nil {
return nil
}
return s.(*api.Service)
} | go | func GetService(tx ReadTx, id string) *api.Service {
s := tx.get(tableService, id)
if s == nil {
return nil
}
return s.(*api.Service)
} | [
"func",
"GetService",
"(",
"tx",
"ReadTx",
",",
"id",
"string",
")",
"*",
"api",
".",
"Service",
"{",
"s",
":=",
"tx",
".",
"get",
"(",
"tableService",
",",
"id",
")",
"\n",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",... | // GetService looks up a service by ID.
// Returns nil if the service doesn't exist. | [
"GetService",
"looks",
"up",
"a",
"service",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"service",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/services.go#L117-L123 | train |
docker/swarmkit | manager/state/store/services.go | FindServices | func FindServices(tx ReadTx, by By) ([]*api.Service, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byRuntime, byReferencedNetworkID, byReferencedSecretID, byReferencedConfigID, byCustom, byCustomPrefix, byAll:
return nil
default:
return ErrInvalidFindBy... | go | func FindServices(tx ReadTx, by By) ([]*api.Service, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byRuntime, byReferencedNetworkID, byReferencedSecretID, byReferencedConfigID, byCustom, byCustomPrefix, byAll:
return nil
default:
return ErrInvalidFindBy... | [
"func",
"FindServices",
"(",
"tx",
"ReadTx",
",",
"by",
"By",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Service",
",",
"error",
")",
"{",
"checkType",
":=",
"func",
"(",
"by",
"By",
")",
"error",
"{",
"switch",
"by",
".",
"(",
"type",
")",
"{",
"ca... | // FindServices selects a set of services and returns them. | [
"FindServices",
"selects",
"a",
"set",
"of",
"services",
"and",
"returns",
"them",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/services.go#L126-L143 | train |
docker/swarmkit | manager/dispatcher/heartbeat/heartbeat.go | Beat | func (hb *Heartbeat) Beat() {
hb.timer.Reset(time.Duration(atomic.LoadInt64(&hb.timeout)))
} | go | func (hb *Heartbeat) Beat() {
hb.timer.Reset(time.Duration(atomic.LoadInt64(&hb.timeout)))
} | [
"func",
"(",
"hb",
"*",
"Heartbeat",
")",
"Beat",
"(",
")",
"{",
"hb",
".",
"timer",
".",
"Reset",
"(",
"time",
".",
"Duration",
"(",
"atomic",
".",
"LoadInt64",
"(",
"&",
"hb",
".",
"timeout",
")",
")",
")",
"\n",
"}"
] | // Beat resets internal timer to zero. It also can be used to reactivate
// Heartbeat after timeout. | [
"Beat",
"resets",
"internal",
"timer",
"to",
"zero",
".",
"It",
"also",
"can",
"be",
"used",
"to",
"reactivate",
"Heartbeat",
"after",
"timeout",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/dispatcher/heartbeat/heartbeat.go#L27-L29 | train |
docker/swarmkit | manager/dispatcher/heartbeat/heartbeat.go | Update | func (hb *Heartbeat) Update(d time.Duration) {
atomic.StoreInt64(&hb.timeout, int64(d))
} | go | func (hb *Heartbeat) Update(d time.Duration) {
atomic.StoreInt64(&hb.timeout, int64(d))
} | [
"func",
"(",
"hb",
"*",
"Heartbeat",
")",
"Update",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"atomic",
".",
"StoreInt64",
"(",
"&",
"hb",
".",
"timeout",
",",
"int64",
"(",
"d",
")",
")",
"\n",
"}"
] | // Update updates internal timeout to d. It does not do Beat. | [
"Update",
"updates",
"internal",
"timeout",
"to",
"d",
".",
"It",
"does",
"not",
"do",
"Beat",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/dispatcher/heartbeat/heartbeat.go#L32-L34 | train |
docker/swarmkit | cmd/swarmctl/cluster/unlockkey.go | displayUnlockKey | func displayUnlockKey(cmd *cobra.Command) error {
conn, err := common.DialConn(cmd)
if err != nil {
return err
}
defer conn.Close()
resp, err := api.NewCAClient(conn).GetUnlockKey(common.Context(cmd), &api.GetUnlockKeyRequest{})
if err != nil {
return err
}
if len(resp.UnlockKey) == 0 {
fmt.Printf("Mana... | go | func displayUnlockKey(cmd *cobra.Command) error {
conn, err := common.DialConn(cmd)
if err != nil {
return err
}
defer conn.Close()
resp, err := api.NewCAClient(conn).GetUnlockKey(common.Context(cmd), &api.GetUnlockKeyRequest{})
if err != nil {
return err
}
if len(resp.UnlockKey) == 0 {
fmt.Printf("Mana... | [
"func",
"displayUnlockKey",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"common",
".",
"DialConn",
"(",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
"... | // get the unlock key | [
"get",
"the",
"unlock",
"key"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarmctl/cluster/unlockkey.go#L15-L32 | train |
docker/swarmkit | manager/orchestrator/constraintenforcer/constraint_enforcer.go | New | func New(store *store.MemoryStore) *ConstraintEnforcer {
return &ConstraintEnforcer{
store: store,
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
}
} | go | func New(store *store.MemoryStore) *ConstraintEnforcer {
return &ConstraintEnforcer{
store: store,
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
}
} | [
"func",
"New",
"(",
"store",
"*",
"store",
".",
"MemoryStore",
")",
"*",
"ConstraintEnforcer",
"{",
"return",
"&",
"ConstraintEnforcer",
"{",
"store",
":",
"store",
",",
"stopChan",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"doneChan",
":",... | // New creates a new ConstraintEnforcer. | [
"New",
"creates",
"a",
"new",
"ConstraintEnforcer",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/constraintenforcer/constraint_enforcer.go#L24-L30 | train |
docker/swarmkit | manager/orchestrator/constraintenforcer/constraint_enforcer.go | Run | func (ce *ConstraintEnforcer) Run() {
defer close(ce.doneChan)
watcher, cancelWatch := state.Watch(ce.store.WatchQueue(), api.EventUpdateNode{})
defer cancelWatch()
var (
nodes []*api.Node
err error
)
ce.store.View(func(readTx store.ReadTx) {
nodes, err = store.FindNodes(readTx, store.All)
})
if err !... | go | func (ce *ConstraintEnforcer) Run() {
defer close(ce.doneChan)
watcher, cancelWatch := state.Watch(ce.store.WatchQueue(), api.EventUpdateNode{})
defer cancelWatch()
var (
nodes []*api.Node
err error
)
ce.store.View(func(readTx store.ReadTx) {
nodes, err = store.FindNodes(readTx, store.All)
})
if err !... | [
"func",
"(",
"ce",
"*",
"ConstraintEnforcer",
")",
"Run",
"(",
")",
"{",
"defer",
"close",
"(",
"ce",
".",
"doneChan",
")",
"\n\n",
"watcher",
",",
"cancelWatch",
":=",
"state",
".",
"Watch",
"(",
"ce",
".",
"store",
".",
"WatchQueue",
"(",
")",
",",... | // Run is the ConstraintEnforcer's main loop. | [
"Run",
"is",
"the",
"ConstraintEnforcer",
"s",
"main",
"loop",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/constraintenforcer/constraint_enforcer.go#L33-L63 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | New | func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocator.NetworkAllocator, error) {
na := &cnmNetworkAllocator{
networks: make(map[string]*network),
services: make(map[string]struct{}),
tasks: make(map[string]struct{}),
nodes: make(map[string]map[string]struct{}),
}
// There ... | go | func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocator.NetworkAllocator, error) {
na := &cnmNetworkAllocator{
networks: make(map[string]*network),
services: make(map[string]struct{}),
tasks: make(map[string]struct{}),
nodes: make(map[string]map[string]struct{}),
}
// There ... | [
"func",
"New",
"(",
"pg",
"plugingetter",
".",
"PluginGetter",
",",
"netConfig",
"*",
"NetworkConfig",
")",
"(",
"networkallocator",
".",
"NetworkAllocator",
",",
"error",
")",
"{",
"na",
":=",
"&",
"cnmNetworkAllocator",
"{",
"networks",
":",
"make",
"(",
"... | // New returns a new NetworkAllocator handle | [
"New",
"returns",
"a",
"new",
"NetworkAllocator",
"handle"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L103-L134 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | Allocate | func (na *cnmNetworkAllocator) Allocate(n *api.Network) error {
if _, ok := na.networks[n.ID]; ok {
return fmt.Errorf("network %s already allocated", n.ID)
}
d, err := na.resolveDriver(n)
if err != nil {
return err
}
nw := &network{
nw: n,
endpoints: make(map[string]string),
isNodeLocal: d.... | go | func (na *cnmNetworkAllocator) Allocate(n *api.Network) error {
if _, ok := na.networks[n.ID]; ok {
return fmt.Errorf("network %s already allocated", n.ID)
}
d, err := na.resolveDriver(n)
if err != nil {
return err
}
nw := &network{
nw: n,
endpoints: make(map[string]string),
isNodeLocal: d.... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"Allocate",
"(",
"n",
"*",
"api",
".",
"Network",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"na",
".",
"networks",
"[",
"n",
".",
"ID",
"]",
";",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
... | // Allocate allocates all the necessary resources both general
// and driver-specific which may be specified in the NetworkSpec | [
"Allocate",
"allocates",
"all",
"the",
"necessary",
"resources",
"both",
"general",
"and",
"driver",
"-",
"specific",
"which",
"may",
"be",
"specified",
"in",
"the",
"NetworkSpec"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L138-L180 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | Deallocate | func (na *cnmNetworkAllocator) Deallocate(n *api.Network) error {
localNet := na.getNetwork(n.ID)
if localNet == nil {
return fmt.Errorf("could not get networker state for network %s", n.ID)
}
// No swarm-level resource deallocation needed for node-local networks
if localNet.isNodeLocal {
delete(na.networks, ... | go | func (na *cnmNetworkAllocator) Deallocate(n *api.Network) error {
localNet := na.getNetwork(n.ID)
if localNet == nil {
return fmt.Errorf("could not get networker state for network %s", n.ID)
}
// No swarm-level resource deallocation needed for node-local networks
if localNet.isNodeLocal {
delete(na.networks, ... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"Deallocate",
"(",
"n",
"*",
"api",
".",
"Network",
")",
"error",
"{",
"localNet",
":=",
"na",
".",
"getNetwork",
"(",
"n",
".",
"ID",
")",
"\n",
"if",
"localNet",
"==",
"nil",
"{",
"return",
"fmt",... | // Deallocate frees all the general and driver specific resources
// which were assigned to the passed network. | [
"Deallocate",
"frees",
"all",
"the",
"general",
"and",
"driver",
"specific",
"resources",
"which",
"were",
"assigned",
"to",
"the",
"passed",
"network",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L188-L207 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | AllocateService | func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
if err = na.portAllocator.serviceAllocatePorts(s); err != nil {
return err
}
defer func() {
if err != nil {
na.DeallocateService(s)
}
}()
if s.Endpoint == nil {
s.Endpoint = &api.Endpoint{}
}
s.Endpoint.Spec = s.Spec.Endpoin... | go | func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
if err = na.portAllocator.serviceAllocatePorts(s); err != nil {
return err
}
defer func() {
if err != nil {
na.DeallocateService(s)
}
}()
if s.Endpoint == nil {
s.Endpoint = &api.Endpoint{}
}
s.Endpoint.Spec = s.Spec.Endpoin... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"AllocateService",
"(",
"s",
"*",
"api",
".",
"Service",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"na",
".",
"portAllocator",
".",
"serviceAllocatePorts",
"(",
"s",
")",
";",
"err",
"!=",... | // AllocateService allocates all the network resources such as virtual
// IP and ports needed by the service. | [
"AllocateService",
"allocates",
"all",
"the",
"network",
"resources",
"such",
"as",
"virtual",
"IP",
"and",
"ports",
"needed",
"by",
"the",
"service",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L211-L298 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | DeallocateService | func (na *cnmNetworkAllocator) DeallocateService(s *api.Service) error {
if s.Endpoint == nil {
return nil
}
for _, vip := range s.Endpoint.VirtualIPs {
if err := na.deallocateVIP(vip); err != nil {
// don't bail here, deallocate as many as possible.
log.L.WithError(err).
WithField("vip.network", vip.... | go | func (na *cnmNetworkAllocator) DeallocateService(s *api.Service) error {
if s.Endpoint == nil {
return nil
}
for _, vip := range s.Endpoint.VirtualIPs {
if err := na.deallocateVIP(vip); err != nil {
// don't bail here, deallocate as many as possible.
log.L.WithError(err).
WithField("vip.network", vip.... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"DeallocateService",
"(",
"s",
"*",
"api",
".",
"Service",
")",
"error",
"{",
"if",
"s",
".",
"Endpoint",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"vip",
":=",
"range",... | // DeallocateService de-allocates all the network resources such as
// virtual IP and ports associated with the service. | [
"DeallocateService",
"de",
"-",
"allocates",
"all",
"the",
"network",
"resources",
"such",
"as",
"virtual",
"IP",
"and",
"ports",
"associated",
"with",
"the",
"service",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L302-L321 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | IsAllocated | func (na *cnmNetworkAllocator) IsAllocated(n *api.Network) bool {
_, ok := na.networks[n.ID]
return ok
} | go | func (na *cnmNetworkAllocator) IsAllocated(n *api.Network) bool {
_, ok := na.networks[n.ID]
return ok
} | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"IsAllocated",
"(",
"n",
"*",
"api",
".",
"Network",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"na",
".",
"networks",
"[",
"n",
".",
"ID",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsAllocated returns if the passed network has been allocated or not. | [
"IsAllocated",
"returns",
"if",
"the",
"passed",
"network",
"has",
"been",
"allocated",
"or",
"not",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L324-L327 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | IsTaskAllocated | func (na *cnmNetworkAllocator) IsTaskAllocated(t *api.Task) bool {
// If the task is not found in the allocated set, then it is
// not allocated.
if _, ok := na.tasks[t.ID]; !ok {
return false
}
// If Networks is empty there is no way this Task is allocated.
if len(t.Networks) == 0 {
return false
}
// To ... | go | func (na *cnmNetworkAllocator) IsTaskAllocated(t *api.Task) bool {
// If the task is not found in the allocated set, then it is
// not allocated.
if _, ok := na.tasks[t.ID]; !ok {
return false
}
// If Networks is empty there is no way this Task is allocated.
if len(t.Networks) == 0 {
return false
}
// To ... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"IsTaskAllocated",
"(",
"t",
"*",
"api",
".",
"Task",
")",
"bool",
"{",
"// If the task is not found in the allocated set, then it is",
"// not allocated.",
"if",
"_",
",",
"ok",
":=",
"na",
".",
"tasks",
"[",
... | // IsTaskAllocated returns if the passed task has its network resources allocated or not. | [
"IsTaskAllocated",
"returns",
"if",
"the",
"passed",
"task",
"has",
"its",
"network",
"resources",
"allocated",
"or",
"not",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L330-L372 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | AllocateTask | func (na *cnmNetworkAllocator) AllocateTask(t *api.Task) error {
for i, nAttach := range t.Networks {
if localNet := na.getNetwork(nAttach.Network.ID); localNet != nil && localNet.isNodeLocal {
continue
}
if err := na.allocateNetworkIPs(nAttach); err != nil {
if err := na.releaseEndpoints(t.Networks[:i]); ... | go | func (na *cnmNetworkAllocator) AllocateTask(t *api.Task) error {
for i, nAttach := range t.Networks {
if localNet := na.getNetwork(nAttach.Network.ID); localNet != nil && localNet.isNodeLocal {
continue
}
if err := na.allocateNetworkIPs(nAttach); err != nil {
if err := na.releaseEndpoints(t.Networks[:i]); ... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"AllocateTask",
"(",
"t",
"*",
"api",
".",
"Task",
")",
"error",
"{",
"for",
"i",
",",
"nAttach",
":=",
"range",
"t",
".",
"Networks",
"{",
"if",
"localNet",
":=",
"na",
".",
"getNetwork",
"(",
"nAt... | // AllocateTask allocates all the endpoint resources for all the
// networks that a task is attached to. | [
"AllocateTask",
"allocates",
"all",
"the",
"endpoint",
"resources",
"for",
"all",
"the",
"networks",
"that",
"a",
"task",
"is",
"attached",
"to",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L457-L473 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | DeallocateTask | func (na *cnmNetworkAllocator) DeallocateTask(t *api.Task) error {
delete(na.tasks, t.ID)
return na.releaseEndpoints(t.Networks)
} | go | func (na *cnmNetworkAllocator) DeallocateTask(t *api.Task) error {
delete(na.tasks, t.ID)
return na.releaseEndpoints(t.Networks)
} | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"DeallocateTask",
"(",
"t",
"*",
"api",
".",
"Task",
")",
"error",
"{",
"delete",
"(",
"na",
".",
"tasks",
",",
"t",
".",
"ID",
")",
"\n",
"return",
"na",
".",
"releaseEndpoints",
"(",
"t",
".",
"... | // DeallocateTask releases all the endpoint resources for all the
// networks that a task is attached to. | [
"DeallocateTask",
"releases",
"all",
"the",
"endpoint",
"resources",
"for",
"all",
"the",
"networks",
"that",
"a",
"task",
"is",
"attached",
"to",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L477-L480 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | IsAttachmentAllocated | func (na *cnmNetworkAllocator) IsAttachmentAllocated(node *api.Node, networkAttachment *api.NetworkAttachment) bool {
if node == nil {
return false
}
if networkAttachment == nil || networkAttachment.Network == nil {
return false
}
// If the node is not found in the allocated set, then it is
// not allocated... | go | func (na *cnmNetworkAllocator) IsAttachmentAllocated(node *api.Node, networkAttachment *api.NetworkAttachment) bool {
if node == nil {
return false
}
if networkAttachment == nil || networkAttachment.Network == nil {
return false
}
// If the node is not found in the allocated set, then it is
// not allocated... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"IsAttachmentAllocated",
"(",
"node",
"*",
"api",
".",
"Node",
",",
"networkAttachment",
"*",
"api",
".",
"NetworkAttachment",
")",
"bool",
"{",
"if",
"node",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}... | // IsAttachmentAllocated returns if the passed node and network has resources allocated or not. | [
"IsAttachmentAllocated",
"returns",
"if",
"the",
"passed",
"node",
"and",
"network",
"has",
"resources",
"allocated",
"or",
"not",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L483-L521 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | AllocateAttachment | func (na *cnmNetworkAllocator) AllocateAttachment(node *api.Node, networkAttachment *api.NetworkAttachment) error {
if err := na.allocateNetworkIPs(networkAttachment); err != nil {
return err
}
if na.nodes[node.ID] == nil {
na.nodes[node.ID] = make(map[string]struct{})
}
na.nodes[node.ID][networkAttachment.N... | go | func (na *cnmNetworkAllocator) AllocateAttachment(node *api.Node, networkAttachment *api.NetworkAttachment) error {
if err := na.allocateNetworkIPs(networkAttachment); err != nil {
return err
}
if na.nodes[node.ID] == nil {
na.nodes[node.ID] = make(map[string]struct{})
}
na.nodes[node.ID][networkAttachment.N... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"AllocateAttachment",
"(",
"node",
"*",
"api",
".",
"Node",
",",
"networkAttachment",
"*",
"api",
".",
"NetworkAttachment",
")",
"error",
"{",
"if",
"err",
":=",
"na",
".",
"allocateNetworkIPs",
"(",
"netwo... | // AllocateAttachment allocates the IP addresses for a LB in a network
// on a given node | [
"AllocateAttachment",
"allocates",
"the",
"IP",
"addresses",
"for",
"a",
"LB",
"in",
"a",
"network",
"on",
"a",
"given",
"node"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L525-L537 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | DeallocateAttachment | func (na *cnmNetworkAllocator) DeallocateAttachment(node *api.Node, networkAttachment *api.NetworkAttachment) error {
delete(na.nodes[node.ID], networkAttachment.Network.ID)
if len(na.nodes[node.ID]) == 0 {
delete(na.nodes, node.ID)
}
return na.releaseEndpoints([]*api.NetworkAttachment{networkAttachment})
} | go | func (na *cnmNetworkAllocator) DeallocateAttachment(node *api.Node, networkAttachment *api.NetworkAttachment) error {
delete(na.nodes[node.ID], networkAttachment.Network.ID)
if len(na.nodes[node.ID]) == 0 {
delete(na.nodes, node.ID)
}
return na.releaseEndpoints([]*api.NetworkAttachment{networkAttachment})
} | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"DeallocateAttachment",
"(",
"node",
"*",
"api",
".",
"Node",
",",
"networkAttachment",
"*",
"api",
".",
"NetworkAttachment",
")",
"error",
"{",
"delete",
"(",
"na",
".",
"nodes",
"[",
"node",
".",
"ID",
... | // DeallocateAttachment deallocates the IP addresses for a LB in a network to
// which the node is attached. | [
"DeallocateAttachment",
"deallocates",
"the",
"IP",
"addresses",
"for",
"a",
"LB",
"in",
"a",
"network",
"to",
"which",
"the",
"node",
"is",
"attached",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L541-L549 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | allocateVIP | func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
var opts map[string]string
localNet := na.getNetwork(vip.NetworkID)
if localNet == nil {
return errors.New("networkallocator: could not find local network state")
}
if localNet.isNodeLocal {
return nil
}
// If this IP is alread... | go | func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
var opts map[string]string
localNet := na.getNetwork(vip.NetworkID)
if localNet == nil {
return errors.New("networkallocator: could not find local network state")
}
if localNet.isNodeLocal {
return nil
}
// If this IP is alread... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"allocateVIP",
"(",
"vip",
"*",
"api",
".",
"Endpoint_VirtualIP",
")",
"error",
"{",
"var",
"opts",
"map",
"[",
"string",
"]",
"string",
"\n",
"localNet",
":=",
"na",
".",
"getNetwork",
"(",
"vip",
".",... | // allocate virtual IP for a single endpoint attachment of the service. | [
"allocate",
"virtual",
"IP",
"for",
"a",
"single",
"endpoint",
"attachment",
"of",
"the",
"service",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L596-L648 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | allocateNetworkIPs | func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment) error {
var ip *net.IPNet
var opts map[string]string
ipam, _, _, err := na.resolveIPAM(nAttach.Network)
if err != nil {
return errors.Wrap(err, "failed to resolve IPAM while allocating")
}
localNet := na.getNetwork(nAttach.Netwo... | go | func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment) error {
var ip *net.IPNet
var opts map[string]string
ipam, _, _, err := na.resolveIPAM(nAttach.Network)
if err != nil {
return errors.Wrap(err, "failed to resolve IPAM while allocating")
}
localNet := na.getNetwork(nAttach.Netwo... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"allocateNetworkIPs",
"(",
"nAttach",
"*",
"api",
".",
"NetworkAttachment",
")",
"error",
"{",
"var",
"ip",
"*",
"net",
".",
"IPNet",
"\n",
"var",
"opts",
"map",
"[",
"string",
"]",
"string",
"\n\n",
"i... | // allocate the IP addresses for a single network attachment of the task. | [
"allocate",
"the",
"IP",
"addresses",
"for",
"a",
"single",
"network",
"attachment",
"of",
"the",
"task",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L683-L741 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | resolveDriver | func (na *cnmNetworkAllocator) resolveDriver(n *api.Network) (*networkDriver, error) {
dName := DefaultDriver
if n.Spec.DriverConfig != nil && n.Spec.DriverConfig.Name != "" {
dName = n.Spec.DriverConfig.Name
}
d, drvcap := na.drvRegistry.Driver(dName)
if d == nil {
err := na.loadDriver(dName)
if err != nil... | go | func (na *cnmNetworkAllocator) resolveDriver(n *api.Network) (*networkDriver, error) {
dName := DefaultDriver
if n.Spec.DriverConfig != nil && n.Spec.DriverConfig.Name != "" {
dName = n.Spec.DriverConfig.Name
}
d, drvcap := na.drvRegistry.Driver(dName)
if d == nil {
err := na.loadDriver(dName)
if err != nil... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"resolveDriver",
"(",
"n",
"*",
"api",
".",
"Network",
")",
"(",
"*",
"networkDriver",
",",
"error",
")",
"{",
"dName",
":=",
"DefaultDriver",
"\n",
"if",
"n",
".",
"Spec",
".",
"DriverConfig",
"!=",
... | // Resolve network driver | [
"Resolve",
"network",
"driver"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L813-L833 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | resolveIPAM | func (na *cnmNetworkAllocator) resolveIPAM(n *api.Network) (ipamapi.Ipam, string, map[string]string, error) {
dName := ipamapi.DefaultIPAM
if n.Spec.IPAM != nil && n.Spec.IPAM.Driver != nil && n.Spec.IPAM.Driver.Name != "" {
dName = n.Spec.IPAM.Driver.Name
}
var dOptions map[string]string
if n.Spec.IPAM != nil ... | go | func (na *cnmNetworkAllocator) resolveIPAM(n *api.Network) (ipamapi.Ipam, string, map[string]string, error) {
dName := ipamapi.DefaultIPAM
if n.Spec.IPAM != nil && n.Spec.IPAM.Driver != nil && n.Spec.IPAM.Driver.Name != "" {
dName = n.Spec.IPAM.Driver.Name
}
var dOptions map[string]string
if n.Spec.IPAM != nil ... | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"resolveIPAM",
"(",
"n",
"*",
"api",
".",
"Network",
")",
"(",
"ipamapi",
".",
"Ipam",
",",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"dName",
":=",
"ipamapi",
".",... | // Resolve the IPAM driver | [
"Resolve",
"the",
"IPAM",
"driver"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L845-L862 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | IsVIPOnIngressNetwork | func (na *cnmNetworkAllocator) IsVIPOnIngressNetwork(vip *api.Endpoint_VirtualIP) bool {
if vip == nil {
return false
}
localNet := na.getNetwork(vip.NetworkID)
if localNet != nil && localNet.nw != nil {
return networkallocator.IsIngressNetwork(localNet.nw)
}
return false
} | go | func (na *cnmNetworkAllocator) IsVIPOnIngressNetwork(vip *api.Endpoint_VirtualIP) bool {
if vip == nil {
return false
}
localNet := na.getNetwork(vip.NetworkID)
if localNet != nil && localNet.nw != nil {
return networkallocator.IsIngressNetwork(localNet.nw)
}
return false
} | [
"func",
"(",
"na",
"*",
"cnmNetworkAllocator",
")",
"IsVIPOnIngressNetwork",
"(",
"vip",
"*",
"api",
".",
"Endpoint_VirtualIP",
")",
"bool",
"{",
"if",
"vip",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"localNet",
":=",
"na",
".",
"getNetwork"... | // IsVIPOnIngressNetwork check if the vip is in ingress network | [
"IsVIPOnIngressNetwork",
"check",
"if",
"the",
"vip",
"is",
"in",
"ingress",
"network"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L999-L1009 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | IsBuiltInDriver | func IsBuiltInDriver(name string) bool {
n := strings.ToLower(name)
for _, d := range initializers {
if n == d.ntype {
return true
}
}
return false
} | go | func IsBuiltInDriver(name string) bool {
n := strings.ToLower(name)
for _, d := range initializers {
if n == d.ntype {
return true
}
}
return false
} | [
"func",
"IsBuiltInDriver",
"(",
"name",
"string",
")",
"bool",
"{",
"n",
":=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"initializers",
"{",
"if",
"n",
"==",
"d",
".",
"ntype",
"{",
"return",
"true",
"... | // IsBuiltInDriver returns whether the passed driver is an internal network driver | [
"IsBuiltInDriver",
"returns",
"whether",
"the",
"passed",
"driver",
"is",
"an",
"internal",
"network",
"driver"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L1012-L1020 | train |
docker/swarmkit | manager/allocator/cnmallocator/networkallocator.go | setIPAMSerialAlloc | func setIPAMSerialAlloc(opts map[string]string) map[string]string {
if opts == nil {
opts = make(map[string]string)
}
if _, ok := opts[ipamapi.AllocSerialPrefix]; !ok {
opts[ipamapi.AllocSerialPrefix] = "true"
}
return opts
} | go | func setIPAMSerialAlloc(opts map[string]string) map[string]string {
if opts == nil {
opts = make(map[string]string)
}
if _, ok := opts[ipamapi.AllocSerialPrefix]; !ok {
opts[ipamapi.AllocSerialPrefix] = "true"
}
return opts
} | [
"func",
"setIPAMSerialAlloc",
"(",
"opts",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"if"... | // setIPAMSerialAlloc sets the ipam allocation method to serial | [
"setIPAMSerialAlloc",
"sets",
"the",
"ipam",
"allocation",
"method",
"to",
"serial"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/cnmallocator/networkallocator.go#L1023-L1031 | train |
docker/swarmkit | template/context.go | NewContext | func NewContext(n *api.NodeDescription, t *api.Task) (ctx Context) {
ctx.Service.ID = t.ServiceID
ctx.Service.Name = t.ServiceAnnotations.Name
ctx.Service.Labels = t.ServiceAnnotations.Labels
ctx.Node.ID = t.NodeID
// Add node information to context only if we have them available
if n != nil {
ctx.Node.Hostna... | go | func NewContext(n *api.NodeDescription, t *api.Task) (ctx Context) {
ctx.Service.ID = t.ServiceID
ctx.Service.Name = t.ServiceAnnotations.Name
ctx.Service.Labels = t.ServiceAnnotations.Labels
ctx.Node.ID = t.NodeID
// Add node information to context only if we have them available
if n != nil {
ctx.Node.Hostna... | [
"func",
"NewContext",
"(",
"n",
"*",
"api",
".",
"NodeDescription",
",",
"t",
"*",
"api",
".",
"Task",
")",
"(",
"ctx",
"Context",
")",
"{",
"ctx",
".",
"Service",
".",
"ID",
"=",
"t",
".",
"ServiceID",
"\n",
"ctx",
".",
"Service",
".",
"Name",
"... | // NewContext returns a new template context from the data available in the
// task and the node where it is scheduled to run.
// The provided context can then be used to populate runtime values in a
// ContainerSpec. | [
"NewContext",
"returns",
"a",
"new",
"template",
"context",
"from",
"the",
"data",
"available",
"in",
"the",
"task",
"and",
"the",
"node",
"where",
"it",
"is",
"scheduled",
"to",
"run",
".",
"The",
"provided",
"context",
"can",
"then",
"be",
"used",
"to",
... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/template/context.go#L56-L82 | train |
docker/swarmkit | template/context.go | NewPayloadContextFromTask | func NewPayloadContextFromTask(node *api.NodeDescription, t *api.Task, dependencies exec.DependencyGetter) (ctx PayloadContext) {
return PayloadContext{
Context: NewContext(node, t),
t: t,
restrictedSecrets: secrets.Restrict(dependencies.Secrets(), t),
restrictedConfigs: configs.Restr... | go | func NewPayloadContextFromTask(node *api.NodeDescription, t *api.Task, dependencies exec.DependencyGetter) (ctx PayloadContext) {
return PayloadContext{
Context: NewContext(node, t),
t: t,
restrictedSecrets: secrets.Restrict(dependencies.Secrets(), t),
restrictedConfigs: configs.Restr... | [
"func",
"NewPayloadContextFromTask",
"(",
"node",
"*",
"api",
".",
"NodeDescription",
",",
"t",
"*",
"api",
".",
"Task",
",",
"dependencies",
"exec",
".",
"DependencyGetter",
")",
"(",
"ctx",
"PayloadContext",
")",
"{",
"return",
"PayloadContext",
"{",
"Contex... | // NewPayloadContextFromTask returns a new template context from the data
// available in the task and the node where it is scheduled to run.
// This context also provides access to the configs
// and secrets that the task has access to. The provided context can then
// be used to populate runtime values in a templated... | [
"NewPayloadContextFromTask",
"returns",
"a",
"new",
"template",
"context",
"from",
"the",
"data",
"available",
"in",
"the",
"task",
"and",
"the",
"node",
"where",
"it",
"is",
"scheduled",
"to",
"run",
".",
"This",
"context",
"also",
"provides",
"access",
"to",... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/template/context.go#L183-L190 | train |
docker/swarmkit | manager/state/store/resources.go | EventUpdate | func (r resourceEntry) EventUpdate(oldObject api.StoreObject) api.Event {
if oldObject != nil {
return api.EventUpdateResource{Resource: r.Resource, OldResource: oldObject.(resourceEntry).Resource}
}
return api.EventUpdateResource{Resource: r.Resource}
} | go | func (r resourceEntry) EventUpdate(oldObject api.StoreObject) api.Event {
if oldObject != nil {
return api.EventUpdateResource{Resource: r.Resource, OldResource: oldObject.(resourceEntry).Resource}
}
return api.EventUpdateResource{Resource: r.Resource}
} | [
"func",
"(",
"r",
"resourceEntry",
")",
"EventUpdate",
"(",
"oldObject",
"api",
".",
"StoreObject",
")",
"api",
".",
"Event",
"{",
"if",
"oldObject",
"!=",
"nil",
"{",
"return",
"api",
".",
"EventUpdateResource",
"{",
"Resource",
":",
"r",
".",
"Resource",... | // ensure that when update events are emitted, we unwrap resourceEntry | [
"ensure",
"that",
"when",
"update",
"events",
"are",
"emitted",
"we",
"unwrap",
"resourceEntry"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/resources.go#L84-L89 | train |
docker/swarmkit | manager/state/store/resources.go | CreateResource | func CreateResource(tx Tx, r *api.Resource) error {
if err := confirmExtension(tx, r); err != nil {
return err
}
// TODO(dperny): currently the "name" index is unique, which means only one
// Resource of _any_ Kind can exist with that name. This isn't a problem
// right now, but the ideal case would be for names... | go | func CreateResource(tx Tx, r *api.Resource) error {
if err := confirmExtension(tx, r); err != nil {
return err
}
// TODO(dperny): currently the "name" index is unique, which means only one
// Resource of _any_ Kind can exist with that name. This isn't a problem
// right now, but the ideal case would be for names... | [
"func",
"CreateResource",
"(",
"tx",
"Tx",
",",
"r",
"*",
"api",
".",
"Resource",
")",
"error",
"{",
"if",
"err",
":=",
"confirmExtension",
"(",
"tx",
",",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// TODO(dperny): cu... | // CreateResource adds a new resource object to the store.
// Returns ErrExist if the ID is already taken.
// Returns ErrNameConflict if a Resource with this Name already exists
// Returns ErrNoKind if the specified Kind does not exist | [
"CreateResource",
"adds",
"a",
"new",
"resource",
"object",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
".",
"Returns",
"ErrNameConflict",
"if",
"a",
"Resource",
"with",
"this",
"Name",
"already",
"exists",
... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/resources.go#L107-L119 | train |
docker/swarmkit | manager/state/store/resources.go | UpdateResource | func UpdateResource(tx Tx, r *api.Resource) error {
if err := confirmExtension(tx, r); err != nil {
return err
}
return tx.update(tableResource, resourceEntry{r})
} | go | func UpdateResource(tx Tx, r *api.Resource) error {
if err := confirmExtension(tx, r); err != nil {
return err
}
return tx.update(tableResource, resourceEntry{r})
} | [
"func",
"UpdateResource",
"(",
"tx",
"Tx",
",",
"r",
"*",
"api",
".",
"Resource",
")",
"error",
"{",
"if",
"err",
":=",
"confirmExtension",
"(",
"tx",
",",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"tx",
... | // UpdateResource updates an existing resource object in the store.
// Returns ErrNotExist if the object doesn't exist. | [
"UpdateResource",
"updates",
"an",
"existing",
"resource",
"object",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"object",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/resources.go#L123-L128 | train |
docker/swarmkit | manager/state/store/resources.go | DeleteResource | func DeleteResource(tx Tx, id string) error {
return tx.delete(tableResource, id)
} | go | func DeleteResource(tx Tx, id string) error {
return tx.delete(tableResource, id)
} | [
"func",
"DeleteResource",
"(",
"tx",
"Tx",
",",
"id",
"string",
")",
"error",
"{",
"return",
"tx",
".",
"delete",
"(",
"tableResource",
",",
"id",
")",
"\n",
"}"
] | // DeleteResource removes a resource object from the store.
// Returns ErrNotExist if the object doesn't exist. | [
"DeleteResource",
"removes",
"a",
"resource",
"object",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"object",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/resources.go#L132-L134 | train |
docker/swarmkit | manager/state/store/resources.go | GetResource | func GetResource(tx ReadTx, id string) *api.Resource {
r := tx.get(tableResource, id)
if r == nil {
return nil
}
return r.(resourceEntry).Resource
} | go | func GetResource(tx ReadTx, id string) *api.Resource {
r := tx.get(tableResource, id)
if r == nil {
return nil
}
return r.(resourceEntry).Resource
} | [
"func",
"GetResource",
"(",
"tx",
"ReadTx",
",",
"id",
"string",
")",
"*",
"api",
".",
"Resource",
"{",
"r",
":=",
"tx",
".",
"get",
"(",
"tableResource",
",",
"id",
")",
"\n",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"retur... | // GetResource looks up a resource object by ID.
// Returns nil if the object doesn't exist. | [
"GetResource",
"looks",
"up",
"a",
"resource",
"object",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"object",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/resources.go#L138-L144 | train |
docker/swarmkit | manager/state/store/resources.go | FindResources | func FindResources(tx ReadTx, by By) ([]*api.Resource, error) {
checkType := func(by By) error {
switch by.(type) {
case byIDPrefix, byName, byNamePrefix, byKind, byCustom, byCustomPrefix:
return nil
default:
return ErrInvalidFindBy
}
}
resourceList := []*api.Resource{}
appendResult := func(o api.Sto... | go | func FindResources(tx ReadTx, by By) ([]*api.Resource, error) {
checkType := func(by By) error {
switch by.(type) {
case byIDPrefix, byName, byNamePrefix, byKind, byCustom, byCustomPrefix:
return nil
default:
return ErrInvalidFindBy
}
}
resourceList := []*api.Resource{}
appendResult := func(o api.Sto... | [
"func",
"FindResources",
"(",
"tx",
"ReadTx",
",",
"by",
"By",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Resource",
",",
"error",
")",
"{",
"checkType",
":=",
"func",
"(",
"by",
"By",
")",
"error",
"{",
"switch",
"by",
".",
"(",
"type",
")",
"{",
"... | // FindResources selects a set of resource objects and returns them. | [
"FindResources",
"selects",
"a",
"set",
"of",
"resource",
"objects",
"and",
"returns",
"them",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/resources.go#L147-L164 | train |
docker/swarmkit | agent/agent.go | New | func New(config *Config) (*Agent, error) {
if err := config.validate(); err != nil {
return nil, err
}
a := &Agent{
config: config,
sessionq: make(chan sessionOperation),
started: make(chan struct{}),
leaving: make(chan struct{}),
left: make(chan struct{})... | go | func New(config *Config) (*Agent, error) {
if err := config.validate(); err != nil {
return nil, err
}
a := &Agent{
config: config,
sessionq: make(chan sessionOperation),
started: make(chan struct{}),
leaving: make(chan struct{}),
left: make(chan struct{})... | [
"func",
"New",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"Agent",
",",
"error",
")",
"{",
"if",
"err",
":=",
"config",
".",
"validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"a",
":=",
"&",
... | // New returns a new agent, ready for task dispatch. | [
"New",
"returns",
"a",
"new",
"agent",
"ready",
"for",
"task",
"dispatch",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L53-L72 | train |
docker/swarmkit | agent/agent.go | Start | func (a *Agent) Start(ctx context.Context) error {
err := errAgentStarted
a.startOnce.Do(func() {
close(a.started)
go a.run(ctx)
err = nil // clear error above, only once.
})
return err
} | go | func (a *Agent) Start(ctx context.Context) error {
err := errAgentStarted
a.startOnce.Do(func() {
close(a.started)
go a.run(ctx)
err = nil // clear error above, only once.
})
return err
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"err",
":=",
"errAgentStarted",
"\n\n",
"a",
".",
"startOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"a",
".",
"started",
")",
... | // Start begins execution of the agent in the provided context, if not already
// started.
//
// Start returns an error if the agent has already started. | [
"Start",
"begins",
"execution",
"of",
"the",
"agent",
"in",
"the",
"provided",
"context",
"if",
"not",
"already",
"started",
".",
"Start",
"returns",
"an",
"error",
"if",
"the",
"agent",
"has",
"already",
"started",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L78-L88 | train |
docker/swarmkit | agent/agent.go | Leave | func (a *Agent) Leave(ctx context.Context) error {
select {
case <-a.started:
default:
return errAgentNotStarted
}
a.leaveOnce.Do(func() {
close(a.leaving)
})
// Do not call Wait until we have confirmed that the agent is no longer
// accepting assignments. Starting a worker might race with Wait.
select {... | go | func (a *Agent) Leave(ctx context.Context) error {
select {
case <-a.started:
default:
return errAgentNotStarted
}
a.leaveOnce.Do(func() {
close(a.leaving)
})
// Do not call Wait until we have confirmed that the agent is no longer
// accepting assignments. Starting a worker might race with Wait.
select {... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Leave",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"a",
".",
"started",
":",
"default",
":",
"return",
"errAgentNotStarted",
"\n",
"}",
"\n\n",
"a",
".",
"leaveOnce",
"... | // Leave instructs the agent to leave the cluster. This method will shutdown
// assignment processing and remove all assignments from the node.
// Leave blocks until worker has finished closing all task managers or agent
// is closed. | [
"Leave",
"instructs",
"the",
"agent",
"to",
"leave",
"the",
"cluster",
".",
"This",
"method",
"will",
"shutdown",
"assignment",
"processing",
"and",
"remove",
"all",
"assignments",
"from",
"the",
"node",
".",
"Leave",
"blocks",
"until",
"worker",
"has",
"finis... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L94-L129 | train |
docker/swarmkit | agent/agent.go | Stop | func (a *Agent) Stop(ctx context.Context) error {
select {
case <-a.started:
default:
return errAgentNotStarted
}
a.stop()
// wait till closed or context cancelled
select {
case <-a.closed:
return nil
case <-ctx.Done():
return ctx.Err()
}
} | go | func (a *Agent) Stop(ctx context.Context) error {
select {
case <-a.started:
default:
return errAgentNotStarted
}
a.stop()
// wait till closed or context cancelled
select {
case <-a.closed:
return nil
case <-ctx.Done():
return ctx.Err()
}
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"a",
".",
"started",
":",
"default",
":",
"return",
"errAgentNotStarted",
"\n",
"}",
"\n\n",
"a",
".",
"stop",
"(",
... | // Stop shuts down the agent, blocking until full shutdown. If the agent is not
// started, Stop will block until the agent has fully shutdown. | [
"Stop",
"shuts",
"down",
"the",
"agent",
"blocking",
"until",
"full",
"shutdown",
".",
"If",
"the",
"agent",
"is",
"not",
"started",
"Stop",
"will",
"block",
"until",
"the",
"agent",
"has",
"fully",
"shutdown",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L133-L149 | train |
docker/swarmkit | agent/agent.go | stop | func (a *Agent) stop() bool {
var stopped bool
a.stopOnce.Do(func() {
close(a.stopped)
stopped = true
})
return stopped
} | go | func (a *Agent) stop() bool {
var stopped bool
a.stopOnce.Do(func() {
close(a.stopped)
stopped = true
})
return stopped
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"stop",
"(",
")",
"bool",
"{",
"var",
"stopped",
"bool",
"\n",
"a",
".",
"stopOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"a",
".",
"stopped",
")",
"\n",
"stopped",
"=",
"true",
"\n",
"}",
... | // stop signals the agent shutdown process, returning true if this call was the
// first to actually shutdown the agent. | [
"stop",
"signals",
"the",
"agent",
"shutdown",
"process",
"returning",
"true",
"if",
"this",
"call",
"was",
"the",
"first",
"to",
"actually",
"shutdown",
"the",
"agent",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L153-L161 | train |
docker/swarmkit | agent/agent.go | Err | func (a *Agent) Err(ctx context.Context) error {
select {
case <-a.closed:
return a.err
case <-ctx.Done():
return ctx.Err()
}
} | go | func (a *Agent) Err(ctx context.Context) error {
select {
case <-a.closed:
return a.err
case <-ctx.Done():
return ctx.Err()
}
} | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Err",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"a",
".",
"closed",
":",
"return",
"a",
".",
"err",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"retur... | // Err returns the error that caused the agent to shutdown or nil. Err blocks
// until the agent is fully shutdown. | [
"Err",
"returns",
"the",
"error",
"that",
"caused",
"the",
"agent",
"to",
"shutdown",
"or",
"nil",
".",
"Err",
"blocks",
"until",
"the",
"agent",
"is",
"fully",
"shutdown",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L165-L172 | train |
docker/swarmkit | agent/agent.go | withSession | func (a *Agent) withSession(ctx context.Context, fn func(session *session) error) error {
response := make(chan error, 1)
select {
case a.sessionq <- sessionOperation{
fn: fn,
response: response,
}:
select {
case err := <-response:
return err
case <-a.closed:
return ErrClosed
case <-ctx.Done... | go | func (a *Agent) withSession(ctx context.Context, fn func(session *session) error) error {
response := make(chan error, 1)
select {
case a.sessionq <- sessionOperation{
fn: fn,
response: response,
}:
select {
case err := <-response:
return err
case <-a.closed:
return ErrClosed
case <-ctx.Done... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"withSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"fn",
"func",
"(",
"session",
"*",
"session",
")",
"error",
")",
"error",
"{",
"response",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"sel... | // withSession runs fn with the current session. | [
"withSession",
"runs",
"fn",
"with",
"the",
"current",
"session",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L461-L481 | train |
docker/swarmkit | agent/agent.go | UpdateTaskStatus | func (a *Agent) UpdateTaskStatus(ctx context.Context, taskID string, status *api.TaskStatus) error {
log.G(ctx).WithField("task.id", taskID).Debug("(*Agent).UpdateTaskStatus")
ctx, cancel := context.WithCancel(ctx)
defer cancel()
errs := make(chan error, 1)
if err := a.withSession(ctx, func(session *session) erro... | go | func (a *Agent) UpdateTaskStatus(ctx context.Context, taskID string, status *api.TaskStatus) error {
log.G(ctx).WithField("task.id", taskID).Debug("(*Agent).UpdateTaskStatus")
ctx, cancel := context.WithCancel(ctx)
defer cancel()
errs := make(chan error, 1)
if err := a.withSession(ctx, func(session *session) erro... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"UpdateTaskStatus",
"(",
"ctx",
"context",
".",
"Context",
",",
"taskID",
"string",
",",
"status",
"*",
"api",
".",
"TaskStatus",
")",
"error",
"{",
"log",
".",
"G",
"(",
"ctx",
")",
".",
"WithField",
"(",
"\"",
... | // UpdateTaskStatus attempts to send a task status update over the current session,
// blocking until the operation is completed.
//
// If an error is returned, the operation should be retried. | [
"UpdateTaskStatus",
"attempts",
"to",
"send",
"a",
"task",
"status",
"update",
"over",
"the",
"current",
"session",
"blocking",
"until",
"the",
"operation",
"is",
"completed",
".",
"If",
"an",
"error",
"is",
"returned",
"the",
"operation",
"should",
"be",
"ret... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L487-L521 | train |
docker/swarmkit | agent/agent.go | Publisher | func (a *Agent) Publisher(ctx context.Context, subscriptionID string) (exec.LogPublisher, func(), error) {
// TODO(stevvooe): The level of coordination here is WAY too much for logs.
// These should only be best effort and really just buffer until a session is
// ready. Ideally, they would use a separate connection ... | go | func (a *Agent) Publisher(ctx context.Context, subscriptionID string) (exec.LogPublisher, func(), error) {
// TODO(stevvooe): The level of coordination here is WAY too much for logs.
// These should only be best effort and really just buffer until a session is
// ready. Ideally, they would use a separate connection ... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"Publisher",
"(",
"ctx",
"context",
".",
"Context",
",",
"subscriptionID",
"string",
")",
"(",
"exec",
".",
"LogPublisher",
",",
"func",
"(",
")",
",",
"error",
")",
"{",
"// TODO(stevvooe): The level of coordination here i... | // Publisher returns a LogPublisher for the given subscription
// as well as a cancel function that should be called when the log stream
// is completed. | [
"Publisher",
"returns",
"a",
"LogPublisher",
"for",
"the",
"given",
"subscription",
"as",
"well",
"as",
"a",
"cancel",
"function",
"that",
"should",
"be",
"called",
"when",
"the",
"log",
"stream",
"is",
"completed",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L526-L570 | train |
docker/swarmkit | agent/agent.go | nodeDescriptionWithHostname | func (a *Agent) nodeDescriptionWithHostname(ctx context.Context, tlsInfo *api.NodeTLSInfo) (*api.NodeDescription, error) {
desc, err := a.config.Executor.Describe(ctx)
// Override hostname and TLS info
if desc != nil {
if a.config.Hostname != "" && desc != nil {
desc.Hostname = a.config.Hostname
}
desc.TLS... | go | func (a *Agent) nodeDescriptionWithHostname(ctx context.Context, tlsInfo *api.NodeTLSInfo) (*api.NodeDescription, error) {
desc, err := a.config.Executor.Describe(ctx)
// Override hostname and TLS info
if desc != nil {
if a.config.Hostname != "" && desc != nil {
desc.Hostname = a.config.Hostname
}
desc.TLS... | [
"func",
"(",
"a",
"*",
"Agent",
")",
"nodeDescriptionWithHostname",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlsInfo",
"*",
"api",
".",
"NodeTLSInfo",
")",
"(",
"*",
"api",
".",
"NodeDescription",
",",
"error",
")",
"{",
"desc",
",",
"err",
":=",
"... | // nodeDescriptionWithHostname retrieves node description, and overrides hostname if available | [
"nodeDescriptionWithHostname",
"retrieves",
"node",
"description",
"and",
"overrides",
"hostname",
"if",
"available"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L573-L585 | train |
docker/swarmkit | agent/agent.go | nodesEqual | func nodesEqual(a, b *api.Node) bool {
a, b = a.Copy(), b.Copy()
a.Status, b.Status = api.NodeStatus{}, api.NodeStatus{}
a.Meta, b.Meta = api.Meta{}, api.Meta{}
return reflect.DeepEqual(a, b)
} | go | func nodesEqual(a, b *api.Node) bool {
a, b = a.Copy(), b.Copy()
a.Status, b.Status = api.NodeStatus{}, api.NodeStatus{}
a.Meta, b.Meta = api.Meta{}, api.Meta{}
return reflect.DeepEqual(a, b)
} | [
"func",
"nodesEqual",
"(",
"a",
",",
"b",
"*",
"api",
".",
"Node",
")",
"bool",
"{",
"a",
",",
"b",
"=",
"a",
".",
"Copy",
"(",
")",
",",
"b",
".",
"Copy",
"(",
")",
"\n\n",
"a",
".",
"Status",
",",
"b",
".",
"Status",
"=",
"api",
".",
"N... | // nodesEqual returns true if the node states are functionally equal, ignoring status,
// version and other superfluous fields.
//
// This used to decide whether or not to propagate a node update to executor. | [
"nodesEqual",
"returns",
"true",
"if",
"the",
"node",
"states",
"are",
"functionally",
"equal",
"ignoring",
"status",
"version",
"and",
"other",
"superfluous",
"fields",
".",
"This",
"used",
"to",
"decide",
"whether",
"or",
"not",
"to",
"propagate",
"a",
"node... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/agent.go#L591-L598 | train |
docker/swarmkit | agent/exec/errors.go | IsTemporary | func IsTemporary(err error) bool {
for err != nil {
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
return true
}
cause := errors.Cause(err)
if cause == err {
break
}
err = cause
}
return false
} | go | func IsTemporary(err error) bool {
for err != nil {
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
return true
}
cause := errors.Cause(err)
if cause == err {
break
}
err = cause
}
return false
} | [
"func",
"IsTemporary",
"(",
"err",
"error",
")",
"bool",
"{",
"for",
"err",
"!=",
"nil",
"{",
"if",
"tmp",
",",
"ok",
":=",
"err",
".",
"(",
"Temporary",
")",
";",
"ok",
"&&",
"tmp",
".",
"Temporary",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
... | // IsTemporary returns true if the error or a recursive cause returns true for
// temporary. | [
"IsTemporary",
"returns",
"true",
"if",
"the",
"error",
"or",
"a",
"recursive",
"cause",
"returns",
"true",
"for",
"temporary",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/errors.go#L67-L82 | train |
docker/swarmkit | ca/auth.go | LogTLSState | func LogTLSState(ctx context.Context, tlsState *tls.ConnectionState) {
if tlsState == nil {
log.G(ctx).Debugf("no TLS Chains found")
return
}
peerCerts := []string{}
verifiedChain := []string{}
for _, cert := range tlsState.PeerCertificates {
peerCerts = append(peerCerts, cert.Subject.CommonName)
}
for _,... | go | func LogTLSState(ctx context.Context, tlsState *tls.ConnectionState) {
if tlsState == nil {
log.G(ctx).Debugf("no TLS Chains found")
return
}
peerCerts := []string{}
verifiedChain := []string{}
for _, cert := range tlsState.PeerCertificates {
peerCerts = append(peerCerts, cert.Subject.CommonName)
}
for _,... | [
"func",
"LogTLSState",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlsState",
"*",
"tls",
".",
"ConnectionState",
")",
"{",
"if",
"tlsState",
"==",
"nil",
"{",
"log",
".",
"G",
"(",
"ctx",
")",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
... | // LogTLSState logs information about the TLS connection and remote peers | [
"LogTLSState",
"logs",
"information",
"about",
"the",
"TLS",
"connection",
"and",
"remote",
"peers"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L27-L50 | train |
docker/swarmkit | ca/auth.go | getCertificateSubject | func getCertificateSubject(tlsState *tls.ConnectionState) (pkix.Name, error) {
if tlsState == nil {
return pkix.Name{}, status.Errorf(codes.PermissionDenied, "request is not using TLS")
}
if len(tlsState.PeerCertificates) == 0 {
return pkix.Name{}, status.Errorf(codes.PermissionDenied, "no client certificates in... | go | func getCertificateSubject(tlsState *tls.ConnectionState) (pkix.Name, error) {
if tlsState == nil {
return pkix.Name{}, status.Errorf(codes.PermissionDenied, "request is not using TLS")
}
if len(tlsState.PeerCertificates) == 0 {
return pkix.Name{}, status.Errorf(codes.PermissionDenied, "no client certificates in... | [
"func",
"getCertificateSubject",
"(",
"tlsState",
"*",
"tls",
".",
"ConnectionState",
")",
"(",
"pkix",
".",
"Name",
",",
"error",
")",
"{",
"if",
"tlsState",
"==",
"nil",
"{",
"return",
"pkix",
".",
"Name",
"{",
"}",
",",
"status",
".",
"Errorf",
"(",... | // getCertificateSubject extracts the subject from a verified client certificate | [
"getCertificateSubject",
"extracts",
"the",
"subject",
"from",
"a",
"verified",
"client",
"certificate"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L53-L65 | train |
docker/swarmkit | ca/auth.go | certSubjectFromContext | func certSubjectFromContext(ctx context.Context) (pkix.Name, error) {
connState, err := tlsConnStateFromContext(ctx)
if err != nil {
return pkix.Name{}, err
}
return getCertificateSubject(connState)
} | go | func certSubjectFromContext(ctx context.Context) (pkix.Name, error) {
connState, err := tlsConnStateFromContext(ctx)
if err != nil {
return pkix.Name{}, err
}
return getCertificateSubject(connState)
} | [
"func",
"certSubjectFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"pkix",
".",
"Name",
",",
"error",
")",
"{",
"connState",
",",
"err",
":=",
"tlsConnStateFromContext",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"pki... | // certSubjectFromContext extracts pkix.Name from context. | [
"certSubjectFromContext",
"extracts",
"pkix",
".",
"Name",
"from",
"context",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L80-L86 | train |
docker/swarmkit | ca/auth.go | AuthorizeOrgAndRole | func AuthorizeOrgAndRole(ctx context.Context, org string, blacklistedCerts map[string]*api.BlacklistedCertificate, ou ...string) (string, error) {
certSubj, err := certSubjectFromContext(ctx)
if err != nil {
return "", err
}
// Check if the current certificate has an OU that authorizes
// access to this method
... | go | func AuthorizeOrgAndRole(ctx context.Context, org string, blacklistedCerts map[string]*api.BlacklistedCertificate, ou ...string) (string, error) {
certSubj, err := certSubjectFromContext(ctx)
if err != nil {
return "", err
}
// Check if the current certificate has an OU that authorizes
// access to this method
... | [
"func",
"AuthorizeOrgAndRole",
"(",
"ctx",
"context",
".",
"Context",
",",
"org",
"string",
",",
"blacklistedCerts",
"map",
"[",
"string",
"]",
"*",
"api",
".",
"BlacklistedCertificate",
",",
"ou",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{... | // AuthorizeOrgAndRole takes in a context and a list of roles, and returns
// the Node ID of the node. | [
"AuthorizeOrgAndRole",
"takes",
"in",
"a",
"context",
"and",
"a",
"list",
"of",
"roles",
"and",
"returns",
"the",
"Node",
"ID",
"of",
"the",
"node",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L90-L102 | train |
docker/swarmkit | ca/auth.go | authorizeOrg | func authorizeOrg(certSubj pkix.Name, org string, blacklistedCerts map[string]*api.BlacklistedCertificate) (string, error) {
if _, ok := blacklistedCerts[certSubj.CommonName]; ok {
return "", status.Errorf(codes.PermissionDenied, "Permission denied: node %s was removed from swarm", certSubj.CommonName)
}
if len(c... | go | func authorizeOrg(certSubj pkix.Name, org string, blacklistedCerts map[string]*api.BlacklistedCertificate) (string, error) {
if _, ok := blacklistedCerts[certSubj.CommonName]; ok {
return "", status.Errorf(codes.PermissionDenied, "Permission denied: node %s was removed from swarm", certSubj.CommonName)
}
if len(c... | [
"func",
"authorizeOrg",
"(",
"certSubj",
"pkix",
".",
"Name",
",",
"org",
"string",
",",
"blacklistedCerts",
"map",
"[",
"string",
"]",
"*",
"api",
".",
"BlacklistedCertificate",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"... | // authorizeOrg takes in a certificate subject and an organization, and returns
// the Node ID of the node. | [
"authorizeOrg",
"takes",
"in",
"a",
"certificate",
"subject",
"and",
"an",
"organization",
"and",
"returns",
"the",
"Node",
"ID",
"of",
"the",
"node",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L106-L116 | train |
docker/swarmkit | ca/auth.go | AuthorizeForwardedRoleAndOrg | func AuthorizeForwardedRoleAndOrg(ctx context.Context, authorizedRoles, forwarderRoles []string, org string, blacklistedCerts map[string]*api.BlacklistedCertificate) (string, error) {
if isForwardedRequest(ctx) {
_, err := AuthorizeOrgAndRole(ctx, org, blacklistedCerts, forwarderRoles...)
if err != nil {
return... | go | func AuthorizeForwardedRoleAndOrg(ctx context.Context, authorizedRoles, forwarderRoles []string, org string, blacklistedCerts map[string]*api.BlacklistedCertificate) (string, error) {
if isForwardedRequest(ctx) {
_, err := AuthorizeOrgAndRole(ctx, org, blacklistedCerts, forwarderRoles...)
if err != nil {
return... | [
"func",
"AuthorizeForwardedRoleAndOrg",
"(",
"ctx",
"context",
".",
"Context",
",",
"authorizedRoles",
",",
"forwarderRoles",
"[",
"]",
"string",
",",
"org",
"string",
",",
"blacklistedCerts",
"map",
"[",
"string",
"]",
"*",
"api",
".",
"BlacklistedCertificate",
... | // AuthorizeForwardedRoleAndOrg checks for proper roles and organization of caller. The RPC may have
// been proxied by a manager, in which case the manager is authenticated and
// so is the certificate information that it forwarded. It returns the node ID
// of the original client. | [
"AuthorizeForwardedRoleAndOrg",
"checks",
"for",
"proper",
"roles",
"and",
"organization",
"of",
"caller",
".",
"The",
"RPC",
"may",
"have",
"been",
"proxied",
"by",
"a",
"manager",
"in",
"which",
"case",
"the",
"manager",
"is",
"authenticated",
"and",
"so",
"... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L122-L156 | train |
docker/swarmkit | ca/auth.go | intersectArrays | func intersectArrays(orig, tgt []string) bool {
for _, i := range orig {
for _, x := range tgt {
if i == x {
return true
}
}
}
return false
} | go | func intersectArrays(orig, tgt []string) bool {
for _, i := range orig {
for _, x := range tgt {
if i == x {
return true
}
}
}
return false
} | [
"func",
"intersectArrays",
"(",
"orig",
",",
"tgt",
"[",
"]",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"i",
":=",
"range",
"orig",
"{",
"for",
"_",
",",
"x",
":=",
"range",
"tgt",
"{",
"if",
"i",
"==",
"x",
"{",
"return",
"true",
"\n",
"}",... | // intersectArrays returns true when there is at least one element in common
// between the two arrays | [
"intersectArrays",
"returns",
"true",
"when",
"there",
"is",
"at",
"least",
"one",
"element",
"in",
"common",
"between",
"the",
"two",
"arrays"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L160-L169 | train |
docker/swarmkit | ca/auth.go | RemoteNode | func RemoteNode(ctx context.Context) (RemoteNodeInfo, error) {
// If we have a value on the context that marks this as a local
// request, we return the node info from the context.
localNodeInfo := ctx.Value(LocalRequestKey)
if localNodeInfo != nil {
nodeInfo, ok := localNodeInfo.(RemoteNodeInfo)
if ok {
re... | go | func RemoteNode(ctx context.Context) (RemoteNodeInfo, error) {
// If we have a value on the context that marks this as a local
// request, we return the node info from the context.
localNodeInfo := ctx.Value(LocalRequestKey)
if localNodeInfo != nil {
nodeInfo, ok := localNodeInfo.(RemoteNodeInfo)
if ok {
re... | [
"func",
"RemoteNode",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"RemoteNodeInfo",
",",
"error",
")",
"{",
"// If we have a value on the context that marks this as a local",
"// request, we return the node info from the context.",
"localNodeInfo",
":=",
"ctx",
".",
"Val... | // RemoteNode returns the node ID and role from the client's TLS certificate.
// If the RPC was forwarded, the original client's ID and role is returned, as
// well as the forwarder's ID. This function does not do authorization checks -
// it only looks up the node ID. | [
"RemoteNode",
"returns",
"the",
"node",
"ID",
"and",
"role",
"from",
"the",
"client",
"s",
"TLS",
"certificate",
".",
"If",
"the",
"RPC",
"was",
"forwarded",
"the",
"original",
"client",
"s",
"ID",
"and",
"role",
"is",
"returned",
"as",
"well",
"as",
"th... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/auth.go#L198-L247 | train |
docker/swarmkit | manager/orchestrator/restart/restart.go | NewSupervisor | func NewSupervisor(store *store.MemoryStore) *Supervisor {
return &Supervisor{
store: store,
delays: make(map[string]*delayedStart),
historyByService: make(map[string]map[orchestrator.SlotTuple]*instanceRestartInfo),
TaskTimeout: defaultOldTaskTimeout,
}
} | go | func NewSupervisor(store *store.MemoryStore) *Supervisor {
return &Supervisor{
store: store,
delays: make(map[string]*delayedStart),
historyByService: make(map[string]map[orchestrator.SlotTuple]*instanceRestartInfo),
TaskTimeout: defaultOldTaskTimeout,
}
} | [
"func",
"NewSupervisor",
"(",
"store",
"*",
"store",
".",
"MemoryStore",
")",
"*",
"Supervisor",
"{",
"return",
"&",
"Supervisor",
"{",
"store",
":",
"store",
",",
"delays",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"delayedStart",
")",
",",
"h... | // NewSupervisor creates a new RestartSupervisor. | [
"NewSupervisor",
"creates",
"a",
"new",
"RestartSupervisor",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/restart/restart.go#L63-L70 | train |
docker/swarmkit | manager/orchestrator/restart/restart.go | UpdatableTasksInSlot | func (r *Supervisor) UpdatableTasksInSlot(ctx context.Context, slot orchestrator.Slot, service *api.Service) orchestrator.Slot {
if len(slot) < 1 {
return nil
}
var updatable orchestrator.Slot
for _, t := range slot {
if t.DesiredState <= api.TaskStateRunning {
updatable = append(updatable, t)
}
}
if le... | go | func (r *Supervisor) UpdatableTasksInSlot(ctx context.Context, slot orchestrator.Slot, service *api.Service) orchestrator.Slot {
if len(slot) < 1 {
return nil
}
var updatable orchestrator.Slot
for _, t := range slot {
if t.DesiredState <= api.TaskStateRunning {
updatable = append(updatable, t)
}
}
if le... | [
"func",
"(",
"r",
"*",
"Supervisor",
")",
"UpdatableTasksInSlot",
"(",
"ctx",
"context",
".",
"Context",
",",
"slot",
"orchestrator",
".",
"Slot",
",",
"service",
"*",
"api",
".",
"Service",
")",
"orchestrator",
".",
"Slot",
"{",
"if",
"len",
"(",
"slot"... | // UpdatableTasksInSlot returns the set of tasks that should be passed to the
// updater from this slot, or an empty slice if none should be. An updatable
// slot has either at least one task that with desired state <= RUNNING, or its
// most recent task has stopped running and should not be restarted. The latter
// c... | [
"UpdatableTasksInSlot",
"returns",
"the",
"set",
"of",
"tasks",
"that",
"should",
"be",
"passed",
"to",
"the",
"updater",
"from",
"this",
"slot",
"or",
"an",
"empty",
"slice",
"if",
"none",
"should",
"be",
".",
"An",
"updatable",
"slot",
"has",
"either",
"... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/restart/restart.go#L310-L342 | train |
docker/swarmkit | manager/orchestrator/restart/restart.go | RecordRestartHistory | func (r *Supervisor) RecordRestartHistory(tuple orchestrator.SlotTuple, replacementTask *api.Task) {
if replacementTask.Spec.Restart == nil || replacementTask.Spec.Restart.MaxAttempts == 0 {
// No limit on the number of restarts, so no need to record
// history.
return
}
r.mu.Lock()
defer r.mu.Unlock()
ser... | go | func (r *Supervisor) RecordRestartHistory(tuple orchestrator.SlotTuple, replacementTask *api.Task) {
if replacementTask.Spec.Restart == nil || replacementTask.Spec.Restart.MaxAttempts == 0 {
// No limit on the number of restarts, so no need to record
// history.
return
}
r.mu.Lock()
defer r.mu.Unlock()
ser... | [
"func",
"(",
"r",
"*",
"Supervisor",
")",
"RecordRestartHistory",
"(",
"tuple",
"orchestrator",
".",
"SlotTuple",
",",
"replacementTask",
"*",
"api",
".",
"Task",
")",
"{",
"if",
"replacementTask",
".",
"Spec",
".",
"Restart",
"==",
"nil",
"||",
"replacement... | // RecordRestartHistory updates the historyByService map to reflect the restart
// of restartedTask. | [
"RecordRestartHistory",
"updates",
"the",
"historyByService",
"map",
"to",
"reflect",
"the",
"restart",
"of",
"restartedTask",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/restart/restart.go#L346-L395 | train |
docker/swarmkit | manager/orchestrator/restart/restart.go | StartNow | func (r *Supervisor) StartNow(tx store.Tx, taskID string) error {
t := store.GetTask(tx, taskID)
if t == nil || t.DesiredState >= api.TaskStateRunning {
return nil
}
t.DesiredState = api.TaskStateRunning
return store.UpdateTask(tx, t)
} | go | func (r *Supervisor) StartNow(tx store.Tx, taskID string) error {
t := store.GetTask(tx, taskID)
if t == nil || t.DesiredState >= api.TaskStateRunning {
return nil
}
t.DesiredState = api.TaskStateRunning
return store.UpdateTask(tx, t)
} | [
"func",
"(",
"r",
"*",
"Supervisor",
")",
"StartNow",
"(",
"tx",
"store",
".",
"Tx",
",",
"taskID",
"string",
")",
"error",
"{",
"t",
":=",
"store",
".",
"GetTask",
"(",
"tx",
",",
"taskID",
")",
"\n",
"if",
"t",
"==",
"nil",
"||",
"t",
".",
"D... | // StartNow moves the task into the RUNNING state so it will proceed to start
// up. | [
"StartNow",
"moves",
"the",
"task",
"into",
"the",
"RUNNING",
"state",
"so",
"it",
"will",
"proceed",
"to",
"start",
"up",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/restart/restart.go#L496-L503 | train |
docker/swarmkit | manager/orchestrator/restart/restart.go | Cancel | func (r *Supervisor) Cancel(taskID string) {
r.mu.Lock()
delay, ok := r.delays[taskID]
r.mu.Unlock()
if !ok {
return
}
delay.cancel()
<-delay.doneCh
} | go | func (r *Supervisor) Cancel(taskID string) {
r.mu.Lock()
delay, ok := r.delays[taskID]
r.mu.Unlock()
if !ok {
return
}
delay.cancel()
<-delay.doneCh
} | [
"func",
"(",
"r",
"*",
"Supervisor",
")",
"Cancel",
"(",
"taskID",
"string",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"delay",
",",
"ok",
":=",
"r",
".",
"delays",
"[",
"taskID",
"]",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")... | // Cancel cancels a pending restart. | [
"Cancel",
"cancels",
"a",
"pending",
"restart",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/restart/restart.go#L506-L517 | train |
docker/swarmkit | manager/orchestrator/restart/restart.go | CancelAll | func (r *Supervisor) CancelAll() {
var cancelled []delayedStart
r.mu.Lock()
for _, delay := range r.delays {
delay.cancel()
}
r.mu.Unlock()
for _, delay := range cancelled {
<-delay.doneCh
}
} | go | func (r *Supervisor) CancelAll() {
var cancelled []delayedStart
r.mu.Lock()
for _, delay := range r.delays {
delay.cancel()
}
r.mu.Unlock()
for _, delay := range cancelled {
<-delay.doneCh
}
} | [
"func",
"(",
"r",
"*",
"Supervisor",
")",
"CancelAll",
"(",
")",
"{",
"var",
"cancelled",
"[",
"]",
"delayedStart",
"\n\n",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"for",
"_",
",",
"delay",
":=",
"range",
"r",
".",
"delays",
"{",
"delay",
".... | // CancelAll aborts all pending restarts and waits for any instances of
// StartNow that have already triggered to complete. | [
"CancelAll",
"aborts",
"all",
"pending",
"restarts",
"and",
"waits",
"for",
"any",
"instances",
"of",
"StartNow",
"that",
"have",
"already",
"triggered",
"to",
"complete",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/restart/restart.go#L521-L533 | train |
docker/swarmkit | manager/orchestrator/restart/restart.go | ClearServiceHistory | func (r *Supervisor) ClearServiceHistory(serviceID string) {
r.mu.Lock()
delete(r.historyByService, serviceID)
r.mu.Unlock()
} | go | func (r *Supervisor) ClearServiceHistory(serviceID string) {
r.mu.Lock()
delete(r.historyByService, serviceID)
r.mu.Unlock()
} | [
"func",
"(",
"r",
"*",
"Supervisor",
")",
"ClearServiceHistory",
"(",
"serviceID",
"string",
")",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"r",
".",
"historyByService",
",",
"serviceID",
")",
"\n",
"r",
".",
"mu",
".",
"Unlock... | // ClearServiceHistory forgets restart history related to a given service ID. | [
"ClearServiceHistory",
"forgets",
"restart",
"history",
"related",
"to",
"a",
"given",
"service",
"ID",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/restart/restart.go#L536-L540 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | NewCluster | func NewCluster() *Cluster {
// TODO(abronan): generate Cluster ID for federation
return &Cluster{
members: make(map[uint64]*Member),
removed: make(map[uint64]bool),
PeersBroadcast: watch.NewQueue(),
}
} | go | func NewCluster() *Cluster {
// TODO(abronan): generate Cluster ID for federation
return &Cluster{
members: make(map[uint64]*Member),
removed: make(map[uint64]bool),
PeersBroadcast: watch.NewQueue(),
}
} | [
"func",
"NewCluster",
"(",
")",
"*",
"Cluster",
"{",
"// TODO(abronan): generate Cluster ID for federation",
"return",
"&",
"Cluster",
"{",
"members",
":",
"make",
"(",
"map",
"[",
"uint64",
"]",
"*",
"Member",
")",
",",
"removed",
":",
"make",
"(",
"map",
"... | // NewCluster creates a new Cluster neighbors list for a raft Member. | [
"NewCluster",
"creates",
"a",
"new",
"Cluster",
"neighbors",
"list",
"for",
"a",
"raft",
"Member",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L47-L55 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | Members | func (c *Cluster) Members() map[uint64]*Member {
members := make(map[uint64]*Member)
c.mu.RLock()
for k, v := range c.members {
members[k] = v
}
c.mu.RUnlock()
return members
} | go | func (c *Cluster) Members() map[uint64]*Member {
members := make(map[uint64]*Member)
c.mu.RLock()
for k, v := range c.members {
members[k] = v
}
c.mu.RUnlock()
return members
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Members",
"(",
")",
"map",
"[",
"uint64",
"]",
"*",
"Member",
"{",
"members",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"*",
"Member",
")",
"\n",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"for",
... | // Members returns the list of raft Members in the Cluster. | [
"Members",
"returns",
"the",
"list",
"of",
"raft",
"Members",
"in",
"the",
"Cluster",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L58-L66 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | Removed | func (c *Cluster) Removed() []uint64 {
c.mu.RLock()
removed := make([]uint64, 0, len(c.removed))
for k := range c.removed {
removed = append(removed, k)
}
c.mu.RUnlock()
return removed
} | go | func (c *Cluster) Removed() []uint64 {
c.mu.RLock()
removed := make([]uint64, 0, len(c.removed))
for k := range c.removed {
removed = append(removed, k)
}
c.mu.RUnlock()
return removed
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Removed",
"(",
")",
"[",
"]",
"uint64",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"removed",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"len",
"(",
"c",
".",
"removed",
")",
")",
"... | // Removed returns the list of raft Members removed from the Cluster. | [
"Removed",
"returns",
"the",
"list",
"of",
"raft",
"Members",
"removed",
"from",
"the",
"Cluster",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L69-L77 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | GetMember | func (c *Cluster) GetMember(id uint64) *Member {
c.mu.RLock()
defer c.mu.RUnlock()
return c.members[id]
} | go | func (c *Cluster) GetMember(id uint64) *Member {
c.mu.RLock()
defer c.mu.RUnlock()
return c.members[id]
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"GetMember",
"(",
"id",
"uint64",
")",
"*",
"Member",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"members",
"[",
"id",
... | // GetMember returns informations on a given Member. | [
"GetMember",
"returns",
"informations",
"on",
"a",
"given",
"Member",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L80-L84 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | AddMember | func (c *Cluster) AddMember(member *Member) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[member.RaftID] {
return ErrIDRemoved
}
c.members[member.RaftID] = member
c.broadcastUpdate()
return nil
} | go | func (c *Cluster) AddMember(member *Member) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[member.RaftID] {
return ErrIDRemoved
}
c.members[member.RaftID] = member
c.broadcastUpdate()
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"AddMember",
"(",
"member",
"*",
"Member",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"removed",
"[",
"member"... | // AddMember adds a node to the Cluster Memberlist. | [
"AddMember",
"adds",
"a",
"node",
"to",
"the",
"Cluster",
"Memberlist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L98-L110 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | RemoveMember | func (c *Cluster) RemoveMember(id uint64) error {
c.mu.Lock()
defer c.mu.Unlock()
c.removed[id] = true
return c.clearMember(id)
} | go | func (c *Cluster) RemoveMember(id uint64) error {
c.mu.Lock()
defer c.mu.Unlock()
c.removed[id] = true
return c.clearMember(id)
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"RemoveMember",
"(",
"id",
"uint64",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"removed",
"[",
"id",
"]",
"=",
"tru... | // RemoveMember removes a node from the Cluster Memberlist, and adds it to
// the removed list. | [
"RemoveMember",
"removes",
"a",
"node",
"from",
"the",
"Cluster",
"Memberlist",
"and",
"adds",
"it",
"to",
"the",
"removed",
"list",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L114-L120 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | UpdateMember | func (c *Cluster) UpdateMember(id uint64, m *api.RaftMember) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[id] {
return ErrIDRemoved
}
oldMember, ok := c.members[id]
if !ok {
return ErrIDNotFound
}
if oldMember.NodeID != m.NodeID {
// Should never happen; this is a sanity check
return errors.N... | go | func (c *Cluster) UpdateMember(id uint64, m *api.RaftMember) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[id] {
return ErrIDRemoved
}
oldMember, ok := c.members[id]
if !ok {
return ErrIDNotFound
}
if oldMember.NodeID != m.NodeID {
// Should never happen; this is a sanity check
return errors.N... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"UpdateMember",
"(",
"id",
"uint64",
",",
"m",
"*",
"api",
".",
"RaftMember",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",... | // UpdateMember updates member address. | [
"UpdateMember",
"updates",
"member",
"address",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L123-L148 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | ClearMember | func (c *Cluster) ClearMember(id uint64) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.clearMember(id)
} | go | func (c *Cluster) ClearMember(id uint64) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.clearMember(id)
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"ClearMember",
"(",
"id",
"uint64",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"c",
".",
"clearMember",
"(",
"id",
"... | // ClearMember removes a node from the Cluster Memberlist, but does NOT add it
// to the removed list. | [
"ClearMember",
"removes",
"a",
"node",
"from",
"the",
"Cluster",
"Memberlist",
"but",
"does",
"NOT",
"add",
"it",
"to",
"the",
"removed",
"list",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L152-L157 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | IsIDRemoved | func (c *Cluster) IsIDRemoved(id uint64) bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.removed[id]
} | go | func (c *Cluster) IsIDRemoved(id uint64) bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.removed[id]
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"IsIDRemoved",
"(",
"id",
"uint64",
")",
"bool",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"removed",
"[",
"id",
"]",
... | // IsIDRemoved checks if a Member is in the remove set. | [
"IsIDRemoved",
"checks",
"if",
"a",
"Member",
"is",
"in",
"the",
"remove",
"set",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L168-L172 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | Clear | func (c *Cluster) Clear() {
c.mu.Lock()
c.members = make(map[uint64]*Member)
c.removed = make(map[uint64]bool)
c.mu.Unlock()
} | go | func (c *Cluster) Clear() {
c.mu.Lock()
c.members = make(map[uint64]*Member)
c.removed = make(map[uint64]bool)
c.mu.Unlock()
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Clear",
"(",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"c",
".",
"members",
"=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"*",
"Member",
")",
"\n",
"c",
".",
"removed",
"=",
"make",
"(",
... | // Clear resets the list of active Members and removed Members. | [
"Clear",
"resets",
"the",
"list",
"of",
"active",
"Members",
"and",
"removed",
"Members",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L175-L181 | train |
docker/swarmkit | manager/state/raft/membership/cluster.go | ValidateConfigurationChange | func (c *Cluster) ValidateConfigurationChange(cc raftpb.ConfChange) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[cc.NodeID] {
return ErrIDRemoved
}
switch cc.Type {
case raftpb.ConfChangeAddNode:
if c.members[cc.NodeID] != nil {
return ErrIDExists
}
case raftpb.ConfChangeRemoveNode:
if c.memb... | go | func (c *Cluster) ValidateConfigurationChange(cc raftpb.ConfChange) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[cc.NodeID] {
return ErrIDRemoved
}
switch cc.Type {
case raftpb.ConfChangeAddNode:
if c.members[cc.NodeID] != nil {
return ErrIDExists
}
case raftpb.ConfChangeRemoveNode:
if c.memb... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"ValidateConfigurationChange",
"(",
"cc",
"raftpb",
".",
"ConfChange",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
... | // ValidateConfigurationChange takes a proposed ConfChange and
// ensures that it is valid. | [
"ValidateConfigurationChange",
"takes",
"a",
"proposed",
"ConfChange",
"and",
"ensures",
"that",
"it",
"is",
"valid",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/membership/cluster.go#L185-L213 | train |
docker/swarmkit | manager/state/store/memory.go | Unlock | func (m *timedMutex) Unlock() {
unlockedTimestamp := m.lockedAt.Load()
m.lockedAt.Store(time.Time{})
m.Mutex.Unlock()
lockedFor := time.Since(unlockedTimestamp.(time.Time))
storeLockDurationTimer.Update(lockedFor)
} | go | func (m *timedMutex) Unlock() {
unlockedTimestamp := m.lockedAt.Load()
m.lockedAt.Store(time.Time{})
m.Mutex.Unlock()
lockedFor := time.Since(unlockedTimestamp.(time.Time))
storeLockDurationTimer.Update(lockedFor)
} | [
"func",
"(",
"m",
"*",
"timedMutex",
")",
"Unlock",
"(",
")",
"{",
"unlockedTimestamp",
":=",
"m",
".",
"lockedAt",
".",
"Load",
"(",
")",
"\n",
"m",
".",
"lockedAt",
".",
"Store",
"(",
"time",
".",
"Time",
"{",
"}",
")",
"\n",
"m",
".",
"Mutex",... | // Unlocks the timedMutex and captures the duration
// for which it was locked in a metric. | [
"Unlocks",
"the",
"timedMutex",
"and",
"captures",
"the",
"duration",
"for",
"which",
"it",
"was",
"locked",
"in",
"a",
"metric",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L130-L136 | train |
docker/swarmkit | manager/state/store/memory.go | NewMemoryStore | func NewMemoryStore(proposer state.Proposer) *MemoryStore {
memDB, err := memdb.NewMemDB(schema)
if err != nil {
// This shouldn't fail
panic(err)
}
return &MemoryStore{
memDB: memDB,
queue: watch.NewQueue(),
proposer: proposer,
}
} | go | func NewMemoryStore(proposer state.Proposer) *MemoryStore {
memDB, err := memdb.NewMemDB(schema)
if err != nil {
// This shouldn't fail
panic(err)
}
return &MemoryStore{
memDB: memDB,
queue: watch.NewQueue(),
proposer: proposer,
}
} | [
"func",
"NewMemoryStore",
"(",
"proposer",
"state",
".",
"Proposer",
")",
"*",
"MemoryStore",
"{",
"memDB",
",",
"err",
":=",
"memdb",
".",
"NewMemDB",
"(",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// This shouldn't fail",
"panic",
"(",
"err",
... | // NewMemoryStore returns an in-memory store. The argument is an optional
// Proposer which will be used to propagate changes to other members in a
// cluster. | [
"NewMemoryStore",
"returns",
"an",
"in",
"-",
"memory",
"store",
".",
"The",
"argument",
"is",
"an",
"optional",
"Proposer",
"which",
"will",
"be",
"used",
"to",
"propagate",
"changes",
"to",
"other",
"members",
"in",
"a",
"cluster",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L161-L173 | train |
docker/swarmkit | manager/state/store/memory.go | View | func (s *MemoryStore) View(cb func(ReadTx)) {
defer metrics.StartTimer(viewLatencyTimer)()
memDBTx := s.memDB.Txn(false)
readTx := readTx{
memDBTx: memDBTx,
}
cb(readTx)
memDBTx.Commit()
} | go | func (s *MemoryStore) View(cb func(ReadTx)) {
defer metrics.StartTimer(viewLatencyTimer)()
memDBTx := s.memDB.Txn(false)
readTx := readTx{
memDBTx: memDBTx,
}
cb(readTx)
memDBTx.Commit()
} | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"View",
"(",
"cb",
"func",
"(",
"ReadTx",
")",
")",
"{",
"defer",
"metrics",
".",
"StartTimer",
"(",
"viewLatencyTimer",
")",
"(",
")",
"\n",
"memDBTx",
":=",
"s",
".",
"memDB",
".",
"Txn",
"(",
"false",
"... | // View executes a read transaction. | [
"View",
"executes",
"a",
"read",
"transaction",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L222-L231 | train |
docker/swarmkit | manager/state/store/memory.go | changelistBetweenVersions | func (s *MemoryStore) changelistBetweenVersions(from, to api.Version) ([]api.Event, error) {
if s.proposer == nil {
return nil, errors.New("store does not support versioning")
}
changes, err := s.proposer.ChangesBetween(from, to)
if err != nil {
return nil, err
}
var changelist []api.Event
for _, change :=... | go | func (s *MemoryStore) changelistBetweenVersions(from, to api.Version) ([]api.Event, error) {
if s.proposer == nil {
return nil, errors.New("store does not support versioning")
}
changes, err := s.proposer.ChangesBetween(from, to)
if err != nil {
return nil, err
}
var changelist []api.Event
for _, change :=... | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"changelistBetweenVersions",
"(",
"from",
",",
"to",
"api",
".",
"Version",
")",
"(",
"[",
"]",
"api",
".",
"Event",
",",
"error",
")",
"{",
"if",
"s",
".",
"proposer",
"==",
"nil",
"{",
"return",
"nil",
"... | // changelistBetweenVersions returns the changes after "from" up to and
// including "to". | [
"changelistBetweenVersions",
"returns",
"the",
"changes",
"after",
"from",
"up",
"to",
"and",
"including",
"to",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L252-L275 | train |
docker/swarmkit | manager/state/store/memory.go | ApplyStoreActions | func (s *MemoryStore) ApplyStoreActions(actions []api.StoreAction) error {
s.updateLock.Lock()
memDBTx := s.memDB.Txn(true)
tx := tx{
readTx: readTx{
memDBTx: memDBTx,
},
}
for _, sa := range actions {
if err := applyStoreAction(&tx, sa); err != nil {
memDBTx.Abort()
s.updateLock.Unlock()
retur... | go | func (s *MemoryStore) ApplyStoreActions(actions []api.StoreAction) error {
s.updateLock.Lock()
memDBTx := s.memDB.Txn(true)
tx := tx{
readTx: readTx{
memDBTx: memDBTx,
},
}
for _, sa := range actions {
if err := applyStoreAction(&tx, sa); err != nil {
memDBTx.Abort()
s.updateLock.Unlock()
retur... | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"ApplyStoreActions",
"(",
"actions",
"[",
"]",
"api",
".",
"StoreAction",
")",
"error",
"{",
"s",
".",
"updateLock",
".",
"Lock",
"(",
")",
"\n",
"memDBTx",
":=",
"s",
".",
"memDB",
".",
"Txn",
"(",
"true",
... | // ApplyStoreActions updates a store based on StoreAction messages. | [
"ApplyStoreActions",
"updates",
"a",
"store",
"based",
"on",
"StoreAction",
"messages",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L278-L306 | train |
docker/swarmkit | manager/state/store/memory.go | Update | func (batch *Batch) Update(cb func(Tx) error) error {
if batch.err != nil {
return batch.err
}
if err := cb(&batch.tx); err != nil {
return err
}
batch.applied++
for batch.changelistLen < len(batch.tx.changelist) {
sa, err := api.NewStoreAction(batch.tx.changelist[batch.changelistLen])
if err != nil {
... | go | func (batch *Batch) Update(cb func(Tx) error) error {
if batch.err != nil {
return batch.err
}
if err := cb(&batch.tx); err != nil {
return err
}
batch.applied++
for batch.changelistLen < len(batch.tx.changelist) {
sa, err := api.NewStoreAction(batch.tx.changelist[batch.changelistLen])
if err != nil {
... | [
"func",
"(",
"batch",
"*",
"Batch",
")",
"Update",
"(",
"cb",
"func",
"(",
"Tx",
")",
"error",
")",
"error",
"{",
"if",
"batch",
".",
"err",
"!=",
"nil",
"{",
"return",
"batch",
".",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"cb",
"(",
"&",
... | // Update adds a single change to a batch. Each call to Update is atomic, but
// different calls to Update may be spread across multiple transactions to
// circumvent transaction size limits. | [
"Update",
"adds",
"a",
"single",
"change",
"to",
"a",
"batch",
".",
"Each",
"call",
"to",
"Update",
"is",
"atomic",
"but",
"different",
"calls",
"to",
"Update",
"may",
"be",
"spread",
"across",
"multiple",
"transactions",
"to",
"circumvent",
"transaction",
"... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L399-L433 | train |
docker/swarmkit | manager/state/store/memory.go | Batch | func (s *MemoryStore) Batch(cb func(*Batch) error) error {
defer metrics.StartTimer(batchLatencyTimer)()
s.updateLock.Lock()
batch := Batch{
store: s,
}
batch.newTx()
if err := cb(&batch); err != nil {
batch.tx.memDBTx.Abort()
s.updateLock.Unlock()
return err
}
err := batch.commit()
s.updateLock.Unl... | go | func (s *MemoryStore) Batch(cb func(*Batch) error) error {
defer metrics.StartTimer(batchLatencyTimer)()
s.updateLock.Lock()
batch := Batch{
store: s,
}
batch.newTx()
if err := cb(&batch); err != nil {
batch.tx.memDBTx.Abort()
s.updateLock.Unlock()
return err
}
err := batch.commit()
s.updateLock.Unl... | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"Batch",
"(",
"cb",
"func",
"(",
"*",
"Batch",
")",
"error",
")",
"error",
"{",
"defer",
"metrics",
".",
"StartTimer",
"(",
"batchLatencyTimer",
")",
"(",
")",
"\n",
"s",
".",
"updateLock",
".",
"Lock",
"(",... | // Batch performs one or more transactions that allow reads and writes
// It invokes a callback that is passed a Batch object. The callback may
// call batch.Update for each change it wants to make as part of the
// batch. The changes in the batch may be split over multiple
// transactions if necessary to keep transact... | [
"Batch",
"performs",
"one",
"or",
"more",
"transactions",
"that",
"allow",
"reads",
"and",
"writes",
"It",
"invokes",
"a",
"callback",
"that",
"is",
"passed",
"a",
"Batch",
"object",
".",
"The",
"callback",
"may",
"call",
"batch",
".",
"Update",
"for",
"ea... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L497-L515 | train |
docker/swarmkit | manager/state/store/memory.go | lookup | func (tx readTx) lookup(table, index, id string) api.StoreObject {
defer metrics.StartTimer(lookupLatencyTimer)()
j, err := tx.memDBTx.First(table, index, id)
if err != nil {
return nil
}
if j != nil {
return j.(api.StoreObject)
}
return nil
} | go | func (tx readTx) lookup(table, index, id string) api.StoreObject {
defer metrics.StartTimer(lookupLatencyTimer)()
j, err := tx.memDBTx.First(table, index, id)
if err != nil {
return nil
}
if j != nil {
return j.(api.StoreObject)
}
return nil
} | [
"func",
"(",
"tx",
"readTx",
")",
"lookup",
"(",
"table",
",",
"index",
",",
"id",
"string",
")",
"api",
".",
"StoreObject",
"{",
"defer",
"metrics",
".",
"StartTimer",
"(",
"lookupLatencyTimer",
")",
"(",
")",
"\n",
"j",
",",
"err",
":=",
"tx",
".",... | // lookup is an internal typed wrapper around memdb. | [
"lookup",
"is",
"an",
"internal",
"typed",
"wrapper",
"around",
"memdb",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L538-L548 | train |
docker/swarmkit | manager/state/store/memory.go | create | func (tx *tx) create(table string, o api.StoreObject) error {
if tx.lookup(table, indexID, o.GetID()) != nil {
return ErrExist
}
copy := o.CopyStoreObject()
meta := copy.GetMeta()
if err := touchMeta(&meta, tx.curVersion); err != nil {
return err
}
copy.SetMeta(meta)
err := tx.memDBTx.Insert(table, copy)
... | go | func (tx *tx) create(table string, o api.StoreObject) error {
if tx.lookup(table, indexID, o.GetID()) != nil {
return ErrExist
}
copy := o.CopyStoreObject()
meta := copy.GetMeta()
if err := touchMeta(&meta, tx.curVersion); err != nil {
return err
}
copy.SetMeta(meta)
err := tx.memDBTx.Insert(table, copy)
... | [
"func",
"(",
"tx",
"*",
"tx",
")",
"create",
"(",
"table",
"string",
",",
"o",
"api",
".",
"StoreObject",
")",
"error",
"{",
"if",
"tx",
".",
"lookup",
"(",
"table",
",",
"indexID",
",",
"o",
".",
"GetID",
"(",
")",
")",
"!=",
"nil",
"{",
"retu... | // create adds a new object to the store.
// Returns ErrExist if the ID is already taken. | [
"create",
"adds",
"a",
"new",
"object",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L552-L570 | train |
docker/swarmkit | manager/state/store/memory.go | update | func (tx *tx) update(table string, o api.StoreObject) error {
oldN := tx.lookup(table, indexID, o.GetID())
if oldN == nil {
return ErrNotExist
}
meta := o.GetMeta()
if tx.curVersion != nil {
if oldN.GetMeta().Version != meta.Version {
return ErrSequenceConflict
}
}
copy := o.CopyStoreObject()
if err... | go | func (tx *tx) update(table string, o api.StoreObject) error {
oldN := tx.lookup(table, indexID, o.GetID())
if oldN == nil {
return ErrNotExist
}
meta := o.GetMeta()
if tx.curVersion != nil {
if oldN.GetMeta().Version != meta.Version {
return ErrSequenceConflict
}
}
copy := o.CopyStoreObject()
if err... | [
"func",
"(",
"tx",
"*",
"tx",
")",
"update",
"(",
"table",
"string",
",",
"o",
"api",
".",
"StoreObject",
")",
"error",
"{",
"oldN",
":=",
"tx",
".",
"lookup",
"(",
"table",
",",
"indexID",
",",
"o",
".",
"GetID",
"(",
")",
")",
"\n",
"if",
"ol... | // Update updates an existing object in the store.
// Returns ErrNotExist if the object doesn't exist. | [
"Update",
"updates",
"an",
"existing",
"object",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"object",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L574-L600 | train |
docker/swarmkit | manager/state/store/memory.go | delete | func (tx *tx) delete(table, id string) error {
n := tx.lookup(table, indexID, id)
if n == nil {
return ErrNotExist
}
err := tx.memDBTx.Delete(table, n)
if err == nil {
tx.changelist = append(tx.changelist, n.EventDelete())
}
return err
} | go | func (tx *tx) delete(table, id string) error {
n := tx.lookup(table, indexID, id)
if n == nil {
return ErrNotExist
}
err := tx.memDBTx.Delete(table, n)
if err == nil {
tx.changelist = append(tx.changelist, n.EventDelete())
}
return err
} | [
"func",
"(",
"tx",
"*",
"tx",
")",
"delete",
"(",
"table",
",",
"id",
"string",
")",
"error",
"{",
"n",
":=",
"tx",
".",
"lookup",
"(",
"table",
",",
"indexID",
",",
"id",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"ErrNotExist",
"\n",
"... | // Delete removes an object from the store.
// Returns ErrNotExist if the object doesn't exist. | [
"Delete",
"removes",
"an",
"object",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"object",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L604-L615 | train |
docker/swarmkit | manager/state/store/memory.go | get | func (tx readTx) get(table, id string) api.StoreObject {
o := tx.lookup(table, indexID, id)
if o == nil {
return nil
}
return o.CopyStoreObject()
} | go | func (tx readTx) get(table, id string) api.StoreObject {
o := tx.lookup(table, indexID, id)
if o == nil {
return nil
}
return o.CopyStoreObject()
} | [
"func",
"(",
"tx",
"readTx",
")",
"get",
"(",
"table",
",",
"id",
"string",
")",
"api",
".",
"StoreObject",
"{",
"o",
":=",
"tx",
".",
"lookup",
"(",
"table",
",",
"indexID",
",",
"id",
")",
"\n",
"if",
"o",
"==",
"nil",
"{",
"return",
"nil",
"... | // Get looks up an object by ID.
// Returns nil if the object doesn't exist. | [
"Get",
"looks",
"up",
"an",
"object",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"object",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L619-L625 | train |
docker/swarmkit | manager/state/store/memory.go | find | func (tx readTx) find(table string, by By, checkType func(By) error, appendResult func(api.StoreObject)) error {
fromResultIterators := func(its ...memdb.ResultIterator) {
ids := make(map[string]struct{})
for _, it := range its {
for {
obj := it.Next()
if obj == nil {
break
}
o := obj.(api.... | go | func (tx readTx) find(table string, by By, checkType func(By) error, appendResult func(api.StoreObject)) error {
fromResultIterators := func(its ...memdb.ResultIterator) {
ids := make(map[string]struct{})
for _, it := range its {
for {
obj := it.Next()
if obj == nil {
break
}
o := obj.(api.... | [
"func",
"(",
"tx",
"readTx",
")",
"find",
"(",
"table",
"string",
",",
"by",
"By",
",",
"checkType",
"func",
"(",
"By",
")",
"error",
",",
"appendResult",
"func",
"(",
"api",
".",
"StoreObject",
")",
")",
"error",
"{",
"fromResultIterators",
":=",
"fun... | // find selects a set of objects calls a callback for each matching object. | [
"find",
"selects",
"a",
"set",
"of",
"objects",
"calls",
"a",
"callback",
"for",
"each",
"matching",
"object",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L775-L802 | train |
docker/swarmkit | manager/state/store/memory.go | Save | func (s *MemoryStore) Save(tx ReadTx) (*pb.StoreSnapshot, error) {
var snapshot pb.StoreSnapshot
for _, os := range objectStorers {
if err := os.Save(tx, &snapshot); err != nil {
return nil, err
}
}
return &snapshot, nil
} | go | func (s *MemoryStore) Save(tx ReadTx) (*pb.StoreSnapshot, error) {
var snapshot pb.StoreSnapshot
for _, os := range objectStorers {
if err := os.Save(tx, &snapshot); err != nil {
return nil, err
}
}
return &snapshot, nil
} | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"Save",
"(",
"tx",
"ReadTx",
")",
"(",
"*",
"pb",
".",
"StoreSnapshot",
",",
"error",
")",
"{",
"var",
"snapshot",
"pb",
".",
"StoreSnapshot",
"\n",
"for",
"_",
",",
"os",
":=",
"range",
"objectStorers",
"{"... | // Save serializes the data in the store. | [
"Save",
"serializes",
"the",
"data",
"in",
"the",
"store",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L805-L814 | train |
docker/swarmkit | manager/state/store/memory.go | Restore | func (s *MemoryStore) Restore(snapshot *pb.StoreSnapshot) error {
return s.updateLocal(func(tx Tx) error {
for _, os := range objectStorers {
if err := os.Restore(tx, snapshot); err != nil {
return err
}
}
return nil
})
} | go | func (s *MemoryStore) Restore(snapshot *pb.StoreSnapshot) error {
return s.updateLocal(func(tx Tx) error {
for _, os := range objectStorers {
if err := os.Restore(tx, snapshot); err != nil {
return err
}
}
return nil
})
} | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"Restore",
"(",
"snapshot",
"*",
"pb",
".",
"StoreSnapshot",
")",
"error",
"{",
"return",
"s",
".",
"updateLocal",
"(",
"func",
"(",
"tx",
"Tx",
")",
"error",
"{",
"for",
"_",
",",
"os",
":=",
"range",
"ob... | // Restore sets the contents of the store to the serialized data in the
// argument. | [
"Restore",
"sets",
"the",
"contents",
"of",
"the",
"store",
"to",
"the",
"serialized",
"data",
"in",
"the",
"argument",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L818-L827 | train |
docker/swarmkit | manager/state/store/memory.go | ViewAndWatch | func ViewAndWatch(store *MemoryStore, cb func(ReadTx) error, specifiers ...api.Event) (watch chan events.Event, cancel func(), err error) {
// Using Update to lock the store and guarantee consistency between
// the watcher and the the state seen by the callback. snapshotReadTx
// exposes this Tx as a ReadTx so the c... | go | func ViewAndWatch(store *MemoryStore, cb func(ReadTx) error, specifiers ...api.Event) (watch chan events.Event, cancel func(), err error) {
// Using Update to lock the store and guarantee consistency between
// the watcher and the the state seen by the callback. snapshotReadTx
// exposes this Tx as a ReadTx so the c... | [
"func",
"ViewAndWatch",
"(",
"store",
"*",
"MemoryStore",
",",
"cb",
"func",
"(",
"ReadTx",
")",
"error",
",",
"specifiers",
"...",
"api",
".",
"Event",
")",
"(",
"watch",
"chan",
"events",
".",
"Event",
",",
"cancel",
"func",
"(",
")",
",",
"err",
"... | // ViewAndWatch calls a callback which can observe the state of this
// MemoryStore. It also returns a channel that will return further events from
// this point so the snapshot can be kept up to date. The watch channel must be
// released with watch.StopWatch when it is no longer needed. The channel is
// guaranteed t... | [
"ViewAndWatch",
"calls",
"a",
"callback",
"which",
"can",
"observe",
"the",
"state",
"of",
"this",
"MemoryStore",
".",
"It",
"also",
"returns",
"a",
"channel",
"that",
"will",
"return",
"further",
"events",
"from",
"this",
"point",
"so",
"the",
"snapshot",
"... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L840-L857 | train |
docker/swarmkit | manager/state/store/memory.go | touchMeta | func touchMeta(meta *api.Meta, version *api.Version) error {
// Skip meta update if version is not defined as it means we're applying
// from raft or restoring from a snapshot.
if version == nil {
return nil
}
now, err := gogotypes.TimestampProto(time.Now())
if err != nil {
return err
}
meta.Version = *ve... | go | func touchMeta(meta *api.Meta, version *api.Version) error {
// Skip meta update if version is not defined as it means we're applying
// from raft or restoring from a snapshot.
if version == nil {
return nil
}
now, err := gogotypes.TimestampProto(time.Now())
if err != nil {
return err
}
meta.Version = *ve... | [
"func",
"touchMeta",
"(",
"meta",
"*",
"api",
".",
"Meta",
",",
"version",
"*",
"api",
".",
"Version",
")",
"error",
"{",
"// Skip meta update if version is not defined as it means we're applying",
"// from raft or restoring from a snapshot.",
"if",
"version",
"==",
"nil"... | // touchMeta updates an object's timestamps when necessary and bumps the version
// if provided. | [
"touchMeta",
"updates",
"an",
"object",
"s",
"timestamps",
"when",
"necessary",
"and",
"bumps",
"the",
"version",
"if",
"provided",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/memory.go#L946-L968 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.