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 @@
"Mode": "static",
"Receiver": {
"MaxConnections": 32,
"StaticEndpoints": [ "localhost:8411" ]
"StaticEndpoints": [ "0.0.0.0:8411" ]
},
"Broker": {
"StaticEndpoint": "localhost:8413"
"StaticEndpoint": "0.0.0.0:8413"
},
"Mongo": {
"StaticEndpoint": "localhost:27017"
"StaticEndpoint": "0.0.0.0:27017"
},
"FileTransferService": {
"StaticEndpoint": "localhost:8414"
"StaticEndpoint": "0.0.0.0:8414"
},
"Monitoring": {
"StaticEndpoint": "localhost:8420"
"StaticEndpoint": "0.0.0.0:8420"
},
"Port": 8410,
"LogLevel": "info"
......
package common
import "errors"
import (
log "asapo_common/logger"
"errors"
"os"
"strings"
)
type ReceiverInfo struct {
StaticEndpoints []string
MaxConnections int
UseIBAddress bool
StaticEndpoints []string
MaxConnections int
UseIBAddress bool
}
type MonitoringInfo struct {
StaticEndpoint string
StaticEndpoint string
}
type BrokerInfo struct {
StaticEndpoint string
StaticEndpoint string
}
type MongoInfo struct {
StaticEndpoint string
StaticEndpoint string
}
type FtsInfo struct {
StaticEndpoint string
StaticEndpoint string
}
type Settings struct {
Receiver ReceiverInfo
Broker BrokerInfo
Monitoring MonitoringInfo
Mongo MongoInfo
FileTransferService FtsInfo
ConsulEndpoints []string
Mode string
Kubernetes struct {
Mode string
Receiver ReceiverInfo
Broker BrokerInfo
Monitoring MonitoringInfo
Mongo MongoInfo
FileTransferService FtsInfo
ConsulEndpoints []string
Mode string
Kubernetes struct {
Mode string
ConfigFile string
Namespace string
Namespace string
}
Port int
LogLevel string
Port int
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 {
if settings.Mode == "static"{
if len(settings.Receiver.StaticEndpoints) == 0 || len(settings.Broker.StaticEndpoint) == 0 || len(settings.Mongo.StaticEndpoint) == 0{
if settings.Mode == "static" {
if len(settings.Receiver.StaticEndpoints) == 0 || len(settings.Broker.StaticEndpoint) == 0 || len(settings.Mongo.StaticEndpoint) == 0 {
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 {
......@@ -61,7 +99,7 @@ func (settings *Settings) Validate() error {
}
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
......
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