You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/07/11 01:19:47 UTC

[trafficcontrol] branch master updated (14f4d63 -> 125c7e1)

This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git.


    from 14f4d63  Update the Schema/Result/ProfileTypeValue.pm file to support the addition of the GROVE_PROFILE type to the profile_type enum.
     new b6e0971  fixed import conflicts
     new bf2617c  fixed import conflicts
     new 7b45810  added routes for /staticdnsentries
     new 9aba036  successfully created the staticdnsentry API tests
     new e1eb5d0  tied in the data dependencies for the staticdnsentries
     new 96e4a81  successfully tested the Create and Update
     new 712fbe2  successfully built the API Tests for StaticDNSEntries
     new c2f3ac4  cleaned up unused insert funcs
     new 65215b7  returned last_updated in the GET
     new 955bf8a  updated to use parameters instead of path params
     new 27a8394  cleaned up after merge conflicts
     new 253022c  switched struct reference to use the Nullable version
     new 125c7e1  fixed the unit tests after merge conflicts

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 traffic_ops/client/v13/deliveryservice.go          |  10 +
 .../client/v13/deliveryservice_endpoints.go        |   4 +
 .../v13/{coordinate.go => staticdnsentry.go}       |  48 ++--
 traffic_ops/testing/api/v13/profiles_test.go       |   3 -
 .../testing/api/v13/staticdnsentries_test.go       | 156 ++++++++++
 traffic_ops/testing/api/v13/tc-fixtures.json       | 316 ++++++++++++---------
 traffic_ops/testing/api/v13/todb.go                | 111 --------
 traffic_ops/testing/api/v13/traffic_control.go     |   1 +
 traffic_ops/traffic_ops_golang/routes.go           |   7 +-
 .../staticdnsentry/staticdnsentry.go               | 221 +++++++++++++-
 .../staticdnsentry_test.go}                        |  44 ++-
 11 files changed, 611 insertions(+), 310 deletions(-)
 copy traffic_ops/client/v13/{coordinate.go => staticdnsentry.go} (65%)
 create mode 100644 traffic_ops/testing/api/v13/staticdnsentries_test.go
 copy traffic_ops/traffic_ops_golang/{deliveryservice/request/comment/comments_test.go => staticdnsentry/staticdnsentry_test.go} (68%)


[trafficcontrol] 05/13: tied in the data dependencies for the staticdnsentries

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit e1eb5d0ff9943952e5ed51e463b30d09d8c86d1a
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed May 30 13:01:59 2018 -0600

    tied in the data dependencies for the staticdnsentries
---
 .../testing/api/v13/staticdnsentries_test.go       | 39 +++++++++++++++++-----
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
index cd669b0..3e88032 100644
--- a/traffic_ops/testing/api/v13/staticdnsentries_test.go
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -16,6 +16,7 @@ package v13
 */
 
 import (
+	"fmt"
 	"testing"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-log"
@@ -24,23 +25,45 @@ import (
 
 func TestStaticDNSEntries(t *testing.T) {
 
+	CreateTestCDNs(t)
+	CreateTestTypes(t)
+	CreateTestProfiles(t)
+	CreateTestStatuses(t)
+	CreateTestDivisions(t)
+	CreateTestRegions(t)
+	CreateTestPhysLocations(t)
+	CreateTestCacheGroups(t)
+	CreateTestServers(t)
+	CreateTestDeliveryServices(t)
 	CreateTestStaticDNSEntries(t)
-	UpdateTestStaticDNSEntries(t)
 	GetTestStaticDNSEntries(t)
+	UpdateTestStaticDNSEntries(t)
 	DeleteTestStaticDNSEntries(t)
+	DeleteTestTypes(t)
+	DeleteTestDeliveryServices(t)
+	DeleteTestServers(t)
+	DeleteTestCacheGroups(t)
+	DeleteTestPhysLocations(t)
+	DeleteTestRegions(t)
+	DeleteTestDivisions(t)
+	DeleteTestStatuses(t)
+	DeleteTestProfiles(t)
+	DeleteTestTypes(t)
+	DeleteTestCDNs(t)
 
 }
 
 func CreateTestStaticDNSEntries(t *testing.T) {
 
 	for _, staticDNSEntry := range testData.StaticDNSEntries {
-
-		// GET DeliveryService by Name
-		//respStatuses, _, err := TOSession.GetStatusByName("ONLINE")
-		//if err != nil {
-		//t.Errorf("cannot GET Status by name: ONLINE - %v\n", err)
-		//}
-		//respStatus := respStatuses[0]
+		// GET EDGE type
+		respTypes, _, err := TOSession.GetTypeByName(staticDNSEntry.Type)
+		fmt.Printf("respTypes ---> %v\n", respTypes)
+		if err != nil {
+			t.Errorf("cannot GET Type by name: %v\n", err)
+		}
+		respType := respTypes[0]
+		staticDNSEntry.Type = respType.Name
 		resp, _, err := TOSession.CreateStaticDNSEntry(staticDNSEntry)
 		log.Debugln("Response: ", resp)
 		if err != nil {


[trafficcontrol] 04/13: successfully created the staticdnsentry API tests

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 9aba036b33277346c69bac09c633227f6a82049d
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed May 30 12:40:27 2018 -0600

    successfully created the staticdnsentry API tests
    
    hooked in the lookup by XMLID
---
 .../v13/{staticdnsentry.go => staticdnsentries.go} |   5 +
 traffic_ops/client/v13/deliveryservice.go          |  10 ++
 .../client/v13/deliveryservice_endpoints.go        |   4 +
 traffic_ops/client/v13/staticdnsentry.go           | 133 +++++++++++++++++++++
 .../testing/api/v13/staticdnsentries_test.go       | 118 ++++++++++++++++++
 traffic_ops/testing/api/v13/tc-fixtures.json       |  11 +-
 traffic_ops/testing/api/v13/traffic_control.go     |   1 +
 7 files changed, 278 insertions(+), 4 deletions(-)

diff --git a/lib/go-tc/v13/staticdnsentry.go b/lib/go-tc/v13/staticdnsentries.go
similarity index 96%
rename from lib/go-tc/v13/staticdnsentry.go
rename to lib/go-tc/v13/staticdnsentries.go
index 0baa9bd..14941f4 100644
--- a/lib/go-tc/v13/staticdnsentry.go
+++ b/lib/go-tc/v13/staticdnsentries.go
@@ -21,6 +21,11 @@ import tc "github.com/apache/trafficcontrol/lib/go-tc"
  * under the License.
  */
 
+// StaticDNSEntries ...
+type StaticDNSEntriesResponse struct {
+	Response []StaticDNSEntry `json:"response"`
+}
+
 // StatisDNSEntry ...
 type StaticDNSEntry struct {
 
diff --git a/traffic_ops/client/v13/deliveryservice.go b/traffic_ops/client/v13/deliveryservice.go
index 0ad4599..c5a5448 100644
--- a/traffic_ops/client/v13/deliveryservice.go
+++ b/traffic_ops/client/v13/deliveryservice.go
@@ -56,6 +56,16 @@ func (to *Session) GetDeliveryServicesByServer(id int) ([]tc.DeliveryServiceV13,
 	return data.Response, reqInf, nil
 }
 
+func (to *Session) GetDeliveryServiceByXMLID(XMLID string) ([]tc.DeliveryService, ReqInf, error) {
+	var data tc.GetDeliveryServiceResponse
+	reqInf, err := get(to, deliveryServicesByXMLID(XMLID), &data)
+	if err != nil {
+		return nil, reqInf, err
+	}
+
+	return data.Response, reqInf, nil
+}
+
 // DeliveryService gets the DeliveryService for the ID it's passed
 // Deprecated: use GetDeliveryService
 func (to *Session) DeliveryService(id string) (*tc.DeliveryServiceV13, error) {
diff --git a/traffic_ops/client/v13/deliveryservice_endpoints.go b/traffic_ops/client/v13/deliveryservice_endpoints.go
index c0251cd..ada7517 100644
--- a/traffic_ops/client/v13/deliveryservice_endpoints.go
+++ b/traffic_ops/client/v13/deliveryservice_endpoints.go
@@ -64,3 +64,7 @@ func deliveryServiceSSLKeysByIDEp(id string) string {
 func deliveryServiceSSLKeysByHostnameEp(hostname string) string {
 	return apiBase + dsPath + "/hostname/" + hostname + "/sslkeys.json"
 }
+
+func deliveryServicesByXMLID(XMLID string) string {
+	return apiBase + dsPath + "?xmlId=" + XMLID
+}
diff --git a/traffic_ops/client/v13/staticdnsentry.go b/traffic_ops/client/v13/staticdnsentry.go
new file mode 100644
index 0000000..45eca07
--- /dev/null
+++ b/traffic_ops/client/v13/staticdnsentry.go
@@ -0,0 +1,133 @@
+/*
+
+   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.
+*/
+
+package v13
+
+import (
+	"encoding/json"
+	"fmt"
+	"net"
+	"net/http"
+
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
+)
+
+const (
+	API_v13_StaticDNSEntries = "/api/1.3/staticdnsentries"
+)
+
+// Create a StaticDNSEntry
+func (to *Session) CreateStaticDNSEntry(cdn v13.StaticDNSEntry) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(cdn)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	resp, remoteAddr, err := to.request(http.MethodPost, API_v13_StaticDNSEntries, reqBody)
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	defer resp.Body.Close()
+	var alerts tc.Alerts
+	err = json.NewDecoder(resp.Body).Decode(&alerts)
+	return alerts, reqInf, nil
+}
+
+// Update a StaticDNSEntry by ID
+func (to *Session) UpdateStaticDNSEntryByID(id int, cdn v13.StaticDNSEntry) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(cdn)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	route := fmt.Sprintf("%s/%d", API_v13_StaticDNSEntries, id)
+	resp, remoteAddr, err := to.request(http.MethodPut, route, reqBody)
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	defer resp.Body.Close()
+	var alerts tc.Alerts
+	err = json.NewDecoder(resp.Body).Decode(&alerts)
+	return alerts, reqInf, nil
+}
+
+// Returns a list of StaticDNSEntrys
+func (to *Session) GetStaticDNSEntries() ([]v13.StaticDNSEntry, ReqInf, error) {
+	resp, remoteAddr, err := to.request(http.MethodGet, API_v13_StaticDNSEntries, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return nil, reqInf, err
+	}
+	defer resp.Body.Close()
+
+	var data v13.StaticDNSEntriesResponse
+	err = json.NewDecoder(resp.Body).Decode(&data)
+	return data.Response, reqInf, nil
+}
+
+// GET a StaticDNSEntry by the StaticDNSEntry ID
+func (to *Session) GetStaticDNSEntryByID(id int) ([]v13.StaticDNSEntry, ReqInf, error) {
+	route := fmt.Sprintf("%s/%d", API_v13_StaticDNSEntries, id)
+	resp, remoteAddr, err := to.request(http.MethodGet, route, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return nil, reqInf, err
+	}
+	defer resp.Body.Close()
+
+	var data v13.StaticDNSEntriesResponse
+	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
+		return nil, reqInf, err
+	}
+
+	return data.Response, reqInf, nil
+}
+
+// GET a StaticDNSEntry by the StaticDNSEntry hsot
+func (to *Session) GetStaticDNSEntriesByHost(host string) ([]v13.StaticDNSEntry, ReqInf, error) {
+	url := fmt.Sprintf("%s?host=%s", API_v13_StaticDNSEntries, host)
+	resp, remoteAddr, err := to.request(http.MethodGet, url, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return nil, reqInf, err
+	}
+	defer resp.Body.Close()
+
+	var data v13.StaticDNSEntriesResponse
+	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
+		return nil, reqInf, err
+	}
+
+	return data.Response, reqInf, nil
+}
+
+// DELETE a StaticDNSEntry by ID
+func (to *Session) DeleteStaticDNSEntryByID(id int) (tc.Alerts, ReqInf, error) {
+	route := fmt.Sprintf("%s/%d", API_v13_StaticDNSEntries, id)
+	resp, remoteAddr, err := to.request(http.MethodDelete, route, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	defer resp.Body.Close()
+	var alerts tc.Alerts
+	err = json.NewDecoder(resp.Body).Decode(&alerts)
+	return alerts, reqInf, nil
+}
diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
new file mode 100644
index 0000000..cd669b0
--- /dev/null
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -0,0 +1,118 @@
+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 (
+	"testing"
+
+	"github.com/apache/incubator-trafficcontrol/lib/go-log"
+	tc "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+)
+
+func TestStaticDNSEntries(t *testing.T) {
+
+	CreateTestStaticDNSEntries(t)
+	UpdateTestStaticDNSEntries(t)
+	GetTestStaticDNSEntries(t)
+	DeleteTestStaticDNSEntries(t)
+
+}
+
+func CreateTestStaticDNSEntries(t *testing.T) {
+
+	for _, staticDNSEntry := range testData.StaticDNSEntries {
+
+		// GET DeliveryService by Name
+		//respStatuses, _, err := TOSession.GetStatusByName("ONLINE")
+		//if err != nil {
+		//t.Errorf("cannot GET Status by name: ONLINE - %v\n", err)
+		//}
+		//respStatus := respStatuses[0]
+		resp, _, err := TOSession.CreateStaticDNSEntry(staticDNSEntry)
+		log.Debugln("Response: ", resp)
+		if err != nil {
+			t.Errorf("could not CREATE staticDNSEntry: %v\n", err)
+		}
+	}
+
+}
+
+func UpdateTestStaticDNSEntries(t *testing.T) {
+
+	firstStaticDNSEntrie := testData.StaticDNSEntries[0]
+	// Retrieve the StaticDNSEntrie by name so we can get the id for the Update
+	resp, _, err := TOSession.GetStaticDNSEntriesByHost(firstStaticDNSEntrie.Host)
+	if err != nil {
+		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntrie.Host, err)
+	}
+	remoteStaticDNSEntry := resp[0]
+	expectedAddress := "address99"
+	remoteStaticDNSEntry.Address = expectedAddress
+	var alert tc.Alerts
+	alert, _, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
+	if err != nil {
+		t.Errorf("cannot UPDATE StaticDNSEntrie by id: %v - %v\n", err, alert)
+	}
+
+	// Retrieve the StaticDNSEntrie to check StaticDNSEntrie name got updated
+	resp, _, err = TOSession.GetStaticDNSEntryByID(remoteStaticDNSEntry.ID)
+	if err != nil {
+		t.Errorf("cannot GET StaticDNSEntries by name: '$%s', %v\n", firstStaticDNSEntrie.Host, err)
+	}
+	respStaticDNSEntry := resp[0]
+	if respStaticDNSEntry.Address != expectedAddress {
+		t.Errorf("results do not match actual: %s, expected: %s\n", respStaticDNSEntry.Address, expectedAddress)
+	}
+
+}
+
+func GetTestStaticDNSEntries(t *testing.T) {
+
+	for _, staticDNSEntry := range testData.StaticDNSEntries {
+		resp, _, err := TOSession.GetStaticDNSEntriesByHost(staticDNSEntry.Host)
+		if err != nil {
+			t.Errorf("cannot GET StaticDNSEntries by name: %v - %v\n", err, resp)
+		}
+	}
+}
+
+func DeleteTestStaticDNSEntries(t *testing.T) {
+
+	for _, staticDNSEntry := range testData.StaticDNSEntries {
+		// Retrieve the StaticDNSEntrie by name so we can get the id for the Update
+		resp, _, err := TOSession.GetStaticDNSEntriesByHost(staticDNSEntry.Host)
+		if err != nil {
+			t.Errorf("cannot GET StaticDNSEntries by name: %v - %v\n", staticDNSEntry.Host, err)
+		}
+		if len(resp) > 0 {
+			respStaticDNSEntrie := resp[0]
+
+			_, _, err := TOSession.DeleteStaticDNSEntryByID(respStaticDNSEntrie.ID)
+			if err != nil {
+				t.Errorf("cannot DELETE StaticDNSEntrie by name: '%s' %v\n", respStaticDNSEntrie.Host, err)
+			}
+
+			// Retrieve the StaticDNSEntrie to see if it got deleted
+			staticDNSEntries, _, err := TOSession.GetStaticDNSEntriesByHost(staticDNSEntry.Host)
+			if err != nil {
+				t.Errorf("error deleting StaticDNSEntrie name: %s\n", err.Error())
+			}
+			if len(staticDNSEntries) > 0 {
+				t.Errorf("expected StaticDNSEntry name: %s to be deleted\n", staticDNSEntry.Host)
+			}
+		}
+	}
+}
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index 4948293..d0799d0 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -1018,19 +1018,22 @@
         {
             "host": "host1",
             "address": "address1",
-            "typeName": "AAAA_RECORD",
+            "dsname": "ds1",
+            "typename": "AAAA_RECORD",
             "ttl": 10 
         },
         {
             "host": "host2",
             "address": "address2",
-            "typeName": "A_RECORD",
+            "dsname": "ds2",
+            "typename": "A_RECORD",
             "ttl": 10 
         },
         {
             "host": "host3",
-            "name": "127.0.0.1",
-            "typeName": "CNAME_RECORD",
+            "dsName": "ds3",
+            "address": "127.0.0.1",
+            "typename": "CNAME_RECORD",
             "ttl": 10 
         }
     ],
diff --git a/traffic_ops/testing/api/v13/traffic_control.go b/traffic_ops/testing/api/v13/traffic_control.go
index 98fcdfc..80e40ab 100644
--- a/traffic_ops/testing/api/v13/traffic_control.go
+++ b/traffic_ops/testing/api/v13/traffic_control.go
@@ -39,6 +39,7 @@ type TrafficControl struct {
 	Roles                          []v13.Role                          `json:"roles"`
 	Servers                        []v13.Server                        `json:"servers"`
 	Statuses                       []v12.Status                        `json:"statuses"`
+	StaticDNSEntries               []v13.StaticDNSEntry                `json:"staticdnsentries"`
 	Tenants                        []v12.Tenant                        `json:"tenants"`
 	Types                          []v12.Type                          `json:"types"`
 }


[trafficcontrol] 12/13: switched struct reference to use the Nullable version

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 253022c9ec629d4ac868b55c4eaf00a03582b780
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Jul 10 16:21:04 2018 -0600

    switched struct reference to use the Nullable version
---
 traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index 6ba3944..5f213b0 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -109,7 +109,7 @@ func (staticDNSEntry *TOStaticDNSEntry) Read(parameters map[string]string) ([]in
 	defer rows.Close()
 	staticDNSEntries := []interface{}{}
 	for rows.Next() {
-		s := v13.StaticDNSEntry{}
+		s := v13.StaticDNSEntryNullable{}
 		if err = rows.StructScan(&s); err != nil {
 			log.Errorln("error parsing StaticDNSEntry rows: " + err.Error())
 			return nil, []error{tc.DBError}, tc.SystemError


[trafficcontrol] 02/13: fixed import conflicts

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit bf2617c6b99e5c6f453e64d36a0b4aaec7b423db
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Jun 25 06:58:39 2018 -0600

    fixed import conflicts
---
 .../staticdnsentry/staticdnsentry.go               | 230 ++++++++++++++++++++-
 1 file changed, 228 insertions(+), 2 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index 7ebc076..988b3ab 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -20,10 +20,16 @@ package staticdnsentry
  */
 
 import (
+	"errors"
+	"fmt"
+
 	"github.com/apache/trafficcontrol/lib/go-log"
 	"github.com/apache/trafficcontrol/lib/go-tc"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/auth"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	"github.com/jmoiron/sqlx"
+	"github.com/lib/pq"
 )
 
 type TOStaticDNSEntry struct {
@@ -38,6 +44,11 @@ func GetReaderSingleton() func(reqInfo *api.APIInfo) api.Reader {
 	}
 }
 
+func (staticDNSEntry *TOStaticDNSEntry) SetKeys(keys map[string]interface{}) {
+	i, _ := keys["id"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	staticDNSEntry.ID = &i
+}
+
 func (staticDNSEntry *TOStaticDNSEntry) Read(parameters map[string]string) ([]interface{}, []error, tc.ApiErrorType) {
 	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
 		"deliveryservice": dbhelpers.WhereColumnInfo{"deliveryservice", nil}, // order by
@@ -67,9 +78,218 @@ func (staticDNSEntry *TOStaticDNSEntry) Read(parameters map[string]string) ([]in
 	return staticDNSEntries, []error{}, tc.NoError
 }
 
+//The TOStaticDNSEntry implementation of the Creator interface
+//all implementations of Creator should use transactions and return the proper errorType
+//ParsePQUniqueConstraintError is used to determine if a staticDNSEntry with conflicting values exists
+//if so, it will return an errorType of DataConflict and the type should be appended to the
+//generic error message returned
+//The insert sql returns the id and lastUpdated values of the newly inserted staticDNSEntry and have
+//to be added to the struct
+func (staticDNSEntry *TOStaticDNSEntry) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
+	rollbackTransaction := true
+	tx, err := db.Beginx()
+	defer func() {
+		if tx == nil || !rollbackTransaction {
+			return
+		}
+		err := tx.Rollback()
+		if err != nil {
+			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
+		}
+	}()
+
+	if err != nil {
+		log.Error.Printf("could not begin transaction: %v", err)
+		return tc.DBError, tc.SystemError
+	}
+	// make sure that staticDNSEntry.DomainName is lowercase
+	resultRows, err := tx.NamedQuery(insertQuery(), staticDNSEntry)
+	if err != nil {
+		if pqErr, ok := err.(*pq.Error); ok {
+			err, eType := dbhelpers.ParsePQUniqueConstraintError(pqErr)
+			if eType == tc.DataConflictError {
+				return errors.New("a staticDNSEntry with " + err.Error()), eType
+			}
+			return err, eType
+		} else {
+			log.Errorf("received non pq error: %++v from create execution", err)
+			return tc.DBError, tc.SystemError
+		}
+	}
+	defer resultRows.Close()
+
+	var id int
+	var lastUpdated tc.TimeNoMod
+	rowsAffected := 0
+	for resultRows.Next() {
+		rowsAffected++
+		if err := resultRows.Scan(&id, &lastUpdated); err != nil {
+			log.Error.Printf("could not scan id from insert: %s\n", err)
+			return tc.DBError, tc.SystemError
+		}
+	}
+	if rowsAffected == 0 {
+		err = errors.New("no staticDNSEntry was inserted, no id was returned")
+		log.Errorln(err)
+		return tc.DBError, tc.SystemError
+	} else if rowsAffected > 1 {
+		err = errors.New("too many ids returned from staticDNSEntry insert")
+		log.Errorln(err)
+		return tc.DBError, tc.SystemError
+	}
+	staticDNSEntry.SetKeys(map[string]interface{}{"id": id})
+	staticDNSEntry.LastUpdated = &lastUpdated
+	err = tx.Commit()
+	if err != nil {
+		log.Errorln("Could not commit transaction: ", err)
+		return tc.DBError, tc.SystemError
+	}
+	rollbackTransaction = false
+	return nil, tc.NoError
+}
+
+func insertQuery() string {
+	query := `INSERT INTO staticdnsentry (
+address,
+deliveryservice,
+cachegroup,
+host,
+type,
+ttl) VALUES (
+:address,
+:deliveryservice,
+:cachegroup,
+:host,
+:type,
+:ttl) RETURNING id,last_updated`
+	return query
+}
+
+//The TOStaticDNSEntry implementation of the Updater interface
+//all implementations of Updater should use transactions and return the proper errorType
+//ParsePQUniqueConstraintError is used to determine if a staticDNSEntry with conflicting values exists
+//if so, it will return an errorType of DataConflict and the type should be appended to the
+//generic error message returned
+func (staticDNSEntry *TOStaticDNSEntry) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
+	rollbackTransaction := true
+	tx, err := db.Beginx()
+	defer func() {
+		if tx == nil || !rollbackTransaction {
+			return
+		}
+		err := tx.Rollback()
+		if err != nil {
+			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
+		}
+	}()
+
+	if err != nil {
+		log.Error.Printf("could not begin transaction: %v", err)
+		return tc.DBError, tc.SystemError
+	}
+	log.Debugf("about to run exec query: %s with staticDNSEntry: %++v", updateQuery(), staticDNSEntry)
+	resultRows, err := tx.NamedQuery(updateQuery(), staticDNSEntry)
+	if err != nil {
+		if pqErr, ok := err.(*pq.Error); ok {
+			err, eType := dbhelpers.ParsePQUniqueConstraintError(pqErr)
+			if eType == tc.DataConflictError {
+				return errors.New("a staticDNSEntry with " + err.Error()), eType
+			}
+			return err, eType
+		} else {
+			log.Errorf("received error: %++v from update execution", err)
+			return tc.DBError, tc.SystemError
+		}
+	}
+	defer resultRows.Close()
+
+	var lastUpdated tc.TimeNoMod
+	rowsAffected := 0
+	for resultRows.Next() {
+		rowsAffected++
+		if err := resultRows.Scan(&lastUpdated); err != nil {
+			log.Error.Printf("could not scan lastUpdated from insert: %s\n", err)
+			return tc.DBError, tc.SystemError
+		}
+	}
+	log.Debugf("lastUpdated: %++v", lastUpdated)
+	staticDNSEntry.LastUpdated = &lastUpdated
+	if rowsAffected != 1 {
+		if rowsAffected < 1 {
+			return errors.New("no staticDNSEntry found with this id"), tc.DataMissingError
+		} else {
+			return fmt.Errorf("this update affected too many rows: %d", rowsAffected), tc.SystemError
+		}
+	}
+	err = tx.Commit()
+	if err != nil {
+		log.Errorln("Could not commit transaction: ", err)
+		return tc.DBError, tc.SystemError
+	}
+	rollbackTransaction = false
+	return nil, tc.NoError
+}
+
+func updateQuery() string {
+	query := `UPDATE
+staticdnsentry SET
+address=:address,
+deliveryservice=:deliveryservice,
+cachegroup=:cachegroup,
+host=:host,
+type=:type,
+ttl=:ttl
+WHERE id=:id RETURNING last_updated`
+	return query
+}
+
+//The StaticDNSEntry implementation of the Deleter interface
+//all implementations of Deleter should use transactions and return the proper errorType
+func (staticDNSEntry *TOStaticDNSEntry) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
+	rollbackTransaction := true
+	tx, err := db.Beginx()
+	defer func() {
+		if tx == nil || !rollbackTransaction {
+			return
+		}
+		err := tx.Rollback()
+		if err != nil {
+			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
+		}
+	}()
+
+	if err != nil {
+		log.Error.Printf("could not begin transaction: %v", err)
+		return tc.DBError, tc.SystemError
+	}
+	log.Debugf("about to run exec query: %s with staticDNSEntry: %++v", deleteQuery(), staticDNSEntry)
+	result, err := tx.NamedExec(deleteQuery(), staticDNSEntry)
+	if err != nil {
+		log.Errorf("received error: %++v from delete execution", err)
+		return tc.DBError, tc.SystemError
+	}
+	rowsAffected, err := result.RowsAffected()
+	if err != nil {
+		return tc.DBError, tc.SystemError
+	}
+	if rowsAffected != 1 {
+		if rowsAffected < 1 {
+			return errors.New("no staticDNSEntry with that id found"), tc.DataMissingError
+		} else {
+			return fmt.Errorf("this create affected too many rows: %d", rowsAffected), tc.SystemError
+		}
+	}
+	err = tx.Commit()
+	if err != nil {
+		log.Errorln("Could not commit transaction: ", err)
+		return tc.DBError, tc.SystemError
+	}
+	rollbackTransaction = false
+	return nil, tc.NoError
+}
+
 func selectQuery() string {
-	return `
-SELECT
+	return `SELECT
 ds.xml_id as dsname,
 sde.host,
 sde.ttl,
@@ -82,3 +302,9 @@ JOIN cachegroup as cg ON sde.cachegroup = cg.id
 JOIN deliveryservice as ds on sde.deliveryservice = ds.id
 `
 }
+
+func deleteQuery() string {
+	query := `DELETE FROM staticdnsentry
+WHERE id=:id`
+	return query
+}


[trafficcontrol] 11/13: cleaned up after merge conflicts

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 27a8394404cf7702677179c720c0b962415d3458
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Jul 10 15:34:18 2018 -0600

    cleaned up after merge conflicts
---
 lib/go-tc/v13/staticdnsentries.go                  | 137 ---------------------
 traffic_ops/traffic_ops_golang/routes.go           |  11 +-
 .../staticdnsentry/staticdnsentry.go               | 136 +++++++++-----------
 3 files changed, 60 insertions(+), 224 deletions(-)

diff --git a/lib/go-tc/v13/staticdnsentries.go b/lib/go-tc/v13/staticdnsentries.go
deleted file mode 100644
index cfb1ef8..0000000
--- a/lib/go-tc/v13/staticdnsentries.go
+++ /dev/null
@@ -1,137 +0,0 @@
-package v13
-
-import tc "github.com/apache/trafficcontrol/lib/go-tc"
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-// StaticDNSEntries ...
-type StaticDNSEntriesResponse struct {
-	Response []StaticDNSEntry `json:"response"`
-}
-
-// StatisDNSEntry ...
-type StaticDNSEntry struct {
-
-	// The static IP Address or fqdn of the static dns entry
-	//
-	// required: true
-	Address string `json:"address" db:"address"`
-
-	// The Cachegroup Name associated
-	//
-	CacheGroupName string `json:"cachegroup"`
-
-	// The Cachegroup ID associated
-	//
-	CacheGroupID int `json:"cachegroupId" db:"cachegroup_id"`
-
-	// The DeliveryService associated
-	//
-	DeliveryService string `json:"deliveryservice" db:"dsname"`
-
-	// The DeliveryService associated
-	//
-	// required: true
-	DeliveryServiceID int `json:"deliveryserviceId" db:"deliveryservice_id"`
-
-	// The host of the static dns entry
-	//
-	// required: true
-	Host string `json:"host" db:"host"`
-
-	// ID of the StaticDNSEntry
-	//
-	// required: true
-	ID int `json:"id" db:"id"`
-
-	// LastUpdated
-	//
-	LastUpdated tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
-
-	// The Time To Live for the static dns entry
-	//
-	// required: true
-	TTL int64 `json:"ttl" db:"ttl"`
-
-	// The type of the static DNS entry
-	//
-	// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
-	Type string `json:"type"`
-
-	// The type id of the static DNS entry
-	//
-	// required: true
-	TypeID int `json:"typeId" db:"type_id"`
-}
-
-// StatisDNSEntryNullable ...
-type StaticDNSEntryNullable struct {
-
-	// The static IP Address or fqdn of the static dns entry
-	//
-	// required: true
-	Address *string `json:"address" db:"address"`
-
-	// The Cachegroup Name associated
-	//
-	CacheGroupName *string `json:"cachegroup" db:"cachegroup"`
-
-	// The Cachegroup ID associated
-	//
-	CacheGroupID *int `json:"cachegroupId" db:"cachegroup_id"`
-
-	// The DeliveryService Name associated
-	//
-	DeliveryService *string `json:"deliveryservice" db:"dsname"`
-
-	// DeliveryService ID of the StaticDNSEntry
-	//
-	// required: true
-	DeliveryServiceID *int `json:"deliveryserviceId" db:"deliveryservice_id"`
-
-	// The host of the static dns entry
-	//
-	// required: true
-	Host *string `json:"host" db:"host"`
-
-	// ID of the StaticDNSEntry
-	//
-	// required: true
-	ID *int `json:"id" db:"id"`
-
-	// LastUpdated
-	//
-	LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
-
-	// The Time To Live for the static dns entry
-	//
-	// required: true
-	TTL *int64 `json:"ttl" db:"ttl"`
-
-	// The type of the static DNS entry
-	//
-	// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
-	Type *string `json:"type"`
-
-	// The type id of the static DNS entry
-	//
-	// required: true
-	TypeID int `json:"typeId" db:"type_id"`
-}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index dc79fb6..ed48e2a 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -316,12 +316,11 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{1.3, http.MethodGet, `servers/{host_name}/update_status$`, server.GetServerUpdateStatusHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
 
 		//StaticDNSEntries
-		{1.1, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadOnlyHandler(staticdnsentry.GetReaderSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodGet, `staticdnsentries/?$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodPut, `staticdnsentries/?$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
-		{1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
-		{1.3, http.MethodDelete, `staticdnsentries/?$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.1, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadHandler(staticdnsentry.GetTypeSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodGet, `staticdnsentries/?$`, api.ReadHandler(staticdnsentry.GetTypeSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodPut, `staticdnsentries/?$`, api.UpdateHandler(staticdnsentry.GetTypeSingleton()), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetTypeSingleton()), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodDelete, `staticdnsentries/?$`, api.DeleteHandler(staticdnsentry.GetTypeSingleton()), auth.PrivLevelOperations, Authenticated, nil},
 
 		//ProfileParameters
 		{1.1, http.MethodGet, `profiles/{id}/parameters/?(\.json)?$`, profileparameter.GetProfileID(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index 292338c..6ba3944 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -22,33 +22,74 @@ package staticdnsentry
 import (
 	"errors"
 	"fmt"
+	"strconv"
 
 	"github.com/apache/trafficcontrol/lib/go-log"
 	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-tc/v13"
+	"github.com/apache/trafficcontrol/lib/go-util"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
-	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/auth"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
-	"github.com/jmoiron/sqlx"
+	validation "github.com/go-ozzo/ozzo-validation"
 	"github.com/lib/pq"
 )
 
 type TOStaticDNSEntry struct {
 	ReqInfo *api.APIInfo `json:"-"`
-	tc.StaticDNSEntry
+	v13.StaticDNSEntryNullable
 }
 
-func GetReaderSingleton() func(reqInfo *api.APIInfo) api.Reader {
-	return func(reqInfo *api.APIInfo) api.Reader {
-		toReturn := TOStaticDNSEntry{reqInfo, tc.StaticDNSEntry{}}
+func GetTypeSingleton() api.CRUDFactory {
+	return func(reqInfo *api.APIInfo) api.CRUDer {
+		toReturn := TOStaticDNSEntry{reqInfo, v13.StaticDNSEntryNullable{}}
 		return &toReturn
 	}
 }
 
+func (staticDNSEntry TOStaticDNSEntry) GetKeyFieldsInfo() []api.KeyFieldInfo {
+	return []api.KeyFieldInfo{{"id", api.GetIntKey}}
+}
+
+//Implementation of the Identifier, Validator interface functions
+func (staticDNSEntry TOStaticDNSEntry) GetKeys() (map[string]interface{}, bool) {
+	if staticDNSEntry.ID == nil {
+		return map[string]interface{}{"id": 0}, false
+	}
+	return map[string]interface{}{"id": *staticDNSEntry.ID}, true
+}
+
+func (staticDNSEntry TOStaticDNSEntry) GetAuditName() string {
+	if staticDNSEntry.Host != nil {
+		return *staticDNSEntry.Host
+	}
+	if staticDNSEntry.ID != nil {
+		return strconv.Itoa(*staticDNSEntry.ID)
+	}
+	return "0"
+}
+
+func (staticDNSEntry TOStaticDNSEntry) GetType() string {
+	return "staticDNSEntry"
+}
+
 func (staticDNSEntry *TOStaticDNSEntry) SetKeys(keys map[string]interface{}) {
 	i, _ := keys["id"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
 	staticDNSEntry.ID = &i
 }
 
+// Validate fulfills the api.Validator interface
+func (staticDNSEntry TOStaticDNSEntry) Validate() error {
+	errs := validation.Errors{
+		"host":    validation.Validate(staticDNSEntry.Host, validation.Required),
+		"address": validation.Validate(staticDNSEntry.Address, validation.Required),
+		"dsname":  validation.Validate(staticDNSEntry.DeliveryService, validation.Required),
+		"ttl":     validation.Validate(staticDNSEntry.TTL, validation.Required),
+		"type":    validation.Validate(staticDNSEntry.Type, validation.Required),
+	}
+	return util.JoinErrs(tovalidate.ToErrors(errs))
+}
+
 func (staticDNSEntry *TOStaticDNSEntry) Read(parameters map[string]string) ([]interface{}, []error, tc.ApiErrorType) {
 	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
 		"deliveryservice": dbhelpers.WhereColumnInfo{"deliveryservice", nil}, // order by
@@ -68,7 +109,7 @@ func (staticDNSEntry *TOStaticDNSEntry) Read(parameters map[string]string) ([]in
 	defer rows.Close()
 	staticDNSEntries := []interface{}{}
 	for rows.Next() {
-		s := tc.StaticDNSEntry{}
+		s := v13.StaticDNSEntry{}
 		if err = rows.StructScan(&s); err != nil {
 			log.Errorln("error parsing StaticDNSEntry rows: " + err.Error())
 			return nil, []error{tc.DBError}, tc.SystemError
@@ -85,25 +126,8 @@ func (staticDNSEntry *TOStaticDNSEntry) Read(parameters map[string]string) ([]in
 //generic error message returned
 //The insert sql returns the id and lastUpdated values of the newly inserted staticDNSEntry and have
 //to be added to the struct
-func (staticDNSEntry *TOStaticDNSEntry) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
-	rollbackTransaction := true
-	tx, err := db.Beginx()
-	defer func() {
-		if tx == nil || !rollbackTransaction {
-			return
-		}
-		err := tx.Rollback()
-		if err != nil {
-			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
-		}
-	}()
-
-	if err != nil {
-		log.Error.Printf("could not begin transaction: %v", err)
-		return tc.DBError, tc.SystemError
-	}
-	// make sure that staticDNSEntry.DomainName is lowercase
-	resultRows, err := tx.NamedQuery(insertQuery(), staticDNSEntry)
+func (staticDNSEntry *TOStaticDNSEntry) Create() (error, tc.ApiErrorType) {
+	resultRows, err := staticDNSEntry.ReqInfo.Tx.NamedQuery(insertQuery(), staticDNSEntry)
 	if err != nil {
 		if pqErr, ok := err.(*pq.Error); ok {
 			err, eType := dbhelpers.ParsePQUniqueConstraintError(pqErr)
@@ -139,12 +163,6 @@ func (staticDNSEntry *TOStaticDNSEntry) Create(db *sqlx.DB, user auth.CurrentUse
 	}
 	staticDNSEntry.SetKeys(map[string]interface{}{"id": id})
 	staticDNSEntry.LastUpdated = &lastUpdated
-	err = tx.Commit()
-	if err != nil {
-		log.Errorln("Could not commit transaction: ", err)
-		return tc.DBError, tc.SystemError
-	}
-	rollbackTransaction = false
 	return nil, tc.NoError
 }
 
@@ -170,26 +188,9 @@ ttl) VALUES (
 //ParsePQUniqueConstraintError is used to determine if a staticDNSEntry with conflicting values exists
 //if so, it will return an errorType of DataConflict and the type should be appended to the
 //generic error message returned
-func (staticDNSEntry *TOStaticDNSEntry) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
-	fmt.Printf("staticDNSEntry.DeliveryService ---> %v\n", *staticDNSEntry.DeliveryService)
-	rollbackTransaction := true
-	tx, err := db.Beginx()
-	defer func() {
-		if tx == nil || !rollbackTransaction {
-			return
-		}
-		err := tx.Rollback()
-		if err != nil {
-			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
-		}
-	}()
-
-	if err != nil {
-		log.Error.Printf("could not begin transaction: %v", err)
-		return tc.DBError, tc.SystemError
-	}
+func (staticDNSEntry *TOStaticDNSEntry) Update() (error, tc.ApiErrorType) {
 	log.Debugf("about to run exec query: %s with staticDNSEntry: %++v", updateQuery(), staticDNSEntry)
-	resultRows, err := tx.NamedQuery(updateQuery(), staticDNSEntry)
+	resultRows, err := staticDNSEntry.ReqInfo.Tx.NamedQuery(updateQuery(), staticDNSEntry)
 	if err != nil {
 		if pqErr, ok := err.(*pq.Error); ok {
 			err, eType := dbhelpers.ParsePQUniqueConstraintError(pqErr)
@@ -222,12 +223,6 @@ func (staticDNSEntry *TOStaticDNSEntry) Update(db *sqlx.DB, user auth.CurrentUse
 			return fmt.Errorf("this update affected too many rows: %d", rowsAffected), tc.SystemError
 		}
 	}
-	err = tx.Commit()
-	if err != nil {
-		log.Errorln("Could not commit transaction: ", err)
-		return tc.DBError, tc.SystemError
-	}
-	rollbackTransaction = false
 	return nil, tc.NoError
 }
 
@@ -247,25 +242,9 @@ WHERE id=:id RETURNING last_updated`
 
 //The StaticDNSEntry implementation of the Deleter interface
 //all implementations of Deleter should use transactions and return the proper errorType
-func (staticDNSEntry *TOStaticDNSEntry) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
-	rollbackTransaction := true
-	tx, err := db.Beginx()
-	defer func() {
-		if tx == nil || !rollbackTransaction {
-			return
-		}
-		err := tx.Rollback()
-		if err != nil {
-			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
-		}
-	}()
-
-	if err != nil {
-		log.Error.Printf("could not begin transaction: %v", err)
-		return tc.DBError, tc.SystemError
-	}
+func (staticDNSEntry *TOStaticDNSEntry) Delete() (error, tc.ApiErrorType) {
 	log.Debugf("about to run exec query: %s with staticDNSEntry: %++v", deleteQuery(), staticDNSEntry)
-	result, err := tx.NamedExec(deleteQuery(), staticDNSEntry)
+	result, err := staticDNSEntry.ReqInfo.Tx.NamedExec(deleteQuery(), staticDNSEntry)
 	if err != nil {
 		log.Errorf("received error: %++v from delete execution", err)
 		return tc.DBError, tc.SystemError
@@ -281,13 +260,8 @@ func (staticDNSEntry *TOStaticDNSEntry) Delete(db *sqlx.DB, user auth.CurrentUse
 			return fmt.Errorf("this create affected too many rows: %d", rowsAffected), tc.SystemError
 		}
 	}
-	err = tx.Commit()
-	if err != nil {
-		log.Errorln("Could not commit transaction: ", err)
-		return tc.DBError, tc.SystemError
-	}
-	rollbackTransaction = false
 	return nil, tc.NoError
+
 }
 
 func selectQuery() string {


[trafficcontrol] 10/13: updated to use parameters instead of path params

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 955bf8a0d963bccac5a6b063d16c5cb0aa38ea52
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Jun 25 12:01:42 2018 -0600

    updated to use parameters instead of path params
---
 traffic_ops/client/v13/staticdnsentry.go             | 10 +++++-----
 traffic_ops/testing/api/v13/staticdnsentries_test.go |  4 ++--
 traffic_ops/testing/api/v13/tc-fixtures.json         |  6 +++---
 traffic_ops/traffic_ops_golang/routes.go             |  6 +++---
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/traffic_ops/client/v13/staticdnsentry.go b/traffic_ops/client/v13/staticdnsentry.go
index 45eca07..15e1a42 100644
--- a/traffic_ops/client/v13/staticdnsentry.go
+++ b/traffic_ops/client/v13/staticdnsentry.go
@@ -21,8 +21,8 @@ import (
 	"net"
 	"net/http"
 
-	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
-	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/v13"
 )
 
 const (
@@ -57,7 +57,7 @@ func (to *Session) UpdateStaticDNSEntryByID(id int, cdn v13.StaticDNSEntry) (tc.
 	if err != nil {
 		return tc.Alerts{}, reqInf, err
 	}
-	route := fmt.Sprintf("%s/%d", API_v13_StaticDNSEntries, id)
+	route := fmt.Sprintf("%s?id=%d", API_v13_StaticDNSEntries, id)
 	resp, remoteAddr, err := to.request(http.MethodPut, route, reqBody)
 	if err != nil {
 		return tc.Alerts{}, reqInf, err
@@ -84,7 +84,7 @@ func (to *Session) GetStaticDNSEntries() ([]v13.StaticDNSEntry, ReqInf, error) {
 
 // GET a StaticDNSEntry by the StaticDNSEntry ID
 func (to *Session) GetStaticDNSEntryByID(id int) ([]v13.StaticDNSEntry, ReqInf, error) {
-	route := fmt.Sprintf("%s/%d", API_v13_StaticDNSEntries, id)
+	route := fmt.Sprintf("%s?id=%d", API_v13_StaticDNSEntries, id)
 	resp, remoteAddr, err := to.request(http.MethodGet, route, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
 	if err != nil {
@@ -120,7 +120,7 @@ func (to *Session) GetStaticDNSEntriesByHost(host string) ([]v13.StaticDNSEntry,
 
 // DELETE a StaticDNSEntry by ID
 func (to *Session) DeleteStaticDNSEntryByID(id int) (tc.Alerts, ReqInf, error) {
-	route := fmt.Sprintf("%s/%d", API_v13_StaticDNSEntries, id)
+	route := fmt.Sprintf("%s?id=%d", API_v13_StaticDNSEntries, id)
 	resp, remoteAddr, err := to.request(http.MethodDelete, route, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
 	if err != nil {
diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
index b74336d..9dad333 100644
--- a/traffic_ops/testing/api/v13/staticdnsentries_test.go
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -18,8 +18,8 @@ package v13
 import (
 	"testing"
 
-	"github.com/apache/incubator-trafficcontrol/lib/go-log"
-	tc "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-log"
+	tc "github.com/apache/trafficcontrol/lib/go-tc"
 )
 
 func TestStaticDNSEntries(t *testing.T) {
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index 3381924..e6b7c37 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -1026,7 +1026,7 @@
         {
             "address": "address1",
             "cachegroup": "cachegroup1",
-            "deliveryservice": "test-ds1",
+            "deliveryservice": "ds1",
             "host": "host1",
             "type": "AAAA_RECORD",
             "ttl": 10
@@ -1034,14 +1034,14 @@
         {
             "address": "address2",
             "cachegroup": "cachegroup2",
-            "deliveryservice": "test-ds1",
+            "deliveryservice": "ds1",
             "host": "host2",
             "type": "A_RECORD",
             "ttl": 10
         },
         {
             "host": "host3",
-            "deliveryservice": "test-ds1",
+            "deliveryservice": "ds1",
             "cachegroup": "cachegroup2",
             "address": "127.0.0.1",
             "type": "CNAME_RECORD",
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index d976577..dc79fb6 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -318,10 +318,10 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		//StaticDNSEntries
 		{1.1, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadOnlyHandler(staticdnsentry.GetReaderSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
 		{1.3, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodGet, `staticdnsentries/{id}$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodPut, `staticdnsentries/{id}$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodGet, `staticdnsentries/?$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodPut, `staticdnsentries/?$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 		{1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
-		{1.3, http.MethodDelete, `staticdnsentries/{id}$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodDelete, `staticdnsentries/?$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 
 		//ProfileParameters
 		{1.1, http.MethodGet, `profiles/{id}/parameters/?(\.json)?$`, profileparameter.GetProfileID(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},


[trafficcontrol] 03/13: added routes for /staticdnsentries

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 7b45810a0e6e10d487eb673de1167d954c63dc6c
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed May 30 08:24:49 2018 -0600

    added routes for /staticdnsentries
    
    added fixture data for the staticdnsentries API
    
    updated the enum doc for the types
---
 lib/go-tc/v13/staticdnsentry.go              |  4 ++--
 traffic_ops/testing/api/v13/tc-fixtures.json | 20 ++++++++++++++++++++
 traffic_ops/traffic_ops_golang/routes.go     |  5 +++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/go-tc/v13/staticdnsentry.go b/lib/go-tc/v13/staticdnsentry.go
index a3da4f7..0baa9bd 100644
--- a/lib/go-tc/v13/staticdnsentry.go
+++ b/lib/go-tc/v13/staticdnsentry.go
@@ -60,7 +60,7 @@ type StaticDNSEntry struct {
 	// The type of the static DNS entry
 	//
 	// required: true
-	// enum: ["A_RECORD", "CNAME_RECORD"]
+	// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
 	Type string `json:"type" db:"type"`
 }
 
@@ -103,6 +103,6 @@ type StaticDNSEntryNullable struct {
 	// The type of the static DNS entry
 	//
 	// required: true
-	// enum: ["A_RECORD", "CNAME_RECORD"]
+	// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
 	Type *string `json:"type" db:"type"`
 }
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index 21f61f9..4948293 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -1014,6 +1014,26 @@
             "xmppPasswd": ""
         }
     ],
+    "staticdnsentries": [
+        {
+            "host": "host1",
+            "address": "address1",
+            "typeName": "AAAA_RECORD",
+            "ttl": 10 
+        },
+        {
+            "host": "host2",
+            "address": "address2",
+            "typeName": "A_RECORD",
+            "ttl": 10 
+        },
+        {
+            "host": "host3",
+            "name": "127.0.0.1",
+            "typeName": "CNAME_RECORD",
+            "ttl": 10 
+        }
+    ],
     "statuses": [
         {
             "description": "Edge: Puts server in CCR config file in this state, but CCR will never route traffic to it. Mid: Server will not be included in parent.config files for its edge caches",
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 301d5d6..252851d 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -315,7 +315,12 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{1.3, http.MethodPost, `servers/{id}/deliveryservices$`, server.AssignDeliveryServicesToServerHandler(d.DB), auth.PrivLevelOperations, Authenticated, nil},
 		{1.3, http.MethodGet, `servers/{host_name}/update_status$`, server.GetServerUpdateStatusHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
 
+		//StaticDNSEntries
 		{1.1, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadOnlyHandler(staticdnsentry.GetReaderSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodPut, `staticdnsentries/?$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
+		{1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
+		{1.3, http.MethodDelete, `staticdnsentries/?$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
 
 		//ProfileParameters
 		{1.1, http.MethodGet, `profiles/{id}/parameters/?(\.json)?$`, profileparameter.GetProfileID(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},


[trafficcontrol] 08/13: cleaned up unused insert funcs

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit c2f3ac4a29e44f9eee525e0e0525ae80af3505f6
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu May 31 08:31:03 2018 -0600

    cleaned up unused insert funcs
---
 traffic_ops/testing/api/v13/todb.go | 111 ------------------------------------
 1 file changed, 111 deletions(-)

diff --git a/traffic_ops/testing/api/v13/todb.go b/traffic_ops/testing/api/v13/todb.go
index 7f97673..6936194 100644
--- a/traffic_ops/testing/api/v13/todb.go
+++ b/traffic_ops/testing/api/v13/todb.go
@@ -166,95 +166,6 @@ INSERT INTO tenant (name, active, parent_id, last_updated) VALUES ('badtenant',
 	return nil
 }
 
-// SetupDeliveryServices ...
-func SetupDeliveryServices(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-INSERT INTO deliveryservice (id, xml_id, active, dscp, signing_algorithm, qstring_ignore, geo_limit, http_bypass_fqdn, dns_bypass_ip, dns_bypass_ip6, dns_bypass_ttl, org_server_fqdn, type, profile, cdn_id, ccr_dns_ttl, global_max_mbps, global_max_tps, long_desc, long_desc_1, long_desc_2, max_dns_answers, info_url, miss_lat, miss_long, check_path, last_updated, protocol, ssl_key_version, ipv6_routing_enabled, range_request_handling, edge_header_rewrite, origin_shield, mid_header_rewrite,  [...]
-`
-	err := execSQL(db, sqlStmt, "deliveryservice")
-	if err != nil {
-		return fmt.Errorf("exec failed %v", err)
-	}
-	return nil
-}
-
-// SetupRegexes ...
-func SetupRegexes(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (100, '.*\.omg-01\..*', 19, '2018-01-19 21:58:36.120746');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1000, '.*\.target-ds1\..*', 19, '2018-01-19 21:58:36.125624');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1100, '.*\.target-ds2\..*', 19, '2018-01-19 21:58:36.128372');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1200, '.*\.target-ds3\..*', 19, '2018-01-19 21:58:36.130749');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1300, '.*\.target-ds4\..*', 19, '2018-01-19 21:58:36.133992');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1400, '.*\.target-ds5\..*', 19, '2018-01-19 21:58:36.136503');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1500, '.*\.target-ds6\..*', 19, '2018-01-19 21:58:36.138890');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1600, '.*\.target-ds7\..*', 19, '2018-01-19 21:58:36.140495');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1700, '.*\.target-ds8\..*', 19, '2018-01-19 21:58:36.142473');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1800, '.*\.target-ds9\..*', 19, '2018-01-19 21:58:36.144087');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (1900, '.*\.target-ds10\..*', 19, '2018-01-19 21:58:36.145505');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (200, '.*\.foo\..*', 19, '2018-01-19 21:58:36.146953');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (300, '.*/force-to-one/.*', 20, '2018-01-19 21:58:36.149052');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (400, '.*/force-to-one-also/.*', 20, '2018-01-19 21:58:36.150904');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (500, '.*/go-to-four/.*', 20, '2018-01-19 21:58:36.152416');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (600, '.*/use-three/.*', 20, '2018-01-19 21:58:36.153884');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (700, '.*\.new-steering-ds\..*', 19, '2018-01-19 21:58:36.155352');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (800, '.*\.steering-ds1\..*', 19, '2018-01-19 21:58:36.156867');
-INSERT INTO regex (id, pattern, type, last_updated) VALUES (900, '.*\.steering-ds2\..*', 19, '2018-01-19 21:58:36.158999');
-`
-	err := execSQL(db, sqlStmt, "regex")
-	if err != nil {
-		return fmt.Errorf("exec failed %v", err)
-	}
-	return nil
-}
-
-// SetupDeliveryServiceRegexes ...
-func SetupDeliveryServiceRegexes(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (200, 100, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (400, 100, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (400, 1000, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (500, 1100, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (600, 1200, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (700, 1300, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (800, 1400, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (900, 1500, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (1000, 1600, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (1100, 1700, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (1200, 1800, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (1300, 1900, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (100, 200, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (400, 200, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (700, 300, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (600, 400, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (300, 600, 0);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (100, 800, 1);
-INSERT INTO deliveryservice_regex (deliveryservice, regex, set_number) VALUES (200, 900, 0);
-`
-	err := execSQL(db, sqlStmt, "deliveryservice_regex")
-	if err != nil {
-		return fmt.Errorf("exec failed %v", err)
-	}
-	return nil
-}
-
 // SetupDeliveryServiceTmUsers ...
 func SetupDeliveryServiceTmUsers(db *sql.DB) error {
 
@@ -268,28 +179,6 @@ INSERT INTO deliveryservice_tmuser (deliveryservice, tm_user_id, last_updated) V
 	return nil
 }
 
-// SetupDeliveryServiceServers ...
-func SetupDeliveryServiceServers(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (100, 300, '2018-01-19 21:19:32.396609');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (100, 1300, '2018-01-19 21:19:32.408819');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (100, 100, '2018-01-19 21:19:32.414612');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (200, 800, '2018-01-19 21:19:32.420745');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (200, 700, '2018-01-19 21:19:32.426505');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (500, 1500, '2018-01-19 21:19:32.434097');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (500, 1400, '2018-01-19 21:19:32.439622');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (600, 1400, '2018-01-19 21:19:32.440831');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (600, 1500, '2018-01-19 21:19:32.442121');
-INSERT INTO deliveryservice_server (deliveryservice, server, last_updated) VALUES (700, 900, '2018-01-19 21:19:32.443372');
-`
-	err := execSQL(db, sqlStmt, "deliveryservice_server")
-	if err != nil {
-		return fmt.Errorf("exec failed %v", err)
-	}
-	return nil
-}
-
 // SetupJobStatuses ...
 func SetupJobStatuses(db *sql.DB) error {
 


[trafficcontrol] 06/13: successfully tested the Create and Update

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 96e4a81e6bf00771ef61849510fe7a4a9f6472aa
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed May 30 15:36:47 2018 -0600

    successfully tested the Create and Update
---
 lib/go-tc/v13/staticdnsentries.go                  |  46 ++-
 .../testing/api/v13/staticdnsentries_test.go       |  47 ++-
 traffic_ops/testing/api/v13/tc-fixtures.json       | 315 +++++++++++----------
 traffic_ops/traffic_ops_golang/routes.go           |   7 +-
 .../staticdnsentry/staticdnsentry.go               |   7 +-
 5 files changed, 239 insertions(+), 183 deletions(-)

diff --git a/lib/go-tc/v13/staticdnsentries.go b/lib/go-tc/v13/staticdnsentries.go
index 14941f4..cfb1ef8 100644
--- a/lib/go-tc/v13/staticdnsentries.go
+++ b/lib/go-tc/v13/staticdnsentries.go
@@ -34,15 +34,23 @@ type StaticDNSEntry struct {
 	// required: true
 	Address string `json:"address" db:"address"`
 
-	// The Cachegroup associated
+	// The Cachegroup Name associated
 	//
-	CacheGroup string `json:"cachegroup" db:"cachegroup"`
+	CacheGroupName string `json:"cachegroup"`
+
+	// The Cachegroup ID associated
+	//
+	CacheGroupID int `json:"cachegroupId" db:"cachegroup_id"`
 
 	// The DeliveryService associated
 	//
-	// required: true
 	DeliveryService string `json:"deliveryservice" db:"dsname"`
 
+	// The DeliveryService associated
+	//
+	// required: true
+	DeliveryServiceID int `json:"deliveryserviceId" db:"deliveryservice_id"`
+
 	// The host of the static dns entry
 	//
 	// required: true
@@ -64,9 +72,13 @@ type StaticDNSEntry struct {
 
 	// The type of the static DNS entry
 	//
-	// required: true
 	// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
-	Type string `json:"type" db:"type"`
+	Type string `json:"type"`
+
+	// The type id of the static DNS entry
+	//
+	// required: true
+	TypeID int `json:"typeId" db:"type_id"`
 }
 
 // StatisDNSEntryNullable ...
@@ -77,15 +89,23 @@ type StaticDNSEntryNullable struct {
 	// required: true
 	Address *string `json:"address" db:"address"`
 
-	// The Cachegroup associated
+	// The Cachegroup Name associated
 	//
-	CacheGroup *string `json:"cachegroup" db:"cachegroup"`
+	CacheGroupName *string `json:"cachegroup" db:"cachegroup"`
 
-	// The DeliveryService associated
+	// The Cachegroup ID associated
+	//
+	CacheGroupID *int `json:"cachegroupId" db:"cachegroup_id"`
+
+	// The DeliveryService Name associated
 	//
-	// required: true
 	DeliveryService *string `json:"deliveryservice" db:"dsname"`
 
+	// DeliveryService ID of the StaticDNSEntry
+	//
+	// required: true
+	DeliveryServiceID *int `json:"deliveryserviceId" db:"deliveryservice_id"`
+
 	// The host of the static dns entry
 	//
 	// required: true
@@ -107,7 +127,11 @@ type StaticDNSEntryNullable struct {
 
 	// The type of the static DNS entry
 	//
-	// required: true
 	// enum: ["A_RECORD", "AAAA_RECORD", "CNAME_RECORD"]
-	Type *string `json:"type" db:"type"`
+	Type *string `json:"type"`
+
+	// The type id of the static DNS entry
+	//
+	// required: true
+	TypeID int `json:"typeId" db:"type_id"`
 }
diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
index 3e88032..1cbe9ed 100644
--- a/traffic_ops/testing/api/v13/staticdnsentries_test.go
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -56,14 +56,31 @@ func TestStaticDNSEntries(t *testing.T) {
 func CreateTestStaticDNSEntries(t *testing.T) {
 
 	for _, staticDNSEntry := range testData.StaticDNSEntries {
-		// GET EDGE type
+
+		// GET StaticDNSEntry type
 		respTypes, _, err := TOSession.GetTypeByName(staticDNSEntry.Type)
-		fmt.Printf("respTypes ---> %v\n", respTypes)
 		if err != nil {
 			t.Errorf("cannot GET Type by name: %v\n", err)
 		}
 		respType := respTypes[0]
-		staticDNSEntry.Type = respType.Name
+		staticDNSEntry.TypeID = respType.ID
+
+		// GET DeliveryService to associate
+		respDSes, _, err := TOSession.GetDeliveryServiceByXMLID(staticDNSEntry.DeliveryService)
+		if err != nil {
+			t.Errorf("cannot GET DeliveryService by XMLID: %v\n", err)
+		}
+		respDS := respDSes[0]
+		staticDNSEntry.DeliveryServiceID = respDS.ID
+
+		// GET Cachegroup to associate
+		respGroups, _, err := TOSession.GetCacheGroupByName(staticDNSEntry.CacheGroupName)
+		if err != nil {
+			t.Errorf("cannot GET CacheGroup by Name: %v\n", err)
+		}
+		respGroup := respGroups[0]
+		staticDNSEntry.CacheGroupID = respGroup.ID
+
 		resp, _, err := TOSession.CreateStaticDNSEntry(staticDNSEntry)
 		log.Debugln("Response: ", resp)
 		if err != nil {
@@ -75,25 +92,27 @@ func CreateTestStaticDNSEntries(t *testing.T) {
 
 func UpdateTestStaticDNSEntries(t *testing.T) {
 
-	firstStaticDNSEntrie := testData.StaticDNSEntries[0]
-	// Retrieve the StaticDNSEntrie by name so we can get the id for the Update
-	resp, _, err := TOSession.GetStaticDNSEntriesByHost(firstStaticDNSEntrie.Host)
+	firstStaticDNSEntry := testData.StaticDNSEntries[0]
+	// Retrieve the StaticDNSEntries by name so we can get the id for the Update
+	resp, _, err := TOSession.GetStaticDNSEntriesByHost(firstStaticDNSEntry.Host)
 	if err != nil {
-		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntrie.Host, err)
+		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntry.Host, err)
 	}
 	remoteStaticDNSEntry := resp[0]
+	fmt.Printf("remoteStaticDNSEntry ---> %v\n", remoteStaticDNSEntry)
+	fmt.Printf("remoteStaticDNSEntry.ID ---> %v\n", remoteStaticDNSEntry.ID)
 	expectedAddress := "address99"
 	remoteStaticDNSEntry.Address = expectedAddress
 	var alert tc.Alerts
 	alert, _, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
 	if err != nil {
-		t.Errorf("cannot UPDATE StaticDNSEntrie by id: %v - %v\n", err, alert)
+		t.Errorf("cannot UPDATE StaticDNSEntries by id: %v - %v\n", err, alert)
 	}
 
-	// Retrieve the StaticDNSEntrie to check StaticDNSEntrie name got updated
+	// Retrieve the StaticDNSEntries to check StaticDNSEntries name got updated
 	resp, _, err = TOSession.GetStaticDNSEntryByID(remoteStaticDNSEntry.ID)
 	if err != nil {
-		t.Errorf("cannot GET StaticDNSEntries by name: '$%s', %v\n", firstStaticDNSEntrie.Host, err)
+		t.Errorf("cannot GET StaticDNSEntries by name: '$%s', %v\n", firstStaticDNSEntry.Host, err)
 	}
 	respStaticDNSEntry := resp[0]
 	if respStaticDNSEntry.Address != expectedAddress {
@@ -115,17 +134,17 @@ func GetTestStaticDNSEntries(t *testing.T) {
 func DeleteTestStaticDNSEntries(t *testing.T) {
 
 	for _, staticDNSEntry := range testData.StaticDNSEntries {
-		// Retrieve the StaticDNSEntrie by name so we can get the id for the Update
+		// Retrieve the StaticDNSEntries by name so we can get the id for the Update
 		resp, _, err := TOSession.GetStaticDNSEntriesByHost(staticDNSEntry.Host)
 		if err != nil {
 			t.Errorf("cannot GET StaticDNSEntries by name: %v - %v\n", staticDNSEntry.Host, err)
 		}
 		if len(resp) > 0 {
-			respStaticDNSEntrie := resp[0]
+			respStaticDNSEntry := resp[0]
 
-			_, _, err := TOSession.DeleteStaticDNSEntryByID(respStaticDNSEntrie.ID)
+			_, _, err := TOSession.DeleteStaticDNSEntryByID(respStaticDNSEntry.ID)
 			if err != nil {
-				t.Errorf("cannot DELETE StaticDNSEntrie by name: '%s' %v\n", respStaticDNSEntrie.Host, err)
+				t.Errorf("cannot DELETE StaticDNSEntrie by name: '%s' %v\n", respStaticDNSEntry.Host, err)
 			}
 
 			// Retrieve the StaticDNSEntrie to see if it got deleted
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index d0799d0..3381924 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -174,137 +174,137 @@
     ],
     "deliveryServices": [
         {
-          "active": true,
-          "cacheurl": "cacheUrl1",
-          "ccrDnsTtl": 3600,
-          "cdnName": "cdn1",
-          "checkPath": "",
-          "deepCachingType": "NEVER",
-          "displayName": "ds1DisplayName",
-          "dnsBypassCname": null,
-          "dnsBypassIp": "",
-          "dnsBypassIp6": "",
-          "dnsBypassTtl": 30,
-          "dscp": 40,
-          "edgeHeaderRewrite": "edgeHeader1",
-          "exampleURLs": [
-            "http://ccr.ds1.example.net",
-            "https://ccr.ds1.example.net"
-          ],
-          "fqPacingRate": 0,
-          "geoLimit": 0,
-          "geoLimitCountries": "",
-          "geoLimitRedirectURL": null,
-          "geoProvider": 0,
-          "globalMaxMbps": 0,
-          "globalMaxTps": 0,
-          "httpBypassFqdn": "",
-          "infoUrl": "TBD",
-          "initialDispersion": 1,
-          "ipv6RoutingEnabled": true,
-          "lastUpdated": "2018-04-06 16:48:51+00",
-          "logsEnabled": false,
-          "longDesc": "d s 1",
-          "longDesc1": "ds1",
-          "longDesc2": "ds1",
-          "matchList": [
-            {
-              "pattern": ".*\\.ds1\\..*",
-              "setNumber": 0,
-              "type": "HOST_REGEXP"
-            }
-          ],
-          "maxDnsAnswers": 0,
-          "midHeaderRewrite": "midHeader1",
-          "missLat": 41.881944,
-          "missLong": -87.627778,
-          "multiSiteOrigin": false,
-          "orgServerFqdn": "http://origin.example.net",
-          "originShield": null,
-          "profileDescription": null,
-          "profileId": null,
-          "profileName": null,
-          "protocol": 2,
-          "qstringIgnore": 1,
-          "rangeRequestHandling": 0,
-          "regexRemap": "rr1",
-          "regionalGeoBlocking": false,
-          "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/remapPlugin1.lua",
-          "routingName": "ccr-ds1",
-          "signed": false,
-          "signingAlgorithm": "url_sig",
-          "sslKeyVersion": 2,
-          "tenant": "tenant1",
-          "tenantName": "tenant1",
-          "type": "HTTP_LIVE",
-          "xmlId": "ds1",
-          "anonymousBlockingEnabled": true
-        },
-        {
-          "active": true,
-          "cacheurl": "cacheUrl2",
-          "ccrDnsTtl": 3600,
-          "cdnName": "cdn1",
-          "checkPath": "",
-          "deepCachingType": "NEVER",
-          "displayName": "d s 1",
-          "dnsBypassCname": null,
-          "dnsBypassIp": "",
-          "dnsBypassIp6": "",
-          "dnsBypassTtl": 30,
-          "dscp": 40,
-          "edgeHeaderRewrite": "edgeRewrite2",
-          "exampleURLs": [
-            "http://ccr.ds2.example.net",
-            "https://ccr.ds2x.example.net"
-          ],
-          "fqPacingRate": 0,
-          "geoLimit": 0,
-          "geoLimitCountries": "",
-          "geoLimitRedirectURL": null,
-          "geoProvider": 0,
-          "globalMaxMbps": 0,
-          "globalMaxTps": 0,
-          "httpBypassFqdn": "",
-          "infoUrl": "TBD",
-          "initialDispersion": 1,
-          "ipv6RoutingEnabled": true,
-          "lastUpdated": "2018-04-06 16:48:51+00",
-          "logsEnabled": false,
-          "longDesc": "d s 1",
-          "longDesc1": "ds2",
-          "longDesc2": "ds2",
-          "matchList": [
-            {
-              "pattern": ".*\\.ds2\\..*",
-              "setNumber": 0,
-              "type": "HOST_REGEXP"
-            }
-          ],
-          "maxDnsAnswers": 0,
-          "midHeaderRewrite": "midRewrite2",
-          "missLat": 41.881944,
-          "missLong": -87.627778,
-          "multiSiteOrigin": false,
-          "orgServerFqdn": "http://origin.ds2.example.net",
-          "originShield": null,
-          "profileDescription": null,
-          "profileName": null,
-          "protocol": 2,
-          "qstringIgnore": 1,
-          "rangeRequestHandling": 0,
-          "regexRemap": "regexRemap2",
-          "regionalGeoBlocking": false,
-          "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/ds2plugin.lua",
-          "routingName": "ccr-ds2",
-          "signed": false,
-          "signingAlgorithm": "url_sig",
-          "sslKeyVersion": 2,
-          "tenant": "tenant2",
-          "tenantName": "tenant2",
-          "type": "HTTP_LIVE",
-          "xmlId": "ds2",
-          "anonymousBlockingEnabled": true
+            "active": true,
+            "cacheurl": "cacheUrl1",
+            "ccrDnsTtl": 3600,
+            "cdnName": "cdn1",
+            "checkPath": "",
+            "deepCachingType": "NEVER",
+            "displayName": "ds1DisplayName",
+            "dnsBypassCname": null,
+            "dnsBypassIp": "",
+            "dnsBypassIp6": "",
+            "dnsBypassTtl": 30,
+            "dscp": 40,
+            "edgeHeaderRewrite": "edgeHeader1",
+            "exampleURLs": [
+                "http://ccr.ds1.example.net",
+                "https://ccr.ds1.example.net"
+            ],
+            "fqPacingRate": 0,
+            "geoLimit": 0,
+            "geoLimitCountries": "",
+            "geoLimitRedirectURL": null,
+            "geoProvider": 0,
+            "globalMaxMbps": 0,
+            "globalMaxTps": 0,
+            "httpBypassFqdn": "",
+            "infoUrl": "TBD",
+            "initialDispersion": 1,
+            "ipv6RoutingEnabled": true,
+            "lastUpdated": "2018-04-06 16:48:51+00",
+            "logsEnabled": false,
+            "longDesc": "d s 1",
+            "longDesc1": "ds1",
+            "longDesc2": "ds1",
+            "matchList": [
+                {
+                    "pattern": ".*\\.ds1\\..*",
+                    "setNumber": 0,
+                    "type": "HOST_REGEXP"
+                }
+            ],
+            "maxDnsAnswers": 0,
+            "midHeaderRewrite": "midHeader1",
+            "missLat": 41.881944,
+            "missLong": -87.627778,
+            "multiSiteOrigin": false,
+            "orgServerFqdn": "http://origin.example.net",
+            "originShield": null,
+            "profileDescription": null,
+            "profileId": null,
+            "profileName": null,
+            "protocol": 2,
+            "qstringIgnore": 1,
+            "rangeRequestHandling": 0,
+            "regexRemap": "rr1",
+            "regionalGeoBlocking": false,
+            "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/remapPlugin1.lua",
+            "routingName": "ccr-ds1",
+            "signed": false,
+            "signingAlgorithm": "url_sig",
+            "sslKeyVersion": 2,
+            "tenant": "tenant1",
+            "tenantName": "tenant1",
+            "type": "HTTP_LIVE",
+            "xmlId": "ds1",
+            "anonymousBlockingEnabled": true
+        },
+        {
+            "active": true,
+            "cacheurl": "cacheUrl2",
+            "ccrDnsTtl": 3600,
+            "cdnName": "cdn1",
+            "checkPath": "",
+            "deepCachingType": "NEVER",
+            "displayName": "d s 1",
+            "dnsBypassCname": null,
+            "dnsBypassIp": "",
+            "dnsBypassIp6": "",
+            "dnsBypassTtl": 30,
+            "dscp": 40,
+            "edgeHeaderRewrite": "edgeRewrite2",
+            "exampleURLs": [
+                "http://ccr.ds2.example.net",
+                "https://ccr.ds2x.example.net"
+            ],
+            "fqPacingRate": 0,
+            "geoLimit": 0,
+            "geoLimitCountries": "",
+            "geoLimitRedirectURL": null,
+            "geoProvider": 0,
+            "globalMaxMbps": 0,
+            "globalMaxTps": 0,
+            "httpBypassFqdn": "",
+            "infoUrl": "TBD",
+            "initialDispersion": 1,
+            "ipv6RoutingEnabled": true,
+            "lastUpdated": "2018-04-06 16:48:51+00",
+            "logsEnabled": false,
+            "longDesc": "d s 1",
+            "longDesc1": "ds2",
+            "longDesc2": "ds2",
+            "matchList": [
+                {
+                    "pattern": ".*\\.ds2\\..*",
+                    "setNumber": 0,
+                    "type": "HOST_REGEXP"
+                }
+            ],
+            "maxDnsAnswers": 0,
+            "midHeaderRewrite": "midRewrite2",
+            "missLat": 41.881944,
+            "missLong": -87.627778,
+            "multiSiteOrigin": false,
+            "orgServerFqdn": "http://origin.ds2.example.net",
+            "originShield": null,
+            "profileDescription": null,
+            "profileName": null,
+            "protocol": 2,
+            "qstringIgnore": 1,
+            "rangeRequestHandling": 0,
+            "regexRemap": "regexRemap2",
+            "regionalGeoBlocking": false,
+            "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/ds2plugin.lua",
+            "routingName": "ccr-ds2",
+            "signed": false,
+            "signingAlgorithm": "url_sig",
+            "sslKeyVersion": 2,
+            "tenant": "tenant2",
+            "tenantName": "tenant2",
+            "type": "HTTP_LIVE",
+            "xmlId": "ds2",
+            "anonymousBlockingEnabled": true
         }
     ],
     "divisions": [
@@ -616,16 +616,24 @@
     ],
     "roles": [
         {
-            "name":"new_admin",
-            "description":"super-user 2",
-            "privLevel":30,
-            "capabilities":["all-read","all-write", "cdn-read"]
-        },
-        {
-            "name":"bad_admin",
-            "description":"super-user 3",
-            "privLevel":30,
-            "capabilities":["all-read","all-write","invalid-capability"]
+            "name": "new_admin",
+            "description": "super-user 2",
+            "privLevel": 30,
+            "capabilities": [
+                "all-read",
+                "all-write",
+                "cdn-read"
+            ]
+        },
+        {
+            "name": "bad_admin",
+            "description": "super-user 3",
+            "privLevel": 30,
+            "capabilities": [
+                "all-read",
+                "all-write",
+                "invalid-capability"
+            ]
         }
     ],
     "servers": [
@@ -1016,25 +1024,28 @@
     ],
     "staticdnsentries": [
         {
-            "host": "host1",
             "address": "address1",
-            "dsname": "ds1",
-            "typename": "AAAA_RECORD",
-            "ttl": 10 
+            "cachegroup": "cachegroup1",
+            "deliveryservice": "test-ds1",
+            "host": "host1",
+            "type": "AAAA_RECORD",
+            "ttl": 10
         },
         {
-            "host": "host2",
             "address": "address2",
-            "dsname": "ds2",
-            "typename": "A_RECORD",
-            "ttl": 10 
+            "cachegroup": "cachegroup2",
+            "deliveryservice": "test-ds1",
+            "host": "host2",
+            "type": "A_RECORD",
+            "ttl": 10
         },
         {
             "host": "host3",
-            "dsName": "ds3",
+            "deliveryservice": "test-ds1",
+            "cachegroup": "cachegroup2",
             "address": "127.0.0.1",
-            "typename": "CNAME_RECORD",
-            "ttl": 10 
+            "type": "CNAME_RECORD",
+            "ttl": 10
         }
     ],
     "statuses": [
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 252851d..d976577 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -318,9 +318,10 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		//StaticDNSEntries
 		{1.1, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadOnlyHandler(staticdnsentry.GetReaderSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
 		{1.3, http.MethodGet, `staticdnsentries/?(\.json)?$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodPut, `staticdnsentries/?$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
-		{1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
-		{1.3, http.MethodDelete, `staticdnsentries/?$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelAdmin, Authenticated, nil},
+		{1.3, http.MethodGet, `staticdnsentries/{id}$`, api.ReadHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodPut, `staticdnsentries/{id}$`, api.UpdateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodPost, `staticdnsentries/?$`, api.CreateHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodDelete, `staticdnsentries/{id}$`, api.DeleteHandler(staticdnsentry.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 
 		//ProfileParameters
 		{1.1, http.MethodGet, `profiles/{id}/parameters/?(\.json)?$`, profileparameter.GetProfileID(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index 988b3ab..0c2ac98 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -157,10 +157,10 @@ host,
 type,
 ttl) VALUES (
 :address,
-:deliveryservice,
-:cachegroup,
+:deliveryservice_id,
+:cachegroup_id,
 :host,
-:type,
+:type_id,
 :ttl) RETURNING id,last_updated`
 	return query
 }
@@ -292,6 +292,7 @@ func selectQuery() string {
 	return `SELECT
 ds.xml_id as dsname,
 sde.host,
+sde.id as id,
 sde.ttl,
 sde.address,
 tp.name as type,


[trafficcontrol] 09/13: returned last_updated in the GET

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 65215b7299425068e4af8696b5e49ec7c2b89462
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu May 31 09:47:15 2018 -0600

    returned last_updated in the GET
---
 traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index c64bc4c..292338c 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -298,6 +298,7 @@ sde.id as id,
 sde.deliveryservice as deliveryservice_id,
 sde.ttl,
 sde.address,
+sde.last_updated,
 tp.id as type_id,
 tp.name as type,
 cg.id as cachegroup_id,


[trafficcontrol] 13/13: fixed the unit tests after merge conflicts

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 125c7e197102da0ef095c7fcf76853f0c71b057a
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Jul 10 16:30:52 2018 -0600

    fixed the unit tests after merge conflicts
---
 .../traffic_ops_golang/staticdnsentry/staticdnsentry_test.go | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry_test.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry_test.go
index 9597758..122062a 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry_test.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry_test.go
@@ -25,6 +25,7 @@ import (
 	"strings"
 	"testing"
 
+	util "github.com/apache/trafficcontrol/lib/go-util"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/test"
 )
@@ -69,18 +70,21 @@ func TestInterfaces(t *testing.T) {
 func TestValidate(t *testing.T) {
 	// invalid name, empty domainname
 	ts := TOStaticDNSEntry{}
-	errs := test.SortErrors(ts.Validate(nil))
+	errs := util.JoinErrsStr(test.SortErrors(test.SplitErrors(ts.Validate())))
 
-	expectedErrs := []error{
+	expectedErrs := util.JoinErrsStr([]error{
 		errors.New(`'address' cannot be blank`),
 		errors.New(`'dsname' cannot be blank`),
 		errors.New(`'host' cannot be blank`),
 		errors.New(`'ttl' cannot be blank`),
 		errors.New(`'type' cannot be blank`),
-	}
+	})
 
 	if !reflect.DeepEqual(expectedErrs, errs) {
-		t.Errorf("expected %s, got %s", expectedErrs, errs)
+		t.Errorf("expected %s, GOT %s", expectedErrs, errs)
 	}
+	//if err != nil {
+	//t.Errorf("expected nil, got %s", err)
+	//}
 
 }


[trafficcontrol] 07/13: successfully built the API Tests for StaticDNSEntries

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 712fbe2983f6125441618376053574bc6d134a0b
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu May 31 08:03:18 2018 -0600

    successfully built the API Tests for StaticDNSEntries
---
 traffic_ops/testing/api/v13/profiles_test.go                  |  3 ---
 traffic_ops/testing/api/v13/staticdnsentries_test.go          | 10 +++-------
 .../traffic_ops_golang/staticdnsentry/staticdnsentry.go       | 11 ++++++++---
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/traffic_ops/testing/api/v13/profiles_test.go b/traffic_ops/testing/api/v13/profiles_test.go
index 42dc0c8..0610325 100644
--- a/traffic_ops/testing/api/v13/profiles_test.go
+++ b/traffic_ops/testing/api/v13/profiles_test.go
@@ -16,7 +16,6 @@
 package v13
 
 import (
-	"fmt"
 	"testing"
 
 	"github.com/apache/trafficcontrol/lib/go-log"
@@ -46,8 +45,6 @@ func CreateTestProfiles(t *testing.T) {
 	for _, pr := range testData.Profiles {
 		cdns, _, err := TOSession.GetCDNByName(pr.CDNName)
 		respCDN := cdns[0]
-		cdnName := respCDN.Name
-		fmt.Printf("profileName: %s, cdnName %s\n", pr.Name, cdnName)
 		pr.CDNID = respCDN.ID
 
 		resp, _, err := TOSession.CreateProfile(pr)
diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
index 1cbe9ed..b74336d 100644
--- a/traffic_ops/testing/api/v13/staticdnsentries_test.go
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -16,7 +16,6 @@ package v13
 */
 
 import (
-	"fmt"
 	"testing"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-log"
@@ -38,9 +37,8 @@ func TestStaticDNSEntries(t *testing.T) {
 	CreateTestStaticDNSEntries(t)
 	GetTestStaticDNSEntries(t)
 	UpdateTestStaticDNSEntries(t)
-	DeleteTestStaticDNSEntries(t)
-	DeleteTestTypes(t)
 	DeleteTestDeliveryServices(t)
+	DeleteTestStaticDNSEntries(t)
 	DeleteTestServers(t)
 	DeleteTestCacheGroups(t)
 	DeleteTestPhysLocations(t)
@@ -99,14 +97,12 @@ func UpdateTestStaticDNSEntries(t *testing.T) {
 		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntry.Host, err)
 	}
 	remoteStaticDNSEntry := resp[0]
-	fmt.Printf("remoteStaticDNSEntry ---> %v\n", remoteStaticDNSEntry)
-	fmt.Printf("remoteStaticDNSEntry.ID ---> %v\n", remoteStaticDNSEntry.ID)
-	expectedAddress := "address99"
+	expectedAddress := "address2"
 	remoteStaticDNSEntry.Address = expectedAddress
 	var alert tc.Alerts
 	alert, _, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
 	if err != nil {
-		t.Errorf("cannot UPDATE StaticDNSEntries by id: %v - %v\n", err, alert)
+		t.Errorf("cannot UPDATE StaticDNSEntries using url: %v - %v\n", err, alert)
 	}
 
 	// Retrieve the StaticDNSEntries to check StaticDNSEntries name got updated
diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index 0c2ac98..c64bc4c 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -171,6 +171,7 @@ ttl) VALUES (
 //if so, it will return an errorType of DataConflict and the type should be appended to the
 //generic error message returned
 func (staticDNSEntry *TOStaticDNSEntry) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
+	fmt.Printf("staticDNSEntry.DeliveryService ---> %v\n", *staticDNSEntry.DeliveryService)
 	rollbackTransaction := true
 	tx, err := db.Beginx()
 	defer func() {
@@ -233,11 +234,12 @@ func (staticDNSEntry *TOStaticDNSEntry) Update(db *sqlx.DB, user auth.CurrentUse
 func updateQuery() string {
 	query := `UPDATE
 staticdnsentry SET
+id=:id,
 address=:address,
-deliveryservice=:deliveryservice,
-cachegroup=:cachegroup,
+deliveryservice=:deliveryservice_id,
+cachegroup=:cachegroup_id,
 host=:host,
-type=:type,
+type=:type_id,
 ttl=:ttl
 WHERE id=:id RETURNING last_updated`
 	return query
@@ -293,9 +295,12 @@ func selectQuery() string {
 ds.xml_id as dsname,
 sde.host,
 sde.id as id,
+sde.deliveryservice as deliveryservice_id,
 sde.ttl,
 sde.address,
+tp.id as type_id,
 tp.name as type,
+cg.id as cachegroup_id,
 cg.name as cachegroup
 FROM staticdnsentry as sde
 JOIN type as tp on sde.type = tp.id


[trafficcontrol] 01/13: fixed import conflicts

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit b6e0971ffd1e1ed2da981da5f1c7a7620c300d35
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Jun 25 06:58:27 2018 -0600

    fixed import conflicts
---
 lib/go-tc/v13/staticdnsentry.go                    | 108 +++++++++++++++++++++
 .../staticdnsentry/staticdnsentry_test.go          |  86 ++++++++++++++++
 2 files changed, 194 insertions(+)

diff --git a/lib/go-tc/v13/staticdnsentry.go b/lib/go-tc/v13/staticdnsentry.go
new file mode 100644
index 0000000..a3da4f7
--- /dev/null
+++ b/lib/go-tc/v13/staticdnsentry.go
@@ -0,0 +1,108 @@
+package v13
+
+import tc "github.com/apache/trafficcontrol/lib/go-tc"
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+// StatisDNSEntry ...
+type StaticDNSEntry struct {
+
+	// The static IP Address or fqdn of the static dns entry
+	//
+	// required: true
+	Address string `json:"address" db:"address"`
+
+	// The Cachegroup associated
+	//
+	CacheGroup string `json:"cachegroup" db:"cachegroup"`
+
+	// The DeliveryService associated
+	//
+	// required: true
+	DeliveryService string `json:"deliveryservice" db:"dsname"`
+
+	// The host of the static dns entry
+	//
+	// required: true
+	Host string `json:"host" db:"host"`
+
+	// ID of the StaticDNSEntry
+	//
+	// required: true
+	ID int `json:"id" db:"id"`
+
+	// LastUpdated
+	//
+	LastUpdated tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+
+	// The Time To Live for the static dns entry
+	//
+	// required: true
+	TTL int64 `json:"ttl" db:"ttl"`
+
+	// The type of the static DNS entry
+	//
+	// required: true
+	// enum: ["A_RECORD", "CNAME_RECORD"]
+	Type string `json:"type" db:"type"`
+}
+
+// StatisDNSEntryNullable ...
+type StaticDNSEntryNullable struct {
+
+	// The static IP Address or fqdn of the static dns entry
+	//
+	// required: true
+	Address *string `json:"address" db:"address"`
+
+	// The Cachegroup associated
+	//
+	CacheGroup *string `json:"cachegroup" db:"cachegroup"`
+
+	// The DeliveryService associated
+	//
+	// required: true
+	DeliveryService *string `json:"deliveryservice" db:"dsname"`
+
+	// The host of the static dns entry
+	//
+	// required: true
+	Host *string `json:"host" db:"host"`
+
+	// ID of the StaticDNSEntry
+	//
+	// required: true
+	ID *int `json:"id" db:"id"`
+
+	// LastUpdated
+	//
+	LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+
+	// The Time To Live for the static dns entry
+	//
+	// required: true
+	TTL *int64 `json:"ttl" db:"ttl"`
+
+	// The type of the static DNS entry
+	//
+	// required: true
+	// enum: ["A_RECORD", "CNAME_RECORD"]
+	Type *string `json:"type" db:"type"`
+}
diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry_test.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry_test.go
new file mode 100644
index 0000000..9597758
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry_test.go
@@ -0,0 +1,86 @@
+package staticdnsentry
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 (
+	"errors"
+	"reflect"
+	"strings"
+	"testing"
+
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/test"
+)
+
+func TestFuncs(t *testing.T) {
+	if strings.Index(selectQuery(), "SELECT") != 0 {
+		t.Errorf("expected selectQuery to start with SELECT")
+	}
+	if strings.Index(insertQuery(), "INSERT") != 0 {
+		t.Errorf("expected insertQuery to start with INSERT")
+	}
+	if strings.Index(updateQuery(), "UPDATE") != 0 {
+		t.Errorf("expected updateQuery to start with UPDATE")
+	}
+	if strings.Index(deleteQuery(), "DELETE") != 0 {
+		t.Errorf("expected deleteQuery to start with DELETE")
+	}
+
+}
+
+func TestInterfaces(t *testing.T) {
+	var i interface{}
+	i = &TOStaticDNSEntry{}
+
+	if _, ok := i.(api.Creator); !ok {
+		t.Errorf("staticDNSEntry must be creator")
+	}
+	if _, ok := i.(api.Reader); !ok {
+		t.Errorf("staticDNSEntry must be reader")
+	}
+	if _, ok := i.(api.Updater); !ok {
+		t.Errorf("staticDNSEntry must be updater")
+	}
+	if _, ok := i.(api.Deleter); !ok {
+		t.Errorf("staticDNSEntry must be deleter")
+	}
+	if _, ok := i.(api.Identifier); !ok {
+		t.Errorf("staticDNSEntry must be Identifier")
+	}
+}
+
+func TestValidate(t *testing.T) {
+	// invalid name, empty domainname
+	ts := TOStaticDNSEntry{}
+	errs := test.SortErrors(ts.Validate(nil))
+
+	expectedErrs := []error{
+		errors.New(`'address' cannot be blank`),
+		errors.New(`'dsname' cannot be blank`),
+		errors.New(`'host' cannot be blank`),
+		errors.New(`'ttl' cannot be blank`),
+		errors.New(`'type' cannot be blank`),
+	}
+
+	if !reflect.DeepEqual(expectedErrs, errs) {
+		t.Errorf("expected %s, got %s", expectedErrs, errs)
+	}
+
+}