id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
154,100 | juju/juju | apiserver/httpcontext/auth.go | sendStatusAndJSON | func sendStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{}) error {
body, err := json.Marshal(response)
if err != nil {
return errors.Errorf("cannot marshal JSON result %#v: %v", response, err)
}
if statusCode == http.StatusUnauthorized {
w.Header().Set("WWW-Authenticate", `Basic realm="juju"`)
}
w.Header().Set("Content-Type", params.ContentTypeJSON)
w.Header().Set("Content-Length", fmt.Sprint(len(body)))
w.WriteHeader(statusCode)
if _, err := w.Write(body); err != nil {
return errors.Annotate(err, "cannot write response")
}
return nil
} | go | func sendStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{}) error {
body, err := json.Marshal(response)
if err != nil {
return errors.Errorf("cannot marshal JSON result %#v: %v", response, err)
}
if statusCode == http.StatusUnauthorized {
w.Header().Set("WWW-Authenticate", `Basic realm="juju"`)
}
w.Header().Set("Content-Type", params.ContentTypeJSON)
w.Header().Set("Content-Length", fmt.Sprint(len(body)))
w.WriteHeader(statusCode)
if _, err := w.Write(body); err != nil {
return errors.Annotate(err, "cannot write response")
}
return nil
} | [
"func",
"sendStatusAndJSON",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"statusCode",
"int",
",",
"response",
"interface",
"{",
"}",
")",
"error",
"{",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"response",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"statusCode",
"==",
"http",
".",
"StatusUnauthorized",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"`Basic realm=\"juju\"`",
")",
"\n",
"}",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"params",
".",
"ContentTypeJSON",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprint",
"(",
"len",
"(",
"body",
")",
")",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"statusCode",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // sendStatusAndJSON sends an HTTP status code and
// a JSON-encoded response to a client. | [
"sendStatusAndJSON",
"sends",
"an",
"HTTP",
"status",
"code",
"and",
"a",
"JSON",
"-",
"encoded",
"response",
"to",
"a",
"client",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/httpcontext/auth.go#L115-L131 |
154,101 | juju/juju | apiserver/httpcontext/auth.go | sendError | func sendError(w http.ResponseWriter, errToSend error) error {
paramsErr, statusCode := common.ServerErrorAndStatus(errToSend)
logger.Debugf("sending error: %d %v", statusCode, paramsErr)
return errors.Trace(sendStatusAndJSON(w, statusCode, ¶ms.ErrorResult{
Error: paramsErr,
}))
} | go | func sendError(w http.ResponseWriter, errToSend error) error {
paramsErr, statusCode := common.ServerErrorAndStatus(errToSend)
logger.Debugf("sending error: %d %v", statusCode, paramsErr)
return errors.Trace(sendStatusAndJSON(w, statusCode, ¶ms.ErrorResult{
Error: paramsErr,
}))
} | [
"func",
"sendError",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"errToSend",
"error",
")",
"error",
"{",
"paramsErr",
",",
"statusCode",
":=",
"common",
".",
"ServerErrorAndStatus",
"(",
"errToSend",
")",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"statusCode",
",",
"paramsErr",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"sendStatusAndJSON",
"(",
"w",
",",
"statusCode",
",",
"&",
"params",
".",
"ErrorResult",
"{",
"Error",
":",
"paramsErr",
",",
"}",
")",
")",
"\n",
"}"
] | // sendError sends a JSON-encoded error response
// for errors encountered during processing. | [
"sendError",
"sends",
"a",
"JSON",
"-",
"encoded",
"error",
"response",
"for",
"errors",
"encountered",
"during",
"processing",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/httpcontext/auth.go#L135-L141 |
154,102 | juju/juju | apiserver/httpcontext/auth.go | RequestAuthInfo | func RequestAuthInfo(req *http.Request) (AuthInfo, bool) {
authInfo, ok := req.Context().Value(authInfoKey{}).(AuthInfo)
return authInfo, ok
} | go | func RequestAuthInfo(req *http.Request) (AuthInfo, bool) {
authInfo, ok := req.Context().Value(authInfoKey{}).(AuthInfo)
return authInfo, ok
} | [
"func",
"RequestAuthInfo",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"AuthInfo",
",",
"bool",
")",
"{",
"authInfo",
",",
"ok",
":=",
"req",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"authInfoKey",
"{",
"}",
")",
".",
"(",
"AuthInfo",
")",
"\n",
"return",
"authInfo",
",",
"ok",
"\n",
"}"
] | // RequestAuthInfo returns the AuthInfo associated with the request,
// if any, and a boolean indicating whether or not the request was
// authenticated. | [
"RequestAuthInfo",
"returns",
"the",
"AuthInfo",
"associated",
"with",
"the",
"request",
"if",
"any",
"and",
"a",
"boolean",
"indicating",
"whether",
"or",
"not",
"the",
"request",
"was",
"authenticated",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/httpcontext/auth.go#L180-L183 |
154,103 | juju/juju | cmd/juju/application/removerelation.go | NewRemoveRelationCommand | func NewRemoveRelationCommand() cmd.Command {
command := &removeRelationCommand{}
command.newAPIFunc = func() (ApplicationDestroyRelationAPI, error) {
root, err := command.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return application.NewClient(root), nil
}
return modelcmd.Wrap(command)
} | go | func NewRemoveRelationCommand() cmd.Command {
command := &removeRelationCommand{}
command.newAPIFunc = func() (ApplicationDestroyRelationAPI, error) {
root, err := command.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return application.NewClient(root), nil
}
return modelcmd.Wrap(command)
} | [
"func",
"NewRemoveRelationCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"command",
":=",
"&",
"removeRelationCommand",
"{",
"}",
"\n",
"command",
".",
"newAPIFunc",
"=",
"func",
"(",
")",
"(",
"ApplicationDestroyRelationAPI",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"command",
".",
"NewAPIRoot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"application",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n\n",
"}",
"\n",
"return",
"modelcmd",
".",
"Wrap",
"(",
"command",
")",
"\n",
"}"
] | // NewRemoveRelationCommand returns a command to remove a relation between 2 applications. | [
"NewRemoveRelationCommand",
"returns",
"a",
"command",
"to",
"remove",
"a",
"relation",
"between",
"2",
"applications",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/removerelation.go#L61-L72 |
154,104 | juju/juju | api/migrationminion/client.go | Watch | func (c *Client) Watch() (watcher.MigrationStatusWatcher, error) {
var result params.NotifyWatchResult
err := c.caller.FacadeCall("Watch", nil, &result)
if err != nil {
return nil, errors.Trace(err)
}
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewMigrationStatusWatcher(c.caller.RawAPICaller(), result.NotifyWatcherId)
return w, nil
} | go | func (c *Client) Watch() (watcher.MigrationStatusWatcher, error) {
var result params.NotifyWatchResult
err := c.caller.FacadeCall("Watch", nil, &result)
if err != nil {
return nil, errors.Trace(err)
}
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewMigrationStatusWatcher(c.caller.RawAPICaller(), result.NotifyWatcherId)
return w, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Watch",
"(",
")",
"(",
"watcher",
".",
"MigrationStatusWatcher",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"NotifyWatchResult",
"\n",
"err",
":=",
"c",
".",
"caller",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"nil",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"w",
":=",
"apiwatcher",
".",
"NewMigrationStatusWatcher",
"(",
"c",
".",
"caller",
".",
"RawAPICaller",
"(",
")",
",",
"result",
".",
"NotifyWatcherId",
")",
"\n",
"return",
"w",
",",
"nil",
"\n",
"}"
] | // Watch returns a watcher which reports when the status changes for
// the migration for the model associated with the API connection. | [
"Watch",
"returns",
"a",
"watcher",
"which",
"reports",
"when",
"the",
"status",
"changes",
"for",
"the",
"migration",
"for",
"the",
"model",
"associated",
"with",
"the",
"API",
"connection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationminion/client.go#L27-L38 |
154,105 | juju/juju | api/migrationminion/client.go | Report | func (c *Client) Report(migrationId string, phase migration.Phase, success bool) error {
args := params.MinionReport{
MigrationId: migrationId,
Phase: phase.String(),
Success: success,
}
err := c.caller.FacadeCall("Report", args, nil)
return errors.Trace(err)
} | go | func (c *Client) Report(migrationId string, phase migration.Phase, success bool) error {
args := params.MinionReport{
MigrationId: migrationId,
Phase: phase.String(),
Success: success,
}
err := c.caller.FacadeCall("Report", args, nil)
return errors.Trace(err)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Report",
"(",
"migrationId",
"string",
",",
"phase",
"migration",
".",
"Phase",
",",
"success",
"bool",
")",
"error",
"{",
"args",
":=",
"params",
".",
"MinionReport",
"{",
"MigrationId",
":",
"migrationId",
",",
"Phase",
":",
"phase",
".",
"String",
"(",
")",
",",
"Success",
":",
"success",
",",
"}",
"\n",
"err",
":=",
"c",
".",
"caller",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"nil",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Report allows a migration minion to report if it successfully
// completed its activities for a given migration phase. | [
"Report",
"allows",
"a",
"migration",
"minion",
"to",
"report",
"if",
"it",
"successfully",
"completed",
"its",
"activities",
"for",
"a",
"given",
"migration",
"phase",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/migrationminion/client.go#L42-L50 |
154,106 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | NewMockSystemdServiceManager | func NewMockSystemdServiceManager(ctrl *gomock.Controller) *MockSystemdServiceManager {
mock := &MockSystemdServiceManager{ctrl: ctrl}
mock.recorder = &MockSystemdServiceManagerMockRecorder{mock}
return mock
} | go | func NewMockSystemdServiceManager(ctrl *gomock.Controller) *MockSystemdServiceManager {
mock := &MockSystemdServiceManager{ctrl: ctrl}
mock.recorder = &MockSystemdServiceManagerMockRecorder{mock}
return mock
} | [
"func",
"NewMockSystemdServiceManager",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockSystemdServiceManager",
"{",
"mock",
":=",
"&",
"MockSystemdServiceManager",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockSystemdServiceManagerMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockSystemdServiceManager creates a new mock instance | [
"NewMockSystemdServiceManager",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L27-L31 |
154,107 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | CopyAgentBinary | func (m *MockSystemdServiceManager) CopyAgentBinary(arg0 string, arg1 []string, arg2, arg3, arg4 string, arg5 version.Number) error {
ret := m.ctrl.Call(m, "CopyAgentBinary", arg0, arg1, arg2, arg3, arg4, arg5)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockSystemdServiceManager) CopyAgentBinary(arg0 string, arg1 []string, arg2, arg3, arg4 string, arg5 version.Number) error {
ret := m.ctrl.Call(m, "CopyAgentBinary", arg0, arg1, arg2, arg3, arg4, arg5)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockSystemdServiceManager",
")",
"CopyAgentBinary",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"string",
",",
"arg2",
",",
"arg3",
",",
"arg4",
"string",
",",
"arg5",
"version",
".",
"Number",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
",",
"arg5",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // CopyAgentBinary mocks base method | [
"CopyAgentBinary",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L39-L43 |
154,108 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | CopyAgentBinary | func (mr *MockSystemdServiceManagerMockRecorder) CopyAgentBinary(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CopyAgentBinary", reflect.TypeOf((*MockSystemdServiceManager)(nil).CopyAgentBinary), arg0, arg1, arg2, arg3, arg4, arg5)
} | go | func (mr *MockSystemdServiceManagerMockRecorder) CopyAgentBinary(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CopyAgentBinary", reflect.TypeOf((*MockSystemdServiceManager)(nil).CopyAgentBinary), arg0, arg1, arg2, arg3, arg4, arg5)
} | [
"func",
"(",
"mr",
"*",
"MockSystemdServiceManagerMockRecorder",
")",
"CopyAgentBinary",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
",",
"arg5",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockSystemdServiceManager",
")",
"(",
"nil",
")",
".",
"CopyAgentBinary",
")",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
",",
"arg5",
")",
"\n",
"}"
] | // CopyAgentBinary indicates an expected call of CopyAgentBinary | [
"CopyAgentBinary",
"indicates",
"an",
"expected",
"call",
"of",
"CopyAgentBinary"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L46-L48 |
154,109 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | CreateAgentConf | func (m *MockSystemdServiceManager) CreateAgentConf(arg0, arg1 string) (common.Conf, error) {
ret := m.ctrl.Call(m, "CreateAgentConf", arg0, arg1)
ret0, _ := ret[0].(common.Conf)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockSystemdServiceManager) CreateAgentConf(arg0, arg1 string) (common.Conf, error) {
ret := m.ctrl.Call(m, "CreateAgentConf", arg0, arg1)
ret0, _ := ret[0].(common.Conf)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockSystemdServiceManager",
")",
"CreateAgentConf",
"(",
"arg0",
",",
"arg1",
"string",
")",
"(",
"common",
".",
"Conf",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"common",
".",
"Conf",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // CreateAgentConf mocks base method | [
"CreateAgentConf",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L51-L56 |
154,110 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | FindAgents | func (m *MockSystemdServiceManager) FindAgents(arg0 string) (string, []string, []string, error) {
ret := m.ctrl.Call(m, "FindAgents", arg0)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].([]string)
ret2, _ := ret[2].([]string)
ret3, _ := ret[3].(error)
return ret0, ret1, ret2, ret3
} | go | func (m *MockSystemdServiceManager) FindAgents(arg0 string) (string, []string, []string, error) {
ret := m.ctrl.Call(m, "FindAgents", arg0)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].([]string)
ret2, _ := ret[2].([]string)
ret3, _ := ret[3].(error)
return ret0, ret1, ret2, ret3
} | [
"func",
"(",
"m",
"*",
"MockSystemdServiceManager",
")",
"FindAgents",
"(",
"arg0",
"string",
")",
"(",
"string",
",",
"[",
"]",
"string",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"[",
"]",
"string",
")",
"\n",
"ret2",
",",
"_",
":=",
"ret",
"[",
"2",
"]",
".",
"(",
"[",
"]",
"string",
")",
"\n",
"ret3",
",",
"_",
":=",
"ret",
"[",
"3",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
",",
"ret2",
",",
"ret3",
"\n",
"}"
] | // FindAgents mocks base method | [
"FindAgents",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L64-L71 |
154,111 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | StartAllAgents | func (m *MockSystemdServiceManager) StartAllAgents(arg0 string, arg1 []string, arg2 string) (string, []string, error) {
ret := m.ctrl.Call(m, "StartAllAgents", arg0, arg1, arg2)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].([]string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | go | func (m *MockSystemdServiceManager) StartAllAgents(arg0 string, arg1 []string, arg2 string) (string, []string, error) {
ret := m.ctrl.Call(m, "StartAllAgents", arg0, arg1, arg2)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].([]string)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
} | [
"func",
"(",
"m",
"*",
"MockSystemdServiceManager",
")",
"StartAllAgents",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"string",
",",
"arg2",
"string",
")",
"(",
"string",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"[",
"]",
"string",
")",
"\n",
"ret2",
",",
"_",
":=",
"ret",
"[",
"2",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
",",
"ret2",
"\n",
"}"
] | // StartAllAgents mocks base method | [
"StartAllAgents",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L79-L85 |
154,112 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | StartAllAgents | func (mr *MockSystemdServiceManagerMockRecorder) StartAllAgents(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartAllAgents", reflect.TypeOf((*MockSystemdServiceManager)(nil).StartAllAgents), arg0, arg1, arg2)
} | go | func (mr *MockSystemdServiceManagerMockRecorder) StartAllAgents(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartAllAgents", reflect.TypeOf((*MockSystemdServiceManager)(nil).StartAllAgents), arg0, arg1, arg2)
} | [
"func",
"(",
"mr",
"*",
"MockSystemdServiceManagerMockRecorder",
")",
"StartAllAgents",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockSystemdServiceManager",
")",
"(",
"nil",
")",
".",
"StartAllAgents",
")",
",",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"\n",
"}"
] | // StartAllAgents indicates an expected call of StartAllAgents | [
"StartAllAgents",
"indicates",
"an",
"expected",
"call",
"of",
"StartAllAgents"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L88-L90 |
154,113 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | WriteServiceFiles | func (m *MockSystemdServiceManager) WriteServiceFiles() error {
ret := m.ctrl.Call(m, "WriteServiceFiles")
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockSystemdServiceManager) WriteServiceFiles() error {
ret := m.ctrl.Call(m, "WriteServiceFiles")
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockSystemdServiceManager",
")",
"WriteServiceFiles",
"(",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // WriteServiceFiles mocks base method | [
"WriteServiceFiles",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L93-L97 |
154,114 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | WriteServiceFiles | func (mr *MockSystemdServiceManagerMockRecorder) WriteServiceFiles() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteServiceFiles", reflect.TypeOf((*MockSystemdServiceManager)(nil).WriteServiceFiles))
} | go | func (mr *MockSystemdServiceManagerMockRecorder) WriteServiceFiles() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteServiceFiles", reflect.TypeOf((*MockSystemdServiceManager)(nil).WriteServiceFiles))
} | [
"func",
"(",
"mr",
"*",
"MockSystemdServiceManagerMockRecorder",
")",
"WriteServiceFiles",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockSystemdServiceManager",
")",
"(",
"nil",
")",
".",
"WriteServiceFiles",
")",
")",
"\n",
"}"
] | // WriteServiceFiles indicates an expected call of WriteServiceFiles | [
"WriteServiceFiles",
"indicates",
"an",
"expected",
"call",
"of",
"WriteServiceFiles"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L100-L102 |
154,115 | juju/juju | worker/upgradeseries/mocks/servicemanager_mock.go | WriteSystemdAgents | func (m *MockSystemdServiceManager) WriteSystemdAgents(arg0 string, arg1 []string, arg2, arg3, arg4 string) ([]string, []string, []string, error) {
ret := m.ctrl.Call(m, "WriteSystemdAgents", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].([]string)
ret2, _ := ret[2].([]string)
ret3, _ := ret[3].(error)
return ret0, ret1, ret2, ret3
} | go | func (m *MockSystemdServiceManager) WriteSystemdAgents(arg0 string, arg1 []string, arg2, arg3, arg4 string) ([]string, []string, []string, error) {
ret := m.ctrl.Call(m, "WriteSystemdAgents", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].([]string)
ret1, _ := ret[1].([]string)
ret2, _ := ret[2].([]string)
ret3, _ := ret[3].(error)
return ret0, ret1, ret2, ret3
} | [
"func",
"(",
"m",
"*",
"MockSystemdServiceManager",
")",
"WriteSystemdAgents",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"string",
",",
"arg2",
",",
"arg3",
",",
"arg4",
"string",
")",
"(",
"[",
"]",
"string",
",",
"[",
"]",
"string",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"]",
"string",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"[",
"]",
"string",
")",
"\n",
"ret2",
",",
"_",
":=",
"ret",
"[",
"2",
"]",
".",
"(",
"[",
"]",
"string",
")",
"\n",
"ret3",
",",
"_",
":=",
"ret",
"[",
"3",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
",",
"ret2",
",",
"ret3",
"\n",
"}"
] | // WriteSystemdAgents mocks base method | [
"WriteSystemdAgents",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/upgradeseries/mocks/servicemanager_mock.go#L105-L112 |
154,116 | juju/juju | apiserver/facades/controller/charmrevisionupdater/updater.go | NewCharmRevisionUpdaterAPI | func NewCharmRevisionUpdaterAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*CharmRevisionUpdaterAPI, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &CharmRevisionUpdaterAPI{
state: st, resources: resources, authorizer: authorizer}, nil
} | go | func NewCharmRevisionUpdaterAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*CharmRevisionUpdaterAPI, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &CharmRevisionUpdaterAPI{
state: st, resources: resources, authorizer: authorizer}, nil
} | [
"func",
"NewCharmRevisionUpdaterAPI",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
")",
"(",
"*",
"CharmRevisionUpdaterAPI",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthController",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"CharmRevisionUpdaterAPI",
"{",
"state",
":",
"st",
",",
"resources",
":",
"resources",
",",
"authorizer",
":",
"authorizer",
"}",
",",
"nil",
"\n",
"}"
] | // NewCharmRevisionUpdaterAPI creates a new server-side charmrevisionupdater API end point. | [
"NewCharmRevisionUpdaterAPI",
"creates",
"a",
"new",
"server",
"-",
"side",
"charmrevisionupdater",
"API",
"end",
"point",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/charmrevisionupdater/updater.go#L40-L50 |
154,117 | juju/juju | state/dump.go | DumpAll | func (st *State) DumpAll() (map[string]interface{}, error) {
result := make(map[string]interface{})
// Add in the model document itself.
doc, err := getModelDoc(st)
if err != nil {
return nil, err
}
result[modelsC] = doc
for name, info := range allCollections() {
if !info.global {
docs, err := getAllModelDocs(st, name)
if err != nil {
return nil, errors.Trace(err)
}
if len(docs) > 0 {
result[name] = docs
}
}
}
return result, nil
} | go | func (st *State) DumpAll() (map[string]interface{}, error) {
result := make(map[string]interface{})
// Add in the model document itself.
doc, err := getModelDoc(st)
if err != nil {
return nil, err
}
result[modelsC] = doc
for name, info := range allCollections() {
if !info.global {
docs, err := getAllModelDocs(st, name)
if err != nil {
return nil, errors.Trace(err)
}
if len(docs) > 0 {
result[name] = docs
}
}
}
return result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"DumpAll",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"// Add in the model document itself.",
"doc",
",",
"err",
":=",
"getModelDoc",
"(",
"st",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
"[",
"modelsC",
"]",
"=",
"doc",
"\n",
"for",
"name",
",",
"info",
":=",
"range",
"allCollections",
"(",
")",
"{",
"if",
"!",
"info",
".",
"global",
"{",
"docs",
",",
"err",
":=",
"getAllModelDocs",
"(",
"st",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"docs",
")",
">",
"0",
"{",
"result",
"[",
"name",
"]",
"=",
"docs",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // DumpAll returns a map of collection names to a slice of documents
// in that collection. Every document that is related to the current
// model is returned in the map. | [
"DumpAll",
"returns",
"a",
"map",
"of",
"collection",
"names",
"to",
"a",
"slice",
"of",
"documents",
"in",
"that",
"collection",
".",
"Every",
"document",
"that",
"is",
"related",
"to",
"the",
"current",
"model",
"is",
"returned",
"in",
"the",
"map",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/dump.go#L11-L31 |
154,118 | juju/juju | cmd/juju/application/show.go | NewShowApplicationCommand | func NewShowApplicationCommand() cmd.Command {
s := &showApplicationCommand{}
s.newAPIFunc = func() (ApplicationsInfoAPI, error) {
return s.newApplicationAPI()
}
return modelcmd.Wrap(s)
} | go | func NewShowApplicationCommand() cmd.Command {
s := &showApplicationCommand{}
s.newAPIFunc = func() (ApplicationsInfoAPI, error) {
return s.newApplicationAPI()
}
return modelcmd.Wrap(s)
} | [
"func",
"NewShowApplicationCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"s",
":=",
"&",
"showApplicationCommand",
"{",
"}",
"\n",
"s",
".",
"newAPIFunc",
"=",
"func",
"(",
")",
"(",
"ApplicationsInfoAPI",
",",
"error",
")",
"{",
"return",
"s",
".",
"newApplicationAPI",
"(",
")",
"\n",
"}",
"\n",
"return",
"modelcmd",
".",
"Wrap",
"(",
"s",
")",
"\n",
"}"
] | // NewShowApplicationCommand returns a command that displays applications info. | [
"NewShowApplicationCommand",
"returns",
"a",
"command",
"that",
"displays",
"applications",
"info",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/show.go#L36-L42 |
154,119 | juju/juju | cmd/juju/application/show.go | formatApplicationInfos | func formatApplicationInfos(all []params.ApplicationInfo) (map[string]ApplicationInfo, error) {
if len(all) == 0 {
return nil, nil
}
output := make(map[string]ApplicationInfo)
for _, one := range all {
tag, info, err := createApplicationInfo(one)
if err != nil {
return nil, errors.Trace(err)
}
output[tag.Name] = info
}
return output, nil
} | go | func formatApplicationInfos(all []params.ApplicationInfo) (map[string]ApplicationInfo, error) {
if len(all) == 0 {
return nil, nil
}
output := make(map[string]ApplicationInfo)
for _, one := range all {
tag, info, err := createApplicationInfo(one)
if err != nil {
return nil, errors.Trace(err)
}
output[tag.Name] = info
}
return output, nil
} | [
"func",
"formatApplicationInfos",
"(",
"all",
"[",
"]",
"params",
".",
"ApplicationInfo",
")",
"(",
"map",
"[",
"string",
"]",
"ApplicationInfo",
",",
"error",
")",
"{",
"if",
"len",
"(",
"all",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"output",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"ApplicationInfo",
")",
"\n",
"for",
"_",
",",
"one",
":=",
"range",
"all",
"{",
"tag",
",",
"info",
",",
"err",
":=",
"createApplicationInfo",
"(",
"one",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"output",
"[",
"tag",
".",
"Name",
"]",
"=",
"info",
"\n",
"}",
"\n",
"return",
"output",
",",
"nil",
"\n",
"}"
] | // formatApplicationInfos takes a set of params.ApplicationInfo and
// creates a mapping from storage ID application name to application info. | [
"formatApplicationInfos",
"takes",
"a",
"set",
"of",
"params",
".",
"ApplicationInfo",
"and",
"creates",
"a",
"mapping",
"from",
"storage",
"ID",
"application",
"name",
"to",
"application",
"info",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/show.go#L162-L175 |
154,120 | juju/juju | api/common/cloudspec/cloudspec.go | NewCloudSpecAPI | func NewCloudSpecAPI(facade base.FacadeCaller, modelTag names.ModelTag) *CloudSpecAPI {
return &CloudSpecAPI{facade, modelTag}
} | go | func NewCloudSpecAPI(facade base.FacadeCaller, modelTag names.ModelTag) *CloudSpecAPI {
return &CloudSpecAPI{facade, modelTag}
} | [
"func",
"NewCloudSpecAPI",
"(",
"facade",
"base",
".",
"FacadeCaller",
",",
"modelTag",
"names",
".",
"ModelTag",
")",
"*",
"CloudSpecAPI",
"{",
"return",
"&",
"CloudSpecAPI",
"{",
"facade",
",",
"modelTag",
"}",
"\n",
"}"
] | // NewCloudSpecAPI creates a CloudSpecAPI using the provided
// FacadeCaller. | [
"NewCloudSpecAPI",
"creates",
"a",
"CloudSpecAPI",
"using",
"the",
"provided",
"FacadeCaller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/common/cloudspec/cloudspec.go#L27-L29 |
154,121 | juju/juju | api/common/cloudspec/cloudspec.go | WatchCloudSpecChanges | func (api *CloudSpecAPI) WatchCloudSpecChanges() (watcher.NotifyWatcher, error) {
var results params.NotifyWatchResults
args := params.Entities{Entities: []params.Entity{{api.modelTag.String()}}}
err := api.facade.FacadeCall("WatchCloudSpecsChanges", args, &results)
if err != nil {
return nil, err
}
if n := len(results.Results); n != 1 {
return nil, errors.Errorf("expected 1 result, got %d", n)
}
result := results.Results[0]
if result.Error != nil {
return nil, errors.Annotate(result.Error, "API request failed")
}
return apiwatcher.NewNotifyWatcher(api.facade.RawAPICaller(), result), nil
} | go | func (api *CloudSpecAPI) WatchCloudSpecChanges() (watcher.NotifyWatcher, error) {
var results params.NotifyWatchResults
args := params.Entities{Entities: []params.Entity{{api.modelTag.String()}}}
err := api.facade.FacadeCall("WatchCloudSpecsChanges", args, &results)
if err != nil {
return nil, err
}
if n := len(results.Results); n != 1 {
return nil, errors.Errorf("expected 1 result, got %d", n)
}
result := results.Results[0]
if result.Error != nil {
return nil, errors.Annotate(result.Error, "API request failed")
}
return apiwatcher.NewNotifyWatcher(api.facade.RawAPICaller(), result), nil
} | [
"func",
"(",
"api",
"*",
"CloudSpecAPI",
")",
"WatchCloudSpecChanges",
"(",
")",
"(",
"watcher",
".",
"NotifyWatcher",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"NotifyWatchResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"api",
".",
"modelTag",
".",
"String",
"(",
")",
"}",
"}",
"}",
"\n",
"err",
":=",
"api",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
":=",
"len",
"(",
"results",
".",
"Results",
")",
";",
"n",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"result",
".",
"Error",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"apiwatcher",
".",
"NewNotifyWatcher",
"(",
"api",
".",
"facade",
".",
"RawAPICaller",
"(",
")",
",",
"result",
")",
",",
"nil",
"\n",
"}"
] | // WatchCloudSpecChanges returns a NotifyWatcher waiting for the
// model's cloud to change. | [
"WatchCloudSpecChanges",
"returns",
"a",
"NotifyWatcher",
"waiting",
"for",
"the",
"model",
"s",
"cloud",
"to",
"change",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/common/cloudspec/cloudspec.go#L33-L48 |
154,122 | juju/juju | api/common/cloudspec/cloudspec.go | CloudSpec | func (api *CloudSpecAPI) CloudSpec() (environs.CloudSpec, error) {
var results params.CloudSpecResults
args := params.Entities{Entities: []params.Entity{{api.modelTag.String()}}}
err := api.facade.FacadeCall("CloudSpec", args, &results)
if err != nil {
return environs.CloudSpec{}, err
}
if n := len(results.Results); n != 1 {
return environs.CloudSpec{}, errors.Errorf("expected 1 result, got %d", n)
}
result := results.Results[0]
if result.Error != nil {
return environs.CloudSpec{}, errors.Annotate(result.Error, "API request failed")
}
return api.MakeCloudSpec(result.Result)
} | go | func (api *CloudSpecAPI) CloudSpec() (environs.CloudSpec, error) {
var results params.CloudSpecResults
args := params.Entities{Entities: []params.Entity{{api.modelTag.String()}}}
err := api.facade.FacadeCall("CloudSpec", args, &results)
if err != nil {
return environs.CloudSpec{}, err
}
if n := len(results.Results); n != 1 {
return environs.CloudSpec{}, errors.Errorf("expected 1 result, got %d", n)
}
result := results.Results[0]
if result.Error != nil {
return environs.CloudSpec{}, errors.Annotate(result.Error, "API request failed")
}
return api.MakeCloudSpec(result.Result)
} | [
"func",
"(",
"api",
"*",
"CloudSpecAPI",
")",
"CloudSpec",
"(",
")",
"(",
"environs",
".",
"CloudSpec",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"CloudSpecResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"api",
".",
"modelTag",
".",
"String",
"(",
")",
"}",
"}",
"}",
"\n",
"err",
":=",
"api",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"environs",
".",
"CloudSpec",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
":=",
"len",
"(",
"results",
".",
"Results",
")",
";",
"n",
"!=",
"1",
"{",
"return",
"environs",
".",
"CloudSpec",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"environs",
".",
"CloudSpec",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"result",
".",
"Error",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"api",
".",
"MakeCloudSpec",
"(",
"result",
".",
"Result",
")",
"\n",
"}"
] | // CloudSpec returns the cloud specification for the model associated
// with the API facade. | [
"CloudSpec",
"returns",
"the",
"cloud",
"specification",
"for",
"the",
"model",
"associated",
"with",
"the",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/common/cloudspec/cloudspec.go#L52-L67 |
154,123 | juju/juju | api/common/cloudspec/cloudspec.go | MakeCloudSpec | func (api *CloudSpecAPI) MakeCloudSpec(pSpec *params.CloudSpec) (environs.CloudSpec, error) {
if pSpec == nil {
return environs.CloudSpec{}, errors.NotValidf("nil value")
}
var credential *cloud.Credential
if pSpec.Credential != nil {
credentialValue := cloud.NewCredential(
cloud.AuthType(pSpec.Credential.AuthType),
pSpec.Credential.Attributes,
)
credential = &credentialValue
}
spec := environs.CloudSpec{
Type: pSpec.Type,
Name: pSpec.Name,
Region: pSpec.Region,
Endpoint: pSpec.Endpoint,
IdentityEndpoint: pSpec.IdentityEndpoint,
StorageEndpoint: pSpec.StorageEndpoint,
CACertificates: pSpec.CACertificates,
Credential: credential,
}
if err := spec.Validate(); err != nil {
return environs.CloudSpec{}, errors.Annotate(err, "validating CloudSpec")
}
return spec, nil
} | go | func (api *CloudSpecAPI) MakeCloudSpec(pSpec *params.CloudSpec) (environs.CloudSpec, error) {
if pSpec == nil {
return environs.CloudSpec{}, errors.NotValidf("nil value")
}
var credential *cloud.Credential
if pSpec.Credential != nil {
credentialValue := cloud.NewCredential(
cloud.AuthType(pSpec.Credential.AuthType),
pSpec.Credential.Attributes,
)
credential = &credentialValue
}
spec := environs.CloudSpec{
Type: pSpec.Type,
Name: pSpec.Name,
Region: pSpec.Region,
Endpoint: pSpec.Endpoint,
IdentityEndpoint: pSpec.IdentityEndpoint,
StorageEndpoint: pSpec.StorageEndpoint,
CACertificates: pSpec.CACertificates,
Credential: credential,
}
if err := spec.Validate(); err != nil {
return environs.CloudSpec{}, errors.Annotate(err, "validating CloudSpec")
}
return spec, nil
} | [
"func",
"(",
"api",
"*",
"CloudSpecAPI",
")",
"MakeCloudSpec",
"(",
"pSpec",
"*",
"params",
".",
"CloudSpec",
")",
"(",
"environs",
".",
"CloudSpec",
",",
"error",
")",
"{",
"if",
"pSpec",
"==",
"nil",
"{",
"return",
"environs",
".",
"CloudSpec",
"{",
"}",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"credential",
"*",
"cloud",
".",
"Credential",
"\n",
"if",
"pSpec",
".",
"Credential",
"!=",
"nil",
"{",
"credentialValue",
":=",
"cloud",
".",
"NewCredential",
"(",
"cloud",
".",
"AuthType",
"(",
"pSpec",
".",
"Credential",
".",
"AuthType",
")",
",",
"pSpec",
".",
"Credential",
".",
"Attributes",
",",
")",
"\n",
"credential",
"=",
"&",
"credentialValue",
"\n",
"}",
"\n",
"spec",
":=",
"environs",
".",
"CloudSpec",
"{",
"Type",
":",
"pSpec",
".",
"Type",
",",
"Name",
":",
"pSpec",
".",
"Name",
",",
"Region",
":",
"pSpec",
".",
"Region",
",",
"Endpoint",
":",
"pSpec",
".",
"Endpoint",
",",
"IdentityEndpoint",
":",
"pSpec",
".",
"IdentityEndpoint",
",",
"StorageEndpoint",
":",
"pSpec",
".",
"StorageEndpoint",
",",
"CACertificates",
":",
"pSpec",
".",
"CACertificates",
",",
"Credential",
":",
"credential",
",",
"}",
"\n",
"if",
"err",
":=",
"spec",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"environs",
".",
"CloudSpec",
"{",
"}",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"spec",
",",
"nil",
"\n",
"}"
] | // MakeCloudSpec creates an environs.CloudSpec from a params.CloudSpec
// that has been returned from the apiserver. | [
"MakeCloudSpec",
"creates",
"an",
"environs",
".",
"CloudSpec",
"from",
"a",
"params",
".",
"CloudSpec",
"that",
"has",
"been",
"returned",
"from",
"the",
"apiserver",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/common/cloudspec/cloudspec.go#L71-L97 |
154,124 | juju/juju | state/images.go | ImageStorage | func (st *State) ImageStorage() imagestorage.Storage {
return imageStorageNewStorage(st.session, st.ModelUUID())
} | go | func (st *State) ImageStorage() imagestorage.Storage {
return imageStorageNewStorage(st.session, st.ModelUUID())
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ImageStorage",
"(",
")",
"imagestorage",
".",
"Storage",
"{",
"return",
"imageStorageNewStorage",
"(",
"st",
".",
"session",
",",
"st",
".",
"ModelUUID",
"(",
")",
")",
"\n",
"}"
] | // ImageStorage returns a new imagestorage.Storage
// that stores image metadata. | [
"ImageStorage",
"returns",
"a",
"new",
"imagestorage",
".",
"Storage",
"that",
"stores",
"image",
"metadata",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/images.go#L16-L18 |
154,125 | juju/juju | api/diskmanager/diskmanager.go | NewState | func NewState(caller base.APICaller, authTag names.MachineTag) *State {
return &State{
base.NewFacadeCaller(caller, diskManagerFacade),
authTag,
}
} | go | func NewState(caller base.APICaller, authTag names.MachineTag) *State {
return &State{
base.NewFacadeCaller(caller, diskManagerFacade),
authTag,
}
} | [
"func",
"NewState",
"(",
"caller",
"base",
".",
"APICaller",
",",
"authTag",
"names",
".",
"MachineTag",
")",
"*",
"State",
"{",
"return",
"&",
"State",
"{",
"base",
".",
"NewFacadeCaller",
"(",
"caller",
",",
"diskManagerFacade",
")",
",",
"authTag",
",",
"}",
"\n",
"}"
] | // NewState creates a new client-side DiskManager facade. | [
"NewState",
"creates",
"a",
"new",
"client",
"-",
"side",
"DiskManager",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/diskmanager/diskmanager.go#L23-L28 |
154,126 | juju/juju | api/diskmanager/diskmanager.go | SetMachineBlockDevices | func (st *State) SetMachineBlockDevices(devices []storage.BlockDevice) error {
args := params.SetMachineBlockDevices{
MachineBlockDevices: []params.MachineBlockDevices{{
Machine: st.tag.String(),
BlockDevices: devices,
}},
}
var results params.ErrorResults
err := st.facade.FacadeCall("SetMachineBlockDevices", args, &results)
if err != nil {
return err
}
return results.OneError()
} | go | func (st *State) SetMachineBlockDevices(devices []storage.BlockDevice) error {
args := params.SetMachineBlockDevices{
MachineBlockDevices: []params.MachineBlockDevices{{
Machine: st.tag.String(),
BlockDevices: devices,
}},
}
var results params.ErrorResults
err := st.facade.FacadeCall("SetMachineBlockDevices", args, &results)
if err != nil {
return err
}
return results.OneError()
} | [
"func",
"(",
"st",
"*",
"State",
")",
"SetMachineBlockDevices",
"(",
"devices",
"[",
"]",
"storage",
".",
"BlockDevice",
")",
"error",
"{",
"args",
":=",
"params",
".",
"SetMachineBlockDevices",
"{",
"MachineBlockDevices",
":",
"[",
"]",
"params",
".",
"MachineBlockDevices",
"{",
"{",
"Machine",
":",
"st",
".",
"tag",
".",
"String",
"(",
")",
",",
"BlockDevices",
":",
"devices",
",",
"}",
"}",
",",
"}",
"\n",
"var",
"results",
"params",
".",
"ErrorResults",
"\n",
"err",
":=",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"results",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // SetMachineBlockDevices sets the block devices attached to the machine
// identified by the authenticated machine tag. | [
"SetMachineBlockDevices",
"sets",
"the",
"block",
"devices",
"attached",
"to",
"the",
"machine",
"identified",
"by",
"the",
"authenticated",
"machine",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/diskmanager/diskmanager.go#L32-L45 |
154,127 | juju/juju | storage/provider/dummy/filesystemsource.go | ValidateFilesystemParams | func (s *FilesystemSource) ValidateFilesystemParams(params storage.FilesystemParams) error {
s.MethodCall(s, "ValidateFilesystemParams", params)
if s.ValidateFilesystemParamsFunc != nil {
return s.ValidateFilesystemParamsFunc(params)
}
return nil
} | go | func (s *FilesystemSource) ValidateFilesystemParams(params storage.FilesystemParams) error {
s.MethodCall(s, "ValidateFilesystemParams", params)
if s.ValidateFilesystemParamsFunc != nil {
return s.ValidateFilesystemParamsFunc(params)
}
return nil
} | [
"func",
"(",
"s",
"*",
"FilesystemSource",
")",
"ValidateFilesystemParams",
"(",
"params",
"storage",
".",
"FilesystemParams",
")",
"error",
"{",
"s",
".",
"MethodCall",
"(",
"s",
",",
"\"",
"\"",
",",
"params",
")",
"\n",
"if",
"s",
".",
"ValidateFilesystemParamsFunc",
"!=",
"nil",
"{",
"return",
"s",
".",
"ValidateFilesystemParamsFunc",
"(",
"params",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidateFilesystemParams is defined on storage.FilesystemSource. | [
"ValidateFilesystemParams",
"is",
"defined",
"on",
"storage",
".",
"FilesystemSource",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/dummy/filesystemsource.go#L56-L62 |
154,128 | juju/juju | apiserver/facades/client/application/mocks/charm_mock.go | NewMockStateCharm | func NewMockStateCharm(ctrl *gomock.Controller) *MockStateCharm {
mock := &MockStateCharm{ctrl: ctrl}
mock.recorder = &MockStateCharmMockRecorder{mock}
return mock
} | go | func NewMockStateCharm(ctrl *gomock.Controller) *MockStateCharm {
mock := &MockStateCharm{ctrl: ctrl}
mock.recorder = &MockStateCharmMockRecorder{mock}
return mock
} | [
"func",
"NewMockStateCharm",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockStateCharm",
"{",
"mock",
":=",
"&",
"MockStateCharm",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockStateCharmMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockStateCharm creates a new mock instance | [
"NewMockStateCharm",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charm_mock.go#L24-L28 |
154,129 | juju/juju | apiserver/facades/client/application/mocks/charm_mock.go | IsUploaded | func (m *MockStateCharm) IsUploaded() bool {
ret := m.ctrl.Call(m, "IsUploaded")
ret0, _ := ret[0].(bool)
return ret0
} | go | func (m *MockStateCharm) IsUploaded() bool {
ret := m.ctrl.Call(m, "IsUploaded")
ret0, _ := ret[0].(bool)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockStateCharm",
")",
"IsUploaded",
"(",
")",
"bool",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // IsUploaded mocks base method | [
"IsUploaded",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charm_mock.go#L36-L40 |
154,130 | juju/juju | apiserver/facades/client/application/mocks/charm_mock.go | IsUploaded | func (mr *MockStateCharmMockRecorder) IsUploaded() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUploaded", reflect.TypeOf((*MockStateCharm)(nil).IsUploaded))
} | go | func (mr *MockStateCharmMockRecorder) IsUploaded() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUploaded", reflect.TypeOf((*MockStateCharm)(nil).IsUploaded))
} | [
"func",
"(",
"mr",
"*",
"MockStateCharmMockRecorder",
")",
"IsUploaded",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockStateCharm",
")",
"(",
"nil",
")",
".",
"IsUploaded",
")",
")",
"\n",
"}"
] | // IsUploaded indicates an expected call of IsUploaded | [
"IsUploaded",
"indicates",
"an",
"expected",
"call",
"of",
"IsUploaded"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charm_mock.go#L43-L45 |
154,131 | juju/juju | apiserver/facades/client/application/mocks/charmstore_mock.go | ControllerConfig | func (m *MockState) ControllerConfig() (controller.Config, error) {
ret := m.ctrl.Call(m, "ControllerConfig")
ret0, _ := ret[0].(controller.Config)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockState) ControllerConfig() (controller.Config, error) {
ret := m.ctrl.Call(m, "ControllerConfig")
ret0, _ := ret[0].(controller.Config)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockState",
")",
"ControllerConfig",
"(",
")",
"(",
"controller",
".",
"Config",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"controller",
".",
"Config",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ControllerConfig mocks base method | [
"ControllerConfig",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charmstore_mock.go#L41-L46 |
154,132 | juju/juju | apiserver/facades/client/application/mocks/charmstore_mock.go | ModelUUID | func (m *MockState) ModelUUID() string {
ret := m.ctrl.Call(m, "ModelUUID")
ret0, _ := ret[0].(string)
return ret0
} | go | func (m *MockState) ModelUUID() string {
ret := m.ctrl.Call(m, "ModelUUID")
ret0, _ := ret[0].(string)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockState",
")",
"ModelUUID",
"(",
")",
"string",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // ModelUUID mocks base method | [
"ModelUUID",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charmstore_mock.go#L67-L71 |
154,133 | juju/juju | apiserver/facades/client/application/mocks/charmstore_mock.go | ModelUUID | func (mr *MockStateMockRecorder) ModelUUID() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModelUUID", reflect.TypeOf((*MockState)(nil).ModelUUID))
} | go | func (mr *MockStateMockRecorder) ModelUUID() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModelUUID", reflect.TypeOf((*MockState)(nil).ModelUUID))
} | [
"func",
"(",
"mr",
"*",
"MockStateMockRecorder",
")",
"ModelUUID",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockState",
")",
"(",
"nil",
")",
".",
"ModelUUID",
")",
")",
"\n",
"}"
] | // ModelUUID indicates an expected call of ModelUUID | [
"ModelUUID",
"indicates",
"an",
"expected",
"call",
"of",
"ModelUUID"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charmstore_mock.go#L74-L76 |
154,134 | juju/juju | apiserver/facades/client/application/mocks/charmstore_mock.go | MongoSession | func (m *MockState) MongoSession() *mgo_v2.Session {
ret := m.ctrl.Call(m, "MongoSession")
ret0, _ := ret[0].(*mgo_v2.Session)
return ret0
} | go | func (m *MockState) MongoSession() *mgo_v2.Session {
ret := m.ctrl.Call(m, "MongoSession")
ret0, _ := ret[0].(*mgo_v2.Session)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockState",
")",
"MongoSession",
"(",
")",
"*",
"mgo_v2",
".",
"Session",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"mgo_v2",
".",
"Session",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // MongoSession mocks base method | [
"MongoSession",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charmstore_mock.go#L79-L83 |
154,135 | juju/juju | apiserver/facades/client/application/mocks/charmstore_mock.go | PrepareStoreCharmUpload | func (m *MockState) PrepareStoreCharmUpload(arg0 *charm_v6.URL) (application.StateCharm, error) {
ret := m.ctrl.Call(m, "PrepareStoreCharmUpload", arg0)
ret0, _ := ret[0].(application.StateCharm)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockState) PrepareStoreCharmUpload(arg0 *charm_v6.URL) (application.StateCharm, error) {
ret := m.ctrl.Call(m, "PrepareStoreCharmUpload", arg0)
ret0, _ := ret[0].(application.StateCharm)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockState",
")",
"PrepareStoreCharmUpload",
"(",
"arg0",
"*",
"charm_v6",
".",
"URL",
")",
"(",
"application",
".",
"StateCharm",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"application",
".",
"StateCharm",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // PrepareStoreCharmUpload mocks base method | [
"PrepareStoreCharmUpload",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charmstore_mock.go#L91-L96 |
154,136 | juju/juju | apiserver/facades/client/application/mocks/charmstore_mock.go | UpdateUploadedCharm | func (m *MockState) UpdateUploadedCharm(arg0 state.CharmInfo) (*state.Charm, error) {
ret := m.ctrl.Call(m, "UpdateUploadedCharm", arg0)
ret0, _ := ret[0].(*state.Charm)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockState) UpdateUploadedCharm(arg0 state.CharmInfo) (*state.Charm, error) {
ret := m.ctrl.Call(m, "UpdateUploadedCharm", arg0)
ret0, _ := ret[0].(*state.Charm)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockState",
")",
"UpdateUploadedCharm",
"(",
"arg0",
"state",
".",
"CharmInfo",
")",
"(",
"*",
"state",
".",
"Charm",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"state",
".",
"Charm",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // UpdateUploadedCharm mocks base method | [
"UpdateUploadedCharm",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/mocks/charmstore_mock.go#L104-L109 |
154,137 | juju/juju | worker/httpserver/worker.go | Report | func (w *Worker) Report() map[string]interface{} {
w.mu.Lock()
result := map[string]interface{}{
"api-port": w.config.APIPort,
"status": w.status,
"ports": w.holdable.report(),
}
if w.config.ControllerAPIPort != 0 {
result["api-port-open-delay"] = w.config.APIPortOpenDelay
result["controller-api-port"] = w.config.ControllerAPIPort
}
w.mu.Unlock()
return result
} | go | func (w *Worker) Report() map[string]interface{} {
w.mu.Lock()
result := map[string]interface{}{
"api-port": w.config.APIPort,
"status": w.status,
"ports": w.holdable.report(),
}
if w.config.ControllerAPIPort != 0 {
result["api-port-open-delay"] = w.config.APIPortOpenDelay
result["controller-api-port"] = w.config.ControllerAPIPort
}
w.mu.Unlock()
return result
} | [
"func",
"(",
"w",
"*",
"Worker",
")",
"Report",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"result",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"w",
".",
"config",
".",
"APIPort",
",",
"\"",
"\"",
":",
"w",
".",
"status",
",",
"\"",
"\"",
":",
"w",
".",
"holdable",
".",
"report",
"(",
")",
",",
"}",
"\n",
"if",
"w",
".",
"config",
".",
"ControllerAPIPort",
"!=",
"0",
"{",
"result",
"[",
"\"",
"\"",
"]",
"=",
"w",
".",
"config",
".",
"APIPortOpenDelay",
"\n",
"result",
"[",
"\"",
"\"",
"]",
"=",
"w",
".",
"config",
".",
"ControllerAPIPort",
"\n",
"}",
"\n",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"result",
"\n",
"}"
] | // Report provides information for the engine report. | [
"Report",
"provides",
"information",
"for",
"the",
"engine",
"report",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/httpserver/worker.go#L125-L138 |
154,138 | juju/juju | worker/httpserver/worker.go | Close | func (d *dualListener) Close() error {
// Only close the channel once.
d.closer.Do(func() { close(d.done) })
err := d.controllerListener.Close()
d.mu.Lock()
defer d.mu.Unlock()
if d.apiListener != nil {
err2 := d.apiListener.Close()
if err == nil {
err = err2
}
// If we already have a close error, we don't really care
// about this one.
}
d.status = "closed ports"
return errors.Trace(err)
} | go | func (d *dualListener) Close() error {
// Only close the channel once.
d.closer.Do(func() { close(d.done) })
err := d.controllerListener.Close()
d.mu.Lock()
defer d.mu.Unlock()
if d.apiListener != nil {
err2 := d.apiListener.Close()
if err == nil {
err = err2
}
// If we already have a close error, we don't really care
// about this one.
}
d.status = "closed ports"
return errors.Trace(err)
} | [
"func",
"(",
"d",
"*",
"dualListener",
")",
"Close",
"(",
")",
"error",
"{",
"// Only close the channel once.",
"d",
".",
"closer",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"d",
".",
"done",
")",
"}",
")",
"\n",
"err",
":=",
"d",
".",
"controllerListener",
".",
"Close",
"(",
")",
"\n",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"d",
".",
"apiListener",
"!=",
"nil",
"{",
"err2",
":=",
"d",
".",
"apiListener",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"err2",
"\n",
"}",
"\n",
"// If we already have a close error, we don't really care",
"// about this one.",
"}",
"\n",
"d",
".",
"status",
"=",
"\"",
"\"",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Close implements net.Listener. Closes all the open listeners. | [
"Close",
"implements",
"net",
".",
"Listener",
".",
"Closes",
"all",
"the",
"open",
"listeners",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/httpserver/worker.go#L428-L444 |
154,139 | juju/juju | worker/httpserver/worker.go | Addr | func (d *dualListener) Addr() net.Addr {
d.mu.Lock()
defer d.mu.Unlock()
if d.apiListener != nil {
return d.apiListener.Addr()
}
return d.controllerListener.Addr()
} | go | func (d *dualListener) Addr() net.Addr {
d.mu.Lock()
defer d.mu.Unlock()
if d.apiListener != nil {
return d.apiListener.Addr()
}
return d.controllerListener.Addr()
} | [
"func",
"(",
"d",
"*",
"dualListener",
")",
"Addr",
"(",
")",
"net",
".",
"Addr",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"d",
".",
"apiListener",
"!=",
"nil",
"{",
"return",
"d",
".",
"apiListener",
".",
"Addr",
"(",
")",
"\n",
"}",
"\n",
"return",
"d",
".",
"controllerListener",
".",
"Addr",
"(",
")",
"\n",
"}"
] | // Addr implements net.Listener. If the api port has been opened, we
// return that, otherwise we return the controller port address. | [
"Addr",
"implements",
"net",
".",
"Listener",
".",
"If",
"the",
"api",
"port",
"has",
"been",
"opened",
"we",
"return",
"that",
"otherwise",
"we",
"return",
"the",
"controller",
"port",
"address",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/httpserver/worker.go#L448-L455 |
154,140 | juju/juju | worker/httpserver/worker.go | openAPIPort | func (d *dualListener) openAPIPort(topic string, conn apiserver.APIConnection, err error) {
if err != nil {
logger.Errorf("programming error: %v", err)
return
}
// We are wanting to make sure that the api-caller has connected before we
// open the api port. Each api connection is published with the origin tag.
// Any origin that matches our agent name means that someone has connected
// to us. We need to also check which agent connected as it is possible that
// one of the other HA controller could connect before we connect to
// ourselves.
if conn.Origin != d.agentName || conn.AgentTag != d.agentName {
return
}
d.unsub()
if d.delay > 0 {
d.mu.Lock()
d.status = "waiting prior to opening agent port"
d.mu.Unlock()
logger.Infof("waiting for %s before allowing api connections", d.delay)
<-d.clock.After(d.delay)
}
d.mu.Lock()
defer d.mu.Unlock()
// Make sure we haven't been closed already.
select {
case <-d.done:
return
default:
// We are all good.
}
listenAddr := net.JoinHostPort("", strconv.Itoa(d.apiPort))
listener, err := net.Listen("tcp", listenAddr)
if err != nil {
select {
case d.errors <- err:
case <-d.done:
logger.Errorf("can't open api port: %v, but worker exiting already", err)
}
return
}
logger.Infof("listening for api connections on %q", listener.Addr())
d.apiListener = listener
go d.accept(listener)
d.status = ""
} | go | func (d *dualListener) openAPIPort(topic string, conn apiserver.APIConnection, err error) {
if err != nil {
logger.Errorf("programming error: %v", err)
return
}
// We are wanting to make sure that the api-caller has connected before we
// open the api port. Each api connection is published with the origin tag.
// Any origin that matches our agent name means that someone has connected
// to us. We need to also check which agent connected as it is possible that
// one of the other HA controller could connect before we connect to
// ourselves.
if conn.Origin != d.agentName || conn.AgentTag != d.agentName {
return
}
d.unsub()
if d.delay > 0 {
d.mu.Lock()
d.status = "waiting prior to opening agent port"
d.mu.Unlock()
logger.Infof("waiting for %s before allowing api connections", d.delay)
<-d.clock.After(d.delay)
}
d.mu.Lock()
defer d.mu.Unlock()
// Make sure we haven't been closed already.
select {
case <-d.done:
return
default:
// We are all good.
}
listenAddr := net.JoinHostPort("", strconv.Itoa(d.apiPort))
listener, err := net.Listen("tcp", listenAddr)
if err != nil {
select {
case d.errors <- err:
case <-d.done:
logger.Errorf("can't open api port: %v, but worker exiting already", err)
}
return
}
logger.Infof("listening for api connections on %q", listener.Addr())
d.apiListener = listener
go d.accept(listener)
d.status = ""
} | [
"func",
"(",
"d",
"*",
"dualListener",
")",
"openAPIPort",
"(",
"topic",
"string",
",",
"conn",
"apiserver",
".",
"APIConnection",
",",
"err",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// We are wanting to make sure that the api-caller has connected before we",
"// open the api port. Each api connection is published with the origin tag.",
"// Any origin that matches our agent name means that someone has connected",
"// to us. We need to also check which agent connected as it is possible that",
"// one of the other HA controller could connect before we connect to",
"// ourselves.",
"if",
"conn",
".",
"Origin",
"!=",
"d",
".",
"agentName",
"||",
"conn",
".",
"AgentTag",
"!=",
"d",
".",
"agentName",
"{",
"return",
"\n",
"}",
"\n\n",
"d",
".",
"unsub",
"(",
")",
"\n",
"if",
"d",
".",
"delay",
">",
"0",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"d",
".",
"status",
"=",
"\"",
"\"",
"\n",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"d",
".",
"delay",
")",
"\n",
"<-",
"d",
".",
"clock",
".",
"After",
"(",
"d",
".",
"delay",
")",
"\n",
"}",
"\n\n",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"// Make sure we haven't been closed already.",
"select",
"{",
"case",
"<-",
"d",
".",
"done",
":",
"return",
"\n",
"default",
":",
"// We are all good.",
"}",
"\n\n",
"listenAddr",
":=",
"net",
".",
"JoinHostPort",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"d",
".",
"apiPort",
")",
")",
"\n",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"listenAddr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"select",
"{",
"case",
"d",
".",
"errors",
"<-",
"err",
":",
"case",
"<-",
"d",
".",
"done",
":",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"listener",
".",
"Addr",
"(",
")",
")",
"\n",
"d",
".",
"apiListener",
"=",
"listener",
"\n",
"go",
"d",
".",
"accept",
"(",
"listener",
")",
"\n",
"d",
".",
"status",
"=",
"\"",
"\"",
"\n",
"}"
] | // openAPIPort opens the api port and starts accepting connections. | [
"openAPIPort",
"opens",
"the",
"api",
"port",
"and",
"starts",
"accepting",
"connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/httpserver/worker.go#L463-L512 |
154,141 | juju/juju | cmd/juju/romulus/listplans/list_plans.go | Init | func (c *ListPlansCommand) Init(args []string) error {
if len(args) == 0 {
return errors.New("missing arguments")
}
charmURL, args := args[0], args[1:]
if err := cmd.CheckEmpty(args); err != nil {
return errors.Errorf("unknown command line arguments: " + strings.Join(args, ","))
}
c.CharmURL = charmURL
return c.CommandBase.Init(args)
} | go | func (c *ListPlansCommand) Init(args []string) error {
if len(args) == 0 {
return errors.New("missing arguments")
}
charmURL, args := args[0], args[1:]
if err := cmd.CheckEmpty(args); err != nil {
return errors.Errorf("unknown command line arguments: " + strings.Join(args, ","))
}
c.CharmURL = charmURL
return c.CommandBase.Init(args)
} | [
"func",
"(",
"c",
"*",
"ListPlansCommand",
")",
"Init",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"charmURL",
",",
"args",
":=",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"\n",
"if",
"err",
":=",
"cmd",
".",
"CheckEmpty",
"(",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"c",
".",
"CharmURL",
"=",
"charmURL",
"\n",
"return",
"c",
".",
"CommandBase",
".",
"Init",
"(",
"args",
")",
"\n",
"}"
] | // Init reads and verifies the cli arguments for the ListPlansCommand | [
"Init",
"reads",
"and",
"verifies",
"the",
"cli",
"arguments",
"for",
"the",
"ListPlansCommand"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/romulus/listplans/list_plans.go#L72-L82 |
154,142 | juju/juju | cmd/juju/romulus/listplans/list_plans.go | Run | func (c *ListPlansCommand) Run(ctx *cmd.Context) (rErr error) {
client, err := c.BakeryClient()
if err != nil {
return errors.Annotate(err, "failed to create an http client")
}
resolver, err := rcmd.NewCharmStoreResolverForControllerCmd(&c.ControllerCommandBase)
if err != nil {
return errors.Trace(err)
}
resolvedURL, err := resolver.Resolve(client, c.CharmURL)
if err != nil {
return errors.Annotatef(err, "failed to resolve charmURL %v", c.CharmURL)
}
c.CharmURL = resolvedURL
apiRoot, err := rcmd.GetMeteringURLForControllerCmd(&c.ControllerCommandBase)
if err != nil {
return errors.Trace(err)
}
apiClient, err := newClient(apiRoot, client)
if err != nil {
return errors.Annotate(err, "failed to create a plan API client")
}
plans, err := apiClient.GetAssociatedPlans(c.CharmURL)
if err != nil {
return errors.Annotate(err, "failed to retrieve plans")
}
output := make([]plan, len(plans))
for i, p := range plans {
outputPlan := plan{
URL: p.URL,
}
def, err := readPlan(bytes.NewBufferString(p.Definition))
if err != nil {
return errors.Annotate(err, "failed to parse plan definition")
}
if def.Description != nil {
outputPlan.Price = def.Description.Price
outputPlan.Description = def.Description.Text
}
output[i] = outputPlan
}
if len(output) == 0 && c.out.Name() == "tabular" {
ctx.Infof("No plans to display.")
}
err = c.out.Write(ctx, output)
if err != nil {
return errors.Trace(err)
}
return nil
} | go | func (c *ListPlansCommand) Run(ctx *cmd.Context) (rErr error) {
client, err := c.BakeryClient()
if err != nil {
return errors.Annotate(err, "failed to create an http client")
}
resolver, err := rcmd.NewCharmStoreResolverForControllerCmd(&c.ControllerCommandBase)
if err != nil {
return errors.Trace(err)
}
resolvedURL, err := resolver.Resolve(client, c.CharmURL)
if err != nil {
return errors.Annotatef(err, "failed to resolve charmURL %v", c.CharmURL)
}
c.CharmURL = resolvedURL
apiRoot, err := rcmd.GetMeteringURLForControllerCmd(&c.ControllerCommandBase)
if err != nil {
return errors.Trace(err)
}
apiClient, err := newClient(apiRoot, client)
if err != nil {
return errors.Annotate(err, "failed to create a plan API client")
}
plans, err := apiClient.GetAssociatedPlans(c.CharmURL)
if err != nil {
return errors.Annotate(err, "failed to retrieve plans")
}
output := make([]plan, len(plans))
for i, p := range plans {
outputPlan := plan{
URL: p.URL,
}
def, err := readPlan(bytes.NewBufferString(p.Definition))
if err != nil {
return errors.Annotate(err, "failed to parse plan definition")
}
if def.Description != nil {
outputPlan.Price = def.Description.Price
outputPlan.Description = def.Description.Text
}
output[i] = outputPlan
}
if len(output) == 0 && c.out.Name() == "tabular" {
ctx.Infof("No plans to display.")
}
err = c.out.Write(ctx, output)
if err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"ListPlansCommand",
")",
"Run",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
")",
"(",
"rErr",
"error",
")",
"{",
"client",
",",
"err",
":=",
"c",
".",
"BakeryClient",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resolver",
",",
"err",
":=",
"rcmd",
".",
"NewCharmStoreResolverForControllerCmd",
"(",
"&",
"c",
".",
"ControllerCommandBase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"resolvedURL",
",",
"err",
":=",
"resolver",
".",
"Resolve",
"(",
"client",
",",
"c",
".",
"CharmURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"c",
".",
"CharmURL",
")",
"\n",
"}",
"\n",
"c",
".",
"CharmURL",
"=",
"resolvedURL",
"\n\n",
"apiRoot",
",",
"err",
":=",
"rcmd",
".",
"GetMeteringURLForControllerCmd",
"(",
"&",
"c",
".",
"ControllerCommandBase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"apiClient",
",",
"err",
":=",
"newClient",
"(",
"apiRoot",
",",
"client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"plans",
",",
"err",
":=",
"apiClient",
".",
"GetAssociatedPlans",
"(",
"c",
".",
"CharmURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"output",
":=",
"make",
"(",
"[",
"]",
"plan",
",",
"len",
"(",
"plans",
")",
")",
"\n",
"for",
"i",
",",
"p",
":=",
"range",
"plans",
"{",
"outputPlan",
":=",
"plan",
"{",
"URL",
":",
"p",
".",
"URL",
",",
"}",
"\n",
"def",
",",
"err",
":=",
"readPlan",
"(",
"bytes",
".",
"NewBufferString",
"(",
"p",
".",
"Definition",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"def",
".",
"Description",
"!=",
"nil",
"{",
"outputPlan",
".",
"Price",
"=",
"def",
".",
"Description",
".",
"Price",
"\n",
"outputPlan",
".",
"Description",
"=",
"def",
".",
"Description",
".",
"Text",
"\n",
"}",
"\n",
"output",
"[",
"i",
"]",
"=",
"outputPlan",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"output",
")",
"==",
"0",
"&&",
"c",
".",
"out",
".",
"Name",
"(",
")",
"==",
"\"",
"\"",
"{",
"ctx",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"out",
".",
"Write",
"(",
"ctx",
",",
"output",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Run implements Command.Run.
// Retrieves the plan from the plans service. The set of plans to be
// retrieved can be limited using the plan and isv flags. | [
"Run",
"implements",
"Command",
".",
"Run",
".",
"Retrieves",
"the",
"plan",
"from",
"the",
"plans",
"service",
".",
"The",
"set",
"of",
"plans",
"to",
"be",
"retrieved",
"can",
"be",
"limited",
"using",
"the",
"plan",
"and",
"isv",
"flags",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/romulus/listplans/list_plans.go#L100-L156 |
154,143 | juju/juju | cmd/juju/romulus/listplans/list_plans.go | formatSummary | func formatSummary(writer io.Writer, value interface{}) error {
plans, ok := value.([]plan)
if !ok {
return errors.Errorf("expected value of type %T, got %T", plans, value)
}
tw := output.TabWriter(writer)
p := func(values ...interface{}) {
for _, v := range values {
fmt.Fprintf(tw, "%s\t", v)
}
fmt.Fprintln(tw)
}
p("Plan", "Price")
for _, plan := range plans {
p(plan.URL, plan.Price)
}
tw.Flush()
return nil
} | go | func formatSummary(writer io.Writer, value interface{}) error {
plans, ok := value.([]plan)
if !ok {
return errors.Errorf("expected value of type %T, got %T", plans, value)
}
tw := output.TabWriter(writer)
p := func(values ...interface{}) {
for _, v := range values {
fmt.Fprintf(tw, "%s\t", v)
}
fmt.Fprintln(tw)
}
p("Plan", "Price")
for _, plan := range plans {
p(plan.URL, plan.Price)
}
tw.Flush()
return nil
} | [
"func",
"formatSummary",
"(",
"writer",
"io",
".",
"Writer",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"plans",
",",
"ok",
":=",
"value",
".",
"(",
"[",
"]",
"plan",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"plans",
",",
"value",
")",
"\n",
"}",
"\n",
"tw",
":=",
"output",
".",
"TabWriter",
"(",
"writer",
")",
"\n",
"p",
":=",
"func",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"values",
"{",
"fmt",
".",
"Fprintf",
"(",
"tw",
",",
"\"",
"\\t",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"tw",
")",
"\n",
"}",
"\n",
"p",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"plans",
"{",
"p",
"(",
"plan",
".",
"URL",
",",
"plan",
".",
"Price",
")",
"\n",
"}",
"\n",
"tw",
".",
"Flush",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // formatSummary returns a summary of available plans. | [
"formatSummary",
"returns",
"a",
"summary",
"of",
"available",
"plans",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/romulus/listplans/list_plans.go#L165-L183 |
154,144 | juju/juju | cmd/juju/romulus/listplans/list_plans.go | formatTabular | func formatTabular(writer io.Writer, value interface{}) error {
plans, ok := value.([]plan)
if !ok {
return errors.Errorf("expected value of type %T, got %T", plans, value)
}
table := uitable.New()
table.MaxColWidth = 50
table.Wrap = true
table.AddRow("Plan", "Price", "Description")
for _, plan := range plans {
table.AddRow(plan.URL, plan.Price, plan.Description)
}
fmt.Fprint(writer, table)
return nil
} | go | func formatTabular(writer io.Writer, value interface{}) error {
plans, ok := value.([]plan)
if !ok {
return errors.Errorf("expected value of type %T, got %T", plans, value)
}
table := uitable.New()
table.MaxColWidth = 50
table.Wrap = true
table.AddRow("Plan", "Price", "Description")
for _, plan := range plans {
table.AddRow(plan.URL, plan.Price, plan.Description)
}
fmt.Fprint(writer, table)
return nil
} | [
"func",
"formatTabular",
"(",
"writer",
"io",
".",
"Writer",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"plans",
",",
"ok",
":=",
"value",
".",
"(",
"[",
"]",
"plan",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"plans",
",",
"value",
")",
"\n",
"}",
"\n\n",
"table",
":=",
"uitable",
".",
"New",
"(",
")",
"\n",
"table",
".",
"MaxColWidth",
"=",
"50",
"\n",
"table",
".",
"Wrap",
"=",
"true",
"\n\n",
"table",
".",
"AddRow",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"plans",
"{",
"table",
".",
"AddRow",
"(",
"plan",
".",
"URL",
",",
"plan",
".",
"Price",
",",
"plan",
".",
"Description",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprint",
"(",
"writer",
",",
"table",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // formatTabular returns a tabular summary of available plans. | [
"formatTabular",
"returns",
"a",
"tabular",
"summary",
"of",
"available",
"plans",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/romulus/listplans/list_plans.go#L186-L202 |
154,145 | juju/juju | cmd/juju/romulus/listplans/list_plans.go | readPlan | func readPlan(r io.Reader) (plan *planModel, err error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return
}
var doc planModel
err = yaml.Unmarshal(data, &doc)
if err != nil {
return
}
return &doc, nil
} | go | func readPlan(r io.Reader) (plan *planModel, err error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return
}
var doc planModel
err = yaml.Unmarshal(data, &doc)
if err != nil {
return
}
return &doc, nil
} | [
"func",
"readPlan",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"plan",
"*",
"planModel",
",",
"err",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"var",
"doc",
"planModel",
"\n",
"err",
"=",
"yaml",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"doc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"&",
"doc",
",",
"nil",
"\n",
"}"
] | // readPlan reads, parses and returns a planModel struct representation. | [
"readPlan",
"reads",
"parses",
"and",
"returns",
"a",
"planModel",
"struct",
"representation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/romulus/listplans/list_plans.go#L215-L227 |
154,146 | juju/juju | caas/kubernetes/provider/mocks/appv1_mock.go | NewMockAppsV1Interface | func NewMockAppsV1Interface(ctrl *gomock.Controller) *MockAppsV1Interface {
mock := &MockAppsV1Interface{ctrl: ctrl}
mock.recorder = &MockAppsV1InterfaceMockRecorder{mock}
return mock
} | go | func NewMockAppsV1Interface(ctrl *gomock.Controller) *MockAppsV1Interface {
mock := &MockAppsV1Interface{ctrl: ctrl}
mock.recorder = &MockAppsV1InterfaceMockRecorder{mock}
return mock
} | [
"func",
"NewMockAppsV1Interface",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockAppsV1Interface",
"{",
"mock",
":=",
"&",
"MockAppsV1Interface",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockAppsV1InterfaceMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockAppsV1Interface creates a new mock instance | [
"NewMockAppsV1Interface",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/appv1_mock.go#L31-L35 |
154,147 | juju/juju | caas/kubernetes/provider/mocks/appv1_mock.go | ControllerRevisions | func (m *MockAppsV1Interface) ControllerRevisions(arg0 string) v11.ControllerRevisionInterface {
ret := m.ctrl.Call(m, "ControllerRevisions", arg0)
ret0, _ := ret[0].(v11.ControllerRevisionInterface)
return ret0
} | go | func (m *MockAppsV1Interface) ControllerRevisions(arg0 string) v11.ControllerRevisionInterface {
ret := m.ctrl.Call(m, "ControllerRevisions", arg0)
ret0, _ := ret[0].(v11.ControllerRevisionInterface)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockAppsV1Interface",
")",
"ControllerRevisions",
"(",
"arg0",
"string",
")",
"v11",
".",
"ControllerRevisionInterface",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"v11",
".",
"ControllerRevisionInterface",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // ControllerRevisions mocks base method | [
"ControllerRevisions",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/appv1_mock.go#L43-L47 |
154,148 | juju/juju | caas/kubernetes/provider/mocks/appv1_mock.go | ControllerRevisions | func (mr *MockAppsV1InterfaceMockRecorder) ControllerRevisions(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerRevisions", reflect.TypeOf((*MockAppsV1Interface)(nil).ControllerRevisions), arg0)
} | go | func (mr *MockAppsV1InterfaceMockRecorder) ControllerRevisions(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControllerRevisions", reflect.TypeOf((*MockAppsV1Interface)(nil).ControllerRevisions), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockAppsV1InterfaceMockRecorder",
")",
"ControllerRevisions",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockAppsV1Interface",
")",
"(",
"nil",
")",
".",
"ControllerRevisions",
")",
",",
"arg0",
")",
"\n",
"}"
] | // ControllerRevisions indicates an expected call of ControllerRevisions | [
"ControllerRevisions",
"indicates",
"an",
"expected",
"call",
"of",
"ControllerRevisions"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/appv1_mock.go#L50-L52 |
154,149 | juju/juju | caas/kubernetes/provider/mocks/appv1_mock.go | StatefulSets | func (m *MockAppsV1Interface) StatefulSets(arg0 string) v11.StatefulSetInterface {
ret := m.ctrl.Call(m, "StatefulSets", arg0)
ret0, _ := ret[0].(v11.StatefulSetInterface)
return ret0
} | go | func (m *MockAppsV1Interface) StatefulSets(arg0 string) v11.StatefulSetInterface {
ret := m.ctrl.Call(m, "StatefulSets", arg0)
ret0, _ := ret[0].(v11.StatefulSetInterface)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockAppsV1Interface",
")",
"StatefulSets",
"(",
"arg0",
"string",
")",
"v11",
".",
"StatefulSetInterface",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"v11",
".",
"StatefulSetInterface",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // StatefulSets mocks base method | [
"StatefulSets",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/appv1_mock.go#L103-L107 |
154,150 | juju/juju | caas/kubernetes/provider/mocks/appv1_mock.go | NewMockDeploymentInterface | func NewMockDeploymentInterface(ctrl *gomock.Controller) *MockDeploymentInterface {
mock := &MockDeploymentInterface{ctrl: ctrl}
mock.recorder = &MockDeploymentInterfaceMockRecorder{mock}
return mock
} | go | func NewMockDeploymentInterface(ctrl *gomock.Controller) *MockDeploymentInterface {
mock := &MockDeploymentInterface{ctrl: ctrl}
mock.recorder = &MockDeploymentInterfaceMockRecorder{mock}
return mock
} | [
"func",
"NewMockDeploymentInterface",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockDeploymentInterface",
"{",
"mock",
":=",
"&",
"MockDeploymentInterface",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockDeploymentInterfaceMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockDeploymentInterface creates a new mock instance | [
"NewMockDeploymentInterface",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/appv1_mock.go#L126-L130 |
154,151 | juju/juju | caas/kubernetes/provider/mocks/appv1_mock.go | Watch | func (mr *MockDeploymentInterfaceMockRecorder) Watch(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockDeploymentInterface)(nil).Watch), arg0)
} | go | func (mr *MockDeploymentInterfaceMockRecorder) Watch(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockDeploymentInterface)(nil).Watch), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockDeploymentInterfaceMockRecorder",
")",
"Watch",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockDeploymentInterface",
")",
"(",
"nil",
")",
".",
"Watch",
")",
",",
"arg0",
")",
"\n",
"}"
] | // Watch indicates an expected call of Watch | [
"Watch",
"indicates",
"an",
"expected",
"call",
"of",
"Watch"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/appv1_mock.go#L253-L255 |
154,152 | juju/juju | caas/kubernetes/provider/mocks/appv1_mock.go | NewMockStatefulSetInterface | func NewMockStatefulSetInterface(ctrl *gomock.Controller) *MockStatefulSetInterface {
mock := &MockStatefulSetInterface{ctrl: ctrl}
mock.recorder = &MockStatefulSetInterfaceMockRecorder{mock}
return mock
} | go | func NewMockStatefulSetInterface(ctrl *gomock.Controller) *MockStatefulSetInterface {
mock := &MockStatefulSetInterface{ctrl: ctrl}
mock.recorder = &MockStatefulSetInterfaceMockRecorder{mock}
return mock
} | [
"func",
"NewMockStatefulSetInterface",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockStatefulSetInterface",
"{",
"mock",
":=",
"&",
"MockStatefulSetInterface",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockStatefulSetInterfaceMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockStatefulSetInterface creates a new mock instance | [
"NewMockStatefulSetInterface",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/appv1_mock.go#L269-L273 |
154,153 | juju/juju | rpc/rpcreflect/value.go | ValueOf | func ValueOf(rootValue reflect.Value) Value {
if !rootValue.IsValid() {
return Value{}
}
return Value{
rootValue: rootValue,
rootType: TypeOf(rootValue.Type()),
}
} | go | func ValueOf(rootValue reflect.Value) Value {
if !rootValue.IsValid() {
return Value{}
}
return Value{
rootValue: rootValue,
rootType: TypeOf(rootValue.Type()),
}
} | [
"func",
"ValueOf",
"(",
"rootValue",
"reflect",
".",
"Value",
")",
"Value",
"{",
"if",
"!",
"rootValue",
".",
"IsValid",
"(",
")",
"{",
"return",
"Value",
"{",
"}",
"\n",
"}",
"\n",
"return",
"Value",
"{",
"rootValue",
":",
"rootValue",
",",
"rootType",
":",
"TypeOf",
"(",
"rootValue",
".",
"Type",
"(",
")",
")",
",",
"}",
"\n",
"}"
] | // ValueOf returns a value that can be used to call RPC-style
// methods on the given root value. It returns the zero
// Value if rootValue.IsValid is false. | [
"ValueOf",
"returns",
"a",
"value",
"that",
"can",
"be",
"used",
"to",
"call",
"RPC",
"-",
"style",
"methods",
"on",
"the",
"given",
"root",
"value",
".",
"It",
"returns",
"the",
"zero",
"Value",
"if",
"rootValue",
".",
"IsValid",
"is",
"false",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/rpc/rpcreflect/value.go#L56-L64 |
154,154 | juju/juju | rpc/rpcreflect/value.go | FindMethod | func (v Value) FindMethod(rootMethodName string, version int, objMethodName string) (MethodCaller, error) {
if !v.IsValid() {
panic("FindMethod called on invalid Value")
}
caller := methodCaller{
rootValue: v.rootValue,
}
var err error
caller.rootMethod, err = v.rootType.Method(rootMethodName)
if err != nil {
return nil, &CallNotImplementedError{
RootMethod: rootMethodName,
}
}
caller.objMethod, err = caller.rootMethod.ObjType.Method(objMethodName)
if err != nil {
return nil, &CallNotImplementedError{
RootMethod: rootMethodName,
Method: objMethodName,
}
}
return caller, nil
} | go | func (v Value) FindMethod(rootMethodName string, version int, objMethodName string) (MethodCaller, error) {
if !v.IsValid() {
panic("FindMethod called on invalid Value")
}
caller := methodCaller{
rootValue: v.rootValue,
}
var err error
caller.rootMethod, err = v.rootType.Method(rootMethodName)
if err != nil {
return nil, &CallNotImplementedError{
RootMethod: rootMethodName,
}
}
caller.objMethod, err = caller.rootMethod.ObjType.Method(objMethodName)
if err != nil {
return nil, &CallNotImplementedError{
RootMethod: rootMethodName,
Method: objMethodName,
}
}
return caller, nil
} | [
"func",
"(",
"v",
"Value",
")",
"FindMethod",
"(",
"rootMethodName",
"string",
",",
"version",
"int",
",",
"objMethodName",
"string",
")",
"(",
"MethodCaller",
",",
"error",
")",
"{",
"if",
"!",
"v",
".",
"IsValid",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"caller",
":=",
"methodCaller",
"{",
"rootValue",
":",
"v",
".",
"rootValue",
",",
"}",
"\n",
"var",
"err",
"error",
"\n",
"caller",
".",
"rootMethod",
",",
"err",
"=",
"v",
".",
"rootType",
".",
"Method",
"(",
"rootMethodName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"CallNotImplementedError",
"{",
"RootMethod",
":",
"rootMethodName",
",",
"}",
"\n",
"}",
"\n",
"caller",
".",
"objMethod",
",",
"err",
"=",
"caller",
".",
"rootMethod",
".",
"ObjType",
".",
"Method",
"(",
"objMethodName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"CallNotImplementedError",
"{",
"RootMethod",
":",
"rootMethodName",
",",
"Method",
":",
"objMethodName",
",",
"}",
"\n",
"}",
"\n",
"return",
"caller",
",",
"nil",
"\n",
"}"
] | // FindMethod returns an object that can be used to make calls on
// the given root value to the given root method and object method.
// It returns an error if either the root method or the object
// method were not found.
// It panics if called on the zero Value.
// The version argument is ignored - all versions will find
// the same method. | [
"FindMethod",
"returns",
"an",
"object",
"that",
"can",
"be",
"used",
"to",
"make",
"calls",
"on",
"the",
"given",
"root",
"value",
"to",
"the",
"given",
"root",
"method",
"and",
"object",
"method",
".",
"It",
"returns",
"an",
"error",
"if",
"either",
"the",
"root",
"method",
"or",
"the",
"object",
"method",
"were",
"not",
"found",
".",
"It",
"panics",
"if",
"called",
"on",
"the",
"zero",
"Value",
".",
"The",
"version",
"argument",
"is",
"ignored",
"-",
"all",
"versions",
"will",
"find",
"the",
"same",
"method",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/rpc/rpcreflect/value.go#L83-L105 |
154,155 | juju/juju | rpc/rpcreflect/value.go | Kill | func (v Value) Kill() {
if killer, ok := v.rootValue.Interface().(killer); ok {
killer.Kill()
}
} | go | func (v Value) Kill() {
if killer, ok := v.rootValue.Interface().(killer); ok {
killer.Kill()
}
} | [
"func",
"(",
"v",
"Value",
")",
"Kill",
"(",
")",
"{",
"if",
"killer",
",",
"ok",
":=",
"v",
".",
"rootValue",
".",
"Interface",
"(",
")",
".",
"(",
"killer",
")",
";",
"ok",
"{",
"killer",
".",
"Kill",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Kill implements rpc.Killer.Kill by calling Kill on the root
// value if it implements Killer. | [
"Kill",
"implements",
"rpc",
".",
"Killer",
".",
"Kill",
"by",
"calling",
"Kill",
"on",
"the",
"root",
"value",
"if",
"it",
"implements",
"Killer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/rpc/rpcreflect/value.go#L115-L119 |
154,156 | juju/juju | worker/uniter/agent.go | setAgentStatus | func setAgentStatus(u *Uniter, agentStatus status.Status, info string, data map[string]interface{}) error {
u.setStatusMutex.Lock()
defer u.setStatusMutex.Unlock()
if u.lastReportedStatus == agentStatus && u.lastReportedMessage == info {
return nil
}
u.lastReportedStatus = agentStatus
u.lastReportedMessage = info
logger.Debugf("[AGENT-STATUS] %s: %s", agentStatus, info)
return u.unit.SetAgentStatus(agentStatus, info, data)
} | go | func setAgentStatus(u *Uniter, agentStatus status.Status, info string, data map[string]interface{}) error {
u.setStatusMutex.Lock()
defer u.setStatusMutex.Unlock()
if u.lastReportedStatus == agentStatus && u.lastReportedMessage == info {
return nil
}
u.lastReportedStatus = agentStatus
u.lastReportedMessage = info
logger.Debugf("[AGENT-STATUS] %s: %s", agentStatus, info)
return u.unit.SetAgentStatus(agentStatus, info, data)
} | [
"func",
"setAgentStatus",
"(",
"u",
"*",
"Uniter",
",",
"agentStatus",
"status",
".",
"Status",
",",
"info",
"string",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"u",
".",
"setStatusMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"setStatusMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"u",
".",
"lastReportedStatus",
"==",
"agentStatus",
"&&",
"u",
".",
"lastReportedMessage",
"==",
"info",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"u",
".",
"lastReportedStatus",
"=",
"agentStatus",
"\n",
"u",
".",
"lastReportedMessage",
"=",
"info",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"agentStatus",
",",
"info",
")",
"\n",
"return",
"u",
".",
"unit",
".",
"SetAgentStatus",
"(",
"agentStatus",
",",
"info",
",",
"data",
")",
"\n",
"}"
] | // setAgentStatus sets the unit's status if it has changed since last time this method was called. | [
"setAgentStatus",
"sets",
"the",
"unit",
"s",
"status",
"if",
"it",
"has",
"changed",
"since",
"last",
"time",
"this",
"method",
"was",
"called",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/agent.go#L12-L22 |
154,157 | juju/juju | worker/uniter/agent.go | reportAgentError | func reportAgentError(u *Uniter, userMessage string, err error) {
// If a non-nil error is reported (e.g. due to an operation failing),
// set the agent status to Failed.
if err == nil {
return
}
logger.Errorf("%s: %v", userMessage, err)
err2 := setAgentStatus(u, status.Failed, userMessage, nil)
if err2 != nil {
logger.Errorf("updating agent status: %v", err2)
}
} | go | func reportAgentError(u *Uniter, userMessage string, err error) {
// If a non-nil error is reported (e.g. due to an operation failing),
// set the agent status to Failed.
if err == nil {
return
}
logger.Errorf("%s: %v", userMessage, err)
err2 := setAgentStatus(u, status.Failed, userMessage, nil)
if err2 != nil {
logger.Errorf("updating agent status: %v", err2)
}
} | [
"func",
"reportAgentError",
"(",
"u",
"*",
"Uniter",
",",
"userMessage",
"string",
",",
"err",
"error",
")",
"{",
"// If a non-nil error is reported (e.g. due to an operation failing),",
"// set the agent status to Failed.",
"if",
"err",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"userMessage",
",",
"err",
")",
"\n",
"err2",
":=",
"setAgentStatus",
"(",
"u",
",",
"status",
".",
"Failed",
",",
"userMessage",
",",
"nil",
")",
"\n",
"if",
"err2",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err2",
")",
"\n",
"}",
"\n",
"}"
] | // reportAgentError reports if there was an error performing an agent operation. | [
"reportAgentError",
"reports",
"if",
"there",
"was",
"an",
"error",
"performing",
"an",
"agent",
"operation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/agent.go#L25-L36 |
154,158 | juju/juju | worker/uniter/agent.go | setUpgradeSeriesStatus | func setUpgradeSeriesStatus(u *Uniter, status model.UpgradeSeriesStatus, reason string) error {
return u.unit.SetUpgradeSeriesStatus(status, reason)
} | go | func setUpgradeSeriesStatus(u *Uniter, status model.UpgradeSeriesStatus, reason string) error {
return u.unit.SetUpgradeSeriesStatus(status, reason)
} | [
"func",
"setUpgradeSeriesStatus",
"(",
"u",
"*",
"Uniter",
",",
"status",
"model",
".",
"UpgradeSeriesStatus",
",",
"reason",
"string",
")",
"error",
"{",
"return",
"u",
".",
"unit",
".",
"SetUpgradeSeriesStatus",
"(",
"status",
",",
"reason",
")",
"\n",
"}"
] | // setUpgradeSeriesStatus sets the upgrade series status. | [
"setUpgradeSeriesStatus",
"sets",
"the",
"upgrade",
"series",
"status",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/agent.go#L39-L41 |
154,159 | juju/juju | caas/kubernetes/provider/k8stypes.go | parseK8sPodSpec | func parseK8sPodSpec(in string) (*caas.PodSpec, error) {
// Do the common fields.
var spec caas.PodSpec
if err := yaml.Unmarshal([]byte(in), &spec); err != nil {
return nil, errors.Trace(err)
}
// Do the k8s pod attributes.
var pod k8sPod
decoder := k8syaml.NewYAMLOrJSONDecoder(strings.NewReader(in), len(in))
if err := decoder.Decode(&pod); err != nil {
return nil, errors.Trace(err)
}
if pod.K8sPodSpec != nil {
spec.ProviderPod = pod.K8sPodSpec
}
// Do the k8s containers.
var containers k8sContainers
decoder = k8syaml.NewYAMLOrJSONDecoder(strings.NewReader(in), len(in))
if err := decoder.Decode(&containers); err != nil {
return nil, errors.Trace(err)
}
if len(containers.Containers) == 0 {
return nil, errors.New("require at least one container spec")
}
quoteBoolStrings(containers.Containers)
quoteBoolStrings(containers.InitContainers)
// Compose the result.
spec.Containers = make([]caas.ContainerSpec, len(containers.Containers))
for i, c := range containers.Containers {
if err := c.Validate(); err != nil {
return nil, errors.Trace(err)
}
spec.Containers[i] = containerFromK8sSpec(c)
}
spec.InitContainers = make([]caas.ContainerSpec, len(containers.InitContainers))
for i, c := range containers.InitContainers {
if err := c.Validate(); err != nil {
return nil, errors.Trace(err)
}
spec.InitContainers[i] = containerFromK8sSpec(c)
}
spec.CustomResourceDefinitions = containers.CustomResourceDefinitions
return &spec, nil
} | go | func parseK8sPodSpec(in string) (*caas.PodSpec, error) {
// Do the common fields.
var spec caas.PodSpec
if err := yaml.Unmarshal([]byte(in), &spec); err != nil {
return nil, errors.Trace(err)
}
// Do the k8s pod attributes.
var pod k8sPod
decoder := k8syaml.NewYAMLOrJSONDecoder(strings.NewReader(in), len(in))
if err := decoder.Decode(&pod); err != nil {
return nil, errors.Trace(err)
}
if pod.K8sPodSpec != nil {
spec.ProviderPod = pod.K8sPodSpec
}
// Do the k8s containers.
var containers k8sContainers
decoder = k8syaml.NewYAMLOrJSONDecoder(strings.NewReader(in), len(in))
if err := decoder.Decode(&containers); err != nil {
return nil, errors.Trace(err)
}
if len(containers.Containers) == 0 {
return nil, errors.New("require at least one container spec")
}
quoteBoolStrings(containers.Containers)
quoteBoolStrings(containers.InitContainers)
// Compose the result.
spec.Containers = make([]caas.ContainerSpec, len(containers.Containers))
for i, c := range containers.Containers {
if err := c.Validate(); err != nil {
return nil, errors.Trace(err)
}
spec.Containers[i] = containerFromK8sSpec(c)
}
spec.InitContainers = make([]caas.ContainerSpec, len(containers.InitContainers))
for i, c := range containers.InitContainers {
if err := c.Validate(); err != nil {
return nil, errors.Trace(err)
}
spec.InitContainers[i] = containerFromK8sSpec(c)
}
spec.CustomResourceDefinitions = containers.CustomResourceDefinitions
return &spec, nil
} | [
"func",
"parseK8sPodSpec",
"(",
"in",
"string",
")",
"(",
"*",
"caas",
".",
"PodSpec",
",",
"error",
")",
"{",
"// Do the common fields.",
"var",
"spec",
"caas",
".",
"PodSpec",
"\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"in",
")",
",",
"&",
"spec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Do the k8s pod attributes.",
"var",
"pod",
"k8sPod",
"\n",
"decoder",
":=",
"k8syaml",
".",
"NewYAMLOrJSONDecoder",
"(",
"strings",
".",
"NewReader",
"(",
"in",
")",
",",
"len",
"(",
"in",
")",
")",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"pod",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"pod",
".",
"K8sPodSpec",
"!=",
"nil",
"{",
"spec",
".",
"ProviderPod",
"=",
"pod",
".",
"K8sPodSpec",
"\n",
"}",
"\n\n",
"// Do the k8s containers.",
"var",
"containers",
"k8sContainers",
"\n",
"decoder",
"=",
"k8syaml",
".",
"NewYAMLOrJSONDecoder",
"(",
"strings",
".",
"NewReader",
"(",
"in",
")",
",",
"len",
"(",
"in",
")",
")",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"containers",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"containers",
".",
"Containers",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"quoteBoolStrings",
"(",
"containers",
".",
"Containers",
")",
"\n",
"quoteBoolStrings",
"(",
"containers",
".",
"InitContainers",
")",
"\n\n",
"// Compose the result.",
"spec",
".",
"Containers",
"=",
"make",
"(",
"[",
"]",
"caas",
".",
"ContainerSpec",
",",
"len",
"(",
"containers",
".",
"Containers",
")",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"containers",
".",
"Containers",
"{",
"if",
"err",
":=",
"c",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"spec",
".",
"Containers",
"[",
"i",
"]",
"=",
"containerFromK8sSpec",
"(",
"c",
")",
"\n",
"}",
"\n",
"spec",
".",
"InitContainers",
"=",
"make",
"(",
"[",
"]",
"caas",
".",
"ContainerSpec",
",",
"len",
"(",
"containers",
".",
"InitContainers",
")",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"containers",
".",
"InitContainers",
"{",
"if",
"err",
":=",
"c",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"spec",
".",
"InitContainers",
"[",
"i",
"]",
"=",
"containerFromK8sSpec",
"(",
"c",
")",
"\n",
"}",
"\n",
"spec",
".",
"CustomResourceDefinitions",
"=",
"containers",
".",
"CustomResourceDefinitions",
"\n",
"return",
"&",
"spec",
",",
"nil",
"\n",
"}"
] | // parseK8sPodSpec parses a YAML file which defines how to
// configure a CAAS pod. We allow for generic container
// set up plus k8s select specific features. | [
"parseK8sPodSpec",
"parses",
"a",
"YAML",
"file",
"which",
"defines",
"how",
"to",
"configure",
"a",
"CAAS",
"pod",
".",
"We",
"allow",
"for",
"generic",
"container",
"set",
"up",
"plus",
"k8s",
"select",
"specific",
"features",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/k8stypes.go#L90-L137 |
154,160 | juju/juju | worker/toolsversionchecker/manifold.go | Manifold | func Manifold(config ManifoldConfig) dependency.Manifold {
typedConfig := engine.AgentAPIManifoldConfig(config)
return engine.AgentAPIManifold(typedConfig, newWorker)
} | go | func Manifold(config ManifoldConfig) dependency.Manifold {
typedConfig := engine.AgentAPIManifoldConfig(config)
return engine.AgentAPIManifold(typedConfig, newWorker)
} | [
"func",
"Manifold",
"(",
"config",
"ManifoldConfig",
")",
"dependency",
".",
"Manifold",
"{",
"typedConfig",
":=",
"engine",
".",
"AgentAPIManifoldConfig",
"(",
"config",
")",
"\n",
"return",
"engine",
".",
"AgentAPIManifold",
"(",
"typedConfig",
",",
"newWorker",
")",
"\n",
"}"
] | // Manifold returns a dependency manifold that runs a toolsversionchecker worker,
// using the api connection resource named in the supplied config. | [
"Manifold",
"returns",
"a",
"dependency",
"manifold",
"that",
"runs",
"a",
"toolsversionchecker",
"worker",
"using",
"the",
"api",
"connection",
"resource",
"named",
"in",
"the",
"supplied",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/toolsversionchecker/manifold.go#L27-L30 |
154,161 | juju/juju | state/annotations.go | Annotations | func (m *Model) Annotations(entity GlobalEntity) (map[string]string, error) {
doc := new(annotatorDoc)
annotations, closer := m.st.db().GetCollection(annotationsC)
defer closer()
err := annotations.FindId(entity.globalKey()).One(doc)
if err == mgo.ErrNotFound {
// Returning an empty map if there are no annotations.
return make(map[string]string), nil
}
if err != nil {
return nil, errors.Trace(err)
}
return doc.Annotations, nil
} | go | func (m *Model) Annotations(entity GlobalEntity) (map[string]string, error) {
doc := new(annotatorDoc)
annotations, closer := m.st.db().GetCollection(annotationsC)
defer closer()
err := annotations.FindId(entity.globalKey()).One(doc)
if err == mgo.ErrNotFound {
// Returning an empty map if there are no annotations.
return make(map[string]string), nil
}
if err != nil {
return nil, errors.Trace(err)
}
return doc.Annotations, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Annotations",
"(",
"entity",
"GlobalEntity",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"doc",
":=",
"new",
"(",
"annotatorDoc",
")",
"\n",
"annotations",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"annotationsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"err",
":=",
"annotations",
".",
"FindId",
"(",
"entity",
".",
"globalKey",
"(",
")",
")",
".",
"One",
"(",
"doc",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"// Returning an empty map if there are no annotations.",
"return",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"doc",
".",
"Annotations",
",",
"nil",
"\n",
"}"
] | // Annotations returns all the annotations corresponding to an entity. | [
"Annotations",
"returns",
"all",
"the",
"annotations",
"corresponding",
"to",
"an",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/annotations.go#L74-L87 |
154,162 | juju/juju | state/annotations.go | Annotation | func (m *Model) Annotation(entity GlobalEntity, key string) (string, error) {
ann, err := m.Annotations(entity)
if err != nil {
return "", errors.Trace(err)
}
return ann[key], nil
} | go | func (m *Model) Annotation(entity GlobalEntity, key string) (string, error) {
ann, err := m.Annotations(entity)
if err != nil {
return "", errors.Trace(err)
}
return ann[key], nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Annotation",
"(",
"entity",
"GlobalEntity",
",",
"key",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"ann",
",",
"err",
":=",
"m",
".",
"Annotations",
"(",
"entity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ann",
"[",
"key",
"]",
",",
"nil",
"\n",
"}"
] | // Annotation returns the annotation value corresponding to the given key.
// If the requested annotation is not found, an empty string is returned. | [
"Annotation",
"returns",
"the",
"annotation",
"value",
"corresponding",
"to",
"the",
"given",
"key",
".",
"If",
"the",
"requested",
"annotation",
"is",
"not",
"found",
"an",
"empty",
"string",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/annotations.go#L91-L97 |
154,163 | juju/juju | state/annotations.go | insertAnnotationsOps | func insertAnnotationsOps(st *State, entity GlobalEntity, toInsert map[string]string) ([]txn.Op, error) {
tag := entity.Tag()
ops := []txn.Op{{
C: annotationsC,
Id: st.docID(entity.globalKey()),
Assert: txn.DocMissing,
Insert: &annotatorDoc{
GlobalKey: entity.globalKey(),
Tag: tag.String(),
Annotations: toInsert,
},
}}
switch tag := tag.(type) {
case names.ModelTag:
if tag.Id() == st.ControllerModelUUID() {
// This is the controller model, and cannot be removed.
// Ergo, we can skip the existence check below.
return ops, nil
}
}
// If the entity is not the controller model, add a DocExists check on the
// entity document, in order to avoid possible races between entity
// removal and annotation creation.
coll, id, err := st.tagToCollectionAndId(tag)
if err != nil {
return nil, errors.Trace(err)
}
return append(ops, txn.Op{
C: coll,
Id: id,
Assert: txn.DocExists,
}), nil
} | go | func insertAnnotationsOps(st *State, entity GlobalEntity, toInsert map[string]string) ([]txn.Op, error) {
tag := entity.Tag()
ops := []txn.Op{{
C: annotationsC,
Id: st.docID(entity.globalKey()),
Assert: txn.DocMissing,
Insert: &annotatorDoc{
GlobalKey: entity.globalKey(),
Tag: tag.String(),
Annotations: toInsert,
},
}}
switch tag := tag.(type) {
case names.ModelTag:
if tag.Id() == st.ControllerModelUUID() {
// This is the controller model, and cannot be removed.
// Ergo, we can skip the existence check below.
return ops, nil
}
}
// If the entity is not the controller model, add a DocExists check on the
// entity document, in order to avoid possible races between entity
// removal and annotation creation.
coll, id, err := st.tagToCollectionAndId(tag)
if err != nil {
return nil, errors.Trace(err)
}
return append(ops, txn.Op{
C: coll,
Id: id,
Assert: txn.DocExists,
}), nil
} | [
"func",
"insertAnnotationsOps",
"(",
"st",
"*",
"State",
",",
"entity",
"GlobalEntity",
",",
"toInsert",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"tag",
":=",
"entity",
".",
"Tag",
"(",
")",
"\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"annotationsC",
",",
"Id",
":",
"st",
".",
"docID",
"(",
"entity",
".",
"globalKey",
"(",
")",
")",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"&",
"annotatorDoc",
"{",
"GlobalKey",
":",
"entity",
".",
"globalKey",
"(",
")",
",",
"Tag",
":",
"tag",
".",
"String",
"(",
")",
",",
"Annotations",
":",
"toInsert",
",",
"}",
",",
"}",
"}",
"\n\n",
"switch",
"tag",
":=",
"tag",
".",
"(",
"type",
")",
"{",
"case",
"names",
".",
"ModelTag",
":",
"if",
"tag",
".",
"Id",
"(",
")",
"==",
"st",
".",
"ControllerModelUUID",
"(",
")",
"{",
"// This is the controller model, and cannot be removed.",
"// Ergo, we can skip the existence check below.",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If the entity is not the controller model, add a DocExists check on the",
"// entity document, in order to avoid possible races between entity",
"// removal and annotation creation.",
"coll",
",",
"id",
",",
"err",
":=",
"st",
".",
"tagToCollectionAndId",
"(",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"append",
"(",
"ops",
",",
"txn",
".",
"Op",
"{",
"C",
":",
"coll",
",",
"Id",
":",
"id",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"}",
")",
",",
"nil",
"\n",
"}"
] | // insertAnnotationsOps returns the operations required to insert annotations in MongoDB. | [
"insertAnnotationsOps",
"returns",
"the",
"operations",
"required",
"to",
"insert",
"annotations",
"in",
"MongoDB",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/annotations.go#L100-L134 |
154,164 | juju/juju | state/annotations.go | updateAnnotations | func updateAnnotations(mb modelBackend, entity GlobalEntity, toUpdate, toRemove bson.M) []txn.Op {
return []txn.Op{{
C: annotationsC,
Id: mb.docID(entity.globalKey()),
Assert: txn.DocExists,
Update: setUnsetUpdateAnnotations(toUpdate, toRemove),
}}
} | go | func updateAnnotations(mb modelBackend, entity GlobalEntity, toUpdate, toRemove bson.M) []txn.Op {
return []txn.Op{{
C: annotationsC,
Id: mb.docID(entity.globalKey()),
Assert: txn.DocExists,
Update: setUnsetUpdateAnnotations(toUpdate, toRemove),
}}
} | [
"func",
"updateAnnotations",
"(",
"mb",
"modelBackend",
",",
"entity",
"GlobalEntity",
",",
"toUpdate",
",",
"toRemove",
"bson",
".",
"M",
")",
"[",
"]",
"txn",
".",
"Op",
"{",
"return",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"annotationsC",
",",
"Id",
":",
"mb",
".",
"docID",
"(",
"entity",
".",
"globalKey",
"(",
")",
")",
",",
"Assert",
":",
"txn",
".",
"DocExists",
",",
"Update",
":",
"setUnsetUpdateAnnotations",
"(",
"toUpdate",
",",
"toRemove",
")",
",",
"}",
"}",
"\n",
"}"
] | // updateAnnotations returns the operations required to update or remove annotations in MongoDB. | [
"updateAnnotations",
"returns",
"the",
"operations",
"required",
"to",
"update",
"or",
"remove",
"annotations",
"in",
"MongoDB",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/annotations.go#L137-L144 |
154,165 | juju/juju | state/annotations.go | annotationRemoveOp | func annotationRemoveOp(mb modelBackend, id string) txn.Op {
return txn.Op{
C: annotationsC,
Id: mb.docID(id),
Remove: true,
}
} | go | func annotationRemoveOp(mb modelBackend, id string) txn.Op {
return txn.Op{
C: annotationsC,
Id: mb.docID(id),
Remove: true,
}
} | [
"func",
"annotationRemoveOp",
"(",
"mb",
"modelBackend",
",",
"id",
"string",
")",
"txn",
".",
"Op",
"{",
"return",
"txn",
".",
"Op",
"{",
"C",
":",
"annotationsC",
",",
"Id",
":",
"mb",
".",
"docID",
"(",
"id",
")",
",",
"Remove",
":",
"true",
",",
"}",
"\n",
"}"
] | // annotationRemoveOp returns an operation to remove a given annotation
// document from MongoDB. | [
"annotationRemoveOp",
"returns",
"an",
"operation",
"to",
"remove",
"a",
"given",
"annotation",
"document",
"from",
"MongoDB",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/annotations.go#L148-L154 |
154,166 | juju/juju | apiserver/facades/client/application/application.go | NewFacadeV4 | func NewFacadeV4(ctx facade.Context) (*APIv4, error) {
api, err := NewFacadeV5(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv4{api}, nil
} | go | func NewFacadeV4(ctx facade.Context) (*APIv4, error) {
api, err := NewFacadeV5(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv4{api}, nil
} | [
"func",
"NewFacadeV4",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"APIv4",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"NewFacadeV5",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"APIv4",
"{",
"api",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacadeV4 provides the signature required for facade registration
// for versions 1-4. | [
"NewFacadeV4",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"for",
"versions",
"1",
"-",
"4",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L111-L117 |
154,167 | juju/juju | apiserver/facades/client/application/application.go | NewFacadeV5 | func NewFacadeV5(ctx facade.Context) (*APIv5, error) {
api, err := NewFacadeV6(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv5{api}, nil
} | go | func NewFacadeV5(ctx facade.Context) (*APIv5, error) {
api, err := NewFacadeV6(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv5{api}, nil
} | [
"func",
"NewFacadeV5",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"APIv5",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"NewFacadeV6",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"APIv5",
"{",
"api",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacadeV5 provides the signature required for facade registration
// for version 5. | [
"NewFacadeV5",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"for",
"version",
"5",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L121-L127 |
154,168 | juju/juju | apiserver/facades/client/application/application.go | NewFacadeV6 | func NewFacadeV6(ctx facade.Context) (*APIv6, error) {
api, err := NewFacadeV7(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv6{api}, nil
} | go | func NewFacadeV6(ctx facade.Context) (*APIv6, error) {
api, err := NewFacadeV7(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv6{api}, nil
} | [
"func",
"NewFacadeV6",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"APIv6",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"NewFacadeV7",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"APIv6",
"{",
"api",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacadeV6 provides the signature required for facade registration
// for version 6. | [
"NewFacadeV6",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"for",
"version",
"6",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L131-L137 |
154,169 | juju/juju | apiserver/facades/client/application/application.go | NewFacadeV7 | func NewFacadeV7(ctx facade.Context) (*APIv7, error) {
api, err := NewFacadeV8(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv7{api}, nil
} | go | func NewFacadeV7(ctx facade.Context) (*APIv7, error) {
api, err := NewFacadeV8(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv7{api}, nil
} | [
"func",
"NewFacadeV7",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"APIv7",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"NewFacadeV8",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"APIv7",
"{",
"api",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacadeV7 provides the signature required for facade registration
// for version 7. | [
"NewFacadeV7",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"for",
"version",
"7",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L141-L147 |
154,170 | juju/juju | apiserver/facades/client/application/application.go | NewFacadeV8 | func NewFacadeV8(ctx facade.Context) (*APIv8, error) {
api, err := NewFacadeV9(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv8{api}, nil
} | go | func NewFacadeV8(ctx facade.Context) (*APIv8, error) {
api, err := NewFacadeV9(ctx)
if err != nil {
return nil, errors.Trace(err)
}
return &APIv8{api}, nil
} | [
"func",
"NewFacadeV8",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"APIv8",
",",
"error",
")",
"{",
"api",
",",
"err",
":=",
"NewFacadeV9",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"APIv8",
"{",
"api",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacadeV8 provides the signature required for facade registration
// for version 8. | [
"NewFacadeV8",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"for",
"version",
"8",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L151-L157 |
154,171 | juju/juju | apiserver/facades/client/application/application.go | NewAPIBase | func NewAPIBase(
backend Backend,
storageAccess storageInterface,
authorizer facade.Authorizer,
blockChecker BlockChecker,
model Model,
stateCharm func(Charm) *state.Charm,
deployApplication func(ApplicationDeployer, DeployApplicationParams) (Application, error),
storagePoolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
resources facade.Resources,
storageValidator caas.StorageValidator,
) (*APIBase, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &APIBase{
backend: backend,
storageAccess: storageAccess,
authorizer: authorizer,
check: blockChecker,
model: model,
modelType: model.Type(),
stateCharm: stateCharm,
deployApplicationFunc: deployApplication,
storagePoolManager: storagePoolManager,
registry: registry,
resources: resources,
storageValidator: storageValidator,
}, nil
} | go | func NewAPIBase(
backend Backend,
storageAccess storageInterface,
authorizer facade.Authorizer,
blockChecker BlockChecker,
model Model,
stateCharm func(Charm) *state.Charm,
deployApplication func(ApplicationDeployer, DeployApplicationParams) (Application, error),
storagePoolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
resources facade.Resources,
storageValidator caas.StorageValidator,
) (*APIBase, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
return &APIBase{
backend: backend,
storageAccess: storageAccess,
authorizer: authorizer,
check: blockChecker,
model: model,
modelType: model.Type(),
stateCharm: stateCharm,
deployApplicationFunc: deployApplication,
storagePoolManager: storagePoolManager,
registry: registry,
resources: resources,
storageValidator: storageValidator,
}, nil
} | [
"func",
"NewAPIBase",
"(",
"backend",
"Backend",
",",
"storageAccess",
"storageInterface",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
"blockChecker",
"BlockChecker",
",",
"model",
"Model",
",",
"stateCharm",
"func",
"(",
"Charm",
")",
"*",
"state",
".",
"Charm",
",",
"deployApplication",
"func",
"(",
"ApplicationDeployer",
",",
"DeployApplicationParams",
")",
"(",
"Application",
",",
"error",
")",
",",
"storagePoolManager",
"poolmanager",
".",
"PoolManager",
",",
"registry",
"storage",
".",
"ProviderRegistry",
",",
"resources",
"facade",
".",
"Resources",
",",
"storageValidator",
"caas",
".",
"StorageValidator",
",",
")",
"(",
"*",
"APIBase",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthClient",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"APIBase",
"{",
"backend",
":",
"backend",
",",
"storageAccess",
":",
"storageAccess",
",",
"authorizer",
":",
"authorizer",
",",
"check",
":",
"blockChecker",
",",
"model",
":",
"model",
",",
"modelType",
":",
"model",
".",
"Type",
"(",
")",
",",
"stateCharm",
":",
"stateCharm",
",",
"deployApplicationFunc",
":",
"deployApplication",
",",
"storagePoolManager",
":",
"storagePoolManager",
",",
"registry",
":",
"registry",
",",
"resources",
":",
"resources",
",",
"storageValidator",
":",
"storageValidator",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewAPIBase returns a new application API facade. | [
"NewAPIBase",
"returns",
"a",
"new",
"application",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L211-L241 |
154,172 | juju/juju | apiserver/facades/client/application/application.go | SetMetricCredentials | func (api *APIBase) SetMetricCredentials(args params.ApplicationMetricCredentials) (params.ErrorResults, error) {
if err := api.checkCanWrite(); err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Creds)),
}
if len(args.Creds) == 0 {
return result, nil
}
for i, a := range args.Creds {
application, err := api.backend.Application(a.ApplicationName)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
err = application.SetMetricCredentials(a.MetricCredentials)
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
} | go | func (api *APIBase) SetMetricCredentials(args params.ApplicationMetricCredentials) (params.ErrorResults, error) {
if err := api.checkCanWrite(); err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Creds)),
}
if len(args.Creds) == 0 {
return result, nil
}
for i, a := range args.Creds {
application, err := api.backend.Application(a.ApplicationName)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
err = application.SetMetricCredentials(a.MetricCredentials)
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"SetMetricCredentials",
"(",
"args",
"params",
".",
"ApplicationMetricCredentials",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Creds",
")",
")",
",",
"}",
"\n",
"if",
"len",
"(",
"args",
".",
"Creds",
")",
"==",
"0",
"{",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n",
"for",
"i",
",",
"a",
":=",
"range",
"args",
".",
"Creds",
"{",
"application",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"a",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"err",
"=",
"application",
".",
"SetMetricCredentials",
"(",
"a",
".",
"MetricCredentials",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetMetricCredentials sets credentials on the application. | [
"SetMetricCredentials",
"sets",
"credentials",
"on",
"the",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L263-L285 |
154,173 | juju/juju | apiserver/facades/client/application/application.go | Deploy | func (api *APIv5) Deploy(args params.ApplicationsDeployV5) (params.ErrorResults, error) {
noDefinedPolicy := ""
var newArgs params.ApplicationsDeploy
for _, value := range args.Applications {
newArgs.Applications = append(newArgs.Applications, params.ApplicationDeploy{
ApplicationName: value.ApplicationName,
Series: value.Series,
CharmURL: value.CharmURL,
Channel: value.Channel,
NumUnits: value.NumUnits,
Config: value.Config,
ConfigYAML: value.ConfigYAML,
Constraints: value.Constraints,
Placement: value.Placement,
Policy: noDefinedPolicy,
Storage: value.Storage,
AttachStorage: value.AttachStorage,
EndpointBindings: value.EndpointBindings,
Resources: value.Resources,
})
}
return api.APIBase.Deploy(newArgs)
} | go | func (api *APIv5) Deploy(args params.ApplicationsDeployV5) (params.ErrorResults, error) {
noDefinedPolicy := ""
var newArgs params.ApplicationsDeploy
for _, value := range args.Applications {
newArgs.Applications = append(newArgs.Applications, params.ApplicationDeploy{
ApplicationName: value.ApplicationName,
Series: value.Series,
CharmURL: value.CharmURL,
Channel: value.Channel,
NumUnits: value.NumUnits,
Config: value.Config,
ConfigYAML: value.ConfigYAML,
Constraints: value.Constraints,
Placement: value.Placement,
Policy: noDefinedPolicy,
Storage: value.Storage,
AttachStorage: value.AttachStorage,
EndpointBindings: value.EndpointBindings,
Resources: value.Resources,
})
}
return api.APIBase.Deploy(newArgs)
} | [
"func",
"(",
"api",
"*",
"APIv5",
")",
"Deploy",
"(",
"args",
"params",
".",
"ApplicationsDeployV5",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"noDefinedPolicy",
":=",
"\"",
"\"",
"\n",
"var",
"newArgs",
"params",
".",
"ApplicationsDeploy",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"args",
".",
"Applications",
"{",
"newArgs",
".",
"Applications",
"=",
"append",
"(",
"newArgs",
".",
"Applications",
",",
"params",
".",
"ApplicationDeploy",
"{",
"ApplicationName",
":",
"value",
".",
"ApplicationName",
",",
"Series",
":",
"value",
".",
"Series",
",",
"CharmURL",
":",
"value",
".",
"CharmURL",
",",
"Channel",
":",
"value",
".",
"Channel",
",",
"NumUnits",
":",
"value",
".",
"NumUnits",
",",
"Config",
":",
"value",
".",
"Config",
",",
"ConfigYAML",
":",
"value",
".",
"ConfigYAML",
",",
"Constraints",
":",
"value",
".",
"Constraints",
",",
"Placement",
":",
"value",
".",
"Placement",
",",
"Policy",
":",
"noDefinedPolicy",
",",
"Storage",
":",
"value",
".",
"Storage",
",",
"AttachStorage",
":",
"value",
".",
"AttachStorage",
",",
"EndpointBindings",
":",
"value",
".",
"EndpointBindings",
",",
"Resources",
":",
"value",
".",
"Resources",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"api",
".",
"APIBase",
".",
"Deploy",
"(",
"newArgs",
")",
"\n",
"}"
] | // Deploy fetches the charms from the charm store and deploys them
// using the specified placement directives.
// V5 deploy did not support policy, so pass through an empty string. | [
"Deploy",
"fetches",
"the",
"charms",
"from",
"the",
"charm",
"store",
"and",
"deploys",
"them",
"using",
"the",
"specified",
"placement",
"directives",
".",
"V5",
"deploy",
"did",
"not",
"support",
"policy",
"so",
"pass",
"through",
"an",
"empty",
"string",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L290-L312 |
154,174 | juju/juju | apiserver/facades/client/application/application.go | Deploy | func (api *APIBase) Deploy(args params.ApplicationsDeploy) (params.ErrorResults, error) {
if err := api.checkCanWrite(); err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Applications)),
}
if err := api.check.ChangeAllowed(); err != nil {
return result, errors.Trace(err)
}
for i, arg := range args.Applications {
err := deployApplication(api.backend, api.model, api.stateCharm, arg, api.deployApplicationFunc, api.storagePoolManager, api.registry, api.storageValidator)
result.Results[i].Error = common.ServerError(err)
if err != nil && len(arg.Resources) != 0 {
// Remove any pending resources - these would have been
// converted into real resources if the application had
// been created successfully, but will otherwise be
// leaked. lp:1705730
// TODO(babbageclunk): rework the deploy API so the
// resources are created transactionally to avoid needing
// to do this.
resources, err := api.backend.Resources()
if err != nil {
logger.Errorf("couldn't get backend.Resources")
continue
}
err = resources.RemovePendingAppResources(arg.ApplicationName, arg.Resources)
if err != nil {
logger.Errorf("couldn't remove pending resources for %q", arg.ApplicationName)
}
}
}
return result, nil
} | go | func (api *APIBase) Deploy(args params.ApplicationsDeploy) (params.ErrorResults, error) {
if err := api.checkCanWrite(); err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Applications)),
}
if err := api.check.ChangeAllowed(); err != nil {
return result, errors.Trace(err)
}
for i, arg := range args.Applications {
err := deployApplication(api.backend, api.model, api.stateCharm, arg, api.deployApplicationFunc, api.storagePoolManager, api.registry, api.storageValidator)
result.Results[i].Error = common.ServerError(err)
if err != nil && len(arg.Resources) != 0 {
// Remove any pending resources - these would have been
// converted into real resources if the application had
// been created successfully, but will otherwise be
// leaked. lp:1705730
// TODO(babbageclunk): rework the deploy API so the
// resources are created transactionally to avoid needing
// to do this.
resources, err := api.backend.Resources()
if err != nil {
logger.Errorf("couldn't get backend.Resources")
continue
}
err = resources.RemovePendingAppResources(arg.ApplicationName, arg.Resources)
if err != nil {
logger.Errorf("couldn't remove pending resources for %q", arg.ApplicationName)
}
}
}
return result, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"Deploy",
"(",
"args",
"params",
".",
"ApplicationsDeploy",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Applications",
")",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Applications",
"{",
"err",
":=",
"deployApplication",
"(",
"api",
".",
"backend",
",",
"api",
".",
"model",
",",
"api",
".",
"stateCharm",
",",
"arg",
",",
"api",
".",
"deployApplicationFunc",
",",
"api",
".",
"storagePoolManager",
",",
"api",
".",
"registry",
",",
"api",
".",
"storageValidator",
")",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"&&",
"len",
"(",
"arg",
".",
"Resources",
")",
"!=",
"0",
"{",
"// Remove any pending resources - these would have been",
"// converted into real resources if the application had",
"// been created successfully, but will otherwise be",
"// leaked. lp:1705730",
"// TODO(babbageclunk): rework the deploy API so the",
"// resources are created transactionally to avoid needing",
"// to do this.",
"resources",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Resources",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"err",
"=",
"resources",
".",
"RemovePendingAppResources",
"(",
"arg",
".",
"ApplicationName",
",",
"arg",
".",
"Resources",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"arg",
".",
"ApplicationName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Deploy fetches the charms from the charm store and deploys them
// using the specified placement directives. | [
"Deploy",
"fetches",
"the",
"charms",
"from",
"the",
"charm",
"store",
"and",
"deploys",
"them",
"using",
"the",
"specified",
"placement",
"directives",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L343-L378 |
154,175 | juju/juju | apiserver/facades/client/application/application.go | splitApplicationAndCharmConfigFromYAML | func splitApplicationAndCharmConfigFromYAML(modelType state.ModelType, inYaml, appName string) (
appCfg map[string]interface{},
outYaml string,
_ error,
) {
var allSettings map[string]map[string]interface{}
if err := goyaml.Unmarshal([]byte(inYaml), &allSettings); err != nil {
return nil, "", errors.Annotate(err, "cannot parse settings data")
}
settings, ok := allSettings[appName]
if !ok {
return nil, "", errors.Errorf("no settings found for %q", appName)
}
providerSchema, _, err := applicationConfigSchema(modelType)
if err != nil {
return nil, "", errors.Trace(err)
}
appConfigKeys := application.KnownConfigKeys(providerSchema)
appConfigAttrs := make(map[string]interface{})
for k, v := range settings {
if appConfigKeys.Contains(k) {
appConfigAttrs[k] = v
delete(settings, k)
}
}
if len(settings) == 0 {
return appConfigAttrs, "", nil
}
allSettings[appName] = settings
charmConfig, err := goyaml.Marshal(allSettings)
if err != nil {
return nil, "", errors.Annotate(err, "cannot marshall charm settings")
}
return appConfigAttrs, string(charmConfig), nil
} | go | func splitApplicationAndCharmConfigFromYAML(modelType state.ModelType, inYaml, appName string) (
appCfg map[string]interface{},
outYaml string,
_ error,
) {
var allSettings map[string]map[string]interface{}
if err := goyaml.Unmarshal([]byte(inYaml), &allSettings); err != nil {
return nil, "", errors.Annotate(err, "cannot parse settings data")
}
settings, ok := allSettings[appName]
if !ok {
return nil, "", errors.Errorf("no settings found for %q", appName)
}
providerSchema, _, err := applicationConfigSchema(modelType)
if err != nil {
return nil, "", errors.Trace(err)
}
appConfigKeys := application.KnownConfigKeys(providerSchema)
appConfigAttrs := make(map[string]interface{})
for k, v := range settings {
if appConfigKeys.Contains(k) {
appConfigAttrs[k] = v
delete(settings, k)
}
}
if len(settings) == 0 {
return appConfigAttrs, "", nil
}
allSettings[appName] = settings
charmConfig, err := goyaml.Marshal(allSettings)
if err != nil {
return nil, "", errors.Annotate(err, "cannot marshall charm settings")
}
return appConfigAttrs, string(charmConfig), nil
} | [
"func",
"splitApplicationAndCharmConfigFromYAML",
"(",
"modelType",
"state",
".",
"ModelType",
",",
"inYaml",
",",
"appName",
"string",
")",
"(",
"appCfg",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"outYaml",
"string",
",",
"_",
"error",
",",
")",
"{",
"var",
"allSettings",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"goyaml",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"inYaml",
")",
",",
"&",
"allSettings",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"settings",
",",
"ok",
":=",
"allSettings",
"[",
"appName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"appName",
")",
"\n",
"}",
"\n\n",
"providerSchema",
",",
"_",
",",
"err",
":=",
"applicationConfigSchema",
"(",
"modelType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"appConfigKeys",
":=",
"application",
".",
"KnownConfigKeys",
"(",
"providerSchema",
")",
"\n\n",
"appConfigAttrs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"settings",
"{",
"if",
"appConfigKeys",
".",
"Contains",
"(",
"k",
")",
"{",
"appConfigAttrs",
"[",
"k",
"]",
"=",
"v",
"\n",
"delete",
"(",
"settings",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"settings",
")",
"==",
"0",
"{",
"return",
"appConfigAttrs",
",",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"allSettings",
"[",
"appName",
"]",
"=",
"settings",
"\n",
"charmConfig",
",",
"err",
":=",
"goyaml",
".",
"Marshal",
"(",
"allSettings",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"appConfigAttrs",
",",
"string",
"(",
"charmConfig",
")",
",",
"nil",
"\n",
"}"
] | // splitApplicationAndCharmConfigFromYAML extracts app specific settings from a charm config YAML
// and returns those app settings plus a YAML with just the charm settings left behind. | [
"splitApplicationAndCharmConfigFromYAML",
"extracts",
"app",
"specific",
"settings",
"from",
"a",
"charm",
"config",
"YAML",
"and",
"returns",
"those",
"app",
"settings",
"plus",
"a",
"YAML",
"with",
"just",
"the",
"charm",
"settings",
"left",
"behind",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L419-L456 |
154,176 | juju/juju | apiserver/facades/client/application/application.go | checkMachinePlacement | func checkMachinePlacement(backend Backend, args params.ApplicationDeploy) error {
errTemplate := "cannot deploy %q to machine %s"
app := args.ApplicationName
for _, p := range args.Placement {
dir := p.Directive
toProvisionedMachine := p.Scope == instance.MachineScope
if !toProvisionedMachine && dir == "" {
continue
}
m, err := backend.Machine(dir)
if err != nil {
if errors.IsNotFound(err) && !toProvisionedMachine {
continue
}
return errors.Annotatef(err, errTemplate, app, dir)
}
locked, err := m.IsLockedForSeriesUpgrade()
if locked {
err = errors.New("machine is locked for series upgrade")
}
if err != nil {
return errors.Annotatef(err, errTemplate, app, dir)
}
locked, err = m.IsParentLockedForSeriesUpgrade()
if locked {
err = errors.New("parent machine is locked for series upgrade")
}
if err != nil {
return errors.Annotatef(err, errTemplate, app, dir)
}
}
return nil
} | go | func checkMachinePlacement(backend Backend, args params.ApplicationDeploy) error {
errTemplate := "cannot deploy %q to machine %s"
app := args.ApplicationName
for _, p := range args.Placement {
dir := p.Directive
toProvisionedMachine := p.Scope == instance.MachineScope
if !toProvisionedMachine && dir == "" {
continue
}
m, err := backend.Machine(dir)
if err != nil {
if errors.IsNotFound(err) && !toProvisionedMachine {
continue
}
return errors.Annotatef(err, errTemplate, app, dir)
}
locked, err := m.IsLockedForSeriesUpgrade()
if locked {
err = errors.New("machine is locked for series upgrade")
}
if err != nil {
return errors.Annotatef(err, errTemplate, app, dir)
}
locked, err = m.IsParentLockedForSeriesUpgrade()
if locked {
err = errors.New("parent machine is locked for series upgrade")
}
if err != nil {
return errors.Annotatef(err, errTemplate, app, dir)
}
}
return nil
} | [
"func",
"checkMachinePlacement",
"(",
"backend",
"Backend",
",",
"args",
"params",
".",
"ApplicationDeploy",
")",
"error",
"{",
"errTemplate",
":=",
"\"",
"\"",
"\n",
"app",
":=",
"args",
".",
"ApplicationName",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"args",
".",
"Placement",
"{",
"dir",
":=",
"p",
".",
"Directive",
"\n\n",
"toProvisionedMachine",
":=",
"p",
".",
"Scope",
"==",
"instance",
".",
"MachineScope",
"\n",
"if",
"!",
"toProvisionedMachine",
"&&",
"dir",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"m",
",",
"err",
":=",
"backend",
".",
"Machine",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"&&",
"!",
"toProvisionedMachine",
"{",
"continue",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"errTemplate",
",",
"app",
",",
"dir",
")",
"\n",
"}",
"\n\n",
"locked",
",",
"err",
":=",
"m",
".",
"IsLockedForSeriesUpgrade",
"(",
")",
"\n",
"if",
"locked",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"errTemplate",
",",
"app",
",",
"dir",
")",
"\n",
"}",
"\n\n",
"locked",
",",
"err",
"=",
"m",
".",
"IsParentLockedForSeriesUpgrade",
"(",
")",
"\n",
"if",
"locked",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"errTemplate",
",",
"app",
",",
"dir",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // checkMachinePlacement does a non-exhaustive validation of any supplied
// placement directives.
// If the placement scope is for a machine, ensure that the machine exists.
// If the placement is for a machine or a container on an existing machine,
// check that the machine is not locked for series upgrade. | [
"checkMachinePlacement",
"does",
"a",
"non",
"-",
"exhaustive",
"validation",
"of",
"any",
"supplied",
"placement",
"directives",
".",
"If",
"the",
"placement",
"scope",
"is",
"for",
"a",
"machine",
"ensure",
"that",
"the",
"machine",
"exists",
".",
"If",
"the",
"placement",
"is",
"for",
"a",
"machine",
"or",
"a",
"container",
"on",
"an",
"existing",
"machine",
"check",
"that",
"the",
"machine",
"is",
"not",
"locked",
"for",
"series",
"upgrade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L640-L678 |
154,177 | juju/juju | apiserver/facades/client/application/application.go | applicationSetSettingsStrings | func applicationSetSettingsStrings(
application Application, gen string, settings map[string]string,
) error {
ch, _, err := application.Charm()
if err != nil {
return errors.Trace(err)
}
// Parse config in a compatible way (see function comment).
changes, err := parseSettingsCompatible(ch.Config(), settings)
if err != nil {
return errors.Trace(err)
}
return application.UpdateCharmConfig(gen, changes)
} | go | func applicationSetSettingsStrings(
application Application, gen string, settings map[string]string,
) error {
ch, _, err := application.Charm()
if err != nil {
return errors.Trace(err)
}
// Parse config in a compatible way (see function comment).
changes, err := parseSettingsCompatible(ch.Config(), settings)
if err != nil {
return errors.Trace(err)
}
return application.UpdateCharmConfig(gen, changes)
} | [
"func",
"applicationSetSettingsStrings",
"(",
"application",
"Application",
",",
"gen",
"string",
",",
"settings",
"map",
"[",
"string",
"]",
"string",
",",
")",
"error",
"{",
"ch",
",",
"_",
",",
"err",
":=",
"application",
".",
"Charm",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Parse config in a compatible way (see function comment).",
"changes",
",",
"err",
":=",
"parseSettingsCompatible",
"(",
"ch",
".",
"Config",
"(",
")",
",",
"settings",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"application",
".",
"UpdateCharmConfig",
"(",
"gen",
",",
"changes",
")",
"\n",
"}"
] | // applicationSetSettingsStrings updates the settings for the given application,
// taking the configuration from a map of strings. | [
"applicationSetSettingsStrings",
"updates",
"the",
"settings",
"for",
"the",
"given",
"application",
"taking",
"the",
"configuration",
"from",
"a",
"map",
"of",
"strings",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L682-L695 |
154,178 | juju/juju | apiserver/facades/client/application/application.go | Update | func (api *APIBase) Update(args params.ApplicationUpdate) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if !args.ForceCharmURL {
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
}
app, err := api.backend.Application(args.ApplicationName)
if err != nil {
return errors.Trace(err)
}
// Set the charm for the given application.
if args.CharmURL != "" {
// For now we do not support changing the channel through Update().
// TODO(ericsnow) Support it?
channel := app.Channel()
if err = api.updateCharm(
setCharmParams{
AppName: args.ApplicationName,
Application: app,
Channel: channel,
Force: forceParams{
ForceSeries: args.ForceSeries,
ForceUnits: args.ForceCharmURL,
Force: args.Force,
},
},
args.CharmURL,
); err != nil {
return errors.Trace(err)
}
}
// Set the minimum number of units for the given application.
if args.MinUnits != nil {
if err = app.SetMinUnits(*args.MinUnits); err != nil {
return errors.Trace(err)
}
}
// Set up application's settings.
// If the config change is generational, add the app to the generation.
configChange := false
if args.SettingsYAML != "" {
err = applicationSetCharmConfigYAML(args.ApplicationName, app, args.Generation, args.SettingsYAML)
if err != nil {
return errors.Annotate(err, "setting configuration from YAML")
}
configChange = true
} else if len(args.SettingsStrings) > 0 {
if err = applicationSetSettingsStrings(app, args.Generation, args.SettingsStrings); err != nil {
return errors.Trace(err)
}
configChange = true
}
if configChange && args.Generation != model.GenerationMaster {
if err := api.addAppToBranch(args.Generation, args.ApplicationName); err != nil {
return errors.Trace(err)
}
}
// Update application's constraints.
if args.Constraints != nil {
return app.SetConstraints(*args.Constraints)
}
return nil
} | go | func (api *APIBase) Update(args params.ApplicationUpdate) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if !args.ForceCharmURL {
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
}
app, err := api.backend.Application(args.ApplicationName)
if err != nil {
return errors.Trace(err)
}
// Set the charm for the given application.
if args.CharmURL != "" {
// For now we do not support changing the channel through Update().
// TODO(ericsnow) Support it?
channel := app.Channel()
if err = api.updateCharm(
setCharmParams{
AppName: args.ApplicationName,
Application: app,
Channel: channel,
Force: forceParams{
ForceSeries: args.ForceSeries,
ForceUnits: args.ForceCharmURL,
Force: args.Force,
},
},
args.CharmURL,
); err != nil {
return errors.Trace(err)
}
}
// Set the minimum number of units for the given application.
if args.MinUnits != nil {
if err = app.SetMinUnits(*args.MinUnits); err != nil {
return errors.Trace(err)
}
}
// Set up application's settings.
// If the config change is generational, add the app to the generation.
configChange := false
if args.SettingsYAML != "" {
err = applicationSetCharmConfigYAML(args.ApplicationName, app, args.Generation, args.SettingsYAML)
if err != nil {
return errors.Annotate(err, "setting configuration from YAML")
}
configChange = true
} else if len(args.SettingsStrings) > 0 {
if err = applicationSetSettingsStrings(app, args.Generation, args.SettingsStrings); err != nil {
return errors.Trace(err)
}
configChange = true
}
if configChange && args.Generation != model.GenerationMaster {
if err := api.addAppToBranch(args.Generation, args.ApplicationName); err != nil {
return errors.Trace(err)
}
}
// Update application's constraints.
if args.Constraints != nil {
return app.SetConstraints(*args.Constraints)
}
return nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"Update",
"(",
"args",
"params",
".",
"ApplicationUpdate",
")",
"error",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"args",
".",
"ForceCharmURL",
"{",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"app",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"args",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Set the charm for the given application.",
"if",
"args",
".",
"CharmURL",
"!=",
"\"",
"\"",
"{",
"// For now we do not support changing the channel through Update().",
"// TODO(ericsnow) Support it?",
"channel",
":=",
"app",
".",
"Channel",
"(",
")",
"\n",
"if",
"err",
"=",
"api",
".",
"updateCharm",
"(",
"setCharmParams",
"{",
"AppName",
":",
"args",
".",
"ApplicationName",
",",
"Application",
":",
"app",
",",
"Channel",
":",
"channel",
",",
"Force",
":",
"forceParams",
"{",
"ForceSeries",
":",
"args",
".",
"ForceSeries",
",",
"ForceUnits",
":",
"args",
".",
"ForceCharmURL",
",",
"Force",
":",
"args",
".",
"Force",
",",
"}",
",",
"}",
",",
"args",
".",
"CharmURL",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Set the minimum number of units for the given application.",
"if",
"args",
".",
"MinUnits",
"!=",
"nil",
"{",
"if",
"err",
"=",
"app",
".",
"SetMinUnits",
"(",
"*",
"args",
".",
"MinUnits",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Set up application's settings.",
"// If the config change is generational, add the app to the generation.",
"configChange",
":=",
"false",
"\n",
"if",
"args",
".",
"SettingsYAML",
"!=",
"\"",
"\"",
"{",
"err",
"=",
"applicationSetCharmConfigYAML",
"(",
"args",
".",
"ApplicationName",
",",
"app",
",",
"args",
".",
"Generation",
",",
"args",
".",
"SettingsYAML",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"configChange",
"=",
"true",
"\n",
"}",
"else",
"if",
"len",
"(",
"args",
".",
"SettingsStrings",
")",
">",
"0",
"{",
"if",
"err",
"=",
"applicationSetSettingsStrings",
"(",
"app",
",",
"args",
".",
"Generation",
",",
"args",
".",
"SettingsStrings",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"configChange",
"=",
"true",
"\n",
"}",
"\n",
"if",
"configChange",
"&&",
"args",
".",
"Generation",
"!=",
"model",
".",
"GenerationMaster",
"{",
"if",
"err",
":=",
"api",
".",
"addAppToBranch",
"(",
"args",
".",
"Generation",
",",
"args",
".",
"ApplicationName",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Update application's constraints.",
"if",
"args",
".",
"Constraints",
"!=",
"nil",
"{",
"return",
"app",
".",
"SetConstraints",
"(",
"*",
"args",
".",
"Constraints",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Update updates the application attributes, including charm URL,
// minimum number of units, charm config and constraints.
// All parameters in params.ApplicationUpdate except the application name are optional. | [
"Update",
"updates",
"the",
"application",
"attributes",
"including",
"charm",
"URL",
"minimum",
"number",
"of",
"units",
"charm",
"config",
"and",
"constraints",
".",
"All",
"parameters",
"in",
"params",
".",
"ApplicationUpdate",
"except",
"the",
"application",
"name",
"are",
"optional",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L748-L815 |
154,179 | juju/juju | apiserver/facades/client/application/application.go | updateCharm | func (api *APIBase) updateCharm(
params setCharmParams,
url string,
) error {
curl, err := charm.ParseURL(url)
if err != nil {
return errors.Trace(err)
}
charm, err := api.backend.Charm(curl)
if err != nil {
return errors.Trace(err)
}
return api.applicationSetCharm(params, charm)
} | go | func (api *APIBase) updateCharm(
params setCharmParams,
url string,
) error {
curl, err := charm.ParseURL(url)
if err != nil {
return errors.Trace(err)
}
charm, err := api.backend.Charm(curl)
if err != nil {
return errors.Trace(err)
}
return api.applicationSetCharm(params, charm)
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"updateCharm",
"(",
"params",
"setCharmParams",
",",
"url",
"string",
",",
")",
"error",
"{",
"curl",
",",
"err",
":=",
"charm",
".",
"ParseURL",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"charm",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Charm",
"(",
"curl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"api",
".",
"applicationSetCharm",
"(",
"params",
",",
"charm",
")",
"\n",
"}"
] | // updateCharm parses the charm url and then grabs the charm from the backend.
// this is analogous to setCharmWithAgentValidation, minus the validation around
// setting the profile charm. | [
"updateCharm",
"parses",
"the",
"charm",
"url",
"and",
"then",
"grabs",
"the",
"charm",
"from",
"the",
"backend",
".",
"this",
"is",
"analogous",
"to",
"setCharmWithAgentValidation",
"minus",
"the",
"validation",
"around",
"setting",
"the",
"profile",
"charm",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L820-L833 |
154,180 | juju/juju | apiserver/facades/client/application/application.go | UpdateApplicationSeries | func (api *APIBase) UpdateApplicationSeries(args params.UpdateSeriesArgs) (params.ErrorResults, error) {
if err := api.checkCanWrite(); err != nil {
return params.ErrorResults{}, err
}
if err := api.check.ChangeAllowed(); err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
results := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Args)),
}
for i, arg := range args.Args {
err := api.updateOneApplicationSeries(arg)
results.Results[i].Error = common.ServerError(err)
}
return results, nil
} | go | func (api *APIBase) UpdateApplicationSeries(args params.UpdateSeriesArgs) (params.ErrorResults, error) {
if err := api.checkCanWrite(); err != nil {
return params.ErrorResults{}, err
}
if err := api.check.ChangeAllowed(); err != nil {
return params.ErrorResults{}, errors.Trace(err)
}
results := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Args)),
}
for i, arg := range args.Args {
err := api.updateOneApplicationSeries(arg)
results.Results[i].Error = common.ServerError(err)
}
return results, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"UpdateApplicationSeries",
"(",
"args",
"params",
".",
"UpdateSeriesArgs",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"results",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Args",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Args",
"{",
"err",
":=",
"api",
".",
"updateOneApplicationSeries",
"(",
"arg",
")",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // UpdateApplicationSeries updates the application series. Series for
// subordinates updated too. | [
"UpdateApplicationSeries",
"updates",
"the",
"application",
"series",
".",
"Series",
"for",
"subordinates",
"updated",
"too",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L837-L852 |
154,181 | juju/juju | apiserver/facades/client/application/application.go | SetCharm | func (api *APIBase) SetCharm(args params.ApplicationSetCharm) error {
if err := api.checkCanWrite(); err != nil {
return err
}
// when forced units in error, don't block
if !args.ForceUnits {
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
}
application, err := api.backend.Application(args.ApplicationName)
if err != nil {
return errors.Trace(err)
}
channel := csparams.Channel(args.Channel)
return api.setCharmWithAgentValidation(
setCharmParams{
AppName: args.ApplicationName,
Application: application,
Channel: channel,
ConfigSettingsStrings: args.ConfigSettings,
ConfigSettingsYAML: args.ConfigSettingsYAML,
ResourceIDs: args.ResourceIDs,
StorageConstraints: args.StorageConstraints,
Force: forceParams{
ForceSeries: args.ForceSeries,
ForceUnits: args.ForceUnits,
Force: args.Force,
},
},
args.CharmURL,
)
} | go | func (api *APIBase) SetCharm(args params.ApplicationSetCharm) error {
if err := api.checkCanWrite(); err != nil {
return err
}
// when forced units in error, don't block
if !args.ForceUnits {
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
}
application, err := api.backend.Application(args.ApplicationName)
if err != nil {
return errors.Trace(err)
}
channel := csparams.Channel(args.Channel)
return api.setCharmWithAgentValidation(
setCharmParams{
AppName: args.ApplicationName,
Application: application,
Channel: channel,
ConfigSettingsStrings: args.ConfigSettings,
ConfigSettingsYAML: args.ConfigSettingsYAML,
ResourceIDs: args.ResourceIDs,
StorageConstraints: args.StorageConstraints,
Force: forceParams{
ForceSeries: args.ForceSeries,
ForceUnits: args.ForceUnits,
Force: args.Force,
},
},
args.CharmURL,
)
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"SetCharm",
"(",
"args",
"params",
".",
"ApplicationSetCharm",
")",
"error",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// when forced units in error, don't block",
"if",
"!",
"args",
".",
"ForceUnits",
"{",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"application",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"args",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"channel",
":=",
"csparams",
".",
"Channel",
"(",
"args",
".",
"Channel",
")",
"\n",
"return",
"api",
".",
"setCharmWithAgentValidation",
"(",
"setCharmParams",
"{",
"AppName",
":",
"args",
".",
"ApplicationName",
",",
"Application",
":",
"application",
",",
"Channel",
":",
"channel",
",",
"ConfigSettingsStrings",
":",
"args",
".",
"ConfigSettings",
",",
"ConfigSettingsYAML",
":",
"args",
".",
"ConfigSettingsYAML",
",",
"ResourceIDs",
":",
"args",
".",
"ResourceIDs",
",",
"StorageConstraints",
":",
"args",
".",
"StorageConstraints",
",",
"Force",
":",
"forceParams",
"{",
"ForceSeries",
":",
"args",
".",
"ForceSeries",
",",
"ForceUnits",
":",
"args",
".",
"ForceUnits",
",",
"Force",
":",
"args",
".",
"Force",
",",
"}",
",",
"}",
",",
"args",
".",
"CharmURL",
",",
")",
"\n",
"}"
] | // SetCharm sets the charm for a given for the application. | [
"SetCharm",
"sets",
"the",
"charm",
"for",
"a",
"given",
"for",
"the",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L882-L914 |
154,182 | juju/juju | apiserver/facades/client/application/application.go | setCharmWithAgentValidation | func (api *APIBase) setCharmWithAgentValidation(
params setCharmParams,
url string,
) error {
curl, err := charm.ParseURL(url)
if err != nil {
return errors.Trace(err)
}
newCharm, err := api.backend.Charm(curl)
if err != nil {
return errors.Trace(err)
}
if api.modelType == state.ModelTypeCAAS {
return api.applicationSetCharm(params, newCharm)
}
application := params.Application
// Check if the controller agent tools version is greater than the
// version we support for the new LXD profiles.
// Then check all the units, to see what their agent tools versions is
// so that we can ensure that everyone is aligned. If the units version
// is too low (i.e. less than the 2.6.0 epoch), then show an error
// message that the operator should upgrade to receive the latest
// LXD Profile changes.
// Ensure that we only check agent versions of a charm when we have a
// non-empty profile. So this check will only be run in the following
// scenarios; adding a profile, upgrading a profile. Removal of a
// profile, that had an existing charm, will check if there is currently
// an existing charm and if so, run the check.
// Checking that is possible, but that would require asking every unit
// machines what profiles they currently have and matching with the
// incoming update. This could be very costly when you have lots of
// machines.
currentCharm, _, err := application.Charm()
if err != nil {
logger.Debugf("Unable to locate current charm: %v", err)
}
if lxdprofile.NotEmpty(lxdCharmProfiler{Charm: currentCharm}) ||
lxdprofile.NotEmpty(lxdCharmProfiler{Charm: newCharm}) {
if err := validateAgentVersions(application, api.model); err != nil {
return errors.Trace(err)
}
}
return api.applicationSetCharm(params, newCharm)
} | go | func (api *APIBase) setCharmWithAgentValidation(
params setCharmParams,
url string,
) error {
curl, err := charm.ParseURL(url)
if err != nil {
return errors.Trace(err)
}
newCharm, err := api.backend.Charm(curl)
if err != nil {
return errors.Trace(err)
}
if api.modelType == state.ModelTypeCAAS {
return api.applicationSetCharm(params, newCharm)
}
application := params.Application
// Check if the controller agent tools version is greater than the
// version we support for the new LXD profiles.
// Then check all the units, to see what their agent tools versions is
// so that we can ensure that everyone is aligned. If the units version
// is too low (i.e. less than the 2.6.0 epoch), then show an error
// message that the operator should upgrade to receive the latest
// LXD Profile changes.
// Ensure that we only check agent versions of a charm when we have a
// non-empty profile. So this check will only be run in the following
// scenarios; adding a profile, upgrading a profile. Removal of a
// profile, that had an existing charm, will check if there is currently
// an existing charm and if so, run the check.
// Checking that is possible, but that would require asking every unit
// machines what profiles they currently have and matching with the
// incoming update. This could be very costly when you have lots of
// machines.
currentCharm, _, err := application.Charm()
if err != nil {
logger.Debugf("Unable to locate current charm: %v", err)
}
if lxdprofile.NotEmpty(lxdCharmProfiler{Charm: currentCharm}) ||
lxdprofile.NotEmpty(lxdCharmProfiler{Charm: newCharm}) {
if err := validateAgentVersions(application, api.model); err != nil {
return errors.Trace(err)
}
}
return api.applicationSetCharm(params, newCharm)
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"setCharmWithAgentValidation",
"(",
"params",
"setCharmParams",
",",
"url",
"string",
",",
")",
"error",
"{",
"curl",
",",
"err",
":=",
"charm",
".",
"ParseURL",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"newCharm",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Charm",
"(",
"curl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"api",
".",
"modelType",
"==",
"state",
".",
"ModelTypeCAAS",
"{",
"return",
"api",
".",
"applicationSetCharm",
"(",
"params",
",",
"newCharm",
")",
"\n",
"}",
"\n\n",
"application",
":=",
"params",
".",
"Application",
"\n",
"// Check if the controller agent tools version is greater than the",
"// version we support for the new LXD profiles.",
"// Then check all the units, to see what their agent tools versions is",
"// so that we can ensure that everyone is aligned. If the units version",
"// is too low (i.e. less than the 2.6.0 epoch), then show an error",
"// message that the operator should upgrade to receive the latest",
"// LXD Profile changes.",
"// Ensure that we only check agent versions of a charm when we have a",
"// non-empty profile. So this check will only be run in the following",
"// scenarios; adding a profile, upgrading a profile. Removal of a",
"// profile, that had an existing charm, will check if there is currently",
"// an existing charm and if so, run the check.",
"// Checking that is possible, but that would require asking every unit",
"// machines what profiles they currently have and matching with the",
"// incoming update. This could be very costly when you have lots of",
"// machines.",
"currentCharm",
",",
"_",
",",
"err",
":=",
"application",
".",
"Charm",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"lxdprofile",
".",
"NotEmpty",
"(",
"lxdCharmProfiler",
"{",
"Charm",
":",
"currentCharm",
"}",
")",
"||",
"lxdprofile",
".",
"NotEmpty",
"(",
"lxdCharmProfiler",
"{",
"Charm",
":",
"newCharm",
"}",
")",
"{",
"if",
"err",
":=",
"validateAgentVersions",
"(",
"application",
",",
"api",
".",
"model",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"api",
".",
"applicationSetCharm",
"(",
"params",
",",
"newCharm",
")",
"\n",
"}"
] | // setCharmWithAgentValidation checks the agent versions of the application
// and unit before continuing on. These checks are important to prevent old
// code running at the same time as the new code. If you encounter the error,
// the correct and only work around is to upgrade the units to match the
// controller. | [
"setCharmWithAgentValidation",
"checks",
"the",
"agent",
"versions",
"of",
"the",
"application",
"and",
"unit",
"before",
"continuing",
"on",
".",
"These",
"checks",
"are",
"important",
"to",
"prevent",
"old",
"code",
"running",
"at",
"the",
"same",
"time",
"as",
"the",
"new",
"code",
".",
"If",
"you",
"encounter",
"the",
"error",
"the",
"correct",
"and",
"only",
"work",
"around",
"is",
"to",
"upgrade",
"the",
"units",
"to",
"match",
"the",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L921-L967 |
154,183 | juju/juju | apiserver/facades/client/application/application.go | applicationSetCharm | func (api *APIBase) applicationSetCharm(
params setCharmParams,
stateCharm Charm,
) error {
var err error
var settings charm.Settings
if params.ConfigSettingsYAML != "" {
settings, err = stateCharm.Config().ParseSettingsYAML([]byte(params.ConfigSettingsYAML), params.AppName)
} else if len(params.ConfigSettingsStrings) > 0 {
settings, err = parseSettingsCompatible(stateCharm.Config(), params.ConfigSettingsStrings)
}
if err != nil {
return errors.Annotate(err, "parsing config settings")
}
var stateStorageConstraints map[string]state.StorageConstraints
if len(params.StorageConstraints) > 0 {
stateStorageConstraints = make(map[string]state.StorageConstraints)
for name, cons := range params.StorageConstraints {
stateCons := state.StorageConstraints{Pool: cons.Pool}
if cons.Size != nil {
stateCons.Size = *cons.Size
}
if cons.Count != nil {
stateCons.Count = *cons.Count
}
stateStorageConstraints[name] = stateCons
}
}
force := params.Force
cfg := state.SetCharmConfig{
Charm: api.stateCharm(stateCharm),
Channel: params.Channel,
ConfigSettings: settings,
ForceSeries: force.ForceSeries,
ForceUnits: force.ForceUnits,
Force: force.Force,
ResourceIDs: params.ResourceIDs,
StorageConstraints: stateStorageConstraints,
}
return params.Application.SetCharm(cfg)
} | go | func (api *APIBase) applicationSetCharm(
params setCharmParams,
stateCharm Charm,
) error {
var err error
var settings charm.Settings
if params.ConfigSettingsYAML != "" {
settings, err = stateCharm.Config().ParseSettingsYAML([]byte(params.ConfigSettingsYAML), params.AppName)
} else if len(params.ConfigSettingsStrings) > 0 {
settings, err = parseSettingsCompatible(stateCharm.Config(), params.ConfigSettingsStrings)
}
if err != nil {
return errors.Annotate(err, "parsing config settings")
}
var stateStorageConstraints map[string]state.StorageConstraints
if len(params.StorageConstraints) > 0 {
stateStorageConstraints = make(map[string]state.StorageConstraints)
for name, cons := range params.StorageConstraints {
stateCons := state.StorageConstraints{Pool: cons.Pool}
if cons.Size != nil {
stateCons.Size = *cons.Size
}
if cons.Count != nil {
stateCons.Count = *cons.Count
}
stateStorageConstraints[name] = stateCons
}
}
force := params.Force
cfg := state.SetCharmConfig{
Charm: api.stateCharm(stateCharm),
Channel: params.Channel,
ConfigSettings: settings,
ForceSeries: force.ForceSeries,
ForceUnits: force.ForceUnits,
Force: force.Force,
ResourceIDs: params.ResourceIDs,
StorageConstraints: stateStorageConstraints,
}
return params.Application.SetCharm(cfg)
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"applicationSetCharm",
"(",
"params",
"setCharmParams",
",",
"stateCharm",
"Charm",
",",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"settings",
"charm",
".",
"Settings",
"\n",
"if",
"params",
".",
"ConfigSettingsYAML",
"!=",
"\"",
"\"",
"{",
"settings",
",",
"err",
"=",
"stateCharm",
".",
"Config",
"(",
")",
".",
"ParseSettingsYAML",
"(",
"[",
"]",
"byte",
"(",
"params",
".",
"ConfigSettingsYAML",
")",
",",
"params",
".",
"AppName",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"params",
".",
"ConfigSettingsStrings",
")",
">",
"0",
"{",
"settings",
",",
"err",
"=",
"parseSettingsCompatible",
"(",
"stateCharm",
".",
"Config",
"(",
")",
",",
"params",
".",
"ConfigSettingsStrings",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"stateStorageConstraints",
"map",
"[",
"string",
"]",
"state",
".",
"StorageConstraints",
"\n",
"if",
"len",
"(",
"params",
".",
"StorageConstraints",
")",
">",
"0",
"{",
"stateStorageConstraints",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"state",
".",
"StorageConstraints",
")",
"\n",
"for",
"name",
",",
"cons",
":=",
"range",
"params",
".",
"StorageConstraints",
"{",
"stateCons",
":=",
"state",
".",
"StorageConstraints",
"{",
"Pool",
":",
"cons",
".",
"Pool",
"}",
"\n",
"if",
"cons",
".",
"Size",
"!=",
"nil",
"{",
"stateCons",
".",
"Size",
"=",
"*",
"cons",
".",
"Size",
"\n",
"}",
"\n",
"if",
"cons",
".",
"Count",
"!=",
"nil",
"{",
"stateCons",
".",
"Count",
"=",
"*",
"cons",
".",
"Count",
"\n",
"}",
"\n",
"stateStorageConstraints",
"[",
"name",
"]",
"=",
"stateCons",
"\n",
"}",
"\n",
"}",
"\n",
"force",
":=",
"params",
".",
"Force",
"\n",
"cfg",
":=",
"state",
".",
"SetCharmConfig",
"{",
"Charm",
":",
"api",
".",
"stateCharm",
"(",
"stateCharm",
")",
",",
"Channel",
":",
"params",
".",
"Channel",
",",
"ConfigSettings",
":",
"settings",
",",
"ForceSeries",
":",
"force",
".",
"ForceSeries",
",",
"ForceUnits",
":",
"force",
".",
"ForceUnits",
",",
"Force",
":",
"force",
".",
"Force",
",",
"ResourceIDs",
":",
"params",
".",
"ResourceIDs",
",",
"StorageConstraints",
":",
"stateStorageConstraints",
",",
"}",
"\n",
"return",
"params",
".",
"Application",
".",
"SetCharm",
"(",
"cfg",
")",
"\n",
"}"
] | // applicationSetCharm sets the charm for the given for the application. | [
"applicationSetCharm",
"sets",
"the",
"charm",
"for",
"the",
"given",
"for",
"the",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L970-L1010 |
154,184 | juju/juju | apiserver/facades/client/application/application.go | charmConfigFromGetYaml | func charmConfigFromGetYaml(yamlContents map[string]interface{}) (charm.Settings, error) {
onlySettings := charm.Settings{}
settingsMap, ok := yamlContents["settings"].(map[interface{}]interface{})
if !ok {
return nil, errors.New("unknown format for settings")
}
for setting := range settingsMap {
s, ok := settingsMap[setting].(map[interface{}]interface{})
if !ok {
return nil, errors.Errorf("unknown format for settings section %v", setting)
}
// some keys might not have a value, we don't care about those.
v, ok := s["value"]
if !ok {
continue
}
stringSetting, ok := setting.(string)
if !ok {
return nil, errors.Errorf("unexpected setting key, expected string got %T", setting)
}
onlySettings[stringSetting] = v
}
return onlySettings, nil
} | go | func charmConfigFromGetYaml(yamlContents map[string]interface{}) (charm.Settings, error) {
onlySettings := charm.Settings{}
settingsMap, ok := yamlContents["settings"].(map[interface{}]interface{})
if !ok {
return nil, errors.New("unknown format for settings")
}
for setting := range settingsMap {
s, ok := settingsMap[setting].(map[interface{}]interface{})
if !ok {
return nil, errors.Errorf("unknown format for settings section %v", setting)
}
// some keys might not have a value, we don't care about those.
v, ok := s["value"]
if !ok {
continue
}
stringSetting, ok := setting.(string)
if !ok {
return nil, errors.Errorf("unexpected setting key, expected string got %T", setting)
}
onlySettings[stringSetting] = v
}
return onlySettings, nil
} | [
"func",
"charmConfigFromGetYaml",
"(",
"yamlContents",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"charm",
".",
"Settings",
",",
"error",
")",
"{",
"onlySettings",
":=",
"charm",
".",
"Settings",
"{",
"}",
"\n",
"settingsMap",
",",
"ok",
":=",
"yamlContents",
"[",
"\"",
"\"",
"]",
".",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"setting",
":=",
"range",
"settingsMap",
"{",
"s",
",",
"ok",
":=",
"settingsMap",
"[",
"setting",
"]",
".",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"setting",
")",
"\n",
"}",
"\n",
"// some keys might not have a value, we don't care about those.",
"v",
",",
"ok",
":=",
"s",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"stringSetting",
",",
"ok",
":=",
"setting",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"setting",
")",
"\n",
"}",
"\n",
"onlySettings",
"[",
"stringSetting",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"onlySettings",
",",
"nil",
"\n",
"}"
] | // charmConfigFromGetYaml will parse a yaml produced by juju get and generate
// charm.Settings from it that can then be sent to the application. | [
"charmConfigFromGetYaml",
"will",
"parse",
"a",
"yaml",
"produced",
"by",
"juju",
"get",
"and",
"generate",
"charm",
".",
"Settings",
"from",
"it",
"that",
"can",
"then",
"be",
"sent",
"to",
"the",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1014-L1038 |
154,185 | juju/juju | apiserver/facades/client/application/application.go | applicationSetCharmConfigYAML | func applicationSetCharmConfigYAML(
appName string, application Application, gen string, settings string,
) error {
b := []byte(settings)
var all map[string]interface{}
if err := goyaml.Unmarshal(b, &all); err != nil {
return errors.Annotate(err, "parsing settings data")
}
// The file is already in the right format.
if _, ok := all[appName]; !ok {
changes, err := charmConfigFromGetYaml(all)
if err != nil {
return errors.Annotate(err, "processing YAML generated by get")
}
return errors.Annotate(application.UpdateCharmConfig(gen, changes), "updating settings with application YAML")
}
ch, _, err := application.Charm()
if err != nil {
return errors.Annotate(err, "obtaining charm for this application")
}
changes, err := ch.Config().ParseSettingsYAML(b, appName)
if err != nil {
return errors.Annotate(err, "creating config from YAML")
}
return errors.Annotate(application.UpdateCharmConfig(gen, changes), "updating settings")
} | go | func applicationSetCharmConfigYAML(
appName string, application Application, gen string, settings string,
) error {
b := []byte(settings)
var all map[string]interface{}
if err := goyaml.Unmarshal(b, &all); err != nil {
return errors.Annotate(err, "parsing settings data")
}
// The file is already in the right format.
if _, ok := all[appName]; !ok {
changes, err := charmConfigFromGetYaml(all)
if err != nil {
return errors.Annotate(err, "processing YAML generated by get")
}
return errors.Annotate(application.UpdateCharmConfig(gen, changes), "updating settings with application YAML")
}
ch, _, err := application.Charm()
if err != nil {
return errors.Annotate(err, "obtaining charm for this application")
}
changes, err := ch.Config().ParseSettingsYAML(b, appName)
if err != nil {
return errors.Annotate(err, "creating config from YAML")
}
return errors.Annotate(application.UpdateCharmConfig(gen, changes), "updating settings")
} | [
"func",
"applicationSetCharmConfigYAML",
"(",
"appName",
"string",
",",
"application",
"Application",
",",
"gen",
"string",
",",
"settings",
"string",
",",
")",
"error",
"{",
"b",
":=",
"[",
"]",
"byte",
"(",
"settings",
")",
"\n",
"var",
"all",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"goyaml",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"all",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// The file is already in the right format.",
"if",
"_",
",",
"ok",
":=",
"all",
"[",
"appName",
"]",
";",
"!",
"ok",
"{",
"changes",
",",
"err",
":=",
"charmConfigFromGetYaml",
"(",
"all",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotate",
"(",
"application",
".",
"UpdateCharmConfig",
"(",
"gen",
",",
"changes",
")",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ch",
",",
"_",
",",
"err",
":=",
"application",
".",
"Charm",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"changes",
",",
"err",
":=",
"ch",
".",
"Config",
"(",
")",
".",
"ParseSettingsYAML",
"(",
"b",
",",
"appName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotate",
"(",
"application",
".",
"UpdateCharmConfig",
"(",
"gen",
",",
"changes",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // applicationSetCharmConfigYAML updates the charm config for the
// given application, taking the configuration from a YAML string. | [
"applicationSetCharmConfigYAML",
"updates",
"the",
"charm",
"config",
"for",
"the",
"given",
"application",
"taking",
"the",
"configuration",
"from",
"a",
"YAML",
"string",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1042-L1069 |
154,186 | juju/juju | apiserver/facades/client/application/application.go | Set | func (api *APIBase) Set(p params.ApplicationSet) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
app, err := api.backend.Application(p.ApplicationName)
if err != nil {
return err
}
ch, _, err := app.Charm()
if err != nil {
return err
}
// Validate the settings.
changes, err := ch.Config().ParseSettingsStrings(p.Options)
if err != nil {
return err
}
return app.UpdateCharmConfig(model.GenerationMaster, changes)
} | go | func (api *APIBase) Set(p params.ApplicationSet) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
app, err := api.backend.Application(p.ApplicationName)
if err != nil {
return err
}
ch, _, err := app.Charm()
if err != nil {
return err
}
// Validate the settings.
changes, err := ch.Config().ParseSettingsStrings(p.Options)
if err != nil {
return err
}
return app.UpdateCharmConfig(model.GenerationMaster, changes)
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"Set",
"(",
"p",
"params",
".",
"ApplicationSet",
")",
"error",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"app",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"p",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ch",
",",
"_",
",",
"err",
":=",
"app",
".",
"Charm",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Validate the settings.",
"changes",
",",
"err",
":=",
"ch",
".",
"Config",
"(",
")",
".",
"ParseSettingsStrings",
"(",
"p",
".",
"Options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"app",
".",
"UpdateCharmConfig",
"(",
"model",
".",
"GenerationMaster",
",",
"changes",
")",
"\n",
"}"
] | // Set implements the server side of Application.Set.
// It does not unset values that are set to an empty string.
// Unset should be used for that. | [
"Set",
"implements",
"the",
"server",
"side",
"of",
"Application",
".",
"Set",
".",
"It",
"does",
"not",
"unset",
"values",
"that",
"are",
"set",
"to",
"an",
"empty",
"string",
".",
"Unset",
"should",
"be",
"used",
"for",
"that",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1088-L1110 |
154,187 | juju/juju | apiserver/facades/client/application/application.go | Unset | func (api *APIBase) Unset(p params.ApplicationUnset) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
app, err := api.backend.Application(p.ApplicationName)
if err != nil {
return err
}
settings := make(charm.Settings)
for _, option := range p.Options {
settings[option] = nil
}
// We need a guard on the API server-side for direct API callers such as
// python-libjuju. Always default to the master branch.
if p.BranchName == "" {
p.BranchName = model.GenerationMaster
}
return app.UpdateCharmConfig(p.BranchName, settings)
} | go | func (api *APIBase) Unset(p params.ApplicationUnset) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
app, err := api.backend.Application(p.ApplicationName)
if err != nil {
return err
}
settings := make(charm.Settings)
for _, option := range p.Options {
settings[option] = nil
}
// We need a guard on the API server-side for direct API callers such as
// python-libjuju. Always default to the master branch.
if p.BranchName == "" {
p.BranchName = model.GenerationMaster
}
return app.UpdateCharmConfig(p.BranchName, settings)
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"Unset",
"(",
"p",
"params",
".",
"ApplicationUnset",
")",
"error",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"app",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"p",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"settings",
":=",
"make",
"(",
"charm",
".",
"Settings",
")",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"p",
".",
"Options",
"{",
"settings",
"[",
"option",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"// We need a guard on the API server-side for direct API callers such as",
"// python-libjuju. Always default to the master branch.",
"if",
"p",
".",
"BranchName",
"==",
"\"",
"\"",
"{",
"p",
".",
"BranchName",
"=",
"model",
".",
"GenerationMaster",
"\n",
"}",
"\n",
"return",
"app",
".",
"UpdateCharmConfig",
"(",
"p",
".",
"BranchName",
",",
"settings",
")",
"\n",
"}"
] | // Unset implements the server side of Client.Unset. | [
"Unset",
"implements",
"the",
"server",
"side",
"of",
"Client",
".",
"Unset",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1113-L1135 |
154,188 | juju/juju | apiserver/facades/client/application/application.go | CharmRelations | func (api *APIBase) CharmRelations(p params.ApplicationCharmRelations) (params.ApplicationCharmRelationsResults, error) {
var results params.ApplicationCharmRelationsResults
if err := api.checkCanRead(); err != nil {
return results, errors.Trace(err)
}
app, err := api.backend.Application(p.ApplicationName)
if err != nil {
return results, errors.Trace(err)
}
endpoints, err := app.Endpoints()
if err != nil {
return results, errors.Trace(err)
}
results.CharmRelations = make([]string, len(endpoints))
for i, endpoint := range endpoints {
results.CharmRelations[i] = endpoint.Relation.Name
}
return results, nil
} | go | func (api *APIBase) CharmRelations(p params.ApplicationCharmRelations) (params.ApplicationCharmRelationsResults, error) {
var results params.ApplicationCharmRelationsResults
if err := api.checkCanRead(); err != nil {
return results, errors.Trace(err)
}
app, err := api.backend.Application(p.ApplicationName)
if err != nil {
return results, errors.Trace(err)
}
endpoints, err := app.Endpoints()
if err != nil {
return results, errors.Trace(err)
}
results.CharmRelations = make([]string, len(endpoints))
for i, endpoint := range endpoints {
results.CharmRelations[i] = endpoint.Relation.Name
}
return results, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"CharmRelations",
"(",
"p",
"params",
".",
"ApplicationCharmRelations",
")",
"(",
"params",
".",
"ApplicationCharmRelationsResults",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"ApplicationCharmRelationsResults",
"\n",
"if",
"err",
":=",
"api",
".",
"checkCanRead",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"app",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"p",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"endpoints",
",",
"err",
":=",
"app",
".",
"Endpoints",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"results",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"results",
".",
"CharmRelations",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"endpoints",
")",
")",
"\n",
"for",
"i",
",",
"endpoint",
":=",
"range",
"endpoints",
"{",
"results",
".",
"CharmRelations",
"[",
"i",
"]",
"=",
"endpoint",
".",
"Relation",
".",
"Name",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // CharmRelations implements the server side of Application.CharmRelations. | [
"CharmRelations",
"implements",
"the",
"server",
"side",
"of",
"Application",
".",
"CharmRelations",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1138-L1157 |
154,189 | juju/juju | apiserver/facades/client/application/application.go | addApplicationUnits | func addApplicationUnits(backend Backend, modelType state.ModelType, args params.AddApplicationUnits) ([]Unit, error) {
if args.NumUnits < 1 {
return nil, errors.New("must add at least one unit")
}
assignUnits := true
if modelType != state.ModelTypeIAAS {
// In a CAAS model, there are no machines for
// units to be assigned to.
assignUnits = false
if len(args.AttachStorage) > 0 {
return nil, errors.Errorf(
"AttachStorage may not be specified for %s models",
modelType,
)
}
if len(args.Placement) > 1 {
return nil, errors.Errorf(
"only 1 placement directive is supported for %s models, got %d",
modelType,
len(args.Placement),
)
}
}
// Parse storage tags in AttachStorage.
if len(args.AttachStorage) > 0 && args.NumUnits != 1 {
return nil, errors.Errorf("AttachStorage is non-empty, but NumUnits is %d", args.NumUnits)
}
attachStorage := make([]names.StorageTag, len(args.AttachStorage))
for i, tagString := range args.AttachStorage {
tag, err := names.ParseStorageTag(tagString)
if err != nil {
return nil, errors.Trace(err)
}
attachStorage[i] = tag
}
application, err := backend.Application(args.ApplicationName)
if err != nil {
return nil, errors.Trace(err)
}
return addUnits(
application,
args.ApplicationName,
args.NumUnits,
args.Placement,
attachStorage,
assignUnits,
)
} | go | func addApplicationUnits(backend Backend, modelType state.ModelType, args params.AddApplicationUnits) ([]Unit, error) {
if args.NumUnits < 1 {
return nil, errors.New("must add at least one unit")
}
assignUnits := true
if modelType != state.ModelTypeIAAS {
// In a CAAS model, there are no machines for
// units to be assigned to.
assignUnits = false
if len(args.AttachStorage) > 0 {
return nil, errors.Errorf(
"AttachStorage may not be specified for %s models",
modelType,
)
}
if len(args.Placement) > 1 {
return nil, errors.Errorf(
"only 1 placement directive is supported for %s models, got %d",
modelType,
len(args.Placement),
)
}
}
// Parse storage tags in AttachStorage.
if len(args.AttachStorage) > 0 && args.NumUnits != 1 {
return nil, errors.Errorf("AttachStorage is non-empty, but NumUnits is %d", args.NumUnits)
}
attachStorage := make([]names.StorageTag, len(args.AttachStorage))
for i, tagString := range args.AttachStorage {
tag, err := names.ParseStorageTag(tagString)
if err != nil {
return nil, errors.Trace(err)
}
attachStorage[i] = tag
}
application, err := backend.Application(args.ApplicationName)
if err != nil {
return nil, errors.Trace(err)
}
return addUnits(
application,
args.ApplicationName,
args.NumUnits,
args.Placement,
attachStorage,
assignUnits,
)
} | [
"func",
"addApplicationUnits",
"(",
"backend",
"Backend",
",",
"modelType",
"state",
".",
"ModelType",
",",
"args",
"params",
".",
"AddApplicationUnits",
")",
"(",
"[",
"]",
"Unit",
",",
"error",
")",
"{",
"if",
"args",
".",
"NumUnits",
"<",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"assignUnits",
":=",
"true",
"\n",
"if",
"modelType",
"!=",
"state",
".",
"ModelTypeIAAS",
"{",
"// In a CAAS model, there are no machines for",
"// units to be assigned to.",
"assignUnits",
"=",
"false",
"\n",
"if",
"len",
"(",
"args",
".",
"AttachStorage",
")",
">",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"modelType",
",",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"args",
".",
"Placement",
")",
">",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"modelType",
",",
"len",
"(",
"args",
".",
"Placement",
")",
",",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Parse storage tags in AttachStorage.",
"if",
"len",
"(",
"args",
".",
"AttachStorage",
")",
">",
"0",
"&&",
"args",
".",
"NumUnits",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"args",
".",
"NumUnits",
")",
"\n",
"}",
"\n",
"attachStorage",
":=",
"make",
"(",
"[",
"]",
"names",
".",
"StorageTag",
",",
"len",
"(",
"args",
".",
"AttachStorage",
")",
")",
"\n",
"for",
"i",
",",
"tagString",
":=",
"range",
"args",
".",
"AttachStorage",
"{",
"tag",
",",
"err",
":=",
"names",
".",
"ParseStorageTag",
"(",
"tagString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"attachStorage",
"[",
"i",
"]",
"=",
"tag",
"\n",
"}",
"\n",
"application",
",",
"err",
":=",
"backend",
".",
"Application",
"(",
"args",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"addUnits",
"(",
"application",
",",
"args",
".",
"ApplicationName",
",",
"args",
".",
"NumUnits",
",",
"args",
".",
"Placement",
",",
"attachStorage",
",",
"assignUnits",
",",
")",
"\n",
"}"
] | // addApplicationUnits adds a given number of units to an application. | [
"addApplicationUnits",
"adds",
"a",
"given",
"number",
"of",
"units",
"to",
"an",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1237-L1286 |
154,190 | juju/juju | apiserver/facades/client/application/application.go | ScaleApplications | func (api *APIBase) ScaleApplications(args params.ScaleApplicationsParams) (params.ScaleApplicationResults, error) {
if api.modelType != state.ModelTypeCAAS {
return params.ScaleApplicationResults{}, errors.NotSupportedf("scaling applications on a non-container model")
}
if err := api.checkCanWrite(); err != nil {
return params.ScaleApplicationResults{}, errors.Trace(err)
}
scaleApplication := func(arg params.ScaleApplicationParams) (*params.ScaleApplicationInfo, error) {
if arg.Scale < 0 && arg.ScaleChange == 0 {
return nil, errors.NotValidf("scale < 0")
} else if arg.Scale != 0 && arg.ScaleChange != 0 {
return nil, errors.NotValidf("requesting both scale and scale-change")
}
appTag, err := names.ParseApplicationTag(arg.ApplicationTag)
if err != nil {
return nil, errors.Trace(err)
}
name := appTag.Id()
app, err := api.backend.Application(name)
if errors.IsNotFound(err) {
return nil, errors.Errorf("application %q does not exist", name)
} else if err != nil {
return nil, errors.Trace(err)
}
var info params.ScaleApplicationInfo
if arg.ScaleChange != 0 {
newScale, err := app.ChangeScale(arg.ScaleChange)
if err != nil {
return nil, errors.Trace(err)
}
info.Scale = newScale
} else {
if err := app.SetScale(arg.Scale); err != nil {
return nil, errors.Trace(err)
}
info.Scale = arg.Scale
}
return &info, nil
}
results := make([]params.ScaleApplicationResult, len(args.Applications))
for i, entity := range args.Applications {
info, err := scaleApplication(entity)
if err != nil {
results[i].Error = common.ServerError(err)
continue
}
results[i].Info = info
}
return params.ScaleApplicationResults{results}, nil
} | go | func (api *APIBase) ScaleApplications(args params.ScaleApplicationsParams) (params.ScaleApplicationResults, error) {
if api.modelType != state.ModelTypeCAAS {
return params.ScaleApplicationResults{}, errors.NotSupportedf("scaling applications on a non-container model")
}
if err := api.checkCanWrite(); err != nil {
return params.ScaleApplicationResults{}, errors.Trace(err)
}
scaleApplication := func(arg params.ScaleApplicationParams) (*params.ScaleApplicationInfo, error) {
if arg.Scale < 0 && arg.ScaleChange == 0 {
return nil, errors.NotValidf("scale < 0")
} else if arg.Scale != 0 && arg.ScaleChange != 0 {
return nil, errors.NotValidf("requesting both scale and scale-change")
}
appTag, err := names.ParseApplicationTag(arg.ApplicationTag)
if err != nil {
return nil, errors.Trace(err)
}
name := appTag.Id()
app, err := api.backend.Application(name)
if errors.IsNotFound(err) {
return nil, errors.Errorf("application %q does not exist", name)
} else if err != nil {
return nil, errors.Trace(err)
}
var info params.ScaleApplicationInfo
if arg.ScaleChange != 0 {
newScale, err := app.ChangeScale(arg.ScaleChange)
if err != nil {
return nil, errors.Trace(err)
}
info.Scale = newScale
} else {
if err := app.SetScale(arg.Scale); err != nil {
return nil, errors.Trace(err)
}
info.Scale = arg.Scale
}
return &info, nil
}
results := make([]params.ScaleApplicationResult, len(args.Applications))
for i, entity := range args.Applications {
info, err := scaleApplication(entity)
if err != nil {
results[i].Error = common.ServerError(err)
continue
}
results[i].Info = info
}
return params.ScaleApplicationResults{results}, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"ScaleApplications",
"(",
"args",
"params",
".",
"ScaleApplicationsParams",
")",
"(",
"params",
".",
"ScaleApplicationResults",
",",
"error",
")",
"{",
"if",
"api",
".",
"modelType",
"!=",
"state",
".",
"ModelTypeCAAS",
"{",
"return",
"params",
".",
"ScaleApplicationResults",
"{",
"}",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ScaleApplicationResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"scaleApplication",
":=",
"func",
"(",
"arg",
"params",
".",
"ScaleApplicationParams",
")",
"(",
"*",
"params",
".",
"ScaleApplicationInfo",
",",
"error",
")",
"{",
"if",
"arg",
".",
"Scale",
"<",
"0",
"&&",
"arg",
".",
"ScaleChange",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"arg",
".",
"Scale",
"!=",
"0",
"&&",
"arg",
".",
"ScaleChange",
"!=",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"appTag",
",",
"err",
":=",
"names",
".",
"ParseApplicationTag",
"(",
"arg",
".",
"ApplicationTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"name",
":=",
"appTag",
".",
"Id",
"(",
")",
"\n",
"app",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"name",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"info",
"params",
".",
"ScaleApplicationInfo",
"\n",
"if",
"arg",
".",
"ScaleChange",
"!=",
"0",
"{",
"newScale",
",",
"err",
":=",
"app",
".",
"ChangeScale",
"(",
"arg",
".",
"ScaleChange",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"info",
".",
"Scale",
"=",
"newScale",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"app",
".",
"SetScale",
"(",
"arg",
".",
"Scale",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"info",
".",
"Scale",
"=",
"arg",
".",
"Scale",
"\n",
"}",
"\n",
"return",
"&",
"info",
",",
"nil",
"\n",
"}",
"\n",
"results",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"ScaleApplicationResult",
",",
"len",
"(",
"args",
".",
"Applications",
")",
")",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"args",
".",
"Applications",
"{",
"info",
",",
"err",
":=",
"scaleApplication",
"(",
"entity",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
"[",
"i",
"]",
".",
"Info",
"=",
"info",
"\n",
"}",
"\n",
"return",
"params",
".",
"ScaleApplicationResults",
"{",
"results",
"}",
",",
"nil",
"\n",
"}"
] | // ScaleApplications scales the specified application to the requested number of units. | [
"ScaleApplications",
"scales",
"the",
"specified",
"application",
"to",
"the",
"requested",
"number",
"of",
"units",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1583-L1633 |
154,191 | juju/juju | apiserver/facades/client/application/application.go | GetConstraints | func (api *APIBase) GetConstraints(args params.Entities) (params.ApplicationGetConstraintsResults, error) {
if err := api.checkCanRead(); err != nil {
return params.ApplicationGetConstraintsResults{}, errors.Trace(err)
}
results := params.ApplicationGetConstraintsResults{
Results: make([]params.ApplicationConstraint, len(args.Entities)),
}
for i, arg := range args.Entities {
cons, err := api.getConstraints(arg.Tag)
results.Results[i].Constraints = cons
results.Results[i].Error = common.ServerError(err)
}
return results, nil
} | go | func (api *APIBase) GetConstraints(args params.Entities) (params.ApplicationGetConstraintsResults, error) {
if err := api.checkCanRead(); err != nil {
return params.ApplicationGetConstraintsResults{}, errors.Trace(err)
}
results := params.ApplicationGetConstraintsResults{
Results: make([]params.ApplicationConstraint, len(args.Entities)),
}
for i, arg := range args.Entities {
cons, err := api.getConstraints(arg.Tag)
results.Results[i].Constraints = cons
results.Results[i].Error = common.ServerError(err)
}
return results, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"GetConstraints",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"ApplicationGetConstraintsResults",
",",
"error",
")",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanRead",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ApplicationGetConstraintsResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"results",
":=",
"params",
".",
"ApplicationGetConstraintsResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ApplicationConstraint",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"cons",
",",
"err",
":=",
"api",
".",
"getConstraints",
"(",
"arg",
".",
"Tag",
")",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Constraints",
"=",
"cons",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // GetConstraints returns the constraints for a given application. | [
"GetConstraints",
"returns",
"the",
"constraints",
"for",
"a",
"given",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1636-L1649 |
154,192 | juju/juju | apiserver/facades/client/application/application.go | SetConstraints | func (api *APIBase) SetConstraints(args params.SetConstraints) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
app, err := api.backend.Application(args.ApplicationName)
if err != nil {
return err
}
return app.SetConstraints(args.Constraints)
} | go | func (api *APIBase) SetConstraints(args params.SetConstraints) error {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
app, err := api.backend.Application(args.ApplicationName)
if err != nil {
return err
}
return app.SetConstraints(args.Constraints)
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"SetConstraints",
"(",
"args",
"params",
".",
"SetConstraints",
")",
"error",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"app",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"args",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"app",
".",
"SetConstraints",
"(",
"args",
".",
"Constraints",
")",
"\n",
"}"
] | // SetConstraints sets the constraints for a given application. | [
"SetConstraints",
"sets",
"the",
"constraints",
"for",
"a",
"given",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1669-L1681 |
154,193 | juju/juju | apiserver/facades/client/application/application.go | DestroyRelation | func (api *APIBase) DestroyRelation(args params.DestroyRelation) (err error) {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.RemoveAllowed(); err != nil {
return errors.Trace(err)
}
var (
rel Relation
eps []state.Endpoint
)
if len(args.Endpoints) > 0 {
eps, err = api.backend.InferEndpoints(args.Endpoints...)
if err != nil {
return err
}
rel, err = api.backend.EndpointsRelation(eps...)
} else {
rel, err = api.backend.Relation(args.RelationId)
}
if err != nil {
return err
}
return rel.Destroy()
} | go | func (api *APIBase) DestroyRelation(args params.DestroyRelation) (err error) {
if err := api.checkCanWrite(); err != nil {
return err
}
if err := api.check.RemoveAllowed(); err != nil {
return errors.Trace(err)
}
var (
rel Relation
eps []state.Endpoint
)
if len(args.Endpoints) > 0 {
eps, err = api.backend.InferEndpoints(args.Endpoints...)
if err != nil {
return err
}
rel, err = api.backend.EndpointsRelation(eps...)
} else {
rel, err = api.backend.Relation(args.RelationId)
}
if err != nil {
return err
}
return rel.Destroy()
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"DestroyRelation",
"(",
"args",
"params",
".",
"DestroyRelation",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"RemoveAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"(",
"rel",
"Relation",
"\n",
"eps",
"[",
"]",
"state",
".",
"Endpoint",
"\n",
")",
"\n",
"if",
"len",
"(",
"args",
".",
"Endpoints",
")",
">",
"0",
"{",
"eps",
",",
"err",
"=",
"api",
".",
"backend",
".",
"InferEndpoints",
"(",
"args",
".",
"Endpoints",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"rel",
",",
"err",
"=",
"api",
".",
"backend",
".",
"EndpointsRelation",
"(",
"eps",
"...",
")",
"\n",
"}",
"else",
"{",
"rel",
",",
"err",
"=",
"api",
".",
"backend",
".",
"Relation",
"(",
"args",
".",
"RelationId",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"rel",
".",
"Destroy",
"(",
")",
"\n",
"}"
] | // DestroyRelation removes the relation between the
// specified endpoints or an id. | [
"DestroyRelation",
"removes",
"the",
"relation",
"between",
"the",
"specified",
"endpoints",
"or",
"an",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1742-L1766 |
154,194 | juju/juju | apiserver/facades/client/application/application.go | SetRelationsSuspended | func (api *APIBase) SetRelationsSuspended(args params.RelationSuspendedArgs) (params.ErrorResults, error) {
var statusResults params.ErrorResults
if err := api.checkCanWrite(); err != nil {
return statusResults, errors.Trace(err)
}
if err := api.check.ChangeAllowed(); err != nil {
return statusResults, errors.Trace(err)
}
changeOne := func(arg params.RelationSuspendedArg) error {
rel, err := api.backend.Relation(arg.RelationId)
if err != nil {
return errors.Trace(err)
}
if rel.Suspended() == arg.Suspended {
return nil
}
_, err = api.backend.OfferConnectionForRelation(rel.Tag().Id())
if errors.IsNotFound(err) {
return errors.Errorf("cannot set suspend status for %q which is not associated with an offer", rel.Tag().Id())
}
message := arg.Message
if !arg.Suspended {
message = ""
}
err = rel.SetSuspended(arg.Suspended, message)
if err != nil {
return errors.Trace(err)
}
statusValue := status.Joining
if arg.Suspended {
statusValue = status.Suspending
}
return rel.SetStatus(status.StatusInfo{
Status: statusValue,
Message: arg.Message,
})
}
results := make([]params.ErrorResult, len(args.Args))
for i, arg := range args.Args {
err := changeOne(arg)
results[i].Error = common.ServerError(err)
}
statusResults.Results = results
return statusResults, nil
} | go | func (api *APIBase) SetRelationsSuspended(args params.RelationSuspendedArgs) (params.ErrorResults, error) {
var statusResults params.ErrorResults
if err := api.checkCanWrite(); err != nil {
return statusResults, errors.Trace(err)
}
if err := api.check.ChangeAllowed(); err != nil {
return statusResults, errors.Trace(err)
}
changeOne := func(arg params.RelationSuspendedArg) error {
rel, err := api.backend.Relation(arg.RelationId)
if err != nil {
return errors.Trace(err)
}
if rel.Suspended() == arg.Suspended {
return nil
}
_, err = api.backend.OfferConnectionForRelation(rel.Tag().Id())
if errors.IsNotFound(err) {
return errors.Errorf("cannot set suspend status for %q which is not associated with an offer", rel.Tag().Id())
}
message := arg.Message
if !arg.Suspended {
message = ""
}
err = rel.SetSuspended(arg.Suspended, message)
if err != nil {
return errors.Trace(err)
}
statusValue := status.Joining
if arg.Suspended {
statusValue = status.Suspending
}
return rel.SetStatus(status.StatusInfo{
Status: statusValue,
Message: arg.Message,
})
}
results := make([]params.ErrorResult, len(args.Args))
for i, arg := range args.Args {
err := changeOne(arg)
results[i].Error = common.ServerError(err)
}
statusResults.Results = results
return statusResults, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"SetRelationsSuspended",
"(",
"args",
"params",
".",
"RelationSuspendedArgs",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"var",
"statusResults",
"params",
".",
"ErrorResults",
"\n",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"statusResults",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"statusResults",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"changeOne",
":=",
"func",
"(",
"arg",
"params",
".",
"RelationSuspendedArg",
")",
"error",
"{",
"rel",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Relation",
"(",
"arg",
".",
"RelationId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"rel",
".",
"Suspended",
"(",
")",
"==",
"arg",
".",
"Suspended",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"api",
".",
"backend",
".",
"OfferConnectionForRelation",
"(",
"rel",
".",
"Tag",
"(",
")",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rel",
".",
"Tag",
"(",
")",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"message",
":=",
"arg",
".",
"Message",
"\n",
"if",
"!",
"arg",
".",
"Suspended",
"{",
"message",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"err",
"=",
"rel",
".",
"SetSuspended",
"(",
"arg",
".",
"Suspended",
",",
"message",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"statusValue",
":=",
"status",
".",
"Joining",
"\n",
"if",
"arg",
".",
"Suspended",
"{",
"statusValue",
"=",
"status",
".",
"Suspending",
"\n",
"}",
"\n",
"return",
"rel",
".",
"SetStatus",
"(",
"status",
".",
"StatusInfo",
"{",
"Status",
":",
"statusValue",
",",
"Message",
":",
"arg",
".",
"Message",
",",
"}",
")",
"\n",
"}",
"\n",
"results",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Args",
"{",
"err",
":=",
"changeOne",
"(",
"arg",
")",
"\n",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"statusResults",
".",
"Results",
"=",
"results",
"\n",
"return",
"statusResults",
",",
"nil",
"\n",
"}"
] | // SetRelationsSuspended sets the suspended status of the specified relations. | [
"SetRelationsSuspended",
"sets",
"the",
"suspended",
"status",
"of",
"the",
"specified",
"relations",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1769-L1815 |
154,195 | juju/juju | apiserver/facades/client/application/application.go | Consume | func (api *APIBase) Consume(args params.ConsumeApplicationArgs) (params.ErrorResults, error) {
var consumeResults params.ErrorResults
if err := api.checkCanWrite(); err != nil {
return consumeResults, errors.Trace(err)
}
if err := api.check.ChangeAllowed(); err != nil {
return consumeResults, errors.Trace(err)
}
results := make([]params.ErrorResult, len(args.Args))
for i, arg := range args.Args {
err := api.consumeOne(arg)
results[i].Error = common.ServerError(err)
}
consumeResults.Results = results
return consumeResults, nil
} | go | func (api *APIBase) Consume(args params.ConsumeApplicationArgs) (params.ErrorResults, error) {
var consumeResults params.ErrorResults
if err := api.checkCanWrite(); err != nil {
return consumeResults, errors.Trace(err)
}
if err := api.check.ChangeAllowed(); err != nil {
return consumeResults, errors.Trace(err)
}
results := make([]params.ErrorResult, len(args.Args))
for i, arg := range args.Args {
err := api.consumeOne(arg)
results[i].Error = common.ServerError(err)
}
consumeResults.Results = results
return consumeResults, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"Consume",
"(",
"args",
"params",
".",
"ConsumeApplicationArgs",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"var",
"consumeResults",
"params",
".",
"ErrorResults",
"\n",
"if",
"err",
":=",
"api",
".",
"checkCanWrite",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"consumeResults",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"check",
".",
"ChangeAllowed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"consumeResults",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"results",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Args",
"{",
"err",
":=",
"api",
".",
"consumeOne",
"(",
"arg",
")",
"\n",
"results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"consumeResults",
".",
"Results",
"=",
"results",
"\n",
"return",
"consumeResults",
",",
"nil",
"\n",
"}"
] | // Consume adds remote applications to the model without creating any
// relations. | [
"Consume",
"adds",
"remote",
"applications",
"to",
"the",
"model",
"without",
"creating",
"any",
"relations",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1819-L1835 |
154,196 | juju/juju | apiserver/facades/client/application/application.go | saveRemoteApplication | func (api *APIBase) saveRemoteApplication(
sourceModelTag names.ModelTag,
applicationName string,
offer params.ApplicationOfferDetails,
mac *macaroon.Macaroon,
) (RemoteApplication, error) {
remoteEps := make([]charm.Relation, len(offer.Endpoints))
for j, ep := range offer.Endpoints {
remoteEps[j] = charm.Relation{
Name: ep.Name,
Role: ep.Role,
Interface: ep.Interface,
}
}
remoteSpaces := make([]*environs.ProviderSpaceInfo, len(offer.Spaces))
for i, space := range offer.Spaces {
remoteSpaces[i] = providerSpaceInfoFromParams(space)
}
// If the a remote application with the same name and endpoints from the same
// source model already exists, we will use that one.
remoteApp, err := api.maybeUpdateExistingApplicationEndpoints(applicationName, sourceModelTag, remoteEps)
if err == nil {
return remoteApp, nil
} else if !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
return api.backend.AddRemoteApplication(state.AddRemoteApplicationParams{
Name: applicationName,
OfferUUID: offer.OfferUUID,
URL: offer.OfferURL,
SourceModel: sourceModelTag,
Endpoints: remoteEps,
Spaces: remoteSpaces,
Bindings: offer.Bindings,
Macaroon: mac,
})
} | go | func (api *APIBase) saveRemoteApplication(
sourceModelTag names.ModelTag,
applicationName string,
offer params.ApplicationOfferDetails,
mac *macaroon.Macaroon,
) (RemoteApplication, error) {
remoteEps := make([]charm.Relation, len(offer.Endpoints))
for j, ep := range offer.Endpoints {
remoteEps[j] = charm.Relation{
Name: ep.Name,
Role: ep.Role,
Interface: ep.Interface,
}
}
remoteSpaces := make([]*environs.ProviderSpaceInfo, len(offer.Spaces))
for i, space := range offer.Spaces {
remoteSpaces[i] = providerSpaceInfoFromParams(space)
}
// If the a remote application with the same name and endpoints from the same
// source model already exists, we will use that one.
remoteApp, err := api.maybeUpdateExistingApplicationEndpoints(applicationName, sourceModelTag, remoteEps)
if err == nil {
return remoteApp, nil
} else if !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
return api.backend.AddRemoteApplication(state.AddRemoteApplicationParams{
Name: applicationName,
OfferUUID: offer.OfferUUID,
URL: offer.OfferURL,
SourceModel: sourceModelTag,
Endpoints: remoteEps,
Spaces: remoteSpaces,
Bindings: offer.Bindings,
Macaroon: mac,
})
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"saveRemoteApplication",
"(",
"sourceModelTag",
"names",
".",
"ModelTag",
",",
"applicationName",
"string",
",",
"offer",
"params",
".",
"ApplicationOfferDetails",
",",
"mac",
"*",
"macaroon",
".",
"Macaroon",
",",
")",
"(",
"RemoteApplication",
",",
"error",
")",
"{",
"remoteEps",
":=",
"make",
"(",
"[",
"]",
"charm",
".",
"Relation",
",",
"len",
"(",
"offer",
".",
"Endpoints",
")",
")",
"\n",
"for",
"j",
",",
"ep",
":=",
"range",
"offer",
".",
"Endpoints",
"{",
"remoteEps",
"[",
"j",
"]",
"=",
"charm",
".",
"Relation",
"{",
"Name",
":",
"ep",
".",
"Name",
",",
"Role",
":",
"ep",
".",
"Role",
",",
"Interface",
":",
"ep",
".",
"Interface",
",",
"}",
"\n",
"}",
"\n\n",
"remoteSpaces",
":=",
"make",
"(",
"[",
"]",
"*",
"environs",
".",
"ProviderSpaceInfo",
",",
"len",
"(",
"offer",
".",
"Spaces",
")",
")",
"\n",
"for",
"i",
",",
"space",
":=",
"range",
"offer",
".",
"Spaces",
"{",
"remoteSpaces",
"[",
"i",
"]",
"=",
"providerSpaceInfoFromParams",
"(",
"space",
")",
"\n",
"}",
"\n\n",
"// If the a remote application with the same name and endpoints from the same",
"// source model already exists, we will use that one.",
"remoteApp",
",",
"err",
":=",
"api",
".",
"maybeUpdateExistingApplicationEndpoints",
"(",
"applicationName",
",",
"sourceModelTag",
",",
"remoteEps",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"remoteApp",
",",
"nil",
"\n",
"}",
"else",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"api",
".",
"backend",
".",
"AddRemoteApplication",
"(",
"state",
".",
"AddRemoteApplicationParams",
"{",
"Name",
":",
"applicationName",
",",
"OfferUUID",
":",
"offer",
".",
"OfferUUID",
",",
"URL",
":",
"offer",
".",
"OfferURL",
",",
"SourceModel",
":",
"sourceModelTag",
",",
"Endpoints",
":",
"remoteEps",
",",
"Spaces",
":",
"remoteSpaces",
",",
"Bindings",
":",
"offer",
".",
"Bindings",
",",
"Macaroon",
":",
"mac",
",",
"}",
")",
"\n",
"}"
] | // saveRemoteApplication saves the details of the specified remote application and its endpoints
// to the state model so relations to the remote application can be created. | [
"saveRemoteApplication",
"saves",
"the",
"details",
"of",
"the",
"specified",
"remote",
"application",
"and",
"its",
"endpoints",
"to",
"the",
"state",
"model",
"so",
"relations",
"to",
"the",
"remote",
"application",
"can",
"be",
"created",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1873-L1912 |
154,197 | juju/juju | apiserver/facades/client/application/application.go | providerSpaceInfoFromParams | func providerSpaceInfoFromParams(space params.RemoteSpace) *environs.ProviderSpaceInfo {
result := &environs.ProviderSpaceInfo{
CloudType: space.CloudType,
ProviderAttributes: space.ProviderAttributes,
SpaceInfo: network.SpaceInfo{
Name: space.Name,
ProviderId: network.Id(space.ProviderId),
},
}
for _, subnet := range space.Subnets {
resultSubnet := network.SubnetInfo{
CIDR: subnet.CIDR,
ProviderId: network.Id(subnet.ProviderId),
ProviderNetworkId: network.Id(subnet.ProviderNetworkId),
SpaceProviderId: network.Id(subnet.ProviderSpaceId),
VLANTag: subnet.VLANTag,
AvailabilityZones: subnet.Zones,
}
result.Subnets = append(result.Subnets, resultSubnet)
}
return result
} | go | func providerSpaceInfoFromParams(space params.RemoteSpace) *environs.ProviderSpaceInfo {
result := &environs.ProviderSpaceInfo{
CloudType: space.CloudType,
ProviderAttributes: space.ProviderAttributes,
SpaceInfo: network.SpaceInfo{
Name: space.Name,
ProviderId: network.Id(space.ProviderId),
},
}
for _, subnet := range space.Subnets {
resultSubnet := network.SubnetInfo{
CIDR: subnet.CIDR,
ProviderId: network.Id(subnet.ProviderId),
ProviderNetworkId: network.Id(subnet.ProviderNetworkId),
SpaceProviderId: network.Id(subnet.ProviderSpaceId),
VLANTag: subnet.VLANTag,
AvailabilityZones: subnet.Zones,
}
result.Subnets = append(result.Subnets, resultSubnet)
}
return result
} | [
"func",
"providerSpaceInfoFromParams",
"(",
"space",
"params",
".",
"RemoteSpace",
")",
"*",
"environs",
".",
"ProviderSpaceInfo",
"{",
"result",
":=",
"&",
"environs",
".",
"ProviderSpaceInfo",
"{",
"CloudType",
":",
"space",
".",
"CloudType",
",",
"ProviderAttributes",
":",
"space",
".",
"ProviderAttributes",
",",
"SpaceInfo",
":",
"network",
".",
"SpaceInfo",
"{",
"Name",
":",
"space",
".",
"Name",
",",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"space",
".",
"ProviderId",
")",
",",
"}",
",",
"}",
"\n",
"for",
"_",
",",
"subnet",
":=",
"range",
"space",
".",
"Subnets",
"{",
"resultSubnet",
":=",
"network",
".",
"SubnetInfo",
"{",
"CIDR",
":",
"subnet",
".",
"CIDR",
",",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"subnet",
".",
"ProviderId",
")",
",",
"ProviderNetworkId",
":",
"network",
".",
"Id",
"(",
"subnet",
".",
"ProviderNetworkId",
")",
",",
"SpaceProviderId",
":",
"network",
".",
"Id",
"(",
"subnet",
".",
"ProviderSpaceId",
")",
",",
"VLANTag",
":",
"subnet",
".",
"VLANTag",
",",
"AvailabilityZones",
":",
"subnet",
".",
"Zones",
",",
"}",
"\n",
"result",
".",
"Subnets",
"=",
"append",
"(",
"result",
".",
"Subnets",
",",
"resultSubnet",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // providerSpaceInfoFromParams converts a params.RemoteSpace to the
// equivalent ProviderSpaceInfo. | [
"providerSpaceInfoFromParams",
"converts",
"a",
"params",
".",
"RemoteSpace",
"to",
"the",
"equivalent",
"ProviderSpaceInfo",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1916-L1937 |
154,198 | juju/juju | apiserver/facades/client/application/application.go | maybeUpdateExistingApplicationEndpoints | func (api *APIBase) maybeUpdateExistingApplicationEndpoints(
applicationName string, sourceModelTag names.ModelTag, remoteEps []charm.Relation,
) (RemoteApplication, error) {
existingRemoteApp, err := api.backend.RemoteApplication(applicationName)
if err != nil {
return nil, errors.Trace(err)
}
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
if existingRemoteApp.SourceModel().Id() != sourceModelTag.Id() {
return nil, errors.AlreadyExistsf("remote application called %q from a different model", applicationName)
}
newEpsMap := make(map[charm.Relation]bool)
for _, ep := range remoteEps {
newEpsMap[ep] = true
}
existingEps, err := existingRemoteApp.Endpoints()
if err != nil {
return nil, errors.Trace(err)
}
maybeSameEndpoints := len(newEpsMap) == len(existingEps)
existingEpsByName := make(map[string]charm.Relation)
for _, ep := range existingEps {
existingEpsByName[ep.Name] = ep.Relation
delete(newEpsMap, ep.Relation)
}
sameEndpoints := maybeSameEndpoints && len(newEpsMap) == 0
if sameEndpoints {
return existingRemoteApp, nil
}
// Gather the new endpoints. All new endpoints passed to AddEndpoints()
// below must not have the same name as an existing endpoint.
var newEps []charm.Relation
for ep := range newEpsMap {
// See if we are attempting to update endpoints with the same name but
// different relation data.
if existing, ok := existingEpsByName[ep.Name]; ok && existing != ep {
return nil, errors.Errorf("conflicting endpoint %v", ep.Name)
}
newEps = append(newEps, ep)
}
if len(newEps) > 0 {
// Update the existing remote app to have the new, additional endpoints.
if err := existingRemoteApp.AddEndpoints(newEps); err != nil {
return nil, errors.Trace(err)
}
}
return existingRemoteApp, nil
} | go | func (api *APIBase) maybeUpdateExistingApplicationEndpoints(
applicationName string, sourceModelTag names.ModelTag, remoteEps []charm.Relation,
) (RemoteApplication, error) {
existingRemoteApp, err := api.backend.RemoteApplication(applicationName)
if err != nil {
return nil, errors.Trace(err)
}
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
if existingRemoteApp.SourceModel().Id() != sourceModelTag.Id() {
return nil, errors.AlreadyExistsf("remote application called %q from a different model", applicationName)
}
newEpsMap := make(map[charm.Relation]bool)
for _, ep := range remoteEps {
newEpsMap[ep] = true
}
existingEps, err := existingRemoteApp.Endpoints()
if err != nil {
return nil, errors.Trace(err)
}
maybeSameEndpoints := len(newEpsMap) == len(existingEps)
existingEpsByName := make(map[string]charm.Relation)
for _, ep := range existingEps {
existingEpsByName[ep.Name] = ep.Relation
delete(newEpsMap, ep.Relation)
}
sameEndpoints := maybeSameEndpoints && len(newEpsMap) == 0
if sameEndpoints {
return existingRemoteApp, nil
}
// Gather the new endpoints. All new endpoints passed to AddEndpoints()
// below must not have the same name as an existing endpoint.
var newEps []charm.Relation
for ep := range newEpsMap {
// See if we are attempting to update endpoints with the same name but
// different relation data.
if existing, ok := existingEpsByName[ep.Name]; ok && existing != ep {
return nil, errors.Errorf("conflicting endpoint %v", ep.Name)
}
newEps = append(newEps, ep)
}
if len(newEps) > 0 {
// Update the existing remote app to have the new, additional endpoints.
if err := existingRemoteApp.AddEndpoints(newEps); err != nil {
return nil, errors.Trace(err)
}
}
return existingRemoteApp, nil
} | [
"func",
"(",
"api",
"*",
"APIBase",
")",
"maybeUpdateExistingApplicationEndpoints",
"(",
"applicationName",
"string",
",",
"sourceModelTag",
"names",
".",
"ModelTag",
",",
"remoteEps",
"[",
"]",
"charm",
".",
"Relation",
",",
")",
"(",
"RemoteApplication",
",",
"error",
")",
"{",
"existingRemoteApp",
",",
"err",
":=",
"api",
".",
"backend",
".",
"RemoteApplication",
"(",
"applicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"existingRemoteApp",
".",
"SourceModel",
"(",
")",
".",
"Id",
"(",
")",
"!=",
"sourceModelTag",
".",
"Id",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"AlreadyExistsf",
"(",
"\"",
"\"",
",",
"applicationName",
")",
"\n",
"}",
"\n",
"newEpsMap",
":=",
"make",
"(",
"map",
"[",
"charm",
".",
"Relation",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"ep",
":=",
"range",
"remoteEps",
"{",
"newEpsMap",
"[",
"ep",
"]",
"=",
"true",
"\n",
"}",
"\n",
"existingEps",
",",
"err",
":=",
"existingRemoteApp",
".",
"Endpoints",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"maybeSameEndpoints",
":=",
"len",
"(",
"newEpsMap",
")",
"==",
"len",
"(",
"existingEps",
")",
"\n",
"existingEpsByName",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"charm",
".",
"Relation",
")",
"\n",
"for",
"_",
",",
"ep",
":=",
"range",
"existingEps",
"{",
"existingEpsByName",
"[",
"ep",
".",
"Name",
"]",
"=",
"ep",
".",
"Relation",
"\n",
"delete",
"(",
"newEpsMap",
",",
"ep",
".",
"Relation",
")",
"\n",
"}",
"\n",
"sameEndpoints",
":=",
"maybeSameEndpoints",
"&&",
"len",
"(",
"newEpsMap",
")",
"==",
"0",
"\n",
"if",
"sameEndpoints",
"{",
"return",
"existingRemoteApp",
",",
"nil",
"\n",
"}",
"\n\n",
"// Gather the new endpoints. All new endpoints passed to AddEndpoints()",
"// below must not have the same name as an existing endpoint.",
"var",
"newEps",
"[",
"]",
"charm",
".",
"Relation",
"\n",
"for",
"ep",
":=",
"range",
"newEpsMap",
"{",
"// See if we are attempting to update endpoints with the same name but",
"// different relation data.",
"if",
"existing",
",",
"ok",
":=",
"existingEpsByName",
"[",
"ep",
".",
"Name",
"]",
";",
"ok",
"&&",
"existing",
"!=",
"ep",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ep",
".",
"Name",
")",
"\n",
"}",
"\n",
"newEps",
"=",
"append",
"(",
"newEps",
",",
"ep",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"newEps",
")",
">",
"0",
"{",
"// Update the existing remote app to have the new, additional endpoints.",
"if",
"err",
":=",
"existingRemoteApp",
".",
"AddEndpoints",
"(",
"newEps",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"existingRemoteApp",
",",
"nil",
"\n",
"}"
] | // maybeUpdateExistingApplicationEndpoints looks for a remote application with the
// specified name and source model tag and tries to update its endpoints with the
// new ones specified. If the endpoints are compatible, the newly updated remote
// application is returned. | [
"maybeUpdateExistingApplicationEndpoints",
"looks",
"for",
"a",
"remote",
"application",
"with",
"the",
"specified",
"name",
"and",
"source",
"model",
"tag",
"and",
"tries",
"to",
"update",
"its",
"endpoints",
"with",
"the",
"new",
"ones",
"specified",
".",
"If",
"the",
"endpoints",
"are",
"compatible",
"the",
"newly",
"updated",
"remote",
"application",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L1943-L1994 |
154,199 | juju/juju | apiserver/facades/client/application/application.go | GetConstraints | func (api *APIv4) GetConstraints(args params.GetApplicationConstraints) (params.GetConstraintsResults, error) {
if err := api.checkCanRead(); err != nil {
return params.GetConstraintsResults{}, errors.Trace(err)
}
app, err := api.backend.Application(args.ApplicationName)
if err != nil {
return params.GetConstraintsResults{}, errors.Trace(err)
}
cons, err := app.Constraints()
return params.GetConstraintsResults{cons}, errors.Trace(err)
} | go | func (api *APIv4) GetConstraints(args params.GetApplicationConstraints) (params.GetConstraintsResults, error) {
if err := api.checkCanRead(); err != nil {
return params.GetConstraintsResults{}, errors.Trace(err)
}
app, err := api.backend.Application(args.ApplicationName)
if err != nil {
return params.GetConstraintsResults{}, errors.Trace(err)
}
cons, err := app.Constraints()
return params.GetConstraintsResults{cons}, errors.Trace(err)
} | [
"func",
"(",
"api",
"*",
"APIv4",
")",
"GetConstraints",
"(",
"args",
"params",
".",
"GetApplicationConstraints",
")",
"(",
"params",
".",
"GetConstraintsResults",
",",
"error",
")",
"{",
"if",
"err",
":=",
"api",
".",
"checkCanRead",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"GetConstraintsResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"app",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Application",
"(",
"args",
".",
"ApplicationName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"GetConstraintsResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"cons",
",",
"err",
":=",
"app",
".",
"Constraints",
"(",
")",
"\n",
"return",
"params",
".",
"GetConstraintsResults",
"{",
"cons",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // GetConstraints returns the v4 implementation of GetConstraints. | [
"GetConstraints",
"returns",
"the",
"v4",
"implementation",
"of",
"GetConstraints",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/application.go#L2007-L2017 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.