You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ro...@apache.org on 2018/10/04 19:54:35 UTC
[trafficcontrol] branch master updated: Remove some
unused/duplicated dbhelper functions
This is an automated email from the ASF dual-hosted git repository.
rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 8b2c71a Remove some unused/duplicated dbhelper functions
8b2c71a is described below
commit 8b2c71a68aefd31c7df99269a19d9f3e13f65c90
Author: Rawlin Peters <ra...@comcast.com>
AuthorDate: Tue Oct 2 16:01:50 2018 -0600
Remove some unused/duplicated dbhelper functions
---
.../traffic_ops_golang/dbhelpers/db_helpers.go | 66 ++--------------------
.../traffic_ops_golang/deliveryservice/urlkey.go | 17 +-----
2 files changed, 6 insertions(+), 77 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go b/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
index 866342c..7bc31ed 100644
--- a/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
+++ b/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
@@ -22,6 +22,7 @@ package dbhelpers
import (
"database/sql"
"errors"
+ "fmt"
"strings"
"github.com/apache/trafficcontrol/lib/go-log"
@@ -101,30 +102,6 @@ func parseCriteriaAndQueryValues(queryParamsToSQLCols map[string]WhereColumnInfo
return criteria, queryValues, errs
}
-// FinishTx commits the transaction if commit is true when it's called, otherwise it rolls back the transaction. This is designed to be called in a defer.
-func FinishTx(tx *sql.Tx, commit *bool) {
- if tx == nil {
- return
- }
- if !*commit {
- tx.Rollback()
- return
- }
- tx.Commit()
-}
-
-// FinishTxX commits the transaction if commit is true when it's called, otherwise it rolls back the transaction. This is designed to be called in a defer.
-func FinishTxX(tx *sqlx.Tx, commit *bool) {
- if tx == nil {
- return
- }
- if !*commit {
- tx.Rollback()
- return
- }
- tx.Commit()
-}
-
// AddTenancyCheck takes a WHERE clause (can be ""), the associated queryValues (can be empty),
// a tenantColumnName that should provide a bigint corresponding to the tenantID of the object being checked (this may require a CAST),
// and an array of the tenantIDs the user has access to; it returns a where clause and associated queryValues including filtering based on tenancy.
@@ -140,53 +117,18 @@ func AddTenancyCheck(where string, queryValues map[string]interface{}, tenantCol
return where, queryValues
}
-// GetGlobalParams returns the value of the global param, whether it existed, or any error
-func GetGlobalParam(tx *sql.Tx, name string) (string, bool, error) {
- return GetParam(tx, name, "global")
-}
-
-// GetParam returns the value of the param, whether it existed, or any error.
-func GetParam(tx *sql.Tx, name string, configFile string) (string, bool, error) {
- val := ""
- if err := tx.QueryRow(`select value from parameter where name = $1 and config_file = $2`, name, configFile).Scan(&val); err != nil {
- if err == sql.ErrNoRows {
- return "", false, nil
- }
- return "", false, errors.New("Error querying global paramter '" + name + "': " + err.Error())
- }
- return val, true, nil
-}
-
-// GetDSNameFromID returns the delivery service name, whether it existed, and any error.
+// GetDSNameFromID loads the DeliveryService's xml_id from the database, from the ID. Returns whether the delivery service was found, and any error.
func GetDSNameFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, bool, error) {
name := tc.DeliveryServiceName("")
- if err := tx.QueryRow(`select xml_id from deliveryservice where id = $1`, id).Scan(&name); err != nil {
+ if err := tx.QueryRow(`SELECT xml_id FROM deliveryservice WHERE id = $1`, id).Scan(&name); err != nil {
if err == sql.ErrNoRows {
return tc.DeliveryServiceName(""), false, nil
}
- return tc.DeliveryServiceName(""), false, errors.New("querying delivery service name: " + err.Error())
+ return tc.DeliveryServiceName(""), false, fmt.Errorf("querying xml_id for delivery service ID '%v': %v", id, err)
}
return name, true, nil
}
-// returns returns the delivery service name and cdn, whether it existed, and any error.
-func GetDSNameAndCDNFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, tc.CDNName, bool, error) {
- name := tc.DeliveryServiceName("")
- cdn := tc.CDNName("")
- if err := tx.QueryRow(`
-SELECT ds.xml_id, cdn.name
-FROM deliveryservice as ds
-JOIN cdn on cdn.id = ds.cdn_id
-WHERE ds.id = $1
-`, id).Scan(&name, &cdn); err != nil {
- if err == sql.ErrNoRows {
- return tc.DeliveryServiceName(""), tc.CDNName(""), false, nil
- }
- return tc.DeliveryServiceName(""), tc.CDNName(""), false, errors.New("querying delivery service name: " + err.Error())
- }
- return name, cdn, true, nil
-}
-
// GetProfileNameFromID returns the profile's name, whether a profile with ID exists, or any error.
func GetProfileNameFromID(id int, tx *sql.Tx) (string, bool, error) {
name := ""
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go b/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go
index 19c06f8..33312f8 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go
@@ -21,7 +21,6 @@ package deliveryservice
import (
"crypto/rand"
- "database/sql"
"errors"
"fmt"
"math/big"
@@ -30,6 +29,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/riaksvc"
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/tenant"
)
@@ -47,7 +47,7 @@ func GetURLKeysByID(w http.ResponseWriter, r *http.Request) {
return
}
- ds, ok, err := GetDSNameFromID(inf.Tx.Tx, inf.IntParams["id"])
+ ds, ok, err := dbhelpers.GetDSNameFromID(inf.Tx.Tx, inf.IntParams["id"])
if err != nil {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("getting delivery service name from ID: "+err.Error()))
return
@@ -231,19 +231,6 @@ func CopyURLKeys(w http.ResponseWriter, r *http.Request) {
api.WriteRespAlert(w, r, tc.SuccessLevel, "Successfully copied and stored keys")
}
-// GetDSNameFromID loads the DeliveryService's xml_id from the database, from the ID. Returns whether the delivery service was found, and any error.
-// TODO move somewhere generic
-func GetDSNameFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, bool, error) {
- name := tc.DeliveryServiceName("")
- if err := tx.QueryRow(`SELECT xml_id FROM deliveryservice where id = $1`, id).Scan(&name); err != nil {
- if err == sql.ErrNoRows {
- return tc.DeliveryServiceName(""), false, nil
- }
- return tc.DeliveryServiceName(""), false, fmt.Errorf("querying xml_id for delivery service ID '%v': %v", id, err)
- }
- return name, true, nil
-}
-
func GenerateURLKeys(w http.ResponseWriter, r *http.Request) {
inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, nil)
if userErr != nil || sysErr != nil {