Skip to content
Snippets Groups Projects
Commit a86a3156 authored by Mikhail Karnevskiy's avatar Mikhail Karnevskiy
Browse files

Enable standalone service from the other nodes in the notwork. Discovery...

Enable standalone service from the other nodes in the notwork. Discovery substitutes service endpoints to the actual hostname if endpoint is equal to 0.0.0.0.
parent 3ec2d19b
No related branches found
No related tags found
No related merge requests found
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
"Mode": "static", "Mode": "static",
"Receiver": { "Receiver": {
"MaxConnections": 32, "MaxConnections": 32,
"StaticEndpoints": [ "localhost:8411" ] "StaticEndpoints": [ "0.0.0.0:8411" ]
}, },
"Broker": { "Broker": {
"StaticEndpoint": "localhost:8413" "StaticEndpoint": "0.0.0.0:8413"
}, },
"Mongo": { "Mongo": {
"StaticEndpoint": "localhost:27017" "StaticEndpoint": "0.0.0.0:27017"
}, },
"FileTransferService": { "FileTransferService": {
"StaticEndpoint": "localhost:8414" "StaticEndpoint": "0.0.0.0:8414"
}, },
"Monitoring": { "Monitoring": {
"StaticEndpoint": "localhost:8420" "StaticEndpoint": "0.0.0.0:8420"
}, },
"Port": 8410, "Port": 8410,
"LogLevel": "info" "LogLevel": "info"
......
package common package common
import "errors" import (
log "asapo_common/logger"
"errors"
"os"
"strings"
)
type ReceiverInfo struct { type ReceiverInfo struct {
StaticEndpoints []string StaticEndpoints []string
MaxConnections int MaxConnections int
UseIBAddress bool UseIBAddress bool
} }
type MonitoringInfo struct { type MonitoringInfo struct {
StaticEndpoint string StaticEndpoint string
} }
type BrokerInfo struct { type BrokerInfo struct {
StaticEndpoint string StaticEndpoint string
} }
type MongoInfo struct { type MongoInfo struct {
StaticEndpoint string StaticEndpoint string
} }
type FtsInfo struct { type FtsInfo struct {
StaticEndpoint string StaticEndpoint string
} }
type Settings struct { type Settings struct {
Receiver ReceiverInfo Receiver ReceiverInfo
Broker BrokerInfo Broker BrokerInfo
Monitoring MonitoringInfo Monitoring MonitoringInfo
Mongo MongoInfo Mongo MongoInfo
FileTransferService FtsInfo FileTransferService FtsInfo
ConsulEndpoints []string ConsulEndpoints []string
Mode string Mode string
Kubernetes struct { Kubernetes struct {
Mode string Mode string
ConfigFile string ConfigFile string
Namespace string Namespace string
} }
Port int Port int
LogLevel string LogLevel string
}
func (settings *Settings) setCurrentServer() error {
hostname, err := os.Hostname()
if err != nil {
return err
}
if settings.Receiver.StaticEndpoints[0] > "0.0.0.0" {
settings.Receiver.StaticEndpoints[0] = strings.Replace(settings.Receiver.StaticEndpoints[0], "0.0.0.0", hostname, 1)
log.Info("Replace Receiver server to " + hostname)
}
if settings.Broker.StaticEndpoint > "0.0.0.0" {
settings.Broker.StaticEndpoint = strings.Replace(settings.Broker.StaticEndpoint, "0.0.0.0", hostname, 1)
log.Info("Replace Broker server to " + hostname)
}
if settings.Monitoring.StaticEndpoint > "0.0.0.0" {
settings.Monitoring.StaticEndpoint = strings.Replace(settings.Monitoring.StaticEndpoint, "0.0.0.0", hostname, 1)
log.Info("Replace Monitoring server to " + hostname)
}
if settings.Mongo.StaticEndpoint > "0.0.0.0" {
settings.Mongo.StaticEndpoint = strings.Replace(settings.Mongo.StaticEndpoint, "0.0.0.0", hostname, 1)
log.Info("Replace Mongo server to " + hostname)
}
if settings.FileTransferService.StaticEndpoint > "0.0.0.0" {
settings.FileTransferService.StaticEndpoint = strings.Replace(settings.FileTransferService.StaticEndpoint, "0.0.0.0", hostname, 1)
log.Info("Replace FileTransferService server to " + hostname)
}
return nil
} }
func (settings *Settings) Validate() error { func (settings *Settings) Validate() error {
if settings.Mode == "static"{ if settings.Mode == "static" {
if len(settings.Receiver.StaticEndpoints) == 0 || len(settings.Broker.StaticEndpoint) == 0 || len(settings.Mongo.StaticEndpoint) == 0{ if len(settings.Receiver.StaticEndpoints) == 0 || len(settings.Broker.StaticEndpoint) == 0 || len(settings.Mongo.StaticEndpoint) == 0 {
return errors.New("static endpoints not set") return errors.New("static endpoints not set")
} }
err := settings.setCurrentServer()
if err != nil {
return errors.New("unable to get server name")
}
} }
if settings.Receiver.MaxConnections == 0 { if settings.Receiver.MaxConnections == 0 {
...@@ -61,7 +99,7 @@ func (settings *Settings) Validate() error { ...@@ -61,7 +99,7 @@ func (settings *Settings) Validate() error {
} }
if settings.Mode != "static" && settings.Mode != "consul" && settings.Mode != "kubernetes" { if settings.Mode != "static" && settings.Mode != "consul" && settings.Mode != "kubernetes" {
return errors.New("wrong mode: " + settings.Mode+ ", (allowed static|consul|kubernetes)") return errors.New("wrong mode: " + settings.Mode + ", (allowed static|consul|kubernetes)")
} }
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment