This is an automated email from the ASF dual-hosted git repository.
rawlin 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 f599571 Set server XMPPID to hostname if empty (#5725)
f599571 is described below
commit f599571c9e076d1176fed1ba966d0fc43013829c
Author: Zach Hoffman <[email protected]>
AuthorDate: Fri Apr 9 15:29:29 2021 -0600
Set server XMPPID to hostname if empty (#5725)
* Generate XMPPID on server update if it is empty
* Hyphenate traffic-ops.yml
* Simplify condition
* Migration sets XMPPID to hostname if XMPPID is null
* Do not persistently set XMPPID on PUT if it is empty
* Remove xmpp_id from SQL query
* Include hostname in warning
* Use newer definition of XMPPID for API v1
* More accurate changelog entry
---
.../workflows/{traffic ops.yml => traffic-ops.yml} | 4 +--
CHANGELOG.md | 1 +
docs/source/api/v1/servers.rst | 4 +--
.../api/v1/servers_hostname_name_details.rst | 2 +-
docs/source/api/v1/servers_id.rst | 4 +--
go.sum | 10 --------
...81469_generate_uuid_for_xmpp_id_where_empty.sql | 22 ++++++++++++++++
traffic_ops/traffic_ops_golang/server/servers.go | 29 +++++++++++-----------
8 files changed, 44 insertions(+), 32 deletions(-)
diff --git a/.github/workflows/traffic ops.yml
b/.github/workflows/traffic-ops.yml
similarity index 97%
rename from .github/workflows/traffic ops.yml
rename to .github/workflows/traffic-ops.yml
index 65ffa0f..32cdef5 100644
--- a/.github/workflows/traffic ops.yml
+++ b/.github/workflows/traffic-ops.yml
@@ -26,7 +26,7 @@ on:
paths:
- .github/actions/todb-init/**
- .github/actions/to-integration-tests/**
- - .github/workflows/traffic ops.yml
+ - .github/workflows/traffic-ops.yml
- go.mod
- go.sum
- GO_VERSION
@@ -41,7 +41,7 @@ on:
paths:
- .github/actions/todb-init/**
- .github/actions/to-integration-tests/**
- - .github/workflows/traffic ops.yml
+ - .github/workflows/traffic-ops.yml
- go.mod
- go.sum
- GO_VERSION
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f1d5ab..b909080 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,6 +49,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- [#5405](https://github.com/apache/trafficcontrol/issues/5405) - Prevent
Tenant update from choosing child as new parent
- [#5384](https://github.com/apache/trafficcontrol/issues/5384) - New grids
will now properly remember the current page number.
- [#5548](https://github.com/apache/trafficcontrol/issues/5548) - Don't return
a `403 Forbidden` when the user tries to get servers of a non-existent DS using
`GET /servers?dsId={{nonexistent DS ID}}`
+- [#5724](https://github.com/apache/trafficcontrol/issues/5724) - Set XMPPID
to hostname if the server had none, don't error on server update when XMPPID is
empty
### Changed
- Updated the Traffic Ops Python client to 3.0
diff --git a/docs/source/api/v1/servers.rst b/docs/source/api/v1/servers.rst
index 807aba5..73f0b79 100644
--- a/docs/source/api/v1/servers.rst
+++ b/docs/source/api/v1/servers.rst
@@ -123,7 +123,7 @@ Response Structure
:type: The name of the :term:`Type` of this server
:typeId: The integral, unique identifier of the 'type' of this server
:updPending: A boolean value which, if ``true``, indicates that the server has
updates of some kind pending, typically to be acted upon by Traffic Ops ORT
-:xmppId: An identifier to be used in XMPP communications with the server -
in nearly all cases this will be the same as ``hostName``
+:xmppId: A system-generated UUID used to generate a server hashId for use
in Traffic Router's consistent hashing algorithm. This value is set when a
server is created and cannot be changed afterwards.
:xmppPasswd: The password used in XMPP communications with the server
.. code-block:: http
@@ -339,7 +339,7 @@ Response Structure
:type: The name of the 'type' of this server
:typeId: The integral, unique identifier of the 'type' of this server
:updPending: A boolean value which, if ``true``, indicates that the server has
updates of some kind pending, typically to be acted upon by Traffic Ops ORT
-:xmppId: An identifier to be used in XMPP communications with the server -
in nearly all cases this will be the same as ``hostName``
+:xmppId: A system-generated UUID used to generate a server hashId for use
in Traffic Router's consistent hashing algorithm. This value is set when a
server is created and cannot be changed afterwards.
:xmppPasswd: The password used in XMPP communications with the server
.. code-block:: http
diff --git a/docs/source/api/v1/servers_hostname_name_details.rst
b/docs/source/api/v1/servers_hostname_name_details.rst
index d492109..22db7d3 100644
--- a/docs/source/api/v1/servers_hostname_name_details.rst
+++ b/docs/source/api/v1/servers_hostname_name_details.rst
@@ -80,7 +80,7 @@ Response Structure
.. note:: This is typically thought of as synonymous with "HTTP port",
as the port specified by ``httpsPort`` may also be used for incoming TCP
connections.
:type: The name of the 'type' of this server
-:xmppId: An identifier to be used in XMPP communications with the server -
in nearly all cases this will be the same as ``hostName``
+:xmppId: A system-generated UUID used to generate a server hashId for use
in Traffic Router's consistent hashing algorithm. This value is set when a
server is created and cannot be changed afterwards.
:xmppPasswd: The password used in XMPP communications with the server
.. code-block:: http
diff --git a/docs/source/api/v1/servers_id.rst
b/docs/source/api/v1/servers_id.rst
index 1273227..31fbf42 100644
--- a/docs/source/api/v1/servers_id.rst
+++ b/docs/source/api/v1/servers_id.rst
@@ -123,7 +123,7 @@ Response Structure
:type: The name of the 'type' of this server
:typeId: The integral, unique identifier of the 'type' of this server
:updPending: A boolean value which, if ``true``, indicates that the server has
updates of some kind pending, typically to be acted upon by Traffic Ops ORT
-:xmppId: An identifier to be used in XMPP communications with the server -
in nearly all cases this will be the same as ``hostName``
+:xmppId: A system-generated UUID used to generate a server hashId for use
in Traffic Router's consistent hashing algorithm. This value is set when a
server is created and cannot be changed afterwards.
:xmppPasswd: The password used in XMPP communications with the server
.. code-block:: http
@@ -355,7 +355,7 @@ Response Structure
:type: The name of the 'type' of this server
:typeId: The integral, unique identifier of the 'type' of this server
:updPending: A boolean value which, if ``true``, indicates that the server has
updates of some kind pending, typically to be acted upon by Traffic Ops ORT
-:xmppId: An identifier to be used in XMPP communications with the server -
in nearly all cases this will be the same as ``hostName``
+:xmppId: A system-generated UUID used to generate a server hashId for use
in Traffic Router's consistent hashing algorithm. This value is set when a
server is created and cannot be changed afterwards.
:xmppPasswd: The password used in XMPP communications with the server
.. code-block:: http
diff --git a/go.sum b/go.sum
index 87c9b55..256119e 100644
--- a/go.sum
+++ b/go.sum
@@ -86,8 +86,6 @@ go.etcd.io/bbolt v1.3.5
h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod
h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod
h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
-golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod
h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod
h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod
h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -95,8 +93,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod
h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod
h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod
h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod
h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
-golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E=
-golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod
h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c
h1:KHUzaHIpjWVlVVNh65G3hhuj3KB1HnjY6Cq5cTvRQT8=
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod
h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
@@ -105,25 +101,19 @@ golang.org/x/sys
v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005
h1:pDMpM2zh2MT0kHy037cKlSby2nEhD50SYqwQk76Nm40=
-golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54
h1:rF3Ohx8DRyl8h2zw9qojyLHLhrJpEMgyPOImREEryf0=
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod
h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod
h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
-golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod
h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
diff --git
a/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.sql
b/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.sql
new file mode 100644
index 0000000..44b37b1
--- /dev/null
+++
b/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.sql
@@ -0,0 +1,22 @@
+/*
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+-- +goose Up
+-- SQL in section 'Up' is executed when this migration is applied
+UPDATE "server" s set xmpp_id = host_name WHERE s.xmpp_id IS NULL OR s.xmpp_id
= '';
+
+-- +goose Down
+-- SQL section 'Down' is executed when this migration is rolled back
+UPDATE "server" s set xmpp_id = NULL WHERE s.xmpp_id IS NULL OR s.xmpp_id = '';
diff --git a/traffic_ops/traffic_ops_golang/server/servers.go
b/traffic_ops/traffic_ops_golang/server/servers.go
index 1243e1a..b869e5e 100644
--- a/traffic_ops/traffic_ops_golang/server/servers.go
+++ b/traffic_ops/traffic_ops_golang/server/servers.go
@@ -492,6 +492,11 @@ const deleteServerQuery = `DELETE FROM server WHERE id=$1`
const deleteInterfacesQuery = `DELETE FROM interface WHERE server=$1`
const deleteIPsQuery = `DELETE FROM ip_address WHERE server = $1`
+func newUUID() *string {
+ uuidReference := uuid.New().String()
+ return &uuidReference
+}
+
func validateCommon(s *tc.CommonServerProperties, tx *sql.Tx) []error {
noSpaces := validation.NewStringRule(tovalidate.NoSpaces, "cannot
contain spaces")
@@ -514,11 +519,6 @@ func validateCommon(s *tc.CommonServerProperties, tx
*sql.Tx) []error {
return errs
}
- if s.XMPPID == nil || *s.XMPPID == "" {
- hostName := *s.HostName
- s.XMPPID = &hostName
- }
-
if _, err := tc.ValidateTypeID(tx, s.TypeID, "server"); err != nil {
errs = append(errs, err)
}
@@ -1459,10 +1459,8 @@ func Update(w http.ResponseWriter, r *http.Request) {
}
original := originals[0]
- if original.XMPPID == nil {
- sysErr = errors.New("original server had no XMPPID")
- api.HandleErr(w, r, tx, http.StatusInternalServerError, nil,
sysErr)
- return
+ if original.XMPPID == nil || *original.XMPPID == "" {
+ log.Warnf("original server %s had no XMPPID\n",
*original.HostName)
}
if original.StatusID == nil {
sysErr = errors.New("original server had no status ID")
@@ -1489,7 +1487,10 @@ func Update(w http.ResponseWriter, r *http.Request) {
original.StatusLastUpdated = &original.LastUpdated.Time
}
- originalXMPPID := *original.XMPPID
+ var originalXMPPID string
+ if original.XMPPID != nil {
+ originalXMPPID = *original.XMPPID
+ }
originalStatusID := *original.StatusID
var server tc.ServerV40
@@ -1638,7 +1639,7 @@ func Update(w http.ResponseWriter, r *http.Request) {
return
}
- if server.XMPPID != nil && *server.XMPPID != originalXMPPID {
+ if server.XMPPID != nil && *server.XMPPID != "" && originalXMPPID != ""
&& *server.XMPPID != originalXMPPID {
api.WriteAlerts(w, r, http.StatusBadRequest,
tc.CreateAlerts(tc.ErrorLevel, fmt.Sprintf("server cannot be updated due to
requested XMPPID change. XMPIDD is immutable")))
return
}
@@ -1801,8 +1802,7 @@ func createV2(inf *api.APIInfo, w http.ResponseWriter, r
*http.Request) {
}
}
- str := uuid.New().String()
- server.XMPPID = &str
+ server.XMPPID = newUUID()
if err := validateV2(&server, tx); err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
@@ -1872,8 +1872,7 @@ func createV3(inf *api.APIInfo, w http.ResponseWriter, r
*http.Request) {
}
}
- str := uuid.New().String()
- server.XMPPID = &str
+ server.XMPPID = newUUID()
_, err := validateV3(&server, tx)
if err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)