Skip to content

Commit 44b0f61

Browse files
committed
Configuration option for stable Node ID
1 parent 9c6ae1e commit 44b0f61

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

cmd/lb/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() {
4545
config.ReadConfiguration(configFileName)
4646

4747
myArea := config.GetString(config.REGISTRY_AREA, "ROME")
48-
node.LocalNode = node.NewIdentifier(myArea)
48+
node.LocalNode = node.NewRandomIdentifier(myArea)
4949

5050
err := registration.RegisterLoadBalancer()
5151
if err != nil {

cmd/serverledge/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ func main() {
3232

3333
// register to etcd, this way server is visible to the others under a given local area
3434
myArea := config.GetString(config.REGISTRY_AREA, "ROME")
35-
node.LocalNode = node.NewIdentifier(myArea)
35+
myId := config.GetString(config.REGISTRY_NODE_ID, "")
36+
if myId == "" {
37+
node.LocalNode = node.NewRandomIdentifier(myArea)
38+
} else {
39+
node.LocalNode = node.NewIdentifier(myId, myArea)
40+
}
3641

3742
err := registration.RegisterNode()
3843
if err != nil {

internal/config/keys.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@ const CACHE_CLEANUP = "cache.cleanup"
3232
// default expiration time assigned to a cache item (Seconds)
3333
const CACHE_ITEM_EXPIRATION = "cache.expiration"
3434

35-
// default policy is to persist cache (boolean). Use false in localonly deployments
36-
const CACHE_PERSISTENCE = "cache.persistence"
37-
38-
// true if the current server is a remote cloud server
39-
const IS_IN_CLOUD = "cloud"
40-
4135
// the area wich the server belongs to
4236
const REGISTRY_AREA = "registry.area"
4337

38+
// (optional) ID of this node (must be unique in the area!)
39+
const REGISTRY_NODE_ID = "registry.node.id"
40+
4441
// the area that acts as "remote cloud" for this node
4542
const REGISTRY_REMOTE_AREA = "registry.remote.area"
4643

internal/node/node.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ func (n NodeID) String() string {
2424
return fmt.Sprintf("(%s)%s", n.Area, n.Key)
2525
}
2626

27-
func NewIdentifier(area string) NodeID {
27+
func NewRandomIdentifier(area string) NodeID {
2828
id := shortuuid.New() + strconv.FormatInt(time.Now().UnixNano(), 10)
2929
return NodeID{Area: area, Key: id}
3030
}
3131

32+
func NewIdentifier(id, area string) NodeID {
33+
return NodeID{Area: area, Key: id}
34+
}
35+
3236
type Resources struct {
3337
sync.RWMutex
3438
totalMemory int64

internal/test/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func testStartServerledge(isInCloud bool, outboundIp string) *echo.Echo {
4747
schedulingPolicy := &scheduling.DefaultLocalPolicy{}
4848
// register to etcd, this way server is visible to the others under a given local area
4949
myArea := config.GetString(config.REGISTRY_AREA, "ROME")
50-
node.LocalNode = node.NewIdentifier(myArea)
50+
node.LocalNode = node.NewRandomIdentifier(myArea)
5151

5252
err := registration.RegisterNode()
5353
if err != nil {

0 commit comments

Comments
 (0)