This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 302
/
interface.go
107 lines (89 loc) · 4.02 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
106
107
package registry
import (
"time"
"github.com/coreos/fleet/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
"github.com/coreos/fleet/job"
"github.com/coreos/fleet/machine"
"github.com/coreos/fleet/unit"
)
type Registry interface {
ClearUnitHeartbeat(name string)
CreateUnit(*job.Unit) error
DestroyUnit(string) error
UnitHeartbeat(name, machID string, ttl time.Duration) error
Machines() ([]machine.MachineState, error)
RemoveMachineState(machID string) error
RemoveUnitState(jobName string) error
SaveUnitState(jobName string, unitState *unit.UnitState, ttl time.Duration)
ScheduleUnit(name, machID string) error
SetUnitTargetState(name string, state job.JobState) error
SetMachineState(ms machine.MachineState, ttl time.Duration) (uint64, error)
UnscheduleUnit(name, machID string) error
UnitRegistry
}
type UnitRegistry interface {
Schedule() ([]job.ScheduledUnit, error)
ScheduledUnit(name string) (*job.ScheduledUnit, error)
Unit(name string) (*job.Unit, error)
Units() ([]job.Unit, error)
UnitStates() ([]*unit.UnitState, error)
}
type ClusterRegistry interface {
LatestDaemonVersion() (*semver.Version, error)
// EngineVersion returns the current version of the cluster. If the
// cluster does not yet have a version, zero will be returned. If
// any error occurs, an error object will be returned. In this case,
// the returned version number should be ignored.
EngineVersion() (int, error)
// UpdateEngineVersion attempts to compare-and-swap the cluster version
// from one value to another. Any failures in this process will be
// indicated by the returned error object. A nil value will be returned
// on success.
UpdateEngineVersion(from, to int) error
}
type LeaseRegistry interface {
// GetLease fetches a Lease only if it exists. If it does not
// exist, a nil Lease will be returned. Any other failures
// result in non-nil error and nil Lease objects.
GetLease(name string) (Lease, error)
// AcquireLease acquires a named lease only if the lease is not
// currently held. If a Lease cannot be acquired, a nil Lease
// object is returned. An error is returned only if there is a
// failure communicating with the Registry.
AcquireLease(name, machID string, ver int, period time.Duration) (Lease, error)
// StealLease attempts to replace the lessee of the Lease identified
// by the provided name and index with a new lessee. This function
// will fail if the named Lease has progressed past the given index.
StealLease(name, machID string, ver int, period time.Duration, idx uint64) (Lease, error)
}
// Lease proxies to an auto-expiring lease stored in a LeaseRegistry.
// The creator of a Lease must repeatedly call Renew to keep their lease
// from expiring.
type Lease interface {
// Renew attempts to extend the Lease TTL to the provided duration.
// The operation will succeed only if the Lease has not changed in
// the LeaseRegistry since it was last renewed or first acquired.
// An error is returned if the Lease has already expired, or if the
// operation fails for any other reason.
Renew(time.Duration) error
// Release relinquishes the ownership of a Lease back to the Registry.
// After calling Release, the Lease object should be discarded. An
// error is returned if the Lease has already expired, or if the
// operation fails for any other reason.
Release() error
// MachineID returns the ID of the Machine that holds this Lease. This
// value must be considered a cached value as it is not guaranteed to
// be correct.
MachineID() string
// Version returns the current version at which the lesse is operating.
// This value has the same correctness guarantees as MachineID.
// It is up to the caller to determine what this Version means.
Version() int
// Index exposes the relative time at which the Lease was created or
// renewed. For example, this could be implemented as the ModifiedIndex
// field of a node in etcd.
Index() uint64
// TimeRemaining represents the amount of time left on the Lease when
// it was fetched from the LeaseRegistry.
TimeRemaining() time.Duration
}