-
Notifications
You must be signed in to change notification settings - Fork 0
/
distributedDomain.go
231 lines (203 loc) · 8.7 KB
/
distributedDomain.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package connect
import "encoding/json"
// HomeServer - User's home server in a distributed domain.
type HomeServer struct {
Id KId `json:"id"` // server's id
Name string `json:"name"` // server's Internet hostname
}
type HomeServerList []HomeServer
type ClusterErrorType string
const (
clSuccess ClusterErrorType = "clSuccess"
clError ClusterErrorType = "clError" // Generic cluster error, see ClusterError.errorMessage for details
clSelfConnectError ClusterErrorType = "clSelfConnectError" // The master cannot be the same as slave
clConnectToSlaveError ClusterErrorType = "clConnectToSlaveError" // ServerConnection to slave is not allowed
clInaccessibleHost ClusterErrorType = "clInaccessibleHost" // Cannot connect to the specified host
clInvalidUserOrPassword ClusterErrorType = "clInvalidUserOrPassword" // User name or password are invalid or has insufficient rights
clIncorrectClusterVersion ClusterErrorType = "clIncorrectClusterVersion" // Remote server has incompatible implementation of cluster services
clDataConflict ClusterErrorType = "clDataConflict" // There are multiple resources/aliases or mailing lists with the same name, server cannot be connected to cluster
clDirServiceRemoteEmpty ClusterErrorType = "clDirServiceRemoteEmpty" // Specified distributed domain has no Directory Service configured on remote distributed domain host
clDirServiceLocalEmpty ClusterErrorType = "clDirServiceLocalEmpty" // Specified distributed domain has no Directory Service configured on local distributed domain host
clDirServiceDifferent ClusterErrorType = "clDirServiceDifferent" // Specified distributed domain has different Directory Service configured on local and remote distributed domain host
)
type ClusterConflictTarget string
const (
clResource ClusterConflictTarget = "clResource"
clAlias ClusterConflictTarget = "clAlias"
clMailingList ClusterConflictTarget = "clMailingList"
clDomainAlias ClusterConflictTarget = "clDomainAlias"
clDomain ClusterConflictTarget = "clDomain"
)
type ClusterConflict struct {
Type ClusterConflictTarget `json:"type"`
Name string `json:"name"`
Domain string `json:"domain"`
HomeServer string `json:"homeServer"`
}
type ClusterConflictList []ClusterConflict
type ClusterError struct {
Type ClusterErrorType `json:"type"`
ErrorMessage LocalizableMessage `json:"errorMessage"` // is assigned if type is clError
ConflictList ClusterConflictList `json:"conflictList"` // List of Resources/Aliases/MLists which are already defined in cluster. The conflictList is empty if type is different from dataConflict.
}
// ClusterRole - Role of the server in cluster
type ClusterRole string
const (
clStandalone ClusterRole = "clStandalone"
clMaster ClusterRole = "clMaster"
clSlave ClusterRole = "clSlave"
)
type ClusterStatus string
const (
csReady ClusterStatus = "csReady" // Server in claster work well.
csError ClusterStatus = "csError" // Server in claster don't work with some error, see errorMessages for details
)
type LocalizableMessageList []LocalizableMessage
type ClusterDomainStatus string
const (
csDomainNotChecked ClusterDomainStatus = "csDomainNotChecked"
csDomainExists ClusterDomainStatus = "csDomainExists"
csDomainDoesNotExist ClusterDomainStatus = "csDomainDoesNotExist"
)
type ClusterServer struct {
Hostname string `json:"hostname"`
IsPrimary bool `json:"isPrimary"`
IsLocal bool `json:"isLocal"`
Status ClusterStatus `json:"status"`
ErrorMessages LocalizableMessageList `json:"errorMessages"` // is assigned if type is clError
DomainStatus ClusterDomainStatus `json:"domainStatus"`
}
type ClusterAuthentication struct {
HostName string `json:"hostName"`
AdminUser string `json:"adminUser"`
Password string `json:"password"`
}
type ClusterServerList []ClusterServer
// DistributedDomainConnect - Connect server to cluster as slave.
// Parameters
// hostName - name of the master server
// adminUser - username of administrator on the master server
// password - administrator's password
// Return
// result - if ClusterErrorType is not clSuccess, error argument contains additional error info
func (s *ServerConnection) DistributedDomainConnect(hostName string, adminUser string, password string) (*ClusterError, error) {
params := struct {
HostName string `json:"hostName"`
AdminUser string `json:"adminUser"`
Password string `json:"password"`
}{hostName, adminUser, password}
data, err := s.CallRaw("DistributedDomain.connect", params)
if err != nil {
return nil, err
}
result := struct {
Result struct {
Result ClusterError `json:"result"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &result)
return &result.Result.Result, err
}
// DistributedDomainCopy - Copy domain from the master server.
// Parameters
// domainName - name of the domain on the master server that you want to copy. Name can be obtained by using method getDomainsFromServer.
func (s *ServerConnection) DistributedDomainCopy(domainName string) error {
params := struct {
DomainName string `json:"domainName"`
}{domainName}
_, err := s.CallRaw("DistributedDomain.copy", params)
return err
}
// DistributedDomainDisconnect - Disconnect server from the cluster.
func (s *ServerConnection) DistributedDomainDisconnect() error {
_, err := s.CallRaw("DistributedDomain.disconnect", nil)
return err
}
// DistributedDomainGetDistributable - Retrieve domains, which can be distributed, from the master server as a standalone server.
// Parameters
// connected - true means the caller is connected to cluster
// authentication - Structure with a credential. Credential will be used when connected is false.
// Return
// domainNames - List of domains which can be distributed (they have a directory service set).
func (s *ServerConnection) DistributedDomainGetDistributable(authentication ClusterAuthentication, connected bool) (StringList, error) {
params := struct {
Authentication ClusterAuthentication `json:"authentication"`
Connected bool `json:"connected"`
}{authentication, connected}
data, err := s.CallRaw("DistributedDomain.getDistributable", params)
if err != nil {
return nil, err
}
domainNames := struct {
Result struct {
DomainNames StringList `json:"domainNames"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &domainNames)
return domainNames.Result.DomainNames, err
}
// DistributedDomainGetRole - Return server role in the cluster.
func (s *ServerConnection) DistributedDomainGetRole() (*ClusterRole, bool, error) {
data, err := s.CallRaw("DistributedDomain.getRole", nil)
if err != nil {
return nil, false, err
}
role := struct {
Result struct {
Role ClusterRole `json:"role"`
IsMultiServer bool `json:"isMultiServer"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &role)
return &role.Result.Role, role.Result.IsMultiServer, err
}
// DistributedDomainGetServerList - Retrieve information about servers in the cluster.
// Return
// servers - List of all servers in cluster.
func (s *ServerConnection) DistributedDomainGetServerList() (ClusterServerList, error) {
data, err := s.CallRaw("DistributedDomain.getServerList", nil)
if err != nil {
return nil, err
}
servers := struct {
Result struct {
Servers ClusterServerList `json:"servers"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &servers)
return servers.Result.Servers, err
}
// DistributedDomainGetHomeServerList - Retrieve information about servers in the cluster.
// Return
// servers - List of all servers in cluster.
func (s *ServerConnection) DistributedDomainGetHomeServerList() (HomeServerList, error) {
data, err := s.CallRaw("DistributedDomain.getHomeServerList", nil)
if err != nil {
return nil, err
}
servers := struct {
Result struct {
Servers HomeServerList `json:"servers"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &servers)
return servers.Result.Servers, err
}
// DistributedDomainGetStatus - Notes: This method fails if caller has not admin rights; This method fails if there is no cluster
// Return
// isInCluster true if server is not standalone
// isError status of error in cluster
func (s *ServerConnection) DistributedDomainGetStatus() (bool, bool, error) {
data, err := s.CallRaw("DistributedDomain.getStatus", nil)
if err != nil {
return false, false, err
}
isInCluster := struct {
Result struct {
IsInCluster bool `json:"isInCluster"`
IsError bool `json:"isError"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &isInCluster)
return isInCluster.Result.IsInCluster, isInCluster.Result.IsError, err
}