Commit 6ec27aed authored by Stefan Dähling's avatar Stefan Dähling
Browse files

use module switches in agency

parent ea342ae5
Pipeline #272622 passed with stages
in 1 minute and 10 seconds
...@@ -47,6 +47,7 @@ package agency ...@@ -47,6 +47,7 @@ package agency
import ( import (
"errors" "errors"
"log" "log"
"os"
"sync" "sync"
"time" "time"
...@@ -61,12 +62,19 @@ type DF struct { ...@@ -61,12 +62,19 @@ type DF struct {
nodeID int nodeID int
mutex *sync.Mutex mutex *sync.Mutex
registeredServices map[string]schemas.Service registeredServices map[string]schemas.Service
active bool // indicates if df is active (switch via env)
logError *log.Logger logError *log.Logger
logInfo *log.Logger logInfo *log.Logger
} }
// RegisterService registers a new service with the DF // RegisterService registers a new service with the DF
func (df *DF) RegisterService(svc schemas.Service) (id string, err error) { func (df *DF) RegisterService(svc schemas.Service) (id string, err error) {
df.mutex.Lock()
if !df.active {
df.mutex.Unlock()
return
}
df.mutex.Unlock()
id = "-1" id = "-1"
if svc.Desc == "" { if svc.Desc == "" {
err = errors.New("Empty description not allowed") err = errors.New("Empty description not allowed")
...@@ -103,6 +111,10 @@ func (df *DF) RegisterService(svc schemas.Service) (id string, err error) { ...@@ -103,6 +111,10 @@ func (df *DF) RegisterService(svc schemas.Service) (id string, err error) {
// SearchForService search for a service with given description // SearchForService search for a service with given description
func (df *DF) SearchForService(desc string) (svc []schemas.Service, err error) { func (df *DF) SearchForService(desc string) (svc []schemas.Service, err error) {
df.mutex.Lock() df.mutex.Lock()
if !df.active {
df.mutex.Unlock()
return
}
masID := df.masID masID := df.masID
df.mutex.Unlock() df.mutex.Unlock()
var temp []schemas.Service var temp []schemas.Service
...@@ -121,6 +133,10 @@ func (df *DF) SearchForService(desc string) (svc []schemas.Service, err error) { ...@@ -121,6 +133,10 @@ func (df *DF) SearchForService(desc string) (svc []schemas.Service, err error) {
// SearchForLocalService search for a service with given description // SearchForLocalService search for a service with given description
func (df *DF) SearchForLocalService(desc string, dist float64) (svc []schemas.Service, err error) { func (df *DF) SearchForLocalService(desc string, dist float64) (svc []schemas.Service, err error) {
df.mutex.Lock() df.mutex.Lock()
if !df.active {
df.mutex.Unlock()
return
}
masID := df.masID masID := df.masID
nodeID := df.nodeID nodeID := df.nodeID
df.mutex.Unlock() df.mutex.Unlock()
...@@ -139,6 +155,12 @@ func (df *DF) SearchForLocalService(desc string, dist float64) (svc []schemas.Se ...@@ -139,6 +155,12 @@ func (df *DF) SearchForLocalService(desc string, dist float64) (svc []schemas.Se
// DeregisterService registers a new service with the DF // DeregisterService registers a new service with the DF
func (df *DF) DeregisterService(svcID string) (err error) { func (df *DF) DeregisterService(svcID string) (err error) {
df.mutex.Lock()
if !df.active {
df.mutex.Unlock()
return
}
df.mutex.Unlock()
desc := "" desc := ""
df.mutex.Lock() df.mutex.Lock()
masID := df.masID masID := df.masID
...@@ -167,9 +189,14 @@ func newDF(masID int, agentID int, nodeID int, logErr *log.Logger, logInf *log.L ...@@ -167,9 +189,14 @@ func newDF(masID int, agentID int, nodeID int, logErr *log.Logger, logInf *log.L
masID: masID, masID: masID,
nodeID: nodeID, nodeID: nodeID,
mutex: &sync.Mutex{}, mutex: &sync.Mutex{},
active: false,
logError: logErr, logError: logErr,
logInfo: logInf, logInfo: logInf,
} }
act := os.Getenv("CLONEMAP_DF")
if act == "ON" {
df.active = true
}
df.registeredServices = make(map[string]schemas.Service) df.registeredServices = make(map[string]schemas.Service)
return return
} }
...@@ -46,6 +46,7 @@ package agency ...@@ -46,6 +46,7 @@ package agency
import ( import (
"errors" "errors"
"fmt"
"log" "log"
"os" "os"
"sync" "sync"
...@@ -139,6 +140,10 @@ func (log *loggerClient) storeLogs() (err error) { ...@@ -139,6 +140,10 @@ func (log *loggerClient) storeLogs() (err error) {
} }
} }
} }
} else {
// print messages to stdout if logger is turned off
logMsg := <-log.logIn
fmt.Println(logMsg)
} }
return return
} }
......
...@@ -317,7 +317,7 @@ func (stub *LocalStub) createAgency(image string, masID int, imID int, agencyID ...@@ -317,7 +317,7 @@ func (stub *LocalStub) createAgency(image string, masID int, imID int, agencyID
} else { } else {
com += " -e CLONEMAP_DF=\"OFF\" " com += " -e CLONEMAP_DF=\"OFF\" "
} }
com += " -e CLONEMAP_LOG_LEVEL=\"error\" " com += " -e CLONEMAP_LOG_LEVEL=\"info\" "
com += image com += image
cmd := exec.Command("bash", "-c", com) cmd := exec.Command("bash", "-c", com)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment