From 33d8179c123429357bcf5a19248dad9d62c96df3 Mon Sep 17 00:00:00 2001 From: "Kannan.G.B" <111871677+gbkannan89@users.noreply.github.com> Date: Tue, 1 Aug 2023 04:08:53 +0530 Subject: [PATCH] Fix `/deliveryservices/{{ID}}/servers` and `/deliveryservices/{{ID}}/servers/eligible` to use RFC3339 timestamps (#7660) * typo mistake correction * added for v5 version with time conversion * changelog * time format updated in doc * test updated * typo correction * sample response time updated * minor version typo fixed to major version for api5 * comment added * using common function * comments addressed * comment addressed * test type changed * server basev5 is now remoed * comment addressed --- CHANGELOG.md | 1 + .../api/v5/deliveryservices_id_servers.rst | 4 +- .../deliveryservices_id_servers_eligible.rst | 4 +- lib/go-tc/deliveryservice_servers.go | 65 +++++++++++++++++++ lib/go-tc/federation_resolver.go | 2 +- .../deliveryservice/eligible.go | 14 ++++ .../deliveryservice/servers/servers.go | 14 ++++ traffic_ops/v5-client/deliveryservice.go | 4 +- .../v5-client/deliveryserviceserver.go | 4 +- 9 files changed, 103 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 134e3eabe9..b8f9a07712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - [#7575](https://github.com/apache/trafficcontrol/pull/7575) *Traffic Ops* Fixes `types` v5 apis to respond with `RFC3339` date/time Format. - [#7628](https://github.com/apache/trafficcontrol/pull/7628) *Traffic Ops* Fixes an issue where certificate chain validation failed based on leading or trailing whitespace. - [#7596](https://github.com/apache/trafficcontrol/pull/7596) *Traffic Ops* Fixes `federation_resolvers` v5 apis to respond with `RFC3339` date/time Format. +- [#7660](https://github.com/apache/trafficcontrol/pull/7660) *Traffic Ops* Fixes `deliveryServices` v5 apis to respond with `RFC3339` date/time Format. ### Removed - [#7271](https://github.com/apache/trafficcontrol/pull/7271) Remove components in `infrastructre/docker/`, not in use as cdn-in-a-box performs the same functionality. diff --git a/docs/source/api/v5/deliveryservices_id_servers.rst b/docs/source/api/v5/deliveryservices_id_servers.rst index 02e578982a..b0008360ec 100644 --- a/docs/source/api/v5/deliveryservices_id_servers.rst +++ b/docs/source/api/v5/deliveryservices_id_servers.rst @@ -70,7 +70,7 @@ Response Structure :gateway: The IPv4 or IPv6 gateway address of the server - applicable for the interface ``name`` :service_address: A boolean determining if content will be routed to the IP address -:lastUpdated: The time and date at which this server was last updated, in :ref:`non-rfc-datetime` +:lastUpdated: The time and date at which this server was last updated, in :rfc:`3339` :mgmtIpAddress: The IPv4 address of the server's management port :mgmtIpGateway: The IPv4 gateway of the server's management port :mgmtIpNetmask: The IPv4 subnet mask of the server's management port @@ -125,7 +125,7 @@ Response Structure "iloIpNetmask": "", "iloPassword": "", "iloUsername": "", - "lastUpdated": "2018-11-14 21:08:44+00", + "lastUpdated": "2018-11-14T15:18:14.952814+05:30", "mgmtIpAddress": "", "mgmtIpGateway": "", "mgmtIpNetmask": "", diff --git a/docs/source/api/v5/deliveryservices_id_servers_eligible.rst b/docs/source/api/v5/deliveryservices_id_servers_eligible.rst index f51c34f946..bd9af9f19c 100644 --- a/docs/source/api/v5/deliveryservices_id_servers_eligible.rst +++ b/docs/source/api/v5/deliveryservices_id_servers_eligible.rst @@ -76,7 +76,7 @@ Response Structure :gateway: The IPv4 or IPv6 gateway address of the server - applicable for the interface ``name`` :service_address: A boolean determining if content will be routed to the IP address -:lastUpdated: The time and date at which this server was last updated, in :ref:`non-rfc-datetime` +:lastUpdated: The time and date at which this server was last updated, in :rfc:`3339` :mgmtIpAddress: The IPv4 address of the server's management port :mgmtIpGateway: The IPv4 gateway of the server's management port :mgmtIpNetmask: The IPv4 subnet mask of the server's management port @@ -121,7 +121,7 @@ Response Structure "iloIpNetmask": "", "iloPassword": "", "iloUsername": "", - "lastUpdated": "2018-10-30 16:01:12+00", + "lastUpdated": "2018-10-30T15:18:14.952814+05:30", "mgmtIpAddress": "", "mgmtIpGateway": "", "mgmtIpNetmask": "", diff --git a/lib/go-tc/deliveryservice_servers.go b/lib/go-tc/deliveryservice_servers.go index 7f1d1a1570..55894fd063 100644 --- a/lib/go-tc/deliveryservice_servers.go +++ b/lib/go-tc/deliveryservice_servers.go @@ -205,6 +205,26 @@ type DSServerResponseV40 struct { // API version 4. type DSServerResponseV4 = DSServerResponseV40 +// DSServerV5 is an alias for the latest minor version of the major version 5. +type DSServerV5 = DSServerV50 + +// DSServerV50 contains information for a Delivery Service Server. +type DSServerV50 struct { + ServerV4 // Please replace me when ServerV50 is born + LastUpdated *time.Time `json:"lastUpdated" db:"last_updated"` + ServerCapabilities []string `json:"-" db:"server_capabilities"` + DeliveryServiceCapabilities []string `json:"-" db:"deliveryservice_capabilities"` +} + +// DSServerResponseV5 is an alias for the latest minor version of the major version 5. +type DSServerResponseV5 = DSServerResponseV50 + +// DSServerResponseV50 is response from Traffic Ops to a request for servers assigned to a Delivery Service - in the latest minor version APIv50. +type DSServerResponseV50 struct { + Response []DSServerV50 `json:"response"` + Alerts +} + // ToDSServerBaseV4 upgrades the DSServerBase to the structure used by the // latest minor version of version 4 of Traffic Ops's API. func (oldBase DSServerBase) ToDSServerBaseV4() DSServerBaseV4 { @@ -290,3 +310,48 @@ func (baseV4 DSServerBaseV4) ToDSServerBase(routerHostName, routerPort, pDesc *s dsServerBase.RouterPortName = routerPort return dsServerBase } + +// ToDSServerV5 convert DSServerV4 lastUpdated time format to RFC3339 for DSServerV5 +// and also assign V4 values to V5 +func (server DSServerV4) ToDSServerV5() DSServerV5 { + r := time.Unix(server.LastUpdated.Unix(), 0) + + return DSServerV5{ + ServerV4: ServerV4{ + Cachegroup: server.Cachegroup, + CachegroupID: server.CachegroupID, + CDNID: server.CDNID, + CDNName: server.CDNName, + DeliveryServices: server.DeliveryServices, + DomainName: server.DomainName, + FQDN: server.FQDN, + FqdnTime: server.FqdnTime, + GUID: server.GUID, + HostName: server.HostName, + HTTPSPort: server.HTTPSPort, + ID: server.ID, + ILOIPAddress: server.ILOIPAddress, + ILOIPGateway: server.ILOIPGateway, + ILOIPNetmask: server.ILOIPNetmask, + ILOPassword: server.ILOPassword, + ILOUsername: server.ILOUsername, + MgmtIPAddress: server.MgmtIPAddress, + MgmtIPGateway: server.MgmtIPGateway, + MgmtIPNetmask: server.MgmtIPNetmask, + OfflineReason: server.OfflineReason, + PhysLocation: server.PhysLocation, + PhysLocationID: server.PhysLocationID, + Rack: server.Rack, + Status: server.Status, + StatusID: server.StatusID, + TCPPort: server.TCPPort, + Type: server.Type, + TypeID: server.TypeID, + UpdPending: server.UpdPending, + Interfaces: *server.ServerInterfaces, + }, + LastUpdated: &r, + ServerCapabilities: server.ServerCapabilities, + DeliveryServiceCapabilities: server.DeliveryServiceCapabilities, + } +} diff --git a/lib/go-tc/federation_resolver.go b/lib/go-tc/federation_resolver.go index 51bf965531..2e2f74be06 100644 --- a/lib/go-tc/federation_resolver.go +++ b/lib/go-tc/federation_resolver.go @@ -72,7 +72,7 @@ type FederationResolversResponseV50 struct { Response []FederationResolverV5 `json:"response"` } -// FederationResolverResponseV50 - represents struct response used for the latest minor version associated with APIv5. +// FederationResolverResponseV5 - represents struct response used for the latest minor version associated with APIv5. type FederationResolverResponseV5 = FederationResolverResponseV50 // FederationResolverResponseV50 - POST request to its /federation_resolvers endpoint APIv50. diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/eligible.go b/traffic_ops/traffic_ops_golang/deliveryservice/eligible.go index 691a1ae7ba..7f06667a46 100644 --- a/traffic_ops/traffic_ops_golang/deliveryservice/eligible.go +++ b/traffic_ops/traffic_ops_golang/deliveryservice/eligible.go @@ -96,6 +96,20 @@ func GetServersEligible(w http.ResponseWriter, r *http.Request) { api.WriteResp(w, r, v3ServerList) return } + + // Based on version we load Delivery Service Eligible Server - for version 5 and above we use DSServerV5 + if inf.Version.GreaterThanOrEqualTo(&api.Version{Major: 5, Minor: 0}) { + + newServerList := make([]tc.DSServerV5, len(servers)) + + for i, server := range servers { + newServerList[i] = server.ToDSServerV5() + } + + api.WriteResp(w, r, newServerList) + return + } + api.WriteResp(w, r, servers) } diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go b/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go index 21556bd7de..cf518786c6 100644 --- a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go +++ b/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go @@ -724,6 +724,20 @@ func GetReadAssigned(w http.ResponseWriter, r *http.Request) { api.WriteAlertsObj(w, r, http.StatusOK, alerts, v3ServerList) return } + + // Based on version we load Delivery Service Server - for version 5 and above we use DSServerV5 + if inf.Version.GreaterThanOrEqualTo(&api.Version{Major: 5, Minor: 0}) { + + newServerList := make([]tc.DSServerV5, len(servers)) + + for i, server := range servers { + newServerList[i] = server.ToDSServerV5() + } + + api.WriteAlertsObj(w, r, http.StatusOK, alerts, newServerList) + return + } + api.WriteAlertsObj(w, r, http.StatusOK, alerts, servers) } diff --git a/traffic_ops/v5-client/deliveryservice.go b/traffic_ops/v5-client/deliveryservice.go index ac238c6321..2a669d585a 100644 --- a/traffic_ops/v5-client/deliveryservice.go +++ b/traffic_ops/v5-client/deliveryservice.go @@ -282,8 +282,8 @@ func (to *Session) GetDeliveryServiceSSLKeys(xmlid string, opts RequestOptions) // GetDeliveryServicesEligible returns the servers eligible for assignment to the Delivery // Service identified by the integral, unique identifier 'dsID'. -func (to *Session) GetDeliveryServicesEligible(dsID int, opts RequestOptions) (tc.DSServerResponseV4, toclientlib.ReqInf, error) { - var resp tc.DSServerResponseV4 +func (to *Session) GetDeliveryServicesEligible(dsID int, opts RequestOptions) (tc.DSServerResponseV5, toclientlib.ReqInf, error) { + var resp tc.DSServerResponseV5 reqInf, err := to.get(fmt.Sprintf(apiDeliveryServiceEligibleServers, dsID), opts, &resp) return resp, reqInf, err } diff --git a/traffic_ops/v5-client/deliveryserviceserver.go b/traffic_ops/v5-client/deliveryserviceserver.go index 225870b42a..5f269c872f 100644 --- a/traffic_ops/v5-client/deliveryserviceserver.go +++ b/traffic_ops/v5-client/deliveryserviceserver.go @@ -59,9 +59,9 @@ func (to *Session) AssignServersToDeliveryService(servers []string, xmlID string } // GetServersByDeliveryService gets the servers that are assigned to the delivery service with the given ID. -func (to *Session) GetServersByDeliveryService(id int, opts RequestOptions) (tc.DSServerResponseV4, toclientlib.ReqInf, error) { +func (to *Session) GetServersByDeliveryService(id int, opts RequestOptions) (tc.DSServerResponseV5, toclientlib.ReqInf, error) { route := fmt.Sprintf(apiDeliveryServicesServers, strconv.Itoa(id)) - resp := tc.DSServerResponseV4{} + resp := tc.DSServerResponseV5{} reqInf, err := to.get(route, opts, &resp) return resp, reqInf, err }