• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang runner.NewRunner函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: do

func (w *collect) do() error {
	logger.Tracef("recording metrics")

	config := w.agent.CurrentConfig()
	tag := config.Tag()
	unitTag, ok := tag.(names.UnitTag)
	if !ok {
		return errors.Errorf("expected a unit tag, got %v", tag)
	}
	paths := uniter.NewWorkerPaths(config.DataDir(), unitTag, "metrics-collect")

	recorder, err := newRecorder(unitTag, paths, w.unitCharmLookup, w.metricFactory)
	if errors.Cause(err) == errMetricsNotDefined {
		logger.Tracef("%v", err)
		return nil
	} else if err != nil {
		return errors.Annotate(err, "failed to instantiate metric recorder")
	}

	ctx := newHookContext(unitTag.String(), recorder)
	err = ctx.addJujuUnitsMetric()
	if err != nil {
		return errors.Annotatef(err, "error adding 'juju-units' metric")
	}

	r := runner.NewRunner(ctx, paths)
	err = r.RunHook(string(hooks.CollectMetrics))
	if err != nil {
		return errors.Annotatef(err, "error running 'collect-metrics' hook")
	}
	return nil
}
开发者ID:imoapps,项目名称:juju,代码行数:32,代码来源:manifold.go


示例2: TestRunHook

func (s *RunHookSuite) TestRunHook(c *gc.C) {
	uuid, err := utils.NewUUID()
	c.Assert(err, jc.ErrorIsNil)
	for i, t := range runHookTests {
		c.Logf("\ntest %d: %s; perm %v", i, t.summary, t.spec.perm)
		ctx := s.getHookContext(c, uuid.String(), t.relid, t.remote, noProxies)
		paths := NewRealPaths(c)
		rnr := runner.NewRunner(ctx, paths)
		var hookExists bool
		if t.spec.perm != 0 {
			spec := t.spec
			spec.dir = "hooks"
			spec.name = hookName
			c.Logf("makeCharm %#v", spec)
			makeCharm(c, spec, paths.charm)
			hookExists = true
		}
		t0 := time.Now()
		err := rnr.RunHook("something-happened")
		if t.err == "" && hookExists {
			c.Assert(err, jc.ErrorIsNil)
		} else if !hookExists {
			c.Assert(runner.IsMissingHookError(err), jc.IsTrue)
		} else {
			c.Assert(err, gc.ErrorMatches, t.err)
		}
		if t.spec.background != "" && time.Now().Sub(t0) > 5*time.Second {
			c.Errorf("background process holding up hook execution")
		}
	}
}
开发者ID:mhilton,项目名称:juju,代码行数:31,代码来源:runner_test.go


示例3: TestRunCommandsEnvStdOutAndErrAndRC

func (s *RunCommandSuite) TestRunCommandsEnvStdOutAndErrAndRC(c *gc.C) {
	// TODO(bogdanteleaga): powershell throws another exit status code when
	// outputting to stderr using Write-Error. Either find another way to
	// output to stderr or change the checks
	if runtime.GOOS == "windows" {
		c.Skip("bug 1403084: Have to figure out a good way to output to stderr from powershell")
	}
	ctx, err := s.contextFactory.HookContext(hook.Info{Kind: hooks.ConfigChanged})
	c.Assert(err, jc.ErrorIsNil)
	paths := runnertesting.NewRealPaths(c)
	runner := runner.NewRunner(ctx, paths)

	commands := `
echo $JUJU_CHARM_DIR
echo this is standard err >&2
exit 42
`
	result, err := runner.RunCommands(commands)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(result.Code, gc.Equals, 42)
	c.Assert(strings.TrimRight(string(result.Stdout), "\r\n"), gc.Equals, paths.GetCharmDir())
	c.Assert(strings.TrimRight(string(result.Stderr), "\r\n"), gc.Equals, "this is standard err")
	c.Assert(ctx.GetProcess(), gc.NotNil)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:25,代码来源:runner_test.go


示例4: TestRunHook

func (s *RunHookSuite) TestRunHook(c *gc.C) {
	for i, t := range runHookTests {
		c.Logf("\ntest %d: %s; perm %v", i, t.summary, t.spec.perm)
		ctx, err := s.contextFactory.HookContext(hook.Info{Kind: hooks.ConfigChanged})
		c.Assert(err, jc.ErrorIsNil)

		paths := runnertesting.NewRealPaths(c)
		rnr := runner.NewRunner(ctx, paths)
		var hookExists bool
		if t.spec.perm != 0 {
			spec := t.spec
			spec.dir = "hooks"
			spec.name = hookName
			c.Logf("makeCharm %#v", spec)
			makeCharm(c, spec, paths.GetCharmDir())
			hookExists = true
		}
		t0 := time.Now()
		err = rnr.RunHook("something-happened")
		if t.err == "" && hookExists {
			c.Assert(err, jc.ErrorIsNil)
		} else if !hookExists {
			c.Assert(context.IsMissingHookError(err), jc.IsTrue)
		} else {
			c.Assert(err, gc.ErrorMatches, t.err)
		}
		if t.spec.background != "" && time.Now().Sub(t0) > 5*time.Second {
			c.Errorf("background process holding up hook execution")
		}
	}
}
开发者ID:kakamessi99,项目名称:juju,代码行数:31,代码来源:runner_test.go


示例5: TestRunActionParamsFailure

func (s *RunMockContextSuite) TestRunActionParamsFailure(c *gc.C) {
	expectErr := errors.New("stork")
	ctx := &MockContext{
		actionData:      &context.ActionData{},
		actionParamsErr: expectErr,
	}
	actualErr := runner.NewRunner(ctx, s.paths).RunAction("juju-run")
	c.Assert(errors.Cause(actualErr), gc.Equals, expectErr)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:9,代码来源:runner_test.go


示例6: TestRunCommandsFlushFailure

func (s *RunMockContextSuite) TestRunCommandsFlushFailure(c *gc.C) {
	expectErr := errors.New("pew pew pew")
	ctx := &MockContext{
		flushResult: expectErr,
	}
	_, actualErr := runner.NewRunner(ctx, s.paths).RunCommands(echoPidScript + "; exit 123")
	c.Assert(actualErr, gc.Equals, expectErr)
	c.Assert(ctx.flushBadge, gc.Equals, "run commands")
	c.Assert(ctx.flushFailure, gc.IsNil) // exit code in _ result, as tested elsewhere
	s.assertRecordedPid(c, ctx.expectPid)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:11,代码来源:runner_test.go


示例7: TestRunCommandsFlushSuccess

func (s *RunMockContextSuite) TestRunCommandsFlushSuccess(c *gc.C) {
	expectErr := errors.New("pew pew pew")
	ctx := &MockContext{
		flushResult: expectErr,
	}
	_, actualErr := runner.NewRunner(ctx, s.paths).RunCommands(echoPidScript)
	c.Assert(actualErr, gc.Equals, expectErr)
	c.Assert(ctx.flushBadge, gc.Equals, "run commands")
	c.Assert(ctx.flushFailure, gc.IsNil)
	s.assertRecordedPid(c, ctx.expectPid)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:11,代码来源:runner_test.go


示例8: TestRunHookFlushSuccess

func (s *RunMockContextSuite) TestRunHookFlushSuccess(c *gc.C) {
	expectErr := errors.New("pew pew pew")
	ctx := &MockContext{
		flushResult: expectErr,
	}
	makeCharm(c, hookSpec{
		dir:  "hooks",
		name: hookName,
		perm: 0700,
	}, s.paths.GetCharmDir())
	actualErr := runner.NewRunner(ctx, s.paths).RunHook("something-happened")
	c.Assert(actualErr, gc.Equals, expectErr)
	c.Assert(ctx.flushBadge, gc.Equals, "something-happened")
	c.Assert(ctx.flushFailure, gc.IsNil)
	s.assertRecordedPid(c, ctx.expectPid)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:16,代码来源:runner_test.go


示例9: TestRunHookFlushFailure

func (s *RunMockContextSuite) TestRunHookFlushFailure(c *gc.C) {
	expectErr := errors.New("pew pew pew")
	ctx := &MockContext{
		flushResult: expectErr,
	}
	makeCharm(c, hookSpec{
		dir:  "hooks",
		name: hookName,
		perm: 0700,
		code: 123,
	}, s.paths.charm)
	actualErr := runner.NewRunner(ctx, s.paths).RunHook("something-happened")
	c.Assert(actualErr, gc.Equals, expectErr)
	c.Assert(ctx.flushBadge, gc.Equals, "something-happened")
	c.Assert(ctx.flushFailure, gc.ErrorMatches, "exit status 123")
	s.assertRecordedPid(c, ctx.expectPid)
}
开发者ID:mhilton,项目名称:juju,代码行数:17,代码来源:runner_test.go


示例10: TestRunActionSuccessful

func (s *RunMockContextSuite) TestRunActionSuccessful(c *gc.C) {
	ctx := &MockContext{
		actionData: &context.ActionData{},
		actionParams: map[string]interface{}{
			"command": "echo 1",
			"timeout": 0,
		},
		actionResults: map[string]interface{}{},
	}
	err := runner.NewRunner(ctx, s.paths).RunAction("juju-run")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ctx.flushBadge, gc.Equals, "juju-run")
	c.Assert(ctx.flushFailure, gc.IsNil)
	c.Assert(ctx.actionResults["Code"], gc.Equals, "0")
	c.Assert(strings.TrimRight(ctx.actionResults["Stdout"].(string), "\r\n"), gc.Equals, "1")
	c.Assert(ctx.actionResults["Stderr"], gc.Equals, "")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:17,代码来源:runner_test.go


示例11: RunHook

func (w *hookRunner) RunHook(code, info string, interrupt <-chan struct{}) (runErr error) {
	unitTag := w.tag
	paths := uniter.NewPaths(w.config.DataDir(), unitTag)
	ctx := NewLimitedContext(unitTag.String())
	ctx.SetEnvVars(map[string]string{
		"JUJU_METER_STATUS": code,
		"JUJU_METER_INFO":   info,
	})
	r := runner.NewRunner(ctx, paths)
	releaser, err := w.acquireExecutionLock(interrupt)
	if err != nil {
		return errors.Annotate(err, "failed to acquire machine lock")
	}
	// Defer the logging first so it is executed after the Release. LIFO.
	defer logger.Debugf("release lock %q for meter status hook execution", w.machineLockName)
	defer releaser.Release()
	return r.RunHook(string(hooks.MeterStatusChanged))
}
开发者ID:bac,项目名称:juju,代码行数:18,代码来源:runner.go


示例12: do

func (h *hookRunner) do(recorder spool.MetricRecorder) error {
	h.m.Lock()
	defer h.m.Unlock()
	logger.Tracef("recording metrics")

	ctx := newHookContext(h.unitTag, recorder)
	err := ctx.addJujuUnitsMetric()
	if err != nil {
		return errors.Annotatef(err, "error adding 'juju-units' metric")
	}

	r := runner.NewRunner(ctx, h.paths)
	err = r.RunHook(string(hooks.CollectMetrics))
	if err != nil {
		return errors.Annotatef(err, "error running 'collect-metrics' hook")
	}
	return nil
}
开发者ID:exekias,项目名称:juju,代码行数:18,代码来源:manifold.go


示例13: TestRunActionCancelled

func (s *RunMockContextSuite) TestRunActionCancelled(c *gc.C) {
	timeout := 1 * time.Nanosecond
	ctx := &MockContext{
		actionData: &context.ActionData{},
		actionParams: map[string]interface{}{
			"command": "sleep 10",
			"timeout": float64(timeout.Nanoseconds()),
		},
		actionResults: map[string]interface{}{},
	}
	err := runner.NewRunner(ctx, s.paths).RunAction("juju-run")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ctx.flushBadge, gc.Equals, "juju-run")
	c.Assert(ctx.flushFailure, gc.Equals, exec.ErrCancelled)
	c.Assert(ctx.actionResults["Code"], gc.Equals, nil)
	c.Assert(ctx.actionResults["Stdout"], gc.Equals, nil)
	c.Assert(ctx.actionResults["Stderr"], gc.Equals, nil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:18,代码来源:runner_test.go


示例14: RunHook

func (w *hookRunner) RunHook(code, info string, interrupt <-chan struct{}) (runErr error) {
	unitTag := w.tag
	paths := uniter.NewPaths(w.config.DataDir(), unitTag)
	ctx := NewLimitedContext(unitTag.String())
	ctx.SetEnvVars(map[string]string{
		"JUJU_METER_STATUS": code,
		"JUJU_METER_INFO":   info,
	})
	r := runner.NewRunner(ctx, paths)
	unlock, err := w.acquireExecutionLock(interrupt)
	if err != nil {
		return errors.Annotate(err, "failed to acquire machine lock")
	}
	defer func() {
		unlockErr := unlock()
		if unlockErr != nil {
			logger.Criticalf("hook run resulted in error %v; unlock failure error: %v", runErr, unlockErr)
		}
	}()
	return r.RunHook(string(hooks.MeterStatusChanged))
}
开发者ID:imoapps,项目名称:juju,代码行数:21,代码来源:runner.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang runner.Context类代码示例发布时间:2022-05-23
下一篇:
Golang resolver.LocalState类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap