From 116bb4750b87e8964c30f739cfe5d28e4a5b4f15 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 12:27:36 -0700 Subject: [PATCH 01/13] Add GoDoc --- lib/go-tc/crconfig.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/go-tc/crconfig.go b/lib/go-tc/crconfig.go index c4eaa48e31..4d30af9932 100644 --- a/lib/go-tc/crconfig.go +++ b/lib/go-tc/crconfig.go @@ -199,11 +199,13 @@ type CRConfigMonitor struct { ServerStatus *CRConfigServerStatus `json:"status,omitempty"` } +// CRConfigStats is the type of the 'stats' property of a CDN Snapshot. type CRConfigStats struct { CDNName *string `json:"CDN_name,omitempty"` DateUnixSeconds *int64 `json:"date,omitempty"` TMHost *string `json:"tm_host,omitempty"` - TMPath *string `json:"tm_path,omitempty"` - TMUser *string `json:"tm_user,omitempty"` - TMVersion *string `json:"tm_version,omitempty"` + // Deprecated: Don't ever use this for anything. It's been removed from APIv4 responses. + TMPath *string `json:"tm_path,omitempty"` + TMUser *string `json:"tm_user,omitempty"` + TMVersion *string `json:"tm_version,omitempty"` } From 38c32d208443893fd8ca2662b3a0fe1da848ce11 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 12:36:10 -0700 Subject: [PATCH 02/13] Remove checking for specific value of tm_path in CRConfig tests below v4 --- traffic_ops/testing/api/v1/crconfig_test.go | 5 +---- traffic_ops/testing/api/v2/crconfig_test.go | 5 +---- traffic_ops/testing/api/v3/crconfig_test.go | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/traffic_ops/testing/api/v1/crconfig_test.go b/traffic_ops/testing/api/v1/crconfig_test.go index e02a0c8da7..0143470237 100644 --- a/traffic_ops/testing/api/v1/crconfig_test.go +++ b/traffic_ops/testing/api/v1/crconfig_test.go @@ -17,7 +17,6 @@ package v1 import ( "encoding/json" - "strings" "testing" "github.com/apache/trafficcontrol/lib/go-tc" @@ -113,9 +112,7 @@ func UpdateTestCRConfigSnapshot(t *testing.T) { } if crc.Stats.TMPath == nil { - t.Errorf("GetCRConfig crc.Stats.Path expected: 'snapshot/"+cdn+"', actual: %+v", crc.Stats.TMPath) - } else if !strings.HasSuffix(*crc.Stats.TMPath, "snapshot/"+cdn) { - t.Errorf("GetCRConfig crc.Stats.Path expected: '/snapshot"+cdn+"', actual: %+v", *crc.Stats.TMPath) + t.Errorf("GetCRConfig crc.Stats.Path expected: some string (but deprecated so we don't check the contents), actual: null") } if crc.Stats.TMHost == nil { diff --git a/traffic_ops/testing/api/v2/crconfig_test.go b/traffic_ops/testing/api/v2/crconfig_test.go index c5d2c5772c..16eb0567b4 100644 --- a/traffic_ops/testing/api/v2/crconfig_test.go +++ b/traffic_ops/testing/api/v2/crconfig_test.go @@ -17,7 +17,6 @@ package v2 import ( "encoding/json" - "strings" "testing" "github.com/apache/trafficcontrol/lib/go-tc" @@ -113,9 +112,7 @@ func UpdateTestCRConfigSnapshot(t *testing.T) { } if crc.Stats.TMPath == nil { - t.Errorf("GetCRConfig crc.Stats.Path expected: '/snapshot', actual: %+v", crc.Stats.TMPath) - } else if !strings.HasSuffix(*crc.Stats.TMPath, "snapshot") { - t.Errorf("GetCRConfig crc.Stats.Path expected: '/snapshot', actual: %+v", *crc.Stats.TMPath) + t.Error("GetCRConfig crc.Stats.Path expected: some non-null string (but we don't check contents because it's deprecated), actual: null") } if crc.Stats.TMHost == nil { diff --git a/traffic_ops/testing/api/v3/crconfig_test.go b/traffic_ops/testing/api/v3/crconfig_test.go index 1a651f7324..64473a6b0d 100644 --- a/traffic_ops/testing/api/v3/crconfig_test.go +++ b/traffic_ops/testing/api/v3/crconfig_test.go @@ -17,7 +17,6 @@ package v3 import ( "encoding/json" - "strings" "testing" "github.com/apache/trafficcontrol/lib/go-tc" @@ -114,9 +113,7 @@ func UpdateTestCRConfigSnapshot(t *testing.T) { } if crc.Stats.TMPath == nil { - t.Errorf("GetCRConfig crc.Stats.Path expected: '/snapshot', actual: %+v", crc.Stats.TMPath) - } else if !strings.HasSuffix(*crc.Stats.TMPath, "snapshot") { - t.Errorf("GetCRConfig crc.Stats.Path expected: '/snapshot', actual: %+v", *crc.Stats.TMPath) + t.Error("GetCRConfig crc.Stats.Path expected: some non-null string (but we don't check contents because it's deprecated), actual: null") } if crc.Stats.TMHost == nil { From 6c847172b475f71f8feccc1d810a387cfad19695 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 12:38:15 -0700 Subject: [PATCH 03/13] Fix v4 tests checking for non-nil tm_path --- traffic_ops/testing/api/v4/crconfig_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/traffic_ops/testing/api/v4/crconfig_test.go b/traffic_ops/testing/api/v4/crconfig_test.go index 8cf98d67fd..6d44ecaadd 100644 --- a/traffic_ops/testing/api/v4/crconfig_test.go +++ b/traffic_ops/testing/api/v4/crconfig_test.go @@ -17,7 +17,6 @@ package v4 import ( "encoding/json" - "strings" "testing" "github.com/apache/trafficcontrol/lib/go-tc" @@ -113,10 +112,8 @@ func UpdateTestCRConfigSnapshot(t *testing.T) { } } - if crc.Stats.TMPath == nil { - t.Errorf("GetCRConfig crc.Stats.Path expected: '/snapshot', actual: %+v", crc.Stats.TMPath) - } else if !strings.HasSuffix(*crc.Stats.TMPath, "snapshot") { - t.Errorf("GetCRConfig crc.Stats.Path expected: '/snapshot', actual: %+v", *crc.Stats.TMPath) + if crc.Stats.TMPath != nil { + t.Errorf("Expected no TMPath in APIv4, but it was: %v", *crc.Stats.TMPath) } if crc.Stats.TMHost == nil { From 3a0bbc2fb9c845889303d0f8b27777846a2da310 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 12:39:51 -0700 Subject: [PATCH 04/13] Remove tm_path from APIv4, add dummy values to <= v3 (not stored when snapshots taken) --- .../traffic_ops_golang/crconfig/crconfig.go | 8 +++--- .../traffic_ops_golang/crconfig/handler.go | 25 ++++++++++++++----- .../traffic_ops_golang/crconfig/stats.go | 3 +-- .../traffic_ops_golang/crconfig/stats_test.go | 3 +-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/traffic_ops/traffic_ops_golang/crconfig/crconfig.go b/traffic_ops/traffic_ops_golang/crconfig/crconfig.go index c89f93b599..f252b9c20f 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/crconfig.go +++ b/traffic_ops/traffic_ops_golang/crconfig/crconfig.go @@ -30,7 +30,7 @@ import ( ) // Make creates and returns the CRConfig from the database. -func Make(tx *sql.Tx, cdn, user, toHost, reqPath, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) { +func Make(tx *sql.Tx, cdn, user, toHost, toVersion string, useClientReqHost bool, emulateOldPath bool) (*tc.CRConfig, error) { crc := tc.CRConfig{} err := error(nil) @@ -67,11 +67,11 @@ func Make(tx *sql.Tx, cdn, user, toHost, reqPath, toVersion string, useClientReq toHost = getTMURLHost(paramTMURL) } + crc.Stats = makeStats(cdn, user, toHost, toVersion) if emulateOldPath { - reqPath = "/tools/write_crconfig/" + cdn + crc.Stats.TMPath = new(string) + *crc.Stats.TMPath = "/tools/write_crconfig/" + cdn } - - crc.Stats = makeStats(cdn, user, toHost, reqPath, toVersion) return &crc, nil } diff --git a/traffic_ops/traffic_ops_golang/crconfig/handler.go b/traffic_ops/traffic_ops_golang/crconfig/handler.go index c37dae491c..2a48b41206 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/handler.go +++ b/traffic_ops/traffic_ops_golang/crconfig/handler.go @@ -23,6 +23,7 @@ import ( "database/sql" "encoding/json" "errors" + "fmt" "net/http" "net/url" "strconv" @@ -48,7 +49,8 @@ func Handler(w http.ResponseWriter, r *http.Request) { defer inf.Close() start := time.Now() - crConfig, err := Make(inf.Tx.Tx, inf.Params["cdn"], inf.User.UserName, r.Host, r.URL.Path, inf.Config.Version, inf.Config.CRConfigUseRequestHost, inf.Config.CRConfigEmulateOldPath) + emulate := inf.Config.CRConfigEmulateOldPath || inf.Version.Major < 4 + crConfig, err := Make(inf.Tx.Tx, inf.Params["cdn"], inf.User.UserName, r.Host, inf.Config.Version, inf.Config.CRConfigUseRequestHost, emulate) if err != nil { api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err) return @@ -75,8 +77,17 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) { api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, errors.New("CDN not found"), nil) return } - w.Header().Set(rfc.ContentType, rfc.ApplicationJSON) - w.Write([]byte(`{"response":` + snapshot + `}`)) + + var decoded tc.CRConfig + if err = json.Unmarshal([]byte(snapshot), &decoded); err != nil { + api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err)) + } + + if inf.Version.Major < 4 { + decoded.Stats.TMPath = new(string) + *decoded.Stats.TMPath = fmt.Sprintf("/api/4.0/cdns/%s/snapshot", inf.Params["cdn"]) + } + api.WriteResp(w, r, decoded) } func SnapshotGetMonitoringLegacyHandler(w http.ResponseWriter, r *http.Request) { @@ -214,7 +225,8 @@ func snapshotHandler(w http.ResponseWriter, r *http.Request, deprecated bool) { } } - crConfig, err := Make(inf.Tx.Tx, cdn, inf.User.UserName, r.Host, r.URL.Path, inf.Config.Version, inf.Config.CRConfigUseRequestHost, inf.Config.CRConfigEmulateOldPath) + // We never store tm_path, even though low API versions show it in responses. + crConfig, err := Make(inf.Tx.Tx, cdn, inf.User.UserName, r.Host, inf.Config.Version, inf.Config.CRConfigUseRequestHost, false) if err != nil { api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err, deprecated, &alt) return @@ -243,7 +255,7 @@ func snapshotHandler(w http.ResponseWriter, r *http.Request, deprecated bool) { api.WriteResp(w, r, "SUCCESS") } -// SnapshotGUIHandler creates the CRConfig JSON and writes it to the snapshot table in the database. The response emulates the old Perl UI function. This should go away when the old Perl UI ceases to exist. +// SnapshotOldGUIHandler creates the CRConfig JSON and writes it to the snapshot table in the database. The response emulates the old Perl UI function. This should go away when the old Perl UI ceases to exist. func SnapshotOldGUIHandler(w http.ResponseWriter, r *http.Request) { inf, userErr, sysErr, _ := api.NewInfo(r, []string{"cdn"}, nil) if userErr != nil || sysErr != nil { @@ -260,7 +272,8 @@ func SnapshotOldGUIHandler(w http.ResponseWriter, r *http.Request) { cdn := inf.Params["cdn"] - crConfig, err := Make(inf.Tx.Tx, cdn, inf.User.UserName, r.Host, r.URL.Path, inf.Config.Version, inf.Config.CRConfigUseRequestHost, inf.Config.CRConfigEmulateOldPath) + // We never store tm_path, even though low API versions show it in responses. + crConfig, err := Make(inf.Tx.Tx, cdn, inf.User.UserName, r.Host, inf.Config.Version, inf.Config.CRConfigUseRequestHost, false) if err != nil { writePerlHTMLErr(w, r, inf.Tx.Tx, errors.New(r.RemoteAddr+" making CRConfig: "+err.Error()), err) return diff --git a/traffic_ops/traffic_ops_golang/crconfig/stats.go b/traffic_ops/traffic_ops_golang/crconfig/stats.go index d17b98e61d..480cf27166 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/stats.go +++ b/traffic_ops/traffic_ops_golang/crconfig/stats.go @@ -25,13 +25,12 @@ import ( "github.com/apache/trafficcontrol/lib/go-tc" ) -func makeStats(cdn string, user string, host string, path string, version string) tc.CRConfigStats { +func makeStats(cdn string, user string, host string, version string) tc.CRConfigStats { epoch := time.Now().Unix() return tc.CRConfigStats{ CDNName: &cdn, DateUnixSeconds: &epoch, TMHost: &host, - TMPath: &path, TMUser: &user, TMVersion: &version, } diff --git a/traffic_ops/traffic_ops_golang/crconfig/stats_test.go b/traffic_ops/traffic_ops_golang/crconfig/stats_test.go index 8a31a7b429..96e66f96e6 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/stats_test.go +++ b/traffic_ops/traffic_ops_golang/crconfig/stats_test.go @@ -31,7 +31,6 @@ func ExpectedMakeStats() tc.CRConfigStats { return tc.CRConfigStats{ CDNName: randStr(), TMHost: randStr(), - TMPath: randStr(), TMUser: randStr(), TMVersion: randStr(), } @@ -40,7 +39,7 @@ func ExpectedMakeStats() tc.CRConfigStats { func TestMakeStats(t *testing.T) { expected := ExpectedMakeStats() start := time.Now() - actual := makeStats(*expected.CDNName, *expected.TMUser, *expected.TMHost, *expected.TMPath, *expected.TMVersion) + actual := makeStats(*expected.CDNName, *expected.TMUser, *expected.TMHost, *expected.TMVersion) end := time.Now() expected.DateUnixSeconds = actual.DateUnixSeconds if !reflect.DeepEqual(expected, actual) { From 367414a6d8d51561fa7e24b46d6e8b206b836fd8 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 12:40:51 -0700 Subject: [PATCH 05/13] Remove tm_path references from TR tests --- traffic_router/core/src/test/resources/publish/CrConfig.json | 2 -- traffic_router/core/src/test/resources/publish/CrConfig2.json | 2 -- traffic_router/core/src/test/resources/publish/CrConfig3.json | 2 -- traffic_router/core/src/test/resources/publish/CrConfig4.json | 2 -- 4 files changed, 8 deletions(-) diff --git a/traffic_router/core/src/test/resources/publish/CrConfig.json b/traffic_router/core/src/test/resources/publish/CrConfig.json index c9e8cab453..29080e802d 100644 --- a/traffic_router/core/src/test/resources/publish/CrConfig.json +++ b/traffic_router/core/src/test/resources/publish/CrConfig.json @@ -1855,7 +1855,6 @@ "tm_version": "1.5.0-3027.8d600a8e", "CDN_name": "thecdn", "tm_user": "admin1", - "tm_path": "/tools/write_crconfig/thecdn", "date": 1465084800, "tm_host": "localhost:8889" }, @@ -1961,4 +1960,3 @@ "edge.http.routing": "true" } } - diff --git a/traffic_router/core/src/test/resources/publish/CrConfig2.json b/traffic_router/core/src/test/resources/publish/CrConfig2.json index 12f949becb..191480fe61 100644 --- a/traffic_router/core/src/test/resources/publish/CrConfig2.json +++ b/traffic_router/core/src/test/resources/publish/CrConfig2.json @@ -1162,7 +1162,6 @@ "tm_version": "1.5.0-3027.8d600a8e", "CDN_name": "thecdn", "tm_user": "admin2", - "tm_path": "/tools/write_crconfig/thecdn", "date": 1465171200, "tm_host": "localhost:8889" }, @@ -1251,4 +1250,3 @@ "dnssec.enabled": "false" } } - diff --git a/traffic_router/core/src/test/resources/publish/CrConfig3.json b/traffic_router/core/src/test/resources/publish/CrConfig3.json index 52ed5cf493..ac25ab394c 100644 --- a/traffic_router/core/src/test/resources/publish/CrConfig3.json +++ b/traffic_router/core/src/test/resources/publish/CrConfig3.json @@ -1213,7 +1213,6 @@ "tm_version": "1.5.0-3027.8d600a8e", "CDN_name": "thecdn", "tm_user": "admin3", - "tm_path": "/tools/write_crconfig/thecdn", "date": 1465257600, "tm_host": "localhost:8889" }, @@ -1302,4 +1301,3 @@ "dnssec.enabled": "false" } } - diff --git a/traffic_router/core/src/test/resources/publish/CrConfig4.json b/traffic_router/core/src/test/resources/publish/CrConfig4.json index 1f27b410a6..08fcecb8e8 100644 --- a/traffic_router/core/src/test/resources/publish/CrConfig4.json +++ b/traffic_router/core/src/test/resources/publish/CrConfig4.json @@ -1207,7 +1207,6 @@ "tm_version": "1.5.0-3027.8d600a8e", "CDN_name": "thecdn", "tm_user": "admin4", - "tm_path": "/tools/write_crconfig/thecdn", "date": 1465344000, "tm_host": "localhost:8889" }, @@ -1296,4 +1295,3 @@ "dnssec.enabled": "false" } } - From f137c484901509586051f284b7449caf6258d002 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 12:45:45 -0700 Subject: [PATCH 06/13] Add deprecation notices for tm_path in API versions < 4 --- docs/source/api/v1/cdns_name_snapshot.rst | 5 +++++ docs/source/api/v2/cdns_name_snapshot.rst | 4 ++++ docs/source/api/v2/cdns_name_snapshot_new.rst | 5 +++++ docs/source/api/v3/cdns_name_snapshot.rst | 5 +++++ docs/source/api/v3/cdns_name_snapshot_new.rst | 5 +++++ 5 files changed, 24 insertions(+) diff --git a/docs/source/api/v1/cdns_name_snapshot.rst b/docs/source/api/v1/cdns_name_snapshot.rst index 746d41d1f9..7edd9d482a 100644 --- a/docs/source/api/v1/cdns_name_snapshot.rst +++ b/docs/source/api/v1/cdns_name_snapshot.rst @@ -321,6 +321,11 @@ Response Structure :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN + + .. deprecated:: ATCv5.1 + + This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 + :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version diff --git a/docs/source/api/v2/cdns_name_snapshot.rst b/docs/source/api/v2/cdns_name_snapshot.rst index bcdc07b7a5..6a68704850 100644 --- a/docs/source/api/v2/cdns_name_snapshot.rst +++ b/docs/source/api/v2/cdns_name_snapshot.rst @@ -315,6 +315,10 @@ Response Structure :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN + .. deprecated:: ATCv5.1 + + This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 + :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version diff --git a/docs/source/api/v2/cdns_name_snapshot_new.rst b/docs/source/api/v2/cdns_name_snapshot_new.rst index dfe2dbd5c5..3c645f2a34 100644 --- a/docs/source/api/v2/cdns_name_snapshot_new.rst +++ b/docs/source/api/v2/cdns_name_snapshot_new.rst @@ -314,6 +314,11 @@ Response Structure :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN + + .. deprecated:: ATCv5.1 + + This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 + :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version diff --git a/docs/source/api/v3/cdns_name_snapshot.rst b/docs/source/api/v3/cdns_name_snapshot.rst index 90cc14109e..498a389b08 100644 --- a/docs/source/api/v3/cdns_name_snapshot.rst +++ b/docs/source/api/v3/cdns_name_snapshot.rst @@ -317,6 +317,11 @@ Response Structure :CDN_name: The name of this CDN :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server + + .. deprecated:: ATCv5.1 + + This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 + :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version diff --git a/docs/source/api/v3/cdns_name_snapshot_new.rst b/docs/source/api/v3/cdns_name_snapshot_new.rst index 23c8507c06..82b47ab1ed 100644 --- a/docs/source/api/v3/cdns_name_snapshot_new.rst +++ b/docs/source/api/v3/cdns_name_snapshot_new.rst @@ -318,6 +318,11 @@ Response Structure :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN + + .. deprecated:: ATCv5.1 + + This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 + :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version From 1af1ee2d893e88b50acb56942398cd283ebd8d44 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 12:45:56 -0700 Subject: [PATCH 07/13] Remove tm_path from APIv4 docs --- docs/source/api/v4/cdns_name_snapshot.rst | 2 -- docs/source/api/v4/cdns_name_snapshot_new.rst | 2 -- 2 files changed, 4 deletions(-) diff --git a/docs/source/api/v4/cdns_name_snapshot.rst b/docs/source/api/v4/cdns_name_snapshot.rst index 7aeb245111..b8371b0489 100644 --- a/docs/source/api/v4/cdns_name_snapshot.rst +++ b/docs/source/api/v4/cdns_name_snapshot.rst @@ -317,7 +317,6 @@ Response Structure :CDN_name: The name of this CDN :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server - :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version @@ -541,7 +540,6 @@ Response Structure "CDN_name": "CDN-in-a-Box", "date": 1590600715, "tm_host": "trafficops.infra.ciab.test:443", - "tm_path": "/api/4.0/snapshot", "tm_user": "admin", "tm_version": "development" }, diff --git a/docs/source/api/v4/cdns_name_snapshot_new.rst b/docs/source/api/v4/cdns_name_snapshot_new.rst index 2419f76d4c..066e5deb8a 100644 --- a/docs/source/api/v4/cdns_name_snapshot_new.rst +++ b/docs/source/api/v4/cdns_name_snapshot_new.rst @@ -317,7 +317,6 @@ Response Structure :CDN_name: The name of this CDN :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server - :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version @@ -555,7 +554,6 @@ Response Structure "CDN_name": "CDN-in-a-Box", "date": 1590607873, "tm_host": "trafficops.infra.ciab.test:443", - "tm_path": "/api/4.0/cdns/CDN-in-a-Box/snapshot/new", "tm_user": "admin", "tm_version": "development" }, From 4aa31d5096ff6b5396eb3e4874e6963e94709e7f Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 27 Jan 2021 13:14:20 -0700 Subject: [PATCH 08/13] Add migration to remove existing tm_paths --- .../2021012600000000_remove_tm_path.sql | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 traffic_ops/app/db/migrations/2021012600000000_remove_tm_path.sql diff --git a/traffic_ops/app/db/migrations/2021012600000000_remove_tm_path.sql b/traffic_ops/app/db/migrations/2021012600000000_remove_tm_path.sql new file mode 100644 index 0000000000..25f38cec46 --- /dev/null +++ b/traffic_ops/app/db/migrations/2021012600000000_remove_tm_path.sql @@ -0,0 +1,23 @@ +/* + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +-- +goose Up +UPDATE snapshot +SET crconfig = crconfig::jsonb #- '{stats,tm_path}' +WHERE crconfig::jsonb ? 'stats' AND (crconfig::jsonb -> 'stats') ? 'tm_path'; + +-- +goose Down +UPDATE snapshot SET crconfig = jsonb_set(crconfig::jsonb, '{stats,tm_path}', ('"/api/4.0/cdns/' || (crconfig::jsonb -> 'stats' ->> 'CDN_name') || '/snapshot"')::jsonb) +WHERE crconfig::jsonb ? 'stats' AND (crconfig::jsonb -> 'stats') ? 'CDN_name'; From 2b8f37bf751a0e8ebfc5aaa6027087334480cf6e Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Jan 2021 11:31:12 -0700 Subject: [PATCH 09/13] Fix migration order --- ...000_remove_tm_path.sql => 2021012800000000_remove_tm_path.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename traffic_ops/app/db/migrations/{2021012600000000_remove_tm_path.sql => 2021012800000000_remove_tm_path.sql} (100%) diff --git a/traffic_ops/app/db/migrations/2021012600000000_remove_tm_path.sql b/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql similarity index 100% rename from traffic_ops/app/db/migrations/2021012600000000_remove_tm_path.sql rename to traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql From 0a8588d13a5b60b4a4e399f78798c340984cfb1e Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 3 Feb 2021 16:07:26 -0700 Subject: [PATCH 10/13] Add deprecation notice to snapshot_new v1 docs --- docs/source/api/v1/cdns_name_snapshot_new.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/source/api/v1/cdns_name_snapshot_new.rst b/docs/source/api/v1/cdns_name_snapshot_new.rst index 479fd5975b..3d3143d904 100644 --- a/docs/source/api/v1/cdns_name_snapshot_new.rst +++ b/docs/source/api/v1/cdns_name_snapshot_new.rst @@ -320,6 +320,11 @@ Response Structure :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN + + .. deprecated:: ATCv5.1 + + This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 + :tm_user: The username of the currently logged-in user :tm_version: The full version number of the Traffic Ops server, including release number, git commit hash, and supported Enterprise Linux version From da8532214152d375badf365bb734bf0dc62e3cb0 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 3 Feb 2021 16:08:20 -0700 Subject: [PATCH 11/13] Change deprecation notices to be the correct version --- docs/source/api/v1/cdns_name_snapshot.rst | 2 +- docs/source/api/v1/cdns_name_snapshot_new.rst | 2 +- docs/source/api/v2/cdns_name_snapshot.rst | 2 +- docs/source/api/v2/cdns_name_snapshot_new.rst | 2 +- docs/source/api/v3/cdns_name_snapshot.rst | 2 +- docs/source/api/v3/cdns_name_snapshot_new.rst | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/api/v1/cdns_name_snapshot.rst b/docs/source/api/v1/cdns_name_snapshot.rst index 7edd9d482a..8699ea6e72 100644 --- a/docs/source/api/v1/cdns_name_snapshot.rst +++ b/docs/source/api/v1/cdns_name_snapshot.rst @@ -322,7 +322,7 @@ Response Structure :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN - .. deprecated:: ATCv5.1 + .. deprecated:: ATCv6 This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 diff --git a/docs/source/api/v1/cdns_name_snapshot_new.rst b/docs/source/api/v1/cdns_name_snapshot_new.rst index 3d3143d904..0e58819182 100644 --- a/docs/source/api/v1/cdns_name_snapshot_new.rst +++ b/docs/source/api/v1/cdns_name_snapshot_new.rst @@ -321,7 +321,7 @@ Response Structure :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN - .. deprecated:: ATCv5.1 + .. deprecated:: ATCv6 This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 diff --git a/docs/source/api/v2/cdns_name_snapshot.rst b/docs/source/api/v2/cdns_name_snapshot.rst index 6a68704850..c3e3fedff2 100644 --- a/docs/source/api/v2/cdns_name_snapshot.rst +++ b/docs/source/api/v2/cdns_name_snapshot.rst @@ -315,7 +315,7 @@ Response Structure :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN - .. deprecated:: ATCv5.1 + .. deprecated:: ATCv6 This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 diff --git a/docs/source/api/v2/cdns_name_snapshot_new.rst b/docs/source/api/v2/cdns_name_snapshot_new.rst index 3c645f2a34..17b4591bbc 100644 --- a/docs/source/api/v2/cdns_name_snapshot_new.rst +++ b/docs/source/api/v2/cdns_name_snapshot_new.rst @@ -315,7 +315,7 @@ Response Structure :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN - .. deprecated:: ATCv5.1 + .. deprecated:: ATCv6 This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 diff --git a/docs/source/api/v3/cdns_name_snapshot.rst b/docs/source/api/v3/cdns_name_snapshot.rst index 498a389b08..354c150376 100644 --- a/docs/source/api/v3/cdns_name_snapshot.rst +++ b/docs/source/api/v3/cdns_name_snapshot.rst @@ -318,7 +318,7 @@ Response Structure :date: The UNIX epoch timestamp date in the Traffic Ops server's own timezone :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server - .. deprecated:: ATCv5.1 + .. deprecated:: ATCv6 This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 diff --git a/docs/source/api/v3/cdns_name_snapshot_new.rst b/docs/source/api/v3/cdns_name_snapshot_new.rst index 82b47ab1ed..588360ac3d 100644 --- a/docs/source/api/v3/cdns_name_snapshot_new.rst +++ b/docs/source/api/v3/cdns_name_snapshot_new.rst @@ -319,7 +319,7 @@ Response Structure :tm_host: The :abbr:`FQDN (Fully Qualified Domain Name)` of the Traffic Ops server :tm_path: A path relative to the root of the Traffic Ops server where a request may be replaced to have this :term:`Snapshot` overwritten by the current *configured state* of the CDN - .. deprecated:: ATCv5.1 + .. deprecated:: ATCv6 This information should never be used; instead all tools and (especially) components **must** use the documented API. This field was removed in APIv4 From 5f05b9f4da3e068d13a4f824f9de9e021e5098c4 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 3 Feb 2021 16:13:05 -0700 Subject: [PATCH 12/13] Add migration comment --- .../migrations/2021012800000000_remove_tm_path.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql b/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql index 25f38cec46..ec9288d41d 100644 --- a/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql +++ b/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.sql @@ -13,6 +13,18 @@ limitations under the License. */ +/* +This migration removes the 'tm_path' property from the 'stats' property of the +'crconfig' column of stored CDN Snapshots, if it exists. + +When reverted, it will insert (if possible) a 'tm_path' value of +/api/4.0/cdns/{{CDN Name}}/snapshot +where 'CDN Name' is the name of the CDN snapshotted as determined by the +Snapshot data - NOT the linked CDN object. This is so it does not self-confilct +afterward regarding which CDN is named, even if the one to which it is linked +is wrong, somehow. +*/ + -- +goose Up UPDATE snapshot SET crconfig = crconfig::jsonb #- '{stats,tm_path}' From d9bdd01da22bc8c653acff747c0dd94018dfbd7d Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 3 Feb 2021 18:04:56 -0700 Subject: [PATCH 13/13] Add configuration check for emulating legacy paths --- traffic_ops/traffic_ops_golang/crconfig/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/traffic_ops_golang/crconfig/handler.go b/traffic_ops/traffic_ops_golang/crconfig/handler.go index 2a48b41206..3aec8fc2ae 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/handler.go +++ b/traffic_ops/traffic_ops_golang/crconfig/handler.go @@ -83,7 +83,7 @@ func SnapshotGetHandler(w http.ResponseWriter, r *http.Request) { api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("failed to unmarshal stored snapshot for cdn '%s': %v", inf.Params["cdn"], err)) } - if inf.Version.Major < 4 { + if inf.Version.Major < 4 || (inf.Config != nil && inf.Config.CRConfigEmulateOldPath) { decoded.Stats.TMPath = new(string) *decoded.Stats.TMPath = fmt.Sprintf("/api/4.0/cdns/%s/snapshot", inf.Params["cdn"]) }