Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Go-Driver to latest version. #312

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 59 additions & 59 deletions dashboard/assets.go

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions deps/github.com/arangodb/go-driver/.envrc

This file was deleted.

1 change: 0 additions & 1 deletion deps/github.com/arangodb/go-driver/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions deps/github.com/arangodb/go-driver/.travis.yml

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions deps/github.com/arangodb/go-driver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ type Client interface {
// This function requires ArangoDB 3.1.15 or up.
SynchronizeEndpoints(ctx context.Context) error

// SynchronizeEndpoints2 fetches all endpoints from an ArangoDB cluster and updates the
// connection to use those endpoints.
// When this client is connected to a single server, nothing happens.
// When this client is connected to a cluster of servers, the connection will be updated to reflect
// the layout of the cluster.
// Compared to SynchronizeEndpoints, this function expects a database name as additional parameter.
// This database name is used to call `_db/<dbname>/_api/cluster/endpoints`. SynchronizeEndpoints uses
// the default database, i.e. `_system`. In the case the user does not have access to `_system`,
// SynchronizeEndpoints does not work with earlier versions of arangodb.
SynchronizeEndpoints2(ctx context.Context, dbname string) error

// Connection returns the connection used by this client
Connection() Connection

Expand Down
40 changes: 28 additions & 12 deletions deps/github.com/arangodb/go-driver/client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package driver

import (
"context"
"path"
"time"

"github.com/arangodb/go-driver/util"
Expand Down Expand Up @@ -67,19 +68,28 @@ func (c *client) Connection() Connection {
// When this client is connected to a cluster of servers, the connection will be updated to reflect
// the layout of the cluster.
func (c *client) SynchronizeEndpoints(ctx context.Context) error {
role, err := c.ServerRole(ctx)
if err != nil {
return WithStack(err)
}
if role == ServerRoleSingle {
// Standalone server, do nothing
return nil
}
return c.SynchronizeEndpoints2(ctx, "")
}

// SynchronizeEndpoints2 fetches all endpoints from an ArangoDB cluster and updates the
// connection to use those endpoints.
// When this client is connected to a single server, nothing happens.
// When this client is connected to a cluster of servers, the connection will be updated to reflect
// the layout of the cluster.
// Compared to SynchronizeEndpoints, this function expects a database name as additional parameter.
// This database name is used to call `_db/<dbname>/_api/cluster/endpoints`. SynchronizeEndpoints uses
// the default database, i.e. `_system`. In the case the user does not have access to `_system`,
// SynchronizeEndpoints does not work with earlier versions of arangodb.
func (c *client) SynchronizeEndpoints2(ctx context.Context, dbname string) error {
// Cluster mode, fetch endpoints
cep, err := c.clusterEndpoints(ctx)
cep, err := c.clusterEndpoints(ctx, dbname)
if err != nil {
return WithStack(err)
// ignore Forbidden: automatic failover is not enabled errors
if !IsArangoErrorWithErrorNum(err, 403, 0, 11) { // 3.2 returns no error code, thus check for 0
return WithStack(err)
}

return nil
}
var endpoints []string
for _, ep := range cep.Endpoints {
Expand Down Expand Up @@ -114,8 +124,14 @@ type clusterEndpoint struct {
}

// clusterEndpoints returns the endpoints of a cluster.
func (c *client) clusterEndpoints(ctx context.Context) (clusterEndpointsResponse, error) {
req, err := c.conn.NewRequest("GET", "_api/cluster/endpoints")
func (c *client) clusterEndpoints(ctx context.Context, dbname string) (clusterEndpointsResponse, error) {
var url string
if dbname == "" {
url = "_api/cluster/endpoints"
} else {
url = path.Join("_db", pathEscape(dbname), "_api/cluster/endpoints")
}
req, err := c.conn.NewRequest("GET", url)
if err != nil {
return clusterEndpointsResponse{}, WithStack(err)
}
Expand Down
28 changes: 28 additions & 0 deletions deps/github.com/arangodb/go-driver/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type ServerHealth struct {
Status ServerStatus `json:"Status"`
CanBeDeleted bool `json:"CanBeDeleted"`
HostID string `json:"Host,omitempty"`
Version Version `json:"Version,omitempty"`
Engine EngineType `json:"Engine,omitempty"`
}

// ServerStatus describes the health status of a server
Expand All @@ -93,6 +95,8 @@ const (
type DatabaseInventory struct {
// Details of all collections
Collections []InventoryCollection `json:"collections,omitempty"`
// Details of all views
Views []InventoryView `json:"views,omitempty"`
}

// IsReady returns true if the IsReady flag of all collections is set.
Expand Down Expand Up @@ -124,6 +128,17 @@ func (i DatabaseInventory) CollectionByName(name string) (InventoryCollection, b
return InventoryCollection{}, false
}

// ViewByName returns the InventoryView with given name.
// Return false if not found.
func (i DatabaseInventory) ViewByName(name string) (InventoryView, bool) {
for _, v := range i.Views {
if v.Name == name {
return v, true
}
}
return InventoryView{}, false
}

// InventoryCollection is a single element of a DatabaseInventory, containing all information
// of a specific collection.
type InventoryCollection struct {
Expand Down Expand Up @@ -196,6 +211,19 @@ func (i InventoryIndex) FieldsEqual(fields []string) bool {
return stringSliceEqualsIgnoreOrder(i.Fields, fields)
}

// InventoryView is a single element of a DatabaseInventory, containing all information
// of a specific view.
type InventoryView struct {
Name string `json:"name,omitempty"`
Deleted bool `json:"deleted,omitempty"`
ID string `json:"id,omitempty"`
IsSystem bool `json:"isSystem,omitempty"`
PlanID string `json:"planId,omitempty"`
Type ViewType `json:"type,omitempty"`
// Include all properties from an arangosearch view.
ArangoSearchViewProperties
}

// stringSliceEqualsIgnoreOrder returns true when the given lists contain the same elements.
// The order of elements is irrelevant.
func stringSliceEqualsIgnoreOrder(a, b []string) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (c *collection) ReadDocument(ctx context.Context, key string, result interf
if err != nil {
return DocumentMeta{}, WithStack(err)
}
// This line introduces a lot of side effects. In particular If-Match headers are now set (which is a bugfix)
// and invalid query parameters like waitForSync (which is potentially breaking change)
cs := applyContextSettings(ctx, req)
resp, err := c.conn.Do(ctx, req)
if err != nil {
return DocumentMeta{}, WithStack(err)
Expand All @@ -71,6 +74,8 @@ func (c *collection) ReadDocument(ctx context.Context, key string, result interf
if err := resp.ParseBody("", &meta); err != nil {
return DocumentMeta{}, WithStack(err)
}
// load context response values
loadContextResponseValues(cs, resp)
// Parse result
if result != nil {
if err := resp.ParseBody("", result); err != nil {
Expand Down Expand Up @@ -120,6 +125,8 @@ func (c *collection) ReadDocuments(ctx context.Context, keys []string, results i
if err := resp.CheckStatus(200); err != nil {
return nil, nil, WithStack(err)
}
// load context response values
loadContextResponseValues(cs, resp)
// Parse response array
metas, errs, err := parseResponseArray(resp, resultCount, cs, results)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ type indexData struct {
MinLength int `json:"minLength,omitempty"`
}

type genericIndexData struct {
ID string `json:"id,omitempty"`
Type string `json:"type"`
}

type indexListResponse struct {
Indexes []indexData `json:"indexes,omitempty"`
Indexes []genericIndexData `json:"indexes,omitempty"`
}

// Index opens a connection to an existing index within the collection.
Expand All @@ -60,7 +65,7 @@ func (c *collection) Index(ctx context.Context, name string) (Index, error) {
if err := resp.ParseBody("", &data); err != nil {
return nil, WithStack(err)
}
idx, err := newIndex(data.ID, c)
idx, err := newIndex(data.ID, data.Type, c)
if err != nil {
return nil, WithStack(err)
}
Expand Down Expand Up @@ -106,7 +111,7 @@ func (c *collection) Indexes(ctx context.Context) ([]Index, error) {
}
result := make([]Index, 0, len(data.Indexes))
for _, x := range data.Indexes {
idx, err := newIndex(x.ID, c)
idx, err := newIndex(x.ID, x.Type, c)
if err != nil {
return nil, WithStack(err)
}
Expand All @@ -121,7 +126,7 @@ func (c *collection) Indexes(ctx context.Context) ([]Index, error) {
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
func (c *collection) EnsureFullTextIndex(ctx context.Context, fields []string, options *EnsureFullTextIndexOptions) (Index, bool, error) {
input := indexData{
Type: "fulltext",
Type: string(FullTextIndex),
Fields: fields,
}
if options != nil {
Expand All @@ -146,7 +151,7 @@ func (c *collection) EnsureFullTextIndex(ctx context.Context, fields []string, o
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
func (c *collection) EnsureGeoIndex(ctx context.Context, fields []string, options *EnsureGeoIndexOptions) (Index, bool, error) {
input := indexData{
Type: "geo",
Type: string(GeoIndex),
Fields: fields,
}
if options != nil {
Expand All @@ -164,7 +169,7 @@ func (c *collection) EnsureGeoIndex(ctx context.Context, fields []string, option
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
func (c *collection) EnsureHashIndex(ctx context.Context, fields []string, options *EnsureHashIndexOptions) (Index, bool, error) {
input := indexData{
Type: "hash",
Type: string(HashIndex),
Fields: fields,
}
off := false
Expand All @@ -187,7 +192,7 @@ func (c *collection) EnsureHashIndex(ctx context.Context, fields []string, optio
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
func (c *collection) EnsurePersistentIndex(ctx context.Context, fields []string, options *EnsurePersistentIndexOptions) (Index, bool, error) {
input := indexData{
Type: "persistent",
Type: string(PersistentIndex),
Fields: fields,
}
if options != nil {
Expand All @@ -206,7 +211,7 @@ func (c *collection) EnsurePersistentIndex(ctx context.Context, fields []string,
// The index is returned, together with a boolean indicating if the index was newly created (true) or pre-existing (false).
func (c *collection) EnsureSkipListIndex(ctx context.Context, fields []string, options *EnsureSkipListIndexOptions) (Index, bool, error) {
input := indexData{
Type: "skiplist",
Type: string(SkipListIndex),
Fields: fields,
}
off := false
Expand Down Expand Up @@ -248,7 +253,7 @@ func (c *collection) ensureIndex(ctx context.Context, options indexData) (Index,
if err := resp.ParseBody("", &data); err != nil {
return nil, false, WithStack(err)
}
idx, err := newIndex(data.ID, c)
idx, err := newIndex(data.ID, data.Type, c)
if err != nil {
return nil, false, WithStack(err)
}
Expand Down
4 changes: 4 additions & 0 deletions deps/github.com/arangodb/go-driver/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type Request interface {
Written() bool
// Clone creates a new request containing the same data as this request
Clone() Request
// Path returns the Request path
Path() string
// Method returns the Request method
Method() string
}

// Response represents the response from the server on a given request.
Expand Down
Loading