本文整理汇总了Golang中github.com/juju/juju/agent.ConfigSetterWriter.Model方法的典型用法代码示例。如果您正苦于以下问题:Golang ConfigSetterWriter.Model方法的具体用法?Golang ConfigSetterWriter.Model怎么用?Golang ConfigSetterWriter.Model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/agent.ConfigSetterWriter
的用法示例。
在下文中一共展示了ConfigSetterWriter.Model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Restore
//.........这里部分代码省略.........
StopMongo: mongo.StopService,
NewMongoSession: NewMongoSession,
GetDB: GetDB,
}
// Restore mongodb from backup
restorer, err := NewDBRestorer(rArgs)
if err != nil {
return nil, errors.Annotate(err, "error preparing for restore")
}
if err := restorer.Restore(workspace.DBDumpDir, oldDialInfo); err != nil {
return nil, errors.Annotate(err, "error restoring state from backup")
}
// Re-start replicaset with the new value for server address
logger.Infof("restarting replicaset")
memberHostPort := net.JoinHostPort(args.PrivateAddress, strconv.Itoa(ssi.StatePort))
err = resetReplicaSet(dialInfo, memberHostPort)
if err != nil {
return nil, errors.Annotate(err, "cannot reset replicaSet")
}
err = updateMongoEntries(args.NewInstId, args.NewInstTag.Id(), backupMachine.Id(), dialInfo)
if err != nil {
return nil, errors.Annotate(err, "cannot update mongo entries")
}
// From here we work with the restored controller
mgoInfo, ok := agentConfig.MongoInfo()
if !ok {
return nil, errors.Errorf("cannot retrieve info to connect to mongo")
}
st, err := newStateConnection(agentConfig.Controller(), agentConfig.Model(), mgoInfo)
if err != nil {
return nil, errors.Trace(err)
}
defer st.Close()
machine, err := st.Machine(backupMachine.Id())
if err != nil {
return nil, errors.Trace(err)
}
logger.Infof("updating local machine addresses")
err = updateMachineAddresses(machine, args.PrivateAddress, args.PublicAddress)
if err != nil {
return nil, errors.Annotate(err, "cannot update api server machine addresses")
}
// Update the APIHostPorts as well. Under normal circumstances the API
// Host Ports are only set during bootstrap and by the peergrouper worker.
// Unfortunately right now, the peer grouper is busy restarting and isn't
// guaranteed to set the host ports before the remote machines we are
// about to tell about us. If it doesn't, the remote machine gets its
// agent.conf file updated with this new machine's IP address, it then
// starts, and the "api-address-updater" worker asks for the api host
// ports, and gets told the old IP address of the machine that was backed
// up. It then writes this incorrect file to its agent.conf file, which
// causes it to attempt to reconnect to the api server. Unfortunately it
// now has the wrong address and can never get the correct one.
// So, we set it explicitly here.
if err := st.SetAPIHostPorts([][]network.HostPort{APIHostPorts}); err != nil {
return nil, errors.Annotate(err, "cannot update api server host ports")
}
// update all agents known to the new controller.
示例2: Restore
//.........这里部分代码省略.........
}
logger.Infof("wrote new agent config")
if backupMachine.Id() != "0" {
logger.Infof("extra work needed backup belongs to %q machine", backupMachine.String())
serviceName := "jujud-" + agentConfig.Tag().String()
aInfo := service.NewMachineAgentInfo(
agentConfig.Tag().Id(),
dataDir,
paths.MustSucceed(paths.LogDir(args.NewInstSeries)),
)
// TODO(perrito666) renderer should have a RendererForSeries, for the moment
// restore only works on linuxes.
renderer, _ := shell.NewRenderer("bash")
serviceAgentConf := service.AgentConf(aInfo, renderer)
svc, err := service.NewService(serviceName, serviceAgentConf, args.NewInstSeries)
if err != nil {
return nil, errors.Annotate(err, "cannot generate service for the restored agent.")
}
if err := svc.Install(); err != nil {
return nil, errors.Annotate(err, "cannot install service for the restored agent.")
}
logger.Infof("new machine service")
}
logger.Infof("mongo service will be reinstalled to ensure its presence")
if err := ensureMongoService(agentConfig); err != nil {
return nil, errors.Annotate(err, "failed to reinstall service for juju-db")
}
logger.Infof("new mongo will be restored")
// Restore mongodb from backup
if err := placeNewMongoService(workspace.DBDumpDir, version); err != nil {
return nil, errors.Annotate(err, "error restoring state from backup")
}
// Re-start replicaset with the new value for server address
dialInfo, err := newDialInfo(args.PrivateAddress, agentConfig)
if err != nil {
return nil, errors.Annotate(err, "cannot produce dial information")
}
logger.Infof("restarting replicaset")
memberHostPort := net.JoinHostPort(args.PrivateAddress, strconv.Itoa(ssi.StatePort))
err = resetReplicaSet(dialInfo, memberHostPort)
if err != nil {
return nil, errors.Annotate(err, "cannot reset replicaSet")
}
err = updateMongoEntries(args.NewInstId, args.NewInstTag.Id(), backupMachine.Id(), dialInfo)
if err != nil {
return nil, errors.Annotate(err, "cannot update mongo entries")
}
// From here we work with the restored controller
mgoInfo, ok := agentConfig.MongoInfo()
if !ok {
return nil, errors.Errorf("cannot retrieve info to connect to mongo")
}
st, err := newStateConnection(agentConfig.Model(), mgoInfo)
if err != nil {
return nil, errors.Trace(err)
}
defer st.Close()
machine, err := st.Machine(backupMachine.Id())
if err != nil {
return nil, errors.Trace(err)
}
err = updateMachineAddresses(machine, args.PrivateAddress, args.PublicAddress)
if err != nil {
return nil, errors.Annotate(err, "cannot update api server machine addresses")
}
// update all agents known to the new controller.
// TODO(perrito666): We should never stop process because of this.
// updateAllMachines will not return errors for individual
// agent update failures
machines, err := st.AllMachines()
if err != nil {
return nil, errors.Trace(err)
}
if err = updateAllMachines(args.PrivateAddress, machines); err != nil {
return nil, errors.Annotate(err, "cannot update agents")
}
info, err := st.RestoreInfoSetter()
if err != nil {
return nil, errors.Trace(err)
}
// Mark restoreInfo as Finished so upon restart of the apiserver
// the client can reconnect and determine if we where succesful.
err = info.SetStatus(state.RestoreFinished)
return backupMachine, errors.Annotate(err, "failed to set status to finished")
}