id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
15,400 |
intelsdi-x/snap
|
mgmt/rest/server.go
|
authMiddleware
|
func (s *Server) authMiddleware(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
reqOrigin := r.Header.Get("Origin")
s.setAllowedOrigins(rw, reqOrigin)
defer r.Body.Close()
if s.auth {
_, password, ok := r.BasicAuth()
// If we have valid password or going to tribe/agreements endpoint
// go to next. tribe/agreements endpoint used for populating
// snaptel help page when tribe mode is turned on.
if ok && password == s.authpwd {
next(rw, r)
} else {
v2.Write(401, v2.UnauthError{Code: 401, Message: "Not authorized. Please specify the same password that used to start snapteld. E.g: [snaptel -p plugin list] or [curl http://localhost:8181/v2/plugins -u snap]"}, rw)
}
} else {
next(rw, r)
}
}
|
go
|
func (s *Server) authMiddleware(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
reqOrigin := r.Header.Get("Origin")
s.setAllowedOrigins(rw, reqOrigin)
defer r.Body.Close()
if s.auth {
_, password, ok := r.BasicAuth()
// If we have valid password or going to tribe/agreements endpoint
// go to next. tribe/agreements endpoint used for populating
// snaptel help page when tribe mode is turned on.
if ok && password == s.authpwd {
next(rw, r)
} else {
v2.Write(401, v2.UnauthError{Code: 401, Message: "Not authorized. Please specify the same password that used to start snapteld. E.g: [snaptel -p plugin list] or [curl http://localhost:8181/v2/plugins -u snap]"}, rw)
}
} else {
next(rw, r)
}
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"authMiddleware",
"(",
"rw",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"next",
"http",
".",
"HandlerFunc",
")",
"{",
"reqOrigin",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"s",
".",
"setAllowedOrigins",
"(",
"rw",
",",
"reqOrigin",
")",
"\n\n",
"defer",
"r",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"s",
".",
"auth",
"{",
"_",
",",
"password",
",",
"ok",
":=",
"r",
".",
"BasicAuth",
"(",
")",
"\n",
"// If we have valid password or going to tribe/agreements endpoint",
"// go to next. tribe/agreements endpoint used for populating",
"// snaptel help page when tribe mode is turned on.",
"if",
"ok",
"&&",
"password",
"==",
"s",
".",
"authpwd",
"{",
"next",
"(",
"rw",
",",
"r",
")",
"\n",
"}",
"else",
"{",
"v2",
".",
"Write",
"(",
"401",
",",
"v2",
".",
"UnauthError",
"{",
"Code",
":",
"401",
",",
"Message",
":",
"\"",
"\"",
"}",
",",
"rw",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"next",
"(",
"rw",
",",
"r",
")",
"\n",
"}",
"\n",
"}"
] |
// Auth Middleware for REST API
|
[
"Auth",
"Middleware",
"for",
"REST",
"API"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/server.go#L164-L182
|
15,401 |
intelsdi-x/snap
|
mgmt/rest/server.go
|
setAllowedOrigins
|
func (s *Server) setAllowedOrigins(rw http.ResponseWriter, ro string) {
if len(s.allowedOrigins) > 0 {
if _, ok := s.allowedOrigins[ro]; ok {
// localhost CORS is not supported by all browsers. It has to use "*".
if strings.Contains(ro, "127.0.0.1") || strings.Contains(ro, "localhost") {
ro = "*"
}
rw.Header().Set("Access-Control-Allow-Origin", ro)
rw.Header().Set("Access-Control-Allow-Methods", allowedMethods)
rw.Header().Set("Access-Control-Allow-Headers", allowedHeaders)
rw.Header().Set("Access-Control-Max-Age", strconv.Itoa(maxAge))
}
}
}
|
go
|
func (s *Server) setAllowedOrigins(rw http.ResponseWriter, ro string) {
if len(s.allowedOrigins) > 0 {
if _, ok := s.allowedOrigins[ro]; ok {
// localhost CORS is not supported by all browsers. It has to use "*".
if strings.Contains(ro, "127.0.0.1") || strings.Contains(ro, "localhost") {
ro = "*"
}
rw.Header().Set("Access-Control-Allow-Origin", ro)
rw.Header().Set("Access-Control-Allow-Methods", allowedMethods)
rw.Header().Set("Access-Control-Allow-Headers", allowedHeaders)
rw.Header().Set("Access-Control-Max-Age", strconv.Itoa(maxAge))
}
}
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"setAllowedOrigins",
"(",
"rw",
"http",
".",
"ResponseWriter",
",",
"ro",
"string",
")",
"{",
"if",
"len",
"(",
"s",
".",
"allowedOrigins",
")",
">",
"0",
"{",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"allowedOrigins",
"[",
"ro",
"]",
";",
"ok",
"{",
"// localhost CORS is not supported by all browsers. It has to use \"*\".",
"if",
"strings",
".",
"Contains",
"(",
"ro",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"ro",
",",
"\"",
"\"",
")",
"{",
"ro",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"rw",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"ro",
")",
"\n",
"rw",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"allowedMethods",
")",
"\n",
"rw",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"allowedHeaders",
")",
"\n",
"rw",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"maxAge",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// CORS origins have to be turned on explicitly in the global config.
// Otherwise, it defaults to the same origin.
|
[
"CORS",
"origins",
"have",
"to",
"be",
"turned",
"on",
"explicitly",
"in",
"the",
"global",
"config",
".",
"Otherwise",
"it",
"defaults",
"to",
"the",
"same",
"origin",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/server.go#L186-L199
|
15,402 |
intelsdi-x/snap
|
pkg/schedule/cron_schedule.go
|
NewCronSchedule
|
func NewCronSchedule(entry string) *CronSchedule {
schedule := cron.New()
return &CronSchedule{
entry: entry,
schedule: schedule,
enabled: false,
}
}
|
go
|
func NewCronSchedule(entry string) *CronSchedule {
schedule := cron.New()
return &CronSchedule{
entry: entry,
schedule: schedule,
enabled: false,
}
}
|
[
"func",
"NewCronSchedule",
"(",
"entry",
"string",
")",
"*",
"CronSchedule",
"{",
"schedule",
":=",
"cron",
".",
"New",
"(",
")",
"\n",
"return",
"&",
"CronSchedule",
"{",
"entry",
":",
"entry",
",",
"schedule",
":",
"schedule",
",",
"enabled",
":",
"false",
",",
"}",
"\n",
"}"
] |
// NewCronSchedule creates and starts new cron schedule and returns an instance of CronSchedule
|
[
"NewCronSchedule",
"creates",
"and",
"starts",
"new",
"cron",
"schedule",
"and",
"returns",
"an",
"instance",
"of",
"CronSchedule"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/schedule/cron_schedule.go#L40-L47
|
15,403 |
intelsdi-x/snap
|
pkg/schedule/cron_schedule.go
|
Validate
|
func (c *CronSchedule) Validate() error {
if c.entry == "" {
return ErrMissingCronEntry
}
_, err := cron.Parse(c.entry)
if err != nil {
return err
}
return nil
}
|
go
|
func (c *CronSchedule) Validate() error {
if c.entry == "" {
return ErrMissingCronEntry
}
_, err := cron.Parse(c.entry)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"CronSchedule",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"c",
".",
"entry",
"==",
"\"",
"\"",
"{",
"return",
"ErrMissingCronEntry",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"cron",
".",
"Parse",
"(",
"c",
".",
"entry",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate returns error if cron entry doesn't match crontab format
|
[
"Validate",
"returns",
"error",
"if",
"cron",
"entry",
"doesn",
"t",
"match",
"crontab",
"format"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/schedule/cron_schedule.go#L60-L69
|
15,404 |
intelsdi-x/snap
|
pkg/schedule/cron_schedule.go
|
Wait
|
func (c *CronSchedule) Wait(last time.Time) Response {
var err error
now := time.Now()
// first run
if (last == time.Time{}) {
last = now
}
// schedule not enabled, either due to first run or invalid cron entry
if !c.enabled {
err = c.schedule.AddFunc(c.entry, func() {})
if err != nil {
c.state = Error
} else {
c.enabled = true
}
}
var misses uint
if c.enabled {
s := c.schedule.Entries()[0].Schedule
// calculate misses
for next := last; next.Before(now); {
next = s.Next(next)
if next.After(now) {
break
}
misses++
}
// wait
waitTime := s.Next(now)
time.Sleep(waitTime.Sub(now))
}
return &CronScheduleResponse{
state: c.GetState(),
err: err,
missed: misses,
lastTime: time.Now(),
}
}
|
go
|
func (c *CronSchedule) Wait(last time.Time) Response {
var err error
now := time.Now()
// first run
if (last == time.Time{}) {
last = now
}
// schedule not enabled, either due to first run or invalid cron entry
if !c.enabled {
err = c.schedule.AddFunc(c.entry, func() {})
if err != nil {
c.state = Error
} else {
c.enabled = true
}
}
var misses uint
if c.enabled {
s := c.schedule.Entries()[0].Schedule
// calculate misses
for next := last; next.Before(now); {
next = s.Next(next)
if next.After(now) {
break
}
misses++
}
// wait
waitTime := s.Next(now)
time.Sleep(waitTime.Sub(now))
}
return &CronScheduleResponse{
state: c.GetState(),
err: err,
missed: misses,
lastTime: time.Now(),
}
}
|
[
"func",
"(",
"c",
"*",
"CronSchedule",
")",
"Wait",
"(",
"last",
"time",
".",
"Time",
")",
"Response",
"{",
"var",
"err",
"error",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"// first run",
"if",
"(",
"last",
"==",
"time",
".",
"Time",
"{",
"}",
")",
"{",
"last",
"=",
"now",
"\n",
"}",
"\n",
"// schedule not enabled, either due to first run or invalid cron entry",
"if",
"!",
"c",
".",
"enabled",
"{",
"err",
"=",
"c",
".",
"schedule",
".",
"AddFunc",
"(",
"c",
".",
"entry",
",",
"func",
"(",
")",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"state",
"=",
"Error",
"\n",
"}",
"else",
"{",
"c",
".",
"enabled",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"misses",
"uint",
"\n",
"if",
"c",
".",
"enabled",
"{",
"s",
":=",
"c",
".",
"schedule",
".",
"Entries",
"(",
")",
"[",
"0",
"]",
".",
"Schedule",
"\n\n",
"// calculate misses",
"for",
"next",
":=",
"last",
";",
"next",
".",
"Before",
"(",
"now",
")",
";",
"{",
"next",
"=",
"s",
".",
"Next",
"(",
"next",
")",
"\n",
"if",
"next",
".",
"After",
"(",
"now",
")",
"{",
"break",
"\n",
"}",
"\n",
"misses",
"++",
"\n",
"}",
"\n\n",
"// wait",
"waitTime",
":=",
"s",
".",
"Next",
"(",
"now",
")",
"\n",
"time",
".",
"Sleep",
"(",
"waitTime",
".",
"Sub",
"(",
"now",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"CronScheduleResponse",
"{",
"state",
":",
"c",
".",
"GetState",
"(",
")",
",",
"err",
":",
"err",
",",
"missed",
":",
"misses",
",",
"lastTime",
":",
"time",
".",
"Now",
"(",
")",
",",
"}",
"\n",
"}"
] |
// Wait waits as long as specified in cron entry
|
[
"Wait",
"waits",
"as",
"long",
"as",
"specified",
"in",
"cron",
"entry"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/schedule/cron_schedule.go#L72-L114
|
15,405 |
intelsdi-x/snap
|
core/cdata/tree.go
|
Add
|
func (c *ConfigDataTree) Add(ns []string, cdn *ConfigDataNode) {
c.cTree.Add(ns, cdn)
}
|
go
|
func (c *ConfigDataTree) Add(ns []string, cdn *ConfigDataNode) {
c.cTree.Add(ns, cdn)
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataTree",
")",
"Add",
"(",
"ns",
"[",
"]",
"string",
",",
"cdn",
"*",
"ConfigDataNode",
")",
"{",
"c",
".",
"cTree",
".",
"Add",
"(",
"ns",
",",
"cdn",
")",
"\n",
"}"
] |
// Adds a ConfigDataNode at the provided namespace.
|
[
"Adds",
"a",
"ConfigDataNode",
"at",
"the",
"provided",
"namespace",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/tree.go#L58-L60
|
15,406 |
intelsdi-x/snap
|
core/cdata/tree.go
|
Get
|
func (c *ConfigDataTree) Get(ns []string) *ConfigDataNode {
n := c.cTree.Get(ns)
if n == nil {
return nil
}
switch t := n.(type) {
case ConfigDataNode:
return &t
default:
return t.(*ConfigDataNode)
}
}
|
go
|
func (c *ConfigDataTree) Get(ns []string) *ConfigDataNode {
n := c.cTree.Get(ns)
if n == nil {
return nil
}
switch t := n.(type) {
case ConfigDataNode:
return &t
default:
return t.(*ConfigDataNode)
}
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataTree",
")",
"Get",
"(",
"ns",
"[",
"]",
"string",
")",
"*",
"ConfigDataNode",
"{",
"n",
":=",
"c",
".",
"cTree",
".",
"Get",
"(",
"ns",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"switch",
"t",
":=",
"n",
".",
"(",
"type",
")",
"{",
"case",
"ConfigDataNode",
":",
"return",
"&",
"t",
"\n",
"default",
":",
"return",
"t",
".",
"(",
"*",
"ConfigDataNode",
")",
"\n\n",
"}",
"\n",
"}"
] |
// Returns a ConfigDataNode that is a merged version of the namespace provided.
|
[
"Returns",
"a",
"ConfigDataNode",
"that",
"is",
"a",
"merged",
"version",
"of",
"the",
"namespace",
"provided",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/tree.go#L63-L75
|
15,407 |
intelsdi-x/snap
|
control/plugin/plugin_deprecated.go
|
CacheTTL
|
func CacheTTL(t time.Duration) metaOp {
return func(m *PluginMeta) {
m.CacheTTL = t
}
}
|
go
|
func CacheTTL(t time.Duration) metaOp {
return func(m *PluginMeta) {
m.CacheTTL = t
}
}
|
[
"func",
"CacheTTL",
"(",
"t",
"time",
".",
"Duration",
")",
"metaOp",
"{",
"return",
"func",
"(",
"m",
"*",
"PluginMeta",
")",
"{",
"m",
".",
"CacheTTL",
"=",
"t",
"\n",
"}",
"\n",
"}"
] |
// CacheTTL is an option that can be be provided to the func NewPluginMeta.
|
[
"CacheTTL",
"is",
"an",
"option",
"that",
"can",
"be",
"be",
"provided",
"to",
"the",
"func",
"NewPluginMeta",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/plugin/plugin_deprecated.go#L74-L78
|
15,408 |
intelsdi-x/snap
|
control/plugin/plugin_deprecated.go
|
NewPluginMeta
|
func NewPluginMeta(name string, version int, pluginType PluginType, acceptContentTypes, returnContentTypes []string, opts ...metaOp) *PluginMeta {
// An empty accepted content type default to "snap.*"
if len(acceptContentTypes) == 0 {
acceptContentTypes = append(acceptContentTypes, "snap.*")
}
// Validate content type formats
for _, s := range acceptContentTypes {
b, e := regexp.MatchString(`^[a-z0-9*]+\.[a-z0-9*]+$`, s)
if e != nil {
panic(e)
}
if !b {
panic(fmt.Sprintf("Bad accept content type [%s] for [%d] [%s]", name, version, s))
}
}
for _, s := range returnContentTypes {
b, e := regexp.MatchString(`^[a-z0-9*]+\.[a-z0-9*]+$`, s)
if e != nil {
panic(e)
}
if !b {
panic(fmt.Sprintf("Bad return content type [%s] for [%d] [%s]", name, version, s))
}
}
p := &PluginMeta{
Name: name,
Version: version,
Type: pluginType,
AcceptedContentTypes: acceptContentTypes,
ReturnedContentTypes: returnContentTypes,
//set the default for concurrency count to 1
ConcurrencyCount: 1,
}
for _, opt := range opts {
opt(p)
}
return p
}
|
go
|
func NewPluginMeta(name string, version int, pluginType PluginType, acceptContentTypes, returnContentTypes []string, opts ...metaOp) *PluginMeta {
// An empty accepted content type default to "snap.*"
if len(acceptContentTypes) == 0 {
acceptContentTypes = append(acceptContentTypes, "snap.*")
}
// Validate content type formats
for _, s := range acceptContentTypes {
b, e := regexp.MatchString(`^[a-z0-9*]+\.[a-z0-9*]+$`, s)
if e != nil {
panic(e)
}
if !b {
panic(fmt.Sprintf("Bad accept content type [%s] for [%d] [%s]", name, version, s))
}
}
for _, s := range returnContentTypes {
b, e := regexp.MatchString(`^[a-z0-9*]+\.[a-z0-9*]+$`, s)
if e != nil {
panic(e)
}
if !b {
panic(fmt.Sprintf("Bad return content type [%s] for [%d] [%s]", name, version, s))
}
}
p := &PluginMeta{
Name: name,
Version: version,
Type: pluginType,
AcceptedContentTypes: acceptContentTypes,
ReturnedContentTypes: returnContentTypes,
//set the default for concurrency count to 1
ConcurrencyCount: 1,
}
for _, opt := range opts {
opt(p)
}
return p
}
|
[
"func",
"NewPluginMeta",
"(",
"name",
"string",
",",
"version",
"int",
",",
"pluginType",
"PluginType",
",",
"acceptContentTypes",
",",
"returnContentTypes",
"[",
"]",
"string",
",",
"opts",
"...",
"metaOp",
")",
"*",
"PluginMeta",
"{",
"// An empty accepted content type default to \"snap.*\"",
"if",
"len",
"(",
"acceptContentTypes",
")",
"==",
"0",
"{",
"acceptContentTypes",
"=",
"append",
"(",
"acceptContentTypes",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Validate content type formats",
"for",
"_",
",",
"s",
":=",
"range",
"acceptContentTypes",
"{",
"b",
",",
"e",
":=",
"regexp",
".",
"MatchString",
"(",
"`^[a-z0-9*]+\\.[a-z0-9*]+$`",
",",
"s",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"panic",
"(",
"e",
")",
"\n",
"}",
"\n",
"if",
"!",
"b",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"version",
",",
"s",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"returnContentTypes",
"{",
"b",
",",
"e",
":=",
"regexp",
".",
"MatchString",
"(",
"`^[a-z0-9*]+\\.[a-z0-9*]+$`",
",",
"s",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"panic",
"(",
"e",
")",
"\n",
"}",
"\n",
"if",
"!",
"b",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"version",
",",
"s",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"p",
":=",
"&",
"PluginMeta",
"{",
"Name",
":",
"name",
",",
"Version",
":",
"version",
",",
"Type",
":",
"pluginType",
",",
"AcceptedContentTypes",
":",
"acceptContentTypes",
",",
"ReturnedContentTypes",
":",
"returnContentTypes",
",",
"//set the default for concurrency count to 1",
"ConcurrencyCount",
":",
"1",
",",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"p",
")",
"\n",
"}",
"\n\n",
"return",
"p",
"\n",
"}"
] |
// NewPluginMeta constructs and returns a PluginMeta struct
|
[
"NewPluginMeta",
"constructs",
"and",
"returns",
"a",
"PluginMeta",
"struct"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/plugin/plugin_deprecated.go#L81-L122
|
15,409 |
intelsdi-x/snap
|
control/strategy/config_based.go
|
Select
|
func (cb *configBased) Select(aps []AvailablePlugin, id string) (AvailablePlugin, error) {
if ap, ok := cb.plugins[id]; ok && ap != nil {
return ap, nil
}
// add first one in case it's new id
for _, ap := range aps {
available := true
for _, busyPlugin := range cb.plugins {
if ap == busyPlugin {
available = false
}
}
if available {
cb.plugins[id] = ap
return ap, nil
}
}
cb.logger.WithFields(log.Fields{
"_block": "findAvailablePlugin",
"strategy": cb.String(),
"error": fmt.Sprintf("%v of %v plugins are available", len(aps)-len(cb.plugins), len(aps)),
}).Error(ErrCouldNotSelect)
return nil, ErrCouldNotSelect
}
|
go
|
func (cb *configBased) Select(aps []AvailablePlugin, id string) (AvailablePlugin, error) {
if ap, ok := cb.plugins[id]; ok && ap != nil {
return ap, nil
}
// add first one in case it's new id
for _, ap := range aps {
available := true
for _, busyPlugin := range cb.plugins {
if ap == busyPlugin {
available = false
}
}
if available {
cb.plugins[id] = ap
return ap, nil
}
}
cb.logger.WithFields(log.Fields{
"_block": "findAvailablePlugin",
"strategy": cb.String(),
"error": fmt.Sprintf("%v of %v plugins are available", len(aps)-len(cb.plugins), len(aps)),
}).Error(ErrCouldNotSelect)
return nil, ErrCouldNotSelect
}
|
[
"func",
"(",
"cb",
"*",
"configBased",
")",
"Select",
"(",
"aps",
"[",
"]",
"AvailablePlugin",
",",
"id",
"string",
")",
"(",
"AvailablePlugin",
",",
"error",
")",
"{",
"if",
"ap",
",",
"ok",
":=",
"cb",
".",
"plugins",
"[",
"id",
"]",
";",
"ok",
"&&",
"ap",
"!=",
"nil",
"{",
"return",
"ap",
",",
"nil",
"\n",
"}",
"\n\n",
"// add first one in case it's new id",
"for",
"_",
",",
"ap",
":=",
"range",
"aps",
"{",
"available",
":=",
"true",
"\n",
"for",
"_",
",",
"busyPlugin",
":=",
"range",
"cb",
".",
"plugins",
"{",
"if",
"ap",
"==",
"busyPlugin",
"{",
"available",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"available",
"{",
"cb",
".",
"plugins",
"[",
"id",
"]",
"=",
"ap",
"\n",
"return",
"ap",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"cb",
".",
"logger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"cb",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"len",
"(",
"aps",
")",
"-",
"len",
"(",
"cb",
".",
"plugins",
")",
",",
"len",
"(",
"aps",
")",
")",
",",
"}",
")",
".",
"Error",
"(",
"ErrCouldNotSelect",
")",
"\n",
"return",
"nil",
",",
"ErrCouldNotSelect",
"\n",
"}"
] |
// Select selects an available plugin using the config based plugin strategy.
|
[
"Select",
"selects",
"an",
"available",
"plugin",
"using",
"the",
"config",
"based",
"plugin",
"strategy",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/config_based.go#L52-L76
|
15,410 |
intelsdi-x/snap
|
core/cdata/node.go
|
GobEncode
|
func (c *ConfigDataNode) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if err := encoder.Encode(&c.table); err != nil {
return nil, err
}
return w.Bytes(), nil
}
|
go
|
func (c *ConfigDataNode) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if err := encoder.Encode(&c.table); err != nil {
return nil, err
}
return w.Bytes(), nil
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataNode",
")",
"GobEncode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"encoder",
":=",
"gob",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"&",
"c",
".",
"table",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"w",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GobEcode encodes a ConfigDataNode in go binary format
|
[
"GobEcode",
"encodes",
"a",
"ConfigDataNode",
"in",
"go",
"binary",
"format"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L40-L47
|
15,411 |
intelsdi-x/snap
|
core/cdata/node.go
|
GobDecode
|
func (c *ConfigDataNode) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
c.mutex = new(sync.Mutex)
decoder := gob.NewDecoder(r)
return decoder.Decode(&c.table)
}
|
go
|
func (c *ConfigDataNode) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
c.mutex = new(sync.Mutex)
decoder := gob.NewDecoder(r)
return decoder.Decode(&c.table)
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataNode",
")",
"GobDecode",
"(",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"r",
":=",
"bytes",
".",
"NewBuffer",
"(",
"buf",
")",
"\n",
"c",
".",
"mutex",
"=",
"new",
"(",
"sync",
".",
"Mutex",
")",
"\n",
"decoder",
":=",
"gob",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"return",
"decoder",
".",
"Decode",
"(",
"&",
"c",
".",
"table",
")",
"\n",
"}"
] |
// GobDecode decodes a GOB into a ConfigDataNode
|
[
"GobDecode",
"decodes",
"a",
"GOB",
"into",
"a",
"ConfigDataNode"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L50-L55
|
15,412 |
intelsdi-x/snap
|
core/cdata/node.go
|
UnmarshalJSON
|
func (c *ConfigDataNode) UnmarshalJSON(data []byte) error {
t := map[string]interface{}{}
c.table = map[string]ctypes.ConfigValue{}
dec := json.NewDecoder(bytes.NewReader(data))
dec.UseNumber()
if err := dec.Decode(&t); err != nil {
return err
}
for k, i := range t {
switch t := i.(type) {
case string:
c.table[k] = ctypes.ConfigValueStr{Value: t}
case bool:
c.table[k] = ctypes.ConfigValueBool{Value: t}
case json.Number:
if v, err := t.Int64(); err == nil {
c.table[k] = ctypes.ConfigValueInt{Value: int(v)}
continue
}
if v, err := t.Float64(); err == nil {
c.table[k] = ctypes.ConfigValueFloat{Value: v}
continue
}
default:
return fmt.Errorf("Error Unmarshalling JSON ConfigDataNode. Key: %v Type: %v is unsupported.", k, t)
}
}
c.mutex = new(sync.Mutex)
return nil
}
|
go
|
func (c *ConfigDataNode) UnmarshalJSON(data []byte) error {
t := map[string]interface{}{}
c.table = map[string]ctypes.ConfigValue{}
dec := json.NewDecoder(bytes.NewReader(data))
dec.UseNumber()
if err := dec.Decode(&t); err != nil {
return err
}
for k, i := range t {
switch t := i.(type) {
case string:
c.table[k] = ctypes.ConfigValueStr{Value: t}
case bool:
c.table[k] = ctypes.ConfigValueBool{Value: t}
case json.Number:
if v, err := t.Int64(); err == nil {
c.table[k] = ctypes.ConfigValueInt{Value: int(v)}
continue
}
if v, err := t.Float64(); err == nil {
c.table[k] = ctypes.ConfigValueFloat{Value: v}
continue
}
default:
return fmt.Errorf("Error Unmarshalling JSON ConfigDataNode. Key: %v Type: %v is unsupported.", k, t)
}
}
c.mutex = new(sync.Mutex)
return nil
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataNode",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"t",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"c",
".",
"table",
"=",
"map",
"[",
"string",
"]",
"ctypes",
".",
"ConfigValue",
"{",
"}",
"\n",
"dec",
":=",
"json",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewReader",
"(",
"data",
")",
")",
"\n",
"dec",
".",
"UseNumber",
"(",
")",
"\n",
"if",
"err",
":=",
"dec",
".",
"Decode",
"(",
"&",
"t",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"i",
":=",
"range",
"t",
"{",
"switch",
"t",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"c",
".",
"table",
"[",
"k",
"]",
"=",
"ctypes",
".",
"ConfigValueStr",
"{",
"Value",
":",
"t",
"}",
"\n",
"case",
"bool",
":",
"c",
".",
"table",
"[",
"k",
"]",
"=",
"ctypes",
".",
"ConfigValueBool",
"{",
"Value",
":",
"t",
"}",
"\n",
"case",
"json",
".",
"Number",
":",
"if",
"v",
",",
"err",
":=",
"t",
".",
"Int64",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"c",
".",
"table",
"[",
"k",
"]",
"=",
"ctypes",
".",
"ConfigValueInt",
"{",
"Value",
":",
"int",
"(",
"v",
")",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"v",
",",
"err",
":=",
"t",
".",
"Float64",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"c",
".",
"table",
"[",
"k",
"]",
"=",
"ctypes",
".",
"ConfigValueFloat",
"{",
"Value",
":",
"v",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"mutex",
"=",
"new",
"(",
"sync",
".",
"Mutex",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON unmarshals JSON into a ConfigDataNode
|
[
"UnmarshalJSON",
"unmarshals",
"JSON",
"into",
"a",
"ConfigDataNode"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L63-L93
|
15,413 |
intelsdi-x/snap
|
core/cdata/node.go
|
NewNode
|
func NewNode() *ConfigDataNode {
return &ConfigDataNode{
mutex: new(sync.Mutex),
table: make(map[string]ctypes.ConfigValue),
}
}
|
go
|
func NewNode() *ConfigDataNode {
return &ConfigDataNode{
mutex: new(sync.Mutex),
table: make(map[string]ctypes.ConfigValue),
}
}
|
[
"func",
"NewNode",
"(",
")",
"*",
"ConfigDataNode",
"{",
"return",
"&",
"ConfigDataNode",
"{",
"mutex",
":",
"new",
"(",
"sync",
".",
"Mutex",
")",
",",
"table",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"ctypes",
".",
"ConfigValue",
")",
",",
"}",
"\n",
"}"
] |
// Returns a new and empty node.
|
[
"Returns",
"a",
"new",
"and",
"empty",
"node",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L96-L101
|
15,414 |
intelsdi-x/snap
|
core/cdata/node.go
|
AddItem
|
func (c *ConfigDataNode) AddItem(k string, v ctypes.ConfigValue) {
// And empty is a noop
if k == "" {
return
}
c.mutex.Lock()
defer c.mutex.Unlock()
c.table[k] = v
}
|
go
|
func (c *ConfigDataNode) AddItem(k string, v ctypes.ConfigValue) {
// And empty is a noop
if k == "" {
return
}
c.mutex.Lock()
defer c.mutex.Unlock()
c.table[k] = v
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataNode",
")",
"AddItem",
"(",
"k",
"string",
",",
"v",
"ctypes",
".",
"ConfigValue",
")",
"{",
"// And empty is a noop",
"if",
"k",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"table",
"[",
"k",
"]",
"=",
"v",
"\n",
"}"
] |
// Adds an item to the ConfigDataNode.
|
[
"Adds",
"an",
"item",
"to",
"the",
"ConfigDataNode",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L118-L126
|
15,415 |
intelsdi-x/snap
|
core/cdata/node.go
|
ReverseMergeInPlace
|
func (c *ConfigDataNode) ReverseMergeInPlace(n ctree.Node) ctree.Node {
cd := n.(*ConfigDataNode)
new_table := make(map[string]ctypes.ConfigValue)
// Lock here since we are modifying c.table
c.mutex.Lock()
defer c.mutex.Unlock()
t := cd.Table()
t2 := c.table
for k, v := range t {
new_table[k] = v
}
for k, v := range t2 {
new_table[k] = v
}
c.table = new_table
return c
}
|
go
|
func (c *ConfigDataNode) ReverseMergeInPlace(n ctree.Node) ctree.Node {
cd := n.(*ConfigDataNode)
new_table := make(map[string]ctypes.ConfigValue)
// Lock here since we are modifying c.table
c.mutex.Lock()
defer c.mutex.Unlock()
t := cd.Table()
t2 := c.table
for k, v := range t {
new_table[k] = v
}
for k, v := range t2 {
new_table[k] = v
}
c.table = new_table
return c
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataNode",
")",
"ReverseMergeInPlace",
"(",
"n",
"ctree",
".",
"Node",
")",
"ctree",
".",
"Node",
"{",
"cd",
":=",
"n",
".",
"(",
"*",
"ConfigDataNode",
")",
"\n",
"new_table",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"ctypes",
".",
"ConfigValue",
")",
"\n",
"// Lock here since we are modifying c.table",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"t",
":=",
"cd",
".",
"Table",
"(",
")",
"\n",
"t2",
":=",
"c",
".",
"table",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"t",
"{",
"new_table",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"t2",
"{",
"new_table",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"c",
".",
"table",
"=",
"new_table",
"\n",
"return",
"c",
"\n",
"}"
] |
// Merges a ConfigDataNode with this one but does not overwrite any
// conflicting values. Any conflicts are decided by the callers value.
|
[
"Merges",
"a",
"ConfigDataNode",
"with",
"this",
"one",
"but",
"does",
"not",
"overwrite",
"any",
"conflicting",
"values",
".",
"Any",
"conflicts",
"are",
"decided",
"by",
"the",
"callers",
"value",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L145-L161
|
15,416 |
intelsdi-x/snap
|
core/cdata/node.go
|
ReverseMerge
|
func (c *ConfigDataNode) ReverseMerge(n ctree.Node) *ConfigDataNode {
cd := n.(*ConfigDataNode)
copy := NewNode()
t2 := c.table
for k, v := range cd.Table() {
copy.table[k] = v
}
for k, v := range t2 {
copy.table[k] = v
}
return copy
}
|
go
|
func (c *ConfigDataNode) ReverseMerge(n ctree.Node) *ConfigDataNode {
cd := n.(*ConfigDataNode)
copy := NewNode()
t2 := c.table
for k, v := range cd.Table() {
copy.table[k] = v
}
for k, v := range t2 {
copy.table[k] = v
}
return copy
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataNode",
")",
"ReverseMerge",
"(",
"n",
"ctree",
".",
"Node",
")",
"*",
"ConfigDataNode",
"{",
"cd",
":=",
"n",
".",
"(",
"*",
"ConfigDataNode",
")",
"\n",
"copy",
":=",
"NewNode",
"(",
")",
"\n",
"t2",
":=",
"c",
".",
"table",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"cd",
".",
"Table",
"(",
")",
"{",
"copy",
".",
"table",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"t2",
"{",
"copy",
".",
"table",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"copy",
"\n",
"}"
] |
// Merges a ConfigDataNode with a copy of the current ConfigDataNode and returns
// the copy. The merge does not overwrite any conflicting values.
// Any conflicts are decided by the callers value.
|
[
"Merges",
"a",
"ConfigDataNode",
"with",
"a",
"copy",
"of",
"the",
"current",
"ConfigDataNode",
"and",
"returns",
"the",
"copy",
".",
"The",
"merge",
"does",
"not",
"overwrite",
"any",
"conflicting",
"values",
".",
"Any",
"conflicts",
"are",
"decided",
"by",
"the",
"callers",
"value",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L166-L177
|
15,417 |
intelsdi-x/snap
|
core/cdata/node.go
|
ApplyDefaults
|
func (c *ConfigDataNode) ApplyDefaults(defaults map[string]ctypes.ConfigValue) {
// Lock here since we are modifying c.table
c.mutex.Lock()
defer c.mutex.Unlock()
for name, def := range defaults {
if _, ok := c.table[name]; !ok {
c.table[name] = def
}
}
}
|
go
|
func (c *ConfigDataNode) ApplyDefaults(defaults map[string]ctypes.ConfigValue) {
// Lock here since we are modifying c.table
c.mutex.Lock()
defer c.mutex.Unlock()
for name, def := range defaults {
if _, ok := c.table[name]; !ok {
c.table[name] = def
}
}
}
|
[
"func",
"(",
"c",
"*",
"ConfigDataNode",
")",
"ApplyDefaults",
"(",
"defaults",
"map",
"[",
"string",
"]",
"ctypes",
".",
"ConfigValue",
")",
"{",
"// Lock here since we are modifying c.table",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"for",
"name",
",",
"def",
":=",
"range",
"defaults",
"{",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"table",
"[",
"name",
"]",
";",
"!",
"ok",
"{",
"c",
".",
"table",
"[",
"name",
"]",
"=",
"def",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// ApplyDefaults will set default values if the given ConfigDataNode doesn't
// already have a value for the given configuration.
|
[
"ApplyDefaults",
"will",
"set",
"default",
"values",
"if",
"the",
"given",
"ConfigDataNode",
"doesn",
"t",
"already",
"have",
"a",
"value",
"for",
"the",
"given",
"configuration",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L181-L190
|
15,418 |
intelsdi-x/snap
|
core/cdata/node.go
|
DeleteItem
|
func (c ConfigDataNode) DeleteItem(k string) {
c.mutex.Lock()
defer c.mutex.Unlock()
delete(c.table, k)
}
|
go
|
func (c ConfigDataNode) DeleteItem(k string) {
c.mutex.Lock()
defer c.mutex.Unlock()
delete(c.table, k)
}
|
[
"func",
"(",
"c",
"ConfigDataNode",
")",
"DeleteItem",
"(",
"k",
"string",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"c",
".",
"table",
",",
"k",
")",
"\n",
"}"
] |
// Deletes a field in ConfigDataNode. If the field does not exist Delete is
// considered a no-op
|
[
"Deletes",
"a",
"field",
"in",
"ConfigDataNode",
".",
"If",
"the",
"field",
"does",
"not",
"exist",
"Delete",
"is",
"considered",
"a",
"no",
"-",
"op"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/cdata/node.go#L194-L198
|
15,419 |
intelsdi-x/snap
|
mgmt/tribe/tribe.go
|
broadcast
|
func (t *tribe) broadcast(mt msgType, msg interface{}, notify chan<- struct{}) error {
raw, err := encodeMessage(mt, msg)
if err != nil {
return err
}
t.broadcasts.QueueBroadcast(&broadcast{
msg: raw,
notify: notify,
})
return nil
}
|
go
|
func (t *tribe) broadcast(mt msgType, msg interface{}, notify chan<- struct{}) error {
raw, err := encodeMessage(mt, msg)
if err != nil {
return err
}
t.broadcasts.QueueBroadcast(&broadcast{
msg: raw,
notify: notify,
})
return nil
}
|
[
"func",
"(",
"t",
"*",
"tribe",
")",
"broadcast",
"(",
"mt",
"msgType",
",",
"msg",
"interface",
"{",
"}",
",",
"notify",
"chan",
"<-",
"struct",
"{",
"}",
")",
"error",
"{",
"raw",
",",
"err",
":=",
"encodeMessage",
"(",
"mt",
",",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"t",
".",
"broadcasts",
".",
"QueueBroadcast",
"(",
"&",
"broadcast",
"{",
"msg",
":",
"raw",
",",
"notify",
":",
"notify",
",",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// broadcast takes a tribe message type, encodes it for the wire, and queues
// the broadcast. If a notify channel is given, this channel will be closed
// when the broadcast is sent.
|
[
"broadcast",
"takes",
"a",
"tribe",
"message",
"type",
"encodes",
"it",
"for",
"the",
"wire",
"and",
"queues",
"the",
"broadcast",
".",
"If",
"a",
"notify",
"channel",
"is",
"given",
"this",
"channel",
"will",
"be",
"closed",
"when",
"the",
"broadcast",
"is",
"sent",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/tribe/tribe.go#L435-L446
|
15,420 |
intelsdi-x/snap
|
mgmt/rest/config.go
|
GetDefaultConfig
|
func GetDefaultConfig() *Config {
return &Config{
Enable: defaultEnable,
Port: defaultPort,
Address: defaultAddress,
HTTPS: defaultHTTPS,
RestCertificate: defaultRestCertificate,
RestKey: defaultRestKey,
RestAuth: defaultAuth,
RestAuthPassword: defaultAuthPassword,
portSetByConfig: defaultPortSetByConfig,
Pprof: defaultPprof,
Corsd: defaultCorsd,
}
}
|
go
|
func GetDefaultConfig() *Config {
return &Config{
Enable: defaultEnable,
Port: defaultPort,
Address: defaultAddress,
HTTPS: defaultHTTPS,
RestCertificate: defaultRestCertificate,
RestKey: defaultRestKey,
RestAuth: defaultAuth,
RestAuthPassword: defaultAuthPassword,
portSetByConfig: defaultPortSetByConfig,
Pprof: defaultPprof,
Corsd: defaultCorsd,
}
}
|
[
"func",
"GetDefaultConfig",
"(",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"Enable",
":",
"defaultEnable",
",",
"Port",
":",
"defaultPort",
",",
"Address",
":",
"defaultAddress",
",",
"HTTPS",
":",
"defaultHTTPS",
",",
"RestCertificate",
":",
"defaultRestCertificate",
",",
"RestKey",
":",
"defaultRestKey",
",",
"RestAuth",
":",
"defaultAuth",
",",
"RestAuthPassword",
":",
"defaultAuthPassword",
",",
"portSetByConfig",
":",
"defaultPortSetByConfig",
",",
"Pprof",
":",
"defaultPprof",
",",
"Corsd",
":",
"defaultCorsd",
",",
"}",
"\n",
"}"
] |
// GetDefaultConfig gets the default snapteld configuration
|
[
"GetDefaultConfig",
"gets",
"the",
"default",
"snapteld",
"configuration"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/config.go#L80-L94
|
15,421 |
intelsdi-x/snap
|
core/task.go
|
TaskDeadlineDuration
|
func TaskDeadlineDuration(v time.Duration) TaskOption {
return func(t Task) TaskOption {
previous := t.DeadlineDuration()
t.SetDeadlineDuration(v)
log.WithFields(log.Fields{
"_module": "core",
"_block": "TaskDeadlineDuration",
"task-id": t.ID(),
"task-name": t.GetName(),
"task deadline duration": t.DeadlineDuration(),
}).Debug("Setting deadlineDuration on task")
return TaskDeadlineDuration(previous)
}
}
|
go
|
func TaskDeadlineDuration(v time.Duration) TaskOption {
return func(t Task) TaskOption {
previous := t.DeadlineDuration()
t.SetDeadlineDuration(v)
log.WithFields(log.Fields{
"_module": "core",
"_block": "TaskDeadlineDuration",
"task-id": t.ID(),
"task-name": t.GetName(),
"task deadline duration": t.DeadlineDuration(),
}).Debug("Setting deadlineDuration on task")
return TaskDeadlineDuration(previous)
}
}
|
[
"func",
"TaskDeadlineDuration",
"(",
"v",
"time",
".",
"Duration",
")",
"TaskOption",
"{",
"return",
"func",
"(",
"t",
"Task",
")",
"TaskOption",
"{",
"previous",
":=",
"t",
".",
"DeadlineDuration",
"(",
")",
"\n",
"t",
".",
"SetDeadlineDuration",
"(",
"v",
")",
"\n",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"t",
".",
"ID",
"(",
")",
",",
"\"",
"\"",
":",
"t",
".",
"GetName",
"(",
")",
",",
"\"",
"\"",
":",
"t",
".",
"DeadlineDuration",
"(",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"TaskDeadlineDuration",
"(",
"previous",
")",
"\n",
"}",
"\n",
"}"
] |
// TaskDeadlineDuration sets the tasks deadline.
// The deadline is the amount of time that can pass before a worker begins
// processing the tasks collect job.
|
[
"TaskDeadlineDuration",
"sets",
"the",
"tasks",
"deadline",
".",
"The",
"deadline",
"is",
"the",
"amount",
"of",
"time",
"that",
"can",
"pass",
"before",
"a",
"worker",
"begins",
"processing",
"the",
"tasks",
"collect",
"job",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/task.go#L108-L122
|
15,422 |
intelsdi-x/snap
|
core/task.go
|
OptionStopOnFailure
|
func OptionStopOnFailure(v int) TaskOption {
return func(t Task) TaskOption {
previous := t.GetStopOnFailure()
t.SetStopOnFailure(v)
log.WithFields(log.Fields{
"_module": "core",
"_block": "OptionStopOnFailure",
"task-id": t.ID(),
"task-name": t.GetName(),
"consecutive failure limit": t.GetStopOnFailure(),
}).Debug("Setting stop-on-failure limit for task")
return OptionStopOnFailure(previous)
}
}
|
go
|
func OptionStopOnFailure(v int) TaskOption {
return func(t Task) TaskOption {
previous := t.GetStopOnFailure()
t.SetStopOnFailure(v)
log.WithFields(log.Fields{
"_module": "core",
"_block": "OptionStopOnFailure",
"task-id": t.ID(),
"task-name": t.GetName(),
"consecutive failure limit": t.GetStopOnFailure(),
}).Debug("Setting stop-on-failure limit for task")
return OptionStopOnFailure(previous)
}
}
|
[
"func",
"OptionStopOnFailure",
"(",
"v",
"int",
")",
"TaskOption",
"{",
"return",
"func",
"(",
"t",
"Task",
")",
"TaskOption",
"{",
"previous",
":=",
"t",
".",
"GetStopOnFailure",
"(",
")",
"\n",
"t",
".",
"SetStopOnFailure",
"(",
"v",
")",
"\n",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"t",
".",
"ID",
"(",
")",
",",
"\"",
"\"",
":",
"t",
".",
"GetName",
"(",
")",
",",
"\"",
"\"",
":",
"t",
".",
"GetStopOnFailure",
"(",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"OptionStopOnFailure",
"(",
"previous",
")",
"\n",
"}",
"\n",
"}"
] |
// TaskStopOnFailure sets the tasks stopOnFailure
// The stopOnFailure is the number of consecutive task failures that will
// trigger disabling the task
|
[
"TaskStopOnFailure",
"sets",
"the",
"tasks",
"stopOnFailure",
"The",
"stopOnFailure",
"is",
"the",
"number",
"of",
"consecutive",
"task",
"failures",
"that",
"will",
"trigger",
"disabling",
"the",
"task"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/task.go#L127-L140
|
15,423 |
intelsdi-x/snap
|
control/control.go
|
CacheExpiration
|
func CacheExpiration(t time.Duration) PluginControlOpt {
return func(c *pluginControl) {
strategy.GlobalCacheExpiration = t
}
}
|
go
|
func CacheExpiration(t time.Duration) PluginControlOpt {
return func(c *pluginControl) {
strategy.GlobalCacheExpiration = t
}
}
|
[
"func",
"CacheExpiration",
"(",
"t",
"time",
".",
"Duration",
")",
"PluginControlOpt",
"{",
"return",
"func",
"(",
"c",
"*",
"pluginControl",
")",
"{",
"strategy",
".",
"GlobalCacheExpiration",
"=",
"t",
"\n",
"}",
"\n",
"}"
] |
// CacheExpiration is the PluginControlOpt which sets the global metric cache TTL
|
[
"CacheExpiration",
"is",
"the",
"PluginControlOpt",
"which",
"sets",
"the",
"global",
"metric",
"cache",
"TTL"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L167-L171
|
15,424 |
intelsdi-x/snap
|
control/control.go
|
OptSetConfig
|
func OptSetConfig(cfg *Config) PluginControlOpt {
return func(c *pluginControl) {
c.Config = cfg
c.pluginManager.SetPluginConfig(cfg.Plugins)
c.pluginManager.SetPluginLoadTimeout(c.Config.PluginLoadTimeout)
c.pluginRunner.SetPluginLoadTimeout(c.Config.PluginLoadTimeout)
}
}
|
go
|
func OptSetConfig(cfg *Config) PluginControlOpt {
return func(c *pluginControl) {
c.Config = cfg
c.pluginManager.SetPluginConfig(cfg.Plugins)
c.pluginManager.SetPluginLoadTimeout(c.Config.PluginLoadTimeout)
c.pluginRunner.SetPluginLoadTimeout(c.Config.PluginLoadTimeout)
}
}
|
[
"func",
"OptSetConfig",
"(",
"cfg",
"*",
"Config",
")",
"PluginControlOpt",
"{",
"return",
"func",
"(",
"c",
"*",
"pluginControl",
")",
"{",
"c",
".",
"Config",
"=",
"cfg",
"\n",
"c",
".",
"pluginManager",
".",
"SetPluginConfig",
"(",
"cfg",
".",
"Plugins",
")",
"\n",
"c",
".",
"pluginManager",
".",
"SetPluginLoadTimeout",
"(",
"c",
".",
"Config",
".",
"PluginLoadTimeout",
")",
"\n",
"c",
".",
"pluginRunner",
".",
"SetPluginLoadTimeout",
"(",
"c",
".",
"Config",
".",
"PluginLoadTimeout",
")",
"\n",
"}",
"\n",
"}"
] |
// OptSetConfig sets the plugin control configuration.
|
[
"OptSetConfig",
"sets",
"the",
"plugin",
"control",
"configuration",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L174-L181
|
15,425 |
intelsdi-x/snap
|
control/control.go
|
OptSetTags
|
func OptSetTags(tags map[string]map[string]string) PluginControlOpt {
return func(c *pluginControl) {
c.pluginManager.SetPluginTags(tags)
}
}
|
go
|
func OptSetTags(tags map[string]map[string]string) PluginControlOpt {
return func(c *pluginControl) {
c.pluginManager.SetPluginTags(tags)
}
}
|
[
"func",
"OptSetTags",
"(",
"tags",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"string",
")",
"PluginControlOpt",
"{",
"return",
"func",
"(",
"c",
"*",
"pluginControl",
")",
"{",
"c",
".",
"pluginManager",
".",
"SetPluginTags",
"(",
"tags",
")",
"\n",
"}",
"\n",
"}"
] |
// OptSetTags sets the plugin control tags.
|
[
"OptSetTags",
"sets",
"the",
"plugin",
"control",
"tags",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L184-L188
|
15,426 |
intelsdi-x/snap
|
control/control.go
|
New
|
func New(cfg *Config) *pluginControl {
// construct a slice of options from the input configuration
opts := []PluginControlOpt{
MaxRunningPlugins(cfg.MaxRunningPlugins),
CacheExpiration(cfg.CacheExpiration.Duration),
OptSetConfig(cfg),
OptSetTags(cfg.Tags),
MaxPluginRestarts(cfg),
}
c := &pluginControl{}
c.Config = cfg
// Initialize components
// Event Manager
c.eventManager = gomit.NewEventController()
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("pevent controller created")
// Metric Catalog
c.metricCatalog = newMetricCatalog()
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("metric catalog created")
managerOpts := []pluginManagerOpt{
OptSetPprof(cfg.Pprof),
OptSetTempDirPath(cfg.TempDirPath),
}
runnerOpts := []pluginRunnerOpt{}
if cfg.IsTLSEnabled() {
if cfg.CACertPaths != "" {
certPaths := filepath.SplitList(cfg.CACertPaths)
c.grpcSecurity = client.SecurityTLSExtended(cfg.TLSCertPath, cfg.TLSKeyPath, client.SecureClient, certPaths)
} else {
c.grpcSecurity = client.SecurityTLSEnabled(cfg.TLSCertPath, cfg.TLSKeyPath, client.SecureClient)
}
managerOpts = append(managerOpts, OptEnableManagerTLS(c.grpcSecurity))
runnerOpts = append(runnerOpts, OptEnableRunnerTLS(c.grpcSecurity))
}
// Plugin Manager
c.pluginManager = newPluginManager(managerOpts...)
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("plugin manager created")
// Plugin Manager needs a reference to the metric catalog
c.pluginManager.SetMetricCatalog(c.metricCatalog)
// Signing Manager
c.signingManager = &psigning.SigningManager{}
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("signing manager created")
// Plugin Runner
c.pluginRunner = newRunner(runnerOpts...)
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("runner created")
c.pluginRunner.AddDelegates(c.eventManager)
c.pluginRunner.SetEmitter(c.eventManager)
c.pluginRunner.SetMetricCatalog(c.metricCatalog)
c.pluginRunner.SetPluginManager(c.pluginManager)
// Pass runner events to control main module
c.eventManager.RegisterHandler(c.Name(), c)
// Create subscription group - used for managing a group of subscriptions
c.subscriptionGroups = newSubscriptionGroups(c)
// Start stuff
err := c.pluginRunner.Start()
if err != nil {
panic(err)
}
// apply options
// it is important that this happens last, as an option may
// require that an internal member of c be constructed.
for _, opt := range opts {
opt(c)
}
return c
}
|
go
|
func New(cfg *Config) *pluginControl {
// construct a slice of options from the input configuration
opts := []PluginControlOpt{
MaxRunningPlugins(cfg.MaxRunningPlugins),
CacheExpiration(cfg.CacheExpiration.Duration),
OptSetConfig(cfg),
OptSetTags(cfg.Tags),
MaxPluginRestarts(cfg),
}
c := &pluginControl{}
c.Config = cfg
// Initialize components
// Event Manager
c.eventManager = gomit.NewEventController()
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("pevent controller created")
// Metric Catalog
c.metricCatalog = newMetricCatalog()
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("metric catalog created")
managerOpts := []pluginManagerOpt{
OptSetPprof(cfg.Pprof),
OptSetTempDirPath(cfg.TempDirPath),
}
runnerOpts := []pluginRunnerOpt{}
if cfg.IsTLSEnabled() {
if cfg.CACertPaths != "" {
certPaths := filepath.SplitList(cfg.CACertPaths)
c.grpcSecurity = client.SecurityTLSExtended(cfg.TLSCertPath, cfg.TLSKeyPath, client.SecureClient, certPaths)
} else {
c.grpcSecurity = client.SecurityTLSEnabled(cfg.TLSCertPath, cfg.TLSKeyPath, client.SecureClient)
}
managerOpts = append(managerOpts, OptEnableManagerTLS(c.grpcSecurity))
runnerOpts = append(runnerOpts, OptEnableRunnerTLS(c.grpcSecurity))
}
// Plugin Manager
c.pluginManager = newPluginManager(managerOpts...)
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("plugin manager created")
// Plugin Manager needs a reference to the metric catalog
c.pluginManager.SetMetricCatalog(c.metricCatalog)
// Signing Manager
c.signingManager = &psigning.SigningManager{}
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("signing manager created")
// Plugin Runner
c.pluginRunner = newRunner(runnerOpts...)
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("runner created")
c.pluginRunner.AddDelegates(c.eventManager)
c.pluginRunner.SetEmitter(c.eventManager)
c.pluginRunner.SetMetricCatalog(c.metricCatalog)
c.pluginRunner.SetPluginManager(c.pluginManager)
// Pass runner events to control main module
c.eventManager.RegisterHandler(c.Name(), c)
// Create subscription group - used for managing a group of subscriptions
c.subscriptionGroups = newSubscriptionGroups(c)
// Start stuff
err := c.pluginRunner.Start()
if err != nil {
panic(err)
}
// apply options
// it is important that this happens last, as an option may
// require that an internal member of c be constructed.
for _, opt := range opts {
opt(c)
}
return c
}
|
[
"func",
"New",
"(",
"cfg",
"*",
"Config",
")",
"*",
"pluginControl",
"{",
"// construct a slice of options from the input configuration",
"opts",
":=",
"[",
"]",
"PluginControlOpt",
"{",
"MaxRunningPlugins",
"(",
"cfg",
".",
"MaxRunningPlugins",
")",
",",
"CacheExpiration",
"(",
"cfg",
".",
"CacheExpiration",
".",
"Duration",
")",
",",
"OptSetConfig",
"(",
"cfg",
")",
",",
"OptSetTags",
"(",
"cfg",
".",
"Tags",
")",
",",
"MaxPluginRestarts",
"(",
"cfg",
")",
",",
"}",
"\n",
"c",
":=",
"&",
"pluginControl",
"{",
"}",
"\n",
"c",
".",
"Config",
"=",
"cfg",
"\n",
"// Initialize components",
"// Event Manager",
"c",
".",
"eventManager",
"=",
"gomit",
".",
"NewEventController",
"(",
")",
"\n\n",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// Metric Catalog",
"c",
".",
"metricCatalog",
"=",
"newMetricCatalog",
"(",
")",
"\n",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"managerOpts",
":=",
"[",
"]",
"pluginManagerOpt",
"{",
"OptSetPprof",
"(",
"cfg",
".",
"Pprof",
")",
",",
"OptSetTempDirPath",
"(",
"cfg",
".",
"TempDirPath",
")",
",",
"}",
"\n",
"runnerOpts",
":=",
"[",
"]",
"pluginRunnerOpt",
"{",
"}",
"\n",
"if",
"cfg",
".",
"IsTLSEnabled",
"(",
")",
"{",
"if",
"cfg",
".",
"CACertPaths",
"!=",
"\"",
"\"",
"{",
"certPaths",
":=",
"filepath",
".",
"SplitList",
"(",
"cfg",
".",
"CACertPaths",
")",
"\n",
"c",
".",
"grpcSecurity",
"=",
"client",
".",
"SecurityTLSExtended",
"(",
"cfg",
".",
"TLSCertPath",
",",
"cfg",
".",
"TLSKeyPath",
",",
"client",
".",
"SecureClient",
",",
"certPaths",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"grpcSecurity",
"=",
"client",
".",
"SecurityTLSEnabled",
"(",
"cfg",
".",
"TLSCertPath",
",",
"cfg",
".",
"TLSKeyPath",
",",
"client",
".",
"SecureClient",
")",
"\n",
"}",
"\n",
"managerOpts",
"=",
"append",
"(",
"managerOpts",
",",
"OptEnableManagerTLS",
"(",
"c",
".",
"grpcSecurity",
")",
")",
"\n",
"runnerOpts",
"=",
"append",
"(",
"runnerOpts",
",",
"OptEnableRunnerTLS",
"(",
"c",
".",
"grpcSecurity",
")",
")",
"\n",
"}",
"\n",
"// Plugin Manager",
"c",
".",
"pluginManager",
"=",
"newPluginManager",
"(",
"managerOpts",
"...",
")",
"\n",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// Plugin Manager needs a reference to the metric catalog",
"c",
".",
"pluginManager",
".",
"SetMetricCatalog",
"(",
"c",
".",
"metricCatalog",
")",
"\n\n",
"// Signing Manager",
"c",
".",
"signingManager",
"=",
"&",
"psigning",
".",
"SigningManager",
"{",
"}",
"\n",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// Plugin Runner",
"c",
".",
"pluginRunner",
"=",
"newRunner",
"(",
"runnerOpts",
"...",
")",
"\n",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"c",
".",
"pluginRunner",
".",
"AddDelegates",
"(",
"c",
".",
"eventManager",
")",
"\n",
"c",
".",
"pluginRunner",
".",
"SetEmitter",
"(",
"c",
".",
"eventManager",
")",
"\n",
"c",
".",
"pluginRunner",
".",
"SetMetricCatalog",
"(",
"c",
".",
"metricCatalog",
")",
"\n",
"c",
".",
"pluginRunner",
".",
"SetPluginManager",
"(",
"c",
".",
"pluginManager",
")",
"\n\n",
"// Pass runner events to control main module",
"c",
".",
"eventManager",
".",
"RegisterHandler",
"(",
"c",
".",
"Name",
"(",
")",
",",
"c",
")",
"\n\n",
"// Create subscription group - used for managing a group of subscriptions",
"c",
".",
"subscriptionGroups",
"=",
"newSubscriptionGroups",
"(",
"c",
")",
"\n\n",
"// Start stuff",
"err",
":=",
"c",
".",
"pluginRunner",
".",
"Start",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// apply options",
"// it is important that this happens last, as an option may",
"// require that an internal member of c be constructed.",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"c",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] |
// New returns a new pluginControl instance
|
[
"New",
"returns",
"a",
"new",
"pluginControl",
"instance"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L198-L283
|
15,427 |
intelsdi-x/snap
|
control/control.go
|
Load
|
func (p *pluginControl) Load(rp *core.RequestedPlugin) (core.CatalogedPlugin, serror.SnapError) {
f := map[string]interface{}{
"_block": "load",
}
details, serr := p.returnPluginDetails(rp)
if serr != nil {
return nil, serr
}
if details.IsPackage {
defer os.RemoveAll(filepath.Dir(details.ExecPath))
}
controlLogger.WithFields(f).Info("plugin load called")
if !p.Started {
se := serror.New(ErrControllerNotStarted)
se.SetFields(f)
controlLogger.WithFields(f).Error(se)
return nil, se
}
pl, se := p.pluginManager.LoadPlugin(details, p.eventManager)
if se != nil {
return nil, se
}
// If plugin was loaded from a package, remove ExecPath for
// the temporary plugin that was used for load
if pl.Details.IsPackage {
pl.Details.ExecPath = ""
}
// defer sending event
event := &control_event.LoadPluginEvent{
Name: pl.Meta.Name,
Version: pl.Meta.Version,
Type: int(pl.Meta.Type),
Signed: pl.Details.Signed,
}
defer p.eventManager.Emit(event)
return pl, nil
}
|
go
|
func (p *pluginControl) Load(rp *core.RequestedPlugin) (core.CatalogedPlugin, serror.SnapError) {
f := map[string]interface{}{
"_block": "load",
}
details, serr := p.returnPluginDetails(rp)
if serr != nil {
return nil, serr
}
if details.IsPackage {
defer os.RemoveAll(filepath.Dir(details.ExecPath))
}
controlLogger.WithFields(f).Info("plugin load called")
if !p.Started {
se := serror.New(ErrControllerNotStarted)
se.SetFields(f)
controlLogger.WithFields(f).Error(se)
return nil, se
}
pl, se := p.pluginManager.LoadPlugin(details, p.eventManager)
if se != nil {
return nil, se
}
// If plugin was loaded from a package, remove ExecPath for
// the temporary plugin that was used for load
if pl.Details.IsPackage {
pl.Details.ExecPath = ""
}
// defer sending event
event := &control_event.LoadPluginEvent{
Name: pl.Meta.Name,
Version: pl.Meta.Version,
Type: int(pl.Meta.Type),
Signed: pl.Details.Signed,
}
defer p.eventManager.Emit(event)
return pl, nil
}
|
[
"func",
"(",
"p",
"*",
"pluginControl",
")",
"Load",
"(",
"rp",
"*",
"core",
".",
"RequestedPlugin",
")",
"(",
"core",
".",
"CatalogedPlugin",
",",
"serror",
".",
"SnapError",
")",
"{",
"f",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"details",
",",
"serr",
":=",
"p",
".",
"returnPluginDetails",
"(",
"rp",
")",
"\n",
"if",
"serr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"serr",
"\n",
"}",
"\n",
"if",
"details",
".",
"IsPackage",
"{",
"defer",
"os",
".",
"RemoveAll",
"(",
"filepath",
".",
"Dir",
"(",
"details",
".",
"ExecPath",
")",
")",
"\n",
"}",
"\n\n",
"controlLogger",
".",
"WithFields",
"(",
"f",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"p",
".",
"Started",
"{",
"se",
":=",
"serror",
".",
"New",
"(",
"ErrControllerNotStarted",
")",
"\n",
"se",
".",
"SetFields",
"(",
"f",
")",
"\n",
"controlLogger",
".",
"WithFields",
"(",
"f",
")",
".",
"Error",
"(",
"se",
")",
"\n",
"return",
"nil",
",",
"se",
"\n",
"}",
"\n\n",
"pl",
",",
"se",
":=",
"p",
".",
"pluginManager",
".",
"LoadPlugin",
"(",
"details",
",",
"p",
".",
"eventManager",
")",
"\n",
"if",
"se",
"!=",
"nil",
"{",
"return",
"nil",
",",
"se",
"\n",
"}",
"\n\n",
"// If plugin was loaded from a package, remove ExecPath for",
"// the temporary plugin that was used for load",
"if",
"pl",
".",
"Details",
".",
"IsPackage",
"{",
"pl",
".",
"Details",
".",
"ExecPath",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// defer sending event",
"event",
":=",
"&",
"control_event",
".",
"LoadPluginEvent",
"{",
"Name",
":",
"pl",
".",
"Meta",
".",
"Name",
",",
"Version",
":",
"pl",
".",
"Meta",
".",
"Version",
",",
"Type",
":",
"int",
"(",
"pl",
".",
"Meta",
".",
"Type",
")",
",",
"Signed",
":",
"pl",
".",
"Details",
".",
"Signed",
",",
"}",
"\n",
"defer",
"p",
".",
"eventManager",
".",
"Emit",
"(",
"event",
")",
"\n",
"return",
"pl",
",",
"nil",
"\n",
"}"
] |
// Load is the public method to load a plugin into
// the LoadedPlugins array and issue an event when
// successful.
|
[
"Load",
"is",
"the",
"public",
"method",
"to",
"load",
"a",
"plugin",
"into",
"the",
"LoadedPlugins",
"array",
"and",
"issue",
"an",
"event",
"when",
"successful",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L523-L564
|
15,428 |
intelsdi-x/snap
|
control/control.go
|
SubscribeDeps
|
func (p *pluginControl) SubscribeDeps(id string, requested []core.RequestedMetric, plugins []core.SubscribedPlugin, configTree *cdata.ConfigDataTree) (serrs []serror.SnapError) {
return p.subscriptionGroups.Add(id, requested, configTree, plugins)
}
|
go
|
func (p *pluginControl) SubscribeDeps(id string, requested []core.RequestedMetric, plugins []core.SubscribedPlugin, configTree *cdata.ConfigDataTree) (serrs []serror.SnapError) {
return p.subscriptionGroups.Add(id, requested, configTree, plugins)
}
|
[
"func",
"(",
"p",
"*",
"pluginControl",
")",
"SubscribeDeps",
"(",
"id",
"string",
",",
"requested",
"[",
"]",
"core",
".",
"RequestedMetric",
",",
"plugins",
"[",
"]",
"core",
".",
"SubscribedPlugin",
",",
"configTree",
"*",
"cdata",
".",
"ConfigDataTree",
")",
"(",
"serrs",
"[",
"]",
"serror",
".",
"SnapError",
")",
"{",
"return",
"p",
".",
"subscriptionGroups",
".",
"Add",
"(",
"id",
",",
"requested",
",",
"configTree",
",",
"plugins",
")",
"\n",
"}"
] |
// SubscribeDeps will subscribe to collectors, processors and publishers. The collectors are subscribed by mapping the provided
// array of core.RequestedMetrics to the corresponding plugins while processors and publishers provided in the array of core.Plugin
// will be subscribed directly. The ID provides a logical grouping of subscriptions.
|
[
"SubscribeDeps",
"will",
"subscribe",
"to",
"collectors",
"processors",
"and",
"publishers",
".",
"The",
"collectors",
"are",
"subscribed",
"by",
"mapping",
"the",
"provided",
"array",
"of",
"core",
".",
"RequestedMetrics",
"to",
"the",
"corresponding",
"plugins",
"while",
"processors",
"and",
"publishers",
"provided",
"in",
"the",
"array",
"of",
"core",
".",
"Plugin",
"will",
"be",
"subscribed",
"directly",
".",
"The",
"ID",
"provides",
"a",
"logical",
"grouping",
"of",
"subscriptions",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L748-L750
|
15,429 |
intelsdi-x/snap
|
control/control.go
|
UnsubscribeDeps
|
func (p *pluginControl) UnsubscribeDeps(id string) []serror.SnapError {
// update view and unsubscribe to plugins
return p.subscriptionGroups.Remove(id)
}
|
go
|
func (p *pluginControl) UnsubscribeDeps(id string) []serror.SnapError {
// update view and unsubscribe to plugins
return p.subscriptionGroups.Remove(id)
}
|
[
"func",
"(",
"p",
"*",
"pluginControl",
")",
"UnsubscribeDeps",
"(",
"id",
"string",
")",
"[",
"]",
"serror",
".",
"SnapError",
"{",
"// update view and unsubscribe to plugins",
"return",
"p",
".",
"subscriptionGroups",
".",
"Remove",
"(",
"id",
")",
"\n",
"}"
] |
// UnsubscribeDeps unsubscribes a group of dependencies provided the subscription group ID
|
[
"UnsubscribeDeps",
"unsubscribes",
"a",
"group",
"of",
"dependencies",
"provided",
"the",
"subscription",
"group",
"ID"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L753-L756
|
15,430 |
intelsdi-x/snap
|
control/control.go
|
SetMonitorOptions
|
func (p *pluginControl) SetMonitorOptions(options ...monitorOption) {
p.pluginRunner.Monitor().Option(options...)
}
|
go
|
func (p *pluginControl) SetMonitorOptions(options ...monitorOption) {
p.pluginRunner.Monitor().Option(options...)
}
|
[
"func",
"(",
"p",
"*",
"pluginControl",
")",
"SetMonitorOptions",
"(",
"options",
"...",
"monitorOption",
")",
"{",
"p",
".",
"pluginRunner",
".",
"Monitor",
"(",
")",
".",
"Option",
"(",
"options",
"...",
")",
"\n",
"}"
] |
// SetMonitorOptions exposes monitors options
|
[
"SetMonitorOptions",
"exposes",
"monitors",
"options"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L878-L880
|
15,431 |
intelsdi-x/snap
|
control/control.go
|
CollectMetrics
|
func (p *pluginControl) CollectMetrics(id string, allTags map[string]map[string]string) (metrics []core.Metric, errs []error) {
// If control is not started we don't want tasks to be able to
// go through a workflow.
if !p.Started {
return nil, []error{ErrControllerNotStarted}
}
// Subscription groups are processed anytime a plugin is loaded/unloaded.
pluginToMetricMap, serrs, err := p.subscriptionGroups.Get(id)
if err != nil {
controlLogger.WithFields(log.Fields{
"_block": "CollectorMetrics",
"subscription-group-id": id,
}).Error(err)
errs = append(errs, err)
return
}
// If We received errors when the requested metrics were last processed
// against the metric catalog we need to return them to the caller.
if serrs != nil {
for _, e := range serrs {
errs = append(errs, e)
}
}
for ns, nsTags := range allTags {
for k, v := range nsTags {
log.WithFields(log.Fields{
"_module": "control",
"block": "CollectMetrics",
"type": "pluginCollector",
"ns": ns,
"tag-key": k,
"tag-val": v,
}).Debug("Tags in CollectMetrics")
}
}
cMetrics := make(chan []core.Metric)
cError := make(chan error)
var wg sync.WaitGroup
// For each available plugin call available plugin using RPC client and wait for response (goroutines)
for pluginKey, pmt := range pluginToMetricMap {
// merge global plugin config into the config for the metric
for _, mt := range pmt.metricTypes {
if mt.Config() != nil {
mt.Config().ReverseMergeInPlace(p.Config.Plugins.getPluginConfigDataNode(core.CollectorPluginType, pmt.plugin.Name(), pmt.plugin.Version()))
}
}
wg.Add(1)
go func(pluginKey string, mt []core.Metric) {
mts, err := p.pluginRunner.AvailablePlugins().collectMetrics(pluginKey, mt, id)
if err != nil {
cError <- err
} else {
cMetrics <- mts
}
}(pluginKey, pmt.metricTypes)
}
go func() {
for m := range cMetrics {
// Reapply standard tags after collection as a precaution. It is common for
// plugin authors to inadvertently overwrite or not pass along the data
// passed to CollectMetrics so we will help them out here.
for i := range m {
m[i] = p.pluginManager.AddStandardAndWorkflowTags(m[i], allTags)
}
metrics = append(metrics, m...)
wg.Done()
}
}()
go func() {
for e := range cError {
errs = append(errs, e)
wg.Done()
}
}()
wg.Wait()
close(cMetrics)
close(cError)
if len(errs) > 0 {
return nil, errs
}
return
}
|
go
|
func (p *pluginControl) CollectMetrics(id string, allTags map[string]map[string]string) (metrics []core.Metric, errs []error) {
// If control is not started we don't want tasks to be able to
// go through a workflow.
if !p.Started {
return nil, []error{ErrControllerNotStarted}
}
// Subscription groups are processed anytime a plugin is loaded/unloaded.
pluginToMetricMap, serrs, err := p.subscriptionGroups.Get(id)
if err != nil {
controlLogger.WithFields(log.Fields{
"_block": "CollectorMetrics",
"subscription-group-id": id,
}).Error(err)
errs = append(errs, err)
return
}
// If We received errors when the requested metrics were last processed
// against the metric catalog we need to return them to the caller.
if serrs != nil {
for _, e := range serrs {
errs = append(errs, e)
}
}
for ns, nsTags := range allTags {
for k, v := range nsTags {
log.WithFields(log.Fields{
"_module": "control",
"block": "CollectMetrics",
"type": "pluginCollector",
"ns": ns,
"tag-key": k,
"tag-val": v,
}).Debug("Tags in CollectMetrics")
}
}
cMetrics := make(chan []core.Metric)
cError := make(chan error)
var wg sync.WaitGroup
// For each available plugin call available plugin using RPC client and wait for response (goroutines)
for pluginKey, pmt := range pluginToMetricMap {
// merge global plugin config into the config for the metric
for _, mt := range pmt.metricTypes {
if mt.Config() != nil {
mt.Config().ReverseMergeInPlace(p.Config.Plugins.getPluginConfigDataNode(core.CollectorPluginType, pmt.plugin.Name(), pmt.plugin.Version()))
}
}
wg.Add(1)
go func(pluginKey string, mt []core.Metric) {
mts, err := p.pluginRunner.AvailablePlugins().collectMetrics(pluginKey, mt, id)
if err != nil {
cError <- err
} else {
cMetrics <- mts
}
}(pluginKey, pmt.metricTypes)
}
go func() {
for m := range cMetrics {
// Reapply standard tags after collection as a precaution. It is common for
// plugin authors to inadvertently overwrite or not pass along the data
// passed to CollectMetrics so we will help them out here.
for i := range m {
m[i] = p.pluginManager.AddStandardAndWorkflowTags(m[i], allTags)
}
metrics = append(metrics, m...)
wg.Done()
}
}()
go func() {
for e := range cError {
errs = append(errs, e)
wg.Done()
}
}()
wg.Wait()
close(cMetrics)
close(cError)
if len(errs) > 0 {
return nil, errs
}
return
}
|
[
"func",
"(",
"p",
"*",
"pluginControl",
")",
"CollectMetrics",
"(",
"id",
"string",
",",
"allTags",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"metrics",
"[",
"]",
"core",
".",
"Metric",
",",
"errs",
"[",
"]",
"error",
")",
"{",
"// If control is not started we don't want tasks to be able to",
"// go through a workflow.",
"if",
"!",
"p",
".",
"Started",
"{",
"return",
"nil",
",",
"[",
"]",
"error",
"{",
"ErrControllerNotStarted",
"}",
"\n",
"}",
"\n\n",
"// Subscription groups are processed anytime a plugin is loaded/unloaded.",
"pluginToMetricMap",
",",
"serrs",
",",
"err",
":=",
"p",
".",
"subscriptionGroups",
".",
"Get",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"errs",
"=",
"append",
"(",
"errs",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// If We received errors when the requested metrics were last processed",
"// against the metric catalog we need to return them to the caller.",
"if",
"serrs",
"!=",
"nil",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"serrs",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"e",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"ns",
",",
"nsTags",
":=",
"range",
"allTags",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"nsTags",
"{",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"ns",
",",
"\"",
"\"",
":",
"k",
",",
"\"",
"\"",
":",
"v",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"cMetrics",
":=",
"make",
"(",
"chan",
"[",
"]",
"core",
".",
"Metric",
")",
"\n",
"cError",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n\n",
"// For each available plugin call available plugin using RPC client and wait for response (goroutines)",
"for",
"pluginKey",
",",
"pmt",
":=",
"range",
"pluginToMetricMap",
"{",
"// merge global plugin config into the config for the metric",
"for",
"_",
",",
"mt",
":=",
"range",
"pmt",
".",
"metricTypes",
"{",
"if",
"mt",
".",
"Config",
"(",
")",
"!=",
"nil",
"{",
"mt",
".",
"Config",
"(",
")",
".",
"ReverseMergeInPlace",
"(",
"p",
".",
"Config",
".",
"Plugins",
".",
"getPluginConfigDataNode",
"(",
"core",
".",
"CollectorPluginType",
",",
"pmt",
".",
"plugin",
".",
"Name",
"(",
")",
",",
"pmt",
".",
"plugin",
".",
"Version",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n\n",
"go",
"func",
"(",
"pluginKey",
"string",
",",
"mt",
"[",
"]",
"core",
".",
"Metric",
")",
"{",
"mts",
",",
"err",
":=",
"p",
".",
"pluginRunner",
".",
"AvailablePlugins",
"(",
")",
".",
"collectMetrics",
"(",
"pluginKey",
",",
"mt",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cError",
"<-",
"err",
"\n",
"}",
"else",
"{",
"cMetrics",
"<-",
"mts",
"\n",
"}",
"\n",
"}",
"(",
"pluginKey",
",",
"pmt",
".",
"metricTypes",
")",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"m",
":=",
"range",
"cMetrics",
"{",
"// Reapply standard tags after collection as a precaution. It is common for",
"// plugin authors to inadvertently overwrite or not pass along the data",
"// passed to CollectMetrics so we will help them out here.",
"for",
"i",
":=",
"range",
"m",
"{",
"m",
"[",
"i",
"]",
"=",
"p",
".",
"pluginManager",
".",
"AddStandardAndWorkflowTags",
"(",
"m",
"[",
"i",
"]",
",",
"allTags",
")",
"\n",
"}",
"\n",
"metrics",
"=",
"append",
"(",
"metrics",
",",
"m",
"...",
")",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"e",
":=",
"range",
"cError",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"e",
")",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"cMetrics",
")",
"\n",
"close",
"(",
"cError",
")",
"\n\n",
"if",
"len",
"(",
"errs",
")",
">",
"0",
"{",
"return",
"nil",
",",
"errs",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// CollectMetrics is a blocking call to collector plugins returning a collection
// of metrics and errors. If an error is encountered no metrics will be
// returned.
|
[
"CollectMetrics",
"is",
"a",
"blocking",
"call",
"to",
"collector",
"plugins",
"returning",
"a",
"collection",
"of",
"metrics",
"and",
"errors",
".",
"If",
"an",
"error",
"is",
"encountered",
"no",
"metrics",
"will",
"be",
"returned",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/control.go#L988-L1079
|
15,432 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
New
|
func New(cfg *Config) *scheduler {
schedulerLogger.WithFields(log.Fields{
"_block": "New",
"value": cfg.WorkManagerQueueSize,
}).Info("Setting work manager queue size")
schedulerLogger.WithFields(log.Fields{
"_block": "New",
"value": cfg.WorkManagerPoolSize,
}).Info("Setting work manager pool size")
opts := []workManagerOption{
CollectQSizeOption(cfg.WorkManagerQueueSize),
CollectWkrSizeOption(cfg.WorkManagerPoolSize),
PublishQSizeOption(cfg.WorkManagerQueueSize),
PublishWkrSizeOption(cfg.WorkManagerPoolSize),
ProcessQSizeOption(cfg.WorkManagerQueueSize),
ProcessWkrSizeOption(cfg.WorkManagerPoolSize),
}
s := &scheduler{
tasks: newTaskCollection(),
eventManager: gomit.NewEventController(),
taskWatcherColl: newTaskWatcherCollection(),
}
// we are setting the size of the queue and number of workers for
// collect, process and publish consistently for now
s.workManager = newWorkManager(opts...)
s.workManager.Start()
s.eventManager.RegisterHandler(HandlerRegistrationName, s)
return s
}
|
go
|
func New(cfg *Config) *scheduler {
schedulerLogger.WithFields(log.Fields{
"_block": "New",
"value": cfg.WorkManagerQueueSize,
}).Info("Setting work manager queue size")
schedulerLogger.WithFields(log.Fields{
"_block": "New",
"value": cfg.WorkManagerPoolSize,
}).Info("Setting work manager pool size")
opts := []workManagerOption{
CollectQSizeOption(cfg.WorkManagerQueueSize),
CollectWkrSizeOption(cfg.WorkManagerPoolSize),
PublishQSizeOption(cfg.WorkManagerQueueSize),
PublishWkrSizeOption(cfg.WorkManagerPoolSize),
ProcessQSizeOption(cfg.WorkManagerQueueSize),
ProcessWkrSizeOption(cfg.WorkManagerPoolSize),
}
s := &scheduler{
tasks: newTaskCollection(),
eventManager: gomit.NewEventController(),
taskWatcherColl: newTaskWatcherCollection(),
}
// we are setting the size of the queue and number of workers for
// collect, process and publish consistently for now
s.workManager = newWorkManager(opts...)
s.workManager.Start()
s.eventManager.RegisterHandler(HandlerRegistrationName, s)
return s
}
|
[
"func",
"New",
"(",
"cfg",
"*",
"Config",
")",
"*",
"scheduler",
"{",
"schedulerLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"cfg",
".",
"WorkManagerQueueSize",
",",
"}",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"schedulerLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"cfg",
".",
"WorkManagerPoolSize",
",",
"}",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"opts",
":=",
"[",
"]",
"workManagerOption",
"{",
"CollectQSizeOption",
"(",
"cfg",
".",
"WorkManagerQueueSize",
")",
",",
"CollectWkrSizeOption",
"(",
"cfg",
".",
"WorkManagerPoolSize",
")",
",",
"PublishQSizeOption",
"(",
"cfg",
".",
"WorkManagerQueueSize",
")",
",",
"PublishWkrSizeOption",
"(",
"cfg",
".",
"WorkManagerPoolSize",
")",
",",
"ProcessQSizeOption",
"(",
"cfg",
".",
"WorkManagerQueueSize",
")",
",",
"ProcessWkrSizeOption",
"(",
"cfg",
".",
"WorkManagerPoolSize",
")",
",",
"}",
"\n",
"s",
":=",
"&",
"scheduler",
"{",
"tasks",
":",
"newTaskCollection",
"(",
")",
",",
"eventManager",
":",
"gomit",
".",
"NewEventController",
"(",
")",
",",
"taskWatcherColl",
":",
"newTaskWatcherCollection",
"(",
")",
",",
"}",
"\n\n",
"// we are setting the size of the queue and number of workers for",
"// collect, process and publish consistently for now",
"s",
".",
"workManager",
"=",
"newWorkManager",
"(",
"opts",
"...",
")",
"\n",
"s",
".",
"workManager",
".",
"Start",
"(",
")",
"\n",
"s",
".",
"eventManager",
".",
"RegisterHandler",
"(",
"HandlerRegistrationName",
",",
"s",
")",
"\n\n",
"return",
"s",
"\n",
"}"
] |
// New returns an instance of the scheduler
// The MetricManager must be set before the scheduler can be started.
// The MetricManager must be started before it can be used.
|
[
"New",
"returns",
"an",
"instance",
"of",
"the",
"scheduler",
"The",
"MetricManager",
"must",
"be",
"set",
"before",
"the",
"scheduler",
"can",
"be",
"started",
".",
"The",
"MetricManager",
"must",
"be",
"started",
"before",
"it",
"can",
"be",
"used",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L243-L273
|
15,433 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
CreateTask
|
func (s *scheduler) CreateTask(sch schedule.Schedule, wfMap *wmap.WorkflowMap, startOnCreate bool, opts ...core.TaskOption) (core.Task, core.TaskErrors) {
return s.createTask(sch, wfMap, startOnCreate, "user", opts...)
}
|
go
|
func (s *scheduler) CreateTask(sch schedule.Schedule, wfMap *wmap.WorkflowMap, startOnCreate bool, opts ...core.TaskOption) (core.Task, core.TaskErrors) {
return s.createTask(sch, wfMap, startOnCreate, "user", opts...)
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"CreateTask",
"(",
"sch",
"schedule",
".",
"Schedule",
",",
"wfMap",
"*",
"wmap",
".",
"WorkflowMap",
",",
"startOnCreate",
"bool",
",",
"opts",
"...",
"core",
".",
"TaskOption",
")",
"(",
"core",
".",
"Task",
",",
"core",
".",
"TaskErrors",
")",
"{",
"return",
"s",
".",
"createTask",
"(",
"sch",
",",
"wfMap",
",",
"startOnCreate",
",",
"\"",
"\"",
",",
"opts",
"...",
")",
"\n",
"}"
] |
// CreateTask creates and returns task
|
[
"CreateTask",
"creates",
"and",
"returns",
"task"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L292-L294
|
15,434 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
GetTasks
|
func (s *scheduler) GetTasks() map[string]core.Task {
tasks := make(map[string]core.Task)
for id, t := range s.tasks.Table() {
tasks[id] = t
}
return tasks
}
|
go
|
func (s *scheduler) GetTasks() map[string]core.Task {
tasks := make(map[string]core.Task)
for id, t := range s.tasks.Table() {
tasks[id] = t
}
return tasks
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"GetTasks",
"(",
")",
"map",
"[",
"string",
"]",
"core",
".",
"Task",
"{",
"tasks",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"core",
".",
"Task",
")",
"\n",
"for",
"id",
",",
"t",
":=",
"range",
"s",
".",
"tasks",
".",
"Table",
"(",
")",
"{",
"tasks",
"[",
"id",
"]",
"=",
"t",
"\n",
"}",
"\n",
"return",
"tasks",
"\n",
"}"
] |
// GetTasks returns a copy of the tasks in a map where the task id is the key
|
[
"GetTasks",
"returns",
"a",
"copy",
"of",
"the",
"tasks",
"in",
"a",
"map",
"where",
"the",
"task",
"id",
"is",
"the",
"key"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L486-L492
|
15,435 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
GetTask
|
func (s *scheduler) GetTask(id string) (core.Task, error) {
t, err := s.getTask(id)
if err != nil {
schedulerLogger.WithFields(log.Fields{
"_block": "get-task",
"_error": ErrTaskNotFound,
"task-id": id,
}).Error("error getting task")
return nil, err // We do this to send back an explicit nil on the interface
}
return t, nil
}
|
go
|
func (s *scheduler) GetTask(id string) (core.Task, error) {
t, err := s.getTask(id)
if err != nil {
schedulerLogger.WithFields(log.Fields{
"_block": "get-task",
"_error": ErrTaskNotFound,
"task-id": id,
}).Error("error getting task")
return nil, err // We do this to send back an explicit nil on the interface
}
return t, nil
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"GetTask",
"(",
"id",
"string",
")",
"(",
"core",
".",
"Task",
",",
"error",
")",
"{",
"t",
",",
"err",
":=",
"s",
".",
"getTask",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"schedulerLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"ErrTaskNotFound",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"// We do this to send back an explicit nil on the interface",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] |
// GetTask provided the task id a task is returned
|
[
"GetTask",
"provided",
"the",
"task",
"id",
"a",
"task",
"is",
"returned"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L495-L506
|
15,436 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
StartTask
|
func (s *scheduler) StartTask(id string) []serror.SnapError {
return s.startTask(id, "user")
}
|
go
|
func (s *scheduler) StartTask(id string) []serror.SnapError {
return s.startTask(id, "user")
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"StartTask",
"(",
"id",
"string",
")",
"[",
"]",
"serror",
".",
"SnapError",
"{",
"return",
"s",
".",
"startTask",
"(",
"id",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// StartTask provided a task id a task is started
|
[
"StartTask",
"provided",
"a",
"task",
"id",
"a",
"task",
"is",
"started"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L509-L511
|
15,437 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
StopTask
|
func (s *scheduler) StopTask(id string) []serror.SnapError {
return s.stopTask(id, "user")
}
|
go
|
func (s *scheduler) StopTask(id string) []serror.SnapError {
return s.stopTask(id, "user")
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"StopTask",
"(",
"id",
"string",
")",
"[",
"]",
"serror",
".",
"SnapError",
"{",
"return",
"s",
".",
"stopTask",
"(",
"id",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// StopTask provided a task id a task is stopped
|
[
"StopTask",
"provided",
"a",
"task",
"id",
"a",
"task",
"is",
"stopped"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L583-L585
|
15,438 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
EnableTask
|
func (s *scheduler) EnableTask(id string) (core.Task, error) {
t, e := s.getTask(id)
if e != nil {
schedulerLogger.WithFields(log.Fields{
"_block": "enable-task",
"_error": ErrTaskNotFound,
"task-id": id,
}).Error("error enabling task")
return nil, e
}
err := t.Enable()
if err != nil {
schedulerLogger.WithFields(log.Fields{
"_block": "enable-task",
"_error": err.Error(),
"task-id": id,
}).Error("error enabling task")
return nil, err
}
schedulerLogger.WithFields(log.Fields{
"_block": "enable-task",
"task-id": t.ID(),
"task-state": t.State(),
}).Info("task enabled")
return t, nil
}
|
go
|
func (s *scheduler) EnableTask(id string) (core.Task, error) {
t, e := s.getTask(id)
if e != nil {
schedulerLogger.WithFields(log.Fields{
"_block": "enable-task",
"_error": ErrTaskNotFound,
"task-id": id,
}).Error("error enabling task")
return nil, e
}
err := t.Enable()
if err != nil {
schedulerLogger.WithFields(log.Fields{
"_block": "enable-task",
"_error": err.Error(),
"task-id": id,
}).Error("error enabling task")
return nil, err
}
schedulerLogger.WithFields(log.Fields{
"_block": "enable-task",
"task-id": t.ID(),
"task-state": t.State(),
}).Info("task enabled")
return t, nil
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"EnableTask",
"(",
"id",
"string",
")",
"(",
"core",
".",
"Task",
",",
"error",
")",
"{",
"t",
",",
"e",
":=",
"s",
".",
"getTask",
"(",
"id",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"schedulerLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"ErrTaskNotFound",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"e",
"\n",
"}",
"\n\n",
"err",
":=",
"t",
".",
"Enable",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"schedulerLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"schedulerLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"t",
".",
"ID",
"(",
")",
",",
"\"",
"\"",
":",
"t",
".",
"State",
"(",
")",
",",
"}",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] |
//EnableTask changes state from disabled to stopped
|
[
"EnableTask",
"changes",
"state",
"from",
"disabled",
"to",
"stopped"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L644-L670
|
15,439 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
SetMetricManager
|
func (s *scheduler) SetMetricManager(mm managesMetrics) {
s.metricManager = mm
schedulerLogger.WithFields(log.Fields{
"_block": "set-metric-manager",
}).Debug("metric manager linked")
}
|
go
|
func (s *scheduler) SetMetricManager(mm managesMetrics) {
s.metricManager = mm
schedulerLogger.WithFields(log.Fields{
"_block": "set-metric-manager",
}).Debug("metric manager linked")
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"SetMetricManager",
"(",
"mm",
"managesMetrics",
")",
"{",
"s",
".",
"metricManager",
"=",
"mm",
"\n",
"schedulerLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// Set metricManager for scheduler
|
[
"Set",
"metricManager",
"for",
"scheduler"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L750-L755
|
15,440 |
intelsdi-x/snap
|
scheduler/scheduler.go
|
HandleGomitEvent
|
func (s *scheduler) HandleGomitEvent(e gomit.Event) {
switch v := e.Body.(type) {
case *scheduler_event.MetricCollectedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
"metric-count": len(v.Metrics),
}).Debug("event received")
s.taskWatcherColl.handleMetricCollected(v.TaskID, v.Metrics)
case *scheduler_event.MetricCollectionFailedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
"errors-count": v.Errors,
}).Debug("event received")
case *scheduler_event.TaskStartedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
s.taskWatcherColl.handleTaskStarted(v.TaskID)
case *scheduler_event.TaskStoppedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
// We need to unsubscribe from deps when a task has stopped
task, _ := s.getTask(v.TaskID)
task.UnsubscribePlugins()
s.taskWatcherColl.handleTaskStopped(v.TaskID)
case *scheduler_event.TaskEndedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
// We need to unsubscribe from deps when a task has ended
task, _ := s.getTask(v.TaskID)
task.UnsubscribePlugins()
s.taskWatcherColl.handleTaskEnded(v.TaskID)
case *scheduler_event.TaskDisabledEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
"disabled-reason": v.Why,
}).Debug("event received")
// We need to unsubscribe from deps when a task goes disabled
task, _ := s.getTask(v.TaskID)
task.UnsubscribePlugins()
s.taskWatcherColl.handleTaskDisabled(v.TaskID, v.Why)
case *scheduler_event.PluginsUnsubscribedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
default:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
}).Debug("event received")
}
}
|
go
|
func (s *scheduler) HandleGomitEvent(e gomit.Event) {
switch v := e.Body.(type) {
case *scheduler_event.MetricCollectedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
"metric-count": len(v.Metrics),
}).Debug("event received")
s.taskWatcherColl.handleMetricCollected(v.TaskID, v.Metrics)
case *scheduler_event.MetricCollectionFailedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
"errors-count": v.Errors,
}).Debug("event received")
case *scheduler_event.TaskStartedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
s.taskWatcherColl.handleTaskStarted(v.TaskID)
case *scheduler_event.TaskStoppedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
// We need to unsubscribe from deps when a task has stopped
task, _ := s.getTask(v.TaskID)
task.UnsubscribePlugins()
s.taskWatcherColl.handleTaskStopped(v.TaskID)
case *scheduler_event.TaskEndedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
// We need to unsubscribe from deps when a task has ended
task, _ := s.getTask(v.TaskID)
task.UnsubscribePlugins()
s.taskWatcherColl.handleTaskEnded(v.TaskID)
case *scheduler_event.TaskDisabledEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
"disabled-reason": v.Why,
}).Debug("event received")
// We need to unsubscribe from deps when a task goes disabled
task, _ := s.getTask(v.TaskID)
task.UnsubscribePlugins()
s.taskWatcherColl.handleTaskDisabled(v.TaskID, v.Why)
case *scheduler_event.PluginsUnsubscribedEvent:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
"task-id": v.TaskID,
}).Debug("event received")
default:
log.WithFields(log.Fields{
"_module": "scheduler-events",
"_block": "handle-events",
"event-namespace": e.Namespace(),
}).Debug("event received")
}
}
|
[
"func",
"(",
"s",
"*",
"scheduler",
")",
"HandleGomitEvent",
"(",
"e",
"gomit",
".",
"Event",
")",
"{",
"switch",
"v",
":=",
"e",
".",
"Body",
".",
"(",
"type",
")",
"{",
"case",
"*",
"scheduler_event",
".",
"MetricCollectedEvent",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"TaskID",
",",
"\"",
"\"",
":",
"len",
"(",
"v",
".",
"Metrics",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"s",
".",
"taskWatcherColl",
".",
"handleMetricCollected",
"(",
"v",
".",
"TaskID",
",",
"v",
".",
"Metrics",
")",
"\n",
"case",
"*",
"scheduler_event",
".",
"MetricCollectionFailedEvent",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"TaskID",
",",
"\"",
"\"",
":",
"v",
".",
"Errors",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"case",
"*",
"scheduler_event",
".",
"TaskStartedEvent",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"TaskID",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"s",
".",
"taskWatcherColl",
".",
"handleTaskStarted",
"(",
"v",
".",
"TaskID",
")",
"\n",
"case",
"*",
"scheduler_event",
".",
"TaskStoppedEvent",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"TaskID",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// We need to unsubscribe from deps when a task has stopped",
"task",
",",
"_",
":=",
"s",
".",
"getTask",
"(",
"v",
".",
"TaskID",
")",
"\n",
"task",
".",
"UnsubscribePlugins",
"(",
")",
"\n",
"s",
".",
"taskWatcherColl",
".",
"handleTaskStopped",
"(",
"v",
".",
"TaskID",
")",
"\n",
"case",
"*",
"scheduler_event",
".",
"TaskEndedEvent",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"TaskID",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// We need to unsubscribe from deps when a task has ended",
"task",
",",
"_",
":=",
"s",
".",
"getTask",
"(",
"v",
".",
"TaskID",
")",
"\n",
"task",
".",
"UnsubscribePlugins",
"(",
")",
"\n",
"s",
".",
"taskWatcherColl",
".",
"handleTaskEnded",
"(",
"v",
".",
"TaskID",
")",
"\n",
"case",
"*",
"scheduler_event",
".",
"TaskDisabledEvent",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"TaskID",
",",
"\"",
"\"",
":",
"v",
".",
"Why",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// We need to unsubscribe from deps when a task goes disabled",
"task",
",",
"_",
":=",
"s",
".",
"getTask",
"(",
"v",
".",
"TaskID",
")",
"\n",
"task",
".",
"UnsubscribePlugins",
"(",
")",
"\n",
"s",
".",
"taskWatcherColl",
".",
"handleTaskDisabled",
"(",
"v",
".",
"TaskID",
",",
"v",
".",
"Why",
")",
"\n",
"case",
"*",
"scheduler_event",
".",
"PluginsUnsubscribedEvent",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"TaskID",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Namespace",
"(",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] |
// Central handling for all async events in scheduler
|
[
"Central",
"handling",
"for",
"all",
"async",
"events",
"in",
"scheduler"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/scheduler.go#L772-L848
|
15,441 |
intelsdi-x/snap
|
mgmt/rest/v1/task.go
|
enableTask
|
func (s *apiV1) enableTask(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
id := p.ByName("id")
tsk, err := s.taskManager.EnableTask(id)
if err != nil {
if strings.Contains(err.Error(), ErrTaskNotFound.Error()) {
rbody.Write(404, rbody.FromError(err), w)
return
}
rbody.Write(500, rbody.FromError(err), w)
return
}
task := &rbody.ScheduledTaskEnabled{}
task.AddScheduledTask = *rbody.AddSchedulerTaskFromTask(tsk)
rbody.Write(200, task, w)
}
|
go
|
func (s *apiV1) enableTask(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
id := p.ByName("id")
tsk, err := s.taskManager.EnableTask(id)
if err != nil {
if strings.Contains(err.Error(), ErrTaskNotFound.Error()) {
rbody.Write(404, rbody.FromError(err), w)
return
}
rbody.Write(500, rbody.FromError(err), w)
return
}
task := &rbody.ScheduledTaskEnabled{}
task.AddScheduledTask = *rbody.AddSchedulerTaskFromTask(tsk)
rbody.Write(200, task, w)
}
|
[
"func",
"(",
"s",
"*",
"apiV1",
")",
"enableTask",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"p",
"httprouter",
".",
"Params",
")",
"{",
"id",
":=",
"p",
".",
"ByName",
"(",
"\"",
"\"",
")",
"\n",
"tsk",
",",
"err",
":=",
"s",
".",
"taskManager",
".",
"EnableTask",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"ErrTaskNotFound",
".",
"Error",
"(",
")",
")",
"{",
"rbody",
".",
"Write",
"(",
"404",
",",
"rbody",
".",
"FromError",
"(",
"err",
")",
",",
"w",
")",
"\n",
"return",
"\n",
"}",
"\n",
"rbody",
".",
"Write",
"(",
"500",
",",
"rbody",
".",
"FromError",
"(",
"err",
")",
",",
"w",
")",
"\n",
"return",
"\n",
"}",
"\n",
"task",
":=",
"&",
"rbody",
".",
"ScheduledTaskEnabled",
"{",
"}",
"\n",
"task",
".",
"AddScheduledTask",
"=",
"*",
"rbody",
".",
"AddSchedulerTaskFromTask",
"(",
"tsk",
")",
"\n",
"rbody",
".",
"Write",
"(",
"200",
",",
"task",
",",
"w",
")",
"\n",
"}"
] |
//enableTask changes the task state from Disabled to Stopped
|
[
"enableTask",
"changes",
"the",
"task",
"state",
"from",
"Disabled",
"to",
"Stopped"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/v1/task.go#L241-L255
|
15,442 |
intelsdi-x/snap
|
pkg/aci/aci.go
|
Manifest
|
func Manifest(f io.ReadSeeker) (*schema.ImageManifest, error) {
m, err := specaci.ManifestFromImage(f)
if err != nil {
return nil, err
}
return m, nil
}
|
go
|
func Manifest(f io.ReadSeeker) (*schema.ImageManifest, error) {
m, err := specaci.ManifestFromImage(f)
if err != nil {
return nil, err
}
return m, nil
}
|
[
"func",
"Manifest",
"(",
"f",
"io",
".",
"ReadSeeker",
")",
"(",
"*",
"schema",
".",
"ImageManifest",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"specaci",
".",
"ManifestFromImage",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// Manifest returns the ImageManifest inside the ACI file
|
[
"Manifest",
"returns",
"the",
"ImageManifest",
"inside",
"the",
"ACI",
"file"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/aci/aci.go#L56-L62
|
15,443 |
intelsdi-x/snap
|
pkg/aci/aci.go
|
Extract
|
func Extract(f io.ReadSeeker) (string, error) {
fileMode := os.FileMode(0755)
tr, err := specaci.NewCompressedTarReader(f)
if err != nil {
return "", err
}
defer tr.Close()
// Extract archive to temporary directory
dir, err := ioutil.TempDir("", "")
if err != nil {
return "", err
}
aciLogger.WithField("directory", dir).Debugf(
"Extracting archive to temporary directory")
for {
hdr, err := tr.Reader.Next()
if err == io.EOF {
break
}
if err != nil {
return "", fmt.Errorf("%v\n%v", ErrNext, err)
}
file := filepath.Join(dir, hdr.Name)
switch hdr.Typeflag {
case tar.TypeReg:
w, err := os.Create(file)
if err != nil {
return "", fmt.Errorf("%v: %v\n%v", ErrCreatingFile, file, err)
}
_, err = io.Copy(w, tr)
if err != nil {
w.Close()
return "", fmt.Errorf("%v: %v\n%v", ErrCopyingFile, file, err)
}
w.Close()
err = os.Chmod(file, fileMode)
if err != nil {
return "", fmt.Errorf("%v: %v\n%v", ErrChmod, file, err)
}
case tar.TypeDir:
err = os.MkdirAll(file, fileMode)
if err != nil {
return "", fmt.Errorf("%v: %v\n%v", ErrMkdirAll, file, err)
}
case tar.TypeSymlink:
err := os.Symlink(
filepath.Join(dir, filepath.Dir(hdr.Name), hdr.Linkname),
filepath.Join(dir, hdr.Name))
if err != nil {
return "", fmt.Errorf("%v: name: %v Linkname: %v \n%v",
ErrCreatingSymLink, hdr.Name, hdr.Linkname, err)
}
default:
return "", fmt.Errorf("%v (type: %d): %v", ErrUntar, hdr.Typeflag, hdr.Name)
}
}
return dir, nil
}
|
go
|
func Extract(f io.ReadSeeker) (string, error) {
fileMode := os.FileMode(0755)
tr, err := specaci.NewCompressedTarReader(f)
if err != nil {
return "", err
}
defer tr.Close()
// Extract archive to temporary directory
dir, err := ioutil.TempDir("", "")
if err != nil {
return "", err
}
aciLogger.WithField("directory", dir).Debugf(
"Extracting archive to temporary directory")
for {
hdr, err := tr.Reader.Next()
if err == io.EOF {
break
}
if err != nil {
return "", fmt.Errorf("%v\n%v", ErrNext, err)
}
file := filepath.Join(dir, hdr.Name)
switch hdr.Typeflag {
case tar.TypeReg:
w, err := os.Create(file)
if err != nil {
return "", fmt.Errorf("%v: %v\n%v", ErrCreatingFile, file, err)
}
_, err = io.Copy(w, tr)
if err != nil {
w.Close()
return "", fmt.Errorf("%v: %v\n%v", ErrCopyingFile, file, err)
}
w.Close()
err = os.Chmod(file, fileMode)
if err != nil {
return "", fmt.Errorf("%v: %v\n%v", ErrChmod, file, err)
}
case tar.TypeDir:
err = os.MkdirAll(file, fileMode)
if err != nil {
return "", fmt.Errorf("%v: %v\n%v", ErrMkdirAll, file, err)
}
case tar.TypeSymlink:
err := os.Symlink(
filepath.Join(dir, filepath.Dir(hdr.Name), hdr.Linkname),
filepath.Join(dir, hdr.Name))
if err != nil {
return "", fmt.Errorf("%v: name: %v Linkname: %v \n%v",
ErrCreatingSymLink, hdr.Name, hdr.Linkname, err)
}
default:
return "", fmt.Errorf("%v (type: %d): %v", ErrUntar, hdr.Typeflag, hdr.Name)
}
}
return dir, nil
}
|
[
"func",
"Extract",
"(",
"f",
"io",
".",
"ReadSeeker",
")",
"(",
"string",
",",
"error",
")",
"{",
"fileMode",
":=",
"os",
".",
"FileMode",
"(",
"0755",
")",
"\n\n",
"tr",
",",
"err",
":=",
"specaci",
".",
"NewCompressedTarReader",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"tr",
".",
"Close",
"(",
")",
"\n\n",
"// Extract archive to temporary directory",
"dir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"aciLogger",
".",
"WithField",
"(",
"\"",
"\"",
",",
"dir",
")",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"for",
"{",
"hdr",
",",
"err",
":=",
"tr",
".",
"Reader",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrNext",
",",
"err",
")",
"\n",
"}",
"\n",
"file",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"hdr",
".",
"Name",
")",
"\n\n",
"switch",
"hdr",
".",
"Typeflag",
"{",
"case",
"tar",
".",
"TypeReg",
":",
"w",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrCreatingFile",
",",
"file",
",",
"err",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"w",
",",
"tr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"Close",
"(",
")",
"\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrCopyingFile",
",",
"file",
",",
"err",
")",
"\n",
"}",
"\n",
"w",
".",
"Close",
"(",
")",
"\n",
"err",
"=",
"os",
".",
"Chmod",
"(",
"file",
",",
"fileMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrChmod",
",",
"file",
",",
"err",
")",
"\n",
"}",
"\n",
"case",
"tar",
".",
"TypeDir",
":",
"err",
"=",
"os",
".",
"MkdirAll",
"(",
"file",
",",
"fileMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrMkdirAll",
",",
"file",
",",
"err",
")",
"\n",
"}",
"\n",
"case",
"tar",
".",
"TypeSymlink",
":",
"err",
":=",
"os",
".",
"Symlink",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"filepath",
".",
"Dir",
"(",
"hdr",
".",
"Name",
")",
",",
"hdr",
".",
"Linkname",
")",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"hdr",
".",
"Name",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrCreatingSymLink",
",",
"hdr",
".",
"Name",
",",
"hdr",
".",
"Linkname",
",",
"err",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ErrUntar",
",",
"hdr",
".",
"Typeflag",
",",
"hdr",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"dir",
",",
"nil",
"\n",
"}"
] |
// Extract expands the ACI file to a temporary directory, returning
// the directory path where the ACI was expanded or an error
|
[
"Extract",
"expands",
"the",
"ACI",
"file",
"to",
"a",
"temporary",
"directory",
"returning",
"the",
"directory",
"path",
"where",
"the",
"ACI",
"was",
"expanded",
"or",
"an",
"error"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/aci/aci.go#L66-L126
|
15,444 |
intelsdi-x/snap
|
pkg/aci/aci.go
|
Validate
|
func Validate(f io.ReadSeeker) error {
tr, err := specaci.NewCompressedTarReader(f)
defer tr.Close()
if err != nil {
return err
}
if err := specaci.ValidateArchive(tr.Reader); err != nil {
return err
}
return nil
}
|
go
|
func Validate(f io.ReadSeeker) error {
tr, err := specaci.NewCompressedTarReader(f)
defer tr.Close()
if err != nil {
return err
}
if err := specaci.ValidateArchive(tr.Reader); err != nil {
return err
}
return nil
}
|
[
"func",
"Validate",
"(",
"f",
"io",
".",
"ReadSeeker",
")",
"error",
"{",
"tr",
",",
"err",
":=",
"specaci",
".",
"NewCompressedTarReader",
"(",
"f",
")",
"\n",
"defer",
"tr",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"specaci",
".",
"ValidateArchive",
"(",
"tr",
".",
"Reader",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate makes sure the archive is valid. Otherwise,
// an error is returned
|
[
"Validate",
"makes",
"sure",
"the",
"archive",
"is",
"valid",
".",
"Otherwise",
"an",
"error",
"is",
"returned"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/aci/aci.go#L130-L141
|
15,445 |
intelsdi-x/snap
|
control/subscription_group.go
|
Remove
|
func (s subscriptionGroups) Remove(id string) []serror.SnapError {
s.Lock()
defer s.Unlock()
return s.remove(id)
}
|
go
|
func (s subscriptionGroups) Remove(id string) []serror.SnapError {
s.Lock()
defer s.Unlock()
return s.remove(id)
}
|
[
"func",
"(",
"s",
"subscriptionGroups",
")",
"Remove",
"(",
"id",
"string",
")",
"[",
"]",
"serror",
".",
"SnapError",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
".",
"remove",
"(",
"id",
")",
"\n",
"}"
] |
// Remove removes a subscription group given a subscription group ID.
|
[
"Remove",
"removes",
"a",
"subscription",
"group",
"given",
"a",
"subscription",
"group",
"ID",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/subscription_group.go#L144-L148
|
15,446 |
intelsdi-x/snap
|
control/subscription_group.go
|
validatePluginUnloading
|
func (s *subscriptionGroups) validatePluginUnloading(pluginToUnload *loadedPlugin) (errs []serror.SnapError) {
s.Lock()
defer s.Unlock()
for id, group := range s.subscriptionMap {
if err := group.validatePluginUnloading(id, pluginToUnload); err != nil {
errs = append(errs, err)
}
}
return errs
}
|
go
|
func (s *subscriptionGroups) validatePluginUnloading(pluginToUnload *loadedPlugin) (errs []serror.SnapError) {
s.Lock()
defer s.Unlock()
for id, group := range s.subscriptionMap {
if err := group.validatePluginUnloading(id, pluginToUnload); err != nil {
errs = append(errs, err)
}
}
return errs
}
|
[
"func",
"(",
"s",
"*",
"subscriptionGroups",
")",
"validatePluginUnloading",
"(",
"pluginToUnload",
"*",
"loadedPlugin",
")",
"(",
"errs",
"[",
"]",
"serror",
".",
"SnapError",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"for",
"id",
",",
"group",
":=",
"range",
"s",
".",
"subscriptionMap",
"{",
"if",
"err",
":=",
"group",
".",
"validatePluginUnloading",
"(",
"id",
",",
"pluginToUnload",
")",
";",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"errs",
"\n",
"}"
] |
// validatePluginUnloading checks if process of unloading the plugin is safe for existing running tasks.
// If the plugin is used by running task and there is no replacements, return an error with appropriate message
// containing ids of tasks which use the plugin, what blocks unloading process until they are stopped
|
[
"validatePluginUnloading",
"checks",
"if",
"process",
"of",
"unloading",
"the",
"plugin",
"is",
"safe",
"for",
"existing",
"running",
"tasks",
".",
"If",
"the",
"plugin",
"is",
"used",
"by",
"running",
"task",
"and",
"there",
"is",
"no",
"replacements",
"return",
"an",
"error",
"with",
"appropriate",
"message",
"containing",
"ids",
"of",
"tasks",
"which",
"use",
"the",
"plugin",
"what",
"blocks",
"unloading",
"process",
"until",
"they",
"are",
"stopped"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/subscription_group.go#L260-L269
|
15,447 |
intelsdi-x/snap
|
control/subscription_group.go
|
pluginIsSubscribed
|
func (s *subscriptionGroup) pluginIsSubscribed(plugin *loadedPlugin) bool {
// range over subscribed plugins to find if the plugin is there
for _, sp := range s.plugins {
if sp.TypeName() == plugin.TypeName() && sp.Name() == plugin.Name() && sp.Version() == plugin.Version() {
return true
}
}
return false
}
|
go
|
func (s *subscriptionGroup) pluginIsSubscribed(plugin *loadedPlugin) bool {
// range over subscribed plugins to find if the plugin is there
for _, sp := range s.plugins {
if sp.TypeName() == plugin.TypeName() && sp.Name() == plugin.Name() && sp.Version() == plugin.Version() {
return true
}
}
return false
}
|
[
"func",
"(",
"s",
"*",
"subscriptionGroup",
")",
"pluginIsSubscribed",
"(",
"plugin",
"*",
"loadedPlugin",
")",
"bool",
"{",
"// range over subscribed plugins to find if the plugin is there",
"for",
"_",
",",
"sp",
":=",
"range",
"s",
".",
"plugins",
"{",
"if",
"sp",
".",
"TypeName",
"(",
")",
"==",
"plugin",
".",
"TypeName",
"(",
")",
"&&",
"sp",
".",
"Name",
"(",
")",
"==",
"plugin",
".",
"Name",
"(",
")",
"&&",
"sp",
".",
"Version",
"(",
")",
"==",
"plugin",
".",
"Version",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// pluginIsSubscribed returns true if a provided plugin has been found among subscribed plugins
// in the following subscription group
|
[
"pluginIsSubscribed",
"returns",
"true",
"if",
"a",
"provided",
"plugin",
"has",
"been",
"found",
"among",
"subscribed",
"plugins",
"in",
"the",
"following",
"subscription",
"group"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/subscription_group.go#L365-L373
|
15,448 |
intelsdi-x/snap
|
control/subscription_group.go
|
validatePluginUnloading
|
func (s *subscriptionGroup) validatePluginUnloading(id string, plgToUnload *loadedPlugin) (serr serror.SnapError) {
impacted := false
if !s.pluginIsSubscribed(plgToUnload) {
// the plugin is not subscribed, so the task is not impacted by its unloading
return nil
}
controlLogger.WithFields(log.Fields{
"_block": "subscriptionGroup.validatePluginUnloading",
"task-id": id,
"plugin-to-unload": plgToUnload.Key(),
}).Debug("validating impact of unloading the plugin")
for _, requestedMetric := range s.requestedMetrics {
// get all plugins exposing the requested metric
plgs, _ := s.GetPlugins(requestedMetric.Namespace())
// when requested version is fixed (greater than 0), take into account only plugins in the requested version
if requestedMetric.Version() > 0 {
// skip those which are not impacted by unloading (version different than plgToUnload.Version())
if requestedMetric.Version() == plgToUnload.Version() {
plgsInVer := []core.CatalogedPlugin{}
for _, plg := range plgs {
if plg.Version() == requestedMetric.Version() {
plgsInVer = append(plgsInVer, plg)
}
}
// set plugins only in the requested version
plgs = plgsInVer
}
}
if len(plgs) == 1 && plgs[0].Key() == plgToUnload.Key() {
// the requested metric is exposed only by the single plugin and there is no replacement
impacted = true
controlLogger.WithFields(log.Fields{
"_block": "subscriptionGroup.validatePluginUnloading",
"task-id": id,
"plugin-to-unload": plgToUnload.Key(),
"requested-metric": fmt.Sprintf("%s:%d", requestedMetric.Namespace(), requestedMetric.Version()),
}).Errorf("unloading the plugin would cause missing in collection the requested metric")
}
}
if impacted {
serr = serror.New(ErrPluginCannotBeUnloaded, map[string]interface{}{
"task-id": id,
"plugin-to-unload": plgToUnload.Key(),
})
}
return serr
}
|
go
|
func (s *subscriptionGroup) validatePluginUnloading(id string, plgToUnload *loadedPlugin) (serr serror.SnapError) {
impacted := false
if !s.pluginIsSubscribed(plgToUnload) {
// the plugin is not subscribed, so the task is not impacted by its unloading
return nil
}
controlLogger.WithFields(log.Fields{
"_block": "subscriptionGroup.validatePluginUnloading",
"task-id": id,
"plugin-to-unload": plgToUnload.Key(),
}).Debug("validating impact of unloading the plugin")
for _, requestedMetric := range s.requestedMetrics {
// get all plugins exposing the requested metric
plgs, _ := s.GetPlugins(requestedMetric.Namespace())
// when requested version is fixed (greater than 0), take into account only plugins in the requested version
if requestedMetric.Version() > 0 {
// skip those which are not impacted by unloading (version different than plgToUnload.Version())
if requestedMetric.Version() == plgToUnload.Version() {
plgsInVer := []core.CatalogedPlugin{}
for _, plg := range plgs {
if plg.Version() == requestedMetric.Version() {
plgsInVer = append(plgsInVer, plg)
}
}
// set plugins only in the requested version
plgs = plgsInVer
}
}
if len(plgs) == 1 && plgs[0].Key() == plgToUnload.Key() {
// the requested metric is exposed only by the single plugin and there is no replacement
impacted = true
controlLogger.WithFields(log.Fields{
"_block": "subscriptionGroup.validatePluginUnloading",
"task-id": id,
"plugin-to-unload": plgToUnload.Key(),
"requested-metric": fmt.Sprintf("%s:%d", requestedMetric.Namespace(), requestedMetric.Version()),
}).Errorf("unloading the plugin would cause missing in collection the requested metric")
}
}
if impacted {
serr = serror.New(ErrPluginCannotBeUnloaded, map[string]interface{}{
"task-id": id,
"plugin-to-unload": plgToUnload.Key(),
})
}
return serr
}
|
[
"func",
"(",
"s",
"*",
"subscriptionGroup",
")",
"validatePluginUnloading",
"(",
"id",
"string",
",",
"plgToUnload",
"*",
"loadedPlugin",
")",
"(",
"serr",
"serror",
".",
"SnapError",
")",
"{",
"impacted",
":=",
"false",
"\n",
"if",
"!",
"s",
".",
"pluginIsSubscribed",
"(",
"plgToUnload",
")",
"{",
"// the plugin is not subscribed, so the task is not impacted by its unloading",
"return",
"nil",
"\n",
"}",
"\n",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"id",
",",
"\"",
"\"",
":",
"plgToUnload",
".",
"Key",
"(",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"requestedMetric",
":=",
"range",
"s",
".",
"requestedMetrics",
"{",
"// get all plugins exposing the requested metric",
"plgs",
",",
"_",
":=",
"s",
".",
"GetPlugins",
"(",
"requestedMetric",
".",
"Namespace",
"(",
")",
")",
"\n",
"// when requested version is fixed (greater than 0), take into account only plugins in the requested version",
"if",
"requestedMetric",
".",
"Version",
"(",
")",
">",
"0",
"{",
"// skip those which are not impacted by unloading (version different than plgToUnload.Version())",
"if",
"requestedMetric",
".",
"Version",
"(",
")",
"==",
"plgToUnload",
".",
"Version",
"(",
")",
"{",
"plgsInVer",
":=",
"[",
"]",
"core",
".",
"CatalogedPlugin",
"{",
"}",
"\n\n",
"for",
"_",
",",
"plg",
":=",
"range",
"plgs",
"{",
"if",
"plg",
".",
"Version",
"(",
")",
"==",
"requestedMetric",
".",
"Version",
"(",
")",
"{",
"plgsInVer",
"=",
"append",
"(",
"plgsInVer",
",",
"plg",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// set plugins only in the requested version",
"plgs",
"=",
"plgsInVer",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"plgs",
")",
"==",
"1",
"&&",
"plgs",
"[",
"0",
"]",
".",
"Key",
"(",
")",
"==",
"plgToUnload",
".",
"Key",
"(",
")",
"{",
"// the requested metric is exposed only by the single plugin and there is no replacement",
"impacted",
"=",
"true",
"\n",
"controlLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"id",
",",
"\"",
"\"",
":",
"plgToUnload",
".",
"Key",
"(",
")",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"requestedMetric",
".",
"Namespace",
"(",
")",
",",
"requestedMetric",
".",
"Version",
"(",
")",
")",
",",
"}",
")",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"impacted",
"{",
"serr",
"=",
"serror",
".",
"New",
"(",
"ErrPluginCannotBeUnloaded",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"id",
",",
"\"",
"\"",
":",
"plgToUnload",
".",
"Key",
"(",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"serr",
"\n",
"}"
] |
// validatePluginUnloading verifies if a given plugin might be unloaded without causing running task failures
|
[
"validatePluginUnloading",
"verifies",
"if",
"a",
"given",
"plugin",
"might",
"be",
"unloaded",
"without",
"causing",
"running",
"task",
"failures"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/subscription_group.go#L376-L424
|
15,449 |
intelsdi-x/snap
|
control/subscription_group.go
|
comparePlugins
|
func comparePlugins(newPlugins,
oldPlugins []core.SubscribedPlugin) (adds,
removes []core.SubscribedPlugin) {
newMap := make(map[string]int)
oldMap := make(map[string]int)
for _, n := range newPlugins {
newMap[key(n)]++
}
for _, o := range oldPlugins {
oldMap[key(o)]++
}
for _, n := range newPlugins {
if oldMap[key(n)] > 0 {
oldMap[key(n)]--
continue
}
adds = append(adds, n)
}
for _, o := range oldPlugins {
if newMap[key(o)] > 0 {
newMap[key(o)]--
continue
}
removes = append(removes, o)
}
return
}
|
go
|
func comparePlugins(newPlugins,
oldPlugins []core.SubscribedPlugin) (adds,
removes []core.SubscribedPlugin) {
newMap := make(map[string]int)
oldMap := make(map[string]int)
for _, n := range newPlugins {
newMap[key(n)]++
}
for _, o := range oldPlugins {
oldMap[key(o)]++
}
for _, n := range newPlugins {
if oldMap[key(n)] > 0 {
oldMap[key(n)]--
continue
}
adds = append(adds, n)
}
for _, o := range oldPlugins {
if newMap[key(o)] > 0 {
newMap[key(o)]--
continue
}
removes = append(removes, o)
}
return
}
|
[
"func",
"comparePlugins",
"(",
"newPlugins",
",",
"oldPlugins",
"[",
"]",
"core",
".",
"SubscribedPlugin",
")",
"(",
"adds",
",",
"removes",
"[",
"]",
"core",
".",
"SubscribedPlugin",
")",
"{",
"newMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"oldMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n\n",
"for",
"_",
",",
"n",
":=",
"range",
"newPlugins",
"{",
"newMap",
"[",
"key",
"(",
"n",
")",
"]",
"++",
"\n",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"oldPlugins",
"{",
"oldMap",
"[",
"key",
"(",
"o",
")",
"]",
"++",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"n",
":=",
"range",
"newPlugins",
"{",
"if",
"oldMap",
"[",
"key",
"(",
"n",
")",
"]",
">",
"0",
"{",
"oldMap",
"[",
"key",
"(",
"n",
")",
"]",
"--",
"\n",
"continue",
"\n",
"}",
"\n",
"adds",
"=",
"append",
"(",
"adds",
",",
"n",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"o",
":=",
"range",
"oldPlugins",
"{",
"if",
"newMap",
"[",
"key",
"(",
"o",
")",
"]",
">",
"0",
"{",
"newMap",
"[",
"key",
"(",
"o",
")",
"]",
"--",
"\n",
"continue",
"\n",
"}",
"\n",
"removes",
"=",
"append",
"(",
"removes",
",",
"o",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// comparePlugins compares the new state of plugins with the previous state.
// It returns an array of plugins that need to be subscribed and an array of
// plugins that need to be unsubscribed.
|
[
"comparePlugins",
"compares",
"the",
"new",
"state",
"of",
"plugins",
"with",
"the",
"previous",
"state",
".",
"It",
"returns",
"an",
"array",
"of",
"plugins",
"that",
"need",
"to",
"be",
"subscribed",
"and",
"an",
"array",
"of",
"plugins",
"that",
"need",
"to",
"be",
"unsubscribed",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/subscription_group.go#L643-L673
|
15,450 |
intelsdi-x/snap
|
mgmt/rest/client/plugin.go
|
LoadPlugin
|
func (c *Client) LoadPlugin(p []string) *LoadPluginResult {
r := new(LoadPluginResult)
resp, err := c.pluginUploadRequest(p)
if err != nil {
r.Err = serror.New(err)
return r
}
switch resp.Meta.Type {
case rbody.PluginsLoadedType:
pl := resp.Body.(*rbody.PluginsLoaded)
r.LoadedPlugins = convertLoadedPlugins(pl.LoadedPlugins)
case rbody.ErrorType:
f := resp.Body.(*rbody.Error).Fields
fields := make(map[string]interface{})
for k, v := range f {
fields[k] = v
}
r.Err = serror.New(resp.Body.(*rbody.Error), fields)
default:
r.Err = serror.New(ErrAPIResponseMetaType)
}
return r
}
|
go
|
func (c *Client) LoadPlugin(p []string) *LoadPluginResult {
r := new(LoadPluginResult)
resp, err := c.pluginUploadRequest(p)
if err != nil {
r.Err = serror.New(err)
return r
}
switch resp.Meta.Type {
case rbody.PluginsLoadedType:
pl := resp.Body.(*rbody.PluginsLoaded)
r.LoadedPlugins = convertLoadedPlugins(pl.LoadedPlugins)
case rbody.ErrorType:
f := resp.Body.(*rbody.Error).Fields
fields := make(map[string]interface{})
for k, v := range f {
fields[k] = v
}
r.Err = serror.New(resp.Body.(*rbody.Error), fields)
default:
r.Err = serror.New(ErrAPIResponseMetaType)
}
return r
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"LoadPlugin",
"(",
"p",
"[",
"]",
"string",
")",
"*",
"LoadPluginResult",
"{",
"r",
":=",
"new",
"(",
"LoadPluginResult",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"pluginUploadRequest",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"Err",
"=",
"serror",
".",
"New",
"(",
"err",
")",
"\n",
"return",
"r",
"\n",
"}",
"\n\n",
"switch",
"resp",
".",
"Meta",
".",
"Type",
"{",
"case",
"rbody",
".",
"PluginsLoadedType",
":",
"pl",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"PluginsLoaded",
")",
"\n",
"r",
".",
"LoadedPlugins",
"=",
"convertLoadedPlugins",
"(",
"pl",
".",
"LoadedPlugins",
")",
"\n",
"case",
"rbody",
".",
"ErrorType",
":",
"f",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"Error",
")",
".",
"Fields",
"\n",
"fields",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"f",
"{",
"fields",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"r",
".",
"Err",
"=",
"serror",
".",
"New",
"(",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"Error",
")",
",",
"fields",
")",
"\n",
"default",
":",
"r",
".",
"Err",
"=",
"serror",
".",
"New",
"(",
"ErrAPIResponseMetaType",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// LoadPlugin loads plugins for the given plugin names.
// A slide of loaded plugins returns if succeeded. Otherwise, an error is returned.
|
[
"LoadPlugin",
"loads",
"plugins",
"for",
"the",
"given",
"plugin",
"names",
".",
"A",
"slide",
"of",
"loaded",
"plugins",
"returns",
"if",
"succeeded",
".",
"Otherwise",
"an",
"error",
"is",
"returned",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/plugin.go#L35-L58
|
15,451 |
intelsdi-x/snap
|
mgmt/rest/client/plugin.go
|
UnloadPlugin
|
func (c *Client) UnloadPlugin(pluginType, name string, version int) *UnloadPluginResult {
r := &UnloadPluginResult{}
resp, err := c.do("DELETE", fmt.Sprintf("/plugins/%s/%s/%d", pluginType, url.QueryEscape(name), version), ContentTypeJSON)
if err != nil {
r.Err = err
return r
}
switch resp.Meta.Type {
case rbody.PluginUnloadedType:
// Success
up := resp.Body.(*rbody.PluginUnloaded)
r = &UnloadPluginResult{up, nil}
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
go
|
func (c *Client) UnloadPlugin(pluginType, name string, version int) *UnloadPluginResult {
r := &UnloadPluginResult{}
resp, err := c.do("DELETE", fmt.Sprintf("/plugins/%s/%s/%d", pluginType, url.QueryEscape(name), version), ContentTypeJSON)
if err != nil {
r.Err = err
return r
}
switch resp.Meta.Type {
case rbody.PluginUnloadedType:
// Success
up := resp.Body.(*rbody.PluginUnloaded)
r = &UnloadPluginResult{up, nil}
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"UnloadPlugin",
"(",
"pluginType",
",",
"name",
"string",
",",
"version",
"int",
")",
"*",
"UnloadPluginResult",
"{",
"r",
":=",
"&",
"UnloadPluginResult",
"{",
"}",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"do",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pluginType",
",",
"url",
".",
"QueryEscape",
"(",
"name",
")",
",",
"version",
")",
",",
"ContentTypeJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"Err",
"=",
"err",
"\n",
"return",
"r",
"\n",
"}",
"\n\n",
"switch",
"resp",
".",
"Meta",
".",
"Type",
"{",
"case",
"rbody",
".",
"PluginUnloadedType",
":",
"// Success",
"up",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"PluginUnloaded",
")",
"\n",
"r",
"=",
"&",
"UnloadPluginResult",
"{",
"up",
",",
"nil",
"}",
"\n",
"case",
"rbody",
".",
"ErrorType",
":",
"r",
".",
"Err",
"=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"Error",
")",
"\n",
"default",
":",
"r",
".",
"Err",
"=",
"ErrAPIResponseMetaType",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// UnloadPlugin unloads a plugin given plugin type, name, and version through an HTTP DELETE request.
// The unloaded plugin returns if succeeded. Otherwise, an error is returned.
|
[
"UnloadPlugin",
"unloads",
"a",
"plugin",
"given",
"plugin",
"type",
"name",
"and",
"version",
"through",
"an",
"HTTP",
"DELETE",
"request",
".",
"The",
"unloaded",
"plugin",
"returns",
"if",
"succeeded",
".",
"Otherwise",
"an",
"error",
"is",
"returned",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/plugin.go#L62-L81
|
15,452 |
intelsdi-x/snap
|
mgmt/rest/client/plugin.go
|
GetPlugins
|
func (c *Client) GetPlugins(details bool) *GetPluginsResult {
r := &GetPluginsResult{}
var path string
if details {
path = "/plugins?details"
} else {
path = "/plugins"
}
resp, err := c.do("GET", path, ContentTypeJSON)
if err != nil {
r.Err = err
return r
}
switch resp.Meta.Type {
// TODO change this to concrete const type when Joel adds it
case rbody.PluginListType:
// Success
b := resp.Body.(*rbody.PluginList)
r.LoadedPlugins = convertLoadedPlugins(b.LoadedPlugins)
r.AvailablePlugins = convertAvailablePlugins(b.AvailablePlugins)
return r
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
go
|
func (c *Client) GetPlugins(details bool) *GetPluginsResult {
r := &GetPluginsResult{}
var path string
if details {
path = "/plugins?details"
} else {
path = "/plugins"
}
resp, err := c.do("GET", path, ContentTypeJSON)
if err != nil {
r.Err = err
return r
}
switch resp.Meta.Type {
// TODO change this to concrete const type when Joel adds it
case rbody.PluginListType:
// Success
b := resp.Body.(*rbody.PluginList)
r.LoadedPlugins = convertLoadedPlugins(b.LoadedPlugins)
r.AvailablePlugins = convertAvailablePlugins(b.AvailablePlugins)
return r
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetPlugins",
"(",
"details",
"bool",
")",
"*",
"GetPluginsResult",
"{",
"r",
":=",
"&",
"GetPluginsResult",
"{",
"}",
"\n\n",
"var",
"path",
"string",
"\n",
"if",
"details",
"{",
"path",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"path",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"do",
"(",
"\"",
"\"",
",",
"path",
",",
"ContentTypeJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"Err",
"=",
"err",
"\n",
"return",
"r",
"\n",
"}",
"\n\n",
"switch",
"resp",
".",
"Meta",
".",
"Type",
"{",
"// TODO change this to concrete const type when Joel adds it",
"case",
"rbody",
".",
"PluginListType",
":",
"// Success",
"b",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"PluginList",
")",
"\n",
"r",
".",
"LoadedPlugins",
"=",
"convertLoadedPlugins",
"(",
"b",
".",
"LoadedPlugins",
")",
"\n",
"r",
".",
"AvailablePlugins",
"=",
"convertAvailablePlugins",
"(",
"b",
".",
"AvailablePlugins",
")",
"\n",
"return",
"r",
"\n",
"case",
"rbody",
".",
"ErrorType",
":",
"r",
".",
"Err",
"=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"Error",
")",
"\n",
"default",
":",
"r",
".",
"Err",
"=",
"ErrAPIResponseMetaType",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// GetPlugins returns the loaded and available plugins through an HTTP GET request.
// By specifying the details flag to tweak output info. An error returns if it failed.
|
[
"GetPlugins",
"returns",
"the",
"loaded",
"and",
"available",
"plugins",
"through",
"an",
"HTTP",
"GET",
"request",
".",
"By",
"specifying",
"the",
"details",
"flag",
"to",
"tweak",
"output",
"info",
".",
"An",
"error",
"returns",
"if",
"it",
"failed",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/plugin.go#L129-L159
|
15,453 |
intelsdi-x/snap
|
mgmt/rest/client/plugin.go
|
GetPlugin
|
func (c *Client) GetPlugin(typ, name string, ver int) *GetPluginResult {
r := &GetPluginResult{}
path := "/plugins/" + typ + "/" + name + "/" + strconv.Itoa(ver)
resp, err := c.do("GET", path, ContentTypeJSON)
if err != nil {
r.Err = err
return r
}
switch resp.Meta.Type {
// TODO change this to concrete const type when Joel adds it
case rbody.PluginReturnedType:
// Success
b := resp.Body.(*rbody.PluginReturned)
r.ReturnedPlugin = ReturnedPlugin{b}
return r
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
go
|
func (c *Client) GetPlugin(typ, name string, ver int) *GetPluginResult {
r := &GetPluginResult{}
path := "/plugins/" + typ + "/" + name + "/" + strconv.Itoa(ver)
resp, err := c.do("GET", path, ContentTypeJSON)
if err != nil {
r.Err = err
return r
}
switch resp.Meta.Type {
// TODO change this to concrete const type when Joel adds it
case rbody.PluginReturnedType:
// Success
b := resp.Body.(*rbody.PluginReturned)
r.ReturnedPlugin = ReturnedPlugin{b}
return r
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetPlugin",
"(",
"typ",
",",
"name",
"string",
",",
"ver",
"int",
")",
"*",
"GetPluginResult",
"{",
"r",
":=",
"&",
"GetPluginResult",
"{",
"}",
"\n\n",
"path",
":=",
"\"",
"\"",
"+",
"typ",
"+",
"\"",
"\"",
"+",
"name",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"ver",
")",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"do",
"(",
"\"",
"\"",
",",
"path",
",",
"ContentTypeJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"Err",
"=",
"err",
"\n",
"return",
"r",
"\n",
"}",
"\n\n",
"switch",
"resp",
".",
"Meta",
".",
"Type",
"{",
"// TODO change this to concrete const type when Joel adds it",
"case",
"rbody",
".",
"PluginReturnedType",
":",
"// Success",
"b",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"PluginReturned",
")",
"\n",
"r",
".",
"ReturnedPlugin",
"=",
"ReturnedPlugin",
"{",
"b",
"}",
"\n",
"return",
"r",
"\n",
"case",
"rbody",
".",
"ErrorType",
":",
"r",
".",
"Err",
"=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"Error",
")",
"\n",
"default",
":",
"r",
".",
"Err",
"=",
"ErrAPIResponseMetaType",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// GetPlugin returns the requested plugin through an HTTP GET request. An error returns if it failed.
|
[
"GetPlugin",
"returns",
"the",
"requested",
"plugin",
"through",
"an",
"HTTP",
"GET",
"request",
".",
"An",
"error",
"returns",
"if",
"it",
"failed",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/plugin.go#L162-L186
|
15,454 |
intelsdi-x/snap
|
scheduler/watcher.go
|
Close
|
func (t *TaskWatcher) Close() error {
for _, x := range t.taskIDs {
t.parent.rm(x, t)
}
return nil
}
|
go
|
func (t *TaskWatcher) Close() error {
for _, x := range t.taskIDs {
t.parent.rm(x, t)
}
return nil
}
|
[
"func",
"(",
"t",
"*",
"TaskWatcher",
")",
"Close",
"(",
")",
"error",
"{",
"for",
"_",
",",
"x",
":=",
"range",
"t",
".",
"taskIDs",
"{",
"t",
".",
"parent",
".",
"rm",
"(",
"x",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close stops watching a task. Cannot be restarted.
|
[
"Close",
"stops",
"watching",
"a",
"task",
".",
"Cannot",
"be",
"restarted",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/watcher.go#L44-L49
|
15,455 |
intelsdi-x/snap
|
control/strategy/pool.go
|
Insert
|
func (p *pool) Insert(a AvailablePlugin) error {
if a.Type() != plugin.CollectorPluginType && a.Type() != plugin.ProcessorPluginType && a.Type() != plugin.PublisherPluginType && a.Type() != plugin.StreamCollectorPluginType {
return ErrBadType
}
// If an empty pool is created, it does not have
// any available plugins from which to retrieve
// concurrency count or exclusivity. We ensure it
// is set correctly on an insert.
if len(p.plugins) == 0 {
if err := p.applyPluginMeta(a); err != nil {
return err
}
}
a.SetID(p.generatePID())
p.plugins[a.ID()] = a
return nil
}
|
go
|
func (p *pool) Insert(a AvailablePlugin) error {
if a.Type() != plugin.CollectorPluginType && a.Type() != plugin.ProcessorPluginType && a.Type() != plugin.PublisherPluginType && a.Type() != plugin.StreamCollectorPluginType {
return ErrBadType
}
// If an empty pool is created, it does not have
// any available plugins from which to retrieve
// concurrency count or exclusivity. We ensure it
// is set correctly on an insert.
if len(p.plugins) == 0 {
if err := p.applyPluginMeta(a); err != nil {
return err
}
}
a.SetID(p.generatePID())
p.plugins[a.ID()] = a
return nil
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"Insert",
"(",
"a",
"AvailablePlugin",
")",
"error",
"{",
"if",
"a",
".",
"Type",
"(",
")",
"!=",
"plugin",
".",
"CollectorPluginType",
"&&",
"a",
".",
"Type",
"(",
")",
"!=",
"plugin",
".",
"ProcessorPluginType",
"&&",
"a",
".",
"Type",
"(",
")",
"!=",
"plugin",
".",
"PublisherPluginType",
"&&",
"a",
".",
"Type",
"(",
")",
"!=",
"plugin",
".",
"StreamCollectorPluginType",
"{",
"return",
"ErrBadType",
"\n",
"}",
"\n",
"// If an empty pool is created, it does not have",
"// any available plugins from which to retrieve",
"// concurrency count or exclusivity. We ensure it",
"// is set correctly on an insert.",
"if",
"len",
"(",
"p",
".",
"plugins",
")",
"==",
"0",
"{",
"if",
"err",
":=",
"p",
".",
"applyPluginMeta",
"(",
"a",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"a",
".",
"SetID",
"(",
"p",
".",
"generatePID",
"(",
")",
")",
"\n",
"p",
".",
"plugins",
"[",
"a",
".",
"ID",
"(",
")",
"]",
"=",
"a",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Insert inserts an AvailablePlugin into the pool
|
[
"Insert",
"inserts",
"an",
"AvailablePlugin",
"into",
"the",
"pool"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L182-L199
|
15,456 |
intelsdi-x/snap
|
control/strategy/pool.go
|
applyPluginMeta
|
func (p *pool) applyPluginMeta(a AvailablePlugin) error {
// Checking if plugin is exclusive
// (only one instance should be running).
if a.Exclusive() {
p.max = 1
}
// Set the cache TTL
cacheTTL := GlobalCacheExpiration
// if the plugin exposes a default TTL that is greater the the global default use it
if a.CacheTTL() != 0 && a.CacheTTL() > GlobalCacheExpiration {
cacheTTL = a.CacheTTL()
}
// Set the concurrency count
p.concurrencyCount = a.ConcurrencyCount()
// Set the routing and caching strategy
switch a.RoutingStrategy() {
case plugin.DefaultRouting:
p.RoutingAndCaching = NewLRU(cacheTTL)
case plugin.StickyRouting:
p.RoutingAndCaching = NewSticky(cacheTTL)
p.concurrencyCount = 1
case plugin.ConfigRouting:
p.RoutingAndCaching = NewConfigBased(cacheTTL)
default:
return ErrBadStrategy
}
return nil
}
|
go
|
func (p *pool) applyPluginMeta(a AvailablePlugin) error {
// Checking if plugin is exclusive
// (only one instance should be running).
if a.Exclusive() {
p.max = 1
}
// Set the cache TTL
cacheTTL := GlobalCacheExpiration
// if the plugin exposes a default TTL that is greater the the global default use it
if a.CacheTTL() != 0 && a.CacheTTL() > GlobalCacheExpiration {
cacheTTL = a.CacheTTL()
}
// Set the concurrency count
p.concurrencyCount = a.ConcurrencyCount()
// Set the routing and caching strategy
switch a.RoutingStrategy() {
case plugin.DefaultRouting:
p.RoutingAndCaching = NewLRU(cacheTTL)
case plugin.StickyRouting:
p.RoutingAndCaching = NewSticky(cacheTTL)
p.concurrencyCount = 1
case plugin.ConfigRouting:
p.RoutingAndCaching = NewConfigBased(cacheTTL)
default:
return ErrBadStrategy
}
return nil
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"applyPluginMeta",
"(",
"a",
"AvailablePlugin",
")",
"error",
"{",
"// Checking if plugin is exclusive",
"// (only one instance should be running).",
"if",
"a",
".",
"Exclusive",
"(",
")",
"{",
"p",
".",
"max",
"=",
"1",
"\n",
"}",
"\n\n",
"// Set the cache TTL",
"cacheTTL",
":=",
"GlobalCacheExpiration",
"\n",
"// if the plugin exposes a default TTL that is greater the the global default use it",
"if",
"a",
".",
"CacheTTL",
"(",
")",
"!=",
"0",
"&&",
"a",
".",
"CacheTTL",
"(",
")",
">",
"GlobalCacheExpiration",
"{",
"cacheTTL",
"=",
"a",
".",
"CacheTTL",
"(",
")",
"\n",
"}",
"\n\n",
"// Set the concurrency count",
"p",
".",
"concurrencyCount",
"=",
"a",
".",
"ConcurrencyCount",
"(",
")",
"\n\n",
"// Set the routing and caching strategy",
"switch",
"a",
".",
"RoutingStrategy",
"(",
")",
"{",
"case",
"plugin",
".",
"DefaultRouting",
":",
"p",
".",
"RoutingAndCaching",
"=",
"NewLRU",
"(",
"cacheTTL",
")",
"\n",
"case",
"plugin",
".",
"StickyRouting",
":",
"p",
".",
"RoutingAndCaching",
"=",
"NewSticky",
"(",
"cacheTTL",
")",
"\n",
"p",
".",
"concurrencyCount",
"=",
"1",
"\n",
"case",
"plugin",
".",
"ConfigRouting",
":",
"p",
".",
"RoutingAndCaching",
"=",
"NewConfigBased",
"(",
"cacheTTL",
")",
"\n",
"default",
":",
"return",
"ErrBadStrategy",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// applyPluginMeta is called when the first plugin is added to the pool
|
[
"applyPluginMeta",
"is",
"called",
"when",
"the",
"first",
"plugin",
"is",
"added",
"to",
"the",
"pool"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L202-L233
|
15,457 |
intelsdi-x/snap
|
control/strategy/pool.go
|
Subscribe
|
func (p *pool) Subscribe(taskID string) {
p.Lock()
defer p.Unlock()
if _, exists := p.subs[taskID]; !exists {
// Version is the last item in the key, so we split here
// to retrieve it for the subscription.
p.subs[taskID] = &subscription{
TaskID: taskID,
Version: p.version,
}
}
}
|
go
|
func (p *pool) Subscribe(taskID string) {
p.Lock()
defer p.Unlock()
if _, exists := p.subs[taskID]; !exists {
// Version is the last item in the key, so we split here
// to retrieve it for the subscription.
p.subs[taskID] = &subscription{
TaskID: taskID,
Version: p.version,
}
}
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"Subscribe",
"(",
"taskID",
"string",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"_",
",",
"exists",
":=",
"p",
".",
"subs",
"[",
"taskID",
"]",
";",
"!",
"exists",
"{",
"// Version is the last item in the key, so we split here",
"// to retrieve it for the subscription.",
"p",
".",
"subs",
"[",
"taskID",
"]",
"=",
"&",
"subscription",
"{",
"TaskID",
":",
"taskID",
",",
"Version",
":",
"p",
".",
"version",
",",
"}",
"\n",
"}",
"\n",
"}"
] |
// subscribe adds a subscription to the pool.
// Using subscribe is idempotent.
|
[
"subscribe",
"adds",
"a",
"subscription",
"to",
"the",
"pool",
".",
"Using",
"subscribe",
"is",
"idempotent",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L237-L249
|
15,458 |
intelsdi-x/snap
|
control/strategy/pool.go
|
Unsubscribe
|
func (p *pool) Unsubscribe(taskID string) {
p.Lock()
defer p.Unlock()
delete(p.subs, taskID)
}
|
go
|
func (p *pool) Unsubscribe(taskID string) {
p.Lock()
defer p.Unlock()
delete(p.subs, taskID)
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"Unsubscribe",
"(",
"taskID",
"string",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"p",
".",
"subs",
",",
"taskID",
")",
"\n",
"}"
] |
// unsubscribe removes a subscription from the pool.
// Using unsubscribe is idempotent.
|
[
"unsubscribe",
"removes",
"a",
"subscription",
"from",
"the",
"pool",
".",
"Using",
"unsubscribe",
"is",
"idempotent",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L253-L257
|
15,459 |
intelsdi-x/snap
|
control/strategy/pool.go
|
Eligible
|
func (p *pool) Eligible() bool {
p.RLock()
defer p.RUnlock()
// optimization: don't even bother with concurrency
// count if we have already reached pool max
if len(p.plugins) >= p.max {
return false
}
// Check if pool is eligible and number of plugins is less than maximum allowed
if len(p.subs) > p.concurrencyCount*len(p.plugins) {
return true
}
return false
}
|
go
|
func (p *pool) Eligible() bool {
p.RLock()
defer p.RUnlock()
// optimization: don't even bother with concurrency
// count if we have already reached pool max
if len(p.plugins) >= p.max {
return false
}
// Check if pool is eligible and number of plugins is less than maximum allowed
if len(p.subs) > p.concurrencyCount*len(p.plugins) {
return true
}
return false
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"Eligible",
"(",
")",
"bool",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n\n",
"// optimization: don't even bother with concurrency",
"// count if we have already reached pool max",
"if",
"len",
"(",
"p",
".",
"plugins",
")",
">=",
"p",
".",
"max",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Check if pool is eligible and number of plugins is less than maximum allowed",
"if",
"len",
"(",
"p",
".",
"subs",
")",
">",
"p",
".",
"concurrencyCount",
"*",
"len",
"(",
"p",
".",
"plugins",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// Eligible returns a bool indicating whether the pool is eligible to grow
|
[
"Eligible",
"returns",
"a",
"bool",
"indicating",
"whether",
"the",
"pool",
"is",
"eligible",
"to",
"grow"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L260-L276
|
15,460 |
intelsdi-x/snap
|
control/strategy/pool.go
|
Kill
|
func (p *pool) Kill(id uint32, reason string) {
p.Lock()
defer p.Unlock()
ap, ok := p.plugins[id]
if ok {
ap.Kill(reason)
delete(p.plugins, id)
}
}
|
go
|
func (p *pool) Kill(id uint32, reason string) {
p.Lock()
defer p.Unlock()
ap, ok := p.plugins[id]
if ok {
ap.Kill(reason)
delete(p.plugins, id)
}
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"Kill",
"(",
"id",
"uint32",
",",
"reason",
"string",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"ap",
",",
"ok",
":=",
"p",
".",
"plugins",
"[",
"id",
"]",
"\n",
"if",
"ok",
"{",
"ap",
".",
"Kill",
"(",
"reason",
")",
"\n",
"delete",
"(",
"p",
".",
"plugins",
",",
"id",
")",
"\n",
"}",
"\n",
"}"
] |
// kill kills and removes the available plugin from its pool.
// Using kill is idempotent.
|
[
"kill",
"kills",
"and",
"removes",
"the",
"available",
"plugin",
"from",
"its",
"pool",
".",
"Using",
"kill",
"is",
"idempotent",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L280-L289
|
15,461 |
intelsdi-x/snap
|
control/strategy/pool.go
|
KillAll
|
func (p *pool) KillAll(reason string) {
for id, rp := range p.plugins {
log.WithFields(log.Fields{
"_block": "KillAll",
"reason": reason,
}).Debug(fmt.Sprintf("handling 'KillAll' for pool '%v', killing plugin '%v:%v'", p.String(), rp.Name(), rp.Version()))
if err := rp.Stop(reason); err != nil {
log.WithFields(log.Fields{
"_block": "KillAll",
"reason": reason,
}).Error(err)
}
p.Kill(id, reason)
}
}
|
go
|
func (p *pool) KillAll(reason string) {
for id, rp := range p.plugins {
log.WithFields(log.Fields{
"_block": "KillAll",
"reason": reason,
}).Debug(fmt.Sprintf("handling 'KillAll' for pool '%v', killing plugin '%v:%v'", p.String(), rp.Name(), rp.Version()))
if err := rp.Stop(reason); err != nil {
log.WithFields(log.Fields{
"_block": "KillAll",
"reason": reason,
}).Error(err)
}
p.Kill(id, reason)
}
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"KillAll",
"(",
"reason",
"string",
")",
"{",
"for",
"id",
",",
"rp",
":=",
"range",
"p",
".",
"plugins",
"{",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"reason",
",",
"}",
")",
".",
"Debug",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"String",
"(",
")",
",",
"rp",
".",
"Name",
"(",
")",
",",
"rp",
".",
"Version",
"(",
")",
")",
")",
"\n",
"if",
"err",
":=",
"rp",
".",
"Stop",
"(",
"reason",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"reason",
",",
"}",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"\n",
"p",
".",
"Kill",
"(",
"id",
",",
"reason",
")",
"\n",
"}",
"\n",
"}"
] |
// Kill all instances of a plugin
|
[
"Kill",
"all",
"instances",
"of",
"a",
"plugin"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L292-L306
|
15,462 |
intelsdi-x/snap
|
control/strategy/pool.go
|
SelectAndKill
|
func (p *pool) SelectAndKill(id, reason string) {
rp, err := p.Remove(p.plugins.Values(), id)
if err != nil {
log.WithFields(log.Fields{
"_block": "SelectAndKill",
"taskID": id,
"reason": reason,
}).Error(err)
return
}
if err := rp.Stop(reason); err != nil {
log.WithFields(log.Fields{
"_block": "SelectAndKill",
"taskID": id,
"reason": reason,
}).Error(err)
}
if err := rp.Kill(reason); err != nil {
log.WithFields(log.Fields{
"_block": "SelectAndKill",
"taskID": id,
"reason": reason,
}).Error(err)
}
p.remove(rp.ID())
}
|
go
|
func (p *pool) SelectAndKill(id, reason string) {
rp, err := p.Remove(p.plugins.Values(), id)
if err != nil {
log.WithFields(log.Fields{
"_block": "SelectAndKill",
"taskID": id,
"reason": reason,
}).Error(err)
return
}
if err := rp.Stop(reason); err != nil {
log.WithFields(log.Fields{
"_block": "SelectAndKill",
"taskID": id,
"reason": reason,
}).Error(err)
}
if err := rp.Kill(reason); err != nil {
log.WithFields(log.Fields{
"_block": "SelectAndKill",
"taskID": id,
"reason": reason,
}).Error(err)
}
p.remove(rp.ID())
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"SelectAndKill",
"(",
"id",
",",
"reason",
"string",
")",
"{",
"rp",
",",
"err",
":=",
"p",
".",
"Remove",
"(",
"p",
".",
"plugins",
".",
"Values",
"(",
")",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"id",
",",
"\"",
"\"",
":",
"reason",
",",
"}",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
":=",
"rp",
".",
"Stop",
"(",
"reason",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"id",
",",
"\"",
"\"",
":",
"reason",
",",
"}",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"rp",
".",
"Kill",
"(",
"reason",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"id",
",",
"\"",
"\"",
":",
"reason",
",",
"}",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"\n",
"p",
".",
"remove",
"(",
"rp",
".",
"ID",
"(",
")",
")",
"\n",
"}"
] |
// SelectAndKill selects, kills and removes the available plugin from the pool
|
[
"SelectAndKill",
"selects",
"kills",
"and",
"removes",
"the",
"available",
"plugin",
"from",
"the",
"pool"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L309-L334
|
15,463 |
intelsdi-x/snap
|
control/strategy/pool.go
|
remove
|
func (p *pool) remove(id uint32) {
p.Lock()
defer p.Unlock()
delete(p.plugins, id)
}
|
go
|
func (p *pool) remove(id uint32) {
p.Lock()
defer p.Unlock()
delete(p.plugins, id)
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"remove",
"(",
"id",
"uint32",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"p",
".",
"plugins",
",",
"id",
")",
"\n",
"}"
] |
// remove removes an available plugin from the the pool.
// using remove is idempotent.
|
[
"remove",
"removes",
"an",
"available",
"plugin",
"from",
"the",
"the",
"pool",
".",
"using",
"remove",
"is",
"idempotent",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L338-L342
|
15,464 |
intelsdi-x/snap
|
control/strategy/pool.go
|
Count
|
func (p *pool) Count() int {
p.RLock()
defer p.RUnlock()
return len(p.plugins)
}
|
go
|
func (p *pool) Count() int {
p.RLock()
defer p.RUnlock()
return len(p.plugins)
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"Count",
"(",
")",
"int",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"p",
".",
"plugins",
")",
"\n",
"}"
] |
// Count returns the number of plugins in the pool
|
[
"Count",
"returns",
"the",
"number",
"of",
"plugins",
"in",
"the",
"pool"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L345-L349
|
15,465 |
intelsdi-x/snap
|
control/strategy/pool.go
|
SubscriptionCount
|
func (p *pool) SubscriptionCount() int {
p.RLock()
defer p.RUnlock()
return len(p.subs)
}
|
go
|
func (p *pool) SubscriptionCount() int {
p.RLock()
defer p.RUnlock()
return len(p.subs)
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"SubscriptionCount",
"(",
")",
"int",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"p",
".",
"subs",
")",
"\n",
"}"
] |
// SubscriptionCount returns the number of subscriptions in the pool
|
[
"SubscriptionCount",
"returns",
"the",
"number",
"of",
"subscriptions",
"in",
"the",
"pool"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L359-L363
|
15,466 |
intelsdi-x/snap
|
control/strategy/pool.go
|
SelectAP
|
func (p *pool) SelectAP(taskID string, config map[string]ctypes.ConfigValue) (AvailablePlugin, serror.SnapError) {
aps := p.plugins.Values()
var id string
switch p.Strategy().String() {
case "least-recently-used":
id = ""
case "sticky":
id = taskID
case "config-based":
id = idFromCfg(config)
default:
return nil, serror.New(ErrBadStrategy)
}
ap, err := p.Select(aps, id)
if err != nil {
return nil, serror.New(err)
}
return ap, nil
}
|
go
|
func (p *pool) SelectAP(taskID string, config map[string]ctypes.ConfigValue) (AvailablePlugin, serror.SnapError) {
aps := p.plugins.Values()
var id string
switch p.Strategy().String() {
case "least-recently-used":
id = ""
case "sticky":
id = taskID
case "config-based":
id = idFromCfg(config)
default:
return nil, serror.New(ErrBadStrategy)
}
ap, err := p.Select(aps, id)
if err != nil {
return nil, serror.New(err)
}
return ap, nil
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"SelectAP",
"(",
"taskID",
"string",
",",
"config",
"map",
"[",
"string",
"]",
"ctypes",
".",
"ConfigValue",
")",
"(",
"AvailablePlugin",
",",
"serror",
".",
"SnapError",
")",
"{",
"aps",
":=",
"p",
".",
"plugins",
".",
"Values",
"(",
")",
"\n\n",
"var",
"id",
"string",
"\n",
"switch",
"p",
".",
"Strategy",
"(",
")",
".",
"String",
"(",
")",
"{",
"case",
"\"",
"\"",
":",
"id",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"id",
"=",
"taskID",
"\n",
"case",
"\"",
"\"",
":",
"id",
"=",
"idFromCfg",
"(",
"config",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"serror",
".",
"New",
"(",
"ErrBadStrategy",
")",
"\n",
"}",
"\n\n",
"ap",
",",
"err",
":=",
"p",
".",
"Select",
"(",
"aps",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"serror",
".",
"New",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ap",
",",
"nil",
"\n",
"}"
] |
// SelectAP selects an available plugin from the pool
// the method is not thread safe, it should be protected outside of the body
|
[
"SelectAP",
"selects",
"an",
"available",
"plugin",
"from",
"the",
"pool",
"the",
"method",
"is",
"not",
"thread",
"safe",
"it",
"should",
"be",
"protected",
"outside",
"of",
"the",
"body"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L367-L387
|
15,467 |
intelsdi-x/snap
|
control/strategy/pool.go
|
generatePID
|
func (p *pool) generatePID() uint32 {
atomic.AddUint32(&p.pidCounter, 1)
return p.pidCounter
}
|
go
|
func (p *pool) generatePID() uint32 {
atomic.AddUint32(&p.pidCounter, 1)
return p.pidCounter
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"generatePID",
"(",
")",
"uint32",
"{",
"atomic",
".",
"AddUint32",
"(",
"&",
"p",
".",
"pidCounter",
",",
"1",
")",
"\n",
"return",
"p",
".",
"pidCounter",
"\n",
"}"
] |
// generatePID returns the next available pid for the pool
|
[
"generatePID",
"returns",
"the",
"next",
"available",
"pid",
"for",
"the",
"pool"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L401-L404
|
15,468 |
intelsdi-x/snap
|
control/strategy/pool.go
|
CacheTTL
|
func (p *pool) CacheTTL(taskID string) (time.Duration, error) {
if len(p.plugins) == 0 {
return 0, ErrPoolEmpty
}
return p.RoutingAndCaching.CacheTTL(taskID)
}
|
go
|
func (p *pool) CacheTTL(taskID string) (time.Duration, error) {
if len(p.plugins) == 0 {
return 0, ErrPoolEmpty
}
return p.RoutingAndCaching.CacheTTL(taskID)
}
|
[
"func",
"(",
"p",
"*",
"pool",
")",
"CacheTTL",
"(",
"taskID",
"string",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"if",
"len",
"(",
"p",
".",
"plugins",
")",
"==",
"0",
"{",
"return",
"0",
",",
"ErrPoolEmpty",
"\n",
"}",
"\n",
"return",
"p",
".",
"RoutingAndCaching",
".",
"CacheTTL",
"(",
"taskID",
")",
"\n",
"}"
] |
// CacheTTL returns the cacheTTL for the pool
|
[
"CacheTTL",
"returns",
"the",
"cacheTTL",
"for",
"the",
"pool"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/strategy/pool.go#L407-L412
|
15,469 |
intelsdi-x/snap
|
pkg/psigning/psigning.go
|
ValidateSignature
|
func (s *SigningManager) ValidateSignature(keyringFiles []string, signedFile string, signature []byte) error {
var signedby string
var e error
var checked *openpgp.Entity
signed, err := os.Open(signedFile)
if err != nil {
return fmt.Errorf("%v: %v\n%v", ErrSignedFileNotFound, signedFile, err)
}
defer signed.Close()
//Go through all the keyrings til either signature is valid or end of keyrings
for _, keyringFile := range keyringFiles {
keyringf, err := os.Open(keyringFile)
if err != nil {
return fmt.Errorf("%v: %v\n%v", ErrKeyringFileNotFound, keyringFile, err)
}
defer keyringf.Close()
//Read both armored and unarmored keyrings
keyring, err := openpgp.ReadArmoredKeyRing(keyringf)
if err != nil {
keyringf.Seek(0, 0)
keyring, err = openpgp.ReadKeyRing(keyringf)
if err != nil {
return fmt.Errorf("%v: %v\n%v", ErrUnableToReadKeyring, keyringFile, err)
}
}
//Check the armored detached signature
checked, e = openpgp.CheckArmoredDetachedSignature(keyring, signed, bytes.NewReader(signature))
if e == nil {
for k := range checked.Identities {
signedby = signedby + k
}
fmt.Printf("Signature made %v using RSA key ID %v\nGood signature from %v\n", time.Now().Format(time.RFC1123), checked.PrimaryKey.KeyIdShortString(), signedby)
return nil
}
signed.Seek(0, 0)
}
return fmt.Errorf("%v\n%v", ErrCheckSignature, e)
}
|
go
|
func (s *SigningManager) ValidateSignature(keyringFiles []string, signedFile string, signature []byte) error {
var signedby string
var e error
var checked *openpgp.Entity
signed, err := os.Open(signedFile)
if err != nil {
return fmt.Errorf("%v: %v\n%v", ErrSignedFileNotFound, signedFile, err)
}
defer signed.Close()
//Go through all the keyrings til either signature is valid or end of keyrings
for _, keyringFile := range keyringFiles {
keyringf, err := os.Open(keyringFile)
if err != nil {
return fmt.Errorf("%v: %v\n%v", ErrKeyringFileNotFound, keyringFile, err)
}
defer keyringf.Close()
//Read both armored and unarmored keyrings
keyring, err := openpgp.ReadArmoredKeyRing(keyringf)
if err != nil {
keyringf.Seek(0, 0)
keyring, err = openpgp.ReadKeyRing(keyringf)
if err != nil {
return fmt.Errorf("%v: %v\n%v", ErrUnableToReadKeyring, keyringFile, err)
}
}
//Check the armored detached signature
checked, e = openpgp.CheckArmoredDetachedSignature(keyring, signed, bytes.NewReader(signature))
if e == nil {
for k := range checked.Identities {
signedby = signedby + k
}
fmt.Printf("Signature made %v using RSA key ID %v\nGood signature from %v\n", time.Now().Format(time.RFC1123), checked.PrimaryKey.KeyIdShortString(), signedby)
return nil
}
signed.Seek(0, 0)
}
return fmt.Errorf("%v\n%v", ErrCheckSignature, e)
}
|
[
"func",
"(",
"s",
"*",
"SigningManager",
")",
"ValidateSignature",
"(",
"keyringFiles",
"[",
"]",
"string",
",",
"signedFile",
"string",
",",
"signature",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"signedby",
"string",
"\n",
"var",
"e",
"error",
"\n",
"var",
"checked",
"*",
"openpgp",
".",
"Entity",
"\n\n",
"signed",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"signedFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrSignedFileNotFound",
",",
"signedFile",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"signed",
".",
"Close",
"(",
")",
"\n\n",
"//Go through all the keyrings til either signature is valid or end of keyrings",
"for",
"_",
",",
"keyringFile",
":=",
"range",
"keyringFiles",
"{",
"keyringf",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"keyringFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrKeyringFileNotFound",
",",
"keyringFile",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"keyringf",
".",
"Close",
"(",
")",
"\n\n",
"//Read both armored and unarmored keyrings",
"keyring",
",",
"err",
":=",
"openpgp",
".",
"ReadArmoredKeyRing",
"(",
"keyringf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"keyringf",
".",
"Seek",
"(",
"0",
",",
"0",
")",
"\n",
"keyring",
",",
"err",
"=",
"openpgp",
".",
"ReadKeyRing",
"(",
"keyringf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrUnableToReadKeyring",
",",
"keyringFile",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"//Check the armored detached signature",
"checked",
",",
"e",
"=",
"openpgp",
".",
"CheckArmoredDetachedSignature",
"(",
"keyring",
",",
"signed",
",",
"bytes",
".",
"NewReader",
"(",
"signature",
")",
")",
"\n",
"if",
"e",
"==",
"nil",
"{",
"for",
"k",
":=",
"range",
"checked",
".",
"Identities",
"{",
"signedby",
"=",
"signedby",
"+",
"k",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"Format",
"(",
"time",
".",
"RFC1123",
")",
",",
"checked",
".",
"PrimaryKey",
".",
"KeyIdShortString",
"(",
")",
",",
"signedby",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"signed",
".",
"Seek",
"(",
"0",
",",
"0",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"ErrCheckSignature",
",",
"e",
")",
"\n",
"}"
] |
//ValidateSignature is exported for plugin authoring
|
[
"ValidateSignature",
"is",
"exported",
"for",
"plugin",
"authoring"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/psigning/psigning.go#L49-L90
|
15,470 |
intelsdi-x/snap
|
core/ctypes/ctypes.go
|
SupportedTypes
|
func SupportedTypes() []string {
// This is kind of a hack but keeps the definition of types here in
// ctypes.go. If you create a new ConfigValue type be sure and add here
// to return the Type() response. This will cause any depedant components
// to acknowledge and use that type.
t := []string{
// String
ConfigValueStr{}.Type(),
// Integer
ConfigValueInt{}.Type(),
// Float
ConfigValueFloat{}.Type(),
// Bool
ConfigValueBool{}.Type(),
}
return t
}
|
go
|
func SupportedTypes() []string {
// This is kind of a hack but keeps the definition of types here in
// ctypes.go. If you create a new ConfigValue type be sure and add here
// to return the Type() response. This will cause any depedant components
// to acknowledge and use that type.
t := []string{
// String
ConfigValueStr{}.Type(),
// Integer
ConfigValueInt{}.Type(),
// Float
ConfigValueFloat{}.Type(),
// Bool
ConfigValueBool{}.Type(),
}
return t
}
|
[
"func",
"SupportedTypes",
"(",
")",
"[",
"]",
"string",
"{",
"// This is kind of a hack but keeps the definition of types here in",
"// ctypes.go. If you create a new ConfigValue type be sure and add here",
"// to return the Type() response. This will cause any depedant components",
"// to acknowledge and use that type.",
"t",
":=",
"[",
"]",
"string",
"{",
"// String",
"ConfigValueStr",
"{",
"}",
".",
"Type",
"(",
")",
",",
"// Integer",
"ConfigValueInt",
"{",
"}",
".",
"Type",
"(",
")",
",",
"// Float",
"ConfigValueFloat",
"{",
"}",
".",
"Type",
"(",
")",
",",
"// Bool",
"ConfigValueBool",
"{",
"}",
".",
"Type",
"(",
")",
",",
"}",
"\n",
"return",
"t",
"\n",
"}"
] |
// Returns a slice of string keywords for the types supported by ConfigValue.
|
[
"Returns",
"a",
"slice",
"of",
"string",
"keywords",
"for",
"the",
"types",
"supported",
"by",
"ConfigValue",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/ctypes/ctypes.go#L79-L95
|
15,471 |
intelsdi-x/snap
|
control/plugin/execution.go
|
NewExecutablePlugin
|
func NewExecutablePlugin(a Arg, commands ...string) (*ExecutablePlugin, error) {
jsonArgs, err := json.Marshal(a)
if err != nil {
return nil, err
}
cmd := &exec.Cmd{
Path: commands[0],
Args: append(commands, string(jsonArgs)),
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
return &ExecutablePlugin{
cmd: &commandWrapper{cmd},
stdout: stdout,
stderr: stderr,
}, nil
}
|
go
|
func NewExecutablePlugin(a Arg, commands ...string) (*ExecutablePlugin, error) {
jsonArgs, err := json.Marshal(a)
if err != nil {
return nil, err
}
cmd := &exec.Cmd{
Path: commands[0],
Args: append(commands, string(jsonArgs)),
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
return &ExecutablePlugin{
cmd: &commandWrapper{cmd},
stdout: stdout,
stderr: stderr,
}, nil
}
|
[
"func",
"NewExecutablePlugin",
"(",
"a",
"Arg",
",",
"commands",
"...",
"string",
")",
"(",
"*",
"ExecutablePlugin",
",",
"error",
")",
"{",
"jsonArgs",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cmd",
":=",
"&",
"exec",
".",
"Cmd",
"{",
"Path",
":",
"commands",
"[",
"0",
"]",
",",
"Args",
":",
"append",
"(",
"commands",
",",
"string",
"(",
"jsonArgs",
")",
")",
",",
"}",
"\n",
"stdout",
",",
"err",
":=",
"cmd",
".",
"StdoutPipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stderr",
",",
"err",
":=",
"cmd",
".",
"StderrPipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"ExecutablePlugin",
"{",
"cmd",
":",
"&",
"commandWrapper",
"{",
"cmd",
"}",
",",
"stdout",
":",
"stdout",
",",
"stderr",
":",
"stderr",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewExecutablePlugin returns a new ExecutablePlugin.
|
[
"NewExecutablePlugin",
"returns",
"a",
"new",
"ExecutablePlugin",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/plugin/execution.go#L80-L102
|
15,472 |
intelsdi-x/snap
|
control/plugin/execution.go
|
Run
|
func (e *ExecutablePlugin) Run(timeout time.Duration) (Response, error) {
var (
respReceived bool
resp Response
err error
respBytes []byte
)
doneChan := make(chan struct{})
stdOutScanner := bufio.NewScanner(e.stdout)
// Start the command and begin reading its output.
if err = e.cmd.Start(); err != nil {
return resp, err
}
e.captureStderr()
go func() {
for {
for stdOutScanner.Scan() {
// The first chunk from the scanner is the plugin's response to the
// handshake. Once we've received that, we can begin to forward
// logs on to snapteld's log.
if !respReceived {
respBytes = stdOutScanner.Bytes()
err = json.Unmarshal(respBytes, &resp)
respReceived = true
close(doneChan)
} else {
execLogger.WithFields(log.Fields{
"plugin": e.name,
"io": "stdout",
}).Debug(stdOutScanner.Text())
}
}
if errScanner := stdOutScanner.Err(); errScanner != nil {
reader := bufio.NewReader(e.stdout)
log, errRead := reader.ReadString('\n')
if errRead == io.EOF {
break
}
execLogger.
WithField("plugin", path.Base(e.cmd.Path())).
WithField("io", "stdout").
WithField("scanner_err", errScanner).
WithField("read_string_err", errRead).
Warn(log)
continue //scanner finished with errors so try to scan once again
}
break //scanner finished scanning without errors so break the loop
}
}()
// Wait until:
// a) We receive a signal that the plugin has responded
// OR
// b) The timeout expires
select {
case <-doneChan:
case <-time.After(timeout):
// We timed out waiting for the plugin's response. Set err.
err = fmt.Errorf("timed out waiting for plugin %s", path.Base(e.cmd.Path()))
}
if err != nil {
execLogger.WithFields(log.Fields{
"received_response": string(respBytes),
}).Error("error loading plugin")
// Kill the plugin if we failed to load it.
e.Kill()
}
lowerName := strings.ToLower(resp.Meta.Name)
if lowerName != resp.Meta.Name {
execLogger.WithFields(log.Fields{
"plugin-name": resp.Meta.Name,
"plugin-version": resp.Meta.Version,
"plugin-type": resp.Type.String(),
}).Warning("uppercase plugin name")
}
resp.Meta.Name = lowerName
return resp, err
}
|
go
|
func (e *ExecutablePlugin) Run(timeout time.Duration) (Response, error) {
var (
respReceived bool
resp Response
err error
respBytes []byte
)
doneChan := make(chan struct{})
stdOutScanner := bufio.NewScanner(e.stdout)
// Start the command and begin reading its output.
if err = e.cmd.Start(); err != nil {
return resp, err
}
e.captureStderr()
go func() {
for {
for stdOutScanner.Scan() {
// The first chunk from the scanner is the plugin's response to the
// handshake. Once we've received that, we can begin to forward
// logs on to snapteld's log.
if !respReceived {
respBytes = stdOutScanner.Bytes()
err = json.Unmarshal(respBytes, &resp)
respReceived = true
close(doneChan)
} else {
execLogger.WithFields(log.Fields{
"plugin": e.name,
"io": "stdout",
}).Debug(stdOutScanner.Text())
}
}
if errScanner := stdOutScanner.Err(); errScanner != nil {
reader := bufio.NewReader(e.stdout)
log, errRead := reader.ReadString('\n')
if errRead == io.EOF {
break
}
execLogger.
WithField("plugin", path.Base(e.cmd.Path())).
WithField("io", "stdout").
WithField("scanner_err", errScanner).
WithField("read_string_err", errRead).
Warn(log)
continue //scanner finished with errors so try to scan once again
}
break //scanner finished scanning without errors so break the loop
}
}()
// Wait until:
// a) We receive a signal that the plugin has responded
// OR
// b) The timeout expires
select {
case <-doneChan:
case <-time.After(timeout):
// We timed out waiting for the plugin's response. Set err.
err = fmt.Errorf("timed out waiting for plugin %s", path.Base(e.cmd.Path()))
}
if err != nil {
execLogger.WithFields(log.Fields{
"received_response": string(respBytes),
}).Error("error loading plugin")
// Kill the plugin if we failed to load it.
e.Kill()
}
lowerName := strings.ToLower(resp.Meta.Name)
if lowerName != resp.Meta.Name {
execLogger.WithFields(log.Fields{
"plugin-name": resp.Meta.Name,
"plugin-version": resp.Meta.Version,
"plugin-type": resp.Type.String(),
}).Warning("uppercase plugin name")
}
resp.Meta.Name = lowerName
return resp, err
}
|
[
"func",
"(",
"e",
"*",
"ExecutablePlugin",
")",
"Run",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"Response",
",",
"error",
")",
"{",
"var",
"(",
"respReceived",
"bool",
"\n",
"resp",
"Response",
"\n",
"err",
"error",
"\n",
"respBytes",
"[",
"]",
"byte",
"\n",
")",
"\n\n",
"doneChan",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"stdOutScanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"e",
".",
"stdout",
")",
"\n\n",
"// Start the command and begin reading its output.",
"if",
"err",
"=",
"e",
".",
"cmd",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"e",
".",
"captureStderr",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"for",
"stdOutScanner",
".",
"Scan",
"(",
")",
"{",
"// The first chunk from the scanner is the plugin's response to the",
"// handshake. Once we've received that, we can begin to forward",
"// logs on to snapteld's log.",
"if",
"!",
"respReceived",
"{",
"respBytes",
"=",
"stdOutScanner",
".",
"Bytes",
"(",
")",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"respBytes",
",",
"&",
"resp",
")",
"\n",
"respReceived",
"=",
"true",
"\n",
"close",
"(",
"doneChan",
")",
"\n",
"}",
"else",
"{",
"execLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"e",
".",
"name",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
")",
".",
"Debug",
"(",
"stdOutScanner",
".",
"Text",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"errScanner",
":=",
"stdOutScanner",
".",
"Err",
"(",
")",
";",
"errScanner",
"!=",
"nil",
"{",
"reader",
":=",
"bufio",
".",
"NewReader",
"(",
"e",
".",
"stdout",
")",
"\n",
"log",
",",
"errRead",
":=",
"reader",
".",
"ReadString",
"(",
"'\\n'",
")",
"\n",
"if",
"errRead",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n\n",
"execLogger",
".",
"WithField",
"(",
"\"",
"\"",
",",
"path",
".",
"Base",
"(",
"e",
".",
"cmd",
".",
"Path",
"(",
")",
")",
")",
".",
"WithField",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"WithField",
"(",
"\"",
"\"",
",",
"errScanner",
")",
".",
"WithField",
"(",
"\"",
"\"",
",",
"errRead",
")",
".",
"Warn",
"(",
"log",
")",
"\n\n",
"continue",
"//scanner finished with errors so try to scan once again",
"\n",
"}",
"\n",
"break",
"//scanner finished scanning without errors so break the loop",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// Wait until:",
"// a) We receive a signal that the plugin has responded",
"// OR",
"// b) The timeout expires",
"select",
"{",
"case",
"<-",
"doneChan",
":",
"case",
"<-",
"time",
".",
"After",
"(",
"timeout",
")",
":",
"// We timed out waiting for the plugin's response. Set err.",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
".",
"Base",
"(",
"e",
".",
"cmd",
".",
"Path",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"execLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"string",
"(",
"respBytes",
")",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n\n",
"// Kill the plugin if we failed to load it.",
"e",
".",
"Kill",
"(",
")",
"\n",
"}",
"\n",
"lowerName",
":=",
"strings",
".",
"ToLower",
"(",
"resp",
".",
"Meta",
".",
"Name",
")",
"\n",
"if",
"lowerName",
"!=",
"resp",
".",
"Meta",
".",
"Name",
"{",
"execLogger",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"resp",
".",
"Meta",
".",
"Name",
",",
"\"",
"\"",
":",
"resp",
".",
"Meta",
".",
"Version",
",",
"\"",
"\"",
":",
"resp",
".",
"Type",
".",
"String",
"(",
")",
",",
"}",
")",
".",
"Warning",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"resp",
".",
"Meta",
".",
"Name",
"=",
"lowerName",
"\n\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] |
// Run executes the plugin and waits for a response, or times out.
|
[
"Run",
"executes",
"the",
"plugin",
"and",
"waits",
"for",
"a",
"response",
"or",
"times",
"out",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/plugin/execution.go#L105-L190
|
15,473 |
intelsdi-x/snap
|
core/metric.go
|
Strings
|
func (n Namespace) Strings() []string {
var ns []string
for _, namespaceElement := range n {
ns = append(ns, namespaceElement.Value)
}
return ns
}
|
go
|
func (n Namespace) Strings() []string {
var ns []string
for _, namespaceElement := range n {
ns = append(ns, namespaceElement.Value)
}
return ns
}
|
[
"func",
"(",
"n",
"Namespace",
")",
"Strings",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"ns",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"namespaceElement",
":=",
"range",
"n",
"{",
"ns",
"=",
"append",
"(",
"ns",
",",
"namespaceElement",
".",
"Value",
")",
"\n",
"}",
"\n",
"return",
"ns",
"\n",
"}"
] |
// Strings returns an array of strings that represent the elements of the
// namespace.
|
[
"Strings",
"returns",
"an",
"array",
"of",
"strings",
"that",
"represent",
"the",
"elements",
"of",
"the",
"namespace",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/metric.go#L62-L68
|
15,474 |
intelsdi-x/snap
|
core/metric.go
|
getSeparator
|
func (n Namespace) getSeparator() string {
smap := initSeparatorMap()
for _, e := range n {
// look at each char
for _, r := range e.Value {
ch := fmt.Sprintf("%c", r)
if v, ok := smap[ch]; ok && !v {
smap[ch] = true
}
}
}
// Go through our separator list
for _, s := range nsPriorityList {
if v, ok := smap[s]; ok && !v {
return s
}
}
return Separator
}
|
go
|
func (n Namespace) getSeparator() string {
smap := initSeparatorMap()
for _, e := range n {
// look at each char
for _, r := range e.Value {
ch := fmt.Sprintf("%c", r)
if v, ok := smap[ch]; ok && !v {
smap[ch] = true
}
}
}
// Go through our separator list
for _, s := range nsPriorityList {
if v, ok := smap[s]; ok && !v {
return s
}
}
return Separator
}
|
[
"func",
"(",
"n",
"Namespace",
")",
"getSeparator",
"(",
")",
"string",
"{",
"smap",
":=",
"initSeparatorMap",
"(",
")",
"\n\n",
"for",
"_",
",",
"e",
":=",
"range",
"n",
"{",
"// look at each char",
"for",
"_",
",",
"r",
":=",
"range",
"e",
".",
"Value",
"{",
"ch",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"if",
"v",
",",
"ok",
":=",
"smap",
"[",
"ch",
"]",
";",
"ok",
"&&",
"!",
"v",
"{",
"smap",
"[",
"ch",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Go through our separator list",
"for",
"_",
",",
"s",
":=",
"range",
"nsPriorityList",
"{",
"if",
"v",
",",
"ok",
":=",
"smap",
"[",
"s",
"]",
";",
"ok",
"&&",
"!",
"v",
"{",
"return",
"s",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"Separator",
"\n",
"}"
] |
// getSeparator returns the highest suitable separator from the nsPriorityList.
// Otherwise the core separator is returned.
|
[
"getSeparator",
"returns",
"the",
"highest",
"suitable",
"separator",
"from",
"the",
"nsPriorityList",
".",
"Otherwise",
"the",
"core",
"separator",
"is",
"returned",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/metric.go#L72-L92
|
15,475 |
intelsdi-x/snap
|
core/metric.go
|
initSeparatorMap
|
func initSeparatorMap() map[string]bool {
m := map[string]bool{}
for _, s := range nsPriorityList {
m[s] = false
}
return m
}
|
go
|
func initSeparatorMap() map[string]bool {
m := map[string]bool{}
for _, s := range nsPriorityList {
m[s] = false
}
return m
}
|
[
"func",
"initSeparatorMap",
"(",
")",
"map",
"[",
"string",
"]",
"bool",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"nsPriorityList",
"{",
"m",
"[",
"s",
"]",
"=",
"false",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] |
// initSeparatorMap populates the local map of nsPriorityList.
|
[
"initSeparatorMap",
"populates",
"the",
"local",
"map",
"of",
"nsPriorityList",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/metric.go#L95-L102
|
15,476 |
intelsdi-x/snap
|
core/metric.go
|
NewNamespace
|
func NewNamespace(ns ...string) Namespace {
n := make([]NamespaceElement, len(ns))
for i, ns := range ns {
n[i] = NamespaceElement{Value: ns}
}
return n
}
|
go
|
func NewNamespace(ns ...string) Namespace {
n := make([]NamespaceElement, len(ns))
for i, ns := range ns {
n[i] = NamespaceElement{Value: ns}
}
return n
}
|
[
"func",
"NewNamespace",
"(",
"ns",
"...",
"string",
")",
"Namespace",
"{",
"n",
":=",
"make",
"(",
"[",
"]",
"NamespaceElement",
",",
"len",
"(",
"ns",
")",
")",
"\n",
"for",
"i",
",",
"ns",
":=",
"range",
"ns",
"{",
"n",
"[",
"i",
"]",
"=",
"NamespaceElement",
"{",
"Value",
":",
"ns",
"}",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] |
// NewNamespace takes an array of strings and returns a Namespace. A Namespace
// is an array of NamespaceElements. The provided array of strings is used to
// set the corresponding Value fields in the array of NamespaceElements.
|
[
"NewNamespace",
"takes",
"an",
"array",
"of",
"strings",
"and",
"returns",
"a",
"Namespace",
".",
"A",
"Namespace",
"is",
"an",
"array",
"of",
"NamespaceElements",
".",
"The",
"provided",
"array",
"of",
"strings",
"is",
"used",
"to",
"set",
"the",
"corresponding",
"Value",
"fields",
"in",
"the",
"array",
"of",
"NamespaceElements",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/metric.go#L124-L130
|
15,477 |
intelsdi-x/snap
|
core/metric.go
|
AddDynamicElement
|
func (n Namespace) AddDynamicElement(name, description string) Namespace {
nse := NamespaceElement{Name: name, Description: description, Value: "*"}
return append(n, nse)
}
|
go
|
func (n Namespace) AddDynamicElement(name, description string) Namespace {
nse := NamespaceElement{Name: name, Description: description, Value: "*"}
return append(n, nse)
}
|
[
"func",
"(",
"n",
"Namespace",
")",
"AddDynamicElement",
"(",
"name",
",",
"description",
"string",
")",
"Namespace",
"{",
"nse",
":=",
"NamespaceElement",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Value",
":",
"\"",
"\"",
"}",
"\n",
"return",
"append",
"(",
"n",
",",
"nse",
")",
"\n",
"}"
] |
// AddDynamicElement adds a dynamic element to the given Namespace. A dynamic
// NamespaceElement is defined by having a nonempty Name field.
|
[
"AddDynamicElement",
"adds",
"a",
"dynamic",
"element",
"to",
"the",
"given",
"Namespace",
".",
"A",
"dynamic",
"NamespaceElement",
"is",
"defined",
"by",
"having",
"a",
"nonempty",
"Name",
"field",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/metric.go#L134-L137
|
15,478 |
intelsdi-x/snap
|
core/metric.go
|
AddStaticElement
|
func (n Namespace) AddStaticElement(value string) Namespace {
nse := NamespaceElement{Value: value}
return append(n, nse)
}
|
go
|
func (n Namespace) AddStaticElement(value string) Namespace {
nse := NamespaceElement{Value: value}
return append(n, nse)
}
|
[
"func",
"(",
"n",
"Namespace",
")",
"AddStaticElement",
"(",
"value",
"string",
")",
"Namespace",
"{",
"nse",
":=",
"NamespaceElement",
"{",
"Value",
":",
"value",
"}",
"\n",
"return",
"append",
"(",
"n",
",",
"nse",
")",
"\n",
"}"
] |
// AddStaticElement adds a static element to the given Namespace. A static
// NamespaceElement is defined by having an empty Name field.
|
[
"AddStaticElement",
"adds",
"a",
"static",
"element",
"to",
"the",
"given",
"Namespace",
".",
"A",
"static",
"NamespaceElement",
"is",
"defined",
"by",
"having",
"an",
"empty",
"Name",
"field",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/metric.go#L141-L144
|
15,479 |
intelsdi-x/snap
|
core/metric.go
|
AddStaticElements
|
func (n Namespace) AddStaticElements(values ...string) Namespace {
for _, value := range values {
n = append(n, NamespaceElement{Value: value})
}
return n
}
|
go
|
func (n Namespace) AddStaticElements(values ...string) Namespace {
for _, value := range values {
n = append(n, NamespaceElement{Value: value})
}
return n
}
|
[
"func",
"(",
"n",
"Namespace",
")",
"AddStaticElements",
"(",
"values",
"...",
"string",
")",
"Namespace",
"{",
"for",
"_",
",",
"value",
":=",
"range",
"values",
"{",
"n",
"=",
"append",
"(",
"n",
",",
"NamespaceElement",
"{",
"Value",
":",
"value",
"}",
")",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] |
// AddStaticElements adds a static elements to the given Namespace. A static
// NamespaceElement is defined by having an empty Name field.
|
[
"AddStaticElements",
"adds",
"a",
"static",
"elements",
"to",
"the",
"given",
"Namespace",
".",
"A",
"static",
"NamespaceElement",
"is",
"defined",
"by",
"having",
"an",
"empty",
"Name",
"field",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/core/metric.go#L148-L153
|
15,480 |
intelsdi-x/snap
|
scheduler/worker.go
|
start
|
func (w *worker) start() {
for {
select {
case q := <-w.rcv:
// assert that deadline is not exceeded
if chrono.Chrono.Now().Before(q.Job().Deadline()) {
q.Job().Run()
} else {
// the deadline was exceeded and this job will not run
q.Job().AddErrors(errors.New("Worker refused to run overdue job."))
}
// mark the job complete
q.Promise().Complete(q.Job().Errors())
// the single kill-channel -- used when resizing worker pools
case <-w.kamikaze:
return
//the broadcast that kills all workers
case <-workerKillChan:
return
}
}
}
|
go
|
func (w *worker) start() {
for {
select {
case q := <-w.rcv:
// assert that deadline is not exceeded
if chrono.Chrono.Now().Before(q.Job().Deadline()) {
q.Job().Run()
} else {
// the deadline was exceeded and this job will not run
q.Job().AddErrors(errors.New("Worker refused to run overdue job."))
}
// mark the job complete
q.Promise().Complete(q.Job().Errors())
// the single kill-channel -- used when resizing worker pools
case <-w.kamikaze:
return
//the broadcast that kills all workers
case <-workerKillChan:
return
}
}
}
|
[
"func",
"(",
"w",
"*",
"worker",
")",
"start",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"q",
":=",
"<-",
"w",
".",
"rcv",
":",
"// assert that deadline is not exceeded",
"if",
"chrono",
".",
"Chrono",
".",
"Now",
"(",
")",
".",
"Before",
"(",
"q",
".",
"Job",
"(",
")",
".",
"Deadline",
"(",
")",
")",
"{",
"q",
".",
"Job",
"(",
")",
".",
"Run",
"(",
")",
"\n",
"}",
"else",
"{",
"// the deadline was exceeded and this job will not run",
"q",
".",
"Job",
"(",
")",
".",
"AddErrors",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"// mark the job complete",
"q",
".",
"Promise",
"(",
")",
".",
"Complete",
"(",
"q",
".",
"Job",
"(",
")",
".",
"Errors",
"(",
")",
")",
"\n\n",
"// the single kill-channel -- used when resizing worker pools",
"case",
"<-",
"w",
".",
"kamikaze",
":",
"return",
"\n\n",
"//the broadcast that kills all workers",
"case",
"<-",
"workerKillChan",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// begin a worker
|
[
"begin",
"a",
"worker"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/scheduler/worker.go#L46-L70
|
15,481 |
intelsdi-x/snap
|
mgmt/rest/client/metric.go
|
FetchMetrics
|
func (c *Client) FetchMetrics(ns string, ver int) *GetMetricsResult {
r := &GetMetricsResult{}
q := fmt.Sprintf("/metrics?ns=%s&ver=%d", ns, ver)
resp, err := c.do("GET", q, ContentTypeJSON)
if err != nil {
return &GetMetricsResult{Err: err}
}
switch resp.Meta.Type {
case rbody.MetricsReturnedType:
mc := resp.Body.(*rbody.MetricsReturned)
r.Catalog = convertCatalog(mc)
case rbody.MetricReturnedType:
mc := resp.Body.(*rbody.MetricReturned)
r.Catalog = []*rbody.Metric{mc.Metric}
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
go
|
func (c *Client) FetchMetrics(ns string, ver int) *GetMetricsResult {
r := &GetMetricsResult{}
q := fmt.Sprintf("/metrics?ns=%s&ver=%d", ns, ver)
resp, err := c.do("GET", q, ContentTypeJSON)
if err != nil {
return &GetMetricsResult{Err: err}
}
switch resp.Meta.Type {
case rbody.MetricsReturnedType:
mc := resp.Body.(*rbody.MetricsReturned)
r.Catalog = convertCatalog(mc)
case rbody.MetricReturnedType:
mc := resp.Body.(*rbody.MetricReturned)
r.Catalog = []*rbody.Metric{mc.Metric}
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"FetchMetrics",
"(",
"ns",
"string",
",",
"ver",
"int",
")",
"*",
"GetMetricsResult",
"{",
"r",
":=",
"&",
"GetMetricsResult",
"{",
"}",
"\n",
"q",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ns",
",",
"ver",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"do",
"(",
"\"",
"\"",
",",
"q",
",",
"ContentTypeJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"GetMetricsResult",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"switch",
"resp",
".",
"Meta",
".",
"Type",
"{",
"case",
"rbody",
".",
"MetricsReturnedType",
":",
"mc",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"MetricsReturned",
")",
"\n",
"r",
".",
"Catalog",
"=",
"convertCatalog",
"(",
"mc",
")",
"\n",
"case",
"rbody",
".",
"MetricReturnedType",
":",
"mc",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"MetricReturned",
")",
"\n",
"r",
".",
"Catalog",
"=",
"[",
"]",
"*",
"rbody",
".",
"Metric",
"{",
"mc",
".",
"Metric",
"}",
"\n",
"case",
"rbody",
".",
"ErrorType",
":",
"r",
".",
"Err",
"=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"Error",
")",
"\n",
"default",
":",
"r",
".",
"Err",
"=",
"ErrAPIResponseMetaType",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// FetchMetrics retrieves the metric catalog given metric namespace and version through an HTTP GET request.
// It returns the corresponding metric catalog if succeeded. Otherwise, an error is returned.
|
[
"FetchMetrics",
"retrieves",
"the",
"metric",
"catalog",
"given",
"metric",
"namespace",
"and",
"version",
"through",
"an",
"HTTP",
"GET",
"request",
".",
"It",
"returns",
"the",
"corresponding",
"metric",
"catalog",
"if",
"succeeded",
".",
"Otherwise",
"an",
"error",
"is",
"returned",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/metric.go#L57-L78
|
15,482 |
intelsdi-x/snap
|
mgmt/rest/client/metric.go
|
GetMetricVersions
|
func (c *Client) GetMetricVersions(ns string) *GetMetricsResult {
r := &GetMetricsResult{}
q := fmt.Sprintf("/metrics?ns=%s", ns)
resp, err := c.do("GET", q, ContentTypeJSON)
if err != nil {
return &GetMetricsResult{Err: err}
}
switch resp.Meta.Type {
case rbody.MetricsReturnedType:
mc := resp.Body.(*rbody.MetricsReturned)
r.Catalog = convertCatalog(mc)
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
go
|
func (c *Client) GetMetricVersions(ns string) *GetMetricsResult {
r := &GetMetricsResult{}
q := fmt.Sprintf("/metrics?ns=%s", ns)
resp, err := c.do("GET", q, ContentTypeJSON)
if err != nil {
return &GetMetricsResult{Err: err}
}
switch resp.Meta.Type {
case rbody.MetricsReturnedType:
mc := resp.Body.(*rbody.MetricsReturned)
r.Catalog = convertCatalog(mc)
case rbody.ErrorType:
r.Err = resp.Body.(*rbody.Error)
default:
r.Err = ErrAPIResponseMetaType
}
return r
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetMetricVersions",
"(",
"ns",
"string",
")",
"*",
"GetMetricsResult",
"{",
"r",
":=",
"&",
"GetMetricsResult",
"{",
"}",
"\n",
"q",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ns",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"do",
"(",
"\"",
"\"",
",",
"q",
",",
"ContentTypeJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"GetMetricsResult",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"switch",
"resp",
".",
"Meta",
".",
"Type",
"{",
"case",
"rbody",
".",
"MetricsReturnedType",
":",
"mc",
":=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"MetricsReturned",
")",
"\n",
"r",
".",
"Catalog",
"=",
"convertCatalog",
"(",
"mc",
")",
"\n",
"case",
"rbody",
".",
"ErrorType",
":",
"r",
".",
"Err",
"=",
"resp",
".",
"Body",
".",
"(",
"*",
"rbody",
".",
"Error",
")",
"\n",
"default",
":",
"r",
".",
"Err",
"=",
"ErrAPIResponseMetaType",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// GetMetricVersions retrieves all versions of a metric at a given namespace.
|
[
"GetMetricVersions",
"retrieves",
"all",
"versions",
"of",
"a",
"metric",
"at",
"a",
"given",
"namespace",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/metric.go#L81-L99
|
15,483 |
intelsdi-x/snap
|
pkg/stringutils/string.go
|
GetFirstChar
|
func GetFirstChar(s string) string {
firstChar := ""
for _, r := range s {
firstChar = fmt.Sprintf("%c", r)
break
}
return firstChar
}
|
go
|
func GetFirstChar(s string) string {
firstChar := ""
for _, r := range s {
firstChar = fmt.Sprintf("%c", r)
break
}
return firstChar
}
|
[
"func",
"GetFirstChar",
"(",
"s",
"string",
")",
"string",
"{",
"firstChar",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"firstChar",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"break",
"\n",
"}",
"\n",
"return",
"firstChar",
"\n",
"}"
] |
// GetFirstChar returns the first character from the input string.
|
[
"GetFirstChar",
"returns",
"the",
"first",
"character",
"from",
"the",
"input",
"string",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/stringutils/string.go#L25-L32
|
15,484 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
GobEncode
|
func (c *ConfigTree) GobEncode() ([]byte, error) {
//todo throw an error if not frozen
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if c.root == nil {
c.root = &node{}
// c.root.setKeys([]string{})
}
if err := encoder.Encode(c.root); err != nil {
return nil, err
}
return w.Bytes(), nil
}
|
go
|
func (c *ConfigTree) GobEncode() ([]byte, error) {
//todo throw an error if not frozen
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if c.root == nil {
c.root = &node{}
// c.root.setKeys([]string{})
}
if err := encoder.Encode(c.root); err != nil {
return nil, err
}
return w.Bytes(), nil
}
|
[
"func",
"(",
"c",
"*",
"ConfigTree",
")",
"GobEncode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"//todo throw an error if not frozen",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"encoder",
":=",
"gob",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"if",
"c",
".",
"root",
"==",
"nil",
"{",
"c",
".",
"root",
"=",
"&",
"node",
"{",
"}",
"\n",
"// c.root.setKeys([]string{})",
"}",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"c",
".",
"root",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"w",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GobEncode returns the encoded ConfigTree. Otherwise,
// an error is returned
|
[
"GobEncode",
"returns",
"the",
"encoded",
"ConfigTree",
".",
"Otherwise",
"an",
"error",
"is",
"returned"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L51-L63
|
15,485 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
GobDecode
|
func (c *ConfigTree) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
decoder := gob.NewDecoder(r)
if err := decoder.Decode(&c.root); err != nil {
return err
}
return nil
}
|
go
|
func (c *ConfigTree) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
decoder := gob.NewDecoder(r)
if err := decoder.Decode(&c.root); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"ConfigTree",
")",
"GobDecode",
"(",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"r",
":=",
"bytes",
".",
"NewBuffer",
"(",
"buf",
")",
"\n",
"decoder",
":=",
"gob",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"c",
".",
"root",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// GobDecode decodes the ConfigTree.
|
[
"GobDecode",
"decodes",
"the",
"ConfigTree",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L66-L73
|
15,486 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
MarshalJSON
|
func (c *ConfigTree) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Root *node `json:"root"`
}{
Root: c.root,
})
}
|
go
|
func (c *ConfigTree) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Root *node `json:"root"`
}{
Root: c.root,
})
}
|
[
"func",
"(",
"c",
"*",
"ConfigTree",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Root",
"*",
"node",
"`json:\"root\"`",
"\n",
"}",
"{",
"Root",
":",
"c",
".",
"root",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON marshals ConfigTree
|
[
"MarshalJSON",
"marshals",
"ConfigTree"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L76-L82
|
15,487 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
Add
|
func (c *ConfigTree) Add(ns []string, inNode Node) {
c.log(fmt.Sprintf("Adding %v at %s\n", inNode, ns))
if len(ns) == 0 {
c.log(fmt.Sprintln("ns is empty - returning with no change to tree"))
return
}
f, remain := ns[0], ns[1:]
c.log(fmt.Sprintf("first ns (%s) remain (%s)", f, remain))
if c.root == nil {
// Create node at root
c.root = new(node)
c.root.setKeys([]string{f})
c.log(fmt.Sprintf("Root now = %v\n", c.root.keys))
// If remain is empty then the inNode belongs at this root level
if len(remain) == 0 {
c.log(fmt.Sprintf("adding node at root level\n"))
c.root.Node = inNode
// And return since we are done
return
}
} else {
if f != c.root.keys[0] {
panic("Can't add a new root namespace")
}
}
c.root.add(remain, inNode)
}
|
go
|
func (c *ConfigTree) Add(ns []string, inNode Node) {
c.log(fmt.Sprintf("Adding %v at %s\n", inNode, ns))
if len(ns) == 0 {
c.log(fmt.Sprintln("ns is empty - returning with no change to tree"))
return
}
f, remain := ns[0], ns[1:]
c.log(fmt.Sprintf("first ns (%s) remain (%s)", f, remain))
if c.root == nil {
// Create node at root
c.root = new(node)
c.root.setKeys([]string{f})
c.log(fmt.Sprintf("Root now = %v\n", c.root.keys))
// If remain is empty then the inNode belongs at this root level
if len(remain) == 0 {
c.log(fmt.Sprintf("adding node at root level\n"))
c.root.Node = inNode
// And return since we are done
return
}
} else {
if f != c.root.keys[0] {
panic("Can't add a new root namespace")
}
}
c.root.add(remain, inNode)
}
|
[
"func",
"(",
"c",
"*",
"ConfigTree",
")",
"Add",
"(",
"ns",
"[",
"]",
"string",
",",
"inNode",
"Node",
")",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"inNode",
",",
"ns",
")",
")",
"\n",
"if",
"len",
"(",
"ns",
")",
"==",
"0",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintln",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"f",
",",
"remain",
":=",
"ns",
"[",
"0",
"]",
",",
"ns",
"[",
"1",
":",
"]",
"\n",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
",",
"remain",
")",
")",
"\n",
"if",
"c",
".",
"root",
"==",
"nil",
"{",
"// Create node at root",
"c",
".",
"root",
"=",
"new",
"(",
"node",
")",
"\n",
"c",
".",
"root",
".",
"setKeys",
"(",
"[",
"]",
"string",
"{",
"f",
"}",
")",
"\n\n",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"c",
".",
"root",
".",
"keys",
")",
")",
"\n\n",
"// If remain is empty then the inNode belongs at this root level",
"if",
"len",
"(",
"remain",
")",
"==",
"0",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"c",
".",
"root",
".",
"Node",
"=",
"inNode",
"\n",
"// And return since we are done",
"return",
"\n",
"}",
"\n\n",
"}",
"else",
"{",
"if",
"f",
"!=",
"c",
".",
"root",
".",
"keys",
"[",
"0",
"]",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"root",
".",
"add",
"(",
"remain",
",",
"inNode",
")",
"\n\n",
"}"
] |
// Add adds a new tree node
|
[
"Add",
"adds",
"a",
"new",
"tree",
"node"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L85-L115
|
15,488 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
Get
|
func (c *ConfigTree) Get(ns []string) Node {
c.log(fmt.Sprintf("Get on ns (%s)\n", ns))
retNodes := new([]Node)
// Return if no root exists (no tree without a root)
if c.root == nil {
c.log(fmt.Sprintln("ctree: no root - returning nil"))
return nil
}
if len(c.root.keys) == 0 {
//This will be the case when a plugin returns an empty configPolicyTree
return nil
}
rootKeyLength := len(c.root.keys)
if len(ns) < rootKeyLength {
c.log(fmt.Sprintln("ns less than root key length - returning nil"))
return nil
}
match, remain := ns[:rootKeyLength], ns[rootKeyLength:]
if bytes.Compare(nsToByteArray(match), c.root.keysBytes) != 0 {
c.log(fmt.Sprintf("no match versus root key (match:'%s' != root:'%s')\n", string(nsToByteArray(match)), string(c.root.keysBytes)))
return nil
}
c.log(fmt.Sprintf("Match root key (match:'%s' == root:'%s')\n", string(nsToByteArray(match)), string(c.root.keysBytes)))
if c.root.Node != nil {
c.log(fmt.Sprintf("adding root node (not nil) to nodes to merge (%v)\n", c.root.Node))
*retNodes = append(*retNodes, c.root.Node)
}
c.log(fmt.Sprintf("children to get from (%d)\n", len(c.root.nodes)))
for _, child := range c.root.nodes {
childNodes := child.get(remain)
*retNodes = append(*retNodes, *childNodes...)
}
if len(*retNodes) == 0 {
// There are no child nodes with configs so we return
return nil
}
c.log(fmt.Sprintf("nodes to merge count (%d)\n", len(*retNodes)))
// Call Node.Merge() sequentially on the retNodes
rn := (*retNodes)[0]
for _, n := range (*retNodes)[1:] {
rn = rn.Merge(n)
}
return rn
}
|
go
|
func (c *ConfigTree) Get(ns []string) Node {
c.log(fmt.Sprintf("Get on ns (%s)\n", ns))
retNodes := new([]Node)
// Return if no root exists (no tree without a root)
if c.root == nil {
c.log(fmt.Sprintln("ctree: no root - returning nil"))
return nil
}
if len(c.root.keys) == 0 {
//This will be the case when a plugin returns an empty configPolicyTree
return nil
}
rootKeyLength := len(c.root.keys)
if len(ns) < rootKeyLength {
c.log(fmt.Sprintln("ns less than root key length - returning nil"))
return nil
}
match, remain := ns[:rootKeyLength], ns[rootKeyLength:]
if bytes.Compare(nsToByteArray(match), c.root.keysBytes) != 0 {
c.log(fmt.Sprintf("no match versus root key (match:'%s' != root:'%s')\n", string(nsToByteArray(match)), string(c.root.keysBytes)))
return nil
}
c.log(fmt.Sprintf("Match root key (match:'%s' == root:'%s')\n", string(nsToByteArray(match)), string(c.root.keysBytes)))
if c.root.Node != nil {
c.log(fmt.Sprintf("adding root node (not nil) to nodes to merge (%v)\n", c.root.Node))
*retNodes = append(*retNodes, c.root.Node)
}
c.log(fmt.Sprintf("children to get from (%d)\n", len(c.root.nodes)))
for _, child := range c.root.nodes {
childNodes := child.get(remain)
*retNodes = append(*retNodes, *childNodes...)
}
if len(*retNodes) == 0 {
// There are no child nodes with configs so we return
return nil
}
c.log(fmt.Sprintf("nodes to merge count (%d)\n", len(*retNodes)))
// Call Node.Merge() sequentially on the retNodes
rn := (*retNodes)[0]
for _, n := range (*retNodes)[1:] {
rn = rn.Merge(n)
}
return rn
}
|
[
"func",
"(",
"c",
"*",
"ConfigTree",
")",
"Get",
"(",
"ns",
"[",
"]",
"string",
")",
"Node",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"ns",
")",
")",
"\n",
"retNodes",
":=",
"new",
"(",
"[",
"]",
"Node",
")",
"\n",
"// Return if no root exists (no tree without a root)",
"if",
"c",
".",
"root",
"==",
"nil",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintln",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"root",
".",
"keys",
")",
"==",
"0",
"{",
"//This will be the case when a plugin returns an empty configPolicyTree",
"return",
"nil",
"\n",
"}",
"\n\n",
"rootKeyLength",
":=",
"len",
"(",
"c",
".",
"root",
".",
"keys",
")",
"\n\n",
"if",
"len",
"(",
"ns",
")",
"<",
"rootKeyLength",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintln",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"match",
",",
"remain",
":=",
"ns",
"[",
":",
"rootKeyLength",
"]",
",",
"ns",
"[",
"rootKeyLength",
":",
"]",
"\n",
"if",
"bytes",
".",
"Compare",
"(",
"nsToByteArray",
"(",
"match",
")",
",",
"c",
".",
"root",
".",
"keysBytes",
")",
"!=",
"0",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"string",
"(",
"nsToByteArray",
"(",
"match",
")",
")",
",",
"string",
"(",
"c",
".",
"root",
".",
"keysBytes",
")",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"string",
"(",
"nsToByteArray",
"(",
"match",
")",
")",
",",
"string",
"(",
"c",
".",
"root",
".",
"keysBytes",
")",
")",
")",
"\n\n",
"if",
"c",
".",
"root",
".",
"Node",
"!=",
"nil",
"{",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"c",
".",
"root",
".",
"Node",
")",
")",
"\n",
"*",
"retNodes",
"=",
"append",
"(",
"*",
"retNodes",
",",
"c",
".",
"root",
".",
"Node",
")",
"\n",
"}",
"\n\n",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"len",
"(",
"c",
".",
"root",
".",
"nodes",
")",
")",
")",
"\n",
"for",
"_",
",",
"child",
":=",
"range",
"c",
".",
"root",
".",
"nodes",
"{",
"childNodes",
":=",
"child",
".",
"get",
"(",
"remain",
")",
"\n",
"*",
"retNodes",
"=",
"append",
"(",
"*",
"retNodes",
",",
"*",
"childNodes",
"...",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"*",
"retNodes",
")",
"==",
"0",
"{",
"// There are no child nodes with configs so we return",
"return",
"nil",
"\n",
"}",
"\n\n",
"c",
".",
"log",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"len",
"(",
"*",
"retNodes",
")",
")",
")",
"\n",
"// Call Node.Merge() sequentially on the retNodes",
"rn",
":=",
"(",
"*",
"retNodes",
")",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"(",
"*",
"retNodes",
")",
"[",
"1",
":",
"]",
"{",
"rn",
"=",
"rn",
".",
"Merge",
"(",
"n",
")",
"\n",
"}",
"\n",
"return",
"rn",
"\n",
"}"
] |
// Get returns a tree node given the namespace
|
[
"Get",
"returns",
"a",
"tree",
"node",
"given",
"the",
"namespace"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L153-L203
|
15,489 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
MarshalJSON
|
func (n *node) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Nodes []*node `json:"nodes"`
Keys []string `json:"keys"`
KeysBytes []byte `json:"keysbytes"`
Node Node `json:"node"`
}{
Nodes: n.nodes,
Keys: n.keys,
KeysBytes: n.keysBytes,
Node: n.Node,
})
}
|
go
|
func (n *node) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Nodes []*node `json:"nodes"`
Keys []string `json:"keys"`
KeysBytes []byte `json:"keysbytes"`
Node Node `json:"node"`
}{
Nodes: n.nodes,
Keys: n.keys,
KeysBytes: n.keysBytes,
Node: n.Node,
})
}
|
[
"func",
"(",
"n",
"*",
"node",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Nodes",
"[",
"]",
"*",
"node",
"`json:\"nodes\"`",
"\n",
"Keys",
"[",
"]",
"string",
"`json:\"keys\"`",
"\n",
"KeysBytes",
"[",
"]",
"byte",
"`json:\"keysbytes\"`",
"\n",
"Node",
"Node",
"`json:\"node\"`",
"\n",
"}",
"{",
"Nodes",
":",
"n",
".",
"nodes",
",",
"Keys",
":",
"n",
".",
"keys",
",",
"KeysBytes",
":",
"n",
".",
"keysBytes",
",",
"Node",
":",
"n",
".",
"Node",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON marshals the ConfigTree.
|
[
"MarshalJSON",
"marshals",
"the",
"ConfigTree",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L223-L235
|
15,490 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
GobEncode
|
func (n *node) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if err := encoder.Encode(n.nodes); err != nil {
return nil, err
}
if err := encoder.Encode(n.keys); err != nil {
return nil, err
}
if err := encoder.Encode(n.keysBytes); err != nil {
return nil, err
}
if err := encoder.Encode(&n.Node); err != nil {
return nil, err
}
return w.Bytes(), nil
}
|
go
|
func (n *node) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if err := encoder.Encode(n.nodes); err != nil {
return nil, err
}
if err := encoder.Encode(n.keys); err != nil {
return nil, err
}
if err := encoder.Encode(n.keysBytes); err != nil {
return nil, err
}
if err := encoder.Encode(&n.Node); err != nil {
return nil, err
}
return w.Bytes(), nil
}
|
[
"func",
"(",
"n",
"*",
"node",
")",
"GobEncode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"encoder",
":=",
"gob",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"n",
".",
"nodes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"n",
".",
"keys",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"n",
".",
"keysBytes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"&",
"n",
".",
"Node",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"w",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GobEncode encodes every member of node struct instance
|
[
"GobEncode",
"encodes",
"every",
"member",
"of",
"node",
"struct",
"instance"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L238-L254
|
15,491 |
intelsdi-x/snap
|
pkg/ctree/tree.go
|
GobDecode
|
func (n *node) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
decoder := gob.NewDecoder(r)
if err := decoder.Decode(&n.nodes); err != nil {
return err
}
if err := decoder.Decode(&n.keys); err != nil {
return err
}
if err := decoder.Decode(&n.keysBytes); err != nil {
return err
}
return decoder.Decode(&n.Node)
}
|
go
|
func (n *node) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
decoder := gob.NewDecoder(r)
if err := decoder.Decode(&n.nodes); err != nil {
return err
}
if err := decoder.Decode(&n.keys); err != nil {
return err
}
if err := decoder.Decode(&n.keysBytes); err != nil {
return err
}
return decoder.Decode(&n.Node)
}
|
[
"func",
"(",
"n",
"*",
"node",
")",
"GobDecode",
"(",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"r",
":=",
"bytes",
".",
"NewBuffer",
"(",
"buf",
")",
"\n",
"decoder",
":=",
"gob",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"n",
".",
"nodes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"n",
".",
"keys",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"n",
".",
"keysBytes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"decoder",
".",
"Decode",
"(",
"&",
"n",
".",
"Node",
")",
"\n",
"}"
] |
// GobDecode decodes every member of node struct instance
|
[
"GobDecode",
"decodes",
"every",
"member",
"of",
"node",
"struct",
"instance"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/pkg/ctree/tree.go#L257-L270
|
15,492 |
intelsdi-x/snap
|
control/plugin/cpolicy/float.go
|
MarshalJSON
|
func (f *FloatRule) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Key string `json:"key"`
Required bool `json:"required"`
Default ctypes.ConfigValue `json:"default,omitempty"`
Minimum ctypes.ConfigValue `json:"minimum,omitempty"`
Maximum ctypes.ConfigValue `json:"maximum,omitempty"`
Type string `json:"type"`
}{
Key: f.key,
Required: f.required,
Default: f.Default(),
Minimum: f.Minimum(),
Maximum: f.Maximum(),
Type: FloatType,
})
}
|
go
|
func (f *FloatRule) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Key string `json:"key"`
Required bool `json:"required"`
Default ctypes.ConfigValue `json:"default,omitempty"`
Minimum ctypes.ConfigValue `json:"minimum,omitempty"`
Maximum ctypes.ConfigValue `json:"maximum,omitempty"`
Type string `json:"type"`
}{
Key: f.key,
Required: f.required,
Default: f.Default(),
Minimum: f.Minimum(),
Maximum: f.Maximum(),
Type: FloatType,
})
}
|
[
"func",
"(",
"f",
"*",
"FloatRule",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Key",
"string",
"`json:\"key\"`",
"\n",
"Required",
"bool",
"`json:\"required\"`",
"\n",
"Default",
"ctypes",
".",
"ConfigValue",
"`json:\"default,omitempty\"`",
"\n",
"Minimum",
"ctypes",
".",
"ConfigValue",
"`json:\"minimum,omitempty\"`",
"\n",
"Maximum",
"ctypes",
".",
"ConfigValue",
"`json:\"maximum,omitempty\"`",
"\n",
"Type",
"string",
"`json:\"type\"`",
"\n",
"}",
"{",
"Key",
":",
"f",
".",
"key",
",",
"Required",
":",
"f",
".",
"required",
",",
"Default",
":",
"f",
".",
"Default",
"(",
")",
",",
"Minimum",
":",
"f",
".",
"Minimum",
"(",
")",
",",
"Maximum",
":",
"f",
".",
"Maximum",
"(",
")",
",",
"Type",
":",
"FloatType",
",",
"}",
")",
"\n",
"}"
] |
// MarshalJSON marshals a FloatRule into JSON
|
[
"MarshalJSON",
"marshals",
"a",
"FloatRule",
"into",
"JSON"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/plugin/cpolicy/float.go#L48-L64
|
15,493 |
intelsdi-x/snap
|
control/plugin/cpolicy/float.go
|
GobEncode
|
func (f *FloatRule) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if err := encoder.Encode(f.key); err != nil {
return nil, err
}
if err := encoder.Encode(f.required); err != nil {
return nil, err
}
if f.default_ == nil {
encoder.Encode(false)
} else {
encoder.Encode(true)
if err := encoder.Encode(&f.default_); err != nil {
return nil, err
}
}
if f.minimum == nil {
encoder.Encode(false)
} else {
encoder.Encode(true)
if err := encoder.Encode(f.minimum); err != nil {
return nil, err
}
}
if f.maximum == nil {
encoder.Encode(false)
} else {
encoder.Encode(true)
if err := encoder.Encode(f.maximum); err != nil {
return nil, err
}
}
return w.Bytes(), nil
}
|
go
|
func (f *FloatRule) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
if err := encoder.Encode(f.key); err != nil {
return nil, err
}
if err := encoder.Encode(f.required); err != nil {
return nil, err
}
if f.default_ == nil {
encoder.Encode(false)
} else {
encoder.Encode(true)
if err := encoder.Encode(&f.default_); err != nil {
return nil, err
}
}
if f.minimum == nil {
encoder.Encode(false)
} else {
encoder.Encode(true)
if err := encoder.Encode(f.minimum); err != nil {
return nil, err
}
}
if f.maximum == nil {
encoder.Encode(false)
} else {
encoder.Encode(true)
if err := encoder.Encode(f.maximum); err != nil {
return nil, err
}
}
return w.Bytes(), nil
}
|
[
"func",
"(",
"f",
"*",
"FloatRule",
")",
"GobEncode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"encoder",
":=",
"gob",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"f",
".",
"key",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"f",
".",
"required",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"f",
".",
"default_",
"==",
"nil",
"{",
"encoder",
".",
"Encode",
"(",
"false",
")",
"\n",
"}",
"else",
"{",
"encoder",
".",
"Encode",
"(",
"true",
")",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"&",
"f",
".",
"default_",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"f",
".",
"minimum",
"==",
"nil",
"{",
"encoder",
".",
"Encode",
"(",
"false",
")",
"\n",
"}",
"else",
"{",
"encoder",
".",
"Encode",
"(",
"true",
")",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"f",
".",
"minimum",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"f",
".",
"maximum",
"==",
"nil",
"{",
"encoder",
".",
"Encode",
"(",
"false",
")",
"\n",
"}",
"else",
"{",
"encoder",
".",
"Encode",
"(",
"true",
")",
"\n",
"if",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"f",
".",
"maximum",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"w",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GobEncode encodes a FloatRule into a GOB
|
[
"GobEncode",
"encodes",
"a",
"FloatRule",
"into",
"a",
"GOB"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/plugin/cpolicy/float.go#L71-L105
|
15,494 |
intelsdi-x/snap
|
control/plugin/cpolicy/float.go
|
Default
|
func (f *FloatRule) Default() ctypes.ConfigValue {
if f.default_ != nil {
return ctypes.ConfigValueFloat{Value: *f.default_}
}
return nil
}
|
go
|
func (f *FloatRule) Default() ctypes.ConfigValue {
if f.default_ != nil {
return ctypes.ConfigValueFloat{Value: *f.default_}
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"FloatRule",
")",
"Default",
"(",
")",
"ctypes",
".",
"ConfigValue",
"{",
"if",
"f",
".",
"default_",
"!=",
"nil",
"{",
"return",
"ctypes",
".",
"ConfigValueFloat",
"{",
"Value",
":",
"*",
"f",
".",
"default_",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Default returns the rule's default value
|
[
"Default",
"returns",
"the",
"rule",
"s",
"default",
"value"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/control/plugin/cpolicy/float.go#L180-L185
|
15,495 |
intelsdi-x/snap
|
mgmt/rest/client/client.go
|
parseURL
|
func parseURL(url string) error {
if !govalidator.IsURL(url) || !strings.HasPrefix(url, "http") {
return fmt.Errorf("URL %s is not in the format of http(s)://<ip>:<port>", url)
}
return nil
}
|
go
|
func parseURL(url string) error {
if !govalidator.IsURL(url) || !strings.HasPrefix(url, "http") {
return fmt.Errorf("URL %s is not in the format of http(s)://<ip>:<port>", url)
}
return nil
}
|
[
"func",
"parseURL",
"(",
"url",
"string",
")",
"error",
"{",
"if",
"!",
"govalidator",
".",
"IsURL",
"(",
"url",
")",
"||",
"!",
"strings",
".",
"HasPrefix",
"(",
"url",
",",
"\"",
"\"",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"url",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Checks validity of URL
|
[
"Checks",
"validity",
"of",
"URL"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/client.go#L85-L90
|
15,496 |
intelsdi-x/snap
|
mgmt/rest/client/client.go
|
Password
|
func Password(p string) metaOp {
return func(c *Client) {
c.Password = strings.TrimSpace(p)
}
}
|
go
|
func Password(p string) metaOp {
return func(c *Client) {
c.Password = strings.TrimSpace(p)
}
}
|
[
"func",
"Password",
"(",
"p",
"string",
")",
"metaOp",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"{",
"c",
".",
"Password",
"=",
"strings",
".",
"TrimSpace",
"(",
"p",
")",
"\n",
"}",
"\n",
"}"
] |
//Password is an option than can be provided to the func client.New.
|
[
"Password",
"is",
"an",
"option",
"than",
"can",
"be",
"provided",
"to",
"the",
"func",
"client",
".",
"New",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/client.go#L95-L99
|
15,497 |
intelsdi-x/snap
|
mgmt/rest/client/client.go
|
Timeout
|
func Timeout(t time.Duration) metaOp {
return func(c *Client) {
c.http.Timeout = t
}
}
|
go
|
func Timeout(t time.Duration) metaOp {
return func(c *Client) {
c.http.Timeout = t
}
}
|
[
"func",
"Timeout",
"(",
"t",
"time",
".",
"Duration",
")",
"metaOp",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"{",
"c",
".",
"http",
".",
"Timeout",
"=",
"t",
"\n",
"}",
"\n",
"}"
] |
//Timeout is an option that can be provided to the func client.New in order to set HTTP connection timeout.
|
[
"Timeout",
"is",
"an",
"option",
"that",
"can",
"be",
"provided",
"to",
"the",
"func",
"client",
".",
"New",
"in",
"order",
"to",
"set",
"HTTP",
"connection",
"timeout",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/client.go#L109-L113
|
15,498 |
intelsdi-x/snap
|
mgmt/rest/client/client.go
|
New
|
func New(url, ver string, insecure bool, opts ...metaOp) (*Client, error) {
if err := parseURL(url); err != nil {
return nil, err
}
if ver == "" {
ver = "v1"
}
var t *http.Transport
if insecure {
t = insecureTransport
} else {
t = secureTransport
}
c := &Client{
URL: url,
Version: ver,
http: &http.Client{
Transport: t,
},
}
for _, opt := range opts {
opt(c)
}
c.prefix = url + "/" + ver
return c, nil
}
|
go
|
func New(url, ver string, insecure bool, opts ...metaOp) (*Client, error) {
if err := parseURL(url); err != nil {
return nil, err
}
if ver == "" {
ver = "v1"
}
var t *http.Transport
if insecure {
t = insecureTransport
} else {
t = secureTransport
}
c := &Client{
URL: url,
Version: ver,
http: &http.Client{
Transport: t,
},
}
for _, opt := range opts {
opt(c)
}
c.prefix = url + "/" + ver
return c, nil
}
|
[
"func",
"New",
"(",
"url",
",",
"ver",
"string",
",",
"insecure",
"bool",
",",
"opts",
"...",
"metaOp",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"err",
":=",
"parseURL",
"(",
"url",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"ver",
"==",
"\"",
"\"",
"{",
"ver",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"var",
"t",
"*",
"http",
".",
"Transport",
"\n",
"if",
"insecure",
"{",
"t",
"=",
"insecureTransport",
"\n",
"}",
"else",
"{",
"t",
"=",
"secureTransport",
"\n",
"}",
"\n",
"c",
":=",
"&",
"Client",
"{",
"URL",
":",
"url",
",",
"Version",
":",
"ver",
",",
"http",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"t",
",",
"}",
",",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"c",
")",
"\n",
"}",
"\n",
"c",
".",
"prefix",
"=",
"url",
"+",
"\"",
"\"",
"+",
"ver",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// New returns a pointer to a snap api client
// if ver is an empty string, v1 is used by default
|
[
"New",
"returns",
"a",
"pointer",
"to",
"a",
"snap",
"api",
"client",
"if",
"ver",
"is",
"an",
"empty",
"string",
"v1",
"is",
"used",
"by",
"default"
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/client.go#L128-L154
|
15,499 |
intelsdi-x/snap
|
mgmt/rest/client/client.go
|
TribeRequest
|
func (c *Client) TribeRequest() (*http.Response, error) {
req, err := http.NewRequest("GET", c.URL, nil)
if err != nil {
return nil, err
}
addAuth(req, "snap", c.Password)
rsp, err := c.http.Do(req)
if err != nil {
return nil, err
}
return rsp, nil
}
|
go
|
func (c *Client) TribeRequest() (*http.Response, error) {
req, err := http.NewRequest("GET", c.URL, nil)
if err != nil {
return nil, err
}
addAuth(req, "snap", c.Password)
rsp, err := c.http.Do(req)
if err != nil {
return nil, err
}
return rsp, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"TribeRequest",
"(",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"c",
".",
"URL",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"addAuth",
"(",
"req",
",",
"\"",
"\"",
",",
"c",
".",
"Password",
")",
"\n",
"rsp",
",",
"err",
":=",
"c",
".",
"http",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
",",
"nil",
"\n",
"}"
] |
// Passthrough for tribe request to allow use of client auth.
|
[
"Passthrough",
"for",
"tribe",
"request",
"to",
"allow",
"use",
"of",
"client",
"auth",
"."
] |
e3a6c8e39994b3980df0c7b069d5ede810622952
|
https://github.com/intelsdi-x/snap/blob/e3a6c8e39994b3980df0c7b069d5ede810622952/mgmt/rest/client/client.go#L421-L432
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.