This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 8049d27 Fix DS 3.0 fields for DSRs (#5062)
8049d27 is described below
commit 8049d27ee9f3e7e7e9296ce1d6d55ca7dc7a332a
Author: Rawlin Peters <[email protected]>
AuthorDate: Tue Sep 22 15:53:13 2020 -0600
Fix DS 3.0 fields for DSRs (#5062)
Fixes #5019
---
lib/go-tc/deliveryservice_requests.go | 26 +++++++-------
lib/go-tc/deliveryservices.go | 40 +++++++++++++++++-----
.../deliveryservice/request/requests_test.go | 2 +-
3 files changed, 46 insertions(+), 22 deletions(-)
diff --git a/lib/go-tc/deliveryservice_requests.go
b/lib/go-tc/deliveryservice_requests.go
index 3da0307..b156564 100644
--- a/lib/go-tc/deliveryservice_requests.go
+++ b/lib/go-tc/deliveryservice_requests.go
@@ -406,19 +406,19 @@ type DeliveryServiceRequest struct {
// DeliveryServiceRequestNullable is used as part of the workflow to create,
// modify, or delete a delivery service.
type DeliveryServiceRequestNullable struct {
- AssigneeID *int `json:"assigneeId,omitempty"
db:"assignee_id"`
- Assignee *string `json:"assignee,omitempty"`
- AuthorID *IDNoMod `json:"authorId"
db:"author_id"`
- Author *string `json:"author"`
- ChangeType *string `json:"changeType"
db:"change_type"`
- CreatedAt *TimeNoMod `json:"createdAt"
db:"created_at"`
- ID *int `json:"id" db:"id"`
- LastEditedBy *string `json:"lastEditedBy"`
- LastEditedByID *IDNoMod `json:"lastEditedById"
db:"last_edited_by_id"`
- LastUpdated *TimeNoMod `json:"lastUpdated"
db:"last_updated"`
- DeliveryService *DeliveryServiceNullable `json:"deliveryService"
db:"deliveryservice"` // TODO version DeliveryServiceRequest
- Status *RequestStatus `json:"status" db:"status"`
- XMLID *string `json:"-" db:"xml_id"`
+ AssigneeID *int
`json:"assigneeId,omitempty" db:"assignee_id"`
+ Assignee *string `json:"assignee,omitempty"`
+ AuthorID *IDNoMod `json:"authorId"
db:"author_id"`
+ Author *string `json:"author"`
+ ChangeType *string `json:"changeType"
db:"change_type"`
+ CreatedAt *TimeNoMod `json:"createdAt"
db:"created_at"`
+ ID *int `json:"id" db:"id"`
+ LastEditedBy *string `json:"lastEditedBy"`
+ LastEditedByID *IDNoMod `json:"lastEditedById"
db:"last_edited_by_id"`
+ LastUpdated *TimeNoMod `json:"lastUpdated"
db:"last_updated"`
+ DeliveryService *DeliveryServiceNullableV30 `json:"deliveryService"
db:"deliveryservice"`
+ Status *RequestStatus `json:"status" db:"status"`
+ XMLID *string `json:"-" db:"xml_id"`
}
// UnmarshalJSON implements the json.Unmarshaller interface to suppress
unmarshalling for IDNoMod
diff --git a/lib/go-tc/deliveryservices.go b/lib/go-tc/deliveryservices.go
index 99342c4..52cc7fc 100644
--- a/lib/go-tc/deliveryservices.go
+++ b/lib/go-tc/deliveryservices.go
@@ -608,21 +608,45 @@ func (ds *DeliveryServiceNullableV30)
validateTopologyFields() error {
return nil
}
-// Value implements the driver.Valuer interface
-// marshals struct to json to pass back as a json.RawMessage
-func (d *DeliveryServiceNullable) Value() (driver.Value, error) {
- b, err := json.Marshal(d)
+func jsonValue(v interface{}) (driver.Value, error) {
+ b, err := json.Marshal(v)
return b, err
}
-// Scan implements the sql.Scanner interface
-// expects json.RawMessage and unmarshals to a deliveryservice struct
-func (d *DeliveryServiceNullable) Scan(src interface{}) error {
+func jsonScan(src interface{}, dest interface{}) error {
b, ok := src.([]byte)
if !ok {
return fmt.Errorf("expected deliveryservice in byte array form;
got %T", src)
}
- return json.Unmarshal(b, d)
+ return json.Unmarshal(b, dest)
+}
+
+// NOTE: the driver.Valuer and sql.Scanner interface implementations are
+// necessary for Delivery Service Requests which store and read raw JSON
+// from the database.
+
+// Value implements the driver.Valuer interface --
+// marshals struct to json to pass back as a json.RawMessage.
+func (ds *DeliveryServiceNullable) Value() (driver.Value, error) {
+ return jsonValue(ds)
+}
+
+// Scan implements the sql.Scanner interface --
+// expects json.RawMessage and unmarshals to a DeliveryServiceNullable struct.
+func (ds *DeliveryServiceNullable) Scan(src interface{}) error {
+ return jsonScan(src, ds)
+}
+
+// Value implements the driver.Valuer interface --
+// marshals struct to json to pass back as a json.RawMessage.
+func (ds *DeliveryServiceNullableV30) Value() (driver.Value, error) {
+ return jsonValue(ds)
+}
+
+// Scan implements the sql.Scanner interface --
+// expects json.RawMessage and unmarshals to a DeliveryServiceNullableV30
struct.
+func (ds *DeliveryServiceNullableV30) Scan(src interface{}) error {
+ return jsonScan(src, ds)
}
// DeliveryServiceMatch ...
diff --git
a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go
b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go
index f932f5a..521d6c2 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests_test.go
@@ -58,7 +58,7 @@ func TestGetDeliveryServiceRequest(t *testing.T) {
b := true
u := "UPDATE"
st := tc.RequestStatusSubmitted
- ds := tc.DeliveryServiceNullable{}
+ ds := tc.DeliveryServiceNullableV30{}
ds.XMLID = &s
ds.CDNID = &i
ds.LogsEnabled = &b