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 2018/09/24 14:41:03 UTC

[GitHub] rawlinp closed pull request #2837: Change TO client CRConfig functions to use the api endpoints

rawlinp closed pull request #2837: Change TO client CRConfig functions to use the api endpoints
URL: https://github.com/apache/trafficcontrol/pull/2837
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_ops/client/crconfig.go b/traffic_ops/client/crconfig.go
index 626ed4333..2c7fb3396 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 000000000..e9f0210c4
--- /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: ")
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services