You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2018/09/24 14:41:08 UTC
[trafficcontrol] branch master updated: Change TO client CRConfig
to use api, add snap
This is an automated email from the ASF dual-hosted git repository.
rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 61351bb Change TO client CRConfig to use api, add snap
61351bb is described below
commit 61351bbfe047e8928698f4c4653cb4aa27acfa3d
Author: Robert Butts <ro...@apache.org>
AuthorDate: Tue Sep 18 16:18:19 2018 -0600
Change TO client CRConfig to use api, add snap
---
traffic_ops/client/crconfig.go | 29 +++++++++--
traffic_ops/testing/api/v13/crconfig_test.go | 77 ++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 3 deletions(-)
diff --git a/traffic_ops/client/crconfig.go b/traffic_ops/client/crconfig.go
index 626ed43..2c7fb33 100644
--- a/traffic_ops/client/crconfig.go
+++ b/traffic_ops/client/crconfig.go
@@ -15,7 +15,10 @@
package client
-import "fmt"
+import (
+ "encoding/json"
+ "net/http"
+)
// CRConfigRaw Deprecated: use GetCRConfig instead
func (to *Session) CRConfigRaw(cdn string) ([]byte, error) {
@@ -23,8 +26,28 @@ func (to *Session) CRConfigRaw(cdn string) ([]byte, error) {
return bytes, err
}
+type OuterResponse struct {
+ Response json.RawMessage `json:"response"`
+}
+
// GetCRConfig returns the raw JSON bytes of the CRConfig from Traffic Ops, and whether the bytes were from the client's internal cache.
func (to *Session) GetCRConfig(cdn string) ([]byte, ReqInf, error) {
- url := fmt.Sprintf("/CRConfig-Snapshots/%s/CRConfig.json", cdn)
- return to.getBytesWithTTL(url, tmPollingInterval)
+ uri := apiBase + `/cdns/` + cdn + `/snapshot`
+ bts, reqInf, err := to.getBytesWithTTL(uri, tmPollingInterval)
+ if err != nil {
+ return nil, reqInf, err
+ }
+
+ resp := OuterResponse{}
+ if err := json.Unmarshal(bts, &resp); err != nil {
+ return nil, reqInf, err
+ }
+ return []byte(resp.Response), reqInf, nil
+}
+
+func (to *Session) SnapshotCRConfig(cdn string) (ReqInf, error) {
+ uri := apiBase + `/snapshot/` + cdn
+ _, remoteAddr, err := to.request(http.MethodPut, uri, nil)
+ reqInf := ReqInf{RemoteAddr: remoteAddr, CacheHitStatus: CacheHitStatusMiss}
+ return reqInf, err
}
diff --git a/traffic_ops/testing/api/v13/crconfig_test.go b/traffic_ops/testing/api/v13/crconfig_test.go
new file mode 100644
index 0000000..e9f0210
--- /dev/null
+++ b/traffic_ops/testing/api/v13/crconfig_test.go
@@ -0,0 +1,77 @@
+package v13
+
+/*
+
+ 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.
+*/
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+func TestCRConfig(t *testing.T) {
+ CreateTestCDNs(t)
+ CreateTestTypes(t)
+ CreateTestProfiles(t)
+ CreateTestStatuses(t)
+ CreateTestDivisions(t)
+ CreateTestRegions(t)
+ CreateTestPhysLocations(t)
+ CreateTestCacheGroups(t)
+ CreateTestServers(t)
+ CreateTestDeliveryServices(t)
+
+ UpdateTestCRConfigSnapshot(t)
+
+ DeleteTestDeliveryServices(t)
+ DeleteTestServers(t)
+ DeleteTestCacheGroups(t)
+ DeleteTestPhysLocations(t)
+ DeleteTestRegions(t)
+ DeleteTestDivisions(t)
+ DeleteTestStatuses(t)
+ DeleteTestProfiles(t)
+ DeleteTestTypes(t)
+ DeleteTestCDNs(t)
+}
+
+func UpdateTestCRConfigSnapshot(t *testing.T) {
+ log.Debugln("UpdateTestCRConfigSnapshot")
+
+ if len(testData.CDNs) < 1 {
+ t.Fatalf("no cdn test data")
+ }
+ cdn := testData.CDNs[0].Name
+ _, err := TOSession.SnapshotCRConfig(cdn)
+ if err != nil {
+ t.Fatalf("SnapshotCRConfig err expected nil, actual %+v", err)
+ }
+ crcBts, _, err := TOSession.GetCRConfig(cdn)
+ if err != nil {
+ t.Fatalf("GetCRConfig err expected nil, actual %+v", err)
+ }
+ crc := tc.CRConfig{}
+ if err := json.Unmarshal(crcBts, &crc); err != nil {
+ t.Fatalf("GetCRConfig bytes expected: valid tc.CRConfig, actual JSON unmarshal err: %+v", err)
+ }
+
+ if len(crc.DeliveryServices) == 0 {
+ t.Fatalf("GetCRConfig len(crc.DeliveryServices) expected: >0, actual: 0")
+ }
+
+ log.Debugln("UpdateTestCRConfigSnapshot() PASSED: ")
+}