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
157,600
juju/juju
apiserver/facades/agent/uniter/uniter.go
WatchUnitRelations
func (u *UniterAPI) WatchUnitRelations(args params.Entities) (params.StringsWatchResults, error) { result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } canAccess, err := u.accessUnit() if err != nil { return params.StringsWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseUnitTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } err = common.ErrPerm if canAccess(tag) { result.Results[i], err = u.watchOneUnitRelations(tag) } result.Results[i].Error = common.ServerError(err) } return result, nil }
go
func (u *UniterAPI) WatchUnitRelations(args params.Entities) (params.StringsWatchResults, error) { result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } canAccess, err := u.accessUnit() if err != nil { return params.StringsWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseUnitTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } err = common.ErrPerm if canAccess(tag) { result.Results[i], err = u.watchOneUnitRelations(tag) } result.Results[i].Error = common.ServerError(err) } return result, nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "WatchUnitRelations", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "StringsWatchResults", ",", "error", ")", "{", "result", ":=", "params", ".", "StringsWatchResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "StringsWatchResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n", "canAccess", ",", "err", ":=", "u", ".", "accessUnit", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "StringsWatchResults", "{", "}", ",", "err", "\n", "}", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseUnitTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n", "err", "=", "common", ".", "ErrPerm", "\n", "if", "canAccess", "(", "tag", ")", "{", "result", ".", "Results", "[", "i", "]", ",", "err", "=", "u", ".", "watchOneUnitRelations", "(", "tag", ")", "\n", "}", "\n", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// WatchUnitRelations returns a StringsWatcher, for each given // unit, that notifies of changes to the lifecycles of relations // relevant to that unit. For principal units, this will be all of the // relations for the application. For subordinate units, only // relations with the principal unit's application will be monitored.
[ "WatchUnitRelations", "returns", "a", "StringsWatcher", "for", "each", "given", "unit", "that", "notifies", "of", "changes", "to", "the", "lifecycles", "of", "relations", "relevant", "to", "that", "unit", ".", "For", "principal", "units", "this", "will", "be", "all", "of", "the", "relations", "for", "the", "application", ".", "For", "subordinate", "units", "only", "relations", "with", "the", "principal", "unit", "s", "application", "will", "be", "monitored", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2235-L2256
157,601
juju/juju
apiserver/facades/agent/uniter/uniter.go
WatchApplicationRelations
func (u *UniterAPIV4) WatchApplicationRelations(args params.Entities) (params.StringsWatchResults, error) { result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } canAccess, err := u.accessApplication() if err != nil { return params.StringsWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseApplicationTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } err = common.ErrPerm if canAccess(tag) { result.Results[i], err = u.watchOneApplicationRelations(tag) } result.Results[i].Error = common.ServerError(err) } return result, nil }
go
func (u *UniterAPIV4) WatchApplicationRelations(args params.Entities) (params.StringsWatchResults, error) { result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } canAccess, err := u.accessApplication() if err != nil { return params.StringsWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseApplicationTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } err = common.ErrPerm if canAccess(tag) { result.Results[i], err = u.watchOneApplicationRelations(tag) } result.Results[i].Error = common.ServerError(err) } return result, nil }
[ "func", "(", "u", "*", "UniterAPIV4", ")", "WatchApplicationRelations", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "StringsWatchResults", ",", "error", ")", "{", "result", ":=", "params", ".", "StringsWatchResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "StringsWatchResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n", "canAccess", ",", "err", ":=", "u", ".", "accessApplication", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "StringsWatchResults", "{", "}", ",", "err", "\n", "}", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseApplicationTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n", "err", "=", "common", ".", "ErrPerm", "\n", "if", "canAccess", "(", "tag", ")", "{", "result", ".", "Results", "[", "i", "]", ",", "err", "=", "u", ".", "watchOneApplicationRelations", "(", "tag", ")", "\n", "}", "\n", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// WatchApplicationRelations returns a StringsWatcher, for each given // application, that notifies of changes to the lifecycles of // relations involving that application. This method is obsolete - // it's been replaced by WatchUnitRelations in V5 of the uniter API.
[ "WatchApplicationRelations", "returns", "a", "StringsWatcher", "for", "each", "given", "application", "that", "notifies", "of", "changes", "to", "the", "lifecycles", "of", "relations", "involving", "that", "application", ".", "This", "method", "is", "obsolete", "-", "it", "s", "been", "replaced", "by", "WatchUnitRelations", "in", "V5", "of", "the", "uniter", "API", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2460-L2481
157,602
juju/juju
apiserver/facades/agent/uniter/uniter.go
NetworkInfo
func (u *UniterAPIV6) NetworkInfo(args params.NetworkInfoParams) (params.NetworkInfoResultsV6, error) { v6Results, err := u.UniterAPI.NetworkInfo(args) if err != nil { return params.NetworkInfoResultsV6{}, errors.Trace(err) } return networkInfoResultsToV6(v6Results), nil }
go
func (u *UniterAPIV6) NetworkInfo(args params.NetworkInfoParams) (params.NetworkInfoResultsV6, error) { v6Results, err := u.UniterAPI.NetworkInfo(args) if err != nil { return params.NetworkInfoResultsV6{}, errors.Trace(err) } return networkInfoResultsToV6(v6Results), nil }
[ "func", "(", "u", "*", "UniterAPIV6", ")", "NetworkInfo", "(", "args", "params", ".", "NetworkInfoParams", ")", "(", "params", ".", "NetworkInfoResultsV6", ",", "error", ")", "{", "v6Results", ",", "err", ":=", "u", ".", "UniterAPI", ".", "NetworkInfo", "(", "args", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "NetworkInfoResultsV6", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "networkInfoResultsToV6", "(", "v6Results", ")", ",", "nil", "\n", "}" ]
// Network Info implements UniterAPIV6 version of NetworkInfo by constructing an API V6 compatible result.
[ "Network", "Info", "implements", "UniterAPIV6", "version", "of", "NetworkInfo", "by", "constructing", "an", "API", "V6", "compatible", "result", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2522-L2528
157,603
juju/juju
apiserver/facades/agent/uniter/uniter.go
SetPodSpec
func (u *UniterAPI) SetPodSpec(args params.SetPodSpecParams) (params.ErrorResults, error) { results := params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Specs)), } authTag := u.auth.GetAuthTag() canAccess := func(tag names.Tag) bool { if tag, ok := tag.(names.ApplicationTag); ok { switch authTag.(type) { case names.UnitTag: appName, err := names.UnitApplication(authTag.Id()) return err == nil && appName == tag.Id() case names.ApplicationTag: return tag == authTag } } return false } cfg, err := u.m.ModelConfig() if err != nil { return params.ErrorResults{}, errors.Trace(err) } provider, err := environs.Provider(cfg.Type()) if err != nil { return params.ErrorResults{}, errors.Trace(err) } cassProvider, ok := provider.(caas.ContainerEnvironProvider) if !ok { return params.ErrorResults{}, errors.NotValidf("container environ provider %T", provider) } for i, arg := range args.Specs { tag, err := names.ParseApplicationTag(arg.Tag) if err != nil { results.Results[i].Error = common.ServerError(err) continue } if !canAccess(tag) { results.Results[i].Error = common.ServerError(common.ErrPerm) continue } if _, err := cassProvider.ParsePodSpec(arg.Value); err != nil { results.Results[i].Error = common.ServerError(errors.Annotate(err, "invalid pod spec")) continue } cm, err := u.m.CAASModel() if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Error = common.ServerError( cm.SetPodSpec(tag, arg.Value), ) } return results, nil }
go
func (u *UniterAPI) SetPodSpec(args params.SetPodSpecParams) (params.ErrorResults, error) { results := params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Specs)), } authTag := u.auth.GetAuthTag() canAccess := func(tag names.Tag) bool { if tag, ok := tag.(names.ApplicationTag); ok { switch authTag.(type) { case names.UnitTag: appName, err := names.UnitApplication(authTag.Id()) return err == nil && appName == tag.Id() case names.ApplicationTag: return tag == authTag } } return false } cfg, err := u.m.ModelConfig() if err != nil { return params.ErrorResults{}, errors.Trace(err) } provider, err := environs.Provider(cfg.Type()) if err != nil { return params.ErrorResults{}, errors.Trace(err) } cassProvider, ok := provider.(caas.ContainerEnvironProvider) if !ok { return params.ErrorResults{}, errors.NotValidf("container environ provider %T", provider) } for i, arg := range args.Specs { tag, err := names.ParseApplicationTag(arg.Tag) if err != nil { results.Results[i].Error = common.ServerError(err) continue } if !canAccess(tag) { results.Results[i].Error = common.ServerError(common.ErrPerm) continue } if _, err := cassProvider.ParsePodSpec(arg.Value); err != nil { results.Results[i].Error = common.ServerError(errors.Annotate(err, "invalid pod spec")) continue } cm, err := u.m.CAASModel() if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Error = common.ServerError( cm.SetPodSpec(tag, arg.Value), ) } return results, nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "SetPodSpec", "(", "args", "params", ".", "SetPodSpecParams", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "results", ":=", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Specs", ")", ")", ",", "}", "\n", "authTag", ":=", "u", ".", "auth", ".", "GetAuthTag", "(", ")", "\n", "canAccess", ":=", "func", "(", "tag", "names", ".", "Tag", ")", "bool", "{", "if", "tag", ",", "ok", ":=", "tag", ".", "(", "names", ".", "ApplicationTag", ")", ";", "ok", "{", "switch", "authTag", ".", "(", "type", ")", "{", "case", "names", ".", "UnitTag", ":", "appName", ",", "err", ":=", "names", ".", "UnitApplication", "(", "authTag", ".", "Id", "(", ")", ")", "\n", "return", "err", "==", "nil", "&&", "appName", "==", "tag", ".", "Id", "(", ")", "\n", "case", "names", ".", "ApplicationTag", ":", "return", "tag", "==", "authTag", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}", "\n\n", "cfg", ",", "err", ":=", "u", ".", "m", ".", "ModelConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "ErrorResults", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "provider", ",", "err", ":=", "environs", ".", "Provider", "(", "cfg", ".", "Type", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "ErrorResults", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "cassProvider", ",", "ok", ":=", "provider", ".", "(", "caas", ".", "ContainerEnvironProvider", ")", "\n", "if", "!", "ok", "{", "return", "params", ".", "ErrorResults", "{", "}", ",", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "provider", ")", "\n", "}", "\n\n", "for", "i", ",", "arg", ":=", "range", "args", ".", "Specs", "{", "tag", ",", "err", ":=", "names", ".", "ParseApplicationTag", "(", "arg", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "!", "canAccess", "(", "tag", ")", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n", "if", "_", ",", "err", ":=", "cassProvider", ".", "ParsePodSpec", "(", "arg", ".", "Value", ")", ";", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", ")", "\n", "continue", "\n", "}", "\n", "cm", ",", "err", ":=", "u", ".", "m", ".", "CAASModel", "(", ")", "\n", "if", "err", "!=", "nil", "{", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "results", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "cm", ".", "SetPodSpec", "(", "tag", ",", "arg", ".", "Value", ")", ",", ")", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// SetPodSpec sets the pod specs for a set of applications.
[ "SetPodSpec", "sets", "the", "pod", "specs", "for", "a", "set", "of", "applications", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2538-L2593
157,604
juju/juju
apiserver/facades/agent/uniter/uniter.go
CloudSpec
func (u *UniterAPI) CloudSpec() (params.CloudSpecResult, error) { canAccess, err := u.accessCloudSpec() if err != nil { return params.CloudSpecResult{}, err } if !canAccess() { return params.CloudSpecResult{Error: common.ServerError(common.ErrPerm)}, nil } return u.cloudSpec.GetCloudSpec(u.m.Tag().(names.ModelTag)), nil }
go
func (u *UniterAPI) CloudSpec() (params.CloudSpecResult, error) { canAccess, err := u.accessCloudSpec() if err != nil { return params.CloudSpecResult{}, err } if !canAccess() { return params.CloudSpecResult{Error: common.ServerError(common.ErrPerm)}, nil } return u.cloudSpec.GetCloudSpec(u.m.Tag().(names.ModelTag)), nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "CloudSpec", "(", ")", "(", "params", ".", "CloudSpecResult", ",", "error", ")", "{", "canAccess", ",", "err", ":=", "u", ".", "accessCloudSpec", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "CloudSpecResult", "{", "}", ",", "err", "\n", "}", "\n", "if", "!", "canAccess", "(", ")", "{", "return", "params", ".", "CloudSpecResult", "{", "Error", ":", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "}", ",", "nil", "\n", "}", "\n\n", "return", "u", ".", "cloudSpec", ".", "GetCloudSpec", "(", "u", ".", "m", ".", "Tag", "(", ")", ".", "(", "names", ".", "ModelTag", ")", ")", ",", "nil", "\n", "}" ]
// CloudSpec returns the cloud spec used by the model in which the // authenticated unit or application resides. // A check is made beforehand to ensure that the request is made by an entity // that has been granted the appropriate trust.
[ "CloudSpec", "returns", "the", "cloud", "spec", "used", "by", "the", "model", "in", "which", "the", "authenticated", "unit", "or", "application", "resides", ".", "A", "check", "is", "made", "beforehand", "to", "ensure", "that", "the", "request", "is", "made", "by", "an", "entity", "that", "has", "been", "granted", "the", "appropriate", "trust", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2599-L2609
157,605
juju/juju
apiserver/facades/agent/uniter/uniter.go
GoalStates
func (u *UniterAPI) GoalStates(args params.Entities) (params.GoalStateResults, error) { result := params.GoalStateResults{ Results: make([]params.GoalStateResult, len(args.Entities)), } canAccess, err := u.accessUnit() if err != nil { return params.GoalStateResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseUnitTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } if !canAccess(tag) { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } unit, err := u.getUnit(tag) if err != nil { result.Results[i].Error = common.ServerError(err) continue } result.Results[i].Result, err = u.oneGoalState(unit) if err != nil { result.Results[i].Error = common.ServerError(err) } } return result, nil }
go
func (u *UniterAPI) GoalStates(args params.Entities) (params.GoalStateResults, error) { result := params.GoalStateResults{ Results: make([]params.GoalStateResult, len(args.Entities)), } canAccess, err := u.accessUnit() if err != nil { return params.GoalStateResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseUnitTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } if !canAccess(tag) { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } unit, err := u.getUnit(tag) if err != nil { result.Results[i].Error = common.ServerError(err) continue } result.Results[i].Result, err = u.oneGoalState(unit) if err != nil { result.Results[i].Error = common.ServerError(err) } } return result, nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "GoalStates", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "GoalStateResults", ",", "error", ")", "{", "result", ":=", "params", ".", "GoalStateResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "GoalStateResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n\n", "canAccess", ",", "err", ":=", "u", ".", "accessUnit", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "GoalStateResults", "{", "}", ",", "err", "\n", "}", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseUnitTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n", "if", "!", "canAccess", "(", "tag", ")", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n", "unit", ",", "err", ":=", "u", ".", "getUnit", "(", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "result", ".", "Results", "[", "i", "]", ".", "Result", ",", "err", "=", "u", ".", "oneGoalState", "(", "unit", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// GoalStates returns information of charm units and relations.
[ "GoalStates", "returns", "information", "of", "charm", "units", "and", "relations", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2612-L2642
157,606
juju/juju
apiserver/facades/agent/uniter/uniter.go
oneGoalState
func (u *UniterAPI) oneGoalState(unit *state.Unit) (*params.GoalState, error) { app, err := unit.Application() if err != nil { return nil, err } gs := params.GoalState{} gs.Units, err = u.goalStateUnits(app, unit.Name()) if err != nil { return nil, err } allRelations, err := app.Relations() if err != nil { return nil, err } if allRelations != nil { gs.Relations, err = u.goalStateRelations(app.Name(), unit.Name(), allRelations) if err != nil { return nil, err } } return &gs, nil }
go
func (u *UniterAPI) oneGoalState(unit *state.Unit) (*params.GoalState, error) { app, err := unit.Application() if err != nil { return nil, err } gs := params.GoalState{} gs.Units, err = u.goalStateUnits(app, unit.Name()) if err != nil { return nil, err } allRelations, err := app.Relations() if err != nil { return nil, err } if allRelations != nil { gs.Relations, err = u.goalStateRelations(app.Name(), unit.Name(), allRelations) if err != nil { return nil, err } } return &gs, nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "oneGoalState", "(", "unit", "*", "state", ".", "Unit", ")", "(", "*", "params", ".", "GoalState", ",", "error", ")", "{", "app", ",", "err", ":=", "unit", ".", "Application", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "gs", ":=", "params", ".", "GoalState", "{", "}", "\n", "gs", ".", "Units", ",", "err", "=", "u", ".", "goalStateUnits", "(", "app", ",", "unit", ".", "Name", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "allRelations", ",", "err", ":=", "app", ".", "Relations", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "allRelations", "!=", "nil", "{", "gs", ".", "Relations", ",", "err", "=", "u", ".", "goalStateRelations", "(", "app", ".", "Name", "(", ")", ",", "unit", ".", "Name", "(", ")", ",", "allRelations", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "&", "gs", ",", "nil", "\n", "}" ]
// oneGoalState creates the goal state for a given unit.
[ "oneGoalState", "creates", "the", "goal", "state", "for", "a", "given", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2645-L2667
157,607
juju/juju
apiserver/facades/agent/uniter/uniter.go
goalStateRelations
func (u *UniterAPI) goalStateRelations(appName, principalName string, allRelations []*state.Relation) (map[string]params.UnitsGoalState, error) { result := map[string]params.UnitsGoalState{} for _, r := range allRelations { statusInfo, err := r.Status() if err != nil { return nil, errors.Annotate(err, "getting relation status") } endPoints := r.Endpoints() if len(endPoints) == 1 { // Ignore peer relations here. continue } // First determine the local endpoint name to use later // as the key in the result map. var resultEndpointName string for _, e := range endPoints { if e.ApplicationName == appName { resultEndpointName = e.Name } } if resultEndpointName == "" { continue } // Now gather the goal state. for _, e := range endPoints { var key string app, err := u.st.Application(e.ApplicationName) if err == nil { key = app.Name() } else if errors.IsNotFound(err) { logger.Debugf("application %q must be a remote application.", e.ApplicationName) remoteApplication, err := u.st.RemoteApplication(e.ApplicationName) if err != nil { return nil, err } var ok bool key, ok = remoteApplication.URL() if !ok { // If we are on the offering side of a remote relation, don't show anything // in goal state for that relation. continue } } else { return nil, err } // We don't show units for the same application as we are currently processing. if key == appName { continue } goalState := params.GoalStateStatus{} goalState.Status = statusInfo.Status.String() goalState.Since = statusInfo.Since relationGoalState := result[e.Name] if relationGoalState == nil { relationGoalState = params.UnitsGoalState{} } relationGoalState[key] = goalState // For local applications, add in the status of units as well. if app != nil { units, err := u.goalStateUnits(app, principalName) if err != nil { return nil, err } for unitName, unitGS := range units { relationGoalState[unitName] = unitGS } } // Merge in the goal state for the current remote endpoint // with any other goal state already collected for the local endpoint. unitsGoalState := result[resultEndpointName] if unitsGoalState == nil { unitsGoalState = params.UnitsGoalState{} } for k, v := range relationGoalState { unitsGoalState[k] = v } result[resultEndpointName] = unitsGoalState } } return result, nil }
go
func (u *UniterAPI) goalStateRelations(appName, principalName string, allRelations []*state.Relation) (map[string]params.UnitsGoalState, error) { result := map[string]params.UnitsGoalState{} for _, r := range allRelations { statusInfo, err := r.Status() if err != nil { return nil, errors.Annotate(err, "getting relation status") } endPoints := r.Endpoints() if len(endPoints) == 1 { // Ignore peer relations here. continue } // First determine the local endpoint name to use later // as the key in the result map. var resultEndpointName string for _, e := range endPoints { if e.ApplicationName == appName { resultEndpointName = e.Name } } if resultEndpointName == "" { continue } // Now gather the goal state. for _, e := range endPoints { var key string app, err := u.st.Application(e.ApplicationName) if err == nil { key = app.Name() } else if errors.IsNotFound(err) { logger.Debugf("application %q must be a remote application.", e.ApplicationName) remoteApplication, err := u.st.RemoteApplication(e.ApplicationName) if err != nil { return nil, err } var ok bool key, ok = remoteApplication.URL() if !ok { // If we are on the offering side of a remote relation, don't show anything // in goal state for that relation. continue } } else { return nil, err } // We don't show units for the same application as we are currently processing. if key == appName { continue } goalState := params.GoalStateStatus{} goalState.Status = statusInfo.Status.String() goalState.Since = statusInfo.Since relationGoalState := result[e.Name] if relationGoalState == nil { relationGoalState = params.UnitsGoalState{} } relationGoalState[key] = goalState // For local applications, add in the status of units as well. if app != nil { units, err := u.goalStateUnits(app, principalName) if err != nil { return nil, err } for unitName, unitGS := range units { relationGoalState[unitName] = unitGS } } // Merge in the goal state for the current remote endpoint // with any other goal state already collected for the local endpoint. unitsGoalState := result[resultEndpointName] if unitsGoalState == nil { unitsGoalState = params.UnitsGoalState{} } for k, v := range relationGoalState { unitsGoalState[k] = v } result[resultEndpointName] = unitsGoalState } } return result, nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "goalStateRelations", "(", "appName", ",", "principalName", "string", ",", "allRelations", "[", "]", "*", "state", ".", "Relation", ")", "(", "map", "[", "string", "]", "params", ".", "UnitsGoalState", ",", "error", ")", "{", "result", ":=", "map", "[", "string", "]", "params", ".", "UnitsGoalState", "{", "}", "\n\n", "for", "_", ",", "r", ":=", "range", "allRelations", "{", "statusInfo", ",", "err", ":=", "r", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "endPoints", ":=", "r", ".", "Endpoints", "(", ")", "\n", "if", "len", "(", "endPoints", ")", "==", "1", "{", "// Ignore peer relations here.", "continue", "\n", "}", "\n\n", "// First determine the local endpoint name to use later", "// as the key in the result map.", "var", "resultEndpointName", "string", "\n", "for", "_", ",", "e", ":=", "range", "endPoints", "{", "if", "e", ".", "ApplicationName", "==", "appName", "{", "resultEndpointName", "=", "e", ".", "Name", "\n", "}", "\n", "}", "\n", "if", "resultEndpointName", "==", "\"", "\"", "{", "continue", "\n", "}", "\n\n", "// Now gather the goal state.", "for", "_", ",", "e", ":=", "range", "endPoints", "{", "var", "key", "string", "\n", "app", ",", "err", ":=", "u", ".", "st", ".", "Application", "(", "e", ".", "ApplicationName", ")", "\n", "if", "err", "==", "nil", "{", "key", "=", "app", ".", "Name", "(", ")", "\n", "}", "else", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "logger", ".", "Debugf", "(", "\"", "\"", ",", "e", ".", "ApplicationName", ")", "\n", "remoteApplication", ",", "err", ":=", "u", ".", "st", ".", "RemoteApplication", "(", "e", ".", "ApplicationName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "ok", "bool", "\n", "key", ",", "ok", "=", "remoteApplication", ".", "URL", "(", ")", "\n", "if", "!", "ok", "{", "// If we are on the offering side of a remote relation, don't show anything", "// in goal state for that relation.", "continue", "\n", "}", "\n", "}", "else", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// We don't show units for the same application as we are currently processing.", "if", "key", "==", "appName", "{", "continue", "\n", "}", "\n\n", "goalState", ":=", "params", ".", "GoalStateStatus", "{", "}", "\n", "goalState", ".", "Status", "=", "statusInfo", ".", "Status", ".", "String", "(", ")", "\n", "goalState", ".", "Since", "=", "statusInfo", ".", "Since", "\n", "relationGoalState", ":=", "result", "[", "e", ".", "Name", "]", "\n", "if", "relationGoalState", "==", "nil", "{", "relationGoalState", "=", "params", ".", "UnitsGoalState", "{", "}", "\n", "}", "\n", "relationGoalState", "[", "key", "]", "=", "goalState", "\n\n", "// For local applications, add in the status of units as well.", "if", "app", "!=", "nil", "{", "units", ",", "err", ":=", "u", ".", "goalStateUnits", "(", "app", ",", "principalName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "unitName", ",", "unitGS", ":=", "range", "units", "{", "relationGoalState", "[", "unitName", "]", "=", "unitGS", "\n", "}", "\n", "}", "\n\n", "// Merge in the goal state for the current remote endpoint", "// with any other goal state already collected for the local endpoint.", "unitsGoalState", ":=", "result", "[", "resultEndpointName", "]", "\n", "if", "unitsGoalState", "==", "nil", "{", "unitsGoalState", "=", "params", ".", "UnitsGoalState", "{", "}", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "relationGoalState", "{", "unitsGoalState", "[", "k", "]", "=", "v", "\n", "}", "\n", "result", "[", "resultEndpointName", "]", "=", "unitsGoalState", "\n", "}", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// goalStateRelations creates the structure with all the relations between endpoints in an application.
[ "goalStateRelations", "creates", "the", "structure", "with", "all", "the", "relations", "between", "endpoints", "in", "an", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2670-L2758
157,608
juju/juju
apiserver/facades/agent/uniter/uniter.go
goalStateUnits
func (u *UniterAPI) goalStateUnits(app *state.Application, principalName string) (params.UnitsGoalState, error) { allUnits, err := app.AllUnits() if err != nil { return nil, err } unitsGoalState := params.UnitsGoalState{} for _, unit := range allUnits { // Ignore subordinates belonging to other units. pn, ok := unit.PrincipalName() if ok && pn != principalName { continue } unitLife := unit.Life() if unitLife == state.Dead { // only show Alive and Dying units logger.Debugf("unit %q is dead, ignore it.", unit.Name()) continue } unitGoalState := params.GoalStateStatus{} statusInfo, err := unit.Status() if err != nil { return nil, errors.Trace(err) } unitGoalState.Status = statusInfo.Status.String() if unitLife == state.Dying { unitGoalState.Status = unitLife.String() } unitGoalState.Since = statusInfo.Since unitsGoalState[unit.Name()] = unitGoalState } return unitsGoalState, nil }
go
func (u *UniterAPI) goalStateUnits(app *state.Application, principalName string) (params.UnitsGoalState, error) { allUnits, err := app.AllUnits() if err != nil { return nil, err } unitsGoalState := params.UnitsGoalState{} for _, unit := range allUnits { // Ignore subordinates belonging to other units. pn, ok := unit.PrincipalName() if ok && pn != principalName { continue } unitLife := unit.Life() if unitLife == state.Dead { // only show Alive and Dying units logger.Debugf("unit %q is dead, ignore it.", unit.Name()) continue } unitGoalState := params.GoalStateStatus{} statusInfo, err := unit.Status() if err != nil { return nil, errors.Trace(err) } unitGoalState.Status = statusInfo.Status.String() if unitLife == state.Dying { unitGoalState.Status = unitLife.String() } unitGoalState.Since = statusInfo.Since unitsGoalState[unit.Name()] = unitGoalState } return unitsGoalState, nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "goalStateUnits", "(", "app", "*", "state", ".", "Application", ",", "principalName", "string", ")", "(", "params", ".", "UnitsGoalState", ",", "error", ")", "{", "allUnits", ",", "err", ":=", "app", ".", "AllUnits", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "unitsGoalState", ":=", "params", ".", "UnitsGoalState", "{", "}", "\n", "for", "_", ",", "unit", ":=", "range", "allUnits", "{", "// Ignore subordinates belonging to other units.", "pn", ",", "ok", ":=", "unit", ".", "PrincipalName", "(", ")", "\n", "if", "ok", "&&", "pn", "!=", "principalName", "{", "continue", "\n", "}", "\n", "unitLife", ":=", "unit", ".", "Life", "(", ")", "\n", "if", "unitLife", "==", "state", ".", "Dead", "{", "// only show Alive and Dying units", "logger", ".", "Debugf", "(", "\"", "\"", ",", "unit", ".", "Name", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "unitGoalState", ":=", "params", ".", "GoalStateStatus", "{", "}", "\n", "statusInfo", ",", "err", ":=", "unit", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "unitGoalState", ".", "Status", "=", "statusInfo", ".", "Status", ".", "String", "(", ")", "\n", "if", "unitLife", "==", "state", ".", "Dying", "{", "unitGoalState", ".", "Status", "=", "unitLife", ".", "String", "(", ")", "\n", "}", "\n", "unitGoalState", ".", "Since", "=", "statusInfo", ".", "Since", "\n", "unitsGoalState", "[", "unit", ".", "Name", "(", ")", "]", "=", "unitGoalState", "\n", "}", "\n\n", "return", "unitsGoalState", ",", "nil", "\n", "}" ]
// goalStateUnits loops through all application units related to principalName, // and stores the goal state status in UnitsGoalState.
[ "goalStateUnits", "loops", "through", "all", "application", "units", "related", "to", "principalName", "and", "stores", "the", "goal", "state", "status", "in", "UnitsGoalState", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2762-L2795
157,609
juju/juju
apiserver/facades/agent/uniter/uniter.go
WatchUnitAddressesHash
func (u *UniterAPI) WatchUnitAddressesHash(args params.Entities) (params.StringsWatchResults, error) { getWatcher := func(unit *state.Unit) (state.StringsWatcher, error) { if !unit.ShouldBeAssigned() { return unit.WatchContainerAddressesHash(), nil } machineId, err := unit.AssignedMachineId() if err != nil { return nil, err } machine, err := u.st.Machine(machineId) if err != nil { return nil, err } return machine.WatchAddressesHash(), nil } result, err := u.watchHashes(args, getWatcher) if err != nil { return params.StringsWatchResults{}, errors.Trace(err) } return result, nil }
go
func (u *UniterAPI) WatchUnitAddressesHash(args params.Entities) (params.StringsWatchResults, error) { getWatcher := func(unit *state.Unit) (state.StringsWatcher, error) { if !unit.ShouldBeAssigned() { return unit.WatchContainerAddressesHash(), nil } machineId, err := unit.AssignedMachineId() if err != nil { return nil, err } machine, err := u.st.Machine(machineId) if err != nil { return nil, err } return machine.WatchAddressesHash(), nil } result, err := u.watchHashes(args, getWatcher) if err != nil { return params.StringsWatchResults{}, errors.Trace(err) } return result, nil }
[ "func", "(", "u", "*", "UniterAPI", ")", "WatchUnitAddressesHash", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "StringsWatchResults", ",", "error", ")", "{", "getWatcher", ":=", "func", "(", "unit", "*", "state", ".", "Unit", ")", "(", "state", ".", "StringsWatcher", ",", "error", ")", "{", "if", "!", "unit", ".", "ShouldBeAssigned", "(", ")", "{", "return", "unit", ".", "WatchContainerAddressesHash", "(", ")", ",", "nil", "\n", "}", "\n", "machineId", ",", "err", ":=", "unit", ".", "AssignedMachineId", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "machine", ",", "err", ":=", "u", ".", "st", ".", "Machine", "(", "machineId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "machine", ".", "WatchAddressesHash", "(", ")", ",", "nil", "\n", "}", "\n", "result", ",", "err", ":=", "u", ".", "watchHashes", "(", "args", ",", "getWatcher", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "StringsWatchResults", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// WatchUnitAddressesHash returns a StringsWatcher that yields the // hashes of the addresses for the unit whenever the addresses // change. The uniter can use the hash to determine whether the actual // address values have changed since it last saw the config.
[ "WatchUnitAddressesHash", "returns", "a", "StringsWatcher", "that", "yields", "the", "hashes", "of", "the", "addresses", "for", "the", "unit", "whenever", "the", "addresses", "change", ".", "The", "uniter", "can", "use", "the", "hash", "to", "determine", "whether", "the", "actual", "address", "values", "have", "changed", "since", "it", "last", "saw", "the", "config", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2832-L2852
157,610
juju/juju
apiserver/facades/agent/uniter/uniter.go
CloudAPIVersion
func (u *UniterAPI) CloudAPIVersion() (params.StringResult, error) { result := params.StringResult{} configGetter := stateenvirons.EnvironConfigGetter{State: u.st, Model: u.m, NewContainerBroker: u.containerBrokerFunc} spec, err := configGetter.CloudSpec() if err != nil { return result, common.ServerError(err) } apiVersion, err := configGetter.CloudAPIVersion(spec) if err != nil { return result, common.ServerError(err) } result.Result = apiVersion return result, err }
go
func (u *UniterAPI) CloudAPIVersion() (params.StringResult, error) { result := params.StringResult{} configGetter := stateenvirons.EnvironConfigGetter{State: u.st, Model: u.m, NewContainerBroker: u.containerBrokerFunc} spec, err := configGetter.CloudSpec() if err != nil { return result, common.ServerError(err) } apiVersion, err := configGetter.CloudAPIVersion(spec) if err != nil { return result, common.ServerError(err) } result.Result = apiVersion return result, err }
[ "func", "(", "u", "*", "UniterAPI", ")", "CloudAPIVersion", "(", ")", "(", "params", ".", "StringResult", ",", "error", ")", "{", "result", ":=", "params", ".", "StringResult", "{", "}", "\n\n", "configGetter", ":=", "stateenvirons", ".", "EnvironConfigGetter", "{", "State", ":", "u", ".", "st", ",", "Model", ":", "u", ".", "m", ",", "NewContainerBroker", ":", "u", ".", "containerBrokerFunc", "}", "\n", "spec", ",", "err", ":=", "configGetter", ".", "CloudSpec", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "apiVersion", ",", "err", ":=", "configGetter", ".", "CloudAPIVersion", "(", "spec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "common", ".", "ServerError", "(", "err", ")", "\n", "}", "\n", "result", ".", "Result", "=", "apiVersion", "\n", "return", "result", ",", "err", "\n", "}" ]
// CloudAPIVersion returns the cloud API version, if available.
[ "CloudAPIVersion", "returns", "the", "cloud", "API", "version", "if", "available", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/uniter.go#L2915-L2929
157,611
juju/juju
provider/maas/interfaces.go
NetworkInterfaces
func (env *maasEnviron) NetworkInterfaces(ctx context.ProviderCallContext, instId instance.Id) ([]network.InterfaceInfo, error) { inst, err := env.getInstance(ctx, instId) if err != nil { return nil, errors.Trace(err) } subnetsMap, err := env.subnetToSpaceIds(ctx) if err != nil { return nil, errors.Trace(err) } if env.usingMAAS2() { dnsSearchDomains, err := env.Domains(ctx) if err != nil { return nil, errors.Trace(err) } return maas2NetworkInterfaces(ctx, inst.(*maas2Instance), subnetsMap, dnsSearchDomains...) } else { mi := inst.(*maas1Instance) return maasObjectNetworkInterfaces(ctx, mi.maasObject, subnetsMap) } }
go
func (env *maasEnviron) NetworkInterfaces(ctx context.ProviderCallContext, instId instance.Id) ([]network.InterfaceInfo, error) { inst, err := env.getInstance(ctx, instId) if err != nil { return nil, errors.Trace(err) } subnetsMap, err := env.subnetToSpaceIds(ctx) if err != nil { return nil, errors.Trace(err) } if env.usingMAAS2() { dnsSearchDomains, err := env.Domains(ctx) if err != nil { return nil, errors.Trace(err) } return maas2NetworkInterfaces(ctx, inst.(*maas2Instance), subnetsMap, dnsSearchDomains...) } else { mi := inst.(*maas1Instance) return maasObjectNetworkInterfaces(ctx, mi.maasObject, subnetsMap) } }
[ "func", "(", "env", "*", "maasEnviron", ")", "NetworkInterfaces", "(", "ctx", "context", ".", "ProviderCallContext", ",", "instId", "instance", ".", "Id", ")", "(", "[", "]", "network", ".", "InterfaceInfo", ",", "error", ")", "{", "inst", ",", "err", ":=", "env", ".", "getInstance", "(", "ctx", ",", "instId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "subnetsMap", ",", "err", ":=", "env", ".", "subnetToSpaceIds", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "env", ".", "usingMAAS2", "(", ")", "{", "dnsSearchDomains", ",", "err", ":=", "env", ".", "Domains", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "maas2NetworkInterfaces", "(", "ctx", ",", "inst", ".", "(", "*", "maas2Instance", ")", ",", "subnetsMap", ",", "dnsSearchDomains", "...", ")", "\n", "}", "else", "{", "mi", ":=", "inst", ".", "(", "*", "maas1Instance", ")", "\n", "return", "maasObjectNetworkInterfaces", "(", "ctx", ",", "mi", ".", "maasObject", ",", "subnetsMap", ")", "\n", "}", "\n", "}" ]
// NetworkInterfaces implements Environ.NetworkInterfaces.
[ "NetworkInterfaces", "implements", "Environ", ".", "NetworkInterfaces", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/interfaces.go#L89-L108
157,612
juju/juju
container/lxd/connection.go
NewServerSpec
func NewServerSpec(host, serverCert string, clientCert *Certificate) ServerSpec { return ServerSpec{ Host: EnsureHTTPS(host), connectionArgs: &lxd.ConnectionArgs{ TLSServerCert: serverCert, TLSClientCert: string(clientCert.CertPEM), TLSClientKey: string(clientCert.KeyPEM), }, } }
go
func NewServerSpec(host, serverCert string, clientCert *Certificate) ServerSpec { return ServerSpec{ Host: EnsureHTTPS(host), connectionArgs: &lxd.ConnectionArgs{ TLSServerCert: serverCert, TLSClientCert: string(clientCert.CertPEM), TLSClientKey: string(clientCert.KeyPEM), }, } }
[ "func", "NewServerSpec", "(", "host", ",", "serverCert", "string", ",", "clientCert", "*", "Certificate", ")", "ServerSpec", "{", "return", "ServerSpec", "{", "Host", ":", "EnsureHTTPS", "(", "host", ")", ",", "connectionArgs", ":", "&", "lxd", ".", "ConnectionArgs", "{", "TLSServerCert", ":", "serverCert", ",", "TLSClientCert", ":", "string", "(", "clientCert", ".", "CertPEM", ")", ",", "TLSClientKey", ":", "string", "(", "clientCert", ".", "KeyPEM", ")", ",", "}", ",", "}", "\n", "}" ]
// NewServerSpec creates a ServerSpec with default values where needed. // It also ensures the HTTPS for the host implicitly
[ "NewServerSpec", "creates", "a", "ServerSpec", "with", "default", "values", "where", "needed", ".", "It", "also", "ensures", "the", "HTTPS", "for", "the", "host", "implicitly" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L40-L49
157,613
juju/juju
container/lxd/connection.go
WithProxy
func (s ServerSpec) WithProxy(proxy ProxyFunc) ServerSpec { s.connectionArgs.Proxy = proxy return s }
go
func (s ServerSpec) WithProxy(proxy ProxyFunc) ServerSpec { s.connectionArgs.Proxy = proxy return s }
[ "func", "(", "s", "ServerSpec", ")", "WithProxy", "(", "proxy", "ProxyFunc", ")", "ServerSpec", "{", "s", ".", "connectionArgs", ".", "Proxy", "=", "proxy", "\n", "return", "s", "\n", "}" ]
// WithProxy adds the optional proxy to the server spec. // Returns the ServerSpec to enable chaining of optional values
[ "WithProxy", "adds", "the", "optional", "proxy", "to", "the", "server", "spec", ".", "Returns", "the", "ServerSpec", "to", "enable", "chaining", "of", "optional", "values" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L53-L56
157,614
juju/juju
container/lxd/connection.go
WithClientCertificate
func (s ServerSpec) WithClientCertificate(clientCert *Certificate) ServerSpec { s.connectionArgs.TLSClientCert = string(clientCert.CertPEM) s.connectionArgs.TLSClientKey = string(clientCert.KeyPEM) return s }
go
func (s ServerSpec) WithClientCertificate(clientCert *Certificate) ServerSpec { s.connectionArgs.TLSClientCert = string(clientCert.CertPEM) s.connectionArgs.TLSClientKey = string(clientCert.KeyPEM) return s }
[ "func", "(", "s", "ServerSpec", ")", "WithClientCertificate", "(", "clientCert", "*", "Certificate", ")", "ServerSpec", "{", "s", ".", "connectionArgs", ".", "TLSClientCert", "=", "string", "(", "clientCert", ".", "CertPEM", ")", "\n", "s", ".", "connectionArgs", ".", "TLSClientKey", "=", "string", "(", "clientCert", ".", "KeyPEM", ")", "\n", "return", "s", "\n", "}" ]
// WithClientCertificate adds the optional client Certificate to the server // spec. // Returns the ServerSpec to enable chaining of optional values
[ "WithClientCertificate", "adds", "the", "optional", "client", "Certificate", "to", "the", "server", "spec", ".", "Returns", "the", "ServerSpec", "to", "enable", "chaining", "of", "optional", "values" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L61-L65
157,615
juju/juju
container/lxd/connection.go
WithSkipGetServer
func (s ServerSpec) WithSkipGetServer(b bool) ServerSpec { s.connectionArgs.SkipGetServer = b return s }
go
func (s ServerSpec) WithSkipGetServer(b bool) ServerSpec { s.connectionArgs.SkipGetServer = b return s }
[ "func", "(", "s", "ServerSpec", ")", "WithSkipGetServer", "(", "b", "bool", ")", "ServerSpec", "{", "s", ".", "connectionArgs", ".", "SkipGetServer", "=", "b", "\n", "return", "s", "\n", "}" ]
// WithSkipGetServer adds the option skipping of the get server verification to // the server spec.
[ "WithSkipGetServer", "adds", "the", "option", "skipping", "of", "the", "get", "server", "verification", "to", "the", "server", "spec", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L69-L72
157,616
juju/juju
container/lxd/connection.go
NewInsecureServerSpec
func NewInsecureServerSpec(host string) ServerSpec { return ServerSpec{ Host: EnsureHTTPS(host), connectionArgs: &lxd.ConnectionArgs{ InsecureSkipVerify: true, }, } }
go
func NewInsecureServerSpec(host string) ServerSpec { return ServerSpec{ Host: EnsureHTTPS(host), connectionArgs: &lxd.ConnectionArgs{ InsecureSkipVerify: true, }, } }
[ "func", "NewInsecureServerSpec", "(", "host", "string", ")", "ServerSpec", "{", "return", "ServerSpec", "{", "Host", ":", "EnsureHTTPS", "(", "host", ")", ",", "connectionArgs", ":", "&", "lxd", ".", "ConnectionArgs", "{", "InsecureSkipVerify", ":", "true", ",", "}", ",", "}", "\n", "}" ]
// NewInsecureServerSpec creates a ServerSpec without certificate requirements, // which also bypasses the TLS verification. // It also ensures the HTTPS for the host implicitly
[ "NewInsecureServerSpec", "creates", "a", "ServerSpec", "without", "certificate", "requirements", "which", "also", "bypasses", "the", "TLS", "verification", ".", "It", "also", "ensures", "the", "HTTPS", "for", "the", "host", "implicitly" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L77-L84
157,617
juju/juju
container/lxd/connection.go
MakeSimpleStreamsServerSpec
func MakeSimpleStreamsServerSpec(name, host string) ServerSpec { return ServerSpec{ Name: name, Host: EnsureHTTPS(host), Protocol: SimpleStreamsProtocol, } }
go
func MakeSimpleStreamsServerSpec(name, host string) ServerSpec { return ServerSpec{ Name: name, Host: EnsureHTTPS(host), Protocol: SimpleStreamsProtocol, } }
[ "func", "MakeSimpleStreamsServerSpec", "(", "name", ",", "host", "string", ")", "ServerSpec", "{", "return", "ServerSpec", "{", "Name", ":", "name", ",", "Host", ":", "EnsureHTTPS", "(", "host", ")", ",", "Protocol", ":", "SimpleStreamsProtocol", ",", "}", "\n", "}" ]
// MakeSimpleStreamsServerSpec creates a ServerSpec for the SimpleStreams // protocol, ensuring that the host is HTTPS
[ "MakeSimpleStreamsServerSpec", "creates", "a", "ServerSpec", "for", "the", "SimpleStreams", "protocol", "ensuring", "that", "the", "host", "is", "HTTPS" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L88-L94
157,618
juju/juju
container/lxd/connection.go
ConnectRemote
func ConnectRemote(spec ServerSpec) (lxd.ContainerServer, error) { // Ensure the Port on the Host, if we get an error it is reasonable to // assume that the address in the spec is invalid. uri, err := EnsureHostPort(spec.Host) if err != nil { return nil, errors.Trace(err) } client, err := lxd.ConnectLXD(uri, spec.connectionArgs) return client, errors.Trace(err) }
go
func ConnectRemote(spec ServerSpec) (lxd.ContainerServer, error) { // Ensure the Port on the Host, if we get an error it is reasonable to // assume that the address in the spec is invalid. uri, err := EnsureHostPort(spec.Host) if err != nil { return nil, errors.Trace(err) } client, err := lxd.ConnectLXD(uri, spec.connectionArgs) return client, errors.Trace(err) }
[ "func", "ConnectRemote", "(", "spec", "ServerSpec", ")", "(", "lxd", ".", "ContainerServer", ",", "error", ")", "{", "// Ensure the Port on the Host, if we get an error it is reasonable to", "// assume that the address in the spec is invalid.", "uri", ",", "err", ":=", "EnsureHostPort", "(", "spec", ".", "Host", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "client", ",", "err", ":=", "lxd", ".", "ConnectLXD", "(", "uri", ",", "spec", ".", "connectionArgs", ")", "\n", "return", "client", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}" ]
// ConnectRemote connects to LXD on a remote socket.
[ "ConnectRemote", "connects", "to", "LXD", "on", "a", "remote", "socket", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L139-L148
157,619
juju/juju
container/lxd/connection.go
EnsureHTTPS
func EnsureHTTPS(address string) string { if strings.HasPrefix(address, "https://") { return address } if strings.HasPrefix(address, "http://") { addr := strings.Replace(address, "http://", "https://", 1) logger.Debugf("LXD requires https://, using: %s", addr) return addr } return "https://" + address }
go
func EnsureHTTPS(address string) string { if strings.HasPrefix(address, "https://") { return address } if strings.HasPrefix(address, "http://") { addr := strings.Replace(address, "http://", "https://", 1) logger.Debugf("LXD requires https://, using: %s", addr) return addr } return "https://" + address }
[ "func", "EnsureHTTPS", "(", "address", "string", ")", "string", "{", "if", "strings", ".", "HasPrefix", "(", "address", ",", "\"", "\"", ")", "{", "return", "address", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "address", ",", "\"", "\"", ")", "{", "addr", ":=", "strings", ".", "Replace", "(", "address", ",", "\"", "\"", ",", "\"", "\"", ",", "1", ")", "\n", "logger", ".", "Debugf", "(", "\"", "\"", ",", "addr", ")", "\n", "return", "addr", "\n", "}", "\n", "return", "\"", "\"", "+", "address", "\n", "}" ]
// EnsureHTTPS takes a URI and ensures that it is a HTTPS URL. // LXD Requires HTTPS.
[ "EnsureHTTPS", "takes", "a", "URI", "and", "ensures", "that", "it", "is", "a", "HTTPS", "URL", ".", "LXD", "Requires", "HTTPS", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L181-L191
157,620
juju/juju
container/lxd/connection.go
EnsureHostPort
func EnsureHostPort(address string) (string, error) { // make sure we ensure a schema, otherwise somewhere:8443 can return a // the following //:8443/somewhere uri, err := url.Parse(EnsureHTTPS(address)) if err != nil { return "", errors.Trace(err) } if uri.Port() == "" { uri.Host = fmt.Sprintf("%s:%d", uri.Host, defaultPort) } return uri.String(), nil }
go
func EnsureHostPort(address string) (string, error) { // make sure we ensure a schema, otherwise somewhere:8443 can return a // the following //:8443/somewhere uri, err := url.Parse(EnsureHTTPS(address)) if err != nil { return "", errors.Trace(err) } if uri.Port() == "" { uri.Host = fmt.Sprintf("%s:%d", uri.Host, defaultPort) } return uri.String(), nil }
[ "func", "EnsureHostPort", "(", "address", "string", ")", "(", "string", ",", "error", ")", "{", "// make sure we ensure a schema, otherwise somewhere:8443 can return a", "// the following //:8443/somewhere", "uri", ",", "err", ":=", "url", ".", "Parse", "(", "EnsureHTTPS", "(", "address", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "uri", ".", "Port", "(", ")", "==", "\"", "\"", "{", "uri", ".", "Host", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "uri", ".", "Host", ",", "defaultPort", ")", "\n", "}", "\n", "return", "uri", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// EnsureHostPort takes a URI and ensures that it has a port set, if it doesn't // then it will ensure that port if added. // The address supplied for the Host will be validated when parsed and if the // address is not valid, then it will return an error.
[ "EnsureHostPort", "takes", "a", "URI", "and", "ensures", "that", "it", "has", "a", "port", "set", "if", "it", "doesn", "t", "then", "it", "will", "ensure", "that", "port", "if", "added", ".", "The", "address", "supplied", "for", "the", "Host", "will", "be", "validated", "when", "parsed", "and", "if", "the", "address", "is", "not", "valid", "then", "it", "will", "return", "an", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/connection.go#L199-L210
157,621
juju/juju
state/watcher/helpers.go
Stop
func Stop(w Stopper, t *tomb.Tomb) { if err := w.Stop(); err != nil { if err != tomb.ErrStillAlive && err != tomb.ErrDying { // tomb.Kill() checks for the two errors above // by value, so we shouldn't wrap them, but we // wrap any other error. err = errors.Trace(err) } t.Kill(err) } }
go
func Stop(w Stopper, t *tomb.Tomb) { if err := w.Stop(); err != nil { if err != tomb.ErrStillAlive && err != tomb.ErrDying { // tomb.Kill() checks for the two errors above // by value, so we shouldn't wrap them, but we // wrap any other error. err = errors.Trace(err) } t.Kill(err) } }
[ "func", "Stop", "(", "w", "Stopper", ",", "t", "*", "tomb", ".", "Tomb", ")", "{", "if", "err", ":=", "w", ".", "Stop", "(", ")", ";", "err", "!=", "nil", "{", "if", "err", "!=", "tomb", ".", "ErrStillAlive", "&&", "err", "!=", "tomb", ".", "ErrDying", "{", "// tomb.Kill() checks for the two errors above", "// by value, so we shouldn't wrap them, but we", "// wrap any other error.", "err", "=", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "t", ".", "Kill", "(", "err", ")", "\n", "}", "\n", "}" ]
// Stop stops the watcher. If an error is returned by the // watcher, t is killed with the error.
[ "Stop", "stops", "the", "watcher", ".", "If", "an", "error", "is", "returned", "by", "the", "watcher", "t", "is", "killed", "with", "the", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/watcher/helpers.go#L23-L33
157,622
juju/juju
state/watcher/helpers.go
EnsureErr
func EnsureErr(w Errer) error { err := w.Err() if err == nil { return errors.Errorf("expected an error from %v, got nil", w) } else if err == tomb.ErrStillAlive { return errors.Annotatef(err, "expected %v to be stopped", w) } return errors.Trace(err) }
go
func EnsureErr(w Errer) error { err := w.Err() if err == nil { return errors.Errorf("expected an error from %v, got nil", w) } else if err == tomb.ErrStillAlive { return errors.Annotatef(err, "expected %v to be stopped", w) } return errors.Trace(err) }
[ "func", "EnsureErr", "(", "w", "Errer", ")", "error", "{", "err", ":=", "w", ".", "Err", "(", ")", "\n", "if", "err", "==", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "w", ")", "\n", "}", "else", "if", "err", "==", "tomb", ".", "ErrStillAlive", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "w", ")", "\n", "}", "\n", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}" ]
// EnsureErr returns the error with which w died. Calling it will also // return an error if w is still running or was stopped cleanly.
[ "EnsureErr", "returns", "the", "error", "with", "which", "w", "died", ".", "Calling", "it", "will", "also", "return", "an", "error", "if", "w", "is", "still", "running", "or", "was", "stopped", "cleanly", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/watcher/helpers.go#L37-L45
157,623
juju/juju
apiserver/facades/agent/metricsender/nopsender.go
Send
func (n NopSender) Send(batches []*wireformat.MetricBatch) (*wireformat.Response, error) { var resp = make(wireformat.EnvironmentResponses) for _, batch := range batches { resp.Ack(batch.ModelUUID, batch.UUID) } uuid, err := utils.NewUUID() if err != nil { return nil, err } return &wireformat.Response{UUID: uuid.String(), EnvResponses: resp}, nil }
go
func (n NopSender) Send(batches []*wireformat.MetricBatch) (*wireformat.Response, error) { var resp = make(wireformat.EnvironmentResponses) for _, batch := range batches { resp.Ack(batch.ModelUUID, batch.UUID) } uuid, err := utils.NewUUID() if err != nil { return nil, err } return &wireformat.Response{UUID: uuid.String(), EnvResponses: resp}, nil }
[ "func", "(", "n", "NopSender", ")", "Send", "(", "batches", "[", "]", "*", "wireformat", ".", "MetricBatch", ")", "(", "*", "wireformat", ".", "Response", ",", "error", ")", "{", "var", "resp", "=", "make", "(", "wireformat", ".", "EnvironmentResponses", ")", "\n", "for", "_", ",", "batch", ":=", "range", "batches", "{", "resp", ".", "Ack", "(", "batch", ".", "ModelUUID", ",", "batch", ".", "UUID", ")", "\n", "}", "\n", "uuid", ",", "err", ":=", "utils", ".", "NewUUID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "wireformat", ".", "Response", "{", "UUID", ":", "uuid", ".", "String", "(", ")", ",", "EnvResponses", ":", "resp", "}", ",", "nil", "\n", "}" ]
// Implement the send interface, act like everything is fine.
[ "Implement", "the", "send", "interface", "act", "like", "everything", "is", "fine", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/metricsender/nopsender.go#L17-L27
157,624
juju/juju
apiserver/facades/agent/uniter/lxdprofile.go
NewLXDProfileAPI
func NewLXDProfileAPI( backend LXDProfileBackend, resources facade.Resources, authorizer facade.Authorizer, accessUnit common.GetAuthFunc, logger loggo.Logger, ) *LXDProfileAPI { logger.Tracef("NewLXDProfileAPI called with %s", authorizer.GetAuthTag()) return &LXDProfileAPI{ backend: backend, resources: resources, accessUnit: accessUnit, logger: logger, } }
go
func NewLXDProfileAPI( backend LXDProfileBackend, resources facade.Resources, authorizer facade.Authorizer, accessUnit common.GetAuthFunc, logger loggo.Logger, ) *LXDProfileAPI { logger.Tracef("NewLXDProfileAPI called with %s", authorizer.GetAuthTag()) return &LXDProfileAPI{ backend: backend, resources: resources, accessUnit: accessUnit, logger: logger, } }
[ "func", "NewLXDProfileAPI", "(", "backend", "LXDProfileBackend", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ",", "accessUnit", "common", ".", "GetAuthFunc", ",", "logger", "loggo", ".", "Logger", ",", ")", "*", "LXDProfileAPI", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "authorizer", ".", "GetAuthTag", "(", ")", ")", "\n", "return", "&", "LXDProfileAPI", "{", "backend", ":", "backend", ",", "resources", ":", "resources", ",", "accessUnit", ":", "accessUnit", ",", "logger", ":", "logger", ",", "}", "\n", "}" ]
// NewLXDProfileAPI returns a new LXDProfileAPI. Currently both // GetAuthFuncs can used to determine current permissions.
[ "NewLXDProfileAPI", "returns", "a", "new", "LXDProfileAPI", ".", "Currently", "both", "GetAuthFuncs", "can", "used", "to", "determine", "current", "permissions", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/lxdprofile.go#L50-L64
157,625
juju/juju
apiserver/facades/agent/uniter/lxdprofile.go
NewExternalLXDProfileAPI
func NewExternalLXDProfileAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, accessUnit common.GetAuthFunc, logger loggo.Logger, ) *LXDProfileAPI { return NewLXDProfileAPI( LXDProfileState{st}, resources, authorizer, accessUnit, logger, ) }
go
func NewExternalLXDProfileAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, accessUnit common.GetAuthFunc, logger loggo.Logger, ) *LXDProfileAPI { return NewLXDProfileAPI( LXDProfileState{st}, resources, authorizer, accessUnit, logger, ) }
[ "func", "NewExternalLXDProfileAPI", "(", "st", "*", "state", ".", "State", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ",", "accessUnit", "common", ".", "GetAuthFunc", ",", "logger", "loggo", ".", "Logger", ",", ")", "*", "LXDProfileAPI", "{", "return", "NewLXDProfileAPI", "(", "LXDProfileState", "{", "st", "}", ",", "resources", ",", "authorizer", ",", "accessUnit", ",", "logger", ",", ")", "\n", "}" ]
// NewExternalLXDProfileAPI can be used for API registration.
[ "NewExternalLXDProfileAPI", "can", "be", "used", "for", "API", "registration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/lxdprofile.go#L86-L100
157,626
juju/juju
apiserver/facades/agent/uniter/lxdprofile.go
WatchUnitLXDProfileUpgradeNotifications
func (u *LXDProfileAPI) WatchUnitLXDProfileUpgradeNotifications(args params.Entities) (params.StringsWatchResults, error) { u.logger.Tracef("Starting WatchUnitLXDProfileUpgradeNotifications with %+v", args) result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } canAccess, err := u.accessUnit() if err != nil { return params.StringsWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } if !canAccess(tag) { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } unit, err := u.getLXDProfileUnit(tag) if err != nil { result.Results[i].Error = common.ServerError(err) continue } watcherId, initial, err := u.watchOneChangeUnitLXDProfileUpgradeNotifications(unit) if err != nil { result.Results[i].Error = common.ServerError(err) continue } result.Results[i].StringsWatcherId = watcherId result.Results[i].Changes = initial } return result, nil }
go
func (u *LXDProfileAPI) WatchUnitLXDProfileUpgradeNotifications(args params.Entities) (params.StringsWatchResults, error) { u.logger.Tracef("Starting WatchUnitLXDProfileUpgradeNotifications with %+v", args) result := params.StringsWatchResults{ Results: make([]params.StringsWatchResult, len(args.Entities)), } canAccess, err := u.accessUnit() if err != nil { return params.StringsWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseTag(entity.Tag) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } if !canAccess(tag) { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } unit, err := u.getLXDProfileUnit(tag) if err != nil { result.Results[i].Error = common.ServerError(err) continue } watcherId, initial, err := u.watchOneChangeUnitLXDProfileUpgradeNotifications(unit) if err != nil { result.Results[i].Error = common.ServerError(err) continue } result.Results[i].StringsWatcherId = watcherId result.Results[i].Changes = initial } return result, nil }
[ "func", "(", "u", "*", "LXDProfileAPI", ")", "WatchUnitLXDProfileUpgradeNotifications", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "StringsWatchResults", ",", "error", ")", "{", "u", ".", "logger", ".", "Tracef", "(", "\"", "\"", ",", "args", ")", "\n", "result", ":=", "params", ".", "StringsWatchResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "StringsWatchResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n", "canAccess", ",", "err", ":=", "u", ".", "accessUnit", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "StringsWatchResults", "{", "}", ",", "err", "\n", "}", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n\n", "if", "!", "canAccess", "(", "tag", ")", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "common", ".", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n", "unit", ",", "err", ":=", "u", ".", "getLXDProfileUnit", "(", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "watcherId", ",", "initial", ",", "err", ":=", "u", ".", "watchOneChangeUnitLXDProfileUpgradeNotifications", "(", "unit", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "common", ".", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n\n", "result", ".", "Results", "[", "i", "]", ".", "StringsWatcherId", "=", "watcherId", "\n", "result", ".", "Results", "[", "i", "]", ".", "Changes", "=", "initial", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// WatchUnitLXDProfileUpgradeNotifications returns a StringsWatcher for observing // changes to the lxd profile changes for one unit.
[ "WatchUnitLXDProfileUpgradeNotifications", "returns", "a", "StringsWatcher", "for", "observing", "changes", "to", "the", "lxd", "profile", "changes", "for", "one", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/lxdprofile.go#L104-L139
157,627
juju/juju
apiserver/facades/agent/uniter/lxdprofile.go
RemoveUpgradeCharmProfileData
func (u *LXDProfileAPI) RemoveUpgradeCharmProfileData(args params.Entities) (params.ErrorResults, error) { // This is a canned response for V9 of the API, so that clients will still // be supported and the error for each params entity is nil, along with the // call. return params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Entities)), }, nil }
go
func (u *LXDProfileAPI) RemoveUpgradeCharmProfileData(args params.Entities) (params.ErrorResults, error) { // This is a canned response for V9 of the API, so that clients will still // be supported and the error for each params entity is nil, along with the // call. return params.ErrorResults{ Results: make([]params.ErrorResult, len(args.Entities)), }, nil }
[ "func", "(", "u", "*", "LXDProfileAPI", ")", "RemoveUpgradeCharmProfileData", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "// This is a canned response for V9 of the API, so that clients will still", "// be supported and the error for each params entity is nil, along with the", "// call.", "return", "params", ".", "ErrorResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "ErrorResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", ",", "nil", "\n", "}" ]
// RemoveUpgradeCharmProfileData is intended to clean up the LXDProfile status // to ensure that we start from a clean slate.
[ "RemoveUpgradeCharmProfileData", "is", "intended", "to", "clean", "up", "the", "LXDProfile", "status", "to", "ensure", "that", "we", "start", "from", "a", "clean", "slate", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/uniter/lxdprofile.go#L209-L216
157,628
juju/juju
provider/gce/google/conn_instance.go
AddInstance
func (gce *Connection) AddInstance(spec InstanceSpec) (*Instance, error) { raw := spec.raw() if err := gce.addInstance(raw, spec.Type, spec.AvailabilityZone); err != nil { return nil, errors.Trace(err) } return newInstance(raw, &spec), nil }
go
func (gce *Connection) AddInstance(spec InstanceSpec) (*Instance, error) { raw := spec.raw() if err := gce.addInstance(raw, spec.Type, spec.AvailabilityZone); err != nil { return nil, errors.Trace(err) } return newInstance(raw, &spec), nil }
[ "func", "(", "gce", "*", "Connection", ")", "AddInstance", "(", "spec", "InstanceSpec", ")", "(", "*", "Instance", ",", "error", ")", "{", "raw", ":=", "spec", ".", "raw", "(", ")", "\n", "if", "err", ":=", "gce", ".", "addInstance", "(", "raw", ",", "spec", ".", "Type", ",", "spec", ".", "AvailabilityZone", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "return", "newInstance", "(", "raw", ",", "&", "spec", ")", ",", "nil", "\n", "}" ]
// AddInstance creates a new instance based on the spec's data and // returns it. The instance will be created using the provided // connection and in the provided zone.
[ "AddInstance", "creates", "a", "new", "instance", "based", "on", "the", "spec", "s", "data", "and", "returns", "it", ".", "The", "instance", "will", "be", "created", "using", "the", "provided", "connection", "and", "in", "the", "provided", "zone", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_instance.go#L48-L55
157,629
juju/juju
provider/gce/google/conn_instance.go
Instance
func (gce *Connection) Instance(id, zone string) (Instance, error) { var result Instance raw, err := gce.raw.GetInstance(gce.projectID, zone, id) if err != nil { return result, errors.Trace(err) } result = *newInstance(raw, nil) return result, nil }
go
func (gce *Connection) Instance(id, zone string) (Instance, error) { var result Instance raw, err := gce.raw.GetInstance(gce.projectID, zone, id) if err != nil { return result, errors.Trace(err) } result = *newInstance(raw, nil) return result, nil }
[ "func", "(", "gce", "*", "Connection", ")", "Instance", "(", "id", ",", "zone", "string", ")", "(", "Instance", ",", "error", ")", "{", "var", "result", "Instance", "\n", "raw", ",", "err", ":=", "gce", ".", "raw", ".", "GetInstance", "(", "gce", ".", "projectID", ",", "zone", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "result", "=", "*", "newInstance", "(", "raw", ",", "nil", ")", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Instance gets the up-to-date info about the given instance // and returns it.
[ "Instance", "gets", "the", "up", "-", "to", "-", "date", "info", "about", "the", "given", "instance", "and", "returns", "it", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_instance.go#L59-L67
157,630
juju/juju
provider/gce/google/conn_instance.go
UpdateMetadata
func (gce *Connection) UpdateMetadata(key, value string, ids ...string) error { if len(ids) == 0 { return nil } instances, err := gce.raw.ListInstances(gce.projectID, "") if err != nil { return errors.Annotatef(err, "updating metadata for instances %v", ids) } var failed []string for _, instID := range ids { for _, inst := range instances { if inst.Name == instID { if err := gce.updateInstanceMetadata(inst, key, value); err != nil { failed = append(failed, instID) logger.Errorf("while updating metadata for instance %q (%v=%q): %v", instID, key, value, err) } break } } } if len(failed) != 0 { return errors.Errorf("some metadata updates failed: %v", failed) } return nil }
go
func (gce *Connection) UpdateMetadata(key, value string, ids ...string) error { if len(ids) == 0 { return nil } instances, err := gce.raw.ListInstances(gce.projectID, "") if err != nil { return errors.Annotatef(err, "updating metadata for instances %v", ids) } var failed []string for _, instID := range ids { for _, inst := range instances { if inst.Name == instID { if err := gce.updateInstanceMetadata(inst, key, value); err != nil { failed = append(failed, instID) logger.Errorf("while updating metadata for instance %q (%v=%q): %v", instID, key, value, err) } break } } } if len(failed) != 0 { return errors.Errorf("some metadata updates failed: %v", failed) } return nil }
[ "func", "(", "gce", "*", "Connection", ")", "UpdateMetadata", "(", "key", ",", "value", "string", ",", "ids", "...", "string", ")", "error", "{", "if", "len", "(", "ids", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "instances", ",", "err", ":=", "gce", ".", "raw", ".", "ListInstances", "(", "gce", ".", "projectID", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "ids", ")", "\n", "}", "\n", "var", "failed", "[", "]", "string", "\n", "for", "_", ",", "instID", ":=", "range", "ids", "{", "for", "_", ",", "inst", ":=", "range", "instances", "{", "if", "inst", ".", "Name", "==", "instID", "{", "if", "err", ":=", "gce", ".", "updateInstanceMetadata", "(", "inst", ",", "key", ",", "value", ")", ";", "err", "!=", "nil", "{", "failed", "=", "append", "(", "failed", ",", "instID", ")", "\n", "logger", ".", "Errorf", "(", "\"", "\"", ",", "instID", ",", "key", ",", "value", ",", "err", ")", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "failed", ")", "!=", "0", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "failed", ")", "\n", "}", "\n", "return", "nil", "\n\n", "}" ]
// UpdateMetadata sets the metadata key to the specified value for // all of the instance ids given. The call blocks until all // of the instances are updated or the request fails.
[ "UpdateMetadata", "sets", "the", "metadata", "key", "to", "the", "specified", "value", "for", "all", "of", "the", "instance", "ids", "given", ".", "The", "call", "blocks", "until", "all", "of", "the", "instances", "are", "updated", "or", "the", "request", "fails", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/conn_instance.go#L146-L173
157,631
juju/juju
apiserver/common/upgradeseries.go
NewUpgradeSeriesAPI
func NewUpgradeSeriesAPI( backend UpgradeSeriesBackend, resources facade.Resources, authorizer facade.Authorizer, accessMachine GetAuthFunc, accessUnit GetAuthFunc, logger loggo.Logger, ) *UpgradeSeriesAPI { logger.Tracef("NewUpgradeSeriesAPI called with %s", authorizer.GetAuthTag()) return &UpgradeSeriesAPI{ backend: backend, resources: resources, accessUnitOrMachine: AuthAny(accessUnit, accessMachine), AccessMachine: accessMachine, accessUnit: accessUnit, logger: logger, } }
go
func NewUpgradeSeriesAPI( backend UpgradeSeriesBackend, resources facade.Resources, authorizer facade.Authorizer, accessMachine GetAuthFunc, accessUnit GetAuthFunc, logger loggo.Logger, ) *UpgradeSeriesAPI { logger.Tracef("NewUpgradeSeriesAPI called with %s", authorizer.GetAuthTag()) return &UpgradeSeriesAPI{ backend: backend, resources: resources, accessUnitOrMachine: AuthAny(accessUnit, accessMachine), AccessMachine: accessMachine, accessUnit: accessUnit, logger: logger, } }
[ "func", "NewUpgradeSeriesAPI", "(", "backend", "UpgradeSeriesBackend", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ",", "accessMachine", "GetAuthFunc", ",", "accessUnit", "GetAuthFunc", ",", "logger", "loggo", ".", "Logger", ",", ")", "*", "UpgradeSeriesAPI", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "authorizer", ".", "GetAuthTag", "(", ")", ")", "\n", "return", "&", "UpgradeSeriesAPI", "{", "backend", ":", "backend", ",", "resources", ":", "resources", ",", "accessUnitOrMachine", ":", "AuthAny", "(", "accessUnit", ",", "accessMachine", ")", ",", "AccessMachine", ":", "accessMachine", ",", "accessUnit", ":", "accessUnit", ",", "logger", ":", "logger", ",", "}", "\n", "}" ]
// NewUpgradeSeriesAPI returns a new UpgradeSeriesAPI. Currently both // GetAuthFuncs can used to determine current permissions.
[ "NewUpgradeSeriesAPI", "returns", "a", "new", "UpgradeSeriesAPI", ".", "Currently", "both", "GetAuthFuncs", "can", "used", "to", "determine", "current", "permissions", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/upgradeseries.go#L95-L112
157,632
juju/juju
apiserver/common/upgradeseries.go
WatchUpgradeSeriesNotifications
func (u *UpgradeSeriesAPI) WatchUpgradeSeriesNotifications(args params.Entities) (params.NotifyWatchResults, error) { u.logger.Tracef("Starting WatchUpgradeSeriesNotifications with %+v", args) result := params.NotifyWatchResults{ Results: make([]params.NotifyWatchResult, len(args.Entities)), } canAccess, err := u.accessUnitOrMachine() if err != nil { return params.NotifyWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseTag(entity.Tag) if err != nil { result.Results[i].Error = ServerError(ErrPerm) continue } if !canAccess(tag) { result.Results[i].Error = ServerError(ErrPerm) continue } machine, err := u.GetMachine(tag) if err != nil { result.Results[i].Error = ServerError(err) continue } w, err := machine.WatchUpgradeSeriesNotifications() if err != nil { result.Results[i].Error = ServerError(err) continue } watcherId := u.resources.Register(w) result.Results[i].NotifyWatcherId = watcherId } return result, nil }
go
func (u *UpgradeSeriesAPI) WatchUpgradeSeriesNotifications(args params.Entities) (params.NotifyWatchResults, error) { u.logger.Tracef("Starting WatchUpgradeSeriesNotifications with %+v", args) result := params.NotifyWatchResults{ Results: make([]params.NotifyWatchResult, len(args.Entities)), } canAccess, err := u.accessUnitOrMachine() if err != nil { return params.NotifyWatchResults{}, err } for i, entity := range args.Entities { tag, err := names.ParseTag(entity.Tag) if err != nil { result.Results[i].Error = ServerError(ErrPerm) continue } if !canAccess(tag) { result.Results[i].Error = ServerError(ErrPerm) continue } machine, err := u.GetMachine(tag) if err != nil { result.Results[i].Error = ServerError(err) continue } w, err := machine.WatchUpgradeSeriesNotifications() if err != nil { result.Results[i].Error = ServerError(err) continue } watcherId := u.resources.Register(w) result.Results[i].NotifyWatcherId = watcherId } return result, nil }
[ "func", "(", "u", "*", "UpgradeSeriesAPI", ")", "WatchUpgradeSeriesNotifications", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "NotifyWatchResults", ",", "error", ")", "{", "u", ".", "logger", ".", "Tracef", "(", "\"", "\"", ",", "args", ")", "\n", "result", ":=", "params", ".", "NotifyWatchResults", "{", "Results", ":", "make", "(", "[", "]", "params", ".", "NotifyWatchResult", ",", "len", "(", "args", ".", "Entities", ")", ")", ",", "}", "\n", "canAccess", ",", "err", ":=", "u", ".", "accessUnitOrMachine", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "NotifyWatchResults", "{", "}", ",", "err", "\n", "}", "\n", "for", "i", ",", "entity", ":=", "range", "args", ".", "Entities", "{", "tag", ",", "err", ":=", "names", ".", "ParseTag", "(", "entity", ".", "Tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n\n", "if", "!", "canAccess", "(", "tag", ")", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "ErrPerm", ")", "\n", "continue", "\n", "}", "\n", "machine", ",", "err", ":=", "u", ".", "GetMachine", "(", "tag", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "w", ",", "err", ":=", "machine", ".", "WatchUpgradeSeriesNotifications", "(", ")", "\n", "if", "err", "!=", "nil", "{", "result", ".", "Results", "[", "i", "]", ".", "Error", "=", "ServerError", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "watcherId", ":=", "u", ".", "resources", ".", "Register", "(", "w", ")", "\n", "result", ".", "Results", "[", "i", "]", ".", "NotifyWatcherId", "=", "watcherId", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// WatchUpgradeSeriesNotifications returns a NotifyWatcher for observing changes to upgrade series locks.
[ "WatchUpgradeSeriesNotifications", "returns", "a", "NotifyWatcher", "for", "observing", "changes", "to", "upgrade", "series", "locks", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/upgradeseries.go#L115-L149
157,633
juju/juju
apiserver/common/upgradeseries.go
UpgradeSeriesUnitStatus
func (u *UpgradeSeriesAPI) UpgradeSeriesUnitStatus(args params.Entities) (params.UpgradeSeriesStatusResults, error) { u.logger.Tracef("Starting UpgradeSeriesUnitStatus with %+v", args) return u.unitStatus(args) }
go
func (u *UpgradeSeriesAPI) UpgradeSeriesUnitStatus(args params.Entities) (params.UpgradeSeriesStatusResults, error) { u.logger.Tracef("Starting UpgradeSeriesUnitStatus with %+v", args) return u.unitStatus(args) }
[ "func", "(", "u", "*", "UpgradeSeriesAPI", ")", "UpgradeSeriesUnitStatus", "(", "args", "params", ".", "Entities", ")", "(", "params", ".", "UpgradeSeriesStatusResults", ",", "error", ")", "{", "u", ".", "logger", ".", "Tracef", "(", "\"", "\"", ",", "args", ")", "\n", "return", "u", ".", "unitStatus", "(", "args", ")", "\n", "}" ]
// UpgradeSeriesUnitStatus returns the current preparation status of an // upgrading unit. // If no series upgrade is in progress an error is returned instead.
[ "UpgradeSeriesUnitStatus", "returns", "the", "current", "preparation", "status", "of", "an", "upgrading", "unit", ".", "If", "no", "series", "upgrade", "is", "in", "progress", "an", "error", "is", "returned", "instead", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/upgradeseries.go#L154-L157
157,634
juju/juju
apiserver/common/upgradeseries.go
SetUpgradeSeriesUnitStatus
func (u *UpgradeSeriesAPI) SetUpgradeSeriesUnitStatus( args params.UpgradeSeriesStatusParams, ) (params.ErrorResults, error) { u.logger.Tracef("Starting SetUpgradeSeriesUnitStatus with %+v", args) return u.setUnitStatus(args) }
go
func (u *UpgradeSeriesAPI) SetUpgradeSeriesUnitStatus( args params.UpgradeSeriesStatusParams, ) (params.ErrorResults, error) { u.logger.Tracef("Starting SetUpgradeSeriesUnitStatus with %+v", args) return u.setUnitStatus(args) }
[ "func", "(", "u", "*", "UpgradeSeriesAPI", ")", "SetUpgradeSeriesUnitStatus", "(", "args", "params", ".", "UpgradeSeriesStatusParams", ",", ")", "(", "params", ".", "ErrorResults", ",", "error", ")", "{", "u", ".", "logger", ".", "Tracef", "(", "\"", "\"", ",", "args", ")", "\n", "return", "u", ".", "setUnitStatus", "(", "args", ")", "\n", "}" ]
// SetUpgradeSeriesUnitStatus sets the upgrade series status of the unit. // If no upgrade is in progress an error is returned instead.
[ "SetUpgradeSeriesUnitStatus", "sets", "the", "upgrade", "series", "status", "of", "the", "unit", ".", "If", "no", "upgrade", "is", "in", "progress", "an", "error", "is", "returned", "instead", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/upgradeseries.go#L161-L166
157,635
juju/juju
apiserver/common/upgradeseries.go
NewExternalUpgradeSeriesAPI
func NewExternalUpgradeSeriesAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, accessMachine GetAuthFunc, accessUnit GetAuthFunc, logger loggo.Logger, ) *UpgradeSeriesAPI { return NewUpgradeSeriesAPI(UpgradeSeriesState{st}, resources, authorizer, accessMachine, accessUnit, logger) }
go
func NewExternalUpgradeSeriesAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, accessMachine GetAuthFunc, accessUnit GetAuthFunc, logger loggo.Logger, ) *UpgradeSeriesAPI { return NewUpgradeSeriesAPI(UpgradeSeriesState{st}, resources, authorizer, accessMachine, accessUnit, logger) }
[ "func", "NewExternalUpgradeSeriesAPI", "(", "st", "*", "state", ".", "State", ",", "resources", "facade", ".", "Resources", ",", "authorizer", "facade", ".", "Authorizer", ",", "accessMachine", "GetAuthFunc", ",", "accessUnit", "GetAuthFunc", ",", "logger", "loggo", ".", "Logger", ",", ")", "*", "UpgradeSeriesAPI", "{", "return", "NewUpgradeSeriesAPI", "(", "UpgradeSeriesState", "{", "st", "}", ",", "resources", ",", "authorizer", ",", "accessMachine", ",", "accessUnit", ",", "logger", ")", "\n", "}" ]
// NewExternalUpgradeSeriesAPI can be used for API registration.
[ "NewExternalUpgradeSeriesAPI", "can", "be", "used", "for", "API", "registration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/upgradeseries.go#L192-L201
157,636
juju/juju
apiserver/facades/controller/migrationmaster/facade.go
Watch
func (api *API) Watch() params.NotifyWatchResult { watch := api.backend.WatchForMigration() if _, ok := <-watch.Changes(); ok { return params.NotifyWatchResult{ NotifyWatcherId: api.resources.Register(watch), } } return params.NotifyWatchResult{ Error: common.ServerError(watcher.EnsureErr(watch)), } }
go
func (api *API) Watch() params.NotifyWatchResult { watch := api.backend.WatchForMigration() if _, ok := <-watch.Changes(); ok { return params.NotifyWatchResult{ NotifyWatcherId: api.resources.Register(watch), } } return params.NotifyWatchResult{ Error: common.ServerError(watcher.EnsureErr(watch)), } }
[ "func", "(", "api", "*", "API", ")", "Watch", "(", ")", "params", ".", "NotifyWatchResult", "{", "watch", ":=", "api", ".", "backend", ".", "WatchForMigration", "(", ")", "\n", "if", "_", ",", "ok", ":=", "<-", "watch", ".", "Changes", "(", ")", ";", "ok", "{", "return", "params", ".", "NotifyWatchResult", "{", "NotifyWatcherId", ":", "api", ".", "resources", ".", "Register", "(", "watch", ")", ",", "}", "\n", "}", "\n", "return", "params", ".", "NotifyWatchResult", "{", "Error", ":", "common", ".", "ServerError", "(", "watcher", ".", "EnsureErr", "(", "watch", ")", ")", ",", "}", "\n", "}" ]
// Watch starts watching for an active migration for the model // associated with the API connection. The returned id should be used // with the NotifyWatcher facade to receive events.
[ "Watch", "starts", "watching", "for", "an", "active", "migration", "for", "the", "model", "associated", "with", "the", "API", "connection", ".", "The", "returned", "id", "should", "be", "used", "with", "the", "NotifyWatcher", "facade", "to", "receive", "events", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/facade.go#L62-L72
157,637
juju/juju
apiserver/facades/controller/migrationmaster/facade.go
ModelInfo
func (api *API) ModelInfo() (params.MigrationModelInfo, error) { empty := params.MigrationModelInfo{} name, err := api.backend.ModelName() if err != nil { return empty, errors.Annotate(err, "retrieving model name") } owner, err := api.backend.ModelOwner() if err != nil { return empty, errors.Annotate(err, "retrieving model owner") } vers, err := api.backend.AgentVersion() if err != nil { return empty, errors.Annotate(err, "retrieving agent version") } return params.MigrationModelInfo{ UUID: api.backend.ModelUUID(), Name: name, OwnerTag: owner.String(), AgentVersion: vers, }, nil }
go
func (api *API) ModelInfo() (params.MigrationModelInfo, error) { empty := params.MigrationModelInfo{} name, err := api.backend.ModelName() if err != nil { return empty, errors.Annotate(err, "retrieving model name") } owner, err := api.backend.ModelOwner() if err != nil { return empty, errors.Annotate(err, "retrieving model owner") } vers, err := api.backend.AgentVersion() if err != nil { return empty, errors.Annotate(err, "retrieving agent version") } return params.MigrationModelInfo{ UUID: api.backend.ModelUUID(), Name: name, OwnerTag: owner.String(), AgentVersion: vers, }, nil }
[ "func", "(", "api", "*", "API", ")", "ModelInfo", "(", ")", "(", "params", ".", "MigrationModelInfo", ",", "error", ")", "{", "empty", ":=", "params", ".", "MigrationModelInfo", "{", "}", "\n\n", "name", ",", "err", ":=", "api", ".", "backend", ".", "ModelName", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "empty", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "owner", ",", "err", ":=", "api", ".", "backend", ".", "ModelOwner", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "empty", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "vers", ",", "err", ":=", "api", ".", "backend", ".", "AgentVersion", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "empty", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "params", ".", "MigrationModelInfo", "{", "UUID", ":", "api", ".", "backend", ".", "ModelUUID", "(", ")", ",", "Name", ":", "name", ",", "OwnerTag", ":", "owner", ".", "String", "(", ")", ",", "AgentVersion", ":", "vers", ",", "}", ",", "nil", "\n", "}" ]
// ModelInfo returns essential information about the model to be // migrated.
[ "ModelInfo", "returns", "essential", "information", "about", "the", "model", "to", "be", "migrated", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/facade.go#L115-L139
157,638
juju/juju
apiserver/facades/controller/migrationmaster/facade.go
SetStatusMessage
func (api *API) SetStatusMessage(args params.SetMigrationStatusMessageArgs) error { mig, err := api.backend.LatestMigration() if err != nil { return errors.Annotate(err, "could not get migration") } err = mig.SetStatusMessage(args.Message) return errors.Annotate(err, "failed to set status message") }
go
func (api *API) SetStatusMessage(args params.SetMigrationStatusMessageArgs) error { mig, err := api.backend.LatestMigration() if err != nil { return errors.Annotate(err, "could not get migration") } err = mig.SetStatusMessage(args.Message) return errors.Annotate(err, "failed to set status message") }
[ "func", "(", "api", "*", "API", ")", "SetStatusMessage", "(", "args", "params", ".", "SetMigrationStatusMessageArgs", ")", "error", "{", "mig", ",", "err", ":=", "api", ".", "backend", ".", "LatestMigration", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "err", "=", "mig", ".", "SetStatusMessage", "(", "args", ".", "Message", ")", "\n", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}" ]
// SetStatusMessage sets a human readable status message containing // information about the migration's progress. This will be shown in // status output shown to the end user.
[ "SetStatusMessage", "sets", "a", "human", "readable", "status", "message", "containing", "information", "about", "the", "migration", "s", "progress", ".", "This", "will", "be", "shown", "in", "status", "output", "shown", "to", "the", "end", "user", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/facade.go#L184-L191
157,639
juju/juju
apiserver/facades/controller/migrationmaster/facade.go
Export
func (api *API) Export() (params.SerializedModel, error) { var serialized params.SerializedModel model, err := api.backend.Export() if err != nil { return serialized, err } bytes, err := description.Serialize(model) if err != nil { return serialized, err } serialized.Bytes = bytes serialized.Charms = getUsedCharms(model) serialized.Resources = getUsedResources(model) if model.Type() == string(coremodel.IAAS) { serialized.Tools = getUsedTools(model) } return serialized, nil }
go
func (api *API) Export() (params.SerializedModel, error) { var serialized params.SerializedModel model, err := api.backend.Export() if err != nil { return serialized, err } bytes, err := description.Serialize(model) if err != nil { return serialized, err } serialized.Bytes = bytes serialized.Charms = getUsedCharms(model) serialized.Resources = getUsedResources(model) if model.Type() == string(coremodel.IAAS) { serialized.Tools = getUsedTools(model) } return serialized, nil }
[ "func", "(", "api", "*", "API", ")", "Export", "(", ")", "(", "params", ".", "SerializedModel", ",", "error", ")", "{", "var", "serialized", "params", ".", "SerializedModel", "\n\n", "model", ",", "err", ":=", "api", ".", "backend", ".", "Export", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "serialized", ",", "err", "\n", "}", "\n\n", "bytes", ",", "err", ":=", "description", ".", "Serialize", "(", "model", ")", "\n", "if", "err", "!=", "nil", "{", "return", "serialized", ",", "err", "\n", "}", "\n", "serialized", ".", "Bytes", "=", "bytes", "\n", "serialized", ".", "Charms", "=", "getUsedCharms", "(", "model", ")", "\n", "serialized", ".", "Resources", "=", "getUsedResources", "(", "model", ")", "\n", "if", "model", ".", "Type", "(", ")", "==", "string", "(", "coremodel", ".", "IAAS", ")", "{", "serialized", ".", "Tools", "=", "getUsedTools", "(", "model", ")", "\n", "}", "\n", "return", "serialized", ",", "nil", "\n", "}" ]
// Export serializes the model associated with the API connection.
[ "Export", "serializes", "the", "model", "associated", "with", "the", "API", "connection", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/facade.go#L194-L213
157,640
juju/juju
apiserver/facades/controller/migrationmaster/facade.go
Reap
func (api *API) Reap() error { migration, err := api.backend.LatestMigration() if err != nil { return errors.Trace(err) } err = api.backend.RemoveExportingModelDocs() if err != nil { return errors.Trace(err) } // We need to mark the migration as complete here, since removing // the model might kill the worker before it has a chance to set // the phase itself. return errors.Trace(migration.SetPhase(coremigration.DONE)) }
go
func (api *API) Reap() error { migration, err := api.backend.LatestMigration() if err != nil { return errors.Trace(err) } err = api.backend.RemoveExportingModelDocs() if err != nil { return errors.Trace(err) } // We need to mark the migration as complete here, since removing // the model might kill the worker before it has a chance to set // the phase itself. return errors.Trace(migration.SetPhase(coremigration.DONE)) }
[ "func", "(", "api", "*", "API", ")", "Reap", "(", ")", "error", "{", "migration", ",", "err", ":=", "api", ".", "backend", ".", "LatestMigration", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "err", "=", "api", ".", "backend", ".", "RemoveExportingModelDocs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// We need to mark the migration as complete here, since removing", "// the model might kill the worker before it has a chance to set", "// the phase itself.", "return", "errors", ".", "Trace", "(", "migration", ".", "SetPhase", "(", "coremigration", ".", "DONE", ")", ")", "\n", "}" ]
// Reap removes all documents for the model associated with the API // connection.
[ "Reap", "removes", "all", "documents", "for", "the", "model", "associated", "with", "the", "API", "connection", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/facade.go#L217-L230
157,641
juju/juju
apiserver/facades/controller/migrationmaster/facade.go
WatchMinionReports
func (api *API) WatchMinionReports() params.NotifyWatchResult { mig, err := api.backend.LatestMigration() if err != nil { return params.NotifyWatchResult{Error: common.ServerError(err)} } watch, err := mig.WatchMinionReports() if err != nil { return params.NotifyWatchResult{Error: common.ServerError(err)} } if _, ok := <-watch.Changes(); ok { return params.NotifyWatchResult{ NotifyWatcherId: api.resources.Register(watch), } } return params.NotifyWatchResult{ Error: common.ServerError(watcher.EnsureErr(watch)), } }
go
func (api *API) WatchMinionReports() params.NotifyWatchResult { mig, err := api.backend.LatestMigration() if err != nil { return params.NotifyWatchResult{Error: common.ServerError(err)} } watch, err := mig.WatchMinionReports() if err != nil { return params.NotifyWatchResult{Error: common.ServerError(err)} } if _, ok := <-watch.Changes(); ok { return params.NotifyWatchResult{ NotifyWatcherId: api.resources.Register(watch), } } return params.NotifyWatchResult{ Error: common.ServerError(watcher.EnsureErr(watch)), } }
[ "func", "(", "api", "*", "API", ")", "WatchMinionReports", "(", ")", "params", ".", "NotifyWatchResult", "{", "mig", ",", "err", ":=", "api", ".", "backend", ".", "LatestMigration", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "NotifyWatchResult", "{", "Error", ":", "common", ".", "ServerError", "(", "err", ")", "}", "\n", "}", "\n\n", "watch", ",", "err", ":=", "mig", ".", "WatchMinionReports", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "NotifyWatchResult", "{", "Error", ":", "common", ".", "ServerError", "(", "err", ")", "}", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "<-", "watch", ".", "Changes", "(", ")", ";", "ok", "{", "return", "params", ".", "NotifyWatchResult", "{", "NotifyWatcherId", ":", "api", ".", "resources", ".", "Register", "(", "watch", ")", ",", "}", "\n", "}", "\n", "return", "params", ".", "NotifyWatchResult", "{", "Error", ":", "common", ".", "ServerError", "(", "watcher", ".", "EnsureErr", "(", "watch", ")", ")", ",", "}", "\n", "}" ]
// WatchMinionReports sets up a watcher which reports when a report // for a migration minion has arrived.
[ "WatchMinionReports", "sets", "up", "a", "watcher", "which", "reports", "when", "a", "report", "for", "a", "migration", "minion", "has", "arrived", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/migrationmaster/facade.go#L234-L253
157,642
juju/juju
api/controller/gui.go
GUIArchives
func (c *Client) GUIArchives() ([]params.GUIArchiveVersion, error) { httpClient, err := c.facade.RawAPICaller().HTTPClient() if err != nil { return nil, errors.Annotate(err, "cannot retrieve HTTP client") } var resp params.GUIArchiveResponse if err = httpClient.Get(guiArchivePath, &resp); err != nil { return nil, errors.Annotate(err, "cannot retrieve GUI archives info") } return resp.Versions, nil }
go
func (c *Client) GUIArchives() ([]params.GUIArchiveVersion, error) { httpClient, err := c.facade.RawAPICaller().HTTPClient() if err != nil { return nil, errors.Annotate(err, "cannot retrieve HTTP client") } var resp params.GUIArchiveResponse if err = httpClient.Get(guiArchivePath, &resp); err != nil { return nil, errors.Annotate(err, "cannot retrieve GUI archives info") } return resp.Versions, nil }
[ "func", "(", "c", "*", "Client", ")", "GUIArchives", "(", ")", "(", "[", "]", "params", ".", "GUIArchiveVersion", ",", "error", ")", "{", "httpClient", ",", "err", ":=", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ".", "HTTPClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "var", "resp", "params", ".", "GUIArchiveResponse", "\n", "if", "err", "=", "httpClient", ".", "Get", "(", "guiArchivePath", ",", "&", "resp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ".", "Versions", ",", "nil", "\n", "}" ]
// GUIArchives retrieves information about Juju GUI archives currently present // in the Juju controller.
[ "GUIArchives", "retrieves", "information", "about", "Juju", "GUI", "archives", "currently", "present", "in", "the", "Juju", "controller", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/controller/gui.go#L26-L36
157,643
juju/juju
api/controller/gui.go
UploadGUIArchive
func (c *Client) UploadGUIArchive(r io.ReadSeeker, hash string, size int64, vers version.Number) (current bool, err error) { // Prepare the request. v := url.Values{} v.Set("version", vers.String()) v.Set("hash", hash) req, err := http.NewRequest("POST", guiArchivePath+"?"+v.Encode(), nil) if err != nil { return false, errors.Annotate(err, "cannot create upload request") } req.Header.Set("Content-Type", "application/x-tar-bzip2") req.ContentLength = size // Retrieve a client and send the request. httpClient, err := c.facade.RawAPICaller().HTTPClient() if err != nil { return false, errors.Annotate(err, "cannot retrieve HTTP client") } var resp params.GUIArchiveVersion if err = httpClient.Do(req, r, &resp); err != nil { return false, errors.Annotate(err, "cannot upload the GUI archive") } return resp.Current, nil }
go
func (c *Client) UploadGUIArchive(r io.ReadSeeker, hash string, size int64, vers version.Number) (current bool, err error) { // Prepare the request. v := url.Values{} v.Set("version", vers.String()) v.Set("hash", hash) req, err := http.NewRequest("POST", guiArchivePath+"?"+v.Encode(), nil) if err != nil { return false, errors.Annotate(err, "cannot create upload request") } req.Header.Set("Content-Type", "application/x-tar-bzip2") req.ContentLength = size // Retrieve a client and send the request. httpClient, err := c.facade.RawAPICaller().HTTPClient() if err != nil { return false, errors.Annotate(err, "cannot retrieve HTTP client") } var resp params.GUIArchiveVersion if err = httpClient.Do(req, r, &resp); err != nil { return false, errors.Annotate(err, "cannot upload the GUI archive") } return resp.Current, nil }
[ "func", "(", "c", "*", "Client", ")", "UploadGUIArchive", "(", "r", "io", ".", "ReadSeeker", ",", "hash", "string", ",", "size", "int64", ",", "vers", "version", ".", "Number", ")", "(", "current", "bool", ",", "err", "error", ")", "{", "// Prepare the request.", "v", ":=", "url", ".", "Values", "{", "}", "\n", "v", ".", "Set", "(", "\"", "\"", ",", "vers", ".", "String", "(", ")", ")", "\n", "v", ".", "Set", "(", "\"", "\"", ",", "hash", ")", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "guiArchivePath", "+", "\"", "\"", "+", "v", ".", "Encode", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "ContentLength", "=", "size", "\n\n", "// Retrieve a client and send the request.", "httpClient", ",", "err", ":=", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ".", "HTTPClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "var", "resp", "params", ".", "GUIArchiveVersion", "\n", "if", "err", "=", "httpClient", ".", "Do", "(", "req", ",", "r", ",", "&", "resp", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "resp", ".", "Current", ",", "nil", "\n", "}" ]
// UploadGUIArchive uploads a GUI archive to the controller over HTTPS, and // reports about whether the upload updated the current GUI served by Juju.
[ "UploadGUIArchive", "uploads", "a", "GUI", "archive", "to", "the", "controller", "over", "HTTPS", "and", "reports", "about", "whether", "the", "upload", "updated", "the", "current", "GUI", "served", "by", "Juju", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/controller/gui.go#L40-L62
157,644
juju/juju
api/controller/gui.go
SelectGUIVersion
func (c *Client) SelectGUIVersion(vers version.Number) error { // Prepare the request. req, err := http.NewRequest("PUT", guiVersionPath, nil) if err != nil { return errors.Annotate(err, "cannot create PUT request") } req.Header.Set("Content-Type", params.ContentTypeJSON) content, err := json.Marshal(params.GUIVersionRequest{ Version: vers, }) if err != nil { errors.Annotate(err, "cannot marshal request body") } // Retrieve a client and send the request. httpClient, err := c.facade.RawAPICaller().HTTPClient() if err != nil { return errors.Annotate(err, "cannot retrieve HTTP client") } if err = httpClient.Do(req, bytes.NewReader(content), nil); err != nil { return errors.Annotate(err, "cannot select GUI version") } return nil }
go
func (c *Client) SelectGUIVersion(vers version.Number) error { // Prepare the request. req, err := http.NewRequest("PUT", guiVersionPath, nil) if err != nil { return errors.Annotate(err, "cannot create PUT request") } req.Header.Set("Content-Type", params.ContentTypeJSON) content, err := json.Marshal(params.GUIVersionRequest{ Version: vers, }) if err != nil { errors.Annotate(err, "cannot marshal request body") } // Retrieve a client and send the request. httpClient, err := c.facade.RawAPICaller().HTTPClient() if err != nil { return errors.Annotate(err, "cannot retrieve HTTP client") } if err = httpClient.Do(req, bytes.NewReader(content), nil); err != nil { return errors.Annotate(err, "cannot select GUI version") } return nil }
[ "func", "(", "c", "*", "Client", ")", "SelectGUIVersion", "(", "vers", "version", ".", "Number", ")", "error", "{", "// Prepare the request.", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "guiVersionPath", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "params", ".", "ContentTypeJSON", ")", "\n", "content", ",", "err", ":=", "json", ".", "Marshal", "(", "params", ".", "GUIVersionRequest", "{", "Version", ":", "vers", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Retrieve a client and send the request.", "httpClient", ",", "err", ":=", "c", ".", "facade", ".", "RawAPICaller", "(", ")", ".", "HTTPClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "err", "=", "httpClient", ".", "Do", "(", "req", ",", "bytes", ".", "NewReader", "(", "content", ")", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SelectGUIVersion selects which version of the Juju GUI is served by the // controller.
[ "SelectGUIVersion", "selects", "which", "version", "of", "the", "Juju", "GUI", "is", "served", "by", "the", "controller", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/controller/gui.go#L66-L89
157,645
juju/juju
cmd/juju/application/scaleapplication.go
NewScaleApplicationCommand
func NewScaleApplicationCommand() modelcmd.ModelCommand { cmd := &scaleApplicationCommand{} cmd.newAPIFunc = func() (scaleApplicationAPI, error) { root, err := cmd.NewAPIRoot() if err != nil { return nil, errors.Trace(err) } return application.NewClient(root), nil } return modelcmd.Wrap(cmd) }
go
func NewScaleApplicationCommand() modelcmd.ModelCommand { cmd := &scaleApplicationCommand{} cmd.newAPIFunc = func() (scaleApplicationAPI, error) { root, err := cmd.NewAPIRoot() if err != nil { return nil, errors.Trace(err) } return application.NewClient(root), nil } return modelcmd.Wrap(cmd) }
[ "func", "NewScaleApplicationCommand", "(", ")", "modelcmd", ".", "ModelCommand", "{", "cmd", ":=", "&", "scaleApplicationCommand", "{", "}", "\n", "cmd", ".", "newAPIFunc", "=", "func", "(", ")", "(", "scaleApplicationAPI", ",", "error", ")", "{", "root", ",", "err", ":=", "cmd", ".", "NewAPIRoot", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "application", ".", "NewClient", "(", "root", ")", ",", "nil", "\n", "}", "\n", "return", "modelcmd", ".", "Wrap", "(", "cmd", ")", "\n", "}" ]
// NewScaleApplicationCommand returns a command which scales an application's units.
[ "NewScaleApplicationCommand", "returns", "a", "command", "which", "scales", "an", "application", "s", "units", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/scaleapplication.go#L20-L30
157,646
juju/juju
mongo/mongo.go
NewerThan
func (v Version) NewerThan(ver Version) int { if v == MongoUpgrade || ver == MongoUpgrade { return 0 } if v.Major > ver.Major { return 1 } if v.Major < ver.Major { return -1 } if v.Minor > ver.Minor { return 1 } if v.Minor < ver.Minor { return -1 } if v.Point > ver.Point { return 1 } if v.Point < ver.Point { return -1 } return 0 }
go
func (v Version) NewerThan(ver Version) int { if v == MongoUpgrade || ver == MongoUpgrade { return 0 } if v.Major > ver.Major { return 1 } if v.Major < ver.Major { return -1 } if v.Minor > ver.Minor { return 1 } if v.Minor < ver.Minor { return -1 } if v.Point > ver.Point { return 1 } if v.Point < ver.Point { return -1 } return 0 }
[ "func", "(", "v", "Version", ")", "NewerThan", "(", "ver", "Version", ")", "int", "{", "if", "v", "==", "MongoUpgrade", "||", "ver", "==", "MongoUpgrade", "{", "return", "0", "\n", "}", "\n", "if", "v", ".", "Major", ">", "ver", ".", "Major", "{", "return", "1", "\n", "}", "\n", "if", "v", ".", "Major", "<", "ver", ".", "Major", "{", "return", "-", "1", "\n", "}", "\n", "if", "v", ".", "Minor", ">", "ver", ".", "Minor", "{", "return", "1", "\n", "}", "\n", "if", "v", ".", "Minor", "<", "ver", ".", "Minor", "{", "return", "-", "1", "\n", "}", "\n", "if", "v", ".", "Point", ">", "ver", ".", "Point", "{", "return", "1", "\n", "}", "\n", "if", "v", ".", "Point", "<", "ver", ".", "Point", "{", "return", "-", "1", "\n", "}", "\n", "return", "0", "\n", "}" ]
// NewerThan will return 1 if the passed version is older than // v, 0 if they are equal (or ver is a special case such as // Upgrading and -1 if ver is newer.
[ "NewerThan", "will", "return", "1", "if", "the", "passed", "version", "is", "older", "than", "v", "0", "if", "they", "are", "equal", "(", "or", "ver", "is", "a", "special", "case", "such", "as", "Upgrading", "and", "-", "1", "if", "ver", "is", "newer", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L106-L129
157,647
juju/juju
mongo/mongo.go
String
func (v Version) String() string { s := fmt.Sprintf("%d.%d", v.Major, v.Minor) if v.Point > 0 { s = fmt.Sprintf("%s.%d", s, v.Point) } if v.Patch != "" { s = fmt.Sprintf("%s.%s", s, v.Patch) } if v.StorageEngine != "" { s = fmt.Sprintf("%s/%s", s, v.StorageEngine) } return s }
go
func (v Version) String() string { s := fmt.Sprintf("%d.%d", v.Major, v.Minor) if v.Point > 0 { s = fmt.Sprintf("%s.%d", s, v.Point) } if v.Patch != "" { s = fmt.Sprintf("%s.%s", s, v.Patch) } if v.StorageEngine != "" { s = fmt.Sprintf("%s/%s", s, v.StorageEngine) } return s }
[ "func", "(", "v", "Version", ")", "String", "(", ")", "string", "{", "s", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ".", "Major", ",", "v", ".", "Minor", ")", "\n", "if", "v", ".", "Point", ">", "0", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ",", "v", ".", "Point", ")", "\n", "}", "\n", "if", "v", ".", "Patch", "!=", "\"", "\"", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ",", "v", ".", "Patch", ")", "\n", "}", "\n", "if", "v", ".", "StorageEngine", "!=", "\"", "\"", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ",", "v", ".", "StorageEngine", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// String serializes the version into a string.
[ "String", "serializes", "the", "version", "into", "a", "string", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L202-L214
157,648
juju/juju
mongo/mongo.go
JujuMongodPath
func JujuMongodPath(v Version) string { return fmt.Sprintf("/usr/lib/juju/mongo%d.%d/bin/mongod", v.Major, v.Minor) }
go
func JujuMongodPath(v Version) string { return fmt.Sprintf("/usr/lib/juju/mongo%d.%d/bin/mongod", v.Major, v.Minor) }
[ "func", "JujuMongodPath", "(", "v", "Version", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ".", "Major", ",", "v", ".", "Minor", ")", "\n", "}" ]
// JujuMongodPath returns the path for the mongod binary // with the specified version.
[ "JujuMongodPath", "returns", "the", "path", "for", "the", "mongod", "binary", "with", "the", "specified", "version", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L218-L220
157,649
juju/juju
mongo/mongo.go
IsMaster
func IsMaster(session *mgo.Session, obj WithAddresses) (bool, error) { addrs := obj.Addresses() masterHostPort, err := replicaset.MasterHostPort(session) // If the replica set has not been configured, then we // can have only one master and the caller must // be that master. if err == replicaset.ErrMasterNotConfigured { return true, nil } if err != nil { return false, err } masterAddr, _, err := net.SplitHostPort(masterHostPort) if err != nil { return false, err } for _, addr := range addrs { if addr.Value == masterAddr { return true, nil } } return false, nil }
go
func IsMaster(session *mgo.Session, obj WithAddresses) (bool, error) { addrs := obj.Addresses() masterHostPort, err := replicaset.MasterHostPort(session) // If the replica set has not been configured, then we // can have only one master and the caller must // be that master. if err == replicaset.ErrMasterNotConfigured { return true, nil } if err != nil { return false, err } masterAddr, _, err := net.SplitHostPort(masterHostPort) if err != nil { return false, err } for _, addr := range addrs { if addr.Value == masterAddr { return true, nil } } return false, nil }
[ "func", "IsMaster", "(", "session", "*", "mgo", ".", "Session", ",", "obj", "WithAddresses", ")", "(", "bool", ",", "error", ")", "{", "addrs", ":=", "obj", ".", "Addresses", "(", ")", "\n\n", "masterHostPort", ",", "err", ":=", "replicaset", ".", "MasterHostPort", "(", "session", ")", "\n\n", "// If the replica set has not been configured, then we", "// can have only one master and the caller must", "// be that master.", "if", "err", "==", "replicaset", ".", "ErrMasterNotConfigured", "{", "return", "true", ",", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "masterAddr", ",", "_", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "masterHostPort", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "addr", ":=", "range", "addrs", "{", "if", "addr", ".", "Value", "==", "masterAddr", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// IsMaster returns a boolean that represents whether the given // machine's peer address is the primary mongo host for the replicaset
[ "IsMaster", "returns", "a", "boolean", "that", "represents", "whether", "the", "given", "machine", "s", "peer", "address", "is", "the", "primary", "mongo", "host", "for", "the", "replicaset" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L270-L296
157,650
juju/juju
mongo/mongo.go
SelectPeerAddress
func SelectPeerAddress(addrs []network.Address) string { // ScopeMachineLocal addresses are never suitable for mongo peers, // as each controller runs on a separate machine. const allowMachineLocal = false // The second bool result is ignored intentionally (we return an empty // string if no suitable address is available.) addr, _ := network.SelectControllerAddress(addrs, allowMachineLocal) return addr.Value }
go
func SelectPeerAddress(addrs []network.Address) string { // ScopeMachineLocal addresses are never suitable for mongo peers, // as each controller runs on a separate machine. const allowMachineLocal = false // The second bool result is ignored intentionally (we return an empty // string if no suitable address is available.) addr, _ := network.SelectControllerAddress(addrs, allowMachineLocal) return addr.Value }
[ "func", "SelectPeerAddress", "(", "addrs", "[", "]", "network", ".", "Address", ")", "string", "{", "// ScopeMachineLocal addresses are never suitable for mongo peers,", "// as each controller runs on a separate machine.", "const", "allowMachineLocal", "=", "false", "\n\n", "// The second bool result is ignored intentionally (we return an empty", "// string if no suitable address is available.)", "addr", ",", "_", ":=", "network", ".", "SelectControllerAddress", "(", "addrs", ",", "allowMachineLocal", ")", "\n", "return", "addr", ".", "Value", "\n", "}" ]
// SelectPeerAddress returns the address to use as the mongo replica set peer // address by selecting it from the given addresses. If no addresses are // available an empty string is returned.
[ "SelectPeerAddress", "returns", "the", "address", "to", "use", "as", "the", "mongo", "replica", "set", "peer", "address", "by", "selecting", "it", "from", "the", "given", "addresses", ".", "If", "no", "addresses", "are", "available", "an", "empty", "string", "is", "returned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L301-L310
157,651
juju/juju
mongo/mongo.go
Path
func Path(version Version) (string, error) { return mongoPath(version, os.Stat, exec.LookPath) }
go
func Path(version Version) (string, error) { return mongoPath(version, os.Stat, exec.LookPath) }
[ "func", "Path", "(", "version", "Version", ")", "(", "string", ",", "error", ")", "{", "return", "mongoPath", "(", "version", ",", "os", ".", "Stat", ",", "exec", ".", "LookPath", ")", "\n", "}" ]
// Path returns the executable path to be used to run mongod on this // machine. If the juju-bundled version of mongo exists, it will return that // path, otherwise it will return the command to run mongod from the path.
[ "Path", "returns", "the", "executable", "path", "to", "be", "used", "to", "run", "mongod", "on", "this", "machine", ".", "If", "the", "juju", "-", "bundled", "version", "of", "mongo", "exists", "it", "will", "return", "that", "path", "otherwise", "it", "will", "return", "the", "command", "to", "run", "mongod", "from", "the", "path", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L328-L330
157,652
juju/juju
mongo/mongo.go
NewMemoryProfile
func NewMemoryProfile(m string) (MemoryProfile, error) { mp := MemoryProfile(m) if err := mp.Validate(); err != nil { return MemoryProfile(""), err } return mp, nil }
go
func NewMemoryProfile(m string) (MemoryProfile, error) { mp := MemoryProfile(m) if err := mp.Validate(); err != nil { return MemoryProfile(""), err } return mp, nil }
[ "func", "NewMemoryProfile", "(", "m", "string", ")", "(", "MemoryProfile", ",", "error", ")", "{", "mp", ":=", "MemoryProfile", "(", "m", ")", "\n", "if", "err", ":=", "mp", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "MemoryProfile", "(", "\"", "\"", ")", ",", "err", "\n", "}", "\n", "return", "mp", ",", "nil", "\n", "}" ]
// NewMemoryProfile returns a Memory Profile from the passed value.
[ "NewMemoryProfile", "returns", "a", "Memory", "Profile", "from", "the", "passed", "value", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L389-L395
157,653
juju/juju
mongo/mongo.go
packagesForSeries
func packagesForSeries(series string) ([]string, []string) { switch series { case "precise", "centos7": return []string{"mongodb-server"}, []string{} case "trusty": return []string{"juju-mongodb"}, []string{} case "xenial", "artful": return []string{JujuMongoPackage, JujuMongoToolsPackage}, []string{} default: // Bionic and newer return []string{"mongodb-server-core", "mongodb-clients"}, []string{} } }
go
func packagesForSeries(series string) ([]string, []string) { switch series { case "precise", "centos7": return []string{"mongodb-server"}, []string{} case "trusty": return []string{"juju-mongodb"}, []string{} case "xenial", "artful": return []string{JujuMongoPackage, JujuMongoToolsPackage}, []string{} default: // Bionic and newer return []string{"mongodb-server-core", "mongodb-clients"}, []string{} } }
[ "func", "packagesForSeries", "(", "series", "string", ")", "(", "[", "]", "string", ",", "[", "]", "string", ")", "{", "switch", "series", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "[", "]", "string", "{", "\"", "\"", "}", ",", "[", "]", "string", "{", "}", "\n", "case", "\"", "\"", ":", "return", "[", "]", "string", "{", "\"", "\"", "}", ",", "[", "]", "string", "{", "}", "\n", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "[", "]", "string", "{", "JujuMongoPackage", ",", "JujuMongoToolsPackage", "}", ",", "[", "]", "string", "{", "}", "\n", "default", ":", "// Bionic and newer", "return", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "[", "]", "string", "{", "}", "\n", "}", "\n", "}" ]
// packagesForSeries returns the name of the mongo package for the series // of the machine that it is going to be running on plus a fallback for // options where the package is going to be ready eventually but might not // yet be.
[ "packagesForSeries", "returns", "the", "name", "of", "the", "mongo", "package", "for", "the", "series", "of", "the", "machine", "that", "it", "is", "going", "to", "be", "running", "on", "plus", "a", "fallback", "for", "options", "where", "the", "package", "is", "going", "to", "be", "ready", "eventually", "but", "might", "not", "yet", "be", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/mongo.go#L779-L791
157,654
juju/juju
worker/machiner/manifold.go
Manifold
func Manifold(config ManifoldConfig) dependency.Manifold { return dependency.Manifold{ Inputs: []string{ config.AgentName, config.APICallerName, config.FanConfigurerName, }, Start: func(context dependency.Context) (worker.Worker, error) { var agent agent.Agent if err := context.Get(config.AgentName, &agent); err != nil { return nil, err } var apiCaller base.APICaller if err := context.Get(config.APICallerName, &apiCaller); err != nil { return nil, err } var fanConfigurerReady bool if err := context.Get(config.FanConfigurerName, &fanConfigurerReady); err != nil { return nil, err } if !fanConfigurerReady { return nil, dependency.ErrMissing } return newWorker(agent, apiCaller) }, } }
go
func Manifold(config ManifoldConfig) dependency.Manifold { return dependency.Manifold{ Inputs: []string{ config.AgentName, config.APICallerName, config.FanConfigurerName, }, Start: func(context dependency.Context) (worker.Worker, error) { var agent agent.Agent if err := context.Get(config.AgentName, &agent); err != nil { return nil, err } var apiCaller base.APICaller if err := context.Get(config.APICallerName, &apiCaller); err != nil { return nil, err } var fanConfigurerReady bool if err := context.Get(config.FanConfigurerName, &fanConfigurerReady); err != nil { return nil, err } if !fanConfigurerReady { return nil, dependency.ErrMissing } return newWorker(agent, apiCaller) }, } }
[ "func", "Manifold", "(", "config", "ManifoldConfig", ")", "dependency", ".", "Manifold", "{", "return", "dependency", ".", "Manifold", "{", "Inputs", ":", "[", "]", "string", "{", "config", ".", "AgentName", ",", "config", ".", "APICallerName", ",", "config", ".", "FanConfigurerName", ",", "}", ",", "Start", ":", "func", "(", "context", "dependency", ".", "Context", ")", "(", "worker", ".", "Worker", ",", "error", ")", "{", "var", "agent", "agent", ".", "Agent", "\n", "if", "err", ":=", "context", ".", "Get", "(", "config", ".", "AgentName", ",", "&", "agent", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "apiCaller", "base", ".", "APICaller", "\n", "if", "err", ":=", "context", ".", "Get", "(", "config", ".", "APICallerName", ",", "&", "apiCaller", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "fanConfigurerReady", "bool", "\n", "if", "err", ":=", "context", ".", "Get", "(", "config", ".", "FanConfigurerName", ",", "&", "fanConfigurerReady", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "!", "fanConfigurerReady", "{", "return", "nil", ",", "dependency", ".", "ErrMissing", "\n", "}", "\n", "return", "newWorker", "(", "agent", ",", "apiCaller", ")", "\n", "}", ",", "}", "\n", "}" ]
// Manifold returns a dependency manifold that runs a machiner worker, using // the resource names defined in the supplied config.
[ "Manifold", "returns", "a", "dependency", "manifold", "that", "runs", "a", "machiner", "worker", "using", "the", "resource", "names", "defined", "in", "the", "supplied", "config", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/machiner/manifold.go#L28-L54
157,655
juju/juju
state/application.go
charmConfigKey
func (a *Application) charmConfigKey() string { return applicationCharmConfigKey(a.doc.Name, a.doc.CharmURL) }
go
func (a *Application) charmConfigKey() string { return applicationCharmConfigKey(a.doc.Name, a.doc.CharmURL) }
[ "func", "(", "a", "*", "Application", ")", "charmConfigKey", "(", ")", "string", "{", "return", "applicationCharmConfigKey", "(", "a", ".", "doc", ".", "Name", ",", "a", ".", "doc", ".", "CharmURL", ")", "\n", "}" ]
// charmConfigKey returns the charm-version-specific settings collection // key for the application.
[ "charmConfigKey", "returns", "the", "charm", "-", "version", "-", "specific", "settings", "collection", "key", "for", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L126-L128
157,656
juju/juju
state/application.go
storageConstraintsKey
func (a *Application) storageConstraintsKey() string { return applicationStorageConstraintsKey(a.doc.Name, a.doc.CharmURL) }
go
func (a *Application) storageConstraintsKey() string { return applicationStorageConstraintsKey(a.doc.Name, a.doc.CharmURL) }
[ "func", "(", "a", "*", "Application", ")", "storageConstraintsKey", "(", ")", "string", "{", "return", "applicationStorageConstraintsKey", "(", "a", ".", "doc", ".", "Name", ",", "a", ".", "doc", ".", "CharmURL", ")", "\n", "}" ]
// storageConstraintsKey returns the charm-version-specific storage // constraints collection key for the application.
[ "storageConstraintsKey", "returns", "the", "charm", "-", "version", "-", "specific", "storage", "constraints", "collection", "key", "for", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L146-L148
157,657
juju/juju
state/application.go
deviceConstraintsKey
func (a *Application) deviceConstraintsKey() string { return applicationDeviceConstraintsKey(a.doc.Name, a.doc.CharmURL) }
go
func (a *Application) deviceConstraintsKey() string { return applicationDeviceConstraintsKey(a.doc.Name, a.doc.CharmURL) }
[ "func", "(", "a", "*", "Application", ")", "deviceConstraintsKey", "(", ")", "string", "{", "return", "applicationDeviceConstraintsKey", "(", "a", ".", "doc", ".", "Name", ",", "a", ".", "doc", ".", "CharmURL", ")", "\n", "}" ]
// deviceConstraintsKey returns the charm-version-specific device // constraints collection key for the application.
[ "deviceConstraintsKey", "returns", "the", "charm", "-", "version", "-", "specific", "device", "constraints", "collection", "key", "for", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L156-L158
157,658
juju/juju
state/application.go
AgentTools
func (a *Application) AgentTools() (*tools.Tools, error) { if a.doc.Tools == nil { return nil, errors.NotFoundf("operator image metadata for application %q", a) } result := *a.doc.Tools return &result, nil }
go
func (a *Application) AgentTools() (*tools.Tools, error) { if a.doc.Tools == nil { return nil, errors.NotFoundf("operator image metadata for application %q", a) } result := *a.doc.Tools return &result, nil }
[ "func", "(", "a", "*", "Application", ")", "AgentTools", "(", ")", "(", "*", "tools", ".", "Tools", ",", "error", ")", "{", "if", "a", ".", "doc", ".", "Tools", "==", "nil", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "a", ")", "\n", "}", "\n", "result", ":=", "*", "a", ".", "doc", ".", "Tools", "\n", "return", "&", "result", ",", "nil", "\n", "}" ]
// AgentTools returns the tools that the operator is currently running. // It an error that satisfies errors.IsNotFound if the tools have not // yet been set.
[ "AgentTools", "returns", "the", "tools", "that", "the", "operator", "is", "currently", "running", ".", "It", "an", "error", "that", "satisfies", "errors", ".", "IsNotFound", "if", "the", "tools", "have", "not", "yet", "been", "set", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L173-L179
157,659
juju/juju
state/application.go
Destroy
func (a *Application) Destroy() (err error) { defer func() { logger.Tracef("Application(%s).Destroy() => %v", a.doc.Name, err) if err == nil { // This is a white lie; the document might actually be removed. a.doc.Life = Dying } }() return a.st.ApplyOperation(a.DestroyOperation()) }
go
func (a *Application) Destroy() (err error) { defer func() { logger.Tracef("Application(%s).Destroy() => %v", a.doc.Name, err) if err == nil { // This is a white lie; the document might actually be removed. a.doc.Life = Dying } }() return a.st.ApplyOperation(a.DestroyOperation()) }
[ "func", "(", "a", "*", "Application", ")", "Destroy", "(", ")", "(", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ",", "err", ")", "\n", "if", "err", "==", "nil", "{", "// This is a white lie; the document might actually be removed.", "a", ".", "doc", ".", "Life", "=", "Dying", "\n", "}", "\n", "}", "(", ")", "\n", "return", "a", ".", "st", ".", "ApplyOperation", "(", "a", ".", "DestroyOperation", "(", ")", ")", "\n", "}" ]
// Destroy ensures that the application and all its relations will be removed at // some point; if the application has no units, and no relation involving the // application has any units in scope, they are all removed immediately.
[ "Destroy", "ensures", "that", "the", "application", "and", "all", "its", "relations", "will", "be", "removed", "at", "some", "point", ";", "if", "the", "application", "has", "no", "units", "and", "no", "relation", "involving", "the", "application", "has", "any", "units", "in", "scope", "they", "are", "all", "removed", "immediately", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L207-L216
157,660
juju/juju
state/application.go
DestroyOperation
func (a *Application) DestroyOperation() *DestroyApplicationOperation { return &DestroyApplicationOperation{ app: &Application{st: a.st, doc: a.doc}, } }
go
func (a *Application) DestroyOperation() *DestroyApplicationOperation { return &DestroyApplicationOperation{ app: &Application{st: a.st, doc: a.doc}, } }
[ "func", "(", "a", "*", "Application", ")", "DestroyOperation", "(", ")", "*", "DestroyApplicationOperation", "{", "return", "&", "DestroyApplicationOperation", "{", "app", ":", "&", "Application", "{", "st", ":", "a", ".", "st", ",", "doc", ":", "a", ".", "doc", "}", ",", "}", "\n", "}" ]
// DestroyOperation returns a model operation that will destroy the application.
[ "DestroyOperation", "returns", "a", "model", "operation", "that", "will", "destroy", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L219-L223
157,661
juju/juju
state/application.go
removeOps
func (a *Application) removeOps(asserts bson.D, op *ForcedOperation) ([]txn.Op, error) { ops := []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: asserts, Remove: true, }} // Remove application offers. removeOfferOps, err := removeApplicationOffersOps(a.st, a.doc.Name) if err != nil { if !op.Force { return nil, errors.Trace(err) } op.AddError(err) } ops = append(ops, removeOfferOps...) // Note that appCharmDecRefOps might not catch the final decref // when run in a transaction that decrefs more than once. So we // avoid attempting to do the final cleanup in the ref dec ops and // do it explicitly below. name := a.doc.Name curl := a.doc.CharmURL // When 'force' is set, this call will return operations to delete application references // to this charm as well as accumulate all operational errors encountered in the operation. // If the 'force' is not set, any error will be fatal and no operations will be returned. charmOps, err := appCharmDecRefOps(a.st, name, curl, false, op) if err != nil { if errors.Cause(err) == errRefcountAlreadyZero { // We have already removed the reference to the charm, this indicates // the application is already removed, reload yourself and try again return nil, errRefresh } if !op.Force { return nil, errors.Trace(err) } op.AddError(err) } ops = append(ops, charmOps...) // By the time we get to here, all units and charm refs have been removed, // so it's safe to do this additional cleanup. ops = append(ops, finalAppCharmRemoveOps(name, curl)...) ops = append(ops, a.removeCloudServiceOps()...) globalKey := a.globalKey() ops = append(ops, removeEndpointBindingsOp(globalKey), removeConstraintsOp(globalKey), annotationRemoveOp(a.st, globalKey), removeLeadershipSettingsOp(name), removeStatusOp(a.st, globalKey), removeStatusOp(a.st, applicationGlobalOperatorKey(name)), removeSettingsOp(settingsC, a.applicationConfigKey()), removeModelApplicationRefOp(a.st, name), removePodSpecOp(a.ApplicationTag()), ) return ops, nil }
go
func (a *Application) removeOps(asserts bson.D, op *ForcedOperation) ([]txn.Op, error) { ops := []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: asserts, Remove: true, }} // Remove application offers. removeOfferOps, err := removeApplicationOffersOps(a.st, a.doc.Name) if err != nil { if !op.Force { return nil, errors.Trace(err) } op.AddError(err) } ops = append(ops, removeOfferOps...) // Note that appCharmDecRefOps might not catch the final decref // when run in a transaction that decrefs more than once. So we // avoid attempting to do the final cleanup in the ref dec ops and // do it explicitly below. name := a.doc.Name curl := a.doc.CharmURL // When 'force' is set, this call will return operations to delete application references // to this charm as well as accumulate all operational errors encountered in the operation. // If the 'force' is not set, any error will be fatal and no operations will be returned. charmOps, err := appCharmDecRefOps(a.st, name, curl, false, op) if err != nil { if errors.Cause(err) == errRefcountAlreadyZero { // We have already removed the reference to the charm, this indicates // the application is already removed, reload yourself and try again return nil, errRefresh } if !op.Force { return nil, errors.Trace(err) } op.AddError(err) } ops = append(ops, charmOps...) // By the time we get to here, all units and charm refs have been removed, // so it's safe to do this additional cleanup. ops = append(ops, finalAppCharmRemoveOps(name, curl)...) ops = append(ops, a.removeCloudServiceOps()...) globalKey := a.globalKey() ops = append(ops, removeEndpointBindingsOp(globalKey), removeConstraintsOp(globalKey), annotationRemoveOp(a.st, globalKey), removeLeadershipSettingsOp(name), removeStatusOp(a.st, globalKey), removeStatusOp(a.st, applicationGlobalOperatorKey(name)), removeSettingsOp(settingsC, a.applicationConfigKey()), removeModelApplicationRefOp(a.st, name), removePodSpecOp(a.ApplicationTag()), ) return ops, nil }
[ "func", "(", "a", "*", "Application", ")", "removeOps", "(", "asserts", "bson", ".", "D", ",", "op", "*", "ForcedOperation", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "ops", ":=", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "applicationsC", ",", "Id", ":", "a", ".", "doc", ".", "DocID", ",", "Assert", ":", "asserts", ",", "Remove", ":", "true", ",", "}", "}", "\n\n", "// Remove application offers.", "removeOfferOps", ",", "err", ":=", "removeApplicationOffersOps", "(", "a", ".", "st", ",", "a", ".", "doc", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "op", ".", "Force", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "op", ".", "AddError", "(", "err", ")", "\n", "}", "\n", "ops", "=", "append", "(", "ops", ",", "removeOfferOps", "...", ")", "\n\n", "// Note that appCharmDecRefOps might not catch the final decref", "// when run in a transaction that decrefs more than once. So we", "// avoid attempting to do the final cleanup in the ref dec ops and", "// do it explicitly below.", "name", ":=", "a", ".", "doc", ".", "Name", "\n", "curl", ":=", "a", ".", "doc", ".", "CharmURL", "\n", "// When 'force' is set, this call will return operations to delete application references", "// to this charm as well as accumulate all operational errors encountered in the operation.", "// If the 'force' is not set, any error will be fatal and no operations will be returned.", "charmOps", ",", "err", ":=", "appCharmDecRefOps", "(", "a", ".", "st", ",", "name", ",", "curl", ",", "false", ",", "op", ")", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "Cause", "(", "err", ")", "==", "errRefcountAlreadyZero", "{", "// We have already removed the reference to the charm, this indicates", "// the application is already removed, reload yourself and try again", "return", "nil", ",", "errRefresh", "\n", "}", "\n", "if", "!", "op", ".", "Force", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "op", ".", "AddError", "(", "err", ")", "\n", "}", "\n", "ops", "=", "append", "(", "ops", ",", "charmOps", "...", ")", "\n\n", "// By the time we get to here, all units and charm refs have been removed,", "// so it's safe to do this additional cleanup.", "ops", "=", "append", "(", "ops", ",", "finalAppCharmRemoveOps", "(", "name", ",", "curl", ")", "...", ")", "\n\n", "ops", "=", "append", "(", "ops", ",", "a", ".", "removeCloudServiceOps", "(", ")", "...", ")", "\n", "globalKey", ":=", "a", ".", "globalKey", "(", ")", "\n", "ops", "=", "append", "(", "ops", ",", "removeEndpointBindingsOp", "(", "globalKey", ")", ",", "removeConstraintsOp", "(", "globalKey", ")", ",", "annotationRemoveOp", "(", "a", ".", "st", ",", "globalKey", ")", ",", "removeLeadershipSettingsOp", "(", "name", ")", ",", "removeStatusOp", "(", "a", ".", "st", ",", "globalKey", ")", ",", "removeStatusOp", "(", "a", ".", "st", ",", "applicationGlobalOperatorKey", "(", "name", ")", ")", ",", "removeSettingsOp", "(", "settingsC", ",", "a", ".", "applicationConfigKey", "(", ")", ")", ",", "removeModelApplicationRefOp", "(", "a", ".", "st", ",", "name", ")", ",", "removePodSpecOp", "(", "a", ".", "ApplicationTag", "(", ")", ")", ",", ")", "\n", "return", "ops", ",", "nil", "\n", "}" ]
// removeOps returns the operations required to remove the application. Supplied // asserts will be included in the operation on the application document. // When force is set, the operation will proceed regardless of the errors, // and if any errors are encountered, all possible accumulated operations // as well as all encountered errors will be returned. // When 'force' is set, this call will return operations to remove this // application and will accumulate all operational errors encountered in the operation. // If the 'force' is not set, any error will be fatal and no operations will be returned.
[ "removeOps", "returns", "the", "operations", "required", "to", "remove", "the", "application", ".", "Supplied", "asserts", "will", "be", "included", "in", "the", "operation", "on", "the", "application", "document", ".", "When", "force", "is", "set", "the", "operation", "will", "proceed", "regardless", "of", "the", "errors", "and", "if", "any", "errors", "are", "encountered", "all", "possible", "accumulated", "operations", "as", "well", "as", "all", "encountered", "errors", "will", "be", "returned", ".", "When", "force", "is", "set", "this", "call", "will", "return", "operations", "to", "remove", "this", "application", "and", "will", "accumulate", "all", "operational", "errors", "encountered", "in", "the", "operation", ".", "If", "the", "force", "is", "not", "set", "any", "error", "will", "be", "fatal", "and", "no", "operations", "will", "be", "returned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L458-L517
157,662
juju/juju
state/application.go
Charm
func (a *Application) Charm() (ch *Charm, force bool, err error) { // We don't worry about the channel since we aren't interacting // with the charm store here. ch, err = a.st.Charm(a.doc.CharmURL) if err != nil { return nil, false, err } return ch, a.doc.ForceCharm, nil }
go
func (a *Application) Charm() (ch *Charm, force bool, err error) { // We don't worry about the channel since we aren't interacting // with the charm store here. ch, err = a.st.Charm(a.doc.CharmURL) if err != nil { return nil, false, err } return ch, a.doc.ForceCharm, nil }
[ "func", "(", "a", "*", "Application", ")", "Charm", "(", ")", "(", "ch", "*", "Charm", ",", "force", "bool", ",", "err", "error", ")", "{", "// We don't worry about the channel since we aren't interacting", "// with the charm store here.", "ch", ",", "err", "=", "a", ".", "st", ".", "Charm", "(", "a", ".", "doc", ".", "CharmURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "return", "ch", ",", "a", ".", "doc", ".", "ForceCharm", ",", "nil", "\n", "}" ]
// Charm returns the application's charm and whether units should upgrade to that // charm even if they are in an error state.
[ "Charm", "returns", "the", "application", "s", "charm", "and", "whether", "units", "should", "upgrade", "to", "that", "charm", "even", "if", "they", "are", "in", "an", "error", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L554-L562
157,663
juju/juju
state/application.go
CharmURL
func (a *Application) CharmURL() (curl *charm.URL, force bool) { return a.doc.CharmURL, a.doc.ForceCharm }
go
func (a *Application) CharmURL() (curl *charm.URL, force bool) { return a.doc.CharmURL, a.doc.ForceCharm }
[ "func", "(", "a", "*", "Application", ")", "CharmURL", "(", ")", "(", "curl", "*", "charm", ".", "URL", ",", "force", "bool", ")", "{", "return", "a", ".", "doc", ".", "CharmURL", ",", "a", ".", "doc", ".", "ForceCharm", "\n", "}" ]
// CharmURL returns the application's charm URL, and whether units should upgrade // to the charm with that URL even if they are in an error state.
[ "CharmURL", "returns", "the", "application", "s", "charm", "URL", "and", "whether", "units", "should", "upgrade", "to", "the", "charm", "with", "that", "URL", "even", "if", "they", "are", "in", "an", "error", "state", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L578-L580
157,664
juju/juju
state/application.go
Channel
func (a *Application) Channel() csparams.Channel { return csparams.Channel(a.doc.Channel) }
go
func (a *Application) Channel() csparams.Channel { return csparams.Channel(a.doc.Channel) }
[ "func", "(", "a", "*", "Application", ")", "Channel", "(", ")", "csparams", ".", "Channel", "{", "return", "csparams", ".", "Channel", "(", "a", ".", "doc", ".", "Channel", ")", "\n", "}" ]
// Channel identifies the charm store channel from which the application's // charm was deployed. It is only needed when interacting with the charm // store.
[ "Channel", "identifies", "the", "charm", "store", "channel", "from", "which", "the", "application", "s", "charm", "was", "deployed", ".", "It", "is", "only", "needed", "when", "interacting", "with", "the", "charm", "store", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L585-L587
157,665
juju/juju
state/application.go
extraPeerRelations
func (a *Application) extraPeerRelations(newMeta *charm.Meta) map[string]charm.Relation { if newMeta == nil { // This should never happen, since we're checking the charm in SetCharm already. panic("newMeta is nil") } ch, _, err := a.Charm() if err != nil { return nil } newPeers := newMeta.Peers oldPeers := ch.Meta().Peers extraPeers := make(map[string]charm.Relation) for relName, rel := range newPeers { if _, ok := oldPeers[relName]; !ok { extraPeers[relName] = rel } } return extraPeers }
go
func (a *Application) extraPeerRelations(newMeta *charm.Meta) map[string]charm.Relation { if newMeta == nil { // This should never happen, since we're checking the charm in SetCharm already. panic("newMeta is nil") } ch, _, err := a.Charm() if err != nil { return nil } newPeers := newMeta.Peers oldPeers := ch.Meta().Peers extraPeers := make(map[string]charm.Relation) for relName, rel := range newPeers { if _, ok := oldPeers[relName]; !ok { extraPeers[relName] = rel } } return extraPeers }
[ "func", "(", "a", "*", "Application", ")", "extraPeerRelations", "(", "newMeta", "*", "charm", ".", "Meta", ")", "map", "[", "string", "]", "charm", ".", "Relation", "{", "if", "newMeta", "==", "nil", "{", "// This should never happen, since we're checking the charm in SetCharm already.", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "ch", ",", "_", ",", "err", ":=", "a", ".", "Charm", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "newPeers", ":=", "newMeta", ".", "Peers", "\n", "oldPeers", ":=", "ch", ".", "Meta", "(", ")", ".", "Peers", "\n", "extraPeers", ":=", "make", "(", "map", "[", "string", "]", "charm", ".", "Relation", ")", "\n", "for", "relName", ",", "rel", ":=", "range", "newPeers", "{", "if", "_", ",", "ok", ":=", "oldPeers", "[", "relName", "]", ";", "!", "ok", "{", "extraPeers", "[", "relName", "]", "=", "rel", "\n", "}", "\n", "}", "\n", "return", "extraPeers", "\n", "}" ]
// extraPeerRelations returns only the peer relations in newMeta not // present in the application's current charm meta data.
[ "extraPeerRelations", "returns", "only", "the", "peer", "relations", "in", "newMeta", "not", "present", "in", "the", "application", "s", "current", "charm", "meta", "data", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L635-L653
157,666
juju/juju
state/application.go
DeployedMachines
func (a *Application) DeployedMachines() ([]*Machine, error) { units, err := a.AllUnits() if err != nil { return nil, errors.Trace(err) } machineIds := set.NewStrings() var machines []*Machine for _, u := range units { // AssignedMachineId returns the correct machine // whether principal or subordinate. id, err := u.AssignedMachineId() if err != nil { if errors.IsNotAssigned(err) { // We aren't interested in this unit at this time. continue } return nil, errors.Trace(err) } if machineIds.Contains(id) { continue } m, err := a.st.Machine(id) if err != nil { return nil, errors.Trace(err) } machineIds.Add(id) machines = append(machines, m) } return machines, nil }
go
func (a *Application) DeployedMachines() ([]*Machine, error) { units, err := a.AllUnits() if err != nil { return nil, errors.Trace(err) } machineIds := set.NewStrings() var machines []*Machine for _, u := range units { // AssignedMachineId returns the correct machine // whether principal or subordinate. id, err := u.AssignedMachineId() if err != nil { if errors.IsNotAssigned(err) { // We aren't interested in this unit at this time. continue } return nil, errors.Trace(err) } if machineIds.Contains(id) { continue } m, err := a.st.Machine(id) if err != nil { return nil, errors.Trace(err) } machineIds.Add(id) machines = append(machines, m) } return machines, nil }
[ "func", "(", "a", "*", "Application", ")", "DeployedMachines", "(", ")", "(", "[", "]", "*", "Machine", ",", "error", ")", "{", "units", ",", "err", ":=", "a", ".", "AllUnits", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "machineIds", ":=", "set", ".", "NewStrings", "(", ")", "\n", "var", "machines", "[", "]", "*", "Machine", "\n", "for", "_", ",", "u", ":=", "range", "units", "{", "// AssignedMachineId returns the correct machine", "// whether principal or subordinate.", "id", ",", "err", ":=", "u", ".", "AssignedMachineId", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "errors", ".", "IsNotAssigned", "(", "err", ")", "{", "// We aren't interested in this unit at this time.", "continue", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "machineIds", ".", "Contains", "(", "id", ")", "{", "continue", "\n", "}", "\n\n", "m", ",", "err", ":=", "a", ".", "st", ".", "Machine", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "machineIds", ".", "Add", "(", "id", ")", "\n", "machines", "=", "append", "(", "machines", ",", "m", ")", "\n", "}", "\n", "return", "machines", ",", "nil", "\n", "}" ]
// Deployed machines returns the collection of machines // that this application has units deployed to.
[ "Deployed", "machines", "returns", "the", "collection", "of", "machines", "that", "this", "application", "has", "units", "deployed", "to", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L966-L997
157,667
juju/juju
state/application.go
incCharmModifiedVersionOps
func incCharmModifiedVersionOps(applicationID string) []txn.Op { return []txn.Op{{ C: applicationsC, Id: applicationID, Assert: txn.DocExists, Update: bson.D{{"$inc", bson.D{{"charmmodifiedversion", 1}}}}, }} }
go
func incCharmModifiedVersionOps(applicationID string) []txn.Op { return []txn.Op{{ C: applicationsC, Id: applicationID, Assert: txn.DocExists, Update: bson.D{{"$inc", bson.D{{"charmmodifiedversion", 1}}}}, }} }
[ "func", "incCharmModifiedVersionOps", "(", "applicationID", "string", ")", "[", "]", "txn", ".", "Op", "{", "return", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "applicationsC", ",", "Id", ":", "applicationID", ",", "Assert", ":", "txn", ".", "DocExists", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "1", "}", "}", "}", "}", ",", "}", "}", "\n", "}" ]
// incCharmModifiedVersionOps returns the operations necessary to increment // the CharmModifiedVersion field for the given application.
[ "incCharmModifiedVersionOps", "returns", "the", "operations", "necessary", "to", "increment", "the", "CharmModifiedVersion", "field", "for", "the", "given", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1111-L1118
157,668
juju/juju
state/application.go
UpdateApplicationSeries
func (a *Application) UpdateApplicationSeries(series string, force bool) (err error) { buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { // If we've tried once already and failed, re-evaluate the criteria. if err := a.Refresh(); err != nil { return nil, errors.Trace(err) } } // Exit early if the Application series doesn't need to change. if a.Series() == series { return nil, jujutxn.ErrNoOperations } // Verify and gather data for the transaction operations. err := a.VerifySupportedSeries(series, force) if err != nil { return nil, err } units, err := a.AllUnits() if err != nil { return nil, errors.Trace(err) } var subApps []*Application var unit *Unit if len(units) > 0 { // All units have the same subordinates... unit = units[0] for _, n := range unit.SubordinateNames() { app, err := a.st.Application(unitAppName(n)) if err != nil { return nil, err } err = app.VerifySupportedSeries(series, force) if err != nil { return nil, err } subApps = append(subApps, app) } } //Create the transaction operations ops := []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", a.doc.CharmURL}, {"unitcount", a.doc.UnitCount}}, Update: bson.D{{"$set", bson.D{{"series", series}}}}, }} if unit != nil { ops = append(ops, txn.Op{ C: unitsC, Id: unit.doc.DocID, Assert: bson.D{{"life", Alive}, {"subordinates", unit.SubordinateNames()}}, }) } for _, sub := range subApps { ops = append(ops, txn.Op{ C: applicationsC, Id: sub.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", sub.doc.CharmURL}, {"unitcount", sub.doc.UnitCount}}, Update: bson.D{{"$set", bson.D{{"series", series}}}}, }) } return ops, nil } err = a.st.db().Run(buildTxn) return errors.Annotatef(err, "updating application series") }
go
func (a *Application) UpdateApplicationSeries(series string, force bool) (err error) { buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { // If we've tried once already and failed, re-evaluate the criteria. if err := a.Refresh(); err != nil { return nil, errors.Trace(err) } } // Exit early if the Application series doesn't need to change. if a.Series() == series { return nil, jujutxn.ErrNoOperations } // Verify and gather data for the transaction operations. err := a.VerifySupportedSeries(series, force) if err != nil { return nil, err } units, err := a.AllUnits() if err != nil { return nil, errors.Trace(err) } var subApps []*Application var unit *Unit if len(units) > 0 { // All units have the same subordinates... unit = units[0] for _, n := range unit.SubordinateNames() { app, err := a.st.Application(unitAppName(n)) if err != nil { return nil, err } err = app.VerifySupportedSeries(series, force) if err != nil { return nil, err } subApps = append(subApps, app) } } //Create the transaction operations ops := []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", a.doc.CharmURL}, {"unitcount", a.doc.UnitCount}}, Update: bson.D{{"$set", bson.D{{"series", series}}}}, }} if unit != nil { ops = append(ops, txn.Op{ C: unitsC, Id: unit.doc.DocID, Assert: bson.D{{"life", Alive}, {"subordinates", unit.SubordinateNames()}}, }) } for _, sub := range subApps { ops = append(ops, txn.Op{ C: applicationsC, Id: sub.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", sub.doc.CharmURL}, {"unitcount", sub.doc.UnitCount}}, Update: bson.D{{"$set", bson.D{{"series", series}}}}, }) } return ops, nil } err = a.st.db().Run(buildTxn) return errors.Annotatef(err, "updating application series") }
[ "func", "(", "a", "*", "Application", ")", "UpdateApplicationSeries", "(", "series", "string", ",", "force", "bool", ")", "(", "err", "error", ")", "{", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "if", "attempt", ">", "0", "{", "// If we've tried once already and failed, re-evaluate the criteria.", "if", "err", ":=", "a", ".", "Refresh", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "// Exit early if the Application series doesn't need to change.", "if", "a", ".", "Series", "(", ")", "==", "series", "{", "return", "nil", ",", "jujutxn", ".", "ErrNoOperations", "\n", "}", "\n\n", "// Verify and gather data for the transaction operations.", "err", ":=", "a", ".", "VerifySupportedSeries", "(", "series", ",", "force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "units", ",", "err", ":=", "a", ".", "AllUnits", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "var", "subApps", "[", "]", "*", "Application", "\n", "var", "unit", "*", "Unit", "\n\n", "if", "len", "(", "units", ")", ">", "0", "{", "// All units have the same subordinates...", "unit", "=", "units", "[", "0", "]", "\n", "for", "_", ",", "n", ":=", "range", "unit", ".", "SubordinateNames", "(", ")", "{", "app", ",", "err", ":=", "a", ".", "st", ".", "Application", "(", "unitAppName", "(", "n", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", "=", "app", ".", "VerifySupportedSeries", "(", "series", ",", "force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "subApps", "=", "append", "(", "subApps", ",", "app", ")", "\n", "}", "\n", "}", "\n\n", "//Create the transaction operations", "ops", ":=", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "applicationsC", ",", "Id", ":", "a", ".", "doc", ".", "DocID", ",", "Assert", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "Alive", "}", ",", "{", "\"", "\"", ",", "a", ".", "doc", ".", "CharmURL", "}", ",", "{", "\"", "\"", ",", "a", ".", "doc", ".", "UnitCount", "}", "}", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "series", "}", "}", "}", "}", ",", "}", "}", "\n\n", "if", "unit", "!=", "nil", "{", "ops", "=", "append", "(", "ops", ",", "txn", ".", "Op", "{", "C", ":", "unitsC", ",", "Id", ":", "unit", ".", "doc", ".", "DocID", ",", "Assert", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "Alive", "}", ",", "{", "\"", "\"", ",", "unit", ".", "SubordinateNames", "(", ")", "}", "}", ",", "}", ")", "\n", "}", "\n\n", "for", "_", ",", "sub", ":=", "range", "subApps", "{", "ops", "=", "append", "(", "ops", ",", "txn", ".", "Op", "{", "C", ":", "applicationsC", ",", "Id", ":", "sub", ".", "doc", ".", "DocID", ",", "Assert", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "Alive", "}", ",", "{", "\"", "\"", ",", "sub", ".", "doc", ".", "CharmURL", "}", ",", "{", "\"", "\"", ",", "sub", ".", "doc", ".", "UnitCount", "}", "}", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "series", "}", "}", "}", "}", ",", "}", ")", "\n", "}", "\n", "return", "ops", ",", "nil", "\n", "}", "\n\n", "err", "=", "a", ".", "st", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", "\n", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "}" ]
// UpdateApplicationSeries updates the series for the Application.
[ "UpdateApplicationSeries", "updates", "the", "series", "for", "the", "Application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1322-L1397
157,669
juju/juju
state/application.go
VerifySupportedSeries
func (a *Application) VerifySupportedSeries(series string, force bool) error { ch, _, err := a.Charm() if err != nil { return err } supportedSeries := ch.Meta().Series if len(supportedSeries) == 0 { supportedSeries = append(supportedSeries, ch.URL().Series) } _, seriesSupportedErr := charm.SeriesForCharm(series, supportedSeries) if seriesSupportedErr != nil && !force { return &ErrIncompatibleSeries{ SeriesList: supportedSeries, Series: series, CharmName: ch.String(), } } return nil }
go
func (a *Application) VerifySupportedSeries(series string, force bool) error { ch, _, err := a.Charm() if err != nil { return err } supportedSeries := ch.Meta().Series if len(supportedSeries) == 0 { supportedSeries = append(supportedSeries, ch.URL().Series) } _, seriesSupportedErr := charm.SeriesForCharm(series, supportedSeries) if seriesSupportedErr != nil && !force { return &ErrIncompatibleSeries{ SeriesList: supportedSeries, Series: series, CharmName: ch.String(), } } return nil }
[ "func", "(", "a", "*", "Application", ")", "VerifySupportedSeries", "(", "series", "string", ",", "force", "bool", ")", "error", "{", "ch", ",", "_", ",", "err", ":=", "a", ".", "Charm", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "supportedSeries", ":=", "ch", ".", "Meta", "(", ")", ".", "Series", "\n", "if", "len", "(", "supportedSeries", ")", "==", "0", "{", "supportedSeries", "=", "append", "(", "supportedSeries", ",", "ch", ".", "URL", "(", ")", ".", "Series", ")", "\n", "}", "\n", "_", ",", "seriesSupportedErr", ":=", "charm", ".", "SeriesForCharm", "(", "series", ",", "supportedSeries", ")", "\n", "if", "seriesSupportedErr", "!=", "nil", "&&", "!", "force", "{", "return", "&", "ErrIncompatibleSeries", "{", "SeriesList", ":", "supportedSeries", ",", "Series", ":", "series", ",", "CharmName", ":", "ch", ".", "String", "(", ")", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// VerifySupportedSeries verifies if the given series is supported by the // application.
[ "VerifySupportedSeries", "verifies", "if", "the", "given", "series", "is", "supported", "by", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1401-L1419
157,670
juju/juju
state/application.go
Refresh
func (a *Application) Refresh() error { applications, closer := a.st.db().GetCollection(applicationsC) defer closer() err := applications.FindId(a.doc.DocID).One(&a.doc) if err == mgo.ErrNotFound { return errors.NotFoundf("application %q", a) } if err != nil { return errors.Errorf("cannot refresh application %q: %v", a, err) } return nil }
go
func (a *Application) Refresh() error { applications, closer := a.st.db().GetCollection(applicationsC) defer closer() err := applications.FindId(a.doc.DocID).One(&a.doc) if err == mgo.ErrNotFound { return errors.NotFoundf("application %q", a) } if err != nil { return errors.Errorf("cannot refresh application %q: %v", a, err) } return nil }
[ "func", "(", "a", "*", "Application", ")", "Refresh", "(", ")", "error", "{", "applications", ",", "closer", ":=", "a", ".", "st", ".", "db", "(", ")", ".", "GetCollection", "(", "applicationsC", ")", "\n", "defer", "closer", "(", ")", "\n\n", "err", ":=", "applications", ".", "FindId", "(", "a", ".", "doc", ".", "DocID", ")", ".", "One", "(", "&", "a", ".", "doc", ")", "\n", "if", "err", "==", "mgo", ".", "ErrNotFound", "{", "return", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "a", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "a", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Refresh refreshes the contents of the Application from the underlying // state. It returns an error that satisfies errors.IsNotFound if the // application has been removed.
[ "Refresh", "refreshes", "the", "contents", "of", "the", "Application", "from", "the", "underlying", "state", ".", "It", "returns", "an", "error", "that", "satisfies", "errors", ".", "IsNotFound", "if", "the", "application", "has", "been", "removed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1429-L1441
157,671
juju/juju
state/application.go
ChangeScale
func (a *Application) ChangeScale(scaleChange int) (int, error) { newScale := a.doc.DesiredScale + scaleChange if newScale < 0 { return a.doc.DesiredScale, errors.NotValidf("cannot remove more units than currently exist") } buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { alive, err := isAlive(a.st, applicationsC, a.doc.DocID) if err != nil { return nil, errors.Trace(err) } else if !alive { return nil, applicationNotAliveErr } if err := a.Refresh(); err != nil { return nil, errors.Trace(err) } newScale = a.doc.DesiredScale + scaleChange if newScale < 0 { return nil, errors.NotValidf("cannot remove more units than currently exist") } } return []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", a.doc.CharmURL}, {"unitcount", a.doc.UnitCount}, {"scale", a.doc.DesiredScale}}, Update: bson.D{{"$set", bson.D{{"scale", newScale}}}}, }}, nil } if err := a.st.db().Run(buildTxn); err != nil { return a.doc.DesiredScale, errors.Errorf("cannot set scale for application %q to %v: %v", a, newScale, onAbort(err, applicationNotAliveErr)) } a.doc.DesiredScale = newScale return newScale, nil }
go
func (a *Application) ChangeScale(scaleChange int) (int, error) { newScale := a.doc.DesiredScale + scaleChange if newScale < 0 { return a.doc.DesiredScale, errors.NotValidf("cannot remove more units than currently exist") } buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { alive, err := isAlive(a.st, applicationsC, a.doc.DocID) if err != nil { return nil, errors.Trace(err) } else if !alive { return nil, applicationNotAliveErr } if err := a.Refresh(); err != nil { return nil, errors.Trace(err) } newScale = a.doc.DesiredScale + scaleChange if newScale < 0 { return nil, errors.NotValidf("cannot remove more units than currently exist") } } return []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", a.doc.CharmURL}, {"unitcount", a.doc.UnitCount}, {"scale", a.doc.DesiredScale}}, Update: bson.D{{"$set", bson.D{{"scale", newScale}}}}, }}, nil } if err := a.st.db().Run(buildTxn); err != nil { return a.doc.DesiredScale, errors.Errorf("cannot set scale for application %q to %v: %v", a, newScale, onAbort(err, applicationNotAliveErr)) } a.doc.DesiredScale = newScale return newScale, nil }
[ "func", "(", "a", "*", "Application", ")", "ChangeScale", "(", "scaleChange", "int", ")", "(", "int", ",", "error", ")", "{", "newScale", ":=", "a", ".", "doc", ".", "DesiredScale", "+", "scaleChange", "\n", "if", "newScale", "<", "0", "{", "return", "a", ".", "doc", ".", "DesiredScale", ",", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "if", "attempt", ">", "0", "{", "alive", ",", "err", ":=", "isAlive", "(", "a", ".", "st", ",", "applicationsC", ",", "a", ".", "doc", ".", "DocID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "!", "alive", "{", "return", "nil", ",", "applicationNotAliveErr", "\n", "}", "\n", "if", "err", ":=", "a", ".", "Refresh", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "newScale", "=", "a", ".", "doc", ".", "DesiredScale", "+", "scaleChange", "\n", "if", "newScale", "<", "0", "{", "return", "nil", ",", "errors", ".", "NotValidf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "applicationsC", ",", "Id", ":", "a", ".", "doc", ".", "DocID", ",", "Assert", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "Alive", "}", ",", "{", "\"", "\"", ",", "a", ".", "doc", ".", "CharmURL", "}", ",", "{", "\"", "\"", ",", "a", ".", "doc", ".", "UnitCount", "}", ",", "{", "\"", "\"", ",", "a", ".", "doc", ".", "DesiredScale", "}", "}", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "newScale", "}", "}", "}", "}", ",", "}", "}", ",", "nil", "\n", "}", "\n", "if", "err", ":=", "a", ".", "st", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", ";", "err", "!=", "nil", "{", "return", "a", ".", "doc", ".", "DesiredScale", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "a", ",", "newScale", ",", "onAbort", "(", "err", ",", "applicationNotAliveErr", ")", ")", "\n", "}", "\n", "a", ".", "doc", ".", "DesiredScale", "=", "newScale", "\n", "return", "newScale", ",", "nil", "\n", "}" ]
// ChangeScale alters the existing scale by the provided change amount, returning the new amount. // This is used on CAAS models.
[ "ChangeScale", "alters", "the", "existing", "scale", "by", "the", "provided", "change", "amount", "returning", "the", "new", "amount", ".", "This", "is", "used", "on", "CAAS", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1457-L1493
157,672
juju/juju
state/application.go
SetScale
func (a *Application) SetScale(scale int) error { if scale < 0 { return errors.NotValidf("application scale %d", scale) } buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { alive, err := isAlive(a.st, applicationsC, a.doc.DocID) if err != nil { return nil, errors.Trace(err) } else if !alive { return nil, applicationNotAliveErr } if err := a.Refresh(); err != nil { return nil, errors.Trace(err) } } return []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", a.doc.CharmURL}, {"unitcount", a.doc.UnitCount}}, Update: bson.D{{"$set", bson.D{{"scale", scale}}}}, }}, nil } if err := a.st.db().Run(buildTxn); err != nil { return errors.Errorf("cannot set scale for application %q to %v: %v", a, scale, onAbort(err, applicationNotAliveErr)) } a.doc.DesiredScale = scale return nil }
go
func (a *Application) SetScale(scale int) error { if scale < 0 { return errors.NotValidf("application scale %d", scale) } buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { alive, err := isAlive(a.st, applicationsC, a.doc.DocID) if err != nil { return nil, errors.Trace(err) } else if !alive { return nil, applicationNotAliveErr } if err := a.Refresh(); err != nil { return nil, errors.Trace(err) } } return []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: bson.D{{"life", Alive}, {"charmurl", a.doc.CharmURL}, {"unitcount", a.doc.UnitCount}}, Update: bson.D{{"$set", bson.D{{"scale", scale}}}}, }}, nil } if err := a.st.db().Run(buildTxn); err != nil { return errors.Errorf("cannot set scale for application %q to %v: %v", a, scale, onAbort(err, applicationNotAliveErr)) } a.doc.DesiredScale = scale return nil }
[ "func", "(", "a", "*", "Application", ")", "SetScale", "(", "scale", "int", ")", "error", "{", "if", "scale", "<", "0", "{", "return", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "scale", ")", "\n", "}", "\n", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "if", "attempt", ">", "0", "{", "alive", ",", "err", ":=", "isAlive", "(", "a", ".", "st", ",", "applicationsC", ",", "a", ".", "doc", ".", "DocID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "!", "alive", "{", "return", "nil", ",", "applicationNotAliveErr", "\n", "}", "\n", "if", "err", ":=", "a", ".", "Refresh", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "applicationsC", ",", "Id", ":", "a", ".", "doc", ".", "DocID", ",", "Assert", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "Alive", "}", ",", "{", "\"", "\"", ",", "a", ".", "doc", ".", "CharmURL", "}", ",", "{", "\"", "\"", ",", "a", ".", "doc", ".", "UnitCount", "}", "}", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "scale", "}", "}", "}", "}", ",", "}", "}", ",", "nil", "\n", "}", "\n", "if", "err", ":=", "a", ".", "st", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "a", ",", "scale", ",", "onAbort", "(", "err", ",", "applicationNotAliveErr", ")", ")", "\n", "}", "\n", "a", ".", "doc", ".", "DesiredScale", "=", "scale", "\n", "return", "nil", "\n", "}" ]
// SetScale sets the application's desired scale value. // This is used on CAAS models.
[ "SetScale", "sets", "the", "application", "s", "desired", "scale", "value", ".", "This", "is", "used", "on", "CAAS", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1497-L1527
157,673
juju/juju
state/application.go
newUnitName
func (a *Application) newUnitName() (string, error) { unitSeq, err := sequence(a.st, a.Tag().String()) if err != nil { return "", errors.Trace(err) } name := a.doc.Name + "/" + strconv.Itoa(unitSeq) return name, nil }
go
func (a *Application) newUnitName() (string, error) { unitSeq, err := sequence(a.st, a.Tag().String()) if err != nil { return "", errors.Trace(err) } name := a.doc.Name + "/" + strconv.Itoa(unitSeq) return name, nil }
[ "func", "(", "a", "*", "Application", ")", "newUnitName", "(", ")", "(", "string", ",", "error", ")", "{", "unitSeq", ",", "err", ":=", "sequence", "(", "a", ".", "st", ",", "a", ".", "Tag", "(", ")", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "name", ":=", "a", ".", "doc", ".", "Name", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "unitSeq", ")", "\n", "return", "name", ",", "nil", "\n", "}" ]
// newUnitName returns the next unit name.
[ "newUnitName", "returns", "the", "next", "unit", "name", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1530-L1537
157,674
juju/juju
state/application.go
addUnitOps
func (a *Application) addUnitOps( principalName string, args AddUnitParams, asserts bson.D, ) (string, []txn.Op, error) { var cons constraints.Value if !a.doc.Subordinate { scons, err := a.Constraints() if errors.IsNotFound(err) { return "", nil, errors.NotFoundf("application %q", a.Name()) } if err != nil { return "", nil, errors.Trace(err) } cons, err = a.st.ResolveConstraints(scons) if err != nil { return "", nil, errors.Trace(err) } } storageCons, err := a.StorageConstraints() if err != nil { return "", nil, errors.Trace(err) } uNames, ops, err := a.addUnitOpsWithCons(applicationAddUnitOpsArgs{ cons: cons, principalName: principalName, storageCons: storageCons, attachStorage: args.AttachStorage, providerId: args.ProviderId, address: args.Address, ports: args.Ports, }) if err != nil { return uNames, ops, errors.Trace(err) } // we verify the application is alive asserts = append(isAliveDoc, asserts...) ops = append(ops, a.incUnitCountOp(asserts)) return uNames, ops, nil }
go
func (a *Application) addUnitOps( principalName string, args AddUnitParams, asserts bson.D, ) (string, []txn.Op, error) { var cons constraints.Value if !a.doc.Subordinate { scons, err := a.Constraints() if errors.IsNotFound(err) { return "", nil, errors.NotFoundf("application %q", a.Name()) } if err != nil { return "", nil, errors.Trace(err) } cons, err = a.st.ResolveConstraints(scons) if err != nil { return "", nil, errors.Trace(err) } } storageCons, err := a.StorageConstraints() if err != nil { return "", nil, errors.Trace(err) } uNames, ops, err := a.addUnitOpsWithCons(applicationAddUnitOpsArgs{ cons: cons, principalName: principalName, storageCons: storageCons, attachStorage: args.AttachStorage, providerId: args.ProviderId, address: args.Address, ports: args.Ports, }) if err != nil { return uNames, ops, errors.Trace(err) } // we verify the application is alive asserts = append(isAliveDoc, asserts...) ops = append(ops, a.incUnitCountOp(asserts)) return uNames, ops, nil }
[ "func", "(", "a", "*", "Application", ")", "addUnitOps", "(", "principalName", "string", ",", "args", "AddUnitParams", ",", "asserts", "bson", ".", "D", ",", ")", "(", "string", ",", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "var", "cons", "constraints", ".", "Value", "\n", "if", "!", "a", ".", "doc", ".", "Subordinate", "{", "scons", ",", "err", ":=", "a", ".", "Constraints", "(", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "\"", "\"", ",", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "a", ".", "Name", "(", ")", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "cons", ",", "err", "=", "a", ".", "st", ".", "ResolveConstraints", "(", "scons", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "storageCons", ",", "err", ":=", "a", ".", "StorageConstraints", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "uNames", ",", "ops", ",", "err", ":=", "a", ".", "addUnitOpsWithCons", "(", "applicationAddUnitOpsArgs", "{", "cons", ":", "cons", ",", "principalName", ":", "principalName", ",", "storageCons", ":", "storageCons", ",", "attachStorage", ":", "args", ".", "AttachStorage", ",", "providerId", ":", "args", ".", "ProviderId", ",", "address", ":", "args", ".", "Address", ",", "ports", ":", "args", ".", "Ports", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "uNames", ",", "ops", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// we verify the application is alive", "asserts", "=", "append", "(", "isAliveDoc", ",", "asserts", "...", ")", "\n", "ops", "=", "append", "(", "ops", ",", "a", ".", "incUnitCountOp", "(", "asserts", ")", ")", "\n", "return", "uNames", ",", "ops", ",", "nil", "\n", "}" ]
// addUnitOps returns a unique name for a new unit, and a list of txn operations // necessary to create that unit. The principalName param must be non-empty if // and only if s is a subordinate application. Only one subordinate of a given // application will be assigned to a given principal. The asserts param can be used // to include additional assertions for the application document. This method // assumes that the application already exists in the db.
[ "addUnitOps", "returns", "a", "unique", "name", "for", "a", "new", "unit", "and", "a", "list", "of", "txn", "operations", "necessary", "to", "create", "that", "unit", ".", "The", "principalName", "param", "must", "be", "non", "-", "empty", "if", "and", "only", "if", "s", "is", "a", "subordinate", "application", ".", "Only", "one", "subordinate", "of", "a", "given", "application", "will", "be", "assigned", "to", "a", "given", "principal", ".", "The", "asserts", "param", "can", "be", "used", "to", "include", "additional", "assertions", "for", "the", "application", "document", ".", "This", "method", "assumes", "that", "the", "application", "already", "exists", "in", "the", "db", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1545-L1584
157,675
juju/juju
state/application.go
incApplicationOffersRefOp
func incApplicationOffersRefOp(mb modelBackend, appName string) (txn.Op, error) { refcounts, closer := mb.db().GetCollection(refcountsC) defer closer() offerRefCountKey := applicationOffersRefCountKey(appName) incRefOp, err := nsRefcounts.CreateOrIncRefOp(refcounts, offerRefCountKey, 1) return incRefOp, errors.Trace(err) }
go
func incApplicationOffersRefOp(mb modelBackend, appName string) (txn.Op, error) { refcounts, closer := mb.db().GetCollection(refcountsC) defer closer() offerRefCountKey := applicationOffersRefCountKey(appName) incRefOp, err := nsRefcounts.CreateOrIncRefOp(refcounts, offerRefCountKey, 1) return incRefOp, errors.Trace(err) }
[ "func", "incApplicationOffersRefOp", "(", "mb", "modelBackend", ",", "appName", "string", ")", "(", "txn", ".", "Op", ",", "error", ")", "{", "refcounts", ",", "closer", ":=", "mb", ".", "db", "(", ")", ".", "GetCollection", "(", "refcountsC", ")", "\n", "defer", "closer", "(", ")", "\n", "offerRefCountKey", ":=", "applicationOffersRefCountKey", "(", "appName", ")", "\n", "incRefOp", ",", "err", ":=", "nsRefcounts", ".", "CreateOrIncRefOp", "(", "refcounts", ",", "offerRefCountKey", ",", "1", ")", "\n", "return", "incRefOp", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}" ]
// incApplicationOffersRefOp returns a txn.Op that increments the reference // count for an application offer.
[ "incApplicationOffersRefOp", "returns", "a", "txn", ".", "Op", "that", "increments", "the", "reference", "count", "for", "an", "application", "offer", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1830-L1836
157,676
juju/juju
state/application.go
countApplicationOffersRefOp
func countApplicationOffersRefOp(mb modelBackend, appName string) (txn.Op, int, error) { refcounts, closer := mb.db().GetCollection(refcountsC) defer closer() key := applicationOffersRefCountKey(appName) return nsRefcounts.CurrentOp(refcounts, key) }
go
func countApplicationOffersRefOp(mb modelBackend, appName string) (txn.Op, int, error) { refcounts, closer := mb.db().GetCollection(refcountsC) defer closer() key := applicationOffersRefCountKey(appName) return nsRefcounts.CurrentOp(refcounts, key) }
[ "func", "countApplicationOffersRefOp", "(", "mb", "modelBackend", ",", "appName", "string", ")", "(", "txn", ".", "Op", ",", "int", ",", "error", ")", "{", "refcounts", ",", "closer", ":=", "mb", ".", "db", "(", ")", ".", "GetCollection", "(", "refcountsC", ")", "\n", "defer", "closer", "(", ")", "\n", "key", ":=", "applicationOffersRefCountKey", "(", "appName", ")", "\n", "return", "nsRefcounts", ".", "CurrentOp", "(", "refcounts", ",", "key", ")", "\n", "}" ]
// countApplicationOffersRefOp returns the number of offers for an application, // along with a txn.Op that ensures that that does not change.
[ "countApplicationOffersRefOp", "returns", "the", "number", "of", "offers", "for", "an", "application", "along", "with", "a", "txn", ".", "Op", "that", "ensures", "that", "that", "does", "not", "change", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1840-L1845
157,677
juju/juju
state/application.go
decApplicationOffersRefOp
func decApplicationOffersRefOp(mb modelBackend, appName string) (txn.Op, error) { refcounts, closer := mb.db().GetCollection(refcountsC) defer closer() offerRefCountKey := applicationOffersRefCountKey(appName) decRefOp, _, err := nsRefcounts.DyingDecRefOp(refcounts, offerRefCountKey) if err != nil { return txn.Op{}, errors.Trace(err) } return decRefOp, nil }
go
func decApplicationOffersRefOp(mb modelBackend, appName string) (txn.Op, error) { refcounts, closer := mb.db().GetCollection(refcountsC) defer closer() offerRefCountKey := applicationOffersRefCountKey(appName) decRefOp, _, err := nsRefcounts.DyingDecRefOp(refcounts, offerRefCountKey) if err != nil { return txn.Op{}, errors.Trace(err) } return decRefOp, nil }
[ "func", "decApplicationOffersRefOp", "(", "mb", "modelBackend", ",", "appName", "string", ")", "(", "txn", ".", "Op", ",", "error", ")", "{", "refcounts", ",", "closer", ":=", "mb", ".", "db", "(", ")", ".", "GetCollection", "(", "refcountsC", ")", "\n", "defer", "closer", "(", ")", "\n", "offerRefCountKey", ":=", "applicationOffersRefCountKey", "(", "appName", ")", "\n", "decRefOp", ",", "_", ",", "err", ":=", "nsRefcounts", ".", "DyingDecRefOp", "(", "refcounts", ",", "offerRefCountKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "decRefOp", ",", "nil", "\n", "}" ]
// decApplicationOffersRefOp returns a txn.Op that decrements the reference // count for an application offer.
[ "decApplicationOffersRefOp", "returns", "a", "txn", ".", "Op", "that", "decrements", "the", "reference", "count", "for", "an", "application", "offer", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1849-L1858
157,678
juju/juju
state/application.go
incUnitCountOp
func (a *Application) incUnitCountOp(asserts bson.D) txn.Op { op := txn.Op{ C: applicationsC, Id: a.doc.DocID, Update: bson.D{{"$inc", bson.D{{"unitcount", 1}}}}, } if len(asserts) > 0 { op.Assert = asserts } return op }
go
func (a *Application) incUnitCountOp(asserts bson.D) txn.Op { op := txn.Op{ C: applicationsC, Id: a.doc.DocID, Update: bson.D{{"$inc", bson.D{{"unitcount", 1}}}}, } if len(asserts) > 0 { op.Assert = asserts } return op }
[ "func", "(", "a", "*", "Application", ")", "incUnitCountOp", "(", "asserts", "bson", ".", "D", ")", "txn", ".", "Op", "{", "op", ":=", "txn", ".", "Op", "{", "C", ":", "applicationsC", ",", "Id", ":", "a", ".", "doc", ".", "DocID", ",", "Update", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "bson", ".", "D", "{", "{", "\"", "\"", ",", "1", "}", "}", "}", "}", ",", "}", "\n", "if", "len", "(", "asserts", ")", ">", "0", "{", "op", ".", "Assert", "=", "asserts", "\n", "}", "\n", "return", "op", "\n", "}" ]
// incUnitCountOp returns the operation to increment the application's unit count.
[ "incUnitCountOp", "returns", "the", "operation", "to", "increment", "the", "application", "s", "unit", "count", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1861-L1871
157,679
juju/juju
state/application.go
AddUnit
func (a *Application) AddUnit(args AddUnitParams) (unit *Unit, err error) { defer errors.DeferredAnnotatef(&err, "cannot add unit to application %q", a) name, ops, err := a.addUnitOps("", args, nil) if err != nil { return nil, err } if err := a.st.db().RunTransaction(ops); err == txn.ErrAborted { if alive, err := isAlive(a.st, applicationsC, a.doc.DocID); err != nil { return nil, err } else if !alive { return nil, applicationNotAliveErr } return nil, errors.New("inconsistent state") } else if err != nil { return nil, err } return a.st.Unit(name) }
go
func (a *Application) AddUnit(args AddUnitParams) (unit *Unit, err error) { defer errors.DeferredAnnotatef(&err, "cannot add unit to application %q", a) name, ops, err := a.addUnitOps("", args, nil) if err != nil { return nil, err } if err := a.st.db().RunTransaction(ops); err == txn.ErrAborted { if alive, err := isAlive(a.st, applicationsC, a.doc.DocID); err != nil { return nil, err } else if !alive { return nil, applicationNotAliveErr } return nil, errors.New("inconsistent state") } else if err != nil { return nil, err } return a.st.Unit(name) }
[ "func", "(", "a", "*", "Application", ")", "AddUnit", "(", "args", "AddUnitParams", ")", "(", "unit", "*", "Unit", ",", "err", "error", ")", "{", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ",", "a", ")", "\n", "name", ",", "ops", ",", "err", ":=", "a", ".", "addUnitOps", "(", "\"", "\"", ",", "args", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "a", ".", "st", ".", "db", "(", ")", ".", "RunTransaction", "(", "ops", ")", ";", "err", "==", "txn", ".", "ErrAborted", "{", "if", "alive", ",", "err", ":=", "isAlive", "(", "a", ".", "st", ",", "applicationsC", ",", "a", ".", "doc", ".", "DocID", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "else", "if", "!", "alive", "{", "return", "nil", ",", "applicationNotAliveErr", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "a", ".", "st", ".", "Unit", "(", "name", ")", "\n", "}" ]
// AddUnit adds a new principal unit to the application.
[ "AddUnit", "adds", "a", "new", "principal", "unit", "to", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L1891-L1909
157,680
juju/juju
state/application.go
AllUnits
func (a *Application) AllUnits() (units []*Unit, err error) { return allUnits(a.st, a.doc.Name) }
go
func (a *Application) AllUnits() (units []*Unit, err error) { return allUnits(a.st, a.doc.Name) }
[ "func", "(", "a", "*", "Application", ")", "AllUnits", "(", ")", "(", "units", "[", "]", "*", "Unit", ",", "err", "error", ")", "{", "return", "allUnits", "(", "a", ".", "st", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}" ]
// AllUnits returns all units of the application.
[ "AllUnits", "returns", "all", "units", "of", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2046-L2048
157,681
juju/juju
state/application.go
CharmConfig
func (a *Application) CharmConfig(branchName string) (charm.Settings, error) { if a.doc.CharmURL == nil { return nil, fmt.Errorf("application charm not set") } s, err := charmSettingsWithDefaults(a.st, a.doc.CharmURL, a.Name(), branchName) return s, errors.Annotatef(err, "charm config for application %q", a.doc.Name) }
go
func (a *Application) CharmConfig(branchName string) (charm.Settings, error) { if a.doc.CharmURL == nil { return nil, fmt.Errorf("application charm not set") } s, err := charmSettingsWithDefaults(a.st, a.doc.CharmURL, a.Name(), branchName) return s, errors.Annotatef(err, "charm config for application %q", a.doc.Name) }
[ "func", "(", "a", "*", "Application", ")", "CharmConfig", "(", "branchName", "string", ")", "(", "charm", ".", "Settings", ",", "error", ")", "{", "if", "a", ".", "doc", ".", "CharmURL", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s", ",", "err", ":=", "charmSettingsWithDefaults", "(", "a", ".", "st", ",", "a", ".", "doc", ".", "CharmURL", ",", "a", ".", "Name", "(", ")", ",", "branchName", ")", "\n", "return", "s", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}" ]
// CharmConfig returns the raw user configuration for the application's charm.
[ "CharmConfig", "returns", "the", "raw", "user", "configuration", "for", "the", "application", "s", "charm", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2091-L2098
157,682
juju/juju
state/application.go
UpdateCharmConfig
func (a *Application) UpdateCharmConfig(branchName string, changes charm.Settings) error { ch, _, err := a.Charm() if err != nil { return errors.Trace(err) } changes, err = ch.Config().ValidateSettings(changes) if err != nil { return errors.Trace(err) } // TODO(fwereade) state.Settings is itself really problematic in just // about every use case. This needs to be resolved some time; but at // least the settings docs are keyed by charm url as well as application // name, so the actual impact of a race is non-threatening. current, err := readSettings(a.st.db(), settingsC, a.charmConfigKey()) if err != nil { return errors.Annotatef(err, "charm config for application %q", a.doc.Name) } if branchName == model.GenerationMaster { return errors.Trace(a.updateMasterConfig(current, changes)) } return errors.Trace(a.updateBranchConfig(branchName, current, changes)) }
go
func (a *Application) UpdateCharmConfig(branchName string, changes charm.Settings) error { ch, _, err := a.Charm() if err != nil { return errors.Trace(err) } changes, err = ch.Config().ValidateSettings(changes) if err != nil { return errors.Trace(err) } // TODO(fwereade) state.Settings is itself really problematic in just // about every use case. This needs to be resolved some time; but at // least the settings docs are keyed by charm url as well as application // name, so the actual impact of a race is non-threatening. current, err := readSettings(a.st.db(), settingsC, a.charmConfigKey()) if err != nil { return errors.Annotatef(err, "charm config for application %q", a.doc.Name) } if branchName == model.GenerationMaster { return errors.Trace(a.updateMasterConfig(current, changes)) } return errors.Trace(a.updateBranchConfig(branchName, current, changes)) }
[ "func", "(", "a", "*", "Application", ")", "UpdateCharmConfig", "(", "branchName", "string", ",", "changes", "charm", ".", "Settings", ")", "error", "{", "ch", ",", "_", ",", "err", ":=", "a", ".", "Charm", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "changes", ",", "err", "=", "ch", ".", "Config", "(", ")", ".", "ValidateSettings", "(", "changes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// TODO(fwereade) state.Settings is itself really problematic in just", "// about every use case. This needs to be resolved some time; but at", "// least the settings docs are keyed by charm url as well as application", "// name, so the actual impact of a race is non-threatening.", "current", ",", "err", ":=", "readSettings", "(", "a", ".", "st", ".", "db", "(", ")", ",", "settingsC", ",", "a", ".", "charmConfigKey", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}", "\n\n", "if", "branchName", "==", "model", ".", "GenerationMaster", "{", "return", "errors", ".", "Trace", "(", "a", ".", "updateMasterConfig", "(", "current", ",", "changes", ")", ")", "\n", "}", "\n", "return", "errors", ".", "Trace", "(", "a", ".", "updateBranchConfig", "(", "branchName", ",", "current", ",", "changes", ")", ")", "\n", "}" ]
// UpdateCharmConfig changes a application's charm config settings. Values set // to nil will be deleted; unknown and invalid values will return an error.
[ "UpdateCharmConfig", "changes", "a", "application", "s", "charm", "config", "settings", ".", "Values", "set", "to", "nil", "will", "be", "deleted", ";", "unknown", "and", "invalid", "values", "will", "return", "an", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2138-L2161
157,683
juju/juju
state/application.go
updateBranchConfig
func (a *Application) updateBranchConfig(branchName string, current *Settings, validChanges charm.Settings) error { branch, err := a.st.Branch(branchName) if err != nil { return errors.Trace(err) } return errors.Trace(branch.UpdateCharmConfig(a.Name(), current, validChanges)) }
go
func (a *Application) updateBranchConfig(branchName string, current *Settings, validChanges charm.Settings) error { branch, err := a.st.Branch(branchName) if err != nil { return errors.Trace(err) } return errors.Trace(branch.UpdateCharmConfig(a.Name(), current, validChanges)) }
[ "func", "(", "a", "*", "Application", ")", "updateBranchConfig", "(", "branchName", "string", ",", "current", "*", "Settings", ",", "validChanges", "charm", ".", "Settings", ")", "error", "{", "branch", ",", "err", ":=", "a", ".", "st", ".", "Branch", "(", "branchName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "return", "errors", ".", "Trace", "(", "branch", ".", "UpdateCharmConfig", "(", "a", ".", "Name", "(", ")", ",", "current", ",", "validChanges", ")", ")", "\n", "}" ]
// updateBranchConfig compares the incoming charm settings to the current // settings to generate a collection of changes, which is used to update the // branch with the input name.
[ "updateBranchConfig", "compares", "the", "incoming", "charm", "settings", "to", "the", "current", "settings", "to", "generate", "a", "collection", "of", "changes", "which", "is", "used", "to", "update", "the", "branch", "with", "the", "input", "name", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2180-L2187
157,684
juju/juju
state/application.go
ApplicationConfig
func (a *Application) ApplicationConfig() (application.ConfigAttributes, error) { config, err := readSettings(a.st.db(), settingsC, a.applicationConfigKey()) if errors.IsNotFound(err) || len(config.Keys()) == 0 { return application.ConfigAttributes(nil), nil } else if err != nil { return nil, errors.Annotatef(err, "application config for application %q", a.doc.Name) } return application.ConfigAttributes(config.Map()), nil }
go
func (a *Application) ApplicationConfig() (application.ConfigAttributes, error) { config, err := readSettings(a.st.db(), settingsC, a.applicationConfigKey()) if errors.IsNotFound(err) || len(config.Keys()) == 0 { return application.ConfigAttributes(nil), nil } else if err != nil { return nil, errors.Annotatef(err, "application config for application %q", a.doc.Name) } return application.ConfigAttributes(config.Map()), nil }
[ "func", "(", "a", "*", "Application", ")", "ApplicationConfig", "(", ")", "(", "application", ".", "ConfigAttributes", ",", "error", ")", "{", "config", ",", "err", ":=", "readSettings", "(", "a", ".", "st", ".", "db", "(", ")", ",", "settingsC", ",", "a", ".", "applicationConfigKey", "(", ")", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "||", "len", "(", "config", ".", "Keys", "(", ")", ")", "==", "0", "{", "return", "application", ".", "ConfigAttributes", "(", "nil", ")", ",", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}", "\n", "return", "application", ".", "ConfigAttributes", "(", "config", ".", "Map", "(", ")", ")", ",", "nil", "\n", "}" ]
// ApplicationConfig returns the configuration for the application itself.
[ "ApplicationConfig", "returns", "the", "configuration", "for", "the", "application", "itself", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2190-L2198
157,685
juju/juju
state/application.go
UpdateApplicationConfig
func (a *Application) UpdateApplicationConfig( changes application.ConfigAttributes, reset []string, schema environschema.Fields, defaults schema.Defaults, ) error { node, err := readSettings(a.st.db(), settingsC, a.applicationConfigKey()) if errors.IsNotFound(err) { return errors.Errorf("cannot update application config since no config exists for application %v", a.doc.Name) } else if err != nil { return errors.Annotatef(err, "application config for application %q", a.doc.Name) } resetKeys := set.NewStrings(reset...) for name, value := range changes { if resetKeys.Contains(name) { continue } node.Set(name, value) } for _, name := range reset { node.Delete(name) } newConfig, err := application.NewConfig(node.Map(), schema, defaults) if err != nil { return errors.Trace(err) } if err := newConfig.Validate(); err != nil { return errors.Trace(err) } // Update node so it gets coerced values with correct types. coerced := newConfig.Attributes() for _, key := range node.Keys() { node.Set(key, coerced[key]) } _, err = node.Write() return err }
go
func (a *Application) UpdateApplicationConfig( changes application.ConfigAttributes, reset []string, schema environschema.Fields, defaults schema.Defaults, ) error { node, err := readSettings(a.st.db(), settingsC, a.applicationConfigKey()) if errors.IsNotFound(err) { return errors.Errorf("cannot update application config since no config exists for application %v", a.doc.Name) } else if err != nil { return errors.Annotatef(err, "application config for application %q", a.doc.Name) } resetKeys := set.NewStrings(reset...) for name, value := range changes { if resetKeys.Contains(name) { continue } node.Set(name, value) } for _, name := range reset { node.Delete(name) } newConfig, err := application.NewConfig(node.Map(), schema, defaults) if err != nil { return errors.Trace(err) } if err := newConfig.Validate(); err != nil { return errors.Trace(err) } // Update node so it gets coerced values with correct types. coerced := newConfig.Attributes() for _, key := range node.Keys() { node.Set(key, coerced[key]) } _, err = node.Write() return err }
[ "func", "(", "a", "*", "Application", ")", "UpdateApplicationConfig", "(", "changes", "application", ".", "ConfigAttributes", ",", "reset", "[", "]", "string", ",", "schema", "environschema", ".", "Fields", ",", "defaults", "schema", ".", "Defaults", ",", ")", "error", "{", "node", ",", "err", ":=", "readSettings", "(", "a", ".", "st", ".", "db", "(", ")", ",", "settingsC", ",", "a", ".", "applicationConfigKey", "(", ")", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}", "\n", "resetKeys", ":=", "set", ".", "NewStrings", "(", "reset", "...", ")", "\n", "for", "name", ",", "value", ":=", "range", "changes", "{", "if", "resetKeys", ".", "Contains", "(", "name", ")", "{", "continue", "\n", "}", "\n", "node", ".", "Set", "(", "name", ",", "value", ")", "\n", "}", "\n", "for", "_", ",", "name", ":=", "range", "reset", "{", "node", ".", "Delete", "(", "name", ")", "\n", "}", "\n", "newConfig", ",", "err", ":=", "application", ".", "NewConfig", "(", "node", ".", "Map", "(", ")", ",", "schema", ",", "defaults", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "newConfig", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// Update node so it gets coerced values with correct types.", "coerced", ":=", "newConfig", ".", "Attributes", "(", ")", "\n", "for", "_", ",", "key", ":=", "range", "node", ".", "Keys", "(", ")", "{", "node", ".", "Set", "(", "key", ",", "coerced", "[", "key", "]", ")", "\n", "}", "\n", "_", ",", "err", "=", "node", ".", "Write", "(", ")", "\n", "return", "err", "\n", "}" ]
// UpdateApplicationConfig changes an application's config settings. // Unknown and invalid values will return an error.
[ "UpdateApplicationConfig", "changes", "an", "application", "s", "config", "settings", ".", "Unknown", "and", "invalid", "values", "will", "return", "an", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2202-L2238
157,686
juju/juju
state/application.go
LeaderSettings
func (a *Application) LeaderSettings() (map[string]string, error) { // There's no compelling reason to have these methods on Application -- and // thus require an extra db read to access them -- but it stops the State // type getting even more cluttered. doc, err := readSettingsDoc(a.st.db(), settingsC, leadershipSettingsKey(a.doc.Name)) if errors.IsNotFound(err) { return nil, errors.NotFoundf("application %q", a.doc.Name) } else if err != nil { return nil, errors.Annotatef(err, "application %q", a.doc.Name) } result := make(map[string]string) for escapedKey, interfaceValue := range doc.Settings { key := mgoutils.UnescapeKey(escapedKey) if value, _ := interfaceValue.(string); value != "" { // Empty strings are technically bad data -- when set, they clear. result[key] = value } else { // Some bad data isn't reason enough to obscure the good data. logger.Warningf("unexpected leader settings value for %s: %#v", key, interfaceValue) } } return result, nil }
go
func (a *Application) LeaderSettings() (map[string]string, error) { // There's no compelling reason to have these methods on Application -- and // thus require an extra db read to access them -- but it stops the State // type getting even more cluttered. doc, err := readSettingsDoc(a.st.db(), settingsC, leadershipSettingsKey(a.doc.Name)) if errors.IsNotFound(err) { return nil, errors.NotFoundf("application %q", a.doc.Name) } else if err != nil { return nil, errors.Annotatef(err, "application %q", a.doc.Name) } result := make(map[string]string) for escapedKey, interfaceValue := range doc.Settings { key := mgoutils.UnescapeKey(escapedKey) if value, _ := interfaceValue.(string); value != "" { // Empty strings are technically bad data -- when set, they clear. result[key] = value } else { // Some bad data isn't reason enough to obscure the good data. logger.Warningf("unexpected leader settings value for %s: %#v", key, interfaceValue) } } return result, nil }
[ "func", "(", "a", "*", "Application", ")", "LeaderSettings", "(", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "// There's no compelling reason to have these methods on Application -- and", "// thus require an extra db read to access them -- but it stops the State", "// type getting even more cluttered.", "doc", ",", "err", ":=", "readSettingsDoc", "(", "a", ".", "st", ".", "db", "(", ")", ",", "settingsC", ",", "leadershipSettingsKey", "(", "a", ".", "doc", ".", "Name", ")", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}", "\n", "result", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "escapedKey", ",", "interfaceValue", ":=", "range", "doc", ".", "Settings", "{", "key", ":=", "mgoutils", ".", "UnescapeKey", "(", "escapedKey", ")", "\n", "if", "value", ",", "_", ":=", "interfaceValue", ".", "(", "string", ")", ";", "value", "!=", "\"", "\"", "{", "// Empty strings are technically bad data -- when set, they clear.", "result", "[", "key", "]", "=", "value", "\n", "}", "else", "{", "// Some bad data isn't reason enough to obscure the good data.", "logger", ".", "Warningf", "(", "\"", "\"", ",", "key", ",", "interfaceValue", ")", "\n", "}", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// LeaderSettings returns a application's leader settings. If nothing has been set // yet, it will return an empty map; this is not an error.
[ "LeaderSettings", "returns", "a", "application", "s", "leader", "settings", ".", "If", "nothing", "has", "been", "set", "yet", "it", "will", "return", "an", "empty", "map", ";", "this", "is", "not", "an", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2242-L2265
157,687
juju/juju
state/application.go
Constraints
func (a *Application) Constraints() (constraints.Value, error) { if a.doc.Subordinate { return constraints.Value{}, ErrSubordinateConstraints } return readConstraints(a.st, a.globalKey()) }
go
func (a *Application) Constraints() (constraints.Value, error) { if a.doc.Subordinate { return constraints.Value{}, ErrSubordinateConstraints } return readConstraints(a.st, a.globalKey()) }
[ "func", "(", "a", "*", "Application", ")", "Constraints", "(", ")", "(", "constraints", ".", "Value", ",", "error", ")", "{", "if", "a", ".", "doc", ".", "Subordinate", "{", "return", "constraints", ".", "Value", "{", "}", ",", "ErrSubordinateConstraints", "\n", "}", "\n", "return", "readConstraints", "(", "a", ".", "st", ",", "a", ".", "globalKey", "(", ")", ")", "\n", "}" ]
// Constraints returns the current application constraints.
[ "Constraints", "returns", "the", "current", "application", "constraints", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2331-L2336
157,688
juju/juju
state/application.go
SetConstraints
func (a *Application) SetConstraints(cons constraints.Value) (err error) { unsupported, err := a.st.validateConstraints(cons) if len(unsupported) > 0 { logger.Warningf( "setting constraints on application %q: unsupported constraints: %v", a.Name(), strings.Join(unsupported, ",")) } else if err != nil { return err } if a.doc.Subordinate { return ErrSubordinateConstraints } defer errors.DeferredAnnotatef(&err, "cannot set constraints") if a.doc.Life != Alive { return applicationNotAliveErr } ops := []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: isAliveDoc, }} ops = append(ops, setConstraintsOp(a.globalKey(), cons)) return onAbort(a.st.db().RunTransaction(ops), applicationNotAliveErr) }
go
func (a *Application) SetConstraints(cons constraints.Value) (err error) { unsupported, err := a.st.validateConstraints(cons) if len(unsupported) > 0 { logger.Warningf( "setting constraints on application %q: unsupported constraints: %v", a.Name(), strings.Join(unsupported, ",")) } else if err != nil { return err } if a.doc.Subordinate { return ErrSubordinateConstraints } defer errors.DeferredAnnotatef(&err, "cannot set constraints") if a.doc.Life != Alive { return applicationNotAliveErr } ops := []txn.Op{{ C: applicationsC, Id: a.doc.DocID, Assert: isAliveDoc, }} ops = append(ops, setConstraintsOp(a.globalKey(), cons)) return onAbort(a.st.db().RunTransaction(ops), applicationNotAliveErr) }
[ "func", "(", "a", "*", "Application", ")", "SetConstraints", "(", "cons", "constraints", ".", "Value", ")", "(", "err", "error", ")", "{", "unsupported", ",", "err", ":=", "a", ".", "st", ".", "validateConstraints", "(", "cons", ")", "\n", "if", "len", "(", "unsupported", ")", ">", "0", "{", "logger", ".", "Warningf", "(", "\"", "\"", ",", "a", ".", "Name", "(", ")", ",", "strings", ".", "Join", "(", "unsupported", ",", "\"", "\"", ")", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "a", ".", "doc", ".", "Subordinate", "{", "return", "ErrSubordinateConstraints", "\n", "}", "\n", "defer", "errors", ".", "DeferredAnnotatef", "(", "&", "err", ",", "\"", "\"", ")", "\n", "if", "a", ".", "doc", ".", "Life", "!=", "Alive", "{", "return", "applicationNotAliveErr", "\n", "}", "\n", "ops", ":=", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "applicationsC", ",", "Id", ":", "a", ".", "doc", ".", "DocID", ",", "Assert", ":", "isAliveDoc", ",", "}", "}", "\n", "ops", "=", "append", "(", "ops", ",", "setConstraintsOp", "(", "a", ".", "globalKey", "(", ")", ",", "cons", ")", ")", "\n", "return", "onAbort", "(", "a", ".", "st", ".", "db", "(", ")", ".", "RunTransaction", "(", "ops", ")", ",", "applicationNotAliveErr", ")", "\n", "}" ]
// SetConstraints replaces the current application constraints.
[ "SetConstraints", "replaces", "the", "current", "application", "constraints", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2339-L2361
157,689
juju/juju
state/application.go
defaultEndpointBindings
func (a *Application) defaultEndpointBindings() (map[string]string, error) { if a.doc.CharmURL == nil { return map[string]string{}, nil } appCharm, _, err := a.Charm() if err != nil { return nil, errors.Trace(err) } return DefaultEndpointBindingsForCharm(appCharm.Meta()), nil }
go
func (a *Application) defaultEndpointBindings() (map[string]string, error) { if a.doc.CharmURL == nil { return map[string]string{}, nil } appCharm, _, err := a.Charm() if err != nil { return nil, errors.Trace(err) } return DefaultEndpointBindingsForCharm(appCharm.Meta()), nil }
[ "func", "(", "a", "*", "Application", ")", "defaultEndpointBindings", "(", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "if", "a", ".", "doc", ".", "CharmURL", "==", "nil", "{", "return", "map", "[", "string", "]", "string", "{", "}", ",", "nil", "\n", "}", "\n\n", "appCharm", ",", "_", ",", "err", ":=", "a", ".", "Charm", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "return", "DefaultEndpointBindingsForCharm", "(", "appCharm", ".", "Meta", "(", ")", ")", ",", "nil", "\n", "}" ]
// defaultEndpointBindings returns a map with each endpoint from the current // charm metadata bound to an empty space. If no charm URL is set yet, it // returns an empty map.
[ "defaultEndpointBindings", "returns", "a", "map", "with", "each", "endpoint", "from", "the", "current", "charm", "metadata", "bound", "to", "an", "empty", "space", ".", "If", "no", "charm", "URL", "is", "set", "yet", "it", "returns", "an", "empty", "map", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2384-L2395
157,690
juju/juju
state/application.go
SetMetricCredentials
func (a *Application) SetMetricCredentials(b []byte) error { buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { alive, err := isAlive(a.st, applicationsC, a.doc.DocID) if err != nil { return nil, errors.Trace(err) } else if !alive { return nil, applicationNotAliveErr } } ops := []txn.Op{ { C: applicationsC, Id: a.doc.DocID, Assert: isAliveDoc, Update: bson.M{"$set": bson.M{"metric-credentials": b}}, }, } return ops, nil } if err := a.st.db().Run(buildTxn); err != nil { return errors.Annotatef(err, "cannot update metric credentials") } a.doc.MetricCredentials = b return nil }
go
func (a *Application) SetMetricCredentials(b []byte) error { buildTxn := func(attempt int) ([]txn.Op, error) { if attempt > 0 { alive, err := isAlive(a.st, applicationsC, a.doc.DocID) if err != nil { return nil, errors.Trace(err) } else if !alive { return nil, applicationNotAliveErr } } ops := []txn.Op{ { C: applicationsC, Id: a.doc.DocID, Assert: isAliveDoc, Update: bson.M{"$set": bson.M{"metric-credentials": b}}, }, } return ops, nil } if err := a.st.db().Run(buildTxn); err != nil { return errors.Annotatef(err, "cannot update metric credentials") } a.doc.MetricCredentials = b return nil }
[ "func", "(", "a", "*", "Application", ")", "SetMetricCredentials", "(", "b", "[", "]", "byte", ")", "error", "{", "buildTxn", ":=", "func", "(", "attempt", "int", ")", "(", "[", "]", "txn", ".", "Op", ",", "error", ")", "{", "if", "attempt", ">", "0", "{", "alive", ",", "err", ":=", "isAlive", "(", "a", ".", "st", ",", "applicationsC", ",", "a", ".", "doc", ".", "DocID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "!", "alive", "{", "return", "nil", ",", "applicationNotAliveErr", "\n", "}", "\n", "}", "\n", "ops", ":=", "[", "]", "txn", ".", "Op", "{", "{", "C", ":", "applicationsC", ",", "Id", ":", "a", ".", "doc", ".", "DocID", ",", "Assert", ":", "isAliveDoc", ",", "Update", ":", "bson", ".", "M", "{", "\"", "\"", ":", "bson", ".", "M", "{", "\"", "\"", ":", "b", "}", "}", ",", "}", ",", "}", "\n", "return", "ops", ",", "nil", "\n", "}", "\n", "if", "err", ":=", "a", ".", "st", ".", "db", "(", ")", ".", "Run", "(", "buildTxn", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "a", ".", "doc", ".", "MetricCredentials", "=", "b", "\n", "return", "nil", "\n", "}" ]
// SetMetricCredentials updates the metric credentials associated with this application.
[ "SetMetricCredentials", "updates", "the", "metric", "credentials", "associated", "with", "this", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2403-L2428
157,691
juju/juju
state/application.go
StorageConstraints
func (a *Application) StorageConstraints() (map[string]StorageConstraints, error) { cons, err := readStorageConstraints(a.st, a.storageConstraintsKey()) if errors.IsNotFound(err) { return nil, nil } else if err != nil { return nil, errors.Annotatef(err, "application %q", a.doc.Name) } return cons, nil }
go
func (a *Application) StorageConstraints() (map[string]StorageConstraints, error) { cons, err := readStorageConstraints(a.st, a.storageConstraintsKey()) if errors.IsNotFound(err) { return nil, nil } else if err != nil { return nil, errors.Annotatef(err, "application %q", a.doc.Name) } return cons, nil }
[ "func", "(", "a", "*", "Application", ")", "StorageConstraints", "(", ")", "(", "map", "[", "string", "]", "StorageConstraints", ",", "error", ")", "{", "cons", ",", "err", ":=", "readStorageConstraints", "(", "a", ".", "st", ",", "a", ".", "storageConstraintsKey", "(", ")", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "a", ".", "doc", ".", "Name", ")", "\n", "}", "\n", "return", "cons", ",", "nil", "\n", "}" ]
// StorageConstraints returns the storage constraints for the application.
[ "StorageConstraints", "returns", "the", "storage", "constraints", "for", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2431-L2439
157,692
juju/juju
state/application.go
DeviceConstraints
func (a *Application) DeviceConstraints() (map[string]DeviceConstraints, error) { cons, err := readDeviceConstraints(a.st, a.deviceConstraintsKey()) if errors.IsNotFound(err) { return nil, nil } else if err != nil { return nil, errors.Trace(err) } return cons, nil }
go
func (a *Application) DeviceConstraints() (map[string]DeviceConstraints, error) { cons, err := readDeviceConstraints(a.st, a.deviceConstraintsKey()) if errors.IsNotFound(err) { return nil, nil } else if err != nil { return nil, errors.Trace(err) } return cons, nil }
[ "func", "(", "a", "*", "Application", ")", "DeviceConstraints", "(", ")", "(", "map", "[", "string", "]", "DeviceConstraints", ",", "error", ")", "{", "cons", ",", "err", ":=", "readDeviceConstraints", "(", "a", ".", "st", ",", "a", ".", "deviceConstraintsKey", "(", ")", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "cons", ",", "nil", "\n", "}" ]
// DeviceConstraints returns the device constraints for the application.
[ "DeviceConstraints", "returns", "the", "device", "constraints", "for", "the", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2442-L2450
157,693
juju/juju
state/application.go
Status
func (a *Application) Status() (status.StatusInfo, error) { statuses, closer := a.st.db().GetCollection(statusesC) defer closer() query := statuses.Find(bson.D{{"_id", a.globalKey()}, {"neverset", true}}) if count, err := query.Count(); err != nil { return status.StatusInfo{}, errors.Trace(err) } else if count != 0 { // This indicates that SetStatus has never been called on this application. // This in turn implies the application status document is likely to be // inaccurate, so we return aggregated unit statuses instead. // // TODO(fwereade): this is completely wrong and will produce bad results // in not-very-challenging scenarios. The leader unit remains responsible // for setting the application status in a timely way, *whether or not the // charm's hooks exists or sets an application status*. This logic should be // removed as soon as possible, and the responsibilities implemented in // the right places rather than being applied at seeming random. units, err := a.AllUnits() if err != nil { return status.StatusInfo{}, err } logger.Tracef("application %q has %d units", a.Name(), len(units)) var unitStatuses []status.StatusInfo for _, unit := range units { unitStatus, err := unit.Status() if err != nil { return status.StatusInfo{}, errors.Annotatef(err, "deriving application status from %q", unit.Name()) } unitStatuses = append(unitStatuses, unitStatus) } if len(unitStatuses) > 0 { return deriveApplicationStatus(unitStatuses), nil } } return getStatus(a.st.db(), a.globalKey(), "application") }
go
func (a *Application) Status() (status.StatusInfo, error) { statuses, closer := a.st.db().GetCollection(statusesC) defer closer() query := statuses.Find(bson.D{{"_id", a.globalKey()}, {"neverset", true}}) if count, err := query.Count(); err != nil { return status.StatusInfo{}, errors.Trace(err) } else if count != 0 { // This indicates that SetStatus has never been called on this application. // This in turn implies the application status document is likely to be // inaccurate, so we return aggregated unit statuses instead. // // TODO(fwereade): this is completely wrong and will produce bad results // in not-very-challenging scenarios. The leader unit remains responsible // for setting the application status in a timely way, *whether or not the // charm's hooks exists or sets an application status*. This logic should be // removed as soon as possible, and the responsibilities implemented in // the right places rather than being applied at seeming random. units, err := a.AllUnits() if err != nil { return status.StatusInfo{}, err } logger.Tracef("application %q has %d units", a.Name(), len(units)) var unitStatuses []status.StatusInfo for _, unit := range units { unitStatus, err := unit.Status() if err != nil { return status.StatusInfo{}, errors.Annotatef(err, "deriving application status from %q", unit.Name()) } unitStatuses = append(unitStatuses, unitStatus) } if len(unitStatuses) > 0 { return deriveApplicationStatus(unitStatuses), nil } } return getStatus(a.st.db(), a.globalKey(), "application") }
[ "func", "(", "a", "*", "Application", ")", "Status", "(", ")", "(", "status", ".", "StatusInfo", ",", "error", ")", "{", "statuses", ",", "closer", ":=", "a", ".", "st", ".", "db", "(", ")", ".", "GetCollection", "(", "statusesC", ")", "\n", "defer", "closer", "(", ")", "\n", "query", ":=", "statuses", ".", "Find", "(", "bson", ".", "D", "{", "{", "\"", "\"", ",", "a", ".", "globalKey", "(", ")", "}", ",", "{", "\"", "\"", ",", "true", "}", "}", ")", "\n", "if", "count", ",", "err", ":=", "query", ".", "Count", "(", ")", ";", "err", "!=", "nil", "{", "return", "status", ".", "StatusInfo", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "else", "if", "count", "!=", "0", "{", "// This indicates that SetStatus has never been called on this application.", "// This in turn implies the application status document is likely to be", "// inaccurate, so we return aggregated unit statuses instead.", "//", "// TODO(fwereade): this is completely wrong and will produce bad results", "// in not-very-challenging scenarios. The leader unit remains responsible", "// for setting the application status in a timely way, *whether or not the", "// charm's hooks exists or sets an application status*. This logic should be", "// removed as soon as possible, and the responsibilities implemented in", "// the right places rather than being applied at seeming random.", "units", ",", "err", ":=", "a", ".", "AllUnits", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", ".", "StatusInfo", "{", "}", ",", "err", "\n", "}", "\n", "logger", ".", "Tracef", "(", "\"", "\"", ",", "a", ".", "Name", "(", ")", ",", "len", "(", "units", ")", ")", "\n", "var", "unitStatuses", "[", "]", "status", ".", "StatusInfo", "\n", "for", "_", ",", "unit", ":=", "range", "units", "{", "unitStatus", ",", "err", ":=", "unit", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", ".", "StatusInfo", "{", "}", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "unit", ".", "Name", "(", ")", ")", "\n", "}", "\n", "unitStatuses", "=", "append", "(", "unitStatuses", ",", "unitStatus", ")", "\n", "}", "\n", "if", "len", "(", "unitStatuses", ")", ">", "0", "{", "return", "deriveApplicationStatus", "(", "unitStatuses", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "getStatus", "(", "a", ".", "st", ".", "db", "(", ")", ",", "a", ".", "globalKey", "(", ")", ",", "\"", "\"", ")", "\n", "}" ]
// Status returns the status of the application. // Only unit leaders are allowed to set the status of the application. // If no status is recorded, then there are no unit leaders and the // status is derived from the unit status values.
[ "Status", "returns", "the", "status", "of", "the", "application", ".", "Only", "unit", "leaders", "are", "allowed", "to", "set", "the", "status", "of", "the", "application", ".", "If", "no", "status", "is", "recorded", "then", "there", "are", "no", "unit", "leaders", "and", "the", "status", "is", "derived", "from", "the", "unit", "status", "values", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2456-L2491
157,694
juju/juju
state/application.go
SetOperatorStatus
func (a *Application) SetOperatorStatus(sInfo status.StatusInfo) error { m, err := a.st.Model() if err != nil { return errors.Trace(err) } if m.Type() != ModelTypeCAAS { return errors.NotSupportedf("caas operation on non-caas model") } err = setStatus(a.st.db(), setStatusParams{ badge: "operator", globalKey: applicationGlobalOperatorKey(a.Name()), status: sInfo.Status, message: sInfo.Message, rawData: sInfo.Data, updated: timeOrNow(sInfo.Since, a.st.clock()), }) if err != nil { return errors.Trace(err) } appStatus, err := a.Status() if err != nil { return errors.Trace(err) } expectWorkload, err := expectWorkload(a.st, a.Name()) if err != nil { return errors.Trace(err) } historyDoc, err := caasHistoryRewriteDoc(appStatus, sInfo, expectWorkload, caasApplicationDisplayStatus, a.st.clock()) if err != nil { return errors.Trace(err) } if historyDoc != nil { // rewriting application status history _, err = probablyUpdateStatusHistory(a.st.db(), a.globalKey(), *historyDoc) if err != nil { return errors.Trace(err) } } return nil }
go
func (a *Application) SetOperatorStatus(sInfo status.StatusInfo) error { m, err := a.st.Model() if err != nil { return errors.Trace(err) } if m.Type() != ModelTypeCAAS { return errors.NotSupportedf("caas operation on non-caas model") } err = setStatus(a.st.db(), setStatusParams{ badge: "operator", globalKey: applicationGlobalOperatorKey(a.Name()), status: sInfo.Status, message: sInfo.Message, rawData: sInfo.Data, updated: timeOrNow(sInfo.Since, a.st.clock()), }) if err != nil { return errors.Trace(err) } appStatus, err := a.Status() if err != nil { return errors.Trace(err) } expectWorkload, err := expectWorkload(a.st, a.Name()) if err != nil { return errors.Trace(err) } historyDoc, err := caasHistoryRewriteDoc(appStatus, sInfo, expectWorkload, caasApplicationDisplayStatus, a.st.clock()) if err != nil { return errors.Trace(err) } if historyDoc != nil { // rewriting application status history _, err = probablyUpdateStatusHistory(a.st.db(), a.globalKey(), *historyDoc) if err != nil { return errors.Trace(err) } } return nil }
[ "func", "(", "a", "*", "Application", ")", "SetOperatorStatus", "(", "sInfo", "status", ".", "StatusInfo", ")", "error", "{", "m", ",", "err", ":=", "a", ".", "st", ".", "Model", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "m", ".", "Type", "(", ")", "!=", "ModelTypeCAAS", "{", "return", "errors", ".", "NotSupportedf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "err", "=", "setStatus", "(", "a", ".", "st", ".", "db", "(", ")", ",", "setStatusParams", "{", "badge", ":", "\"", "\"", ",", "globalKey", ":", "applicationGlobalOperatorKey", "(", "a", ".", "Name", "(", ")", ")", ",", "status", ":", "sInfo", ".", "Status", ",", "message", ":", "sInfo", ".", "Message", ",", "rawData", ":", "sInfo", ".", "Data", ",", "updated", ":", "timeOrNow", "(", "sInfo", ".", "Since", ",", "a", ".", "st", ".", "clock", "(", ")", ")", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "appStatus", ",", "err", ":=", "a", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "expectWorkload", ",", "err", ":=", "expectWorkload", "(", "a", ".", "st", ",", "a", ".", "Name", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "historyDoc", ",", "err", ":=", "caasHistoryRewriteDoc", "(", "appStatus", ",", "sInfo", ",", "expectWorkload", ",", "caasApplicationDisplayStatus", ",", "a", ".", "st", ".", "clock", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "historyDoc", "!=", "nil", "{", "// rewriting application status history", "_", ",", "err", "=", "probablyUpdateStatusHistory", "(", "a", ".", "st", ".", "db", "(", ")", ",", "a", ".", "globalKey", "(", ")", ",", "*", "historyDoc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SetOperatorStatus sets the operator status for an application. // This is used on CAAS models.
[ "SetOperatorStatus", "sets", "the", "operator", "status", "for", "an", "application", ".", "This", "is", "used", "on", "CAAS", "models", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2553-L2593
157,695
juju/juju
state/application.go
StatusHistory
func (a *Application) StatusHistory(filter status.StatusHistoryFilter) ([]status.StatusInfo, error) { args := &statusHistoryArgs{ db: a.st.db(), globalKey: a.globalKey(), filter: filter, } return statusHistory(args) }
go
func (a *Application) StatusHistory(filter status.StatusHistoryFilter) ([]status.StatusInfo, error) { args := &statusHistoryArgs{ db: a.st.db(), globalKey: a.globalKey(), filter: filter, } return statusHistory(args) }
[ "func", "(", "a", "*", "Application", ")", "StatusHistory", "(", "filter", "status", ".", "StatusHistoryFilter", ")", "(", "[", "]", "status", ".", "StatusInfo", ",", "error", ")", "{", "args", ":=", "&", "statusHistoryArgs", "{", "db", ":", "a", ".", "st", ".", "db", "(", ")", ",", "globalKey", ":", "a", ".", "globalKey", "(", ")", ",", "filter", ":", "filter", ",", "}", "\n", "return", "statusHistory", "(", "args", ")", "\n", "}" ]
// StatusHistory returns a slice of at most filter.Size StatusInfo items // or items as old as filter.Date or items newer than now - filter.Delta time // representing past statuses for this application.
[ "StatusHistory", "returns", "a", "slice", "of", "at", "most", "filter", ".", "Size", "StatusInfo", "items", "or", "items", "as", "old", "as", "filter", ".", "Date", "or", "items", "newer", "than", "now", "-", "filter", ".", "Delta", "time", "representing", "past", "statuses", "for", "this", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2598-L2605
157,696
juju/juju
state/application.go
ApplicationAndUnitsStatus
func (a *Application) ApplicationAndUnitsStatus() (status.StatusInfo, map[string]status.StatusInfo, error) { applicationStatus, err := a.Status() if err != nil { return status.StatusInfo{}, nil, errors.Trace(err) } units, err := a.AllUnits() if err != nil { return status.StatusInfo{}, nil, err } results := make(map[string]status.StatusInfo, len(units)) for _, unit := range units { unitStatus, err := unit.Status() if err != nil { return status.StatusInfo{}, nil, err } results[unit.Name()] = unitStatus } return applicationStatus, results, nil }
go
func (a *Application) ApplicationAndUnitsStatus() (status.StatusInfo, map[string]status.StatusInfo, error) { applicationStatus, err := a.Status() if err != nil { return status.StatusInfo{}, nil, errors.Trace(err) } units, err := a.AllUnits() if err != nil { return status.StatusInfo{}, nil, err } results := make(map[string]status.StatusInfo, len(units)) for _, unit := range units { unitStatus, err := unit.Status() if err != nil { return status.StatusInfo{}, nil, err } results[unit.Name()] = unitStatus } return applicationStatus, results, nil }
[ "func", "(", "a", "*", "Application", ")", "ApplicationAndUnitsStatus", "(", ")", "(", "status", ".", "StatusInfo", ",", "map", "[", "string", "]", "status", ".", "StatusInfo", ",", "error", ")", "{", "applicationStatus", ",", "err", ":=", "a", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", ".", "StatusInfo", "{", "}", ",", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "units", ",", "err", ":=", "a", ".", "AllUnits", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", ".", "StatusInfo", "{", "}", ",", "nil", ",", "err", "\n", "}", "\n", "results", ":=", "make", "(", "map", "[", "string", "]", "status", ".", "StatusInfo", ",", "len", "(", "units", ")", ")", "\n", "for", "_", ",", "unit", ":=", "range", "units", "{", "unitStatus", ",", "err", ":=", "unit", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", ".", "StatusInfo", "{", "}", ",", "nil", ",", "err", "\n", "}", "\n", "results", "[", "unit", ".", "Name", "(", ")", "]", "=", "unitStatus", "\n", "}", "\n", "return", "applicationStatus", ",", "results", ",", "nil", "\n\n", "}" ]
// ApplicationAndUnitsStatus returns the status for this application and all its units.
[ "ApplicationAndUnitsStatus", "returns", "the", "status", "for", "this", "application", "and", "all", "its", "units", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2608-L2627
157,697
juju/juju
state/application.go
PasswordValid
func (a *Application) PasswordValid(password string) bool { agentHash := utils.AgentPasswordHash(password) if agentHash == a.doc.PasswordHash { return true } return false }
go
func (a *Application) PasswordValid(password string) bool { agentHash := utils.AgentPasswordHash(password) if agentHash == a.doc.PasswordHash { return true } return false }
[ "func", "(", "a", "*", "Application", ")", "PasswordValid", "(", "password", "string", ")", "bool", "{", "agentHash", ":=", "utils", ".", "AgentPasswordHash", "(", "password", ")", "\n", "if", "agentHash", "==", "a", ".", "doc", ".", "PasswordHash", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// PasswordValid returns whether the given password is valid // for the given application.
[ "PasswordValid", "returns", "whether", "the", "given", "password", "is", "valid", "for", "the", "given", "application", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2747-L2753
157,698
juju/juju
state/application.go
UpdateUnits
func (a *Application) UpdateUnits(unitsOp *UpdateUnitsOperation) error { return a.st.ApplyOperation(unitsOp) }
go
func (a *Application) UpdateUnits(unitsOp *UpdateUnitsOperation) error { return a.st.ApplyOperation(unitsOp) }
[ "func", "(", "a", "*", "Application", ")", "UpdateUnits", "(", "unitsOp", "*", "UpdateUnitsOperation", ")", "error", "{", "return", "a", ".", "st", ".", "ApplyOperation", "(", "unitsOp", ")", "\n", "}" ]
// UpdateUnits applies the given application unit update operations.
[ "UpdateUnits", "applies", "the", "given", "application", "unit", "update", "operations", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2767-L2769
157,699
juju/juju
state/application.go
AddOperation
func (a *Application) AddOperation(props UnitUpdateProperties) *AddUnitOperation { return &AddUnitOperation{ application: &Application{st: a.st, doc: a.doc}, props: props, } }
go
func (a *Application) AddOperation(props UnitUpdateProperties) *AddUnitOperation { return &AddUnitOperation{ application: &Application{st: a.st, doc: a.doc}, props: props, } }
[ "func", "(", "a", "*", "Application", ")", "AddOperation", "(", "props", "UnitUpdateProperties", ")", "*", "AddUnitOperation", "{", "return", "&", "AddUnitOperation", "{", "application", ":", "&", "Application", "{", "st", ":", "a", ".", "st", ",", "doc", ":", "a", ".", "doc", "}", ",", "props", ":", "props", ",", "}", "\n", "}" ]
// AddOperation returns a model operation that will add a unit.
[ "AddOperation", "returns", "a", "model", "operation", "that", "will", "add", "a", "unit", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/application.go#L2826-L2831