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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed
- [#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.
- [#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.
- [#7612](https://github.com/apache/trafficcontrol/pull/7612) *Traffic Ops* Fixes Divisions V5 apis to respond with RFC3339 date/time Format
Expand Down
8 changes: 4 additions & 4 deletions docs/source/api/v5/phys_locations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Response Structure
:comments: Any and all human-readable comments
:email: The email address of the physical location's ``poc``
:id: An integral, unique identifier for the physical location
:lastUpdated: The date and time at which the physical location was last updated, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which the physical location was last updated, in :rfc:`3339` Format
:name: The name of the physical location
:phone: A phone number where the the physical location's ``poc`` might be reached
:poc: The name of a "point of contact" for the physical location
Expand Down Expand Up @@ -103,7 +103,7 @@ Response Structure
"comments": "",
"email": "",
"id": 2,
"lastUpdated": "2018-12-05 17:50:58+00",
"lastUpdated": "2018-12-05T18:56:27.057163+05:30",
"name": "CDN_in_a_Box",
"phone": "",
"poc": "",
Expand Down Expand Up @@ -173,7 +173,7 @@ Response Structure
:comments: Any and all human-readable comments
:email: The email address of the physical location's ``poc``
:id: An integral, unique identifier for the physical location
:lastUpdated: The date and time at which the physical location was last updated, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which the physical location was last updated, in :rfc:`3339`
:name: The name of the physical location
:phone: A phone number where the the physical location's ``poc`` might be reached
:poc: The name of a "point of contact" for the physical location
Expand Down Expand Up @@ -210,7 +210,7 @@ Response Structure
"comments": "Buckingham Palace",
"email": "steve.kingstone@royal.gsx.gov.uk",
"id": 3,
"lastUpdated": "2018-12-06 00:14:47+00",
"lastUpdated": "2018-12-06T18:56:27.057163+05:30",
"name": "Great_Britain",
"phone": "0-843-816-6276",
"poc": "Her Majesty The Queen Elizabeth Alexandra Mary Windsor II",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/api/v5/phys_locations_id.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Response Structure
:comments: Any and all human-readable comments
:email: The email address of the physical location's ``poc``
:id: An integral, unique identifier for the physical location
:lastUpdated: The date and time at which the physical location was last updated, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which the physical location was last updated, in :rfc:`3339`
:name: The name of the physical location
:phone: A phone number where the the physical location's ``poc`` might be reached
:poc: The name of a "point of contact" for the physical location
Expand Down Expand Up @@ -122,7 +122,7 @@ Response Structure
"comments": "The White House",
"email": "the@white.house",
"id": 2,
"lastUpdated": "2018-12-05 23:39:17+00",
"lastUpdated": "2018-12-05T18:56:27.057163+05:30",
"name": "CDN_in_a_Box",
"phone": "1-202-456-1414",
"poc": "Donald J. Trump",
Expand Down
63 changes: 63 additions & 0 deletions lib/go-tc/physlocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package tc
* under the License.
*/

import "time"

// PhysLocationsResponse is a list of PhysLocations as a response.
type PhysLocationsResponse struct {
Response []PhysLocation `json:"response"`
Expand Down Expand Up @@ -201,3 +203,64 @@ type PhysLocationNullable struct {
type PhysLocationTrimmed struct {
Name string `json:"name"`
}

// PhysLocationV5 is an alias for the latest minor version for the major version 5.
type PhysLocationV5 PhysLocationV50

// PhysLocationV50 contains the physical location of a cache group.
type PhysLocationV50 struct {
Address string `json:"address" db:"address"`
City string `json:"city" db:"city"`
Comments string `json:"comments" db:"comments"`
Email string `json:"email" db:"email"`
ID int `json:"id" db:"id"`
LastUpdated time.Time `json:"lastUpdated" db:"last_updated"`
Name string `json:"name" db:"name"`
Phone string `json:"phone" db:"phone"`
POC string `json:"poc" db:"poc"`
RegionID int `json:"regionId" db:"region"`
RegionName string `json:"region" db:"region_name"`
ShortName string `json:"shortName" db:"short_name"`
State string `json:"state" db:"state"`
Zip string `json:"zip" db:"zip"`
}

// PhysLocationsResponseV5 is an alias for the latest minor version for the major version 5.
type PhysLocationsResponseV5 PhysLocationsResponseV50

// PhysLocationsResponseV50 is a list of PhysLocations as a response.
type PhysLocationsResponseV50 struct {
Response []PhysLocationV5 `json:"response"`
Alerts
}

// PhysLocationNullableV5 is an alias for the latest minor version for the major version 5.
type PhysLocationNullableV5 PhysLocationNullableV50

// PhysLocationNullableV50 contains the physical location of a cache group. It
// allows for all fields to be null.
type PhysLocationNullableV50 struct {
Address *string `json:"address" db:"address"`
City *string `json:"city" db:"city"`
Comments *string `json:"comments" db:"comments"`
Email *string `json:"email" db:"email"`
ID *int `json:"id" db:"id"`
LastUpdated time.Time `json:"lastUpdated" db:"last_updated"`
Name *string `json:"name" db:"name"`
Phone *string `json:"phone" db:"phone"`
POC *string `json:"poc" db:"poc"`
RegionID *int `json:"regionId" db:"region"`
RegionName *string `json:"region" db:"region_name"`
ShortName *string `json:"shortName" db:"short_name"`
State *string `json:"state" db:"state"`
Zip *string `json:"zip" db:"zip"`
}

// PhysLocationResponseV5 is an alias for the latest minor version for the major version 5.
type PhysLocationResponseV5 PhysLocationResponseV50

// PhysLocationResponseV50 is a single PhysLocationNullable as a response.
type PhysLocationResponseV50 struct {
Response PhysLocationNullableV5 `json:"response"`
Alerts
}
22 changes: 11 additions & 11 deletions traffic_ops/testing/api/v5/phys_locations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestPhysLocations(t *testing.T) {
currentTimeRFC := currentTime.Format(time.RFC1123)
tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)

methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.PhysLocation]{
methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.PhysLocationV5]{
"GET": {
"NOT MODIFIED when NO CHANGES made": {
ClientSession: TOSession,
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestPhysLocations(t *testing.T) {
"POST": {
"OK when VALID request": {
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "100 blah lane",
City: "foo",
Comments: "comment",
Expand All @@ -112,12 +112,12 @@ func TestPhysLocations(t *testing.T) {
State: "CO",
Zip: "80602",
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusCreated),
validatePhysicalLocationUpdateCreateFields("testPhysicalLocation", map[string]interface{}{"Name": "testPhysicalLocation"})),
},
"BAD REQUEST when REGION ID does NOT MATCH REGION NAME": {
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "Atlanta",
Name: "HotAtlanta",
Expand All @@ -135,7 +135,7 @@ func TestPhysLocations(t *testing.T) {
"OK when VALID request": {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "NewCity",
Name: "HotAtlanta",
Expand All @@ -152,7 +152,7 @@ func TestPhysLocations(t *testing.T) {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}}},
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "Atlanta",
RegionID: GetRegionID(t, "region1")(),
Expand All @@ -166,7 +166,7 @@ func TestPhysLocations(t *testing.T) {
"PRECONDITION FAILED when updating with IFMATCH ETAG Header": {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "Atlanta",
RegionID: GetRegionID(t, "region1")(),
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestPhysLocations(t *testing.T) {
func validatePhysicalLocationFields(expectedResp map[string]interface{}) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Physical Location response to not be nil.")
plResp := resp.([]tc.PhysLocation)
plResp := resp.([]tc.PhysLocationV5)
for field, expected := range expectedResp {
for _, pl := range plResp {
switch field {
Expand Down Expand Up @@ -259,7 +259,7 @@ func validatePhysicalLocationUpdateCreateFields(name string, expectedResp map[st

func validatePhysicalLocationPagination(paginationParam string) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
paginationResp := resp.([]tc.PhysLocation)
paginationResp := resp.([]tc.PhysLocationV5)

opts := client.NewRequestOptions()
opts.QueryParameters.Set("orderby", "id")
Expand All @@ -283,7 +283,7 @@ func validatePhysicalLocationSort() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, alerts tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Physical Location response to not be nil.")
var physLocNames []string
physLocResp := resp.([]tc.PhysLocation)
physLocResp := resp.([]tc.PhysLocationV5)
for _, pl := range physLocResp {
physLocNames = append(physLocNames, pl.Name)
}
Expand All @@ -295,7 +295,7 @@ func validatePhysicalLocationIDSort() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, alerts tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Physical Location response to not be nil.")
var physLocIDs []int
physLocResp := resp.([]tc.PhysLocation)
physLocResp := resp.([]tc.PhysLocationV5)
for _, pl := range physLocResp {
physLocIDs = append(physLocIDs, pl.ID)
}
Expand Down
2 changes: 1 addition & 1 deletion traffic_ops/testing/api/v5/traffic_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type TrafficControl struct {
Profiles []tc.Profile `json:"profiles"`
Parameters []tc.Parameter `json:"parameters"`
ProfileParameters []tc.ProfileParameter `json:"profileParameters"`
PhysLocations []tc.PhysLocation `json:"physLocations"`
PhysLocations []tc.PhysLocationV5 `json:"physLocations"`
Regions []tc.Region `json:"regions"`
Roles []tc.RoleV4 `json:"roles"`
Servers []tc.ServerV4 `json:"servers"`
Expand Down
15 changes: 15 additions & 0 deletions traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2232,3 +2232,18 @@ func DivisionExists(tx *sql.Tx, id string) (bool, error) {
}
return true, nil
}

// PhysLocationExists confirms whether the PhysLocationExists exists, and an error (if one occurs).
func PhysLocationExists(tx *sql.Tx, id string) (bool, error) {
Comment thread
jagan-parthiban marked this conversation as resolved.
var count int
if err := tx.QueryRow("SELECT count(name) FROM phys_location WHERE id=$1", id).Scan(&count); err != nil {
return false, fmt.Errorf("error getting PhysLocation info: %w", err)
}
if count == 0 {
return false, nil
}
if count != 1 {
return false, fmt.Errorf("getting PhysLocation info - expected row count: 1, actual: %d", count)
}
return true, nil
}
Loading