本文整理汇总了Golang中launchpad/net/juju-core/environs.Environ.SetConfig方法的典型用法代码示例。如果您正苦于以下问题:Golang Environ.SetConfig方法的具体用法?Golang Environ.SetConfig怎么用?Golang Environ.SetConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/juju-core/environs.Environ
的用法示例。
在下文中一共展示了Environ.SetConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run
func (u *Upgrader) run() error {
// Let the state know the version that is currently running.
currentTools, err := tools.ReadTools(u.dataDir, version.Current)
if err != nil {
// Don't abort everything because we can't find the tools directory.
// The problem should sort itself out as we will immediately
// download some more tools and upgrade.
log.Warningf("upgrader cannot read current tools: %v", err)
currentTools = &tools.Tools{
Binary: version.Current,
}
}
err = u.agentState.SetAgentTools(currentTools)
if err != nil {
return err
}
// TODO(fwereade): this whole package should be ignorant of environs,
// so it shouldn't be watching environ config (and it shouldn't be
// looking in storage): we should be able to find out what to download
// from state, exactly as we do for charms.
w := u.st.WatchEnvironConfig()
defer watcher.Stop(w, &u.tomb)
// Rather than using worker.WaitForEnviron, invalid environments are
// managed explicitly so that all configuration changes are observed
// by the loop below.
var environ environs.Environ
// TODO(rog) retry downloads when they fail.
var (
download *downloader.Download
downloadTools *tools.Tools
downloadDone <-chan downloader.Status
)
// If we're killed early on (probably as a result of some other
// task dying) we allow ourselves some time to try to connect to
// the state and download a new version. We return to normal
// undelayed behaviour when:
// 1) We find there's no upgrade to do.
// 2) A download fails.
tomb := delayedTomb(&u.tomb, upgraderKillDelay)
noDelay := func() {
if tomb != &u.tomb {
tomb.Kill(nil)
tomb = &u.tomb
}
}
for {
// We wait for the tools to change while we're downloading
// so that if something goes wrong (for instance a bad URL
// hangs up) another change to the proposed tools can
// potentially fix things.
select {
case cfg, ok := <-w.Changes():
if !ok {
return watcher.MustErr(w)
}
var err error
if environ == nil {
environ, err = environs.New(cfg)
if err != nil {
log.Errorf("upgrader loaded invalid initial environment configuration: %v", err)
break
}
} else {
err = environ.SetConfig(cfg)
if err != nil {
log.Warningf("upgrader loaded invalid environment configuration: %v", err)
// continue on, because the version number is still significant.
}
}
proposed, ok := cfg.AgentVersion()
if !ok {
// This shouldn't be possible; but if it happens it's no reason
// to kill this task. Just wait for the config to change again.
continue
}
if download != nil {
// There's a download in progress, stop it if we need to.
if downloadTools.Number == proposed {
// We are already downloading the requested tools.
break
}
// Tools changed. We need to stop and restart.
download.Stop()
download, downloadTools, downloadDone = nil, nil, nil
}
// TODO: major version upgrades.
if proposed.Major != version.Current.Major {
log.Errorf("major version upgrades are not supported yet")
noDelay()
break
}
if proposed == version.Current.Number {
noDelay()
break
}
required := version.Binary{
Number: proposed,
//.........这里部分代码省略.........
示例2: run
func (u *Upgrader) run() error {
// Let the state know the version that is currently running.
currentTools, err := environs.ReadTools(u.dataDir, version.Current)
if err != nil {
// Don't abort everything because we can't find the tools directory.
// The problem should sort itself out as we will immediately
// download some more tools and upgrade.
log.Printf("cmd/jujud: upgrader cannot read current tools: %v", err)
currentTools = &state.Tools{
Binary: version.Current,
}
}
err = u.agentState.SetAgentTools(currentTools)
if err != nil {
return err
}
w := u.st.WatchEnvironConfig()
defer watcher.Stop(w, &u.tomb)
// Rather than using worker.WaitForEnviron, invalid environments are
// managed explicitly so that all configuration changes are observed
// by the loop below.
var environ environs.Environ
// TODO(rog) retry downloads when they fail.
var (
download *downloader.Download
downloadTools *state.Tools
downloadDone <-chan downloader.Status
)
// If we're killed early on (probably as a result of some other
// task dying) we allow ourselves some time to try to connect to
// the state and download a new version. We return to normal
// undelayed behaviour when:
// 1) We find there's no upgrade to do.
// 2) A download fails.
tomb := delayedTomb(&u.tomb, upgraderKillDelay)
noDelay := func() {
if tomb != &u.tomb {
tomb.Kill(nil)
tomb = &u.tomb
}
}
for {
// We wait for the tools to change while we're downloading
// so that if something goes wrong (for instance a bad URL
// hangs up) another change to the proposed tools can
// potentially fix things.
select {
case cfg, ok := <-w.Changes():
if !ok {
return watcher.MustErr(w)
}
var err error
if environ == nil {
environ, err = environs.New(cfg)
if err != nil {
log.Printf("cmd/jujud: upgrader loaded invalid initial environment configuration: %v", err)
break
}
} else {
err = environ.SetConfig(cfg)
if err != nil {
log.Printf("cmd/jujud: upgrader loaded invalid environment configuration: %v", err)
// continue on, because the version number is still significant.
}
}
vers := cfg.AgentVersion()
if download != nil {
// There's a download in progress, stop it if we need to.
if vers == downloadTools.Number {
// We are already downloading the requested tools.
break
}
// Tools changed. We need to stop and restart.
download.Stop()
download, downloadTools, downloadDone = nil, nil, nil
}
// Ignore the proposed tools if we're already running the
// proposed version.
if vers == version.Current.Number {
noDelay()
break
}
binary := version.Current
binary.Number = vers
if tools, err := environs.ReadTools(u.dataDir, binary); err == nil {
// The tools have already been downloaded, so use them.
return u.upgradeReady(currentTools, tools)
}
flags := environs.CompatVersion
if cfg.Development() {
flags |= environs.DevVersion
}
tools, err := environs.FindTools(environ, binary, flags)
if err != nil {
log.Printf("cmd/jujud: upgrader error finding tools for %v: %v", binary, err)
noDelay()
//.........这里部分代码省略.........