~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/jujud/agent/engine/apiagent.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package engine
 
5
 
 
6
import (
 
7
        "github.com/juju/juju/agent"
 
8
        "github.com/juju/juju/api/base"
 
9
        "github.com/juju/juju/worker"
 
10
        "github.com/juju/juju/worker/dependency"
 
11
)
 
12
 
 
13
// Many manifolds completely depend on an agent and an API connection; this
 
14
// type configures them.
 
15
type AgentApiManifoldConfig struct {
 
16
        AgentName     string
 
17
        APICallerName string
 
18
}
 
19
 
 
20
// AgentApiStartFunc encapsulates the behaviour that varies among AgentApiManifolds.
 
21
type AgentApiStartFunc func(agent.Agent, base.APICaller) (worker.Worker, error)
 
22
 
 
23
// AgentApiManifold returns a dependency.Manifold that calls the supplied start
 
24
// func with the API and agent resources defined in the config (once those
 
25
// resources are present).
 
26
func AgentApiManifold(config AgentApiManifoldConfig, start AgentApiStartFunc) dependency.Manifold {
 
27
        return dependency.Manifold{
 
28
                Inputs: []string{
 
29
                        config.AgentName,
 
30
                        config.APICallerName,
 
31
                },
 
32
                Start: func(context dependency.Context) (worker.Worker, error) {
 
33
                        var agent agent.Agent
 
34
                        if err := context.Get(config.AgentName, &agent); err != nil {
 
35
                                return nil, err
 
36
                        }
 
37
                        var apiCaller base.APICaller
 
38
                        if err := context.Get(config.APICallerName, &apiCaller); err != nil {
 
39
                                return nil, err
 
40
                        }
 
41
                        return start(agent, apiCaller)
 
42
                },
 
43
        }
 
44
}