当前位置: 首页>>代码示例>>Golang>>正文


Golang state.Charm类代码示例

本文整理汇总了Golang中launchpad/net/juju-core/state.Charm的典型用法代码示例。如果您正苦于以下问题:Golang Charm类的具体用法?Golang Charm怎么用?Golang Charm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Charm类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ModeConflicted

// ModeConflicted is responsible for watching and responding to:
// * user resolution of charm upgrade conflicts
// * forced charm upgrade requests
func ModeConflicted(sch *state.Charm) Mode {
	return func(u *Uniter) (next Mode, err error) {
		defer modeContext("ModeConflicted", &err)()
		if err = u.unit.SetStatus(state.UnitError, "upgrade failed"); err != nil {
			return nil, err
		}
		u.f.WantResolvedEvent()
		u.f.WantUpgradeEvent(sch.URL(), true)
		for {
			select {
			case <-u.tomb.Dying():
				return nil, tomb.ErrDying
			case <-u.f.ResolvedEvents():
				err = u.charm.Snapshotf("Upgrade conflict resolved.")
				if e := u.unit.ClearResolved(); e != nil {
					return nil, e
				}
				if err != nil {
					return nil, err
				}
				return ModeUpgrading(sch), nil
			case upgrade := <-u.f.UpgradeEvents():
				if err := u.charm.Revert(); err != nil {
					return nil, err
				}
				return ModeUpgrading(upgrade), nil
			}
		}
		panic("unreachable")
	}
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:34,代码来源:modes.go

示例2: ModeInstalling

// ModeInstalling is responsible for the initial charm deployment.
func ModeInstalling(sch *state.Charm) Mode {
	name := fmt.Sprintf("ModeInstalling %s", sch.URL())
	return func(u *Uniter) (next Mode, err error) {
		defer modeContext(name, &err)()
		if err = u.deploy(sch, Install); err != nil {
			return nil, err
		}
		return ModeContinue, nil
	}
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:11,代码来源:modes.go

示例3: deploy

// deploy deploys the supplied charm, and sets follow-up hook operation state
// as indicated by reason.
func (u *Uniter) deploy(sch *state.Charm, reason Op) error {
	if reason != Install && reason != Upgrade {
		panic(fmt.Errorf("%q is not a deploy operation", reason))
	}
	var hi *hook.Info
	if u.s != nil && (u.s.Op == RunHook || u.s.Op == Upgrade) {
		// If this upgrade interrupts a RunHook, we need to preserve the hook
		// info so that we can return to the appropriate error state. However,
		// if we're resuming (or have force-interrupted) an Upgrade, we also
		// need to preserve whatever hook info was preserved when we initially
		// started upgrading, to ensure we still return to the correct state.
		hi = u.s.Hook
	}
	url := sch.URL()
	if u.s == nil || u.s.OpStep != Done {
		log.Printf("worker/uniter: fetching charm %q", url)
		bun, err := u.bundles.Read(sch, u.tomb.Dying())
		if err != nil {
			return err
		}
		if err = u.deployer.Stage(bun, url); err != nil {
			return err
		}
		log.Printf("worker/uniter: deploying charm %q", url)
		if err = u.writeState(reason, Pending, hi, url); err != nil {
			return err
		}
		if err = u.deployer.Deploy(u.charm); err != nil {
			return err
		}
		if err = u.writeState(reason, Done, hi, url); err != nil {
			return err
		}
	}
	log.Printf("worker/uniter: charm %q is deployed", url)
	if err := u.unit.SetCharm(sch); err != nil {
		return err
	}
	status := Queued
	if hi != nil {
		// If a hook operation was interrupted, restore it.
		status = Pending
	} else {
		// Otherwise, queue the relevant post-deploy hook.
		hi = &hook.Info{}
		switch reason {
		case Install:
			hi.Kind = hook.Install
		case Upgrade:
			hi.Kind = hook.UpgradeCharm
		}
	}
	return u.writeState(RunHook, status, hi, nil)
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:56,代码来源:uniter.go

示例4: ModeUpgrading

// ModeUpgrading is responsible for upgrading the charm.
func ModeUpgrading(sch *state.Charm) Mode {
	name := fmt.Sprintf("ModeUpgrading %s", sch.URL())
	return func(u *Uniter) (next Mode, err error) {
		defer modeContext(name, &err)()
		if err = u.deploy(sch, Upgrade); err == charm.ErrConflict {
			return ModeConflicted(sch), nil
		} else if err != nil {
			return nil, err
		}
		return ModeContinue, nil
	}
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:13,代码来源:modes.go

示例5: assertCustomCharm

func assertCustomCharm(c *C, ch *state.Charm, series string, meta *charm.Meta, config *charm.Config, revision int) {
	// Check Charm interface method results.
	c.Assert(ch.Meta(), DeepEquals, meta)
	c.Assert(ch.Config(), DeepEquals, config)
	c.Assert(ch.Revision(), DeepEquals, revision)

	// Test URL matches charm and expected series.
	url := ch.URL()
	c.Assert(url.Series, Equals, series)
	c.Assert(url.Revision, Equals, ch.Revision())

	// Ignore the BundleURL and BundleSHA256 methods, they're irrelevant.
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:13,代码来源:charm_test.go

示例6: TestSetCharmConfig

func (s *ServiceSuite) TestSetCharmConfig(c *C) {
	charms := map[string]*state.Charm{
		stringConfig:    s.AddConfigCharm(c, "wordpress", stringConfig, 1),
		emptyConfig:     s.AddConfigCharm(c, "wordpress", emptyConfig, 2),
		floatConfig:     s.AddConfigCharm(c, "wordpress", floatConfig, 3),
		newStringConfig: s.AddConfigCharm(c, "wordpress", newStringConfig, 4),
	}

	for i, t := range setCharmConfigTests {
		c.Logf("test %d: %s", i, t.summary)

		origCh := charms[t.startconfig]
		svc, err := s.State.AddService("wordpress", origCh)
		c.Assert(err, IsNil)
		err = svc.UpdateConfigSettings(t.startvalues)
		c.Assert(err, IsNil)

		newCh := charms[t.endconfig]
		err = svc.SetCharm(newCh, false)
		var expectVals charm.Settings
		var expectCh *state.Charm
		if t.err != "" {
			c.Assert(err, ErrorMatches, t.err)
			expectCh = origCh
			expectVals = t.startvalues
		} else {
			c.Assert(err, IsNil)
			expectCh = newCh
			expectVals = t.endvalues
		}

		sch, _, err := svc.Charm()
		c.Assert(err, IsNil)
		c.Assert(sch.URL(), DeepEquals, expectCh.URL())
		settings, err := svc.ConfigSettings()
		c.Assert(err, IsNil)
		if len(expectVals) == 0 {
			c.Assert(settings, HasLen, 0)
		} else {
			c.Assert(settings, DeepEquals, expectVals)
		}

		err = svc.Destroy()
		c.Assert(err, IsNil)
	}
}
开发者ID:hivetech,项目名称:judo.legacy,代码行数:46,代码来源:service_test.go

示例7: AddService

// AddService creates a new service with the given name to run the given
// charm.  If svcName is empty, the charm name will be used.
func (conn *Conn) AddService(name string, ch *state.Charm) (*state.Service, error) {
	if name == "" {
		name = ch.URL().Name // TODO ch.Meta().Name ?
	}
	svc, err := conn.State.AddService(name, ch)
	if err != nil {
		return nil, err
	}
	meta := ch.Meta()
	for rname, rel := range meta.Peers {
		ep := state.Endpoint{
			name,
			rel.Interface,
			rname,
			state.RolePeer,
			rel.Scope,
		}
		if _, err := conn.State.AddRelation(ep); err != nil {
			return nil, fmt.Errorf("cannot add peer relation %q to service %q: %v", rname, name, err)
		}
	}
	return svc, nil
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:25,代码来源:conn.go

示例8: bundlePath

// bundlePath returns the path to the location where the verified charm
// bundle identified by sch will be, or has been, saved.
func (d *BundlesDir) bundlePath(sch *state.Charm) string {
	return filepath.Join(d.path, charm.Quote(sch.URL().String()))
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:5,代码来源:charm.go

示例9: download

// download fetches the supplied charm and checks that it has the correct sha256
// hash, then copies it into the directory. If a value is received on abort, the
// download will be stopped.
func (d *BundlesDir) download(sch *state.Charm, abort <-chan struct{}) (err error) {
	defer trivial.ErrorContextf(&err, "failed to download charm %q from %q", sch.URL(), sch.BundleURL())
	dir := d.downloadsPath()
	if err := os.MkdirAll(dir, 0755); err != nil {
		return err
	}
	burl := sch.BundleURL().String()
	log.Printf("worker/uniter/charm: downloading %s from %s", sch.URL(), burl)
	dl := downloader.New(burl, dir)
	defer dl.Stop()
	for {
		select {
		case <-abort:
			log.Printf("worker/uniter/charm: download aborted")
			return fmt.Errorf("aborted")
		case st := <-dl.Done():
			if st.Err != nil {
				return st.Err
			}
			log.Printf("worker/uniter/charm: download complete")
			defer st.File.Close()
			hash := sha256.New()
			if _, err = io.Copy(hash, st.File); err != nil {
				return err
			}
			actualSha256 := hex.EncodeToString(hash.Sum(nil))
			if actualSha256 != sch.BundleSha256() {
				return fmt.Errorf(
					"expected sha256 %q, got %q", sch.BundleSha256(), actualSha256,
				)
			}
			log.Printf("worker/uniter/charm: download verified")
			if err := os.MkdirAll(d.path, 0755); err != nil {
				return err
			}
			return os.Rename(st.File.Name(), d.bundlePath(sch))
		}
	}
	panic("unreachable")
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:43,代码来源:charm.go

示例10: assertStandardCharm

func assertStandardCharm(c *C, ch *state.Charm, series string) {
	chd := testing.Charms.Dir(ch.Meta().Name)
	assertCustomCharm(c, ch, series, chd.Meta(), chd.Config(), chd.Revision())
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:4,代码来源:charm_test.go

示例11: assertCharm

func assertCharm(c *C, bun *corecharm.Bundle, sch *state.Charm) {
	c.Assert(bun.Revision(), Equals, sch.Revision())
	c.Assert(bun.Meta(), DeepEquals, sch.Meta())
	c.Assert(bun.Config(), DeepEquals, sch.Config())
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:5,代码来源:charm_test.go


注:本文中的launchpad/net/juju-core/state.Charm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。