Changes to add the read only cores and some fixes to bugs
for processing the config file.
Change-Id: I1393c05d4cbce215e97d1f17b13e044eda7ae472
diff --git a/afrouter/afrouter/backend.go b/afrouter/afrouter/backend.go
index 9262d43..8ec286e 100644
--- a/afrouter/afrouter/backend.go
+++ b/afrouter/afrouter/backend.go
@@ -78,6 +78,7 @@
strategy int
location int
field string // Used only if location is protobuf
+ key string
}
type beConnection struct {
@@ -125,7 +126,7 @@
var err error = nil
var rtrn_err bool = false
var be *backend
- log.Debug("Creating a backend cluster with %v", conf)
+ log.Debugf("Creating a backend cluster with %v", conf)
// Validate the configuration
if conf.Name == "" {
log.Error("A backend cluster must have a name")
@@ -598,6 +599,14 @@
rtrn_err = true
}
be.activeAssoc.field = conf.Association.Field
+
+ if conf.Association.Key == "" && be.activeAssoc.location == AL_HEADER {
+ log.Errorf("An association key must be provided if the backend "+
+ "type is active/active and the location is set to header "+
+ "for backend %s in cluster %s", conf.Name, clusterName)
+ rtrn_err = true
+ }
+ be.activeAssoc.key = conf.Association.Key
if rtrn_err {
return nil, errors.New("Backend configuration failed")
}
@@ -605,6 +614,15 @@
// Connections can consist of just a name. This allows for dynamic configuration
// at a later time.
// TODO: validate that there is one connection for all but active/active backends
+ if len(conf.Connections) > 1 && be.activeAssoc.strategy != BE_ACTIVE_ACTIVE {
+ log.Errorf("Only one connection must be specified if the association "+
+ "strategy is not set to 'active_active'")
+ rtrn_err = true
+ }
+ if len(conf.Connections) == 0 {
+ log.Errorf("At least one connection must be specified")
+ rtrn_err = true
+ }
for _,cnConf := range conf.Connections {
if cnConf.Name == "" {
log.Errorf("A connection must have a name for backend %s in cluster %s",
diff --git a/afrouter/afrouter/config.go b/afrouter/afrouter/config.go
index 528a3f7..a9a01eb 100644
--- a/afrouter/afrouter/config.go
+++ b/afrouter/afrouter/config.go
@@ -91,7 +91,7 @@
type OverrideConfig struct {
Methods []string `json:"methods"`
- Method []string `json:"method"`
+ Method string `json:"method"`
RouteField string `json:"routing_field"`
}
@@ -113,6 +113,7 @@
Strategy string `json:"strategy"`
Location string `json:"location"`
Field string `json:"field"`
+ Key string `json:"key"`
}
type ConnectionConfig struct {
@@ -183,7 +184,10 @@
return err
}
- json.Unmarshal(configBytes, conf)
+ if err := json.Unmarshal(configBytes, conf); err != nil {
+ log.Errorf("Unmarshaling of the configuratino file failed: %v", err)
+ return err
+ }
// Now resolve references to different config objects in the
// config file. Currently there are 2 possible references
diff --git a/afrouter/afrouter/helpers.go b/afrouter/afrouter/helpers.go
index 6235337..4d7362b 100644
--- a/afrouter/afrouter/helpers.go
+++ b/afrouter/afrouter/helpers.go
@@ -17,9 +17,11 @@
package afrouter
+//import "github.com/opencord/voltha-go/common/log"
+
func strIndex(ar []string, match string) int {
- for idx := range ar {
- if ar[idx] == match {
+ for idx,v := range ar {
+ if v == match {
return idx
}
}