// NewContextFactory returns a ContextFactory capable of creating execution contexts backed // by the supplied unit's supplied API connection. func NewContextFactory( state *uniter.State, unitTag names.UnitTag, tracker leadership.Tracker, getRelationInfos RelationsFunc, storage StorageContextAccessor, paths Paths, clock clock.Clock, ) ( ContextFactory, error, ) { unit, err := state.Unit(unitTag) if err != nil { return nil, errors.Trace(err) } machineTag, err := unit.AssignedMachine() if err != nil { return nil, errors.Trace(err) } model, err := state.Model() if err != nil { return nil, errors.Trace(err) } zone, err := unit.AvailabilityZone() if err != nil { return nil, errors.Trace(err) } f := &contextFactory{ unit: unit, state: state, tracker: tracker, paths: paths, modelUUID: model.UUID(), envName: model.Name(), machineTag: machineTag, getRelationInfos: getRelationInfos, relationCaches: map[int]*RelationCache{}, storage: storage, rand: rand.New(rand.NewSource(time.Now().Unix())), clock: clock, zone: zone, } return f, nil }
// NewFactory returns a Factory capable of creating execution contexts backed // by the supplied unit's supplied API connection. func NewFactory( state *uniter.State, unitTag names.UnitTag, tracker leadership.Tracker, getRelationInfos RelationsFunc, storage StorageContextAccessor, paths Paths, ) ( Factory, error, ) { unit, err := state.Unit(unitTag) if err != nil { return nil, errors.Trace(err) } service, err := state.Service(unit.ServiceTag()) if err != nil { return nil, errors.Trace(err) } ownerTag, err := service.OwnerTag() if err != nil { return nil, errors.Trace(err) } machineTag, err := unit.AssignedMachine() if err != nil { return nil, errors.Trace(err) } environment, err := state.Environment() if err != nil { return nil, errors.Trace(err) } return &factory{ unit: unit, state: state, tracker: tracker, paths: paths, envUUID: environment.UUID(), envName: environment.Name(), machineTag: machineTag, ownerTag: ownerTag, getRelationInfos: getRelationInfos, relationCaches: map[int]*RelationCache{}, storage: storage, rand: rand.New(rand.NewSource(time.Now().Unix())), }, nil }
// NewRelations returns a new Relations instance. func NewRelations(st *uniter.State, tag names.UnitTag, charmDir, relationsDir string, abort <-chan struct{}) (Relations, error) { unit, err := st.Unit(tag) if err != nil { return nil, errors.Trace(err) } r := &relations{ st: st, unit: unit, charmDir: charmDir, relationsDir: relationsDir, relationers: make(map[int]*Relationer), abort: abort, } if err := r.init(); err != nil { return nil, errors.Trace(err) } return r, nil }
func newRelations(st *uniter.State, tag names.UnitTag, paths Paths, abort <-chan struct{}) (*relations, error) { unit, err := st.Unit(tag) if err != nil { return nil, errors.Trace(err) } r := &relations{ st: st, unit: unit, charmDir: paths.State.CharmDir, relationsDir: paths.State.RelationsDir, relationers: make(map[int]*Relationer), relationHooks: make(chan hook.Info), abort: abort, } if err := r.init(); err != nil { return nil, errors.Trace(err) } return r, nil }