id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
157,200 | juju/juju | mongo/service.go | asServiceConf | func (mongoArgs *ConfigArgs) asServiceConf() common.Conf {
// See https://docs.mongodb.com/manual/reference/ulimit/.
limits := map[string]string{
"fsize": "unlimited", // file size
"cpu": "unlimited", // cpu time
"as": "unlimited", // virtual memory size
"memlock": "unlimited", // locked-in-memory size
"nofile": "64000", // open files
"nproc": "64000", // processes/threads
}
conf := common.Conf{
Desc: "juju state database",
Limit: limits,
Timeout: serviceTimeout,
ExecStart: mongoArgs.startCommand(),
ExtraScript: mongoArgs.extraScript(),
}
return conf
} | go | func (mongoArgs *ConfigArgs) asServiceConf() common.Conf {
// See https://docs.mongodb.com/manual/reference/ulimit/.
limits := map[string]string{
"fsize": "unlimited", // file size
"cpu": "unlimited", // cpu time
"as": "unlimited", // virtual memory size
"memlock": "unlimited", // locked-in-memory size
"nofile": "64000", // open files
"nproc": "64000", // processes/threads
}
conf := common.Conf{
Desc: "juju state database",
Limit: limits,
Timeout: serviceTimeout,
ExecStart: mongoArgs.startCommand(),
ExtraScript: mongoArgs.extraScript(),
}
return conf
} | [
"func",
"(",
"mongoArgs",
"*",
"ConfigArgs",
")",
"asServiceConf",
"(",
")",
"common",
".",
"Conf",
"{",
"// See https://docs.mongodb.com/manual/reference/ulimit/.",
"limits",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"/... | // asServiceConf returns the init system config for the mongo state service. | [
"asServiceConf",
"returns",
"the",
"init",
"system",
"config",
"for",
"the",
"mongo",
"state",
"service",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/mongo/service.go#L359-L377 |
157,201 | juju/juju | container/broker/kvm-broker.go | StartInstance | func (broker *kvmBroker) StartInstance(ctx context.ProviderCallContext, args environs.StartInstanceParams) (*environs.StartInstanceResult, error) {
// TODO: refactor common code out of the container brokers.
containerMachineID := args.InstanceConfig.MachineId
kvmLogger.Infof("starting kvm container for containerMachineID: %s", containerMachineID)
// TODO: Default to using the host network until we can configure. Yes,
// this is using the LxcBridge value, we should put it in the api call for
// container config.
bridgeDevice := broker.agentConfig.Value(agent.LxcBridge)
if bridgeDevice == "" {
bridgeDevice = network.DefaultKVMBridge
}
config, err := broker.api.ContainerConfig()
if err != nil {
kvmLogger.Errorf("failed to get container config: %v", err)
return nil, err
}
err = broker.prepareHost(names.NewMachineTag(containerMachineID), kvmLogger, args.Abort)
if err != nil {
return nil, errors.Trace(err)
}
preparedInfo, err := prepareOrGetContainerInterfaceInfo(
broker.api,
containerMachineID,
true, // allocate if possible, do not maintain existing.
kvmLogger,
)
if err != nil {
return nil, errors.Trace(err)
}
// Something to fallback to if there are no devices given in args.NetworkInfo
// TODO(jam): 2017-02-07, this feels like something that should never need
// to be invoked, because either StartInstance or
// prepareOrGetContainerInterfaceInfo should always return a value. The
// test suite currently doesn't think so, and I'm hesitant to munge it too
// much.
interfaces, err := finishNetworkConfig(bridgeDevice, preparedInfo)
if err != nil {
return nil, errors.Trace(err)
}
network := container.BridgeNetworkConfig(bridgeDevice, 0, interfaces)
// The provisioner worker will provide all tools it knows about
// (after applying explicitly specified constraints), which may
// include tools for architectures other than the host's.
//
// container/kvm only allows running container==host arch, so
// we constrain the tools to host arch here regardless of the
// constraints specified.
archTools, err := matchHostArchTools(args.Tools)
if err != nil {
return nil, errors.Trace(err)
}
series := archTools.OneSeries()
args.InstanceConfig.MachineContainerType = instance.KVM
if err := args.InstanceConfig.SetTools(archTools); err != nil {
return nil, errors.Trace(err)
}
cloudInitUserData, err := combinedCloudInitData(
config.CloudInitUserData,
config.ContainerInheritProperties,
series, kvmLogger)
if err != nil {
return nil, errors.Trace(err)
}
if err := instancecfg.PopulateInstanceConfig(
args.InstanceConfig,
config.ProviderType,
config.AuthorizedKeys,
config.SSLHostnameVerification,
config.LegacyProxy,
config.JujuProxy,
config.AptProxy,
config.AptMirror,
config.EnableOSRefreshUpdate,
config.EnableOSUpgrade,
cloudInitUserData,
nil,
); err != nil {
kvmLogger.Errorf("failed to populate machine config: %v", err)
return nil, err
}
storageConfig := &container.StorageConfig{
AllowMount: true,
}
inst, hardware, err := broker.manager.CreateContainer(
args.InstanceConfig, args.Constraints,
series, network, storageConfig, args.StatusCallback,
)
if err != nil {
kvmLogger.Errorf("failed to start container: %v", err)
return nil, err
}
kvmLogger.Infof("started kvm container for containerMachineID: %s, %s, %s", containerMachineID, inst.Id(), hardware.String())
return &environs.StartInstanceResult{
Instance: inst,
Hardware: hardware,
NetworkInfo: interfaces,
}, nil
} | go | func (broker *kvmBroker) StartInstance(ctx context.ProviderCallContext, args environs.StartInstanceParams) (*environs.StartInstanceResult, error) {
// TODO: refactor common code out of the container brokers.
containerMachineID := args.InstanceConfig.MachineId
kvmLogger.Infof("starting kvm container for containerMachineID: %s", containerMachineID)
// TODO: Default to using the host network until we can configure. Yes,
// this is using the LxcBridge value, we should put it in the api call for
// container config.
bridgeDevice := broker.agentConfig.Value(agent.LxcBridge)
if bridgeDevice == "" {
bridgeDevice = network.DefaultKVMBridge
}
config, err := broker.api.ContainerConfig()
if err != nil {
kvmLogger.Errorf("failed to get container config: %v", err)
return nil, err
}
err = broker.prepareHost(names.NewMachineTag(containerMachineID), kvmLogger, args.Abort)
if err != nil {
return nil, errors.Trace(err)
}
preparedInfo, err := prepareOrGetContainerInterfaceInfo(
broker.api,
containerMachineID,
true, // allocate if possible, do not maintain existing.
kvmLogger,
)
if err != nil {
return nil, errors.Trace(err)
}
// Something to fallback to if there are no devices given in args.NetworkInfo
// TODO(jam): 2017-02-07, this feels like something that should never need
// to be invoked, because either StartInstance or
// prepareOrGetContainerInterfaceInfo should always return a value. The
// test suite currently doesn't think so, and I'm hesitant to munge it too
// much.
interfaces, err := finishNetworkConfig(bridgeDevice, preparedInfo)
if err != nil {
return nil, errors.Trace(err)
}
network := container.BridgeNetworkConfig(bridgeDevice, 0, interfaces)
// The provisioner worker will provide all tools it knows about
// (after applying explicitly specified constraints), which may
// include tools for architectures other than the host's.
//
// container/kvm only allows running container==host arch, so
// we constrain the tools to host arch here regardless of the
// constraints specified.
archTools, err := matchHostArchTools(args.Tools)
if err != nil {
return nil, errors.Trace(err)
}
series := archTools.OneSeries()
args.InstanceConfig.MachineContainerType = instance.KVM
if err := args.InstanceConfig.SetTools(archTools); err != nil {
return nil, errors.Trace(err)
}
cloudInitUserData, err := combinedCloudInitData(
config.CloudInitUserData,
config.ContainerInheritProperties,
series, kvmLogger)
if err != nil {
return nil, errors.Trace(err)
}
if err := instancecfg.PopulateInstanceConfig(
args.InstanceConfig,
config.ProviderType,
config.AuthorizedKeys,
config.SSLHostnameVerification,
config.LegacyProxy,
config.JujuProxy,
config.AptProxy,
config.AptMirror,
config.EnableOSRefreshUpdate,
config.EnableOSUpgrade,
cloudInitUserData,
nil,
); err != nil {
kvmLogger.Errorf("failed to populate machine config: %v", err)
return nil, err
}
storageConfig := &container.StorageConfig{
AllowMount: true,
}
inst, hardware, err := broker.manager.CreateContainer(
args.InstanceConfig, args.Constraints,
series, network, storageConfig, args.StatusCallback,
)
if err != nil {
kvmLogger.Errorf("failed to start container: %v", err)
return nil, err
}
kvmLogger.Infof("started kvm container for containerMachineID: %s, %s, %s", containerMachineID, inst.Id(), hardware.String())
return &environs.StartInstanceResult{
Instance: inst,
Hardware: hardware,
NetworkInfo: interfaces,
}, nil
} | [
"func",
"(",
"broker",
"*",
"kvmBroker",
")",
"StartInstance",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"environs",
".",
"StartInstanceParams",
")",
"(",
"*",
"environs",
".",
"StartInstanceResult",
",",
"error",
")",
"{",
"// TODO: refact... | // StartInstance is specified in the Broker interface. | [
"StartInstance",
"is",
"specified",
"in",
"the",
"Broker",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/broker/kvm-broker.go#L55-L162 |
157,202 | juju/juju | api/firewallrules/client.go | NewClient | func NewClient(st base.APICallCloser) *Client {
frontend, backend := base.NewClientFacade(st, "FirewallRules")
return &Client{ClientFacade: frontend, st: st, facade: backend}
} | go | func NewClient(st base.APICallCloser) *Client {
frontend, backend := base.NewClientFacade(st, "FirewallRules")
return &Client{ClientFacade: frontend, st: st, facade: backend}
} | [
"func",
"NewClient",
"(",
"st",
"base",
".",
"APICallCloser",
")",
"*",
"Client",
"{",
"frontend",
",",
"backend",
":=",
"base",
".",
"NewClientFacade",
"(",
"st",
",",
"\"",
"\"",
")",
"\n",
"return",
"&",
"Client",
"{",
"ClientFacade",
":",
"frontend",... | // NewClient creates a new client for accessing the firewall rules api. | [
"NewClient",
"creates",
"a",
"new",
"client",
"for",
"accessing",
"the",
"firewall",
"rules",
"api",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/firewallrules/client.go#L21-L24 |
157,203 | juju/juju | api/firewallrules/client.go | SetFirewallRule | func (c *Client) SetFirewallRule(service string, whiteListCidrs []string) error {
serviceValue := params.KnownServiceValue(service)
if err := serviceValue.Validate(); err != nil {
return errors.Trace(err)
}
args := params.FirewallRuleArgs{
Args: []params.FirewallRule{
{
KnownService: serviceValue,
WhitelistCIDRS: whiteListCidrs,
}},
}
var results params.ErrorResults
if err := c.facade.FacadeCall("SetFirewallRules", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | go | func (c *Client) SetFirewallRule(service string, whiteListCidrs []string) error {
serviceValue := params.KnownServiceValue(service)
if err := serviceValue.Validate(); err != nil {
return errors.Trace(err)
}
args := params.FirewallRuleArgs{
Args: []params.FirewallRule{
{
KnownService: serviceValue,
WhitelistCIDRS: whiteListCidrs,
}},
}
var results params.ErrorResults
if err := c.facade.FacadeCall("SetFirewallRules", args, &results); err != nil {
return errors.Trace(err)
}
return results.OneError()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetFirewallRule",
"(",
"service",
"string",
",",
"whiteListCidrs",
"[",
"]",
"string",
")",
"error",
"{",
"serviceValue",
":=",
"params",
".",
"KnownServiceValue",
"(",
"service",
")",
"\n",
"if",
"err",
":=",
"servic... | // SetFirewallRule creates or updates a firewall rule. | [
"SetFirewallRule",
"creates",
"or",
"updates",
"a",
"firewall",
"rule",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/firewallrules/client.go#L27-L45 |
157,204 | juju/juju | api/authentication/visitor.go | NewVisitor | func NewVisitor(username string, getPassword func(string) (string, error)) *Visitor {
return &Visitor{
username: username,
getPassword: getPassword,
}
} | go | func NewVisitor(username string, getPassword func(string) (string, error)) *Visitor {
return &Visitor{
username: username,
getPassword: getPassword,
}
} | [
"func",
"NewVisitor",
"(",
"username",
"string",
",",
"getPassword",
"func",
"(",
"string",
")",
"(",
"string",
",",
"error",
")",
")",
"*",
"Visitor",
"{",
"return",
"&",
"Visitor",
"{",
"username",
":",
"username",
",",
"getPassword",
":",
"getPassword",... | // NewVisitor returns a new Visitor. | [
"NewVisitor",
"returns",
"a",
"new",
"Visitor",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/authentication/visitor.go#L26-L31 |
157,205 | juju/juju | api/authentication/visitor.go | VisitWebPage | func (v *Visitor) VisitWebPage(client *httpbakery.Client, methodURLs map[string]*url.URL) error {
methodURL := methodURLs[authMethod]
if methodURL == nil {
return httpbakery.ErrMethodNotSupported
}
password, err := v.getPassword(v.username)
if err != nil {
return err
}
// POST to the URL with username and password.
resp, err := client.PostForm(methodURL.String(), url.Values{
"user": {v.username},
"password": {password},
})
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return nil
}
var jsonError httpbakery.Error
if err := json.NewDecoder(resp.Body).Decode(&jsonError); err != nil {
return errors.Annotate(err, "unmarshalling error")
}
return &jsonError
} | go | func (v *Visitor) VisitWebPage(client *httpbakery.Client, methodURLs map[string]*url.URL) error {
methodURL := methodURLs[authMethod]
if methodURL == nil {
return httpbakery.ErrMethodNotSupported
}
password, err := v.getPassword(v.username)
if err != nil {
return err
}
// POST to the URL with username and password.
resp, err := client.PostForm(methodURL.String(), url.Values{
"user": {v.username},
"password": {password},
})
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return nil
}
var jsonError httpbakery.Error
if err := json.NewDecoder(resp.Body).Decode(&jsonError); err != nil {
return errors.Annotate(err, "unmarshalling error")
}
return &jsonError
} | [
"func",
"(",
"v",
"*",
"Visitor",
")",
"VisitWebPage",
"(",
"client",
"*",
"httpbakery",
".",
"Client",
",",
"methodURLs",
"map",
"[",
"string",
"]",
"*",
"url",
".",
"URL",
")",
"error",
"{",
"methodURL",
":=",
"methodURLs",
"[",
"authMethod",
"]",
"\... | // VisitWebPage is part of the httpbakery.Visitor interface. | [
"VisitWebPage",
"is",
"part",
"of",
"the",
"httpbakery",
".",
"Visitor",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/authentication/visitor.go#L34-L63 |
157,206 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewMockOperation | func NewMockOperation(ctrl *gomock.Controller) *MockOperation {
mock := &MockOperation{ctrl: ctrl}
mock.recorder = &MockOperationMockRecorder{mock}
return mock
} | go | func NewMockOperation(ctrl *gomock.Controller) *MockOperation {
mock := &MockOperation{ctrl: ctrl}
mock.recorder = &MockOperationMockRecorder{mock}
return mock
} | [
"func",
"NewMockOperation",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockOperation",
"{",
"mock",
":=",
"&",
"MockOperation",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockOperationMockRecorder",
"{",
"mock",
... | // NewMockOperation creates a new mock instance | [
"NewMockOperation",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L27-L31 |
157,207 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | Commit | func (mr *MockOperationMockRecorder) Commit(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Commit", reflect.TypeOf((*MockOperation)(nil).Commit), arg0)
} | go | func (mr *MockOperationMockRecorder) Commit(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Commit", reflect.TypeOf((*MockOperation)(nil).Commit), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockOperationMockRecorder",
")",
"Commit",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
... | // Commit indicates an expected call of Commit | [
"Commit",
"indicates",
"an",
"expected",
"call",
"of",
"Commit"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L47-L49 |
157,208 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | Execute | func (m *MockOperation) Execute(arg0 operation.State) (*operation.State, error) {
ret := m.ctrl.Call(m, "Execute", arg0)
ret0, _ := ret[0].(*operation.State)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockOperation) Execute(arg0 operation.State) (*operation.State, error) {
ret := m.ctrl.Call(m, "Execute", arg0)
ret0, _ := ret[0].(*operation.State)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockOperation",
")",
"Execute",
"(",
"arg0",
"operation",
".",
"State",
")",
"(",
"*",
"operation",
".",
"State",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
... | // Execute mocks base method | [
"Execute",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L52-L57 |
157,209 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NeedsGlobalMachineLock | func (m *MockOperation) NeedsGlobalMachineLock() bool {
ret := m.ctrl.Call(m, "NeedsGlobalMachineLock")
ret0, _ := ret[0].(bool)
return ret0
} | go | func (m *MockOperation) NeedsGlobalMachineLock() bool {
ret := m.ctrl.Call(m, "NeedsGlobalMachineLock")
ret0, _ := ret[0].(bool)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockOperation",
")",
"NeedsGlobalMachineLock",
"(",
")",
"bool",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",... | // NeedsGlobalMachineLock mocks base method | [
"NeedsGlobalMachineLock",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L65-L69 |
157,210 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewAcceptLeadership | func (m *MockFactory) NewAcceptLeadership() (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewAcceptLeadership")
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockFactory) NewAcceptLeadership() (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewAcceptLeadership")
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockFactory",
")",
"NewAcceptLeadership",
"(",
")",
"(",
"operation",
".",
"Operation",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret... | // NewAcceptLeadership mocks base method | [
"NewAcceptLeadership",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L125-L130 |
157,211 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewAction | func (m *MockFactory) NewAction(arg0 string) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewAction", arg0)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockFactory) NewAction(arg0 string) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewAction", arg0)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockFactory",
")",
"NewAction",
"(",
"arg0",
"string",
")",
"(",
"operation",
".",
"Operation",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",... | // NewAction mocks base method | [
"NewAction",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L138-L143 |
157,212 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewCommands | func (m *MockFactory) NewCommands(arg0 operation.CommandArgs, arg1 operation.CommandResponseFunc) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewCommands", arg0, arg1)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockFactory) NewCommands(arg0 operation.CommandArgs, arg1 operation.CommandResponseFunc) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewCommands", arg0, arg1)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockFactory",
")",
"NewCommands",
"(",
"arg0",
"operation",
".",
"CommandArgs",
",",
"arg1",
"operation",
".",
"CommandResponseFunc",
")",
"(",
"operation",
".",
"Operation",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
... | // NewCommands mocks base method | [
"NewCommands",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L151-L156 |
157,213 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewResignLeadership | func (mr *MockFactoryMockRecorder) NewResignLeadership() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewResignLeadership", reflect.TypeOf((*MockFactory)(nil).NewResignLeadership))
} | go | func (mr *MockFactoryMockRecorder) NewResignLeadership() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewResignLeadership", reflect.TypeOf((*MockFactory)(nil).NewResignLeadership))
} | [
"func",
"(",
"mr",
"*",
"MockFactoryMockRecorder",
")",
"NewResignLeadership",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
... | // NewResignLeadership indicates an expected call of NewResignLeadership | [
"NewResignLeadership",
"indicates",
"an",
"expected",
"call",
"of",
"NewResignLeadership"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L224-L226 |
157,214 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewResolvedUpgrade | func (m *MockFactory) NewResolvedUpgrade(arg0 *charm_v6.URL) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewResolvedUpgrade", arg0)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockFactory) NewResolvedUpgrade(arg0 *charm_v6.URL) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewResolvedUpgrade", arg0)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockFactory",
")",
"NewResolvedUpgrade",
"(",
"arg0",
"*",
"charm_v6",
".",
"URL",
")",
"(",
"operation",
".",
"Operation",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
... | // NewResolvedUpgrade mocks base method | [
"NewResolvedUpgrade",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L229-L234 |
157,215 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewResolvedUpgrade | func (mr *MockFactoryMockRecorder) NewResolvedUpgrade(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewResolvedUpgrade", reflect.TypeOf((*MockFactory)(nil).NewResolvedUpgrade), arg0)
} | go | func (mr *MockFactoryMockRecorder) NewResolvedUpgrade(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewResolvedUpgrade", reflect.TypeOf((*MockFactory)(nil).NewResolvedUpgrade), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockFactoryMockRecorder",
")",
"NewResolvedUpgrade",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
... | // NewResolvedUpgrade indicates an expected call of NewResolvedUpgrade | [
"NewResolvedUpgrade",
"indicates",
"an",
"expected",
"call",
"of",
"NewResolvedUpgrade"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L237-L239 |
157,216 | juju/juju | worker/uniter/operation/mocks/interface_mock.go | NewRunHook | func (m *MockFactory) NewRunHook(arg0 hook.Info) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewRunHook", arg0)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockFactory) NewRunHook(arg0 hook.Info) (operation.Operation, error) {
ret := m.ctrl.Call(m, "NewRunHook", arg0)
ret0, _ := ret[0].(operation.Operation)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockFactory",
")",
"NewRunHook",
"(",
"arg0",
"hook",
".",
"Info",
")",
"(",
"operation",
".",
"Operation",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
... | // NewRunHook mocks base method | [
"NewRunHook",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/operation/mocks/interface_mock.go#L255-L260 |
157,217 | juju/juju | worker/lease/pin.go | invoke | func (c pin) invoke(ch chan<- pin) error {
for {
select {
case <-c.stop:
return errStopped
case ch <- c:
ch = nil
case err := <-c.response:
return err
}
}
} | go | func (c pin) invoke(ch chan<- pin) error {
for {
select {
case <-c.stop:
return errStopped
case ch <- c:
ch = nil
case err := <-c.response:
return err
}
}
} | [
"func",
"(",
"c",
"pin",
")",
"invoke",
"(",
"ch",
"chan",
"<-",
"pin",
")",
"error",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"c",
".",
"stop",
":",
"return",
"errStopped",
"\n",
"case",
"ch",
"<-",
"c",
":",
"ch",
"=",
"nil",
"\n",
"case... | // invoke sends the claim on the supplied channel and waits for a response. | [
"invoke",
"sends",
"the",
"claim",
"on",
"the",
"supplied",
"channel",
"and",
"waits",
"for",
"a",
"response",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/lease/pin.go#L20-L31 |
157,218 | juju/juju | container/kvm/instance.go | ClosePorts | func (kvm *kvmInstance) ClosePorts(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error {
return fmt.Errorf("not implemented")
} | go | func (kvm *kvmInstance) ClosePorts(ctx context.ProviderCallContext, machineId string, rules []network.IngressRule) error {
return fmt.Errorf("not implemented")
} | [
"func",
"(",
"kvm",
"*",
"kvmInstance",
")",
"ClosePorts",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"machineId",
"string",
",",
"rules",
"[",
"]",
"network",
".",
"IngressRule",
")",
"error",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
... | // ClosePorts implements instances.Instance.ClosePorts. | [
"ClosePorts",
"implements",
"instances",
".",
"Instance",
".",
"ClosePorts",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/kvm/instance.go#L57-L59 |
157,219 | juju/juju | api/unitassigner/unitassigner.go | New | func New(caller base.APICaller) API {
fc := base.NewFacadeCaller(caller, uaFacade)
return API{facade: fc}
} | go | func New(caller base.APICaller) API {
fc := base.NewFacadeCaller(caller, uaFacade)
return API{facade: fc}
} | [
"func",
"New",
"(",
"caller",
"base",
".",
"APICaller",
")",
"API",
"{",
"fc",
":=",
"base",
".",
"NewFacadeCaller",
"(",
"caller",
",",
"uaFacade",
")",
"\n",
"return",
"API",
"{",
"facade",
":",
"fc",
"}",
"\n",
"}"
] | // New creates a new client-side UnitAssigner facade. | [
"New",
"creates",
"a",
"new",
"client",
"-",
"side",
"UnitAssigner",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/unitassigner/unitassigner.go#L24-L27 |
157,220 | juju/juju | api/unitassigner/unitassigner.go | AssignUnits | func (a API) AssignUnits(tags []names.UnitTag) ([]error, error) {
entities := make([]params.Entity, len(tags))
for i, tag := range tags {
entities[i] = params.Entity{Tag: tag.String()}
}
args := params.Entities{Entities: entities}
var result params.ErrorResults
if err := a.facade.FacadeCall("AssignUnits", args, &result); err != nil {
return nil, err
}
errs := make([]error, len(result.Results))
for i, e := range result.Results {
if e.Error != nil {
errs[i] = convertNotFound(e.Error)
}
}
return errs, nil
} | go | func (a API) AssignUnits(tags []names.UnitTag) ([]error, error) {
entities := make([]params.Entity, len(tags))
for i, tag := range tags {
entities[i] = params.Entity{Tag: tag.String()}
}
args := params.Entities{Entities: entities}
var result params.ErrorResults
if err := a.facade.FacadeCall("AssignUnits", args, &result); err != nil {
return nil, err
}
errs := make([]error, len(result.Results))
for i, e := range result.Results {
if e.Error != nil {
errs[i] = convertNotFound(e.Error)
}
}
return errs, nil
} | [
"func",
"(",
"a",
"API",
")",
"AssignUnits",
"(",
"tags",
"[",
"]",
"names",
".",
"UnitTag",
")",
"(",
"[",
"]",
"error",
",",
"error",
")",
"{",
"entities",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"Entity",
",",
"len",
"(",
"tags",
")",
")... | // AssignUnits tells the controller to run whatever unit assignments it has.
// Unit assignments for units that no longer exist will return an error that
// satisfies errors.IsNotFound. | [
"AssignUnits",
"tells",
"the",
"controller",
"to",
"run",
"whatever",
"unit",
"assignments",
"it",
"has",
".",
"Unit",
"assignments",
"for",
"units",
"that",
"no",
"longer",
"exist",
"will",
"return",
"an",
"error",
"that",
"satisfies",
"errors",
".",
"IsNotFo... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/unitassigner/unitassigner.go#L32-L50 |
157,221 | juju/juju | api/unitassigner/unitassigner.go | convertNotFound | func convertNotFound(err error) error {
if params.IsCodeNotFound(err) {
return errors.NewNotFound(err, "")
}
return err
} | go | func convertNotFound(err error) error {
if params.IsCodeNotFound(err) {
return errors.NewNotFound(err, "")
}
return err
} | [
"func",
"convertNotFound",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"params",
".",
"IsCodeNotFound",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"NewNotFound",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // convertNotFound converts param notfound errors into errors.notfound values. | [
"convertNotFound",
"converts",
"param",
"notfound",
"errors",
"into",
"errors",
".",
"notfound",
"values",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/unitassigner/unitassigner.go#L53-L58 |
157,222 | juju/juju | api/unitassigner/unitassigner.go | WatchUnitAssignments | func (a API) WatchUnitAssignments() (watcher.StringsWatcher, error) {
var result params.StringsWatchResult
err := a.facade.FacadeCall("WatchUnitAssignments", nil, &result)
if err != nil {
return nil, err
}
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewStringsWatcher(a.facade.RawAPICaller(), result)
return w, nil
} | go | func (a API) WatchUnitAssignments() (watcher.StringsWatcher, error) {
var result params.StringsWatchResult
err := a.facade.FacadeCall("WatchUnitAssignments", nil, &result)
if err != nil {
return nil, err
}
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewStringsWatcher(a.facade.RawAPICaller(), result)
return w, nil
} | [
"func",
"(",
"a",
"API",
")",
"WatchUnitAssignments",
"(",
")",
"(",
"watcher",
".",
"StringsWatcher",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"StringsWatchResult",
"\n",
"err",
":=",
"a",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\""... | // WatchUnitAssignments watches the server for new unit assignments to be
// created. | [
"WatchUnitAssignments",
"watches",
"the",
"server",
"for",
"new",
"unit",
"assignments",
"to",
"be",
"created",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/unitassigner/unitassigner.go#L62-L73 |
157,223 | juju/juju | api/unitassigner/unitassigner.go | SetAgentStatus | func (a API) SetAgentStatus(args params.SetStatus) error {
var result params.ErrorResults
err := a.facade.FacadeCall("SetAgentStatus", args, &result)
if err != nil {
return err
}
return result.Combine()
} | go | func (a API) SetAgentStatus(args params.SetStatus) error {
var result params.ErrorResults
err := a.facade.FacadeCall("SetAgentStatus", args, &result)
if err != nil {
return err
}
return result.Combine()
} | [
"func",
"(",
"a",
"API",
")",
"SetAgentStatus",
"(",
"args",
"params",
".",
"SetStatus",
")",
"error",
"{",
"var",
"result",
"params",
".",
"ErrorResults",
"\n",
"err",
":=",
"a",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"... | // SetAgentStatus sets the status of the unit agents. | [
"SetAgentStatus",
"sets",
"the",
"status",
"of",
"the",
"unit",
"agents",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/unitassigner/unitassigner.go#L76-L83 |
157,224 | juju/juju | service/service.go | newService | func newService(name string, conf common.Conf, initSystem, series string) (Service, error) {
var svc Service
var err error
switch initSystem {
case InitSystemWindows:
svc, err = windows.NewService(name, conf)
case InitSystemUpstart:
svc, err = upstart.NewService(name, conf), nil
case InitSystemSystemd:
svc, err = systemd.NewServiceWithDefaults(name, conf)
case InitSystemSnap:
svc, err = snap.NewServiceFromName(name, conf)
default:
return nil, errors.NotFoundf("init system %q", initSystem)
}
if err != nil {
return nil, errors.Annotatef(err, "failed to wrap service %q", name)
}
return svc, nil
} | go | func newService(name string, conf common.Conf, initSystem, series string) (Service, error) {
var svc Service
var err error
switch initSystem {
case InitSystemWindows:
svc, err = windows.NewService(name, conf)
case InitSystemUpstart:
svc, err = upstart.NewService(name, conf), nil
case InitSystemSystemd:
svc, err = systemd.NewServiceWithDefaults(name, conf)
case InitSystemSnap:
svc, err = snap.NewServiceFromName(name, conf)
default:
return nil, errors.NotFoundf("init system %q", initSystem)
}
if err != nil {
return nil, errors.Annotatef(err, "failed to wrap service %q", name)
}
return svc, nil
} | [
"func",
"newService",
"(",
"name",
"string",
",",
"conf",
"common",
".",
"Conf",
",",
"initSystem",
",",
"series",
"string",
")",
"(",
"Service",
",",
"error",
")",
"{",
"var",
"svc",
"Service",
"\n",
"var",
"err",
"error",
"\n\n",
"switch",
"initSystem"... | // this needs to be stubbed out in some tests | [
"this",
"needs",
"to",
"be",
"stubbed",
"out",
"in",
"some",
"tests"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/service.go#L135-L156 |
157,225 | juju/juju | service/service.go | ListServicesScript | func ListServicesScript() string {
commands := []string{
"init_system=$(" + DiscoverInitSystemScript() + ")",
// If the init system is not identified then the script will
// "exit 1". This is correct since the script should fail if no
// init system can be identified.
newShellSelectCommand("init_system", "exit 1", listServicesCommand),
}
return strings.Join(commands, "\n")
} | go | func ListServicesScript() string {
commands := []string{
"init_system=$(" + DiscoverInitSystemScript() + ")",
// If the init system is not identified then the script will
// "exit 1". This is correct since the script should fail if no
// init system can be identified.
newShellSelectCommand("init_system", "exit 1", listServicesCommand),
}
return strings.Join(commands, "\n")
} | [
"func",
"ListServicesScript",
"(",
")",
"string",
"{",
"commands",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"+",
"DiscoverInitSystemScript",
"(",
")",
"+",
"\"",
"\"",
",",
"// If the init system is not identified then the script will",
"// \"exit 1\". This is correct... | // ListServicesScript returns the commands that should be run to get
// a list of service names on a host. | [
"ListServicesScript",
"returns",
"the",
"commands",
"that",
"should",
"be",
"run",
"to",
"get",
"a",
"list",
"of",
"service",
"names",
"on",
"a",
"host",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/service.go#L189-L198 |
157,226 | juju/juju | service/service.go | InstallAndStart | func InstallAndStart(svc ServiceActions) error {
logger.Infof("Installing and starting service %+v", svc)
if err := svc.Install(); err != nil {
return errors.Trace(err)
}
// For various reasons the init system may take a short time to
// realise that the service has been installed.
var err error
for attempt := installStartRetryAttempts.Start(); attempt.Next(); {
if err != nil {
logger.Errorf("retrying start request (%v)", errors.Cause(err))
}
// we attempt restart if the service is running in case daemon parameters
// have changed, if its not running a regular start will happen.
if err = ManuallyRestart(svc); err == nil {
logger.Debugf("started %v", svc)
break
}
}
return errors.Trace(err)
} | go | func InstallAndStart(svc ServiceActions) error {
logger.Infof("Installing and starting service %+v", svc)
if err := svc.Install(); err != nil {
return errors.Trace(err)
}
// For various reasons the init system may take a short time to
// realise that the service has been installed.
var err error
for attempt := installStartRetryAttempts.Start(); attempt.Next(); {
if err != nil {
logger.Errorf("retrying start request (%v)", errors.Cause(err))
}
// we attempt restart if the service is running in case daemon parameters
// have changed, if its not running a regular start will happen.
if err = ManuallyRestart(svc); err == nil {
logger.Debugf("started %v", svc)
break
}
}
return errors.Trace(err)
} | [
"func",
"InstallAndStart",
"(",
"svc",
"ServiceActions",
")",
"error",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"svc",
")",
"\n",
"if",
"err",
":=",
"svc",
".",
"Install",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"... | // InstallAndStart installs the provided service and tries starting it.
// The first few Start failures are ignored. | [
"InstallAndStart",
"installs",
"the",
"provided",
"service",
"and",
"tries",
"starting",
"it",
".",
"The",
"first",
"few",
"Start",
"failures",
"are",
"ignored",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/service.go#L226-L247 |
157,227 | juju/juju | service/service.go | ManuallyRestart | func ManuallyRestart(svc ServiceActions) error {
// TODO(tsm): fix service.upstart behaviour to match other implementations
// if restartableService, ok := svc.(RestartableService); ok {
// if err := restartableService.Restart(); err != nil {
// return errors.Trace(err)
// }
// return nil
// }
if err := svc.Stop(); err != nil {
logger.Errorf("could not stop service: %v", err)
}
configureableService, ok := svc.(ConfigureableService)
if ok && configureableService.ReConfigureDuringRestart() {
if err := configureableService.Configure(); err != nil {
return errors.Trace(err)
}
return nil
}
if err := svc.Start(); err != nil {
return errors.Trace(err)
}
return nil
} | go | func ManuallyRestart(svc ServiceActions) error {
// TODO(tsm): fix service.upstart behaviour to match other implementations
// if restartableService, ok := svc.(RestartableService); ok {
// if err := restartableService.Restart(); err != nil {
// return errors.Trace(err)
// }
// return nil
// }
if err := svc.Stop(); err != nil {
logger.Errorf("could not stop service: %v", err)
}
configureableService, ok := svc.(ConfigureableService)
if ok && configureableService.ReConfigureDuringRestart() {
if err := configureableService.Configure(); err != nil {
return errors.Trace(err)
}
return nil
}
if err := svc.Start(); err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"ManuallyRestart",
"(",
"svc",
"ServiceActions",
")",
"error",
"{",
"// TODO(tsm): fix service.upstart behaviour to match other implementations",
"// if restartableService, ok := svc.(RestartableService); ok {",
"// \tif err := restartableService.Restart(); err != nil {",
"// \t\tretur... | // ManuallyRestart restarts the service by applying
// its Restart method or by falling back to calling Stop and Start | [
"ManuallyRestart",
"restarts",
"the",
"service",
"by",
"applying",
"its",
"Restart",
"method",
"or",
"by",
"falling",
"back",
"to",
"calling",
"Stop",
"and",
"Start"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/service.go#L270-L294 |
157,228 | juju/juju | service/service.go | FindUnitServiceNames | func FindUnitServiceNames(svcNames []string) map[string]string {
svcMatcher := regexp.MustCompile("^(jujud-.*unit-([a-z0-9-]+)-([0-9]+))$")
unitServices := make(map[string]string)
for _, svc := range svcNames {
if groups := svcMatcher.FindStringSubmatch(svc); len(groups) > 0 {
unitName := groups[2] + "/" + groups[3]
if names.IsValidUnit(unitName) {
unitServices[unitName] = groups[1]
}
}
}
return unitServices
} | go | func FindUnitServiceNames(svcNames []string) map[string]string {
svcMatcher := regexp.MustCompile("^(jujud-.*unit-([a-z0-9-]+)-([0-9]+))$")
unitServices := make(map[string]string)
for _, svc := range svcNames {
if groups := svcMatcher.FindStringSubmatch(svc); len(groups) > 0 {
unitName := groups[2] + "/" + groups[3]
if names.IsValidUnit(unitName) {
unitServices[unitName] = groups[1]
}
}
}
return unitServices
} | [
"func",
"FindUnitServiceNames",
"(",
"svcNames",
"[",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"svcMatcher",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"unitServices",
":=",
"make",
"(",
"map",
"[",
"string",
"]"... | // FindUnitServiceNames accepts a collection of service names as managed by the
// local init system. Any that are identified as being for unit agents are
// returned, keyed on the unit name. | [
"FindUnitServiceNames",
"accepts",
"a",
"collection",
"of",
"service",
"names",
"as",
"managed",
"by",
"the",
"local",
"init",
"system",
".",
"Any",
"that",
"are",
"identified",
"as",
"being",
"for",
"unit",
"agents",
"are",
"returned",
"keyed",
"on",
"the",
... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/service.go#L299-L311 |
157,229 | juju/juju | caas/kubernetes/clientconfig/k8s.go | EnsureK8sCredential | func EnsureK8sCredential(config *clientcmdapi.Config, contextName string) (*clientcmdapi.Config, error) {
clientset, err := newK8sClientSet(config, contextName)
if err != nil {
return nil, errors.Trace(err)
}
return ensureJujuAdminServiceAccount(clientset, config, contextName)
} | go | func EnsureK8sCredential(config *clientcmdapi.Config, contextName string) (*clientcmdapi.Config, error) {
clientset, err := newK8sClientSet(config, contextName)
if err != nil {
return nil, errors.Trace(err)
}
return ensureJujuAdminServiceAccount(clientset, config, contextName)
} | [
"func",
"EnsureK8sCredential",
"(",
"config",
"*",
"clientcmdapi",
".",
"Config",
",",
"contextName",
"string",
")",
"(",
"*",
"clientcmdapi",
".",
"Config",
",",
"error",
")",
"{",
"clientset",
",",
"err",
":=",
"newK8sClientSet",
"(",
"config",
",",
"conte... | // EnsureK8sCredential ensures juju admin service account created with admin cluster role binding setup. | [
"EnsureK8sCredential",
"ensures",
"juju",
"admin",
"service",
"account",
"created",
"with",
"admin",
"cluster",
"role",
"binding",
"setup",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/clientconfig/k8s.go#L26-L32 |
157,230 | juju/juju | caas/kubernetes/clientconfig/k8s.go | NewK8sClientConfig | func NewK8sClientConfig(reader io.Reader, contextName, clusterName string, credentialResolver K8sCredentialResolver) (*ClientConfig, error) {
if reader == nil {
var err error
reader, err = readKubeConfigFile()
if err != nil {
return nil, errors.Annotate(err, "failed to read Kubernetes config file")
}
}
content, err := ioutil.ReadAll(reader)
if err != nil {
return nil, errors.Annotate(err, "failed to read Kubernetes config")
}
config, err := parseKubeConfig(content)
if err != nil {
return nil, errors.Annotate(err, "failed to parse Kubernetes config")
}
contexts, err := contextsFromConfig(config)
if err != nil {
return nil, errors.Annotate(err, "failed to read contexts from kubernetes config")
}
var context Context
if contextName == "" {
contextName = config.CurrentContext
}
if clusterName != "" {
context, contextName, err = pickContextByClusterName(contexts, clusterName)
if err != nil {
return nil, errors.Annotatef(err, "picking context by cluster name %q", clusterName)
}
} else if contextName != "" {
context = contexts[contextName]
logger.Debugf("no cluster name specified, so use current context %q", config.CurrentContext)
}
// exclude not related contexts.
contexts = map[string]Context{}
if contextName != "" && !context.isEmpty() {
contexts[contextName] = context
}
// try find everything below based on context.
clouds, err := cloudsFromConfig(config, context.CloudName)
if err != nil {
return nil, errors.Annotate(err, "failed to read clouds from kubernetes config")
}
credentials, err := credentialsFromConfig(config, context.CredentialName)
if errors.IsNotSupported(err) && credentialResolver != nil {
// try to generate supported credential using provided credential.
config, err = credentialResolver(config, contextName)
if err != nil {
return nil, errors.Annotatef(
err, "ensuring k8s credential because auth info %q is not valid", context.CredentialName)
}
logger.Debugf("try again to get credentials from kubeconfig using the generated auth info")
credentials, err = credentialsFromConfig(config, context.CredentialName)
}
if err != nil {
return nil, errors.Annotate(err, "failed to read credentials from kubernetes config")
}
return &ClientConfig{
Type: "kubernetes",
Contexts: contexts,
CurrentContext: config.CurrentContext,
Clouds: clouds,
Credentials: credentials,
}, nil
} | go | func NewK8sClientConfig(reader io.Reader, contextName, clusterName string, credentialResolver K8sCredentialResolver) (*ClientConfig, error) {
if reader == nil {
var err error
reader, err = readKubeConfigFile()
if err != nil {
return nil, errors.Annotate(err, "failed to read Kubernetes config file")
}
}
content, err := ioutil.ReadAll(reader)
if err != nil {
return nil, errors.Annotate(err, "failed to read Kubernetes config")
}
config, err := parseKubeConfig(content)
if err != nil {
return nil, errors.Annotate(err, "failed to parse Kubernetes config")
}
contexts, err := contextsFromConfig(config)
if err != nil {
return nil, errors.Annotate(err, "failed to read contexts from kubernetes config")
}
var context Context
if contextName == "" {
contextName = config.CurrentContext
}
if clusterName != "" {
context, contextName, err = pickContextByClusterName(contexts, clusterName)
if err != nil {
return nil, errors.Annotatef(err, "picking context by cluster name %q", clusterName)
}
} else if contextName != "" {
context = contexts[contextName]
logger.Debugf("no cluster name specified, so use current context %q", config.CurrentContext)
}
// exclude not related contexts.
contexts = map[string]Context{}
if contextName != "" && !context.isEmpty() {
contexts[contextName] = context
}
// try find everything below based on context.
clouds, err := cloudsFromConfig(config, context.CloudName)
if err != nil {
return nil, errors.Annotate(err, "failed to read clouds from kubernetes config")
}
credentials, err := credentialsFromConfig(config, context.CredentialName)
if errors.IsNotSupported(err) && credentialResolver != nil {
// try to generate supported credential using provided credential.
config, err = credentialResolver(config, contextName)
if err != nil {
return nil, errors.Annotatef(
err, "ensuring k8s credential because auth info %q is not valid", context.CredentialName)
}
logger.Debugf("try again to get credentials from kubeconfig using the generated auth info")
credentials, err = credentialsFromConfig(config, context.CredentialName)
}
if err != nil {
return nil, errors.Annotate(err, "failed to read credentials from kubernetes config")
}
return &ClientConfig{
Type: "kubernetes",
Contexts: contexts,
CurrentContext: config.CurrentContext,
Clouds: clouds,
Credentials: credentials,
}, nil
} | [
"func",
"NewK8sClientConfig",
"(",
"reader",
"io",
".",
"Reader",
",",
"contextName",
",",
"clusterName",
"string",
",",
"credentialResolver",
"K8sCredentialResolver",
")",
"(",
"*",
"ClientConfig",
",",
"error",
")",
"{",
"if",
"reader",
"==",
"nil",
"{",
"va... | // NewK8sClientConfig returns a new Kubernetes client, reading the config from the specified reader. | [
"NewK8sClientConfig",
"returns",
"a",
"new",
"Kubernetes",
"client",
"reading",
"the",
"config",
"from",
"the",
"specified",
"reader",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/clientconfig/k8s.go#L35-L105 |
157,231 | juju/juju | caas/kubernetes/clientconfig/k8s.go | GetKubeConfigPath | func GetKubeConfigPath() string {
kubeconfig := os.Getenv(clientcmd.RecommendedConfigPathEnvVar)
if kubeconfig == "" {
kubeconfig = clientcmd.RecommendedHomeFile
}
logger.Debugf("The kubeconfig file path: %q", kubeconfig)
return kubeconfig
} | go | func GetKubeConfigPath() string {
kubeconfig := os.Getenv(clientcmd.RecommendedConfigPathEnvVar)
if kubeconfig == "" {
kubeconfig = clientcmd.RecommendedHomeFile
}
logger.Debugf("The kubeconfig file path: %q", kubeconfig)
return kubeconfig
} | [
"func",
"GetKubeConfigPath",
"(",
")",
"string",
"{",
"kubeconfig",
":=",
"os",
".",
"Getenv",
"(",
"clientcmd",
".",
"RecommendedConfigPathEnvVar",
")",
"\n",
"if",
"kubeconfig",
"==",
"\"",
"\"",
"{",
"kubeconfig",
"=",
"clientcmd",
".",
"RecommendedHomeFile",... | // GetKubeConfigPath - define kubeconfig file path to use | [
"GetKubeConfigPath",
"-",
"define",
"kubeconfig",
"file",
"path",
"to",
"use"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/clientconfig/k8s.go#L271-L278 |
157,232 | juju/juju | worker/pubsub/remoteserver.go | NewRemoteServer | func NewRemoteServer(config RemoteServerConfig) (RemoteServer, error) {
remote := &remoteServer{
origin: config.Origin,
target: config.Target,
info: config.APIInfo,
logger: config.Logger,
newWriter: config.NewWriter,
hub: config.Hub,
clock: config.Clock,
pending: deque.New(),
data: make(chan struct{}),
}
unsub, err := remote.hub.Subscribe(forwarder.ConnectedTopic, remote.onForwarderConnection)
if err != nil {
return nil, errors.Trace(err)
}
remote.unsubscribe = unsub
remote.tomb.Go(remote.loop)
return remote, nil
} | go | func NewRemoteServer(config RemoteServerConfig) (RemoteServer, error) {
remote := &remoteServer{
origin: config.Origin,
target: config.Target,
info: config.APIInfo,
logger: config.Logger,
newWriter: config.NewWriter,
hub: config.Hub,
clock: config.Clock,
pending: deque.New(),
data: make(chan struct{}),
}
unsub, err := remote.hub.Subscribe(forwarder.ConnectedTopic, remote.onForwarderConnection)
if err != nil {
return nil, errors.Trace(err)
}
remote.unsubscribe = unsub
remote.tomb.Go(remote.loop)
return remote, nil
} | [
"func",
"NewRemoteServer",
"(",
"config",
"RemoteServerConfig",
")",
"(",
"RemoteServer",
",",
"error",
")",
"{",
"remote",
":=",
"&",
"remoteServer",
"{",
"origin",
":",
"config",
".",
"Origin",
",",
"target",
":",
"config",
".",
"Target",
",",
"info",
":... | // NewRemoteServer creates a new RemoteServer that will connect to the remote
// apiserver and pass on messages to the pubsub endpoint of that apiserver. | [
"NewRemoteServer",
"creates",
"a",
"new",
"RemoteServer",
"that",
"will",
"connect",
"to",
"the",
"remote",
"apiserver",
"and",
"pass",
"on",
"messages",
"to",
"the",
"pubsub",
"endpoint",
"of",
"that",
"apiserver",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/pubsub/remoteserver.go#L78-L97 |
157,233 | juju/juju | worker/pubsub/remoteserver.go | Report | func (r *remoteServer) Report() map[string]interface{} {
r.mutex.Lock()
defer r.mutex.Unlock()
var status string
if r.connection == nil {
status = "disconnected"
} else {
status = "connected"
}
return map[string]interface{}{
"status": status,
"addresses": r.info.Addrs,
"queue-len": r.pending.Len(),
"sent": r.sent,
}
} | go | func (r *remoteServer) Report() map[string]interface{} {
r.mutex.Lock()
defer r.mutex.Unlock()
var status string
if r.connection == nil {
status = "disconnected"
} else {
status = "connected"
}
return map[string]interface{}{
"status": status,
"addresses": r.info.Addrs,
"queue-len": r.pending.Len(),
"sent": r.sent,
}
} | [
"func",
"(",
"r",
"*",
"remoteServer",
")",
"Report",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"status",
... | // Report provides information to the engine report.
// It should be fast and minimally blocking. | [
"Report",
"provides",
"information",
"to",
"the",
"engine",
"report",
".",
"It",
"should",
"be",
"fast",
"and",
"minimally",
"blocking",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/pubsub/remoteserver.go#L101-L117 |
157,234 | juju/juju | worker/pubsub/remoteserver.go | IntrospectionReport | func (r *remoteServer) IntrospectionReport() string {
r.mutex.Lock()
defer r.mutex.Unlock()
var status string
if r.connection == nil {
status = "disconnected"
} else {
status = "connected"
}
return fmt.Sprintf(""+
" Status: %s\n"+
" Addresses: %v\n"+
" Queue length: %d\n"+
" Sent count: %d\n",
status, r.info.Addrs, r.pending.Len(), r.sent)
} | go | func (r *remoteServer) IntrospectionReport() string {
r.mutex.Lock()
defer r.mutex.Unlock()
var status string
if r.connection == nil {
status = "disconnected"
} else {
status = "connected"
}
return fmt.Sprintf(""+
" Status: %s\n"+
" Addresses: %v\n"+
" Queue length: %d\n"+
" Sent count: %d\n",
status, r.info.Addrs, r.pending.Len(), r.sent)
} | [
"func",
"(",
"r",
"*",
"remoteServer",
")",
"IntrospectionReport",
"(",
")",
"string",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"status",
"string",
"\n",
"if",
"r",
"."... | // IntrospectionReport is the method called by the subscriber to get
// information about this server. | [
"IntrospectionReport",
"is",
"the",
"method",
"called",
"by",
"the",
"subscriber",
"to",
"get",
"information",
"about",
"this",
"server",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/pubsub/remoteserver.go#L121-L137 |
157,235 | juju/juju | worker/pubsub/remoteserver.go | UpdateAddresses | func (r *remoteServer) UpdateAddresses(addresses []string) {
r.mutex.Lock()
defer r.mutex.Unlock()
if r.connection == nil && r.stopConnecting != nil {
// We are probably trying to reconnect, so interrupt that so we don't
// get a race between setting addresses and trying to read them to
// connect. Note that we don't call the interruptConnecting method
// here because that method also tries to lock the mutex.
r.logger.Debugf("interrupting connecting due to new addresses: %v", addresses)
close(r.stopConnecting)
r.stopConnecting = nil
}
r.info.Addrs = addresses
} | go | func (r *remoteServer) UpdateAddresses(addresses []string) {
r.mutex.Lock()
defer r.mutex.Unlock()
if r.connection == nil && r.stopConnecting != nil {
// We are probably trying to reconnect, so interrupt that so we don't
// get a race between setting addresses and trying to read them to
// connect. Note that we don't call the interruptConnecting method
// here because that method also tries to lock the mutex.
r.logger.Debugf("interrupting connecting due to new addresses: %v", addresses)
close(r.stopConnecting)
r.stopConnecting = nil
}
r.info.Addrs = addresses
} | [
"func",
"(",
"r",
"*",
"remoteServer",
")",
"UpdateAddresses",
"(",
"addresses",
"[",
"]",
"string",
")",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
".",
"connection"... | // UpdateAddresses will update the addresses held for the target API server.
// If we are currently trying to connect to the target, interrupt it so we
// can try again with the new addresses. | [
"UpdateAddresses",
"will",
"update",
"the",
"addresses",
"held",
"for",
"the",
"target",
"API",
"server",
".",
"If",
"we",
"are",
"currently",
"trying",
"to",
"connect",
"to",
"the",
"target",
"interrupt",
"it",
"so",
"we",
"can",
"try",
"again",
"with",
"... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/pubsub/remoteserver.go#L156-L170 |
157,236 | juju/juju | worker/pubsub/remoteserver.go | Publish | func (r *remoteServer) Publish(message *params.PubSubMessage) {
select {
case <-r.tomb.Dying():
r.logger.Tracef("dying, don't send %q", message.Topic)
default:
r.mutex.Lock()
// Only queue the message up if we are currently connected.
notifyData := false
if r.connection != nil {
r.logger.Tracef("queue up topic %q", message.Topic)
r.pending.PushBack(message)
notifyData = r.pending.Len() == 1
} else {
r.logger.Tracef("skipping %q for %s as not connected", message.Topic, r.target)
}
r.mutex.Unlock()
if notifyData {
select {
case r.data <- struct{}{}:
case <-r.connectionReset:
r.logger.Debugf("connection reset while notifying %q for %s", message.Topic, r.target)
}
}
}
} | go | func (r *remoteServer) Publish(message *params.PubSubMessage) {
select {
case <-r.tomb.Dying():
r.logger.Tracef("dying, don't send %q", message.Topic)
default:
r.mutex.Lock()
// Only queue the message up if we are currently connected.
notifyData := false
if r.connection != nil {
r.logger.Tracef("queue up topic %q", message.Topic)
r.pending.PushBack(message)
notifyData = r.pending.Len() == 1
} else {
r.logger.Tracef("skipping %q for %s as not connected", message.Topic, r.target)
}
r.mutex.Unlock()
if notifyData {
select {
case r.data <- struct{}{}:
case <-r.connectionReset:
r.logger.Debugf("connection reset while notifying %q for %s", message.Topic, r.target)
}
}
}
} | [
"func",
"(",
"r",
"*",
"remoteServer",
")",
"Publish",
"(",
"message",
"*",
"params",
".",
"PubSubMessage",
")",
"{",
"select",
"{",
"case",
"<-",
"r",
".",
"tomb",
".",
"Dying",
"(",
")",
":",
"r",
".",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
... | // Publish queues up the message if and only if we have an active connection to
// the target apiserver. | [
"Publish",
"queues",
"up",
"the",
"message",
"if",
"and",
"only",
"if",
"we",
"have",
"an",
"active",
"connection",
"to",
"the",
"target",
"apiserver",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/pubsub/remoteserver.go#L174-L199 |
157,237 | juju/juju | worker/pubsub/remoteserver.go | nextMessage | func (r *remoteServer) nextMessage() *params.PubSubMessage {
r.mutex.Lock()
defer r.mutex.Unlock()
val, ok := r.pending.PopFront()
if !ok {
// nothing to do
return nil
}
// Even though it isn't exactly sent right now, it effectively will
// be very soon, and we want to keep this counter in the mutex lock.
r.sent++
return val.(*params.PubSubMessage)
} | go | func (r *remoteServer) nextMessage() *params.PubSubMessage {
r.mutex.Lock()
defer r.mutex.Unlock()
val, ok := r.pending.PopFront()
if !ok {
// nothing to do
return nil
}
// Even though it isn't exactly sent right now, it effectively will
// be very soon, and we want to keep this counter in the mutex lock.
r.sent++
return val.(*params.PubSubMessage)
} | [
"func",
"(",
"r",
"*",
"remoteServer",
")",
"nextMessage",
"(",
")",
"*",
"params",
".",
"PubSubMessage",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"val",
",",
"ok",
":=",
"r",... | // nextMessage returns the next queued message, and a flag to indicate empty. | [
"nextMessage",
"returns",
"the",
"next",
"queued",
"message",
"and",
"a",
"flag",
"to",
"indicate",
"empty",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/pubsub/remoteserver.go#L202-L214 |
157,238 | juju/juju | worker/pubsub/remoteserver.go | forwardMessages | func (r *remoteServer) forwardMessages(messageToSend <-chan *params.PubSubMessage, messageSent chan<- *params.PubSubMessage) {
var message *params.PubSubMessage
for {
select {
case <-r.tomb.Dying():
return
case message = <-messageToSend:
}
r.mutex.Lock()
conn := r.connection
r.mutex.Unlock()
r.logger.Tracef("forwarding %q to %s, data %v", message.Topic, r.target, message.Data)
if conn != nil {
err := conn.ForwardMessage(message)
if err != nil {
// Some problem sending, so log, close the connection, and try to reconnect.
r.logger.Infof("unable to forward message, reconnecting... : %v", err)
r.resetConnection()
}
}
select {
case <-r.tomb.Dying():
return
case messageSent <- message:
}
}
} | go | func (r *remoteServer) forwardMessages(messageToSend <-chan *params.PubSubMessage, messageSent chan<- *params.PubSubMessage) {
var message *params.PubSubMessage
for {
select {
case <-r.tomb.Dying():
return
case message = <-messageToSend:
}
r.mutex.Lock()
conn := r.connection
r.mutex.Unlock()
r.logger.Tracef("forwarding %q to %s, data %v", message.Topic, r.target, message.Data)
if conn != nil {
err := conn.ForwardMessage(message)
if err != nil {
// Some problem sending, so log, close the connection, and try to reconnect.
r.logger.Infof("unable to forward message, reconnecting... : %v", err)
r.resetConnection()
}
}
select {
case <-r.tomb.Dying():
return
case messageSent <- message:
}
}
} | [
"func",
"(",
"r",
"*",
"remoteServer",
")",
"forwardMessages",
"(",
"messageToSend",
"<-",
"chan",
"*",
"params",
".",
"PubSubMessage",
",",
"messageSent",
"chan",
"<-",
"*",
"params",
".",
"PubSubMessage",
")",
"{",
"var",
"message",
"*",
"params",
".",
"... | // forwardMessages is a goroutine whose sole purpose is to get messages off
// the messageToSend channel, try to send them over the API, and say when they
// are done with this message. This allows for the potential blocking call of
// `ForwardMessage`. If this does block for whatever reason and the worker is
// asked to shutdown, the main loop method is able to do so. That would cause
// the API connection to be closed, which would cause the `ForwardMessage` to
// be unblocked due to the error of the socket closing. | [
"forwardMessages",
"is",
"a",
"goroutine",
"whose",
"sole",
"purpose",
"is",
"to",
"get",
"messages",
"off",
"the",
"messageToSend",
"channel",
"try",
"to",
"send",
"them",
"over",
"the",
"API",
"and",
"say",
"when",
"they",
"are",
"done",
"with",
"this",
... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/pubsub/remoteserver.go#L349-L377 |
157,239 | juju/juju | migration/precheck_shim.go | Model | func (s *precheckShim) Model() (PrecheckModel, error) {
model, err := s.State.Model()
if err != nil {
return nil, errors.Trace(err)
}
return model, nil
} | go | func (s *precheckShim) Model() (PrecheckModel, error) {
model, err := s.State.Model()
if err != nil {
return nil, errors.Trace(err)
}
return model, nil
} | [
"func",
"(",
"s",
"*",
"precheckShim",
")",
"Model",
"(",
")",
"(",
"PrecheckModel",
",",
"error",
")",
"{",
"model",
",",
"err",
":=",
"s",
".",
"State",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors"... | // Model implements PrecheckBackend. | [
"Model",
"implements",
"PrecheckBackend",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L36-L42 |
157,240 | juju/juju | migration/precheck_shim.go | IsMigrationActive | func (s *precheckShim) IsMigrationActive(modelUUID string) (bool, error) {
return state.IsMigrationActive(s.State, modelUUID)
} | go | func (s *precheckShim) IsMigrationActive(modelUUID string) (bool, error) {
return state.IsMigrationActive(s.State, modelUUID)
} | [
"func",
"(",
"s",
"*",
"precheckShim",
")",
"IsMigrationActive",
"(",
"modelUUID",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"state",
".",
"IsMigrationActive",
"(",
"s",
".",
"State",
",",
"modelUUID",
")",
"\n",
"}"
] | // IsMigrationActive implements PrecheckBackend. | [
"IsMigrationActive",
"implements",
"PrecheckBackend",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L45-L47 |
157,241 | juju/juju | migration/precheck_shim.go | AgentVersion | func (s *precheckShim) AgentVersion() (version.Number, error) {
model, err := s.State.Model()
if err != nil {
return version.Zero, errors.Trace(err)
}
cfg, err := model.ModelConfig()
if err != nil {
return version.Zero, errors.Trace(err)
}
vers, ok := cfg.AgentVersion()
if !ok {
return version.Zero, errors.New("no model agent version")
}
return vers, nil
} | go | func (s *precheckShim) AgentVersion() (version.Number, error) {
model, err := s.State.Model()
if err != nil {
return version.Zero, errors.Trace(err)
}
cfg, err := model.ModelConfig()
if err != nil {
return version.Zero, errors.Trace(err)
}
vers, ok := cfg.AgentVersion()
if !ok {
return version.Zero, errors.New("no model agent version")
}
return vers, nil
} | [
"func",
"(",
"s",
"*",
"precheckShim",
")",
"AgentVersion",
"(",
")",
"(",
"version",
".",
"Number",
",",
"error",
")",
"{",
"model",
",",
"err",
":=",
"s",
".",
"State",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ver... | // AgentVersion implements PrecheckBackend. | [
"AgentVersion",
"implements",
"PrecheckBackend",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L50-L65 |
157,242 | juju/juju | migration/precheck_shim.go | AllMachines | func (s *precheckShim) AllMachines() ([]PrecheckMachine, error) {
machines, err := s.State.AllMachines()
if err != nil {
return nil, errors.Trace(err)
}
out := make([]PrecheckMachine, 0, len(machines))
for _, machine := range machines {
out = append(out, machine)
}
return out, nil
} | go | func (s *precheckShim) AllMachines() ([]PrecheckMachine, error) {
machines, err := s.State.AllMachines()
if err != nil {
return nil, errors.Trace(err)
}
out := make([]PrecheckMachine, 0, len(machines))
for _, machine := range machines {
out = append(out, machine)
}
return out, nil
} | [
"func",
"(",
"s",
"*",
"precheckShim",
")",
"AllMachines",
"(",
")",
"(",
"[",
"]",
"PrecheckMachine",
",",
"error",
")",
"{",
"machines",
",",
"err",
":=",
"s",
".",
"State",
".",
"AllMachines",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | // AllMachines implements PrecheckBackend. | [
"AllMachines",
"implements",
"PrecheckBackend",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L68-L78 |
157,243 | juju/juju | migration/precheck_shim.go | AllApplications | func (s *precheckShim) AllApplications() ([]PrecheckApplication, error) {
apps, err := s.State.AllApplications()
if err != nil {
return nil, errors.Trace(err)
}
out := make([]PrecheckApplication, 0, len(apps))
for _, app := range apps {
out = append(out, &precheckAppShim{app})
}
return out, nil
} | go | func (s *precheckShim) AllApplications() ([]PrecheckApplication, error) {
apps, err := s.State.AllApplications()
if err != nil {
return nil, errors.Trace(err)
}
out := make([]PrecheckApplication, 0, len(apps))
for _, app := range apps {
out = append(out, &precheckAppShim{app})
}
return out, nil
} | [
"func",
"(",
"s",
"*",
"precheckShim",
")",
"AllApplications",
"(",
")",
"(",
"[",
"]",
"PrecheckApplication",
",",
"error",
")",
"{",
"apps",
",",
"err",
":=",
"s",
".",
"State",
".",
"AllApplications",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",... | // AllApplications implements PrecheckBackend. | [
"AllApplications",
"implements",
"PrecheckBackend",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L81-L91 |
157,244 | juju/juju | migration/precheck_shim.go | ListPendingResources | func (s *precheckShim) ListPendingResources(app string) ([]resource.Resource, error) {
resources, err := s.resourcesSt.ListPendingResources(app)
if err != nil {
return nil, errors.Trace(err)
}
return resources, nil
} | go | func (s *precheckShim) ListPendingResources(app string) ([]resource.Resource, error) {
resources, err := s.resourcesSt.ListPendingResources(app)
if err != nil {
return nil, errors.Trace(err)
}
return resources, nil
} | [
"func",
"(",
"s",
"*",
"precheckShim",
")",
"ListPendingResources",
"(",
"app",
"string",
")",
"(",
"[",
"]",
"resource",
".",
"Resource",
",",
"error",
")",
"{",
"resources",
",",
"err",
":=",
"s",
".",
"resourcesSt",
".",
"ListPendingResources",
"(",
"... | // ListPendingResources implements PrecheckBackend. | [
"ListPendingResources",
"implements",
"PrecheckBackend",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L106-L112 |
157,245 | juju/juju | migration/precheck_shim.go | ControllerBackend | func (s *precheckShim) ControllerBackend() (PrecheckBackend, error) {
return PrecheckShim(s.controllerState, s.controllerState)
} | go | func (s *precheckShim) ControllerBackend() (PrecheckBackend, error) {
return PrecheckShim(s.controllerState, s.controllerState)
} | [
"func",
"(",
"s",
"*",
"precheckShim",
")",
"ControllerBackend",
"(",
")",
"(",
"PrecheckBackend",
",",
"error",
")",
"{",
"return",
"PrecheckShim",
"(",
"s",
".",
"controllerState",
",",
"s",
".",
"controllerState",
")",
"\n",
"}"
] | // ControllerBackend implements PrecheckBackend. | [
"ControllerBackend",
"implements",
"PrecheckBackend",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L115-L117 |
157,246 | juju/juju | migration/precheck_shim.go | AllUnits | func (s *precheckAppShim) AllUnits() ([]PrecheckUnit, error) {
units, err := s.Application.AllUnits()
if err != nil {
return nil, errors.Trace(err)
}
out := make([]PrecheckUnit, 0, len(units))
for _, unit := range units {
out = append(out, unit)
}
return out, nil
} | go | func (s *precheckAppShim) AllUnits() ([]PrecheckUnit, error) {
units, err := s.Application.AllUnits()
if err != nil {
return nil, errors.Trace(err)
}
out := make([]PrecheckUnit, 0, len(units))
for _, unit := range units {
out = append(out, unit)
}
return out, nil
} | [
"func",
"(",
"s",
"*",
"precheckAppShim",
")",
"AllUnits",
"(",
")",
"(",
"[",
"]",
"PrecheckUnit",
",",
"error",
")",
"{",
"units",
",",
"err",
":=",
"s",
".",
"Application",
".",
"AllUnits",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return"... | // AllUnits implements PrecheckApplication. | [
"AllUnits",
"implements",
"PrecheckApplication",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L142-L152 |
157,247 | juju/juju | migration/precheck_shim.go | Unit | func (s *precheckRelationShim) Unit(pu PrecheckUnit) (PrecheckRelationUnit, error) {
u, ok := pu.(*state.Unit)
if !ok {
return nil, errors.Errorf("got %T instead of *state.Unit", pu)
}
ru, err := s.Relation.Unit(u)
if err != nil {
return nil, errors.Trace(err)
}
return ru, nil
} | go | func (s *precheckRelationShim) Unit(pu PrecheckUnit) (PrecheckRelationUnit, error) {
u, ok := pu.(*state.Unit)
if !ok {
return nil, errors.Errorf("got %T instead of *state.Unit", pu)
}
ru, err := s.Relation.Unit(u)
if err != nil {
return nil, errors.Trace(err)
}
return ru, nil
} | [
"func",
"(",
"s",
"*",
"precheckRelationShim",
")",
"Unit",
"(",
"pu",
"PrecheckUnit",
")",
"(",
"PrecheckRelationUnit",
",",
"error",
")",
"{",
"u",
",",
"ok",
":=",
"pu",
".",
"(",
"*",
"state",
".",
"Unit",
")",
"\n",
"if",
"!",
"ok",
"{",
"retu... | // Unit implements PreCheckRelation. | [
"Unit",
"implements",
"PreCheckRelation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L160-L170 |
157,248 | juju/juju | migration/precheck_shim.go | IsCrossModel | func (s *precheckRelationShim) IsCrossModel() (bool, error) {
_, result, err := s.Relation.RemoteApplication()
return result, err
} | go | func (s *precheckRelationShim) IsCrossModel() (bool, error) {
_, result, err := s.Relation.RemoteApplication()
return result, err
} | [
"func",
"(",
"s",
"*",
"precheckRelationShim",
")",
"IsCrossModel",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"result",
",",
"err",
":=",
"s",
".",
"Relation",
".",
"RemoteApplication",
"(",
")",
"\n",
"return",
"result",
",",
"err",
"... | // IsCrossModel implements PreCheckRelation. | [
"IsCrossModel",
"implements",
"PreCheckRelation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/migration/precheck_shim.go#L173-L176 |
157,249 | juju/juju | caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go | NewMockApiExtensionsClientInterface | func NewMockApiExtensionsClientInterface(ctrl *gomock.Controller) *MockApiExtensionsClientInterface {
mock := &MockApiExtensionsClientInterface{ctrl: ctrl}
mock.recorder = &MockApiExtensionsClientInterfaceMockRecorder{mock}
return mock
} | go | func NewMockApiExtensionsClientInterface(ctrl *gomock.Controller) *MockApiExtensionsClientInterface {
mock := &MockApiExtensionsClientInterface{ctrl: ctrl}
mock.recorder = &MockApiExtensionsClientInterfaceMockRecorder{mock}
return mock
} | [
"func",
"NewMockApiExtensionsClientInterface",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockApiExtensionsClientInterface",
"{",
"mock",
":=",
"&",
"MockApiExtensionsClientInterface",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",... | // NewMockApiExtensionsClientInterface creates a new mock instance | [
"NewMockApiExtensionsClientInterface",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go#L27-L31 |
157,250 | juju/juju | caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go | Apiextensions | func (m *MockApiExtensionsClientInterface) Apiextensions() v1beta1.ApiextensionsV1beta1Interface {
ret := m.ctrl.Call(m, "Apiextensions")
ret0, _ := ret[0].(v1beta1.ApiextensionsV1beta1Interface)
return ret0
} | go | func (m *MockApiExtensionsClientInterface) Apiextensions() v1beta1.ApiextensionsV1beta1Interface {
ret := m.ctrl.Call(m, "Apiextensions")
ret0, _ := ret[0].(v1beta1.ApiextensionsV1beta1Interface)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockApiExtensionsClientInterface",
")",
"Apiextensions",
"(",
")",
"v1beta1",
".",
"ApiextensionsV1beta1Interface",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"re... | // Apiextensions mocks base method | [
"Apiextensions",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go#L39-L43 |
157,251 | juju/juju | caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go | Apiextensions | func (mr *MockApiExtensionsClientInterfaceMockRecorder) Apiextensions() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Apiextensions", reflect.TypeOf((*MockApiExtensionsClientInterface)(nil).Apiextensions))
} | go | func (mr *MockApiExtensionsClientInterfaceMockRecorder) Apiextensions() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Apiextensions", reflect.TypeOf((*MockApiExtensionsClientInterface)(nil).Apiextensions))
} | [
"func",
"(",
"mr",
"*",
"MockApiExtensionsClientInterfaceMockRecorder",
")",
"Apiextensions",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
... | // Apiextensions indicates an expected call of Apiextensions | [
"Apiextensions",
"indicates",
"an",
"expected",
"call",
"of",
"Apiextensions"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go#L46-L48 |
157,252 | juju/juju | caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go | Discovery | func (m *MockApiExtensionsClientInterface) Discovery() discovery.DiscoveryInterface {
ret := m.ctrl.Call(m, "Discovery")
ret0, _ := ret[0].(discovery.DiscoveryInterface)
return ret0
} | go | func (m *MockApiExtensionsClientInterface) Discovery() discovery.DiscoveryInterface {
ret := m.ctrl.Call(m, "Discovery")
ret0, _ := ret[0].(discovery.DiscoveryInterface)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockApiExtensionsClientInterface",
")",
"Discovery",
"(",
")",
"discovery",
".",
"DiscoveryInterface",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
... | // Discovery mocks base method | [
"Discovery",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/kubernetes/provider/mocks/apiextensionsclientset_mock.go#L63-L67 |
157,253 | juju/juju | apiserver/facades/client/application/trust.go | AddTrustSchemaAndDefaults | func AddTrustSchemaAndDefaults(schema environschema.Fields, defaults schema.Defaults) (environschema.Fields, schema.Defaults, error) {
newSchema, err := addTrustSchema(schema)
newDefaults := addTrustDefaults(defaults)
return newSchema, newDefaults, err
} | go | func AddTrustSchemaAndDefaults(schema environschema.Fields, defaults schema.Defaults) (environschema.Fields, schema.Defaults, error) {
newSchema, err := addTrustSchema(schema)
newDefaults := addTrustDefaults(defaults)
return newSchema, newDefaults, err
} | [
"func",
"AddTrustSchemaAndDefaults",
"(",
"schema",
"environschema",
".",
"Fields",
",",
"defaults",
"schema",
".",
"Defaults",
")",
"(",
"environschema",
".",
"Fields",
",",
"schema",
".",
"Defaults",
",",
"error",
")",
"{",
"newSchema",
",",
"err",
":=",
"... | // AddTrustSchemaAndDefaults adds trust schema fields and defaults to an existing set of schema fields and defaults. | [
"AddTrustSchemaAndDefaults",
"adds",
"trust",
"schema",
"fields",
"and",
"defaults",
"to",
"an",
"existing",
"set",
"of",
"schema",
"fields",
"and",
"defaults",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/trust.go#L29-L33 |
157,254 | juju/juju | state/state.go | ControllerTimestamp | func (st *State) ControllerTimestamp() (*time.Time, error) {
now := st.clock().Now()
return &now, nil
} | go | func (st *State) ControllerTimestamp() (*time.Time, error) {
now := st.clock().Now()
return &now, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ControllerTimestamp",
"(",
")",
"(",
"*",
"time",
".",
"Time",
",",
"error",
")",
"{",
"now",
":=",
"st",
".",
"clock",
"(",
")",
".",
"Now",
"(",
")",
"\n",
"return",
"&",
"now",
",",
"nil",
"\n",
"}"
] | // ControllerTimestamp returns the current timestamp of the backend
// controller. | [
"ControllerTimestamp",
"returns",
"the",
"current",
"timestamp",
"of",
"the",
"backend",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L169-L172 |
157,255 | juju/juju | state/state.go | ControllerOwner | func (st *State) ControllerOwner() (names.UserTag, error) {
models, closer := st.db().GetCollection(modelsC)
defer closer()
var doc map[string]string
err := models.FindId(st.ControllerModelUUID()).Select(bson.M{"owner": 1}).One(&doc)
if err != nil {
return names.UserTag{}, errors.Annotate(err, "loading controller model")
}
owner := doc["owner"]
if owner == "" {
return names.UserTag{}, errors.New("model owner missing")
}
return names.NewUserTag(owner), nil
} | go | func (st *State) ControllerOwner() (names.UserTag, error) {
models, closer := st.db().GetCollection(modelsC)
defer closer()
var doc map[string]string
err := models.FindId(st.ControllerModelUUID()).Select(bson.M{"owner": 1}).One(&doc)
if err != nil {
return names.UserTag{}, errors.Annotate(err, "loading controller model")
}
owner := doc["owner"]
if owner == "" {
return names.UserTag{}, errors.New("model owner missing")
}
return names.NewUserTag(owner), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ControllerOwner",
"(",
")",
"(",
"names",
".",
"UserTag",
",",
"error",
")",
"{",
"models",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"modelsC",
")",
"\n",
"defer",
"closer",
"... | // ControllerOwner returns the owner of the controller model. | [
"ControllerOwner",
"returns",
"the",
"owner",
"of",
"the",
"controller",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L191-L204 |
157,256 | juju/juju | state/state.go | setDyingModelToDead | func (st *State) setDyingModelToDead() error {
buildTxn := func(attempt int) ([]txn.Op, error) {
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
if model.Life() != Dying {
return nil, errors.Trace(ErrModelNotDying)
}
ops := []txn.Op{{
C: modelsC,
Id: st.ModelUUID(),
Assert: isDyingDoc,
Update: bson.M{"$set": bson.M{
"life": Dead,
"time-of-death": st.nowToTheSecond(),
}},
}, {
// Cleanup the owner:modelName unique key.
C: usermodelnameC,
Id: model.uniqueIndexID(),
Remove: true,
}}
return ops, nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | go | func (st *State) setDyingModelToDead() error {
buildTxn := func(attempt int) ([]txn.Op, error) {
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
if model.Life() != Dying {
return nil, errors.Trace(ErrModelNotDying)
}
ops := []txn.Op{{
C: modelsC,
Id: st.ModelUUID(),
Assert: isDyingDoc,
Update: bson.M{"$set": bson.M{
"life": Dead,
"time-of-death": st.nowToTheSecond(),
}},
}, {
// Cleanup the owner:modelName unique key.
C: usermodelnameC,
Id: model.uniqueIndexID(),
Remove: true,
}}
return ops, nil
}
if err := st.db().Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"setDyingModelToDead",
"(",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"model",
",",
"err",
":=",
"st",
".",
"Model",
"("... | // setDyingModelToDead sets current dying model to dead. | [
"setDyingModelToDead",
"sets",
"current",
"dying",
"model",
"to",
"dead",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L211-L240 |
157,257 | juju/juju | state/state.go | RemoveDyingModel | func (st *State) RemoveDyingModel() error {
model, err := st.Model()
if err != nil {
return errors.Trace(err)
}
if model.Life() == Alive {
return errors.Errorf("can't remove model: model still alive")
}
if model.Life() == Dying {
// set model to dead if it's dying.
if err = st.setDyingModelToDead(); err != nil {
return errors.Trace(err)
}
}
err = st.removeAllModelDocs(bson.D{{"life", Dead}})
if errors.Cause(err) == txn.ErrAborted {
return errors.New("can't remove model: model not dead")
}
return errors.Trace(err)
} | go | func (st *State) RemoveDyingModel() error {
model, err := st.Model()
if err != nil {
return errors.Trace(err)
}
if model.Life() == Alive {
return errors.Errorf("can't remove model: model still alive")
}
if model.Life() == Dying {
// set model to dead if it's dying.
if err = st.setDyingModelToDead(); err != nil {
return errors.Trace(err)
}
}
err = st.removeAllModelDocs(bson.D{{"life", Dead}})
if errors.Cause(err) == txn.ErrAborted {
return errors.New("can't remove model: model not dead")
}
return errors.Trace(err)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"RemoveDyingModel",
"(",
")",
"error",
"{",
"model",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
... | // RemoveDyingModel sets current model to dead then removes all documents from
// multi-model collections. | [
"RemoveDyingModel",
"sets",
"current",
"model",
"to",
"dead",
"then",
"removes",
"all",
"documents",
"from",
"multi",
"-",
"model",
"collections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L244-L263 |
157,258 | juju/juju | state/state.go | RemoveImportingModelDocs | func (st *State) RemoveImportingModelDocs() error {
err := st.removeAllModelDocs(bson.D{{"migration-mode", MigrationModeImporting}})
if errors.Cause(err) == txn.ErrAborted {
return errors.New("can't remove model: model not being imported for migration")
}
return errors.Trace(err)
} | go | func (st *State) RemoveImportingModelDocs() error {
err := st.removeAllModelDocs(bson.D{{"migration-mode", MigrationModeImporting}})
if errors.Cause(err) == txn.ErrAborted {
return errors.New("can't remove model: model not being imported for migration")
}
return errors.Trace(err)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"RemoveImportingModelDocs",
"(",
")",
"error",
"{",
"err",
":=",
"st",
".",
"removeAllModelDocs",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"MigrationModeImporting",
"}",
"}",
")",
"\n",
"if",
"errors",
"."... | // RemoveImportingModelDocs removes all documents from multi-model collections
// for the current model. This method asserts that the model's migration mode
// is "importing". | [
"RemoveImportingModelDocs",
"removes",
"all",
"documents",
"from",
"multi",
"-",
"model",
"collections",
"for",
"the",
"current",
"model",
".",
"This",
"method",
"asserts",
"that",
"the",
"model",
"s",
"migration",
"mode",
"is",
"importing",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L268-L274 |
157,259 | juju/juju | state/state.go | RemoveExportingModelDocs | func (st *State) RemoveExportingModelDocs() error {
err := st.removeAllModelDocs(bson.D{{"migration-mode", MigrationModeExporting}})
if errors.Cause(err) == txn.ErrAborted {
return errors.New("can't remove model: model not being exported for migration")
}
return errors.Trace(err)
} | go | func (st *State) RemoveExportingModelDocs() error {
err := st.removeAllModelDocs(bson.D{{"migration-mode", MigrationModeExporting}})
if errors.Cause(err) == txn.ErrAborted {
return errors.New("can't remove model: model not being exported for migration")
}
return errors.Trace(err)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"RemoveExportingModelDocs",
"(",
")",
"error",
"{",
"err",
":=",
"st",
".",
"removeAllModelDocs",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"MigrationModeExporting",
"}",
"}",
")",
"\n",
"if",
"errors",
"."... | // RemoveExportingModelDocs removes all documents from multi-model collections
// for the current model. This method asserts that the model's migration mode
// is "exporting". | [
"RemoveExportingModelDocs",
"removes",
"all",
"documents",
"from",
"multi",
"-",
"model",
"collections",
"for",
"the",
"current",
"model",
".",
"This",
"method",
"asserts",
"that",
"the",
"model",
"s",
"migration",
"mode",
"is",
"exporting",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L279-L285 |
157,260 | juju/juju | state/state.go | removeAllInCollectionRaw | func (st *State) removeAllInCollectionRaw(name string) error {
coll, closer := st.db().GetCollection(name)
defer closer()
_, err := coll.Writeable().RemoveAll(nil)
return errors.Trace(err)
} | go | func (st *State) removeAllInCollectionRaw(name string) error {
coll, closer := st.db().GetCollection(name)
defer closer()
_, err := coll.Writeable().RemoveAll(nil)
return errors.Trace(err)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"removeAllInCollectionRaw",
"(",
"name",
"string",
")",
"error",
"{",
"coll",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"name",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"_",
... | // removeAllInCollectionRaw removes all the documents from the given
// named collection. | [
"removeAllInCollectionRaw",
"removes",
"all",
"the",
"documents",
"from",
"the",
"given",
"named",
"collection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L377-L382 |
157,261 | juju/juju | state/state.go | removeAllInCollectionOps | func (st *State) removeAllInCollectionOps(name string) ([]txn.Op, error) {
return st.removeInCollectionOps(name, nil)
} | go | func (st *State) removeAllInCollectionOps(name string) ([]txn.Op, error) {
return st.removeInCollectionOps(name, nil)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"removeAllInCollectionOps",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"return",
"st",
".",
"removeInCollectionOps",
"(",
"name",
",",
"nil",
")",
"\n",
"}"
] | // removeAllInCollectionOps appends to ops operations to
// remove all the documents in the given named collection. | [
"removeAllInCollectionOps",
"appends",
"to",
"ops",
"operations",
"to",
"remove",
"all",
"the",
"documents",
"in",
"the",
"given",
"named",
"collection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L386-L388 |
157,262 | juju/juju | state/state.go | removeInCollectionOps | func (st *State) removeInCollectionOps(name string, sel interface{}) ([]txn.Op, error) {
coll, closer := st.db().GetCollection(name)
defer closer()
var ids []bson.M
err := coll.Find(sel).Select(bson.D{{"_id", 1}}).All(&ids)
if err != nil {
return nil, errors.Trace(err)
}
var ops []txn.Op
for _, id := range ids {
ops = append(ops, txn.Op{
C: name,
Id: id["_id"],
Remove: true,
})
}
return ops, nil
} | go | func (st *State) removeInCollectionOps(name string, sel interface{}) ([]txn.Op, error) {
coll, closer := st.db().GetCollection(name)
defer closer()
var ids []bson.M
err := coll.Find(sel).Select(bson.D{{"_id", 1}}).All(&ids)
if err != nil {
return nil, errors.Trace(err)
}
var ops []txn.Op
for _, id := range ids {
ops = append(ops, txn.Op{
C: name,
Id: id["_id"],
Remove: true,
})
}
return ops, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"removeInCollectionOps",
"(",
"name",
"string",
",",
"sel",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"coll",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
... | // removeInCollectionOps generates operations to remove all documents
// from the named collection matching a specific selector. | [
"removeInCollectionOps",
"generates",
"operations",
"to",
"remove",
"all",
"documents",
"from",
"the",
"named",
"collection",
"matching",
"a",
"specific",
"selector",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L392-L410 |
157,263 | juju/juju | state/state.go | ApplicationLeaders | func (st *State) ApplicationLeaders() (map[string]string, error) {
config, err := st.ControllerConfig()
if err != nil {
return nil, errors.Trace(err)
}
if !config.Features().Contains(feature.LegacyLeases) {
return raftleasestore.LeaseHolders(
&environMongo{st},
leaseHoldersC,
lease.ApplicationLeadershipNamespace,
st.ModelUUID(),
)
}
store, err := st.getLeadershipLeaseStore()
if err != nil {
return nil, errors.Trace(err)
}
leases := store.Leases()
result := make(map[string]string, len(leases))
for key, value := range leases {
result[key.Lease] = value.Holder
}
return result, nil
} | go | func (st *State) ApplicationLeaders() (map[string]string, error) {
config, err := st.ControllerConfig()
if err != nil {
return nil, errors.Trace(err)
}
if !config.Features().Contains(feature.LegacyLeases) {
return raftleasestore.LeaseHolders(
&environMongo{st},
leaseHoldersC,
lease.ApplicationLeadershipNamespace,
st.ModelUUID(),
)
}
store, err := st.getLeadershipLeaseStore()
if err != nil {
return nil, errors.Trace(err)
}
leases := store.Leases()
result := make(map[string]string, len(leases))
for key, value := range leases {
result[key.Lease] = value.Holder
}
return result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ApplicationLeaders",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"config",
",",
"err",
":=",
"st",
".",
"ControllerConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // ApplicationLeaders returns a map of the application name to the
// unit name that is the current leader. | [
"ApplicationLeaders",
"returns",
"a",
"map",
"of",
"the",
"application",
"name",
"to",
"the",
"unit",
"name",
"that",
"is",
"the",
"current",
"leader",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L482-L505 |
157,264 | juju/juju | state/state.go | LeaseNotifyTarget | func (st *State) LeaseNotifyTarget(logDest io.Writer, errorLogger raftleasestore.Logger) raftlease.NotifyTarget {
return raftleasestore.NewNotifyTarget(&environMongo{st}, leaseHoldersC, logDest, errorLogger)
} | go | func (st *State) LeaseNotifyTarget(logDest io.Writer, errorLogger raftleasestore.Logger) raftlease.NotifyTarget {
return raftleasestore.NewNotifyTarget(&environMongo{st}, leaseHoldersC, logDest, errorLogger)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"LeaseNotifyTarget",
"(",
"logDest",
"io",
".",
"Writer",
",",
"errorLogger",
"raftleasestore",
".",
"Logger",
")",
"raftlease",
".",
"NotifyTarget",
"{",
"return",
"raftleasestore",
".",
"NewNotifyTarget",
"(",
"&",
"envi... | // LeaseNotifyTarget returns a raftlease.NotifyTarget for storing
// lease changes in the database. | [
"LeaseNotifyTarget",
"returns",
"a",
"raftlease",
".",
"NotifyTarget",
"for",
"storing",
"lease",
"changes",
"in",
"the",
"database",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L547-L549 |
157,265 | juju/juju | state/state.go | LeaseTrapdoorFunc | func (st *State) LeaseTrapdoorFunc() raftlease.TrapdoorFunc {
return raftleasestore.MakeTrapdoorFunc(&environMongo{st}, leaseHoldersC)
} | go | func (st *State) LeaseTrapdoorFunc() raftlease.TrapdoorFunc {
return raftleasestore.MakeTrapdoorFunc(&environMongo{st}, leaseHoldersC)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"LeaseTrapdoorFunc",
"(",
")",
"raftlease",
".",
"TrapdoorFunc",
"{",
"return",
"raftleasestore",
".",
"MakeTrapdoorFunc",
"(",
"&",
"environMongo",
"{",
"st",
"}",
",",
"leaseHoldersC",
")",
"\n",
"}"
] | // LeaseTrapdoorFunc returns a raftlease.TrapdoorFunc for checking
// lease state in a database. | [
"LeaseTrapdoorFunc",
"returns",
"a",
"raftlease",
".",
"TrapdoorFunc",
"for",
"checking",
"lease",
"state",
"in",
"a",
"database",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L553-L555 |
157,266 | juju/juju | state/state.go | EnsureModelRemoved | func (st *State) EnsureModelRemoved() error {
found := map[string]int{}
var foundOrdered []string
for name, info := range st.database.Schema() {
if info.global {
continue
}
coll, closer := st.db().GetCollection(name)
defer closer()
n, err := coll.Find(nil).Count()
if err != nil {
return errors.Trace(err)
}
if n != 0 {
found[name] = n
foundOrdered = append(foundOrdered, name)
}
}
if len(found) != 0 {
errMessage := fmt.Sprintf("found documents for model with uuid %s:", st.ModelUUID())
sort.Strings(foundOrdered)
for _, name := range foundOrdered {
number := found[name]
errMessage += fmt.Sprintf(" %d %s doc,", number, name)
}
// Remove trailing comma.
errMessage = errMessage[:len(errMessage)-1]
return errors.New(errMessage)
}
return nil
} | go | func (st *State) EnsureModelRemoved() error {
found := map[string]int{}
var foundOrdered []string
for name, info := range st.database.Schema() {
if info.global {
continue
}
coll, closer := st.db().GetCollection(name)
defer closer()
n, err := coll.Find(nil).Count()
if err != nil {
return errors.Trace(err)
}
if n != 0 {
found[name] = n
foundOrdered = append(foundOrdered, name)
}
}
if len(found) != 0 {
errMessage := fmt.Sprintf("found documents for model with uuid %s:", st.ModelUUID())
sort.Strings(foundOrdered)
for _, name := range foundOrdered {
number := found[name]
errMessage += fmt.Sprintf(" %d %s doc,", number, name)
}
// Remove trailing comma.
errMessage = errMessage[:len(errMessage)-1]
return errors.New(errMessage)
}
return nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"EnsureModelRemoved",
"(",
")",
"error",
"{",
"found",
":=",
"map",
"[",
"string",
"]",
"int",
"{",
"}",
"\n",
"var",
"foundOrdered",
"[",
"]",
"string",
"\n",
"for",
"name",
",",
"info",
":=",
"range",
"st",
"... | // EnsureModelRemoved returns an error if any multi-model
// documents for this model are found. It is intended only to be used in
// tests and exported so it can be used in the tests of other packages. | [
"EnsureModelRemoved",
"returns",
"an",
"error",
"if",
"any",
"multi",
"-",
"model",
"documents",
"for",
"this",
"model",
"are",
"found",
".",
"It",
"is",
"intended",
"only",
"to",
"be",
"used",
"in",
"tests",
"and",
"exported",
"so",
"it",
"can",
"be",
"... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L571-L602 |
157,267 | juju/juju | state/state.go | MongoVersion | func (st *State) MongoVersion() (string, error) {
binfo, err := st.session.BuildInfo()
if err != nil {
return "", errors.Annotate(err, "cannot obtain mongo build info")
}
return binfo.Version, nil
} | go | func (st *State) MongoVersion() (string, error) {
binfo, err := st.session.BuildInfo()
if err != nil {
return "", errors.Annotate(err, "cannot obtain mongo build info")
}
return binfo.Version, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"MongoVersion",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"binfo",
",",
"err",
":=",
"st",
".",
"session",
".",
"BuildInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
... | // MongoVersion return the string repre | [
"MongoVersion",
"return",
"the",
"string",
"repre"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L652-L658 |
157,268 | juju/juju | state/state.go | newVersionInconsistentError | func newVersionInconsistentError(currentVersion version.Number, agents []string) *versionInconsistentError {
return &versionInconsistentError{currentVersion, agents}
} | go | func newVersionInconsistentError(currentVersion version.Number, agents []string) *versionInconsistentError {
return &versionInconsistentError{currentVersion, agents}
} | [
"func",
"newVersionInconsistentError",
"(",
"currentVersion",
"version",
".",
"Number",
",",
"agents",
"[",
"]",
"string",
")",
"*",
"versionInconsistentError",
"{",
"return",
"&",
"versionInconsistentError",
"{",
"currentVersion",
",",
"agents",
"}",
"\n",
"}"
] | // newVersionInconsistentError returns a new instance of
// versionInconsistentError. | [
"newVersionInconsistentError",
"returns",
"a",
"new",
"instance",
"of",
"versionInconsistentError",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L698-L700 |
157,269 | juju/juju | state/state.go | IsVersionInconsistentError | func IsVersionInconsistentError(e interface{}) bool {
value := e
// In case of a wrapped error, check the cause first.
cause := errors.Cause(e.(error))
if cause != nil {
value = cause
}
_, ok := value.(*versionInconsistentError)
return ok
} | go | func IsVersionInconsistentError(e interface{}) bool {
value := e
// In case of a wrapped error, check the cause first.
cause := errors.Cause(e.(error))
if cause != nil {
value = cause
}
_, ok := value.(*versionInconsistentError)
return ok
} | [
"func",
"IsVersionInconsistentError",
"(",
"e",
"interface",
"{",
"}",
")",
"bool",
"{",
"value",
":=",
"e",
"\n",
"// In case of a wrapped error, check the cause first.",
"cause",
":=",
"errors",
".",
"Cause",
"(",
"e",
".",
"(",
"error",
")",
")",
"\n",
"if"... | // IsVersionInconsistentError returns if the given error is
// versionInconsistentError. | [
"IsVersionInconsistentError",
"returns",
"if",
"the",
"given",
"error",
"is",
"versionInconsistentError",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L704-L713 |
157,270 | juju/juju | state/state.go | ModelConstraints | func (st *State) ModelConstraints() (constraints.Value, error) {
cons, err := readConstraints(st, modelGlobalKey)
return cons, errors.Trace(err)
} | go | func (st *State) ModelConstraints() (constraints.Value, error) {
cons, err := readConstraints(st, modelGlobalKey)
return cons, errors.Trace(err)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ModelConstraints",
"(",
")",
"(",
"constraints",
".",
"Value",
",",
"error",
")",
"{",
"cons",
",",
"err",
":=",
"readConstraints",
"(",
"st",
",",
"modelGlobalKey",
")",
"\n",
"return",
"cons",
",",
"errors",
"."... | // ModelConstraints returns the current model constraints. | [
"ModelConstraints",
"returns",
"the",
"current",
"model",
"constraints",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L849-L852 |
157,271 | juju/juju | state/state.go | SetModelConstraints | func (st *State) SetModelConstraints(cons constraints.Value) error {
unsupported, err := st.validateConstraints(cons)
if len(unsupported) > 0 {
logger.Warningf(
"setting model constraints: unsupported constraints: %v", strings.Join(unsupported, ","))
} else if err != nil {
return errors.Trace(err)
}
return writeConstraints(st, modelGlobalKey, cons)
} | go | func (st *State) SetModelConstraints(cons constraints.Value) error {
unsupported, err := st.validateConstraints(cons)
if len(unsupported) > 0 {
logger.Warningf(
"setting model constraints: unsupported constraints: %v", strings.Join(unsupported, ","))
} else if err != nil {
return errors.Trace(err)
}
return writeConstraints(st, modelGlobalKey, cons)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"SetModelConstraints",
"(",
"cons",
"constraints",
".",
"Value",
")",
"error",
"{",
"unsupported",
",",
"err",
":=",
"st",
".",
"validateConstraints",
"(",
"cons",
")",
"\n",
"if",
"len",
"(",
"unsupported",
")",
">"... | // SetModelConstraints replaces the current model constraints. | [
"SetModelConstraints",
"replaces",
"the",
"current",
"model",
"constraints",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L855-L864 |
157,272 | juju/juju | state/state.go | AllMachines | func (st *State) AllMachines() ([]*Machine, error) {
machinesCollection, closer := st.db().GetCollection(machinesC)
defer closer()
return st.allMachines(machinesCollection)
} | go | func (st *State) AllMachines() ([]*Machine, error) {
machinesCollection, closer := st.db().GetCollection(machinesC)
defer closer()
return st.allMachines(machinesCollection)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AllMachines",
"(",
")",
"(",
"[",
"]",
"*",
"Machine",
",",
"error",
")",
"{",
"machinesCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"machinesC",
")",
"\n",
"defer",
... | // AllMachines returns all machines in the model
// ordered by id. | [
"AllMachines",
"returns",
"all",
"machines",
"in",
"the",
"model",
"ordered",
"by",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L882-L886 |
157,273 | juju/juju | state/state.go | Machine | func (st *State) Machine(id string) (*Machine, error) {
mdoc, err := st.getMachineDoc(id)
if err != nil {
return nil, err
}
return newMachine(st, mdoc), nil
} | go | func (st *State) Machine(id string) (*Machine, error) {
mdoc, err := st.getMachineDoc(id)
if err != nil {
return nil, err
}
return newMachine(st, mdoc), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Machine",
"(",
"id",
"string",
")",
"(",
"*",
"Machine",
",",
"error",
")",
"{",
"mdoc",
",",
"err",
":=",
"st",
".",
"getMachineDoc",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // Machine returns the machine with the given id. | [
"Machine",
"returns",
"the",
"machine",
"with",
"the",
"given",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L939-L945 |
157,274 | juju/juju | state/state.go | tagToCollectionAndId | func (st *State) tagToCollectionAndId(tag names.Tag) (string, interface{}, error) {
if tag == nil {
return "", nil, errors.Errorf("tag is nil")
}
coll := ""
id := tag.Id()
switch tag := tag.(type) {
case names.MachineTag:
coll = machinesC
id = st.docID(id)
case names.ApplicationTag:
coll = applicationsC
id = st.docID(id)
case names.UnitTag:
coll = unitsC
id = st.docID(id)
case names.UserTag:
coll = usersC
if !tag.IsLocal() {
return "", nil, fmt.Errorf("%q is not a local user", tag.Id())
}
id = tag.Name()
case names.RelationTag:
coll = relationsC
id = st.docID(id)
case names.ModelTag:
coll = modelsC
case names.ActionTag:
coll = actionsC
id = tag.Id()
case names.CharmTag:
coll = charmsC
id = tag.Id()
default:
return "", nil, errors.Errorf("%q is not a valid collection tag", tag)
}
return coll, id, nil
} | go | func (st *State) tagToCollectionAndId(tag names.Tag) (string, interface{}, error) {
if tag == nil {
return "", nil, errors.Errorf("tag is nil")
}
coll := ""
id := tag.Id()
switch tag := tag.(type) {
case names.MachineTag:
coll = machinesC
id = st.docID(id)
case names.ApplicationTag:
coll = applicationsC
id = st.docID(id)
case names.UnitTag:
coll = unitsC
id = st.docID(id)
case names.UserTag:
coll = usersC
if !tag.IsLocal() {
return "", nil, fmt.Errorf("%q is not a local user", tag.Id())
}
id = tag.Name()
case names.RelationTag:
coll = relationsC
id = st.docID(id)
case names.ModelTag:
coll = modelsC
case names.ActionTag:
coll = actionsC
id = tag.Id()
case names.CharmTag:
coll = charmsC
id = tag.Id()
default:
return "", nil, errors.Errorf("%q is not a valid collection tag", tag)
}
return coll, id, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"tagToCollectionAndId",
"(",
"tag",
"names",
".",
"Tag",
")",
"(",
"string",
",",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"tag",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
... | // tagToCollectionAndId, given an entity tag, returns the collection name and id
// of the entity document. | [
"tagToCollectionAndId",
"given",
"an",
"entity",
"tag",
"returns",
"the",
"collection",
"name",
"and",
"id",
"of",
"the",
"entity",
"document",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1039-L1076 |
157,275 | juju/juju | state/state.go | addPeerRelationsOps | func (st *State) addPeerRelationsOps(applicationname string, peers map[string]charm.Relation) ([]txn.Op, error) {
now := st.clock().Now()
var ops []txn.Op
for _, rel := range peers {
relId, err := sequence(st, "relation")
if err != nil {
return nil, errors.Trace(err)
}
eps := []Endpoint{{
ApplicationName: applicationname,
Relation: rel,
}}
relKey := relationKey(eps)
relDoc := &relationDoc{
DocID: st.docID(relKey),
Key: relKey,
ModelUUID: st.ModelUUID(),
Id: relId,
Endpoints: eps,
Life: Alive,
}
relationStatusDoc := statusDoc{
Status: status.Joining,
ModelUUID: st.ModelUUID(),
Updated: now.UnixNano(),
}
ops = append(ops, txn.Op{
C: relationsC,
Id: relDoc.DocID,
Assert: txn.DocMissing,
Insert: relDoc,
}, createStatusOp(st, relationGlobalScope(relId), relationStatusDoc))
}
return ops, nil
} | go | func (st *State) addPeerRelationsOps(applicationname string, peers map[string]charm.Relation) ([]txn.Op, error) {
now := st.clock().Now()
var ops []txn.Op
for _, rel := range peers {
relId, err := sequence(st, "relation")
if err != nil {
return nil, errors.Trace(err)
}
eps := []Endpoint{{
ApplicationName: applicationname,
Relation: rel,
}}
relKey := relationKey(eps)
relDoc := &relationDoc{
DocID: st.docID(relKey),
Key: relKey,
ModelUUID: st.ModelUUID(),
Id: relId,
Endpoints: eps,
Life: Alive,
}
relationStatusDoc := statusDoc{
Status: status.Joining,
ModelUUID: st.ModelUUID(),
Updated: now.UnixNano(),
}
ops = append(ops, txn.Op{
C: relationsC,
Id: relDoc.DocID,
Assert: txn.DocMissing,
Insert: relDoc,
}, createStatusOp(st, relationGlobalScope(relId), relationStatusDoc))
}
return ops, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"addPeerRelationsOps",
"(",
"applicationname",
"string",
",",
"peers",
"map",
"[",
"string",
"]",
"charm",
".",
"Relation",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"now",
":=",
"st",
".",
... | // addPeerRelationsOps returns the operations necessary to add the
// specified application peer relations to the state. | [
"addPeerRelationsOps",
"returns",
"the",
"operations",
"necessary",
"to",
"add",
"the",
"specified",
"application",
"peer",
"relations",
"to",
"the",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1080-L1114 |
157,276 | juju/juju | state/state.go | SaveCloudService | func (st *State) SaveCloudService(args SaveCloudServiceArgs) (_ *CloudService, err error) {
defer errors.DeferredAnnotatef(&err, "cannot add cloud service %q", args.ProviderId)
doc := cloudServiceDoc{
DocID: applicationGlobalKey(args.Id),
ProviderId: args.ProviderId,
Addresses: fromNetworkAddresses(args.Addresses, OriginProvider),
}
svc := newCloudService(st, &doc)
buildTxn := func(int) ([]txn.Op, error) {
return svc.saveServiceOps(doc)
}
if err := st.db().Run(buildTxn); err != nil {
return nil, errors.Annotate(err, "failed to save cloud service")
}
return svc, nil
} | go | func (st *State) SaveCloudService(args SaveCloudServiceArgs) (_ *CloudService, err error) {
defer errors.DeferredAnnotatef(&err, "cannot add cloud service %q", args.ProviderId)
doc := cloudServiceDoc{
DocID: applicationGlobalKey(args.Id),
ProviderId: args.ProviderId,
Addresses: fromNetworkAddresses(args.Addresses, OriginProvider),
}
svc := newCloudService(st, &doc)
buildTxn := func(int) ([]txn.Op, error) {
return svc.saveServiceOps(doc)
}
if err := st.db().Run(buildTxn); err != nil {
return nil, errors.Annotate(err, "failed to save cloud service")
}
return svc, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"SaveCloudService",
"(",
"args",
"SaveCloudServiceArgs",
")",
"(",
"_",
"*",
"CloudService",
",",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"args",
... | // SaveCloudService creates a cloud service. | [
"SaveCloudService",
"creates",
"a",
"cloud",
"service",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1132-L1149 |
157,277 | juju/juju | state/state.go | CloudService | func (st *State) CloudService(id string) (*CloudService, error) {
svc := newCloudService(st, &cloudServiceDoc{DocID: st.docID(applicationGlobalKey(id))})
return svc.CloudService()
} | go | func (st *State) CloudService(id string) (*CloudService, error) {
svc := newCloudService(st, &cloudServiceDoc{DocID: st.docID(applicationGlobalKey(id))})
return svc.CloudService()
} | [
"func",
"(",
"st",
"*",
"State",
")",
"CloudService",
"(",
"id",
"string",
")",
"(",
"*",
"CloudService",
",",
"error",
")",
"{",
"svc",
":=",
"newCloudService",
"(",
"st",
",",
"&",
"cloudServiceDoc",
"{",
"DocID",
":",
"st",
".",
"docID",
"(",
"app... | // CloudService returns a cloud service state by Id. | [
"CloudService",
"returns",
"a",
"cloud",
"service",
"state",
"by",
"Id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1152-L1155 |
157,278 | juju/juju | state/state.go | removeNils | func removeNils(m map[string]interface{}) {
for k, v := range m {
if v == nil {
delete(m, k)
}
}
} | go | func removeNils(m map[string]interface{}) {
for k, v := range m {
if v == nil {
delete(m, k)
}
}
} | [
"func",
"removeNils",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"m",
"{",
"if",
"v",
"==",
"nil",
"{",
"delete",
"(",
"m",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // removeNils removes any keys with nil values from the given map. | [
"removeNils",
"removes",
"any",
"keys",
"with",
"nil",
"values",
"from",
"the",
"given",
"map",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1607-L1613 |
157,279 | juju/juju | state/state.go | assignUnitOps | func assignUnitOps(unitName string, placement instance.Placement) []txn.Op {
udoc := assignUnitDoc{
DocId: unitName,
Scope: placement.Scope,
Directive: placement.Directive,
}
return []txn.Op{{
C: assignUnitC,
Id: udoc.DocId,
Assert: txn.DocMissing,
Insert: udoc,
}}
} | go | func assignUnitOps(unitName string, placement instance.Placement) []txn.Op {
udoc := assignUnitDoc{
DocId: unitName,
Scope: placement.Scope,
Directive: placement.Directive,
}
return []txn.Op{{
C: assignUnitC,
Id: udoc.DocId,
Assert: txn.DocMissing,
Insert: udoc,
}}
} | [
"func",
"assignUnitOps",
"(",
"unitName",
"string",
",",
"placement",
"instance",
".",
"Placement",
")",
"[",
"]",
"txn",
".",
"Op",
"{",
"udoc",
":=",
"assignUnitDoc",
"{",
"DocId",
":",
"unitName",
",",
"Scope",
":",
"placement",
".",
"Scope",
",",
"Di... | // assignUnitOps returns the db ops to save unit assignment for use by the
// UnitAssigner worker. | [
"assignUnitOps",
"returns",
"the",
"db",
"ops",
"to",
"save",
"unit",
"assignment",
"for",
"use",
"by",
"the",
"UnitAssigner",
"worker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1617-L1629 |
157,280 | juju/juju | state/state.go | AssignStagedUnits | func (st *State) AssignStagedUnits(ids []string) ([]UnitAssignmentResult, error) {
query := bson.D{{"_id", bson.D{{"$in", ids}}}}
unitAssignments, err := st.unitAssignments(query)
if err != nil {
return nil, errors.Annotate(err, "getting staged unit assignments")
}
results := make([]UnitAssignmentResult, len(unitAssignments))
for i, a := range unitAssignments {
err := st.assignStagedUnit(a)
results[i].Unit = a.Unit
results[i].Error = err
}
return results, nil
} | go | func (st *State) AssignStagedUnits(ids []string) ([]UnitAssignmentResult, error) {
query := bson.D{{"_id", bson.D{{"$in", ids}}}}
unitAssignments, err := st.unitAssignments(query)
if err != nil {
return nil, errors.Annotate(err, "getting staged unit assignments")
}
results := make([]UnitAssignmentResult, len(unitAssignments))
for i, a := range unitAssignments {
err := st.assignStagedUnit(a)
results[i].Unit = a.Unit
results[i].Error = err
}
return results, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AssignStagedUnits",
"(",
"ids",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"UnitAssignmentResult",
",",
"error",
")",
"{",
"query",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",... | // AssignStagedUnits gets called by the UnitAssigner worker, and runs the given
// assignments. | [
"AssignStagedUnits",
"gets",
"called",
"by",
"the",
"UnitAssigner",
"worker",
"and",
"runs",
"the",
"given",
"assignments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1633-L1646 |
157,281 | juju/juju | state/state.go | AssignUnitWithPlacement | func (st *State) AssignUnitWithPlacement(unit *Unit, placement *instance.Placement) error {
// TODO(natefinch) this should be done as a single transaction, not two.
// Mark https://launchpad.net/bugs/1506994 fixed when done.
data, err := st.parsePlacement(placement)
if err != nil {
return errors.Trace(err)
}
if data.placementType() == directivePlacement {
return unit.assignToNewMachine(data.directive)
}
m, err := st.addMachineWithPlacement(unit, data)
if err != nil {
return errors.Trace(err)
}
return unit.AssignToMachine(m)
} | go | func (st *State) AssignUnitWithPlacement(unit *Unit, placement *instance.Placement) error {
// TODO(natefinch) this should be done as a single transaction, not two.
// Mark https://launchpad.net/bugs/1506994 fixed when done.
data, err := st.parsePlacement(placement)
if err != nil {
return errors.Trace(err)
}
if data.placementType() == directivePlacement {
return unit.assignToNewMachine(data.directive)
}
m, err := st.addMachineWithPlacement(unit, data)
if err != nil {
return errors.Trace(err)
}
return unit.AssignToMachine(m)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AssignUnitWithPlacement",
"(",
"unit",
"*",
"Unit",
",",
"placement",
"*",
"instance",
".",
"Placement",
")",
"error",
"{",
"// TODO(natefinch) this should be done as a single transaction, not two.",
"// Mark https://launchpad.net/bugs... | // AssignUnitWithPlacement chooses a machine using the given placement directive
// and then assigns the unit to it. | [
"AssignUnitWithPlacement",
"chooses",
"a",
"machine",
"using",
"the",
"given",
"placement",
"directive",
"and",
"then",
"assigns",
"the",
"unit",
"to",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1696-L1713 |
157,282 | juju/juju | state/state.go | placementType | func (p placementData) placementType() placementType {
if p.containerType != "" {
return containerPlacement
}
if p.directive != "" {
return directivePlacement
}
return machinePlacement
} | go | func (p placementData) placementType() placementType {
if p.containerType != "" {
return containerPlacement
}
if p.directive != "" {
return directivePlacement
}
return machinePlacement
} | [
"func",
"(",
"p",
"placementData",
")",
"placementType",
"(",
")",
"placementType",
"{",
"if",
"p",
".",
"containerType",
"!=",
"\"",
"\"",
"{",
"return",
"containerPlacement",
"\n",
"}",
"\n",
"if",
"p",
".",
"directive",
"!=",
"\"",
"\"",
"{",
"return"... | // placementType returns the type of placement that this data represents. | [
"placementType",
"returns",
"the",
"type",
"of",
"placement",
"that",
"this",
"data",
"represents",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1733-L1741 |
157,283 | juju/juju | state/state.go | addMachineWithPlacement | func (st *State) addMachineWithPlacement(unit *Unit, data *placementData) (*Machine, error) {
unitCons, err := unit.Constraints()
if err != nil {
return nil, err
}
// Create any new machine marked as dirty so that
// nothing else will grab it before we assign the unit to it.
// TODO(natefinch) fix this when we put assignment in the same
// transaction as adding a machine. See bug
// https://launchpad.net/bugs/1506994
mId := data.machineId
var machine *Machine
if data.machineId != "" {
machine, err = st.Machine(mId)
if err != nil {
return nil, errors.Trace(err)
}
// Check if an upgrade-series lock is present for the requested
// machine or its parent.
// If one exists, return an error to prevent deployment.
locked, err := machine.IsLockedForSeriesUpgrade()
if err != nil {
return nil, errors.Trace(err)
}
if locked {
return nil, errors.Errorf("machine %q is locked for series upgrade", mId)
}
locked, err = machine.IsParentLockedForSeriesUpgrade()
if err != nil {
return nil, errors.Trace(err)
}
if locked {
return nil, errors.Errorf("machine hosting %q is locked for series upgrade", mId)
}
}
switch data.placementType() {
case containerPlacement:
// If a container is to be used, create it.
template := MachineTemplate{
Series: unit.Series(),
Jobs: []MachineJob{JobHostUnits},
Dirty: true,
Constraints: *unitCons,
}
if mId != "" {
return st.AddMachineInsideMachine(template, mId, data.containerType)
}
return st.AddMachineInsideNewMachine(template, template, data.containerType)
case directivePlacement:
return nil, errors.NotSupportedf("programming error: directly adding a machine for %s with a non-machine placement directive", unit.Name())
default:
return machine, nil
}
} | go | func (st *State) addMachineWithPlacement(unit *Unit, data *placementData) (*Machine, error) {
unitCons, err := unit.Constraints()
if err != nil {
return nil, err
}
// Create any new machine marked as dirty so that
// nothing else will grab it before we assign the unit to it.
// TODO(natefinch) fix this when we put assignment in the same
// transaction as adding a machine. See bug
// https://launchpad.net/bugs/1506994
mId := data.machineId
var machine *Machine
if data.machineId != "" {
machine, err = st.Machine(mId)
if err != nil {
return nil, errors.Trace(err)
}
// Check if an upgrade-series lock is present for the requested
// machine or its parent.
// If one exists, return an error to prevent deployment.
locked, err := machine.IsLockedForSeriesUpgrade()
if err != nil {
return nil, errors.Trace(err)
}
if locked {
return nil, errors.Errorf("machine %q is locked for series upgrade", mId)
}
locked, err = machine.IsParentLockedForSeriesUpgrade()
if err != nil {
return nil, errors.Trace(err)
}
if locked {
return nil, errors.Errorf("machine hosting %q is locked for series upgrade", mId)
}
}
switch data.placementType() {
case containerPlacement:
// If a container is to be used, create it.
template := MachineTemplate{
Series: unit.Series(),
Jobs: []MachineJob{JobHostUnits},
Dirty: true,
Constraints: *unitCons,
}
if mId != "" {
return st.AddMachineInsideMachine(template, mId, data.containerType)
}
return st.AddMachineInsideNewMachine(template, template, data.containerType)
case directivePlacement:
return nil, errors.NotSupportedf("programming error: directly adding a machine for %s with a non-machine placement directive", unit.Name())
default:
return machine, nil
}
} | [
"func",
"(",
"st",
"*",
"State",
")",
"addMachineWithPlacement",
"(",
"unit",
"*",
"Unit",
",",
"data",
"*",
"placementData",
")",
"(",
"*",
"Machine",
",",
"error",
")",
"{",
"unitCons",
",",
"err",
":=",
"unit",
".",
"Constraints",
"(",
")",
"\n",
... | // addMachineWithPlacement finds a machine that matches the given
// placement directive for the given unit. | [
"addMachineWithPlacement",
"finds",
"a",
"machine",
"that",
"matches",
"the",
"given",
"placement",
"directive",
"for",
"the",
"given",
"unit",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1763-L1820 |
157,284 | juju/juju | state/state.go | Application | func (st *State) Application(name string) (_ *Application, err error) {
applications, closer := st.db().GetCollection(applicationsC)
defer closer()
if !names.IsValidApplication(name) {
return nil, errors.Errorf("%q is not a valid application name", name)
}
sdoc := &applicationDoc{}
err = applications.FindId(name).One(sdoc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("application %q", name)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get application %q", name)
}
return newApplication(st, sdoc), nil
} | go | func (st *State) Application(name string) (_ *Application, err error) {
applications, closer := st.db().GetCollection(applicationsC)
defer closer()
if !names.IsValidApplication(name) {
return nil, errors.Errorf("%q is not a valid application name", name)
}
sdoc := &applicationDoc{}
err = applications.FindId(name).One(sdoc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("application %q", name)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get application %q", name)
}
return newApplication(st, sdoc), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Application",
"(",
"name",
"string",
")",
"(",
"_",
"*",
"Application",
",",
"err",
"error",
")",
"{",
"applications",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"applicationsC",
... | // Application returns a application state by name. | [
"Application",
"returns",
"a",
"application",
"state",
"by",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1823-L1839 |
157,285 | juju/juju | state/state.go | AllApplications | func (st *State) AllApplications() (applications []*Application, err error) {
applicationsCollection, closer := st.db().GetCollection(applicationsC)
defer closer()
sdocs := []applicationDoc{}
err = applicationsCollection.Find(bson.D{}).All(&sdocs)
if err != nil {
return nil, errors.Errorf("cannot get all applications")
}
for _, v := range sdocs {
applications = append(applications, newApplication(st, &v))
}
return applications, nil
} | go | func (st *State) AllApplications() (applications []*Application, err error) {
applicationsCollection, closer := st.db().GetCollection(applicationsC)
defer closer()
sdocs := []applicationDoc{}
err = applicationsCollection.Find(bson.D{}).All(&sdocs)
if err != nil {
return nil, errors.Errorf("cannot get all applications")
}
for _, v := range sdocs {
applications = append(applications, newApplication(st, &v))
}
return applications, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AllApplications",
"(",
")",
"(",
"applications",
"[",
"]",
"*",
"Application",
",",
"err",
"error",
")",
"{",
"applicationsCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"a... | // AllApplications returns all deployed applications in the model. | [
"AllApplications",
"returns",
"all",
"deployed",
"applications",
"in",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1842-L1855 |
157,286 | juju/juju | state/state.go | endpoints | func (st *State) endpoints(name string, filter func(ep Endpoint) bool) ([]Endpoint, error) {
var appName, relName string
if i := strings.Index(name, ":"); i == -1 {
appName = name
} else if i != 0 && i != len(name)-1 {
appName = name[:i]
relName = name[i+1:]
} else {
return nil, errors.Errorf("invalid endpoint %q", name)
}
app, err := applicationByName(st, appName)
if err != nil {
return nil, errors.Trace(err)
}
eps := []Endpoint{}
if relName != "" {
ep, err := app.Endpoint(relName)
if err != nil {
return nil, errors.Trace(err)
}
eps = append(eps, ep)
} else {
eps, err = app.Endpoints()
if err != nil {
return nil, errors.Trace(err)
}
}
final := []Endpoint{}
for _, ep := range eps {
if filter(ep) {
final = append(final, ep)
}
}
return final, nil
} | go | func (st *State) endpoints(name string, filter func(ep Endpoint) bool) ([]Endpoint, error) {
var appName, relName string
if i := strings.Index(name, ":"); i == -1 {
appName = name
} else if i != 0 && i != len(name)-1 {
appName = name[:i]
relName = name[i+1:]
} else {
return nil, errors.Errorf("invalid endpoint %q", name)
}
app, err := applicationByName(st, appName)
if err != nil {
return nil, errors.Trace(err)
}
eps := []Endpoint{}
if relName != "" {
ep, err := app.Endpoint(relName)
if err != nil {
return nil, errors.Trace(err)
}
eps = append(eps, ep)
} else {
eps, err = app.Endpoints()
if err != nil {
return nil, errors.Trace(err)
}
}
final := []Endpoint{}
for _, ep := range eps {
if filter(ep) {
final = append(final, ep)
}
}
return final, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"endpoints",
"(",
"name",
"string",
",",
"filter",
"func",
"(",
"ep",
"Endpoint",
")",
"bool",
")",
"(",
"[",
"]",
"Endpoint",
",",
"error",
")",
"{",
"var",
"appName",
",",
"relName",
"string",
"\n",
"if",
"i"... | // endpoints returns all endpoints that could be intended by the
// supplied endpoint name, and which cause the filter param to
// return true. | [
"endpoints",
"returns",
"all",
"endpoints",
"that",
"could",
"be",
"intended",
"by",
"the",
"supplied",
"endpoint",
"name",
"and",
"which",
"cause",
"the",
"filter",
"param",
"to",
"return",
"true",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L1976-L2010 |
157,287 | juju/juju | state/state.go | EndpointsRelation | func (st *State) EndpointsRelation(endpoints ...Endpoint) (*Relation, error) {
return st.KeyRelation(relationKey(endpoints))
} | go | func (st *State) EndpointsRelation(endpoints ...Endpoint) (*Relation, error) {
return st.KeyRelation(relationKey(endpoints))
} | [
"func",
"(",
"st",
"*",
"State",
")",
"EndpointsRelation",
"(",
"endpoints",
"...",
"Endpoint",
")",
"(",
"*",
"Relation",
",",
"error",
")",
"{",
"return",
"st",
".",
"KeyRelation",
"(",
"relationKey",
"(",
"endpoints",
")",
")",
"\n",
"}"
] | // EndpointsRelation returns the existing relation with the given endpoints. | [
"EndpointsRelation",
"returns",
"the",
"existing",
"relation",
"with",
"the",
"given",
"endpoints",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2182-L2184 |
157,288 | juju/juju | state/state.go | Relation | func (st *State) Relation(id int) (*Relation, error) {
relations, closer := st.db().GetCollection(relationsC)
defer closer()
doc := relationDoc{}
err := relations.Find(bson.D{{"id", id}}).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("relation %d", id)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get relation %d", id)
}
return newRelation(st, &doc), nil
} | go | func (st *State) Relation(id int) (*Relation, error) {
relations, closer := st.db().GetCollection(relationsC)
defer closer()
doc := relationDoc{}
err := relations.Find(bson.D{{"id", id}}).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("relation %d", id)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get relation %d", id)
}
return newRelation(st, &doc), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Relation",
"(",
"id",
"int",
")",
"(",
"*",
"Relation",
",",
"error",
")",
"{",
"relations",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"relationsC",
")",
"\n",
"defer",
"closer... | // Relation returns the existing relation with the given id. | [
"Relation",
"returns",
"the",
"existing",
"relation",
"with",
"the",
"given",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2204-L2217 |
157,289 | juju/juju | state/state.go | AllRelations | func (st *State) AllRelations() (relations []*Relation, err error) {
relationsCollection, closer := st.db().GetCollection(relationsC)
defer closer()
docs := relationDocSlice{}
err = relationsCollection.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotate(err, "cannot get all relations")
}
sort.Sort(docs)
for _, v := range docs {
relations = append(relations, newRelation(st, &v))
}
return
} | go | func (st *State) AllRelations() (relations []*Relation, err error) {
relationsCollection, closer := st.db().GetCollection(relationsC)
defer closer()
docs := relationDocSlice{}
err = relationsCollection.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotate(err, "cannot get all relations")
}
sort.Sort(docs)
for _, v := range docs {
relations = append(relations, newRelation(st, &v))
}
return
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AllRelations",
"(",
")",
"(",
"relations",
"[",
"]",
"*",
"Relation",
",",
"err",
"error",
")",
"{",
"relationsCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"relationsC",
... | // AllRelations returns all relations in the model ordered by id. | [
"AllRelations",
"returns",
"all",
"relations",
"in",
"the",
"model",
"ordered",
"by",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2220-L2234 |
157,290 | juju/juju | state/state.go | Unit | func (st *State) Unit(name string) (*Unit, error) {
if !names.IsValidUnit(name) {
return nil, errors.Errorf("%q is not a valid unit name", name)
}
units, closer := st.db().GetCollection(unitsC)
defer closer()
doc := unitDoc{}
err := units.FindId(name).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("unit %q", name)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get unit %q", name)
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return newUnit(st, model.Type(), &doc), nil
} | go | func (st *State) Unit(name string) (*Unit, error) {
if !names.IsValidUnit(name) {
return nil, errors.Errorf("%q is not a valid unit name", name)
}
units, closer := st.db().GetCollection(unitsC)
defer closer()
doc := unitDoc{}
err := units.FindId(name).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("unit %q", name)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get unit %q", name)
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return newUnit(st, model.Type(), &doc), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Unit",
"(",
"name",
"string",
")",
"(",
"*",
"Unit",
",",
"error",
")",
"{",
"if",
"!",
"names",
".",
"IsValidUnit",
"(",
"name",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
"... | // Unit returns a unit by name. | [
"Unit",
"returns",
"a",
"unit",
"by",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2251-L2271 |
157,291 | juju/juju | state/state.go | UnitsFor | func (st *State) UnitsFor(machineId string) ([]*Unit, error) {
if !names.IsValidMachine(machineId) {
return nil, errors.Errorf("%q is not a valid machine id", machineId)
}
m := &Machine{
st: st,
doc: machineDoc{
Id: machineId,
},
}
return m.Units()
} | go | func (st *State) UnitsFor(machineId string) ([]*Unit, error) {
if !names.IsValidMachine(machineId) {
return nil, errors.Errorf("%q is not a valid machine id", machineId)
}
m := &Machine{
st: st,
doc: machineDoc{
Id: machineId,
},
}
return m.Units()
} | [
"func",
"(",
"st",
"*",
"State",
")",
"UnitsFor",
"(",
"machineId",
"string",
")",
"(",
"[",
"]",
"*",
"Unit",
",",
"error",
")",
"{",
"if",
"!",
"names",
".",
"IsValidMachine",
"(",
"machineId",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Erro... | // UnitsFor returns the units placed in the given machine id. | [
"UnitsFor",
"returns",
"the",
"units",
"placed",
"in",
"the",
"given",
"machine",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2274-L2285 |
157,292 | juju/juju | state/state.go | UnitsInError | func (st *State) UnitsInError() ([]*Unit, error) {
// First, find the agents in error state.
agentGlobalKeys, err := getEntityKeysForStatus(st, "u", status.Error)
if err != nil {
return nil, errors.Trace(err)
}
// Extract the unit names.
unitNames := make([]string, len(agentGlobalKeys))
for i, key := range agentGlobalKeys {
// agent key prefix is "u#"
if !strings.HasPrefix(key, "u#") {
return nil, errors.NotValidf("unit agent global key %q", key)
}
unitNames[i] = key[2:]
}
// Query the units with the names of units in error.
units, closer := st.db().GetCollection(unitsC)
defer closer()
var docs []unitDoc
err = units.Find(bson.D{{"name", bson.D{{"$in", unitNames}}}}).All(&docs)
if err != nil {
return nil, errors.Trace(err)
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
result := make([]*Unit, len(docs))
for i, doc := range docs {
result[i] = &Unit{st: st, doc: doc, modelType: model.Type()}
}
return result, nil
} | go | func (st *State) UnitsInError() ([]*Unit, error) {
// First, find the agents in error state.
agentGlobalKeys, err := getEntityKeysForStatus(st, "u", status.Error)
if err != nil {
return nil, errors.Trace(err)
}
// Extract the unit names.
unitNames := make([]string, len(agentGlobalKeys))
for i, key := range agentGlobalKeys {
// agent key prefix is "u#"
if !strings.HasPrefix(key, "u#") {
return nil, errors.NotValidf("unit agent global key %q", key)
}
unitNames[i] = key[2:]
}
// Query the units with the names of units in error.
units, closer := st.db().GetCollection(unitsC)
defer closer()
var docs []unitDoc
err = units.Find(bson.D{{"name", bson.D{{"$in", unitNames}}}}).All(&docs)
if err != nil {
return nil, errors.Trace(err)
}
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
result := make([]*Unit, len(docs))
for i, doc := range docs {
result[i] = &Unit{st: st, doc: doc, modelType: model.Type()}
}
return result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"UnitsInError",
"(",
")",
"(",
"[",
"]",
"*",
"Unit",
",",
"error",
")",
"{",
"// First, find the agents in error state.",
"agentGlobalKeys",
",",
"err",
":=",
"getEntityKeysForStatus",
"(",
"st",
",",
"\"",
"\"",
",",
... | // UnitsInError returns the units which have an agent status of Error. | [
"UnitsInError",
"returns",
"the",
"units",
"which",
"have",
"an",
"agent",
"status",
"of",
"Error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2288-L2323 |
157,293 | juju/juju | state/state.go | AssignUnit | func (st *State) AssignUnit(u *Unit, policy AssignmentPolicy) (err error) {
if !u.IsPrincipal() {
return errors.Errorf("subordinate unit %q cannot be assigned directly to a machine", u)
}
defer errors.DeferredAnnotatef(&err, "cannot assign unit %q to machine", u)
var m *Machine
switch policy {
case AssignLocal:
m, err = st.Machine("0")
if err != nil {
return errors.Trace(err)
}
return u.AssignToMachine(m)
case AssignClean:
if _, err = u.AssignToCleanMachine(); errors.Cause(err) != noCleanMachines {
return errors.Trace(err)
}
return u.AssignToNewMachineOrContainer()
case AssignCleanEmpty:
if _, err = u.AssignToCleanEmptyMachine(); errors.Cause(err) != noCleanMachines {
return errors.Trace(err)
}
return u.AssignToNewMachineOrContainer()
case AssignNew:
return errors.Trace(u.AssignToNewMachine())
}
return errors.Errorf("unknown unit assignment policy: %q", policy)
} | go | func (st *State) AssignUnit(u *Unit, policy AssignmentPolicy) (err error) {
if !u.IsPrincipal() {
return errors.Errorf("subordinate unit %q cannot be assigned directly to a machine", u)
}
defer errors.DeferredAnnotatef(&err, "cannot assign unit %q to machine", u)
var m *Machine
switch policy {
case AssignLocal:
m, err = st.Machine("0")
if err != nil {
return errors.Trace(err)
}
return u.AssignToMachine(m)
case AssignClean:
if _, err = u.AssignToCleanMachine(); errors.Cause(err) != noCleanMachines {
return errors.Trace(err)
}
return u.AssignToNewMachineOrContainer()
case AssignCleanEmpty:
if _, err = u.AssignToCleanEmptyMachine(); errors.Cause(err) != noCleanMachines {
return errors.Trace(err)
}
return u.AssignToNewMachineOrContainer()
case AssignNew:
return errors.Trace(u.AssignToNewMachine())
}
return errors.Errorf("unknown unit assignment policy: %q", policy)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AssignUnit",
"(",
"u",
"*",
"Unit",
",",
"policy",
"AssignmentPolicy",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"u",
".",
"IsPrincipal",
"(",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",... | // AssignUnit places the unit on a machine. Depending on the policy, and the
// state of the model, this may lead to new instances being launched
// within the model. | [
"AssignUnit",
"places",
"the",
"unit",
"on",
"a",
"machine",
".",
"Depending",
"on",
"the",
"policy",
"and",
"the",
"state",
"of",
"the",
"model",
"this",
"may",
"lead",
"to",
"new",
"instances",
"being",
"launched",
"within",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2328-L2355 |
157,294 | juju/juju | state/state.go | StartSync | func (st *State) StartSync() {
if advanceable, ok := st.clock().(hasAdvance); ok {
// The amount of time we advance here just needs to be more
// than 10ms as that is the minimum time the txnwatcher
// is waiting on, however one second is more human noticeable.
// The state testing StateSuite type changes the polling interval
// of the pool's txnwatcher to be one second.
advanceable.Advance(time.Second)
}
if syncable, ok := st.workers.txnLogWatcher().(hasStartSync); ok {
syncable.StartSync()
}
st.workers.pingBatcherWorker().Sync()
st.workers.presenceWatcher().Sync()
} | go | func (st *State) StartSync() {
if advanceable, ok := st.clock().(hasAdvance); ok {
// The amount of time we advance here just needs to be more
// than 10ms as that is the minimum time the txnwatcher
// is waiting on, however one second is more human noticeable.
// The state testing StateSuite type changes the polling interval
// of the pool's txnwatcher to be one second.
advanceable.Advance(time.Second)
}
if syncable, ok := st.workers.txnLogWatcher().(hasStartSync); ok {
syncable.StartSync()
}
st.workers.pingBatcherWorker().Sync()
st.workers.presenceWatcher().Sync()
} | [
"func",
"(",
"st",
"*",
"State",
")",
"StartSync",
"(",
")",
"{",
"if",
"advanceable",
",",
"ok",
":=",
"st",
".",
"clock",
"(",
")",
".",
"(",
"hasAdvance",
")",
";",
"ok",
"{",
"// The amount of time we advance here just needs to be more",
"// than 10ms as t... | // StartSync forces watchers to resynchronize their state with the
// database immediately. This will happen periodically automatically.
// This method is called only from tests. | [
"StartSync",
"forces",
"watchers",
"to",
"resynchronize",
"their",
"state",
"with",
"the",
"database",
"immediately",
".",
"This",
"will",
"happen",
"periodically",
"automatically",
".",
"This",
"method",
"is",
"called",
"only",
"from",
"tests",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2367-L2381 |
157,295 | juju/juju | state/state.go | SetAdminMongoPassword | func (st *State) SetAdminMongoPassword(password string) error {
err := mongo.SetAdminMongoPassword(st.session, mongo.AdminUser, password)
return errors.Trace(err)
} | go | func (st *State) SetAdminMongoPassword(password string) error {
err := mongo.SetAdminMongoPassword(st.session, mongo.AdminUser, password)
return errors.Trace(err)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"SetAdminMongoPassword",
"(",
"password",
"string",
")",
"error",
"{",
"err",
":=",
"mongo",
".",
"SetAdminMongoPassword",
"(",
"st",
".",
"session",
",",
"mongo",
".",
"AdminUser",
",",
"password",
")",
"\n",
"return"... | // SetAdminMongoPassword sets the administrative password
// to access the state. If the password is non-empty,
// all subsequent attempts to access the state must
// be authorized; otherwise no authorization is required. | [
"SetAdminMongoPassword",
"sets",
"the",
"administrative",
"password",
"to",
"access",
"the",
"state",
".",
"If",
"the",
"password",
"is",
"non",
"-",
"empty",
"all",
"subsequent",
"attempts",
"to",
"access",
"the",
"state",
"must",
"be",
"authorized",
";",
"ot... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2387-L2390 |
157,296 | juju/juju | state/state.go | ControllerInfo | func (st *State) ControllerInfo() (*ControllerInfo, error) {
session := st.session.Copy()
defer session.Close()
return readRawControllerInfo(session)
} | go | func (st *State) ControllerInfo() (*ControllerInfo, error) {
session := st.session.Copy()
defer session.Close()
return readRawControllerInfo(session)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"ControllerInfo",
"(",
")",
"(",
"*",
"ControllerInfo",
",",
"error",
")",
"{",
"session",
":=",
"st",
".",
"session",
".",
"Copy",
"(",
")",
"\n",
"defer",
"session",
".",
"Close",
"(",
")",
"\n",
"return",
"r... | // ControllerInfo returns information about
// the currently configured controller machines. | [
"ControllerInfo",
"returns",
"information",
"about",
"the",
"currently",
"configured",
"controller",
"machines",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2417-L2421 |
157,297 | juju/juju | state/state.go | readRawControllerInfo | func readRawControllerInfo(session *mgo.Session) (*ControllerInfo, error) {
db := session.DB(jujuDB)
controllers := db.C(controllersC)
var doc controllersDoc
err := controllers.Find(bson.D{{"_id", modelGlobalKey}}).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("controllers document")
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get controllers document")
}
return &ControllerInfo{
CloudName: doc.CloudName,
ModelTag: names.NewModelTag(doc.ModelUUID),
MachineIds: doc.MachineIds,
}, nil
} | go | func readRawControllerInfo(session *mgo.Session) (*ControllerInfo, error) {
db := session.DB(jujuDB)
controllers := db.C(controllersC)
var doc controllersDoc
err := controllers.Find(bson.D{{"_id", modelGlobalKey}}).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("controllers document")
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get controllers document")
}
return &ControllerInfo{
CloudName: doc.CloudName,
ModelTag: names.NewModelTag(doc.ModelUUID),
MachineIds: doc.MachineIds,
}, nil
} | [
"func",
"readRawControllerInfo",
"(",
"session",
"*",
"mgo",
".",
"Session",
")",
"(",
"*",
"ControllerInfo",
",",
"error",
")",
"{",
"db",
":=",
"session",
".",
"DB",
"(",
"jujuDB",
")",
"\n",
"controllers",
":=",
"db",
".",
"C",
"(",
"controllersC",
... | // readRawControllerInfo reads ControllerInfo direct from the supplied session,
// falling back to the bootstrap model document to extract the UUID when
// required. | [
"readRawControllerInfo",
"reads",
"ControllerInfo",
"direct",
"from",
"the",
"supplied",
"session",
"falling",
"back",
"to",
"the",
"bootstrap",
"model",
"document",
"to",
"extract",
"the",
"UUID",
"when",
"required",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2426-L2443 |
157,298 | juju/juju | state/state.go | StateServingInfo | func (st *State) StateServingInfo() (StateServingInfo, error) {
controllers, closer := st.db().GetCollection(controllersC)
defer closer()
var info StateServingInfo
err := controllers.Find(bson.D{{"_id", stateServingInfoKey}}).One(&info)
if err != nil {
return info, errors.Trace(err)
}
if info.StatePort == 0 {
return StateServingInfo{}, errors.NotFoundf("state serving info")
}
return info, nil
} | go | func (st *State) StateServingInfo() (StateServingInfo, error) {
controllers, closer := st.db().GetCollection(controllersC)
defer closer()
var info StateServingInfo
err := controllers.Find(bson.D{{"_id", stateServingInfoKey}}).One(&info)
if err != nil {
return info, errors.Trace(err)
}
if info.StatePort == 0 {
return StateServingInfo{}, errors.NotFoundf("state serving info")
}
return info, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"StateServingInfo",
"(",
")",
"(",
"StateServingInfo",
",",
"error",
")",
"{",
"controllers",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"controllersC",
")",
"\n",
"defer",
"closer",
... | // StateServingInfo returns information for running a controller machine | [
"StateServingInfo",
"returns",
"information",
"for",
"running",
"a",
"controller",
"machine"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2448-L2461 |
157,299 | juju/juju | state/state.go | SetStateServingInfo | func (st *State) SetStateServingInfo(info StateServingInfo) error {
if info.StatePort == 0 || info.APIPort == 0 ||
info.Cert == "" || info.PrivateKey == "" {
return errors.Errorf("incomplete state serving info set in state")
}
if info.CAPrivateKey == "" {
// No CA certificate key means we can't generate new controller
// certificates when needed to add to the certificate SANs.
// Older Juju deployments discard the key because no one realised
// the certificate was flawed, so at best we can log a warning
// until an upgrade process is written.
logger.Warningf("state serving info has no CA certificate key")
}
ops := []txn.Op{{
C: controllersC,
Id: stateServingInfoKey,
Update: bson.D{{"$set", info}},
}}
if err := st.db().RunTransaction(ops); err != nil {
return errors.Annotatef(err, "cannot set state serving info")
}
return nil
} | go | func (st *State) SetStateServingInfo(info StateServingInfo) error {
if info.StatePort == 0 || info.APIPort == 0 ||
info.Cert == "" || info.PrivateKey == "" {
return errors.Errorf("incomplete state serving info set in state")
}
if info.CAPrivateKey == "" {
// No CA certificate key means we can't generate new controller
// certificates when needed to add to the certificate SANs.
// Older Juju deployments discard the key because no one realised
// the certificate was flawed, so at best we can log a warning
// until an upgrade process is written.
logger.Warningf("state serving info has no CA certificate key")
}
ops := []txn.Op{{
C: controllersC,
Id: stateServingInfoKey,
Update: bson.D{{"$set", info}},
}}
if err := st.db().RunTransaction(ops); err != nil {
return errors.Annotatef(err, "cannot set state serving info")
}
return nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"SetStateServingInfo",
"(",
"info",
"StateServingInfo",
")",
"error",
"{",
"if",
"info",
".",
"StatePort",
"==",
"0",
"||",
"info",
".",
"APIPort",
"==",
"0",
"||",
"info",
".",
"Cert",
"==",
"\"",
"\"",
"||",
"i... | // SetStateServingInfo stores information needed for running a controller | [
"SetStateServingInfo",
"stores",
"information",
"needed",
"for",
"running",
"a",
"controller"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/state.go#L2464-L2486 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.