-
Notifications
You must be signed in to change notification settings - Fork 31
/
cluster.go
126 lines (102 loc) · 3.28 KB
/
cluster.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
// Copyright 2019 Netflix, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package p2plab
import (
"context"
"github.com/Netflix/p2plab/metadata"
)
// ClusterAPI defines API for cluster operations.
type ClusterAPI interface {
// Create deploys a cluster.
Create(ctx context.Context, name string, opts ...CreateClusterOption) (id string, err error)
// Get returns a cluster.
Get(ctx context.Context, name string) (Cluster, error)
// Label adds/removes labels to/from clusters.
Label(ctx context.Context, names, adds, removes []string) ([]Cluster, error)
// List returns available clusters.
List(ctx context.Context, opts ...ListOption) ([]Cluster, error)
// Remove destroys clusters permanently.
Remove(ctx context.Context, names ...string) error
}
// Cluster is a group of instances connected in a p2p network. They can be
// provisioned by developers, or CI. Clusters may span multiple regions and
// have heterogeneous nodes.
type Cluster interface {
Labeled
Metadata() metadata.Cluster
// Update updates nodes in a cluster matching the list options with the given
// peer definition.
Update(ctx context.Context, pdef metadata.PeerDefinition, opts ...ListOption) ([]Node, error)
}
// CreateClusterOption is an option to modify create cluster settings.
type CreateClusterOption func(*CreateClusterSettings) error
// CreateClusterSettings specify cluster properties for creation.
type CreateClusterSettings struct {
Definition string
Size int
InstanceType string
Region string
ClusterDefinition metadata.ClusterDefinition
}
func WithClusterDefinition(definition string) CreateClusterOption {
return func(s *CreateClusterSettings) error {
s.Definition = definition
return nil
}
}
func WithClusterSize(size int) CreateClusterOption {
return func(s *CreateClusterSettings) error {
s.Size = size
return nil
}
}
func WithClusterInstanceType(instanceType string) CreateClusterOption {
return func(s *CreateClusterSettings) error {
s.InstanceType = instanceType
return nil
}
}
func WithClusterRegion(region string) CreateClusterOption {
return func(s *CreateClusterSettings) error {
s.Region = region
return nil
}
}
type ListOption func(*ListSettings) error
type ListSettings struct {
Query string
}
func WithQuery(q string) ListOption {
return func(s *ListSettings) error {
s.Query = q
return nil
}
}
type QueryOption func(*QuerySettings) error
type QuerySettings struct {
AddLabels []string
RemoveLabels []string
}
func WithAddLabels(labels ...string) QueryOption {
return func(s *QuerySettings) error {
s.AddLabels = append(s.AddLabels, labels...)
return nil
}
}
func WithRemoveLabels(labels ...string) QueryOption {
return func(s *QuerySettings) error {
s.RemoveLabels = append(s.RemoveLabels, labels...)
return nil
}
}