mhoppa commented on a change in pull request #4041: Block server 
servercapability delete if associated ds requires it
URL: https://github.com/apache/trafficcontrol/pull/4041#discussion_r340672906
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/server/servers_server_capability.go
 ##########
 @@ -117,6 +120,22 @@ func (ssc *TOServerServerCapability) Read() 
([]interface{}, error, error, int) {
 }
 
 func (ssc *TOServerServerCapability) Delete() (error, error, int) {
+       // Ensure that the user is not removing a server capability from the 
server
+       // that is required by the delivery services the server is assigned to 
(if applicable)
+       dsIDs := []int64{}
+       if err := ssc.APIInfo().Tx.QueryRow(checkDSReqCapQuery(), ssc.ServerID, 
ssc.ServerCapability).Scan(pq.Array(&dsIDs)); err != nil {
+               return nil, fmt.Errorf("checking removing server server 
capability would still suffice delivery service requried capabilites: %v", 
err), http.StatusInternalServerError
+       }
+
+       if len(dsIDs) > 0 {
+               dsIdsStr, err := json.Marshal(dsIDs)
+               if err != nil {
+                       return nil, fmt.Errorf("formatting response message on 
bad request to disassociate server capability from server: %v", err), 
http.StatusInternalServerError
+               }
+               return fmt.Errorf("cannot remove the capability %v from the 
server %v as the server is assigned to the delivery services %v that require 
it", *ssc.ServerCapability, *ssc.ServerID, string(dsIdsStr)), nil, 
http.StatusBadRequest
 
 Review comment:
   Ill omit them 👍 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to