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


Golang worker.NewStringsWorker函数代码示例

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


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

示例1: setupContainerWorker

func (s *ContainerSetupSuite) setupContainerWorker(c *gc.C, tag names.MachineTag) (worker.StringsWatchHandler, worker.Runner) {
	testing.PatchExecutable(c, s, "ubuntu-cloudimg-query", containertesting.FakeLxcURLScript)
	runner := worker.NewRunner(allFatal, noImportance)
	pr := s.st.Provisioner()
	machine, err := pr.Machine(tag)
	c.Assert(err, jc.ErrorIsNil)
	err = machine.SetSupportedContainers(instance.ContainerTypes...)
	c.Assert(err, jc.ErrorIsNil)
	cfg := s.AgentConfigForTag(c, tag)

	watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
	params := provisioner.ContainerSetupParams{
		Runner:              runner,
		WorkerName:          watcherName,
		SupportedContainers: instance.ContainerTypes,
		ImageURLGetter:      &containertesting.MockURLGetter{},
		Machine:             machine,
		Provisioner:         pr,
		Config:              cfg,
		InitLock:            s.initLock,
	}
	handler := provisioner.NewContainerSetupHandler(params)
	runner.StartWorker(watcherName, func() (worker.Worker, error) {
		return worker.NewStringsWorker(handler), nil
	})
	return handler, runner
}
开发者ID:chrisjohnston,项目名称:juju,代码行数:27,代码来源:container_initialisation_test.go

示例2: newWorkerWithReleaser

func newWorkerWithReleaser(st stateAddresser, releaser releaser) worker.Worker {
	a := &addresserHandler{
		st:       st,
		releaser: releaser,
	}
	w := worker.NewStringsWorker(a)
	return w
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:8,代码来源:worker.go

示例3: SetUpTest

func (s *stringsWorkerSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)
	s.actor = &stringsHandler{
		actions: nil,
		handled: make(chan []string, 1),
		watcher: &testStringsWatcher{
			changes: make(chan []string),
		},
	}
	s.worker = worker.NewStringsWorker(s.actor)
}
开发者ID:kapilt,项目名称:juju,代码行数:11,代码来源:stringsworker_test.go

示例4: updateSupportedContainers

// updateSupportedContainers records in state that a machine can run the specified containers.
// It starts a watcher and when a container of a given type is first added to the machine,
// the watcher is killed, the machine is set up to be able to start containers of the given type,
// and a suitable provisioner is started.
func (a *MachineAgent) updateSupportedContainers(
	runner worker.Runner,
	st *api.State,
	machineTag string,
	containers []instance.ContainerType,
	agentConfig agent.Config,
) error {
	pr := st.Provisioner()
	tag, err := names.ParseMachineTag(machineTag)
	if err != nil {
		return err
	}
	machine, err := pr.Machine(tag)
	if errors.IsNotFound(err) || err == nil && machine.Life() == params.Dead {
		return worker.ErrTerminateAgent
	}
	if err != nil {
		return errors.Annotatef(err, "cannot load machine %s from state", tag)
	}
	if len(containers) == 0 {
		if err := machine.SupportsNoContainers(); err != nil {
			return errors.Annotatef(err, "clearing supported containers for %s", tag)
		}
		return nil
	}
	if err := machine.SetSupportedContainers(containers...); err != nil {
		return errors.Annotatef(err, "setting supported containers for %s", tag)
	}
	initLock, err := hookExecutionLock(agentConfig.DataDir())
	if err != nil {
		return err
	}
	// Start the watcher to fire when a container is first requested on the machine.
	watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
	handler := provisioner.NewContainerSetupHandler(
		runner,
		watcherName,
		containers,
		machine,
		pr,
		agentConfig,
		initLock,
	)
	a.startWorkerAfterUpgrade(runner, watcherName, func() (worker.Worker, error) {
		return worker.NewStringsWorker(handler), nil
	})
	return nil
}
开发者ID:zhouqt,项目名称:juju,代码行数:52,代码来源:machine.go

示例5: setupContainerWorker

func (s *ContainerSetupSuite) setupContainerWorker(c *gc.C, tag names.MachineTag) (worker.StringsWatchHandler, worker.Runner) {
	runner := worker.NewRunner(allFatal, noImportance)
	pr := s.st.Provisioner()
	machine, err := pr.Machine(tag)
	c.Assert(err, gc.IsNil)
	err = machine.SetSupportedContainers(instance.ContainerTypes...)
	c.Assert(err, gc.IsNil)
	cfg := s.AgentConfigForTag(c, tag)

	watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
	handler := provisioner.NewContainerSetupHandler(runner, watcherName, instance.ContainerTypes, machine, pr, cfg, s.initLock)
	runner.StartWorker(watcherName, func() (worker.Worker, error) {
		return worker.NewStringsWorker(handler), nil
	})
	return handler, runner
}
开发者ID:zhouqt,项目名称:juju,代码行数:16,代码来源:container_initialisation_test.go

示例6: NewWorker

// NewWorker returns a worker that keeps track of IP address
// lifecycles, releaseing and removing dead addresses.
func NewWorker(api *apiaddresser.API) (worker.Worker, error) {
	ok, err := api.CanDeallocateAddresses()
	if err != nil {
		return nil, errors.Annotate(err, "checking address deallocation")
	}
	if !ok {
		// Environment does not support IP address
		// deallocation.
		logger.Debugf("address deallocation not supported; not starting worker")
		return worker.FinishedWorker{}, nil
	}
	ah := &addresserHandler{
		api: api,
	}
	aw := worker.NewStringsWorker(ah)
	return aw, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:19,代码来源:worker.go

示例7: TestHandleErrorStopsWorkerAndWatcher

func (s *stringsWorkerSuite) TestHandleErrorStopsWorkerAndWatcher(c *gc.C) {
	s.stopWorker(c)
	actor := &stringsHandler{
		actions:      nil,
		handled:      make(chan []string, 1),
		handlerError: fmt.Errorf("my handling error"),
		watcher: &testStringsWatcher{
			changes: make(chan []string),
		},
	}
	w := worker.NewStringsWorker(actor)
	actor.watcher.TriggerChange(c, []string{"aa", "bb"})
	waitForHandledStrings(c, actor.handled, []string{"aa", "bb"})
	err := waitShort(c, w)
	c.Check(err, gc.ErrorMatches, "my handling error")
	actor.CheckActions(c, "setup", "handler", "teardown")
	c.Check(actor.watcher.stopped, jc.IsTrue)
}
开发者ID:kapilt,项目名称:juju,代码行数:18,代码来源:stringsworker_test.go

示例8: TestSetUpFailureStopsWithTearDown

func (s *stringsWorkerSuite) TestSetUpFailureStopsWithTearDown(c *gc.C) {
	// Stop the worker and SetUp again, this time with an error
	s.stopWorker(c)
	actor := &stringsHandler{
		actions:    nil,
		handled:    make(chan []string, 1),
		setupError: fmt.Errorf("my special error"),
		watcher: &testStringsWatcher{
			changes: make(chan []string),
		},
	}
	w := worker.NewStringsWorker(actor)
	err := waitShort(c, w)
	c.Check(err, gc.ErrorMatches, "my special error")
	// TearDown is not called on SetUp error.
	actor.CheckActions(c, "setup")
	c.Check(actor.watcher.stopped, jc.IsTrue)
}
开发者ID:kapilt,项目名称:juju,代码行数:18,代码来源:stringsworker_test.go

示例9: newStringsHandlerWorker

func newStringsHandlerWorker(c *gc.C, setupError, handlerError, teardownError error) (*stringsHandler, worker.Worker) {
	sh := &stringsHandler{
		actions:       nil,
		handled:       make(chan []string, 1),
		setupError:    setupError,
		teardownError: teardownError,
		handlerError:  handlerError,
		watcher: &testStringsWatcher{
			changes: make(chan []string),
		},
		setupDone: make(chan struct{}),
	}
	w := worker.NewStringsWorker(sh)
	select {
	case <-sh.setupDone:
	case <-time.After(coretesting.ShortWait):
		c.Error("Failed waiting for stringsHandler.Setup to be called during SetUpTest")
	}
	return sh, w
}
开发者ID:imoapps,项目名称:juju,代码行数:20,代码来源:stringsworker_test.go

示例10: updateSupportedContainers

// updateSupportedContainers records in state that a machine can run the specified containers.
// It starts a watcher and when a container of a given type is first added to the machine,
// the watcher is killed, the machine is set up to be able to start containers of the given type,
// and a suitable provisioner is started.
func (a *MachineAgent) updateSupportedContainers(
	runner worker.Runner,
	st *api.State,
	tag string,
	containers []instance.ContainerType,
	agentConfig agent.Config,
) error {
	pr := st.Provisioner()
	machine, err := pr.Machine(tag)
	if err != nil {
		return fmt.Errorf("%s is not in state: %v", tag, err)
	}
	if len(containers) == 0 {
		if err := machine.SupportsNoContainers(); err != nil {
			return fmt.Errorf("clearing supported containers for %s: %v", tag, err)
		}
		return nil
	}
	if err := machine.SetSupportedContainers(containers...); err != nil {
		return fmt.Errorf("setting supported containers for %s: %v", tag, err)
	}
	initLock, err := hookExecutionLock(agentConfig.DataDir())
	if err != nil {
		return err
	}
	// Start the watcher to fire when a container is first requested on the machine.
	watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
	handler := provisioner.NewContainerSetupHandler(
		runner,
		watcherName,
		containers,
		machine,
		pr,
		agentConfig,
		initLock,
	)
	a.startWorkerAfterUpgrade(runner, watcherName, func() (worker.Worker, error) {
		return worker.NewStringsWorker(handler), nil
	})
	return nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:45,代码来源:machine.go

示例11: New

func New(ua UnitAssigner) worker.Worker {
	return worker.NewStringsWorker(unitAssigner{api: ua})
}
开发者ID:imoapps,项目名称:juju,代码行数:3,代码来源:unitassigner.go

示例12: NewMinUnitsWorker

// NewMinUnitsWorker returns a Worker that runs service.EnsureMinUnits()
// if the number of alive units belonging to a service decreases, or if the
// minimum required number of units for a service is increased.
func NewMinUnitsWorker(st *state.State) worker.Worker {
	mu := &MinUnitsWorker{st: st}
	return worker.NewStringsWorker(mu)
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:minunitsworker.go


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