You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2020/03/03 17:37:27 UTC

[trafficcontrol] branch master updated: fixed so parameters can be associated with cachegroups and profiles (#4457)

This is an automated email from the ASF dual-hosted git repository.

ocket8888 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 4b3d01d  fixed so parameters can be associated with cachegroups and profiles (#4457)
4b3d01d is described below

commit 4b3d01d7855b72762eda171bb2a7335a0d155d55
Author: mattjackson220 <33...@users.noreply.github.com>
AuthorDate: Tue Mar 3 10:37:20 2020 -0700

    fixed so parameters can be associated with cachegroups and profiles (#4457)
    
    * fixed so parameters can be associated with cachegroups and profiles
    
    * update for better func name and error message
---
 docs/source/api/v1/cachegroupparameters.rst                      | 2 +-
 docs/source/api/v2/cachegroupparameters.rst                      | 2 +-
 traffic_ops/app/lib/API/CachegroupParameter.pm                   | 8 ++++----
 traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go | 4 ++--
 traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go           | 8 ++++----
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/docs/source/api/v1/cachegroupparameters.rst b/docs/source/api/v1/cachegroupparameters.rst
index 0e6610e..578f24c 100644
--- a/docs/source/api/v1/cachegroupparameters.rst
+++ b/docs/source/api/v1/cachegroupparameters.rst
@@ -87,7 +87,7 @@ Response Structure
 
 ``POST``
 ========
-Assign :term:`Parameter`\ (s) to :term:`Cache Group`\ (s). :term:`Parameters` already assigned to one or more :term:`Profiles` cannot be assigned to :term:`Cache Groups`.
+Assign :term:`Parameter`\ (s) to :term:`Cache Group`\ (s).
 
 :Auth. Required: Yes
 :Roles Required: "admin" or "operations"
diff --git a/docs/source/api/v2/cachegroupparameters.rst b/docs/source/api/v2/cachegroupparameters.rst
index 65e16a2..c88bf25 100644
--- a/docs/source/api/v2/cachegroupparameters.rst
+++ b/docs/source/api/v2/cachegroupparameters.rst
@@ -87,7 +87,7 @@ Response Structure
 
 ``POST``
 ========
-Assign :term:`Parameter`\ (s) to :term:`Cache Group`\ (s). :term:`Parameters` already assigned to one or more :term:`Profiles` cannot be assigned to :term:`Cache Groups`.
+Assign :term:`Parameter`\ (s) to :term:`Cache Group`\ (s).
 
 :Auth. Required: Yes
 :Roles Required: "admin" or "operations"
diff --git a/traffic_ops/app/lib/API/CachegroupParameter.pm b/traffic_ops/app/lib/API/CachegroupParameter.pm
index be9ae9f..e0f9c23 100644
--- a/traffic_ops/app/lib/API/CachegroupParameter.pm
+++ b/traffic_ops/app/lib/API/CachegroupParameter.pm
@@ -69,10 +69,10 @@ sub create {
 			$self->db->txn_rollback();
 			return $self->alert("Parameter with id: " . $param->{parameterId} . " doesn't exist");
 		}
-		my $cg_param = $self->db->resultset('ProfileParameter')->find( { parameter => $parameter->id, profile => $cg->id } );
+		my $cg_param = $self->db->resultset('CachegroupParameter')->find( { parameter => $parameter->id, cachegroup => $cg->id } );
 		if ( defined($cg_param) ) {
 			$self->db->txn_rollback();
-			return $self->alert("parameter: " . $param->{parameterId} . " already associated with profile: " . $param->{profileId});
+			return $self->alert("parameter: " . $param->{parameterId} . " already associated with cachegroup: " . $param->{cacheGroupId});
 		}
 		$self->db->resultset('CachegroupParameter')->create( { parameter => $parameter->id, cachegroup => $cg->id } )->insert();
 	}
@@ -81,7 +81,7 @@ sub create {
 	&log( $self, "New cache group parameter associations were created.", "APICHANGE" );
 
 	my $response = $params;
-	return $self->success($response, "Profile parameter associations were created.");
+	return $self->success($response, "Cachegroup parameter associations were created.");
 }
 
 sub delete {
@@ -112,7 +112,7 @@ sub delete {
 
 	&log( $self, "Deleted cache group parameter " . $cg->name . " <-> " . $parameter->name, "APICHANGE" );
 
-	return $self->success_message("Profile parameter association was deleted.");
+	return $self->success_message("Cachegroup parameter association was deleted.");
 }
 
 
diff --git a/traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go b/traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
index bcc6416..26d4674 100644
--- a/traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
+++ b/traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
@@ -288,13 +288,13 @@ func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
 	}
 
 	for _, p := range params {
-		ppExists, err := dbhelpers.ProfileParameterExistsByParameterID(*p.Parameter, inf.Tx.Tx)
+		ppExists, err := dbhelpers.CachegroupParameterAssociationExists(*p.Parameter, *p.CacheGroup, inf.Tx.Tx)
 		if err != nil {
 			api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
 			return
 		}
 		if ppExists {
-			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parameter: "+strconv.Itoa(*p.Parameter)+" already associated with one or more profiles."), nil)
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parameter: "+strconv.Itoa(*p.Parameter)+" already associated with cachegroup: "+strconv.Itoa(*p.CacheGroup)+"."), nil)
 			return
 		}
 	}
diff --git a/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go b/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
index 5425d0c..0a7f732 100644
--- a/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
+++ b/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
@@ -747,11 +747,11 @@ func GetUserByID(id int, tx *sql.Tx) (tc.User, bool, error) {
 	return u, true, err
 }
 
-// ProfileParameterExistsByParameterID returns whether a profile parameter association with the given parameter id exists, and any error.
-func ProfileParameterExistsByParameterID(id int, tx *sql.Tx) (bool, error) {
+// CachegroupParameterAssociationExists returns whether a cachegroup parameter association with the given parameter id exists, and any error.
+func CachegroupParameterAssociationExists(id int, cachegroup int, tx *sql.Tx) (bool, error) {
 	count := 0
-	if err := tx.QueryRow(`SELECT count(*) from profile_parameter where parameter = $1`, id).Scan(&count); err != nil {
-		return false, errors.New("querying profile parameter existence from parameter id: " + err.Error())
+	if err := tx.QueryRow(`SELECT count(*) from cachegroup_parameter where parameter = $1 and cachegroup = $2`, id, cachegroup).Scan(&count); err != nil {
+		return false, errors.New("querying cachegroup parameter existence: " + err.Error())
 	}
 	return count > 0, nil
 }