Skip to content

Commit 194a96e

Browse files
authored
Merge pull request #192 from arangodb-helper/feature/add-advertised-endpoint
add advertised endpoint to cluster / active fo
2 parents c3ca1fb + e5cdde2 commit 194a96e

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
## Changes from version 0.12.0 to 0.13.0
2626

27+
- Added advertised endpoint to coordinators and active failover servers.
28+
2729
- Database upgrade procedure has changed.
2830
It is now much more automated and can be triggered using
2931
an `arangodb upgrade --starter.endpoint=...` command.

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"context"
2727
"fmt"
2828
"io/ioutil"
29+
"net/url"
2930
"os"
3031
"os/signal"
3132
"path/filepath"
@@ -86,6 +87,7 @@ var (
8687
logService logging.Service
8788
showVersion bool
8889
id string
90+
advertisedEndpoint string
8991
agencySize int
9092
arangodPath string
9193
arangodJSPath string
@@ -192,7 +194,7 @@ func init() {
192194
pf.StringVar(&logDir, "log.dir", getEnvVar("LOG_DIR", ""), "Custom log file directory.")
193195
f.IntVar(&logRotateFilesToKeep, "log.rotate-files-to-keep", defaultLogRotateFilesToKeep, "Number of files to keep when rotating log files")
194196
f.DurationVar(&logRotateInterval, "log.rotate-interval", defaultLogRotateInterval, "Time between log rotations (0 disables log rotation)")
195-
197+
f.StringVar(&advertisedEndpoint, "cluster.advertised-endpoint", "", "An external endpoint for the servers started by this Starter")
196198
f.IntVar(&agencySize, "cluster.agency-size", 3, "Number of agents in the cluster")
197199
f.BoolSliceVar(&startAgent, "cluster.start-agent", nil, "should an agent instance be started")
198200
f.BoolSliceVar(&startDBserver, "cluster.start-dbserver", nil, "should a dbserver instance be started")
@@ -568,6 +570,11 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo
568570
log.Fatal().Err(err).Msgf("Unsupport image pull policy '%s'", dockerImagePullPolicy)
569571
}
570572

573+
// Sanity checking URL scheme on advertised endpoints
574+
if _, err := url.Parse(advertisedEndpoint); err != nil {
575+
log.Fatal().Err(err).Msgf("Advertised cluster endpoint %s does not meet URL standards", advertisedEndpoint)
576+
}
577+
571578
// Expand home-dis (~) in paths
572579
arangodPath = mustExpand(arangodPath)
573580
arangodJSPath = mustExpand(arangodJSPath)
@@ -707,6 +714,7 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo
707714
ArangodPath: arangodPath,
708715
ArangoSyncPath: arangoSyncPath,
709716
ArangodJSPath: arangodJSPath,
717+
AdvertisedEndpoint: advertisedEndpoint,
710718
MasterPort: masterPort,
711719
RrPath: rrPath,
712720
DataDir: dataDir,

service/arangod_config_builder.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ import (
4545
"github.com/rs/zerolog"
4646
)
4747

48+
var (
49+
urlFixer = strings.NewReplacer(
50+
"http://", "tcp://",
51+
"https://", "ssl://",
52+
)
53+
)
54+
55+
// fixupEndpointURLSchemeForArangod changes endpoint URL schemes used by Starter to ones used by arangodb.
56+
// E.g. "http://localhost:8529" -> "tcp://localhost:8529"
57+
func fixupEndpointURLSchemeForArangod(u string) string {
58+
return urlFixer.Replace(u)
59+
}
60+
4861
// createArangodConf creates an arangod.conf file in the given host directory if it does not yet exists.
4962
// The arangod.conf file contains all settings that are considered static for the lifetime of the server.
5063
func createArangodConf(log zerolog.Logger, bsCfg BootstrapConfig, myHostDir, myContainerDir, myPort string, serverType ServerType, features DatabaseFeatures) ([]Volume, configFile, error) {
@@ -216,6 +229,13 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC
216229
optionPair{"--cluster.my-role", "SINGLE"},
217230
)
218231
}
232+
if serverType == ServerTypeCoordinator || serverType == ServerTypeResilientSingle {
233+
if config.AdvertisedEndpoint != "" {
234+
options = append(options,
235+
optionPair{"--cluster.my-advertised-endpoint", fixupEndpointURLSchemeForArangod(config.AdvertisedEndpoint)},
236+
)
237+
}
238+
}
219239
if serverType != ServerTypeAgent && serverType != ServerTypeSingle {
220240
for _, p := range clusterConfig.AllAgents() {
221241
options = append(options,

service/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Config struct {
5959
ArangodPath string
6060
ArangodJSPath string
6161
ArangoSyncPath string
62+
AdvertisedEndpoint string
6263
MasterPort int
6364
RrPath string
6465
DataDir string

0 commit comments

Comments
 (0)