rob05c commented on a change in pull request #5247:
URL: https://github.com/apache/trafficcontrol/pull/5247#discussion_r525517027



##########
File path: lib/go-atscfg/remapdotconfig.go
##########
@@ -35,81 +34,104 @@ const CacheKeyParameterConfigFile = "cachekey.config"
 const ContentTypeRemapDotConfig = ContentTypeTextASCII
 const LineCommentRemapDotConfig = LineCommentHash
 
+const RemapConfigRangeDirective = `__RANGE_DIRECTIVE__`
+
 func MakeRemapDotConfig(
-       server *tc.ServerNullable,
-       unfilteredDSes []tc.DeliveryServiceNullableV30,
+       server *Server,
+       unfilteredDSes []DeliveryService,
        dss []tc.DeliveryServiceServer,
        dsRegexArr []tc.DeliveryServiceRegexes,
        serverParams []tc.Parameter,
        cdn *tc.CDN,
-       toToolName string, // tm.toolname global parameter (TODO: cache itself?)
-       toURL string, // tm.url global parameter (TODO: cache itself?)
        cacheKeyParams []tc.Parameter,
        topologies []tc.Topology,
        cacheGroupArr []tc.CacheGroupNullable,
        serverCapabilities map[int]map[ServerCapability]struct{},
        dsRequiredCapabilities map[int]map[ServerCapability]struct{},
-) string {
+       hdrComment string,
+) (Cfg, error) {
+       warnings := []string{}
        if server.HostName == nil {
-               return "ERROR: server HostName missing"
+               return Cfg{}, makeErr(warnings, "server HostName missing")
        } else if server.ID == nil {
-               return "ERROR: server ID missing"
+               return Cfg{}, makeErr(warnings, "server ID missing")
        } else if server.Cachegroup == nil {
-               return "ERROR: server Cachegroup missing"
+               return Cfg{}, makeErr(warnings, "server Cachegroup missing")
        } else if server.DomainName == nil {
-               return "ERROR: server DomainName missing"
+               return Cfg{}, makeErr(warnings, "server DomainName missing")
        }
 
        cdnDomain := cdn.DomainName
        dsRegexes := makeDSRegexMap(dsRegexArr)
        // Returned DSes are guaranteed to have a non-nil XMLID, Type, DSCP, 
ID, and Active.
-       dses := remapFilterDSes(server, dss, unfilteredDSes, cacheKeyParams)
+       dses, dsWarns := remapFilterDSes(server, dss, unfilteredDSes, 
cacheKeyParams)
+       warnings = append(warnings, dsWarns...)
 
-       dsProfilesCacheKeyConfigParams, err := 
makeDSProfilesCacheKeyConfigParams(server, dses, cacheKeyParams)
+       dsProfilesCacheKeyConfigParams, paramWarns, err := 
makeDSProfilesCacheKeyConfigParams(server, dses, cacheKeyParams)
+       warnings = append(warnings, paramWarns...)
        if err != nil {
-               log.Errorln("Error making Delivery Service Cache Key Params, 
cache key will be missing! : " + err.Error())
+               warnings = append(warnings, "making Delivery Service Cache Key 
Params, cache key will be missing! : "+err.Error())
        }
 
-       atsMajorVersion := getATSMajorVersion(serverParams)
-       serverPackageParamData := makeServerPackageParamData(server, 
serverParams)
-       cacheURLConfigParams := ParamsToMap(FilterParams(serverParams, 
CacheURLParameterConfigFile, "", "", ""))
-       cacheGroups, err := MakeCGMap(cacheGroupArr)
+       atsMajorVersion, verWarns := getATSMajorVersion(serverParams)
+       warnings = append(warnings, verWarns...)
+       serverPackageParamData, paramWarns := 
makeServerPackageParamData(server, serverParams)
+       warnings = append(warnings, paramWarns...)
+       cacheURLConfigParams, paramWarns := 
paramsToMap(filterParams(serverParams, CacheURLParameterConfigFile, "", "", ""))
+       warnings = append(warnings, paramWarns...)
+       cacheGroups, err := makeCGMap(cacheGroupArr)
        if err != nil {
-               log.Errorln("making remap.config, config will be malformed! : " 
+ err.Error())
+               return Cfg{}, makeErr(warnings, "making remap.config, config 
will be malformed! : "+err.Error())
        }
 
-       nameTopologies := MakeTopologyNameMap(topologies)
+       nameTopologies := makeTopologyNameMap(topologies)
 
-       hdr := GenericHeaderComment(*server.HostName, toToolName, toURL)
+       hdr := makeHdrComment(hdrComment)
+       txt := ""
+       typeWarns := []string{}
        if tc.CacheTypeFromString(server.Type) == tc.CacheTypeMid {
-               return GetServerConfigRemapDotConfigForMid(atsMajorVersion, 
dsProfilesCacheKeyConfigParams, dses, dsRegexes, hdr, server, nameTopologies, 
cacheGroups, serverCapabilities, dsRequiredCapabilities)
+               txt, typeWarns, err = 
getServerConfigRemapDotConfigForMid(atsMajorVersion, 
dsProfilesCacheKeyConfigParams, dses, dsRegexes, hdr, server, nameTopologies, 
cacheGroups, serverCapabilities, dsRequiredCapabilities)
+       } else {
+               txt, typeWarns, err = 
getServerConfigRemapDotConfigForEdge(cacheURLConfigParams, 
dsProfilesCacheKeyConfigParams, serverPackageParamData, dses, dsRegexes, 
atsMajorVersion, hdr, server, nameTopologies, cacheGroups, serverCapabilities, 
dsRequiredCapabilities, cdnDomain)
        }
-       return GetServerConfigRemapDotConfigForEdge(cacheURLConfigParams, 
dsProfilesCacheKeyConfigParams, serverPackageParamData, dses, dsRegexes, 
atsMajorVersion, hdr, server, nameTopologies, cacheGroups, serverCapabilities, 
dsRequiredCapabilities, cdnDomain)
+       warnings = append(warnings, typeWarns...)
+       if err != nil {
+               return Cfg{}, makeErr(warnings, err.Error()) // the GetFor 
funcs include error context
+       }
+
+       return Cfg{
+               Text:        txt,
+               ContentType: ContentTypeRemapDotConfig,
+               LineComment: LineCommentRemapDotConfig,
+               Warnings:    warnings,
+       }, nil
 }
 
-func GetServerConfigRemapDotConfigForMid(
+// GetServerConfigRemapDotConfigForMid returns the remap lines, any warnings, 
and any error.

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to