You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2020/11/25 20:43:24 UTC

[trafficcontrol] 01/04: Removing atscfg as a dependency in traffic_ops_golang (#5312)

This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch 5.0.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit e52754ef3a30194d6a88f9f53ba0d3d3e257fdd3
Author: Myles B <47...@users.noreply.github.com>
AuthorDate: Fri Nov 20 12:06:48 2020 -0700

    Removing atscfg as a dependency in traffic_ops_golang (#5312)
    
    * fulfilling #5301: removing atscfg as a dependency in traffic_ops_golang
    
    - necessary consts moved into `traffic_ops_golang/server/servers_assignment.go`
    - GetConfigFile added to `` and renamed to getConfigFile (isn't used elsewhere in package)
    
    * implemented requested changes, documented additional unused lines
    
    - Threw a few todo comments in atscfg.go
    - Changed multiline string to a backtick wrapped one to save concats
    - Inlined constants as as string literals (they were not used elsewhere)
    
    * reintroduced suffixes/prefixes as constants at fxn level
    
    (cherry picked from commit aaf8007631fde617685b736bd8af81622652f0b8)
---
 lib/go-atscfg/atscfg.go                             |  7 +++----
 .../traffic_ops_golang/server/servers_assignment.go | 21 ++++++++++++++++-----
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/lib/go-atscfg/atscfg.go b/lib/go-atscfg/atscfg.go
index b572dc6..66da3c7 100644
--- a/lib/go-atscfg/atscfg.go
+++ b/lib/go-atscfg/atscfg.go
@@ -33,6 +33,7 @@ import (
 
 const InvalidID = -1
 const DefaultATSVersion = "5" // TODO Emulates Perl; change to 6? ATC no longer officially supports ATS 5.
+// todo also unused
 const HeaderCommentDateFormat = "Mon Jan 2 15:04:05 MST 2006"
 const ContentTypeTextASCII = `text/plain; charset=us-ascii`
 const LineCommentHash = "#"
@@ -243,6 +244,7 @@ func trimParamUnderscoreNumSuffix(paramName string) string {
 }
 
 // topologyIncludesServer returns whether the given topology includes the given server.
+// todo also unused
 func topologyIncludesServer(topology tc.Topology, server *tc.Server) bool {
 	for _, node := range topology.Nodes {
 		if node.Cachegroup == server.Cachegroup {
@@ -607,10 +609,7 @@ func makeErr(warnings []string, err string) error {
 }
 
 // makeErrf is a convenience for formatting errors for makeErr.
+// todo also unused, maybe remove?
 func makeErrf(warnings []string, format string, v ...interface{}) error {
 	return makeErr(warnings, fmt.Sprintf(format, v...))
 }
-
-func GetConfigFile(prefix string, xmlId string) string {
-	return prefix + xmlId + ConfigSuffix
-}
diff --git a/traffic_ops/traffic_ops_golang/server/servers_assignment.go b/traffic_ops/traffic_ops_golang/server/servers_assignment.go
index d9c4fd9..6218369 100644
--- a/traffic_ops/traffic_ops_golang/server/servers_assignment.go
+++ b/traffic_ops/traffic_ops_golang/server/servers_assignment.go
@@ -28,7 +28,6 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/apache/trafficcontrol/lib/go-atscfg"
 	"github.com/apache/trafficcontrol/lib/go-log"
 	"github.com/apache/trafficcontrol/lib/go-tc"
 	"github.com/apache/trafficcontrol/lib/go-util"
@@ -58,6 +57,11 @@ LEFT OUTER JOIN cdn ON cdn.id=deliveryservice.cdn_id
 WHERE deliveryservice.id = ANY($1)
 `
 
+func getConfigFile(prefix string, xmlId string) string {
+	const configSuffix = `.config`
+	return prefix + xmlId + configSuffix
+}
+
 func AssignDeliveryServicesToServerHandler(w http.ResponseWriter, r *http.Request) {
 	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"id"}, []string{"id"})
 	if userErr != nil || sysErr != nil {
@@ -269,7 +273,11 @@ INSERT INTO deliveryservice_server (deliveryservice, server)
 
 	//need remap config location
 	var atsConfigLocation string
-	if err := tx.QueryRow("SELECT value FROM parameter WHERE name = 'location' AND config_file = '" + atscfg.RemapFile + "'").Scan(&atsConfigLocation); err != nil {
+	const remapFile = `remap.config`
+	if err := tx.QueryRow(
+		`SELECT value FROM parameter
+		WHERE name = 'location'
+		AND config_file = '` + remapFile + `'`).Scan(&atsConfigLocation); err != nil {
 		return nil, errors.New("scanning location parameter: " + err.Error())
 	}
 	if strings.HasSuffix(atsConfigLocation, "/") {
@@ -299,21 +307,24 @@ INSERT INTO deliveryservice_server (deliveryservice, server)
 		if err := rows.Scan(&xmlID, &edgeHeaderRewrite, &regexRemap, &cacheURL); err != nil {
 			return nil, errors.New("scanning deliveryservice: " + err.Error())
 		}
+		const headerRewritePrefix = `hdr_rw_`
+		const regexRemapPrefix = `regex_remap_`
+		const cacheURLPrefix = `cacheurl_`
 		if xmlID.Valid && len(xmlID.String) > 0 {
 			//param := "hdr_rw_" + xmlID.String + ".config"
-			param := atscfg.GetConfigFile(atscfg.HeaderRewritePrefix, xmlID.String)
+			param := getConfigFile(headerRewritePrefix, xmlID.String)
 			if edgeHeaderRewrite.Valid && len(edgeHeaderRewrite.String) > 0 {
 				insert = append(insert, param)
 			} else {
 				delete = append(delete, param)
 			}
-			param = atscfg.GetConfigFile(atscfg.RegexRemapPrefix, xmlID.String)
+			param = getConfigFile(regexRemapPrefix, xmlID.String)
 			if regexRemap.Valid && len(regexRemap.String) > 0 {
 				insert = append(insert, param)
 			} else {
 				delete = append(delete, param)
 			}
-			param = atscfg.GetConfigFile(atscfg.CacheUrlPrefix, xmlID.String)
+			param = getConfigFile(cacheURLPrefix, xmlID.String)
 			if cacheURL.Valid && len(cacheURL.String) > 0 {
 				insert = append(insert, param)
 			} else {