General afrouter cleanup.
- Separated backend.go into multiple files.
- Replaced array indexing hack with enum pattern.
- Various renaming for better consistency.
- Removed a few unused structs.
- Replaced a thread with an atomic operation.
Change-Id: I2239692cac21ddb7f513b6d8c247ffa8789714ac
diff --git a/afrouter/afrouter/api.go b/afrouter/afrouter/api.go
index 36e79a3..87f5573 100644
--- a/afrouter/afrouter/api.go
+++ b/afrouter/afrouter/api.go
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-// gRPC affinity router with active/active backends
package afrouter
@@ -46,7 +45,7 @@
log.Errorf("Invalid address '%s' provided for API server", config.Addr)
rtrn_err = true
}
- if rtrn_err == true {
+ if rtrn_err {
return nil, errors.New("Errors in API configuration")
} else {
var err error = nil
@@ -66,7 +65,7 @@
}
func (aa *ArouterApi) getServer(srvr string) (*server, error) {
- if s, ok := aa.ar.servers[srvr]; ok == false {
+ if s, ok := aa.ar.servers[srvr]; !ok {
err := errors.New(fmt.Sprintf("Server '%s' doesn't exist", srvr))
return nil, err
} else {
@@ -86,7 +85,7 @@
return nil, err
}
-func (aa *ArouterApi) getCluster(s *server, clstr string) (*backendCluster, error) {
+func (aa *ArouterApi) getCluster(s *server, clstr string) (*cluster, error) {
for _, pkg := range s.routers {
for _, r := range pkg {
if c := r.FindBackendCluster(clstr); c != nil {
@@ -98,7 +97,7 @@
return nil, err
}
-func (aa *ArouterApi) getBackend(c *backendCluster, bknd string) (*backend, error) {
+func (aa *ArouterApi) getBackend(c *cluster, bknd string) (*backend, error) {
for _, b := range c.backends {
if b.name == bknd {
return b, nil
@@ -109,8 +108,8 @@
return nil, err
}
-func (aa *ArouterApi) getConnection(b *backend, con string) (*beConnection, error) {
- if c, ok := b.connections[con]; ok == false {
+func (aa *ArouterApi) getConnection(b *backend, con string) (*connection, error) {
+ if c, ok := b.connections[con]; !ok {
err := errors.New(fmt.Sprintf("Connection '%s' doesn't exist", con))
return nil, err
} else {
@@ -118,14 +117,13 @@
}
}
-func (aa *ArouterApi) updateConnection(in *pb.Conn, cn *beConnection, b *backend) error {
+func (aa *ArouterApi) updateConnection(in *pb.Conn, cn *connection, b *backend) error {
sPort := strconv.FormatUint(in.Port, 10)
// Check that the ip address and or port are different
if in.Addr == cn.addr && sPort == cn.port {
err := errors.New(fmt.Sprintf("Refusing to change connection '%s' to identical values", in.Connection))
return err
}
- //log.Debugf("BEFORE: Be1: %v Be2 %v", cn.bknd, b)
cn.close()
cn.addr = in.Addr
cn.port = sPort
@@ -146,7 +144,7 @@
_ = aap
log.Debugf("Getting router %s and route %s", in.Router, in.Route)
- if r, ok := allRouters[in.Router+in.Route]; ok == true {
+ if r, ok := allRouters[in.Router+in.Route]; ok {
switch rr := r.(type) {
case AffinityRouter:
log.Debug("Affinity router found")
@@ -177,9 +175,9 @@
// not the same then close the existing connection. If they are bothe the same
// then return an error describing the situation.
var s *server
- var c *backendCluster
+ var c *cluster
var b *backend
- var cn *beConnection
+ var cn *connection
var err error
log.Debugf("SetConnection called! %v", in)