Skip to content

Commit a38a062

Browse files
committed
[fix] Registration without Internet access
1 parent afb202a commit a38a062

8 files changed

Lines changed: 26 additions & 32 deletions

File tree

cmd/lb/main.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99

1010
"golang.org/x/net/context"
1111

12+
"github.com/labstack/echo/v4"
13+
"github.com/labstack/echo/v4/middleware"
1214
"github.com/serverledge-faas/serverledge/internal/config"
1315
"github.com/serverledge-faas/serverledge/internal/lb"
1416
"github.com/serverledge-faas/serverledge/internal/registration"
1517
"github.com/serverledge-faas/serverledge/utils"
16-
"github.com/labstack/echo/v4"
17-
"github.com/labstack/echo/v4/middleware"
1818
)
1919

2020
func registerTerminationHandler(e *echo.Echo) {
@@ -47,14 +47,15 @@ func main() {
4747
// TODO: split Area in Region + Type (e.g., cloud/lb/edge)
4848
region := config.GetString(config.REGISTRY_AREA, "ROME")
4949
registry := &registration.Registry{Area: "lb/" + region}
50-
ipAddress, err := utils.GetOutboundIp()
51-
if err != nil {
52-
log.Printf("Could not get ip address: %v\n", err)
53-
return
50+
51+
defaultAddressStr := "127.0.0.1"
52+
address, err := utils.GetOutboundIp()
53+
if err == nil {
54+
defaultAddressStr = address.String()
5455
}
56+
registration.RegisteredLocalIP = config.GetString(config.API_IP, defaultAddressStr)
5557

56-
hostport := fmt.Sprintf("http://%s:%d", ipAddress.String(), config.GetInt(config.API_PORT, 1323))
57-
if _, err := registry.RegisterToEtcd(hostport); err != nil {
58+
if _, err := registry.RegisterToEtcd(); err != nil {
5859
log.Printf("Could not register to Etcd: %v\n", err)
5960
}
6061

cmd/serverledge/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ func main() {
4646
log.Fatal(err)
4747
}
4848

49+
defaultAddressStr := "127.0.0.1"
4950
address, err := utils.GetOutboundIp()
50-
if err != nil {
51-
log.Fatalf("failed to get ip address: %v", err)
51+
if err == nil {
52+
defaultAddressStr = address.String()
5253
}
53-
ip := config.GetString(config.API_IP, address.String())
54-
url := fmt.Sprintf("http://%s:%d", ip, config.GetInt(config.API_PORT, 1323))
55-
myKey, err := registry.RegisterToEtcd(url)
54+
registration.RegisteredLocalIP = config.GetString(config.API_IP, defaultAddressStr)
55+
56+
myKey, err := registry.RegisterToEtcd()
5657
if err != nil {
5758
log.Fatal(err)
5859
}

internal/api/api.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ func GetServerStatus(c echo.Context) error {
214214

215215
portNumber := config.GetInt("api.port", 1323)
216216

217-
address, err := utils.GetOutboundIp()
218-
url := fmt.Sprintf("http://%s:%d", address.String(), portNumber)
217+
url := fmt.Sprintf("http://%s:%d", registration.RegisteredLocalIP, portNumber)
219218

220219
loadAvg, err := loadavg.Parse()
221220
loadAvgValues := []float64{-1.0, -1.0, -1.0}

internal/api/workflow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"errors"
77
"fmt"
88
"io"
9+
"log"
910
"net/http"
1011
"time"
1112

1213
"github.com/cornelk/hashmap"
1314
"github.com/labstack/echo/v4"
14-
"github.com/labstack/gommon/log"
1515
"github.com/serverledge-faas/serverledge/internal/client"
1616
"github.com/serverledge-faas/serverledge/internal/function"
1717
"github.com/serverledge-faas/serverledge/internal/node"
@@ -50,7 +50,7 @@ func CreateWorkflowFromASL(e echo.Context) error {
5050
comp, err := workflow.FromASL(creationRequest.Name, decodedSrc[:])
5151
if err != nil {
5252
log.Printf("Could not parse workflow from ASL: %v", err)
53-
return e.JSON(http.StatusBadRequest, "workflow already exists")
53+
return e.JSON(http.StatusBadRequest, "ASL parsing failed")
5454
}
5555

5656
err = comp.Save()

internal/registration/edgeNetUDPDiscovery.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ import (
1616
// UDPStatusServer listen for incoming request from other edge-nodes which want to retrieve the status of this server
1717
// this listener should be called asynchronously in the main function
1818
func UDPStatusServer() {
19-
hostname, err := utils.GetOutboundIp()
20-
if err != nil {
21-
log.Fatal(err)
22-
}
23-
19+
hostname := RegisteredLocalIP
2420
port := config.GetInt(config.LISTEN_UDP_PORT, 9876)
2521
address := fmt.Sprintf("%s:%d", hostname, port)
2622
udpAddr, err := net.ResolveUDPAddr("udp", address)

internal/registration/registry.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"strconv"
77
"time"
88

9+
"github.com/lithammer/shortuuid"
910
"github.com/serverledge-faas/serverledge/internal/config"
1011
"github.com/serverledge-faas/serverledge/utils"
11-
"github.com/lithammer/shortuuid"
1212
_ "go.etcd.io/etcd/client/v3"
1313
clientv3 "go.etcd.io/etcd/client/v3"
1414
"golang.org/x/net/context"
@@ -17,14 +17,16 @@ import (
1717
var BASEDIR = "registry"
1818
var TTL = config.GetInt(config.REGISTRATION_TTL, 20) // lease time in Seconds
1919

20+
var RegisteredLocalIP string = "127.0.0.1"
21+
2022
// getEtcdKey append to a given unique id the logical path depending on the Area.
2123
// If it is called with an empty string it returns the base path for the current local Area.
2224
func (r *Registry) getEtcdKey(id string) (key string) {
2325
return fmt.Sprintf("%s/%s/%s", BASEDIR, r.Area, id)
2426
}
2527

2628
// RegisterToEtcd make a registration to the local Area; etcd put operation is performed
27-
func (r *Registry) RegisterToEtcd(hostport string) (string, error) {
29+
func (r *Registry) RegisterToEtcd() (string, error) {
2830
etcdClient, err := utils.GetEtcdClient()
2931
if err != nil {
3032
log.Fatal(UnavailableClientErr)
@@ -41,6 +43,7 @@ func (r *Registry) RegisterToEtcd(hostport string) (string, error) {
4143
return "", err
4244
}
4345

46+
hostport := fmt.Sprintf("http://%s:%d", RegisteredLocalIP, config.GetInt(config.API_PORT, 1323))
4447
log.Printf("Registration key: %s\n", r.Key)
4548
// save couple (id, hostport) to the correct Area-dir on etcd
4649
_, err = etcdClient.Put(ctx, r.Key, hostport, clientv3.WithLease(resp.ID))

internal/test/main_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/labstack/echo/v4"
1414
"github.com/serverledge-faas/serverledge/internal/api"
15-
"github.com/serverledge-faas/serverledge/internal/config"
1615
"github.com/serverledge-faas/serverledge/internal/metrics"
1716
"github.com/serverledge-faas/serverledge/internal/node"
1817
"github.com/serverledge-faas/serverledge/internal/registration"
@@ -58,9 +57,7 @@ func testStartServerledge(isInCloud bool, outboundIp string) (*registration.Regi
5857
log.Fatal(err)
5958
}
6059

61-
ip := config.GetString(config.API_IP, outboundIp)
62-
url := fmt.Sprintf("http://%s:%d", ip, PORT)
63-
myKey, err := registry.RegisterToEtcd(url)
60+
myKey, err := registry.RegisterToEtcd()
6461
if err != nil {
6562
log.Fatal(err)
6663
}

utils/networking.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ func GetOutboundIp() (net.IP, error) {
1313
}
1414

1515
defer func() {
16-
err1 := conn.Close()
17-
if err1 != nil {
18-
panic(err1)
19-
}
16+
_ = conn.Close()
2017
}()
2118

2219
localAddr := conn.LocalAddr().(*net.UDPAddr)

0 commit comments

Comments
 (0)