本文整理汇总了Golang中github.com/juju/juju/worker/uniter/relation.NewRelationsResolver函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRelationsResolver函数的具体用法?Golang NewRelationsResolver怎么用?Golang NewRelationsResolver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRelationsResolver函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: assertHookRelationDeparted
func (s *relationsSuite) assertHookRelationDeparted(c *gc.C, numCalls *int32, apiCalls ...apiCall) relation.Relations {
r := s.assertHookRelationJoined(c, numCalls, apiCalls...)
s.assertHookRelationChanged(c, r, remotestate.RelationSnapshot{
Life: params.Alive,
}, numCalls)
numCallsBefore := *numCalls
localState := resolver.LocalState{
State: operation.State{
Kind: operation.Continue,
},
}
remoteState := remotestate.Snapshot{
Relations: map[int]remotestate.RelationSnapshot{
1: remotestate.RelationSnapshot{
Life: params.Dying,
Members: map[string]int64{
"wordpress": 1,
},
},
},
}
relationsResolver := relation.NewRelationsResolver(r)
op, err := relationsResolver.NextOp(localState, remoteState, &mockOperations{})
c.Assert(err, jc.ErrorIsNil)
assertNumCalls(c, numCalls, numCallsBefore+1)
c.Assert(op.String(), gc.Equals, "run hook relation-departed on unit with relation 1")
// Commit the operation so we save local state for any next operation.
_, err = r.PrepareHook(op.(*mockOperation).hookInfo)
c.Assert(err, jc.ErrorIsNil)
err = r.CommitHook(op.(*mockOperation).hookInfo)
c.Assert(err, jc.ErrorIsNil)
return r
}
开发者ID:kat-co,项目名称:juju,代码行数:35,代码来源:relations_test.go
示例2: TestHookRelationBroken
func (s *relationsSuite) TestHookRelationBroken(c *gc.C) {
var numCalls int32
apiCalls := relationJoinedApiCalls()
apiCalls = append(apiCalls, getPrincipalApiCalls(3)...)
r := s.assertHookRelationDeparted(c, &numCalls, apiCalls...)
localState := resolver.LocalState{
State: operation.State{
Kind: operation.Continue,
},
}
remoteState := remotestate.Snapshot{
Relations: map[int]remotestate.RelationSnapshot{
1: remotestate.RelationSnapshot{
Life: params.Dying,
},
},
}
relationsResolver := relation.NewRelationsResolver(r)
op, err := relationsResolver.NextOp(localState, remoteState, &mockOperations{})
c.Assert(err, jc.ErrorIsNil)
assertNumCalls(c, &numCalls, 11)
c.Assert(op.String(), gc.Equals, "run hook relation-broken on unit with relation 1")
}
开发者ID:kat-co,项目名称:juju,代码行数:25,代码来源:relations_test.go
示例3: TestNextOpNothing
func (s *relationsSuite) TestNextOpNothing(c *gc.C) {
unitTag := names.NewUnitTag("wordpress/0")
abort := make(chan struct{})
var numCalls int32
unitEntity := params.Entities{Entities: []params.Entity{params.Entity{Tag: "unit-wordpress-0"}}}
apiCaller := mockAPICaller(c, &numCalls,
uniterApiCall("Life", unitEntity, params.LifeResults{Results: []params.LifeResult{{Life: params.Alive}}}, nil),
uniterApiCall("JoinedRelations", unitEntity, params.StringsResults{Results: []params.StringsResult{{Result: []string{}}}}, nil),
uniterApiCall("GetPrincipal", unitEntity, params.StringBoolResults{Results: []params.StringBoolResult{{Result: "", Ok: false}}}, nil),
)
st := uniter.NewState(apiCaller, unitTag)
r, err := relation.NewRelations(st, unitTag, s.stateDir, s.relationsDir, abort)
c.Assert(err, jc.ErrorIsNil)
assertNumCalls(c, &numCalls, 2)
localState := resolver.LocalState{
State: operation.State{
Kind: operation.Continue,
},
}
remoteState := remotestate.Snapshot{}
relationsResolver := relation.NewRelationsResolver(r)
_, err = relationsResolver.NextOp(localState, remoteState, &mockOperations{})
c.Assert(errors.Cause(err), gc.Equals, resolver.ErrNoOperation)
}
开发者ID:kat-co,项目名称:juju,代码行数:26,代码来源:relations_test.go
示例4: assertHookRelationChanged
func (s *relationsSuite) assertHookRelationChanged(
c *gc.C, r relation.Relations,
remoteRelationSnapshot remotestate.RelationSnapshot,
numCalls *int32,
) {
numCallsBefore := *numCalls
localState := resolver.LocalState{
State: operation.State{
Kind: operation.Continue,
},
}
remoteState := remotestate.Snapshot{
Relations: map[int]remotestate.RelationSnapshot{
1: remoteRelationSnapshot,
},
}
relationsResolver := relation.NewRelationsResolver(r)
op, err := relationsResolver.NextOp(localState, remoteState, &mockOperations{})
c.Assert(err, jc.ErrorIsNil)
assertNumCalls(c, numCalls, numCallsBefore+1)
c.Assert(op.String(), gc.Equals, "run hook relation-changed on unit with relation 1")
// Commit the operation so we save local state for any next operation.
_, err = r.PrepareHook(op.(*mockOperation).hookInfo)
c.Assert(err, jc.ErrorIsNil)
err = r.CommitHook(op.(*mockOperation).hookInfo)
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:kat-co,项目名称:juju,代码行数:28,代码来源:relations_test.go
示例5: SetUpTest
func (s *resolverSuite) SetUpTest(c *gc.C) {
s.stub = testing.Stub{}
s.charmURL = charm.MustParseURL("cs:precise/mysql-2")
s.remoteState = remotestate.Snapshot{
CharmModifiedVersion: s.charmModifiedVersion,
CharmURL: s.charmURL,
}
s.opFactory = operation.NewFactory(operation.FactoryParams{})
attachments, err := storage.NewAttachments(&dummyStorageAccessor{}, names.NewUnitTag("u/0"), c.MkDir(), nil)
c.Assert(err, jc.ErrorIsNil)
s.clearResolved = func() error {
return errors.New("unexpected resolved")
}
s.reportHookError = func(hook.Info) error {
return errors.New("unexpected report hook error")
}
s.resolverConfig = uniter.ResolverConfig{
ClearResolved: func() error { return s.clearResolved() },
ReportHookError: func(info hook.Info) error { return s.reportHookError(info) },
StartRetryHookTimer: func() { s.stub.AddCall("StartRetryHookTimer") },
StopRetryHookTimer: func() { s.stub.AddCall("StopRetryHookTimer") },
ShouldRetryHooks: true,
Leadership: leadership.NewResolver(),
Actions: uniteractions.NewResolver(),
Relations: relation.NewRelationsResolver(&dummyRelations{}),
Storage: storage.NewResolver(attachments),
Commands: nopResolver{},
}
s.resolver = uniter.NewUniterResolver(s.resolverConfig)
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:resolver_test.go
示例6: TestImplicitRelationNoHooks
func (s *relationsSuite) TestImplicitRelationNoHooks(c *gc.C) {
unitTag := names.NewUnitTag("wordpress/0")
abort := make(chan struct{})
unitEntity := params.Entities{Entities: []params.Entity{params.Entity{Tag: "unit-wordpress-0"}}}
relationResults := params.RelationResults{
Results: []params.RelationResult{
{
Id: 1,
Key: "wordpress:juju-info juju-info:juju-info",
Life: params.Alive,
Endpoint: multiwatcher.Endpoint{
ApplicationName: "wordpress",
Relation: multiwatcher.CharmRelation{Name: "juju-info", Role: string(charm.RoleProvider), Interface: "juju-info", Scope: "global"},
}},
},
}
relationUnits := params.RelationUnits{RelationUnits: []params.RelationUnit{
{Relation: "relation-wordpress.juju-info#juju-info.juju-info", Unit: "unit-wordpress-0"},
}}
apiCalls := []apiCall{
uniterApiCall("Life", unitEntity, params.LifeResults{Results: []params.LifeResult{{Life: params.Alive}}}, nil),
uniterApiCall("JoinedRelations", unitEntity, params.StringsResults{Results: []params.StringsResult{{Result: []string{}}}}, nil),
uniterApiCall("RelationById", params.RelationIds{RelationIds: []int{1}}, relationResults, nil),
uniterApiCall("Relation", relationUnits, relationResults, nil),
uniterApiCall("Relation", relationUnits, relationResults, nil),
uniterApiCall("Watch", unitEntity, params.NotifyWatchResults{Results: []params.NotifyWatchResult{{NotifyWatcherId: "1"}}}, nil),
uniterApiCall("EnterScope", relationUnits, params.ErrorResults{Results: []params.ErrorResult{{}}}, nil),
uniterApiCall("GetPrincipal", unitEntity, params.StringBoolResults{Results: []params.StringBoolResult{{Result: "", Ok: false}}}, nil),
}
var numCalls int32
apiCaller := mockAPICaller(c, &numCalls, apiCalls...)
st := uniter.NewState(apiCaller, unitTag)
r, err := relation.NewRelations(st, unitTag, s.stateDir, s.relationsDir, abort)
c.Assert(err, jc.ErrorIsNil)
localState := resolver.LocalState{
State: operation.State{
Kind: operation.Continue,
},
}
remoteState := remotestate.Snapshot{
Relations: map[int]remotestate.RelationSnapshot{
1: remotestate.RelationSnapshot{
Life: params.Alive,
Members: map[string]int64{
"wordpress": 1,
},
},
},
}
relationsResolver := relation.NewRelationsResolver(r)
_, err = relationsResolver.NextOp(localState, remoteState, &mockOperations{})
c.Assert(errors.Cause(err), gc.Equals, resolver.ErrNoOperation)
}
开发者ID:kat-co,项目名称:juju,代码行数:56,代码来源:relations_test.go
示例7: SetUpTest
func (s *resolverSuite) SetUpTest(c *gc.C) {
s.charmURL = charm.MustParseURL("cs:precise/mysql-2")
s.remoteState = remotestate.Snapshot{
CharmURL: s.charmURL,
}
s.opFactory = operation.NewFactory(operation.FactoryParams{})
attachments, err := storage.NewAttachments(&dummyStorageAccessor{}, names.NewUnitTag("u/0"), c.MkDir(), nil)
c.Assert(err, jc.ErrorIsNil)
s.resolver = uniter.NewUniterResolver(
func() error { return errors.New("unexpected resolved") },
func(_ hook.Info) error { return errors.New("unexpected report hook error") },
func() error { return nil },
uniteractions.NewResolver(),
leadership.NewResolver(),
relation.NewRelationsResolver(&dummyRelations{}),
storage.NewResolver(attachments),
)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:20,代码来源:resolver_test.go
示例8: assertHookRelationJoined
func (s *relationsSuite) assertHookRelationJoined(c *gc.C, numCalls *int32, apiCalls ...apiCall) relation.Relations {
unitTag := names.NewUnitTag("wordpress/0")
abort := make(chan struct{})
apiCaller := mockAPICaller(c, numCalls, apiCalls...)
st := uniter.NewState(apiCaller, unitTag)
r, err := relation.NewRelations(st, unitTag, s.stateDir, s.relationsDir, abort)
c.Assert(err, jc.ErrorIsNil)
assertNumCalls(c, numCalls, 2)
localState := resolver.LocalState{
State: operation.State{
Kind: operation.Continue,
},
}
remoteState := remotestate.Snapshot{
Relations: map[int]remotestate.RelationSnapshot{
1: remotestate.RelationSnapshot{
Life: params.Alive,
Members: map[string]int64{
"wordpress": 1,
},
},
},
}
relationsResolver := relation.NewRelationsResolver(r)
op, err := relationsResolver.NextOp(localState, remoteState, &mockOperations{})
c.Assert(err, jc.ErrorIsNil)
assertNumCalls(c, numCalls, 8)
c.Assert(op.String(), gc.Equals, "run hook relation-joined on unit with relation 1")
// Commit the operation so we save local state for any next operation.
_, err = r.PrepareHook(op.(*mockOperation).hookInfo)
c.Assert(err, jc.ErrorIsNil)
err = r.CommitHook(op.(*mockOperation).hookInfo)
c.Assert(err, jc.ErrorIsNil)
return r
}
开发者ID:kat-co,项目名称:juju,代码行数:38,代码来源:relations_test.go
示例9: loop
//.........这里部分代码省略.........
if opState.Kind != operation.Continue {
// We should only set idle status if we're in
// the "Continue" state, which indicates that
// there is nothing to do and we're not in an
// error state.
return nil
}
return setAgentStatus(u, status.StatusIdle, "", nil)
}
clearResolved := func() error {
if err := u.unit.ClearResolved(); err != nil {
return errors.Trace(err)
}
watcher.ClearResolvedMode()
return nil
}
for {
if err = restartWatcher(); err != nil {
err = errors.Annotate(err, "(re)starting watcher")
break
}
uniterResolver := NewUniterResolver(ResolverConfig{
ClearResolved: clearResolved,
ReportHookError: u.reportHookError,
FixDeployer: u.deployer.Fix,
ShouldRetryHooks: u.hookRetryStrategy.ShouldRetry,
StartRetryHookTimer: retryHookTimer.Start,
StopRetryHookTimer: retryHookTimer.Reset,
Actions: actions.NewResolver(),
Leadership: uniterleadership.NewResolver(),
Relations: relation.NewRelationsResolver(u.relations),
Storage: storage.NewResolver(u.storage),
Commands: runcommands.NewCommandsResolver(
u.commands, watcher.CommandCompleted,
),
})
// We should not do anything until there has been a change
// to the remote state. The watcher will trigger at least
// once initially.
select {
case <-u.catacomb.Dying():
return u.catacomb.ErrDying()
case <-watcher.RemoteStateChanged():
}
localState := resolver.LocalState{
CharmURL: charmURL,
CharmModifiedVersion: charmModifiedVersion,
}
for err == nil {
err = resolver.Loop(resolver.LoopConfig{
Resolver: uniterResolver,
Watcher: watcher,
Executor: u.operationExecutor,
Factory: u.operationFactory,
Abort: u.catacomb.Dying(),
OnIdle: onIdle,
CharmDirGuard: u.charmDirGuard,
}, &localState)
switch cause := errors.Cause(err); cause {
case nil:
// Loop back around.
开发者ID:xushiwei,项目名称:juju,代码行数:67,代码来源:uniter.go
示例10: loop
//.........这里部分代码省略.........
defer watcherMu.Unlock()
if watcher != nil {
return watcher.Stop()
}
return nil
})
onIdle := func() error {
opState := u.operationExecutor.State()
if opState.Kind != operation.Continue {
// We should only set idle status if we're in
// the "Continue" state, which indicates that
// there is nothing to do and we're not in an
// error state.
return nil
}
return setAgentStatus(u, params.StatusIdle, "", nil)
}
clearResolved := func() error {
if err := u.unit.ClearResolved(); err != nil {
return errors.Trace(err)
}
watcher.ClearResolvedMode()
return nil
}
for {
if err = restartWatcher(); err != nil {
err = errors.Annotate(err, "(re)starting watcher")
break
}
uniterResolver := &uniterResolver{
clearResolved: clearResolved,
reportHookError: u.reportHookError,
fixDeployer: u.deployer.Fix,
actionsResolver: actions.NewResolver(),
leadershipResolver: uniterleadership.NewResolver(),
relationsResolver: relation.NewRelationsResolver(u.relations),
storageResolver: storage.NewResolver(u.storage),
}
// We should not do anything until there has been a change
// to the remote state. The watcher will trigger at least
// once initially.
select {
case <-u.tomb.Dying():
return tomb.ErrDying
case <-watcher.RemoteStateChanged():
}
localState := resolver.LocalState{CharmURL: charmURL}
for err == nil {
err = resolver.Loop(resolver.LoopConfig{
Resolver: uniterResolver,
Watcher: watcher,
Executor: u.operationExecutor,
Factory: u.operationFactory,
Dying: u.tomb.Dying(),
OnIdle: onIdle,
CharmDirLocker: u.charmDirLocker,
}, &localState)
switch cause := errors.Cause(err); cause {
case nil:
// Loop back around.
case tomb.ErrDying:
err = tomb.ErrDying
case operation.ErrNeedsReboot:
err = worker.ErrRebootMachine
case operation.ErrHookFailed:
// Loop back around. The resolver can tell that it is in
// an error state by inspecting the operation state.
err = nil
case resolver.ErrTerminate:
err = u.terminate()
case resolver.ErrRestart:
charmURL = localState.CharmURL
// leave err assigned, causing loop to break
default:
// We need to set conflicted from here, because error
// handling is outside of the resolver's control.
if operation.IsDeployConflictError(cause) {
localState.Conflicted = true
err = setAgentStatus(u, params.StatusError, "upgrade failed", nil)
} else {
reportAgentError(u, "resolver loop error", err)
}
}
}
if errors.Cause(err) != resolver.ErrRestart {
break
}
}
logger.Infof("unit %q shutting down: %s", u.unit, err)
return err
}
开发者ID:kakamessi99,项目名称:juju,代码行数:101,代码来源:uniter.go
注:本文中的github.com/juju/juju/worker/uniter/relation.NewRelationsResolver函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论