rob05c commented on a change in pull request #5247:
URL: https://github.com/apache/trafficcontrol/pull/5247#discussion_r524812082
##########
File path: lib/go-atscfg/cachedotconfig.go
##########
@@ -23,33 +23,95 @@ import (
"sort"
"strings"
- "github.com/apache/trafficcontrol/lib/go-log"
"github.com/apache/trafficcontrol/lib/go-tc"
)
const ContentTypeCacheDotConfig = ContentTypeTextASCII
const LineCommentCacheDotConfig = LineCommentHash
-type ProfileDS struct {
- Type tc.DSType
- OriginFQDN *string
+func MakeCacheDotConfig(
+ server *tc.ServerNullable,
+ servers []tc.ServerNullable,
+ deliveryServices []tc.DeliveryServiceNullableV30,
+ deliveryServiceServers []tc.DeliveryServiceServer,
+ hdrComment string,
+) (Cfg, error) {
+ if tc.CacheTypeFromString(server.Type) == tc.CacheTypeMid {
+ return makeCacheDotConfigMid(server, deliveryServices,
hdrComment)
+ } else {
+ return makeCacheDotConfigEdge(server, servers,
deliveryServices, deliveryServiceServers, hdrComment)
+ }
}
// MakeCacheDotConfig makes the ATS cache.config config file.
// profileDSes must be the list of delivery services, which are assigned to
severs, for which this profile is assigned. It MUST NOT contain any other
delivery services. Note DSesToProfileDSes may be helpful if you have a
[]tc.DeliveryServiceNullable, for example from traffic_ops/client.
-func MakeCacheDotConfig(
- profileName string,
- profileDSes []ProfileDS,
- toToolName string, // tm.toolname global parameter (TODO: cache itself?)
- toURL string, // tm.url global parameter (TODO: cache itself?)
-) string {
+func makeCacheDotConfigEdge(
+ server *tc.ServerNullable,
+ servers []tc.ServerNullable,
+ deliveryServices []tc.DeliveryServiceNullableV30,
+ deliveryServiceServers []tc.DeliveryServiceServer,
+ hdrComment string,
+) (Cfg, error) {
+ warnings := []string{}
+
+ if server.Profile == nil {
+ return Cfg{}, makeErr(warnings, "server missing profile")
+ }
+
+ profileServerIDsMap := map[int]struct{}{}
+ for _, sv := range servers {
+ if sv.Profile == nil {
+ warnings = append(warnings, "servers had server with
nil profile, skipping!")
+ continue
+ }
+ if sv.ID == nil {
+ warnings = append(warnings, "servers had server with
nil id, skipping!")
+ continue
+ }
+ if *sv.Profile != *server.Profile {
+ continue
+ }
+ profileServerIDsMap[*sv.ID] = struct{}{}
+ }
+
+ dsServers := filterDSS(deliveryServiceServers, nil, profileServerIDsMap)
+
+ dsIDs := map[int]struct{}{}
+ for _, dss := range dsServers {
+ if dss.Server == nil || dss.DeliveryService == nil {
+ continue // TODO warn? err?
+ }
+ if _, ok := profileServerIDsMap[*dss.Server]; !ok {
+ continue
+ }
+ dsIDs[*dss.DeliveryService] = struct{}{}
+ }
+
+ profileDSes := []profileDS{}
+ for _, ds := range deliveryServices {
+ if ds.ID == nil || ds.Type == nil || ds.OrgServerFQDN == nil {
+ continue // TODO warn? err?
+ }
+ if *ds.Type == tc.DSTypeInvalid {
+ continue // TODO warn? err?
+ }
+ if *ds.OrgServerFQDN == "" {
+ continue // TODO warn? err?
+ }
Review comment:
Yeah, moved from before it had the ability to return warnings, and I
missed changing it. 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]