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

Renaming a host in TC, does not impact hash_id #4881

Merged
merged 22 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fa729bd
Added a new line
rimashah25 Jun 17, 2020
fdbbd8b
Updated rst file for tp.
rimashah25 Jul 6, 2020
2ddf509
Merge branch 'master' of https://github.com/apache/trafficcontrol int…
rimashah25 Jul 6, 2020
8384e91
Merge branch 'master' of https://github.com/apache/trafficcontrol int…
rimashah25 Jul 8, 2020
2294f8f
Added uuid changes to createV2()
rimashah25 Jul 15, 2020
d40d915
Merge branch 'master' of https://github.com/apache/trafficcontrol int…
rimashah25 Jul 15, 2020
e189917
Added a idparam to get server after an update
rimashah25 Jul 15, 2020
1a1379a
Added test cases for api v2 abd v3
rimashah25 Jul 15, 2020
770c481
Updated test cases and sql-query for api v2 abd v3 with respect to xm…
rimashah25 Jul 16, 2020
9913d43
adds a read-only field to the server form so the user can see the has…
mitchell852 Jul 16, 2020
23acbd6
Updated api docs to reflect the meaning of field: xmppId
rimashah25 Jul 16, 2020
2d7f66e
Edits based on review comments
rimashah25 Jul 17, 2020
785af5a
Updated test cases for api v2 abd v3 and update() based on PR comment…
rimashah25 Jul 20, 2020
72f8c77
Updated alert message
rimashah25 Jul 21, 2020
d12de22
Updated based on PR-review comments
rimashah25 Jul 21, 2020
9a2d830
Removed submodule:
rimashah25 Jul 21, 2020
8e4a27b
Revert "Removed submodule:"
rimashah25 Jul 21, 2020
9d5ac93
Merge branch 'master' of https://github.com/apache/trafficcontrol int…
rimashah25 Jul 21, 2020
b930549
Removed submodule uuid
rimashah25 Jul 21, 2020
629cf89
Updated code based on PR comments
rimashah25 Jul 21, 2020
2f269ec
Added UUID package and not submodule :)
rimashah25 Jul 21, 2020
43c30fb
Added UUID license for weasel tests to pass.
rimashah25 Jul 21, 2020
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 @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Updated /deliveryservices/{{ID}}/servers/eligible to use multiple interfaces in API v3

### Fixed
- Fixed #2156 - Renaming a host in TC, does not impact xmpp_id and thereby hashid [Related github issue](https://github.com/apache/trafficcontrol/issues/2156)
- Fixed #3661 - Anonymous Proxy ipv4 whitelist does not work
- Fixed the `GET /api/x/jobs` and `GET /api/x/jobs/:id` Traffic Ops API routes to allow falling back to Perl via the routing blacklist
- Fixed ORT config generation not using the coalesce_number_v6 Parameter.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/v2/servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Request Structure

: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 optional identifier to be used in XMPP communications with the server - in nearly all cases this should 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.
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
:xmppPasswd: An optional password used in XMPP communications with the server

.. code-block:: http
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/v2/servers_id.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,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.
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
:xmppPasswd: The password used in XMPP communications with the server

.. code-block:: http
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/v3/servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Request Structure

: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 optional identifier to be used in XMPP communications with the server - in nearly all cases this should 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.
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
:xmppPasswd: An optional password used in XMPP communications with the server

.. code-block:: http
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/v3/servers_id.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Request Structure

: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 optional identifier to be used in XMPP communications with the server - in nearly all cases this should be the same as ``hostName``
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
: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: An optional password used in XMPP communications with the server

.. code-block:: http
Expand Down
4 changes: 2 additions & 2 deletions docs/source/development/traffic_portal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ Installing The Traffic Portal Developer Environment
#. Valid SSL certificates and keys are needed for Traffic Portal to run. Generate these (e.g. using `this SuperUser answer <https://superuser.com/questions/226192/avoid-password-prompt-for-keys-and-prompts-for-dn-information#answer-226229>`_) and update ``ssl``.
#. Modify ``api.base_url`` to point to your Traffic Ops API endpoint.
#. Modify ``files.static`` to be ``./app/dist/public``.
#. Modify ``log.stream`` to be ``./server/log/access.log``.

#. Modify ``log.stream`` to be ``./server/log/access.log``. If you have created a ``traffic_portal/log`` directory with ``access.log`` file, use that location.
#. Ensure ca_bundle.crt is present at ``/etc/pki/tls/certs``. If not present, use the cmd: ``sudo touch ca_bundle.crt``
#. Navigate to http(s)://localhost:[port|sslPort defined in ``traffic_portal/conf/config.js``]

.. note:: The Traffic Portal consumes the Traffic Ops API. Modify traffic_portal/conf/config.js to specify the location of Traffic Ops.
32 changes: 31 additions & 1 deletion traffic_ops/testing/api/v2/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@ func UpdateTestServers(t *testing.T) {
t.Errorf("cannot GET Server by hostname: %v - %v", firstServer.HostName, err)
}
remoteServer := resp[0]
originalHostname := resp[0].HostName
originalXMPIDD := resp[0].XMPPID
updatedServerInterface := "bond1"
updatedServerRack := "RR 119.03"
updatedHostName := "atl-edge-01"
updatedXMPPID := "change-it"

// update rack and interfaceName values on server
// update rack, interfaceName and hostName values on server
remoteServer.InterfaceName = updatedServerInterface
remoteServer.Rack = updatedServerRack
remoteServer.HostName = updatedHostName

var alert tc.Alerts
alert, _, err = TOSession.UpdateServerByID(remoteServer.ID, remoteServer)
if err != nil {
Expand All @@ -130,6 +136,30 @@ func UpdateTestServers(t *testing.T) {
t.Errorf("results do not match actual: %s, expected: %s", respServer.Rack, updatedServerRack)
}

//Check change in hostname with no change to xmppid
if originalHostname == respServer.HostName && originalXMPIDD == respServer.XMPPID {
t.Errorf("HostName didn't change. Expected: #{updatedHostName}, actual: #{originalHostname}")
}

//Check to verify XMPPID never gets updated
remoteServer.XMPPID = updatedXMPPID
al, _, err := TOSession.UpdateServerByID(remoteServer.ID, remoteServer)
if err != nil {
t.Logf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", remoteServer.ID, hostName, err, al)
}

//Change back hostname and xmppid to its original name for other tests to pass
remoteServer.HostName = originalHostname
remoteServer.XMPPID = originalXMPIDD
alerts, _, err := TOSession.UpdateServerByID(remoteServer.ID, remoteServer)
if err != nil {
t.Fatalf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", remoteServer.ID, hostName, err, alerts)
}
resp, _, err = TOSession.GetServerByID(remoteServer.ID)
if err != nil {
t.Errorf("cannot GET Server by hostName: %v - %v", originalHostname, err)
}

// Assign server to DS and then attempt to update to a different type
dses, _, err := TOSession.GetDeliveryServicesNullable()
if err != nil {
Expand Down
45 changes: 40 additions & 5 deletions traffic_ops/testing/api/v3/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v3
*/

import (
"fmt"
"github.com/apache/trafficcontrol/lib/go-rfc"
"net/http"
"net/url"
Expand Down Expand Up @@ -79,7 +80,7 @@ func GetTestServersIMSAfterChange(t *testing.T, header http.Header) {
func GetTestServersIMS(t *testing.T) {
var header http.Header
header = make(map[string][]string)
futureTime := time.Now().AddDate(0,0,1)
futureTime := time.Now().AddDate(0, 0, 1)
time := futureTime.Format(time.RFC1123)
header.Set(rfc.IfModifiedSince, time)
params := url.Values{}
Expand Down Expand Up @@ -264,6 +265,13 @@ func UpdateTestServers(t *testing.T) {
t.Fatalf("Got null ID for server '%s'", hostName)
}

originalHostname := *resp.Response[0].HostName
originalXMPIDD := *resp.Response[0].XMPPID
// Creating idParam to get server when hostname changes.
id := fmt.Sprintf("%v", *resp.Response[0].ID)
idParam := url.Values{}
idParam.Add("id", id)

infs := remoteServer.Interfaces
if len(infs) < 1 {
t.Fatalf("Expected server '%s' to have at least one network interface", hostName)
Expand All @@ -272,22 +280,25 @@ func UpdateTestServers(t *testing.T) {

updatedServerInterface := "bond1"
updatedServerRack := "RR 119.03"
updatedHostName := "atl-edge-01"
updatedXMPPID := "change-it"

// update rack and interfaceName values on server
// update rack, interfaceName and hostName values on server
inf.Name = updatedServerInterface
infs[0] = inf
remoteServer.Interfaces = infs
remoteServer.Rack = &updatedServerRack
remoteServer.HostName = &updatedHostName

alerts, _, err := TOSession.UpdateServerByID(*remoteServer.ID, remoteServer)
if err != nil {
t.Fatalf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", *remoteServer.ID, hostName, err, alerts)
}

// Retrieve the server to check rack and interfaceName values were updated
resp, _, err = TOSession.GetServers(&params, nil)
// Retrieve the server to check rack, interfaceName, hostName values were updated
resp, _, err = TOSession.GetServers(&idParam, nil)
if err != nil {
t.Errorf("cannot GET Server by ID: %v - %v", remoteServer.HostName, err)
t.Errorf("cannot GET Server by ID: %v - %v", *remoteServer.HostName, err)
}
if len(resp.Response) < 1 {
t.Fatalf("Expected at least one server to exist by hostname '%s'", hostName)
Expand Down Expand Up @@ -321,6 +332,30 @@ func UpdateTestServers(t *testing.T) {
t.Fatalf("Cannot test server type change update; server '%s' had nil type ID", hostName)
}

//Check change in hostname with no change to xmppid
if originalHostname == *respServer.HostName && originalXMPIDD == *respServer.XMPPID {
t.Errorf("HostName didn't change. Expected: #{updatedHostName}, actual: #{originalHostname}")
}

//Check to verify XMPPID never gets updated
remoteServer.XMPPID = &updatedXMPPID
al, _, err := TOSession.UpdateServerByID(*remoteServer.ID, remoteServer)
if err != nil {
t.Logf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", *remoteServer.ID, hostName, err, al)
}

//Change back hostname and xmppid to its original name for other tests to pass
remoteServer.HostName = &originalHostname
remoteServer.XMPPID = &originalXMPIDD
alert, _, err := TOSession.UpdateServerByID(*remoteServer.ID, remoteServer)
if err != nil {
t.Fatalf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", *remoteServer.ID, hostName, err, alert)
}
resp, _, err = TOSession.GetServers(&params, nil)
if err != nil {
t.Errorf("cannot GET Server by hostName: %v - %v", originalHostname, err)
}

// Assign server to DS and then attempt to update to a different type
dses, _, err := TOSession.GetDeliveryServicesNullable(nil)
if err != nil {
Expand Down
29 changes: 27 additions & 2 deletions traffic_ops/traffic_ops_golang/server/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (

"github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
"github.com/google/uuid"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using UUID to set xmppid to a random uuid

"github.com/jmoiron/sqlx"
"github.com/lib/pq"
)
Expand Down Expand Up @@ -255,7 +256,6 @@ UPDATE server SET
tcp_port=:tcp_port,
type=:server_type_id,
upd_pending=:upd_pending,
xmpp_id=:xmpp_id,
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
xmpp_passwd=:xmpp_passwd
WHERE id=:id
RETURNING
Expand Down Expand Up @@ -984,6 +984,15 @@ func Update(w http.ResponseWriter, r *http.Request) {
}
defer inf.Close()

//Get original xmppid
origSer, _, userErr, sysErr, _, _ := getServers(r.Header, inf.Params, inf.Tx, inf.User, false)
if userErr != nil || sysErr != nil {
api.HandleErr(w, r, tx, errCode, userErr, sysErr)
return
}
originalXMPPID := *origSer[0].XMPPID
changeXMPPID := false

var server tc.ServerNullableV2
var interfaces []tc.ServerInterfaceInfo
if inf.Version.Major >= 3 {
Expand All @@ -992,6 +1001,9 @@ func Update(w http.ResponseWriter, r *http.Request) {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
return
}
if *newServer.XMPPID != originalXMPPID {
changeXMPPID = true
}
serviceInterface, err := validateV3(&newServer, tx)
if err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
Expand All @@ -1010,7 +1022,9 @@ func Update(w http.ResponseWriter, r *http.Request) {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
return
}

if *server.XMPPID != originalXMPPID {
changeXMPPID = true
}
err := validateV2(&server, tx)
if err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
Expand Down Expand Up @@ -1055,6 +1069,11 @@ func Update(w http.ResponseWriter, r *http.Request) {
return
}

if changeXMPPID {
api.WriteRespAlertObj(w, r, tc.ErrorLevel, fmt.Sprintf("server cannot be updated due to requested XMPPID change. XMPIDD is immutable"), nil)
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
return
}

rows, err := inf.Tx.NamedQuery(updateQuery, server)
if err != nil {
userErr, sysErr, errCode = api.ParseDBError(err)
Expand Down Expand Up @@ -1169,6 +1188,9 @@ func createV2(inf *api.APIInfo, w http.ResponseWriter, r *http.Request) {
return
}

str := uuid.New().String()
server.XMPPID = &str

if err := validateV2(&server, tx); err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
return
Expand Down Expand Up @@ -1224,6 +1246,9 @@ func createV3(inf *api.APIInfo, w http.ResponseWriter, r *http.Request) {
return
}

str := uuid.New().String()
rimashah25 marked this conversation as resolved.
Show resolved Hide resolved
server.XMPPID = &str

serviceInterface, err := validateV3(&server, tx)
if err != nil {
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
Expand Down
Submodule uuid added at bd4515
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ <h6>Deprecated</h6>
<span ng-show="hasError(serverForm.routerPortName)" class="form-control-feedback"><i class="fa fa-times"></i></span>
</div>

<label ng-if="!settings.isNew">Hash ID</label>
<div ng-if="!settings.isNew">
<input name="xmppId" type="text" class="form-control" ng-model="server.xmppId" readonly/>
</div>

<fieldset>
<legend>Interfaces<button name="addInterfaceBtn" class="btn btn-primary right-button btn-xs" type="button" title="add a new interface" ng-click="addInterface()"><i class="fa fa-plus"></i></button></legend>
<fieldset ng-repeat="inf in server.interfaces">
Expand Down