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
124,400
bnkamalesh/webgo
middleware/middleware.go
Cors
func Cors(allowedOrigins ...string) http.HandlerFunc { if len(allowedOrigins) == 0 { allowedOrigins = append(allowedOrigins, "*") } return func(rw http.ResponseWriter, req *http.Request) { allowed := false // Set appropriate response headers required for CORS reqOrigin := req.Header.Get(headerGetOrigin) fo...
go
func Cors(allowedOrigins ...string) http.HandlerFunc { if len(allowedOrigins) == 0 { allowedOrigins = append(allowedOrigins, "*") } return func(rw http.ResponseWriter, req *http.Request) { allowed := false // Set appropriate response headers required for CORS reqOrigin := req.Header.Get(headerGetOrigin) fo...
[ "func", "Cors", "(", "allowedOrigins", "...", "string", ")", "http", ".", "HandlerFunc", "{", "if", "len", "(", "allowedOrigins", ")", "==", "0", "{", "allowedOrigins", "=", "append", "(", "allowedOrigins", ",", "\"", "\"", ")", "\n", "}", "\n", "return"...
// Cors is a basic CORS middleware which can be added to individual handlers
[ "Cors", "is", "a", "basic", "CORS", "middleware", "which", "can", "be", "added", "to", "individual", "handlers" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/middleware/middleware.go#L58-L86
124,401
bnkamalesh/webgo
config.go
Load
func (cfg *Config) Load(filepath string) { file, err := ioutil.ReadFile(filepath) if err != nil { LOGHANDLER.Fatal(err) } err = json.Unmarshal(file, cfg) if err != nil { LOGHANDLER.Fatal(err) } err = cfg.Validate() if err != nil { LOGHANDLER.Fatal(ErrInvalidPort) } }
go
func (cfg *Config) Load(filepath string) { file, err := ioutil.ReadFile(filepath) if err != nil { LOGHANDLER.Fatal(err) } err = json.Unmarshal(file, cfg) if err != nil { LOGHANDLER.Fatal(err) } err = cfg.Validate() if err != nil { LOGHANDLER.Fatal(ErrInvalidPort) } }
[ "func", "(", "cfg", "*", "Config", ")", "Load", "(", "filepath", "string", ")", "{", "file", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filepath", ")", "\n", "if", "err", "!=", "nil", "{", "LOGHANDLER", ".", "Fatal", "(", "err", ")", "\n", ...
// Load config file from the provided filepath and validate
[ "Load", "config", "file", "from", "the", "provided", "filepath", "and", "validate" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/config.go#L37-L52
124,402
bnkamalesh/webgo
config.go
Validate
func (cfg *Config) Validate() error { i, err := strconv.Atoi(cfg.Port) if err != nil { return ErrInvalidPort } if i <= 0 || i > 65535 { return ErrInvalidPort } return nil }
go
func (cfg *Config) Validate() error { i, err := strconv.Atoi(cfg.Port) if err != nil { return ErrInvalidPort } if i <= 0 || i > 65535 { return ErrInvalidPort } return nil }
[ "func", "(", "cfg", "*", "Config", ")", "Validate", "(", ")", "error", "{", "i", ",", "err", ":=", "strconv", ".", "Atoi", "(", "cfg", ".", "Port", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ErrInvalidPort", "\n", "}", "\n\n", "if", "i"...
// Validate the config parsed into the Config struct
[ "Validate", "the", "config", "parsed", "into", "the", "Config", "struct" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/config.go#L55-L66
124,403
bnkamalesh/webgo
webgo.go
Context
func Context(r *http.Request) *WC { wc, _ := r.Context().Value(wgoCtxKey).(*WC) return wc }
go
func Context(r *http.Request) *WC { wc, _ := r.Context().Value(wgoCtxKey).(*WC) return wc }
[ "func", "Context", "(", "r", "*", "http", ".", "Request", ")", "*", "WC", "{", "wc", ",", "_", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "wgoCtxKey", ")", ".", "(", "*", "WC", ")", "\n", "return", "wc", "\n", "}" ]
// Context returns the WebgoContext injected inside the HTTP request context
[ "Context", "returns", "the", "WebgoContext", "injected", "inside", "the", "HTTP", "request", "context" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/webgo.go#L35-L38
124,404
bnkamalesh/webgo
webgo.go
StartHTTPS
func (router *Router) StartHTTPS() { cfg := router.config if cfg.CertFile == "" { LOGHANDLER.Fatal("No certificate provided for HTTPS") } if cfg.KeyFile == "" { LOGHANDLER.Fatal("No key file provided for HTTPS") } host := cfg.Host if len(cfg.HTTPSPort) > 0 { host += ":" + cfg.HTTPSPort } router.httpsS...
go
func (router *Router) StartHTTPS() { cfg := router.config if cfg.CertFile == "" { LOGHANDLER.Fatal("No certificate provided for HTTPS") } if cfg.KeyFile == "" { LOGHANDLER.Fatal("No key file provided for HTTPS") } host := cfg.Host if len(cfg.HTTPSPort) > 0 { host += ":" + cfg.HTTPSPort } router.httpsS...
[ "func", "(", "router", "*", "Router", ")", "StartHTTPS", "(", ")", "{", "cfg", ":=", "router", ".", "config", "\n", "if", "cfg", ".", "CertFile", "==", "\"", "\"", "{", "LOGHANDLER", ".", "Fatal", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "c...
// StartHTTPS starts the server with HTTPS enabled
[ "StartHTTPS", "starts", "the", "server", "with", "HTTPS", "enabled" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/webgo.go#L41-L71
124,405
bnkamalesh/webgo
webgo.go
Start
func (router *Router) Start() { cfg := router.config host := cfg.Host if len(cfg.Port) > 0 { host += ":" + cfg.Port } router.httpServer = &http.Server{ Addr: host, Handler: router, ReadTimeout: cfg.ReadTimeout, WriteTimeout: cfg.WriteTimeout, } LOGHANDLER.Info("HTTP server, listening on...
go
func (router *Router) Start() { cfg := router.config host := cfg.Host if len(cfg.Port) > 0 { host += ":" + cfg.Port } router.httpServer = &http.Server{ Addr: host, Handler: router, ReadTimeout: cfg.ReadTimeout, WriteTimeout: cfg.WriteTimeout, } LOGHANDLER.Info("HTTP server, listening on...
[ "func", "(", "router", "*", "Router", ")", "Start", "(", ")", "{", "cfg", ":=", "router", ".", "config", "\n", "host", ":=", "cfg", ".", "Host", "\n\n", "if", "len", "(", "cfg", ".", "Port", ")", ">", "0", "{", "host", "+=", "\"", "\"", "+", ...
// Start starts the HTTP server with the appropriate configurations
[ "Start", "starts", "the", "HTTP", "server", "with", "the", "appropriate", "configurations" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/webgo.go#L74-L93
124,406
bnkamalesh/webgo
webgo.go
Shutdown
func (router *Router) Shutdown() error { if router.httpServer == nil { return nil } timer := router.config.ShutdownTimeout ctx, cancel := context.WithTimeout(context.Background(), timer) defer cancel() err := router.httpServer.Shutdown(ctx) if err != nil { LOGHANDLER.Error(err) } return err }
go
func (router *Router) Shutdown() error { if router.httpServer == nil { return nil } timer := router.config.ShutdownTimeout ctx, cancel := context.WithTimeout(context.Background(), timer) defer cancel() err := router.httpServer.Shutdown(ctx) if err != nil { LOGHANDLER.Error(err) } return err }
[ "func", "(", "router", "*", "Router", ")", "Shutdown", "(", ")", "error", "{", "if", "router", ".", "httpServer", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "timer", ":=", "router", ".", "config", ".", "ShutdownTimeout", "\n\n", "ctx", ",", ...
// Shutdown gracefully shuts down HTTP server
[ "Shutdown", "gracefully", "shuts", "down", "HTTP", "server" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/webgo.go#L96-L110
124,407
bnkamalesh/webgo
webgo.go
ShutdownHTTPS
func (router *Router) ShutdownHTTPS() error { if router.httpsServer == nil { return nil } timer := router.config.ShutdownTimeout ctx, cancel := context.WithTimeout(context.Background(), timer) defer cancel() err := router.httpsServer.Shutdown(ctx) if err != nil && err != http.ErrServerClosed { LOGHANDLER.E...
go
func (router *Router) ShutdownHTTPS() error { if router.httpsServer == nil { return nil } timer := router.config.ShutdownTimeout ctx, cancel := context.WithTimeout(context.Background(), timer) defer cancel() err := router.httpsServer.Shutdown(ctx) if err != nil && err != http.ErrServerClosed { LOGHANDLER.E...
[ "func", "(", "router", "*", "Router", ")", "ShutdownHTTPS", "(", ")", "error", "{", "if", "router", ".", "httpsServer", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "timer", ":=", "router", ".", "config", ".", "ShutdownTimeout", "\n\n", "ctx", "...
// ShutdownHTTPS gracefully shuts down HTTPS server
[ "ShutdownHTTPS", "gracefully", "shuts", "down", "HTTPS", "server" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/webgo.go#L113-L127
124,408
bnkamalesh/webgo
router.go
WriteHeader
func (crw *customResponseWriter) WriteHeader(code int) { if crw.written { LOGHANDLER.Warn(errMultiHeaderWrite) return } crw.statusCode = code crw.ResponseWriter.WriteHeader(code) }
go
func (crw *customResponseWriter) WriteHeader(code int) { if crw.written { LOGHANDLER.Warn(errMultiHeaderWrite) return } crw.statusCode = code crw.ResponseWriter.WriteHeader(code) }
[ "func", "(", "crw", "*", "customResponseWriter", ")", "WriteHeader", "(", "code", "int", ")", "{", "if", "crw", ".", "written", "{", "LOGHANDLER", ".", "Warn", "(", "errMultiHeaderWrite", ")", "\n", "return", "\n", "}", "\n\n", "crw", ".", "statusCode", ...
// WriteHeader is the interface implementation to get HTTP response code and add // it to the custom response writer
[ "WriteHeader", "is", "the", "interface", "implementation", "to", "get", "HTTP", "response", "code", "and", "add", "it", "to", "the", "custom", "response", "writer" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L45-L53
124,409
bnkamalesh/webgo
router.go
Write
func (crw *customResponseWriter) Write(body []byte) (int, error) { if crw.written { LOGHANDLER.Warn(errMultiWrite) return 0, nil } crw.written = true return crw.ResponseWriter.Write(body) }
go
func (crw *customResponseWriter) Write(body []byte) (int, error) { if crw.written { LOGHANDLER.Warn(errMultiWrite) return 0, nil } crw.written = true return crw.ResponseWriter.Write(body) }
[ "func", "(", "crw", "*", "customResponseWriter", ")", "Write", "(", "body", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "crw", ".", "written", "{", "LOGHANDLER", ".", "Warn", "(", "errMultiWrite", ")", "\n", "return", "0", ",", ...
// Write is the interface implementation to respond to the HTTP request, // but check if a response was already sent.
[ "Write", "is", "the", "interface", "implementation", "to", "respond", "to", "the", "HTTP", "request", "but", "check", "if", "a", "response", "was", "already", "sent", "." ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L57-L65
124,410
bnkamalesh/webgo
router.go
computePatternStr
func (r *Route) computePatternStr(patternString string, hasWildcard bool, key string) (string, error) { regexPattern := "" patternKey := "" if hasWildcard { patternKey = fmt.Sprintf(":%s*", key) regexPattern = urlwildcard } else { patternKey = fmt.Sprintf(":%s", key) regexPattern = urlchars } patternStri...
go
func (r *Route) computePatternStr(patternString string, hasWildcard bool, key string) (string, error) { regexPattern := "" patternKey := "" if hasWildcard { patternKey = fmt.Sprintf(":%s*", key) regexPattern = urlwildcard } else { patternKey = fmt.Sprintf(":%s", key) regexPattern = urlchars } patternStri...
[ "func", "(", "r", "*", "Route", ")", "computePatternStr", "(", "patternString", "string", ",", "hasWildcard", "bool", ",", "key", "string", ")", "(", "string", ",", "error", ")", "{", "regexPattern", ":=", "\"", "\"", "\n", "patternKey", ":=", "\"", "\""...
// computePatternStr computes the pattern string required for generating the route's regex. // It also adds the URI parameter key to the route's `keys` field
[ "computePatternStr", "computes", "the", "pattern", "string", "required", "for", "generating", "the", "route", "s", "regex", ".", "It", "also", "adds", "the", "URI", "parameter", "key", "to", "the", "route", "s", "keys", "field" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L96-L125
124,411
bnkamalesh/webgo
router.go
init
func (r *Route) init() error { patternString := r.Pattern var err error if strings.Contains(r.Pattern, ":") { // uriValues is a map of URI Key and it's respective value, // this is calculated per request key := "" hasKey := false hasWildcard := false for i := 0; i < len(r.Pattern); i++ { char := stri...
go
func (r *Route) init() error { patternString := r.Pattern var err error if strings.Contains(r.Pattern, ":") { // uriValues is a map of URI Key and it's respective value, // this is calculated per request key := "" hasKey := false hasWildcard := false for i := 0; i < len(r.Pattern); i++ { char := stri...
[ "func", "(", "r", "*", "Route", ")", "init", "(", ")", "error", "{", "patternString", ":=", "r", ".", "Pattern", "\n", "var", "err", "error", "\n", "if", "strings", ".", "Contains", "(", "r", ".", "Pattern", ",", "\"", "\"", ")", "{", "// uriValues...
// init prepares the URIKeys, compile regex for the provided pattern
[ "init", "prepares", "the", "URIKeys", "compile", "regex", "for", "the", "provided", "pattern" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L128-L180
124,412
bnkamalesh/webgo
router.go
matchAndGet
func (r *Route) matchAndGet(requestURI string) (bool, map[string]string) { if r.Pattern == requestURI { return true, nil } if !r.uriPattern.Match([]byte(requestURI)) { return false, nil } // Getting URI parameters values := r.uriPattern.FindStringSubmatch(requestURI) if len(values) == 0 { return true, ni...
go
func (r *Route) matchAndGet(requestURI string) (bool, map[string]string) { if r.Pattern == requestURI { return true, nil } if !r.uriPattern.Match([]byte(requestURI)) { return false, nil } // Getting URI parameters values := r.uriPattern.FindStringSubmatch(requestURI) if len(values) == 0 { return true, ni...
[ "func", "(", "r", "*", "Route", ")", "matchAndGet", "(", "requestURI", "string", ")", "(", "bool", ",", "map", "[", "string", "]", "string", ")", "{", "if", "r", ".", "Pattern", "==", "requestURI", "{", "return", "true", ",", "nil", "\n", "}", "\n\...
// matchAndGet returns if the request URI matches the pattern defined in a Route as well as // all the URI parameters configured for the route.
[ "matchAndGet", "returns", "if", "the", "request", "URI", "matches", "the", "pattern", "defined", "in", "a", "Route", "as", "well", "as", "all", "the", "URI", "parameters", "configured", "for", "the", "route", "." ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L184-L205
124,413
bnkamalesh/webgo
router.go
ServeHTTP
func (rtr *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rtr.serveHandler(rw, req) }
go
func (rtr *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rtr.serveHandler(rw, req) }
[ "func", "(", "rtr", "*", "Router", ")", "ServeHTTP", "(", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "rtr", ".", "serveHandler", "(", "rw", ",", "req", ")", "\n", "}" ]
// ServeHTTP is the required `ServeHTTP` implementation to listen to HTTP requests
[ "ServeHTTP", "is", "the", "required", "ServeHTTP", "implementation", "to", "listen", "to", "HTTP", "requests" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L303-L305
124,414
bnkamalesh/webgo
router.go
Use
func (rtr *Router) Use(f func(http.ResponseWriter, *http.Request, http.HandlerFunc)) { srv := rtr.serveHandler rtr.serveHandler = func(rw http.ResponseWriter, req *http.Request) { f(rw, req, srv) } }
go
func (rtr *Router) Use(f func(http.ResponseWriter, *http.Request, http.HandlerFunc)) { srv := rtr.serveHandler rtr.serveHandler = func(rw http.ResponseWriter, req *http.Request) { f(rw, req, srv) } }
[ "func", "(", "rtr", "*", "Router", ")", "Use", "(", "f", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ",", "http", ".", "HandlerFunc", ")", ")", "{", "srv", ":=", "rtr", ".", "serveHandler", "\n", "rtr", ".", "serve...
// Use adds a middleware layer
[ "Use", "adds", "a", "middleware", "layer" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L308-L313
124,415
bnkamalesh/webgo
router.go
NewRouter
func NewRouter(cfg *Config, routes []*Route) *Router { handlers := httpHandlers(routes) r := &Router{ optHandlers: handlers[http.MethodOptions], headHandlers: handlers[http.MethodHead], getHandlers: handlers[http.MethodGet], postHandlers: handlers[http.MethodPost], putHandlers: handlers[http.Me...
go
func NewRouter(cfg *Config, routes []*Route) *Router { handlers := httpHandlers(routes) r := &Router{ optHandlers: handlers[http.MethodOptions], headHandlers: handlers[http.MethodHead], getHandlers: handlers[http.MethodGet], postHandlers: handlers[http.MethodPost], putHandlers: handlers[http.Me...
[ "func", "NewRouter", "(", "cfg", "*", "Config", ",", "routes", "[", "]", "*", "Route", ")", "*", "Router", "{", "handlers", ":=", "httpHandlers", "(", "routes", ")", "\n", "r", ":=", "&", "Router", "{", "optHandlers", ":", "handlers", "[", "http", "....
// NewRouter initializes returns a new router instance with all the configurations and routes set
[ "NewRouter", "initializes", "returns", "a", "new", "router", "instance", "with", "all", "the", "configurations", "and", "routes", "set" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L316-L336
124,416
bnkamalesh/webgo
router.go
checkDuplicateRoutes
func checkDuplicateRoutes(idx int, route *Route, routes []*Route) { // checking if the URI pattern is duplicated for i := 0; i < idx; i++ { rt := routes[i] if rt.Name == route.Name { LOGHANDLER.Warn("Duplicate route name(\"" + rt.Name + "\") detected. Route name should be unique.") } if rt.Method == rout...
go
func checkDuplicateRoutes(idx int, route *Route, routes []*Route) { // checking if the URI pattern is duplicated for i := 0; i < idx; i++ { rt := routes[i] if rt.Name == route.Name { LOGHANDLER.Warn("Duplicate route name(\"" + rt.Name + "\") detected. Route name should be unique.") } if rt.Method == rout...
[ "func", "checkDuplicateRoutes", "(", "idx", "int", ",", "route", "*", "Route", ",", "routes", "[", "]", "*", "Route", ")", "{", "// checking if the URI pattern is duplicated", "for", "i", ":=", "0", ";", "i", "<", "idx", ";", "i", "++", "{", "rt", ":=", ...
// checkDuplicateRoutes checks if any of the routes have duplicate name or URI pattern
[ "checkDuplicateRoutes", "checks", "if", "any", "of", "the", "routes", "have", "duplicate", "name", "or", "URI", "pattern" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L339-L356
124,417
bnkamalesh/webgo
router.go
httpHandlers
func httpHandlers(routes []*Route) map[string][]*Route { handlers := make(map[string][]*Route, len(validHTTPMethods)) for _, validMethod := range validHTTPMethods { handlers[validMethod] = []*Route{} } for idx, route := range routes { found := false for _, validMethod := range validHTTPMethods { if route...
go
func httpHandlers(routes []*Route) map[string][]*Route { handlers := make(map[string][]*Route, len(validHTTPMethods)) for _, validMethod := range validHTTPMethods { handlers[validMethod] = []*Route{} } for idx, route := range routes { found := false for _, validMethod := range validHTTPMethods { if route...
[ "func", "httpHandlers", "(", "routes", "[", "]", "*", "Route", ")", "map", "[", "string", "]", "[", "]", "*", "Route", "{", "handlers", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "*", "Route", ",", "len", "(", "validHTTPMethods", ")", ...
// httpHandlers returns all the handlers in a map, for each HTTP method
[ "httpHandlers", "returns", "all", "the", "handlers", "in", "a", "map", "for", "each", "HTTP", "method" ]
e239f16b08195410eee3adc9136b297e2726005b
https://github.com/bnkamalesh/webgo/blob/e239f16b08195410eee3adc9136b297e2726005b/router.go#L359-L397
124,418
bradleyjkemp/cupaloy
util.go
takeSnapshot
func takeSnapshot(i ...interface{}) string { snapshot := &bytes.Buffer{} for _, v := range i { switch vt := v.(type) { case string: snapshot.WriteString(vt) snapshot.WriteString("\n") case []byte: snapshot.Write(vt) snapshot.WriteString("\n") default: spewConfig.Fdump(snapshot, v) } } retu...
go
func takeSnapshot(i ...interface{}) string { snapshot := &bytes.Buffer{} for _, v := range i { switch vt := v.(type) { case string: snapshot.WriteString(vt) snapshot.WriteString("\n") case []byte: snapshot.Write(vt) snapshot.WriteString("\n") default: spewConfig.Fdump(snapshot, v) } } retu...
[ "func", "takeSnapshot", "(", "i", "...", "interface", "{", "}", ")", "string", "{", "snapshot", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "for", "_", ",", "v", ":=", "range", "i", "{", "switch", "vt", ":=", "v", ".", "(", "type", ")", ...
// New snapshot format where some types are written out raw to the file
[ "New", "snapshot", "format", "where", "some", "types", "are", "written", "out", "raw", "to", "the", "file" ]
2f274078d7deac5c43fde81e2b11f982226fbd1b
https://github.com/bradleyjkemp/cupaloy/blob/2f274078d7deac5c43fde81e2b11f982226fbd1b/util.go#L60-L76
124,419
bradleyjkemp/cupaloy
cupaloy.go
SnapshotMulti
func SnapshotMulti(snapshotID string, i ...interface{}) error { snapshotName := fmt.Sprintf("%s-%s", getNameOfCaller(), snapshotID) return Global.snapshot(snapshotName, i...) }
go
func SnapshotMulti(snapshotID string, i ...interface{}) error { snapshotName := fmt.Sprintf("%s-%s", getNameOfCaller(), snapshotID) return Global.snapshot(snapshotName, i...) }
[ "func", "SnapshotMulti", "(", "snapshotID", "string", ",", "i", "...", "interface", "{", "}", ")", "error", "{", "snapshotName", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "getNameOfCaller", "(", ")", ",", "snapshotID", ")", "\n", "return", "Glob...
// SnapshotMulti calls Snapshotter.SnapshotMulti with the global config.
[ "SnapshotMulti", "calls", "Snapshotter", ".", "SnapshotMulti", "with", "the", "global", "config", "." ]
2f274078d7deac5c43fde81e2b11f982226fbd1b
https://github.com/bradleyjkemp/cupaloy/blob/2f274078d7deac5c43fde81e2b11f982226fbd1b/cupaloy.go#L23-L26
124,420
bradleyjkemp/cupaloy
cupaloy.go
SnapshotT
func SnapshotT(t TestingT, i ...interface{}) { t.Helper() Global.SnapshotT(t, i...) }
go
func SnapshotT(t TestingT, i ...interface{}) { t.Helper() Global.SnapshotT(t, i...) }
[ "func", "SnapshotT", "(", "t", "TestingT", ",", "i", "...", "interface", "{", "}", ")", "{", "t", ".", "Helper", "(", ")", "\n", "Global", ".", "SnapshotT", "(", "t", ",", "i", "...", ")", "\n", "}" ]
// SnapshotT calls Snapshotter.SnapshotT with the global config.
[ "SnapshotT", "calls", "Snapshotter", ".", "SnapshotT", "with", "the", "global", "config", "." ]
2f274078d7deac5c43fde81e2b11f982226fbd1b
https://github.com/bradleyjkemp/cupaloy/blob/2f274078d7deac5c43fde81e2b11f982226fbd1b/cupaloy.go#L29-L32
124,421
bradleyjkemp/cupaloy
cupaloy.go
SnapshotMulti
func (c *Config) SnapshotMulti(snapshotID string, i ...interface{}) error { snapshotName := fmt.Sprintf("%s-%s", getNameOfCaller(), snapshotID) return c.snapshot(snapshotName, i...) }
go
func (c *Config) SnapshotMulti(snapshotID string, i ...interface{}) error { snapshotName := fmt.Sprintf("%s-%s", getNameOfCaller(), snapshotID) return c.snapshot(snapshotName, i...) }
[ "func", "(", "c", "*", "Config", ")", "SnapshotMulti", "(", "snapshotID", "string", ",", "i", "...", "interface", "{", "}", ")", "error", "{", "snapshotName", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "getNameOfCaller", "(", ")", ",", "snapsho...
// SnapshotMulti is similar to Snapshot but can be called multiple times from the // same function. This is possible by providing a unique id for each snapshot which is // appended to the function name to form the snapshot name.
[ "SnapshotMulti", "is", "similar", "to", "Snapshot", "but", "can", "be", "called", "multiple", "times", "from", "the", "same", "function", ".", "This", "is", "possible", "by", "providing", "a", "unique", "id", "for", "each", "snapshot", "which", "is", "append...
2f274078d7deac5c43fde81e2b11f982226fbd1b
https://github.com/bradleyjkemp/cupaloy/blob/2f274078d7deac5c43fde81e2b11f982226fbd1b/cupaloy.go#L52-L55
124,422
coreos/fleet
functional/util/util.go
TempUnit
func TempUnit(contents string) (string, error) { tmp, err := ioutil.TempFile(os.TempDir(), "fleet-test-unit-") if err != nil { return "", err } tmp.Write([]byte(contents)) tmp.Close() svc := fmt.Sprintf("%s.service", tmp.Name()) err = os.Rename(tmp.Name(), svc) if err != nil { os.Remove(tmp.Name()) retu...
go
func TempUnit(contents string) (string, error) { tmp, err := ioutil.TempFile(os.TempDir(), "fleet-test-unit-") if err != nil { return "", err } tmp.Write([]byte(contents)) tmp.Close() svc := fmt.Sprintf("%s.service", tmp.Name()) err = os.Rename(tmp.Name(), svc) if err != nil { os.Remove(tmp.Name()) retu...
[ "func", "TempUnit", "(", "contents", "string", ")", "(", "string", ",", "error", ")", "{", "tmp", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "os", ".", "TempDir", "(", ")", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return...
// tempUnit creates a local unit file with the given contents, returning // the name of the file
[ "tempUnit", "creates", "a", "local", "unit", "file", "with", "the", "given", "contents", "returning", "the", "name", "of", "the", "file" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/functional/util/util.go#L140-L157
124,423
coreos/fleet
server/server.go
Supervise
func (s *Server) Supervise() { sd, err := s.mon.Monitor(s.hrt, s.killc) if sd { log.Infof("Server monitor triggered: told to shut down") } else { log.Errorf("Server monitor triggered: %v", err) } close(s.stopc) done := make(chan struct{}) go func() { s.wg.Wait() close(done) }() select { case <-done: ...
go
func (s *Server) Supervise() { sd, err := s.mon.Monitor(s.hrt, s.killc) if sd { log.Infof("Server monitor triggered: told to shut down") } else { log.Errorf("Server monitor triggered: %v", err) } close(s.stopc) done := make(chan struct{}) go func() { s.wg.Wait() close(done) }() select { case <-done: ...
[ "func", "(", "s", "*", "Server", ")", "Supervise", "(", ")", "{", "sd", ",", "err", ":=", "s", ".", "mon", ".", "Monitor", "(", "s", ".", "hrt", ",", "s", ".", "killc", ")", "\n", "if", "sd", "{", "log", ".", "Infof", "(", "\"", "\"", ")", ...
// Supervise monitors the life of the Server and coordinates its shutdown. // A shutdown occurs when the monitor returns, either because a health check // fails or a user triggers a shutdown. If the shutdown is due to a health // check failure, the Server is restarted. Supervise will block shutdown until // all compone...
[ "Supervise", "monitors", "the", "life", "of", "the", "Server", "and", "coordinates", "its", "shutdown", ".", "A", "shutdown", "occurs", "when", "the", "monitor", "returns", "either", "because", "a", "health", "check", "fails", "or", "a", "user", "triggers", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/server/server.go#L263-L288
124,424
coreos/fleet
agent/task.go
Do
func (tm *taskManager) Do(tasks []task, a *Agent) []taskResult { results := make([]taskResult, 0, len(tasks)) for _, t := range tasks { taskFunc, err := tm.mapper(t, a) if err == nil { err = taskFunc() } results = append(results, taskResult{task: t, err: err}) if err != nil { break } } return r...
go
func (tm *taskManager) Do(tasks []task, a *Agent) []taskResult { results := make([]taskResult, 0, len(tasks)) for _, t := range tasks { taskFunc, err := tm.mapper(t, a) if err == nil { err = taskFunc() } results = append(results, taskResult{task: t, err: err}) if err != nil { break } } return r...
[ "func", "(", "tm", "*", "taskManager", ")", "Do", "(", "tasks", "[", "]", "task", ",", "a", "*", "Agent", ")", "[", "]", "taskResult", "{", "results", ":=", "make", "(", "[", "]", "taskResult", ",", "0", ",", "len", "(", "tasks", ")", ")", "\n"...
// Do attempts to complete a series of tasks against an Agent. Each task // is executed in order. If any task is unable to be attempted, or is able // to be attempted but fails, Do will halt execution. The returned slice // will contain a taskResult for every task that was attempted. Do is not // threadsafe.
[ "Do", "attempts", "to", "complete", "a", "series", "of", "tasks", "against", "an", "Agent", ".", "Each", "task", "is", "executed", "in", "order", ".", "If", "any", "task", "is", "unable", "to", "be", "attempted", "or", "is", "able", "to", "be", "attemp...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/task.go#L82-L98
124,425
coreos/fleet
api/units.go
ValidateOptions
func ValidateOptions(opts []*schema.UnitOption) error { uf := schema.MapSchemaUnitOptionsToUnitFile(opts) // Sanity check using go-systemd's deserializer, which will do things // like check for excessive line lengths _, err := gsunit.Deserialize(gsunit.Serialize(uf.Options)) if err != nil { return err } j := ...
go
func ValidateOptions(opts []*schema.UnitOption) error { uf := schema.MapSchemaUnitOptionsToUnitFile(opts) // Sanity check using go-systemd's deserializer, which will do things // like check for excessive line lengths _, err := gsunit.Deserialize(gsunit.Serialize(uf.Options)) if err != nil { return err } j := ...
[ "func", "ValidateOptions", "(", "opts", "[", "]", "*", "schema", ".", "UnitOption", ")", "error", "{", "uf", ":=", "schema", ".", "MapSchemaUnitOptionsToUnitFile", "(", "opts", ")", "\n", "// Sanity check using go-systemd's deserializer, which will do things", "// like ...
// ValidateOptions ensures that a set of UnitOptions is valid; if not, an error // is returned detailing the issue encountered. If there are several problems // with a set of options, only the first is returned.
[ "ValidateOptions", "ensures", "that", "a", "set", "of", "UnitOptions", "is", "valid", ";", "if", "not", "an", "error", "is", "returned", "detailing", "the", "issue", "encountered", ".", "If", "there", "are", "several", "problems", "with", "a", "set", "of", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/api/units.go#L225-L281
124,426
coreos/fleet
functional/platform/nspawn.go
WaitForNUnits
func (nc *nspawnCluster) WaitForNUnits(m Member, expectedUnits int) (map[string][]util.UnitState, error) { var nUnits int retStates := make(map[string][]util.UnitState) checkListUnits := func() bool { outListUnits, _, err := nc.Fleetctl(m, "list-units", "--no-legend", "--full", "--fields", "unit,active,machine") ...
go
func (nc *nspawnCluster) WaitForNUnits(m Member, expectedUnits int) (map[string][]util.UnitState, error) { var nUnits int retStates := make(map[string][]util.UnitState) checkListUnits := func() bool { outListUnits, _, err := nc.Fleetctl(m, "list-units", "--no-legend", "--full", "--fields", "unit,active,machine") ...
[ "func", "(", "nc", "*", "nspawnCluster", ")", "WaitForNUnits", "(", "m", "Member", ",", "expectedUnits", "int", ")", "(", "map", "[", "string", "]", "[", "]", "util", ".", "UnitState", ",", "error", ")", "{", "var", "nUnits", "int", "\n", "retStates", ...
// WaitForNUnits runs fleetctl list-units to verify the actual number of units // matched with the given expected number. It periodically runs list-units // waiting until list-units actually shows the expected units.
[ "WaitForNUnits", "runs", "fleetctl", "list", "-", "units", "to", "verify", "the", "actual", "number", "of", "units", "matched", "with", "the", "given", "expected", "number", ".", "It", "periodically", "runs", "list", "-", "units", "waiting", "until", "list", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/functional/platform/nspawn.go#L146-L182
124,427
coreos/fleet
functional/platform/nspawn.go
WaitForNUnitFiles
func (nc *nspawnCluster) WaitForNUnitFiles(m Member, expectedUnits int) (map[string][]util.UnitFileState, error) { var nUnits int retStates := make(map[string][]util.UnitFileState) checkListUnitFiles := func() bool { outListUnitFiles, _, err := nc.Fleetctl(m, "list-unit-files", "--no-legend", "--full", "--fields"...
go
func (nc *nspawnCluster) WaitForNUnitFiles(m Member, expectedUnits int) (map[string][]util.UnitFileState, error) { var nUnits int retStates := make(map[string][]util.UnitFileState) checkListUnitFiles := func() bool { outListUnitFiles, _, err := nc.Fleetctl(m, "list-unit-files", "--no-legend", "--full", "--fields"...
[ "func", "(", "nc", "*", "nspawnCluster", ")", "WaitForNUnitFiles", "(", "m", "Member", ",", "expectedUnits", "int", ")", "(", "map", "[", "string", "]", "[", "]", "util", ".", "UnitFileState", ",", "error", ")", "{", "var", "nUnits", "int", "\n", "retS...
// WaitForNUnitFiles runs fleetctl list-unit-files to verify the actual number of units // matched with the given expected number. It periodically runs list-unit-files // waiting until list-unit-files actually shows the expected units.
[ "WaitForNUnitFiles", "runs", "fleetctl", "list", "-", "unit", "-", "files", "to", "verify", "the", "actual", "number", "of", "units", "matched", "with", "the", "given", "expected", "number", ".", "It", "periodically", "runs", "list", "-", "unit", "-", "files...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/functional/platform/nspawn.go#L224-L262
124,428
coreos/fleet
functional/platform/nspawn.go
machinePID
func (nc *nspawnCluster) machinePID(name string) (int, error) { for i := 0; i < 100; i++ { mach := fmt.Sprintf("%s%s", nc.name, name) stdout, stderr, err := run(fmt.Sprintf("machinectl show -p Leader %s", mach)) if err != nil { if i != -1 { time.Sleep(100 * time.Millisecond) continue } return -1...
go
func (nc *nspawnCluster) machinePID(name string) (int, error) { for i := 0; i < 100; i++ { mach := fmt.Sprintf("%s%s", nc.name, name) stdout, stderr, err := run(fmt.Sprintf("machinectl show -p Leader %s", mach)) if err != nil { if i != -1 { time.Sleep(100 * time.Millisecond) continue } return -1...
[ "func", "(", "nc", "*", "nspawnCluster", ")", "machinePID", "(", "name", "string", ")", "(", "int", ",", "error", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "100", ";", "i", "++", "{", "mach", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ...
// wait up to 10s for a machine to be started
[ "wait", "up", "to", "10s", "for", "a", "machine", "to", "be", "started" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/functional/platform/nspawn.go#L721-L737
124,429
coreos/fleet
registry/rpc/registrymux.go
ConnectToRegistry
func (r *RegistryMux) ConnectToRegistry(e *engine.Engine) { for { // We have to check if the leader has changed to etcd otherwise keep grpc connection isGrpc, err := e.IsGrpcLeader() // If there is not error then we are able to get the leader state and continue // otherwise we have to wait if err == nil { ...
go
func (r *RegistryMux) ConnectToRegistry(e *engine.Engine) { for { // We have to check if the leader has changed to etcd otherwise keep grpc connection isGrpc, err := e.IsGrpcLeader() // If there is not error then we are able to get the leader state and continue // otherwise we have to wait if err == nil { ...
[ "func", "(", "r", "*", "RegistryMux", ")", "ConnectToRegistry", "(", "e", "*", "engine", ".", "Engine", ")", "{", "for", "{", "// We have to check if the leader has changed to etcd otherwise keep grpc connection", "isGrpc", ",", "err", ":=", "e", ".", "IsGrpcLeader", ...
// ConnectToRegistry allows to disable_engine fleet agents to adapt its Registry // to fleet leader changes regardless of whether is etcd or gRPC based.
[ "ConnectToRegistry", "allows", "to", "disable_engine", "fleet", "agents", "to", "adapt", "its", "Registry", "to", "fleet", "leader", "changes", "regardless", "of", "whether", "is", "etcd", "or", "gRPC", "based", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/rpc/registrymux.go#L64-L95
124,430
coreos/fleet
machine/coreos.go
State
func (m *CoreOSMachine) State() (state MachineState) { m.RLock() defer m.RUnlock() if m.dynamicState == nil { state = MachineState(m.staticState) } else { state = stackState(m.staticState, *m.dynamicState) } return }
go
func (m *CoreOSMachine) State() (state MachineState) { m.RLock() defer m.RUnlock() if m.dynamicState == nil { state = MachineState(m.staticState) } else { state = stackState(m.staticState, *m.dynamicState) } return }
[ "func", "(", "m", "*", "CoreOSMachine", ")", "State", "(", ")", "(", "state", "MachineState", ")", "{", "m", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "RUnlock", "(", ")", "\n\n", "if", "m", ".", "dynamicState", "==", "nil", "{", "state", ...
// State returns a MachineState object representing the CoreOSMachine's // static state overlaid on its dynamic state at the time of execution.
[ "State", "returns", "a", "MachineState", "object", "representing", "the", "CoreOSMachine", "s", "static", "state", "overlaid", "on", "its", "dynamic", "state", "at", "the", "time", "of", "execution", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/machine/coreos.go#L59-L70
124,431
coreos/fleet
machine/coreos.go
Refresh
func (m *CoreOSMachine) Refresh() { m.RLock() defer m.RUnlock() cs := m.currentState() if cs == nil { log.Warning("Unable to refresh machine state") } else { m.dynamicState = cs } }
go
func (m *CoreOSMachine) Refresh() { m.RLock() defer m.RUnlock() cs := m.currentState() if cs == nil { log.Warning("Unable to refresh machine state") } else { m.dynamicState = cs } }
[ "func", "(", "m", "*", "CoreOSMachine", ")", "Refresh", "(", ")", "{", "m", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "RUnlock", "(", ")", "\n\n", "cs", ":=", "m", ".", "currentState", "(", ")", "\n", "if", "cs", "==", "nil", "{", "log",...
// Refresh updates the current state of the CoreOSMachine.
[ "Refresh", "updates", "the", "current", "state", "of", "the", "CoreOSMachine", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/machine/coreos.go#L73-L83
124,432
coreos/fleet
machine/coreos.go
PeriodicRefresh
func (m *CoreOSMachine) PeriodicRefresh(interval time.Duration, stop <-chan struct{}) { ticker := time.NewTicker(interval) for { select { case <-stop: log.Debug("Halting CoreOSMachine.PeriodicRefresh") ticker.Stop() return case <-ticker.C: m.Refresh() } } }
go
func (m *CoreOSMachine) PeriodicRefresh(interval time.Duration, stop <-chan struct{}) { ticker := time.NewTicker(interval) for { select { case <-stop: log.Debug("Halting CoreOSMachine.PeriodicRefresh") ticker.Stop() return case <-ticker.C: m.Refresh() } } }
[ "func", "(", "m", "*", "CoreOSMachine", ")", "PeriodicRefresh", "(", "interval", "time", ".", "Duration", ",", "stop", "<-", "chan", "struct", "{", "}", ")", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "interval", ")", "\n", "for", "{", "select...
// PeriodicRefresh updates the current state of the CoreOSMachine at the // interval indicated. Operation ceases when the provided channel is closed.
[ "PeriodicRefresh", "updates", "the", "current", "state", "of", "the", "CoreOSMachine", "at", "the", "interval", "indicated", ".", "Operation", "ceases", "when", "the", "provided", "channel", "is", "closed", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/machine/coreos.go#L87-L99
124,433
coreos/fleet
machine/coreos.go
currentState
func (m *CoreOSMachine) currentState() *MachineState { id, err := readLocalMachineID("/") if err != nil { log.Errorf("Error retrieving machineID: %v\n", err) return nil } publicIP := getLocalIP() return &MachineState{ ID: id, PublicIP: publicIP, Metadata: make(map[string]string, 0), } }
go
func (m *CoreOSMachine) currentState() *MachineState { id, err := readLocalMachineID("/") if err != nil { log.Errorf("Error retrieving machineID: %v\n", err) return nil } publicIP := getLocalIP() return &MachineState{ ID: id, PublicIP: publicIP, Metadata: make(map[string]string, 0), } }
[ "func", "(", "m", "*", "CoreOSMachine", ")", "currentState", "(", ")", "*", "MachineState", "{", "id", ",", "err", ":=", "readLocalMachineID", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\\n", "\"", ...
// currentState generates a MachineState object with the values read from // the local system
[ "currentState", "generates", "a", "MachineState", "object", "with", "the", "values", "read", "from", "the", "local", "system" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/machine/coreos.go#L103-L115
124,434
coreos/fleet
machine/coreos.go
IsLocalMachineID
func IsLocalMachineID(mID string) bool { m, err := readLocalMachineID("/") return err == nil && m == mID }
go
func IsLocalMachineID(mID string) bool { m, err := readLocalMachineID("/") return err == nil && m == mID }
[ "func", "IsLocalMachineID", "(", "mID", "string", ")", "bool", "{", "m", ",", "err", ":=", "readLocalMachineID", "(", "\"", "\"", ")", "\n", "return", "err", "==", "nil", "&&", "m", "==", "mID", "\n", "}" ]
// IsLocalMachineID returns whether the given machine ID is equal to that of the local machine
[ "IsLocalMachineID", "returns", "whether", "the", "given", "machine", "ID", "is", "equal", "to", "that", "of", "the", "local", "machine" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/machine/coreos.go#L118-L121
124,435
coreos/fleet
agent/unit_state.go
Run
func (p *UnitStatePublisher) Run(beatchan <-chan *unit.UnitStateHeartbeat, stop <-chan struct{}) { var period time.Duration if p.ttl > 10*time.Second { period = p.ttl * 4 / 5 } else { period = p.ttl / 2 } go func() { for { select { case <-stop: return case <-p.clock.After(period): p.cacheMu...
go
func (p *UnitStatePublisher) Run(beatchan <-chan *unit.UnitStateHeartbeat, stop <-chan struct{}) { var period time.Duration if p.ttl > 10*time.Second { period = p.ttl * 4 / 5 } else { period = p.ttl / 2 } go func() { for { select { case <-stop: return case <-p.clock.After(period): p.cacheMu...
[ "func", "(", "p", "*", "UnitStatePublisher", ")", "Run", "(", "beatchan", "<-", "chan", "*", "unit", ".", "UnitStateHeartbeat", ",", "stop", "<-", "chan", "struct", "{", "}", ")", "{", "var", "period", "time", ".", "Duration", "\n", "if", "p", ".", "...
// Run caches all of the heartbeat objects from the provided channel, publishing // them to the Registry every 5s. Heartbeat objects are also published as they // are received on the channel.
[ "Run", "caches", "all", "of", "the", "heartbeat", "objects", "from", "the", "provided", "channel", "publishing", "them", "to", "the", "Registry", "every", "5s", ".", "Heartbeat", "objects", "are", "also", "published", "as", "they", "are", "received", "on", "...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/unit_state.go#L73-L140
124,436
coreos/fleet
agent/unit_state.go
queueForPublish
func (p *UnitStatePublisher) queueForPublish(name string, us *unit.UnitState) { p.toPublishMutex.Lock() p.toPublishStates[name] = us p.toPublishMutex.Unlock() // This may block for some time, but even if it occurs after // the above UnitState has already been published, it will // simply trigger a no-op p.toPubl...
go
func (p *UnitStatePublisher) queueForPublish(name string, us *unit.UnitState) { p.toPublishMutex.Lock() p.toPublishStates[name] = us p.toPublishMutex.Unlock() // This may block for some time, but even if it occurs after // the above UnitState has already been published, it will // simply trigger a no-op p.toPubl...
[ "func", "(", "p", "*", "UnitStatePublisher", ")", "queueForPublish", "(", "name", "string", ",", "us", "*", "unit", ".", "UnitState", ")", "{", "p", ".", "toPublishMutex", ".", "Lock", "(", ")", "\n", "p", ".", "toPublishStates", "[", "name", "]", "=",...
// queueForPublish notifies the publishing goroutines that a particular // UnitState should be published to the Registry. This can block and should be // called in a goroutine.
[ "queueForPublish", "notifies", "the", "publishing", "goroutines", "that", "a", "particular", "UnitState", "should", "be", "published", "to", "the", "Registry", ".", "This", "can", "block", "and", "should", "be", "called", "in", "a", "goroutine", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/unit_state.go#L167-L175
124,437
coreos/fleet
agent/unit_state.go
updateCache
func (p *UnitStatePublisher) updateCache(update *unit.UnitStateHeartbeat) (changed bool) { p.cacheMutex.Lock() defer p.cacheMutex.Unlock() last, ok := p.cache[update.Name] p.cache[update.Name] = update.State if !ok || !reflect.DeepEqual(last, update.State) { changed = true } return }
go
func (p *UnitStatePublisher) updateCache(update *unit.UnitStateHeartbeat) (changed bool) { p.cacheMutex.Lock() defer p.cacheMutex.Unlock() last, ok := p.cache[update.Name] p.cache[update.Name] = update.State if !ok || !reflect.DeepEqual(last, update.State) { changed = true } return }
[ "func", "(", "p", "*", "UnitStatePublisher", ")", "updateCache", "(", "update", "*", "unit", ".", "UnitStateHeartbeat", ")", "(", "changed", "bool", ")", "{", "p", ".", "cacheMutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "cacheMutex", ".", "U...
// updateCache updates the cache of UnitStates which the UnitStatePublisher // uses to determine when a change has occurred, and to do a periodic // publishing of all UnitStates. It returns a boolean indicating whether the // state in the given UnitStateHeartbeat differs from the state from the // previous heartbeat of...
[ "updateCache", "updates", "the", "cache", "of", "UnitStates", "which", "the", "UnitStatePublisher", "uses", "to", "determine", "when", "a", "change", "has", "occurred", "and", "to", "do", "a", "periodic", "publishing", "of", "all", "UnitStates", ".", "It", "re...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/unit_state.go#L182-L193
124,438
coreos/fleet
agent/unit_state.go
Purge
func (p *UnitStatePublisher) Purge() { for name := range p.cache { p.publisher(name, nil) } }
go
func (p *UnitStatePublisher) Purge() { for name := range p.cache { p.publisher(name, nil) } }
[ "func", "(", "p", "*", "UnitStatePublisher", ")", "Purge", "(", ")", "{", "for", "name", ":=", "range", "p", ".", "cache", "{", "p", ".", "publisher", "(", "name", ",", "nil", ")", "\n", "}", "\n", "}" ]
// Purge ensures that the UnitStates for all Units known in the // UnitStatePublisher's cache are removed from the registry.
[ "Purge", "ensures", "that", "the", "UnitStates", "for", "all", "Units", "known", "in", "the", "UnitStatePublisher", "s", "cache", "are", "removed", "from", "the", "registry", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/unit_state.go#L197-L201
124,439
coreos/fleet
agent/unit_state.go
newPublisher
func newPublisher(reg registry.Registry, ttl time.Duration) publishFunc { return func(name string, us *unit.UnitState) { if us == nil { log.Debugf("Destroying UnitState(%s) in Registry", name) err := reg.RemoveUnitState(name) if err != nil { log.Errorf("Failed to destroy UnitState(%s) in Registry: %v", ...
go
func newPublisher(reg registry.Registry, ttl time.Duration) publishFunc { return func(name string, us *unit.UnitState) { if us == nil { log.Debugf("Destroying UnitState(%s) in Registry", name) err := reg.RemoveUnitState(name) if err != nil { log.Errorf("Failed to destroy UnitState(%s) in Registry: %v", ...
[ "func", "newPublisher", "(", "reg", "registry", ".", "Registry", ",", "ttl", "time", ".", "Duration", ")", "publishFunc", "{", "return", "func", "(", "name", "string", ",", "us", "*", "unit", ".", "UnitState", ")", "{", "if", "us", "==", "nil", "{", ...
// newPublisher returns a publishFunc that publishes a single UnitState // by the given name to the provided Registry, with the given TTL
[ "newPublisher", "returns", "a", "publishFunc", "that", "publishes", "a", "single", "UnitState", "by", "the", "given", "name", "to", "the", "provided", "Registry", "with", "the", "given", "TTL" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/unit_state.go#L205-L227
124,440
coreos/fleet
ssh/known_hosts.go
askToTrustHost
func askToTrustHost(addr, algo, fingerprint string) bool { var ans string fmt.Fprintf(os.Stderr, promptToTrustHost, addr, algo, fingerprint) fmt.Scanf("%s\n", &ans) ans = strings.ToLower(ans) if ans != "yes" && ans != "y" { return false } return true }
go
func askToTrustHost(addr, algo, fingerprint string) bool { var ans string fmt.Fprintf(os.Stderr, promptToTrustHost, addr, algo, fingerprint) fmt.Scanf("%s\n", &ans) ans = strings.ToLower(ans) if ans != "yes" && ans != "y" { return false } return true }
[ "func", "askToTrustHost", "(", "addr", ",", "algo", ",", "fingerprint", "string", ")", "bool", "{", "var", "ans", "string", "\n\n", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "promptToTrustHost", ",", "addr", ",", "algo", ",", "fingerprint", "...
// askToTrustHost prompts the user to trust a new key fingerprint while connecting to a host
[ "askToTrustHost", "prompts", "the", "user", "to", "trust", "a", "new", "key", "fingerprint", "while", "connecting", "to", "a", "host" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/known_hosts.go#L59-L71
124,441
coreos/fleet
ssh/known_hosts.go
GetHostKeyAlgorithms
func (kc *HostKeyChecker) GetHostKeyAlgorithms(addr string) []string { var results []string remoteAddr, err := kc.addrToHostPort(addr) if err != nil { log.Errorf("Failed to parse address %v: %v", addr, err) return nil } hostKeys, err := kc.m.GetHostKeys() _, ok := err.(*os.PathError) if err != nil && !ok {...
go
func (kc *HostKeyChecker) GetHostKeyAlgorithms(addr string) []string { var results []string remoteAddr, err := kc.addrToHostPort(addr) if err != nil { log.Errorf("Failed to parse address %v: %v", addr, err) return nil } hostKeys, err := kc.m.GetHostKeys() _, ok := err.(*os.PathError) if err != nil && !ok {...
[ "func", "(", "kc", "*", "HostKeyChecker", ")", "GetHostKeyAlgorithms", "(", "addr", "string", ")", "[", "]", "string", "{", "var", "results", "[", "]", "string", "\n", "remoteAddr", ",", "err", ":=", "kc", ".", "addrToHostPort", "(", "addr", ")", "\n", ...
// Returns public key algorithms of the remote host that are listed // inside known_hosts
[ "Returns", "public", "key", "algorithms", "of", "the", "remote", "host", "that", "are", "listed", "inside", "known_hosts" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/known_hosts.go#L92-L130
124,442
coreos/fleet
ssh/known_hosts.go
addrToHostPort
func (kc *HostKeyChecker) addrToHostPort(a string) (string, error) { if !strings.Contains(a, ":") { // No port, so return unadulterated return a, nil } host, p, err := net.SplitHostPort(a) if err != nil { log.Debugf("Unable to parse addr %s: %v", a, err) return "", err } port, err := strconv.Atoi(p) if ...
go
func (kc *HostKeyChecker) addrToHostPort(a string) (string, error) { if !strings.Contains(a, ":") { // No port, so return unadulterated return a, nil } host, p, err := net.SplitHostPort(a) if err != nil { log.Debugf("Unable to parse addr %s: %v", a, err) return "", err } port, err := strconv.Atoi(p) if ...
[ "func", "(", "kc", "*", "HostKeyChecker", ")", "addrToHostPort", "(", "a", "string", ")", "(", "string", ",", "error", ")", "{", "if", "!", "strings", ".", "Contains", "(", "a", ",", "\"", "\"", ")", "{", "// No port, so return unadulterated", "return", ...
// addrToHostPort takes the given address and parses it into a string suitable // for use in the 'hostnames' field in a known_hosts file. For more details, // see the `SSH_KNOWN_HOSTS FILE FORMAT` section of `man 8 sshd`
[ "addrToHostPort", "takes", "the", "given", "address", "and", "parses", "it", "into", "a", "string", "suitable", "for", "use", "in", "the", "hostnames", "field", "in", "a", "known_hosts", "file", ".", "For", "more", "details", "see", "the", "SSH_KNOWN_HOSTS", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/known_hosts.go#L194-L222
124,443
coreos/fleet
ssh/known_hosts.go
parseKnownHostsLine
func parseKnownHostsLine(line []byte) (string, gossh.PublicKey, error) { // Skip any leading whitespace. line = bytes.TrimLeft(line, "\t ") // Skip comments and empty lines. if bytes.HasPrefix(line, []byte("#")) || len(line) == 0 { return "", nil, nil } // Skip markers. if bytes.HasPrefix(line, []byte("@"))...
go
func parseKnownHostsLine(line []byte) (string, gossh.PublicKey, error) { // Skip any leading whitespace. line = bytes.TrimLeft(line, "\t ") // Skip comments and empty lines. if bytes.HasPrefix(line, []byte("#")) || len(line) == 0 { return "", nil, nil } // Skip markers. if bytes.HasPrefix(line, []byte("@"))...
[ "func", "parseKnownHostsLine", "(", "line", "[", "]", "byte", ")", "(", "string", ",", "gossh", ".", "PublicKey", ",", "error", ")", "{", "// Skip any leading whitespace.", "line", "=", "bytes", ".", "TrimLeft", "(", "line", ",", "\"", "\\t", "\"", ")", ...
// parseKnownHostsLine parses a line from a known hosts file. It returns a // string containing the hosts section of the line, a gossh.PublicKey parsed // from the line, and any error encountered during the parsing.
[ "parseKnownHostsLine", "parses", "a", "line", "from", "a", "known", "hosts", "file", ".", "It", "returns", "a", "string", "containing", "the", "hosts", "section", "of", "the", "line", "a", "gossh", ".", "PublicKey", "parsed", "from", "the", "line", "and", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/known_hosts.go#L284-L319
124,444
coreos/fleet
ssh/known_hosts.go
algoString
func algoString(algo string) string { switch algo { case gossh.KeyAlgoRSA: return "RSA" case gossh.KeyAlgoDSA: return "DSA" case gossh.KeyAlgoECDSA256, gossh.KeyAlgoECDSA384, gossh.KeyAlgoECDSA521: return "ECDSA" } return algo }
go
func algoString(algo string) string { switch algo { case gossh.KeyAlgoRSA: return "RSA" case gossh.KeyAlgoDSA: return "DSA" case gossh.KeyAlgoECDSA256, gossh.KeyAlgoECDSA384, gossh.KeyAlgoECDSA521: return "ECDSA" } return algo }
[ "func", "algoString", "(", "algo", "string", ")", "string", "{", "switch", "algo", "{", "case", "gossh", ".", "KeyAlgoRSA", ":", "return", "\"", "\"", "\n", "case", "gossh", ".", "KeyAlgoDSA", ":", "return", "\"", "\"", "\n", "case", "gossh", ".", "Key...
// algoString returns a short-name representation of an algorithm type
[ "algoString", "returns", "a", "short", "-", "name", "representation", "of", "an", "algorithm", "type" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/known_hosts.go#L355-L365
124,445
coreos/fleet
ssh/known_hosts.go
md5String
func md5String(md5Sum [16]byte) string { md5Str := fmt.Sprintf("% x", md5Sum) md5Str = strings.Replace(md5Str, " ", ":", -1) return md5Str }
go
func md5String(md5Sum [16]byte) string { md5Str := fmt.Sprintf("% x", md5Sum) md5Str = strings.Replace(md5Str, " ", ":", -1) return md5Str }
[ "func", "md5String", "(", "md5Sum", "[", "16", "]", "byte", ")", "string", "{", "md5Str", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "md5Sum", ")", "\n", "md5Str", "=", "strings", ".", "Replace", "(", "md5Str", ",", "\"", "\"", ",", "\"", ...
// md5String returns a formatted string representing the given md5Sum in hex
[ "md5String", "returns", "a", "formatted", "string", "representing", "the", "given", "md5Sum", "in", "hex" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/known_hosts.go#L368-L372
124,446
coreos/fleet
agent/reconcile.go
Run
func (ar *AgentReconciler) Run(a *Agent, stop <-chan struct{}) { reconcile := func() { start := time.Now() ar.Reconcile(a) elapsed := time.Now().Sub(start) msg := fmt.Sprintf("AgentReconciler completed reconciliation in %s", elapsed) if elapsed > reconcileInterval { log.Warning(msg) } else { log.Deb...
go
func (ar *AgentReconciler) Run(a *Agent, stop <-chan struct{}) { reconcile := func() { start := time.Now() ar.Reconcile(a) elapsed := time.Now().Sub(start) msg := fmt.Sprintf("AgentReconciler completed reconciliation in %s", elapsed) if elapsed > reconcileInterval { log.Warning(msg) } else { log.Deb...
[ "func", "(", "ar", "*", "AgentReconciler", ")", "Run", "(", "a", "*", "Agent", ",", "stop", "<-", "chan", "struct", "{", "}", ")", "{", "reconcile", ":=", "func", "(", ")", "{", "start", ":=", "time", ".", "Now", "(", ")", "\n", "ar", ".", "Rec...
// Run periodically attempts to reconcile the provided Agent until the stop // channel is closed. Run will also reconcile in reaction to events on the // AgentReconciler's rStream.
[ "Run", "periodically", "attempts", "to", "reconcile", "the", "provided", "Agent", "until", "the", "stop", "channel", "is", "closed", ".", "Run", "will", "also", "reconcile", "in", "reaction", "to", "events", "on", "the", "AgentReconciler", "s", "rStream", "." ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/reconcile.go#L51-L66
124,447
coreos/fleet
agent/reconcile.go
Reconcile
func (ar *AgentReconciler) Reconcile(a *Agent) { dAgentState, err := desiredAgentState(a, ar.reg) if err != nil { log.Errorf("Unable to determine agent's desired state: %v", err) return } cAgentState, err := a.units() if err != nil { log.Errorf("Unable to determine agent's current state: %v", err) return ...
go
func (ar *AgentReconciler) Reconcile(a *Agent) { dAgentState, err := desiredAgentState(a, ar.reg) if err != nil { log.Errorf("Unable to determine agent's desired state: %v", err) return } cAgentState, err := a.units() if err != nil { log.Errorf("Unable to determine agent's current state: %v", err) return ...
[ "func", "(", "ar", "*", "AgentReconciler", ")", "Reconcile", "(", "a", "*", "Agent", ")", "{", "dAgentState", ",", "err", ":=", "desiredAgentState", "(", "a", ",", "ar", ".", "reg", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(...
// Reconcile drives the local Agent's state towards the desired state // stored in the Registry.
[ "Reconcile", "drives", "the", "local", "Agent", "s", "state", "towards", "the", "desired", "state", "stored", "in", "the", "Registry", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/reconcile.go#L70-L85
124,448
coreos/fleet
agent/reconcile.go
Purge
func (ar *AgentReconciler) Purge(a *Agent) { for { cAgentState, err := a.units() if err != nil { log.Errorf("Unable to determine agent's current state: %v", err) return } if len(cAgentState) == 0 { return } var tasks []task for name, _ := range cAgentState { tasks = append(tasks, task{ t...
go
func (ar *AgentReconciler) Purge(a *Agent) { for { cAgentState, err := a.units() if err != nil { log.Errorf("Unable to determine agent's current state: %v", err) return } if len(cAgentState) == 0 { return } var tasks []task for name, _ := range cAgentState { tasks = append(tasks, task{ t...
[ "func", "(", "ar", "*", "AgentReconciler", ")", "Purge", "(", "a", "*", "Agent", ")", "{", "for", "{", "cAgentState", ",", "err", ":=", "a", ".", "units", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ","...
// Purge attempts to unload all Units that have been loaded locally
[ "Purge", "attempts", "to", "unload", "all", "Units", "that", "have", "been", "loaded", "locally" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/reconcile.go#L88-L113
124,449
coreos/fleet
agent/reconcile.go
calculateTasksForUnits
func (ar *AgentReconciler) calculateTasksForUnits(dState *AgentState, cState unitStates) []task { jobs := pkg.NewUnsafeSet() for cName := range cState { jobs.Add(cName) } for dName := range dState.Units { jobs.Add(dName) } sorted := sort.StringSlice(jobs.Values()) sorted.Sort() var tasks []task for _, n...
go
func (ar *AgentReconciler) calculateTasksForUnits(dState *AgentState, cState unitStates) []task { jobs := pkg.NewUnsafeSet() for cName := range cState { jobs.Add(cName) } for dName := range dState.Units { jobs.Add(dName) } sorted := sort.StringSlice(jobs.Values()) sorted.Sort() var tasks []task for _, n...
[ "func", "(", "ar", "*", "AgentReconciler", ")", "calculateTasksForUnits", "(", "dState", "*", "AgentState", ",", "cState", "unitStates", ")", "[", "]", "task", "{", "jobs", ":=", "pkg", ".", "NewUnsafeSet", "(", ")", "\n", "for", "cName", ":=", "range", ...
// calculateTasksForUnits compares the desired and current state of an Agent. // The generated tasks represent what, in order, should be done to make the // desired state match the current state.
[ "calculateTasksForUnits", "compares", "the", "desired", "and", "current", "state", "of", "an", "Agent", ".", "The", "generated", "tasks", "represent", "what", "in", "order", "should", "be", "done", "to", "make", "the", "desired", "state", "match", "the", "curr...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/reconcile.go#L179-L212
124,450
coreos/fleet
agent/agent.go
units
func (a *Agent) units() (unitStates, error) { launched := pkg.NewUnsafeSet() for _, jName := range a.cache.launchedJobs() { launched.Add(jName) } loaded := pkg.NewUnsafeSet() for _, jName := range a.cache.loadedJobs() { loaded.Add(jName) } units, err := a.um.Units() if err != nil { return nil, fmt.Error...
go
func (a *Agent) units() (unitStates, error) { launched := pkg.NewUnsafeSet() for _, jName := range a.cache.launchedJobs() { launched.Add(jName) } loaded := pkg.NewUnsafeSet() for _, jName := range a.cache.loadedJobs() { loaded.Add(jName) } units, err := a.um.Units() if err != nil { return nil, fmt.Error...
[ "func", "(", "a", "*", "Agent", ")", "units", "(", ")", "(", "unitStates", ",", "error", ")", "{", "launched", ":=", "pkg", ".", "NewUnsafeSet", "(", ")", "\n", "for", "_", ",", "jName", ":=", "range", "a", ".", "cache", ".", "launchedJobs", "(", ...
// units returns a map representing the current state of units known by the agent.
[ "units", "returns", "a", "map", "representing", "the", "current", "state", "of", "units", "known", "by", "the", "agent", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/agent.go#L151-L193
124,451
coreos/fleet
api/serialization.go
sendResponse
func sendResponse(rw http.ResponseWriter, code int, resp interface{}) { enc, err := json.Marshal(resp) if err != nil { log.Errorf("Failed JSON-encoding HTTP response: %v", err) rw.WriteHeader(http.StatusInternalServerError) return } rw.Header().Set("Content-Type", "application/json") rw.WriteHeader(code) ...
go
func sendResponse(rw http.ResponseWriter, code int, resp interface{}) { enc, err := json.Marshal(resp) if err != nil { log.Errorf("Failed JSON-encoding HTTP response: %v", err) rw.WriteHeader(http.StatusInternalServerError) return } rw.Header().Set("Content-Type", "application/json") rw.WriteHeader(code) ...
[ "func", "sendResponse", "(", "rw", "http", ".", "ResponseWriter", ",", "code", "int", ",", "resp", "interface", "{", "}", ")", "{", "enc", ",", "err", ":=", "json", ".", "Marshal", "(", "resp", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", ...
// sendResponse attempts to marshal an arbitrary thing to JSON then write // it to the http.ResponseWriter
[ "sendResponse", "attempts", "to", "marshal", "an", "arbitrary", "thing", "to", "JSON", "then", "write", "it", "to", "the", "http", ".", "ResponseWriter" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/api/serialization.go#L46-L61
124,452
coreos/fleet
api/serialization.go
sendError
func sendError(rw http.ResponseWriter, code int, err error) { resp := errorResponse{Error: errorEntity{Code: code}} if err != nil { resp.Error.Message = err.Error() } sendResponse(rw, code, resp) }
go
func sendError(rw http.ResponseWriter, code int, err error) { resp := errorResponse{Error: errorEntity{Code: code}} if err != nil { resp.Error.Message = err.Error() } sendResponse(rw, code, resp) }
[ "func", "sendError", "(", "rw", "http", ".", "ResponseWriter", ",", "code", "int", ",", "err", "error", ")", "{", "resp", ":=", "errorResponse", "{", "Error", ":", "errorEntity", "{", "Code", ":", "code", "}", "}", "\n", "if", "err", "!=", "nil", "{"...
// sendError builds an errorResponse entity from the given arguments, serializing // the object into the provided http.ResponseWriter
[ "sendError", "builds", "an", "errorResponse", "entity", "from", "the", "given", "arguments", "serializing", "the", "object", "into", "the", "provided", "http", ".", "ResponseWriter" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/api/serialization.go#L78-L84
124,453
coreos/fleet
agent/state.go
HasConflict
func (as *AgentState) HasConflict(pUnitName string, pConflicts []string) (bool, []string) { found := false conflicts := []string{} for _, eUnit := range as.Units { if pUnitName == eUnit.Name { continue } if hasStringInSlice(eUnit.Conflicts(), pUnitName) { conflicts = append(conflicts, pUnitName) fou...
go
func (as *AgentState) HasConflict(pUnitName string, pConflicts []string) (bool, []string) { found := false conflicts := []string{} for _, eUnit := range as.Units { if pUnitName == eUnit.Name { continue } if hasStringInSlice(eUnit.Conflicts(), pUnitName) { conflicts = append(conflicts, pUnitName) fou...
[ "func", "(", "as", "*", "AgentState", ")", "HasConflict", "(", "pUnitName", "string", ",", "pConflicts", "[", "]", "string", ")", "(", "bool", ",", "[", "]", "string", ")", "{", "found", ":=", "false", "\n", "conflicts", ":=", "[", "]", "string", "{"...
// HasConflict determines whether there are any known conflicts with the given Unit
[ "HasConflict", "determines", "whether", "there", "are", "any", "known", "conflicts", "with", "the", "given", "Unit" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/state.go#L52-L78
124,454
coreos/fleet
agent/state.go
hasReplace
func (as *AgentState) hasReplace(pUnitName string, pReplaces []string) (found bool, replace string) { for _, eUnit := range as.Units { foundPrepl := false foundErepl := false retStr := "" if pUnitName == eUnit.Name { continue } for _, pReplace := range pReplaces { if globMatches(pReplace, eUnit.Nam...
go
func (as *AgentState) hasReplace(pUnitName string, pReplaces []string) (found bool, replace string) { for _, eUnit := range as.Units { foundPrepl := false foundErepl := false retStr := "" if pUnitName == eUnit.Name { continue } for _, pReplace := range pReplaces { if globMatches(pReplace, eUnit.Nam...
[ "func", "(", "as", "*", "AgentState", ")", "hasReplace", "(", "pUnitName", "string", ",", "pReplaces", "[", "]", "string", ")", "(", "found", "bool", ",", "replace", "string", ")", "{", "for", "_", ",", "eUnit", ":=", "range", "as", ".", "Units", "{"...
// hasReplace determines whether there are any known replaces with the given Unit
[ "hasReplace", "determines", "whether", "there", "are", "any", "known", "replaces", "with", "the", "given", "Unit" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/agent/state.go#L81-L120
124,455
coreos/fleet
server/monitor.go
Monitor
func (m *Monitor) Monitor(hrt heart.Heart, sdc <-chan struct{}) (bool, error) { ticker := time.Tick(m.ival) for { select { case <-sdc: return true, nil case <-ticker: if _, err := check(hrt, m.TTL); err != nil { return false, err } } } }
go
func (m *Monitor) Monitor(hrt heart.Heart, sdc <-chan struct{}) (bool, error) { ticker := time.Tick(m.ival) for { select { case <-sdc: return true, nil case <-ticker: if _, err := check(hrt, m.TTL); err != nil { return false, err } } } }
[ "func", "(", "m", "*", "Monitor", ")", "Monitor", "(", "hrt", "heart", ".", "Heart", ",", "sdc", "<-", "chan", "struct", "{", "}", ")", "(", "bool", ",", "error", ")", "{", "ticker", ":=", "time", ".", "Tick", "(", "m", ".", "ival", ")", "\n", ...
// Monitor periodically checks the given Heart to make sure it // beats successfully. If the heartbeat check fails for any // reason, an error is returned. If the supplied channel is // closed, Monitor returns true and a nil error.
[ "Monitor", "periodically", "checks", "the", "given", "Heart", "to", "make", "sure", "it", "beats", "successfully", ".", "If", "the", "heartbeat", "check", "fails", "for", "any", "reason", "an", "error", "is", "returned", ".", "If", "the", "supplied", "channe...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/server/monitor.go#L38-L50
124,456
coreos/fleet
server/monitor.go
check
func check(hrt heart.Heart, ttl time.Duration) (idx uint64, err error) { // time out after a third of the machine presence TTL, attempting // the heartbeat up to four times timeout := ttl / 3 interval := timeout / 4 tchan := time.After(timeout) next := time.After(0) for idx == 0 { select { case <-tchan: ...
go
func check(hrt heart.Heart, ttl time.Duration) (idx uint64, err error) { // time out after a third of the machine presence TTL, attempting // the heartbeat up to four times timeout := ttl / 3 interval := timeout / 4 tchan := time.After(timeout) next := time.After(0) for idx == 0 { select { case <-tchan: ...
[ "func", "check", "(", "hrt", "heart", ".", "Heart", ",", "ttl", "time", ".", "Duration", ")", "(", "idx", "uint64", ",", "err", "error", ")", "{", "// time out after a third of the machine presence TTL, attempting", "// the heartbeat up to four times", "timeout", ":="...
// check attempts to beat a Heart several times within a timeout, returning the // log index at which the beat succeeded or an error
[ "check", "attempts", "to", "beat", "a", "Heart", "several", "times", "within", "a", "timeout", "returning", "the", "log", "index", "at", "which", "the", "beat", "succeeded", "or", "an", "error" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/server/monitor.go#L54-L78
124,457
coreos/fleet
fleetctl/fleetctl.go
getClient
func getClient(cCmd *cobra.Command) (client.API, error) { clientDriver, _ := cmdFleet.PersistentFlags().GetString("driver") switch clientDriver { case clientDriverAPI: return getHTTPClient(cCmd) case clientDriverEtcd: return getRegistryClient(cCmd) } return nil, fmt.Errorf("unrecognized driver %q", clientDr...
go
func getClient(cCmd *cobra.Command) (client.API, error) { clientDriver, _ := cmdFleet.PersistentFlags().GetString("driver") switch clientDriver { case clientDriverAPI: return getHTTPClient(cCmd) case clientDriverEtcd: return getRegistryClient(cCmd) } return nil, fmt.Errorf("unrecognized driver %q", clientDr...
[ "func", "getClient", "(", "cCmd", "*", "cobra", ".", "Command", ")", "(", "client", ".", "API", ",", "error", ")", "{", "clientDriver", ",", "_", ":=", "cmdFleet", ".", "PersistentFlags", "(", ")", ".", "GetString", "(", "\"", "\"", ")", "\n\n", "swi...
// getClient initializes a client of fleet based on CLI flags
[ "getClient", "initializes", "a", "client", "of", "fleet", "based", "on", "CLI", "flags" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L315-L326
124,458
coreos/fleet
fleetctl/fleetctl.go
getChecker
func getChecker(cCmd *cobra.Command) *ssh.HostKeyChecker { strictHostKeyChecking, _ := cmdFleet.PersistentFlags().GetBool("strict-host-key-checking") if !strictHostKeyChecking { return nil } knownHostsFile, _ := cmdFleet.PersistentFlags().GetString("known-hosts-file") keyFile := ssh.NewHostKeyFile(knownHostsFil...
go
func getChecker(cCmd *cobra.Command) *ssh.HostKeyChecker { strictHostKeyChecking, _ := cmdFleet.PersistentFlags().GetBool("strict-host-key-checking") if !strictHostKeyChecking { return nil } knownHostsFile, _ := cmdFleet.PersistentFlags().GetString("known-hosts-file") keyFile := ssh.NewHostKeyFile(knownHostsFil...
[ "func", "getChecker", "(", "cCmd", "*", "cobra", ".", "Command", ")", "*", "ssh", ".", "HostKeyChecker", "{", "strictHostKeyChecking", ",", "_", ":=", "cmdFleet", ".", "PersistentFlags", "(", ")", ".", "GetBool", "(", "\"", "\"", ")", "\n", "if", "!", ...
// getChecker creates and returns a HostKeyChecker, or nil if any error is encountered
[ "getChecker", "creates", "and", "returns", "a", "HostKeyChecker", "or", "nil", "if", "any", "error", "is", "encountered" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L492-L501
124,459
coreos/fleet
fleetctl/fleetctl.go
getUnitFile
func getUnitFile(cCmd *cobra.Command, file string) (*unit.UnitFile, error) { var uf *unit.UnitFile name := unitNameMangle(file) log.Debugf("Looking for Unit(%s) or its corresponding template", name) // Assume that the file references a local unit file on disk and // attempt to load it, if it exists if _, err :=...
go
func getUnitFile(cCmd *cobra.Command, file string) (*unit.UnitFile, error) { var uf *unit.UnitFile name := unitNameMangle(file) log.Debugf("Looking for Unit(%s) or its corresponding template", name) // Assume that the file references a local unit file on disk and // attempt to load it, if it exists if _, err :=...
[ "func", "getUnitFile", "(", "cCmd", "*", "cobra", ".", "Command", ",", "file", "string", ")", "(", "*", "unit", ".", "UnitFile", ",", "error", ")", "{", "var", "uf", "*", "unit", ".", "UnitFile", "\n", "name", ":=", "unitNameMangle", "(", "file", ")"...
// getUnitFile attempts to get a UnitFile configuration // It takes a unit file name as a parameter and tries first to lookup // the unit from the local disk. If it fails, it checks if the provided // file name may reference an instance of a template unit, if so, it // tries to get the template configuration either fro...
[ "getUnitFile", "attempts", "to", "get", "a", "UnitFile", "configuration", "It", "takes", "a", "unit", "file", "name", "as", "a", "parameter", "and", "tries", "first", "to", "lookup", "the", "unit", "from", "the", "local", "disk", ".", "If", "it", "fails", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L510-L546
124,460
coreos/fleet
fleetctl/fleetctl.go
getUnitFromFile
func getUnitFromFile(file string) (*unit.UnitFile, error) { out, err := ioutil.ReadFile(file) if err != nil { return nil, err } unitName := path.Base(file) log.Debugf("Unit(%s) found in local filesystem", unitName) return unit.NewUnitFile(string(out)) }
go
func getUnitFromFile(file string) (*unit.UnitFile, error) { out, err := ioutil.ReadFile(file) if err != nil { return nil, err } unitName := path.Base(file) log.Debugf("Unit(%s) found in local filesystem", unitName) return unit.NewUnitFile(string(out)) }
[ "func", "getUnitFromFile", "(", "file", "string", ")", "(", "*", "unit", ".", "UnitFile", ",", "error", ")", "{", "out", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err"...
// getUnitFromFile attempts to load a Unit from a given filename // It returns the Unit or nil, and any error encountered
[ "getUnitFromFile", "attempts", "to", "load", "a", "Unit", "from", "a", "given", "filename", "It", "returns", "the", "Unit", "or", "nil", "and", "any", "error", "encountered" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L550-L560
124,461
coreos/fleet
fleetctl/fleetctl.go
getUnitFileFromTemplate
func getUnitFileFromTemplate(cCmd *cobra.Command, uni *unit.UnitNameInfo, fileName string) (*unit.UnitFile, error) { var uf *unit.UnitFile tmpl, err := cAPI.Unit(uni.Template) if err != nil { return nil, fmt.Errorf("error retrieving template Unit(%s) from Registry: %v", uni.Template, err) } if tmpl != nil { ...
go
func getUnitFileFromTemplate(cCmd *cobra.Command, uni *unit.UnitNameInfo, fileName string) (*unit.UnitFile, error) { var uf *unit.UnitFile tmpl, err := cAPI.Unit(uni.Template) if err != nil { return nil, fmt.Errorf("error retrieving template Unit(%s) from Registry: %v", uni.Template, err) } if tmpl != nil { ...
[ "func", "getUnitFileFromTemplate", "(", "cCmd", "*", "cobra", ".", "Command", ",", "uni", "*", "unit", ".", "UnitNameInfo", ",", "fileName", "string", ")", "(", "*", "unit", ".", "UnitFile", ",", "error", ")", "{", "var", "uf", "*", "unit", ".", "UnitF...
// getUnitFileFromTemplate attempts to get a Unit from a template unit that // is either in the registry or on the file system // It takes two arguments, the template information and the unit file name // It returns the Unit or nil; and any error encountered
[ "getUnitFileFromTemplate", "attempts", "to", "get", "a", "Unit", "from", "a", "template", "unit", "that", "is", "either", "in", "the", "registry", "or", "on", "the", "file", "system", "It", "takes", "two", "arguments", "the", "template", "information", "and", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L566-L593
124,462
coreos/fleet
fleetctl/fleetctl.go
checkReplaceUnitState
func checkReplaceUnitState(unit *schema.Unit) (int, error) { // We replace units only for 'submit', 'load' and // 'start' commands. allowedReplace := map[string][]job.JobState{ "submit": []job.JobState{ job.JobStateInactive, }, "load": []job.JobState{ job.JobStateInactive, job.JobStateLoaded, }, "...
go
func checkReplaceUnitState(unit *schema.Unit) (int, error) { // We replace units only for 'submit', 'load' and // 'start' commands. allowedReplace := map[string][]job.JobState{ "submit": []job.JobState{ job.JobStateInactive, }, "load": []job.JobState{ job.JobStateInactive, job.JobStateLoaded, }, "...
[ "func", "checkReplaceUnitState", "(", "unit", "*", "schema", ".", "Unit", ")", "(", "int", ",", "error", ")", "{", "// We replace units only for 'submit', 'load' and", "// 'start' commands.", "allowedReplace", ":=", "map", "[", "string", "]", "[", "]", "job", ".",...
// checkReplaceUnitState checks if the unit should be replaced. // It takes a Unit object as a parameter. // It returns 0 on success and if the unit should be replaced, 1 if the // unit should not be replaced; and any error encountered.
[ "checkReplaceUnitState", "checks", "if", "the", "unit", "should", "be", "replaced", ".", "It", "takes", "a", "Unit", "object", "as", "a", "parameter", ".", "It", "returns", "0", "on", "success", "and", "if", "the", "unit", "should", "be", "replaced", "1", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L689-L723
124,463
coreos/fleet
fleetctl/fleetctl.go
checkUnitCreation
func checkUnitCreation(cCmd *cobra.Command, arg string) (int, error) { name := unitNameMangle(arg) // First, check if there already exists a Unit by the given name in the Registry unit, err := cAPI.Unit(name) if err != nil { return 1, fmt.Errorf("error retrieving Unit(%s) from Registry: %v", name, err) } repl...
go
func checkUnitCreation(cCmd *cobra.Command, arg string) (int, error) { name := unitNameMangle(arg) // First, check if there already exists a Unit by the given name in the Registry unit, err := cAPI.Unit(name) if err != nil { return 1, fmt.Errorf("error retrieving Unit(%s) from Registry: %v", name, err) } repl...
[ "func", "checkUnitCreation", "(", "cCmd", "*", "cobra", ".", "Command", ",", "arg", "string", ")", "(", "int", ",", "error", ")", "{", "name", ":=", "unitNameMangle", "(", "arg", ")", "\n\n", "// First, check if there already exists a Unit by the given name in the R...
// checkUnitCreation checks if the unit should be created. // It takes a unit file path as a parameter. // It returns 0 on success and if the unit should be created, 1 if the // unit should not be created; and any error encountered.
[ "checkUnitCreation", "checks", "if", "the", "unit", "should", "be", "created", ".", "It", "takes", "a", "unit", "file", "path", "as", "a", "parameter", ".", "It", "returns", "0", "on", "success", "and", "if", "the", "unit", "should", "be", "created", "1"...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L729-L766
124,464
coreos/fleet
fleetctl/fleetctl.go
matchLocalFileAndUnit
func matchLocalFileAndUnit(file string, su *schema.Unit) (bool, error) { a := schema.MapSchemaUnitOptionsToUnitFile(su.Options) _, err := os.Stat(file) if err != nil { return false, err } b, err := getUnitFromFile(file) if err != nil { return false, err } return unit.MatchUnitFiles(a, b), nil }
go
func matchLocalFileAndUnit(file string, su *schema.Unit) (bool, error) { a := schema.MapSchemaUnitOptionsToUnitFile(su.Options) _, err := os.Stat(file) if err != nil { return false, err } b, err := getUnitFromFile(file) if err != nil { return false, err } return unit.MatchUnitFiles(a, b), nil }
[ "func", "matchLocalFileAndUnit", "(", "file", "string", ",", "su", "*", "schema", ".", "Unit", ")", "(", "bool", ",", "error", ")", "{", "a", ":=", "schema", ".", "MapSchemaUnitOptionsToUnitFile", "(", "su", ".", "Options", ")", "\n\n", "_", ",", "err", ...
// matchLocalFileAndUnit compares a file with a Unit // Returns true if the contents of the file matches the unit one, false // otherwise; and any error encountered.
[ "matchLocalFileAndUnit", "compares", "a", "file", "with", "a", "Unit", "Returns", "true", "if", "the", "contents", "of", "the", "file", "matches", "the", "unit", "one", "false", "otherwise", ";", "and", "any", "error", "encountered", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L831-L845
124,465
coreos/fleet
fleetctl/fleetctl.go
isLocalUnitDifferent
func isLocalUnitDifferent(cCmd *cobra.Command, file string, su *schema.Unit, fatal bool) (bool, error) { replace, _ := cCmd.Flags().GetBool("replace") result, err := matchLocalFileAndUnit(file, su) if err == nil { // Warn in case unit differs from local file if result == false && !replace { stderr("WARNING: ...
go
func isLocalUnitDifferent(cCmd *cobra.Command, file string, su *schema.Unit, fatal bool) (bool, error) { replace, _ := cCmd.Flags().GetBool("replace") result, err := matchLocalFileAndUnit(file, su) if err == nil { // Warn in case unit differs from local file if result == false && !replace { stderr("WARNING: ...
[ "func", "isLocalUnitDifferent", "(", "cCmd", "*", "cobra", ".", "Command", ",", "file", "string", ",", "su", "*", "schema", ".", "Unit", ",", "fatal", "bool", ")", "(", "bool", ",", "error", ")", "{", "replace", ",", "_", ":=", "cCmd", ".", "Flags", ...
// isLocalUnitDifferent compares a Unit on the file system with a one // provided from the Registry. // isLocalUnitDifferent first tries to load the passed Unit from the // local file system and compares it with the Unit that is in the // Registry. If it fails to load that Unit from the filesystem and // fatal was not ...
[ "isLocalUnitDifferent", "compares", "a", "Unit", "on", "the", "file", "system", "with", "a", "one", "provided", "from", "the", "Registry", ".", "isLocalUnitDifferent", "first", "tries", "to", "load", "the", "passed", "Unit", "from", "the", "local", "file", "sy...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L860-L892
124,466
coreos/fleet
fleetctl/fleetctl.go
getBlockAttempts
func getBlockAttempts(cCmd *cobra.Command) int { // By default we wait forever var attempts int = 0 if sharedFlags.BlockAttempts > 0 { attempts = sharedFlags.BlockAttempts } if sharedFlags.NoBlock { attempts = -1 } return attempts }
go
func getBlockAttempts(cCmd *cobra.Command) int { // By default we wait forever var attempts int = 0 if sharedFlags.BlockAttempts > 0 { attempts = sharedFlags.BlockAttempts } if sharedFlags.NoBlock { attempts = -1 } return attempts }
[ "func", "getBlockAttempts", "(", "cCmd", "*", "cobra", ".", "Command", ")", "int", "{", "// By default we wait forever", "var", "attempts", "int", "=", "0", "\n\n", "if", "sharedFlags", ".", "BlockAttempts", ">", "0", "{", "attempts", "=", "sharedFlags", ".", ...
// getBlockAttempts gets the correct value of how many attempts to try // before giving up on an operation. // It returns a negative value which means do not block, if zero is // returned then it means try forever, and if a positive value is // returned then try up to that value
[ "getBlockAttempts", "gets", "the", "correct", "value", "of", "how", "many", "attempts", "to", "try", "before", "giving", "up", "on", "an", "operation", ".", "It", "returns", "a", "negative", "value", "which", "means", "do", "not", "block", "if", "zero", "i...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L942-L955
124,467
coreos/fleet
fleetctl/fleetctl.go
tryWaitForUnitStates
func tryWaitForUnitStates(units []string, state string, js job.JobState, maxAttempts int, out io.Writer) error { // We do not wait just assume we reached the desired state if maxAttempts <= -1 { for _, name := range units { stdout("Triggered unit %s %s", name, state) } return nil } errchan := waitForUnitS...
go
func tryWaitForUnitStates(units []string, state string, js job.JobState, maxAttempts int, out io.Writer) error { // We do not wait just assume we reached the desired state if maxAttempts <= -1 { for _, name := range units { stdout("Triggered unit %s %s", name, state) } return nil } errchan := waitForUnitS...
[ "func", "tryWaitForUnitStates", "(", "units", "[", "]", "string", ",", "state", "string", ",", "js", "job", ".", "JobState", ",", "maxAttempts", "int", ",", "out", "io", ".", "Writer", ")", "error", "{", "// We do not wait just assume we reached the desired state"...
// tryWaitForUnitStates tries to wait for units to reach the desired state. // It takes 5 arguments, the units to wait for, the desired state, the // desired JobState, how many attempts before timing out and a writer // interface. // tryWaitForUnitStates polls each of the indicated units until they // reach the desired...
[ "tryWaitForUnitStates", "tries", "to", "wait", "for", "units", "to", "reach", "the", "desired", "state", ".", "It", "takes", "5", "arguments", "the", "units", "to", "wait", "for", "the", "desired", "state", "the", "desired", "JobState", "how", "many", "attem...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L967-L983
124,468
coreos/fleet
fleetctl/fleetctl.go
waitForUnitStates
func waitForUnitStates(units []string, js job.JobState, maxAttempts int, out io.Writer) chan error { errchan := make(chan error) var wg sync.WaitGroup for _, name := range units { wg.Add(1) go checkUnitState(name, js, maxAttempts, out, &wg, errchan) } go func() { wg.Wait() close(errchan) }() return err...
go
func waitForUnitStates(units []string, js job.JobState, maxAttempts int, out io.Writer) chan error { errchan := make(chan error) var wg sync.WaitGroup for _, name := range units { wg.Add(1) go checkUnitState(name, js, maxAttempts, out, &wg, errchan) } go func() { wg.Wait() close(errchan) }() return err...
[ "func", "waitForUnitStates", "(", "units", "[", "]", "string", ",", "js", "job", ".", "JobState", ",", "maxAttempts", "int", ",", "out", "io", ".", "Writer", ")", "chan", "error", "{", "errchan", ":=", "make", "(", "chan", "error", ")", "\n", "var", ...
// waitForUnitStates polls each of the indicated units until each of their // states is equal to that which the caller indicates, or until the // polling operation times out. waitForUnitStates will retry forever, or // up to maxAttempts times before timing out if maxAttempts is greater // than zero. Returned is an erro...
[ "waitForUnitStates", "polls", "each", "of", "the", "indicated", "units", "until", "each", "of", "their", "states", "is", "equal", "to", "that", "which", "the", "caller", "indicates", "or", "until", "the", "polling", "operation", "times", "out", ".", "waitForUn...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L992-L1006
124,469
coreos/fleet
fleetctl/fleetctl.go
waitForSystemdActiveState
func waitForSystemdActiveState(units []string, maxAttempts int) (errch chan error) { errchan := make(chan error) var wg sync.WaitGroup for _, name := range units { wg.Add(1) go checkSystemdActiveState(name, maxAttempts, &wg, errchan) } go func() { wg.Wait() close(errchan) }() return errchan }
go
func waitForSystemdActiveState(units []string, maxAttempts int) (errch chan error) { errchan := make(chan error) var wg sync.WaitGroup for _, name := range units { wg.Add(1) go checkSystemdActiveState(name, maxAttempts, &wg, errchan) } go func() { wg.Wait() close(errchan) }() return errchan }
[ "func", "waitForSystemdActiveState", "(", "units", "[", "]", "string", ",", "maxAttempts", "int", ")", "(", "errch", "chan", "error", ")", "{", "errchan", ":=", "make", "(", "chan", "error", ")", "\n", "var", "wg", "sync", ".", "WaitGroup", "\n", "for", ...
// waitForSystemdActiveState tries to assert that the given unit becomes // active, making use of multiple goroutines that check unit states.
[ "waitForSystemdActiveState", "tries", "to", "assert", "that", "the", "given", "unit", "becomes", "active", "making", "use", "of", "multiple", "goroutines", "that", "check", "unit", "states", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L1093-L1107
124,470
coreos/fleet
fleetctl/fleetctl.go
assertSystemdActiveState
func assertSystemdActiveState(unitName string) error { fetchSystemdActiveState := func() error { us, err := cAPI.UnitState(unitName) if err != nil { return fmt.Errorf("Error getting unit state of %s: %v", unitName, err) } // Get systemd state and check the state is active & loaded. if us.SystemdActiveSta...
go
func assertSystemdActiveState(unitName string) error { fetchSystemdActiveState := func() error { us, err := cAPI.UnitState(unitName) if err != nil { return fmt.Errorf("Error getting unit state of %s: %v", unitName, err) } // Get systemd state and check the state is active & loaded. if us.SystemdActiveSta...
[ "func", "assertSystemdActiveState", "(", "unitName", "string", ")", "error", "{", "fetchSystemdActiveState", ":=", "func", "(", ")", "error", "{", "us", ",", "err", ":=", "cAPI", ".", "UnitState", "(", "unitName", ")", "\n", "if", "err", "!=", "nil", "{", ...
// assertSystemdActiveState determines if a given systemd unit is actually // in the active state, making use of cAPI. // It repeatedly checks up to defaultSleepTimeout. If ActiveState of the given // unit is active and LoadState of the given unit is loaded. // If it cannot get the expected states within the period, re...
[ "assertSystemdActiveState", "determines", "if", "a", "given", "systemd", "unit", "is", "actually", "in", "the", "active", "state", "making", "use", "of", "cAPI", ".", "It", "repeatedly", "checks", "up", "to", "defaultSleepTimeout", ".", "If", "ActiveState", "of"...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L1138-L1159
124,471
coreos/fleet
fleetctl/fleetctl.go
cmdGlobalMachineState
func cmdGlobalMachineState(cCmd *cobra.Command, globalUnits []schema.Unit) (err error) { cmd := cCmd.Name() mapUNs := map[string]string{} for _, unit := range globalUnits { m := cachedMachineState(unit.MachineID) if m == nil || m.ID == "" || m.PublicIP == "" { continue } mapUNs[m.ID] = unit.Name } // c...
go
func cmdGlobalMachineState(cCmd *cobra.Command, globalUnits []schema.Unit) (err error) { cmd := cCmd.Name() mapUNs := map[string]string{} for _, unit := range globalUnits { m := cachedMachineState(unit.MachineID) if m == nil || m.ID == "" || m.PublicIP == "" { continue } mapUNs[m.ID] = unit.Name } // c...
[ "func", "cmdGlobalMachineState", "(", "cCmd", "*", "cobra", ".", "Command", ",", "globalUnits", "[", "]", "schema", ".", "Unit", ")", "(", "err", "error", ")", "{", "cmd", ":=", "cCmd", ".", "Name", "(", ")", "\n", "mapUNs", ":=", "map", "[", "string...
// cmdGlobalMachineState runs a specific fleetctl command on each target machine // where global units are started. To avoid unnecessary ssh connections being // alive, it filters out the list of machines as much as possible.
[ "cmdGlobalMachineState", "runs", "a", "specific", "fleetctl", "command", "on", "each", "target", "machine", "where", "global", "units", "are", "started", ".", "To", "avoid", "unnecessary", "ssh", "connections", "being", "alive", "it", "filters", "out", "the", "l...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/fleetctl/fleetctl.go#L1253-L1280
124,472
coreos/fleet
job/job.go
IsGlobal
func (u *Unit) IsGlobal() bool { j := &Job{ Name: u.Name, Unit: u.Unit, } values := j.requirements()[fleetGlobal] if len(values) == 0 { return false } // Last value found wins last := values[len(values)-1] return isTruthyValue(last) }
go
func (u *Unit) IsGlobal() bool { j := &Job{ Name: u.Name, Unit: u.Unit, } values := j.requirements()[fleetGlobal] if len(values) == 0 { return false } // Last value found wins last := values[len(values)-1] return isTruthyValue(last) }
[ "func", "(", "u", "*", "Unit", ")", "IsGlobal", "(", ")", "bool", "{", "j", ":=", "&", "Job", "{", "Name", ":", "u", ".", "Name", ",", "Unit", ":", "u", ".", "Unit", ",", "}", "\n", "values", ":=", "j", ".", "requirements", "(", ")", "[", "...
// IsGlobal returns whether a Unit is considered a global unit
[ "IsGlobal", "returns", "whether", "a", "Unit", "is", "considered", "a", "global", "unit" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L113-L125
124,473
coreos/fleet
job/job.go
NewJob
func NewJob(name string, unit unit.UnitFile) *Job { return &Job{ Name: name, State: nil, TargetState: JobStateInactive, TargetMachineID: "", Unit: unit, } }
go
func NewJob(name string, unit unit.UnitFile) *Job { return &Job{ Name: name, State: nil, TargetState: JobStateInactive, TargetMachineID: "", Unit: unit, } }
[ "func", "NewJob", "(", "name", "string", ",", "unit", "unit", ".", "UnitFile", ")", "*", "Job", "{", "return", "&", "Job", "{", "Name", ":", "name", ",", "State", ":", "nil", ",", "TargetState", ":", "JobStateInactive", ",", "TargetMachineID", ":", "\"...
// NewJob creates a new Job based on the given name and Unit. // The returned Job has a populated UnitHash and empty JobState. // nil is returned on failure.
[ "NewJob", "creates", "a", "new", "Job", "based", "on", "the", "given", "name", "and", "Unit", ".", "The", "returned", "Job", "has", "a", "populated", "UnitHash", "and", "empty", "JobState", ".", "nil", "is", "returned", "on", "failure", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L130-L138
124,474
coreos/fleet
job/job.go
Conflicts
func (j *Job) Conflicts() []string { conflicts := make([]string, 0) ldConflicts := splitCombine(j.requirements()[deprecatedXPrefix+fleetConflicts]) conflicts = append(conflicts, ldConflicts...) dConflicts := splitCombine(j.requirements()[fleetConflicts]) conflicts = append(conflicts, dConflicts...) return conf...
go
func (j *Job) Conflicts() []string { conflicts := make([]string, 0) ldConflicts := splitCombine(j.requirements()[deprecatedXPrefix+fleetConflicts]) conflicts = append(conflicts, ldConflicts...) dConflicts := splitCombine(j.requirements()[fleetConflicts]) conflicts = append(conflicts, dConflicts...) return conf...
[ "func", "(", "j", "*", "Job", ")", "Conflicts", "(", ")", "[", "]", "string", "{", "conflicts", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n\n", "ldConflicts", ":=", "splitCombine", "(", "j", ".", "requirements", "(", ")", "[", "deprec...
// Conflicts returns a list of Job names that cannot be scheduled to the same // machine as this Job.
[ "Conflicts", "returns", "a", "list", "of", "Job", "names", "that", "cannot", "be", "scheduled", "to", "the", "same", "machine", "as", "this", "Job", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L221-L231
124,475
coreos/fleet
job/job.go
Replaces
func (j *Job) Replaces() []string { replaces := make([]string, 0) replaces = append(replaces, j.requirements()[fleetReplaces]...) return replaces }
go
func (j *Job) Replaces() []string { replaces := make([]string, 0) replaces = append(replaces, j.requirements()[fleetReplaces]...) return replaces }
[ "func", "(", "j", "*", "Job", ")", "Replaces", "(", ")", "[", "]", "string", "{", "replaces", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "replaces", "=", "append", "(", "replaces", ",", "j", ".", "requirements", "(", ")", "[", ...
// Replaces returns a list of Job names that should be scheduled to the another // machine as this Job.
[ "Replaces", "returns", "a", "list", "of", "Job", "names", "that", "should", "be", "scheduled", "to", "the", "another", "machine", "as", "this", "Job", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L235-L239
124,476
coreos/fleet
job/job.go
Peers
func (j *Job) Peers() []string { peers := make([]string, 0) peers = append(peers, j.requirements()[deprecatedXConditionPrefix+fleetMachineOf]...) peers = append(peers, j.requirements()[fleetMachineOf]...) return peers }
go
func (j *Job) Peers() []string { peers := make([]string, 0) peers = append(peers, j.requirements()[deprecatedXConditionPrefix+fleetMachineOf]...) peers = append(peers, j.requirements()[fleetMachineOf]...) return peers }
[ "func", "(", "j", "*", "Job", ")", "Peers", "(", ")", "[", "]", "string", "{", "peers", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "peers", "=", "append", "(", "peers", ",", "j", ".", "requirements", "(", ")", "[", "deprecatedX...
// Peers returns a list of Job names that must be scheduled to the same // machine as this Job.
[ "Peers", "returns", "a", "list", "of", "Job", "names", "that", "must", "be", "scheduled", "to", "the", "same", "machine", "as", "this", "Job", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L243-L248
124,477
coreos/fleet
job/job.go
RequiredTarget
func (j *Job) RequiredTarget() (string, bool) { requirements := j.requirements() var machIDs []string var ok bool // Best case: look for modern declaration machIDs, ok = requirements[fleetMachineID] if ok && len(machIDs) != 0 { return machIDs[0], true } // First fall back to the deprecated syntax machIDs, ...
go
func (j *Job) RequiredTarget() (string, bool) { requirements := j.requirements() var machIDs []string var ok bool // Best case: look for modern declaration machIDs, ok = requirements[fleetMachineID] if ok && len(machIDs) != 0 { return machIDs[0], true } // First fall back to the deprecated syntax machIDs, ...
[ "func", "(", "j", "*", "Job", ")", "RequiredTarget", "(", ")", "(", "string", ",", "bool", ")", "{", "requirements", ":=", "j", ".", "requirements", "(", ")", "\n\n", "var", "machIDs", "[", "]", "string", "\n", "var", "ok", "bool", "\n", "// Best cas...
// RequiredTarget determines whether or not this Job must be scheduled to // a specific machine. If such a requirement exists, the first value returned // represents the ID of such a machine, while the second value will be a bool // true. If no requirement exists, an empty string along with a bool false // will be retu...
[ "RequiredTarget", "determines", "whether", "or", "not", "this", "Job", "must", "be", "scheduled", "to", "a", "specific", "machine", ".", "If", "such", "a", "requirement", "exists", "the", "first", "value", "returned", "represents", "the", "ID", "of", "such", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L255-L282
124,478
coreos/fleet
job/job.go
RequiredTargetMetadata
func (j *Job) RequiredTargetMetadata() map[string]pkg.Set { metadata := make(map[string]pkg.Set) for _, key := range []string{ deprecatedXConditionPrefix + fleetMachineMetadata, fleetMachineMetadata, } { for _, valuePair := range j.requirements()[key] { s := strings.Split(valuePair, "=") if len(s) != 2...
go
func (j *Job) RequiredTargetMetadata() map[string]pkg.Set { metadata := make(map[string]pkg.Set) for _, key := range []string{ deprecatedXConditionPrefix + fleetMachineMetadata, fleetMachineMetadata, } { for _, valuePair := range j.requirements()[key] { s := strings.Split(valuePair, "=") if len(s) != 2...
[ "func", "(", "j", "*", "Job", ")", "RequiredTargetMetadata", "(", ")", "map", "[", "string", "]", "pkg", ".", "Set", "{", "metadata", ":=", "make", "(", "map", "[", "string", "]", "pkg", ".", "Set", ")", "\n\n", "for", "_", ",", "key", ":=", "ran...
// RequiredTargetMetadata return all machine-related metadata from a Job's // requirements. Valid metadata fields are strings of the form `key=value`, // where both key and value are not the empty string.
[ "RequiredTargetMetadata", "return", "all", "machine", "-", "related", "metadata", "from", "a", "Job", "s", "requirements", ".", "Valid", "metadata", "fields", "are", "strings", "of", "the", "form", "key", "=", "value", "where", "both", "key", "and", "value", ...
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L287-L313
124,479
coreos/fleet
job/job.go
isTruthyValue
func isTruthyValue(s string) bool { chl := strings.ToLower(s) return chl == "true" || chl == "yes" || chl == "1" || chl == "on" || chl == "t" }
go
func isTruthyValue(s string) bool { chl := strings.ToLower(s) return chl == "true" || chl == "yes" || chl == "1" || chl == "on" || chl == "t" }
[ "func", "isTruthyValue", "(", "s", "string", ")", "bool", "{", "chl", ":=", "strings", ".", "ToLower", "(", "s", ")", "\n", "return", "chl", "==", "\"", "\"", "||", "chl", "==", "\"", "\"", "||", "chl", "==", "\"", "\"", "||", "chl", "==", "\"", ...
// isTruthyValue returns true if a given string is any of "truthy" value, // i.e. "true", "yes", "1", "on", or "t".
[ "isTruthyValue", "returns", "true", "if", "a", "given", "string", "is", "any", "of", "truthy", "value", "i", ".", "e", ".", "true", "yes", "1", "on", "or", "t", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L336-L339
124,480
coreos/fleet
job/job.go
splitCombine
func splitCombine(inStrs []string) []string { outStrs := make([]string, 0) for _, str := range inStrs { inStrs := strings.Fields(str) outStrs = append(outStrs, inStrs...) } return outStrs }
go
func splitCombine(inStrs []string) []string { outStrs := make([]string, 0) for _, str := range inStrs { inStrs := strings.Fields(str) outStrs = append(outStrs, inStrs...) } return outStrs }
[ "func", "splitCombine", "(", "inStrs", "[", "]", "string", ")", "[", "]", "string", "{", "outStrs", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "str", ":=", "range", "inStrs", "{", "inStrs", ":=", "strings", ".", ...
// splitCombine retrieves each word from an input string slice, to put each // one again into a single slice.
[ "splitCombine", "retrieves", "each", "word", "from", "an", "input", "string", "slice", "to", "put", "each", "one", "again", "into", "a", "single", "slice", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/job/job.go#L343-L350
124,481
coreos/fleet
registry/machine.go
readMachineState
func readMachineState(node *etcd.Node) (mach machine.MachineState, err error) { var metadata map[string]string for _, obj := range node.Nodes { if strings.HasSuffix(obj.Key, "/object") { err = unmarshal(obj.Value, &mach) if err != nil { return } } else if strings.HasSuffix(obj.Key, "/metadata") { ...
go
func readMachineState(node *etcd.Node) (mach machine.MachineState, err error) { var metadata map[string]string for _, obj := range node.Nodes { if strings.HasSuffix(obj.Key, "/object") { err = unmarshal(obj.Value, &mach) if err != nil { return } } else if strings.HasSuffix(obj.Key, "/metadata") { ...
[ "func", "readMachineState", "(", "node", "*", "etcd", ".", "Node", ")", "(", "mach", "machine", ".", "MachineState", ",", "err", "error", ")", "{", "var", "metadata", "map", "[", "string", "]", "string", "\n\n", "for", "_", ",", "obj", ":=", "range", ...
// readMachineState reads machine state from an etcd node
[ "readMachineState", "reads", "machine", "state", "from", "an", "etcd", "node" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/machine.go#L173-L193
124,482
coreos/fleet
registry/event.go
Next
func (es *etcdEventStream) Next(stop chan struct{}) chan pkg.Event { evchan := make(chan pkg.Event) go func() { for { select { case <-stop: return default: } res := watch(es.kAPI, path.Join(es.rootPrefix, jobPrefix), stop) if ev, ok := parse(res, es.rootPrefix); ok { evchan <- ev retu...
go
func (es *etcdEventStream) Next(stop chan struct{}) chan pkg.Event { evchan := make(chan pkg.Event) go func() { for { select { case <-stop: return default: } res := watch(es.kAPI, path.Join(es.rootPrefix, jobPrefix), stop) if ev, ok := parse(res, es.rootPrefix); ok { evchan <- ev retu...
[ "func", "(", "es", "*", "etcdEventStream", ")", "Next", "(", "stop", "chan", "struct", "{", "}", ")", "chan", "pkg", ".", "Event", "{", "evchan", ":=", "make", "(", "chan", "pkg", ".", "Event", ")", "\n", "go", "func", "(", ")", "{", "for", "{", ...
// Next returns a channel which will emit an Event as soon as one of interest occurs
[ "Next", "returns", "a", "channel", "which", "will", "emit", "an", "Event", "as", "soon", "as", "one", "of", "interest", "occurs" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/event.go#L46-L66
124,483
coreos/fleet
registry/rpc/rpcserver.go
SetServingStatus
func (s *rpcserver) SetServingStatus(status pb.HealthCheckResponse_ServingStatus) { s.mu.Lock() s.serverStatus = status s.mu.Unlock() }
go
func (s *rpcserver) SetServingStatus(status pb.HealthCheckResponse_ServingStatus) { s.mu.Lock() s.serverStatus = status s.mu.Unlock() }
[ "func", "(", "s", "*", "rpcserver", ")", "SetServingStatus", "(", "status", "pb", ".", "HealthCheckResponse_ServingStatus", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "s", ".", "serverStatus", "=", "status", "\n", "s", ".", "mu", ".", "Unlo...
// SetServingStatus is called when need to reset the serving status of the service
[ "SetServingStatus", "is", "called", "when", "need", "to", "reset", "the", "serving", "status", "of", "the", "service" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/rpc/rpcserver.go#L117-L121
124,484
coreos/fleet
resource/resource.go
Empty
func (rt ResourceTuple) Empty() bool { return rt.Cores == 0 && rt.Memory == 0 && rt.Disk == 0 }
go
func (rt ResourceTuple) Empty() bool { return rt.Cores == 0 && rt.Memory == 0 && rt.Disk == 0 }
[ "func", "(", "rt", "ResourceTuple", ")", "Empty", "(", ")", "bool", "{", "return", "rt", ".", "Cores", "==", "0", "&&", "rt", ".", "Memory", "==", "0", "&&", "rt", ".", "Disk", "==", "0", "\n", "}" ]
// Empty returns true if all components of the ResourceTuple are zero.
[ "Empty", "returns", "true", "if", "all", "components", "of", "the", "ResourceTuple", "are", "zero", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/resource/resource.go#L29-L31
124,485
coreos/fleet
resource/resource.go
Sum
func Sum(resources ...ResourceTuple) (res ResourceTuple) { for _, r := range resources { res.Cores += r.Cores res.Memory += r.Memory res.Disk += r.Disk } return }
go
func Sum(resources ...ResourceTuple) (res ResourceTuple) { for _, r := range resources { res.Cores += r.Cores res.Memory += r.Memory res.Disk += r.Disk } return }
[ "func", "Sum", "(", "resources", "...", "ResourceTuple", ")", "(", "res", "ResourceTuple", ")", "{", "for", "_", ",", "r", ":=", "range", "resources", "{", "res", ".", "Cores", "+=", "r", ".", "Cores", "\n", "res", ".", "Memory", "+=", "r", ".", "M...
// Sum aggregates a number of ResourceTuples into a single entity
[ "Sum", "aggregates", "a", "number", "of", "ResourceTuples", "into", "a", "single", "entity" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/resource/resource.go#L49-L56
124,486
coreos/fleet
resource/resource.go
Sub
func Sub(r1, r2 ResourceTuple) (res ResourceTuple) { res.Cores = r1.Cores - r2.Cores res.Memory = r1.Memory - r2.Memory res.Disk = r1.Disk - r2.Disk return }
go
func Sub(r1, r2 ResourceTuple) (res ResourceTuple) { res.Cores = r1.Cores - r2.Cores res.Memory = r1.Memory - r2.Memory res.Disk = r1.Disk - r2.Disk return }
[ "func", "Sub", "(", "r1", ",", "r2", "ResourceTuple", ")", "(", "res", "ResourceTuple", ")", "{", "res", ".", "Cores", "=", "r1", ".", "Cores", "-", "r2", ".", "Cores", "\n", "res", ".", "Memory", "=", "r1", ".", "Memory", "-", "r2", ".", "Memory...
// Sub returns a ResourceTuple representing the difference between two // ResourceTuples
[ "Sub", "returns", "a", "ResourceTuple", "representing", "the", "difference", "between", "two", "ResourceTuples" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/resource/resource.go#L60-L65
124,487
coreos/fleet
ssh/ssh.go
Shell
func Shell(client *SSHForwardingClient) error { session, finalize, err := makeSession(client) if err != nil { return err } defer finalize() if err = session.Shell(); err != nil { return err } session.Wait() return nil }
go
func Shell(client *SSHForwardingClient) error { session, finalize, err := makeSession(client) if err != nil { return err } defer finalize() if err = session.Shell(); err != nil { return err } session.Wait() return nil }
[ "func", "Shell", "(", "client", "*", "SSHForwardingClient", ")", "error", "{", "session", ",", "finalize", ",", "err", ":=", "makeSession", "(", "client", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "finalize", ...
// Shell launches an interactive shell on the given client. It returns any // error encountered in setting up the SSH session.
[ "Shell", "launches", "an", "interactive", "shell", "on", "the", "given", "client", ".", "It", "returns", "any", "error", "encountered", "in", "setting", "up", "the", "SSH", "session", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/ssh.go#L143-L157
124,488
coreos/fleet
ssh/ssh.go
SSHAgentClient
func SSHAgentClient() (gosshagent.Agent, error) { sock := os.Getenv("SSH_AUTH_SOCK") if sock == "" { return nil, errors.New("SSH_AUTH_SOCK environment variable is not set. Verify ssh-agent is running. See https://github.com/coreos/fleet/blob/master/Documentation/using-the-client.md for help.") } agent, err := ne...
go
func SSHAgentClient() (gosshagent.Agent, error) { sock := os.Getenv("SSH_AUTH_SOCK") if sock == "" { return nil, errors.New("SSH_AUTH_SOCK environment variable is not set. Verify ssh-agent is running. See https://github.com/coreos/fleet/blob/master/Documentation/using-the-client.md for help.") } agent, err := ne...
[ "func", "SSHAgentClient", "(", ")", "(", "gosshagent", ".", "Agent", ",", "error", ")", "{", "sock", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "sock", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\""...
// SSHAgentClient returns an Agent that talks to the local ssh-agent
[ "SSHAgentClient", "returns", "an", "Agent", "that", "talks", "to", "the", "local", "ssh", "-", "agent" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/ssh/ssh.go#L160-L172
124,489
coreos/fleet
unit/unit.go
MatchUnitFiles
func MatchUnitFiles(a *UnitFile, b *UnitFile) bool { if a.Hash() == b.Hash() { return true } return false }
go
func MatchUnitFiles(a *UnitFile, b *UnitFile) bool { if a.Hash() == b.Hash() { return true } return false }
[ "func", "MatchUnitFiles", "(", "a", "*", "UnitFile", ",", "b", "*", "UnitFile", ")", "bool", "{", "if", "a", ".", "Hash", "(", ")", "==", "b", ".", "Hash", "(", ")", "{", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// MatchUnitFiles compares two unitFiles // Returns true if the units match, false otherwise.
[ "MatchUnitFiles", "compares", "two", "unitFiles", "Returns", "true", "if", "the", "units", "match", "false", "otherwise", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/unit/unit.go#L141-L147
124,490
coreos/fleet
unit/unit.go
RecognizedUnitType
func RecognizedUnitType(name string) bool { types := []string{"service", "socket", "timer", "path", "device", "mount", "automount"} for _, t := range types { suffix := fmt.Sprintf(".%s", t) if strings.HasSuffix(name, suffix) { return true } } return false }
go
func RecognizedUnitType(name string) bool { types := []string{"service", "socket", "timer", "path", "device", "mount", "automount"} for _, t := range types { suffix := fmt.Sprintf(".%s", t) if strings.HasSuffix(name, suffix) { return true } } return false }
[ "func", "RecognizedUnitType", "(", "name", "string", ")", "bool", "{", "types", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "for", ...
// RecognizedUnitType determines whether or not the given unit name represents // a recognized unit type.
[ "RecognizedUnitType", "determines", "whether", "or", "not", "the", "given", "unit", "name", "represents", "a", "recognized", "unit", "type", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/unit/unit.go#L151-L160
124,491
coreos/fleet
unit/unit.go
NewUnitNameInfo
func NewUnitNameInfo(un string) *UnitNameInfo { // Everything past the first @ and before the last . is the instance s := strings.LastIndex(un, ".") if s == -1 { return nil } nu := &UnitNameInfo{FullName: un} name := un[:s] suffix := un[s:] nu.Name = name a := strings.Index(name, "@") if a == -1 { // T...
go
func NewUnitNameInfo(un string) *UnitNameInfo { // Everything past the first @ and before the last . is the instance s := strings.LastIndex(un, ".") if s == -1 { return nil } nu := &UnitNameInfo{FullName: un} name := un[:s] suffix := un[s:] nu.Name = name a := strings.Index(name, "@") if a == -1 { // T...
[ "func", "NewUnitNameInfo", "(", "un", "string", ")", "*", "UnitNameInfo", "{", "// Everything past the first @ and before the last . is the instance", "s", ":=", "strings", ".", "LastIndex", "(", "un", ",", "\"", "\"", ")", "\n", "if", "s", "==", "-", "1", "{", ...
// NewUnitNameInfo generates a UnitNameInfo from the given name. If the given string // is not a correct unit name, nil is returned.
[ "NewUnitNameInfo", "generates", "a", "UnitNameInfo", "from", "the", "given", "name", ".", "If", "the", "given", "string", "is", "not", "a", "correct", "unit", "name", "nil", "is", "returned", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/unit/unit.go#L243-L267
124,492
coreos/fleet
schema/v1-gen.go
Do
func (c *UnitsSetCall) Do(opts ...googleapi.CallOption) error { gensupport.SetOptions(c.urlParams_, opts...) res, err := c.doRequest("json") if err != nil { return err } defer googleapi.CloseBody(res) if err := googleapi.CheckResponse(res); err != nil { return err } return nil // { // "description": "Cr...
go
func (c *UnitsSetCall) Do(opts ...googleapi.CallOption) error { gensupport.SetOptions(c.urlParams_, opts...) res, err := c.doRequest("json") if err != nil { return err } defer googleapi.CloseBody(res) if err := googleapi.CheckResponse(res); err != nil { return err } return nil // { // "description": "Cr...
[ "func", "(", "c", "*", "UnitsSetCall", ")", "Do", "(", "opts", "...", "googleapi", ".", "CallOption", ")", "error", "{", "gensupport", ".", "SetOptions", "(", "c", ".", "urlParams_", ",", "opts", "...", ")", "\n", "res", ",", "err", ":=", "c", ".", ...
// Do executes the "fleet.Unit.Set" call.
[ "Do", "executes", "the", "fleet", ".", "Unit", ".", "Set", "call", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/schema/v1-gen.go#L1197-L1228
124,493
coreos/fleet
systemd/manager.go
Load
func (m *systemdUnitManager) Load(name string, u unit.UnitFile) error { m.mutex.Lock() defer m.mutex.Unlock() err := m.writeUnit(name, u.String()) if err != nil { return err } if _, exists := u.Contents["Install"]; exists { log.Debugf("Detected [Install] section in the systemd unit (%s)", name) ok, err := m...
go
func (m *systemdUnitManager) Load(name string, u unit.UnitFile) error { m.mutex.Lock() defer m.mutex.Unlock() err := m.writeUnit(name, u.String()) if err != nil { return err } if _, exists := u.Contents["Install"]; exists { log.Debugf("Detected [Install] section in the systemd unit (%s)", name) ok, err := m...
[ "func", "(", "m", "*", "systemdUnitManager", ")", "Load", "(", "name", "string", ",", "u", "unit", ".", "UnitFile", ")", "error", "{", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n", "err...
// Load writes the given Unit to disk, subscribing to relevant dbus // events and caching the Unit's Hash.
[ "Load", "writes", "the", "given", "Unit", "to", "disk", "subscribing", "to", "relevant", "dbus", "events", "and", "caching", "the", "Unit", "s", "Hash", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/systemd/manager.go#L104-L121
124,494
coreos/fleet
systemd/manager.go
Unload
func (m *systemdUnitManager) Unload(name string) error { m.mutex.Lock() defer m.mutex.Unlock() delete(m.hashes, name) return m.removeUnit(name) }
go
func (m *systemdUnitManager) Unload(name string) error { m.mutex.Lock() defer m.mutex.Unlock() delete(m.hashes, name) return m.removeUnit(name) }
[ "func", "(", "m", "*", "systemdUnitManager", ")", "Unload", "(", "name", "string", ")", "error", "{", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n", "delete", "(", "m", ".", "hashes", ",...
// Unload removes the indicated unit from the filesystem, deletes its // associated Hash from the cache and clears its unit status in systemd
[ "Unload", "removes", "the", "indicated", "unit", "from", "the", "filesystem", "deletes", "its", "associated", "Hash", "from", "the", "cache", "and", "clears", "its", "unit", "status", "in", "systemd" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/systemd/manager.go#L125-L130
124,495
coreos/fleet
systemd/manager.go
TriggerStart
func (m *systemdUnitManager) TriggerStart(name string) error { jobID, err := m.systemd.StartUnit(name, "replace", nil) if err != nil { log.Errorf("Failed to trigger systemd unit %s start: %v", name, err) return err } log.Infof("Triggered systemd unit %s start: job=%d", name, jobID) return nil }
go
func (m *systemdUnitManager) TriggerStart(name string) error { jobID, err := m.systemd.StartUnit(name, "replace", nil) if err != nil { log.Errorf("Failed to trigger systemd unit %s start: %v", name, err) return err } log.Infof("Triggered systemd unit %s start: job=%d", name, jobID) return nil }
[ "func", "(", "m", "*", "systemdUnitManager", ")", "TriggerStart", "(", "name", "string", ")", "error", "{", "jobID", ",", "err", ":=", "m", ".", "systemd", ".", "StartUnit", "(", "name", ",", "\"", "\"", ",", "nil", ")", "\n", "if", "err", "!=", "n...
// TriggerStart asynchronously starts the unit identified by the given name. // This function does not block for the underlying unit to actually start.
[ "TriggerStart", "asynchronously", "starts", "the", "unit", "identified", "by", "the", "given", "name", ".", "This", "function", "does", "not", "block", "for", "the", "underlying", "unit", "to", "actually", "start", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/systemd/manager.go#L134-L142
124,496
coreos/fleet
systemd/manager.go
TriggerStop
func (m *systemdUnitManager) TriggerStop(name string) error { jobID, err := m.systemd.StopUnit(name, "replace", nil) if err != nil { log.Errorf("Failed to trigger systemd unit %s stop: %v", name, err) return err } log.Infof("Triggered systemd unit %s stop: job=%d", name, jobID) return nil }
go
func (m *systemdUnitManager) TriggerStop(name string) error { jobID, err := m.systemd.StopUnit(name, "replace", nil) if err != nil { log.Errorf("Failed to trigger systemd unit %s stop: %v", name, err) return err } log.Infof("Triggered systemd unit %s stop: job=%d", name, jobID) return nil }
[ "func", "(", "m", "*", "systemdUnitManager", ")", "TriggerStop", "(", "name", "string", ")", "error", "{", "jobID", ",", "err", ":=", "m", ".", "systemd", ".", "StopUnit", "(", "name", ",", "\"", "\"", ",", "nil", ")", "\n", "if", "err", "!=", "nil...
// TriggerStop asynchronously starts the unit identified by the given name. // This function does not block for the underlying unit to actually stop.
[ "TriggerStop", "asynchronously", "starts", "the", "unit", "identified", "by", "the", "given", "name", ".", "This", "function", "does", "not", "block", "for", "the", "underlying", "unit", "to", "actually", "stop", "." ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/systemd/manager.go#L146-L154
124,497
coreos/fleet
systemd/manager.go
GetUnitState
func (m *systemdUnitManager) GetUnitState(name string) (*unit.UnitState, error) { m.mutex.Lock() defer m.mutex.Unlock() us, err := m.getUnitState(name) if err != nil { return nil, err } if h, ok := m.hashes[name]; ok { us.UnitHash = h.String() } return us, nil }
go
func (m *systemdUnitManager) GetUnitState(name string) (*unit.UnitState, error) { m.mutex.Lock() defer m.mutex.Unlock() us, err := m.getUnitState(name) if err != nil { return nil, err } if h, ok := m.hashes[name]; ok { us.UnitHash = h.String() } return us, nil }
[ "func", "(", "m", "*", "systemdUnitManager", ")", "GetUnitState", "(", "name", "string", ")", "(", "*", "unit", ".", "UnitState", ",", "error", ")", "{", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "Unlock", "("...
// GetUnitState generates a UnitState object representing the // current state of a Unit
[ "GetUnitState", "generates", "a", "UnitState", "object", "representing", "the", "current", "state", "of", "a", "Unit" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/systemd/manager.go#L158-L169
124,498
coreos/fleet
registry/version.go
EngineVersion
func (r *EtcdRegistry) EngineVersion() (int, error) { res, err := r.kAPI.Get(context.Background(), r.engineVersionPath(), nil) if err != nil { // no big deal, either the cluster is new or is just // upgrading from old unversioned code if isEtcdError(err, etcd.ErrorCodeKeyNotFound) { err = nil } return 0,...
go
func (r *EtcdRegistry) EngineVersion() (int, error) { res, err := r.kAPI.Get(context.Background(), r.engineVersionPath(), nil) if err != nil { // no big deal, either the cluster is new or is just // upgrading from old unversioned code if isEtcdError(err, etcd.ErrorCodeKeyNotFound) { err = nil } return 0,...
[ "func", "(", "r", "*", "EtcdRegistry", ")", "EngineVersion", "(", ")", "(", "int", ",", "error", ")", "{", "res", ",", "err", ":=", "r", ".", "kAPI", ".", "Get", "(", "context", ".", "Background", "(", ")", ",", "r", ".", "engineVersionPath", "(", ...
// EngineVersion implements the ClusterRegistry interface
[ "EngineVersion", "implements", "the", "ClusterRegistry", "interface" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/version.go#L49-L61
124,499
coreos/fleet
registry/version.go
UpdateEngineVersion
func (r *EtcdRegistry) UpdateEngineVersion(from, to int) error { key := r.engineVersionPath() strTo := strconv.Itoa(to) strFrom := strconv.Itoa(from) opts := &etcd.SetOptions{ PrevValue: strFrom, } _, err := r.kAPI.Set(context.Background(), key, strTo, opts) if err == nil { return nil } else if !isEtcdErr...
go
func (r *EtcdRegistry) UpdateEngineVersion(from, to int) error { key := r.engineVersionPath() strTo := strconv.Itoa(to) strFrom := strconv.Itoa(from) opts := &etcd.SetOptions{ PrevValue: strFrom, } _, err := r.kAPI.Set(context.Background(), key, strTo, opts) if err == nil { return nil } else if !isEtcdErr...
[ "func", "(", "r", "*", "EtcdRegistry", ")", "UpdateEngineVersion", "(", "from", ",", "to", "int", ")", "error", "{", "key", ":=", "r", ".", "engineVersionPath", "(", ")", "\n\n", "strTo", ":=", "strconv", ".", "Itoa", "(", "to", ")", "\n", "strFrom", ...
// UpdateEngineVersion implements the ClusterRegistry interface
[ "UpdateEngineVersion", "implements", "the", "ClusterRegistry", "interface" ]
4522498327e92ffe6fa24eaa087c73e5af4adb53
https://github.com/coreos/fleet/blob/4522498327e92ffe6fa24eaa087c73e5af4adb53/registry/version.go#L64-L85