forked from juju/juju
/
config.go
91 lines (85 loc) · 2.48 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package storageprovisioner
import (
"github.com/juju/clock"
"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/DavinZhang/juju/storage"
"github.com/DavinZhang/juju/worker/common"
)
// Logger represents the methods used by the worker to log details.
type Logger interface {
Tracef(string, ...interface{})
Debugf(string, ...interface{})
Warningf(string, ...interface{})
Errorf(string, ...interface{})
}
// Config holds configuration and dependencies for a storageprovisioner worker.
type Config struct {
Model names.ModelTag
Scope names.Tag
StorageDir string
Applications ApplicationWatcher
Volumes VolumeAccessor
Filesystems FilesystemAccessor
Life LifecycleManager
Registry storage.ProviderRegistry
Machines MachineAccessor
Status StatusSetter
Clock clock.Clock
Logger Logger
CloudCallContextFunc common.CloudCallContextFunc
}
// Validate returns an error if the config cannot be relied upon to start a worker.
func (config Config) Validate() error {
switch config.Scope.(type) {
case nil:
return errors.NotValidf("nil Scope")
case names.ModelTag:
if config.StorageDir != "" {
return errors.NotValidf("environ Scope with non-empty StorageDir")
}
case names.MachineTag:
if config.StorageDir == "" {
return errors.NotValidf("machine Scope with empty StorageDir")
}
if config.Machines == nil {
return errors.NotValidf("nil Machines")
}
case names.ApplicationTag:
if config.StorageDir != "" {
return errors.NotValidf("application Scope with StorageDir")
}
if config.Applications == nil {
return errors.NotValidf("nil Applications")
}
default:
return errors.NotValidf("%T Scope", config.Scope)
}
if config.Volumes == nil {
return errors.NotValidf("nil Volumes")
}
if config.Filesystems == nil {
return errors.NotValidf("nil Filesystems")
}
if config.Life == nil {
return errors.NotValidf("nil Life")
}
if config.Registry == nil {
return errors.NotValidf("nil Registry")
}
if config.Status == nil {
return errors.NotValidf("nil Status")
}
if config.Clock == nil {
return errors.NotValidf("nil Clock")
}
if config.Logger == nil {
return errors.NotValidf("nil Logger")
}
if config.CloudCallContextFunc == nil {
return errors.NotValidf("nil CloudCallContextFunc")
}
return nil
}