~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/logforwarder/orchestrator.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 logforwarder
 
5
 
 
6
import (
 
7
        "github.com/juju/errors"
 
8
 
 
9
        "github.com/juju/juju/api/base"
 
10
)
 
11
 
 
12
type orchestrator struct {
 
13
        *LogForwarder // For now its just a single forwarder.
 
14
}
 
15
 
 
16
// OrchestratorArgs holds the info needed to open a log forwarding
 
17
// orchestration worker.
 
18
type OrchestratorArgs struct {
 
19
        // ControllerUUID is the UUID of the controller for which we will forward logs.
 
20
        ControllerUUID string
 
21
 
 
22
        // LogForwardConfig is the API used to access log forward config.
 
23
        LogForwardConfig LogForwardConfig
 
24
 
 
25
        // Caller is the API caller that will be used.
 
26
        Caller base.APICaller
 
27
 
 
28
        // Sinks are the named functions that open the underlying log sinks
 
29
        // to which log records will be forwarded.
 
30
        Sinks []LogSinkSpec
 
31
 
 
32
        // OpenLogStream is the function that will be used to for the
 
33
        // log stream.
 
34
        OpenLogStream LogStreamFn
 
35
 
 
36
        // OpenLogForwarder opens each log forwarder that will be used.
 
37
        OpenLogForwarder func(OpenLogForwarderArgs) (*LogForwarder, error)
 
38
}
 
39
 
 
40
func newOrchestratorForController(args OrchestratorArgs) (*orchestrator, error) {
 
41
        // For now we work with only 1 forwarder. Later we can have a proper
 
42
        // orchestrator that spawns a sub-worker for each log sink.
 
43
        if len(args.Sinks) == 0 {
 
44
                return nil, nil
 
45
        }
 
46
        if len(args.Sinks) > 1 {
 
47
                return nil, errors.Errorf("multiple log forwarding targets not supported (yet)")
 
48
        }
 
49
        lf, err := args.OpenLogForwarder(OpenLogForwarderArgs{
 
50
                AllModels:        true,
 
51
                ControllerUUID:   args.ControllerUUID,
 
52
                LogForwardConfig: args.LogForwardConfig,
 
53
                Caller:           args.Caller,
 
54
                Name:             args.Sinks[0].Name,
 
55
                OpenSink:         args.Sinks[0].OpenFn,
 
56
                OpenLogStream:    args.OpenLogStream,
 
57
        })
 
58
        return &orchestrator{lf}, errors.Annotate(err, "opening log forwarder")
 
59
}