Skip to content

Commit f2af292

Browse files
authored
Set Licence API support (#606)
1 parent d4824ef commit f2af292

File tree

6 files changed

+175
-91
lines changed

6 files changed

+175
-91
lines changed

v2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Wildcard analyzer support
1919
- Backup API support
2020
- Admin Cluster API support
21+
- Set Licence API support
2122

2223

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

v2/arangodb/client_admin.go

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,6 @@ type ClientAdmin interface {
4040
SetServerMode(ctx context.Context, mode ServerMode) error
4141
}
4242

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-
7743
type ClientAdminLog interface {
7844
// GetLogLevels returns log levels for topics.
7945
GetLogLevels(ctx context.Context, opts *LogLevelsGetOptions) (LogLevels, error)
@@ -85,55 +51,8 @@ type ClientAdminLog interface {
8551
type ClientAdminLicense interface {
8652
// GetLicense returns license of an ArangoDB deployment.
8753
GetLicense(ctx context.Context) (License, error)
88-
}
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"`
13754

138-
ArangoSearchViewProperties
55+
// SetLicense Set a new license for an Enterprise Edition instance.
56+
// Can be called on single servers, Coordinators, and DB-Servers.
57+
SetLicense(ctx context.Context, license string, force bool) error
13958
}

v2/arangodb/client_admin_cluster.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package arangodb
22+
23+
import "context"
24+
25+
type ClientAdminCluster interface {
26+
// Health returns the cluster configuration & health. Not available in single server deployments (403 Forbidden).
27+
Health(ctx context.Context) (ClusterHealth, error)
28+
29+
// DatabaseInventory the inventory of the cluster collections (with entire details) from a specific database.
30+
DatabaseInventory(ctx context.Context, dbName string) (DatabaseInventory, error)
31+
32+
// MoveShard moves a single shard of the given collection between `fromServer` and `toServer`.
33+
MoveShard(ctx context.Context, col Collection, shard ShardID, fromServer, toServer ServerID) (string, error)
34+
35+
// CleanOutServer triggers activities to clean out a DBServer.
36+
CleanOutServer(ctx context.Context, serverID ServerID) (string, error)
37+
38+
// ResignServer triggers activities to let a DBServer resign for all shards.
39+
ResignServer(ctx context.Context, serverID ServerID) (string, error)
40+
41+
// NumberOfServers returns the number of coordinators & dbServers in a clusters and the ID's of cleanedOut servers.
42+
NumberOfServers(ctx context.Context) (NumberOfServersResponse, error)
43+
44+
// IsCleanedOut checks if the dbServer with given ID has been cleaned out.
45+
IsCleanedOut(ctx context.Context, serverID ServerID) (bool, error)
46+
47+
// RemoveServer is a low-level option to remove a server from a cluster.
48+
// This function is suitable for servers of type coordinator or dbServer.
49+
// The use of `ClientServerAdmin.Shutdown` is highly recommended above this function.
50+
RemoveServer(ctx context.Context, serverID ServerID) error
51+
}
52+
53+
type NumberOfServersResponse struct {
54+
NoCoordinators int `json:"numberOfCoordinators,omitempty"`
55+
NoDBServers int `json:"numberOfDBServers,omitempty"`
56+
CleanedServerIDs []ServerID `json:"cleanedServers,omitempty"`
57+
}
58+
59+
type DatabaseInventory struct {
60+
Info DatabaseInfo `json:"properties,omitempty"`
61+
Collections []InventoryCollection `json:"collections,omitempty"`
62+
Views []InventoryView `json:"views,omitempty"`
63+
State ServerStatus `json:"state,omitempty"`
64+
Tick string `json:"tick,omitempty"`
65+
}
66+
67+
type InventoryCollection struct {
68+
Parameters InventoryCollectionParameters `json:"parameters"`
69+
Indexes []InventoryIndex `json:"indexes,omitempty"`
70+
PlanVersion int64 `json:"planVersion,omitempty"`
71+
IsReady bool `json:"isReady,omitempty"`
72+
AllInSync bool `json:"allInSync,omitempty"`
73+
}
74+
75+
type InventoryCollectionParameters struct {
76+
Deleted bool `json:"deleted,omitempty"`
77+
Shards map[ShardID][]ServerID `json:"shards,omitempty"`
78+
PlanID string `json:"planId,omitempty"`
79+
80+
CollectionProperties
81+
}
82+
83+
type InventoryIndex struct {
84+
ID string `json:"id,omitempty"`
85+
Type string `json:"type,omitempty"`
86+
Fields []string `json:"fields,omitempty"`
87+
Unique bool `json:"unique"`
88+
Sparse bool `json:"sparse"`
89+
Deduplicate bool `json:"deduplicate"`
90+
MinLength int `json:"minLength,omitempty"`
91+
GeoJSON bool `json:"geoJson,omitempty"`
92+
Name string `json:"name,omitempty"`
93+
ExpireAfter int `json:"expireAfter,omitempty"`
94+
Estimates bool `json:"estimates,omitempty"`
95+
FieldValueTypes string `json:"fieldValueTypes,omitempty"`
96+
CacheEnabled *bool `json:"cacheEnabled,omitempty"`
97+
}
98+
99+
type InventoryView struct {
100+
Name string `json:"name,omitempty"`
101+
Deleted bool `json:"deleted,omitempty"`
102+
ID string `json:"id,omitempty"`
103+
IsSystem bool `json:"isSystem,omitempty"`
104+
PlanID string `json:"planId,omitempty"`
105+
Type ViewType `json:"type,omitempty"`
106+
107+
ArangoSearchViewProperties
108+
}
109+
110+
// CollectionByName returns the InventoryCollection with given name. Return false if not found.
111+
func (i DatabaseInventory) CollectionByName(name string) (InventoryCollection, bool) {
112+
for _, c := range i.Collections {
113+
if c.Parameters.Name == name {
114+
return c, true
115+
}
116+
}
117+
return InventoryCollection{}, false
118+
}
119+
120+
// ViewByName returns the InventoryView with given name. Return false if not found.
121+
func (i DatabaseInventory) ViewByName(name string) (InventoryView, bool) {
122+
for _, v := range i.Views {
123+
if v.Name == name {
124+
return v, true
125+
}
126+
}
127+
return InventoryView{}, false
128+
}

v2/arangodb/client_admin_license_impl.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -42,27 +42,35 @@ type LicenseStatus string
4242
const (
4343
// LicenseStatusGood - The license is valid for more than 2 weeks.
4444
LicenseStatusGood LicenseStatus = "good"
45+
4546
// LicenseStatusExpired - The license has expired. In this situation, no new Enterprise Edition features can be utilized.
4647
LicenseStatusExpired LicenseStatus = "expired"
48+
4749
// LicenseStatusExpiring - The license is valid for less than 2 weeks.
4850
LicenseStatusExpiring LicenseStatus = "expiring"
51+
4952
// LicenseStatusReadOnly - The license is expired over 2 weeks. The instance is now restricted to read-only mode.
5053
LicenseStatusReadOnly LicenseStatus = "read-only"
5154
)
5255

5356
// License describes license information.
5457
type License struct {
55-
// Features describes properties of the license.
58+
// Features describe properties of the license.
5659
Features LicenseFeatures `json:"features"`
60+
5761
// License is an encrypted license key in Base64 encoding.
58-
License string `json:"license"`
62+
License string `json:"license,omitempty"`
63+
5964
// Status is a status of a license.
60-
Status LicenseStatus `json:"status"`
65+
Status LicenseStatus `json:"status,omitempty"`
66+
6167
// Version is a version of a license.
6268
Version int `json:"version"`
69+
70+
// Hash The hash value of the license.
71+
Hash string `json:"hash,omitempty"`
6372
}
6473

65-
// GetLicense returns license of an ArangoDB deployment.
6674
func (c *clientAdmin) GetLicense(ctx context.Context) (License, error) {
6775
var response struct {
6876
shared.ResponseStruct `json:",inline"`
@@ -80,3 +88,26 @@ func (c *clientAdmin) GetLicense(ctx context.Context) (License, error) {
8088
return License{}, response.AsArangoErrorWithCode(code)
8189
}
8290
}
91+
92+
func (c *clientAdmin) SetLicense(ctx context.Context, license string, force bool) error {
93+
var response struct {
94+
shared.ResponseStruct `json:",inline"`
95+
}
96+
97+
var modifiers []connection.RequestModifier
98+
if force {
99+
modifiers = append(modifiers, connection.WithQuery("force", "true"))
100+
}
101+
102+
resp, err := connection.CallPut(ctx, c.client.connection, "_admin/license", &response, license, modifiers...)
103+
if err != nil {
104+
return errors.WithStack(err)
105+
}
106+
107+
switch code := resp.Code(); code {
108+
case http.StatusCreated:
109+
return nil
110+
default:
111+
return response.AsArangoErrorWithCode(code)
112+
}
113+
}

v2/arangodb/client_server_info.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ import (
3030
type ClientServerInfo interface {
3131
// Version returns version information from the connected database server.
3232
Version(ctx context.Context) (VersionInfo, error)
33+
3334
// VersionWithOptions returns version information from the connected database server.
3435
VersionWithOptions(ctx context.Context, opts *GetVersionOptions) (VersionInfo, error)
36+
3537
// ServerRole returns the role of the server that answers the request.
3638
ServerRole(ctx context.Context) (ServerRole, error)
39+
3740
// ServerID Gets the ID of this server in the cluster.
3841
// An error is returned when calling this to a server that is not part of a cluster.
3942
ServerID(ctx context.Context) (string, error)
@@ -43,11 +46,14 @@ type ClientServerInfo interface {
4346
type VersionInfo struct {
4447
// This will always contain "arango"
4548
Server string `json:"server,omitempty"`
49+
4650
// The server version string. The string has the format "major.minor.sub".
4751
// Major and minor will be numeric, and sub may contain a number or a textual version.
4852
Version Version `json:"version,omitempty"`
53+
4954
// Type of license of the server
5055
License string `json:"license,omitempty"`
56+
5157
// Optional additional details. This is returned only if details were requested
5258
Details map[string]interface{} `json:"details,omitempty"`
5359
}

v2/tests/admin_license_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@ import (
3030
"github.com/arangodb/go-driver/v2/arangodb"
3131
)
3232

33-
// Test_License tests ArangoDB license.
3433
func Test_License(t *testing.T) {
3534
Wrap(t, func(t *testing.T, client arangodb.Client) {
3635
withContextT(t, defaultTestTimeout, func(ctx context.Context, t testing.TB) {

0 commit comments

Comments
 (0)