repo
stringlengths 5
67
| path
stringlengths 4
218
| func_name
stringlengths 0
151
| original_string
stringlengths 52
373k
| language
stringclasses 6
values | code
stringlengths 52
373k
| code_tokens
listlengths 10
512
| docstring
stringlengths 3
47.2k
| docstring_tokens
listlengths 3
234
| sha
stringlengths 40
40
| url
stringlengths 85
339
| partition
stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
pachyderm/pachyderm
|
src/server/pkg/serviceenv/config.go
|
NewConfiguration
|
func NewConfiguration(config interface{}) *Configuration {
configuration := &Configuration{}
switch config.(type) {
case *GlobalConfiguration:
configuration.GlobalConfiguration = config.(*GlobalConfiguration)
return configuration
case *PachdFullConfiguration:
configuration.GlobalConfiguration = &config.(*PachdFullConfiguration).GlobalConfiguration
configuration.PachdSpecificConfiguration = &config.(*PachdFullConfiguration).PachdSpecificConfiguration
return configuration
case *WorkerFullConfiguration:
configuration.GlobalConfiguration = &config.(*WorkerFullConfiguration).GlobalConfiguration
configuration.WorkerSpecificConfiguration = &config.(*WorkerFullConfiguration).WorkerSpecificConfiguration
return configuration
default:
return nil
}
}
|
go
|
func NewConfiguration(config interface{}) *Configuration {
configuration := &Configuration{}
switch config.(type) {
case *GlobalConfiguration:
configuration.GlobalConfiguration = config.(*GlobalConfiguration)
return configuration
case *PachdFullConfiguration:
configuration.GlobalConfiguration = &config.(*PachdFullConfiguration).GlobalConfiguration
configuration.PachdSpecificConfiguration = &config.(*PachdFullConfiguration).PachdSpecificConfiguration
return configuration
case *WorkerFullConfiguration:
configuration.GlobalConfiguration = &config.(*WorkerFullConfiguration).GlobalConfiguration
configuration.WorkerSpecificConfiguration = &config.(*WorkerFullConfiguration).WorkerSpecificConfiguration
return configuration
default:
return nil
}
}
|
[
"func",
"NewConfiguration",
"(",
"config",
"interface",
"{",
"}",
")",
"*",
"Configuration",
"{",
"configuration",
":=",
"&",
"Configuration",
"{",
"}",
"\n",
"switch",
"config",
".",
"(",
"type",
")",
"{",
"case",
"*",
"GlobalConfiguration",
":",
"configuration",
".",
"GlobalConfiguration",
"=",
"config",
".",
"(",
"*",
"GlobalConfiguration",
")",
"\n",
"return",
"configuration",
"\n",
"case",
"*",
"PachdFullConfiguration",
":",
"configuration",
".",
"GlobalConfiguration",
"=",
"&",
"config",
".",
"(",
"*",
"PachdFullConfiguration",
")",
".",
"GlobalConfiguration",
"\n",
"configuration",
".",
"PachdSpecificConfiguration",
"=",
"&",
"config",
".",
"(",
"*",
"PachdFullConfiguration",
")",
".",
"PachdSpecificConfiguration",
"\n",
"return",
"configuration",
"\n",
"case",
"*",
"WorkerFullConfiguration",
":",
"configuration",
".",
"GlobalConfiguration",
"=",
"&",
"config",
".",
"(",
"*",
"WorkerFullConfiguration",
")",
".",
"GlobalConfiguration",
"\n",
"configuration",
".",
"WorkerSpecificConfiguration",
"=",
"&",
"config",
".",
"(",
"*",
"WorkerFullConfiguration",
")",
".",
"WorkerSpecificConfiguration",
"\n",
"return",
"configuration",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// NewConfiguration creates a generic configuration from a specific type of configuration.
|
[
"NewConfiguration",
"creates",
"a",
"generic",
"configuration",
"from",
"a",
"specific",
"type",
"of",
"configuration",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/serviceenv/config.go#L83-L100
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pfsdb/pfsdb.go
|
Repos
|
func Repos(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, reposPrefix),
nil,
&pfs.RepoInfo{},
nil,
nil,
)
}
|
go
|
func Repos(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, reposPrefix),
nil,
&pfs.RepoInfo{},
nil,
nil,
)
}
|
[
"func",
"Repos",
"(",
"etcdClient",
"*",
"etcd",
".",
"Client",
",",
"etcdPrefix",
"string",
")",
"col",
".",
"Collection",
"{",
"return",
"col",
".",
"NewCollection",
"(",
"etcdClient",
",",
"path",
".",
"Join",
"(",
"etcdPrefix",
",",
"reposPrefix",
")",
",",
"nil",
",",
"&",
"pfs",
".",
"RepoInfo",
"{",
"}",
",",
"nil",
",",
"nil",
",",
")",
"\n",
"}"
] |
// Repos returns a collection of repos
|
[
"Repos",
"returns",
"a",
"collection",
"of",
"repos"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pfsdb/pfsdb.go#L28-L37
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pfsdb/pfsdb.go
|
PutFileRecords
|
func PutFileRecords(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, putFileRecordsPrefix),
nil,
&pfs.PutFileRecords{},
nil,
nil,
)
}
|
go
|
func PutFileRecords(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, putFileRecordsPrefix),
nil,
&pfs.PutFileRecords{},
nil,
nil,
)
}
|
[
"func",
"PutFileRecords",
"(",
"etcdClient",
"*",
"etcd",
".",
"Client",
",",
"etcdPrefix",
"string",
")",
"col",
".",
"Collection",
"{",
"return",
"col",
".",
"NewCollection",
"(",
"etcdClient",
",",
"path",
".",
"Join",
"(",
"etcdPrefix",
",",
"putFileRecordsPrefix",
")",
",",
"nil",
",",
"&",
"pfs",
".",
"PutFileRecords",
"{",
"}",
",",
"nil",
",",
"nil",
",",
")",
"\n",
"}"
] |
// PutFileRecords returns a collection of putFileRecords
|
[
"PutFileRecords",
"returns",
"a",
"collection",
"of",
"putFileRecords"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pfsdb/pfsdb.go#L40-L49
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pfsdb/pfsdb.go
|
Commits
|
func Commits(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, commitsPrefix, repo),
[]*col.Index{ProvenanceIndex},
&pfs.CommitInfo{},
nil,
nil,
)
}
|
go
|
func Commits(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, commitsPrefix, repo),
[]*col.Index{ProvenanceIndex},
&pfs.CommitInfo{},
nil,
nil,
)
}
|
[
"func",
"Commits",
"(",
"etcdClient",
"*",
"etcd",
".",
"Client",
",",
"etcdPrefix",
"string",
",",
"repo",
"string",
")",
"col",
".",
"Collection",
"{",
"return",
"col",
".",
"NewCollection",
"(",
"etcdClient",
",",
"path",
".",
"Join",
"(",
"etcdPrefix",
",",
"commitsPrefix",
",",
"repo",
")",
",",
"[",
"]",
"*",
"col",
".",
"Index",
"{",
"ProvenanceIndex",
"}",
",",
"&",
"pfs",
".",
"CommitInfo",
"{",
"}",
",",
"nil",
",",
"nil",
",",
")",
"\n",
"}"
] |
// Commits returns a collection of commits
|
[
"Commits",
"returns",
"a",
"collection",
"of",
"commits"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pfsdb/pfsdb.go#L52-L61
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pfsdb/pfsdb.go
|
Branches
|
func Branches(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, branchesPrefix, repo),
nil,
&pfs.BranchInfo{},
func(key string) error {
if uuid.IsUUIDWithoutDashes(key) {
return fmt.Errorf("branch name cannot be a UUID V4")
}
return nil
},
nil,
)
}
|
go
|
func Branches(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, branchesPrefix, repo),
nil,
&pfs.BranchInfo{},
func(key string) error {
if uuid.IsUUIDWithoutDashes(key) {
return fmt.Errorf("branch name cannot be a UUID V4")
}
return nil
},
nil,
)
}
|
[
"func",
"Branches",
"(",
"etcdClient",
"*",
"etcd",
".",
"Client",
",",
"etcdPrefix",
"string",
",",
"repo",
"string",
")",
"col",
".",
"Collection",
"{",
"return",
"col",
".",
"NewCollection",
"(",
"etcdClient",
",",
"path",
".",
"Join",
"(",
"etcdPrefix",
",",
"branchesPrefix",
",",
"repo",
")",
",",
"nil",
",",
"&",
"pfs",
".",
"BranchInfo",
"{",
"}",
",",
"func",
"(",
"key",
"string",
")",
"error",
"{",
"if",
"uuid",
".",
"IsUUIDWithoutDashes",
"(",
"key",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"branch name cannot be a UUID V4\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
",",
"nil",
",",
")",
"\n",
"}"
] |
// Branches returns a collection of branches
|
[
"Branches",
"returns",
"a",
"collection",
"of",
"branches"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pfsdb/pfsdb.go#L64-L78
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pfsdb/pfsdb.go
|
OpenCommits
|
func OpenCommits(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, openCommitsPrefix),
nil,
&pfs.Commit{},
nil,
nil,
)
}
|
go
|
func OpenCommits(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, openCommitsPrefix),
nil,
&pfs.Commit{},
nil,
nil,
)
}
|
[
"func",
"OpenCommits",
"(",
"etcdClient",
"*",
"etcd",
".",
"Client",
",",
"etcdPrefix",
"string",
")",
"col",
".",
"Collection",
"{",
"return",
"col",
".",
"NewCollection",
"(",
"etcdClient",
",",
"path",
".",
"Join",
"(",
"etcdPrefix",
",",
"openCommitsPrefix",
")",
",",
"nil",
",",
"&",
"pfs",
".",
"Commit",
"{",
"}",
",",
"nil",
",",
"nil",
",",
")",
"\n",
"}"
] |
// OpenCommits returns a collection of open commits
|
[
"OpenCommits",
"returns",
"a",
"collection",
"of",
"open",
"commits"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pfsdb/pfsdb.go#L81-L90
|
test
|
pachyderm/pachyderm
|
src/server/pkg/dag/dag.go
|
NewDAG
|
func NewDAG(nodes map[string][]string) *DAG {
result := &DAG{
parents: make(map[string][]string),
children: make(map[string][]string),
leaves: make(map[string]bool),
}
for id, parents := range nodes {
result.NewNode(id, parents)
}
return result
}
|
go
|
func NewDAG(nodes map[string][]string) *DAG {
result := &DAG{
parents: make(map[string][]string),
children: make(map[string][]string),
leaves: make(map[string]bool),
}
for id, parents := range nodes {
result.NewNode(id, parents)
}
return result
}
|
[
"func",
"NewDAG",
"(",
"nodes",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"*",
"DAG",
"{",
"result",
":=",
"&",
"DAG",
"{",
"parents",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
",",
"children",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
",",
"leaves",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
",",
"}",
"\n",
"for",
"id",
",",
"parents",
":=",
"range",
"nodes",
"{",
"result",
".",
"NewNode",
"(",
"id",
",",
"parents",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] |
// NewDAG creates a DAG and populates it with the given nodes.
|
[
"NewDAG",
"creates",
"a",
"DAG",
"and",
"populates",
"it",
"with",
"the",
"given",
"nodes",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/dag/dag.go#L11-L21
|
test
|
pachyderm/pachyderm
|
src/server/pkg/dag/dag.go
|
NewNode
|
func (d *DAG) NewNode(id string, parents []string) {
d.parents[id] = parents
for _, parentID := range parents {
d.children[parentID] = append(d.children[parentID], id)
d.leaves[parentID] = false
}
if _, ok := d.leaves[id]; !ok {
d.leaves[id] = true
}
}
|
go
|
func (d *DAG) NewNode(id string, parents []string) {
d.parents[id] = parents
for _, parentID := range parents {
d.children[parentID] = append(d.children[parentID], id)
d.leaves[parentID] = false
}
if _, ok := d.leaves[id]; !ok {
d.leaves[id] = true
}
}
|
[
"func",
"(",
"d",
"*",
"DAG",
")",
"NewNode",
"(",
"id",
"string",
",",
"parents",
"[",
"]",
"string",
")",
"{",
"d",
".",
"parents",
"[",
"id",
"]",
"=",
"parents",
"\n",
"for",
"_",
",",
"parentID",
":=",
"range",
"parents",
"{",
"d",
".",
"children",
"[",
"parentID",
"]",
"=",
"append",
"(",
"d",
".",
"children",
"[",
"parentID",
"]",
",",
"id",
")",
"\n",
"d",
".",
"leaves",
"[",
"parentID",
"]",
"=",
"false",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"d",
".",
"leaves",
"[",
"id",
"]",
";",
"!",
"ok",
"{",
"d",
".",
"leaves",
"[",
"id",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}"
] |
// NewNode adds a node to d.
|
[
"NewNode",
"adds",
"a",
"node",
"to",
"d",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/dag/dag.go#L24-L33
|
test
|
pachyderm/pachyderm
|
src/server/pkg/dag/dag.go
|
Sorted
|
func (d *DAG) Sorted() []string {
seen := make(map[string]bool)
var result []string
for id := range d.parents {
result = append(result, dfs(id, d.parents, seen)...)
}
return result
}
|
go
|
func (d *DAG) Sorted() []string {
seen := make(map[string]bool)
var result []string
for id := range d.parents {
result = append(result, dfs(id, d.parents, seen)...)
}
return result
}
|
[
"func",
"(",
"d",
"*",
"DAG",
")",
"Sorted",
"(",
")",
"[",
"]",
"string",
"{",
"seen",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"var",
"result",
"[",
"]",
"string",
"\n",
"for",
"id",
":=",
"range",
"d",
".",
"parents",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"dfs",
"(",
"id",
",",
"d",
".",
"parents",
",",
"seen",
")",
"...",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] |
// Sorted returns all nodes in a topologically sorted order
|
[
"Sorted",
"returns",
"all",
"nodes",
"in",
"a",
"topologically",
"sorted",
"order"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/dag/dag.go#L36-L43
|
test
|
pachyderm/pachyderm
|
src/server/pkg/dag/dag.go
|
Leaves
|
func (d *DAG) Leaves() []string {
var result []string
for id, isLeaf := range d.leaves {
// isLeaf might be false, explicit mark nodes as non leaves
if isLeaf {
result = append(result, id)
}
}
return result
}
|
go
|
func (d *DAG) Leaves() []string {
var result []string
for id, isLeaf := range d.leaves {
// isLeaf might be false, explicit mark nodes as non leaves
if isLeaf {
result = append(result, id)
}
}
return result
}
|
[
"func",
"(",
"d",
"*",
"DAG",
")",
"Leaves",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"result",
"[",
"]",
"string",
"\n",
"for",
"id",
",",
"isLeaf",
":=",
"range",
"d",
".",
"leaves",
"{",
"if",
"isLeaf",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"id",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] |
// Leaves returns a slice containing all leaves in d.
|
[
"Leaves",
"returns",
"a",
"slice",
"containing",
"all",
"leaves",
"in",
"d",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/dag/dag.go#L46-L55
|
test
|
pachyderm/pachyderm
|
src/server/pkg/dag/dag.go
|
Ancestors
|
func (d *DAG) Ancestors(id string, from []string) []string {
seen := make(map[string]bool)
for _, fromID := range from {
seen[fromID] = true
}
return dfs(id, d.parents, seen)
}
|
go
|
func (d *DAG) Ancestors(id string, from []string) []string {
seen := make(map[string]bool)
for _, fromID := range from {
seen[fromID] = true
}
return dfs(id, d.parents, seen)
}
|
[
"func",
"(",
"d",
"*",
"DAG",
")",
"Ancestors",
"(",
"id",
"string",
",",
"from",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"seen",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"fromID",
":=",
"range",
"from",
"{",
"seen",
"[",
"fromID",
"]",
"=",
"true",
"\n",
"}",
"\n",
"return",
"dfs",
"(",
"id",
",",
"d",
".",
"parents",
",",
"seen",
")",
"\n",
"}"
] |
// Ancestors returns a slice containing all ancestors of a node, 'id',
// in d which are a descendant of at least one of the nodes in 'from'.
|
[
"Ancestors",
"returns",
"a",
"slice",
"containing",
"all",
"ancestors",
"of",
"a",
"node",
"id",
"in",
"d",
"which",
"are",
"a",
"descendant",
"of",
"at",
"least",
"one",
"of",
"the",
"nodes",
"in",
"from",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/dag/dag.go#L59-L65
|
test
|
pachyderm/pachyderm
|
src/server/pkg/dag/dag.go
|
Descendants
|
func (d *DAG) Descendants(id string, to []string) []string {
seen := make(map[string]bool)
for _, toID := range to {
seen[toID] = true
}
return bfs(id, d.children, seen)
}
|
go
|
func (d *DAG) Descendants(id string, to []string) []string {
seen := make(map[string]bool)
for _, toID := range to {
seen[toID] = true
}
return bfs(id, d.children, seen)
}
|
[
"func",
"(",
"d",
"*",
"DAG",
")",
"Descendants",
"(",
"id",
"string",
",",
"to",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"seen",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"toID",
":=",
"range",
"to",
"{",
"seen",
"[",
"toID",
"]",
"=",
"true",
"\n",
"}",
"\n",
"return",
"bfs",
"(",
"id",
",",
"d",
".",
"children",
",",
"seen",
")",
"\n",
"}"
] |
// Descendants returns a slice containing all descendants of a node, 'id',
// in d which are an ancestor of at least one of the nodes in 'to'.
|
[
"Descendants",
"returns",
"a",
"slice",
"containing",
"all",
"descendants",
"of",
"a",
"node",
"id",
"in",
"d",
"which",
"are",
"an",
"ancestor",
"of",
"at",
"least",
"one",
"of",
"the",
"nodes",
"in",
"to",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/dag/dag.go#L69-L75
|
test
|
pachyderm/pachyderm
|
src/server/pkg/dag/dag.go
|
Ghosts
|
func (d *DAG) Ghosts() []string {
var result []string
for id := range d.children {
if _, ok := d.parents[id]; !ok {
result = append(result, id)
}
}
return result
}
|
go
|
func (d *DAG) Ghosts() []string {
var result []string
for id := range d.children {
if _, ok := d.parents[id]; !ok {
result = append(result, id)
}
}
return result
}
|
[
"func",
"(",
"d",
"*",
"DAG",
")",
"Ghosts",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"result",
"[",
"]",
"string",
"\n",
"for",
"id",
":=",
"range",
"d",
".",
"children",
"{",
"if",
"_",
",",
"ok",
":=",
"d",
".",
"parents",
"[",
"id",
"]",
";",
"!",
"ok",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"id",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] |
// Ghosts returns nodes that were referenced as parents but never created.
|
[
"Ghosts",
"returns",
"nodes",
"that",
"were",
"referenced",
"as",
"parents",
"but",
"never",
"created",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/dag/dag.go#L78-L86
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
NewPortForwarder
|
func NewPortForwarder(namespace string) (*PortForwarder, error) {
if namespace == "" {
namespace = "default"
}
rules := clientcmd.NewDefaultClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides)
config, err := kubeConfig.ClientConfig()
if err != nil {
return nil, err
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
core := client.CoreV1()
return &PortForwarder{
core: core,
client: core.RESTClient(),
config: config,
namespace: namespace,
logger: log.StandardLogger().Writer(),
stopChansLock: &sync.Mutex{},
stopChans: []chan struct{}{},
shutdown: false,
}, nil
}
|
go
|
func NewPortForwarder(namespace string) (*PortForwarder, error) {
if namespace == "" {
namespace = "default"
}
rules := clientcmd.NewDefaultClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides)
config, err := kubeConfig.ClientConfig()
if err != nil {
return nil, err
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
core := client.CoreV1()
return &PortForwarder{
core: core,
client: core.RESTClient(),
config: config,
namespace: namespace,
logger: log.StandardLogger().Writer(),
stopChansLock: &sync.Mutex{},
stopChans: []chan struct{}{},
shutdown: false,
}, nil
}
|
[
"func",
"NewPortForwarder",
"(",
"namespace",
"string",
")",
"(",
"*",
"PortForwarder",
",",
"error",
")",
"{",
"if",
"namespace",
"==",
"\"\"",
"{",
"namespace",
"=",
"\"default\"",
"\n",
"}",
"\n",
"rules",
":=",
"clientcmd",
".",
"NewDefaultClientConfigLoadingRules",
"(",
")",
"\n",
"overrides",
":=",
"&",
"clientcmd",
".",
"ConfigOverrides",
"{",
"}",
"\n",
"kubeConfig",
":=",
"clientcmd",
".",
"NewNonInteractiveDeferredLoadingClientConfig",
"(",
"rules",
",",
"overrides",
")",
"\n",
"config",
",",
"err",
":=",
"kubeConfig",
".",
"ClientConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"client",
",",
"err",
":=",
"kubernetes",
".",
"NewForConfig",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"core",
":=",
"client",
".",
"CoreV1",
"(",
")",
"\n",
"return",
"&",
"PortForwarder",
"{",
"core",
":",
"core",
",",
"client",
":",
"core",
".",
"RESTClient",
"(",
")",
",",
"config",
":",
"config",
",",
"namespace",
":",
"namespace",
",",
"logger",
":",
"log",
".",
"StandardLogger",
"(",
")",
".",
"Writer",
"(",
")",
",",
"stopChansLock",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"stopChans",
":",
"[",
"]",
"chan",
"struct",
"{",
"}",
"{",
"}",
",",
"shutdown",
":",
"false",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewPortForwarder creates a new port forwarder
|
[
"NewPortForwarder",
"creates",
"a",
"new",
"port",
"forwarder"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L49-L79
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
Run
|
func (f *PortForwarder) Run(appName string, localPort, remotePort uint16) error {
podNameSelector := map[string]string{
"suite": "pachyderm",
"app": appName,
}
podList, err := f.core.Pods(f.namespace).List(metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(metav1.SetAsLabelSelector(podNameSelector)),
TypeMeta: metav1.TypeMeta{
Kind: "ListOptions",
APIVersion: "v1",
},
})
if err != nil {
return err
}
if len(podList.Items) == 0 {
return fmt.Errorf("No pods found for app %s", appName)
}
// Choose a random pod
podName := podList.Items[rand.Intn(len(podList.Items))].Name
url := f.client.Post().
Resource("pods").
Namespace(f.namespace).
Name(podName).
SubResource("portforward").
URL()
transport, upgrader, err := spdy.RoundTripperFor(f.config)
if err != nil {
return err
}
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", url)
ports := []string{fmt.Sprintf("%d:%d", localPort, remotePort)}
readyChan := make(chan struct{}, 1)
stopChan := make(chan struct{}, 1)
// Ensure that the port forwarder isn't already shutdown, and append the
// shutdown channel so this forwarder can be closed
f.stopChansLock.Lock()
if f.shutdown {
f.stopChansLock.Unlock()
return fmt.Errorf("port forwarder is shutdown")
}
f.stopChans = append(f.stopChans, stopChan)
f.stopChansLock.Unlock()
fw, err := portforward.New(dialer, ports, stopChan, readyChan, ioutil.Discard, f.logger)
if err != nil {
return err
}
errChan := make(chan error, 1)
go func() { errChan <- fw.ForwardPorts() }()
select {
case err = <-errChan:
return fmt.Errorf("port forwarding failed: %v", err)
case <-fw.Ready:
return nil
}
}
|
go
|
func (f *PortForwarder) Run(appName string, localPort, remotePort uint16) error {
podNameSelector := map[string]string{
"suite": "pachyderm",
"app": appName,
}
podList, err := f.core.Pods(f.namespace).List(metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(metav1.SetAsLabelSelector(podNameSelector)),
TypeMeta: metav1.TypeMeta{
Kind: "ListOptions",
APIVersion: "v1",
},
})
if err != nil {
return err
}
if len(podList.Items) == 0 {
return fmt.Errorf("No pods found for app %s", appName)
}
// Choose a random pod
podName := podList.Items[rand.Intn(len(podList.Items))].Name
url := f.client.Post().
Resource("pods").
Namespace(f.namespace).
Name(podName).
SubResource("portforward").
URL()
transport, upgrader, err := spdy.RoundTripperFor(f.config)
if err != nil {
return err
}
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, "POST", url)
ports := []string{fmt.Sprintf("%d:%d", localPort, remotePort)}
readyChan := make(chan struct{}, 1)
stopChan := make(chan struct{}, 1)
// Ensure that the port forwarder isn't already shutdown, and append the
// shutdown channel so this forwarder can be closed
f.stopChansLock.Lock()
if f.shutdown {
f.stopChansLock.Unlock()
return fmt.Errorf("port forwarder is shutdown")
}
f.stopChans = append(f.stopChans, stopChan)
f.stopChansLock.Unlock()
fw, err := portforward.New(dialer, ports, stopChan, readyChan, ioutil.Discard, f.logger)
if err != nil {
return err
}
errChan := make(chan error, 1)
go func() { errChan <- fw.ForwardPorts() }()
select {
case err = <-errChan:
return fmt.Errorf("port forwarding failed: %v", err)
case <-fw.Ready:
return nil
}
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"Run",
"(",
"appName",
"string",
",",
"localPort",
",",
"remotePort",
"uint16",
")",
"error",
"{",
"podNameSelector",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"suite\"",
":",
"\"pachyderm\"",
",",
"\"app\"",
":",
"appName",
",",
"}",
"\n",
"podList",
",",
"err",
":=",
"f",
".",
"core",
".",
"Pods",
"(",
"f",
".",
"namespace",
")",
".",
"List",
"(",
"metav1",
".",
"ListOptions",
"{",
"LabelSelector",
":",
"metav1",
".",
"FormatLabelSelector",
"(",
"metav1",
".",
"SetAsLabelSelector",
"(",
"podNameSelector",
")",
")",
",",
"TypeMeta",
":",
"metav1",
".",
"TypeMeta",
"{",
"Kind",
":",
"\"ListOptions\"",
",",
"APIVersion",
":",
"\"v1\"",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"podList",
".",
"Items",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"No pods found for app %s\"",
",",
"appName",
")",
"\n",
"}",
"\n",
"podName",
":=",
"podList",
".",
"Items",
"[",
"rand",
".",
"Intn",
"(",
"len",
"(",
"podList",
".",
"Items",
")",
")",
"]",
".",
"Name",
"\n",
"url",
":=",
"f",
".",
"client",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"\"pods\"",
")",
".",
"Namespace",
"(",
"f",
".",
"namespace",
")",
".",
"Name",
"(",
"podName",
")",
".",
"SubResource",
"(",
"\"portforward\"",
")",
".",
"URL",
"(",
")",
"\n",
"transport",
",",
"upgrader",
",",
"err",
":=",
"spdy",
".",
"RoundTripperFor",
"(",
"f",
".",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"dialer",
":=",
"spdy",
".",
"NewDialer",
"(",
"upgrader",
",",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"transport",
"}",
",",
"\"POST\"",
",",
"url",
")",
"\n",
"ports",
":=",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"%d:%d\"",
",",
"localPort",
",",
"remotePort",
")",
"}",
"\n",
"readyChan",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
"\n",
"stopChan",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
"\n",
"f",
".",
"stopChansLock",
".",
"Lock",
"(",
")",
"\n",
"if",
"f",
".",
"shutdown",
"{",
"f",
".",
"stopChansLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"port forwarder is shutdown\"",
")",
"\n",
"}",
"\n",
"f",
".",
"stopChans",
"=",
"append",
"(",
"f",
".",
"stopChans",
",",
"stopChan",
")",
"\n",
"f",
".",
"stopChansLock",
".",
"Unlock",
"(",
")",
"\n",
"fw",
",",
"err",
":=",
"portforward",
".",
"New",
"(",
"dialer",
",",
"ports",
",",
"stopChan",
",",
"readyChan",
",",
"ioutil",
".",
"Discard",
",",
"f",
".",
"logger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"errChan",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"errChan",
"<-",
"fw",
".",
"ForwardPorts",
"(",
")",
"}",
"(",
")",
"\n",
"select",
"{",
"case",
"err",
"=",
"<-",
"errChan",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"port forwarding failed: %v\"",
",",
"err",
")",
"\n",
"case",
"<-",
"fw",
".",
"Ready",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// Run starts the port forwarder. Returns after initialization is begun,
// returning any initialization errors.
|
[
"Run",
"starts",
"the",
"port",
"forwarder",
".",
"Returns",
"after",
"initialization",
"is",
"begun",
"returning",
"any",
"initialization",
"errors",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L83-L147
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
RunForDaemon
|
func (f *PortForwarder) RunForDaemon(localPort, remotePort uint16) error {
if localPort == 0 {
localPort = pachdLocalPort
}
if remotePort == 0 {
remotePort = pachdRemotePort
}
return f.Run("pachd", localPort, remotePort)
}
|
go
|
func (f *PortForwarder) RunForDaemon(localPort, remotePort uint16) error {
if localPort == 0 {
localPort = pachdLocalPort
}
if remotePort == 0 {
remotePort = pachdRemotePort
}
return f.Run("pachd", localPort, remotePort)
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"RunForDaemon",
"(",
"localPort",
",",
"remotePort",
"uint16",
")",
"error",
"{",
"if",
"localPort",
"==",
"0",
"{",
"localPort",
"=",
"pachdLocalPort",
"\n",
"}",
"\n",
"if",
"remotePort",
"==",
"0",
"{",
"remotePort",
"=",
"pachdRemotePort",
"\n",
"}",
"\n",
"return",
"f",
".",
"Run",
"(",
"\"pachd\"",
",",
"localPort",
",",
"remotePort",
")",
"\n",
"}"
] |
// RunForDaemon creates a port forwarder for the pachd daemon.
|
[
"RunForDaemon",
"creates",
"a",
"port",
"forwarder",
"for",
"the",
"pachd",
"daemon",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L150-L158
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
RunForSAMLACS
|
func (f *PortForwarder) RunForSAMLACS(localPort uint16) error {
if localPort == 0 {
localPort = samlAcsLocalPort
}
return f.Run("pachd", localPort, 654)
}
|
go
|
func (f *PortForwarder) RunForSAMLACS(localPort uint16) error {
if localPort == 0 {
localPort = samlAcsLocalPort
}
return f.Run("pachd", localPort, 654)
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"RunForSAMLACS",
"(",
"localPort",
"uint16",
")",
"error",
"{",
"if",
"localPort",
"==",
"0",
"{",
"localPort",
"=",
"samlAcsLocalPort",
"\n",
"}",
"\n",
"return",
"f",
".",
"Run",
"(",
"\"pachd\"",
",",
"localPort",
",",
"654",
")",
"\n",
"}"
] |
// RunForSAMLACS creates a port forwarder for SAML ACS.
|
[
"RunForSAMLACS",
"creates",
"a",
"port",
"forwarder",
"for",
"SAML",
"ACS",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L161-L166
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
RunForDashUI
|
func (f *PortForwarder) RunForDashUI(localPort uint16) error {
if localPort == 0 {
localPort = dashUILocalPort
}
return f.Run("dash", localPort, 8080)
}
|
go
|
func (f *PortForwarder) RunForDashUI(localPort uint16) error {
if localPort == 0 {
localPort = dashUILocalPort
}
return f.Run("dash", localPort, 8080)
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"RunForDashUI",
"(",
"localPort",
"uint16",
")",
"error",
"{",
"if",
"localPort",
"==",
"0",
"{",
"localPort",
"=",
"dashUILocalPort",
"\n",
"}",
"\n",
"return",
"f",
".",
"Run",
"(",
"\"dash\"",
",",
"localPort",
",",
"8080",
")",
"\n",
"}"
] |
// RunForDashUI creates a port forwarder for the dash UI.
|
[
"RunForDashUI",
"creates",
"a",
"port",
"forwarder",
"for",
"the",
"dash",
"UI",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L169-L174
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
RunForDashWebSocket
|
func (f *PortForwarder) RunForDashWebSocket(localPort uint16) error {
if localPort == 0 {
localPort = dashWebSocketLocalPort
}
return f.Run("dash", localPort, 8081)
}
|
go
|
func (f *PortForwarder) RunForDashWebSocket(localPort uint16) error {
if localPort == 0 {
localPort = dashWebSocketLocalPort
}
return f.Run("dash", localPort, 8081)
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"RunForDashWebSocket",
"(",
"localPort",
"uint16",
")",
"error",
"{",
"if",
"localPort",
"==",
"0",
"{",
"localPort",
"=",
"dashWebSocketLocalPort",
"\n",
"}",
"\n",
"return",
"f",
".",
"Run",
"(",
"\"dash\"",
",",
"localPort",
",",
"8081",
")",
"\n",
"}"
] |
// RunForDashWebSocket creates a port forwarder for the dash websocket.
|
[
"RunForDashWebSocket",
"creates",
"a",
"port",
"forwarder",
"for",
"the",
"dash",
"websocket",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L177-L182
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
RunForPFS
|
func (f *PortForwarder) RunForPFS(localPort uint16) error {
if localPort == 0 {
localPort = pfsLocalPort
}
return f.Run("pachd", localPort, 30652)
}
|
go
|
func (f *PortForwarder) RunForPFS(localPort uint16) error {
if localPort == 0 {
localPort = pfsLocalPort
}
return f.Run("pachd", localPort, 30652)
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"RunForPFS",
"(",
"localPort",
"uint16",
")",
"error",
"{",
"if",
"localPort",
"==",
"0",
"{",
"localPort",
"=",
"pfsLocalPort",
"\n",
"}",
"\n",
"return",
"f",
".",
"Run",
"(",
"\"pachd\"",
",",
"localPort",
",",
"30652",
")",
"\n",
"}"
] |
// RunForPFS creates a port forwarder for PFS over HTTP.
|
[
"RunForPFS",
"creates",
"a",
"port",
"forwarder",
"for",
"PFS",
"over",
"HTTP",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L185-L190
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
RunForS3Gateway
|
func (f *PortForwarder) RunForS3Gateway(localPort uint16) error {
if localPort == 0 {
localPort = s3gatewayLocalPort
}
return f.Run("pachd", localPort, 600)
}
|
go
|
func (f *PortForwarder) RunForS3Gateway(localPort uint16) error {
if localPort == 0 {
localPort = s3gatewayLocalPort
}
return f.Run("pachd", localPort, 600)
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"RunForS3Gateway",
"(",
"localPort",
"uint16",
")",
"error",
"{",
"if",
"localPort",
"==",
"0",
"{",
"localPort",
"=",
"s3gatewayLocalPort",
"\n",
"}",
"\n",
"return",
"f",
".",
"Run",
"(",
"\"pachd\"",
",",
"localPort",
",",
"600",
")",
"\n",
"}"
] |
// RunForS3Gateway creates a port forwarder for the s3gateway.
|
[
"RunForS3Gateway",
"creates",
"a",
"port",
"forwarder",
"for",
"the",
"s3gateway",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L193-L198
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
Lock
|
func (f *PortForwarder) Lock() error {
pidfile.SetPidfilePath(path.Join(os.Getenv("HOME"), ".pachyderm/port-forward.pid"))
return pidfile.Write()
}
|
go
|
func (f *PortForwarder) Lock() error {
pidfile.SetPidfilePath(path.Join(os.Getenv("HOME"), ".pachyderm/port-forward.pid"))
return pidfile.Write()
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"Lock",
"(",
")",
"error",
"{",
"pidfile",
".",
"SetPidfilePath",
"(",
"path",
".",
"Join",
"(",
"os",
".",
"Getenv",
"(",
"\"HOME\"",
")",
",",
"\".pachyderm/port-forward.pid\"",
")",
")",
"\n",
"return",
"pidfile",
".",
"Write",
"(",
")",
"\n",
"}"
] |
// Lock uses pidfiles to ensure that only one port forwarder is running across
// one or more `pachctl` instances
|
[
"Lock",
"uses",
"pidfiles",
"to",
"ensure",
"that",
"only",
"one",
"port",
"forwarder",
"is",
"running",
"across",
"one",
"or",
"more",
"pachctl",
"instances"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L202-L205
|
test
|
pachyderm/pachyderm
|
src/client/portforwarder.go
|
Close
|
func (f *PortForwarder) Close() {
defer f.logger.Close()
f.stopChansLock.Lock()
defer f.stopChansLock.Unlock()
if f.shutdown {
panic("port forwarder already shutdown")
}
f.shutdown = true
for _, stopChan := range f.stopChans {
close(stopChan)
}
}
|
go
|
func (f *PortForwarder) Close() {
defer f.logger.Close()
f.stopChansLock.Lock()
defer f.stopChansLock.Unlock()
if f.shutdown {
panic("port forwarder already shutdown")
}
f.shutdown = true
for _, stopChan := range f.stopChans {
close(stopChan)
}
}
|
[
"func",
"(",
"f",
"*",
"PortForwarder",
")",
"Close",
"(",
")",
"{",
"defer",
"f",
".",
"logger",
".",
"Close",
"(",
")",
"\n",
"f",
".",
"stopChansLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"f",
".",
"stopChansLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"f",
".",
"shutdown",
"{",
"panic",
"(",
"\"port forwarder already shutdown\"",
")",
"\n",
"}",
"\n",
"f",
".",
"shutdown",
"=",
"true",
"\n",
"for",
"_",
",",
"stopChan",
":=",
"range",
"f",
".",
"stopChans",
"{",
"close",
"(",
"stopChan",
")",
"\n",
"}",
"\n",
"}"
] |
// Close shuts down port forwarding.
|
[
"Close",
"shuts",
"down",
"port",
"forwarding",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/portforwarder.go#L208-L223
|
test
|
pachyderm/pachyderm
|
src/server/pkg/watch/watch.go
|
Unmarshal
|
func (e *Event) Unmarshal(key *string, val proto.Message) error {
if err := CheckType(e.Template, val); err != nil {
return err
}
*key = string(e.Key)
return proto.Unmarshal(e.Value, val)
}
|
go
|
func (e *Event) Unmarshal(key *string, val proto.Message) error {
if err := CheckType(e.Template, val); err != nil {
return err
}
*key = string(e.Key)
return proto.Unmarshal(e.Value, val)
}
|
[
"func",
"(",
"e",
"*",
"Event",
")",
"Unmarshal",
"(",
"key",
"*",
"string",
",",
"val",
"proto",
".",
"Message",
")",
"error",
"{",
"if",
"err",
":=",
"CheckType",
"(",
"e",
".",
"Template",
",",
"val",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"key",
"=",
"string",
"(",
"e",
".",
"Key",
")",
"\n",
"return",
"proto",
".",
"Unmarshal",
"(",
"e",
".",
"Value",
",",
"val",
")",
"\n",
"}"
] |
// Unmarshal unmarshals the item in an event into a protobuf message.
|
[
"Unmarshal",
"unmarshals",
"the",
"item",
"in",
"an",
"event",
"into",
"a",
"protobuf",
"message",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/watch/watch.go#L41-L47
|
test
|
pachyderm/pachyderm
|
src/server/pkg/watch/watch.go
|
UnmarshalPrev
|
func (e *Event) UnmarshalPrev(key *string, val proto.Message) error {
if err := CheckType(e.Template, val); err != nil {
return err
}
*key = string(e.PrevKey)
return proto.Unmarshal(e.PrevValue, val)
}
|
go
|
func (e *Event) UnmarshalPrev(key *string, val proto.Message) error {
if err := CheckType(e.Template, val); err != nil {
return err
}
*key = string(e.PrevKey)
return proto.Unmarshal(e.PrevValue, val)
}
|
[
"func",
"(",
"e",
"*",
"Event",
")",
"UnmarshalPrev",
"(",
"key",
"*",
"string",
",",
"val",
"proto",
".",
"Message",
")",
"error",
"{",
"if",
"err",
":=",
"CheckType",
"(",
"e",
".",
"Template",
",",
"val",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"key",
"=",
"string",
"(",
"e",
".",
"PrevKey",
")",
"\n",
"return",
"proto",
".",
"Unmarshal",
"(",
"e",
".",
"PrevValue",
",",
"val",
")",
"\n",
"}"
] |
// UnmarshalPrev unmarshals the prev item in an event into a protobuf
// message.
|
[
"UnmarshalPrev",
"unmarshals",
"the",
"prev",
"item",
"in",
"an",
"event",
"into",
"a",
"protobuf",
"message",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/watch/watch.go#L51-L57
|
test
|
pachyderm/pachyderm
|
src/server/pkg/watch/watch.go
|
MakeWatcher
|
func MakeWatcher(eventCh chan *Event, done chan struct{}) Watcher {
return &watcher{
eventCh: eventCh,
done: done,
}
}
|
go
|
func MakeWatcher(eventCh chan *Event, done chan struct{}) Watcher {
return &watcher{
eventCh: eventCh,
done: done,
}
}
|
[
"func",
"MakeWatcher",
"(",
"eventCh",
"chan",
"*",
"Event",
",",
"done",
"chan",
"struct",
"{",
"}",
")",
"Watcher",
"{",
"return",
"&",
"watcher",
"{",
"eventCh",
":",
"eventCh",
",",
"done",
":",
"done",
",",
"}",
"\n",
"}"
] |
// MakeWatcher returns a Watcher that uses the given event channel and done
// channel internally to deliver events and signal closure, respectively.
|
[
"MakeWatcher",
"returns",
"a",
"Watcher",
"that",
"uses",
"the",
"given",
"event",
"channel",
"and",
"done",
"channel",
"internally",
"to",
"deliver",
"events",
"and",
"signal",
"closure",
"respectively",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/watch/watch.go#L195-L200
|
test
|
pachyderm/pachyderm
|
src/server/pkg/watch/watch.go
|
CheckType
|
func CheckType(template proto.Message, val interface{}) error {
if template != nil {
valType, templateType := reflect.TypeOf(val), reflect.TypeOf(template)
if valType != templateType {
return fmt.Errorf("invalid type, got: %s, expected: %s", valType, templateType)
}
}
return nil
}
|
go
|
func CheckType(template proto.Message, val interface{}) error {
if template != nil {
valType, templateType := reflect.TypeOf(val), reflect.TypeOf(template)
if valType != templateType {
return fmt.Errorf("invalid type, got: %s, expected: %s", valType, templateType)
}
}
return nil
}
|
[
"func",
"CheckType",
"(",
"template",
"proto",
".",
"Message",
",",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"template",
"!=",
"nil",
"{",
"valType",
",",
"templateType",
":=",
"reflect",
".",
"TypeOf",
"(",
"val",
")",
",",
"reflect",
".",
"TypeOf",
"(",
"template",
")",
"\n",
"if",
"valType",
"!=",
"templateType",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"invalid type, got: %s, expected: %s\"",
",",
"valType",
",",
"templateType",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CheckType checks to make sure val has the same type as template, unless
// template is nil in which case it always returns nil.
|
[
"CheckType",
"checks",
"to",
"make",
"sure",
"val",
"has",
"the",
"same",
"type",
"as",
"template",
"unless",
"template",
"is",
"nil",
"in",
"which",
"case",
"it",
"always",
"returns",
"nil",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/watch/watch.go#L204-L212
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pool/pool.go
|
NewPool
|
func NewPool(kubeClient *kube.Clientset, namespace string, serviceName string, port int, queueSize int64, opts ...grpc.DialOption) (*Pool, error) {
endpointsInterface := kubeClient.CoreV1().Endpoints(namespace)
watch, err := endpointsInterface.Watch(metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(metav1.SetAsLabelSelector(
map[string]string{"app": serviceName},
)),
Watch: true,
})
if err != nil {
return nil, err
}
pool := &Pool{
port: port,
endpointsWatch: watch,
opts: opts,
done: make(chan struct{}),
queueSize: queueSize,
}
pool.connsCond = sync.NewCond(&pool.connsLock)
go pool.watchEndpoints()
return pool, nil
}
|
go
|
func NewPool(kubeClient *kube.Clientset, namespace string, serviceName string, port int, queueSize int64, opts ...grpc.DialOption) (*Pool, error) {
endpointsInterface := kubeClient.CoreV1().Endpoints(namespace)
watch, err := endpointsInterface.Watch(metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(metav1.SetAsLabelSelector(
map[string]string{"app": serviceName},
)),
Watch: true,
})
if err != nil {
return nil, err
}
pool := &Pool{
port: port,
endpointsWatch: watch,
opts: opts,
done: make(chan struct{}),
queueSize: queueSize,
}
pool.connsCond = sync.NewCond(&pool.connsLock)
go pool.watchEndpoints()
return pool, nil
}
|
[
"func",
"NewPool",
"(",
"kubeClient",
"*",
"kube",
".",
"Clientset",
",",
"namespace",
"string",
",",
"serviceName",
"string",
",",
"port",
"int",
",",
"queueSize",
"int64",
",",
"opts",
"...",
"grpc",
".",
"DialOption",
")",
"(",
"*",
"Pool",
",",
"error",
")",
"{",
"endpointsInterface",
":=",
"kubeClient",
".",
"CoreV1",
"(",
")",
".",
"Endpoints",
"(",
"namespace",
")",
"\n",
"watch",
",",
"err",
":=",
"endpointsInterface",
".",
"Watch",
"(",
"metav1",
".",
"ListOptions",
"{",
"LabelSelector",
":",
"metav1",
".",
"FormatLabelSelector",
"(",
"metav1",
".",
"SetAsLabelSelector",
"(",
"map",
"[",
"string",
"]",
"string",
"{",
"\"app\"",
":",
"serviceName",
"}",
",",
")",
")",
",",
"Watch",
":",
"true",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"pool",
":=",
"&",
"Pool",
"{",
"port",
":",
"port",
",",
"endpointsWatch",
":",
"watch",
",",
"opts",
":",
"opts",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"queueSize",
":",
"queueSize",
",",
"}",
"\n",
"pool",
".",
"connsCond",
"=",
"sync",
".",
"NewCond",
"(",
"&",
"pool",
".",
"connsLock",
")",
"\n",
"go",
"pool",
".",
"watchEndpoints",
"(",
")",
"\n",
"return",
"pool",
",",
"nil",
"\n",
"}"
] |
// NewPool creates a new connection pool with connections to pods in the
// given service.
|
[
"NewPool",
"creates",
"a",
"new",
"connection",
"pool",
"with",
"connections",
"to",
"pods",
"in",
"the",
"given",
"service",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pool/pool.go#L38-L61
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pool/pool.go
|
Do
|
func (p *Pool) Do(ctx context.Context, f func(cc *grpc.ClientConn) error) error {
var conn *connCount
if err := func() error {
p.connsLock.Lock()
defer p.connsLock.Unlock()
for {
for addr, mapConn := range p.conns {
if mapConn.cc == nil {
cc, err := grpc.DialContext(ctx, addr, p.opts...)
if err != nil {
return fmt.Errorf("failed to connect to %s: %+v", addr, err)
}
mapConn.cc = cc
conn = mapConn
// We break because this conn has a count of 0 which we know
// we're not beating
break
} else {
mapConnCount := atomic.LoadInt64(&mapConn.count)
if mapConnCount < p.queueSize && (conn == nil || mapConnCount < atomic.LoadInt64(&conn.count)) {
conn = mapConn
}
}
}
if conn == nil {
p.connsCond.Wait()
} else {
atomic.AddInt64(&conn.count, 1)
break
}
}
return nil
}(); err != nil {
return err
}
defer p.connsCond.Broadcast()
defer atomic.AddInt64(&conn.count, -1)
return f(conn.cc)
}
|
go
|
func (p *Pool) Do(ctx context.Context, f func(cc *grpc.ClientConn) error) error {
var conn *connCount
if err := func() error {
p.connsLock.Lock()
defer p.connsLock.Unlock()
for {
for addr, mapConn := range p.conns {
if mapConn.cc == nil {
cc, err := grpc.DialContext(ctx, addr, p.opts...)
if err != nil {
return fmt.Errorf("failed to connect to %s: %+v", addr, err)
}
mapConn.cc = cc
conn = mapConn
// We break because this conn has a count of 0 which we know
// we're not beating
break
} else {
mapConnCount := atomic.LoadInt64(&mapConn.count)
if mapConnCount < p.queueSize && (conn == nil || mapConnCount < atomic.LoadInt64(&conn.count)) {
conn = mapConn
}
}
}
if conn == nil {
p.connsCond.Wait()
} else {
atomic.AddInt64(&conn.count, 1)
break
}
}
return nil
}(); err != nil {
return err
}
defer p.connsCond.Broadcast()
defer atomic.AddInt64(&conn.count, -1)
return f(conn.cc)
}
|
[
"func",
"(",
"p",
"*",
"Pool",
")",
"Do",
"(",
"ctx",
"context",
".",
"Context",
",",
"f",
"func",
"(",
"cc",
"*",
"grpc",
".",
"ClientConn",
")",
"error",
")",
"error",
"{",
"var",
"conn",
"*",
"connCount",
"\n",
"if",
"err",
":=",
"func",
"(",
")",
"error",
"{",
"p",
".",
"connsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"connsLock",
".",
"Unlock",
"(",
")",
"\n",
"for",
"{",
"for",
"addr",
",",
"mapConn",
":=",
"range",
"p",
".",
"conns",
"{",
"if",
"mapConn",
".",
"cc",
"==",
"nil",
"{",
"cc",
",",
"err",
":=",
"grpc",
".",
"DialContext",
"(",
"ctx",
",",
"addr",
",",
"p",
".",
"opts",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to connect to %s: %+v\"",
",",
"addr",
",",
"err",
")",
"\n",
"}",
"\n",
"mapConn",
".",
"cc",
"=",
"cc",
"\n",
"conn",
"=",
"mapConn",
"\n",
"break",
"\n",
"}",
"else",
"{",
"mapConnCount",
":=",
"atomic",
".",
"LoadInt64",
"(",
"&",
"mapConn",
".",
"count",
")",
"\n",
"if",
"mapConnCount",
"<",
"p",
".",
"queueSize",
"&&",
"(",
"conn",
"==",
"nil",
"||",
"mapConnCount",
"<",
"atomic",
".",
"LoadInt64",
"(",
"&",
"conn",
".",
"count",
")",
")",
"{",
"conn",
"=",
"mapConn",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"conn",
"==",
"nil",
"{",
"p",
".",
"connsCond",
".",
"Wait",
"(",
")",
"\n",
"}",
"else",
"{",
"atomic",
".",
"AddInt64",
"(",
"&",
"conn",
".",
"count",
",",
"1",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"p",
".",
"connsCond",
".",
"Broadcast",
"(",
")",
"\n",
"defer",
"atomic",
".",
"AddInt64",
"(",
"&",
"conn",
".",
"count",
",",
"-",
"1",
")",
"\n",
"return",
"f",
"(",
"conn",
".",
"cc",
")",
"\n",
"}"
] |
// Do allows you to do something with a grpc.ClientConn.
// Errors returned from f will be returned by Do.
|
[
"Do",
"allows",
"you",
"to",
"do",
"something",
"with",
"a",
"grpc",
".",
"ClientConn",
".",
"Errors",
"returned",
"from",
"f",
"will",
"be",
"returned",
"by",
"Do",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pool/pool.go#L102-L140
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pool/pool.go
|
Close
|
func (p *Pool) Close() error {
close(p.done)
var retErr error
for _, conn := range p.conns {
if conn.cc != nil {
if err := conn.cc.Close(); err != nil {
retErr = err
}
}
}
return retErr
}
|
go
|
func (p *Pool) Close() error {
close(p.done)
var retErr error
for _, conn := range p.conns {
if conn.cc != nil {
if err := conn.cc.Close(); err != nil {
retErr = err
}
}
}
return retErr
}
|
[
"func",
"(",
"p",
"*",
"Pool",
")",
"Close",
"(",
")",
"error",
"{",
"close",
"(",
"p",
".",
"done",
")",
"\n",
"var",
"retErr",
"error",
"\n",
"for",
"_",
",",
"conn",
":=",
"range",
"p",
".",
"conns",
"{",
"if",
"conn",
".",
"cc",
"!=",
"nil",
"{",
"if",
"err",
":=",
"conn",
".",
"cc",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"retErr",
"=",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"retErr",
"\n",
"}"
] |
// Close closes all connections stored in the pool, it returns an error if any
// of the calls to Close error.
|
[
"Close",
"closes",
"all",
"connections",
"stored",
"in",
"the",
"pool",
"it",
"returns",
"an",
"error",
"if",
"any",
"of",
"the",
"calls",
"to",
"Close",
"error",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pool/pool.go#L144-L155
|
test
|
pachyderm/pachyderm
|
src/server/pps/cmds/cmds.go
|
buildImage
|
func buildImage(client *docker.Client, repo string, contextDir string, dockerfile string, destTag string) error {
destImage := fmt.Sprintf("%s:%s", repo, destTag)
fmt.Printf("Building %s, this may take a while.\n", destImage)
err := client.BuildImage(docker.BuildImageOptions{
Name: destImage,
ContextDir: contextDir,
Dockerfile: dockerfile,
OutputStream: os.Stdout,
})
if err != nil {
return fmt.Errorf("could not build docker image: %s", err)
}
return nil
}
|
go
|
func buildImage(client *docker.Client, repo string, contextDir string, dockerfile string, destTag string) error {
destImage := fmt.Sprintf("%s:%s", repo, destTag)
fmt.Printf("Building %s, this may take a while.\n", destImage)
err := client.BuildImage(docker.BuildImageOptions{
Name: destImage,
ContextDir: contextDir,
Dockerfile: dockerfile,
OutputStream: os.Stdout,
})
if err != nil {
return fmt.Errorf("could not build docker image: %s", err)
}
return nil
}
|
[
"func",
"buildImage",
"(",
"client",
"*",
"docker",
".",
"Client",
",",
"repo",
"string",
",",
"contextDir",
"string",
",",
"dockerfile",
"string",
",",
"destTag",
"string",
")",
"error",
"{",
"destImage",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%s:%s\"",
",",
"repo",
",",
"destTag",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"Building %s, this may take a while.\\n\"",
",",
"\\n",
")",
"\n",
"destImage",
"\n",
"err",
":=",
"client",
".",
"BuildImage",
"(",
"docker",
".",
"BuildImageOptions",
"{",
"Name",
":",
"destImage",
",",
"ContextDir",
":",
"contextDir",
",",
"Dockerfile",
":",
"dockerfile",
",",
"OutputStream",
":",
"os",
".",
"Stdout",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"could not build docker image: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// buildImage builds a new docker image.
|
[
"buildImage",
"builds",
"a",
"new",
"docker",
"image",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pps/cmds/cmds.go#L898-L915
|
test
|
pachyderm/pachyderm
|
src/server/pps/cmds/cmds.go
|
pushImage
|
func pushImage(client *docker.Client, authConfig docker.AuthConfiguration, repo string, sourceTag string, destTag string) (string, error) {
sourceImage := fmt.Sprintf("%s:%s", repo, sourceTag)
destImage := fmt.Sprintf("%s:%s", repo, destTag)
fmt.Printf("Tagging/pushing %s, this may take a while.\n", destImage)
if err := client.TagImage(sourceImage, docker.TagImageOptions{
Repo: repo,
Tag: destTag,
Context: context.Background(),
}); err != nil {
err = fmt.Errorf("could not tag docker image: %s", err)
return "", err
}
if err := client.PushImage(
docker.PushImageOptions{
Name: repo,
Tag: destTag,
},
authConfig,
); err != nil {
err = fmt.Errorf("could not push docker image: %s", err)
return "", err
}
return destImage, nil
}
|
go
|
func pushImage(client *docker.Client, authConfig docker.AuthConfiguration, repo string, sourceTag string, destTag string) (string, error) {
sourceImage := fmt.Sprintf("%s:%s", repo, sourceTag)
destImage := fmt.Sprintf("%s:%s", repo, destTag)
fmt.Printf("Tagging/pushing %s, this may take a while.\n", destImage)
if err := client.TagImage(sourceImage, docker.TagImageOptions{
Repo: repo,
Tag: destTag,
Context: context.Background(),
}); err != nil {
err = fmt.Errorf("could not tag docker image: %s", err)
return "", err
}
if err := client.PushImage(
docker.PushImageOptions{
Name: repo,
Tag: destTag,
},
authConfig,
); err != nil {
err = fmt.Errorf("could not push docker image: %s", err)
return "", err
}
return destImage, nil
}
|
[
"func",
"pushImage",
"(",
"client",
"*",
"docker",
".",
"Client",
",",
"authConfig",
"docker",
".",
"AuthConfiguration",
",",
"repo",
"string",
",",
"sourceTag",
"string",
",",
"destTag",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"sourceImage",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%s:%s\"",
",",
"repo",
",",
"sourceTag",
")",
"\n",
"destImage",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%s:%s\"",
",",
"repo",
",",
"destTag",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"Tagging/pushing %s, this may take a while.\\n\"",
",",
"\\n",
")",
"\n",
"destImage",
"\n",
"if",
"err",
":=",
"client",
".",
"TagImage",
"(",
"sourceImage",
",",
"docker",
".",
"TagImageOptions",
"{",
"Repo",
":",
"repo",
",",
"Tag",
":",
"destTag",
",",
"Context",
":",
"context",
".",
"Background",
"(",
")",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"could not tag docker image: %s\"",
",",
"err",
")",
"\n",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"client",
".",
"PushImage",
"(",
"docker",
".",
"PushImageOptions",
"{",
"Name",
":",
"repo",
",",
"Tag",
":",
"destTag",
",",
"}",
",",
"authConfig",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"could not push docker image: %s\"",
",",
"err",
")",
"\n",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"}"
] |
// pushImage pushes a docker image.
|
[
"pushImage",
"pushes",
"a",
"docker",
"image",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pps/cmds/cmds.go#L918-L945
|
test
|
pachyderm/pachyderm
|
src/server/pkg/obj/minio_client.go
|
newMinioClient
|
func newMinioClient(endpoint, bucket, id, secret string, secure bool) (*minioClient, error) {
mclient, err := minio.New(endpoint, id, secret, secure)
if err != nil {
return nil, err
}
return &minioClient{
bucket: bucket,
Client: mclient,
}, nil
}
|
go
|
func newMinioClient(endpoint, bucket, id, secret string, secure bool) (*minioClient, error) {
mclient, err := minio.New(endpoint, id, secret, secure)
if err != nil {
return nil, err
}
return &minioClient{
bucket: bucket,
Client: mclient,
}, nil
}
|
[
"func",
"newMinioClient",
"(",
"endpoint",
",",
"bucket",
",",
"id",
",",
"secret",
"string",
",",
"secure",
"bool",
")",
"(",
"*",
"minioClient",
",",
"error",
")",
"{",
"mclient",
",",
"err",
":=",
"minio",
".",
"New",
"(",
"endpoint",
",",
"id",
",",
"secret",
",",
"secure",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"minioClient",
"{",
"bucket",
":",
"bucket",
",",
"Client",
":",
"mclient",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// Creates a new minioClient structure and returns
|
[
"Creates",
"a",
"new",
"minioClient",
"structure",
"and",
"returns"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/obj/minio_client.go#L19-L28
|
test
|
pachyderm/pachyderm
|
src/server/pkg/obj/minio_client.go
|
newMinioClientV2
|
func newMinioClientV2(endpoint, bucket, id, secret string, secure bool) (*minioClient, error) {
mclient, err := minio.NewV2(endpoint, id, secret, secure)
if err != nil {
return nil, err
}
return &minioClient{
bucket: bucket,
Client: mclient,
}, nil
}
|
go
|
func newMinioClientV2(endpoint, bucket, id, secret string, secure bool) (*minioClient, error) {
mclient, err := minio.NewV2(endpoint, id, secret, secure)
if err != nil {
return nil, err
}
return &minioClient{
bucket: bucket,
Client: mclient,
}, nil
}
|
[
"func",
"newMinioClientV2",
"(",
"endpoint",
",",
"bucket",
",",
"id",
",",
"secret",
"string",
",",
"secure",
"bool",
")",
"(",
"*",
"minioClient",
",",
"error",
")",
"{",
"mclient",
",",
"err",
":=",
"minio",
".",
"NewV2",
"(",
"endpoint",
",",
"id",
",",
"secret",
",",
"secure",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"minioClient",
"{",
"bucket",
":",
"bucket",
",",
"Client",
":",
"mclient",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// Creates a new minioClient S3V2 structure and returns
|
[
"Creates",
"a",
"new",
"minioClient",
"S3V2",
"structure",
"and",
"returns"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/obj/minio_client.go#L31-L40
|
test
|
pachyderm/pachyderm
|
src/server/pkg/obj/minio_client.go
|
newMinioWriter
|
func newMinioWriter(ctx context.Context, client *minioClient, name string) *minioWriter {
reader, writer := io.Pipe()
w := &minioWriter{
ctx: ctx,
errChan: make(chan error),
pipe: writer,
}
go func() {
_, err := client.PutObject(client.bucket, name, reader, "application/octet-stream")
if err != nil {
reader.CloseWithError(err)
}
w.errChan <- err
}()
return w
}
|
go
|
func newMinioWriter(ctx context.Context, client *minioClient, name string) *minioWriter {
reader, writer := io.Pipe()
w := &minioWriter{
ctx: ctx,
errChan: make(chan error),
pipe: writer,
}
go func() {
_, err := client.PutObject(client.bucket, name, reader, "application/octet-stream")
if err != nil {
reader.CloseWithError(err)
}
w.errChan <- err
}()
return w
}
|
[
"func",
"newMinioWriter",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"minioClient",
",",
"name",
"string",
")",
"*",
"minioWriter",
"{",
"reader",
",",
"writer",
":=",
"io",
".",
"Pipe",
"(",
")",
"\n",
"w",
":=",
"&",
"minioWriter",
"{",
"ctx",
":",
"ctx",
",",
"errChan",
":",
"make",
"(",
"chan",
"error",
")",
",",
"pipe",
":",
"writer",
",",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"_",
",",
"err",
":=",
"client",
".",
"PutObject",
"(",
"client",
".",
"bucket",
",",
"name",
",",
"reader",
",",
"\"application/octet-stream\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"reader",
".",
"CloseWithError",
"(",
"err",
")",
"\n",
"}",
"\n",
"w",
".",
"errChan",
"<-",
"err",
"\n",
"}",
"(",
")",
"\n",
"return",
"w",
"\n",
"}"
] |
// Creates a new minio writer and a go routine to upload objects to minio server
|
[
"Creates",
"a",
"new",
"minio",
"writer",
"and",
"a",
"go",
"routine",
"to",
"upload",
"objects",
"to",
"minio",
"server"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/obj/minio_client.go#L50-L65
|
test
|
pachyderm/pachyderm
|
src/server/pkg/obj/minio_client.go
|
Close
|
func (w *minioWriter) Close() error {
span, _ := tracing.AddSpanToAnyExisting(w.ctx, "minioWriter.Close")
defer tracing.FinishAnySpan(span)
if err := w.pipe.Close(); err != nil {
return err
}
return <-w.errChan
}
|
go
|
func (w *minioWriter) Close() error {
span, _ := tracing.AddSpanToAnyExisting(w.ctx, "minioWriter.Close")
defer tracing.FinishAnySpan(span)
if err := w.pipe.Close(); err != nil {
return err
}
return <-w.errChan
}
|
[
"func",
"(",
"w",
"*",
"minioWriter",
")",
"Close",
"(",
")",
"error",
"{",
"span",
",",
"_",
":=",
"tracing",
".",
"AddSpanToAnyExisting",
"(",
"w",
".",
"ctx",
",",
"\"minioWriter.Close\"",
")",
"\n",
"defer",
"tracing",
".",
"FinishAnySpan",
"(",
"span",
")",
"\n",
"if",
"err",
":=",
"w",
".",
"pipe",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"<-",
"w",
".",
"errChan",
"\n",
"}"
] |
// This will block till upload is done
|
[
"This",
"will",
"block",
"till",
"upload",
"is",
"done"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/obj/minio_client.go#L74-L81
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
PipelineRepo
|
func PipelineRepo(pipeline *ppsclient.Pipeline) *pfs.Repo {
return &pfs.Repo{Name: pipeline.Name}
}
|
go
|
func PipelineRepo(pipeline *ppsclient.Pipeline) *pfs.Repo {
return &pfs.Repo{Name: pipeline.Name}
}
|
[
"func",
"PipelineRepo",
"(",
"pipeline",
"*",
"ppsclient",
".",
"Pipeline",
")",
"*",
"pfs",
".",
"Repo",
"{",
"return",
"&",
"pfs",
".",
"Repo",
"{",
"Name",
":",
"pipeline",
".",
"Name",
"}",
"\n",
"}"
] |
// PipelineRepo creates a pfs repo for a given pipeline.
|
[
"PipelineRepo",
"creates",
"a",
"pfs",
"repo",
"for",
"a",
"given",
"pipeline",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L51-L53
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
PipelineRcName
|
func PipelineRcName(name string, version uint64) string {
// k8s won't allow RC names that contain upper-case letters
// or underscores
// TODO: deal with name collision
name = strings.Replace(name, "_", "-", -1)
return fmt.Sprintf("pipeline-%s-v%d", strings.ToLower(name), version)
}
|
go
|
func PipelineRcName(name string, version uint64) string {
// k8s won't allow RC names that contain upper-case letters
// or underscores
// TODO: deal with name collision
name = strings.Replace(name, "_", "-", -1)
return fmt.Sprintf("pipeline-%s-v%d", strings.ToLower(name), version)
}
|
[
"func",
"PipelineRcName",
"(",
"name",
"string",
",",
"version",
"uint64",
")",
"string",
"{",
"name",
"=",
"strings",
".",
"Replace",
"(",
"name",
",",
"\"_\"",
",",
"\"-\"",
",",
"-",
"1",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"pipeline-%s-v%d\"",
",",
"strings",
".",
"ToLower",
"(",
"name",
")",
",",
"version",
")",
"\n",
"}"
] |
// PipelineRcName generates the name of the k8s replication controller that
// manages a pipeline's workers
|
[
"PipelineRcName",
"generates",
"the",
"name",
"of",
"the",
"k8s",
"replication",
"controller",
"that",
"manages",
"a",
"pipeline",
"s",
"workers"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L57-L63
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
GetRequestsResourceListFromPipeline
|
func GetRequestsResourceListFromPipeline(pipelineInfo *pps.PipelineInfo) (*v1.ResourceList, error) {
return getResourceListFromSpec(pipelineInfo.ResourceRequests, pipelineInfo.CacheSize)
}
|
go
|
func GetRequestsResourceListFromPipeline(pipelineInfo *pps.PipelineInfo) (*v1.ResourceList, error) {
return getResourceListFromSpec(pipelineInfo.ResourceRequests, pipelineInfo.CacheSize)
}
|
[
"func",
"GetRequestsResourceListFromPipeline",
"(",
"pipelineInfo",
"*",
"pps",
".",
"PipelineInfo",
")",
"(",
"*",
"v1",
".",
"ResourceList",
",",
"error",
")",
"{",
"return",
"getResourceListFromSpec",
"(",
"pipelineInfo",
".",
"ResourceRequests",
",",
"pipelineInfo",
".",
"CacheSize",
")",
"\n",
"}"
] |
// GetRequestsResourceListFromPipeline returns a list of resources that the pipeline,
// minimally requires.
|
[
"GetRequestsResourceListFromPipeline",
"returns",
"a",
"list",
"of",
"resources",
"that",
"the",
"pipeline",
"minimally",
"requires",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L67-L69
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
GetLimitsResourceListFromPipeline
|
func GetLimitsResourceListFromPipeline(pipelineInfo *pps.PipelineInfo) (*v1.ResourceList, error) {
return getResourceListFromSpec(pipelineInfo.ResourceLimits, pipelineInfo.CacheSize)
}
|
go
|
func GetLimitsResourceListFromPipeline(pipelineInfo *pps.PipelineInfo) (*v1.ResourceList, error) {
return getResourceListFromSpec(pipelineInfo.ResourceLimits, pipelineInfo.CacheSize)
}
|
[
"func",
"GetLimitsResourceListFromPipeline",
"(",
"pipelineInfo",
"*",
"pps",
".",
"PipelineInfo",
")",
"(",
"*",
"v1",
".",
"ResourceList",
",",
"error",
")",
"{",
"return",
"getResourceListFromSpec",
"(",
"pipelineInfo",
".",
"ResourceLimits",
",",
"pipelineInfo",
".",
"CacheSize",
")",
"\n",
"}"
] |
// GetLimitsResourceListFromPipeline returns a list of resources that the pipeline,
// maximally is limited to.
|
[
"GetLimitsResourceListFromPipeline",
"returns",
"a",
"list",
"of",
"resources",
"that",
"the",
"pipeline",
"maximally",
"is",
"limited",
"to",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L121-L123
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
getNumNodes
|
func getNumNodes(kubeClient *kube.Clientset) (int, error) {
nodeList, err := kubeClient.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return 0, fmt.Errorf("unable to retrieve node list from k8s to determine parallelism: %v", err)
}
if len(nodeList.Items) == 0 {
return 0, fmt.Errorf("pachyderm.pps.jobserver: no k8s nodes found")
}
return len(nodeList.Items), nil
}
|
go
|
func getNumNodes(kubeClient *kube.Clientset) (int, error) {
nodeList, err := kubeClient.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return 0, fmt.Errorf("unable to retrieve node list from k8s to determine parallelism: %v", err)
}
if len(nodeList.Items) == 0 {
return 0, fmt.Errorf("pachyderm.pps.jobserver: no k8s nodes found")
}
return len(nodeList.Items), nil
}
|
[
"func",
"getNumNodes",
"(",
"kubeClient",
"*",
"kube",
".",
"Clientset",
")",
"(",
"int",
",",
"error",
")",
"{",
"nodeList",
",",
"err",
":=",
"kubeClient",
".",
"CoreV1",
"(",
")",
".",
"Nodes",
"(",
")",
".",
"List",
"(",
"metav1",
".",
"ListOptions",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"unable to retrieve node list from k8s to determine parallelism: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"nodeList",
".",
"Items",
")",
"==",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"pachyderm.pps.jobserver: no k8s nodes found\"",
")",
"\n",
"}",
"\n",
"return",
"len",
"(",
"nodeList",
".",
"Items",
")",
",",
"nil",
"\n",
"}"
] |
// getNumNodes attempts to retrieve the number of nodes in the current k8s
// cluster
|
[
"getNumNodes",
"attempts",
"to",
"retrieve",
"the",
"number",
"of",
"nodes",
"in",
"the",
"current",
"k8s",
"cluster"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L127-L136
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
GetExpectedNumWorkers
|
func GetExpectedNumWorkers(kubeClient *kube.Clientset, spec *ppsclient.ParallelismSpec) (int, error) {
if spec == nil || (spec.Constant == 0 && spec.Coefficient == 0) {
return 1, nil
} else if spec.Constant > 0 && spec.Coefficient == 0 {
return int(spec.Constant), nil
} else if spec.Constant == 0 && spec.Coefficient > 0 {
// Start ('coefficient' * 'nodes') workers. Determine number of workers
numNodes, err := getNumNodes(kubeClient)
if err != nil {
return 0, err
}
result := math.Floor(spec.Coefficient * float64(numNodes))
return int(math.Max(result, 1)), nil
}
return 0, fmt.Errorf("Unable to interpret ParallelismSpec %+v", spec)
}
|
go
|
func GetExpectedNumWorkers(kubeClient *kube.Clientset, spec *ppsclient.ParallelismSpec) (int, error) {
if spec == nil || (spec.Constant == 0 && spec.Coefficient == 0) {
return 1, nil
} else if spec.Constant > 0 && spec.Coefficient == 0 {
return int(spec.Constant), nil
} else if spec.Constant == 0 && spec.Coefficient > 0 {
// Start ('coefficient' * 'nodes') workers. Determine number of workers
numNodes, err := getNumNodes(kubeClient)
if err != nil {
return 0, err
}
result := math.Floor(spec.Coefficient * float64(numNodes))
return int(math.Max(result, 1)), nil
}
return 0, fmt.Errorf("Unable to interpret ParallelismSpec %+v", spec)
}
|
[
"func",
"GetExpectedNumWorkers",
"(",
"kubeClient",
"*",
"kube",
".",
"Clientset",
",",
"spec",
"*",
"ppsclient",
".",
"ParallelismSpec",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"spec",
"==",
"nil",
"||",
"(",
"spec",
".",
"Constant",
"==",
"0",
"&&",
"spec",
".",
"Coefficient",
"==",
"0",
")",
"{",
"return",
"1",
",",
"nil",
"\n",
"}",
"else",
"if",
"spec",
".",
"Constant",
">",
"0",
"&&",
"spec",
".",
"Coefficient",
"==",
"0",
"{",
"return",
"int",
"(",
"spec",
".",
"Constant",
")",
",",
"nil",
"\n",
"}",
"else",
"if",
"spec",
".",
"Constant",
"==",
"0",
"&&",
"spec",
".",
"Coefficient",
">",
"0",
"{",
"numNodes",
",",
"err",
":=",
"getNumNodes",
"(",
"kubeClient",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"math",
".",
"Floor",
"(",
"spec",
".",
"Coefficient",
"*",
"float64",
"(",
"numNodes",
")",
")",
"\n",
"return",
"int",
"(",
"math",
".",
"Max",
"(",
"result",
",",
"1",
")",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"Unable to interpret ParallelismSpec %+v\"",
",",
"spec",
")",
"\n",
"}"
] |
// GetExpectedNumWorkers computes the expected number of workers that
// pachyderm will start given the ParallelismSpec 'spec'.
//
// This is only exported for testing
|
[
"GetExpectedNumWorkers",
"computes",
"the",
"expected",
"number",
"of",
"workers",
"that",
"pachyderm",
"will",
"start",
"given",
"the",
"ParallelismSpec",
"spec",
".",
"This",
"is",
"only",
"exported",
"for",
"testing"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L142-L157
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
GetExpectedNumHashtrees
|
func GetExpectedNumHashtrees(spec *ppsclient.HashtreeSpec) (int64, error) {
if spec == nil || spec.Constant == 0 {
return 1, nil
} else if spec.Constant > 0 {
return int64(spec.Constant), nil
}
return 0, fmt.Errorf("unable to interpret HashtreeSpec %+v", spec)
}
|
go
|
func GetExpectedNumHashtrees(spec *ppsclient.HashtreeSpec) (int64, error) {
if spec == nil || spec.Constant == 0 {
return 1, nil
} else if spec.Constant > 0 {
return int64(spec.Constant), nil
}
return 0, fmt.Errorf("unable to interpret HashtreeSpec %+v", spec)
}
|
[
"func",
"GetExpectedNumHashtrees",
"(",
"spec",
"*",
"ppsclient",
".",
"HashtreeSpec",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"spec",
"==",
"nil",
"||",
"spec",
".",
"Constant",
"==",
"0",
"{",
"return",
"1",
",",
"nil",
"\n",
"}",
"else",
"if",
"spec",
".",
"Constant",
">",
"0",
"{",
"return",
"int64",
"(",
"spec",
".",
"Constant",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"unable to interpret HashtreeSpec %+v\"",
",",
"spec",
")",
"\n",
"}"
] |
// GetExpectedNumHashtrees computes the expected number of hashtrees that
// Pachyderm will create given the HashtreeSpec 'spec'.
|
[
"GetExpectedNumHashtrees",
"computes",
"the",
"expected",
"number",
"of",
"hashtrees",
"that",
"Pachyderm",
"will",
"create",
"given",
"the",
"HashtreeSpec",
"spec",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L161-L168
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
FailPipeline
|
func FailPipeline(ctx context.Context, etcdClient *etcd.Client, pipelinesCollection col.Collection, pipelineName string, reason string) error {
_, err := col.NewSTM(ctx, etcdClient, func(stm col.STM) error {
pipelines := pipelinesCollection.ReadWrite(stm)
pipelinePtr := new(pps.EtcdPipelineInfo)
if err := pipelines.Get(pipelineName, pipelinePtr); err != nil {
return err
}
pipelinePtr.State = pps.PipelineState_PIPELINE_FAILURE
pipelinePtr.Reason = reason
pipelines.Put(pipelineName, pipelinePtr)
return nil
})
return err
}
|
go
|
func FailPipeline(ctx context.Context, etcdClient *etcd.Client, pipelinesCollection col.Collection, pipelineName string, reason string) error {
_, err := col.NewSTM(ctx, etcdClient, func(stm col.STM) error {
pipelines := pipelinesCollection.ReadWrite(stm)
pipelinePtr := new(pps.EtcdPipelineInfo)
if err := pipelines.Get(pipelineName, pipelinePtr); err != nil {
return err
}
pipelinePtr.State = pps.PipelineState_PIPELINE_FAILURE
pipelinePtr.Reason = reason
pipelines.Put(pipelineName, pipelinePtr)
return nil
})
return err
}
|
[
"func",
"FailPipeline",
"(",
"ctx",
"context",
".",
"Context",
",",
"etcdClient",
"*",
"etcd",
".",
"Client",
",",
"pipelinesCollection",
"col",
".",
"Collection",
",",
"pipelineName",
"string",
",",
"reason",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"col",
".",
"NewSTM",
"(",
"ctx",
",",
"etcdClient",
",",
"func",
"(",
"stm",
"col",
".",
"STM",
")",
"error",
"{",
"pipelines",
":=",
"pipelinesCollection",
".",
"ReadWrite",
"(",
"stm",
")",
"\n",
"pipelinePtr",
":=",
"new",
"(",
"pps",
".",
"EtcdPipelineInfo",
")",
"\n",
"if",
"err",
":=",
"pipelines",
".",
"Get",
"(",
"pipelineName",
",",
"pipelinePtr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"pipelinePtr",
".",
"State",
"=",
"pps",
".",
"PipelineState_PIPELINE_FAILURE",
"\n",
"pipelinePtr",
".",
"Reason",
"=",
"reason",
"\n",
"pipelines",
".",
"Put",
"(",
"pipelineName",
",",
"pipelinePtr",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// FailPipeline updates the pipeline's state to failed and sets the failure reason
|
[
"FailPipeline",
"updates",
"the",
"pipeline",
"s",
"state",
"to",
"failed",
"and",
"sets",
"the",
"failure",
"reason"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L192-L205
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
JobInput
|
func JobInput(pipelineInfo *pps.PipelineInfo, outputCommitInfo *pfs.CommitInfo) *pps.Input {
// branchToCommit maps strings of the form "<repo>/<branch>" to PFS commits
branchToCommit := make(map[string]*pfs.Commit)
key := path.Join
for _, prov := range outputCommitInfo.Provenance {
branchToCommit[key(prov.Commit.Repo.Name, prov.Branch.Name)] = prov.Commit
}
jobInput := proto.Clone(pipelineInfo.Input).(*pps.Input)
pps.VisitInput(jobInput, func(input *pps.Input) {
if input.Pfs != nil {
if commit, ok := branchToCommit[key(input.Pfs.Repo, input.Pfs.Branch)]; ok {
input.Pfs.Commit = commit.ID
}
}
if input.Cron != nil {
if commit, ok := branchToCommit[key(input.Cron.Repo, "master")]; ok {
input.Cron.Commit = commit.ID
}
}
if input.Git != nil {
if commit, ok := branchToCommit[key(input.Git.Name, input.Git.Branch)]; ok {
input.Git.Commit = commit.ID
}
}
})
return jobInput
}
|
go
|
func JobInput(pipelineInfo *pps.PipelineInfo, outputCommitInfo *pfs.CommitInfo) *pps.Input {
// branchToCommit maps strings of the form "<repo>/<branch>" to PFS commits
branchToCommit := make(map[string]*pfs.Commit)
key := path.Join
for _, prov := range outputCommitInfo.Provenance {
branchToCommit[key(prov.Commit.Repo.Name, prov.Branch.Name)] = prov.Commit
}
jobInput := proto.Clone(pipelineInfo.Input).(*pps.Input)
pps.VisitInput(jobInput, func(input *pps.Input) {
if input.Pfs != nil {
if commit, ok := branchToCommit[key(input.Pfs.Repo, input.Pfs.Branch)]; ok {
input.Pfs.Commit = commit.ID
}
}
if input.Cron != nil {
if commit, ok := branchToCommit[key(input.Cron.Repo, "master")]; ok {
input.Cron.Commit = commit.ID
}
}
if input.Git != nil {
if commit, ok := branchToCommit[key(input.Git.Name, input.Git.Branch)]; ok {
input.Git.Commit = commit.ID
}
}
})
return jobInput
}
|
[
"func",
"JobInput",
"(",
"pipelineInfo",
"*",
"pps",
".",
"PipelineInfo",
",",
"outputCommitInfo",
"*",
"pfs",
".",
"CommitInfo",
")",
"*",
"pps",
".",
"Input",
"{",
"branchToCommit",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"pfs",
".",
"Commit",
")",
"\n",
"key",
":=",
"path",
".",
"Join",
"\n",
"for",
"_",
",",
"prov",
":=",
"range",
"outputCommitInfo",
".",
"Provenance",
"{",
"branchToCommit",
"[",
"key",
"(",
"prov",
".",
"Commit",
".",
"Repo",
".",
"Name",
",",
"prov",
".",
"Branch",
".",
"Name",
")",
"]",
"=",
"prov",
".",
"Commit",
"\n",
"}",
"\n",
"jobInput",
":=",
"proto",
".",
"Clone",
"(",
"pipelineInfo",
".",
"Input",
")",
".",
"(",
"*",
"pps",
".",
"Input",
")",
"\n",
"pps",
".",
"VisitInput",
"(",
"jobInput",
",",
"func",
"(",
"input",
"*",
"pps",
".",
"Input",
")",
"{",
"if",
"input",
".",
"Pfs",
"!=",
"nil",
"{",
"if",
"commit",
",",
"ok",
":=",
"branchToCommit",
"[",
"key",
"(",
"input",
".",
"Pfs",
".",
"Repo",
",",
"input",
".",
"Pfs",
".",
"Branch",
")",
"]",
";",
"ok",
"{",
"input",
".",
"Pfs",
".",
"Commit",
"=",
"commit",
".",
"ID",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"input",
".",
"Cron",
"!=",
"nil",
"{",
"if",
"commit",
",",
"ok",
":=",
"branchToCommit",
"[",
"key",
"(",
"input",
".",
"Cron",
".",
"Repo",
",",
"\"master\"",
")",
"]",
";",
"ok",
"{",
"input",
".",
"Cron",
".",
"Commit",
"=",
"commit",
".",
"ID",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"input",
".",
"Git",
"!=",
"nil",
"{",
"if",
"commit",
",",
"ok",
":=",
"branchToCommit",
"[",
"key",
"(",
"input",
".",
"Git",
".",
"Name",
",",
"input",
".",
"Git",
".",
"Branch",
")",
"]",
";",
"ok",
"{",
"input",
".",
"Git",
".",
"Commit",
"=",
"commit",
".",
"ID",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"jobInput",
"\n",
"}"
] |
// JobInput fills in the commits for a JobInfo
|
[
"JobInput",
"fills",
"in",
"the",
"commits",
"for",
"a",
"JobInfo"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L208-L234
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
PipelineReqFromInfo
|
func PipelineReqFromInfo(pipelineInfo *ppsclient.PipelineInfo) *ppsclient.CreatePipelineRequest {
return &ppsclient.CreatePipelineRequest{
Pipeline: pipelineInfo.Pipeline,
Transform: pipelineInfo.Transform,
ParallelismSpec: pipelineInfo.ParallelismSpec,
HashtreeSpec: pipelineInfo.HashtreeSpec,
Egress: pipelineInfo.Egress,
OutputBranch: pipelineInfo.OutputBranch,
ScaleDownThreshold: pipelineInfo.ScaleDownThreshold,
ResourceRequests: pipelineInfo.ResourceRequests,
ResourceLimits: pipelineInfo.ResourceLimits,
Input: pipelineInfo.Input,
Description: pipelineInfo.Description,
CacheSize: pipelineInfo.CacheSize,
EnableStats: pipelineInfo.EnableStats,
Batch: pipelineInfo.Batch,
MaxQueueSize: pipelineInfo.MaxQueueSize,
Service: pipelineInfo.Service,
ChunkSpec: pipelineInfo.ChunkSpec,
DatumTimeout: pipelineInfo.DatumTimeout,
JobTimeout: pipelineInfo.JobTimeout,
Salt: pipelineInfo.Salt,
}
}
|
go
|
func PipelineReqFromInfo(pipelineInfo *ppsclient.PipelineInfo) *ppsclient.CreatePipelineRequest {
return &ppsclient.CreatePipelineRequest{
Pipeline: pipelineInfo.Pipeline,
Transform: pipelineInfo.Transform,
ParallelismSpec: pipelineInfo.ParallelismSpec,
HashtreeSpec: pipelineInfo.HashtreeSpec,
Egress: pipelineInfo.Egress,
OutputBranch: pipelineInfo.OutputBranch,
ScaleDownThreshold: pipelineInfo.ScaleDownThreshold,
ResourceRequests: pipelineInfo.ResourceRequests,
ResourceLimits: pipelineInfo.ResourceLimits,
Input: pipelineInfo.Input,
Description: pipelineInfo.Description,
CacheSize: pipelineInfo.CacheSize,
EnableStats: pipelineInfo.EnableStats,
Batch: pipelineInfo.Batch,
MaxQueueSize: pipelineInfo.MaxQueueSize,
Service: pipelineInfo.Service,
ChunkSpec: pipelineInfo.ChunkSpec,
DatumTimeout: pipelineInfo.DatumTimeout,
JobTimeout: pipelineInfo.JobTimeout,
Salt: pipelineInfo.Salt,
}
}
|
[
"func",
"PipelineReqFromInfo",
"(",
"pipelineInfo",
"*",
"ppsclient",
".",
"PipelineInfo",
")",
"*",
"ppsclient",
".",
"CreatePipelineRequest",
"{",
"return",
"&",
"ppsclient",
".",
"CreatePipelineRequest",
"{",
"Pipeline",
":",
"pipelineInfo",
".",
"Pipeline",
",",
"Transform",
":",
"pipelineInfo",
".",
"Transform",
",",
"ParallelismSpec",
":",
"pipelineInfo",
".",
"ParallelismSpec",
",",
"HashtreeSpec",
":",
"pipelineInfo",
".",
"HashtreeSpec",
",",
"Egress",
":",
"pipelineInfo",
".",
"Egress",
",",
"OutputBranch",
":",
"pipelineInfo",
".",
"OutputBranch",
",",
"ScaleDownThreshold",
":",
"pipelineInfo",
".",
"ScaleDownThreshold",
",",
"ResourceRequests",
":",
"pipelineInfo",
".",
"ResourceRequests",
",",
"ResourceLimits",
":",
"pipelineInfo",
".",
"ResourceLimits",
",",
"Input",
":",
"pipelineInfo",
".",
"Input",
",",
"Description",
":",
"pipelineInfo",
".",
"Description",
",",
"CacheSize",
":",
"pipelineInfo",
".",
"CacheSize",
",",
"EnableStats",
":",
"pipelineInfo",
".",
"EnableStats",
",",
"Batch",
":",
"pipelineInfo",
".",
"Batch",
",",
"MaxQueueSize",
":",
"pipelineInfo",
".",
"MaxQueueSize",
",",
"Service",
":",
"pipelineInfo",
".",
"Service",
",",
"ChunkSpec",
":",
"pipelineInfo",
".",
"ChunkSpec",
",",
"DatumTimeout",
":",
"pipelineInfo",
".",
"DatumTimeout",
",",
"JobTimeout",
":",
"pipelineInfo",
".",
"JobTimeout",
",",
"Salt",
":",
"pipelineInfo",
".",
"Salt",
",",
"}",
"\n",
"}"
] |
// PipelineReqFromInfo converts a PipelineInfo into a CreatePipelineRequest.
|
[
"PipelineReqFromInfo",
"converts",
"a",
"PipelineInfo",
"into",
"a",
"CreatePipelineRequest",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L237-L260
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
NewPipelineManifestReader
|
func NewPipelineManifestReader(path string) (result *PipelineManifestReader, retErr error) {
result = &PipelineManifestReader{}
var pipelineReader io.Reader
if path == "-" {
pipelineReader = io.TeeReader(os.Stdin, &result.buf)
fmt.Print("Reading from stdin.\n")
} else if url, err := url.Parse(path); err == nil && url.Scheme != "" {
resp, err := http.Get(url.String())
if err != nil {
return nil, err
}
defer func() {
if err := resp.Body.Close(); err != nil && retErr == nil {
retErr = err
}
}()
rawBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
pipelineReader = io.TeeReader(strings.NewReader(string(rawBytes)), &result.buf)
} else {
rawBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
pipelineReader = io.TeeReader(strings.NewReader(string(rawBytes)), &result.buf)
}
result.decoder = json.NewDecoder(pipelineReader)
return result, nil
}
|
go
|
func NewPipelineManifestReader(path string) (result *PipelineManifestReader, retErr error) {
result = &PipelineManifestReader{}
var pipelineReader io.Reader
if path == "-" {
pipelineReader = io.TeeReader(os.Stdin, &result.buf)
fmt.Print("Reading from stdin.\n")
} else if url, err := url.Parse(path); err == nil && url.Scheme != "" {
resp, err := http.Get(url.String())
if err != nil {
return nil, err
}
defer func() {
if err := resp.Body.Close(); err != nil && retErr == nil {
retErr = err
}
}()
rawBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
pipelineReader = io.TeeReader(strings.NewReader(string(rawBytes)), &result.buf)
} else {
rawBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
pipelineReader = io.TeeReader(strings.NewReader(string(rawBytes)), &result.buf)
}
result.decoder = json.NewDecoder(pipelineReader)
return result, nil
}
|
[
"func",
"NewPipelineManifestReader",
"(",
"path",
"string",
")",
"(",
"result",
"*",
"PipelineManifestReader",
",",
"retErr",
"error",
")",
"{",
"result",
"=",
"&",
"PipelineManifestReader",
"{",
"}",
"\n",
"var",
"pipelineReader",
"io",
".",
"Reader",
"\n",
"if",
"path",
"==",
"\"-\"",
"{",
"pipelineReader",
"=",
"io",
".",
"TeeReader",
"(",
"os",
".",
"Stdin",
",",
"&",
"result",
".",
"buf",
")",
"\n",
"fmt",
".",
"Print",
"(",
"\"Reading from stdin.\\n\"",
")",
"\n",
"}",
"else",
"\\n",
"\n",
"if",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"path",
")",
";",
"err",
"==",
"nil",
"&&",
"url",
".",
"Scheme",
"!=",
"\"\"",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"url",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"retErr",
"==",
"nil",
"{",
"retErr",
"=",
"err",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"rawBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"pipelineReader",
"=",
"io",
".",
"TeeReader",
"(",
"strings",
".",
"NewReader",
"(",
"string",
"(",
"rawBytes",
")",
")",
",",
"&",
"result",
".",
"buf",
")",
"\n",
"}",
"else",
"{",
"rawBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"pipelineReader",
"=",
"io",
".",
"TeeReader",
"(",
"strings",
".",
"NewReader",
"(",
"string",
"(",
"rawBytes",
")",
")",
",",
"&",
"result",
".",
"buf",
")",
"\n",
"}",
"\n",
"result",
".",
"decoder",
"=",
"json",
".",
"NewDecoder",
"(",
"pipelineReader",
")",
"\n",
"}"
] |
// NewPipelineManifestReader creates a new manifest reader from a path.
|
[
"NewPipelineManifestReader",
"creates",
"a",
"new",
"manifest",
"reader",
"from",
"a",
"path",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L270-L301
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
NextCreatePipelineRequest
|
func (r *PipelineManifestReader) NextCreatePipelineRequest() (*ppsclient.CreatePipelineRequest, error) {
var result ppsclient.CreatePipelineRequest
if err := jsonpb.UnmarshalNext(r.decoder, &result); err != nil {
if err == io.EOF {
return nil, err
}
return nil, fmt.Errorf("malformed pipeline spec: %s", err)
}
return &result, nil
}
|
go
|
func (r *PipelineManifestReader) NextCreatePipelineRequest() (*ppsclient.CreatePipelineRequest, error) {
var result ppsclient.CreatePipelineRequest
if err := jsonpb.UnmarshalNext(r.decoder, &result); err != nil {
if err == io.EOF {
return nil, err
}
return nil, fmt.Errorf("malformed pipeline spec: %s", err)
}
return &result, nil
}
|
[
"func",
"(",
"r",
"*",
"PipelineManifestReader",
")",
"NextCreatePipelineRequest",
"(",
")",
"(",
"*",
"ppsclient",
".",
"CreatePipelineRequest",
",",
"error",
")",
"{",
"var",
"result",
"ppsclient",
".",
"CreatePipelineRequest",
"\n",
"if",
"err",
":=",
"jsonpb",
".",
"UnmarshalNext",
"(",
"r",
".",
"decoder",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"malformed pipeline spec: %s\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"result",
",",
"nil",
"\n",
"}"
] |
// NextCreatePipelineRequest gets the next request from the manifest reader.
|
[
"NextCreatePipelineRequest",
"gets",
"the",
"next",
"request",
"from",
"the",
"manifest",
"reader",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L304-L313
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
DescribeSyntaxError
|
func DescribeSyntaxError(originalErr error, parsedBuffer bytes.Buffer) error {
sErr, ok := originalErr.(*json.SyntaxError)
if !ok {
return originalErr
}
buffer := make([]byte, sErr.Offset)
parsedBuffer.Read(buffer)
lineOffset := strings.LastIndex(string(buffer[:len(buffer)-1]), "\n")
if lineOffset == -1 {
lineOffset = 0
}
lines := strings.Split(string(buffer[:len(buffer)-1]), "\n")
lineNumber := len(lines)
descriptiveErrorString := fmt.Sprintf("Syntax Error on line %v:\n%v\n%v^\n%v\n",
lineNumber,
string(buffer[lineOffset:]),
strings.Repeat(" ", int(sErr.Offset)-2-lineOffset),
originalErr,
)
return errors.New(descriptiveErrorString)
}
|
go
|
func DescribeSyntaxError(originalErr error, parsedBuffer bytes.Buffer) error {
sErr, ok := originalErr.(*json.SyntaxError)
if !ok {
return originalErr
}
buffer := make([]byte, sErr.Offset)
parsedBuffer.Read(buffer)
lineOffset := strings.LastIndex(string(buffer[:len(buffer)-1]), "\n")
if lineOffset == -1 {
lineOffset = 0
}
lines := strings.Split(string(buffer[:len(buffer)-1]), "\n")
lineNumber := len(lines)
descriptiveErrorString := fmt.Sprintf("Syntax Error on line %v:\n%v\n%v^\n%v\n",
lineNumber,
string(buffer[lineOffset:]),
strings.Repeat(" ", int(sErr.Offset)-2-lineOffset),
originalErr,
)
return errors.New(descriptiveErrorString)
}
|
[
"func",
"DescribeSyntaxError",
"(",
"originalErr",
"error",
",",
"parsedBuffer",
"bytes",
".",
"Buffer",
")",
"error",
"{",
"sErr",
",",
"ok",
":=",
"originalErr",
".",
"(",
"*",
"json",
".",
"SyntaxError",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"originalErr",
"\n",
"}",
"\n",
"buffer",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"sErr",
".",
"Offset",
")",
"\n",
"parsedBuffer",
".",
"Read",
"(",
"buffer",
")",
"\n",
"lineOffset",
":=",
"strings",
".",
"LastIndex",
"(",
"string",
"(",
"buffer",
"[",
":",
"len",
"(",
"buffer",
")",
"-",
"1",
"]",
")",
",",
"\"\\n\"",
")",
"\n",
"\\n",
"\n",
"if",
"lineOffset",
"==",
"-",
"1",
"{",
"lineOffset",
"=",
"0",
"\n",
"}",
"\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"string",
"(",
"buffer",
"[",
":",
"len",
"(",
"buffer",
")",
"-",
"1",
"]",
")",
",",
"\"\\n\"",
")",
"\n",
"\\n",
"\n",
"lineNumber",
":=",
"len",
"(",
"lines",
")",
"\n",
"}"
] |
// DescribeSyntaxError describes a syntax error encountered parsing json.
|
[
"DescribeSyntaxError",
"describes",
"a",
"syntax",
"error",
"encountered",
"parsing",
"json",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L316-L342
|
test
|
pachyderm/pachyderm
|
src/server/pkg/ppsutil/util.go
|
UpdateJobState
|
func UpdateJobState(pipelines col.ReadWriteCollection, jobs col.ReadWriteCollection, jobPtr *pps.EtcdJobInfo, state pps.JobState, reason string) error {
// Update pipeline
pipelinePtr := &pps.EtcdPipelineInfo{}
if err := pipelines.Get(jobPtr.Pipeline.Name, pipelinePtr); err != nil {
return err
}
if pipelinePtr.JobCounts == nil {
pipelinePtr.JobCounts = make(map[int32]int32)
}
if pipelinePtr.JobCounts[int32(jobPtr.State)] != 0 {
pipelinePtr.JobCounts[int32(jobPtr.State)]--
}
pipelinePtr.JobCounts[int32(state)]++
pipelinePtr.LastJobState = state
if err := pipelines.Put(jobPtr.Pipeline.Name, pipelinePtr); err != nil {
return err
}
// Update job info
var err error
if state == pps.JobState_JOB_STARTING {
jobPtr.Started, err = types.TimestampProto(time.Now())
} else if IsTerminal(state) {
jobPtr.Finished, err = types.TimestampProto(time.Now())
}
if err != nil {
return err
}
jobPtr.State = state
jobPtr.Reason = reason
return jobs.Put(jobPtr.Job.ID, jobPtr)
}
|
go
|
func UpdateJobState(pipelines col.ReadWriteCollection, jobs col.ReadWriteCollection, jobPtr *pps.EtcdJobInfo, state pps.JobState, reason string) error {
// Update pipeline
pipelinePtr := &pps.EtcdPipelineInfo{}
if err := pipelines.Get(jobPtr.Pipeline.Name, pipelinePtr); err != nil {
return err
}
if pipelinePtr.JobCounts == nil {
pipelinePtr.JobCounts = make(map[int32]int32)
}
if pipelinePtr.JobCounts[int32(jobPtr.State)] != 0 {
pipelinePtr.JobCounts[int32(jobPtr.State)]--
}
pipelinePtr.JobCounts[int32(state)]++
pipelinePtr.LastJobState = state
if err := pipelines.Put(jobPtr.Pipeline.Name, pipelinePtr); err != nil {
return err
}
// Update job info
var err error
if state == pps.JobState_JOB_STARTING {
jobPtr.Started, err = types.TimestampProto(time.Now())
} else if IsTerminal(state) {
jobPtr.Finished, err = types.TimestampProto(time.Now())
}
if err != nil {
return err
}
jobPtr.State = state
jobPtr.Reason = reason
return jobs.Put(jobPtr.Job.ID, jobPtr)
}
|
[
"func",
"UpdateJobState",
"(",
"pipelines",
"col",
".",
"ReadWriteCollection",
",",
"jobs",
"col",
".",
"ReadWriteCollection",
",",
"jobPtr",
"*",
"pps",
".",
"EtcdJobInfo",
",",
"state",
"pps",
".",
"JobState",
",",
"reason",
"string",
")",
"error",
"{",
"pipelinePtr",
":=",
"&",
"pps",
".",
"EtcdPipelineInfo",
"{",
"}",
"\n",
"if",
"err",
":=",
"pipelines",
".",
"Get",
"(",
"jobPtr",
".",
"Pipeline",
".",
"Name",
",",
"pipelinePtr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"pipelinePtr",
".",
"JobCounts",
"==",
"nil",
"{",
"pipelinePtr",
".",
"JobCounts",
"=",
"make",
"(",
"map",
"[",
"int32",
"]",
"int32",
")",
"\n",
"}",
"\n",
"if",
"pipelinePtr",
".",
"JobCounts",
"[",
"int32",
"(",
"jobPtr",
".",
"State",
")",
"]",
"!=",
"0",
"{",
"pipelinePtr",
".",
"JobCounts",
"[",
"int32",
"(",
"jobPtr",
".",
"State",
")",
"]",
"--",
"\n",
"}",
"\n",
"pipelinePtr",
".",
"JobCounts",
"[",
"int32",
"(",
"state",
")",
"]",
"++",
"\n",
"pipelinePtr",
".",
"LastJobState",
"=",
"state",
"\n",
"if",
"err",
":=",
"pipelines",
".",
"Put",
"(",
"jobPtr",
".",
"Pipeline",
".",
"Name",
",",
"pipelinePtr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"if",
"state",
"==",
"pps",
".",
"JobState_JOB_STARTING",
"{",
"jobPtr",
".",
"Started",
",",
"err",
"=",
"types",
".",
"TimestampProto",
"(",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"IsTerminal",
"(",
"state",
")",
"{",
"jobPtr",
".",
"Finished",
",",
"err",
"=",
"types",
".",
"TimestampProto",
"(",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"jobPtr",
".",
"State",
"=",
"state",
"\n",
"jobPtr",
".",
"Reason",
"=",
"reason",
"\n",
"return",
"jobs",
".",
"Put",
"(",
"jobPtr",
".",
"Job",
".",
"ID",
",",
"jobPtr",
")",
"\n",
"}"
] |
// UpdateJobState performs the operations involved with a job state transition.
|
[
"UpdateJobState",
"performs",
"the",
"operations",
"involved",
"with",
"a",
"job",
"state",
"transition",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/ppsutil/util.go#L359-L390
|
test
|
pachyderm/pachyderm
|
src/server/pkg/uuid/uuid.go
|
New
|
func New() string {
var result string
backoff.RetryNotify(func() error {
uuid, err := uuid.NewV4()
if err != nil {
return err
}
result = uuid.String()
return nil
}, backoff.NewInfiniteBackOff(), func(err error, d time.Duration) error {
fmt.Printf("error from uuid.NewV4: %v", err)
return nil
})
return result
}
|
go
|
func New() string {
var result string
backoff.RetryNotify(func() error {
uuid, err := uuid.NewV4()
if err != nil {
return err
}
result = uuid.String()
return nil
}, backoff.NewInfiniteBackOff(), func(err error, d time.Duration) error {
fmt.Printf("error from uuid.NewV4: %v", err)
return nil
})
return result
}
|
[
"func",
"New",
"(",
")",
"string",
"{",
"var",
"result",
"string",
"\n",
"backoff",
".",
"RetryNotify",
"(",
"func",
"(",
")",
"error",
"{",
"uuid",
",",
"err",
":=",
"uuid",
".",
"NewV4",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"result",
"=",
"uuid",
".",
"String",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
",",
"backoff",
".",
"NewInfiniteBackOff",
"(",
")",
",",
"func",
"(",
"err",
"error",
",",
"d",
"time",
".",
"Duration",
")",
"error",
"{",
"fmt",
".",
"Printf",
"(",
"\"error from uuid.NewV4: %v\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"result",
"\n",
"}"
] |
// New returns a new uuid.
|
[
"New",
"returns",
"a",
"new",
"uuid",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/uuid/uuid.go#L14-L28
|
test
|
pachyderm/pachyderm
|
src/server/pkg/errutil/http.go
|
Code
|
func (h *HTTPError) Code() int {
if h == nil {
return http.StatusOK
}
return h.code
}
|
go
|
func (h *HTTPError) Code() int {
if h == nil {
return http.StatusOK
}
return h.code
}
|
[
"func",
"(",
"h",
"*",
"HTTPError",
")",
"Code",
"(",
")",
"int",
"{",
"if",
"h",
"==",
"nil",
"{",
"return",
"http",
".",
"StatusOK",
"\n",
"}",
"\n",
"return",
"h",
".",
"code",
"\n",
"}"
] |
// Code returns the HTTP error code associated with 'h'
|
[
"Code",
"returns",
"the",
"HTTP",
"error",
"code",
"associated",
"with",
"h"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/errutil/http.go#L25-L30
|
test
|
pachyderm/pachyderm
|
src/server/pkg/errutil/http.go
|
NewHTTPError
|
func NewHTTPError(code int, formatStr string, args ...interface{}) *HTTPError {
return &HTTPError{
code: code,
err: fmt.Sprintf(formatStr, args...),
}
}
|
go
|
func NewHTTPError(code int, formatStr string, args ...interface{}) *HTTPError {
return &HTTPError{
code: code,
err: fmt.Sprintf(formatStr, args...),
}
}
|
[
"func",
"NewHTTPError",
"(",
"code",
"int",
",",
"formatStr",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"HTTPError",
"{",
"return",
"&",
"HTTPError",
"{",
"code",
":",
"code",
",",
"err",
":",
"fmt",
".",
"Sprintf",
"(",
"formatStr",
",",
"args",
"...",
")",
",",
"}",
"\n",
"}"
] |
// NewHTTPError returns a new HTTPError where the HTTP error code is 'code' and
// the error message is based on 'formatStr' and 'args'
|
[
"NewHTTPError",
"returns",
"a",
"new",
"HTTPError",
"where",
"the",
"HTTP",
"error",
"code",
"is",
"code",
"and",
"the",
"error",
"message",
"is",
"based",
"on",
"formatStr",
"and",
"args"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/errutil/http.go#L41-L46
|
test
|
pachyderm/pachyderm
|
src/server/pkg/storage/chunk/storage.go
|
NewStorage
|
func NewStorage(objC obj.Client, prefix string) *Storage {
return &Storage{
objC: objC,
prefix: prefix,
}
}
|
go
|
func NewStorage(objC obj.Client, prefix string) *Storage {
return &Storage{
objC: objC,
prefix: prefix,
}
}
|
[
"func",
"NewStorage",
"(",
"objC",
"obj",
".",
"Client",
",",
"prefix",
"string",
")",
"*",
"Storage",
"{",
"return",
"&",
"Storage",
"{",
"objC",
":",
"objC",
",",
"prefix",
":",
"prefix",
",",
"}",
"\n",
"}"
] |
// NewStorage creates a new Storage.
|
[
"NewStorage",
"creates",
"a",
"new",
"Storage",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/storage/chunk/storage.go#L19-L24
|
test
|
pachyderm/pachyderm
|
src/server/pkg/storage/chunk/storage.go
|
DeleteAll
|
func (s *Storage) DeleteAll(ctx context.Context) error {
return s.objC.Walk(ctx, s.prefix, func(hash string) error {
return s.objC.Delete(ctx, hash)
})
}
|
go
|
func (s *Storage) DeleteAll(ctx context.Context) error {
return s.objC.Walk(ctx, s.prefix, func(hash string) error {
return s.objC.Delete(ctx, hash)
})
}
|
[
"func",
"(",
"s",
"*",
"Storage",
")",
"DeleteAll",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"objC",
".",
"Walk",
"(",
"ctx",
",",
"s",
".",
"prefix",
",",
"func",
"(",
"hash",
"string",
")",
"error",
"{",
"return",
"s",
".",
"objC",
".",
"Delete",
"(",
"ctx",
",",
"hash",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// DeleteAll deletes all of the chunks in object storage.
|
[
"DeleteAll",
"deletes",
"all",
"of",
"the",
"chunks",
"in",
"object",
"storage",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/storage/chunk/storage.go#L46-L50
|
test
|
pachyderm/pachyderm
|
src/client/pkg/grpcutil/stream.go
|
Chunk
|
func Chunk(data []byte, chunkSize int) [][]byte {
var result [][]byte
for i := 0; i < len(data); i += chunkSize {
end := i + chunkSize
if end > len(data) {
end = len(data)
}
result = append(result, data[i:end])
}
return result
}
|
go
|
func Chunk(data []byte, chunkSize int) [][]byte {
var result [][]byte
for i := 0; i < len(data); i += chunkSize {
end := i + chunkSize
if end > len(data) {
end = len(data)
}
result = append(result, data[i:end])
}
return result
}
|
[
"func",
"Chunk",
"(",
"data",
"[",
"]",
"byte",
",",
"chunkSize",
"int",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"var",
"result",
"[",
"]",
"[",
"]",
"byte",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"data",
")",
";",
"i",
"+=",
"chunkSize",
"{",
"end",
":=",
"i",
"+",
"chunkSize",
"\n",
"if",
"end",
">",
"len",
"(",
"data",
")",
"{",
"end",
"=",
"len",
"(",
"data",
")",
"\n",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"data",
"[",
"i",
":",
"end",
"]",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] |
// Chunk splits a piece of data up, this is useful for splitting up data that's
// bigger than MaxMsgSize
|
[
"Chunk",
"splits",
"a",
"piece",
"of",
"data",
"up",
"this",
"is",
"useful",
"for",
"splitting",
"up",
"data",
"that",
"s",
"bigger",
"than",
"MaxMsgSize"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pkg/grpcutil/stream.go#L18-L28
|
test
|
pachyderm/pachyderm
|
src/client/pkg/grpcutil/stream.go
|
ChunkReader
|
func ChunkReader(r io.Reader, f func([]byte) error) (int, error) {
var total int
buf := GetBuffer()
defer PutBuffer(buf)
for {
n, err := r.Read(buf)
if n == 0 && err != nil {
if err == io.EOF {
return total, nil
}
return total, err
}
if err := f(buf[:n]); err != nil {
return total, err
}
total += n
}
}
|
go
|
func ChunkReader(r io.Reader, f func([]byte) error) (int, error) {
var total int
buf := GetBuffer()
defer PutBuffer(buf)
for {
n, err := r.Read(buf)
if n == 0 && err != nil {
if err == io.EOF {
return total, nil
}
return total, err
}
if err := f(buf[:n]); err != nil {
return total, err
}
total += n
}
}
|
[
"func",
"ChunkReader",
"(",
"r",
"io",
".",
"Reader",
",",
"f",
"func",
"(",
"[",
"]",
"byte",
")",
"error",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"total",
"int",
"\n",
"buf",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"PutBuffer",
"(",
"buf",
")",
"\n",
"for",
"{",
"n",
",",
"err",
":=",
"r",
".",
"Read",
"(",
"buf",
")",
"\n",
"if",
"n",
"==",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"total",
",",
"nil",
"\n",
"}",
"\n",
"return",
"total",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"f",
"(",
"buf",
"[",
":",
"n",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"total",
",",
"err",
"\n",
"}",
"\n",
"total",
"+=",
"n",
"\n",
"}",
"\n",
"}"
] |
// ChunkReader splits a reader into reasonably sized chunks for the purpose
// of transmitting the chunks over gRPC. For each chunk, it calls the given
// function.
|
[
"ChunkReader",
"splits",
"a",
"reader",
"into",
"reasonably",
"sized",
"chunks",
"for",
"the",
"purpose",
"of",
"transmitting",
"the",
"chunks",
"over",
"gRPC",
".",
"For",
"each",
"chunk",
"it",
"calls",
"the",
"given",
"function",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pkg/grpcutil/stream.go#L33-L50
|
test
|
pachyderm/pachyderm
|
src/client/pkg/grpcutil/stream.go
|
NewStreamingBytesReader
|
func NewStreamingBytesReader(streamingBytesClient StreamingBytesClient, cancel context.CancelFunc) io.ReadCloser {
return &streamingBytesReader{streamingBytesClient: streamingBytesClient, cancel: cancel}
}
|
go
|
func NewStreamingBytesReader(streamingBytesClient StreamingBytesClient, cancel context.CancelFunc) io.ReadCloser {
return &streamingBytesReader{streamingBytesClient: streamingBytesClient, cancel: cancel}
}
|
[
"func",
"NewStreamingBytesReader",
"(",
"streamingBytesClient",
"StreamingBytesClient",
",",
"cancel",
"context",
".",
"CancelFunc",
")",
"io",
".",
"ReadCloser",
"{",
"return",
"&",
"streamingBytesReader",
"{",
"streamingBytesClient",
":",
"streamingBytesClient",
",",
"cancel",
":",
"cancel",
"}",
"\n",
"}"
] |
// NewStreamingBytesReader returns an io.Reader for a StreamingBytesClient.
|
[
"NewStreamingBytesReader",
"returns",
"an",
"io",
".",
"Reader",
"for",
"a",
"StreamingBytesClient",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pkg/grpcutil/stream.go#L65-L67
|
test
|
pachyderm/pachyderm
|
src/client/pkg/grpcutil/stream.go
|
WriteToStreamingBytesServer
|
func WriteToStreamingBytesServer(reader io.Reader, streamingBytesServer StreamingBytesServer) error {
buf := GetBuffer()
defer PutBuffer(buf)
_, err := io.CopyBuffer(NewStreamingBytesWriter(streamingBytesServer), ReaderWrapper{reader}, buf)
return err
}
|
go
|
func WriteToStreamingBytesServer(reader io.Reader, streamingBytesServer StreamingBytesServer) error {
buf := GetBuffer()
defer PutBuffer(buf)
_, err := io.CopyBuffer(NewStreamingBytesWriter(streamingBytesServer), ReaderWrapper{reader}, buf)
return err
}
|
[
"func",
"WriteToStreamingBytesServer",
"(",
"reader",
"io",
".",
"Reader",
",",
"streamingBytesServer",
"StreamingBytesServer",
")",
"error",
"{",
"buf",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"PutBuffer",
"(",
"buf",
")",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"CopyBuffer",
"(",
"NewStreamingBytesWriter",
"(",
"streamingBytesServer",
")",
",",
"ReaderWrapper",
"{",
"reader",
"}",
",",
"buf",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// WriteToStreamingBytesServer writes the data from the io.Reader to the StreamingBytesServer.
|
[
"WriteToStreamingBytesServer",
"writes",
"the",
"data",
"from",
"the",
"io",
".",
"Reader",
"to",
"the",
"StreamingBytesServer",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pkg/grpcutil/stream.go#L131-L136
|
test
|
pachyderm/pachyderm
|
src/client/pkg/grpcutil/stream.go
|
WriteFromStreamingBytesClient
|
func WriteFromStreamingBytesClient(streamingBytesClient StreamingBytesClient, writer io.Writer) error {
for bytesValue, err := streamingBytesClient.Recv(); err != io.EOF; bytesValue, err = streamingBytesClient.Recv() {
if err != nil {
return err
}
if _, err = writer.Write(bytesValue.Value); err != nil {
return err
}
}
return nil
}
|
go
|
func WriteFromStreamingBytesClient(streamingBytesClient StreamingBytesClient, writer io.Writer) error {
for bytesValue, err := streamingBytesClient.Recv(); err != io.EOF; bytesValue, err = streamingBytesClient.Recv() {
if err != nil {
return err
}
if _, err = writer.Write(bytesValue.Value); err != nil {
return err
}
}
return nil
}
|
[
"func",
"WriteFromStreamingBytesClient",
"(",
"streamingBytesClient",
"StreamingBytesClient",
",",
"writer",
"io",
".",
"Writer",
")",
"error",
"{",
"for",
"bytesValue",
",",
"err",
":=",
"streamingBytesClient",
".",
"Recv",
"(",
")",
";",
"err",
"!=",
"io",
".",
"EOF",
";",
"bytesValue",
",",
"err",
"=",
"streamingBytesClient",
".",
"Recv",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
"=",
"writer",
".",
"Write",
"(",
"bytesValue",
".",
"Value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// WriteFromStreamingBytesClient writes from the StreamingBytesClient to the io.Writer.
|
[
"WriteFromStreamingBytesClient",
"writes",
"from",
"the",
"StreamingBytesClient",
"to",
"the",
"io",
".",
"Writer",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pkg/grpcutil/stream.go#L139-L149
|
test
|
pachyderm/pachyderm
|
src/server/pps/server/server.go
|
NewSidecarAPIServer
|
func NewSidecarAPIServer(
env *serviceenv.ServiceEnv,
etcdPrefix string,
iamRole string,
reporter *metrics.Reporter,
workerGrpcPort uint16,
pprofPort uint16,
httpPort uint16,
peerPort uint16,
) (ppsclient.APIServer, error) {
apiServer := &apiServer{
Logger: log.NewLogger("pps.API"),
env: env,
etcdPrefix: etcdPrefix,
iamRole: iamRole,
reporter: reporter,
workerUsesRoot: true,
pipelines: ppsdb.Pipelines(env.GetEtcdClient(), etcdPrefix),
jobs: ppsdb.Jobs(env.GetEtcdClient(), etcdPrefix),
workerGrpcPort: workerGrpcPort,
pprofPort: pprofPort,
httpPort: httpPort,
peerPort: peerPort,
}
return apiServer, nil
}
|
go
|
func NewSidecarAPIServer(
env *serviceenv.ServiceEnv,
etcdPrefix string,
iamRole string,
reporter *metrics.Reporter,
workerGrpcPort uint16,
pprofPort uint16,
httpPort uint16,
peerPort uint16,
) (ppsclient.APIServer, error) {
apiServer := &apiServer{
Logger: log.NewLogger("pps.API"),
env: env,
etcdPrefix: etcdPrefix,
iamRole: iamRole,
reporter: reporter,
workerUsesRoot: true,
pipelines: ppsdb.Pipelines(env.GetEtcdClient(), etcdPrefix),
jobs: ppsdb.Jobs(env.GetEtcdClient(), etcdPrefix),
workerGrpcPort: workerGrpcPort,
pprofPort: pprofPort,
httpPort: httpPort,
peerPort: peerPort,
}
return apiServer, nil
}
|
[
"func",
"NewSidecarAPIServer",
"(",
"env",
"*",
"serviceenv",
".",
"ServiceEnv",
",",
"etcdPrefix",
"string",
",",
"iamRole",
"string",
",",
"reporter",
"*",
"metrics",
".",
"Reporter",
",",
"workerGrpcPort",
"uint16",
",",
"pprofPort",
"uint16",
",",
"httpPort",
"uint16",
",",
"peerPort",
"uint16",
",",
")",
"(",
"ppsclient",
".",
"APIServer",
",",
"error",
")",
"{",
"apiServer",
":=",
"&",
"apiServer",
"{",
"Logger",
":",
"log",
".",
"NewLogger",
"(",
"\"pps.API\"",
")",
",",
"env",
":",
"env",
",",
"etcdPrefix",
":",
"etcdPrefix",
",",
"iamRole",
":",
"iamRole",
",",
"reporter",
":",
"reporter",
",",
"workerUsesRoot",
":",
"true",
",",
"pipelines",
":",
"ppsdb",
".",
"Pipelines",
"(",
"env",
".",
"GetEtcdClient",
"(",
")",
",",
"etcdPrefix",
")",
",",
"jobs",
":",
"ppsdb",
".",
"Jobs",
"(",
"env",
".",
"GetEtcdClient",
"(",
")",
",",
"etcdPrefix",
")",
",",
"workerGrpcPort",
":",
"workerGrpcPort",
",",
"pprofPort",
":",
"pprofPort",
",",
"httpPort",
":",
"httpPort",
",",
"peerPort",
":",
"peerPort",
",",
"}",
"\n",
"return",
"apiServer",
",",
"nil",
"\n",
"}"
] |
// NewSidecarAPIServer creates an APIServer that has limited functionalities
// and is meant to be run as a worker sidecar. It cannot, for instance,
// create pipelines.
|
[
"NewSidecarAPIServer",
"creates",
"an",
"APIServer",
"that",
"has",
"limited",
"functionalities",
"and",
"is",
"meant",
"to",
"be",
"run",
"as",
"a",
"worker",
"sidecar",
".",
"It",
"cannot",
"for",
"instance",
"create",
"pipelines",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pps/server/server.go#L66-L91
|
test
|
pachyderm/pachyderm
|
src/server/enterprise/server/api_server.go
|
NewEnterpriseServer
|
func NewEnterpriseServer(env *serviceenv.ServiceEnv, etcdPrefix string) (ec.APIServer, error) {
s := &apiServer{
pachLogger: log.NewLogger("enterprise.API"),
env: env,
enterpriseToken: col.NewCollection(
env.GetEtcdClient(),
etcdPrefix, // only one collection--no extra prefix needed
nil,
&ec.EnterpriseRecord{},
nil,
nil,
),
}
s.enterpriseExpiration.Store(time.Time{})
go s.watchEnterpriseToken(etcdPrefix)
return s, nil
}
|
go
|
func NewEnterpriseServer(env *serviceenv.ServiceEnv, etcdPrefix string) (ec.APIServer, error) {
s := &apiServer{
pachLogger: log.NewLogger("enterprise.API"),
env: env,
enterpriseToken: col.NewCollection(
env.GetEtcdClient(),
etcdPrefix, // only one collection--no extra prefix needed
nil,
&ec.EnterpriseRecord{},
nil,
nil,
),
}
s.enterpriseExpiration.Store(time.Time{})
go s.watchEnterpriseToken(etcdPrefix)
return s, nil
}
|
[
"func",
"NewEnterpriseServer",
"(",
"env",
"*",
"serviceenv",
".",
"ServiceEnv",
",",
"etcdPrefix",
"string",
")",
"(",
"ec",
".",
"APIServer",
",",
"error",
")",
"{",
"s",
":=",
"&",
"apiServer",
"{",
"pachLogger",
":",
"log",
".",
"NewLogger",
"(",
"\"enterprise.API\"",
")",
",",
"env",
":",
"env",
",",
"enterpriseToken",
":",
"col",
".",
"NewCollection",
"(",
"env",
".",
"GetEtcdClient",
"(",
")",
",",
"etcdPrefix",
",",
"nil",
",",
"&",
"ec",
".",
"EnterpriseRecord",
"{",
"}",
",",
"nil",
",",
"nil",
",",
")",
",",
"}",
"\n",
"s",
".",
"enterpriseExpiration",
".",
"Store",
"(",
"time",
".",
"Time",
"{",
"}",
")",
"\n",
"go",
"s",
".",
"watchEnterpriseToken",
"(",
"etcdPrefix",
")",
"\n",
"return",
"s",
",",
"nil",
"\n",
"}"
] |
// NewEnterpriseServer returns an implementation of ec.APIServer.
|
[
"NewEnterpriseServer",
"returns",
"an",
"implementation",
"of",
"ec",
".",
"APIServer",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/enterprise/server/api_server.go#L72-L88
|
test
|
pachyderm/pachyderm
|
src/server/enterprise/server/api_server.go
|
validateActivationCode
|
func validateActivationCode(code string) (expiration time.Time, err error) {
// Parse the public key. If these steps fail, something is seriously
// wrong and we should crash the service by panicking.
block, _ := pem.Decode([]byte(publicKey))
if block == nil {
return time.Time{}, fmt.Errorf("failed to pem decode public key")
}
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return time.Time{}, fmt.Errorf("failed to parse DER encoded public key: %s", err.Error())
}
rsaPub, ok := pub.(*rsa.PublicKey)
if !ok {
return time.Time{}, fmt.Errorf("public key isn't an RSA key")
}
// Decode the base64-encoded activation code
decodedActivationCode, err := base64.StdEncoding.DecodeString(code)
if err != nil {
return time.Time{}, fmt.Errorf("activation code is not base64 encoded")
}
activationCode := &activationCode{}
if err := json.Unmarshal(decodedActivationCode, &activationCode); err != nil {
return time.Time{}, fmt.Errorf("activation code is not valid JSON")
}
// Decode the signature
decodedSignature, err := base64.StdEncoding.DecodeString(activationCode.Signature)
if err != nil {
return time.Time{}, fmt.Errorf("signature is not base64 encoded")
}
// Compute the sha256 checksum of the token
hashedToken := sha256.Sum256([]byte(activationCode.Token))
// Verify that the signature is valid
if err := rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, hashedToken[:], decodedSignature); err != nil {
return time.Time{}, fmt.Errorf("invalid signature in activation code")
}
// Unmarshal the token
token := token{}
if err := json.Unmarshal([]byte(activationCode.Token), &token); err != nil {
return time.Time{}, fmt.Errorf("token is not valid JSON")
}
// Parse the expiration. Note that this string is generated by Date.toJSON()
// running in node, so Go's definition of RFC 3339 timestamps (which is
// incomplete) must be compatible with the strings that node generates. So far
// it seems to work.
expiration, err = time.Parse(time.RFC3339, token.Expiry)
if err != nil {
return time.Time{}, fmt.Errorf("expiration is not valid ISO 8601 string")
}
// Check that the activation code has not expired
if time.Now().After(expiration) {
return time.Time{}, fmt.Errorf("the activation code has expired")
}
return expiration, nil
}
|
go
|
func validateActivationCode(code string) (expiration time.Time, err error) {
// Parse the public key. If these steps fail, something is seriously
// wrong and we should crash the service by panicking.
block, _ := pem.Decode([]byte(publicKey))
if block == nil {
return time.Time{}, fmt.Errorf("failed to pem decode public key")
}
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return time.Time{}, fmt.Errorf("failed to parse DER encoded public key: %s", err.Error())
}
rsaPub, ok := pub.(*rsa.PublicKey)
if !ok {
return time.Time{}, fmt.Errorf("public key isn't an RSA key")
}
// Decode the base64-encoded activation code
decodedActivationCode, err := base64.StdEncoding.DecodeString(code)
if err != nil {
return time.Time{}, fmt.Errorf("activation code is not base64 encoded")
}
activationCode := &activationCode{}
if err := json.Unmarshal(decodedActivationCode, &activationCode); err != nil {
return time.Time{}, fmt.Errorf("activation code is not valid JSON")
}
// Decode the signature
decodedSignature, err := base64.StdEncoding.DecodeString(activationCode.Signature)
if err != nil {
return time.Time{}, fmt.Errorf("signature is not base64 encoded")
}
// Compute the sha256 checksum of the token
hashedToken := sha256.Sum256([]byte(activationCode.Token))
// Verify that the signature is valid
if err := rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, hashedToken[:], decodedSignature); err != nil {
return time.Time{}, fmt.Errorf("invalid signature in activation code")
}
// Unmarshal the token
token := token{}
if err := json.Unmarshal([]byte(activationCode.Token), &token); err != nil {
return time.Time{}, fmt.Errorf("token is not valid JSON")
}
// Parse the expiration. Note that this string is generated by Date.toJSON()
// running in node, so Go's definition of RFC 3339 timestamps (which is
// incomplete) must be compatible with the strings that node generates. So far
// it seems to work.
expiration, err = time.Parse(time.RFC3339, token.Expiry)
if err != nil {
return time.Time{}, fmt.Errorf("expiration is not valid ISO 8601 string")
}
// Check that the activation code has not expired
if time.Now().After(expiration) {
return time.Time{}, fmt.Errorf("the activation code has expired")
}
return expiration, nil
}
|
[
"func",
"validateActivationCode",
"(",
"code",
"string",
")",
"(",
"expiration",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"block",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"[",
"]",
"byte",
"(",
"publicKey",
")",
")",
"\n",
"if",
"block",
"==",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to pem decode public key\"",
")",
"\n",
"}",
"\n",
"pub",
",",
"err",
":=",
"x509",
".",
"ParsePKIXPublicKey",
"(",
"block",
".",
"Bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to parse DER encoded public key: %s\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"rsaPub",
",",
"ok",
":=",
"pub",
".",
"(",
"*",
"rsa",
".",
"PublicKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"public key isn't an RSA key\"",
")",
"\n",
"}",
"\n",
"decodedActivationCode",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"code",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"activation code is not base64 encoded\"",
")",
"\n",
"}",
"\n",
"activationCode",
":=",
"&",
"activationCode",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"decodedActivationCode",
",",
"&",
"activationCode",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"activation code is not valid JSON\"",
")",
"\n",
"}",
"\n",
"decodedSignature",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"activationCode",
".",
"Signature",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"signature is not base64 encoded\"",
")",
"\n",
"}",
"\n",
"hashedToken",
":=",
"sha256",
".",
"Sum256",
"(",
"[",
"]",
"byte",
"(",
"activationCode",
".",
"Token",
")",
")",
"\n",
"if",
"err",
":=",
"rsa",
".",
"VerifyPKCS1v15",
"(",
"rsaPub",
",",
"crypto",
".",
"SHA256",
",",
"hashedToken",
"[",
":",
"]",
",",
"decodedSignature",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"invalid signature in activation code\"",
")",
"\n",
"}",
"\n",
"token",
":=",
"token",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"activationCode",
".",
"Token",
")",
",",
"&",
"token",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"token is not valid JSON\"",
")",
"\n",
"}",
"\n",
"expiration",
",",
"err",
"=",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC3339",
",",
"token",
".",
"Expiry",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"expiration is not valid ISO 8601 string\"",
")",
"\n",
"}",
"\n",
"if",
"time",
".",
"Now",
"(",
")",
".",
"After",
"(",
"expiration",
")",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"the activation code has expired\"",
")",
"\n",
"}",
"\n",
"return",
"expiration",
",",
"nil",
"\n",
"}"
] |
// validateActivationCode checks the validity of an activation code
|
[
"validateActivationCode",
"checks",
"the",
"validity",
"of",
"an",
"activation",
"code"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/enterprise/server/api_server.go#L143-L202
|
test
|
pachyderm/pachyderm
|
src/server/enterprise/server/api_server.go
|
Activate
|
func (a *apiServer) Activate(ctx context.Context, req *ec.ActivateRequest) (resp *ec.ActivateResponse, retErr error) {
a.LogReq(req)
defer func(start time.Time) { a.pachLogger.Log(req, resp, retErr, time.Since(start)) }(time.Now())
// Validate the activation code
expiration, err := validateActivationCode(req.ActivationCode)
if err != nil {
return nil, fmt.Errorf("error validating activation code: %s", err.Error())
}
// Allow request to override expiration in the activation code, for testing
if req.Expires != nil {
customExpiration, err := types.TimestampFromProto(req.Expires)
if err == nil && expiration.After(customExpiration) {
expiration = customExpiration
}
}
expirationProto, err := types.TimestampProto(expiration)
if err != nil {
return nil, fmt.Errorf("could not convert expiration time \"%s\" to proto: %s", expiration.String(), err.Error())
}
if _, err := col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
e := a.enterpriseToken.ReadWrite(stm)
// blind write
return e.Put(enterpriseTokenKey, &ec.EnterpriseRecord{
ActivationCode: req.ActivationCode,
Expires: expirationProto,
})
}); err != nil {
return nil, err
}
// Wait until watcher observes the write
if err := backoff.Retry(func() error {
if t := a.enterpriseExpiration.Load().(time.Time); t.IsZero() {
return fmt.Errorf("enterprise not activated")
}
return nil
}, backoff.RetryEvery(time.Second)); err != nil {
return nil, err
}
time.Sleep(time.Second) // give other pachd nodes time to observe the write
return &ec.ActivateResponse{
Info: &ec.TokenInfo{
Expires: expirationProto,
},
}, nil
}
|
go
|
func (a *apiServer) Activate(ctx context.Context, req *ec.ActivateRequest) (resp *ec.ActivateResponse, retErr error) {
a.LogReq(req)
defer func(start time.Time) { a.pachLogger.Log(req, resp, retErr, time.Since(start)) }(time.Now())
// Validate the activation code
expiration, err := validateActivationCode(req.ActivationCode)
if err != nil {
return nil, fmt.Errorf("error validating activation code: %s", err.Error())
}
// Allow request to override expiration in the activation code, for testing
if req.Expires != nil {
customExpiration, err := types.TimestampFromProto(req.Expires)
if err == nil && expiration.After(customExpiration) {
expiration = customExpiration
}
}
expirationProto, err := types.TimestampProto(expiration)
if err != nil {
return nil, fmt.Errorf("could not convert expiration time \"%s\" to proto: %s", expiration.String(), err.Error())
}
if _, err := col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
e := a.enterpriseToken.ReadWrite(stm)
// blind write
return e.Put(enterpriseTokenKey, &ec.EnterpriseRecord{
ActivationCode: req.ActivationCode,
Expires: expirationProto,
})
}); err != nil {
return nil, err
}
// Wait until watcher observes the write
if err := backoff.Retry(func() error {
if t := a.enterpriseExpiration.Load().(time.Time); t.IsZero() {
return fmt.Errorf("enterprise not activated")
}
return nil
}, backoff.RetryEvery(time.Second)); err != nil {
return nil, err
}
time.Sleep(time.Second) // give other pachd nodes time to observe the write
return &ec.ActivateResponse{
Info: &ec.TokenInfo{
Expires: expirationProto,
},
}, nil
}
|
[
"func",
"(",
"a",
"*",
"apiServer",
")",
"Activate",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"ec",
".",
"ActivateRequest",
")",
"(",
"resp",
"*",
"ec",
".",
"ActivateResponse",
",",
"retErr",
"error",
")",
"{",
"a",
".",
"LogReq",
"(",
"req",
")",
"\n",
"defer",
"func",
"(",
"start",
"time",
".",
"Time",
")",
"{",
"a",
".",
"pachLogger",
".",
"Log",
"(",
"req",
",",
"resp",
",",
"retErr",
",",
"time",
".",
"Since",
"(",
"start",
")",
")",
"}",
"(",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"expiration",
",",
"err",
":=",
"validateActivationCode",
"(",
"req",
".",
"ActivationCode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"error validating activation code: %s\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"req",
".",
"Expires",
"!=",
"nil",
"{",
"customExpiration",
",",
"err",
":=",
"types",
".",
"TimestampFromProto",
"(",
"req",
".",
"Expires",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"expiration",
".",
"After",
"(",
"customExpiration",
")",
"{",
"expiration",
"=",
"customExpiration",
"\n",
"}",
"\n",
"}",
"\n",
"expirationProto",
",",
"err",
":=",
"types",
".",
"TimestampProto",
"(",
"expiration",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"could not convert expiration time \\\"%s\\\" to proto: %s\"",
",",
"\\\"",
",",
"\\\"",
")",
"\n",
"}",
"\n",
"expiration",
".",
"String",
"(",
")",
"\n",
"err",
".",
"Error",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"col",
".",
"NewSTM",
"(",
"ctx",
",",
"a",
".",
"env",
".",
"GetEtcdClient",
"(",
")",
",",
"func",
"(",
"stm",
"col",
".",
"STM",
")",
"error",
"{",
"e",
":=",
"a",
".",
"enterpriseToken",
".",
"ReadWrite",
"(",
"stm",
")",
"\n",
"return",
"e",
".",
"Put",
"(",
"enterpriseTokenKey",
",",
"&",
"ec",
".",
"EnterpriseRecord",
"{",
"ActivationCode",
":",
"req",
".",
"ActivationCode",
",",
"Expires",
":",
"expirationProto",
",",
"}",
")",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"backoff",
".",
"Retry",
"(",
"func",
"(",
")",
"error",
"{",
"if",
"t",
":=",
"a",
".",
"enterpriseExpiration",
".",
"Load",
"(",
")",
".",
"(",
"time",
".",
"Time",
")",
";",
"t",
".",
"IsZero",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"enterprise not activated\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
",",
"backoff",
".",
"RetryEvery",
"(",
"time",
".",
"Second",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}"
] |
// Activate implements the Activate RPC
|
[
"Activate",
"implements",
"the",
"Activate",
"RPC"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/enterprise/server/api_server.go#L205-L252
|
test
|
pachyderm/pachyderm
|
src/server/enterprise/server/api_server.go
|
Deactivate
|
func (a *apiServer) Deactivate(ctx context.Context, req *ec.DeactivateRequest) (resp *ec.DeactivateResponse, retErr error) {
a.LogReq(req)
defer func(start time.Time) { a.pachLogger.Log(req, resp, retErr, time.Since(start)) }(time.Now())
pachClient := a.env.GetPachClient(ctx)
if err := pachClient.DeleteAll(); err != nil {
return nil, fmt.Errorf("could not delete all pachyderm data: %v", err)
}
if _, err := col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
// blind delete
return a.enterpriseToken.ReadWrite(stm).Delete(enterpriseTokenKey)
}); err != nil {
return nil, err
}
// Wait until watcher observes the write
if err := backoff.Retry(func() error {
if t := a.enterpriseExpiration.Load().(time.Time); !t.IsZero() {
return fmt.Errorf("enterprise still activated")
}
return nil
}, backoff.RetryEvery(time.Second)); err != nil {
return nil, err
}
time.Sleep(time.Second) // give other pachd nodes time to observe the write
return &ec.DeactivateResponse{}, nil
}
|
go
|
func (a *apiServer) Deactivate(ctx context.Context, req *ec.DeactivateRequest) (resp *ec.DeactivateResponse, retErr error) {
a.LogReq(req)
defer func(start time.Time) { a.pachLogger.Log(req, resp, retErr, time.Since(start)) }(time.Now())
pachClient := a.env.GetPachClient(ctx)
if err := pachClient.DeleteAll(); err != nil {
return nil, fmt.Errorf("could not delete all pachyderm data: %v", err)
}
if _, err := col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
// blind delete
return a.enterpriseToken.ReadWrite(stm).Delete(enterpriseTokenKey)
}); err != nil {
return nil, err
}
// Wait until watcher observes the write
if err := backoff.Retry(func() error {
if t := a.enterpriseExpiration.Load().(time.Time); !t.IsZero() {
return fmt.Errorf("enterprise still activated")
}
return nil
}, backoff.RetryEvery(time.Second)); err != nil {
return nil, err
}
time.Sleep(time.Second) // give other pachd nodes time to observe the write
return &ec.DeactivateResponse{}, nil
}
|
[
"func",
"(",
"a",
"*",
"apiServer",
")",
"Deactivate",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"ec",
".",
"DeactivateRequest",
")",
"(",
"resp",
"*",
"ec",
".",
"DeactivateResponse",
",",
"retErr",
"error",
")",
"{",
"a",
".",
"LogReq",
"(",
"req",
")",
"\n",
"defer",
"func",
"(",
"start",
"time",
".",
"Time",
")",
"{",
"a",
".",
"pachLogger",
".",
"Log",
"(",
"req",
",",
"resp",
",",
"retErr",
",",
"time",
".",
"Since",
"(",
"start",
")",
")",
"}",
"(",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"pachClient",
":=",
"a",
".",
"env",
".",
"GetPachClient",
"(",
"ctx",
")",
"\n",
"if",
"err",
":=",
"pachClient",
".",
"DeleteAll",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"could not delete all pachyderm data: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"col",
".",
"NewSTM",
"(",
"ctx",
",",
"a",
".",
"env",
".",
"GetEtcdClient",
"(",
")",
",",
"func",
"(",
"stm",
"col",
".",
"STM",
")",
"error",
"{",
"return",
"a",
".",
"enterpriseToken",
".",
"ReadWrite",
"(",
"stm",
")",
".",
"Delete",
"(",
"enterpriseTokenKey",
")",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"backoff",
".",
"Retry",
"(",
"func",
"(",
")",
"error",
"{",
"if",
"t",
":=",
"a",
".",
"enterpriseExpiration",
".",
"Load",
"(",
")",
".",
"(",
"time",
".",
"Time",
")",
";",
"!",
"t",
".",
"IsZero",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"enterprise still activated\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
",",
"backoff",
".",
"RetryEvery",
"(",
"time",
".",
"Second",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"return",
"&",
"ec",
".",
"DeactivateResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] |
// Deactivate deletes the current cluster's enterprise token, and puts the
// cluster in the "NONE" enterprise state. It also deletes all data in the
// cluster, to avoid invalid cluster states. This call only makes sense for
// testing
|
[
"Deactivate",
"deletes",
"the",
"current",
"cluster",
"s",
"enterprise",
"token",
"and",
"puts",
"the",
"cluster",
"in",
"the",
"NONE",
"enterprise",
"state",
".",
"It",
"also",
"deletes",
"all",
"data",
"in",
"the",
"cluster",
"to",
"avoid",
"invalid",
"cluster",
"states",
".",
"This",
"call",
"only",
"makes",
"sense",
"for",
"testing"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/enterprise/server/api_server.go#L287-L315
|
test
|
pachyderm/pachyderm
|
src/server/pkg/exec/exec.go
|
lookExtensions
|
func lookExtensions(path, dir string) (string, error) {
if filepath.Base(path) == path {
path = filepath.Join(".", path)
}
if dir == "" {
return exec.LookPath(path)
}
if filepath.VolumeName(path) != "" {
return exec.LookPath(path)
}
if len(path) > 1 && os.IsPathSeparator(path[0]) {
return exec.LookPath(path)
}
dirandpath := filepath.Join(dir, path)
// We assume that LookPath will only add file extension.
lp, err := exec.LookPath(dirandpath)
if err != nil {
return "", err
}
ext := strings.TrimPrefix(lp, dirandpath)
return path + ext, nil
}
|
go
|
func lookExtensions(path, dir string) (string, error) {
if filepath.Base(path) == path {
path = filepath.Join(".", path)
}
if dir == "" {
return exec.LookPath(path)
}
if filepath.VolumeName(path) != "" {
return exec.LookPath(path)
}
if len(path) > 1 && os.IsPathSeparator(path[0]) {
return exec.LookPath(path)
}
dirandpath := filepath.Join(dir, path)
// We assume that LookPath will only add file extension.
lp, err := exec.LookPath(dirandpath)
if err != nil {
return "", err
}
ext := strings.TrimPrefix(lp, dirandpath)
return path + ext, nil
}
|
[
"func",
"lookExtensions",
"(",
"path",
",",
"dir",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"filepath",
".",
"Base",
"(",
"path",
")",
"==",
"path",
"{",
"path",
"=",
"filepath",
".",
"Join",
"(",
"\".\"",
",",
"path",
")",
"\n",
"}",
"\n",
"if",
"dir",
"==",
"\"\"",
"{",
"return",
"exec",
".",
"LookPath",
"(",
"path",
")",
"\n",
"}",
"\n",
"if",
"filepath",
".",
"VolumeName",
"(",
"path",
")",
"!=",
"\"\"",
"{",
"return",
"exec",
".",
"LookPath",
"(",
"path",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"path",
")",
">",
"1",
"&&",
"os",
".",
"IsPathSeparator",
"(",
"path",
"[",
"0",
"]",
")",
"{",
"return",
"exec",
".",
"LookPath",
"(",
"path",
")",
"\n",
"}",
"\n",
"dirandpath",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"path",
")",
"\n",
"lp",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"dirandpath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"ext",
":=",
"strings",
".",
"TrimPrefix",
"(",
"lp",
",",
"dirandpath",
")",
"\n",
"return",
"path",
"+",
"ext",
",",
"nil",
"\n",
"}"
] |
// lookExtensions finds windows executable by its dir and path.
// It uses LookPath to try appropriate extensions.
// lookExtensions does not search PATH, instead it converts `prog` into `.\prog`.
|
[
"lookExtensions",
"finds",
"windows",
"executable",
"by",
"its",
"dir",
"and",
"path",
".",
"It",
"uses",
"LookPath",
"to",
"try",
"appropriate",
"extensions",
".",
"lookExtensions",
"does",
"not",
"search",
"PATH",
"instead",
"it",
"converts",
"prog",
"into",
".",
"\\",
"prog",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/exec/exec.go#L296-L317
|
test
|
pachyderm/pachyderm
|
src/server/pkg/exec/exec.go
|
Start
|
func (c *Cmd) Start() error {
if c.lookPathErr != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return c.lookPathErr
}
if runtime.GOOS == "windows" {
lp, err := lookExtensions(c.Path, c.Dir)
if err != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return err
}
c.Path = lp
}
if c.Process != nil {
return errors.New("exec: already started")
}
if c.ctx != nil {
select {
case <-c.ctx.Done():
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return c.ctx.Err()
default:
}
}
type F func(*Cmd) (*os.File, error)
for _, setupFd := range []F{(*Cmd).stdin, (*Cmd).stdout, (*Cmd).stderr} {
fd, err := setupFd(c)
if err != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return err
}
c.childFiles = append(c.childFiles, fd)
}
c.childFiles = append(c.childFiles, c.ExtraFiles...)
var err error
c.Process, err = os.StartProcess(c.Path, c.argv(), &os.ProcAttr{
Dir: c.Dir,
Files: c.childFiles,
Env: dedupEnv(c.envv()),
Sys: c.SysProcAttr,
})
if err != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return err
}
c.closeDescriptors(c.closeAfterStart)
c.errch = make(chan error, len(c.goroutine))
for _, fn := range c.goroutine {
go func(fn func() error) {
c.errch <- fn()
}(fn)
}
if c.ctx != nil {
c.waitDone = make(chan struct{})
go func() {
select {
case <-c.ctx.Done():
c.Process.Kill()
case <-c.waitDone:
}
}()
}
return nil
}
|
go
|
func (c *Cmd) Start() error {
if c.lookPathErr != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return c.lookPathErr
}
if runtime.GOOS == "windows" {
lp, err := lookExtensions(c.Path, c.Dir)
if err != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return err
}
c.Path = lp
}
if c.Process != nil {
return errors.New("exec: already started")
}
if c.ctx != nil {
select {
case <-c.ctx.Done():
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return c.ctx.Err()
default:
}
}
type F func(*Cmd) (*os.File, error)
for _, setupFd := range []F{(*Cmd).stdin, (*Cmd).stdout, (*Cmd).stderr} {
fd, err := setupFd(c)
if err != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return err
}
c.childFiles = append(c.childFiles, fd)
}
c.childFiles = append(c.childFiles, c.ExtraFiles...)
var err error
c.Process, err = os.StartProcess(c.Path, c.argv(), &os.ProcAttr{
Dir: c.Dir,
Files: c.childFiles,
Env: dedupEnv(c.envv()),
Sys: c.SysProcAttr,
})
if err != nil {
c.closeDescriptors(c.closeAfterStart)
c.closeDescriptors(c.closeAfterWait)
return err
}
c.closeDescriptors(c.closeAfterStart)
c.errch = make(chan error, len(c.goroutine))
for _, fn := range c.goroutine {
go func(fn func() error) {
c.errch <- fn()
}(fn)
}
if c.ctx != nil {
c.waitDone = make(chan struct{})
go func() {
select {
case <-c.ctx.Done():
c.Process.Kill()
case <-c.waitDone:
}
}()
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Cmd",
")",
"Start",
"(",
")",
"error",
"{",
"if",
"c",
".",
"lookPathErr",
"!=",
"nil",
"{",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterStart",
")",
"\n",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterWait",
")",
"\n",
"return",
"c",
".",
"lookPathErr",
"\n",
"}",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"windows\"",
"{",
"lp",
",",
"err",
":=",
"lookExtensions",
"(",
"c",
".",
"Path",
",",
"c",
".",
"Dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterStart",
")",
"\n",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterWait",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"Path",
"=",
"lp",
"\n",
"}",
"\n",
"if",
"c",
".",
"Process",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"exec: already started\"",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"ctx",
"!=",
"nil",
"{",
"select",
"{",
"case",
"<-",
"c",
".",
"ctx",
".",
"Done",
"(",
")",
":",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterStart",
")",
"\n",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterWait",
")",
"\n",
"return",
"c",
".",
"ctx",
".",
"Err",
"(",
")",
"\n",
"default",
":",
"}",
"\n",
"}",
"\n",
"type",
"F",
"func",
"(",
"*",
"Cmd",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"\n",
"for",
"_",
",",
"setupFd",
":=",
"range",
"[",
"]",
"F",
"{",
"(",
"*",
"Cmd",
")",
".",
"stdin",
",",
"(",
"*",
"Cmd",
")",
".",
"stdout",
",",
"(",
"*",
"Cmd",
")",
".",
"stderr",
"}",
"{",
"fd",
",",
"err",
":=",
"setupFd",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterStart",
")",
"\n",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterWait",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"childFiles",
"=",
"append",
"(",
"c",
".",
"childFiles",
",",
"fd",
")",
"\n",
"}",
"\n",
"c",
".",
"childFiles",
"=",
"append",
"(",
"c",
".",
"childFiles",
",",
"c",
".",
"ExtraFiles",
"...",
")",
"\n",
"var",
"err",
"error",
"\n",
"c",
".",
"Process",
",",
"err",
"=",
"os",
".",
"StartProcess",
"(",
"c",
".",
"Path",
",",
"c",
".",
"argv",
"(",
")",
",",
"&",
"os",
".",
"ProcAttr",
"{",
"Dir",
":",
"c",
".",
"Dir",
",",
"Files",
":",
"c",
".",
"childFiles",
",",
"Env",
":",
"dedupEnv",
"(",
"c",
".",
"envv",
"(",
")",
")",
",",
"Sys",
":",
"c",
".",
"SysProcAttr",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterStart",
")",
"\n",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterWait",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"closeDescriptors",
"(",
"c",
".",
"closeAfterStart",
")",
"\n",
"c",
".",
"errch",
"=",
"make",
"(",
"chan",
"error",
",",
"len",
"(",
"c",
".",
"goroutine",
")",
")",
"\n",
"for",
"_",
",",
"fn",
":=",
"range",
"c",
".",
"goroutine",
"{",
"go",
"func",
"(",
"fn",
"func",
"(",
")",
"error",
")",
"{",
"c",
".",
"errch",
"<-",
"fn",
"(",
")",
"\n",
"}",
"(",
"fn",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"ctx",
"!=",
"nil",
"{",
"c",
".",
"waitDone",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"c",
".",
"ctx",
".",
"Done",
"(",
")",
":",
"c",
".",
"Process",
".",
"Kill",
"(",
")",
"\n",
"case",
"<-",
"c",
".",
"waitDone",
":",
"}",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Start starts the specified command but does not wait for it to complete.
//
// The Wait method will return the exit code and release associated resources
// once the command exits.
|
[
"Start",
"starts",
"the",
"specified",
"command",
"but",
"does",
"not",
"wait",
"for",
"it",
"to",
"complete",
".",
"The",
"Wait",
"method",
"will",
"return",
"the",
"exit",
"code",
"and",
"release",
"associated",
"resources",
"once",
"the",
"command",
"exits",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/exec/exec.go#L323-L397
|
test
|
pachyderm/pachyderm
|
src/server/pkg/exec/exec.go
|
CombinedOutput
|
func (c *Cmd) CombinedOutput() ([]byte, error) {
if c.Stdout != nil {
return nil, errors.New("exec: Stdout already set")
}
if c.Stderr != nil {
return nil, errors.New("exec: Stderr already set")
}
var b bytes.Buffer
c.Stdout = &b
c.Stderr = &b
err := c.Run()
return b.Bytes(), err
}
|
go
|
func (c *Cmd) CombinedOutput() ([]byte, error) {
if c.Stdout != nil {
return nil, errors.New("exec: Stdout already set")
}
if c.Stderr != nil {
return nil, errors.New("exec: Stderr already set")
}
var b bytes.Buffer
c.Stdout = &b
c.Stderr = &b
err := c.Run()
return b.Bytes(), err
}
|
[
"func",
"(",
"c",
"*",
"Cmd",
")",
"CombinedOutput",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"c",
".",
"Stdout",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"exec: Stdout already set\"",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"Stderr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"exec: Stderr already set\"",
")",
"\n",
"}",
"\n",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"c",
".",
"Stdout",
"=",
"&",
"b",
"\n",
"c",
".",
"Stderr",
"=",
"&",
"b",
"\n",
"err",
":=",
"c",
".",
"Run",
"(",
")",
"\n",
"return",
"b",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
] |
// CombinedOutput runs the command and returns its combined standard
// output and standard error.
|
[
"CombinedOutput",
"runs",
"the",
"command",
"and",
"returns",
"its",
"combined",
"standard",
"output",
"and",
"standard",
"error",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/exec/exec.go#L500-L512
|
test
|
pachyderm/pachyderm
|
src/server/pkg/exec/exec.go
|
StdinPipe
|
func (c *Cmd) StdinPipe() (io.WriteCloser, error) {
if c.Stdin != nil {
return nil, errors.New("exec: Stdin already set")
}
if c.Process != nil {
return nil, errors.New("exec: StdinPipe after process started")
}
pr, pw, err := os.Pipe()
if err != nil {
return nil, err
}
c.Stdin = pr
c.closeAfterStart = append(c.closeAfterStart, pr)
wc := &closeOnce{File: pw}
c.closeAfterWait = append(c.closeAfterWait, closerFunc(wc.safeClose))
return wc, nil
}
|
go
|
func (c *Cmd) StdinPipe() (io.WriteCloser, error) {
if c.Stdin != nil {
return nil, errors.New("exec: Stdin already set")
}
if c.Process != nil {
return nil, errors.New("exec: StdinPipe after process started")
}
pr, pw, err := os.Pipe()
if err != nil {
return nil, err
}
c.Stdin = pr
c.closeAfterStart = append(c.closeAfterStart, pr)
wc := &closeOnce{File: pw}
c.closeAfterWait = append(c.closeAfterWait, closerFunc(wc.safeClose))
return wc, nil
}
|
[
"func",
"(",
"c",
"*",
"Cmd",
")",
"StdinPipe",
"(",
")",
"(",
"io",
".",
"WriteCloser",
",",
"error",
")",
"{",
"if",
"c",
".",
"Stdin",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"exec: Stdin already set\"",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"Process",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"exec: StdinPipe after process started\"",
")",
"\n",
"}",
"\n",
"pr",
",",
"pw",
",",
"err",
":=",
"os",
".",
"Pipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"Stdin",
"=",
"pr",
"\n",
"c",
".",
"closeAfterStart",
"=",
"append",
"(",
"c",
".",
"closeAfterStart",
",",
"pr",
")",
"\n",
"wc",
":=",
"&",
"closeOnce",
"{",
"File",
":",
"pw",
"}",
"\n",
"c",
".",
"closeAfterWait",
"=",
"append",
"(",
"c",
".",
"closeAfterWait",
",",
"closerFunc",
"(",
"wc",
".",
"safeClose",
")",
")",
"\n",
"return",
"wc",
",",
"nil",
"\n",
"}"
] |
// StdinPipe returns a pipe that will be connected to the command's
// standard input when the command starts.
// The pipe will be closed automatically after Wait sees the command exit.
// A caller need only call Close to force the pipe to close sooner.
// For example, if the command being run will not exit until standard input
// is closed, the caller must close the pipe.
|
[
"StdinPipe",
"returns",
"a",
"pipe",
"that",
"will",
"be",
"connected",
"to",
"the",
"command",
"s",
"standard",
"input",
"when",
"the",
"command",
"starts",
".",
"The",
"pipe",
"will",
"be",
"closed",
"automatically",
"after",
"Wait",
"sees",
"the",
"command",
"exit",
".",
"A",
"caller",
"need",
"only",
"call",
"Close",
"to",
"force",
"the",
"pipe",
"to",
"close",
"sooner",
".",
"For",
"example",
"if",
"the",
"command",
"being",
"run",
"will",
"not",
"exit",
"until",
"standard",
"input",
"is",
"closed",
"the",
"caller",
"must",
"close",
"the",
"pipe",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/exec/exec.go#L520-L536
|
test
|
pachyderm/pachyderm
|
src/server/pkg/exec/exec.go
|
StdoutPipe
|
func (c *Cmd) StdoutPipe() (io.ReadCloser, error) {
if c.Stdout != nil {
return nil, errors.New("exec: Stdout already set")
}
if c.Process != nil {
return nil, errors.New("exec: StdoutPipe after process started")
}
pr, pw, err := os.Pipe()
if err != nil {
return nil, err
}
c.Stdout = pw
c.closeAfterStart = append(c.closeAfterStart, pw)
c.closeAfterWait = append(c.closeAfterWait, pr)
return pr, nil
}
|
go
|
func (c *Cmd) StdoutPipe() (io.ReadCloser, error) {
if c.Stdout != nil {
return nil, errors.New("exec: Stdout already set")
}
if c.Process != nil {
return nil, errors.New("exec: StdoutPipe after process started")
}
pr, pw, err := os.Pipe()
if err != nil {
return nil, err
}
c.Stdout = pw
c.closeAfterStart = append(c.closeAfterStart, pw)
c.closeAfterWait = append(c.closeAfterWait, pr)
return pr, nil
}
|
[
"func",
"(",
"c",
"*",
"Cmd",
")",
"StdoutPipe",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"c",
".",
"Stdout",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"exec: Stdout already set\"",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"Process",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"exec: StdoutPipe after process started\"",
")",
"\n",
"}",
"\n",
"pr",
",",
"pw",
",",
"err",
":=",
"os",
".",
"Pipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"Stdout",
"=",
"pw",
"\n",
"c",
".",
"closeAfterStart",
"=",
"append",
"(",
"c",
".",
"closeAfterStart",
",",
"pw",
")",
"\n",
"c",
".",
"closeAfterWait",
"=",
"append",
"(",
"c",
".",
"closeAfterWait",
",",
"pr",
")",
"\n",
"return",
"pr",
",",
"nil",
"\n",
"}"
] |
// StdoutPipe returns a pipe that will be connected to the command's
// standard output when the command starts.
//
// Wait will close the pipe after seeing the command exit, so most callers
// need not close the pipe themselves; however, an implication is that
// it is incorrect to call Wait before all reads from the pipe have completed.
// For the same reason, it is incorrect to call Run when using StdoutPipe.
// See the example for idiomatic usage.
|
[
"StdoutPipe",
"returns",
"a",
"pipe",
"that",
"will",
"be",
"connected",
"to",
"the",
"command",
"s",
"standard",
"output",
"when",
"the",
"command",
"starts",
".",
"Wait",
"will",
"close",
"the",
"pipe",
"after",
"seeing",
"the",
"command",
"exit",
"so",
"most",
"callers",
"need",
"not",
"close",
"the",
"pipe",
"themselves",
";",
"however",
"an",
"implication",
"is",
"that",
"it",
"is",
"incorrect",
"to",
"call",
"Wait",
"before",
"all",
"reads",
"from",
"the",
"pipe",
"have",
"completed",
".",
"For",
"the",
"same",
"reason",
"it",
"is",
"incorrect",
"to",
"call",
"Run",
"when",
"using",
"StdoutPipe",
".",
"See",
"the",
"example",
"for",
"idiomatic",
"usage",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/exec/exec.go#L612-L627
|
test
|
pachyderm/pachyderm
|
src/server/pkg/exec/exec.go
|
dedupEnvCase
|
func dedupEnvCase(caseInsensitive bool, env []string) []string {
out := make([]string, 0, len(env))
saw := map[string]int{} // key => index into out
for _, kv := range env {
eq := strings.Index(kv, "=")
if eq < 0 {
out = append(out, kv)
continue
}
k := kv[:eq]
if caseInsensitive {
k = strings.ToLower(k)
}
if dupIdx, isDup := saw[k]; isDup {
out[dupIdx] = kv
continue
}
saw[k] = len(out)
out = append(out, kv)
}
return out
}
|
go
|
func dedupEnvCase(caseInsensitive bool, env []string) []string {
out := make([]string, 0, len(env))
saw := map[string]int{} // key => index into out
for _, kv := range env {
eq := strings.Index(kv, "=")
if eq < 0 {
out = append(out, kv)
continue
}
k := kv[:eq]
if caseInsensitive {
k = strings.ToLower(k)
}
if dupIdx, isDup := saw[k]; isDup {
out[dupIdx] = kv
continue
}
saw[k] = len(out)
out = append(out, kv)
}
return out
}
|
[
"func",
"dedupEnvCase",
"(",
"caseInsensitive",
"bool",
",",
"env",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"env",
")",
")",
"\n",
"saw",
":=",
"map",
"[",
"string",
"]",
"int",
"{",
"}",
"\n",
"for",
"_",
",",
"kv",
":=",
"range",
"env",
"{",
"eq",
":=",
"strings",
".",
"Index",
"(",
"kv",
",",
"\"=\"",
")",
"\n",
"if",
"eq",
"<",
"0",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"kv",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"k",
":=",
"kv",
"[",
":",
"eq",
"]",
"\n",
"if",
"caseInsensitive",
"{",
"k",
"=",
"strings",
".",
"ToLower",
"(",
"k",
")",
"\n",
"}",
"\n",
"if",
"dupIdx",
",",
"isDup",
":=",
"saw",
"[",
"k",
"]",
";",
"isDup",
"{",
"out",
"[",
"dupIdx",
"]",
"=",
"kv",
"\n",
"continue",
"\n",
"}",
"\n",
"saw",
"[",
"k",
"]",
"=",
"len",
"(",
"out",
")",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"kv",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] |
// dedupEnvCase is dedupEnv with a case option for testing.
// If caseInsensitive is true, the case of keys is ignored.
|
[
"dedupEnvCase",
"is",
"dedupEnv",
"with",
"a",
"case",
"option",
"for",
"testing",
".",
"If",
"caseInsensitive",
"is",
"true",
"the",
"case",
"of",
"keys",
"is",
"ignored",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/exec/exec.go#L740-L761
|
test
|
pachyderm/pachyderm
|
src/client/pps/util.go
|
InputName
|
func InputName(input *Input) string {
switch {
case input == nil:
return ""
case input.Pfs != nil:
return input.Pfs.Name
case input.Cross != nil:
if len(input.Cross) > 0 {
return InputName(input.Cross[0])
}
case input.Union != nil:
if len(input.Union) > 0 {
return InputName(input.Union[0])
}
}
return ""
}
|
go
|
func InputName(input *Input) string {
switch {
case input == nil:
return ""
case input.Pfs != nil:
return input.Pfs.Name
case input.Cross != nil:
if len(input.Cross) > 0 {
return InputName(input.Cross[0])
}
case input.Union != nil:
if len(input.Union) > 0 {
return InputName(input.Union[0])
}
}
return ""
}
|
[
"func",
"InputName",
"(",
"input",
"*",
"Input",
")",
"string",
"{",
"switch",
"{",
"case",
"input",
"==",
"nil",
":",
"return",
"\"\"",
"\n",
"case",
"input",
".",
"Pfs",
"!=",
"nil",
":",
"return",
"input",
".",
"Pfs",
".",
"Name",
"\n",
"case",
"input",
".",
"Cross",
"!=",
"nil",
":",
"if",
"len",
"(",
"input",
".",
"Cross",
")",
">",
"0",
"{",
"return",
"InputName",
"(",
"input",
".",
"Cross",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"case",
"input",
".",
"Union",
"!=",
"nil",
":",
"if",
"len",
"(",
"input",
".",
"Union",
")",
">",
"0",
"{",
"return",
"InputName",
"(",
"input",
".",
"Union",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"\"",
"\n",
"}"
] |
// InputName computes the name of an Input.
|
[
"InputName",
"computes",
"the",
"name",
"of",
"an",
"Input",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pps/util.go#L31-L47
|
test
|
pachyderm/pachyderm
|
src/client/pps/util.go
|
SortInput
|
func SortInput(input *Input) {
VisitInput(input, func(input *Input) {
SortInputs := func(inputs []*Input) {
sort.SliceStable(inputs, func(i, j int) bool { return InputName(inputs[i]) < InputName(inputs[j]) })
}
switch {
case input.Cross != nil:
SortInputs(input.Cross)
case input.Union != nil:
SortInputs(input.Union)
}
})
}
|
go
|
func SortInput(input *Input) {
VisitInput(input, func(input *Input) {
SortInputs := func(inputs []*Input) {
sort.SliceStable(inputs, func(i, j int) bool { return InputName(inputs[i]) < InputName(inputs[j]) })
}
switch {
case input.Cross != nil:
SortInputs(input.Cross)
case input.Union != nil:
SortInputs(input.Union)
}
})
}
|
[
"func",
"SortInput",
"(",
"input",
"*",
"Input",
")",
"{",
"VisitInput",
"(",
"input",
",",
"func",
"(",
"input",
"*",
"Input",
")",
"{",
"SortInputs",
":=",
"func",
"(",
"inputs",
"[",
"]",
"*",
"Input",
")",
"{",
"sort",
".",
"SliceStable",
"(",
"inputs",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"InputName",
"(",
"inputs",
"[",
"i",
"]",
")",
"<",
"InputName",
"(",
"inputs",
"[",
"j",
"]",
")",
"}",
")",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"input",
".",
"Cross",
"!=",
"nil",
":",
"SortInputs",
"(",
"input",
".",
"Cross",
")",
"\n",
"case",
"input",
".",
"Union",
"!=",
"nil",
":",
"SortInputs",
"(",
"input",
".",
"Union",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] |
// SortInput sorts an Input.
|
[
"SortInput",
"sorts",
"an",
"Input",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pps/util.go#L50-L62
|
test
|
pachyderm/pachyderm
|
src/client/pps/util.go
|
InputBranches
|
func InputBranches(input *Input) []*pfs.Branch {
var result []*pfs.Branch
VisitInput(input, func(input *Input) {
if input.Pfs != nil {
result = append(result, &pfs.Branch{
Repo: &pfs.Repo{Name: input.Pfs.Repo},
Name: input.Pfs.Branch,
})
}
if input.Cron != nil {
result = append(result, &pfs.Branch{
Repo: &pfs.Repo{Name: input.Cron.Repo},
Name: "master",
})
}
if input.Git != nil {
result = append(result, &pfs.Branch{
Repo: &pfs.Repo{Name: input.Git.Name},
Name: input.Git.Branch,
})
}
})
return result
}
|
go
|
func InputBranches(input *Input) []*pfs.Branch {
var result []*pfs.Branch
VisitInput(input, func(input *Input) {
if input.Pfs != nil {
result = append(result, &pfs.Branch{
Repo: &pfs.Repo{Name: input.Pfs.Repo},
Name: input.Pfs.Branch,
})
}
if input.Cron != nil {
result = append(result, &pfs.Branch{
Repo: &pfs.Repo{Name: input.Cron.Repo},
Name: "master",
})
}
if input.Git != nil {
result = append(result, &pfs.Branch{
Repo: &pfs.Repo{Name: input.Git.Name},
Name: input.Git.Branch,
})
}
})
return result
}
|
[
"func",
"InputBranches",
"(",
"input",
"*",
"Input",
")",
"[",
"]",
"*",
"pfs",
".",
"Branch",
"{",
"var",
"result",
"[",
"]",
"*",
"pfs",
".",
"Branch",
"\n",
"VisitInput",
"(",
"input",
",",
"func",
"(",
"input",
"*",
"Input",
")",
"{",
"if",
"input",
".",
"Pfs",
"!=",
"nil",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"pfs",
".",
"Branch",
"{",
"Repo",
":",
"&",
"pfs",
".",
"Repo",
"{",
"Name",
":",
"input",
".",
"Pfs",
".",
"Repo",
"}",
",",
"Name",
":",
"input",
".",
"Pfs",
".",
"Branch",
",",
"}",
")",
"\n",
"}",
"\n",
"if",
"input",
".",
"Cron",
"!=",
"nil",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"pfs",
".",
"Branch",
"{",
"Repo",
":",
"&",
"pfs",
".",
"Repo",
"{",
"Name",
":",
"input",
".",
"Cron",
".",
"Repo",
"}",
",",
"Name",
":",
"\"master\"",
",",
"}",
")",
"\n",
"}",
"\n",
"if",
"input",
".",
"Git",
"!=",
"nil",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"pfs",
".",
"Branch",
"{",
"Repo",
":",
"&",
"pfs",
".",
"Repo",
"{",
"Name",
":",
"input",
".",
"Git",
".",
"Name",
"}",
",",
"Name",
":",
"input",
".",
"Git",
".",
"Branch",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"result",
"\n",
"}"
] |
// InputBranches returns the branches in an Input.
|
[
"InputBranches",
"returns",
"the",
"branches",
"in",
"an",
"Input",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pps/util.go#L65-L88
|
test
|
pachyderm/pachyderm
|
src/client/pps/util.go
|
ValidateGitCloneURL
|
func ValidateGitCloneURL(url string) error {
exampleURL := "https://github.com/org/foo.git"
if url == "" {
return fmt.Errorf("clone URL is missing (example clone URL %v)", exampleURL)
}
// Use the git client's validator to make sure its a valid URL
o := &git.CloneOptions{
URL: url,
}
if err := o.Validate(); err != nil {
return err
}
// Make sure its the type that we want. Of the following we
// only accept the 'clone' type of url:
// git_url: "git://github.com/sjezewski/testgithook.git",
// ssh_url: "git@github.com:sjezewski/testgithook.git",
// clone_url: "https://github.com/sjezewski/testgithook.git",
// svn_url: "https://github.com/sjezewski/testgithook",
invalidErr := fmt.Errorf("clone URL is missing .git suffix (example clone URL %v)", exampleURL)
if !strings.HasSuffix(url, ".git") {
// svn_url case
return invalidErr
}
if !strings.HasPrefix(url, "https://") {
// git_url or ssh_url cases
return invalidErr
}
return nil
}
|
go
|
func ValidateGitCloneURL(url string) error {
exampleURL := "https://github.com/org/foo.git"
if url == "" {
return fmt.Errorf("clone URL is missing (example clone URL %v)", exampleURL)
}
// Use the git client's validator to make sure its a valid URL
o := &git.CloneOptions{
URL: url,
}
if err := o.Validate(); err != nil {
return err
}
// Make sure its the type that we want. Of the following we
// only accept the 'clone' type of url:
// git_url: "git://github.com/sjezewski/testgithook.git",
// ssh_url: "git@github.com:sjezewski/testgithook.git",
// clone_url: "https://github.com/sjezewski/testgithook.git",
// svn_url: "https://github.com/sjezewski/testgithook",
invalidErr := fmt.Errorf("clone URL is missing .git suffix (example clone URL %v)", exampleURL)
if !strings.HasSuffix(url, ".git") {
// svn_url case
return invalidErr
}
if !strings.HasPrefix(url, "https://") {
// git_url or ssh_url cases
return invalidErr
}
return nil
}
|
[
"func",
"ValidateGitCloneURL",
"(",
"url",
"string",
")",
"error",
"{",
"exampleURL",
":=",
"\"https://github.com/org/foo.git\"",
"\n",
"if",
"url",
"==",
"\"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"clone URL is missing (example clone URL %v)\"",
",",
"exampleURL",
")",
"\n",
"}",
"\n",
"o",
":=",
"&",
"git",
".",
"CloneOptions",
"{",
"URL",
":",
"url",
",",
"}",
"\n",
"if",
"err",
":=",
"o",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"invalidErr",
":=",
"fmt",
".",
"Errorf",
"(",
"\"clone URL is missing .git suffix (example clone URL %v)\"",
",",
"exampleURL",
")",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"url",
",",
"\".git\"",
")",
"{",
"return",
"invalidErr",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"url",
",",
"\"https://\"",
")",
"{",
"return",
"invalidErr",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ValidateGitCloneURL returns an error if the provided URL is invalid
|
[
"ValidateGitCloneURL",
"returns",
"an",
"error",
"if",
"the",
"provided",
"URL",
"is",
"invalid"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/pps/util.go#L91-L122
|
test
|
pachyderm/pachyderm
|
src/server/pkg/deploy/cmds/cmds.go
|
containsEmpty
|
func containsEmpty(vals []string) bool {
for _, val := range vals {
if val == "" {
return true
}
}
return false
}
|
go
|
func containsEmpty(vals []string) bool {
for _, val := range vals {
if val == "" {
return true
}
}
return false
}
|
[
"func",
"containsEmpty",
"(",
"vals",
"[",
"]",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"val",
":=",
"range",
"vals",
"{",
"if",
"val",
"==",
"\"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// containsEmpty is a helper function used for validation (particularly for
// validating that creds arguments aren't empty
|
[
"containsEmpty",
"is",
"a",
"helper",
"function",
"used",
"for",
"validation",
"(",
"particularly",
"for",
"validating",
"that",
"creds",
"arguments",
"aren",
"t",
"empty"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/deploy/cmds/cmds.go#L139-L146
|
test
|
pachyderm/pachyderm
|
src/server/admin/server/server.go
|
NewAPIServer
|
func NewAPIServer(address string, storageRoot string, clusterInfo *admin.ClusterInfo) APIServer {
return &apiServer{
Logger: log.NewLogger("admin.API"),
address: address,
storageRoot: storageRoot,
clusterInfo: clusterInfo,
}
}
|
go
|
func NewAPIServer(address string, storageRoot string, clusterInfo *admin.ClusterInfo) APIServer {
return &apiServer{
Logger: log.NewLogger("admin.API"),
address: address,
storageRoot: storageRoot,
clusterInfo: clusterInfo,
}
}
|
[
"func",
"NewAPIServer",
"(",
"address",
"string",
",",
"storageRoot",
"string",
",",
"clusterInfo",
"*",
"admin",
".",
"ClusterInfo",
")",
"APIServer",
"{",
"return",
"&",
"apiServer",
"{",
"Logger",
":",
"log",
".",
"NewLogger",
"(",
"\"admin.API\"",
")",
",",
"address",
":",
"address",
",",
"storageRoot",
":",
"storageRoot",
",",
"clusterInfo",
":",
"clusterInfo",
",",
"}",
"\n",
"}"
] |
// NewAPIServer returns a new admin.APIServer
|
[
"NewAPIServer",
"returns",
"a",
"new",
"admin",
".",
"APIServer"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/admin/server/server.go#L14-L21
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pretty/pretty.go
|
Ago
|
func Ago(timestamp *types.Timestamp) string {
t, _ := types.TimestampFromProto(timestamp)
if t.Equal(time.Time{}) {
return ""
}
return fmt.Sprintf("%s ago", units.HumanDuration(time.Since(t)))
}
|
go
|
func Ago(timestamp *types.Timestamp) string {
t, _ := types.TimestampFromProto(timestamp)
if t.Equal(time.Time{}) {
return ""
}
return fmt.Sprintf("%s ago", units.HumanDuration(time.Since(t)))
}
|
[
"func",
"Ago",
"(",
"timestamp",
"*",
"types",
".",
"Timestamp",
")",
"string",
"{",
"t",
",",
"_",
":=",
"types",
".",
"TimestampFromProto",
"(",
"timestamp",
")",
"\n",
"if",
"t",
".",
"Equal",
"(",
"time",
".",
"Time",
"{",
"}",
")",
"{",
"return",
"\"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s ago\"",
",",
"units",
".",
"HumanDuration",
"(",
"time",
".",
"Since",
"(",
"t",
")",
")",
")",
"\n",
"}"
] |
// Ago pretty-prints the amount of time that has passed
// since timestamp as a human-readable string.
|
[
"Ago",
"pretty",
"-",
"prints",
"the",
"amount",
"of",
"time",
"that",
"has",
"passed",
"since",
"timestamp",
"as",
"a",
"human",
"-",
"readable",
"string",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pretty/pretty.go#L21-L27
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pretty/pretty.go
|
TimeDifference
|
func TimeDifference(from *types.Timestamp, to *types.Timestamp) string {
tFrom, _ := types.TimestampFromProto(from)
tTo, _ := types.TimestampFromProto(to)
return units.HumanDuration(tTo.Sub(tFrom))
}
|
go
|
func TimeDifference(from *types.Timestamp, to *types.Timestamp) string {
tFrom, _ := types.TimestampFromProto(from)
tTo, _ := types.TimestampFromProto(to)
return units.HumanDuration(tTo.Sub(tFrom))
}
|
[
"func",
"TimeDifference",
"(",
"from",
"*",
"types",
".",
"Timestamp",
",",
"to",
"*",
"types",
".",
"Timestamp",
")",
"string",
"{",
"tFrom",
",",
"_",
":=",
"types",
".",
"TimestampFromProto",
"(",
"from",
")",
"\n",
"tTo",
",",
"_",
":=",
"types",
".",
"TimestampFromProto",
"(",
"to",
")",
"\n",
"return",
"units",
".",
"HumanDuration",
"(",
"tTo",
".",
"Sub",
"(",
"tFrom",
")",
")",
"\n",
"}"
] |
// TimeDifference pretty-prints the duration of time between from
// and to as a human-reabable string.
|
[
"TimeDifference",
"pretty",
"-",
"prints",
"the",
"duration",
"of",
"time",
"between",
"from",
"and",
"to",
"as",
"a",
"human",
"-",
"reabable",
"string",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pretty/pretty.go#L31-L35
|
test
|
pachyderm/pachyderm
|
src/server/pkg/pretty/pretty.go
|
Duration
|
func Duration(d *types.Duration) string {
duration, _ := types.DurationFromProto(d)
return units.HumanDuration(duration)
}
|
go
|
func Duration(d *types.Duration) string {
duration, _ := types.DurationFromProto(d)
return units.HumanDuration(duration)
}
|
[
"func",
"Duration",
"(",
"d",
"*",
"types",
".",
"Duration",
")",
"string",
"{",
"duration",
",",
"_",
":=",
"types",
".",
"DurationFromProto",
"(",
"d",
")",
"\n",
"return",
"units",
".",
"HumanDuration",
"(",
"duration",
")",
"\n",
"}"
] |
// Duration pretty prints a duration in a human readable way.
|
[
"Duration",
"pretty",
"prints",
"a",
"duration",
"in",
"a",
"human",
"readable",
"way",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/server/pkg/pretty/pretty.go#L38-L41
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
InspectCluster
|
func (c APIClient) InspectCluster() (*admin.ClusterInfo, error) {
clusterInfo, err := c.AdminAPIClient.InspectCluster(c.Ctx(), &types.Empty{})
if err != nil {
return nil, grpcutil.ScrubGRPC(err)
}
return clusterInfo, nil
}
|
go
|
func (c APIClient) InspectCluster() (*admin.ClusterInfo, error) {
clusterInfo, err := c.AdminAPIClient.InspectCluster(c.Ctx(), &types.Empty{})
if err != nil {
return nil, grpcutil.ScrubGRPC(err)
}
return clusterInfo, nil
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"InspectCluster",
"(",
")",
"(",
"*",
"admin",
".",
"ClusterInfo",
",",
"error",
")",
"{",
"clusterInfo",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"InspectCluster",
"(",
"c",
".",
"Ctx",
"(",
")",
",",
"&",
"types",
".",
"Empty",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"clusterInfo",
",",
"nil",
"\n",
"}"
] |
// InspectCluster retrieves cluster state
|
[
"InspectCluster",
"retrieves",
"cluster",
"state"
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L15-L21
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
Extract
|
func (c APIClient) Extract(objects bool, f func(op *admin.Op) error) error {
extractClient, err := c.AdminAPIClient.Extract(c.Ctx(), &admin.ExtractRequest{NoObjects: !objects})
if err != nil {
return grpcutil.ScrubGRPC(err)
}
for {
op, err := extractClient.Recv()
if err == io.EOF {
break
}
if err != nil {
return grpcutil.ScrubGRPC(err)
}
if err := f(op); err != nil {
return err
}
}
return nil
}
|
go
|
func (c APIClient) Extract(objects bool, f func(op *admin.Op) error) error {
extractClient, err := c.AdminAPIClient.Extract(c.Ctx(), &admin.ExtractRequest{NoObjects: !objects})
if err != nil {
return grpcutil.ScrubGRPC(err)
}
for {
op, err := extractClient.Recv()
if err == io.EOF {
break
}
if err != nil {
return grpcutil.ScrubGRPC(err)
}
if err := f(op); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"Extract",
"(",
"objects",
"bool",
",",
"f",
"func",
"(",
"op",
"*",
"admin",
".",
"Op",
")",
"error",
")",
"error",
"{",
"extractClient",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"Extract",
"(",
"c",
".",
"Ctx",
"(",
")",
",",
"&",
"admin",
".",
"ExtractRequest",
"{",
"NoObjects",
":",
"!",
"objects",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"{",
"op",
",",
"err",
":=",
"extractClient",
".",
"Recv",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"f",
"(",
"op",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Extract all cluster state, call f with each operation.
|
[
"Extract",
"all",
"cluster",
"state",
"call",
"f",
"with",
"each",
"operation",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L24-L42
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
ExtractAll
|
func (c APIClient) ExtractAll(objects bool) ([]*admin.Op, error) {
var result []*admin.Op
if err := c.Extract(objects, func(op *admin.Op) error {
result = append(result, op)
return nil
}); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (c APIClient) ExtractAll(objects bool) ([]*admin.Op, error) {
var result []*admin.Op
if err := c.Extract(objects, func(op *admin.Op) error {
result = append(result, op)
return nil
}); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"ExtractAll",
"(",
"objects",
"bool",
")",
"(",
"[",
"]",
"*",
"admin",
".",
"Op",
",",
"error",
")",
"{",
"var",
"result",
"[",
"]",
"*",
"admin",
".",
"Op",
"\n",
"if",
"err",
":=",
"c",
".",
"Extract",
"(",
"objects",
",",
"func",
"(",
"op",
"*",
"admin",
".",
"Op",
")",
"error",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"op",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// ExtractAll cluster state as a slice of operations.
|
[
"ExtractAll",
"cluster",
"state",
"as",
"a",
"slice",
"of",
"operations",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L45-L54
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
ExtractWriter
|
func (c APIClient) ExtractWriter(objects bool, w io.Writer) error {
writer := pbutil.NewWriter(w)
return c.Extract(objects, func(op *admin.Op) error {
_, err := writer.Write(op)
return err
})
}
|
go
|
func (c APIClient) ExtractWriter(objects bool, w io.Writer) error {
writer := pbutil.NewWriter(w)
return c.Extract(objects, func(op *admin.Op) error {
_, err := writer.Write(op)
return err
})
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"ExtractWriter",
"(",
"objects",
"bool",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"writer",
":=",
"pbutil",
".",
"NewWriter",
"(",
"w",
")",
"\n",
"return",
"c",
".",
"Extract",
"(",
"objects",
",",
"func",
"(",
"op",
"*",
"admin",
".",
"Op",
")",
"error",
"{",
"_",
",",
"err",
":=",
"writer",
".",
"Write",
"(",
"op",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n",
"}"
] |
// ExtractWriter extracts all cluster state and marshals it to w.
|
[
"ExtractWriter",
"extracts",
"all",
"cluster",
"state",
"and",
"marshals",
"it",
"to",
"w",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L57-L63
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
ExtractURL
|
func (c APIClient) ExtractURL(url string) error {
extractClient, err := c.AdminAPIClient.Extract(c.Ctx(), &admin.ExtractRequest{URL: url})
if err != nil {
return grpcutil.ScrubGRPC(err)
}
resp, err := extractClient.Recv()
if err == nil {
return fmt.Errorf("unexpected response from extract: %v", resp)
}
if err != io.EOF {
return err
}
return nil
}
|
go
|
func (c APIClient) ExtractURL(url string) error {
extractClient, err := c.AdminAPIClient.Extract(c.Ctx(), &admin.ExtractRequest{URL: url})
if err != nil {
return grpcutil.ScrubGRPC(err)
}
resp, err := extractClient.Recv()
if err == nil {
return fmt.Errorf("unexpected response from extract: %v", resp)
}
if err != io.EOF {
return err
}
return nil
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"ExtractURL",
"(",
"url",
"string",
")",
"error",
"{",
"extractClient",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"Extract",
"(",
"c",
".",
"Ctx",
"(",
")",
",",
"&",
"admin",
".",
"ExtractRequest",
"{",
"URL",
":",
"url",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"resp",
",",
"err",
":=",
"extractClient",
".",
"Recv",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"unexpected response from extract: %v\"",
",",
"resp",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"io",
".",
"EOF",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ExtractURL extracts all cluster state and marshalls it to object storage.
|
[
"ExtractURL",
"extracts",
"all",
"cluster",
"state",
"and",
"marshalls",
"it",
"to",
"object",
"storage",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L66-L79
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
ExtractPipeline
|
func (c APIClient) ExtractPipeline(pipelineName string) (*pps.CreatePipelineRequest, error) {
op, err := c.AdminAPIClient.ExtractPipeline(c.Ctx(), &admin.ExtractPipelineRequest{Pipeline: NewPipeline(pipelineName)})
if err != nil {
return nil, grpcutil.ScrubGRPC(err)
}
if op.Op1_9 == nil || op.Op1_9.Pipeline == nil {
return nil, fmt.Errorf("malformed response is missing pipeline")
}
return op.Op1_9.Pipeline, nil
}
|
go
|
func (c APIClient) ExtractPipeline(pipelineName string) (*pps.CreatePipelineRequest, error) {
op, err := c.AdminAPIClient.ExtractPipeline(c.Ctx(), &admin.ExtractPipelineRequest{Pipeline: NewPipeline(pipelineName)})
if err != nil {
return nil, grpcutil.ScrubGRPC(err)
}
if op.Op1_9 == nil || op.Op1_9.Pipeline == nil {
return nil, fmt.Errorf("malformed response is missing pipeline")
}
return op.Op1_9.Pipeline, nil
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"ExtractPipeline",
"(",
"pipelineName",
"string",
")",
"(",
"*",
"pps",
".",
"CreatePipelineRequest",
",",
"error",
")",
"{",
"op",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"ExtractPipeline",
"(",
"c",
".",
"Ctx",
"(",
")",
",",
"&",
"admin",
".",
"ExtractPipelineRequest",
"{",
"Pipeline",
":",
"NewPipeline",
"(",
"pipelineName",
")",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"op",
".",
"Op1_9",
"==",
"nil",
"||",
"op",
".",
"Op1_9",
".",
"Pipeline",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"malformed response is missing pipeline\"",
")",
"\n",
"}",
"\n",
"return",
"op",
".",
"Op1_9",
".",
"Pipeline",
",",
"nil",
"\n",
"}"
] |
// ExtractPipeline extracts a single pipeline.
|
[
"ExtractPipeline",
"extracts",
"a",
"single",
"pipeline",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L82-L91
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
Restore
|
func (c APIClient) Restore(ops []*admin.Op) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
for _, op := range ops {
if err := restoreClient.Send(&admin.RestoreRequest{Op: op}); err != nil {
return grpcutil.ScrubGRPC(err)
}
}
return nil
}
|
go
|
func (c APIClient) Restore(ops []*admin.Op) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
for _, op := range ops {
if err := restoreClient.Send(&admin.RestoreRequest{Op: op}); err != nil {
return grpcutil.ScrubGRPC(err)
}
}
return nil
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"Restore",
"(",
"ops",
"[",
"]",
"*",
"admin",
".",
"Op",
")",
"(",
"retErr",
"error",
")",
"{",
"restoreClient",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"Restore",
"(",
"c",
".",
"Ctx",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"_",
",",
"err",
":=",
"restoreClient",
".",
"CloseAndRecv",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"retErr",
"==",
"nil",
"{",
"retErr",
"=",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"for",
"_",
",",
"op",
":=",
"range",
"ops",
"{",
"if",
"err",
":=",
"restoreClient",
".",
"Send",
"(",
"&",
"admin",
".",
"RestoreRequest",
"{",
"Op",
":",
"op",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Restore cluster state from an extract series of operations.
|
[
"Restore",
"cluster",
"state",
"from",
"an",
"extract",
"series",
"of",
"operations",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L94-L110
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
RestoreReader
|
func (c APIClient) RestoreReader(r io.Reader) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
reader := pbutil.NewReader(r)
op := &admin.Op{}
for {
if err := reader.Read(op); err != nil {
if err == io.EOF {
break
}
return err
}
if err := restoreClient.Send(&admin.RestoreRequest{Op: op}); err != nil {
return grpcutil.ScrubGRPC(err)
}
}
return nil
}
|
go
|
func (c APIClient) RestoreReader(r io.Reader) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
reader := pbutil.NewReader(r)
op := &admin.Op{}
for {
if err := reader.Read(op); err != nil {
if err == io.EOF {
break
}
return err
}
if err := restoreClient.Send(&admin.RestoreRequest{Op: op}); err != nil {
return grpcutil.ScrubGRPC(err)
}
}
return nil
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"RestoreReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"retErr",
"error",
")",
"{",
"restoreClient",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"Restore",
"(",
"c",
".",
"Ctx",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"_",
",",
"err",
":=",
"restoreClient",
".",
"CloseAndRecv",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"retErr",
"==",
"nil",
"{",
"retErr",
"=",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"reader",
":=",
"pbutil",
".",
"NewReader",
"(",
"r",
")",
"\n",
"op",
":=",
"&",
"admin",
".",
"Op",
"{",
"}",
"\n",
"for",
"{",
"if",
"err",
":=",
"reader",
".",
"Read",
"(",
"op",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"restoreClient",
".",
"Send",
"(",
"&",
"admin",
".",
"RestoreRequest",
"{",
"Op",
":",
"op",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RestoreReader restores cluster state from a reader containing marshaled ops.
// Such as those written by ExtractWriter.
|
[
"RestoreReader",
"restores",
"cluster",
"state",
"from",
"a",
"reader",
"containing",
"marshaled",
"ops",
".",
"Such",
"as",
"those",
"written",
"by",
"ExtractWriter",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L114-L138
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
RestoreFrom
|
func (c APIClient) RestoreFrom(objects bool, otherC *APIClient) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
return otherC.Extract(objects, func(op *admin.Op) error {
return restoreClient.Send(&admin.RestoreRequest{Op: op})
})
}
|
go
|
func (c APIClient) RestoreFrom(objects bool, otherC *APIClient) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
return otherC.Extract(objects, func(op *admin.Op) error {
return restoreClient.Send(&admin.RestoreRequest{Op: op})
})
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"RestoreFrom",
"(",
"objects",
"bool",
",",
"otherC",
"*",
"APIClient",
")",
"(",
"retErr",
"error",
")",
"{",
"restoreClient",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"Restore",
"(",
"c",
".",
"Ctx",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"_",
",",
"err",
":=",
"restoreClient",
".",
"CloseAndRecv",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"retErr",
"==",
"nil",
"{",
"retErr",
"=",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"otherC",
".",
"Extract",
"(",
"objects",
",",
"func",
"(",
"op",
"*",
"admin",
".",
"Op",
")",
"error",
"{",
"return",
"restoreClient",
".",
"Send",
"(",
"&",
"admin",
".",
"RestoreRequest",
"{",
"Op",
":",
"op",
"}",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// RestoreFrom restores state from another cluster which can be access through otherC.
|
[
"RestoreFrom",
"restores",
"state",
"from",
"another",
"cluster",
"which",
"can",
"be",
"access",
"through",
"otherC",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L141-L154
|
test
|
pachyderm/pachyderm
|
src/client/admin.go
|
RestoreURL
|
func (c APIClient) RestoreURL(url string) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
return grpcutil.ScrubGRPC(restoreClient.Send(&admin.RestoreRequest{URL: url}))
}
|
go
|
func (c APIClient) RestoreURL(url string) (retErr error) {
restoreClient, err := c.AdminAPIClient.Restore(c.Ctx())
if err != nil {
return grpcutil.ScrubGRPC(err)
}
defer func() {
if _, err := restoreClient.CloseAndRecv(); err != nil && retErr == nil {
retErr = grpcutil.ScrubGRPC(err)
}
}()
return grpcutil.ScrubGRPC(restoreClient.Send(&admin.RestoreRequest{URL: url}))
}
|
[
"func",
"(",
"c",
"APIClient",
")",
"RestoreURL",
"(",
"url",
"string",
")",
"(",
"retErr",
"error",
")",
"{",
"restoreClient",
",",
"err",
":=",
"c",
".",
"AdminAPIClient",
".",
"Restore",
"(",
"c",
".",
"Ctx",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"_",
",",
"err",
":=",
"restoreClient",
".",
"CloseAndRecv",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"retErr",
"==",
"nil",
"{",
"retErr",
"=",
"grpcutil",
".",
"ScrubGRPC",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"grpcutil",
".",
"ScrubGRPC",
"(",
"restoreClient",
".",
"Send",
"(",
"&",
"admin",
".",
"RestoreRequest",
"{",
"URL",
":",
"url",
"}",
")",
")",
"\n",
"}"
] |
// RestoreURL restures cluster state from object storage.
|
[
"RestoreURL",
"restures",
"cluster",
"state",
"from",
"object",
"storage",
"."
] |
94fb2d536cb6852a77a49e8f777dc9c1bde2c723
|
https://github.com/pachyderm/pachyderm/blob/94fb2d536cb6852a77a49e8f777dc9c1bde2c723/src/client/admin.go#L157-L168
|
test
|
google/go-cmp
|
cmp/cmpopts/ignore.go
|
IgnoreTypes
|
func IgnoreTypes(typs ...interface{}) cmp.Option {
tf := newTypeFilter(typs...)
return cmp.FilterPath(tf.filter, cmp.Ignore())
}
|
go
|
func IgnoreTypes(typs ...interface{}) cmp.Option {
tf := newTypeFilter(typs...)
return cmp.FilterPath(tf.filter, cmp.Ignore())
}
|
[
"func",
"IgnoreTypes",
"(",
"typs",
"...",
"interface",
"{",
"}",
")",
"cmp",
".",
"Option",
"{",
"tf",
":=",
"newTypeFilter",
"(",
"typs",
"...",
")",
"\n",
"return",
"cmp",
".",
"FilterPath",
"(",
"tf",
".",
"filter",
",",
"cmp",
".",
"Ignore",
"(",
")",
")",
"\n",
"}"
] |
// IgnoreTypes returns an Option that ignores all values assignable to
// certain types, which are specified by passing in a value of each type.
|
[
"IgnoreTypes",
"returns",
"an",
"Option",
"that",
"ignores",
"all",
"values",
"assignable",
"to",
"certain",
"types",
"which",
"are",
"specified",
"by",
"passing",
"in",
"a",
"value",
"of",
"each",
"type",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/cmpopts/ignore.go#L32-L35
|
test
|
google/go-cmp
|
cmp/report_text.go
|
AppendEllipsis
|
func (s *textList) AppendEllipsis(ds diffStats) {
hasStats := ds != diffStats{}
if len(*s) == 0 || !(*s)[len(*s)-1].Value.Equal(textEllipsis) {
if hasStats {
*s = append(*s, textRecord{Value: textEllipsis, Comment: ds})
} else {
*s = append(*s, textRecord{Value: textEllipsis})
}
return
}
if hasStats {
(*s)[len(*s)-1].Comment = (*s)[len(*s)-1].Comment.(diffStats).Append(ds)
}
}
|
go
|
func (s *textList) AppendEllipsis(ds diffStats) {
hasStats := ds != diffStats{}
if len(*s) == 0 || !(*s)[len(*s)-1].Value.Equal(textEllipsis) {
if hasStats {
*s = append(*s, textRecord{Value: textEllipsis, Comment: ds})
} else {
*s = append(*s, textRecord{Value: textEllipsis})
}
return
}
if hasStats {
(*s)[len(*s)-1].Comment = (*s)[len(*s)-1].Comment.(diffStats).Append(ds)
}
}
|
[
"func",
"(",
"s",
"*",
"textList",
")",
"AppendEllipsis",
"(",
"ds",
"diffStats",
")",
"{",
"hasStats",
":=",
"ds",
"!=",
"diffStats",
"{",
"}",
"\n",
"if",
"len",
"(",
"*",
"s",
")",
"==",
"0",
"||",
"!",
"(",
"*",
"s",
")",
"[",
"len",
"(",
"*",
"s",
")",
"-",
"1",
"]",
".",
"Value",
".",
"Equal",
"(",
"textEllipsis",
")",
"{",
"if",
"hasStats",
"{",
"*",
"s",
"=",
"append",
"(",
"*",
"s",
",",
"textRecord",
"{",
"Value",
":",
"textEllipsis",
",",
"Comment",
":",
"ds",
"}",
")",
"\n",
"}",
"else",
"{",
"*",
"s",
"=",
"append",
"(",
"*",
"s",
",",
"textRecord",
"{",
"Value",
":",
"textEllipsis",
"}",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"hasStats",
"{",
"(",
"*",
"s",
")",
"[",
"len",
"(",
"*",
"s",
")",
"-",
"1",
"]",
".",
"Comment",
"=",
"(",
"*",
"s",
")",
"[",
"len",
"(",
"*",
"s",
")",
"-",
"1",
"]",
".",
"Comment",
".",
"(",
"diffStats",
")",
".",
"Append",
"(",
"ds",
")",
"\n",
"}",
"\n",
"}"
] |
// AppendEllipsis appends a new ellipsis node to the list if none already
// exists at the end. If cs is non-zero it coalesces the statistics with the
// previous diffStats.
|
[
"AppendEllipsis",
"appends",
"a",
"new",
"ellipsis",
"node",
"to",
"the",
"list",
"if",
"none",
"already",
"exists",
"at",
"the",
"end",
".",
"If",
"cs",
"is",
"non",
"-",
"zero",
"it",
"coalesces",
"the",
"statistics",
"with",
"the",
"previous",
"diffStats",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/report_text.go#L143-L156
|
test
|
google/go-cmp
|
cmp/internal/function/func.go
|
IsType
|
func IsType(t reflect.Type, ft funcType) bool {
if t == nil || t.Kind() != reflect.Func || t.IsVariadic() {
return false
}
ni, no := t.NumIn(), t.NumOut()
switch ft {
case tbFunc: // func(T) bool
if ni == 1 && no == 1 && t.Out(0) == boolType {
return true
}
case ttbFunc: // func(T, T) bool
if ni == 2 && no == 1 && t.In(0) == t.In(1) && t.Out(0) == boolType {
return true
}
case trbFunc: // func(T, R) bool
if ni == 2 && no == 1 && t.Out(0) == boolType {
return true
}
case tibFunc: // func(T, I) bool
if ni == 2 && no == 1 && t.In(0).AssignableTo(t.In(1)) && t.Out(0) == boolType {
return true
}
case trFunc: // func(T) R
if ni == 1 && no == 1 {
return true
}
}
return false
}
|
go
|
func IsType(t reflect.Type, ft funcType) bool {
if t == nil || t.Kind() != reflect.Func || t.IsVariadic() {
return false
}
ni, no := t.NumIn(), t.NumOut()
switch ft {
case tbFunc: // func(T) bool
if ni == 1 && no == 1 && t.Out(0) == boolType {
return true
}
case ttbFunc: // func(T, T) bool
if ni == 2 && no == 1 && t.In(0) == t.In(1) && t.Out(0) == boolType {
return true
}
case trbFunc: // func(T, R) bool
if ni == 2 && no == 1 && t.Out(0) == boolType {
return true
}
case tibFunc: // func(T, I) bool
if ni == 2 && no == 1 && t.In(0).AssignableTo(t.In(1)) && t.Out(0) == boolType {
return true
}
case trFunc: // func(T) R
if ni == 1 && no == 1 {
return true
}
}
return false
}
|
[
"func",
"IsType",
"(",
"t",
"reflect",
".",
"Type",
",",
"ft",
"funcType",
")",
"bool",
"{",
"if",
"t",
"==",
"nil",
"||",
"t",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Func",
"||",
"t",
".",
"IsVariadic",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"ni",
",",
"no",
":=",
"t",
".",
"NumIn",
"(",
")",
",",
"t",
".",
"NumOut",
"(",
")",
"\n",
"switch",
"ft",
"{",
"case",
"tbFunc",
":",
"if",
"ni",
"==",
"1",
"&&",
"no",
"==",
"1",
"&&",
"t",
".",
"Out",
"(",
"0",
")",
"==",
"boolType",
"{",
"return",
"true",
"\n",
"}",
"\n",
"case",
"ttbFunc",
":",
"if",
"ni",
"==",
"2",
"&&",
"no",
"==",
"1",
"&&",
"t",
".",
"In",
"(",
"0",
")",
"==",
"t",
".",
"In",
"(",
"1",
")",
"&&",
"t",
".",
"Out",
"(",
"0",
")",
"==",
"boolType",
"{",
"return",
"true",
"\n",
"}",
"\n",
"case",
"trbFunc",
":",
"if",
"ni",
"==",
"2",
"&&",
"no",
"==",
"1",
"&&",
"t",
".",
"Out",
"(",
"0",
")",
"==",
"boolType",
"{",
"return",
"true",
"\n",
"}",
"\n",
"case",
"tibFunc",
":",
"if",
"ni",
"==",
"2",
"&&",
"no",
"==",
"1",
"&&",
"t",
".",
"In",
"(",
"0",
")",
".",
"AssignableTo",
"(",
"t",
".",
"In",
"(",
"1",
")",
")",
"&&",
"t",
".",
"Out",
"(",
"0",
")",
"==",
"boolType",
"{",
"return",
"true",
"\n",
"}",
"\n",
"case",
"trFunc",
":",
"if",
"ni",
"==",
"1",
"&&",
"no",
"==",
"1",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsType reports whether the reflect.Type is of the specified function type.
|
[
"IsType",
"reports",
"whether",
"the",
"reflect",
".",
"Type",
"is",
"of",
"the",
"specified",
"function",
"type",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/internal/function/func.go#L38-L66
|
test
|
google/go-cmp
|
cmp/internal/function/func.go
|
NameOf
|
func NameOf(v reflect.Value) string {
fnc := runtime.FuncForPC(v.Pointer())
if fnc == nil {
return "<unknown>"
}
fullName := fnc.Name() // e.g., "long/path/name/mypkg.(*MyType).(long/path/name/mypkg.myMethod)-fm"
// Method closures have a "-fm" suffix.
fullName = strings.TrimSuffix(fullName, "-fm")
var name string
for len(fullName) > 0 {
inParen := strings.HasSuffix(fullName, ")")
fullName = strings.TrimSuffix(fullName, ")")
s := lastIdentRx.FindString(fullName)
if s == "" {
break
}
name = s + "." + name
fullName = strings.TrimSuffix(fullName, s)
if i := strings.LastIndexByte(fullName, '('); inParen && i >= 0 {
fullName = fullName[:i]
}
fullName = strings.TrimSuffix(fullName, ".")
}
return strings.TrimSuffix(name, ".")
}
|
go
|
func NameOf(v reflect.Value) string {
fnc := runtime.FuncForPC(v.Pointer())
if fnc == nil {
return "<unknown>"
}
fullName := fnc.Name() // e.g., "long/path/name/mypkg.(*MyType).(long/path/name/mypkg.myMethod)-fm"
// Method closures have a "-fm" suffix.
fullName = strings.TrimSuffix(fullName, "-fm")
var name string
for len(fullName) > 0 {
inParen := strings.HasSuffix(fullName, ")")
fullName = strings.TrimSuffix(fullName, ")")
s := lastIdentRx.FindString(fullName)
if s == "" {
break
}
name = s + "." + name
fullName = strings.TrimSuffix(fullName, s)
if i := strings.LastIndexByte(fullName, '('); inParen && i >= 0 {
fullName = fullName[:i]
}
fullName = strings.TrimSuffix(fullName, ".")
}
return strings.TrimSuffix(name, ".")
}
|
[
"func",
"NameOf",
"(",
"v",
"reflect",
".",
"Value",
")",
"string",
"{",
"fnc",
":=",
"runtime",
".",
"FuncForPC",
"(",
"v",
".",
"Pointer",
"(",
")",
")",
"\n",
"if",
"fnc",
"==",
"nil",
"{",
"return",
"\"<unknown>\"",
"\n",
"}",
"\n",
"fullName",
":=",
"fnc",
".",
"Name",
"(",
")",
"\n",
"fullName",
"=",
"strings",
".",
"TrimSuffix",
"(",
"fullName",
",",
"\"-fm\"",
")",
"\n",
"var",
"name",
"string",
"\n",
"for",
"len",
"(",
"fullName",
")",
">",
"0",
"{",
"inParen",
":=",
"strings",
".",
"HasSuffix",
"(",
"fullName",
",",
"\")\"",
")",
"\n",
"fullName",
"=",
"strings",
".",
"TrimSuffix",
"(",
"fullName",
",",
"\")\"",
")",
"\n",
"s",
":=",
"lastIdentRx",
".",
"FindString",
"(",
"fullName",
")",
"\n",
"if",
"s",
"==",
"\"\"",
"{",
"break",
"\n",
"}",
"\n",
"name",
"=",
"s",
"+",
"\".\"",
"+",
"name",
"\n",
"fullName",
"=",
"strings",
".",
"TrimSuffix",
"(",
"fullName",
",",
"s",
")",
"\n",
"if",
"i",
":=",
"strings",
".",
"LastIndexByte",
"(",
"fullName",
",",
"'('",
")",
";",
"inParen",
"&&",
"i",
">=",
"0",
"{",
"fullName",
"=",
"fullName",
"[",
":",
"i",
"]",
"\n",
"}",
"\n",
"fullName",
"=",
"strings",
".",
"TrimSuffix",
"(",
"fullName",
",",
"\".\"",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"TrimSuffix",
"(",
"name",
",",
"\".\"",
")",
"\n",
"}"
] |
// NameOf returns the name of the function value.
|
[
"NameOf",
"returns",
"the",
"name",
"of",
"the",
"function",
"value",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/internal/function/func.go#L71-L99
|
test
|
google/go-cmp
|
cmp/internal/value/pointer_unsafe.go
|
PointerOf
|
func PointerOf(v reflect.Value) Pointer {
// The proper representation of a pointer is unsafe.Pointer,
// which is necessary if the GC ever uses a moving collector.
return Pointer{unsafe.Pointer(v.Pointer()), v.Type()}
}
|
go
|
func PointerOf(v reflect.Value) Pointer {
// The proper representation of a pointer is unsafe.Pointer,
// which is necessary if the GC ever uses a moving collector.
return Pointer{unsafe.Pointer(v.Pointer()), v.Type()}
}
|
[
"func",
"PointerOf",
"(",
"v",
"reflect",
".",
"Value",
")",
"Pointer",
"{",
"return",
"Pointer",
"{",
"unsafe",
".",
"Pointer",
"(",
"v",
".",
"Pointer",
"(",
")",
")",
",",
"v",
".",
"Type",
"(",
")",
"}",
"\n",
"}"
] |
// PointerOf returns a Pointer from v, which must be a
// reflect.Ptr, reflect.Slice, or reflect.Map.
|
[
"PointerOf",
"returns",
"a",
"Pointer",
"from",
"v",
"which",
"must",
"be",
"a",
"reflect",
".",
"Ptr",
"reflect",
".",
"Slice",
"or",
"reflect",
".",
"Map",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/internal/value/pointer_unsafe.go#L22-L26
|
test
|
google/go-cmp
|
cmp/internal/diff/diff.go
|
String
|
func (es EditScript) String() string {
b := make([]byte, len(es))
for i, e := range es {
switch e {
case Identity:
b[i] = '.'
case UniqueX:
b[i] = 'X'
case UniqueY:
b[i] = 'Y'
case Modified:
b[i] = 'M'
default:
panic("invalid edit-type")
}
}
return string(b)
}
|
go
|
func (es EditScript) String() string {
b := make([]byte, len(es))
for i, e := range es {
switch e {
case Identity:
b[i] = '.'
case UniqueX:
b[i] = 'X'
case UniqueY:
b[i] = 'Y'
case Modified:
b[i] = 'M'
default:
panic("invalid edit-type")
}
}
return string(b)
}
|
[
"func",
"(",
"es",
"EditScript",
")",
"String",
"(",
")",
"string",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"es",
")",
")",
"\n",
"for",
"i",
",",
"e",
":=",
"range",
"es",
"{",
"switch",
"e",
"{",
"case",
"Identity",
":",
"b",
"[",
"i",
"]",
"=",
"'.'",
"\n",
"case",
"UniqueX",
":",
"b",
"[",
"i",
"]",
"=",
"'X'",
"\n",
"case",
"UniqueY",
":",
"b",
"[",
"i",
"]",
"=",
"'Y'",
"\n",
"case",
"Modified",
":",
"b",
"[",
"i",
"]",
"=",
"'M'",
"\n",
"default",
":",
"panic",
"(",
"\"invalid edit-type\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] |
// String returns a human-readable string representing the edit-script where
// Identity, UniqueX, UniqueY, and Modified are represented by the
// '.', 'X', 'Y', and 'M' characters, respectively.
|
[
"String",
"returns",
"a",
"human",
"-",
"readable",
"string",
"representing",
"the",
"edit",
"-",
"script",
"where",
"Identity",
"UniqueX",
"UniqueY",
"and",
"Modified",
"are",
"represented",
"by",
"the",
".",
"X",
"Y",
"and",
"M",
"characters",
"respectively",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/internal/diff/diff.go#L35-L52
|
test
|
google/go-cmp
|
cmp/internal/diff/diff.go
|
stats
|
func (es EditScript) stats() (s struct{ NI, NX, NY, NM int }) {
for _, e := range es {
switch e {
case Identity:
s.NI++
case UniqueX:
s.NX++
case UniqueY:
s.NY++
case Modified:
s.NM++
default:
panic("invalid edit-type")
}
}
return
}
|
go
|
func (es EditScript) stats() (s struct{ NI, NX, NY, NM int }) {
for _, e := range es {
switch e {
case Identity:
s.NI++
case UniqueX:
s.NX++
case UniqueY:
s.NY++
case Modified:
s.NM++
default:
panic("invalid edit-type")
}
}
return
}
|
[
"func",
"(",
"es",
"EditScript",
")",
"stats",
"(",
")",
"(",
"s",
"struct",
"{",
"NI",
",",
"NX",
",",
"NY",
",",
"NM",
"int",
"}",
")",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"es",
"{",
"switch",
"e",
"{",
"case",
"Identity",
":",
"s",
".",
"NI",
"++",
"\n",
"case",
"UniqueX",
":",
"s",
".",
"NX",
"++",
"\n",
"case",
"UniqueY",
":",
"s",
".",
"NY",
"++",
"\n",
"case",
"Modified",
":",
"s",
".",
"NM",
"++",
"\n",
"default",
":",
"panic",
"(",
"\"invalid edit-type\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// stats returns a histogram of the number of each type of edit operation.
|
[
"stats",
"returns",
"a",
"histogram",
"of",
"the",
"number",
"of",
"each",
"type",
"of",
"edit",
"operation",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/internal/diff/diff.go#L55-L71
|
test
|
google/go-cmp
|
cmp/internal/diff/diff.go
|
connect
|
func (p *path) connect(dst point, f EqualFunc) {
if p.dir > 0 {
// Connect in forward direction.
for dst.X > p.X && dst.Y > p.Y {
switch r := f(p.X, p.Y); {
case r.Equal():
p.append(Identity)
case r.Similar():
p.append(Modified)
case dst.X-p.X >= dst.Y-p.Y:
p.append(UniqueX)
default:
p.append(UniqueY)
}
}
for dst.X > p.X {
p.append(UniqueX)
}
for dst.Y > p.Y {
p.append(UniqueY)
}
} else {
// Connect in reverse direction.
for p.X > dst.X && p.Y > dst.Y {
switch r := f(p.X-1, p.Y-1); {
case r.Equal():
p.append(Identity)
case r.Similar():
p.append(Modified)
case p.Y-dst.Y >= p.X-dst.X:
p.append(UniqueY)
default:
p.append(UniqueX)
}
}
for p.X > dst.X {
p.append(UniqueX)
}
for p.Y > dst.Y {
p.append(UniqueY)
}
}
}
|
go
|
func (p *path) connect(dst point, f EqualFunc) {
if p.dir > 0 {
// Connect in forward direction.
for dst.X > p.X && dst.Y > p.Y {
switch r := f(p.X, p.Y); {
case r.Equal():
p.append(Identity)
case r.Similar():
p.append(Modified)
case dst.X-p.X >= dst.Y-p.Y:
p.append(UniqueX)
default:
p.append(UniqueY)
}
}
for dst.X > p.X {
p.append(UniqueX)
}
for dst.Y > p.Y {
p.append(UniqueY)
}
} else {
// Connect in reverse direction.
for p.X > dst.X && p.Y > dst.Y {
switch r := f(p.X-1, p.Y-1); {
case r.Equal():
p.append(Identity)
case r.Similar():
p.append(Modified)
case p.Y-dst.Y >= p.X-dst.X:
p.append(UniqueY)
default:
p.append(UniqueX)
}
}
for p.X > dst.X {
p.append(UniqueX)
}
for p.Y > dst.Y {
p.append(UniqueY)
}
}
}
|
[
"func",
"(",
"p",
"*",
"path",
")",
"connect",
"(",
"dst",
"point",
",",
"f",
"EqualFunc",
")",
"{",
"if",
"p",
".",
"dir",
">",
"0",
"{",
"for",
"dst",
".",
"X",
">",
"p",
".",
"X",
"&&",
"dst",
".",
"Y",
">",
"p",
".",
"Y",
"{",
"switch",
"r",
":=",
"f",
"(",
"p",
".",
"X",
",",
"p",
".",
"Y",
")",
";",
"{",
"case",
"r",
".",
"Equal",
"(",
")",
":",
"p",
".",
"append",
"(",
"Identity",
")",
"\n",
"case",
"r",
".",
"Similar",
"(",
")",
":",
"p",
".",
"append",
"(",
"Modified",
")",
"\n",
"case",
"dst",
".",
"X",
"-",
"p",
".",
"X",
">=",
"dst",
".",
"Y",
"-",
"p",
".",
"Y",
":",
"p",
".",
"append",
"(",
"UniqueX",
")",
"\n",
"default",
":",
"p",
".",
"append",
"(",
"UniqueY",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"dst",
".",
"X",
">",
"p",
".",
"X",
"{",
"p",
".",
"append",
"(",
"UniqueX",
")",
"\n",
"}",
"\n",
"for",
"dst",
".",
"Y",
">",
"p",
".",
"Y",
"{",
"p",
".",
"append",
"(",
"UniqueY",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"for",
"p",
".",
"X",
">",
"dst",
".",
"X",
"&&",
"p",
".",
"Y",
">",
"dst",
".",
"Y",
"{",
"switch",
"r",
":=",
"f",
"(",
"p",
".",
"X",
"-",
"1",
",",
"p",
".",
"Y",
"-",
"1",
")",
";",
"{",
"case",
"r",
".",
"Equal",
"(",
")",
":",
"p",
".",
"append",
"(",
"Identity",
")",
"\n",
"case",
"r",
".",
"Similar",
"(",
")",
":",
"p",
".",
"append",
"(",
"Modified",
")",
"\n",
"case",
"p",
".",
"Y",
"-",
"dst",
".",
"Y",
">=",
"p",
".",
"X",
"-",
"dst",
".",
"X",
":",
"p",
".",
"append",
"(",
"UniqueY",
")",
"\n",
"default",
":",
"p",
".",
"append",
"(",
"UniqueX",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"p",
".",
"X",
">",
"dst",
".",
"X",
"{",
"p",
".",
"append",
"(",
"UniqueX",
")",
"\n",
"}",
"\n",
"for",
"p",
".",
"Y",
">",
"dst",
".",
"Y",
"{",
"p",
".",
"append",
"(",
"UniqueY",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// connect appends any necessary Identity, Modified, UniqueX, or UniqueY types
// to the edit-script to connect p.point to dst.
|
[
"connect",
"appends",
"any",
"necessary",
"Identity",
"Modified",
"UniqueX",
"or",
"UniqueY",
"types",
"to",
"the",
"edit",
"-",
"script",
"to",
"connect",
"p",
".",
"point",
"to",
"dst",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/internal/diff/diff.go#L304-L346
|
test
|
google/go-cmp
|
cmp/cmpopts/equate.go
|
EquateNaNs
|
func EquateNaNs() cmp.Option {
return cmp.Options{
cmp.FilterValues(areNaNsF64s, cmp.Comparer(equateAlways)),
cmp.FilterValues(areNaNsF32s, cmp.Comparer(equateAlways)),
}
}
|
go
|
func EquateNaNs() cmp.Option {
return cmp.Options{
cmp.FilterValues(areNaNsF64s, cmp.Comparer(equateAlways)),
cmp.FilterValues(areNaNsF32s, cmp.Comparer(equateAlways)),
}
}
|
[
"func",
"EquateNaNs",
"(",
")",
"cmp",
".",
"Option",
"{",
"return",
"cmp",
".",
"Options",
"{",
"cmp",
".",
"FilterValues",
"(",
"areNaNsF64s",
",",
"cmp",
".",
"Comparer",
"(",
"equateAlways",
")",
")",
",",
"cmp",
".",
"FilterValues",
"(",
"areNaNsF32s",
",",
"cmp",
".",
"Comparer",
"(",
"equateAlways",
")",
")",
",",
"}",
"\n",
"}"
] |
// EquateNaNs returns a Comparer option that determines float32 and float64
// NaN values to be equal.
//
// EquateNaNs can be used in conjunction with EquateApprox.
|
[
"EquateNaNs",
"returns",
"a",
"Comparer",
"option",
"that",
"determines",
"float32",
"and",
"float64",
"NaN",
"values",
"to",
"be",
"equal",
".",
"EquateNaNs",
"can",
"be",
"used",
"in",
"conjunction",
"with",
"EquateApprox",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/cmpopts/equate.go#L77-L82
|
test
|
google/go-cmp
|
cmp/path.go
|
Index
|
func (pa Path) Index(i int) PathStep {
if i < 0 {
i = len(pa) + i
}
if i < 0 || i >= len(pa) {
return pathStep{}
}
return pa[i]
}
|
go
|
func (pa Path) Index(i int) PathStep {
if i < 0 {
i = len(pa) + i
}
if i < 0 || i >= len(pa) {
return pathStep{}
}
return pa[i]
}
|
[
"func",
"(",
"pa",
"Path",
")",
"Index",
"(",
"i",
"int",
")",
"PathStep",
"{",
"if",
"i",
"<",
"0",
"{",
"i",
"=",
"len",
"(",
"pa",
")",
"+",
"i",
"\n",
"}",
"\n",
"if",
"i",
"<",
"0",
"||",
"i",
">=",
"len",
"(",
"pa",
")",
"{",
"return",
"pathStep",
"{",
"}",
"\n",
"}",
"\n",
"return",
"pa",
"[",
"i",
"]",
"\n",
"}"
] |
// Index returns the ith step in the Path and supports negative indexing.
// A negative index starts counting from the tail of the Path such that -1
// refers to the last step, -2 refers to the second-to-last step, and so on.
// If index is invalid, this returns a non-nil PathStep that reports a nil Type.
|
[
"Index",
"returns",
"the",
"ith",
"step",
"in",
"the",
"Path",
"and",
"supports",
"negative",
"indexing",
".",
"A",
"negative",
"index",
"starts",
"counting",
"from",
"the",
"tail",
"of",
"the",
"Path",
"such",
"that",
"-",
"1",
"refers",
"to",
"the",
"last",
"step",
"-",
"2",
"refers",
"to",
"the",
"second",
"-",
"to",
"-",
"last",
"step",
"and",
"so",
"on",
".",
"If",
"index",
"is",
"invalid",
"this",
"returns",
"a",
"non",
"-",
"nil",
"PathStep",
"that",
"reports",
"a",
"nil",
"Type",
"."
] |
6f77996f0c42f7b84e5a2b252227263f93432e9b
|
https://github.com/google/go-cmp/blob/6f77996f0c42f7b84e5a2b252227263f93432e9b/cmp/path.go#L81-L89
|
test
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.