-
Notifications
You must be signed in to change notification settings - Fork 668
/
interface.go
105 lines (88 loc) · 2.71 KB
/
interface.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
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package crud
import (
"sync"
"time"
)
// Common interfaces
// Gets the current BareMetal Resource
type ResourceFetcher interface {
// Get should update the s.Resource, and is used by crud.ReadResource() to populate s.D
// Get() may expect s.D.Id() to be set, but not s.Resource, or anything else in s.D
Get() error
}
// ResourceVoider may set its ResourceData state to empty.
type ResourceVoider interface {
// VoidState sets ResourceData ID to "". To be called when
// the resource is gone.
VoidState()
}
// ResourceDataWriter populates ResourceData state from the current
// BareMetal resource
type ResourceDataWriter interface {
ResourceVoider
// SetData populates ResourceData state from current
// BareMetal resource
SetData()
}
// CRUD standard interfaces
// ResourceCreator may create a BareMetal resource and populate into
// ResourceData state by using CreateResource()
type ResourceCreator interface {
ResourceDataWriter
// ID identifies the resource, or a work request to create the resource.
ID() string
Create() error
}
// ResourceReader get BareMetal Resource and updated ResourceData
type ResourceReader interface {
ResourceFetcher
ResourceDataWriter
}
// Updates a BareMetal entity to match ResourceData
type ResourceUpdater interface {
ResourceDataWriter
Update() error
}
// Deletes a BareMetal entity
type ResourceDeleter interface {
ResourceVoider
// ID identifies the resource, or a work request to create the resource.
ID() string
Delete() error
}
// Some resources in the oracle API are removed asynchronously, so even
// after they claim to be gone, other dependencies haven't been notified
// of that fact. This facility allows us to add an artificial delay for
// resources that need a little time to let the oracle API backend catch
// up with reality.
type ExtraWaitPostCreateDelete interface {
ExtraWaitPostCreateDelete() time.Duration
}
type StatefulResource interface {
ResourceReader
State() string
setState(StatefulResource) error
}
type StatefullyCreatedResource interface {
StatefulResource
CreatedPending() []string
CreatedTarget() []string
}
type StatefullyUpdatedResource interface {
StatefulResource
UpdatedPending() []string
UpdatedTarget() []string
}
type StatefullyDeletedResource interface {
StatefulResource
DeletedPending() []string
DeletedTarget() []string
}
// This provides a mechanism for synchronizing CRUD operations from different resources
// that may concurrently modify the same resource. Implementing these interfaces will
// cause the Create/Update/Delete operations to wait on the lock before starting those
// operations.
type SynchronizedResource interface {
GetMutex() *sync.Mutex
}