本文整理汇总了Golang中github.com/juju/names.ModelTag类的典型用法代码示例。如果您正苦于以下问题:Golang ModelTag类的具体用法?Golang ModelTag怎么用?Golang ModelTag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelTag类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewWatcher
// NewWatcher returns a new Watcher.
func NewWatcher(base *mgo.Collection, modelTag names.ModelTag) *Watcher {
w := &Watcher{
modelUUID: modelTag.Id(),
base: base,
pings: pingsC(base),
beings: beingsC(base),
beingKey: make(map[int64]string),
beingSeq: make(map[string]int64),
watches: make(map[string][]chan<- Change),
request: make(chan interface{}),
}
go func() {
err := w.loop()
cause := errors.Cause(err)
// tomb expects ErrDying or ErrStillAlive as
// exact values, so we need to log and unwrap
// the error first.
if err != nil && cause != tomb.ErrDying {
logger.Infof("watcher loop failed: %v", err)
}
w.tomb.Kill(cause)
w.tomb.Done()
}()
return w
}
示例2: AssertModelCall
func (s *ClientSuite) AssertModelCall(c *gc.C, stub *jujutesting.Stub, tag names.ModelTag, call string, err error) {
expectedArg := params.ModelArgs{ModelTag: tag.String()}
stub.CheckCalls(c, []jujutesting.StubCall{
{"MigrationTarget." + call, []interface{}{"", expectedArg}},
})
c.Assert(err, gc.ErrorMatches, "boom")
}
示例3: NewPinger
// NewPinger returns a new Pinger to report that key is alive.
// It starts reporting after Start is called.
func NewPinger(base *mgo.Collection, modelTag names.ModelTag, key string) *Pinger {
return &Pinger{
base: base,
pings: pingsC(base),
beingKey: key,
modelUUID: modelTag.Id(),
}
}
示例4: envIsDead
func (m *modelWorkerManager) envIsDead(modelTag names.ModelTag) error {
uuid := modelTag.Id()
err := m.runner.StopWorker(uuid)
if err != nil {
return errors.Trace(err)
}
return nil
}
示例5: modelNotFound
// envNotFound stops all workers for that model.
func (m *modelWorkerManager) modelNotFound(modelTag names.ModelTag) error {
uuid := modelTag.Id()
if err := m.runner.StopWorker(uuid); err != nil {
return errors.Trace(err)
}
if err := m.runner.StopWorker(dyingModelWorkerId(uuid)); err != nil {
return errors.Trace(err)
}
return nil
}
示例6: GetModel
// GetModel looks for the model identified by the uuid passed in.
func (st *State) GetModel(tag names.ModelTag) (*Model, error) {
models, closer := st.getCollection(modelsC)
defer closer()
env := &Model{st: st}
if err := env.refresh(models.FindId(tag.Id())); err != nil {
return nil, errors.Trace(err)
}
return env, nil
}
示例7: modifyAccess
func (s *modelManagerSuite) modifyAccess(c *gc.C, user names.UserTag, action params.ModelAction, access params.ModelAccessPermission, model names.ModelTag) error {
args := params.ModifyModelAccessRequest{
Changes: []params.ModifyModelAccess{{
UserTag: user.String(),
Action: action,
Access: access,
ModelTag: model.String(),
}}}
result, err := s.modelmanager.ModifyModelAccess(args)
c.Assert(err, jc.ErrorIsNil)
return result.OneError()
}
示例8: ResourceTags
// ResourceTags returns tags to set on an infrastructure resource
// for the specified Juju environment.
func ResourceTags(e names.ModelTag, taggers ...ResourceTagger) map[string]string {
allTags := make(map[string]string)
for _, tagger := range taggers {
tags, ok := tagger.ResourceTags()
if !ok {
continue
}
for k, v := range tags {
allTags[k] = v
}
}
allTags[JujuModel] = e.Id()
return allTags
}
示例9: assertRemoteEnvironment
func (s *loginSuite) assertRemoteEnvironment(c *gc.C, st api.Connection, expected names.ModelTag) {
// Look at what the api thinks it has.
tag, err := st.ModelTag()
c.Assert(err, jc.ErrorIsNil)
c.Assert(tag, gc.Equals, expected)
// Look at what the api Client thinks it has.
client := st.Client()
// ModelUUID looks at the env tag on the api state connection.
c.Assert(client.ModelUUID(), gc.Equals, expected.Id())
// ModelInfo calls a remote method that looks up the environment.
info, err := client.ModelInfo()
c.Assert(err, jc.ErrorIsNil)
c.Assert(info.UUID, gc.Equals, expected.Id())
}
示例10: Open
// Open connects to the server described by the given
// info, waits for it to be initialized, and returns a new State
// representing the model connected to.
//
// A policy may be provided, which will be used to validate and
// modify behaviour of certain operations in state. A nil policy
// may be provided.
//
// Open returns unauthorizedError if access is unauthorized.
func Open(tag names.ModelTag, info *mongo.MongoInfo, opts mongo.DialOpts, policy Policy) (*State, error) {
st, err := open(tag, info, opts, policy)
if err != nil {
return nil, errors.Trace(err)
}
if _, err := st.Model(); err != nil {
if err := st.Close(); err != nil {
logger.Errorf("error closing state for unreadable model %s: %v", tag.Id(), err)
}
return nil, errors.Annotatef(err, "cannot read model %s", tag.Id())
}
// State should only be Opened on behalf of a state server environ; all
// other *States should be created via ForEnviron.
if err := st.start(tag); err != nil {
return nil, errors.Trace(err)
}
return st, nil
}
示例11: newState
// newState creates an incomplete *State, with a configured watcher but no
// pwatcher, leadershipManager, or controllerTag. You must start() the returned
// *State before it will function correctly.
func newState(modelTag names.ModelTag, session *mgo.Session, mongoInfo *mongo.MongoInfo, policy Policy) (_ *State, resultErr error) {
// Set up database.
rawDB := session.DB(jujuDB)
database, err := allCollections().Load(rawDB, modelTag.Id())
if err != nil {
return nil, errors.Trace(err)
}
if err := InitDbLogs(session); err != nil {
return nil, errors.Trace(err)
}
// Create State.
return &State{
modelTag: modelTag,
mongoInfo: mongoInfo,
session: session,
database: database,
policy: policy,
watcher: watcher.New(rawDB.C(txnLogC)),
}, nil
}
示例12: modelIsDying
func (m *modelWorkerManager) modelIsDying(modelTag names.ModelTag) error {
id := dyingModelWorkerId(modelTag.Id())
return m.runner.StartWorker(id, func() (worker.Worker, error) {
st, err := m.st.ForModel(modelTag)
if err != nil {
return nil, errors.Annotatef(err, "failed to open state for model %s", modelTag.Id())
}
closeState := func() {
err := st.Close()
if err != nil {
logger.Errorf("error closing state for model %s: %v", modelTag.Id(), err)
}
}
dyingRunner, err := m.dyingModelWorker(m.st, st)
if err != nil {
closeState()
return nil, errors.Trace(err)
}
// Close State when the runner for the model is done.
go func() {
dyingRunner.Wait()
closeState()
}()
return dyingRunner, nil
})
}
示例13: dumpLogsForEnv
func (c *dumpLogsCommand) dumpLogsForEnv(ctx *cmd.Context, st0 *state.State, tag names.ModelTag) error {
st, err := st0.ForModel(tag)
if err != nil {
return errors.Annotate(err, "failed open model")
}
defer st.Close()
logName := ctx.AbsPath(filepath.Join(c.outDir, fmt.Sprintf("%s.log", tag.Id())))
ctx.Infof("writing to %s", logName)
file, err := os.Create(logName)
if err != nil {
return errors.Annotate(err, "failed to open output file")
}
defer file.Close()
writer := bufio.NewWriter(file)
defer writer.Flush()
tailer, err := state.NewLogTailer(st, &state.LogTailerParams{NoTail: true})
if err != nil {
return errors.Annotate(err, "failed to create a log tailer")
}
logs := tailer.Logs()
for {
rec, ok := <-logs
if !ok {
break
}
writer.WriteString(c.format(
rec.Time,
rec.Level,
rec.Entity,
rec.Module,
rec.Message,
) + "\n")
}
return nil
}
示例14: open
func open(tag names.ModelTag, info *mongo.MongoInfo, opts mongo.DialOpts, policy Policy) (*State, error) {
logger.Infof("opening state, mongo addresses: %q; entity %v", info.Addrs, info.Tag)
logger.Debugf("dialing mongo")
session, err := mongo.DialWithInfo(info.Info, opts)
if err != nil {
return nil, maybeUnauthorized(err, "cannot connect to mongodb")
}
logger.Debugf("connection established")
err = mongodbLogin(session, info)
if err != nil {
session.Close()
return nil, errors.Trace(err)
}
logger.Debugf("mongodb login successful")
// In rare circumstances, we may be upgrading from pre-1.23, and not have the
// model UUID available. In that case we need to infer what it might be;
// we depend on the assumption that this is the only circumstance in which
// the the UUID might not be known.
if tag.Id() == "" {
logger.Warningf("creating state without model tag; inferring bootstrap model")
ssInfo, err := readRawStateServerInfo(session)
if err != nil {
session.Close()
return nil, errors.Trace(err)
}
tag = ssInfo.ModelTag
}
st, err := newState(tag, session, info, policy)
if err != nil {
session.Close()
return nil, errors.Trace(err)
}
return st, nil
}