Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/source/api/v4/deliveryservices_id_servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.

.. versionadded:: 4.1
:cachegroup: A string that is the :ref:`name of the Cache Group <cache-group-name>` to which the server belongs
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belongs
:cdnId: An integral, unique identifier the CDN to which the server belongs
Expand Down Expand Up @@ -142,6 +145,7 @@ Response Structure
"type": "EDGE",
"typeId": 11,
"updPending": false,
"asns": [1,2],
"interfaces": [{
"ipAddresses": [
{
Expand Down
4 changes: 4 additions & 0 deletions docs/source/api/v4/deliveryservices_id_servers_eligible.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.

.. versionadded:: 4.1
:cachegroup: A string which is the :ref:`Name of the Cache Group <cache-group-name>` to which the server belongs
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belongs
:cdnId: An integral, unique identifier the CDN to which the server belongs
Expand Down Expand Up @@ -140,6 +143,7 @@ Response Structure
"type": "EDGE",
"typeId": 11,
"updPending": false,
"asns": [1,2],
"interfaces": [{
"ipAddresses": [
{
Expand Down
8 changes: 8 additions & 0 deletions docs/source/api/v4/servers_id.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.

.. versionadded:: 4.1
:cachegroup: A string that is the :ref:`name of the Cache Group <cache-group-name>` to which the server belongs
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belongs
:cdnId: The integral, unique identifier of the CDN to which the server belongs
Expand Down Expand Up @@ -262,6 +265,7 @@ Response Structure
}
],
"response": {
"asns": [1,2],
"cachegroup": "CDN_in_a_Box_Mid",
"cachegroupId": 6,
"cdnId": 2,
Expand Down Expand Up @@ -355,6 +359,9 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.

.. versionadded:: 4.1
:cachegroup: A string that is the :ref:`name of the Cache Group <cache-group-name>` to which the server belonged
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belonged
:cdnId: The integral, unique identifier of the CDN to which the server belonged
Expand Down Expand Up @@ -453,6 +460,7 @@ Response Structure
}
],
"response": {
"asns": [1,2],
"cachegroup": "CDN_in_a_Box_Mid",
"cachegroupId": 6,
"cdnId": 2,
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/v5/deliveryservices_id_servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.
:cachegroup: A string that is the :ref:`name of the Cache Group <cache-group-name>` to which the server belongs
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belongs
:cdnId: An integral, unique identifier the CDN to which the server belongs
Expand Down Expand Up @@ -142,6 +143,7 @@ Response Structure
"type": "EDGE",
"typeId": 11,
"updPending": false,
"asns": [1,2],
"interfaces": [{
"ipAddresses": [
{
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/v5/deliveryservices_id_servers_eligible.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.
:cachegroup: A string which is the :ref:`Name of the Cache Group <cache-group-name>` to which the server belongs
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belongs
:cdnId: An integral, unique identifier the CDN to which the server belongs
Expand Down Expand Up @@ -140,6 +141,7 @@ Response Structure
"type": "EDGE",
"typeId": 11,
"updPending": false,
"asns": [1,2],
"interfaces": [{
"ipAddresses": [
{
Expand Down
4 changes: 4 additions & 0 deletions docs/source/api/v5/servers_id.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.
:cachegroup: A string that is the :ref:`name of the Cache Group <cache-group-name>` to which the server belongs
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belongs
:cdnId: The integral, unique identifier of the CDN to which the server belongs
Expand Down Expand Up @@ -262,6 +263,7 @@ Response Structure
}
],
"response": {
"asns": [1,2],
"cachegroup": "CDN_in_a_Box_Mid",
"cachegroupId": 6,
"cdnId": 2,
Expand Down Expand Up @@ -355,6 +357,7 @@ Request Structure

Response Structure
------------------
:asns: The :abbr:`ASN (Autonomous System Number)` associated with the cachegroups of the current server.
:cachegroup: A string that is the :ref:`name of the Cache Group <cache-group-name>` to which the server belonged
:cachegroupId: An integer that is the :ref:`ID of the Cache Group <cache-group-id>` to which the server belonged
:cdnId: The integral, unique identifier of the CDN to which the server belonged
Expand Down Expand Up @@ -453,6 +456,7 @@ Response Structure
}
],
"response": {
"asns": [1,2],
"cachegroup": "CDN_in_a_Box_Mid",
"cachegroupId": 6,
"cdnId": 2,
Expand Down
15 changes: 14 additions & 1 deletion lib/go-tc/deliveryservice_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,34 @@ type DSServerResponseV30 struct {

// DSServerV4 contains information for a V4.x Delivery Service Server.
type DSServerV4 struct {
DSServerV40
ASNs []int64 `json:"asns"`
}

// DSServerV40 contains information for a V4.0 Delivery Service Server.
type DSServerV40 struct {
DSServerBaseV4
ServerInterfaces *[]ServerInterfaceInfoV40 `json:"interfaces" db:"interfaces"`
}

// DSServerResponseV40 is the type of a response from Traffic Ops to a request
// for servers assigned to a Delivery Service - in API version 4.0.
type DSServerResponseV40 struct {
Response []DSServerV40 `json:"response"`
Alerts
}

// DSServerResponseV41 is the type of a response from Traffic Ops to a request
// for servers assigned to a Delivery Service - in API version 4.1.
type DSServerResponseV41 struct {
Response []DSServerV4 `json:"response"`
Alerts
}

// DSServerResponseV4 is the type of a response from Traffic Ops to a request
// for servers assigned to a Delivery Service - in the latest minor version of
// API version 4.
type DSServerResponseV4 = DSServerResponseV40
type DSServerResponseV4 = DSServerResponseV41

// ToDSServerBaseV4 upgrades the DSServerBase to the structure used by the
// latest minor version of version 4 of Traffic Ops's API.
Expand Down
13 changes: 12 additions & 1 deletion traffic_ops/traffic_ops_golang/deliveryservice/eligible.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ func GetServersEligible(w http.ResponseWriter, r *http.Request) {
api.WriteResp(w, r, v3ServerList)
return
}
if inf.Version.Major == 4 && inf.Version.Minor < 1 {
Comment thread
ocket8888 marked this conversation as resolved.
v40ServerList := []tc.DSServerV40{}
for _, s := range servers {
sV40 := s.DSServerV40
v40ServerList = append(v40ServerList, sV40)
}
api.WriteResp(w, r, v40ServerList)
return
}
api.WriteResp(w, r, servers)
}

Expand Down Expand Up @@ -147,7 +156,8 @@ t.name as server_type,
s.type as server_type_id,
s.config_update_time > s.config_apply_time AS upd_pending,
ARRAY(select ssc.server_capability from server_server_capability ssc where ssc.server = s.id order by ssc.server_capability) as server_capabilities,
ARRAY(select drc.required_capability from deliveryservices_required_capability drc where drc.deliveryservice_id = (select v from ds_id) order by drc.required_capability) as deliveryservice_capabilities
ARRAY(select drc.required_capability from deliveryservices_required_capability drc where drc.deliveryservice_id = (select v from ds_id) order by drc.required_capability) as deliveryservice_capabilities,
(SELECT ARRAY_AGG(asn) AS asns FROM asn a WHERE a.cachegroup = s.cachegroup) AS asns
Comment thread
zrhoffman marked this conversation as resolved.
`
idRows, err := tx.Query(fmt.Sprintf(queryFormatString, "", queryWhereClause), dsID)
if err != nil {
Expand Down Expand Up @@ -209,6 +219,7 @@ ARRAY(select drc.required_capability from deliveryservices_required_capability d
&s.UpdPending,
pq.Array(&s.ServerCapabilities),
pq.Array(&s.DeliveryServiceCapabilities),
pq.Array(&s.ASNs),
)
if err != nil {
return nil, errors.New("scanning delivery service eligible servers: " + err.Error())
Expand Down
25 changes: 12 additions & 13 deletions traffic_ops/traffic_ops_golang/deliveryservice/eligible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func TestGetEligibleServers(t *testing.T) {
"server_type_id",
"upd_pending",
"server_capabilities",
"deliveryservice_capabilities"}
"deliveryservice_capabilities",
"asns",
}
eligbleRows := sqlmock.NewRows(cols)

for _, s := range testServers {
Expand Down Expand Up @@ -120,6 +122,7 @@ func TestGetEligibleServers(t *testing.T) {
s.UpdPending,
[]byte(`{""}`),
[]byte(`{""}`),
[]byte(`{1,2}`),
)
}
mock.ExpectQuery("SELECT s.id ,").WillReturnRows(eligbleRows)
Expand Down Expand Up @@ -149,18 +152,14 @@ func TestGetEligibleServers(t *testing.T) {
}

func getMockDSServers() []tc.DSServerV4 {
base := tc.DSServerBaseV4{
ID: util.IntPtr(1),
Cachegroup: util.StrPtr("cgTest"),
CachegroupID: util.IntPtr(1),
CDNID: util.IntPtr(1),
CDNName: util.StrPtr("cdnTest"),
DomainName: util.StrPtr("domain"),
}
srv := tc.DSServerV4{
DSServerBaseV4: base,
ServerInterfaces: &[]tc.ServerInterfaceInfoV40{}, // left empty because it must be written as json above since sqlmock does not support nested arrays
}
srv := tc.DSServerV4{}
srv.ID = util.IntPtr(1)
srv.Cachegroup = util.StrPtr("cgTest")
srv.CachegroupID = util.IntPtr(1)
srv.CDNID = util.IntPtr(1)
srv.CDNName = util.StrPtr("cdnTest")
srv.DomainName = util.StrPtr("domain")
srv.ServerInterfaces = &[]tc.ServerInterfaceInfoV40{}
srvsExpected := []tc.DSServerV4{srv}
return srvsExpected
}
Expand Down
14 changes: 12 additions & 2 deletions traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,15 @@ func GetReadAssigned(w http.ResponseWriter, r *http.Request) {
api.WriteAlertsObj(w, r, http.StatusOK, alerts, v3ServerList)
return
}

if inf.Version.Major == 4 && inf.Version.Minor < 1 {
v40ServerList := []tc.DSServerV40{}
for _, s := range servers {
sV40 := s.DSServerV40
v40ServerList = append(v40ServerList, sV40)
}
api.WriteAlertsObj(w, r, http.StatusOK, alerts, v40ServerList)
return
}
api.WriteAlertsObj(w, r, http.StatusOK, alerts, servers)
}

Expand Down Expand Up @@ -758,7 +766,8 @@ s.status as status_id,
s.tcp_port,
t.name as server_type,
s.type as server_type_id,
s.config_update_time > s.config_apply_time AS upd_pending
s.config_update_time > s.config_apply_time AS upd_pending,
(SELECT ARRAY_AGG(asn) AS asns FROM asn a WHERE a.cachegroup = s.cachegroup) AS asns
Comment thread
zrhoffman marked this conversation as resolved.
`

queryFormatString := `
Expand Down Expand Up @@ -833,6 +842,7 @@ WHERE s.id in (select server from deliveryservice_server where deliveryservice =
&s.Type,
&s.TypeID,
&s.UpdPending,
pq.Array(&s.ASNs),
)
if err != nil {
return nil, errors.New("error scanning dss rows: " + err.Error())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func TestReadServers(t *testing.T) {
"tcp_port",
"server_type",
"server_type_id",
"upd_pending"}
"upd_pending",
"asns",
}

rows := sqlmock.NewRows(cols)

Expand Down Expand Up @@ -150,6 +152,7 @@ func TestReadServers(t *testing.T) {
s.Type,
s.TypeID,
s.UpdPending,
[]byte(`{1,2}`),
)
}

Expand Down Expand Up @@ -184,18 +187,14 @@ func TestReadServers(t *testing.T) {
}

func getMockDSServers() []tc.DSServerV4 {
base := tc.DSServerBaseV4{
ID: util.IntPtr(1),
Cachegroup: util.StrPtr("cgTest"),
CachegroupID: util.IntPtr(1),
CDNID: util.IntPtr(1),
CDNName: util.StrPtr("cdnTest"),
DomainName: util.StrPtr("domain"),
}
srv := tc.DSServerV4{
DSServerBaseV4: base,
ServerInterfaces: &[]tc.ServerInterfaceInfoV40{}, // left empty because it must be written as json above since sqlmock does not support nested arrays
}
srv := tc.DSServerV4{}
srv.ID = util.IntPtr(1)
srv.Cachegroup = util.StrPtr("cgTest")
srv.CachegroupID = util.IntPtr(1)
srv.CDNID = util.IntPtr(1)
srv.CDNName = util.StrPtr("cdnTest")
srv.DomainName = util.StrPtr("domain")
srv.ServerInterfaces = &[]tc.ServerInterfaceInfoV40{}
srvsExpected := []tc.DSServerV4{srv}
return srvsExpected
}
Expand Down
Loading