本文整理汇总了Golang中github.com/juju/juju/state.Relation类的典型用法代码示例。如果您正苦于以下问题:Golang Relation类的具体用法?Golang Relation怎么用?Golang Relation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Relation类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addRU
func addRU(c *gc.C, svc *state.Service, rel *state.Relation, principal *state.Unit) (*state.Unit, *state.RelationUnit) {
// Given the service svc in the relation rel, add a unit of svc and create
// a RelationUnit with rel. If principal is supplied, svc is assumed to be
// subordinate and the unit will be created by temporarily entering the
// relation's scope as the principal.
var u *state.Unit
if principal == nil {
unit, err := svc.AddUnit()
c.Assert(err, jc.ErrorIsNil)
u = unit
} else {
origUnits, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
pru, err := rel.Unit(principal)
c.Assert(err, jc.ErrorIsNil)
err = pru.EnterScope(nil) // to create the subordinate
c.Assert(err, jc.ErrorIsNil)
err = pru.LeaveScope() // to reset to initial expected state
c.Assert(err, jc.ErrorIsNil)
newUnits, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
for _, unit := range newUnits {
found := false
for _, old := range origUnits {
if unit.Name() == old.Name() {
found = true
break
}
}
if !found {
u = unit
break
}
}
c.Assert(u, gc.NotNil)
}
preventUnitDestroyRemove(c, u)
ru, err := rel.Unit(u)
c.Assert(err, jc.ErrorIsNil)
return u, ru
}
示例2: prepareRelationResult
func (u *UniterAPIV3) prepareRelationResult(rel *state.Relation, unit *state.Unit) (params.RelationResult, error) {
nothing := params.RelationResult{}
ep, err := rel.Endpoint(unit.ApplicationName())
if err != nil {
// An error here means the unit's service is not part of the
// relation.
return nothing, err
}
return params.RelationResult{
Id: rel.Id(),
Key: rel.String(),
Life: params.Life(rel.Life().String()),
Endpoint: multiwatcher.Endpoint{
ApplicationName: ep.ApplicationName,
Relation: multiwatcher.NewCharmRelation(ep.Relation),
},
}, nil
}
示例3: prepareRelationResult
func (u *UniterAPI) prepareRelationResult(rel *state.Relation, unit *state.Unit) (params.RelationResult, error) {
nothing := params.RelationResult{}
ep, err := rel.Endpoint(unit.ServiceName())
if err != nil {
// An error here means the unit's service is not part of the
// relation.
return nothing, err
}
return params.RelationResult{
Id: rel.Id(),
Key: rel.String(),
Life: params.Life(rel.Life().String()),
Endpoint: params.Endpoint{
ServiceName: ep.ServiceName,
Relation: ep.Relation,
},
}, nil
}