func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) { cfg := a.CurrentConfig() // Grab the tag and ensure that it's for a machine. tag, ok := cfg.Tag().(names.MachineTag) if !ok { return nil, errors.New("this manifold may only be used inside a machine agent") } // Get the machine agent's jobs. // TODO(fwereade): this functionality should be on the // deployer facade instead. agentFacade := apiagent.NewState(apiCaller) entity, err := agentFacade.Entity(tag) if err != nil { return nil, err } var isModelManager bool for _, job := range entity.Jobs() { if job == multiwatcher.JobManageModel { isModelManager = true break } } if !isModelManager { return nil, dependency.ErrMissing } return NewResumer(apiresumer.NewAPI(apiCaller)), nil }
func (s *ResumerSuite) TestResumeTransactionsFailure(c *gc.C) { var callCount int apiCaller := apitesting.APICallerFunc( func(_ string, _ int, _, _ string, _, _ interface{}) error { callCount++ return errors.New("boom!") }, ) st := resumer.NewAPI(apiCaller) err := st.ResumeTransactions() c.Check(err, gc.ErrorMatches, "boom!") c.Check(callCount, gc.Equals, 1) }
func (s *ResumerSuite) TestResumeTransactionsSuccess(c *gc.C) { var callCount int apiCaller := apitesting.APICallerFunc( func(objType string, version int, id, request string, args, results interface{}) error { c.Check(objType, gc.Equals, "Resumer") // Since we're not logging in and getting the supported // facades and their versions, the client will always send // version 0. c.Check(version, gc.Equals, 0) c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "ResumeTransactions") c.Check(args, gc.IsNil) c.Check(results, gc.IsNil) callCount++ return nil }, ) st := resumer.NewAPI(apiCaller) err := st.ResumeTransactions() c.Check(err, jc.ErrorIsNil) c.Check(callCount, gc.Equals, 1) }
// Resumer returns a version of the state that provides functionality // required by the resumer worker. func (st *State) Resumer() *resumer.API { return resumer.NewAPI(st) }
// NewFacade returns a useful live implementation for // ManifoldConfig.NewFacade. func NewFacade(apiCaller base.APICaller) (Facade, error) { return resumer.NewAPI(apiCaller), nil }