-
Notifications
You must be signed in to change notification settings - Fork 71
/
deployment_mode.go
133 lines (114 loc) · 3.82 KB
/
deployment_mode.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
131
132
133
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1
import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
// DeploymentMode specifies the type of ArangoDB deployment to create.
type DeploymentMode string
const (
// DeploymentModeSingle yields a single server
DeploymentModeSingle DeploymentMode = "Single"
// DeploymentModeActiveFailover yields an agency and a active-failover server pair
DeploymentModeActiveFailover DeploymentMode = "ActiveFailover"
// DeploymentModeCluster yields an full cluster (agency, dbservers & coordinators)
DeploymentModeCluster DeploymentMode = "Cluster"
)
// Validate the mode.
// Return errors when validation fails, nil on success.
func (m DeploymentMode) Validate() error {
switch m {
case DeploymentModeSingle, DeploymentModeActiveFailover, DeploymentModeCluster:
return nil
default:
return errors.WithStack(errors.Wrapf(ValidationError, "Unknown deployment mode: '%s'", string(m)))
}
}
// Get mode or default value
func (m *DeploymentMode) Get() DeploymentMode {
if m == nil {
return DeploymentModeCluster
}
return *m
}
// String return string from mode
func (m *DeploymentMode) String() string {
return string(m.Get())
}
// Nww return pointer to mode
func (m DeploymentMode) New() *DeploymentMode {
return &m
}
// HasSingleServers returns true when the given mode is "Single" or "ActiveFailover".
func (m DeploymentMode) HasSingleServers() bool {
return m == DeploymentModeSingle || m == DeploymentModeActiveFailover
}
// HasAgents returns true when the given mode is "ActiveFailover" or "Cluster".
func (m DeploymentMode) HasAgents() bool {
return m == DeploymentModeActiveFailover || m == DeploymentModeCluster
}
// HasDBServers returns true when the given mode is "Cluster".
func (m DeploymentMode) HasDBServers() bool {
return m == DeploymentModeCluster
}
// HasCoordinators returns true when the given mode is "Cluster".
func (m DeploymentMode) HasCoordinators() bool {
return m == DeploymentModeCluster
}
// SupportsSync returns true when the given mode supports dc2dc replication.
func (m DeploymentMode) SupportsSync() bool {
return m == DeploymentModeCluster
}
// IsCluster returns true if the deployment mode is cluster
func (m DeploymentMode) IsCluster() bool {
return m == DeploymentModeCluster
}
// ServingGroup returns mode serving group
func (m DeploymentMode) ServingGroup() ServerGroup {
switch m {
case DeploymentModeCluster:
return ServerGroupCoordinators
case DeploymentModeSingle, DeploymentModeActiveFailover:
return ServerGroupSingle
default:
return ServerGroupUnknown
}
}
// NewMode returns a reference to a string with given value.
func NewMode(input DeploymentMode) *DeploymentMode {
return &input
}
// NewModeOrNil returns nil if input is nil, otherwise returns a clone of the given value.
func NewModeOrNil(input *DeploymentMode) *DeploymentMode {
if input == nil {
return nil
}
return NewMode(*input)
}
// ModeOrDefault returns the default value (or empty string) if input is nil, otherwise returns the referenced value.
func ModeOrDefault(input *DeploymentMode, defaultValue ...DeploymentMode) DeploymentMode {
if input == nil {
if len(defaultValue) > 0 {
return defaultValue[0]
}
return ""
}
return *input
}