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/01/27 21:30:06 UTC

[GitHub] [trafficcontrol] mattjackson220 opened a new pull request #4339: cachegroupparameters rewrite

mattjackson220 opened a new pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339
 
 
   <!--
   ************ 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.
   
   - [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.
   -->
   Rewrites /cachegroupparameters in go
   - [x] This PR fixes #3809 
   
   
   ## 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 Ops
   
   ## What is the best way to verify this PR?
   - Verify that a GET to /cachegroupparameters returns a list of all of the cachegroup / parameter associations
   - Verify that a PUT to /cachegroupparameters with only one association like so:
   {"cachegroupId":1, "parameterId":2}
   adds the association to the table and appears with a GET
   - Verify that a PUT to /cachegroupparameters with multiple associations like so:
   [{"cachegroupId":1, "parameterId":2}, {"cachegroupId":1, "parameterId":2}, {"cachegroupId":2, "parameterId":2}]
   adds all of the associations to the table and they all appear with a GET
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   <!-- If this PR fixes a bug, please list here all of the affected versions - to
   the best of your knowledge. It's also pretty helpful to include a commit hash
   of where 'master' is at the time this PR is opened (if it affects master),
   because what 'master' means will change over time. For example, if this PR
   fixes a bug that's present in master (at commit hash '2697ebac'), in v3.0.0,
   and in the current 3.0.1 Release candidate (e.g. RC1), then this list would
   look like:
   
   - master (2697ebac)
   - 3.0.0
   - 3.0.1 (RC1)
   
   If you don't know what other versions might have this bug, AND don't know how
   to find the commit hash of 'master', then feel free to leave this section
   blank (or, preferably, delete it entirely).
    -->
   
   
   ## 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 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)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r372643832
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("writing cachegroup parameter: "+err.Error()))
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373589613
 
 

 ##########
 File path: traffic_ops/client/cachegroup_parameters.go
 ##########
 @@ -67,6 +67,28 @@ func (to *Session) getCacheGroupParameters(route, queryParams string) ([]tc.Cach
 	return data.Response, reqInf, nil
 }
 
+// GetAllCacheGroupParameters Gets all Cachegroup Parameter associations
+func (to *Session) GetAllCacheGroupParameters() ([]tc.CacheGroupParametersResponseNullable, ReqInf, error) {
+	route := fmt.Sprintf("%s/", API_v1_CacheGroupParameters)
+	return to.getAllCacheGroupParameters(route, "")
+}
+
+func (to *Session) getAllCacheGroupParameters(route, queryParams string) ([]tc.CacheGroupParametersResponseNullable, ReqInf, error) {
 
 Review comment:
   oh originally i was going to mirror the get methods above but realized i only needed the one but left it split even though the second one isnt reused. ill combine them again since theres no need for 2

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] ocket8888 merged pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
ocket8888 merged pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339
 
 
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371978257
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("writing cachegroup parameter: "+err.Error()))
+		return
+	}
+
 
 Review comment:
   I also dont see any logic matching -> 
   https://github.com/apache/trafficcontrol/blob/master/traffic_ops/app/lib/API/CachegroupParameter.pm#L72-L76

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373654216
 
 

 ##########
 File path: traffic_ops/client/cachegroup_parameters.go
 ##########
 @@ -67,6 +67,24 @@ func (to *Session) getCacheGroupParameters(route, queryParams string) ([]tc.Cach
 	return data.Response, reqInf, nil
 }
 
+// GetAllCacheGroupParameters Gets all Cachegroup Parameter associations
+func (to *Session) GetAllCacheGroupParameters() ([]tc.CacheGroupParametersResponseNullable, ReqInf, error) {
+	route := fmt.Sprintf("%s/", API_v1_CacheGroupParameters)
+	r := fmt.Sprintf("%s/%s", route, "")
 
 Review comment:
   wont this turn out as `cachegroupparameters//` I dont think you need to format it twice. I dont think this is a bug but more of clean up 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r374353024
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +187,137 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx, inf.Params)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sqlx.Tx, parameters map[string]string) (tc.CacheGroupParametersList, error) {
+	if _, ok := parameters["orderby"]; !ok {
+		parameters["orderby"] = "cachegroup"
+	}
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup": dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+		"parameter":  dbhelpers.WhereColumnInfo{"cgp.parameter", api.IsInt},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	log.Errorf("MATT JACKSON queryparams = %s", queryValues)
+	log.Errorf("MATT JACKSON parameters = %s", parameters)
+	log.Errorf("MATT JACKSON query = %s", selectAllQuery()+where+orderBy+pagination)
 
 Review comment:
   well thats embarrassing. done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r375336380
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,63 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r372644746
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,44 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
+	CacheGroupParameters []CacheGroupParametersNullable `json:"cachegroupParameters"`
+}
+
+// CacheGroupParameter ...
+type CacheGroupParameters struct {
+	CacheGroup  int       `json:"cachegroupId"  db:"cachegroup"`
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r375339253
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +186,145 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx, inf.Params)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sqlx.Tx, parameters map[string]string) (tc.CacheGroupParametersList, error) {
+	if _, ok := parameters["orderby"]; !ok {
+		parameters["orderby"] = "cachegroup"
+	}
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup": dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+		"parameter":  dbhelpers.WhereColumnInfo{"cgp.parameter", api.IsInt},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.NamedQuery(query, queryValues)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersResponseNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated, &p.CacheGroupName); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, tc.FormatForResponse(p))
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+// AddCacheGroupParameters performs a Create for cachegroup parameter associations.
+// AddCacheGroupParameters accepts data as a single association or an array of multiple.
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, err := ioutil.ReadAll(r.Body)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("reading request body: "+err.Error()), nil)
+		return
+	}
+
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err = decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	for _, p := range params {
+		ppExists, err := dbhelpers.ProfileParameterExistsByParameterID(*p.Parameter, inf.Tx.Tx)
+		if err != nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, nil, err)
 
 Review comment:
   StatusInternalServer error here

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371960727
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("writing cachegroup parameter: "+err.Error()))
+		return
+	}
+
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Cachegroup parameter associations were created.", params)
+}
+
+func selectAllQuery() string {
+	return `SELECT * FROM cachegroup_parameter`
 
 Review comment:
   might be more safe to do a select on the actual fields just to safe guard yourself from potentially changing the response if the underlying table has a migration

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r372646051
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
 
 Review comment:
   no we shouldnt. updated

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373586924
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,61 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
+	CacheGroupParameters []CacheGroupParametersResponseNullable `json:"cachegroupParameters"`
+}
+
+// CacheGroupParameter ...
+type CacheGroupParameters struct {
+	CacheGroup  int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   int       `json:"parameterId"  db:"parameter"`
+	LastUpdated TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterNullable ...
+type CacheGroupParametersNullable struct {
+	CacheGroup  *int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   *int       `json:"parameterId"  db:"parameter"`
+	LastUpdated *TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterResponseNullable ...
+type CacheGroupParametersResponseNullable struct {
+	CacheGroup  *int       `json:"cachegroup"  db:"cachegroup"`
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r374353182
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +187,137 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx, inf.Params)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sqlx.Tx, parameters map[string]string) (tc.CacheGroupParametersList, error) {
+	if _, ok := parameters["orderby"]; !ok {
+		parameters["orderby"] = "cachegroup"
+	}
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup": dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+		"parameter":  dbhelpers.WhereColumnInfo{"cgp.parameter", api.IsInt},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	log.Errorf("MATT JACKSON queryparams = %s", queryValues)
+	log.Errorf("MATT JACKSON parameters = %s", parameters)
+	log.Errorf("MATT JACKSON query = %s", selectAllQuery()+where+orderBy+pagination)
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.NamedQuery(query, queryValues)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersResponseNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated, &p.CacheGroupName); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, tc.FormatForResponse(p))
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+// AddCacheGroupParameters performs a Create for cachegroup parameter associations.
+// AddCacheGroupParameters accepts data as a single association or an array of multiple.
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, err := ioutil.ReadAll(r.Body)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("reading request body: "+err.Error()), nil)
+		return
+	}
+
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err = decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		userErr, sysErr, code := api.ParseDBError(err)
+		api.HandleErr(w, r, inf.Tx.Tx, code, userErr, sysErr)
+		return
+	}
+
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Cachegroup parameter associations were created.", params)
+}
+
+func selectAllQuery() string {
+	return `SELECT cgp.cachegroup, cgp.parameter, cgp.last_updated, cg.name 
+				FROM cachegroup_parameter AS cgp 
+				JOIN cachegroup AS cg ON cg.id = cachegroup`
+	//return `SELECT cachegroup, parameter, last_updated FROM cachegroup_parameter`
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373550201
 
 

 ##########
 File path: docs/source/api/cachegroupparameters.rst
 ##########
 @@ -97,6 +105,32 @@ The request data can take the form of either a single object or an array of one
 		"parameterId": 124
 	}
 
+Array Format
+""""""""""""
+
+:cacheGroupId: An integer that is the :ref:`cache-group-id` of the :term:`Cache Group` to which a :term:`Parameter` is being assigned
+:parameterId:  An integer that is the :ref:`parameter-id` of the :term:`Parameter` being assigned
+
+.. code-block:: http
+	:caption: Request Example
+
+	POST /api/1.1/cachegroupparameters HTTP/1.1
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 39
+	Content-Type: application/json
+
+	[{
+		"cachegroupId": 8,
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r374682240
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,63 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
 
 Review comment:
   nit godoc comment here 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371965912
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
 
 Review comment:
   should we ignore the error here?

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373654752
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +187,137 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx, inf.Params)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sqlx.Tx, parameters map[string]string) (tc.CacheGroupParametersList, error) {
+	if _, ok := parameters["orderby"]; !ok {
+		parameters["orderby"] = "cachegroup"
+	}
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup": dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+		"parameter":  dbhelpers.WhereColumnInfo{"cgp.parameter", api.IsInt},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	log.Errorf("MATT JACKSON queryparams = %s", queryValues)
+	log.Errorf("MATT JACKSON parameters = %s", parameters)
+	log.Errorf("MATT JACKSON query = %s", selectAllQuery()+where+orderBy+pagination)
 
 Review comment:
   should read `MATT JACKSON IS THE MAN` :) should remove these

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373594042
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,124 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
 
 Review comment:
   Lemme throw this out there: you should support a proper superset of the query parameters supported by Perl - more is totally acceptable, if you want, as long as they are documented (along with the version in which they were added).

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373213181
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,124 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
 
 Review comment:
   why the change from https://github.com/apache/trafficcontrol/blob/f1447bde94e84aa93fba9506a387a34e9aea3dd7/traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go#L210 also the parameters passed into the `BuildWhereAndOrderByAndPagination` should be parameters that the APIInfo parsed out ```inf.Params``` 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373586890
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,124 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
 
 Review comment:
   i was thinking to mirror the perl endpoint better but added it back in as well as docs

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r375358732
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +186,145 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx, inf.Params)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sqlx.Tx, parameters map[string]string) (tc.CacheGroupParametersList, error) {
+	if _, ok := parameters["orderby"]; !ok {
+		parameters["orderby"] = "cachegroup"
+	}
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup": dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+		"parameter":  dbhelpers.WhereColumnInfo{"cgp.parameter", api.IsInt},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.NamedQuery(query, queryValues)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersResponseNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated, &p.CacheGroupName); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, tc.FormatForResponse(p))
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+// AddCacheGroupParameters performs a Create for cachegroup parameter associations.
+// AddCacheGroupParameters accepts data as a single association or an array of multiple.
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, err := ioutil.ReadAll(r.Body)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("reading request body: "+err.Error()), nil)
+		return
+	}
+
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err = decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	for _, p := range params {
+		ppExists, err := dbhelpers.ProfileParameterExistsByParameterID(*p.Parameter, inf.Tx.Tx)
+		if err != nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, nil, err)
 
 Review comment:
   oh my bad. done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373003534
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
 
 Review comment:
   on second thought i dont think we want to do this. ill take it out

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373210674
 
 

 ##########
 File path: traffic_ops/client/cachegroup_parameters.go
 ##########
 @@ -67,6 +67,28 @@ func (to *Session) getCacheGroupParameters(route, queryParams string) ([]tc.Cach
 	return data.Response, reqInf, nil
 }
 
+// GetAllCacheGroupParameters Gets all Cachegroup Parameter associations
+func (to *Session) GetAllCacheGroupParameters() ([]tc.CacheGroupParametersResponseNullable, ReqInf, error) {
+	route := fmt.Sprintf("%s/", API_v1_CacheGroupParameters)
+	return to.getAllCacheGroupParameters(route, "")
+}
+
+func (to *Session) getAllCacheGroupParameters(route, queryParams string) ([]tc.CacheGroupParametersResponseNullable, ReqInf, error) {
 
 Review comment:
   just curious why the need for the two methods?

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371966548
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
 
 Review comment:
   this needs to be added to the doc as support request query parameters 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371964966
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
 
 Review comment:
   you should be able (as long as our sqlx is recent enough) to do a bulk insert with a named query so you dont have to convert ints to strings and then joining them before adding them to the query. https://github.com/jmoiron/sqlx/pull/285 is when it was added 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373656331
 
 

 ##########
 File path: docs/source/api/cachegroupparameters.rst
 ##########
 @@ -29,7 +29,15 @@ Extract information about the :ref:`cache-group-parameters` associated with :ter
 
 Response Structure
 ------------------
-No available parameters
+.. table:: Request Query Parameters
+
+	+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------+
+	| Name        | Required | Description                                                                                                                          |
+	+=============+==========+======================================================================================================================================+
+	| cachegroup  | no       | Show only the :ref:`cache-group-parameters` with the :term:`Cache Group` identified by this integral, unique identifier              |
+	+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------+
+	| parameter   | no       | Show only the :ref:`cache-group-parameters` with the :term:`Parameter` identified by this integral, unique identifier                |
+	+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------+
 
 Review comment:
   fwiw by default when you use the db helpers `BuildWhereAndOrderByAndPagination` you get `orderby`, `sortOrder`, `limit`, `offset` and `page` for free. You can see those documented across most of all of our other endpoints

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373210397
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,61 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
+	CacheGroupParameters []CacheGroupParametersResponseNullable `json:"cachegroupParameters"`
+}
+
+// CacheGroupParameter ...
+type CacheGroupParameters struct {
+	CacheGroup  int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   int       `json:"parameterId"  db:"parameter"`
+	LastUpdated TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterNullable ...
+type CacheGroupParametersNullable struct {
+	CacheGroup  *int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   *int       `json:"parameterId"  db:"parameter"`
+	LastUpdated *TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterResponseNullable ...
+type CacheGroupParametersResponseNullable struct {
+	CacheGroup  *int       `json:"cachegroup"  db:"cachegroup"`
 
 Review comment:
   this should be a string representing the cachegroup name instead of id 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371962190
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("writing cachegroup parameter: "+err.Error()))
 
 Review comment:
   the perl implementation returned a 4xx response code if the parameter or cache group didnt exist and the rewrite returns a 500. If you pass the returned non nil error into https://github.com/apache/trafficcontrol/blob/master/traffic_ops/traffic_ops_golang/api/api.go#L737 it should solve it for you but worth checking

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373002528
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
 
 Review comment:
   doesnt look like ours is up to date enough to do this unfortunately

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r372641848
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("writing cachegroup parameter: "+err.Error()))
+		return
+	}
+
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Cachegroup parameter associations were created.", params)
+}
+
+func selectAllQuery() string {
+	return `SELECT * FROM cachegroup_parameter`
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371985792
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,44 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
+	CacheGroupParameters []CacheGroupParametersNullable `json:"cachegroupParameters"`
+}
+
+// CacheGroupParameter ...
+type CacheGroupParameters struct {
+	CacheGroup  int       `json:"cachegroupId"  db:"cachegroup"`
 
 Review comment:
   Yeah, there was a typo in the docs example, which I tried to fix in time for someone rewriting this endpoint to see, but https://github.com/apache/trafficcontrol/pull/4329 still has to get merged....

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373586924
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,61 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
+	CacheGroupParameters []CacheGroupParametersResponseNullable `json:"cachegroupParameters"`
+}
+
+// CacheGroupParameter ...
+type CacheGroupParameters struct {
+	CacheGroup  int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   int       `json:"parameterId"  db:"parameter"`
+	LastUpdated TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterNullable ...
+type CacheGroupParametersNullable struct {
+	CacheGroup  *int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   *int       `json:"parameterId"  db:"parameter"`
+	LastUpdated *TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterResponseNullable ...
+type CacheGroupParametersResponseNullable struct {
+	CacheGroup  *int       `json:"cachegroup"  db:"cachegroup"`
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r374352941
 
 

 ##########
 File path: traffic_ops/client/cachegroup_parameters.go
 ##########
 @@ -67,6 +67,24 @@ func (to *Session) getCacheGroupParameters(route, queryParams string) ([]tc.Cach
 	return data.Response, reqInf, nil
 }
 
+// GetAllCacheGroupParameters Gets all Cachegroup Parameter associations
+func (to *Session) GetAllCacheGroupParameters() ([]tc.CacheGroupParametersResponseNullable, ReqInf, error) {
+	route := fmt.Sprintf("%s/", API_v1_CacheGroupParameters)
+	r := fmt.Sprintf("%s/%s", route, "")
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371971062
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("writing cachegroup parameter: "+err.Error()))
 
 Review comment:
   Perl also returned 4xx response code if that parameter was already associated with the cache group with this implementation does not do 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371978257
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +185,120 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx.Tx)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+func GetAllCacheGroupParameters(tx *sql.Tx) (tc.CacheGroupParametersList, error) {
+	parameters := map[string]string{
+		"orderby": "cachegroup",
+	}
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup":  dbhelpers.WhereColumnInfo{"cachegroup", api.IsInt},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"last_updated", nil},
+		"parameter":   dbhelpers.WhereColumnInfo{"parameter", api.IsInt},
+	}
+	where, orderBy, pagination, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.Query(query)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, p)
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, _ := ioutil.ReadAll(r.Body)
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err := decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("writing cachegroup parameter: "+err.Error()))
+		return
+	}
+
 
 Review comment:
   I also dont see any logic matching -> 
   https://github.com/apache/trafficcontrol/blob/master/traffic_ops/app/lib/API/CachegroupParameter.pm#L72-L76

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r374353082
 
 

 ##########
 File path: docs/source/api/cachegroupparameters.rst
 ##########
 @@ -29,7 +29,15 @@ Extract information about the :ref:`cache-group-parameters` associated with :ter
 
 Response Structure
 ------------------
-No available parameters
+.. table:: Request Query Parameters
+
+	+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------+
+	| Name        | Required | Description                                                                                                                          |
+	+=============+==========+======================================================================================================================================+
+	| cachegroup  | no       | Show only the :ref:`cache-group-parameters` with the :term:`Cache Group` identified by this integral, unique identifier              |
+	+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------+
+	| parameter   | no       | Show only the :ref:`cache-group-parameters` with the :term:`Parameter` identified by this integral, unique identifier                |
+	+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------+
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373208462
 
 

 ##########
 File path: docs/source/api/cachegroupparameters.rst
 ##########
 @@ -97,6 +105,32 @@ The request data can take the form of either a single object or an array of one
 		"parameterId": 124
 	}
 
+Array Format
+""""""""""""
+
+:cacheGroupId: An integer that is the :ref:`cache-group-id` of the :term:`Cache Group` to which a :term:`Parameter` is being assigned
+:parameterId:  An integer that is the :ref:`parameter-id` of the :term:`Parameter` being assigned
+
+.. code-block:: http
+	:caption: Request Example
+
+	POST /api/1.1/cachegroupparameters HTTP/1.1
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 39
+	Content-Type: application/json
+
+	[{
+		"cachegroupId": 8,
 
 Review comment:
   this and below need to be `cacheGroupId` 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373662577
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroupparameter/parameters.go
 ##########
 @@ -180,3 +187,137 @@ func (cgparam *TOCacheGroupParameter) Delete() (error, error, int) {
 
 	return api.GenericDelete(cgparam)
 }
+
+// ReadAllCacheGroupParameters reads all cachegroup parameter associations.
+func ReadAllCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+	output, err := GetAllCacheGroupParameters(inf.Tx, inf.Params)
+	if err != nil {
+		api.WriteRespAlertObj(w, r, tc.ErrorLevel, "querying cachegroupparameters with error: "+err.Error(), output)
+		return
+	}
+	api.WriteResp(w, r, output)
+}
+
+// GetAllCacheGroupParameters gets all cachegroup associations from the database and returns as slice.
+func GetAllCacheGroupParameters(tx *sqlx.Tx, parameters map[string]string) (tc.CacheGroupParametersList, error) {
+	if _, ok := parameters["orderby"]; !ok {
+		parameters["orderby"] = "cachegroup"
+	}
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cachegroup": dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+		"parameter":  dbhelpers.WhereColumnInfo{"cgp.parameter", api.IsInt},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return tc.CacheGroupParametersList{}, util.JoinErrs(errs)
+	}
+
+	log.Errorf("MATT JACKSON queryparams = %s", queryValues)
+	log.Errorf("MATT JACKSON parameters = %s", parameters)
+	log.Errorf("MATT JACKSON query = %s", selectAllQuery()+where+orderBy+pagination)
+	query := selectAllQuery() + where + orderBy + pagination
+	rows, err := tx.NamedQuery(query, queryValues)
+	if err != nil {
+		return tc.CacheGroupParametersList{}, errors.New("querying cachegroupParameters: " + err.Error())
+	}
+	defer rows.Close()
+
+	paramsList := tc.CacheGroupParametersList{}
+	params := []tc.CacheGroupParametersResponseNullable{}
+	for rows.Next() {
+		var p tc.CacheGroupParametersNullable
+		if err = rows.Scan(&p.CacheGroup, &p.Parameter, &p.LastUpdated, &p.CacheGroupName); err != nil {
+			return tc.CacheGroupParametersList{}, errors.New("scanning cachegroupParameters: " + err.Error())
+		}
+		params = append(params, tc.FormatForResponse(p))
+	}
+	paramsList.CacheGroupParameters = params
+	return paramsList, nil
+}
+
+// AddCacheGroupParameters performs a Create for cachegroup parameter associations.
+// AddCacheGroupParameters accepts data as a single association or an array of multiple.
+func AddCacheGroupParameters(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	data, err := ioutil.ReadAll(r.Body)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("reading request body: "+err.Error()), nil)
+		return
+	}
+
+	buf := ioutil.NopCloser(bytes.NewReader(data))
+
+	var paramsInt interface{}
+
+	decoder := json.NewDecoder(buf)
+	err = decoder.Decode(&paramsInt)
+	if err != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing json: "+err.Error()), nil)
+		return
+	}
+
+	var params []tc.CacheGroupParametersNullable
+	_, ok := paramsInt.([]interface{})
+	var parseErr error = nil
+	if !ok {
+		var singleParam tc.CacheGroupParametersNullable
+		parseErr = json.Unmarshal(data, &singleParam)
+		if singleParam.CacheGroup == nil || singleParam.Parameter == nil {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("invalid cachegroup parameter."), nil)
+			return
+		}
+		params = append(params, singleParam)
+	} else {
+		parseErr = json.Unmarshal(data, &params)
+	}
+	if parseErr != nil {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("parsing cachegroup parameter: "+parseErr.Error()), nil)
+		return
+	}
+
+	values := []string{}
+	for _, param := range params {
+		values = append(values, "("+strconv.Itoa(*param.CacheGroup)+", "+strconv.Itoa(*param.Parameter)+")")
+	}
+
+	insQuery := strings.Join(values, ", ")
+	_, err = inf.Tx.Tx.Query(insertQuery() + insQuery)
+
+	if err != nil {
+		userErr, sysErr, code := api.ParseDBError(err)
+		api.HandleErr(w, r, inf.Tx.Tx, code, userErr, sysErr)
+		return
+	}
+
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Cachegroup parameter associations were created.", params)
+}
+
+func selectAllQuery() string {
+	return `SELECT cgp.cachegroup, cgp.parameter, cgp.last_updated, cg.name 
+				FROM cachegroup_parameter AS cgp 
+				JOIN cachegroup AS cg ON cg.id = cachegroup`
+	//return `SELECT cachegroup, parameter, last_updated FROM cachegroup_parameter`
 
 Review comment:
   remove comment
   

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r371979654
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,44 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
+	CacheGroupParameters []CacheGroupParametersNullable `json:"cachegroupParameters"`
+}
+
+// CacheGroupParameter ...
+type CacheGroupParameters struct {
+	CacheGroup  int       `json:"cachegroupId"  db:"cachegroup"`
 
 Review comment:
   FWIW I believe `cachegroupId` was handled as `cacheGroupId` in Perl we should match that 

----------------------------------------------------------------
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


With regards,
Apache Git Services

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4339: cachegroupparameters rewrite
URL: https://github.com/apache/trafficcontrol/pull/4339#discussion_r373567291
 
 

 ##########
 File path: lib/go-tc/cachegroup_parameter_associations.go
 ##########
 @@ -0,0 +1,61 @@
+package tc
+
+/*
+ * 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.
+ */
+
+// CacheGroupParametersResponse is a Cache Group Parameter response body.
+type AllCacheGroupParametersResponse struct {
+	Response CacheGroupParametersList `json:"response"`
+	Alerts
+}
+
+type CacheGroupParametersList struct {
+	CacheGroupParameters []CacheGroupParametersResponseNullable `json:"cachegroupParameters"`
+}
+
+// CacheGroupParameter ...
+type CacheGroupParameters struct {
+	CacheGroup  int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   int       `json:"parameterId"  db:"parameter"`
+	LastUpdated TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterNullable ...
+type CacheGroupParametersNullable struct {
+	CacheGroup  *int       `json:"cacheGroupId"  db:"cachegroup"`
+	Parameter   *int       `json:"parameterId"  db:"parameter"`
+	LastUpdated *TimeNoMod `json:"lastUpdated,omitempty"  db:"last_updated"`
+}
+
+// CacheGroupParameterResponseNullable ...
+type CacheGroupParametersResponseNullable struct {
+	CacheGroup  *int       `json:"cachegroup"  db:"cachegroup"`
 
 Review comment:
   done

----------------------------------------------------------------
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


With regards,
Apache Git Services