44 "context"
55 "flag"
66 "fmt"
7+ "github.com/serverledge-faas/serverledge/internal/config"
78 "log"
89 "os"
910 "os/exec"
@@ -40,48 +41,37 @@ func getShellExt() string {
4041 }
4142}
4243
43- func testStartServerledge (isInCloud bool , outboundIp string ) ( * registration. Registry , * echo.Echo ) {
44+ func testStartServerledge (isInCloud bool , outboundIp string ) * echo.Echo {
4445 //setting up cache parameters
4546 api .CacheSetup ()
4647 schedulingPolicy := & scheduling.DefaultLocalPolicy {}
4748 // register to etcd, this way server is visible to the others under a given local area
48- registry := new (registration.Registry )
49- if isInCloud {
50- registry .Area = "cloud/" + AREA
51- } else {
52- registry .Area = AREA
53- }
54- // before register checkout other servers into the local area
55- _ , err := registry .GetAll (true )
56- if err != nil {
57- log .Fatal (err )
58- }
49+ myArea := config .GetString (config .REGISTRY_AREA , "ROME" )
50+ node .LocalNode = node .NewIdentifier (myArea )
5951
60- myKey , err := registry . RegisterToEtcd ()
52+ err := registration . RegisterNode ()
6153 if err != nil {
6254 log .Fatal (err )
6355 }
6456
65- node .LocalNode = myKey
66-
6757 metrics .Init ()
6858
6959 e := echo .New ()
7060
7161 // Register a signal handler to cleanup things on termination
72- api .RegisterTerminationHandler (registry , e )
62+ api .RegisterTerminationHandler (e )
7363
7464 go scheduling .Run (schedulingPolicy )
7565
7666 if ! isInCloud {
77- err = registration .StartMonitoring (registry )
67+ err = registration .StartMonitoring ()
7868 if err != nil {
7969 log .Fatal (err )
8070 }
8171 }
8272 // needed: if you call a function composition, internally will invoke each function
8373 go api .StartAPIServer (e )
84- return registry , e
74+ return e
8575
8676}
8777
@@ -96,7 +86,7 @@ func TestMain(m *testing.M) {
9686
9787 // TODO: avoid full setup if testing.Short()
9888
99- registry , echoServer , ok := setupServerledge (outboundIp .String ())
89+ echoServer , ok := setupServerledge (outboundIp .String ())
10090 if ok != nil {
10191 fmt .Printf ("failed to initialize serverledgde: %v\n " , ok )
10292 os .Exit (int (codes .Internal ))
@@ -106,7 +96,7 @@ func TestMain(m *testing.M) {
10696 code := m .Run ()
10797
10898 // tear down containers in order
109- err = teardownServerledge (registry , echoServer )
99+ err = teardownServerledge (echoServer )
110100 if err != nil {
111101 fmt .Printf ("failed to remove serverledgde: %v\n " , err )
112102 }
@@ -130,14 +120,14 @@ func startReliably(startScript string, stopScript string, msg string) error {
130120}
131121
132122// run the bash script to initialize serverledge
133- func setupServerledge (outboundIp string ) (* registration. Registry , * echo.Echo , error ) {
123+ func setupServerledge (outboundIp string ) (* echo.Echo , error ) {
134124 _ = startReliably ("../../scripts/start-etcd" + getShellExt (), "../../scripts/stop-etcd" + getShellExt (), "ETCD" )
135- registry , echoServer := testStartServerledge (false , outboundIp )
136- return registry , echoServer , nil
125+ echoServer := testStartServerledge (false , outboundIp )
126+ return echoServer , nil
137127}
138128
139129// run the bash script to stop serverledge
140- func teardownServerledge (registry * registration. Registry , e * echo.Echo ) error {
130+ func teardownServerledge (e * echo.Echo ) error {
141131 cmd1 := exec .CommandContext (context .Background (), getShell (), "../../scripts/remove-etcd" + getShellExt ())
142132
143133 node .ShutdownAllContainers ()
@@ -148,7 +138,7 @@ func teardownServerledge(registry *registration.Registry, e *echo.Echo) error {
148138 defer cancel ()
149139 errEcho := e .Shutdown (ctx )
150140
151- errRegistry := registry .Deregister ()
141+ errRegistry := registration .Deregister ()
152142 err1 := cmd1 .Run ()
153143 return u .ReturnNonNilErr (errEcho , errRegistry , err1 )
154144}
0 commit comments