-
Notifications
You must be signed in to change notification settings - Fork 786
/
types.go
122 lines (104 loc) · 4.53 KB
/
types.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
// The MIT License (MIT)
//
// Copyright (c) 2017-2020 Uber Technologies Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination mocks.go -self_package github.com/uber/cadence/common/reconciliation/invariant
//go:generate enumer -type=Collection
package invariant
import "context"
const (
// CheckResultTypeFailed indicates a failure occurred while attempting to run check
CheckResultTypeFailed CheckResultType = "failed"
// CheckResultTypeCorrupted indicates check successfully ran and detected a corruption
CheckResultTypeCorrupted CheckResultType = "corrupted"
// CheckResultTypeHealthy indicates check successfully ran and detected no corruption
CheckResultTypeHealthy CheckResultType = "healthy"
// FixResultTypeSkipped indicates that fix skipped execution
FixResultTypeSkipped FixResultType = "skipped"
// FixResultTypeFixed indicates that fix successfully fixed an execution
FixResultTypeFixed FixResultType = "fixed"
// FixResultTypeFailed indicates that fix attempted to fix an execution but failed to do so
FixResultTypeFailed FixResultType = "failed"
// HistoryExists asserts that history must exist if concrete execution exists
HistoryExists Name = "history_exists"
// OpenCurrentExecution asserts that an open concrete execution must have a valid current execution
OpenCurrentExecution Name = "open_current_execution"
// ConcreteExecutionExists asserts that an open current execution must have a valid concrete execution
ConcreteExecutionExists Name = "concrete_execution_exists"
// CollectionMutableState is the collection of invariants relating to mutable state
CollectionMutableState Collection = 0
// CollectionHistory is the collection of invariants relating to history
CollectionHistory Collection = 1
)
type (
// Name is the name of an invariant
Name string
// Collection is a type which indicates a collection of invariants
Collection int
// CheckResultType is the result type of running an invariant check
CheckResultType string
// FixResultType is the result type of running an invariant fix
FixResultType string
)
// Invariant represents an invariant of a single execution.
// It can be used to check that the execution satisfies the invariant.
// It can also be used to fix the invariant for an execution.
type Invariant interface {
Check(context.Context, interface{}) CheckResult
Fix(context.Context, interface{}) FixResult
Name() Name
}
// Manager represents a manager of several invariants.
// It can be used to run a group of invariant checks or fixes.
type Manager interface {
RunChecks(context.Context, interface{}) ManagerCheckResult
RunFixes(context.Context, interface{}) ManagerFixResult
}
// ManagerCheckResult is the result of running a list of checks
type ManagerCheckResult struct {
CheckResultType CheckResultType
DeterminingInvariantType *Name
CheckResults []CheckResult
}
// ManagerFixResult is the result of running a list of fixes
type ManagerFixResult struct {
FixResultType FixResultType
DeterminingInvariantName *Name
FixResults []FixResult
}
// CheckResult is the result of running Check.
type CheckResult struct {
CheckResultType CheckResultType
InvariantName Name
Info string
InfoDetails string
}
// FixResult is the result of running Fix.
type FixResult struct {
FixResultType FixResultType
InvariantName Name
CheckResult CheckResult
Info string
InfoDetails string
}
// NamePtr returns a pointer to Name
func NamePtr(t Name) *Name {
return &t
}