Skip to content

Commit d4824ef

Browse files
authored
Admin Cluster API support (#604)
1 parent 83208ee commit d4824ef

14 files changed

+797
-97
lines changed

test/database_test.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,15 @@ func TestDatabaseInfo(t *testing.T) {
178178
}
179179
}
180180

181+
// --database.extended-names-databases=true are enabled by default in 3.12
181182
func TestDatabaseNameUnicode(t *testing.T) {
182183
c := createClient(t, nil)
183-
databaseExtendedNamesRequired(t, c)
184+
185+
ctx := context.Background()
186+
EnsureVersion(t, ctx, c).CheckVersion(MinimumVersion("3.12"))
184187

185188
dbName := "\u006E\u0303\u00f1" + GenerateUUID("test-db-unicode")
186189
normalized := norm.NFC.String(dbName)
187-
ctx := context.Background()
188190
_, err := c.CreateDatabase(ctx, dbName, nil)
189191
require.EqualError(t, err, "database name is not properly UTF-8 NFC-normalized")
190192

@@ -251,29 +253,6 @@ func TestCreateDatabaseReplication2(t *testing.T) {
251253
}
252254
}
253255

254-
// databaseExtendedNamesRequired skips test if the version is < 3.9.0 or the ArangoDB has not been launched
255-
// with the option --database.extended-names-databases=true.
256-
func databaseExtendedNamesRequired(t *testing.T, c driver.Client) {
257-
ctx := context.Background()
258-
EnsureVersion(t, ctx, c).CheckVersion(MinimumVersion("3.9.0"))
259-
260-
// If the database can be created with the below name then it means that it excepts unicode names.
261-
dbName := "\u006E\u0303\u00f1"
262-
normalized := norm.NFC.String(dbName)
263-
db, err := c.CreateDatabase(ctx, normalized, nil)
264-
if err == nil {
265-
require.NoErrorf(t, db.Remove(ctx), "failed to remove testing unicode database")
266-
return
267-
}
268-
269-
if driver.IsArangoErrorWithErrorNum(err, driver.ErrArangoDatabaseNameInvalid, driver.ErrArangoIllegalName) {
270-
t.Skipf("ArangoDB is not launched with the option --database.extended-names-databases=true")
271-
}
272-
273-
// Some other error that has not been expected.
274-
require.NoError(t, err)
275-
}
276-
277256
// databaseReplication2Required skips test if the version is < 3.12.0.
278257
// It also skips the test if the ArangoDB has not been launched with the option--database.default-replication-version=2.
279258
func databaseReplication2Required(t *testing.T, c driver.Client) {

v2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- multi_delimiter analyzer support
1818
- Wildcard analyzer support
1919
- Backup API support
20+
- Admin Cluster API support
2021

2122

2223
## [2.0.3](https://github.com/arangodb/go-driver/tree/v2.0.3) (2023-10-31)

v2/arangodb/client_admin.go

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ type ClientAdmin interface {
2828
ClientAdminLog
2929
ClientAdminBackup
3030
ClientAdminLicense
31-
32-
// Health returns the cluster configuration & health.
33-
// It works in cluster or active fail-over mode.
34-
Health(ctx context.Context) (ClusterHealth, error)
31+
ClientAdminCluster
3532

3633
// ServerMode returns the current mode in which the server/cluster is operating.
3734
// This call needs ArangoDB 3.3 and up.
@@ -43,6 +40,40 @@ type ClientAdmin interface {
4340
SetServerMode(ctx context.Context, mode ServerMode) error
4441
}
4542

43+
type ClientAdminCluster interface {
44+
// Health returns the cluster configuration & health. Not available in single server deployments (403 Forbidden).
45+
Health(ctx context.Context) (ClusterHealth, error)
46+
47+
// DatabaseInventory the inventory of the cluster collections (with entire details) from a specific database.
48+
DatabaseInventory(ctx context.Context, dbName string) (DatabaseInventory, error)
49+
50+
// MoveShard moves a single shard of the given collection between `fromServer` and `toServer`.
51+
MoveShard(ctx context.Context, col Collection, shard ShardID, fromServer, toServer ServerID) (string, error)
52+
53+
// CleanOutServer triggers activities to clean out a DBServer.
54+
CleanOutServer(ctx context.Context, serverID ServerID) (string, error)
55+
56+
// ResignServer triggers activities to let a DBServer resign for all shards.
57+
ResignServer(ctx context.Context, serverID ServerID) (string, error)
58+
59+
// NumberOfServers returns the number of coordinators & dbServers in a clusters and the ID's of cleanedOut servers.
60+
NumberOfServers(ctx context.Context) (NumberOfServersResponse, error)
61+
62+
// IsCleanedOut checks if the dbServer with given ID has been cleaned out.
63+
IsCleanedOut(ctx context.Context, serverID ServerID) (bool, error)
64+
65+
// RemoveServer is a low-level option to remove a server from a cluster.
66+
// This function is suitable for servers of type coordinator or dbServer.
67+
// The use of `ClientServerAdmin.Shutdown` is highly recommended above this function.
68+
RemoveServer(ctx context.Context, serverID ServerID) error
69+
}
70+
71+
type NumberOfServersResponse struct {
72+
NoCoordinators int `json:"numberOfCoordinators,omitempty"`
73+
NoDBServers int `json:"numberOfDBServers,omitempty"`
74+
CleanedServerIDs []ServerID `json:"cleanedServers,omitempty"`
75+
}
76+
4677
type ClientAdminLog interface {
4778
// GetLogLevels returns log levels for topics.
4879
GetLogLevels(ctx context.Context, opts *LogLevelsGetOptions) (LogLevels, error)
@@ -55,3 +86,54 @@ type ClientAdminLicense interface {
5586
// GetLicense returns license of an ArangoDB deployment.
5687
GetLicense(ctx context.Context) (License, error)
5788
}
89+
90+
type DatabaseInventory struct {
91+
Info DatabaseInfo `json:"properties,omitempty"`
92+
Collections []InventoryCollection `json:"collections,omitempty"`
93+
Views []InventoryView `json:"views,omitempty"`
94+
State ServerStatus `json:"state,omitempty"`
95+
Tick string `json:"tick,omitempty"`
96+
}
97+
98+
type InventoryCollection struct {
99+
Parameters InventoryCollectionParameters `json:"parameters"`
100+
Indexes []InventoryIndex `json:"indexes,omitempty"`
101+
PlanVersion int64 `json:"planVersion,omitempty"`
102+
IsReady bool `json:"isReady,omitempty"`
103+
AllInSync bool `json:"allInSync,omitempty"`
104+
}
105+
106+
type InventoryCollectionParameters struct {
107+
Deleted bool `json:"deleted,omitempty"`
108+
Shards map[ShardID][]ServerID `json:"shards,omitempty"`
109+
PlanID string `json:"planId,omitempty"`
110+
111+
CollectionProperties
112+
}
113+
114+
type InventoryIndex struct {
115+
ID string `json:"id,omitempty"`
116+
Type string `json:"type,omitempty"`
117+
Fields []string `json:"fields,omitempty"`
118+
Unique bool `json:"unique"`
119+
Sparse bool `json:"sparse"`
120+
Deduplicate bool `json:"deduplicate"`
121+
MinLength int `json:"minLength,omitempty"`
122+
GeoJSON bool `json:"geoJson,omitempty"`
123+
Name string `json:"name,omitempty"`
124+
ExpireAfter int `json:"expireAfter,omitempty"`
125+
Estimates bool `json:"estimates,omitempty"`
126+
FieldValueTypes string `json:"fieldValueTypes,omitempty"`
127+
CacheEnabled *bool `json:"cacheEnabled,omitempty"`
128+
}
129+
130+
type InventoryView struct {
131+
Name string `json:"name,omitempty"`
132+
Deleted bool `json:"deleted,omitempty"`
133+
ID string `json:"id,omitempty"`
134+
IsSystem bool `json:"isSystem,omitempty"`
135+
PlanID string `json:"planId,omitempty"`
136+
Type ViewType `json:"type,omitempty"`
137+
138+
ArangoSearchViewProperties
139+
}

v2/arangodb/client_admin_backup.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type ClientAdminBackup interface {
4343

4444
// BackupDownload triggers a download of backup into the remote repository using the given config
4545
BackupDownload(ctx context.Context, backupId string, remoteRepository string, config interface{}) (TransferMonitor, error)
46+
47+
TransferMonitor(jobId string, transferType TransferType) (TransferMonitor, error)
4648
}
4749

4850
type TransferMonitor interface {
@@ -53,6 +55,13 @@ type TransferMonitor interface {
5355
Abort(ctx context.Context) error
5456
}
5557

58+
type TransferType string
59+
60+
const (
61+
TransferTypeUpload TransferType = "upload"
62+
TransferTypeDownload TransferType = "download"
63+
)
64+
5665
type BackupCreateOptions struct {
5766
// The label for this backup.
5867
// The label is used together with a timestamp string create a unique backup identifier, <timestamp>_<label>.

v2/arangodb/client_admin_backup_impl.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/arangodb/go-driver/v2/connection"
3131
)
3232

33-
func (c clientAdmin) BackupCreate(ctx context.Context, opt *BackupCreateOptions) (BackupResponse, error) {
33+
func (c *clientAdmin) BackupCreate(ctx context.Context, opt *BackupCreateOptions) (BackupResponse, error) {
3434
url := connection.NewUrl("_admin", "backup", "create")
3535

3636
var response struct {
@@ -56,7 +56,7 @@ func (c clientAdmin) BackupCreate(ctx context.Context, opt *BackupCreateOptions)
5656
}
5757
}
5858

59-
func (c clientAdmin) BackupRestore(ctx context.Context, id string) (BackupRestoreResponse, error) {
59+
func (c *clientAdmin) BackupRestore(ctx context.Context, id string) (BackupRestoreResponse, error) {
6060
url := connection.NewUrl("_admin", "backup", "restore")
6161

6262
var response struct {
@@ -83,7 +83,7 @@ func (c clientAdmin) BackupRestore(ctx context.Context, id string) (BackupRestor
8383
}
8484
}
8585

86-
func (c clientAdmin) BackupDelete(ctx context.Context, id string) error {
86+
func (c *clientAdmin) BackupDelete(ctx context.Context, id string) error {
8787
url := connection.NewUrl("_admin", "backup", "delete")
8888

8989
var response struct {
@@ -109,7 +109,7 @@ func (c clientAdmin) BackupDelete(ctx context.Context, id string) error {
109109
}
110110
}
111111

112-
func (c clientAdmin) BackupList(ctx context.Context, opt *BackupListOptions) (ListBackupsResponse, error) {
112+
func (c *clientAdmin) BackupList(ctx context.Context, opt *BackupListOptions) (ListBackupsResponse, error) {
113113
url := connection.NewUrl("_admin", "backup", "list")
114114

115115
var response struct {
@@ -135,7 +135,7 @@ func (c clientAdmin) BackupList(ctx context.Context, opt *BackupListOptions) (Li
135135
}
136136
}
137137

138-
func (c clientAdmin) BackupUpload(ctx context.Context, backupId string, remoteRepository string, config interface{}) (TransferMonitor, error) {
138+
func (c *clientAdmin) BackupUpload(ctx context.Context, backupId string, remoteRepository string, config interface{}) (TransferMonitor, error) {
139139
url := connection.NewUrl("_admin", "backup", "upload")
140140

141141
var response struct {
@@ -168,7 +168,7 @@ func (c clientAdmin) BackupUpload(ctx context.Context, backupId string, remoteRe
168168
}
169169
}
170170

171-
func (c clientAdmin) BackupDownload(ctx context.Context, backupId string, remoteRepository string, config interface{}) (TransferMonitor, error) {
171+
func (c *clientAdmin) BackupDownload(ctx context.Context, backupId string, remoteRepository string, config interface{}) (TransferMonitor, error) {
172172
url := connection.NewUrl("_admin", "backup", "download")
173173

174174
var response struct {
@@ -201,6 +201,17 @@ func (c clientAdmin) BackupDownload(ctx context.Context, backupId string, remote
201201
}
202202
}
203203

204+
func (c *clientAdmin) TransferMonitor(jobId string, transferType TransferType) (TransferMonitor, error) {
205+
switch transferType {
206+
case TransferTypeUpload:
207+
return newUploadMonitor(c.client, jobId)
208+
case TransferTypeDownload:
209+
return newDownloadMonitor(c.client, jobId)
210+
default:
211+
return nil, errors.Errorf("unsupported transfer type '%s'", transferType)
212+
}
213+
}
214+
204215
type uploadMonitor struct {
205216
client *client
206217
jobId string

0 commit comments

Comments
 (0)