1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
9
"github.com/juju/juju/api/base"
12
type orchestrator struct {
13
*LogForwarder // For now its just a single forwarder.
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.
22
// LogForwardConfig is the API used to access log forward config.
23
LogForwardConfig LogForwardConfig
25
// Caller is the API caller that will be used.
28
// Sinks are the named functions that open the underlying log sinks
29
// to which log records will be forwarded.
32
// OpenLogStream is the function that will be used to for the
34
OpenLogStream LogStreamFn
36
// OpenLogForwarder opens each log forwarder that will be used.
37
OpenLogForwarder func(OpenLogForwarderArgs) (*LogForwarder, error)
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 {
46
if len(args.Sinks) > 1 {
47
return nil, errors.Errorf("multiple log forwarding targets not supported (yet)")
49
lf, err := args.OpenLogForwarder(OpenLogForwarderArgs{
51
ControllerUUID: args.ControllerUUID,
52
LogForwardConfig: args.LogForwardConfig,
54
Name: args.Sinks[0].Name,
55
OpenSink: args.Sinks[0].OpenFn,
56
OpenLogStream: args.OpenLogStream,
58
return &orchestrator{lf}, errors.Annotate(err, "opening log forwarder")