You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/09/08 16:47:05 UTC

[GitHub] [trafficcontrol] zrhoffman opened a new pull request #5016: New endpoint: Queue updates on the servers in a topology

zrhoffman opened a new pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016


   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - This PR allowes you to queue updates on all servers in a topology by adding the `POST /topologies/{name}/queue_update` endpoint.
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - This PR allowes you to queue updates on all servers in a topology by adding the `POST /topologies/{name}/queue_update` endpoint.
   - [x] This PR is not related to any Issue <!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - Documentation
   - Traffic Control Client (Go, Python)
   - Traffic Ops
   - Traffic Portal
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   - Run TO API tests
   - Run TP UI tests
   - Build docs
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [x] This PR includes tests
   - [x] This PR includes documentation
   - [x] This PR includes an update to CHANGELOG.md
   - [x] This PR includes any and all required license headers
   - [x] This PR ensures that database migration sequence does not include a database migration
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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.
   -->
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r491192907



##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, []string{})
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	reqObj := tc.TopologiesQueueUpdateRequest{}
+	if err := json.NewDecoder(r.Body).Decode(&reqObj); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil)
+		return
+	}
+	topologyName := tc.TopologyName(inf.Params["name"])
+	if err := Validate(reqObj, topologyName, inf.Tx.Tx); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, fmt.Errorf("invalid request to queue updates: %s", err), nil)
+		return
+	}
+	if err := queueUpdates(inf.Tx.Tx, topologyName, reqObj.CDNID, reqObj.Action == "queue"); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("Topology queueing updates: "+err.Error()))
+		return
+	}
+
+	message := fmt.Sprintf("TOPOLOGY: %s, ACTION: Topology server updates %sd", topologyName, reqObj.Action)
+	api.CreateChangeLogRawTx(api.ApiChange, message, inf.User, inf.Tx.Tx)
+	api.WriteResp(w, r, tc.TopologiesQueueUpdate{Action: reqObj.Action, CDNID: reqObj.CDNID, Topology: topologyName})
+}
+
+func queueUpdates(tx *sql.Tx, topologyName tc.TopologyName, cdnId int64, queue bool) error {
+	query := `
+UPDATE server s
+SET upd_pending = $1
+FROM cachegroup c, topology_cachegroup tc, cdn
+WHERE s.cachegroup = c.id
+AND c."name" = tc.cachegroup
+AND tc.topology = $2
+AND s.cdn_id = $3
+`
+	var err error
+	if _, err = tx.Exec(query, queue, topologyName, cdnId); err != nil {
+		err = fmt.Errorf("queueing updates: %s", err)

Review comment:
       *Should* it, as in will it not work unless it is `err.Error()`? `fmt`'s reflection successfully casts `Error` to `string` type because it only has 1 field, which is `string` type, so `%s` works.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] srijeet0406 commented on pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#issuecomment-696885143


   Unit tests pass, API tests pass.
   Tested manually, by queueing and dequeueing updates based on topologies, and made sure that only the servers in the topology got affected. 
   Code looks good.
   LGTM 👍 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r485075420



##########
File path: docs/source/api/v3/topologies_name_queue_update.rst
##########
@@ -0,0 +1,86 @@
+..
+..
+.. 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.
+..
+
+.. _to-api-topologies-name-queue_update:
+
+****************************
+``topologies/{{name}}/queue_update``
+****************************
+
+``POST``
+========
+:term:`Queue` or "dequeue" updates for all servers assigned to the :term:`Cachegroups` in a specific :term:`Topology`.

Review comment:
       Changed term reference to `Cache Groups` in 3b2956594




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r491193002



##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, []string{})
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	reqObj := tc.TopologiesQueueUpdateRequest{}
+	if err := json.NewDecoder(r.Body).Decode(&reqObj); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil)
+		return
+	}
+	topologyName := tc.TopologyName(inf.Params["name"])
+	if err := Validate(reqObj, topologyName, inf.Tx.Tx); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, fmt.Errorf("invalid request to queue updates: %s", err), nil)
+		return
+	}
+	if err := queueUpdates(inf.Tx.Tx, topologyName, reqObj.CDNID, reqObj.Action == "queue"); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("Topology queueing updates: "+err.Error()))
+		return
+	}
+
+	message := fmt.Sprintf("TOPOLOGY: %s, ACTION: Topology server updates %sd", topologyName, reqObj.Action)
+	api.CreateChangeLogRawTx(api.ApiChange, message, inf.User, inf.Tx.Tx)
+	api.WriteResp(w, r, tc.TopologiesQueueUpdate{Action: reqObj.Action, CDNID: reqObj.CDNID, Topology: topologyName})
+}
+
+func queueUpdates(tx *sql.Tx, topologyName tc.TopologyName, cdnId int64, queue bool) error {
+	query := `
+UPDATE server s
+SET upd_pending = $1
+FROM cachegroup c, topology_cachegroup tc, cdn
+WHERE s.cachegroup = c.id
+AND c."name" = tc.cachegroup

Review comment:
       Unquoted in 5cbaf5602b




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r491192907



##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, []string{})
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	reqObj := tc.TopologiesQueueUpdateRequest{}
+	if err := json.NewDecoder(r.Body).Decode(&reqObj); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil)
+		return
+	}
+	topologyName := tc.TopologyName(inf.Params["name"])
+	if err := Validate(reqObj, topologyName, inf.Tx.Tx); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, fmt.Errorf("invalid request to queue updates: %s", err), nil)
+		return
+	}
+	if err := queueUpdates(inf.Tx.Tx, topologyName, reqObj.CDNID, reqObj.Action == "queue"); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("Topology queueing updates: "+err.Error()))
+		return
+	}
+
+	message := fmt.Sprintf("TOPOLOGY: %s, ACTION: Topology server updates %sd", topologyName, reqObj.Action)
+	api.CreateChangeLogRawTx(api.ApiChange, message, inf.User, inf.Tx.Tx)
+	api.WriteResp(w, r, tc.TopologiesQueueUpdate{Action: reqObj.Action, CDNID: reqObj.CDNID, Topology: topologyName})
+}
+
+func queueUpdates(tx *sql.Tx, topologyName tc.TopologyName, cdnId int64, queue bool) error {
+	query := `
+UPDATE server s
+SET upd_pending = $1
+FROM cachegroup c, topology_cachegroup tc, cdn
+WHERE s.cachegroup = c.id
+AND c."name" = tc.cachegroup
+AND tc.topology = $2
+AND s.cdn_id = $3
+`
+	var err error
+	if _, err = tx.Exec(query, queue, topologyName, cdnId); err != nil {
+		err = fmt.Errorf("queueing updates: %s", err)

Review comment:
       *Should* it, as in will it not work unless it is `err.Error()`? `fmt`'s reflection successfully casts `error` to `string` type because it only has 1 field, which is `string` type, so `err` works.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp merged pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
rawlinp merged pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] srijeet0406 commented on pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#issuecomment-696885143


   Unit tests pass, API tests pass.
   Tested manually, by queueing and dequeueing updates based on topologies, and made sure that only the servers in the topology got affected. 
   Code looks good.
   LGTM 👍 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r491193151



##########
File path: traffic_ops/testing/api/v3/topologies_queue_update_test.go
##########
@@ -0,0 +1,127 @@
+package v3
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"github.com/apache/trafficcontrol/lib/go-tc"

Review comment:
       Line put below all the other imports, with a blank line in between, in 652b930b3e

##########
File path: lib/go-tc/topologies.go
##########
@@ -47,3 +47,25 @@ type TopologiesResponse struct {
 	Response []Topology `json:"response"`
 	Alerts
 }
+
+// TopologiesQueueUpdateRequest encodes the request data for the POST
+// topologies/{{name}}/queue_update endpoint.
+type TopologiesQueueUpdateRequest struct {
+	Action string `json:"action"`
+	CDNID  int64  `json:"cdnId"`
+}
+
+// TopologiesQueueUpdate encodes the response data for the POST

Review comment:
       Changed to `TopologiesQueueUpdateResponse` in a3aba0f95c

##########
File path: CHANGELOG.md
##########
@@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Traffic Ops API v3
 - Added an optional readiness check service to cdn-in-a-box that exits successfully when it is able to get a `200 OK` from all delivery services
 - [Flexible Topologies (in progress)](https://github.com/apache/trafficcontrol/blob/master/blueprints/flexible-topologies.md)
-    - Traffic Ops: Added an API 3.0 endpoint, /api/3.0/topologies, to create, read, update and delete flexible topologies.
+    - Traffic Ops: Added an API 3.0 endpoint, `GET /api/3.0/topologies`, to create, read, update and delete flexible topologies.
+    - Traffic Ops: Added an API 3.0 endpoint, `POST /api/3.0/topologyes/{name}/queue_update`, to queue or dequeue updates for all servers assigned to the Cachegroups in a given Topology.

Review comment:
       Typo fixed in 5d6f5b919b




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#issuecomment-689628972


   Rebased to master


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp merged pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
rawlinp merged pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#issuecomment-692144136


   Fixed a merge conflict due to `gofmt`


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r491193063



##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {

Review comment:
       Description added in a3aba0f95c

##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"

Review comment:
       Reordered imports in 652b930b3e




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r491192907



##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, []string{})
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	reqObj := tc.TopologiesQueueUpdateRequest{}
+	if err := json.NewDecoder(r.Body).Decode(&reqObj); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil)
+		return
+	}
+	topologyName := tc.TopologyName(inf.Params["name"])
+	if err := Validate(reqObj, topologyName, inf.Tx.Tx); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, fmt.Errorf("invalid request to queue updates: %s", err), nil)
+		return
+	}
+	if err := queueUpdates(inf.Tx.Tx, topologyName, reqObj.CDNID, reqObj.Action == "queue"); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("Topology queueing updates: "+err.Error()))
+		return
+	}
+
+	message := fmt.Sprintf("TOPOLOGY: %s, ACTION: Topology server updates %sd", topologyName, reqObj.Action)
+	api.CreateChangeLogRawTx(api.ApiChange, message, inf.User, inf.Tx.Tx)
+	api.WriteResp(w, r, tc.TopologiesQueueUpdate{Action: reqObj.Action, CDNID: reqObj.CDNID, Topology: topologyName})
+}
+
+func queueUpdates(tx *sql.Tx, topologyName tc.TopologyName, cdnId int64, queue bool) error {
+	query := `
+UPDATE server s
+SET upd_pending = $1
+FROM cachegroup c, topology_cachegroup tc, cdn
+WHERE s.cachegroup = c.id
+AND c."name" = tc.cachegroup
+AND tc.topology = $2
+AND s.cdn_id = $3
+`
+	var err error
+	if _, err = tx.Exec(query, queue, topologyName, cdnId); err != nil {
+		err = fmt.Errorf("queueing updates: %s", err)

Review comment:
       *Should* it, as in will it not work unless it is `err.Error()`? `fmt`'s reflection successfully casts `Error` to `string` type because it only has 1 field, which is `string` type, so `err` works.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] srijeet0406 commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r488873569



##########
File path: traffic_ops/testing/api/v3/topologies_queue_update_test.go
##########
@@ -0,0 +1,127 @@
+package v3
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"github.com/apache/trafficcontrol/lib/go-tc"

Review comment:
       This line should go below all the other imports, with a blank line in between

##########
File path: CHANGELOG.md
##########
@@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Traffic Ops API v3
 - Added an optional readiness check service to cdn-in-a-box that exits successfully when it is able to get a `200 OK` from all delivery services
 - [Flexible Topologies (in progress)](https://github.com/apache/trafficcontrol/blob/master/blueprints/flexible-topologies.md)
-    - Traffic Ops: Added an API 3.0 endpoint, /api/3.0/topologies, to create, read, update and delete flexible topologies.
+    - Traffic Ops: Added an API 3.0 endpoint, `GET /api/3.0/topologies`, to create, read, update and delete flexible topologies.
+    - Traffic Ops: Added an API 3.0 endpoint, `POST /api/3.0/topologyes/{name}/queue_update`, to queue or dequeue updates for all servers assigned to the Cachegroups in a given Topology.

Review comment:
       typo: topologies

##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {

Review comment:
       Might be good to add a description comment here

##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, []string{})
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	reqObj := tc.TopologiesQueueUpdateRequest{}
+	if err := json.NewDecoder(r.Body).Decode(&reqObj); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil)
+		return
+	}
+	topologyName := tc.TopologyName(inf.Params["name"])
+	if err := Validate(reqObj, topologyName, inf.Tx.Tx); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, fmt.Errorf("invalid request to queue updates: %s", err), nil)
+		return
+	}
+	if err := queueUpdates(inf.Tx.Tx, topologyName, reqObj.CDNID, reqObj.Action == "queue"); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("Topology queueing updates: "+err.Error()))
+		return
+	}
+
+	message := fmt.Sprintf("TOPOLOGY: %s, ACTION: Topology server updates %sd", topologyName, reqObj.Action)
+	api.CreateChangeLogRawTx(api.ApiChange, message, inf.User, inf.Tx.Tx)
+	api.WriteResp(w, r, tc.TopologiesQueueUpdate{Action: reqObj.Action, CDNID: reqObj.CDNID, Topology: topologyName})
+}
+
+func queueUpdates(tx *sql.Tx, topologyName tc.TopologyName, cdnId int64, queue bool) error {
+	query := `
+UPDATE server s
+SET upd_pending = $1
+FROM cachegroup c, topology_cachegroup tc, cdn
+WHERE s.cachegroup = c.id
+AND c."name" = tc.cachegroup
+AND tc.topology = $2
+AND s.cdn_id = $3
+`
+	var err error
+	if _, err = tx.Exec(query, queue, topologyName, cdnId); err != nil {
+		err = fmt.Errorf("queueing updates: %s", err)

Review comment:
       Should this be `err.Error()` instead?

##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	validation "github.com/go-ozzo/ozzo-validation"
+	"net/http"
+)
+
+func Validate(reqObj tc.TopologiesQueueUpdateRequest, topologyName tc.TopologyName, tx *sql.Tx) error {
+	errorMap := validation.Errors{}
+
+	if reqObj.Action != "queue" && reqObj.Action != "dequeue" {
+		errorMap["action"] = errors.New("action must be 'queue' or 'dequeue'")
+	}
+
+	if _, cdnExists, err := dbhelpers.GetCDNNameFromID(tx, reqObj.CDNID); err != nil {
+		errorMap["cdnId"] = fmt.Errorf("could not check whether cdn exists for id %d", reqObj.CDNID)
+	} else if !cdnExists {
+		errorMap["cdnId"] = fmt.Errorf("no cdn exists with id %d", reqObj.CDNID)
+	}
+
+	if topologyExists, err := dbhelpers.TopologyExists(tx, topologyName); err != nil {
+		errorMap["topology"] = fmt.Errorf("could not check whether topology %s exists", topologyName)
+	} else if !topologyExists {
+		errorMap["topology"] = fmt.Errorf("no topology exists by the name of %s", topologyName)
+	}
+
+	return util.JoinErrs(tovalidate.ToErrors(errorMap))
+}
+
+func QueueUpdateHandler(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, []string{})
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	reqObj := tc.TopologiesQueueUpdateRequest{}
+	if err := json.NewDecoder(r.Body).Decode(&reqObj); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("malformed JSON: "+err.Error()), nil)
+		return
+	}
+	topologyName := tc.TopologyName(inf.Params["name"])
+	if err := Validate(reqObj, topologyName, inf.Tx.Tx); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, fmt.Errorf("invalid request to queue updates: %s", err), nil)
+		return
+	}
+	if err := queueUpdates(inf.Tx.Tx, topologyName, reqObj.CDNID, reqObj.Action == "queue"); err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("Topology queueing updates: "+err.Error()))
+		return
+	}
+
+	message := fmt.Sprintf("TOPOLOGY: %s, ACTION: Topology server updates %sd", topologyName, reqObj.Action)
+	api.CreateChangeLogRawTx(api.ApiChange, message, inf.User, inf.Tx.Tx)
+	api.WriteResp(w, r, tc.TopologiesQueueUpdate{Action: reqObj.Action, CDNID: reqObj.CDNID, Topology: topologyName})
+}
+
+func queueUpdates(tx *sql.Tx, topologyName tc.TopologyName, cdnId int64, queue bool) error {
+	query := `
+UPDATE server s
+SET upd_pending = $1
+FROM cachegroup c, topology_cachegroup tc, cdn
+WHERE s.cachegroup = c.id
+AND c."name" = tc.cachegroup

Review comment:
       Does this need to be quoted?

##########
File path: lib/go-tc/topologies.go
##########
@@ -47,3 +47,25 @@ type TopologiesResponse struct {
 	Response []Topology `json:"response"`
 	Alerts
 }
+
+// TopologiesQueueUpdateRequest encodes the request data for the POST
+// topologies/{{name}}/queue_update endpoint.
+type TopologiesQueueUpdateRequest struct {
+	Action string `json:"action"`
+	CDNID  int64  `json:"cdnId"`
+}
+
+// TopologiesQueueUpdate encodes the response data for the POST

Review comment:
       Should be `TopologiesQueueUpdateResponse`

##########
File path: traffic_ops/traffic_ops_golang/topology/queue_update.go
##########
@@ -0,0 +1,100 @@
+package topology
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"

Review comment:
       These imports are not ordered correctly




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] shamrickus commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
shamrickus commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r485074180



##########
File path: docs/source/api/v3/topologies_name_queue_update.rst
##########
@@ -0,0 +1,86 @@
+..
+..
+.. 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.
+..
+
+.. _to-api-topologies-name-queue_update:
+
+****************************
+``topologies/{{name}}/queue_update``
+****************************
+
+``POST``
+========
+:term:`Queue` or "dequeue" updates for all servers assigned to the :term:`Cachegroups` in a specific :term:`Topology`.

Review comment:
       Get a build warning:
   `WARNING: term not in glossary: Cachegroups`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r485075566



##########
File path: docs/source/api/v3/topologies_name_queue_update.rst
##########
@@ -0,0 +1,86 @@
+..
+..
+.. 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.
+..
+
+.. _to-api-topologies-name-queue_update:
+
+****************************

Review comment:
       Lengthened in 3b2956594




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] shamrickus commented on a change in pull request #5016: New endpoint: Queue updates on the servers in a topology

Posted by GitBox <gi...@apache.org>.
shamrickus commented on a change in pull request #5016:
URL: https://github.com/apache/trafficcontrol/pull/5016#discussion_r485074680



##########
File path: docs/source/api/v3/topologies_name_queue_update.rst
##########
@@ -0,0 +1,86 @@
+..
+..
+.. 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.
+..
+
+.. _to-api-topologies-name-queue_update:
+
+****************************

Review comment:
       Title overline too short




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org