Skip to content
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
9 changes: 8 additions & 1 deletion service/client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ package service

import driver "github.com/arangodb/go-driver"

type ConnectionType int

const (
ConnectionTypeDatabase ConnectionType = iota
ConnectionTypeAgency
)

// ClientBuilder is a callback used to create authenticated go-driver clients with or without
// follow-redirect.
type ClientBuilder func(endpoints []string, followRedirect bool) (driver.Client, error)
type ClientBuilder func(endpoints []string, connectionType ConnectionType) (driver.Client, error)
7 changes: 4 additions & 3 deletions service/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,12 @@ func (p ClusterConfig) CreateAgencyAPI(clientBuilder ClientBuilder) (agency.Agen
if err != nil {
return nil, maskAny(err)
}
c, err := clientBuilder(endpoints, true)
c, err := clientBuilder(endpoints, ConnectionTypeAgency)
if err != nil {
return nil, maskAny(err)
}
a, err := agency.NewAgency(c.Connection())
conn := c.Connection()
a, err := agency.NewAgency(conn)
if err != nil {
return nil, maskAny(err)
}
Expand All @@ -301,7 +302,7 @@ func (p ClusterConfig) CreateClusterAPI(ctx context.Context, clientBuilder Clien
if err != nil {
return nil, maskAny(err)
}
c, err := clientBuilder(endpoints, true)
c, err := clientBuilder(endpoints, ConnectionTypeDatabase)
if err != nil {
return nil, maskAny(err)
}
Expand Down
4 changes: 2 additions & 2 deletions service/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (p Peer) CreateDBServerAPI(clientBuilder ClientBuilder) (driver.Client, err
port := p.Port + p.PortOffset + ServerType(ServerTypeDBServer).PortOffset()
scheme := NewURLSchemes(p.IsSecure).Browser
ep := fmt.Sprintf("%s://%s", scheme, net.JoinHostPort(p.Address, strconv.Itoa(port)))
c, err := clientBuilder([]string{ep}, false)
c, err := clientBuilder([]string{ep}, ConnectionTypeDatabase)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has a different value for DontFollowRedirects is this correct?

if err != nil {
return nil, maskAny(err)
}
Expand All @@ -117,7 +117,7 @@ func (p Peer) CreateCoordinatorAPI(clientBuilder ClientBuilder) (driver.Client,
port := p.Port + p.PortOffset + ServerType(ServerTypeCoordinator).PortOffset()
scheme := NewURLSchemes(p.IsSecure).Browser
ep := fmt.Sprintf("%s://%s", scheme, net.JoinHostPort(p.Address, strconv.Itoa(port)))
c, err := clientBuilder([]string{ep}, false)
c, err := clientBuilder([]string{ep}, ConnectionTypeDatabase)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has a different value for DontFollowRedirects is this correct?

if err != nil {
return nil, maskAny(err)
}
Expand Down
2 changes: 1 addition & 1 deletion service/runtime_cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type runtimeClusterManagerContext interface {
ChangeState(newState State)

// CreateClient returns go-driver client with authentication configured for the given endpoint.
CreateClient(endpoint []string, followRedirect bool) (driver.Client, error)
CreateClient(endpoint []string, connectionType ConnectionType) (driver.Client, error)

// UpdateClusterConfig updates the current cluster configuration.
UpdateClusterConfig(ClusterConfig)
Expand Down
19 changes: 15 additions & 4 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

"github.com/arangodb-helper/arangodb/client"
driver "github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/agency"
driver_http "github.com/arangodb/go-driver/http"
"github.com/arangodb/go-driver/jwt"
logging "github.com/op/go-logging"
Expand Down Expand Up @@ -940,14 +941,24 @@ func (s *Service) PrepareDatabaseServerRequestFunc() func(*http.Request) error {
}

// CreateClient creates a go-driver client with authentication for the given endpoints.
func (s *Service) CreateClient(endpoints []string, followRedirect bool) (driver.Client, error) {
conn, err := driver_http.NewConnection(driver_http.ConnectionConfig{
func (s *Service) CreateClient(endpoints []string, connectionType ConnectionType) (driver.Client, error) {
connConfig := driver_http.ConnectionConfig{
Endpoints: endpoints,
DontFollowRedirect: !followRedirect,
DontFollowRedirect: connectionType == ConnectionTypeAgency,
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
})
}
var conn driver.Connection
var err error
switch connectionType {
case ConnectionTypeDatabase:
conn, err = driver_http.NewConnection(connConfig)
case ConnectionTypeAgency:
conn, err = agency.NewAgencyConnection(connConfig)
default:
return nil, maskAny(fmt.Errorf("Unknown ConnectionType: %d", connectionType))
}
if err != nil {
return nil, maskAny(err)
}
Expand Down
14 changes: 7 additions & 7 deletions service/upgrade_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type UpgradeManagerContext interface {
// ClusterConfig returns the current cluster configuration and the current peer
ClusterConfig() (ClusterConfig, *Peer, ServiceMode)
// CreateClient creates a go-driver client with authentication for the given endpoints.
CreateClient(endpoints []string, followRedirect bool) (driver.Client, error)
CreateClient(endpoints []string, connectionType ConnectionType) (driver.Client, error)
// RestartServer triggers a restart of the server of the given type.
RestartServer(serverType ServerType) error
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func (m *upgradeManager) isAgencyHealth(ctx context.Context) error {
// Build agency clients
clients := make([]driver.Connection, 0, len(endpoints))
for _, ep := range endpoints {
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeAgency)
if err != nil {
return maskAny(err)
}
Expand All @@ -392,7 +392,7 @@ func (m *upgradeManager) areDBServersResponding(ctx context.Context) error {
}
// Check all
for _, ep := range endpoints {
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has a different value for DontFollowRedirects is this correct?

if err != nil {
return maskAny(err)
}
Expand All @@ -414,7 +414,7 @@ func (m *upgradeManager) areCoordinatorsResponding(ctx context.Context) error {
}
// Check all
for _, ep := range endpoints {
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has a different value for DontFollowRedirects is this correct?

if err != nil {
return maskAny(err)
}
Expand All @@ -436,7 +436,7 @@ func (m *upgradeManager) areSingleServersResponding(ctx context.Context) error {
}
// Check all
for _, ep := range endpoints {
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has a different value for DontFollowRedirects is this correct?

if err != nil {
return maskAny(err)
}
Expand All @@ -459,7 +459,7 @@ func (m *upgradeManager) isSuperVisionMaintenanceSupported(ctx context.Context)
}
// Check agents
for _, ep := range endpoints {
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeAgency)
if err != nil {
return false, maskAny(err)
}
Expand Down Expand Up @@ -546,7 +546,7 @@ func (m *upgradeManager) ShowArangodServerVersions(ctx context.Context) (bool, e
showGroup := func(serverType ServerType, endpoints []string) {
groupVersions := make([]string, len(endpoints))
for i, ep := range endpoints {
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has a different value for DontFollowRedirects is this correct?

if err != nil {
groupVersions[i] = "?"
continue
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.