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

shamrick 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 c59d011a36 Api v5 should return RFC3339 timestamps for Delivery 
Service Servers (#7720)
c59d011a36 is described below

commit c59d011a36938c2a1ce7259c9e76bc2afe773fd8
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Wed Aug 23 09:47:26 2023 -0600

    Api v5 should return RFC3339 timestamps for Delivery Service Servers (#7720)
    
    * Api v5 should return RFC3339 timestamps for Delivery Service Servers
    
    * Add changelog
    
    * code review
---
 CHANGELOG.md                                       |  3 ++-
 docs/source/api/v5/deliveryserviceserver.rst       |  4 ++--
 lib/go-tc/deliveryservice_servers.go               | 27 +++++++++++++++++++++
 .../deliveryservice/servers/servers.go             | 28 +++++++++++++++++++++-
 traffic_ops/v5-client/deliveryserviceserver.go     |  4 ++--
 5 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54b5d46155..56f21ba8f3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -78,7 +78,8 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 ### Fixed
 - [#7730](https://github.com/apache/trafficcontrol/pull/7730) *Traffic 
Monitor* Fixed the panic seen in TM when `plugin.system_stats.timestamp_ms` 
appears as float and not string.
 - [#4393](https://github.com/apache/trafficcontrol/issues/4393) *Traffic Ops* 
Fixed the error code and alert structure when TO is queried for a delivery 
service with no ssl keys.
-- [#7690](https://github.com/apache/trafficcontrol/pull/7690) *Traffic Ops* 
Fixes Logs V5 apis to respond with RFC3339 tiestamps.
+- [#7690](https://github.com/apache/trafficcontrol/pull/7690) *Traffic Ops* 
Fixes Logs V5 api to respond with RFC3339 timestamps.
+- [#7720](https://github.com/apache/trafficcontrol/pull/7720) *Traffic Ops* 
Fixes Delivery Service Servers V5 api to respond with RFC3339 timestamps.
 - [#7631] (https://github.com/apache/trafficcontrol/pull/7631) *Traffic Ops* 
Fixes Phys_Location V5 apis to respond with RFC3339 date/time Format
 - [#7623] (https://github.com/apache/trafficcontrol/pull/7623) *Traffic Ops* 
Removed TryIfModifiedSinceQuery from servicecategories.go and reused from ims.go
 - [#7608](https://github.com/apache/trafficcontrol/pull/7608) *Traffic 
Monitor* Use stats_over_http(plugin.system_stats.timestamp_ms) timestamp field 
to calculate bandwidth for TM's caches.
diff --git a/docs/source/api/v5/deliveryserviceserver.rst 
b/docs/source/api/v5/deliveryserviceserver.rst
index e8269574b1..0e410c0bf3 100644
--- a/docs/source/api/v5/deliveryserviceserver.rst
+++ b/docs/source/api/v5/deliveryserviceserver.rst
@@ -65,7 +65,7 @@ Unlike most API endpoints, this will return a JSON response 
body containing both
 :response: An array of objects, each of which represents a server's 
:term:`Delivery Service` assignment
 
        :deliveryService: The integral, unique identifier of the 
:term:`Delivery Service` to which the server identified by ``server`` is 
assigned
-       :lastUpdated:     The date and time at which the server's assignment to 
a :term:`Delivery Service` was last updated
+       :lastUpdated:     The date and time at which the server's assignment to 
a :term:`Delivery Service` was last updated, in :rfc:`3339` format
        :server:          The integral, unique identifier of a server which is 
assigned to the :term:`Delivery Service` identified by ``deliveryService``
 
 :size: The page number - if pagination was requested in the query parameters, 
else ``0`` to indicate no pagination - of the results represented by the 
``response`` array. This is named "size" for legacy reasons
@@ -91,7 +91,7 @@ Unlike most API endpoints, this will return a JSON response 
body containing both
                {
                        "server": 8,
                        "deliveryService": 1,
-                       "lastUpdated": "2018-11-01 14:10:38+00"
+                       "lastUpdated": "2018-11-01T14:10:38-06:00"
                }
        ],
        "size": 1,
diff --git a/lib/go-tc/deliveryservice_servers.go 
b/lib/go-tc/deliveryservice_servers.go
index 55894fd063..de4090b861 100644
--- a/lib/go-tc/deliveryservice_servers.go
+++ b/lib/go-tc/deliveryservice_servers.go
@@ -19,6 +19,33 @@ import (
        "time"
 )
 
+// DeliveryServiceServerV5 is the struct used to represent a delivery service 
server, in the latest minor version for
+// API 5.x.
+type DeliveryServiceServerV5 = DeliveryServiceServerV50
+
+// DeliveryServiceServerV50 is the type of each entry in the `response` array
+// property of responses from Traffic Ops to GET requests made to the
+// /deliveryserviceservers endpoint of its API, for api version 5.0.
+type DeliveryServiceServerV50 struct {
+       Server          *int       `json:"server" db:"server"`
+       DeliveryService *int       `json:"deliveryService" db:"deliveryservice"`
+       LastUpdated     *time.Time `json:"lastUpdated" db:"last_updated"`
+}
+
+// DeliveryServiceServerResponseV5 is the type of a response from Traffic Ops
+// to a GET request to the /deliveryserviceserver endpoint, for the latest 
minor version of api v5.x.
+type DeliveryServiceServerResponseV5 = DeliveryServiceServerResponseV50
+
+// DeliveryServiceServerResponseV50 is the type of a response from Traffic Ops
+// to a GET request to the /deliveryserviceserver endpoint for API v5.0.
+type DeliveryServiceServerResponseV50 struct {
+       Orderby  string                    `json:"orderby"`
+       Response []DeliveryServiceServerV5 `json:"response"`
+       Size     int                       `json:"size"`
+       Limit    int                       `json:"limit"`
+       Alerts
+}
+
 // DeliveryServiceServerResponse is the type of a response from Traffic Ops
 // to a GET request to the /deliveryserviceserver endpoint.
 type DeliveryServiceServerResponse struct {
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go 
b/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
index cf518786c6..e3a34e0c2a 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
@@ -170,7 +170,33 @@ func ReadDSSHandler(w http.ResponseWriter, r 
*http.Request) {
        if err == nil && results == nil {
                w.WriteHeader(http.StatusNotModified)
        }
-       api.WriteRespRaw(w, r, results)
+       if inf.Version.GreaterThanOrEqualTo(&api.Version{
+               Major: 5,
+               Minor: 0,
+       }) {
+               var resultsV5 tc.DeliveryServiceServerResponseV5
+               resultsV5.Limit = results.Limit
+               resultsV5.Orderby = results.Orderby
+               resultsV5.Size = results.Size
+               resultsV5.Alerts = results.Alerts
+               resultsV5.Response = *upgrade(results.Response)
+               api.WriteRespRaw(w, r, resultsV5)
+       } else {
+               api.WriteRespRaw(w, r, results)
+       }
+}
+
+func upgrade(dsServers []tc.DeliveryServiceServer) 
*[]tc.DeliveryServiceServerV5 {
+       var err error
+       dsServersV5 := make([]tc.DeliveryServiceServerV5, len(dsServers))
+       for i, s := range dsServers {
+               dsServersV5[i].Server = s.Server
+               dsServersV5[i].DeliveryService = s.DeliveryService
+               if dsServersV5[i].LastUpdated, err = 
util.ConvertTimeFormat(s.LastUpdated.Time, time.RFC3339); err != nil {
+                       dsServersV5[i].LastUpdated = &s.LastUpdated.Time
+               }
+       }
+       return &dsServersV5
 }
 
 func (dss *TODeliveryServiceServer) readDSS(h http.Header, tx *sqlx.Tx, user 
*auth.CurrentUser, params map[string]string, intParams map[string]int, dsIDs 
[]int64, serverIDs []int64, useIMS bool) (*tc.DeliveryServiceServerResponse, 
error, *time.Time) {
diff --git a/traffic_ops/v5-client/deliveryserviceserver.go 
b/traffic_ops/v5-client/deliveryserviceserver.go
index 5f269c872f..6a0d290d28 100644
--- a/traffic_ops/v5-client/deliveryserviceserver.go
+++ b/traffic_ops/v5-client/deliveryserviceserver.go
@@ -68,8 +68,8 @@ func (to *Session) GetServersByDeliveryService(id int, opts 
RequestOptions) (tc.
 
 // GetDeliveryServiceServers returns associations between Delivery Services and
 // servers.
-func (to *Session) GetDeliveryServiceServers(opts RequestOptions) 
(tc.DeliveryServiceServerResponse, toclientlib.ReqInf, error) {
-       var resp tc.DeliveryServiceServerResponse
+func (to *Session) GetDeliveryServiceServers(opts RequestOptions) 
(tc.DeliveryServiceServerResponseV5, toclientlib.ReqInf, error) {
+       var resp tc.DeliveryServiceServerResponseV5
        reqInf, err := to.get(apiDeliveryServiceServer, opts, &resp)
        return resp, reqInf, err
 }

Reply via email to