Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix /deliveryservices/{{ID}}/servers and /deliveryservices/{{ID}}/servers/eligible to use RFC3339 timestamps #7660

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
259e95d
typo mistake correction
gbkannan89 Jul 18, 2023
1a6cde5
added for v5 version with time conversion
gbkannan89 Jul 18, 2023
2bf2483
changelog
gbkannan89 Jul 18, 2023
da00599
time format updated in doc
gbkannan89 Jul 18, 2023
5bbafb0
test updated
gbkannan89 Jul 18, 2023
4cff65a
typo correction
gbkannan89 Jul 18, 2023
97112cd
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 18, 2023
cebdec5
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 20, 2023
a727525
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 21, 2023
7886d3a
sample response time updated
gbkannan89 Jul 21, 2023
5e48620
minor version typo fixed to major version for api5
gbkannan89 Jul 21, 2023
ca4dd13
comment added
gbkannan89 Jul 21, 2023
e6480f8
using common function
gbkannan89 Jul 21, 2023
f363422
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 21, 2023
83bbb83
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 24, 2023
6c8e9de
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 25, 2023
06faf7c
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 27, 2023
2d83c50
comments addressed
gbkannan89 Jul 27, 2023
9002d09
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 27, 2023
d41973a
comment addressed
gbkannan89 Jul 28, 2023
ba12ae1
test type changed
gbkannan89 Jul 28, 2023
570d336
server basev5 is now remoed
gbkannan89 Jul 31, 2023
5191286
comment addressed
gbkannan89 Jul 31, 2023
ad1977f
Merge branch 'master' into to-delivery-service-rfc-time-format-v5
gbkannan89 Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/api/v5/deliveryservices_id_servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
: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
Expand Down Expand Up @@ -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": "",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/api/v5/deliveryservices_id_servers_eligible.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
: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
Expand Down Expand Up @@ -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": "",
Expand Down
70 changes: 70 additions & 0 deletions lib/go-tc/deliveryservice_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,47 @@
DeliveryServiceCapabilities []string `json:"-" db:"deliveryservice_capabilities"`
}

// DSServerBaseV5 contains the base information for a Delivery Service Server associated with APIv5.
type DSServerBaseV5 = DSServerBaseV50

// DSServerBaseV50 contains the base information for a Delivery Service Server for the latest major version associated with APIv50.
type DSServerBaseV50 struct {
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved
Cachegroup *string `json:"cachegroup" db:"cachegroup"`
CachegroupID *int `json:"cachegroupId" db:"cachegroup_id"`
CDNID *int `json:"cdnId" db:"cdn_id"`
CDNName *string `json:"cdnName" db:"cdn_name"`
DeliveryServices *map[string][]string `json:"deliveryServices,omitempty"`
DomainName *string `json:"domainName" db:"domain_name"`
FQDN *string `json:"fqdn,omitempty"`
FqdnTime time.Time `json:"-"`
GUID *string `json:"guid" db:"guid"`
HostName *string `json:"hostName" db:"host_name"`
HTTPSPort *int `json:"httpsPort" db:"https_port"`
ID *int `json:"id" db:"id"`
ILOIPAddress *string `json:"iloIpAddress" db:"ilo_ip_address"`
ILOIPGateway *string `json:"iloIpGateway" db:"ilo_ip_gateway"`
ILOIPNetmask *string `json:"iloIpNetmask" db:"ilo_ip_netmask"`
ILOPassword *string `json:"iloPassword" db:"ilo_password"`
ILOUsername *string `json:"iloUsername" db:"ilo_username"`
LastUpdated *time.Time `json:"lastUpdated" db:"last_updated"`
MgmtIPAddress *string `json:"mgmtIpAddress" db:"mgmt_ip_address"`
MgmtIPGateway *string `json:"mgmtIpGateway" db:"mgmt_ip_gateway"`
MgmtIPNetmask *string `json:"mgmtIpNetmask" db:"mgmt_ip_netmask"`
OfflineReason *string `json:"offlineReason" db:"offline_reason"`
PhysLocation *string `json:"physLocation" db:"phys_location"`
PhysLocationID *int `json:"physLocationId" db:"phys_location_id"`
ProfileNames []string `json:"profileNames" db:"profile_name"`
Rack *string `json:"rack" db:"rack"`
Status *string `json:"status" db:"status"`
StatusID *int `json:"statusId" db:"status_id"`
TCPPort *int `json:"tcpPort" db:"tcp_port"`
Type string `json:"type" db:"server_type"`
TypeID *int `json:"typeId" db:"server_type_id"`
UpdPending *bool `json:"updPending" db:"upd_pending"`
ServerCapabilities []string `json:"-" db:"server_capabilities"`
DeliveryServiceCapabilities []string `json:"-" db:"deliveryservice_capabilities"`
}

// DSServerV11 contains the legacy format for a Delivery Service Server.
type DSServerV11 struct {
DSServerBase
Expand All @@ -180,6 +221,15 @@
ServerInterfaces *[]ServerInterfaceInfo `json:"interfaces" db:"interfaces"`
}

// DSServerV5 contains information of Delivery Service Server associated with APIv5.
type DSServerV5 = DSServerV50

// DSServerV50 contains information for a Delivery Service Server for the latest major version associated with APIv50.
type DSServerV50 struct {
DSServerBaseV50
ServerInterfaces *[]ServerInterfaceInfo `json:"interfaces" db:"interfaces"`
}

// DSServerResponseV30 is the type of a response from Traffic Ops to a request
// for servers assigned to a Delivery Service - in API version 3.0.
type DSServerResponseV30 struct {
Expand All @@ -205,6 +255,15 @@
// API version 4.
type DSServerResponseV4 = DSServerResponseV40

// DSServerResponseV50 is response from Traffic Ops to a request for servers assigned to a Delivery Service - in the latest minor version APIv50.
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
type DSServerResponseV50 struct {
Response []DSServerV50 `json:"response"`
Alerts
}

// DSServerResponseV5 is the response from Traffic Ops to a request for servers assigned to a Delivery Service - in APIv5.
type DSServerResponseV5 = DSServerResponseV50

// 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 {
Expand Down Expand Up @@ -290,3 +349,14 @@
dsServerBase.RouterPortName = routerPort
return dsServerBase
}

// ConvertV4LastupdateToV5 convert DSServerV4 lastUpdated time format to RFC3339 for DSServerV5
func ConvertV4LastupdateToV5(serverList []DSServerV4) []DSServerV5 {
updatedServerList := make([]DSServerV5, len(serverList))

for i, server := range serverList {
r := time.Unix(server.LastUpdated.Unix(), 0)
updatedServerList[i].LastUpdated = &r
}
return updatedServerList

Check warning on line 361 in lib/go-tc/deliveryservice_servers.go

View check run for this annotation

Codecov / codecov/patch

lib/go-tc/deliveryservice_servers.go#L354-L361

Added lines #L354 - L361 were not covered by tests
}
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions lib/go-tc/federation_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
TypeID *uint `json:"typeId,omitempty" db:"type"`
}

// FederationResolverV5 - is an alias for the Federal Resolver struct response used for the latest minor version associated with APIv5.
// FederationResolverV5 - is an alias for the Federal Resolver struct response used for the latest major version associated with APIv5.
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved
type FederationResolverV5 = FederationResolverV50

// FederationResolverV50 - is used for RFC3339 format timestamp in FederationResolver which represents a resolver record for a CDN Federation for APIv50.
Expand All @@ -63,7 +63,7 @@
TypeID *uint `json:"typeId,omitempty" db:"type"`
}

// FederationResolversResponseV5 - an alias for the Federation Resolver's struct response used for the latest minor version associated with APIv5.
// FederationResolversResponseV5 - an alias for the Federation Resolver's struct response used for the latest major version associated with APIv5.
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved
type FederationResolversResponseV5 = FederationResolversResponseV50

// FederationResolversResponseV50 - GET request to its /federation_resolvers endpoint for APIv50.
Expand All @@ -72,7 +72,7 @@
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 major version associated with APIv5.
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved
type FederationResolverResponseV5 = FederationResolverResponseV50

// FederationResolverResponseV50 - POST request to its /federation_resolvers endpoint APIv50.
Expand Down Expand Up @@ -104,17 +104,17 @@
}

// UpgradeToFederationResolverV5 upgrades an APIv4 Federal Resolver into an APIv5 Federal Resolver of
// the latest minor version.
// the latest major version APIv5.
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved
func UpgradeToFederationResolverV5(fr FederationResolver) *FederationResolverV5 {
upgraded := FederationResolverV5{
ID: fr.ID,
IPAddress: fr.IPAddress,
LastUpdated: func() *time.Time {
lastUpdated := time.Unix(fr.LastUpdated.Unix(), 0)
return &lastUpdated
}(),

Check warning on line 115 in lib/go-tc/federation_resolver.go

View check run for this annotation

Codecov / codecov/patch

lib/go-tc/federation_resolver.go#L108-L115

Added lines #L108 - L115 were not covered by tests
Type: fr.Type,
}

return &upgraded

Check warning on line 119 in lib/go-tc/federation_resolver.go

View check run for this annotation

Codecov / codecov/patch

lib/go-tc/federation_resolver.go#L119

Added line #L119 was not covered by tests
}
13 changes: 13 additions & 0 deletions traffic_ops/traffic_ops_golang/deliveryservice/eligible.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
}
defer inf.Close()

alerts := tc.Alerts{}
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved

Check warning on line 46 in traffic_ops/traffic_ops_golang/deliveryservice/eligible.go

View check run for this annotation

Codecov / codecov/patch

traffic_ops/traffic_ops_golang/deliveryservice/eligible.go#L45-L46

Added lines #L45 - L46 were not covered by tests
dsTenantID, ok, err := getDSTenantIDByID(inf.Tx.Tx, inf.IntParams["id"])
if err != nil {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking tenant: "+err.Error()))
Expand Down Expand Up @@ -96,6 +98,17 @@
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}) {

// Convert lastupdate time format to RFC3339 of DSServerV4 to DSServerV5
newServerList := tc.ConvertV4LastupdateToV5(servers)

api.WriteAlertsObj(w, r, http.StatusOK, alerts, newServerList)
ocket8888 marked this conversation as resolved.
Show resolved Hide resolved
return
}

Check warning on line 110 in traffic_ops/traffic_ops_golang/deliveryservice/eligible.go

View check run for this annotation

Codecov / codecov/patch

traffic_ops/traffic_ops_golang/deliveryservice/eligible.go#L103-L110

Added lines #L103 - L110 were not covered by tests

api.WriteResp(w, r, servers)
}

Expand Down
11 changes: 11 additions & 0 deletions traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,17 @@
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
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
if inf.Version.GreaterThanOrEqualTo(&api.Version{Major: 5, Minor: 0}) {

// Convert lastupdate time format to RFC3339 of DSServerV4 to DSServerV5
newServerList := tc.ConvertV4LastupdateToV5(servers)

api.WriteAlertsObj(w, r, http.StatusOK, alerts, newServerList)
return
}

Check warning on line 736 in traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go

View check run for this annotation

Codecov / codecov/patch

traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go#L729-L736

Added lines #L729 - L736 were not covered by tests

api.WriteAlertsObj(w, r, http.StatusOK, alerts, servers)
}

Expand Down
4 changes: 2 additions & 2 deletions traffic_ops/v5-client/deliveryservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading