diff --git a/deploy/asapo_services_light/discovery.json b/deploy/asapo_services_light/discovery.json index d249f418f61a3e3ff6b93f3b8d5481c06c4f1ad4..858f06d681f49dac5361b201177b0a6e9733506b 100644 --- a/deploy/asapo_services_light/discovery.json +++ b/deploy/asapo_services_light/discovery.json @@ -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" diff --git a/discovery/src/asapo_discovery/common/structs.go b/discovery/src/asapo_discovery/common/structs.go index e9826cb8c50f28ba772de2d701972f4b287c0097..ecedb4f95b6e111bcddb0f2e26ef044e97387aff 100644 --- a/discovery/src/asapo_discovery/common/structs.go +++ b/discovery/src/asapo_discovery/common/structs.go @@ -1,51 +1,89 @@ 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