/
status_history.go
130 lines (115 loc) · 4.33 KB
/
status_history.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package status
import (
"time"
"github.com/juju/collections/set"
"github.com/juju/errors"
)
// StatusHistoryFilter holds arguments that can be use to filter a status history backlog.
type StatusHistoryFilter struct {
// Size indicates how many results are expected at most.
Size int
// FromDate indicates the earliest date from which logs are expected.
FromDate *time.Time
// Delta indicates the age of the oldest log expected.
Delta *time.Duration
// Exclude indicates the status messages that should be excluded
// from the returned result.
Exclude set.Strings
}
// Validate checks that the minimum requirements of a StatusHistoryFilter are met.
func (f *StatusHistoryFilter) Validate() error {
s := f.Size > 0
t := f.FromDate != nil
d := f.Delta != nil
switch {
case !(s || t || d):
return errors.NotValidf("missing filter parameters")
case s && t:
return errors.NotValidf("Size and Date together")
case s && d:
return errors.NotValidf("Size and Delta together")
case t && d:
return errors.NotValidf("Date and Delta together")
}
return nil
}
// StatusHistoryGetter instances can fetch their status history.
type StatusHistoryGetter interface {
StatusHistory(filter StatusHistoryFilter) ([]StatusInfo, error)
}
// InstanceStatusHistoryGetter instances can fetch their instance status history.
type InstanceStatusHistoryGetter interface {
InstanceStatusHistory(filter StatusHistoryFilter) ([]StatusInfo, error)
}
// DetailedStatus holds status info about a machine or unit agent.
type DetailedStatus struct {
Status Status
Info string
Data map[string]interface{}
Since *time.Time
Kind HistoryKind
}
// History holds many DetailedStatus,
type History []DetailedStatus
// HistoryKind represents the possible types of
// status history entries.
type HistoryKind string
// IMPORTANT DEV NOTE: when changing this HistoryKind list in any way, these may need to be revised:
//
// * HistoryKind.Valid()
// * AllHistoryKind()
// * command help for 'show-status-log' describing these kinds.
const (
// KindModel represents the model itself.
KindModel HistoryKind = "model"
// KindApplication represents an entry for an application.
KindApplication HistoryKind = "application"
// KindSAAS represents an entry for a saas application.
KindSAAS HistoryKind = "saas"
// KindUnit represents agent and workload combined.
KindUnit HistoryKind = "unit"
// KindUnitAgent represent a unit agent status history entry.
KindUnitAgent HistoryKind = "juju-unit"
// KindWorkload represents a charm workload status history entry.
KindWorkload HistoryKind = "workload"
// KindMachineInstance represents an entry for a machine instance.
KindMachineInstance HistoryKind = "machine"
// KindMachine represents an entry for a machine agent.
KindMachine HistoryKind = "juju-machine"
// KindContainerInstance represents an entry for a container instance.
KindContainerInstance HistoryKind = "container"
// KindContainer represents an entry for a container agent.
KindContainer HistoryKind = "juju-container"
)
// String returns a string representation of the HistoryKind.
func (k HistoryKind) String() string {
return string(k)
}
// Valid will return true if the current kind is a valid one.
func (k HistoryKind) Valid() bool {
switch k {
case KindModel, KindUnit, KindUnitAgent, KindWorkload,
KindApplication, KindSAAS,
KindMachineInstance, KindMachine,
KindContainerInstance, KindContainer:
return true
}
return false
}
// AllHistoryKind will return all valid HistoryKinds.
func AllHistoryKind() map[HistoryKind]string {
return map[HistoryKind]string{
KindModel: "statuses for the model itself",
KindApplication: "statuses for the specified application",
KindSAAS: "statuses for the specified SAAS application",
KindUnit: "statuses for specified unit and its workload",
KindUnitAgent: "statuses from the agent that is managing a unit",
KindWorkload: "statuses for unit's workload",
KindMachineInstance: "statuses that occur due to provisioning of a machine",
KindMachine: "status of the agent that is managing a machine",
KindContainerInstance: "statuses from the agent that is managing containers",
KindContainer: "statuses from the containers only and not their host machines",
}
}