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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
cloudfoundry/cli | api/cloudcontroller/cloud_controller_connection.go | NewConnection | func NewConnection(config Config) *CloudControllerConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: config.SkipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: config.DialTimeout,
}).DialContext,
}
return &CloudControllerConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | go | func NewConnection(config Config) *CloudControllerConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: config.SkipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: config.DialTimeout,
}).DialContext,
}
return &CloudControllerConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | [
"func",
"NewConnection",
"(",
"config",
"Config",
")",
"*",
"CloudControllerConnection",
"{",
"tr",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"config",
".",
"SkipSSLValidation",
",",
"}",
",",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"DialContext",
":",
"(",
"&",
"net",
".",
"Dialer",
"{",
"KeepAlive",
":",
"30",
"*",
"time",
".",
"Second",
",",
"Timeout",
":",
"config",
".",
"DialTimeout",
",",
"}",
")",
".",
"DialContext",
",",
"}",
"\n\n",
"return",
"&",
"CloudControllerConnection",
"{",
"HTTPClient",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"tr",
"}",
",",
"}",
"\n",
"}"
] | // NewConnection returns a new CloudControllerConnection with provided
// configuration. | [
"NewConnection",
"returns",
"a",
"new",
"CloudControllerConnection",
"with",
"provided",
"configuration",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/cloud_controller_connection.go#L31-L46 | train |
cloudfoundry/cli | api/cloudcontroller/cloud_controller_connection.go | handleWarnings | func (*CloudControllerConnection) handleWarnings(response *http.Response) ([]string, error) {
rawWarnings := response.Header.Get("X-Cf-Warnings")
if len(rawWarnings) == 0 {
return nil, nil
}
var warnings []string
for _, rawWarning := range strings.Split(rawWarnings, ",") {
warning, err := url.QueryUnescape(rawWarning)
if err != nil {
return nil, err
}
warnings = append(warnings, strings.Trim(warning, " "))
}
return warnings, nil
} | go | func (*CloudControllerConnection) handleWarnings(response *http.Response) ([]string, error) {
rawWarnings := response.Header.Get("X-Cf-Warnings")
if len(rawWarnings) == 0 {
return nil, nil
}
var warnings []string
for _, rawWarning := range strings.Split(rawWarnings, ",") {
warning, err := url.QueryUnescape(rawWarning)
if err != nil {
return nil, err
}
warnings = append(warnings, strings.Trim(warning, " "))
}
return warnings, nil
} | [
"func",
"(",
"*",
"CloudControllerConnection",
")",
"handleWarnings",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"rawWarnings",
":=",
"response",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"rawWarnings",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"warnings",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"rawWarning",
":=",
"range",
"strings",
".",
"Split",
"(",
"rawWarnings",
",",
"\"",
"\"",
")",
"{",
"warning",
",",
"err",
":=",
"url",
".",
"QueryUnescape",
"(",
"rawWarning",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"warnings",
"=",
"append",
"(",
"warnings",
",",
"strings",
".",
"Trim",
"(",
"warning",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"return",
"warnings",
",",
"nil",
"\n",
"}"
] | // handleWarnings looks for the "X-Cf-Warnings" header in the cloud controller
// response and URI decodes them. The value can contain multiple warnings that
// are comma separated. | [
"handleWarnings",
"looks",
"for",
"the",
"X",
"-",
"Cf",
"-",
"Warnings",
"header",
"in",
"the",
"cloud",
"controller",
"response",
"and",
"URI",
"decodes",
"them",
".",
"The",
"value",
"can",
"contain",
"multiple",
"warnings",
"that",
"are",
"comma",
"separated",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/cloud_controller_connection.go#L90-L106 | train |
cloudfoundry/cli | cf/actors/push.go | ProcessPath | func (actor PushActorImpl) ProcessPath(dirOrZipFile string, f func(string) error) error {
if !actor.zipper.IsZipFile(dirOrZipFile) {
if filepath.IsAbs(dirOrZipFile) {
appDir, err := filepath.EvalSymlinks(dirOrZipFile)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
} else {
absPath, err := filepath.Abs(dirOrZipFile)
if err != nil {
return err
}
appDir, err := filepath.EvalSymlinks(absPath)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
}
return nil
}
tempDir, err := ioutil.TempDir("", "unzipped-app")
if err != nil {
return err
}
err = actor.zipper.Unzip(dirOrZipFile, tempDir)
if err != nil {
return err
}
err = f(tempDir)
if err != nil {
return err
}
err = os.RemoveAll(tempDir)
if err != nil {
return err
}
return nil
} | go | func (actor PushActorImpl) ProcessPath(dirOrZipFile string, f func(string) error) error {
if !actor.zipper.IsZipFile(dirOrZipFile) {
if filepath.IsAbs(dirOrZipFile) {
appDir, err := filepath.EvalSymlinks(dirOrZipFile)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
} else {
absPath, err := filepath.Abs(dirOrZipFile)
if err != nil {
return err
}
appDir, err := filepath.EvalSymlinks(absPath)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
}
return nil
}
tempDir, err := ioutil.TempDir("", "unzipped-app")
if err != nil {
return err
}
err = actor.zipper.Unzip(dirOrZipFile, tempDir)
if err != nil {
return err
}
err = f(tempDir)
if err != nil {
return err
}
err = os.RemoveAll(tempDir)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"actor",
"PushActorImpl",
")",
"ProcessPath",
"(",
"dirOrZipFile",
"string",
",",
"f",
"func",
"(",
"string",
")",
"error",
")",
"error",
"{",
"if",
"!",
"actor",
".",
"zipper",
".",
"IsZipFile",
"(",
"dirOrZipFile",
")",
"{",
"if",
"filepath",
".",
"IsAbs",
"(",
"dirOrZipFile",
")",
"{",
"appDir",
",",
"err",
":=",
"filepath",
".",
"EvalSymlinks",
"(",
"dirOrZipFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"f",
"(",
"appDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"absPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"dirOrZipFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"appDir",
",",
"err",
":=",
"filepath",
".",
"EvalSymlinks",
"(",
"absPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"f",
"(",
"appDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"tempDir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"actor",
".",
"zipper",
".",
"Unzip",
"(",
"dirOrZipFile",
",",
"tempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"f",
"(",
"tempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"os",
".",
"RemoveAll",
"(",
"tempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // ProcessPath takes in a director of app files or a zip file which contains
// the app files. If given a zip file, it will extract the zip to a temporary
// location, call the provided callback with that location, and then clean up
// the location after the callback has been executed.
//
// This was done so that the caller of ProcessPath wouldn't need to know if it
// was a zip file or an app dir that it was given, and the caller would not be
// responsible for cleaning up the temporary directory ProcessPath creates when
// given a zip. | [
"ProcessPath",
"takes",
"in",
"a",
"director",
"of",
"app",
"files",
"or",
"a",
"zip",
"file",
"which",
"contains",
"the",
"app",
"files",
".",
"If",
"given",
"a",
"zip",
"file",
"it",
"will",
"extract",
"the",
"zip",
"to",
"a",
"temporary",
"location",
"call",
"the",
"provided",
"callback",
"with",
"that",
"location",
"and",
"then",
"clean",
"up",
"the",
"location",
"after",
"the",
"callback",
"has",
"been",
"executed",
".",
"This",
"was",
"done",
"so",
"that",
"the",
"caller",
"of",
"ProcessPath",
"wouldn",
"t",
"need",
"to",
"know",
"if",
"it",
"was",
"a",
"zip",
"file",
"or",
"an",
"app",
"dir",
"that",
"it",
"was",
"given",
"and",
"the",
"caller",
"would",
"not",
"be",
"responsible",
"for",
"cleaning",
"up",
"the",
"temporary",
"directory",
"ProcessPath",
"creates",
"when",
"given",
"a",
"zip",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/cf/actors/push.go#L55-L106 | train |
cloudfoundry/cli | actor/sharedaction/is_logged_in.go | IsLoggedIn | func (actor Actor) IsLoggedIn() bool {
return actor.Config.AccessToken() != "" || actor.Config.RefreshToken() != ""
} | go | func (actor Actor) IsLoggedIn() bool {
return actor.Config.AccessToken() != "" || actor.Config.RefreshToken() != ""
} | [
"func",
"(",
"actor",
"Actor",
")",
"IsLoggedIn",
"(",
")",
"bool",
"{",
"return",
"actor",
".",
"Config",
".",
"AccessToken",
"(",
")",
"!=",
"\"",
"\"",
"||",
"actor",
".",
"Config",
".",
"RefreshToken",
"(",
")",
"!=",
"\"",
"\"",
"\n",
"}"
] | // IsLoggedIn checks whether a user has authenticated with CF | [
"IsLoggedIn",
"checks",
"whether",
"a",
"user",
"has",
"authenticated",
"with",
"CF"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/sharedaction/is_logged_in.go#L4-L6 | train |
cloudfoundry/cli | api/plugin/request.go | newGETRequest | func (client *Client) newGETRequest(url string) (*http.Request, error) {
request, err := http.NewRequest(
http.MethodGet,
url,
nil,
)
if err != nil {
return nil, err
}
request.Header = http.Header{}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("User-Agent", client.userAgent)
return request, nil
} | go | func (client *Client) newGETRequest(url string) (*http.Request, error) {
request, err := http.NewRequest(
http.MethodGet,
url,
nil,
)
if err != nil {
return nil, err
}
request.Header = http.Header{}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("User-Agent", client.userAgent)
return request, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"newGETRequest",
"(",
"url",
"string",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodGet",
",",
"url",
",",
"nil",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"request",
".",
"Header",
"=",
"http",
".",
"Header",
"{",
"}",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"client",
".",
"userAgent",
")",
"\n\n",
"return",
"request",
",",
"nil",
"\n",
"}"
] | // newGETRequest returns a constructed HTTP.Request with some defaults.
// Defaults are applied when Request options are not filled in. | [
"newGETRequest",
"returns",
"a",
"constructed",
"HTTP",
".",
"Request",
"with",
"some",
"defaults",
".",
"Defaults",
"are",
"applied",
"when",
"Request",
"options",
"are",
"not",
"filled",
"in",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/plugin/request.go#L7-L23 | train |
cloudfoundry/cli | api/cloudcontroller/minimum_version_check.go | MinimumAPIVersionCheck | func MinimumAPIVersionCheck(current string, minimum string) error {
if minimum == "" {
return nil
}
currentSemver, err := semver.Make(current)
if err != nil {
return err
}
minimumSemver, err := semver.Make(minimum)
if err != nil {
return err
}
if currentSemver.Compare(minimumSemver) == -1 {
return ccerror.MinimumAPIVersionNotMetError{
CurrentVersion: current,
MinimumVersion: minimum,
}
}
return nil
} | go | func MinimumAPIVersionCheck(current string, minimum string) error {
if minimum == "" {
return nil
}
currentSemver, err := semver.Make(current)
if err != nil {
return err
}
minimumSemver, err := semver.Make(minimum)
if err != nil {
return err
}
if currentSemver.Compare(minimumSemver) == -1 {
return ccerror.MinimumAPIVersionNotMetError{
CurrentVersion: current,
MinimumVersion: minimum,
}
}
return nil
} | [
"func",
"MinimumAPIVersionCheck",
"(",
"current",
"string",
",",
"minimum",
"string",
")",
"error",
"{",
"if",
"minimum",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"currentSemver",
",",
"err",
":=",
"semver",
".",
"Make",
"(",
"current",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"minimumSemver",
",",
"err",
":=",
"semver",
".",
"Make",
"(",
"minimum",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"currentSemver",
".",
"Compare",
"(",
"minimumSemver",
")",
"==",
"-",
"1",
"{",
"return",
"ccerror",
".",
"MinimumAPIVersionNotMetError",
"{",
"CurrentVersion",
":",
"current",
",",
"MinimumVersion",
":",
"minimum",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // MinimumAPIVersionCheck compares `current` to `minimum`. If `current` is
// older than `minimum` then an error is returned; otherwise, nil is returned. | [
"MinimumAPIVersionCheck",
"compares",
"current",
"to",
"minimum",
".",
"If",
"current",
"is",
"older",
"than",
"minimum",
"then",
"an",
"error",
"is",
"returned",
";",
"otherwise",
"nil",
"is",
"returned",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/minimum_version_check.go#L10-L33 | train |
cloudfoundry/cli | util/ui/request_logger_file_writer.go | RequestLoggerFileWriter | func (ui *UI) RequestLoggerFileWriter(filePaths []string) *RequestLoggerFileWriter {
return newRequestLoggerFileWriter(ui, ui.fileLock, filePaths)
} | go | func (ui *UI) RequestLoggerFileWriter(filePaths []string) *RequestLoggerFileWriter {
return newRequestLoggerFileWriter(ui, ui.fileLock, filePaths)
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"RequestLoggerFileWriter",
"(",
"filePaths",
"[",
"]",
"string",
")",
"*",
"RequestLoggerFileWriter",
"{",
"return",
"newRequestLoggerFileWriter",
"(",
"ui",
",",
"ui",
".",
"fileLock",
",",
"filePaths",
")",
"\n",
"}"
] | // RequestLoggerFileWriter returns a RequestLoggerFileWriter that cannot
// overwrite another RequestLoggerFileWriter. | [
"RequestLoggerFileWriter",
"returns",
"a",
"RequestLoggerFileWriter",
"that",
"cannot",
"overwrite",
"another",
"RequestLoggerFileWriter",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/request_logger_file_writer.go#L142-L144 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/stack.go | UnmarshalJSON | func (stack *Stack) UnmarshalJSON(data []byte) error {
var ccStack struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
Description string `json:"description"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccStack)
if err != nil {
return err
}
stack.GUID = ccStack.Metadata.GUID
stack.Name = ccStack.Entity.Name
stack.Description = ccStack.Entity.Description
return nil
} | go | func (stack *Stack) UnmarshalJSON(data []byte) error {
var ccStack struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
Description string `json:"description"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccStack)
if err != nil {
return err
}
stack.GUID = ccStack.Metadata.GUID
stack.Name = ccStack.Entity.Name
stack.Description = ccStack.Entity.Description
return nil
} | [
"func",
"(",
"stack",
"*",
"Stack",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccStack",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"`json:\"metadata\"`",
"\n",
"Entity",
"struct",
"{",
"Name",
"string",
"`json:\"name\"`",
"\n",
"Description",
"string",
"`json:\"description\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccStack",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"stack",
".",
"GUID",
"=",
"ccStack",
".",
"Metadata",
".",
"GUID",
"\n",
"stack",
".",
"Name",
"=",
"ccStack",
".",
"Entity",
".",
"Name",
"\n",
"stack",
".",
"Description",
"=",
"ccStack",
".",
"Entity",
".",
"Description",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Stack response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Stack",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/stack.go#L22-L39 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/stack.go | GetStack | func (client *Client) GetStack(guid string) (Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStackRequest,
URIParams: Params{"stack_guid": guid},
})
if err != nil {
return Stack{}, nil, err
}
var stack Stack
response := cloudcontroller.Response{
DecodeJSONResponseInto: &stack,
}
err = client.connection.Make(request, &response)
return stack, response.Warnings, err
} | go | func (client *Client) GetStack(guid string) (Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStackRequest,
URIParams: Params{"stack_guid": guid},
})
if err != nil {
return Stack{}, nil, err
}
var stack Stack
response := cloudcontroller.Response{
DecodeJSONResponseInto: &stack,
}
err = client.connection.Make(request, &response)
return stack, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetStack",
"(",
"guid",
"string",
")",
"(",
"Stack",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetStackRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"",
"\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Stack",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"stack",
"Stack",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"stack",
",",
"}",
"\n\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"stack",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetStack returns the requested stack. | [
"GetStack",
"returns",
"the",
"requested",
"stack",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/stack.go#L42-L58 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/stack.go | GetStacks | func (client *Client) GetStacks(filters ...Filter) ([]Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStacksRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullStacksList []Stack
warnings, err := client.paginate(request, Stack{}, func(item interface{}) error {
if space, ok := item.(Stack); ok {
fullStacksList = append(fullStacksList, space)
} else {
return ccerror.UnknownObjectInListError{
Expected: Stack{},
Unexpected: item,
}
}
return nil
})
return fullStacksList, warnings, err
} | go | func (client *Client) GetStacks(filters ...Filter) ([]Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStacksRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullStacksList []Stack
warnings, err := client.paginate(request, Stack{}, func(item interface{}) error {
if space, ok := item.(Stack); ok {
fullStacksList = append(fullStacksList, space)
} else {
return ccerror.UnknownObjectInListError{
Expected: Stack{},
Unexpected: item,
}
}
return nil
})
return fullStacksList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetStacks",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"Stack",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetStacksRequest",
",",
"Query",
":",
"ConvertFilterParameters",
"(",
"filters",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"fullStacksList",
"[",
"]",
"Stack",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Stack",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"space",
",",
"ok",
":=",
"item",
".",
"(",
"Stack",
")",
";",
"ok",
"{",
"fullStacksList",
"=",
"append",
"(",
"fullStacksList",
",",
"space",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Stack",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"fullStacksList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetStacks returns a list of Stacks based off of the provided filters. | [
"GetStacks",
"returns",
"a",
"list",
"of",
"Stacks",
"based",
"off",
"of",
"the",
"provided",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/stack.go#L61-L84 | train |
cloudfoundry/cli | api/cloudcontroller/wrapper/uaa_authentication.go | refreshToken | func (t *UAAAuthentication) refreshToken() error {
var expiresIn time.Duration
tokenStr := strings.TrimPrefix(t.cache.AccessToken(), "bearer ")
token, err := jws.ParseJWT([]byte(tokenStr))
if err != nil {
// if the JWT could not be parsed, force a refresh
expiresIn = 0
} else {
expiration, _ := token.Claims().Expiration()
expiresIn = time.Until(expiration)
}
if expiresIn < accessTokenExpirationMargin {
tokens, err := t.client.RefreshAccessToken(t.cache.RefreshToken())
if err != nil {
return err
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
}
return nil
} | go | func (t *UAAAuthentication) refreshToken() error {
var expiresIn time.Duration
tokenStr := strings.TrimPrefix(t.cache.AccessToken(), "bearer ")
token, err := jws.ParseJWT([]byte(tokenStr))
if err != nil {
// if the JWT could not be parsed, force a refresh
expiresIn = 0
} else {
expiration, _ := token.Claims().Expiration()
expiresIn = time.Until(expiration)
}
if expiresIn < accessTokenExpirationMargin {
tokens, err := t.client.RefreshAccessToken(t.cache.RefreshToken())
if err != nil {
return err
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
}
return nil
} | [
"func",
"(",
"t",
"*",
"UAAAuthentication",
")",
"refreshToken",
"(",
")",
"error",
"{",
"var",
"expiresIn",
"time",
".",
"Duration",
"\n\n",
"tokenStr",
":=",
"strings",
".",
"TrimPrefix",
"(",
"t",
".",
"cache",
".",
"AccessToken",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"token",
",",
"err",
":=",
"jws",
".",
"ParseJWT",
"(",
"[",
"]",
"byte",
"(",
"tokenStr",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// if the JWT could not be parsed, force a refresh",
"expiresIn",
"=",
"0",
"\n",
"}",
"else",
"{",
"expiration",
",",
"_",
":=",
"token",
".",
"Claims",
"(",
")",
".",
"Expiration",
"(",
")",
"\n",
"expiresIn",
"=",
"time",
".",
"Until",
"(",
"expiration",
")",
"\n",
"}",
"\n\n",
"if",
"expiresIn",
"<",
"accessTokenExpirationMargin",
"{",
"tokens",
",",
"err",
":=",
"t",
".",
"client",
".",
"RefreshAccessToken",
"(",
"t",
".",
"cache",
".",
"RefreshToken",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"t",
".",
"cache",
".",
"SetAccessToken",
"(",
"tokens",
".",
"AuthorizationToken",
"(",
")",
")",
"\n",
"t",
".",
"cache",
".",
"SetRefreshToken",
"(",
"tokens",
".",
"RefreshToken",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // refreshToken refreshes the JWT access token if it is expired or about to expire.
// If the access token is not yet expired, no action is performed. | [
"refreshToken",
"refreshes",
"the",
"JWT",
"access",
"token",
"if",
"it",
"is",
"expired",
"or",
"about",
"to",
"expire",
".",
"If",
"the",
"access",
"token",
"is",
"not",
"yet",
"expired",
"no",
"action",
"is",
"performed",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/wrapper/uaa_authentication.go#L83-L105 | train |
cloudfoundry/cli | actor/v2action/service_access.go | EnableServiceForOrg | func (actor Actor) EnableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Public != true {
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | go | func (actor Actor) EnableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Public != true {
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"EnableServiceForOrg",
"(",
"serviceName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Public",
"!=",
"true",
"{",
"_",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"CreateServicePlanVisibility",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"_",
",",
"alreadyExistsError",
":=",
"err",
".",
"(",
"ccerror",
".",
"ServicePlanVisibilityExistsError",
")",
";",
"alreadyExistsError",
"{",
"return",
"allWarnings",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // EnableServiceForOrg enables access for the given service in a specific org. | [
"EnableServiceForOrg",
"enables",
"access",
"for",
"the",
"given",
"service",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L63-L89 | train |
cloudfoundry/cli | actor/v2action/service_access.go | EnablePlanForOrg | func (actor Actor) EnablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
if plan.Public {
return allWarnings, nil
}
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
return allWarnings, err
}
}
return nil, fmt.Errorf("Service plan '%s' not found", servicePlanName)
} | go | func (actor Actor) EnablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
if plan.Public {
return allWarnings, nil
}
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
return allWarnings, err
}
}
return nil, fmt.Errorf("Service plan '%s' not found", servicePlanName)
} | [
"func",
"(",
"actor",
"Actor",
")",
"EnablePlanForOrg",
"(",
"serviceName",
",",
"servicePlanName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Name",
"==",
"servicePlanName",
"{",
"if",
"plan",
".",
"Public",
"{",
"return",
"allWarnings",
",",
"nil",
"\n",
"}",
"\n",
"_",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"CreateServicePlanVisibility",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"_",
",",
"alreadyExistsError",
":=",
"err",
".",
"(",
"ccerror",
".",
"ServicePlanVisibilityExistsError",
")",
";",
"alreadyExistsError",
"{",
"return",
"allWarnings",
",",
"nil",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"servicePlanName",
")",
"\n",
"}"
] | // EnablePlanForOrg enables access to a specific plan of the given service in a specific org. | [
"EnablePlanForOrg",
"enables",
"access",
"to",
"a",
"specific",
"plan",
"of",
"the",
"given",
"service",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L92-L119 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisableServiceForAllOrgs | func (actor Actor) DisableServiceForAllOrgs(serviceName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | go | func (actor Actor) DisableServiceForAllOrgs(serviceName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisableServiceForAllOrgs",
"(",
"serviceName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"\"",
"\"",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"if",
"plan",
".",
"Public",
"==",
"true",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateServicePlan",
"(",
"plan",
".",
"GUID",
",",
"false",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisableServiceForAllOrgs disables access for the given service in all orgs. | [
"DisableServiceForAllOrgs",
"disables",
"access",
"for",
"the",
"given",
"service",
"in",
"all",
"orgs",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L122-L144 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisablePlanForAllOrgs | func (actor Actor) DisablePlanForAllOrgs(serviceName, servicePlanName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
ccv2Warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, ccv2Warnings...)
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | go | func (actor Actor) DisablePlanForAllOrgs(serviceName, servicePlanName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
ccv2Warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, ccv2Warnings...)
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisablePlanForAllOrgs",
"(",
"serviceName",
",",
"servicePlanName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"planFound",
":=",
"false",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Name",
"==",
"servicePlanName",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"\"",
"\"",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"plan",
".",
"Public",
"==",
"true",
"{",
"ccv2Warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateServicePlan",
"(",
"plan",
".",
"GUID",
",",
"false",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"ccv2Warnings",
"...",
")",
"\n",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"planFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"planFound",
"==",
"false",
"{",
"return",
"allWarnings",
",",
"actionerror",
".",
"ServicePlanNotFoundError",
"{",
"PlanName",
":",
"servicePlanName",
",",
"ServiceName",
":",
"serviceName",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisablePlanForAllOrgs disables access to a specific plan of the given service, from the given broker in all orgs. | [
"DisablePlanForAllOrgs",
"disables",
"access",
"to",
"a",
"specific",
"plan",
"of",
"the",
"given",
"service",
"from",
"the",
"given",
"broker",
"in",
"all",
"orgs",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L147-L176 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisableServiceForOrg | func (actor Actor) DisableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
return allWarnings, nil
} | go | func (actor Actor) DisableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisableServiceForOrg",
"(",
"serviceName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisableServiceForOrg disables access for the given service in a specific org. | [
"DisableServiceForOrg",
"disables",
"access",
"for",
"the",
"given",
"service",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L179-L199 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisablePlanForOrg | func (actor Actor) DisablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | go | func (actor Actor) DisablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisablePlanForOrg",
"(",
"serviceName",
",",
"servicePlanName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"planFound",
":=",
"false",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Name",
"==",
"servicePlanName",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"planFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"planFound",
"==",
"false",
"{",
"return",
"allWarnings",
",",
"actionerror",
".",
"ServicePlanNotFoundError",
"{",
"PlanName",
":",
"servicePlanName",
",",
"ServiceName",
":",
"serviceName",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisablePlanForOrg disables access to a specific plan of the given service from the given broker in a specific org. | [
"DisablePlanForOrg",
"disables",
"access",
"to",
"a",
"specific",
"plan",
"of",
"the",
"given",
"service",
"from",
"the",
"given",
"broker",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L202-L231 | train |
cloudfoundry/cli | integration/helpers/service_instance.go | ManagedServiceInstanceGUID | func ManagedServiceInstanceGUID(managedServiceInstanceName string) string {
session := CF("curl", fmt.Sprintf("/v2/service_instances?q=name:%s", managedServiceInstanceName))
Eventually(session).Should(Exit(0))
rawJSON := strings.TrimSpace(string(session.Out.Contents()))
var serviceInstanceGUID ServiceInstanceGUID
err := json.Unmarshal([]byte(rawJSON), &serviceInstanceGUID)
Expect(err).NotTo(HaveOccurred())
Expect(serviceInstanceGUID.Resources).To(HaveLen(1))
return serviceInstanceGUID.Resources[0].Metadata.GUID
} | go | func ManagedServiceInstanceGUID(managedServiceInstanceName string) string {
session := CF("curl", fmt.Sprintf("/v2/service_instances?q=name:%s", managedServiceInstanceName))
Eventually(session).Should(Exit(0))
rawJSON := strings.TrimSpace(string(session.Out.Contents()))
var serviceInstanceGUID ServiceInstanceGUID
err := json.Unmarshal([]byte(rawJSON), &serviceInstanceGUID)
Expect(err).NotTo(HaveOccurred())
Expect(serviceInstanceGUID.Resources).To(HaveLen(1))
return serviceInstanceGUID.Resources[0].Metadata.GUID
} | [
"func",
"ManagedServiceInstanceGUID",
"(",
"managedServiceInstanceName",
"string",
")",
"string",
"{",
"session",
":=",
"CF",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"managedServiceInstanceName",
")",
")",
"\n",
"Eventually",
"(",
"session",
")",
".",
"Should",
"(",
"Exit",
"(",
"0",
")",
")",
"\n\n",
"rawJSON",
":=",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"session",
".",
"Out",
".",
"Contents",
"(",
")",
")",
")",
"\n\n",
"var",
"serviceInstanceGUID",
"ServiceInstanceGUID",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"rawJSON",
")",
",",
"&",
"serviceInstanceGUID",
")",
"\n",
"Expect",
"(",
"err",
")",
".",
"NotTo",
"(",
"HaveOccurred",
"(",
")",
")",
"\n\n",
"Expect",
"(",
"serviceInstanceGUID",
".",
"Resources",
")",
".",
"To",
"(",
"HaveLen",
"(",
"1",
")",
")",
"\n",
"return",
"serviceInstanceGUID",
".",
"Resources",
"[",
"0",
"]",
".",
"Metadata",
".",
"GUID",
"\n",
"}"
] | // ManagedServiceInstanceGUID returns the GUID for a managed service instance. | [
"ManagedServiceInstanceGUID",
"returns",
"the",
"GUID",
"for",
"a",
"managed",
"service",
"instance",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/integration/helpers/service_instance.go#L21-L33 | train |
cloudfoundry/cli | api/uaa/wrapper/uaa_authentication.go | Make | func (t *UAAAuthentication) Make(request *http.Request, passedResponse *uaa.Response) error {
if t.client == nil {
return t.connection.Make(request, passedResponse)
}
var err error
var rawRequestBody []byte
if request.Body != nil {
rawRequestBody, err = ioutil.ReadAll(request.Body)
defer request.Body.Close()
if err != nil {
return err
}
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
if skipAuthenticationHeader(request, rawRequestBody) {
return t.connection.Make(request, passedResponse)
}
}
request.Header.Set("Authorization", t.cache.AccessToken())
err = t.connection.Make(request, passedResponse)
if _, ok := err.(uaa.InvalidAuthTokenError); ok {
tokens, refreshErr := t.client.RefreshAccessToken(t.cache.RefreshToken())
if refreshErr != nil {
return refreshErr
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
if rawRequestBody != nil {
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
}
request.Header.Set("Authorization", t.cache.AccessToken())
return t.connection.Make(request, passedResponse)
}
return err
} | go | func (t *UAAAuthentication) Make(request *http.Request, passedResponse *uaa.Response) error {
if t.client == nil {
return t.connection.Make(request, passedResponse)
}
var err error
var rawRequestBody []byte
if request.Body != nil {
rawRequestBody, err = ioutil.ReadAll(request.Body)
defer request.Body.Close()
if err != nil {
return err
}
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
if skipAuthenticationHeader(request, rawRequestBody) {
return t.connection.Make(request, passedResponse)
}
}
request.Header.Set("Authorization", t.cache.AccessToken())
err = t.connection.Make(request, passedResponse)
if _, ok := err.(uaa.InvalidAuthTokenError); ok {
tokens, refreshErr := t.client.RefreshAccessToken(t.cache.RefreshToken())
if refreshErr != nil {
return refreshErr
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
if rawRequestBody != nil {
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
}
request.Header.Set("Authorization", t.cache.AccessToken())
return t.connection.Make(request, passedResponse)
}
return err
} | [
"func",
"(",
"t",
"*",
"UAAAuthentication",
")",
"Make",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"passedResponse",
"*",
"uaa",
".",
"Response",
")",
"error",
"{",
"if",
"t",
".",
"client",
"==",
"nil",
"{",
"return",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"var",
"rawRequestBody",
"[",
"]",
"byte",
"\n\n",
"if",
"request",
".",
"Body",
"!=",
"nil",
"{",
"rawRequestBody",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"request",
".",
"Body",
")",
"\n",
"defer",
"request",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"request",
".",
"Body",
"=",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewBuffer",
"(",
"rawRequestBody",
")",
")",
"\n\n",
"if",
"skipAuthenticationHeader",
"(",
"request",
",",
"rawRequestBody",
")",
"{",
"return",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"t",
".",
"cache",
".",
"AccessToken",
"(",
")",
")",
"\n\n",
"err",
"=",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"uaa",
".",
"InvalidAuthTokenError",
")",
";",
"ok",
"{",
"tokens",
",",
"refreshErr",
":=",
"t",
".",
"client",
".",
"RefreshAccessToken",
"(",
"t",
".",
"cache",
".",
"RefreshToken",
"(",
")",
")",
"\n",
"if",
"refreshErr",
"!=",
"nil",
"{",
"return",
"refreshErr",
"\n",
"}",
"\n\n",
"t",
".",
"cache",
".",
"SetAccessToken",
"(",
"tokens",
".",
"AuthorizationToken",
"(",
")",
")",
"\n",
"t",
".",
"cache",
".",
"SetRefreshToken",
"(",
"tokens",
".",
"RefreshToken",
")",
"\n\n",
"if",
"rawRequestBody",
"!=",
"nil",
"{",
"request",
".",
"Body",
"=",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewBuffer",
"(",
"rawRequestBody",
")",
")",
"\n",
"}",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"t",
".",
"cache",
".",
"AccessToken",
"(",
")",
")",
"\n",
"return",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Make adds authentication headers to the passed in request and then calls the
// wrapped connection's Make | [
"Make",
"adds",
"authentication",
"headers",
"to",
"the",
"passed",
"in",
"request",
"and",
"then",
"calls",
"the",
"wrapped",
"connection",
"s",
"Make"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/uaa_authentication.go#L48-L90 | train |
cloudfoundry/cli | api/uaa/wrapper/uaa_authentication.go | skipAuthenticationHeader | func skipAuthenticationHeader(request *http.Request, body []byte) bool {
stringBody := string(body)
return strings.Contains(request.URL.String(), "/oauth/token") &&
request.Method == http.MethodPost &&
(strings.Contains(stringBody, "grant_type=refresh_token") ||
strings.Contains(stringBody, "grant_type=password") ||
strings.Contains(stringBody, "grant_type=client_credentials"))
} | go | func skipAuthenticationHeader(request *http.Request, body []byte) bool {
stringBody := string(body)
return strings.Contains(request.URL.String(), "/oauth/token") &&
request.Method == http.MethodPost &&
(strings.Contains(stringBody, "grant_type=refresh_token") ||
strings.Contains(stringBody, "grant_type=password") ||
strings.Contains(stringBody, "grant_type=client_credentials"))
} | [
"func",
"skipAuthenticationHeader",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"body",
"[",
"]",
"byte",
")",
"bool",
"{",
"stringBody",
":=",
"string",
"(",
"body",
")",
"\n\n",
"return",
"strings",
".",
"Contains",
"(",
"request",
".",
"URL",
".",
"String",
"(",
")",
",",
"\"",
"\"",
")",
"&&",
"request",
".",
"Method",
"==",
"http",
".",
"MethodPost",
"&&",
"(",
"strings",
".",
"Contains",
"(",
"stringBody",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"stringBody",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"stringBody",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // The authentication header is not added to token refresh requests or login
// requests. | [
"The",
"authentication",
"header",
"is",
"not",
"added",
"to",
"token",
"refresh",
"requests",
"or",
"login",
"requests",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/uaa_authentication.go#L105-L113 | train |
cloudfoundry/cli | api/plugin/plugin_connection.go | NewConnection | func NewConnection(skipSSLValidation bool, dialTimeout time.Duration) *PluginConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: dialTimeout,
}).DialContext,
}
return &PluginConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | go | func NewConnection(skipSSLValidation bool, dialTimeout time.Duration) *PluginConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: dialTimeout,
}).DialContext,
}
return &PluginConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | [
"func",
"NewConnection",
"(",
"skipSSLValidation",
"bool",
",",
"dialTimeout",
"time",
".",
"Duration",
")",
"*",
"PluginConnection",
"{",
"tr",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"skipSSLValidation",
",",
"}",
",",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"DialContext",
":",
"(",
"&",
"net",
".",
"Dialer",
"{",
"KeepAlive",
":",
"30",
"*",
"time",
".",
"Second",
",",
"Timeout",
":",
"dialTimeout",
",",
"}",
")",
".",
"DialContext",
",",
"}",
"\n\n",
"return",
"&",
"PluginConnection",
"{",
"HTTPClient",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"tr",
"}",
",",
"}",
"\n",
"}"
] | // NewConnection returns a new PluginConnection | [
"NewConnection",
"returns",
"a",
"new",
"PluginConnection"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/plugin/plugin_connection.go#L25-L40 | train |
cloudfoundry/cli | actor/v2action/service.go | GetService | func (actor Actor) GetService(serviceGUID string) (Service, Warnings, error) {
service, warnings, err := actor.CloudControllerClient.GetService(serviceGUID)
return Service(service), Warnings(warnings), err
} | go | func (actor Actor) GetService(serviceGUID string) (Service, Warnings, error) {
service, warnings, err := actor.CloudControllerClient.GetService(serviceGUID)
return Service(service), Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetService",
"(",
"serviceGUID",
"string",
")",
"(",
"Service",
",",
"Warnings",
",",
"error",
")",
"{",
"service",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetService",
"(",
"serviceGUID",
")",
"\n",
"return",
"Service",
"(",
"service",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GetService fetches a service by GUID. | [
"GetService",
"fetches",
"a",
"service",
"by",
"GUID",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service.go#L19-L22 | train |
cloudfoundry/cli | actor/v2action/service.go | GetServicesWithPlans | func (actor Actor) GetServicesWithPlans(filters ...Filter) (ServicesWithPlans, Warnings, error) {
ccv2Filters := []ccv2.Filter{}
for _, f := range filters {
ccv2Filters = append(ccv2Filters, ccv2.Filter(f))
}
var allWarnings Warnings
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2Filters...)
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
servicesWithPlans := ServicesWithPlans{}
for _, service := range services {
servicePlans, warnings, err := actor.CloudControllerClient.GetServicePlans(ccv2.Filter{
Type: constant.ServiceGUIDFilter,
Operator: constant.EqualOperator,
Values: []string{service.GUID},
})
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
plansToReturn := []ServicePlan{}
for _, plan := range servicePlans {
plansToReturn = append(plansToReturn, ServicePlan(plan))
}
servicesWithPlans[Service(service)] = plansToReturn
}
return servicesWithPlans, allWarnings, nil
} | go | func (actor Actor) GetServicesWithPlans(filters ...Filter) (ServicesWithPlans, Warnings, error) {
ccv2Filters := []ccv2.Filter{}
for _, f := range filters {
ccv2Filters = append(ccv2Filters, ccv2.Filter(f))
}
var allWarnings Warnings
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2Filters...)
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
servicesWithPlans := ServicesWithPlans{}
for _, service := range services {
servicePlans, warnings, err := actor.CloudControllerClient.GetServicePlans(ccv2.Filter{
Type: constant.ServiceGUIDFilter,
Operator: constant.EqualOperator,
Values: []string{service.GUID},
})
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
plansToReturn := []ServicePlan{}
for _, plan := range servicePlans {
plansToReturn = append(plansToReturn, ServicePlan(plan))
}
servicesWithPlans[Service(service)] = plansToReturn
}
return servicesWithPlans, allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetServicesWithPlans",
"(",
"filters",
"...",
"Filter",
")",
"(",
"ServicesWithPlans",
",",
"Warnings",
",",
"error",
")",
"{",
"ccv2Filters",
":=",
"[",
"]",
"ccv2",
".",
"Filter",
"{",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"filters",
"{",
"ccv2Filters",
"=",
"append",
"(",
"ccv2Filters",
",",
"ccv2",
".",
"Filter",
"(",
"f",
")",
")",
"\n",
"}",
"\n\n",
"var",
"allWarnings",
"Warnings",
"\n\n",
"services",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetServices",
"(",
"ccv2Filters",
"...",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"Warnings",
"(",
"warnings",
")",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"servicesWithPlans",
":=",
"ServicesWithPlans",
"{",
"}",
"\n",
"for",
"_",
",",
"service",
":=",
"range",
"services",
"{",
"servicePlans",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetServicePlans",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"ServiceGUIDFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"service",
".",
"GUID",
"}",
",",
"}",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"Warnings",
"(",
"warnings",
")",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"plansToReturn",
":=",
"[",
"]",
"ServicePlan",
"{",
"}",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"plansToReturn",
"=",
"append",
"(",
"plansToReturn",
",",
"ServicePlan",
"(",
"plan",
")",
")",
"\n",
"}",
"\n\n",
"servicesWithPlans",
"[",
"Service",
"(",
"service",
")",
"]",
"=",
"plansToReturn",
"\n",
"}",
"\n\n",
"return",
"servicesWithPlans",
",",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // GetServicesWithPlans returns a map of Services to ServicePlans for a particular broker.
// A particular service with associated plans from a broker can be fetched by additionally providing
// a service label filter. | [
"GetServicesWithPlans",
"returns",
"a",
"map",
"of",
"Services",
"to",
"ServicePlans",
"for",
"a",
"particular",
"broker",
".",
"A",
"particular",
"service",
"with",
"associated",
"plans",
"from",
"a",
"broker",
"can",
"be",
"fetched",
"by",
"additionally",
"providing",
"a",
"service",
"label",
"filter",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service.go#L93-L128 | train |
cloudfoundry/cli | actor/v2action/service.go | ServiceExistsWithName | func (actor Actor) ServiceExistsWithName(serviceName string) (bool, Warnings, error) {
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2.Filter{
Type: constant.LabelFilter,
Operator: constant.EqualOperator,
Values: []string{serviceName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(services) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | go | func (actor Actor) ServiceExistsWithName(serviceName string) (bool, Warnings, error) {
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2.Filter{
Type: constant.LabelFilter,
Operator: constant.EqualOperator,
Values: []string{serviceName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(services) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"ServiceExistsWithName",
"(",
"serviceName",
"string",
")",
"(",
"bool",
",",
"Warnings",
",",
"error",
")",
"{",
"services",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetServices",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"LabelFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"serviceName",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"services",
")",
"==",
"0",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}"
] | // ServiceExistsWithName returns true if there is an Organization with the
// provided name, otherwise false. | [
"ServiceExistsWithName",
"returns",
"true",
"if",
"there",
"is",
"an",
"Organization",
"with",
"the",
"provided",
"name",
"otherwise",
"false",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service.go#L132-L147 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/organization.go | GetIsolationSegmentOrganizations | func (client *Client) GetIsolationSegmentOrganizations(isolationSegmentGUID string) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetIsolationSegmentOrganizationsRequest,
URIParams: map[string]string{"isolation_segment_guid": isolationSegmentGUID},
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | go | func (client *Client) GetIsolationSegmentOrganizations(isolationSegmentGUID string) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetIsolationSegmentOrganizationsRequest,
URIParams: map[string]string{"isolation_segment_guid": isolationSegmentGUID},
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetIsolationSegmentOrganizations",
"(",
"isolationSegmentGUID",
"string",
")",
"(",
"[",
"]",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetIsolationSegmentOrganizationsRequest",
",",
"URIParams",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"isolationSegmentGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"fullOrgsList",
"[",
"]",
"Organization",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Organization",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"app",
",",
"ok",
":=",
"item",
".",
"(",
"Organization",
")",
";",
"ok",
"{",
"fullOrgsList",
"=",
"append",
"(",
"fullOrgsList",
",",
"app",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Organization",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"fullOrgsList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetIsolationSegmentOrganizations lists organizations
// entitled to an isolation segment. | [
"GetIsolationSegmentOrganizations",
"lists",
"organizations",
"entitled",
"to",
"an",
"isolation",
"segment",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/organization.go#L25-L48 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/organization.go | GetOrganizations | func (client *Client) GetOrganizations(query ...Query) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | go | func (client *Client) GetOrganizations(query ...Query) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetOrganizations",
"(",
"query",
"...",
"Query",
")",
"(",
"[",
"]",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetOrganizationsRequest",
",",
"Query",
":",
"query",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"fullOrgsList",
"[",
"]",
"Organization",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Organization",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"app",
",",
"ok",
":=",
"item",
".",
"(",
"Organization",
")",
";",
"ok",
"{",
"fullOrgsList",
"=",
"append",
"(",
"fullOrgsList",
",",
"app",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Organization",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"fullOrgsList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetOrganizations lists organizations with optional filters. | [
"GetOrganizations",
"lists",
"organizations",
"with",
"optional",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/organization.go#L51-L74 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/droplet.go | GetApplicationDropletCurrent | func (client *Client) GetApplicationDropletCurrent(appGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationDropletCurrentRequest,
URIParams: map[string]string{"app_guid": appGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | go | func (client *Client) GetApplicationDropletCurrent(appGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationDropletCurrentRequest,
URIParams: map[string]string{"app_guid": appGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetApplicationDropletCurrent",
"(",
"appGUID",
"string",
")",
"(",
"Droplet",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetApplicationDropletCurrentRequest",
",",
"URIParams",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"appGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Droplet",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"responseDroplet",
"Droplet",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"responseDroplet",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"responseDroplet",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetApplicationDropletCurrent returns the current droplet for a given
// application. | [
"GetApplicationDropletCurrent",
"returns",
"the",
"current",
"droplet",
"for",
"a",
"given",
"application",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/droplet.go#L38-L53 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/droplet.go | GetDroplet | func (client *Client) GetDroplet(dropletGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletRequest,
URIParams: map[string]string{"droplet_guid": dropletGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | go | func (client *Client) GetDroplet(dropletGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletRequest,
URIParams: map[string]string{"droplet_guid": dropletGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetDroplet",
"(",
"dropletGUID",
"string",
")",
"(",
"Droplet",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetDropletRequest",
",",
"URIParams",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"dropletGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Droplet",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"responseDroplet",
"Droplet",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"responseDroplet",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n\n",
"return",
"responseDroplet",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetDroplet returns a droplet with the given GUID. | [
"GetDroplet",
"returns",
"a",
"droplet",
"with",
"the",
"given",
"GUID",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/droplet.go#L56-L72 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/droplet.go | GetDroplets | func (client *Client) GetDroplets(query ...Query) ([]Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var responseDroplets []Droplet
warnings, err := client.paginate(request, Droplet{}, func(item interface{}) error {
if droplet, ok := item.(Droplet); ok {
responseDroplets = append(responseDroplets, droplet)
} else {
return ccerror.UnknownObjectInListError{
Expected: Droplet{},
Unexpected: item,
}
}
return nil
})
return responseDroplets, warnings, err
} | go | func (client *Client) GetDroplets(query ...Query) ([]Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var responseDroplets []Droplet
warnings, err := client.paginate(request, Droplet{}, func(item interface{}) error {
if droplet, ok := item.(Droplet); ok {
responseDroplets = append(responseDroplets, droplet)
} else {
return ccerror.UnknownObjectInListError{
Expected: Droplet{},
Unexpected: item,
}
}
return nil
})
return responseDroplets, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetDroplets",
"(",
"query",
"...",
"Query",
")",
"(",
"[",
"]",
"Droplet",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetDropletsRequest",
",",
"Query",
":",
"query",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"responseDroplets",
"[",
"]",
"Droplet",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Droplet",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"droplet",
",",
"ok",
":=",
"item",
".",
"(",
"Droplet",
")",
";",
"ok",
"{",
"responseDroplets",
"=",
"append",
"(",
"responseDroplets",
",",
"droplet",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Droplet",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"responseDroplets",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetDroplets lists droplets with optional filters. | [
"GetDroplets",
"lists",
"droplets",
"with",
"optional",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/droplet.go#L75-L98 | train |
cloudfoundry/cli | types/null_int.go | IsValidValue | func (n *NullInt) IsValidValue(val string) error {
_, err := strconv.Atoi(val)
return err
} | go | func (n *NullInt) IsValidValue(val string) error {
_, err := strconv.Atoi(val)
return err
} | [
"func",
"(",
"n",
"*",
"NullInt",
")",
"IsValidValue",
"(",
"val",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // IsValidValue returns an error if the input value is not an integer. | [
"IsValidValue",
"returns",
"an",
"error",
"if",
"the",
"input",
"value",
"is",
"not",
"an",
"integer",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/types/null_int.go#L34-L37 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/service_instance.go | GetServiceInstances | func (client *Client) GetServiceInstances(query ...Query) ([]ServiceInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceInstancesRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullServiceInstanceList []ServiceInstance
warnings, err := client.paginate(request, ServiceInstance{}, func(item interface{}) error {
if serviceInstance, ok := item.(ServiceInstance); ok {
fullServiceInstanceList = append(fullServiceInstanceList, serviceInstance)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceInstance{},
Unexpected: item,
}
}
return nil
})
return fullServiceInstanceList, warnings, err
} | go | func (client *Client) GetServiceInstances(query ...Query) ([]ServiceInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceInstancesRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullServiceInstanceList []ServiceInstance
warnings, err := client.paginate(request, ServiceInstance{}, func(item interface{}) error {
if serviceInstance, ok := item.(ServiceInstance); ok {
fullServiceInstanceList = append(fullServiceInstanceList, serviceInstance)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceInstance{},
Unexpected: item,
}
}
return nil
})
return fullServiceInstanceList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetServiceInstances",
"(",
"query",
"...",
"Query",
")",
"(",
"[",
"]",
"ServiceInstance",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetServiceInstancesRequest",
",",
"Query",
":",
"query",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"fullServiceInstanceList",
"[",
"]",
"ServiceInstance",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"ServiceInstance",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"serviceInstance",
",",
"ok",
":=",
"item",
".",
"(",
"ServiceInstance",
")",
";",
"ok",
"{",
"fullServiceInstanceList",
"=",
"append",
"(",
"fullServiceInstanceList",
",",
"serviceInstance",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"ServiceInstance",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"fullServiceInstanceList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetServiceInstances lists service instances with optional filters. | [
"GetServiceInstances",
"lists",
"service",
"instances",
"with",
"optional",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/service_instance.go#L17-L40 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/route_mapping.go | UnmarshalJSON | func (routeMapping *RouteMapping) UnmarshalJSON(data []byte) error {
var ccRouteMapping struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
AppGUID string `json:"app_guid"`
RouteGUID string `json:"route_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccRouteMapping)
if err != nil {
return err
}
routeMapping.GUID = ccRouteMapping.Metadata.GUID
routeMapping.AppGUID = ccRouteMapping.Entity.AppGUID
routeMapping.RouteGUID = ccRouteMapping.Entity.RouteGUID
return nil
} | go | func (routeMapping *RouteMapping) UnmarshalJSON(data []byte) error {
var ccRouteMapping struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
AppGUID string `json:"app_guid"`
RouteGUID string `json:"route_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccRouteMapping)
if err != nil {
return err
}
routeMapping.GUID = ccRouteMapping.Metadata.GUID
routeMapping.AppGUID = ccRouteMapping.Entity.AppGUID
routeMapping.RouteGUID = ccRouteMapping.Entity.RouteGUID
return nil
} | [
"func",
"(",
"routeMapping",
"*",
"RouteMapping",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccRouteMapping",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"`json:\"metadata\"`",
"\n",
"Entity",
"struct",
"{",
"AppGUID",
"string",
"`json:\"app_guid\"`",
"\n",
"RouteGUID",
"string",
"`json:\"route_guid\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccRouteMapping",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"routeMapping",
".",
"GUID",
"=",
"ccRouteMapping",
".",
"Metadata",
".",
"GUID",
"\n",
"routeMapping",
".",
"AppGUID",
"=",
"ccRouteMapping",
".",
"Entity",
".",
"AppGUID",
"\n",
"routeMapping",
".",
"RouteGUID",
"=",
"ccRouteMapping",
".",
"Entity",
".",
"RouteGUID",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Route Mapping | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Route",
"Mapping"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route_mapping.go#L22-L40 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/route_mapping.go | GetRouteMapping | func (client *Client) GetRouteMapping(guid string) (RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingRequest,
URIParams: Params{"route_mapping_guid": guid},
})
if err != nil {
return RouteMapping{}, nil, err
}
var routeMapping RouteMapping
response := cloudcontroller.Response{
DecodeJSONResponseInto: &routeMapping,
}
err = client.connection.Make(request, &response)
return routeMapping, response.Warnings, err
} | go | func (client *Client) GetRouteMapping(guid string) (RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingRequest,
URIParams: Params{"route_mapping_guid": guid},
})
if err != nil {
return RouteMapping{}, nil, err
}
var routeMapping RouteMapping
response := cloudcontroller.Response{
DecodeJSONResponseInto: &routeMapping,
}
err = client.connection.Make(request, &response)
return routeMapping, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetRouteMapping",
"(",
"guid",
"string",
")",
"(",
"RouteMapping",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetRouteMappingRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"",
"\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RouteMapping",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"routeMapping",
"RouteMapping",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"routeMapping",
",",
"}",
"\n\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"routeMapping",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetRouteMapping returns a route mapping with the provided guid. | [
"GetRouteMapping",
"returns",
"a",
"route",
"mapping",
"with",
"the",
"provided",
"guid",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route_mapping.go#L43-L59 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/route_mapping.go | GetRouteMappings | func (client *Client) GetRouteMappings(filters ...Filter) ([]RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingsRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullRouteMappingsList []RouteMapping
warnings, err := client.paginate(request, RouteMapping{}, func(item interface{}) error {
if routeMapping, ok := item.(RouteMapping); ok {
fullRouteMappingsList = append(fullRouteMappingsList, routeMapping)
} else {
return ccerror.UnknownObjectInListError{
Expected: RouteMapping{},
Unexpected: item,
}
}
return nil
})
return fullRouteMappingsList, warnings, err
} | go | func (client *Client) GetRouteMappings(filters ...Filter) ([]RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingsRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullRouteMappingsList []RouteMapping
warnings, err := client.paginate(request, RouteMapping{}, func(item interface{}) error {
if routeMapping, ok := item.(RouteMapping); ok {
fullRouteMappingsList = append(fullRouteMappingsList, routeMapping)
} else {
return ccerror.UnknownObjectInListError{
Expected: RouteMapping{},
Unexpected: item,
}
}
return nil
})
return fullRouteMappingsList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetRouteMappings",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"RouteMapping",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetRouteMappingsRequest",
",",
"Query",
":",
"ConvertFilterParameters",
"(",
"filters",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"fullRouteMappingsList",
"[",
"]",
"RouteMapping",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"RouteMapping",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"routeMapping",
",",
"ok",
":=",
"item",
".",
"(",
"RouteMapping",
")",
";",
"ok",
"{",
"fullRouteMappingsList",
"=",
"append",
"(",
"fullRouteMappingsList",
",",
"routeMapping",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"RouteMapping",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"fullRouteMappingsList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetRouteMappings returns a list of RouteMappings based off of the provided queries. | [
"GetRouteMappings",
"returns",
"a",
"list",
"of",
"RouteMappings",
"based",
"off",
"of",
"the",
"provided",
"queries",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route_mapping.go#L62-L85 | train |
cloudfoundry/cli | api/uaa/refresh_token.go | AuthorizationToken | func (refreshTokenResponse RefreshedTokens) AuthorizationToken() string {
return fmt.Sprintf("%s %s", refreshTokenResponse.Type, refreshTokenResponse.AccessToken)
} | go | func (refreshTokenResponse RefreshedTokens) AuthorizationToken() string {
return fmt.Sprintf("%s %s", refreshTokenResponse.Type, refreshTokenResponse.AccessToken)
} | [
"func",
"(",
"refreshTokenResponse",
"RefreshedTokens",
")",
"AuthorizationToken",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"refreshTokenResponse",
".",
"Type",
",",
"refreshTokenResponse",
".",
"AccessToken",
")",
"\n",
"}"
] | // AuthorizationToken returns formatted authorization header. | [
"AuthorizationToken",
"returns",
"formatted",
"authorization",
"header",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/refresh_token.go#L21-L23 | train |
cloudfoundry/cli | api/uaa/refresh_token.go | RefreshAccessToken | func (client *Client) RefreshAccessToken(refreshToken string) (RefreshedTokens, error) {
var values url.Values
switch client.config.UAAGrantType() {
case string(constant.GrantTypeClientCredentials):
values = client.clientCredentialRefreshBody()
case "", string(constant.GrantTypePassword): // CLI used to write empty string for grant type in the case of password; preserve compatibility with old config.json files
values = client.refreshTokenBody(refreshToken)
}
body := strings.NewReader(values.Encode())
request, err := client.newRequest(requestOptions{
RequestName: internal.PostOAuthTokenRequest,
Header: http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
Body: body,
})
if err != nil {
return RefreshedTokens{}, err
}
if client.config.UAAGrantType() != string(constant.GrantTypeClientCredentials) {
request.SetBasicAuth(client.config.UAAOAuthClient(), client.config.UAAOAuthClientSecret())
}
var refreshResponse RefreshedTokens
response := Response{
Result: &refreshResponse,
}
err = client.connection.Make(request, &response)
if err != nil {
return RefreshedTokens{}, err
}
return refreshResponse, nil
} | go | func (client *Client) RefreshAccessToken(refreshToken string) (RefreshedTokens, error) {
var values url.Values
switch client.config.UAAGrantType() {
case string(constant.GrantTypeClientCredentials):
values = client.clientCredentialRefreshBody()
case "", string(constant.GrantTypePassword): // CLI used to write empty string for grant type in the case of password; preserve compatibility with old config.json files
values = client.refreshTokenBody(refreshToken)
}
body := strings.NewReader(values.Encode())
request, err := client.newRequest(requestOptions{
RequestName: internal.PostOAuthTokenRequest,
Header: http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
Body: body,
})
if err != nil {
return RefreshedTokens{}, err
}
if client.config.UAAGrantType() != string(constant.GrantTypeClientCredentials) {
request.SetBasicAuth(client.config.UAAOAuthClient(), client.config.UAAOAuthClientSecret())
}
var refreshResponse RefreshedTokens
response := Response{
Result: &refreshResponse,
}
err = client.connection.Make(request, &response)
if err != nil {
return RefreshedTokens{}, err
}
return refreshResponse, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"RefreshAccessToken",
"(",
"refreshToken",
"string",
")",
"(",
"RefreshedTokens",
",",
"error",
")",
"{",
"var",
"values",
"url",
".",
"Values",
"\n\n",
"switch",
"client",
".",
"config",
".",
"UAAGrantType",
"(",
")",
"{",
"case",
"string",
"(",
"constant",
".",
"GrantTypeClientCredentials",
")",
":",
"values",
"=",
"client",
".",
"clientCredentialRefreshBody",
"(",
")",
"\n",
"case",
"\"",
"\"",
",",
"string",
"(",
"constant",
".",
"GrantTypePassword",
")",
":",
"// CLI used to write empty string for grant type in the case of password; preserve compatibility with old config.json files",
"values",
"=",
"client",
".",
"refreshTokenBody",
"(",
"refreshToken",
")",
"\n",
"}",
"\n\n",
"body",
":=",
"strings",
".",
"NewReader",
"(",
"values",
".",
"Encode",
"(",
")",
")",
"\n\n",
"request",
",",
"err",
":=",
"client",
".",
"newRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PostOAuthTokenRequest",
",",
"Header",
":",
"http",
".",
"Header",
"{",
"\"",
"\"",
":",
"{",
"\"",
"\"",
"}",
"}",
",",
"Body",
":",
"body",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RefreshedTokens",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"config",
".",
"UAAGrantType",
"(",
")",
"!=",
"string",
"(",
"constant",
".",
"GrantTypeClientCredentials",
")",
"{",
"request",
".",
"SetBasicAuth",
"(",
"client",
".",
"config",
".",
"UAAOAuthClient",
"(",
")",
",",
"client",
".",
"config",
".",
"UAAOAuthClientSecret",
"(",
")",
")",
"\n",
"}",
"\n\n",
"var",
"refreshResponse",
"RefreshedTokens",
"\n",
"response",
":=",
"Response",
"{",
"Result",
":",
"&",
"refreshResponse",
",",
"}",
"\n\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RefreshedTokens",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"refreshResponse",
",",
"nil",
"\n",
"}"
] | // RefreshAccessToken refreshes the current access token. | [
"RefreshAccessToken",
"refreshes",
"the",
"current",
"access",
"token",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/refresh_token.go#L26-L62 | train |
cloudfoundry/cli | util/ui/table.go | DisplayKeyValueTable | func (ui *UI) DisplayKeyValueTable(prefix string, table [][]string, padding int) {
rows := len(table)
if rows == 0 {
return
}
var displayTable [][]string
for _, row := range table {
if len(row) > 0 {
displayTable = append(displayTable, row)
}
}
columns := len(displayTable[0])
if columns < 2 || !ui.IsTTY {
ui.DisplayNonWrappingTable(prefix, displayTable, padding)
return
}
ui.displayWrappingTableWithWidth(prefix, displayTable, padding)
} | go | func (ui *UI) DisplayKeyValueTable(prefix string, table [][]string, padding int) {
rows := len(table)
if rows == 0 {
return
}
var displayTable [][]string
for _, row := range table {
if len(row) > 0 {
displayTable = append(displayTable, row)
}
}
columns := len(displayTable[0])
if columns < 2 || !ui.IsTTY {
ui.DisplayNonWrappingTable(prefix, displayTable, padding)
return
}
ui.displayWrappingTableWithWidth(prefix, displayTable, padding)
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"DisplayKeyValueTable",
"(",
"prefix",
"string",
",",
"table",
"[",
"]",
"[",
"]",
"string",
",",
"padding",
"int",
")",
"{",
"rows",
":=",
"len",
"(",
"table",
")",
"\n",
"if",
"rows",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"var",
"displayTable",
"[",
"]",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"table",
"{",
"if",
"len",
"(",
"row",
")",
">",
"0",
"{",
"displayTable",
"=",
"append",
"(",
"displayTable",
",",
"row",
")",
"\n",
"}",
"\n",
"}",
"\n",
"columns",
":=",
"len",
"(",
"displayTable",
"[",
"0",
"]",
")",
"\n\n",
"if",
"columns",
"<",
"2",
"||",
"!",
"ui",
".",
"IsTTY",
"{",
"ui",
".",
"DisplayNonWrappingTable",
"(",
"prefix",
",",
"displayTable",
",",
"padding",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"ui",
".",
"displayWrappingTableWithWidth",
"(",
"prefix",
",",
"displayTable",
",",
"padding",
")",
"\n",
"}"
] | // DisplayKeyValueTable outputs a matrix of strings as a table to UI.Out.
// Prefix will be prepended to each row and padding adds the specified number
// of spaces between columns. The final columns may wrap to multiple lines but
// will still be confined to the last column. Wrapping will occur on word
// boundaries. | [
"DisplayKeyValueTable",
"outputs",
"a",
"matrix",
"of",
"strings",
"as",
"a",
"table",
"to",
"UI",
".",
"Out",
".",
"Prefix",
"will",
"be",
"prepended",
"to",
"each",
"row",
"and",
"padding",
"adds",
"the",
"specified",
"number",
"of",
"spaces",
"between",
"columns",
".",
"The",
"final",
"columns",
"may",
"wrap",
"to",
"multiple",
"lines",
"but",
"will",
"still",
"be",
"confined",
"to",
"the",
"last",
"column",
".",
"Wrapping",
"will",
"occur",
"on",
"word",
"boundaries",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/table.go#L20-L40 | train |
cloudfoundry/cli | util/ui/table.go | DisplayNonWrappingTable | func (ui *UI) DisplayNonWrappingTable(prefix string, table [][]string, padding int) {
ui.terminalLock.Lock()
defer ui.terminalLock.Unlock()
if len(table) == 0 {
return
}
var columnPadding []int
rows := len(table)
columns := len(table[0])
for col := 0; col < columns; col++ {
var max int
for row := 0; row < rows; row++ {
if strLen := wordSize(table[row][col]); max < strLen {
max = strLen
}
}
columnPadding = append(columnPadding, max+padding)
}
for row := 0; row < rows; row++ {
fmt.Fprint(ui.Out, prefix)
for col := 0; col < columns; col++ {
data := table[row][col]
var addedPadding int
if col+1 != columns {
addedPadding = columnPadding[col] - wordSize(data)
}
fmt.Fprintf(ui.Out, "%s%s", data, strings.Repeat(" ", addedPadding))
}
fmt.Fprintf(ui.Out, "\n")
}
} | go | func (ui *UI) DisplayNonWrappingTable(prefix string, table [][]string, padding int) {
ui.terminalLock.Lock()
defer ui.terminalLock.Unlock()
if len(table) == 0 {
return
}
var columnPadding []int
rows := len(table)
columns := len(table[0])
for col := 0; col < columns; col++ {
var max int
for row := 0; row < rows; row++ {
if strLen := wordSize(table[row][col]); max < strLen {
max = strLen
}
}
columnPadding = append(columnPadding, max+padding)
}
for row := 0; row < rows; row++ {
fmt.Fprint(ui.Out, prefix)
for col := 0; col < columns; col++ {
data := table[row][col]
var addedPadding int
if col+1 != columns {
addedPadding = columnPadding[col] - wordSize(data)
}
fmt.Fprintf(ui.Out, "%s%s", data, strings.Repeat(" ", addedPadding))
}
fmt.Fprintf(ui.Out, "\n")
}
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"DisplayNonWrappingTable",
"(",
"prefix",
"string",
",",
"table",
"[",
"]",
"[",
"]",
"string",
",",
"padding",
"int",
")",
"{",
"ui",
".",
"terminalLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ui",
".",
"terminalLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"len",
"(",
"table",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"var",
"columnPadding",
"[",
"]",
"int",
"\n\n",
"rows",
":=",
"len",
"(",
"table",
")",
"\n",
"columns",
":=",
"len",
"(",
"table",
"[",
"0",
"]",
")",
"\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"columns",
";",
"col",
"++",
"{",
"var",
"max",
"int",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"if",
"strLen",
":=",
"wordSize",
"(",
"table",
"[",
"row",
"]",
"[",
"col",
"]",
")",
";",
"max",
"<",
"strLen",
"{",
"max",
"=",
"strLen",
"\n",
"}",
"\n",
"}",
"\n",
"columnPadding",
"=",
"append",
"(",
"columnPadding",
",",
"max",
"+",
"padding",
")",
"\n",
"}",
"\n\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"fmt",
".",
"Fprint",
"(",
"ui",
".",
"Out",
",",
"prefix",
")",
"\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"columns",
";",
"col",
"++",
"{",
"data",
":=",
"table",
"[",
"row",
"]",
"[",
"col",
"]",
"\n",
"var",
"addedPadding",
"int",
"\n",
"if",
"col",
"+",
"1",
"!=",
"columns",
"{",
"addedPadding",
"=",
"columnPadding",
"[",
"col",
"]",
"-",
"wordSize",
"(",
"data",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"ui",
".",
"Out",
",",
"\"",
"\"",
",",
"data",
",",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"addedPadding",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"ui",
".",
"Out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // DisplayNonWrappingTable outputs a matrix of strings as a table to UI.Out.
// Prefix will be prepended to each row and padding adds the specified number
// of spaces between columns. | [
"DisplayNonWrappingTable",
"outputs",
"a",
"matrix",
"of",
"strings",
"as",
"a",
"table",
"to",
"UI",
".",
"Out",
".",
"Prefix",
"will",
"be",
"prepended",
"to",
"each",
"row",
"and",
"padding",
"adds",
"the",
"specified",
"number",
"of",
"spaces",
"between",
"columns",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/table.go#L45-L79 | train |
cloudfoundry/cli | util/ui/table.go | DisplayTableWithHeader | func (ui *UI) DisplayTableWithHeader(prefix string, table [][]string, padding int) {
if len(table) == 0 {
return
}
for i, str := range table[0] {
table[0][i] = ui.modifyColor(str, color.New(color.Bold))
}
ui.DisplayNonWrappingTable(prefix, table, padding)
} | go | func (ui *UI) DisplayTableWithHeader(prefix string, table [][]string, padding int) {
if len(table) == 0 {
return
}
for i, str := range table[0] {
table[0][i] = ui.modifyColor(str, color.New(color.Bold))
}
ui.DisplayNonWrappingTable(prefix, table, padding)
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"DisplayTableWithHeader",
"(",
"prefix",
"string",
",",
"table",
"[",
"]",
"[",
"]",
"string",
",",
"padding",
"int",
")",
"{",
"if",
"len",
"(",
"table",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"for",
"i",
",",
"str",
":=",
"range",
"table",
"[",
"0",
"]",
"{",
"table",
"[",
"0",
"]",
"[",
"i",
"]",
"=",
"ui",
".",
"modifyColor",
"(",
"str",
",",
"color",
".",
"New",
"(",
"color",
".",
"Bold",
")",
")",
"\n",
"}",
"\n\n",
"ui",
".",
"DisplayNonWrappingTable",
"(",
"prefix",
",",
"table",
",",
"padding",
")",
"\n",
"}"
] | // DisplayTableWithHeader outputs a simple non-wrapping table with bolded
// headers. | [
"DisplayTableWithHeader",
"outputs",
"a",
"simple",
"non",
"-",
"wrapping",
"table",
"with",
"bolded",
"headers",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/table.go#L83-L92 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/application_instance.go | GetApplicationApplicationInstances | func (client *Client) GetApplicationApplicationInstances(guid string) (map[int]ApplicationInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetAppInstancesRequest,
URIParams: Params{"app_guid": guid},
})
if err != nil {
return nil, nil, err
}
var instances map[string]ApplicationInstance
response := cloudcontroller.Response{
DecodeJSONResponseInto: &instances,
}
err = client.connection.Make(request, &response)
if err != nil {
return nil, response.Warnings, err
}
returnedInstances := map[int]ApplicationInstance{}
for instanceID, instance := range instances {
id, convertErr := strconv.Atoi(instanceID)
if convertErr != nil {
return nil, response.Warnings, convertErr
}
instance.ID = id
returnedInstances[id] = instance
}
return returnedInstances, response.Warnings, nil
} | go | func (client *Client) GetApplicationApplicationInstances(guid string) (map[int]ApplicationInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetAppInstancesRequest,
URIParams: Params{"app_guid": guid},
})
if err != nil {
return nil, nil, err
}
var instances map[string]ApplicationInstance
response := cloudcontroller.Response{
DecodeJSONResponseInto: &instances,
}
err = client.connection.Make(request, &response)
if err != nil {
return nil, response.Warnings, err
}
returnedInstances := map[int]ApplicationInstance{}
for instanceID, instance := range instances {
id, convertErr := strconv.Atoi(instanceID)
if convertErr != nil {
return nil, response.Warnings, convertErr
}
instance.ID = id
returnedInstances[id] = instance
}
return returnedInstances, response.Warnings, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetApplicationApplicationInstances",
"(",
"guid",
"string",
")",
"(",
"map",
"[",
"int",
"]",
"ApplicationInstance",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetAppInstancesRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"",
"\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"instances",
"map",
"[",
"string",
"]",
"ApplicationInstance",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"instances",
",",
"}",
"\n\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}",
"\n\n",
"returnedInstances",
":=",
"map",
"[",
"int",
"]",
"ApplicationInstance",
"{",
"}",
"\n",
"for",
"instanceID",
",",
"instance",
":=",
"range",
"instances",
"{",
"id",
",",
"convertErr",
":=",
"strconv",
".",
"Atoi",
"(",
"instanceID",
")",
"\n",
"if",
"convertErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"response",
".",
"Warnings",
",",
"convertErr",
"\n",
"}",
"\n",
"instance",
".",
"ID",
"=",
"id",
"\n",
"returnedInstances",
"[",
"id",
"]",
"=",
"instance",
"\n",
"}",
"\n\n",
"return",
"returnedInstances",
",",
"response",
".",
"Warnings",
",",
"nil",
"\n",
"}"
] | // GetApplicationApplicationInstances returns a list of ApplicationInstance for
// a given application. Depending on the state of an application, it might skip
// some application instances. | [
"GetApplicationApplicationInstances",
"returns",
"a",
"list",
"of",
"ApplicationInstance",
"for",
"a",
"given",
"application",
".",
"Depending",
"on",
"the",
"state",
"of",
"an",
"application",
"it",
"might",
"skip",
"some",
"application",
"instances",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/application_instance.go#L50-L80 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/service_plan_visibility.go | UnmarshalJSON | func (servicePlanVisibility *ServicePlanVisibility) UnmarshalJSON(data []byte) error {
var ccServicePlanVisibility struct {
Metadata internal.Metadata
Entity struct {
ServicePlanGUID string `json:"service_plan_guid"`
OrganizationGUID string `json:"organization_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccServicePlanVisibility)
if err != nil {
return err
}
servicePlanVisibility.GUID = ccServicePlanVisibility.Metadata.GUID
servicePlanVisibility.ServicePlanGUID = ccServicePlanVisibility.Entity.ServicePlanGUID
servicePlanVisibility.OrganizationGUID = ccServicePlanVisibility.Entity.OrganizationGUID
return nil
} | go | func (servicePlanVisibility *ServicePlanVisibility) UnmarshalJSON(data []byte) error {
var ccServicePlanVisibility struct {
Metadata internal.Metadata
Entity struct {
ServicePlanGUID string `json:"service_plan_guid"`
OrganizationGUID string `json:"organization_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccServicePlanVisibility)
if err != nil {
return err
}
servicePlanVisibility.GUID = ccServicePlanVisibility.Metadata.GUID
servicePlanVisibility.ServicePlanGUID = ccServicePlanVisibility.Entity.ServicePlanGUID
servicePlanVisibility.OrganizationGUID = ccServicePlanVisibility.Entity.OrganizationGUID
return nil
} | [
"func",
"(",
"servicePlanVisibility",
"*",
"ServicePlanVisibility",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccServicePlanVisibility",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"\n",
"Entity",
"struct",
"{",
"ServicePlanGUID",
"string",
"`json:\"service_plan_guid\"`",
"\n",
"OrganizationGUID",
"string",
"`json:\"organization_guid\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccServicePlanVisibility",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"servicePlanVisibility",
".",
"GUID",
"=",
"ccServicePlanVisibility",
".",
"Metadata",
".",
"GUID",
"\n",
"servicePlanVisibility",
".",
"ServicePlanGUID",
"=",
"ccServicePlanVisibility",
".",
"Entity",
".",
"ServicePlanGUID",
"\n",
"servicePlanVisibility",
".",
"OrganizationGUID",
"=",
"ccServicePlanVisibility",
".",
"Entity",
".",
"OrganizationGUID",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Service Plan Visibilities
// response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Service",
"Plan",
"Visibilities",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_plan_visibility.go#L24-L41 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/service_plan_visibility.go | GetServicePlanVisibilities | func (client *Client) GetServicePlanVisibilities(filters ...Filter) ([]ServicePlanVisibility, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServicePlanVisibilitiesRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullVisibilityList []ServicePlanVisibility
warnings, err := client.paginate(request, ServicePlanVisibility{}, func(item interface{}) error {
if vis, ok := item.(ServicePlanVisibility); ok {
fullVisibilityList = append(fullVisibilityList, vis)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServicePlanVisibility{},
Unexpected: item,
}
}
return nil
})
return fullVisibilityList, warnings, err
} | go | func (client *Client) GetServicePlanVisibilities(filters ...Filter) ([]ServicePlanVisibility, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServicePlanVisibilitiesRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullVisibilityList []ServicePlanVisibility
warnings, err := client.paginate(request, ServicePlanVisibility{}, func(item interface{}) error {
if vis, ok := item.(ServicePlanVisibility); ok {
fullVisibilityList = append(fullVisibilityList, vis)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServicePlanVisibility{},
Unexpected: item,
}
}
return nil
})
return fullVisibilityList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetServicePlanVisibilities",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"ServicePlanVisibility",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetServicePlanVisibilitiesRequest",
",",
"Query",
":",
"ConvertFilterParameters",
"(",
"filters",
")",
",",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"fullVisibilityList",
"[",
"]",
"ServicePlanVisibility",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"ServicePlanVisibility",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"vis",
",",
"ok",
":=",
"item",
".",
"(",
"ServicePlanVisibility",
")",
";",
"ok",
"{",
"fullVisibilityList",
"=",
"append",
"(",
"fullVisibilityList",
",",
"vis",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"ServicePlanVisibility",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"fullVisibilityList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetServicePlanVisibilities returns back a list of Service Plan Visibilities
// given the provided filters. | [
"GetServicePlanVisibilities",
"returns",
"back",
"a",
"list",
"of",
"Service",
"Plan",
"Visibilities",
"given",
"the",
"provided",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_plan_visibility.go#L93-L117 | train |
cloudfoundry/cli | api/uaa/wrapper/request_logger.go | Make | func (logger *RequestLogger) Make(request *http.Request, passedResponse *uaa.Response) error {
err := logger.displayRequest(request)
if err != nil {
logger.output.HandleInternalError(err)
}
err = logger.connection.Make(request, passedResponse)
if passedResponse.HTTPResponse != nil {
displayErr := logger.displayResponse(passedResponse)
if displayErr != nil {
logger.output.HandleInternalError(displayErr)
}
}
return err
} | go | func (logger *RequestLogger) Make(request *http.Request, passedResponse *uaa.Response) error {
err := logger.displayRequest(request)
if err != nil {
logger.output.HandleInternalError(err)
}
err = logger.connection.Make(request, passedResponse)
if passedResponse.HTTPResponse != nil {
displayErr := logger.displayResponse(passedResponse)
if displayErr != nil {
logger.output.HandleInternalError(displayErr)
}
}
return err
} | [
"func",
"(",
"logger",
"*",
"RequestLogger",
")",
"Make",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"passedResponse",
"*",
"uaa",
".",
"Response",
")",
"error",
"{",
"err",
":=",
"logger",
".",
"displayRequest",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"output",
".",
"HandleInternalError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"logger",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n\n",
"if",
"passedResponse",
".",
"HTTPResponse",
"!=",
"nil",
"{",
"displayErr",
":=",
"logger",
".",
"displayResponse",
"(",
"passedResponse",
")",
"\n",
"if",
"displayErr",
"!=",
"nil",
"{",
"logger",
".",
"output",
".",
"HandleInternalError",
"(",
"displayErr",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Make records the request and the response to UI | [
"Make",
"records",
"the",
"request",
"and",
"the",
"response",
"to",
"UI"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/request_logger.go#L44-L60 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | UnmarshalJSON | func (spaceQuota *SpaceQuota) UnmarshalJSON(data []byte) error {
var ccSpaceQuota struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccSpaceQuota)
if err != nil {
return err
}
spaceQuota.GUID = ccSpaceQuota.Metadata.GUID
spaceQuota.Name = ccSpaceQuota.Entity.Name
return nil
} | go | func (spaceQuota *SpaceQuota) UnmarshalJSON(data []byte) error {
var ccSpaceQuota struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccSpaceQuota)
if err != nil {
return err
}
spaceQuota.GUID = ccSpaceQuota.Metadata.GUID
spaceQuota.Name = ccSpaceQuota.Entity.Name
return nil
} | [
"func",
"(",
"spaceQuota",
"*",
"SpaceQuota",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccSpaceQuota",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"`json:\"metadata\"`",
"\n",
"Entity",
"struct",
"{",
"Name",
"string",
"`json:\"name\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccSpaceQuota",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"spaceQuota",
".",
"GUID",
"=",
"ccSpaceQuota",
".",
"Metadata",
".",
"GUID",
"\n",
"spaceQuota",
".",
"Name",
"=",
"ccSpaceQuota",
".",
"Entity",
".",
"Name",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Space Quota response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Space",
"Quota",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L21-L36 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | GetSpaceQuotaDefinition | func (client *Client) GetSpaceQuotaDefinition(guid string) (SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetSpaceQuotaDefinitionRequest,
URIParams: Params{"space_quota_guid": guid},
})
if err != nil {
return SpaceQuota{}, nil, err
}
var spaceQuota SpaceQuota
response := cloudcontroller.Response{
DecodeJSONResponseInto: &spaceQuota,
}
err = client.connection.Make(request, &response)
return spaceQuota, response.Warnings, err
} | go | func (client *Client) GetSpaceQuotaDefinition(guid string) (SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetSpaceQuotaDefinitionRequest,
URIParams: Params{"space_quota_guid": guid},
})
if err != nil {
return SpaceQuota{}, nil, err
}
var spaceQuota SpaceQuota
response := cloudcontroller.Response{
DecodeJSONResponseInto: &spaceQuota,
}
err = client.connection.Make(request, &response)
return spaceQuota, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetSpaceQuotaDefinition",
"(",
"guid",
"string",
")",
"(",
"SpaceQuota",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetSpaceQuotaDefinitionRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"",
"\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"SpaceQuota",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"spaceQuota",
"SpaceQuota",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"spaceQuota",
",",
"}",
"\n\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"spaceQuota",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetSpaceQuotaDefinition returns a Space Quota. | [
"GetSpaceQuotaDefinition",
"returns",
"a",
"Space",
"Quota",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L39-L55 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | GetSpaceQuotas | func (client *Client) GetSpaceQuotas(orgGUID string) ([]SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationSpaceQuotasRequest,
URIParams: Params{"organization_guid": orgGUID},
})
if err != nil {
return nil, nil, err
}
var spaceQuotas []SpaceQuota
warnings, err := client.paginate(request, SpaceQuota{}, func(item interface{}) error {
if spaceQuota, ok := item.(SpaceQuota); ok {
spaceQuotas = append(spaceQuotas, spaceQuota)
} else {
return ccerror.UnknownObjectInListError{
Expected: SpaceQuota{},
Unexpected: item,
}
}
return nil
})
return spaceQuotas, warnings, err
} | go | func (client *Client) GetSpaceQuotas(orgGUID string) ([]SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationSpaceQuotasRequest,
URIParams: Params{"organization_guid": orgGUID},
})
if err != nil {
return nil, nil, err
}
var spaceQuotas []SpaceQuota
warnings, err := client.paginate(request, SpaceQuota{}, func(item interface{}) error {
if spaceQuota, ok := item.(SpaceQuota); ok {
spaceQuotas = append(spaceQuotas, spaceQuota)
} else {
return ccerror.UnknownObjectInListError{
Expected: SpaceQuota{},
Unexpected: item,
}
}
return nil
})
return spaceQuotas, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetSpaceQuotas",
"(",
"orgGUID",
"string",
")",
"(",
"[",
"]",
"SpaceQuota",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetOrganizationSpaceQuotasRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"",
"\"",
":",
"orgGUID",
"}",
",",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"spaceQuotas",
"[",
"]",
"SpaceQuota",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"SpaceQuota",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"spaceQuota",
",",
"ok",
":=",
"item",
".",
"(",
"SpaceQuota",
")",
";",
"ok",
"{",
"spaceQuotas",
"=",
"append",
"(",
"spaceQuotas",
",",
"spaceQuota",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"SpaceQuota",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"spaceQuotas",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetSpaceQuotas returns all the space quotas for the org | [
"GetSpaceQuotas",
"returns",
"all",
"the",
"space",
"quotas",
"for",
"the",
"org"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L58-L82 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | SetSpaceQuota | func (client *Client) SetSpaceQuota(spaceGUID string, quotaGUID string) (Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutSpaceQuotaRequest,
URIParams: Params{"space_quota_guid": quotaGUID, "space_guid": spaceGUID},
})
if err != nil {
return nil, err
}
response := cloudcontroller.Response{}
err = client.connection.Make(request, &response)
return response.Warnings, err
} | go | func (client *Client) SetSpaceQuota(spaceGUID string, quotaGUID string) (Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutSpaceQuotaRequest,
URIParams: Params{"space_quota_guid": quotaGUID, "space_guid": spaceGUID},
})
if err != nil {
return nil, err
}
response := cloudcontroller.Response{}
err = client.connection.Make(request, &response)
return response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetSpaceQuota",
"(",
"spaceGUID",
"string",
",",
"quotaGUID",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PutSpaceQuotaRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"",
"\"",
":",
"quotaGUID",
",",
"\"",
"\"",
":",
"spaceGUID",
"}",
",",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n\n",
"return",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // SetSpaceQuota should set the quota for the space and returns the warnings | [
"SetSpaceQuota",
"should",
"set",
"the",
"quota",
"for",
"the",
"space",
"and",
"returns",
"the",
"warnings"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L85-L99 | train |
cloudfoundry/cli | actor/v2action/organization.go | GetOrganization | func (actor Actor) GetOrganization(guid string) (Organization, Warnings, error) {
org, warnings, err := actor.CloudControllerClient.GetOrganization(guid)
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{GUID: guid}
}
return Organization(org), Warnings(warnings), err
} | go | func (actor Actor) GetOrganization(guid string) (Organization, Warnings, error) {
org, warnings, err := actor.CloudControllerClient.GetOrganization(guid)
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{GUID: guid}
}
return Organization(org), Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetOrganization",
"(",
"guid",
"string",
")",
"(",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"org",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganization",
"(",
"guid",
")",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"ccerror",
".",
"ResourceNotFoundError",
")",
";",
"ok",
"{",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"OrganizationNotFoundError",
"{",
"GUID",
":",
"guid",
"}",
"\n",
"}",
"\n\n",
"return",
"Organization",
"(",
"org",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GetOrganization returns an Organization based on the provided guid. | [
"GetOrganization",
"returns",
"an",
"Organization",
"based",
"on",
"the",
"provided",
"guid",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L15-L23 | train |
cloudfoundry/cli | actor/v2action/organization.go | GetOrganizationByName | func (actor Actor) GetOrganizationByName(orgName string) (Organization, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return Organization{}, Warnings(warnings), err
}
if len(orgs) == 0 {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{Name: orgName}
}
if len(orgs) > 1 {
var guids []string
for _, org := range orgs {
guids = append(guids, org.GUID)
}
return Organization{}, Warnings(warnings), actionerror.MultipleOrganizationsFoundError{Name: orgName, GUIDs: guids}
}
return Organization(orgs[0]), Warnings(warnings), nil
} | go | func (actor Actor) GetOrganizationByName(orgName string) (Organization, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return Organization{}, Warnings(warnings), err
}
if len(orgs) == 0 {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{Name: orgName}
}
if len(orgs) > 1 {
var guids []string
for _, org := range orgs {
guids = append(guids, org.GUID)
}
return Organization{}, Warnings(warnings), actionerror.MultipleOrganizationsFoundError{Name: orgName, GUIDs: guids}
}
return Organization(orgs[0]), Warnings(warnings), nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetOrganizationByName",
"(",
"orgName",
"string",
")",
"(",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"orgs",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganizations",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"NameFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"orgName",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"orgs",
")",
"==",
"0",
"{",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"OrganizationNotFoundError",
"{",
"Name",
":",
"orgName",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"orgs",
")",
">",
"1",
"{",
"var",
"guids",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"org",
":=",
"range",
"orgs",
"{",
"guids",
"=",
"append",
"(",
"guids",
",",
"org",
".",
"GUID",
")",
"\n",
"}",
"\n",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"MultipleOrganizationsFoundError",
"{",
"Name",
":",
"orgName",
",",
"GUIDs",
":",
"guids",
"}",
"\n",
"}",
"\n\n",
"return",
"Organization",
"(",
"orgs",
"[",
"0",
"]",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}"
] | // GetOrganizationByName returns an Organization based off of the name given. | [
"GetOrganizationByName",
"returns",
"an",
"Organization",
"based",
"off",
"of",
"the",
"name",
"given",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L26-L49 | train |
cloudfoundry/cli | actor/v2action/organization.go | GrantOrgManagerByUsername | func (actor Actor) GrantOrgManagerByUsername(guid string, username string) (Warnings, error) {
var warnings ccv2.Warnings
var err error
if actor.Config.UAAGrantType() != string(uaaconst.GrantTypeClientCredentials) {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManagerByUsername(guid, username)
} else {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManager(guid, username)
}
return Warnings(warnings), err
} | go | func (actor Actor) GrantOrgManagerByUsername(guid string, username string) (Warnings, error) {
var warnings ccv2.Warnings
var err error
if actor.Config.UAAGrantType() != string(uaaconst.GrantTypeClientCredentials) {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManagerByUsername(guid, username)
} else {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManager(guid, username)
}
return Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GrantOrgManagerByUsername",
"(",
"guid",
"string",
",",
"username",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"var",
"warnings",
"ccv2",
".",
"Warnings",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"actor",
".",
"Config",
".",
"UAAGrantType",
"(",
")",
"!=",
"string",
"(",
"uaaconst",
".",
"GrantTypeClientCredentials",
")",
"{",
"warnings",
",",
"err",
"=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateOrganizationManagerByUsername",
"(",
"guid",
",",
"username",
")",
"\n",
"}",
"else",
"{",
"warnings",
",",
"err",
"=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateOrganizationManager",
"(",
"guid",
",",
"username",
")",
"\n",
"}",
"\n\n",
"return",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GrantOrgManagerByUsername gives the Org Manager role to the provided user. | [
"GrantOrgManagerByUsername",
"gives",
"the",
"Org",
"Manager",
"role",
"to",
"the",
"provided",
"user",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L52-L63 | train |
cloudfoundry/cli | actor/v2action/organization.go | CreateOrganization | func (actor Actor) CreateOrganization(orgName string, quotaName string) (Organization, Warnings, error) {
var quotaGUID string
var allWarnings Warnings
if quotaName != "" {
quota, warnings, err := actor.GetOrganizationQuotaByName(quotaName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return Organization{}, allWarnings, err
}
quotaGUID = quota.GUID
}
org, warnings, err := actor.CloudControllerClient.CreateOrganization(orgName, quotaGUID)
allWarnings = append(allWarnings, warnings...)
if _, ok := err.(ccerror.OrganizationNameTakenError); ok {
return Organization{}, allWarnings, actionerror.OrganizationNameTakenError{Name: orgName}
}
if err != nil {
return Organization{}, allWarnings, err
}
return Organization(org), allWarnings, nil
} | go | func (actor Actor) CreateOrganization(orgName string, quotaName string) (Organization, Warnings, error) {
var quotaGUID string
var allWarnings Warnings
if quotaName != "" {
quota, warnings, err := actor.GetOrganizationQuotaByName(quotaName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return Organization{}, allWarnings, err
}
quotaGUID = quota.GUID
}
org, warnings, err := actor.CloudControllerClient.CreateOrganization(orgName, quotaGUID)
allWarnings = append(allWarnings, warnings...)
if _, ok := err.(ccerror.OrganizationNameTakenError); ok {
return Organization{}, allWarnings, actionerror.OrganizationNameTakenError{Name: orgName}
}
if err != nil {
return Organization{}, allWarnings, err
}
return Organization(org), allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"CreateOrganization",
"(",
"orgName",
"string",
",",
"quotaName",
"string",
")",
"(",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"var",
"quotaGUID",
"string",
"\n",
"var",
"allWarnings",
"Warnings",
"\n\n",
"if",
"quotaName",
"!=",
"\"",
"\"",
"{",
"quota",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationQuotaByName",
"(",
"quotaName",
")",
"\n\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Organization",
"{",
"}",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"quotaGUID",
"=",
"quota",
".",
"GUID",
"\n",
"}",
"\n\n",
"org",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"CreateOrganization",
"(",
"orgName",
",",
"quotaGUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"ccerror",
".",
"OrganizationNameTakenError",
")",
";",
"ok",
"{",
"return",
"Organization",
"{",
"}",
",",
"allWarnings",
",",
"actionerror",
".",
"OrganizationNameTakenError",
"{",
"Name",
":",
"orgName",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Organization",
"{",
"}",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"Organization",
"(",
"org",
")",
",",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // CreateOrganization creates an Organization based on the provided orgName. | [
"CreateOrganization",
"creates",
"an",
"Organization",
"based",
"on",
"the",
"provided",
"orgName",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L66-L91 | train |
cloudfoundry/cli | actor/v2action/organization.go | DeleteOrganization | func (actor Actor) DeleteOrganization(orgName string) (Warnings, error) {
var allWarnings Warnings
org, warnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
job, deleteWarnings, err := actor.CloudControllerClient.DeleteOrganizationJob(org.GUID)
allWarnings = append(allWarnings, deleteWarnings...)
if err != nil {
return allWarnings, err
}
ccWarnings, err := actor.CloudControllerClient.PollJob(job)
for _, warning := range ccWarnings {
allWarnings = append(allWarnings, warning)
}
return allWarnings, err
} | go | func (actor Actor) DeleteOrganization(orgName string) (Warnings, error) {
var allWarnings Warnings
org, warnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
job, deleteWarnings, err := actor.CloudControllerClient.DeleteOrganizationJob(org.GUID)
allWarnings = append(allWarnings, deleteWarnings...)
if err != nil {
return allWarnings, err
}
ccWarnings, err := actor.CloudControllerClient.PollJob(job)
for _, warning := range ccWarnings {
allWarnings = append(allWarnings, warning)
}
return allWarnings, err
} | [
"func",
"(",
"actor",
"Actor",
")",
"DeleteOrganization",
"(",
"orgName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"var",
"allWarnings",
"Warnings",
"\n\n",
"org",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"job",
",",
"deleteWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"DeleteOrganizationJob",
"(",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"deleteWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n\n",
"ccWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"PollJob",
"(",
"job",
")",
"\n",
"for",
"_",
",",
"warning",
":=",
"range",
"ccWarnings",
"{",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warning",
")",
"\n",
"}",
"\n\n",
"return",
"allWarnings",
",",
"err",
"\n",
"}"
] | // DeleteOrganization deletes the Organization associated with the provided
// GUID. Once the deletion request is sent, it polls the deletion job until
// it's finished. | [
"DeleteOrganization",
"deletes",
"the",
"Organization",
"associated",
"with",
"the",
"provided",
"GUID",
".",
"Once",
"the",
"deletion",
"request",
"is",
"sent",
"it",
"polls",
"the",
"deletion",
"job",
"until",
"it",
"s",
"finished",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L96-L117 | train |
cloudfoundry/cli | actor/v2action/organization.go | GetOrganizations | func (actor Actor) GetOrganizations() ([]Organization, Warnings, error) {
var returnedOrgs []Organization
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations()
for _, org := range orgs {
returnedOrgs = append(returnedOrgs, Organization(org))
}
return returnedOrgs, Warnings(warnings), err
} | go | func (actor Actor) GetOrganizations() ([]Organization, Warnings, error) {
var returnedOrgs []Organization
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations()
for _, org := range orgs {
returnedOrgs = append(returnedOrgs, Organization(org))
}
return returnedOrgs, Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetOrganizations",
"(",
")",
"(",
"[",
"]",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"var",
"returnedOrgs",
"[",
"]",
"Organization",
"\n",
"orgs",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganizations",
"(",
")",
"\n",
"for",
"_",
",",
"org",
":=",
"range",
"orgs",
"{",
"returnedOrgs",
"=",
"append",
"(",
"returnedOrgs",
",",
"Organization",
"(",
"org",
")",
")",
"\n",
"}",
"\n",
"return",
"returnedOrgs",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GetOrganizations returns all the available organizations. | [
"GetOrganizations",
"returns",
"all",
"the",
"available",
"organizations",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L120-L127 | train |
cloudfoundry/cli | actor/v2action/organization.go | OrganizationExistsWithName | func (actor Actor) OrganizationExistsWithName(orgName string) (bool, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(orgs) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | go | func (actor Actor) OrganizationExistsWithName(orgName string) (bool, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(orgs) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"OrganizationExistsWithName",
"(",
"orgName",
"string",
")",
"(",
"bool",
",",
"Warnings",
",",
"error",
")",
"{",
"orgs",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganizations",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"NameFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"orgName",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"orgs",
")",
"==",
"0",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}"
] | // OrganizationExistsWithName returns true if there is an Organization with the
// provided name, otherwise false. | [
"OrganizationExistsWithName",
"returns",
"true",
"if",
"there",
"is",
"an",
"Organization",
"with",
"the",
"provided",
"name",
"otherwise",
"false",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L131-L146 | train |
google/seesaw | ncc/client/ncc_client.go | call | func (nc *nccClient) call(name string, in interface{}, out interface{}) error {
nc.lock.RLock()
client := nc.client
nc.lock.RUnlock()
if client == nil {
return fmt.Errorf("Not connected")
}
ch := make(chan error, 1)
go func() {
ch <- client.Call(name, in, out)
}()
select {
case err := <-ch:
return err
case <-time.After(nccRPCTimeout):
return fmt.Errorf("RPC call timed out after %v", nccRPCTimeout)
}
} | go | func (nc *nccClient) call(name string, in interface{}, out interface{}) error {
nc.lock.RLock()
client := nc.client
nc.lock.RUnlock()
if client == nil {
return fmt.Errorf("Not connected")
}
ch := make(chan error, 1)
go func() {
ch <- client.Call(name, in, out)
}()
select {
case err := <-ch:
return err
case <-time.After(nccRPCTimeout):
return fmt.Errorf("RPC call timed out after %v", nccRPCTimeout)
}
} | [
"func",
"(",
"nc",
"*",
"nccClient",
")",
"call",
"(",
"name",
"string",
",",
"in",
"interface",
"{",
"}",
",",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"nc",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"client",
":=",
"nc",
".",
"client",
"\n",
"nc",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"client",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ch",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"ch",
"<-",
"client",
".",
"Call",
"(",
"name",
",",
"in",
",",
"out",
")",
"\n",
"}",
"(",
")",
"\n",
"select",
"{",
"case",
"err",
":=",
"<-",
"ch",
":",
"return",
"err",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"nccRPCTimeout",
")",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nccRPCTimeout",
")",
"\n",
"}",
"\n",
"}"
] | // call performs an RPC call to the Seesaw v2 nccClient. | [
"call",
"performs",
"an",
"RPC",
"call",
"to",
"the",
"Seesaw",
"v2",
"nccClient",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/client/ncc_client.go#L159-L176 | train |
google/seesaw | healthcheck/core.go | String | func (s State) String() string {
if name, ok := stateNames[s]; ok {
return name
}
return "<unknown>"
} | go | func (s State) String() string {
if name, ok := stateNames[s]; ok {
return name
}
return "<unknown>"
} | [
"func",
"(",
"s",
"State",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"stateNames",
"[",
"s",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String returns the string representation for the given healthcheck state. | [
"String",
"returns",
"the",
"string",
"representation",
"for",
"the",
"given",
"healthcheck",
"state",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L67-L72 | train |
google/seesaw | healthcheck/core.go | String | func (t Target) String() string {
var via string
if t.Mode == seesaw.HCModeDSR {
via = fmt.Sprintf(" (via %s mark %d)", t.Host, t.Mark)
}
return fmt.Sprintf("%s %s%s", t.addr(), t.Mode, via)
} | go | func (t Target) String() string {
var via string
if t.Mode == seesaw.HCModeDSR {
via = fmt.Sprintf(" (via %s mark %d)", t.Host, t.Mark)
}
return fmt.Sprintf("%s %s%s", t.addr(), t.Mode, via)
} | [
"func",
"(",
"t",
"Target",
")",
"String",
"(",
")",
"string",
"{",
"var",
"via",
"string",
"\n",
"if",
"t",
".",
"Mode",
"==",
"seesaw",
".",
"HCModeDSR",
"{",
"via",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Host",
",",
"t",
".",
"Mark",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"addr",
"(",
")",
",",
"t",
".",
"Mode",
",",
"via",
")",
"\n",
"}"
] | // String returns the string representation of a healthcheck target. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"healthcheck",
"target",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L91-L97 | train |
google/seesaw | healthcheck/core.go | addr | func (t *Target) addr() string {
if t.IP.To4() != nil {
return fmt.Sprintf("%v:%d", t.IP, t.Port)
}
return fmt.Sprintf("[%v]:%d", t.IP, t.Port)
} | go | func (t *Target) addr() string {
if t.IP.To4() != nil {
return fmt.Sprintf("%v:%d", t.IP, t.Port)
}
return fmt.Sprintf("[%v]:%d", t.IP, t.Port)
} | [
"func",
"(",
"t",
"*",
"Target",
")",
"addr",
"(",
")",
"string",
"{",
"if",
"t",
".",
"IP",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"IP",
",",
"t",
".",
"Port",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"IP",
",",
"t",
".",
"Port",
")",
"\n",
"}"
] | // addr returns the address string for the healthcheck target. | [
"addr",
"returns",
"the",
"address",
"string",
"for",
"the",
"healthcheck",
"target",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L100-L105 | train |
google/seesaw | healthcheck/core.go | network | func (t *Target) network() string {
version := 4
if t.IP.To4() == nil {
version = 6
}
var network string
switch t.Proto {
case seesaw.IPProtoICMP:
network = "ip4:icmp"
case seesaw.IPProtoICMPv6:
network = "ip6:ipv6-icmp"
case seesaw.IPProtoTCP:
network = fmt.Sprintf("tcp%d", version)
case seesaw.IPProtoUDP:
network = fmt.Sprintf("udp%d", version)
default:
return "(unknown)"
}
return network
} | go | func (t *Target) network() string {
version := 4
if t.IP.To4() == nil {
version = 6
}
var network string
switch t.Proto {
case seesaw.IPProtoICMP:
network = "ip4:icmp"
case seesaw.IPProtoICMPv6:
network = "ip6:ipv6-icmp"
case seesaw.IPProtoTCP:
network = fmt.Sprintf("tcp%d", version)
case seesaw.IPProtoUDP:
network = fmt.Sprintf("udp%d", version)
default:
return "(unknown)"
}
return network
} | [
"func",
"(",
"t",
"*",
"Target",
")",
"network",
"(",
")",
"string",
"{",
"version",
":=",
"4",
"\n",
"if",
"t",
".",
"IP",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"version",
"=",
"6",
"\n",
"}",
"\n\n",
"var",
"network",
"string",
"\n",
"switch",
"t",
".",
"Proto",
"{",
"case",
"seesaw",
".",
"IPProtoICMP",
":",
"network",
"=",
"\"",
"\"",
"\n",
"case",
"seesaw",
".",
"IPProtoICMPv6",
":",
"network",
"=",
"\"",
"\"",
"\n",
"case",
"seesaw",
".",
"IPProtoTCP",
":",
"network",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"version",
")",
"\n",
"case",
"seesaw",
".",
"IPProtoUDP",
":",
"network",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"version",
")",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"network",
"\n",
"}"
] | // network returns the network name for the healthcheck target. | [
"network",
"returns",
"the",
"network",
"name",
"for",
"the",
"healthcheck",
"target",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L108-L129 | train |
google/seesaw | healthcheck/core.go | String | func (r *Result) String() string {
if r.Err != nil {
return r.Err.Error()
}
return r.Message
} | go | func (r *Result) String() string {
if r.Err != nil {
return r.Err.Error()
}
return r.Message
} | [
"func",
"(",
"r",
"*",
"Result",
")",
"String",
"(",
")",
"string",
"{",
"if",
"r",
".",
"Err",
"!=",
"nil",
"{",
"return",
"r",
".",
"Err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"Message",
"\n",
"}"
] | // String returns the string representation of a healthcheck result. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"healthcheck",
"result",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L140-L145 | train |
google/seesaw | healthcheck/core.go | complete | func complete(start time.Time, msg string, success bool, err error) *Result {
// TODO(jsing): Make this clock skew safe.
duration := time.Since(start)
return &Result{msg, success, duration, err}
} | go | func complete(start time.Time, msg string, success bool, err error) *Result {
// TODO(jsing): Make this clock skew safe.
duration := time.Since(start)
return &Result{msg, success, duration, err}
} | [
"func",
"complete",
"(",
"start",
"time",
".",
"Time",
",",
"msg",
"string",
",",
"success",
"bool",
",",
"err",
"error",
")",
"*",
"Result",
"{",
"// TODO(jsing): Make this clock skew safe.",
"duration",
":=",
"time",
".",
"Since",
"(",
"start",
")",
"\n",
"return",
"&",
"Result",
"{",
"msg",
",",
"success",
",",
"duration",
",",
"err",
"}",
"\n",
"}"
] | // complete returns a Result for a completed healthcheck. | [
"complete",
"returns",
"a",
"Result",
"for",
"a",
"completed",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L148-L152 | train |
google/seesaw | healthcheck/core.go | String | func (n *Notification) String() string {
return fmt.Sprintf("ID 0x%x %v", n.Id, n.State)
} | go | func (n *Notification) String() string {
return fmt.Sprintf("ID 0x%x %v", n.Id, n.State)
} | [
"func",
"(",
"n",
"*",
"Notification",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"n",
".",
"Id",
",",
"n",
".",
"State",
")",
"\n",
"}"
] | // String returns the string representation for the given notification. | [
"String",
"returns",
"the",
"string",
"representation",
"for",
"the",
"given",
"notification",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L161-L163 | train |
google/seesaw | healthcheck/core.go | NewConfig | func NewConfig(id Id, checker Checker) *Config {
return &Config{
Id: id,
Interval: 5 * time.Second,
Timeout: 30 * time.Second,
Retries: 0,
Checker: checker,
}
} | go | func NewConfig(id Id, checker Checker) *Config {
return &Config{
Id: id,
Interval: 5 * time.Second,
Timeout: 30 * time.Second,
Retries: 0,
Checker: checker,
}
} | [
"func",
"NewConfig",
"(",
"id",
"Id",
",",
"checker",
"Checker",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"Id",
":",
"id",
",",
"Interval",
":",
"5",
"*",
"time",
".",
"Second",
",",
"Timeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"Retries",
":",
"0",
",",
"Checker",
":",
"checker",
",",
"}",
"\n",
"}"
] | // NewConfig returns an initialised Config. | [
"NewConfig",
"returns",
"an",
"initialised",
"Config",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L186-L194 | train |
google/seesaw | healthcheck/core.go | NewCheck | func NewCheck(notify chan<- *Notification) *Check {
return &Check{
state: StateUnknown,
notify: notify,
update: make(chan Config, 1),
quit: make(chan bool, 1),
}
} | go | func NewCheck(notify chan<- *Notification) *Check {
return &Check{
state: StateUnknown,
notify: notify,
update: make(chan Config, 1),
quit: make(chan bool, 1),
}
} | [
"func",
"NewCheck",
"(",
"notify",
"chan",
"<-",
"*",
"Notification",
")",
"*",
"Check",
"{",
"return",
"&",
"Check",
"{",
"state",
":",
"StateUnknown",
",",
"notify",
":",
"notify",
",",
"update",
":",
"make",
"(",
"chan",
"Config",
",",
"1",
")",
",",
"quit",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"}",
"\n",
"}"
] | // NewCheck returns an initialised Check. | [
"NewCheck",
"returns",
"an",
"initialised",
"Check",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L225-L232 | train |
google/seesaw | healthcheck/core.go | Status | func (hc *Check) Status() Status {
hc.lock.RLock()
defer hc.lock.RUnlock()
status := Status{
LastCheck: hc.start,
Failures: hc.failures,
Successes: hc.successes,
State: hc.state,
}
if hc.result != nil {
status.Duration = hc.result.Duration
status.Message = hc.result.String()
}
return status
} | go | func (hc *Check) Status() Status {
hc.lock.RLock()
defer hc.lock.RUnlock()
status := Status{
LastCheck: hc.start,
Failures: hc.failures,
Successes: hc.successes,
State: hc.state,
}
if hc.result != nil {
status.Duration = hc.result.Duration
status.Message = hc.result.String()
}
return status
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Status",
"(",
")",
"Status",
"{",
"hc",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"hc",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"status",
":=",
"Status",
"{",
"LastCheck",
":",
"hc",
".",
"start",
",",
"Failures",
":",
"hc",
".",
"failures",
",",
"Successes",
":",
"hc",
".",
"successes",
",",
"State",
":",
"hc",
".",
"state",
",",
"}",
"\n",
"if",
"hc",
".",
"result",
"!=",
"nil",
"{",
"status",
".",
"Duration",
"=",
"hc",
".",
"result",
".",
"Duration",
"\n",
"status",
".",
"Message",
"=",
"hc",
".",
"result",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"status",
"\n",
"}"
] | // Status returns the current status for this healthcheck instance. | [
"Status",
"returns",
"the",
"current",
"status",
"for",
"this",
"healthcheck",
"instance",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L235-L249 | train |
google/seesaw | healthcheck/core.go | Run | func (hc *Check) Run(start <-chan time.Time) {
// Wait for initial configuration.
select {
case config := <-hc.update:
hc.Config = config
case <-hc.quit:
return
}
// Wait for a tick to avoid a thundering herd at startup and to
// stagger healthchecks that have the same interval.
if start != nil {
<-start
}
log.Infof("Starting healthchecker for %d (%s)", hc.Id, hc)
ticker := time.NewTicker(hc.Interval)
hc.healthcheck()
for {
select {
case <-hc.quit:
ticker.Stop()
log.Infof("Stopping healthchecker for %d (%s)", hc.Id, hc)
return
case config := <-hc.update:
if hc.Interval != config.Interval {
ticker.Stop()
if start != nil {
<-start
}
ticker = time.NewTicker(config.Interval)
}
hc.Config = config
case <-ticker.C:
hc.healthcheck()
}
}
} | go | func (hc *Check) Run(start <-chan time.Time) {
// Wait for initial configuration.
select {
case config := <-hc.update:
hc.Config = config
case <-hc.quit:
return
}
// Wait for a tick to avoid a thundering herd at startup and to
// stagger healthchecks that have the same interval.
if start != nil {
<-start
}
log.Infof("Starting healthchecker for %d (%s)", hc.Id, hc)
ticker := time.NewTicker(hc.Interval)
hc.healthcheck()
for {
select {
case <-hc.quit:
ticker.Stop()
log.Infof("Stopping healthchecker for %d (%s)", hc.Id, hc)
return
case config := <-hc.update:
if hc.Interval != config.Interval {
ticker.Stop()
if start != nil {
<-start
}
ticker = time.NewTicker(config.Interval)
}
hc.Config = config
case <-ticker.C:
hc.healthcheck()
}
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Run",
"(",
"start",
"<-",
"chan",
"time",
".",
"Time",
")",
"{",
"// Wait for initial configuration.",
"select",
"{",
"case",
"config",
":=",
"<-",
"hc",
".",
"update",
":",
"hc",
".",
"Config",
"=",
"config",
"\n",
"case",
"<-",
"hc",
".",
"quit",
":",
"return",
"\n",
"}",
"\n\n",
"// Wait for a tick to avoid a thundering herd at startup and to",
"// stagger healthchecks that have the same interval.",
"if",
"start",
"!=",
"nil",
"{",
"<-",
"start",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"hc",
".",
"Id",
",",
"hc",
")",
"\n\n",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"hc",
".",
"Interval",
")",
"\n",
"hc",
".",
"healthcheck",
"(",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"hc",
".",
"quit",
":",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"hc",
".",
"Id",
",",
"hc",
")",
"\n",
"return",
"\n\n",
"case",
"config",
":=",
"<-",
"hc",
".",
"update",
":",
"if",
"hc",
".",
"Interval",
"!=",
"config",
".",
"Interval",
"{",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"if",
"start",
"!=",
"nil",
"{",
"<-",
"start",
"\n",
"}",
"\n",
"ticker",
"=",
"time",
".",
"NewTicker",
"(",
"config",
".",
"Interval",
")",
"\n",
"}",
"\n",
"hc",
".",
"Config",
"=",
"config",
"\n\n",
"case",
"<-",
"ticker",
".",
"C",
":",
"hc",
".",
"healthcheck",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Run invokes a healthcheck. It waits for the initial configuration to be
// provided via the configuration channel, after which the configured
// healthchecker is invoked at the given interval. If a new configuration
// is provided the healthchecker is updated and checks are scheduled at the
// new interval. Notifications are generated and sent via the notification
// channel whenever a state transition occurs. Run will terminate once a
// value is received on the quit channel. | [
"Run",
"invokes",
"a",
"healthcheck",
".",
"It",
"waits",
"for",
"the",
"initial",
"configuration",
"to",
"be",
"provided",
"via",
"the",
"configuration",
"channel",
"after",
"which",
"the",
"configured",
"healthchecker",
"is",
"invoked",
"at",
"the",
"given",
"interval",
".",
"If",
"a",
"new",
"configuration",
"is",
"provided",
"the",
"healthchecker",
"is",
"updated",
"and",
"checks",
"are",
"scheduled",
"at",
"the",
"new",
"interval",
".",
"Notifications",
"are",
"generated",
"and",
"sent",
"via",
"the",
"notification",
"channel",
"whenever",
"a",
"state",
"transition",
"occurs",
".",
"Run",
"will",
"terminate",
"once",
"a",
"value",
"is",
"received",
"on",
"the",
"quit",
"channel",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L258-L298 | train |
google/seesaw | healthcheck/core.go | healthcheck | func (hc *Check) healthcheck() {
if hc.Checker == nil {
return
}
start := time.Now()
result := hc.execute()
status := "SUCCESS"
if !result.Success {
status = "FAILURE"
}
log.Infof("%d: (%s) %s: %v", hc.Id, hc, status, result)
hc.lock.Lock()
hc.start = start
hc.result = result
var state State
if result.Success {
state = StateHealthy
hc.failed = 0
hc.successes++
} else {
hc.failed++
hc.failures++
state = StateUnhealthy
}
if hc.state == StateHealthy && hc.failed > 0 && hc.failed <= uint64(hc.Config.Retries) {
log.Infof("%d: Failure %d - retrying...", hc.Id, hc.failed)
state = StateHealthy
}
transition := (hc.state != state)
hc.state = state
hc.lock.Unlock()
if transition {
hc.Notify()
}
} | go | func (hc *Check) healthcheck() {
if hc.Checker == nil {
return
}
start := time.Now()
result := hc.execute()
status := "SUCCESS"
if !result.Success {
status = "FAILURE"
}
log.Infof("%d: (%s) %s: %v", hc.Id, hc, status, result)
hc.lock.Lock()
hc.start = start
hc.result = result
var state State
if result.Success {
state = StateHealthy
hc.failed = 0
hc.successes++
} else {
hc.failed++
hc.failures++
state = StateUnhealthy
}
if hc.state == StateHealthy && hc.failed > 0 && hc.failed <= uint64(hc.Config.Retries) {
log.Infof("%d: Failure %d - retrying...", hc.Id, hc.failed)
state = StateHealthy
}
transition := (hc.state != state)
hc.state = state
hc.lock.Unlock()
if transition {
hc.Notify()
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"healthcheck",
"(",
")",
"{",
"if",
"hc",
".",
"Checker",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"result",
":=",
"hc",
".",
"execute",
"(",
")",
"\n\n",
"status",
":=",
"\"",
"\"",
"\n",
"if",
"!",
"result",
".",
"Success",
"{",
"status",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"hc",
".",
"Id",
",",
"hc",
",",
"status",
",",
"result",
")",
"\n\n",
"hc",
".",
"lock",
".",
"Lock",
"(",
")",
"\n\n",
"hc",
".",
"start",
"=",
"start",
"\n",
"hc",
".",
"result",
"=",
"result",
"\n\n",
"var",
"state",
"State",
"\n",
"if",
"result",
".",
"Success",
"{",
"state",
"=",
"StateHealthy",
"\n",
"hc",
".",
"failed",
"=",
"0",
"\n",
"hc",
".",
"successes",
"++",
"\n",
"}",
"else",
"{",
"hc",
".",
"failed",
"++",
"\n",
"hc",
".",
"failures",
"++",
"\n",
"state",
"=",
"StateUnhealthy",
"\n",
"}",
"\n\n",
"if",
"hc",
".",
"state",
"==",
"StateHealthy",
"&&",
"hc",
".",
"failed",
">",
"0",
"&&",
"hc",
".",
"failed",
"<=",
"uint64",
"(",
"hc",
".",
"Config",
".",
"Retries",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"hc",
".",
"Id",
",",
"hc",
".",
"failed",
")",
"\n",
"state",
"=",
"StateHealthy",
"\n",
"}",
"\n",
"transition",
":=",
"(",
"hc",
".",
"state",
"!=",
"state",
")",
"\n",
"hc",
".",
"state",
"=",
"state",
"\n\n",
"hc",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"transition",
"{",
"hc",
".",
"Notify",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // healthcheck executes the given checker. | [
"healthcheck",
"executes",
"the",
"given",
"checker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L301-L342 | train |
google/seesaw | healthcheck/core.go | Notify | func (hc *Check) Notify() {
hc.notify <- &Notification{
Id: hc.Id,
Status: hc.Status(),
}
} | go | func (hc *Check) Notify() {
hc.notify <- &Notification{
Id: hc.Id,
Status: hc.Status(),
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Notify",
"(",
")",
"{",
"hc",
".",
"notify",
"<-",
"&",
"Notification",
"{",
"Id",
":",
"hc",
".",
"Id",
",",
"Status",
":",
"hc",
".",
"Status",
"(",
")",
",",
"}",
"\n",
"}"
] | // Notify generates a healthcheck notification for this checker. | [
"Notify",
"generates",
"a",
"healthcheck",
"notification",
"for",
"this",
"checker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L345-L350 | train |
google/seesaw | healthcheck/core.go | execute | func (hc *Check) execute() *Result {
ch := make(chan *Result, 1)
checker := hc.Checker
go func() {
// TODO(jsing): Determine a way to ensure that this go routine
// does not linger.
ch <- checker.Check(hc.Timeout)
}()
select {
case result := <-ch:
return result
case <-time.After(hc.Timeout):
return &Result{"Timed out", false, hc.Timeout, nil}
}
} | go | func (hc *Check) execute() *Result {
ch := make(chan *Result, 1)
checker := hc.Checker
go func() {
// TODO(jsing): Determine a way to ensure that this go routine
// does not linger.
ch <- checker.Check(hc.Timeout)
}()
select {
case result := <-ch:
return result
case <-time.After(hc.Timeout):
return &Result{"Timed out", false, hc.Timeout, nil}
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"execute",
"(",
")",
"*",
"Result",
"{",
"ch",
":=",
"make",
"(",
"chan",
"*",
"Result",
",",
"1",
")",
"\n",
"checker",
":=",
"hc",
".",
"Checker",
"\n",
"go",
"func",
"(",
")",
"{",
"// TODO(jsing): Determine a way to ensure that this go routine",
"// does not linger.",
"ch",
"<-",
"checker",
".",
"Check",
"(",
"hc",
".",
"Timeout",
")",
"\n",
"}",
"(",
")",
"\n",
"select",
"{",
"case",
"result",
":=",
"<-",
"ch",
":",
"return",
"result",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"hc",
".",
"Timeout",
")",
":",
"return",
"&",
"Result",
"{",
"\"",
"\"",
",",
"false",
",",
"hc",
".",
"Timeout",
",",
"nil",
"}",
"\n",
"}",
"\n",
"}"
] | // execute invokes the given healthcheck checker with the configured timeout. | [
"execute",
"invokes",
"the",
"given",
"healthcheck",
"checker",
"with",
"the",
"configured",
"timeout",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L353-L367 | train |
google/seesaw | healthcheck/core.go | Blocking | func (hc *Check) Blocking(block bool) {
len := 0
if !block {
len = 1
}
hc.blocking = block
hc.update = make(chan Config, len)
} | go | func (hc *Check) Blocking(block bool) {
len := 0
if !block {
len = 1
}
hc.blocking = block
hc.update = make(chan Config, len)
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Blocking",
"(",
"block",
"bool",
")",
"{",
"len",
":=",
"0",
"\n",
"if",
"!",
"block",
"{",
"len",
"=",
"1",
"\n",
"}",
"\n",
"hc",
".",
"blocking",
"=",
"block",
"\n",
"hc",
".",
"update",
"=",
"make",
"(",
"chan",
"Config",
",",
"len",
")",
"\n",
"}"
] | // Blocking enables or disables blocking updates for a healthcheck. | [
"Blocking",
"enables",
"or",
"disables",
"blocking",
"updates",
"for",
"a",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L378-L385 | train |
google/seesaw | healthcheck/core.go | Update | func (hc *Check) Update(config *Config) {
if hc.blocking {
hc.update <- *config
return
}
select {
case hc.update <- *config:
default:
log.Warningf("Unable to update %d (%s), last update still queued", hc.Id, hc)
}
} | go | func (hc *Check) Update(config *Config) {
if hc.blocking {
hc.update <- *config
return
}
select {
case hc.update <- *config:
default:
log.Warningf("Unable to update %d (%s), last update still queued", hc.Id, hc)
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Update",
"(",
"config",
"*",
"Config",
")",
"{",
"if",
"hc",
".",
"blocking",
"{",
"hc",
".",
"update",
"<-",
"*",
"config",
"\n",
"return",
"\n",
"}",
"\n",
"select",
"{",
"case",
"hc",
".",
"update",
"<-",
"*",
"config",
":",
"default",
":",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"hc",
".",
"Id",
",",
"hc",
")",
"\n",
"}",
"\n",
"}"
] | // Update queues a healthcheck configuration update for processing. | [
"Update",
"queues",
"a",
"healthcheck",
"configuration",
"update",
"for",
"processing",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L388-L398 | train |
google/seesaw | healthcheck/core.go | NewServer | func NewServer(cfg *ServerConfig) *Server {
if cfg == nil {
defaultCfg := DefaultServerConfig()
cfg = &defaultCfg
}
return &Server{
config: cfg,
healthchecks: make(map[Id]*Check),
notify: make(chan *Notification, cfg.ChannelSize),
configs: make(chan map[Id]*Config),
batch: make([]*Notification, 0, cfg.BatchSize),
quit: make(chan bool, 1),
}
} | go | func NewServer(cfg *ServerConfig) *Server {
if cfg == nil {
defaultCfg := DefaultServerConfig()
cfg = &defaultCfg
}
return &Server{
config: cfg,
healthchecks: make(map[Id]*Check),
notify: make(chan *Notification, cfg.ChannelSize),
configs: make(chan map[Id]*Config),
batch: make([]*Notification, 0, cfg.BatchSize),
quit: make(chan bool, 1),
}
} | [
"func",
"NewServer",
"(",
"cfg",
"*",
"ServerConfig",
")",
"*",
"Server",
"{",
"if",
"cfg",
"==",
"nil",
"{",
"defaultCfg",
":=",
"DefaultServerConfig",
"(",
")",
"\n",
"cfg",
"=",
"&",
"defaultCfg",
"\n",
"}",
"\n",
"return",
"&",
"Server",
"{",
"config",
":",
"cfg",
",",
"healthchecks",
":",
"make",
"(",
"map",
"[",
"Id",
"]",
"*",
"Check",
")",
",",
"notify",
":",
"make",
"(",
"chan",
"*",
"Notification",
",",
"cfg",
".",
"ChannelSize",
")",
",",
"configs",
":",
"make",
"(",
"chan",
"map",
"[",
"Id",
"]",
"*",
"Config",
")",
",",
"batch",
":",
"make",
"(",
"[",
"]",
"*",
"Notification",
",",
"0",
",",
"cfg",
".",
"BatchSize",
")",
",",
"quit",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"}",
"\n",
"}"
] | // NewServer returns an initialised healthcheck server. | [
"NewServer",
"returns",
"an",
"initialised",
"healthcheck",
"server",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L439-L454 | train |
google/seesaw | healthcheck/core.go | Run | func (s *Server) Run() {
go s.updater()
go s.notifier()
go s.manager()
<-s.quit
} | go | func (s *Server) Run() {
go s.updater()
go s.notifier()
go s.manager()
<-s.quit
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Run",
"(",
")",
"{",
"go",
"s",
".",
"updater",
"(",
")",
"\n",
"go",
"s",
".",
"notifier",
"(",
")",
"\n",
"go",
"s",
".",
"manager",
"(",
")",
"\n\n",
"<-",
"s",
".",
"quit",
"\n",
"}"
] | // Run runs a healthcheck server. | [
"Run",
"runs",
"a",
"healthcheck",
"server",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L465-L471 | train |
google/seesaw | healthcheck/core.go | getHealthchecks | func (s *Server) getHealthchecks() (*Checks, error) {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return nil, fmt.Errorf("Dial failed: %v", err)
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var checks Checks
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
if err := engine.Call("SeesawEngine.Healthchecks", ctx, &checks); err != nil {
return nil, fmt.Errorf("SeesawEngine.Healthchecks failed: %v", err)
}
return &checks, nil
} | go | func (s *Server) getHealthchecks() (*Checks, error) {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return nil, fmt.Errorf("Dial failed: %v", err)
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var checks Checks
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
if err := engine.Call("SeesawEngine.Healthchecks", ctx, &checks); err != nil {
return nil, fmt.Errorf("SeesawEngine.Healthchecks failed: %v", err)
}
return &checks, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"getHealthchecks",
"(",
")",
"(",
"*",
"Checks",
",",
"error",
")",
"{",
"engineConn",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"\"",
"\"",
",",
"s",
".",
"config",
".",
"EngineSocket",
",",
"engineTimeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"engineConn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"engineTimeout",
")",
")",
"\n",
"engine",
":=",
"rpc",
".",
"NewClient",
"(",
"engineConn",
")",
"\n",
"defer",
"engine",
".",
"Close",
"(",
")",
"\n\n",
"var",
"checks",
"Checks",
"\n",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCHealthcheck",
")",
"\n",
"if",
"err",
":=",
"engine",
".",
"Call",
"(",
"\"",
"\"",
",",
"ctx",
",",
"&",
"checks",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"checks",
",",
"nil",
"\n",
"}"
] | // getHealthchecks attempts to get the current healthcheck configurations from
// the Seesaw Engine. | [
"getHealthchecks",
"attempts",
"to",
"get",
"the",
"current",
"healthcheck",
"configurations",
"from",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L475-L491 | train |
google/seesaw | healthcheck/core.go | updater | func (s *Server) updater() {
for {
log.Info("Getting healthchecks from engine...")
checks, err := s.getHealthchecks()
if err != nil {
log.Error(err)
time.Sleep(5 * time.Second)
} else {
log.Infof("Engine returned %d healthchecks", len(checks.Configs))
s.configs <- checks.Configs
time.Sleep(15 * time.Second)
}
}
} | go | func (s *Server) updater() {
for {
log.Info("Getting healthchecks from engine...")
checks, err := s.getHealthchecks()
if err != nil {
log.Error(err)
time.Sleep(5 * time.Second)
} else {
log.Infof("Engine returned %d healthchecks", len(checks.Configs))
s.configs <- checks.Configs
time.Sleep(15 * time.Second)
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"updater",
"(",
")",
"{",
"for",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"checks",
",",
"err",
":=",
"s",
".",
"getHealthchecks",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"time",
".",
"Sleep",
"(",
"5",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"len",
"(",
"checks",
".",
"Configs",
")",
")",
"\n",
"s",
".",
"configs",
"<-",
"checks",
".",
"Configs",
"\n",
"time",
".",
"Sleep",
"(",
"15",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // updater attempts to fetch healthcheck configurations at regular intervals.
// When configurations are successfully retrieved they are provided to the
// manager via the configs channel. | [
"updater",
"attempts",
"to",
"fetch",
"healthcheck",
"configurations",
"at",
"regular",
"intervals",
".",
"When",
"configurations",
"are",
"successfully",
"retrieved",
"they",
"are",
"provided",
"to",
"the",
"manager",
"via",
"the",
"configs",
"channel",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L496-L509 | train |
google/seesaw | healthcheck/core.go | manager | func (s *Server) manager() {
checkTicker := time.NewTicker(50 * time.Millisecond)
notifyTicker := time.NewTicker(s.config.NotifyInterval)
for {
select {
case configs := <-s.configs:
// Remove healthchecks that have been deleted.
for id, hc := range s.healthchecks {
if configs[id] == nil {
hc.Stop()
delete(s.healthchecks, id)
}
}
// Spawn new healthchecks.
for id := range configs {
if s.healthchecks[id] == nil {
hc := NewCheck(s.notify)
s.healthchecks[id] = hc
go hc.Run(checkTicker.C)
}
}
// Update configurations.
for id, hc := range s.healthchecks {
hc.Update(configs[id])
}
case <-notifyTicker.C:
// Send status notifications for all healthchecks.
for _, hc := range s.healthchecks {
hc.Notify()
}
}
}
} | go | func (s *Server) manager() {
checkTicker := time.NewTicker(50 * time.Millisecond)
notifyTicker := time.NewTicker(s.config.NotifyInterval)
for {
select {
case configs := <-s.configs:
// Remove healthchecks that have been deleted.
for id, hc := range s.healthchecks {
if configs[id] == nil {
hc.Stop()
delete(s.healthchecks, id)
}
}
// Spawn new healthchecks.
for id := range configs {
if s.healthchecks[id] == nil {
hc := NewCheck(s.notify)
s.healthchecks[id] = hc
go hc.Run(checkTicker.C)
}
}
// Update configurations.
for id, hc := range s.healthchecks {
hc.Update(configs[id])
}
case <-notifyTicker.C:
// Send status notifications for all healthchecks.
for _, hc := range s.healthchecks {
hc.Notify()
}
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"manager",
"(",
")",
"{",
"checkTicker",
":=",
"time",
".",
"NewTicker",
"(",
"50",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"notifyTicker",
":=",
"time",
".",
"NewTicker",
"(",
"s",
".",
"config",
".",
"NotifyInterval",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"configs",
":=",
"<-",
"s",
".",
"configs",
":",
"// Remove healthchecks that have been deleted.",
"for",
"id",
",",
"hc",
":=",
"range",
"s",
".",
"healthchecks",
"{",
"if",
"configs",
"[",
"id",
"]",
"==",
"nil",
"{",
"hc",
".",
"Stop",
"(",
")",
"\n",
"delete",
"(",
"s",
".",
"healthchecks",
",",
"id",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Spawn new healthchecks.",
"for",
"id",
":=",
"range",
"configs",
"{",
"if",
"s",
".",
"healthchecks",
"[",
"id",
"]",
"==",
"nil",
"{",
"hc",
":=",
"NewCheck",
"(",
"s",
".",
"notify",
")",
"\n",
"s",
".",
"healthchecks",
"[",
"id",
"]",
"=",
"hc",
"\n",
"go",
"hc",
".",
"Run",
"(",
"checkTicker",
".",
"C",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Update configurations.",
"for",
"id",
",",
"hc",
":=",
"range",
"s",
".",
"healthchecks",
"{",
"hc",
".",
"Update",
"(",
"configs",
"[",
"id",
"]",
")",
"\n",
"}",
"\n",
"case",
"<-",
"notifyTicker",
".",
"C",
":",
"// Send status notifications for all healthchecks.",
"for",
"_",
",",
"hc",
":=",
"range",
"s",
".",
"healthchecks",
"{",
"hc",
".",
"Notify",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // manager is responsible for controlling the healthchecks that are currently
// running. When healthcheck configurations become available, the manager will
// stop and remove deleted healthchecks, spawn new healthchecks and provide
// the current configurations to each of the running healthchecks. | [
"manager",
"is",
"responsible",
"for",
"controlling",
"the",
"healthchecks",
"that",
"are",
"currently",
"running",
".",
"When",
"healthcheck",
"configurations",
"become",
"available",
"the",
"manager",
"will",
"stop",
"and",
"remove",
"deleted",
"healthchecks",
"spawn",
"new",
"healthchecks",
"and",
"provide",
"the",
"current",
"configurations",
"to",
"each",
"of",
"the",
"running",
"healthchecks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L515-L550 | train |
google/seesaw | healthcheck/core.go | notifier | func (s *Server) notifier() {
var timer <-chan time.Time
for {
var err error
select {
case notification := <-s.notify:
s.batch = append(s.batch, notification)
// Collect until BatchDelay passes, or BatchSize are queued.
switch len(s.batch) {
case 1:
timer = time.After(s.config.BatchDelay)
case s.config.BatchSize:
err = s.send()
timer = nil
}
case <-timer:
err = s.send()
}
if err != nil {
log.Fatal(err)
}
}
} | go | func (s *Server) notifier() {
var timer <-chan time.Time
for {
var err error
select {
case notification := <-s.notify:
s.batch = append(s.batch, notification)
// Collect until BatchDelay passes, or BatchSize are queued.
switch len(s.batch) {
case 1:
timer = time.After(s.config.BatchDelay)
case s.config.BatchSize:
err = s.send()
timer = nil
}
case <-timer:
err = s.send()
}
if err != nil {
log.Fatal(err)
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"notifier",
"(",
")",
"{",
"var",
"timer",
"<-",
"chan",
"time",
".",
"Time",
"\n",
"for",
"{",
"var",
"err",
"error",
"\n",
"select",
"{",
"case",
"notification",
":=",
"<-",
"s",
".",
"notify",
":",
"s",
".",
"batch",
"=",
"append",
"(",
"s",
".",
"batch",
",",
"notification",
")",
"\n",
"// Collect until BatchDelay passes, or BatchSize are queued.",
"switch",
"len",
"(",
"s",
".",
"batch",
")",
"{",
"case",
"1",
":",
"timer",
"=",
"time",
".",
"After",
"(",
"s",
".",
"config",
".",
"BatchDelay",
")",
"\n",
"case",
"s",
".",
"config",
".",
"BatchSize",
":",
"err",
"=",
"s",
".",
"send",
"(",
")",
"\n",
"timer",
"=",
"nil",
"\n",
"}",
"\n\n",
"case",
"<-",
"timer",
":",
"err",
"=",
"s",
".",
"send",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // notifier batches healthcheck notifications and sends them to the Seesaw
// Engine. | [
"notifier",
"batches",
"healthcheck",
"notifications",
"and",
"sends",
"them",
"to",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L554-L578 | train |
google/seesaw | healthcheck/core.go | send | func (s *Server) send() error {
failures := 0
for {
err := s.sendBatch(s.batch)
if err == nil {
break
}
failures++
log.Errorf("Send failed %d times: %v", failures, err)
if failures >= s.config.MaxFailures {
return fmt.Errorf("send: %d errors, giving up", failures)
}
time.Sleep(s.config.RetryDelay)
}
s.batch = s.batch[:0]
return nil
} | go | func (s *Server) send() error {
failures := 0
for {
err := s.sendBatch(s.batch)
if err == nil {
break
}
failures++
log.Errorf("Send failed %d times: %v", failures, err)
if failures >= s.config.MaxFailures {
return fmt.Errorf("send: %d errors, giving up", failures)
}
time.Sleep(s.config.RetryDelay)
}
s.batch = s.batch[:0]
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"send",
"(",
")",
"error",
"{",
"failures",
":=",
"0",
"\n",
"for",
"{",
"err",
":=",
"s",
".",
"sendBatch",
"(",
"s",
".",
"batch",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"failures",
"++",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"failures",
",",
"err",
")",
"\n",
"if",
"failures",
">=",
"s",
".",
"config",
".",
"MaxFailures",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"failures",
")",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"s",
".",
"config",
".",
"RetryDelay",
")",
"\n",
"}",
"\n\n",
"s",
".",
"batch",
"=",
"s",
".",
"batch",
"[",
":",
"0",
"]",
"\n",
"return",
"nil",
"\n",
"}"
] | // send sends a batch of notifications to the Seesaw Engine, retrying on any
// error and giving up after MaxFailures. | [
"send",
"sends",
"a",
"batch",
"of",
"notifications",
"to",
"the",
"Seesaw",
"Engine",
"retrying",
"on",
"any",
"error",
"and",
"giving",
"up",
"after",
"MaxFailures",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L582-L601 | train |
google/seesaw | healthcheck/core.go | sendBatch | func (s *Server) sendBatch(batch []*Notification) error {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return err
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var reply int
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
return engine.Call("SeesawEngine.HealthState", &HealthState{ctx, batch}, &reply)
} | go | func (s *Server) sendBatch(batch []*Notification) error {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return err
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var reply int
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
return engine.Call("SeesawEngine.HealthState", &HealthState{ctx, batch}, &reply)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"sendBatch",
"(",
"batch",
"[",
"]",
"*",
"Notification",
")",
"error",
"{",
"engineConn",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"\"",
"\"",
",",
"s",
".",
"config",
".",
"EngineSocket",
",",
"engineTimeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"engineConn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"engineTimeout",
")",
")",
"\n",
"engine",
":=",
"rpc",
".",
"NewClient",
"(",
"engineConn",
")",
"\n",
"defer",
"engine",
".",
"Close",
"(",
")",
"\n\n",
"var",
"reply",
"int",
"\n",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCHealthcheck",
")",
"\n",
"return",
"engine",
".",
"Call",
"(",
"\"",
"\"",
",",
"&",
"HealthState",
"{",
"ctx",
",",
"batch",
"}",
",",
"&",
"reply",
")",
"\n",
"}"
] | // sendBatch sends a batch of notifications to the Seesaw Engine. | [
"sendBatch",
"sends",
"a",
"batch",
"of",
"notifications",
"to",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L604-L616 | train |
google/seesaw | ecu/stats.go | newECUStats | func newECUStats(ecu *ECU) *ecuStats {
return &ecuStats{
ecu: ecu,
stats: &stats{
lastUpdate: time.Unix(0, 0),
lastSuccess: time.Unix(0, 0),
},
}
} | go | func newECUStats(ecu *ECU) *ecuStats {
return &ecuStats{
ecu: ecu,
stats: &stats{
lastUpdate: time.Unix(0, 0),
lastSuccess: time.Unix(0, 0),
},
}
} | [
"func",
"newECUStats",
"(",
"ecu",
"*",
"ECU",
")",
"*",
"ecuStats",
"{",
"return",
"&",
"ecuStats",
"{",
"ecu",
":",
"ecu",
",",
"stats",
":",
"&",
"stats",
"{",
"lastUpdate",
":",
"time",
".",
"Unix",
"(",
"0",
",",
"0",
")",
",",
"lastSuccess",
":",
"time",
".",
"Unix",
"(",
"0",
",",
"0",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // newECUStats returns an initialised ecuStats struct. | [
"newECUStats",
"returns",
"an",
"initialised",
"ecuStats",
"struct",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L63-L71 | train |
google/seesaw | ecu/stats.go | notify | func (e *ecuStats) notify(p publisher) {
e.publishers = append(e.publishers, p)
} | go | func (e *ecuStats) notify(p publisher) {
e.publishers = append(e.publishers, p)
} | [
"func",
"(",
"e",
"*",
"ecuStats",
")",
"notify",
"(",
"p",
"publisher",
")",
"{",
"e",
".",
"publishers",
"=",
"append",
"(",
"e",
".",
"publishers",
",",
"p",
")",
"\n",
"}"
] | // notify registers a publisher for update notifications. | [
"notify",
"registers",
"a",
"publisher",
"for",
"update",
"notifications",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L74-L76 | train |
google/seesaw | ecu/stats.go | run | func (e *ecuStats) run() {
ticker := time.NewTicker(e.ecu.cfg.UpdateInterval)
for {
e.stats.lock.Lock()
e.stats.lastUpdate = time.Now()
e.stats.lock.Unlock()
log.Info("Updating ECU statistics from Seesaw Engine...")
if err := e.update(); err != nil {
log.Warning(err)
} else {
e.stats.lock.Lock()
e.stats.lastSuccess = time.Now()
e.stats.lock.Unlock()
}
for _, p := range e.publishers {
p.update(e.stats)
}
<-ticker.C
}
} | go | func (e *ecuStats) run() {
ticker := time.NewTicker(e.ecu.cfg.UpdateInterval)
for {
e.stats.lock.Lock()
e.stats.lastUpdate = time.Now()
e.stats.lock.Unlock()
log.Info("Updating ECU statistics from Seesaw Engine...")
if err := e.update(); err != nil {
log.Warning(err)
} else {
e.stats.lock.Lock()
e.stats.lastSuccess = time.Now()
e.stats.lock.Unlock()
}
for _, p := range e.publishers {
p.update(e.stats)
}
<-ticker.C
}
} | [
"func",
"(",
"e",
"*",
"ecuStats",
")",
"run",
"(",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"e",
".",
"ecu",
".",
"cfg",
".",
"UpdateInterval",
")",
"\n",
"for",
"{",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lastUpdate",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warning",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lastSuccess",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"e",
".",
"publishers",
"{",
"p",
".",
"update",
"(",
"e",
".",
"stats",
")",
"\n",
"}",
"\n",
"<-",
"ticker",
".",
"C",
"\n",
"}",
"\n",
"}"
] | // run attempts to update the cached statistics from the Seesaw Engine at
// regular intervals. | [
"run",
"attempts",
"to",
"update",
"the",
"cached",
"statistics",
"from",
"the",
"Seesaw",
"Engine",
"at",
"regular",
"intervals",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L80-L100 | train |
google/seesaw | ecu/stats.go | update | func (e *ecuStats) update() error {
// TODO(jsing): Make this untrusted.
ctx := ipc.NewTrustedContext(seesaw.SCECU)
seesawConn, err := conn.NewSeesawIPC(ctx)
if err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
if err := seesawConn.Dial(e.ecu.cfg.EngineSocket); err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
defer seesawConn.Close()
clusterStatus, err := seesawConn.ClusterStatus()
if err != nil {
return fmt.Errorf("Failed to get cluster status: %v", err)
}
e.stats.lock.Lock()
e.stats.ClusterStatus = *clusterStatus
e.stats.lock.Unlock()
configStatus, err := seesawConn.ConfigStatus()
if err != nil {
return fmt.Errorf("Failed to get config status: %v", err)
}
e.stats.lock.Lock()
e.stats.ConfigStatus = *configStatus
e.stats.lock.Unlock()
ha, err := seesawConn.HAStatus()
if err != nil {
return fmt.Errorf("Failed to get HA status: %v", err)
}
e.stats.lock.Lock()
e.stats.HAStatus = *ha
e.stats.lock.Unlock()
neighbors, err := seesawConn.BGPNeighbors()
if err != nil {
return fmt.Errorf("Failed to get BGP neighbors: %v", err)
}
e.stats.lock.Lock()
e.stats.neighbors = neighbors
e.stats.lock.Unlock()
vlans, err := seesawConn.VLANs()
if err != nil {
return fmt.Errorf("Failed to get VLANs: %v", err)
}
e.stats.lock.Lock()
e.stats.vlans = vlans.VLANs
e.stats.lock.Unlock()
vservers, err := seesawConn.Vservers()
if err != nil {
return fmt.Errorf("Failed to get vservers: %v", err)
}
e.stats.lock.Lock()
e.stats.vservers = vservers
e.stats.lock.Unlock()
return nil
} | go | func (e *ecuStats) update() error {
// TODO(jsing): Make this untrusted.
ctx := ipc.NewTrustedContext(seesaw.SCECU)
seesawConn, err := conn.NewSeesawIPC(ctx)
if err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
if err := seesawConn.Dial(e.ecu.cfg.EngineSocket); err != nil {
return fmt.Errorf("Failed to connect to engine: %v", err)
}
defer seesawConn.Close()
clusterStatus, err := seesawConn.ClusterStatus()
if err != nil {
return fmt.Errorf("Failed to get cluster status: %v", err)
}
e.stats.lock.Lock()
e.stats.ClusterStatus = *clusterStatus
e.stats.lock.Unlock()
configStatus, err := seesawConn.ConfigStatus()
if err != nil {
return fmt.Errorf("Failed to get config status: %v", err)
}
e.stats.lock.Lock()
e.stats.ConfigStatus = *configStatus
e.stats.lock.Unlock()
ha, err := seesawConn.HAStatus()
if err != nil {
return fmt.Errorf("Failed to get HA status: %v", err)
}
e.stats.lock.Lock()
e.stats.HAStatus = *ha
e.stats.lock.Unlock()
neighbors, err := seesawConn.BGPNeighbors()
if err != nil {
return fmt.Errorf("Failed to get BGP neighbors: %v", err)
}
e.stats.lock.Lock()
e.stats.neighbors = neighbors
e.stats.lock.Unlock()
vlans, err := seesawConn.VLANs()
if err != nil {
return fmt.Errorf("Failed to get VLANs: %v", err)
}
e.stats.lock.Lock()
e.stats.vlans = vlans.VLANs
e.stats.lock.Unlock()
vservers, err := seesawConn.Vservers()
if err != nil {
return fmt.Errorf("Failed to get vservers: %v", err)
}
e.stats.lock.Lock()
e.stats.vservers = vservers
e.stats.lock.Unlock()
return nil
} | [
"func",
"(",
"e",
"*",
"ecuStats",
")",
"update",
"(",
")",
"error",
"{",
"// TODO(jsing): Make this untrusted.",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCECU",
")",
"\n",
"seesawConn",
",",
"err",
":=",
"conn",
".",
"NewSeesawIPC",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"seesawConn",
".",
"Dial",
"(",
"e",
".",
"ecu",
".",
"cfg",
".",
"EngineSocket",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"seesawConn",
".",
"Close",
"(",
")",
"\n\n",
"clusterStatus",
",",
"err",
":=",
"seesawConn",
".",
"ClusterStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"ClusterStatus",
"=",
"*",
"clusterStatus",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"configStatus",
",",
"err",
":=",
"seesawConn",
".",
"ConfigStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"ConfigStatus",
"=",
"*",
"configStatus",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"ha",
",",
"err",
":=",
"seesawConn",
".",
"HAStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"HAStatus",
"=",
"*",
"ha",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"neighbors",
",",
"err",
":=",
"seesawConn",
".",
"BGPNeighbors",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"neighbors",
"=",
"neighbors",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"vlans",
",",
"err",
":=",
"seesawConn",
".",
"VLANs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"vlans",
"=",
"vlans",
".",
"VLANs",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"vservers",
",",
"err",
":=",
"seesawConn",
".",
"Vservers",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"stats",
".",
"vservers",
"=",
"vservers",
"\n",
"e",
".",
"stats",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // update attempts to update the cached statistics from the Seesaw Engine. | [
"update",
"attempts",
"to",
"update",
"the",
"cached",
"statistics",
"from",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/stats.go#L103-L164 | train |
google/seesaw | engine/healthcheck.go | newHealthcheckManager | func newHealthcheckManager(e *Engine) *healthcheckManager {
return &healthcheckManager{
engine: e,
marks: make(map[seesaw.IP]uint32),
markAlloc: newMarkAllocator(dsrMarkBase, dsrMarkSize),
ncc: ncclient.NewNCC(e.config.NCCSocket),
next: healthcheck.Id((uint64(os.Getpid()) & 0xFFFF) << 48),
vserverChecks: make(map[string]map[checkKey]*check),
quit: make(chan bool),
stopped: make(chan bool),
vcc: make(chan vserverChecks, 100),
}
} | go | func newHealthcheckManager(e *Engine) *healthcheckManager {
return &healthcheckManager{
engine: e,
marks: make(map[seesaw.IP]uint32),
markAlloc: newMarkAllocator(dsrMarkBase, dsrMarkSize),
ncc: ncclient.NewNCC(e.config.NCCSocket),
next: healthcheck.Id((uint64(os.Getpid()) & 0xFFFF) << 48),
vserverChecks: make(map[string]map[checkKey]*check),
quit: make(chan bool),
stopped: make(chan bool),
vcc: make(chan vserverChecks, 100),
}
} | [
"func",
"newHealthcheckManager",
"(",
"e",
"*",
"Engine",
")",
"*",
"healthcheckManager",
"{",
"return",
"&",
"healthcheckManager",
"{",
"engine",
":",
"e",
",",
"marks",
":",
"make",
"(",
"map",
"[",
"seesaw",
".",
"IP",
"]",
"uint32",
")",
",",
"markAlloc",
":",
"newMarkAllocator",
"(",
"dsrMarkBase",
",",
"dsrMarkSize",
")",
",",
"ncc",
":",
"ncclient",
".",
"NewNCC",
"(",
"e",
".",
"config",
".",
"NCCSocket",
")",
",",
"next",
":",
"healthcheck",
".",
"Id",
"(",
"(",
"uint64",
"(",
"os",
".",
"Getpid",
"(",
")",
")",
"&",
"0xFFFF",
")",
"<<",
"48",
")",
",",
"vserverChecks",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"checkKey",
"]",
"*",
"check",
")",
",",
"quit",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"stopped",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"vcc",
":",
"make",
"(",
"chan",
"vserverChecks",
",",
"100",
")",
",",
"}",
"\n",
"}"
] | // newHealthcheckManager creates a new healthcheckManager. | [
"newHealthcheckManager",
"creates",
"a",
"new",
"healthcheckManager",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L68-L80 | train |
google/seesaw | engine/healthcheck.go | configs | func (h *healthcheckManager) configs() map[healthcheck.Id]*healthcheck.Config {
h.lock.RLock()
defer h.lock.RUnlock()
if !h.enabled {
return nil
}
return h.cfgs
} | go | func (h *healthcheckManager) configs() map[healthcheck.Id]*healthcheck.Config {
h.lock.RLock()
defer h.lock.RUnlock()
if !h.enabled {
return nil
}
return h.cfgs
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"configs",
"(",
")",
"map",
"[",
"healthcheck",
".",
"Id",
"]",
"*",
"healthcheck",
".",
"Config",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"h",
".",
"enabled",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"h",
".",
"cfgs",
"\n",
"}"
] | // configs returns the healthcheck Configs for a Seesaw Engine. The returned
// map should only be read, not mutated. If the healthcheckManager is disabled,
// then nil is returned. | [
"configs",
"returns",
"the",
"healthcheck",
"Configs",
"for",
"a",
"Seesaw",
"Engine",
".",
"The",
"returned",
"map",
"should",
"only",
"be",
"read",
"not",
"mutated",
".",
"If",
"the",
"healthcheckManager",
"is",
"disabled",
"then",
"nil",
"is",
"returned",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L85-L92 | train |
google/seesaw | engine/healthcheck.go | update | func (h *healthcheckManager) update(vserverName string, checks map[checkKey]*check) {
if checks == nil {
delete(h.vserverChecks, vserverName)
} else {
h.vserverChecks[vserverName] = checks
}
h.buildMaps()
} | go | func (h *healthcheckManager) update(vserverName string, checks map[checkKey]*check) {
if checks == nil {
delete(h.vserverChecks, vserverName)
} else {
h.vserverChecks[vserverName] = checks
}
h.buildMaps()
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"update",
"(",
"vserverName",
"string",
",",
"checks",
"map",
"[",
"checkKey",
"]",
"*",
"check",
")",
"{",
"if",
"checks",
"==",
"nil",
"{",
"delete",
"(",
"h",
".",
"vserverChecks",
",",
"vserverName",
")",
"\n",
"}",
"else",
"{",
"h",
".",
"vserverChecks",
"[",
"vserverName",
"]",
"=",
"checks",
"\n",
"}",
"\n",
"h",
".",
"buildMaps",
"(",
")",
"\n",
"}"
] | // update updates the healthchecks for a vserver. | [
"update",
"updates",
"the",
"healthchecks",
"for",
"a",
"vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L95-L102 | train |
google/seesaw | engine/healthcheck.go | enable | func (h *healthcheckManager) enable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = true
} | go | func (h *healthcheckManager) enable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = true
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"enable",
"(",
")",
"{",
"h",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"enabled",
"=",
"true",
"\n",
"}"
] | // enable enables the healthcheck manager for the Seesaw Engine. | [
"enable",
"enables",
"the",
"healthcheck",
"manager",
"for",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L105-L109 | train |
google/seesaw | engine/healthcheck.go | disable | func (h *healthcheckManager) disable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = false
} | go | func (h *healthcheckManager) disable() {
h.lock.Lock()
defer h.lock.Unlock()
h.enabled = false
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"disable",
"(",
")",
"{",
"h",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"enabled",
"=",
"false",
"\n",
"}"
] | // disable disables the healthcheck manager for the Seesaw Engine. | [
"disable",
"disables",
"the",
"healthcheck",
"manager",
"for",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L112-L116 | train |
google/seesaw | engine/healthcheck.go | buildMaps | func (h *healthcheckManager) buildMaps() {
allChecks := make(map[checkKey]*check)
for _, vchecks := range h.vserverChecks {
for k, c := range vchecks {
if allChecks[k] == nil {
allChecks[k] = c
} else {
log.Warningf("Duplicate key: %v", k)
}
}
}
h.lock.RLock()
ids := h.ids
cfgs := h.cfgs
checks := h.checks
h.lock.RUnlock()
newIDs := make(map[checkKey]healthcheck.Id)
newCfgs := make(map[healthcheck.Id]*healthcheck.Config)
newChecks := make(map[healthcheck.Id]*check)
for key, c := range allChecks {
id, ok := ids[key]
if !ok {
id = h.next
h.next++
}
// Create a new healthcheck configuration if one did not
// previously exist, or if the check configuration changed.
cfg, ok := cfgs[id]
if !ok || *checks[id].healthcheck != *c.healthcheck {
newCfg, err := h.newConfig(id, key, c.healthcheck)
if err != nil {
log.Error(err)
continue
}
cfg = newCfg
}
newIDs[key] = id
newCfgs[id] = cfg
newChecks[id] = c
}
h.lock.Lock()
h.ids = newIDs
h.cfgs = newCfgs
h.checks = newChecks
h.lock.Unlock()
h.pruneMarks()
} | go | func (h *healthcheckManager) buildMaps() {
allChecks := make(map[checkKey]*check)
for _, vchecks := range h.vserverChecks {
for k, c := range vchecks {
if allChecks[k] == nil {
allChecks[k] = c
} else {
log.Warningf("Duplicate key: %v", k)
}
}
}
h.lock.RLock()
ids := h.ids
cfgs := h.cfgs
checks := h.checks
h.lock.RUnlock()
newIDs := make(map[checkKey]healthcheck.Id)
newCfgs := make(map[healthcheck.Id]*healthcheck.Config)
newChecks := make(map[healthcheck.Id]*check)
for key, c := range allChecks {
id, ok := ids[key]
if !ok {
id = h.next
h.next++
}
// Create a new healthcheck configuration if one did not
// previously exist, or if the check configuration changed.
cfg, ok := cfgs[id]
if !ok || *checks[id].healthcheck != *c.healthcheck {
newCfg, err := h.newConfig(id, key, c.healthcheck)
if err != nil {
log.Error(err)
continue
}
cfg = newCfg
}
newIDs[key] = id
newCfgs[id] = cfg
newChecks[id] = c
}
h.lock.Lock()
h.ids = newIDs
h.cfgs = newCfgs
h.checks = newChecks
h.lock.Unlock()
h.pruneMarks()
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"buildMaps",
"(",
")",
"{",
"allChecks",
":=",
"make",
"(",
"map",
"[",
"checkKey",
"]",
"*",
"check",
")",
"\n",
"for",
"_",
",",
"vchecks",
":=",
"range",
"h",
".",
"vserverChecks",
"{",
"for",
"k",
",",
"c",
":=",
"range",
"vchecks",
"{",
"if",
"allChecks",
"[",
"k",
"]",
"==",
"nil",
"{",
"allChecks",
"[",
"k",
"]",
"=",
"c",
"\n",
"}",
"else",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"ids",
":=",
"h",
".",
"ids",
"\n",
"cfgs",
":=",
"h",
".",
"cfgs",
"\n",
"checks",
":=",
"h",
".",
"checks",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"newIDs",
":=",
"make",
"(",
"map",
"[",
"checkKey",
"]",
"healthcheck",
".",
"Id",
")",
"\n",
"newCfgs",
":=",
"make",
"(",
"map",
"[",
"healthcheck",
".",
"Id",
"]",
"*",
"healthcheck",
".",
"Config",
")",
"\n",
"newChecks",
":=",
"make",
"(",
"map",
"[",
"healthcheck",
".",
"Id",
"]",
"*",
"check",
")",
"\n\n",
"for",
"key",
",",
"c",
":=",
"range",
"allChecks",
"{",
"id",
",",
"ok",
":=",
"ids",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"id",
"=",
"h",
".",
"next",
"\n",
"h",
".",
"next",
"++",
"\n",
"}",
"\n\n",
"// Create a new healthcheck configuration if one did not",
"// previously exist, or if the check configuration changed.",
"cfg",
",",
"ok",
":=",
"cfgs",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"||",
"*",
"checks",
"[",
"id",
"]",
".",
"healthcheck",
"!=",
"*",
"c",
".",
"healthcheck",
"{",
"newCfg",
",",
"err",
":=",
"h",
".",
"newConfig",
"(",
"id",
",",
"key",
",",
"c",
".",
"healthcheck",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"cfg",
"=",
"newCfg",
"\n",
"}",
"\n\n",
"newIDs",
"[",
"key",
"]",
"=",
"id",
"\n",
"newCfgs",
"[",
"id",
"]",
"=",
"cfg",
"\n",
"newChecks",
"[",
"id",
"]",
"=",
"c",
"\n",
"}",
"\n\n",
"h",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"h",
".",
"ids",
"=",
"newIDs",
"\n",
"h",
".",
"cfgs",
"=",
"newCfgs",
"\n",
"h",
".",
"checks",
"=",
"newChecks",
"\n",
"h",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"h",
".",
"pruneMarks",
"(",
")",
"\n",
"}"
] | // buildMaps builds the cfgs, checks, and ids maps based on the vserverChecks. | [
"buildMaps",
"builds",
"the",
"cfgs",
"checks",
"and",
"ids",
"maps",
"based",
"on",
"the",
"vserverChecks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L125-L177 | train |
google/seesaw | engine/healthcheck.go | healthState | func (h *healthcheckManager) healthState(n *healthcheck.Notification) error {
log.V(1).Infof("Received healthcheck notification: %v", n)
h.lock.RLock()
enabled := h.enabled
h.lock.RUnlock()
if !enabled {
log.Warningf("Healthcheck manager is disabled; ignoring healthcheck notification %v", n)
return nil
}
h.engine.syncServer.notify(&SyncNote{Type: SNTHealthcheck, Healthcheck: n})
return h.queueHealthState(n)
} | go | func (h *healthcheckManager) healthState(n *healthcheck.Notification) error {
log.V(1).Infof("Received healthcheck notification: %v", n)
h.lock.RLock()
enabled := h.enabled
h.lock.RUnlock()
if !enabled {
log.Warningf("Healthcheck manager is disabled; ignoring healthcheck notification %v", n)
return nil
}
h.engine.syncServer.notify(&SyncNote{Type: SNTHealthcheck, Healthcheck: n})
return h.queueHealthState(n)
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"healthState",
"(",
"n",
"*",
"healthcheck",
".",
"Notification",
")",
"error",
"{",
"log",
".",
"V",
"(",
"1",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"n",
")",
"\n\n",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"enabled",
":=",
"h",
".",
"enabled",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"!",
"enabled",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"h",
".",
"engine",
".",
"syncServer",
".",
"notify",
"(",
"&",
"SyncNote",
"{",
"Type",
":",
"SNTHealthcheck",
",",
"Healthcheck",
":",
"n",
"}",
")",
"\n\n",
"return",
"h",
".",
"queueHealthState",
"(",
"n",
")",
"\n",
"}"
] | // healthState handles Notifications from the healthcheck component. | [
"healthState",
"handles",
"Notifications",
"from",
"the",
"healthcheck",
"component",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L180-L195 | train |
google/seesaw | engine/healthcheck.go | queueHealthState | func (h *healthcheckManager) queueHealthState(n *healthcheck.Notification) error {
h.lock.RLock()
cfg := h.cfgs[n.Id]
check := h.checks[n.Id]
h.lock.RUnlock()
if cfg == nil || check == nil {
log.Warningf("Unknown healthcheck ID %v", n.Id)
return nil
}
note := &checkNotification{
key: check.key,
description: cfg.Checker.String(),
status: n.Status,
}
check.vserver.queueCheckNotification(note)
return nil
} | go | func (h *healthcheckManager) queueHealthState(n *healthcheck.Notification) error {
h.lock.RLock()
cfg := h.cfgs[n.Id]
check := h.checks[n.Id]
h.lock.RUnlock()
if cfg == nil || check == nil {
log.Warningf("Unknown healthcheck ID %v", n.Id)
return nil
}
note := &checkNotification{
key: check.key,
description: cfg.Checker.String(),
status: n.Status,
}
check.vserver.queueCheckNotification(note)
return nil
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"queueHealthState",
"(",
"n",
"*",
"healthcheck",
".",
"Notification",
")",
"error",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"cfg",
":=",
"h",
".",
"cfgs",
"[",
"n",
".",
"Id",
"]",
"\n",
"check",
":=",
"h",
".",
"checks",
"[",
"n",
".",
"Id",
"]",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"cfg",
"==",
"nil",
"||",
"check",
"==",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"n",
".",
"Id",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"note",
":=",
"&",
"checkNotification",
"{",
"key",
":",
"check",
".",
"key",
",",
"description",
":",
"cfg",
".",
"Checker",
".",
"String",
"(",
")",
",",
"status",
":",
"n",
".",
"Status",
",",
"}",
"\n",
"check",
".",
"vserver",
".",
"queueCheckNotification",
"(",
"note",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // queueHealthState queues a health state Notification for processing by a
// vserver. | [
"queueHealthState",
"queues",
"a",
"health",
"state",
"Notification",
"for",
"processing",
"by",
"a",
"vserver",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L199-L218 | train |
google/seesaw | engine/healthcheck.go | run | func (h *healthcheckManager) run() {
for {
select {
case <-h.quit:
h.unmarkAllBackends()
h.stopped <- true
case vc := <-h.vcc:
h.update(vc.vserverName, vc.checks)
}
}
} | go | func (h *healthcheckManager) run() {
for {
select {
case <-h.quit:
h.unmarkAllBackends()
h.stopped <- true
case vc := <-h.vcc:
h.update(vc.vserverName, vc.checks)
}
}
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"run",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"h",
".",
"quit",
":",
"h",
".",
"unmarkAllBackends",
"(",
")",
"\n",
"h",
".",
"stopped",
"<-",
"true",
"\n",
"case",
"vc",
":=",
"<-",
"h",
".",
"vcc",
":",
"h",
".",
"update",
"(",
"vc",
".",
"vserverName",
",",
"vc",
".",
"checks",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // run runs the healthcheck manager and processes incoming vserver checks. | [
"run",
"runs",
"the",
"healthcheck",
"manager",
"and",
"processes",
"incoming",
"vserver",
"checks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L345-L355 | train |
google/seesaw | engine/healthcheck.go | expire | func (h *healthcheckManager) expire() {
h.lock.RLock()
ids := h.ids
h.lock.RUnlock()
status := healthcheck.Status{State: healthcheck.StateUnknown}
for _, id := range ids {
h.queueHealthState(&healthcheck.Notification{id, status})
}
} | go | func (h *healthcheckManager) expire() {
h.lock.RLock()
ids := h.ids
h.lock.RUnlock()
status := healthcheck.Status{State: healthcheck.StateUnknown}
for _, id := range ids {
h.queueHealthState(&healthcheck.Notification{id, status})
}
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"expire",
"(",
")",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"ids",
":=",
"h",
".",
"ids",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"status",
":=",
"healthcheck",
".",
"Status",
"{",
"State",
":",
"healthcheck",
".",
"StateUnknown",
"}",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"h",
".",
"queueHealthState",
"(",
"&",
"healthcheck",
".",
"Notification",
"{",
"id",
",",
"status",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // expire invalidates the state of all configured healthchecks. | [
"expire",
"invalidates",
"the",
"state",
"of",
"all",
"configured",
"healthchecks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L358-L367 | train |
google/seesaw | engine/healthcheck.go | markBackend | func (h *healthcheckManager) markBackend(backend seesaw.IP) uint32 {
mark, ok := h.marks[backend]
if ok {
return mark
}
mark, err := h.markAlloc.get()
if err != nil {
log.Fatalf("Failed to get mark: %v", err)
}
h.marks[backend] = mark
ip := net.IPv6zero
if backend.AF() == seesaw.IPv4 {
ip = net.IPv4zero
}
ipvsSvc := &ipvs.Service{
Address: ip,
Protocol: ipvs.IPProto(0),
Port: 0,
Scheduler: "rr",
FirewallMark: mark,
Destinations: []*ipvs.Destination{
{
Address: backend.IP(),
Port: 0,
Weight: 1,
Flags: ipvs.DFForwardRoute,
},
},
}
if err := h.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer h.ncc.Close()
log.Infof("Adding DSR IPVS service for %s (mark %d)", backend, mark)
if err := h.ncc.IPVSAddService(ipvsSvc); err != nil {
log.Fatalf("Failed to add IPVS service for DSR: %v", err)
}
return mark
} | go | func (h *healthcheckManager) markBackend(backend seesaw.IP) uint32 {
mark, ok := h.marks[backend]
if ok {
return mark
}
mark, err := h.markAlloc.get()
if err != nil {
log.Fatalf("Failed to get mark: %v", err)
}
h.marks[backend] = mark
ip := net.IPv6zero
if backend.AF() == seesaw.IPv4 {
ip = net.IPv4zero
}
ipvsSvc := &ipvs.Service{
Address: ip,
Protocol: ipvs.IPProto(0),
Port: 0,
Scheduler: "rr",
FirewallMark: mark,
Destinations: []*ipvs.Destination{
{
Address: backend.IP(),
Port: 0,
Weight: 1,
Flags: ipvs.DFForwardRoute,
},
},
}
if err := h.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer h.ncc.Close()
log.Infof("Adding DSR IPVS service for %s (mark %d)", backend, mark)
if err := h.ncc.IPVSAddService(ipvsSvc); err != nil {
log.Fatalf("Failed to add IPVS service for DSR: %v", err)
}
return mark
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"markBackend",
"(",
"backend",
"seesaw",
".",
"IP",
")",
"uint32",
"{",
"mark",
",",
"ok",
":=",
"h",
".",
"marks",
"[",
"backend",
"]",
"\n",
"if",
"ok",
"{",
"return",
"mark",
"\n",
"}",
"\n\n",
"mark",
",",
"err",
":=",
"h",
".",
"markAlloc",
".",
"get",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"h",
".",
"marks",
"[",
"backend",
"]",
"=",
"mark",
"\n\n",
"ip",
":=",
"net",
".",
"IPv6zero",
"\n",
"if",
"backend",
".",
"AF",
"(",
")",
"==",
"seesaw",
".",
"IPv4",
"{",
"ip",
"=",
"net",
".",
"IPv4zero",
"\n",
"}",
"\n\n",
"ipvsSvc",
":=",
"&",
"ipvs",
".",
"Service",
"{",
"Address",
":",
"ip",
",",
"Protocol",
":",
"ipvs",
".",
"IPProto",
"(",
"0",
")",
",",
"Port",
":",
"0",
",",
"Scheduler",
":",
"\"",
"\"",
",",
"FirewallMark",
":",
"mark",
",",
"Destinations",
":",
"[",
"]",
"*",
"ipvs",
".",
"Destination",
"{",
"{",
"Address",
":",
"backend",
".",
"IP",
"(",
")",
",",
"Port",
":",
"0",
",",
"Weight",
":",
"1",
",",
"Flags",
":",
"ipvs",
".",
"DFForwardRoute",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"h",
".",
"ncc",
".",
"Dial",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"h",
".",
"ncc",
".",
"Close",
"(",
")",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"backend",
",",
"mark",
")",
"\n",
"if",
"err",
":=",
"h",
".",
"ncc",
".",
"IPVSAddService",
"(",
"ipvsSvc",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"mark",
"\n",
"}"
] | // markBackend returns a mark for the specified backend and sets up the IPVS
// service entry if it does not exist. | [
"markBackend",
"returns",
"a",
"mark",
"for",
"the",
"specified",
"backend",
"and",
"sets",
"up",
"the",
"IPVS",
"service",
"entry",
"if",
"it",
"does",
"not",
"exist",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L371-L415 | train |
google/seesaw | engine/healthcheck.go | pruneMarks | func (h *healthcheckManager) pruneMarks() {
h.lock.RLock()
checks := h.checks
h.lock.RUnlock()
backends := make(map[seesaw.IP]bool)
for _, check := range checks {
if check.key.healthcheckMode != seesaw.HCModeDSR {
continue
}
backends[check.key.backendIP] = true
}
for ip := range h.marks {
if _, ok := backends[ip]; !ok {
h.unmarkBackend(ip)
}
}
} | go | func (h *healthcheckManager) pruneMarks() {
h.lock.RLock()
checks := h.checks
h.lock.RUnlock()
backends := make(map[seesaw.IP]bool)
for _, check := range checks {
if check.key.healthcheckMode != seesaw.HCModeDSR {
continue
}
backends[check.key.backendIP] = true
}
for ip := range h.marks {
if _, ok := backends[ip]; !ok {
h.unmarkBackend(ip)
}
}
} | [
"func",
"(",
"h",
"*",
"healthcheckManager",
")",
"pruneMarks",
"(",
")",
"{",
"h",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"checks",
":=",
"h",
".",
"checks",
"\n",
"h",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"backends",
":=",
"make",
"(",
"map",
"[",
"seesaw",
".",
"IP",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"check",
":=",
"range",
"checks",
"{",
"if",
"check",
".",
"key",
".",
"healthcheckMode",
"!=",
"seesaw",
".",
"HCModeDSR",
"{",
"continue",
"\n",
"}",
"\n",
"backends",
"[",
"check",
".",
"key",
".",
"backendIP",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"for",
"ip",
":=",
"range",
"h",
".",
"marks",
"{",
"if",
"_",
",",
"ok",
":=",
"backends",
"[",
"ip",
"]",
";",
"!",
"ok",
"{",
"h",
".",
"unmarkBackend",
"(",
"ip",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // pruneMarks unmarks backends that no longer have DSR healthchecks configured. | [
"pruneMarks",
"unmarks",
"backends",
"that",
"no",
"longer",
"have",
"DSR",
"healthchecks",
"configured",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/healthcheck.go#L461-L479 | train |
google/seesaw | engine/config/notifier.go | NewNotifier | func NewNotifier(ec *EngineConfig) (*Notifier, error) {
outgoing := make(chan Notification, 1)
n := &Notifier{
C: outgoing,
outgoing: outgoing,
reload: make(chan bool, 1),
shutdown: make(chan bool, 1),
engineCfg: ec,
source: SourcePeer,
}
note, err := n.bootstrap()
if err != nil {
return nil, err
}
// If the on disk configuration is different, update it.
if note.Source != SourceDisk {
dNote, _ := n.pullConfig(SourceDisk)
if dNote == nil || !dNote.Cluster.Equal(note.Cluster) {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, true); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
}
n.last = note
n.outgoing <- *note
go n.run()
return n, nil
} | go | func NewNotifier(ec *EngineConfig) (*Notifier, error) {
outgoing := make(chan Notification, 1)
n := &Notifier{
C: outgoing,
outgoing: outgoing,
reload: make(chan bool, 1),
shutdown: make(chan bool, 1),
engineCfg: ec,
source: SourcePeer,
}
note, err := n.bootstrap()
if err != nil {
return nil, err
}
// If the on disk configuration is different, update it.
if note.Source != SourceDisk {
dNote, _ := n.pullConfig(SourceDisk)
if dNote == nil || !dNote.Cluster.Equal(note.Cluster) {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, true); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
}
n.last = note
n.outgoing <- *note
go n.run()
return n, nil
} | [
"func",
"NewNotifier",
"(",
"ec",
"*",
"EngineConfig",
")",
"(",
"*",
"Notifier",
",",
"error",
")",
"{",
"outgoing",
":=",
"make",
"(",
"chan",
"Notification",
",",
"1",
")",
"\n",
"n",
":=",
"&",
"Notifier",
"{",
"C",
":",
"outgoing",
",",
"outgoing",
":",
"outgoing",
",",
"reload",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"shutdown",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"engineCfg",
":",
"ec",
",",
"source",
":",
"SourcePeer",
",",
"}",
"\n\n",
"note",
",",
"err",
":=",
"n",
".",
"bootstrap",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// If the on disk configuration is different, update it.",
"if",
"note",
".",
"Source",
"!=",
"SourceDisk",
"{",
"dNote",
",",
"_",
":=",
"n",
".",
"pullConfig",
"(",
"SourceDisk",
")",
"\n",
"if",
"dNote",
"==",
"nil",
"||",
"!",
"dNote",
".",
"Cluster",
".",
"Equal",
"(",
"note",
".",
"Cluster",
")",
"{",
"if",
"err",
":=",
"saveConfig",
"(",
"note",
".",
"protobuf",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"n",
".",
"last",
"=",
"note",
"\n",
"n",
".",
"outgoing",
"<-",
"*",
"note",
"\n\n",
"go",
"n",
".",
"run",
"(",
")",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] | // NewNotifier creates a new Notifier. | [
"NewNotifier",
"creates",
"a",
"new",
"Notifier",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L57-L88 | train |
google/seesaw | engine/config/notifier.go | Source | func (n *Notifier) Source() Source {
n.lock.RLock()
defer n.lock.RUnlock()
return n.source
} | go | func (n *Notifier) Source() Source {
n.lock.RLock()
defer n.lock.RUnlock()
return n.source
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"Source",
"(",
")",
"Source",
"{",
"n",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"n",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"n",
".",
"source",
"\n",
"}"
] | // Source returns the current configuration source. | [
"Source",
"returns",
"the",
"current",
"configuration",
"source",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L91-L95 | train |
google/seesaw | engine/config/notifier.go | SetSource | func (n *Notifier) SetSource(source Source) {
n.lock.Lock()
n.source = source
n.lock.Unlock()
if err := n.Reload(); err != nil {
log.Warningf("Reload failed after setting source: %v", err)
}
} | go | func (n *Notifier) SetSource(source Source) {
n.lock.Lock()
n.source = source
n.lock.Unlock()
if err := n.Reload(); err != nil {
log.Warningf("Reload failed after setting source: %v", err)
}
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"SetSource",
"(",
"source",
"Source",
")",
"{",
"n",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"n",
".",
"source",
"=",
"source",
"\n",
"n",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"n",
".",
"Reload",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // SetSource sets the configuration Source for a Notifier. | [
"SetSource",
"sets",
"the",
"configuration",
"Source",
"for",
"a",
"Notifier",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L98-L105 | train |
google/seesaw | engine/config/notifier.go | Reload | func (n *Notifier) Reload() error {
select {
case n.reload <- true:
default:
return errors.New("reload request already queued")
}
return nil
} | go | func (n *Notifier) Reload() error {
select {
case n.reload <- true:
default:
return errors.New("reload request already queued")
}
return nil
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"Reload",
"(",
")",
"error",
"{",
"select",
"{",
"case",
"n",
".",
"reload",
"<-",
"true",
":",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Reload requests an immediate reload from the configuration source. | [
"Reload",
"requests",
"an",
"immediate",
"reload",
"from",
"the",
"configuration",
"source",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L108-L115 | train |
google/seesaw | engine/config/notifier.go | configCheck | func (n *Notifier) configCheck() {
log.Infof("Checking for config changes...")
s := n.Source()
last := n.last
note, err := n.pullConfig(s)
if err != nil && s == SourcePeer {
log.Errorf("Failed to pull configuration from peer: %v", err)
n.peerFailures++
if n.peerFailures < n.engineCfg.MaxPeerConfigSyncErrors {
return
}
log.Infof("Sync from peer failed %v times, falling back to config server",
n.engineCfg.MaxPeerConfigSyncErrors)
s = SourceServer
note, err = n.pullConfig(s)
}
n.peerFailures = 0
if err != nil {
log.Errorf("Failed to pull configuration: %v", err)
return
}
if s != SourceDisk && s != SourcePeer {
oldMeta := last.protobuf.Metadata
newMeta := note.protobuf.Metadata
if oldMeta != nil && newMeta != nil && oldMeta.GetLastUpdated() > newMeta.GetLastUpdated() {
log.Infof("Ignoring out-of-date config from %v", note.SourceDetail)
return
}
}
if note.Cluster.Equal(last.Cluster) {
log.Infof("No config changes found")
return
}
// If there's only metadata differences, note it so we can skip some processing later.
oldCluster := *n.last.Cluster
oldCluster.Status = seesaw.ConfigStatus{}
newCluster := *note.Cluster
newCluster.Status = seesaw.ConfigStatus{}
if newCluster.Equal(&oldCluster) {
note.MetadataOnly = true
}
log.Infof("Sending config update notification")
n.last = note
n.outgoing <- *note
log.Infof("Sent config update notification")
if s != SourceDisk {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, !note.MetadataOnly); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
} | go | func (n *Notifier) configCheck() {
log.Infof("Checking for config changes...")
s := n.Source()
last := n.last
note, err := n.pullConfig(s)
if err != nil && s == SourcePeer {
log.Errorf("Failed to pull configuration from peer: %v", err)
n.peerFailures++
if n.peerFailures < n.engineCfg.MaxPeerConfigSyncErrors {
return
}
log.Infof("Sync from peer failed %v times, falling back to config server",
n.engineCfg.MaxPeerConfigSyncErrors)
s = SourceServer
note, err = n.pullConfig(s)
}
n.peerFailures = 0
if err != nil {
log.Errorf("Failed to pull configuration: %v", err)
return
}
if s != SourceDisk && s != SourcePeer {
oldMeta := last.protobuf.Metadata
newMeta := note.protobuf.Metadata
if oldMeta != nil && newMeta != nil && oldMeta.GetLastUpdated() > newMeta.GetLastUpdated() {
log.Infof("Ignoring out-of-date config from %v", note.SourceDetail)
return
}
}
if note.Cluster.Equal(last.Cluster) {
log.Infof("No config changes found")
return
}
// If there's only metadata differences, note it so we can skip some processing later.
oldCluster := *n.last.Cluster
oldCluster.Status = seesaw.ConfigStatus{}
newCluster := *note.Cluster
newCluster.Status = seesaw.ConfigStatus{}
if newCluster.Equal(&oldCluster) {
note.MetadataOnly = true
}
log.Infof("Sending config update notification")
n.last = note
n.outgoing <- *note
log.Infof("Sent config update notification")
if s != SourceDisk {
if err := saveConfig(note.protobuf, n.engineCfg.ClusterFile, !note.MetadataOnly); err != nil {
log.Warningf("Failed to save config to %s: %v", n.engineCfg.ClusterFile, err)
}
}
} | [
"func",
"(",
"n",
"*",
"Notifier",
")",
"configCheck",
"(",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"s",
":=",
"n",
".",
"Source",
"(",
")",
"\n",
"last",
":=",
"n",
".",
"last",
"\n",
"note",
",",
"err",
":=",
"n",
".",
"pullConfig",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"s",
"==",
"SourcePeer",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"n",
".",
"peerFailures",
"++",
"\n",
"if",
"n",
".",
"peerFailures",
"<",
"n",
".",
"engineCfg",
".",
"MaxPeerConfigSyncErrors",
"{",
"return",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"n",
".",
"engineCfg",
".",
"MaxPeerConfigSyncErrors",
")",
"\n",
"s",
"=",
"SourceServer",
"\n",
"note",
",",
"err",
"=",
"n",
".",
"pullConfig",
"(",
"s",
")",
"\n",
"}",
"\n",
"n",
".",
"peerFailures",
"=",
"0",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"s",
"!=",
"SourceDisk",
"&&",
"s",
"!=",
"SourcePeer",
"{",
"oldMeta",
":=",
"last",
".",
"protobuf",
".",
"Metadata",
"\n",
"newMeta",
":=",
"note",
".",
"protobuf",
".",
"Metadata",
"\n",
"if",
"oldMeta",
"!=",
"nil",
"&&",
"newMeta",
"!=",
"nil",
"&&",
"oldMeta",
".",
"GetLastUpdated",
"(",
")",
">",
"newMeta",
".",
"GetLastUpdated",
"(",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"note",
".",
"SourceDetail",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"note",
".",
"Cluster",
".",
"Equal",
"(",
"last",
".",
"Cluster",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// If there's only metadata differences, note it so we can skip some processing later.",
"oldCluster",
":=",
"*",
"n",
".",
"last",
".",
"Cluster",
"\n",
"oldCluster",
".",
"Status",
"=",
"seesaw",
".",
"ConfigStatus",
"{",
"}",
"\n",
"newCluster",
":=",
"*",
"note",
".",
"Cluster",
"\n",
"newCluster",
".",
"Status",
"=",
"seesaw",
".",
"ConfigStatus",
"{",
"}",
"\n",
"if",
"newCluster",
".",
"Equal",
"(",
"&",
"oldCluster",
")",
"{",
"note",
".",
"MetadataOnly",
"=",
"true",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"n",
".",
"last",
"=",
"note",
"\n",
"n",
".",
"outgoing",
"<-",
"*",
"note",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"s",
"!=",
"SourceDisk",
"{",
"if",
"err",
":=",
"saveConfig",
"(",
"note",
".",
"protobuf",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"!",
"note",
".",
"MetadataOnly",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"n",
".",
"engineCfg",
".",
"ClusterFile",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // configCheck checks for configuration changes. | [
"configCheck",
"checks",
"for",
"configuration",
"changes",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/config/notifier.go#L138-L194 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.