|
| 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 | +} |
0 commit comments