You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/11/17 23:51:15 UTC
[GitHub] [trafficcontrol] rob05c commented on a change in pull request #6355: Make t3c jobs work with previous TO 4.0
rob05c commented on a change in pull request #6355:
URL: https://github.com/apache/trafficcontrol/pull/6355#discussion_r751773414
##########
File path: cache-config/t3cutil/toreq/conversions.go
##########
@@ -40,3 +48,93 @@ func dsesToLatest(dses []tc.DeliveryServiceV40) []atscfg.DeliveryService {
func jobsToLatest(jobs []tc.InvalidationJobV4) []atscfg.InvalidationJob {
return atscfg.ToInvalidationJobs(jobs)
}
+
+// GetJobsCompat gets jobs from any Traffic Ops built from the ATC `master` branch, and converts the different formats to the latest.
+// This makes t3c work with old or new Traffic Ops deployed from `master`,
+// though it doesn't make a version of t3c older than this work with a new TO,
+// which isn't logically possible from the client.
+func (cl *TOClient) GetJobsCompat(opts toclient.RequestOptions) (tc.InvalidationJobsResponseV4, toclientlib.ReqInf, error) {
+ path := "/jobs"
+
+ objs := struct {
+ Response []InvalidationJobV4PlusLegacy `json:"response"`
+ tc.Alerts
+ }{}
+
+ if len(opts.QueryParameters) > 0 {
+ path += "?" + opts.QueryParameters.Encode()
+ }
+ reqInf, err := cl.c.TOClient.Req(http.MethodGet, path, nil, opts.Header, &objs)
+ if err != nil {
+ return tc.InvalidationJobsResponseV4{}, reqInf, errors.New("request: " + err.Error())
+ }
+
+ resp := tc.InvalidationJobsResponseV4{Alerts: objs.Alerts}
+ for _, job := range objs.Response {
+ newJob, err := InvalidationJobV4FromLegacy(job) // (InvalidationJobV4, error) {
+ if err != nil {
+ return tc.InvalidationJobsResponseV4{}, reqInf, errors.New("converting job from possible legacy format: " + err.Error())
+ }
+ resp.Response = append(resp.Response, newJob)
+ }
+ return resp, reqInf, nil
+}
+
+// InvalidationJobV4ForLegacy is a type alias to prevent MarshalJSON recursion.
+type InvalidationJobV4ForLegacy tc.InvalidationJobV4
+
+// InvalidationJobV4PlusLegacy has the data to deserialize both the latest and older versions that Traffic Ops could return.
+type InvalidationJobV4PlusLegacy struct {
+ StartTime *string `json:"startTime"`
Review comment:
Yes. Added.
##########
File path: cache-config/t3cutil/toreq/clientfuncs.go
##########
@@ -531,7 +531,7 @@ func (cl *TOClient) GetJobs(reqHdr http.Header, cdnName string) ([]atscfg.Invali
opts := *ReqOpts(reqHdr)
opts.QueryParameters.Set("maxRevalDurationDays", "") // only get jobs with a start time within the window defined by the GLOBAL parameter 'maxRevalDurationDays'
opts.QueryParameters.Set("cdn", cdnName) // only get jobs for delivery services in this server's CDN
- toJobs, toReqInf, err := cl.c.GetInvalidationJobs(opts)
+ toJobs, toReqInf, err := cl.GetJobsCompat(opts)
Review comment:
Added.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org