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

[trafficcontrol] branch master updated: Removed unused code in traffic_ops_golang (#4595)

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

ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b5dd40  Removed unused code in traffic_ops_golang (#4595)
3b5dd40 is described below

commit 3b5dd406bf1a0bb456c062b0f6a465ec0617d8ef
Author: Rawlin Peters <ra...@apache.org>
AuthorDate: Mon Apr 6 08:27:50 2020 -0600

    Removed unused code in traffic_ops_golang (#4595)
---
 .../testing/api/v2/deliveryservices_test.go        | 26 +------------
 .../ats/atsserver/parentdotconfig.go               | 44 ----------------------
 traffic_ops/traffic_ops_golang/ats/db.go           | 20 ----------
 .../traffic_ops_golang/cachegroup/cachegroups.go   |  6 ---
 .../traffic_ops_golang/cachegroup/dspost.go        |  5 ---
 .../traffic_ops_golang/cachesstats/cachesstats.go  | 30 ---------------
 .../crconfig/deliveryservice_test.go               | 35 -----------------
 traffic_ops/traffic_ops_golang/crstats/routing.go  | 10 -----
 .../deliveryservice/request/requests.go            |  6 ---
 .../deliveryservice/servers/servers.go             | 32 ----------------
 .../deliveryservice/servers/servers_test.go        | 20 ----------
 .../profileparameter/profile_parameters.go         | 11 ------
 .../traffic_ops_golang/user/deliveryservices.go    | 11 ------
 traffic_ops/traffic_ops_golang/user/user.go        | 11 ------
 14 files changed, 1 insertion(+), 266 deletions(-)

diff --git a/traffic_ops/testing/api/v2/deliveryservices_test.go b/traffic_ops/testing/api/v2/deliveryservices_test.go
index 8f7040a..23504c6 100644
--- a/traffic_ops/testing/api/v2/deliveryservices_test.go
+++ b/traffic_ops/testing/api/v2/deliveryservices_test.go
@@ -19,9 +19,6 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"io"
-	"io/ioutil"
-	"net/http"
 	"reflect"
 	"strconv"
 	"testing"
@@ -332,7 +329,7 @@ func GetAccessibleToTest(t *testing.T) {
 	if err != nil {
 		t.Fatal("unable to get tenant " + err.Error())
 	}
-	err = getByTenants(childTenant.ID, len(testData.DeliveryServices) - 1)
+	err = getByTenants(childTenant.ID, len(testData.DeliveryServices)-1)
 	if err != nil {
 		t.Fatal(err.Error())
 	}
@@ -467,27 +464,6 @@ func DeliveryServiceMinorVersionsTest(t *testing.T) {
 
 }
 
-// TODO: move this helper function into a better location
-func makeRequest(version string, method string, path string, body io.Reader, respStruct interface{}) error {
-	req, err := http.NewRequest(method, TOSession.URL+"/api/"+version+"/"+path, body)
-	if err != nil {
-		return fmt.Errorf("failed to create request: %s", err.Error())
-	}
-	resp, err := TOSession.Client.Do(req)
-	if err != nil {
-		return fmt.Errorf("running request: %s", err.Error())
-	}
-	defer resp.Body.Close()
-	bts, err := ioutil.ReadAll(resp.Body)
-	if err != nil {
-		return fmt.Errorf("reading body: " + err.Error())
-	}
-	if err = json.Unmarshal(bts, respStruct); err != nil {
-		return fmt.Errorf("unmarshalling body '" + string(bts) + "': " + err.Error())
-	}
-	return nil
-}
-
 func DeliveryServiceTenancyTest(t *testing.T) {
 	dses, _, err := TOSession.GetDeliveryServicesNullable()
 	if err != nil {
diff --git a/traffic_ops/traffic_ops_golang/ats/atsserver/parentdotconfig.go b/traffic_ops/traffic_ops_golang/ats/atsserver/parentdotconfig.go
index 3d61f19..c3223f1 100644
--- a/traffic_ops/traffic_ops_golang/ats/atsserver/parentdotconfig.go
+++ b/traffic_ops/traffic_ops_golang/ats/atsserver/parentdotconfig.go
@@ -354,14 +354,6 @@ func getParentConfigDSRaw(tx *sql.Tx, qry string, qryParams []interface{}) ([]at
 	return dses, nil
 }
 
-func parentConfigDSesToNames(dses []atscfg.ParentConfigDS) []string {
-	names := []string{}
-	for _, ds := range dses {
-		names = append(names, string(ds.Name))
-	}
-	return names
-}
-
 func parentConfigDSesToNamesTopLevel(dses []atscfg.ParentConfigDSTopLevel) []string {
 	names := []string{}
 	for _, ds := range dses {
@@ -821,42 +813,6 @@ WHERE
 	return sParams, nil
 }
 
-func getServerParams(tx *sql.Tx, serverID int) (map[string]string, error) {
-	qry := `
-SELECT
-  pa.name
-  pa.value
-FROM
-  parameter pa
-  JOIN profile_parameter pp ON pp.parameter = pa.id
-  JOIN profile pr ON pr.id = pp.profile
-  JOIN server s on s.profile = pr.id
-WHERE
-  s.id = $1
-  AND pa.config_file = 'parent.config'
-  AND pa.name IN (
-    '` + atscfg.ParentConfigParamQStringHandling + `',
-    '` + atscfg.ParentConfigParamAlgorithm + `',
-    '` + atscfg.ParentConfigParamQString + `'
-  )
-`
-	rows, err := tx.Query(qry, serverID)
-	if err != nil {
-		return nil, errors.New("querying: " + err.Error())
-	}
-	defer rows.Close()
-	params := map[string]string{}
-	for rows.Next() {
-		name := ""
-		val := ""
-		if err := rows.Scan(&name, &val); err != nil {
-			return nil, errors.New("scanning: " + err.Error())
-		}
-		params[name] = val
-	}
-	return params, nil
-}
-
 type ParentConfigServerParams struct {
 	QString         string
 	Algorithm       string
diff --git a/traffic_ops/traffic_ops_golang/ats/db.go b/traffic_ops/traffic_ops_golang/ats/db.go
index ac30dcf..3df8787 100644
--- a/traffic_ops/traffic_ops_golang/ats/db.go
+++ b/traffic_ops/traffic_ops_golang/ats/db.go
@@ -37,26 +37,6 @@ import (
 // RemapDotConfigIncludeInactiveDeliveryServices is whether delivery services with 'active' false are included in the remap.config.
 const RemapDotConfigIncludeInactiveDeliveryServices = true
 
-// getProfileData returns the necessary info about the profile, whether it exists, and any error.
-func getProfileData(tx *sql.Tx, id int) (ProfileData, bool, error) {
-	qry := `
-SELECT
-  p.name
-FROM
-  profile p
-WHERE
-  p.id = $1
-`
-	v := ProfileData{ID: id}
-	if err := tx.QueryRow(qry, id).Scan(&v.Name); err != nil {
-		if err == sql.ErrNoRows {
-			return ProfileData{}, false, nil
-		}
-		return ProfileData{}, false, errors.New("querying: " + err.Error())
-	}
-	return v, true, nil
-}
-
 // GetProfilesParamData returns a map[profileID][paramName]paramVal
 func GetProfilesParamData(tx *sql.Tx, profileIDs []int, configFile string) (map[int]map[string]string, error) {
 	qry := `
diff --git a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
index 58c1868..21f2cba 100644
--- a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
+++ b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
@@ -621,12 +621,6 @@ LEFT JOIN cachegroup AS cgp ON cachegroup.parent_cachegroup_id = cgp.id
 LEFT JOIN cachegroup AS cgs ON cachegroup.secondary_parent_cachegroup_id = cgs.id`
 }
 
-// unused?
-// select type name so checks are based on name instead of id
-func selectTypeNameQuery() string {
-	return `SELECT name FROM type WHERE id = $1;`
-}
-
 func UpdateQuery() string {
 	// to disambiguate struct scans, the named
 	// parameter 'type_id' is an alias to cachegroup.type
diff --git a/traffic_ops/traffic_ops_golang/cachegroup/dspost.go b/traffic_ops/traffic_ops_golang/cachegroup/dspost.go
index 31fbe5b..47d7284 100644
--- a/traffic_ops/traffic_ops_golang/cachegroup/dspost.go
+++ b/traffic_ops/traffic_ops_golang/cachegroup/dspost.go
@@ -268,11 +268,6 @@ INSERT INTO profile_parameter (parameter, profile) (
 	return nil
 }
 
-func deleteConfigFile(tx *sql.Tx, configFile string) error {
-	_, err := tx.Exec(`DELETE FROM parameter WHERE name = 'location' AND config_file = $1`, configFile)
-	return err
-}
-
 func getDSTenants(tx *sql.Tx, dsIDs []int64) ([]int64, error) {
 	q := `
 SELECT COALESCE(tenant_id, 0) FROM deliveryservice
diff --git a/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go b/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
index 9157f9f..36e1053 100644
--- a/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
+++ b/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
@@ -25,7 +25,6 @@ import (
 	"errors"
 	"net/http"
 	"strconv"
-	"time"
 
 	"github.com/apache/trafficcontrol/lib/go-log"
 	"github.com/apache/trafficcontrol/lib/go-tc"
@@ -45,8 +44,6 @@ func Get(w http.ResponseWriter, r *http.Request) {
 	api.RespWriter(w, r, inf.Tx.Tx)(getCachesStats(inf.Tx.Tx))
 }
 
-const MonitorProxyParameter = "tm.traffic_mon_fwd_proxy"
-const MonitorRequestTimeout = time.Second * 10
 const MonitorOnlineStatus = "ONLINE"
 
 func getCachesStats(tx *sql.Tx) ([]CacheData, error) {
@@ -242,16 +239,6 @@ WHERE
 	return data, nil
 }
 
-func getMonitorForwardProxy(tx *sql.Tx) (string, error) {
-	forwardProxy, forwardProxyExists, err := getGlobalParam(tx, MonitorProxyParameter)
-	if err != nil {
-		return "", errors.New("getting global monitor proxy parameter: " + err.Error())
-	} else if !forwardProxyExists {
-		forwardProxy = ""
-	}
-	return forwardProxy, nil
-}
-
 // getCDNMonitors returns an FQDN, including port, of an online monitor for each CDN. If a CDN has no online monitors, that CDN will not have an entry in the map. If a CDN has multiple online monitors, an arbitrary one will be returned.
 func getCDNMonitorFQDNs(tx *sql.Tx) (map[tc.CDNName][]string, error) {
 	qry := `
@@ -291,20 +278,3 @@ WHERE
 	}
 	return monitors, nil
 }
-
-// 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")
-}
-
-// getGlobalParams 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
-}
diff --git a/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
index e4d3f0f..d272164 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
@@ -22,7 +22,6 @@ package crconfig
 import (
 	"context"
 	"encoding/json"
-	"math/rand"
 	"reflect"
 	"strconv"
 	"strings"
@@ -34,40 +33,6 @@ import (
 	"gopkg.in/DATA-DOG/go-sqlmock.v1"
 )
 
-func randStrArr() []string {
-	num := int(rand.Int63n(10))
-	s := []string{}
-	for i := 0; i < num; i++ {
-		s = append(s, *randStr())
-	}
-	return s
-}
-
-func randMatchlistArr() []tc.MatchList {
-	num := int(rand.Int63n(10))
-	arr := []tc.MatchList{}
-	for i := 0; i < num; i++ {
-		arr = append(arr, tc.MatchList{
-			Regex:     *randStr(),
-			MatchType: *randStr(),
-		})
-	}
-	return arr
-}
-
-func randMatchsetArr() []*tc.MatchSet {
-	num := int(rand.Int63n(10))
-	httpStr := "HTTP"
-	arr := []*tc.MatchSet{}
-	for i := 0; i < num; i++ {
-		arr = append(arr, &tc.MatchSet{
-			Protocol:  httpStr,
-			MatchList: randMatchlistArr(),
-		})
-	}
-	return arr
-}
-
 func randDS() tc.CRConfigDeliveryService {
 	// truePtr := true
 	falseStrPtr := "false"
diff --git a/traffic_ops/traffic_ops_golang/crstats/routing.go b/traffic_ops/traffic_ops_golang/crstats/routing.go
index a059036..6a18ebc 100644
--- a/traffic_ops/traffic_ops_golang/crstats/routing.go
+++ b/traffic_ops/traffic_ops_golang/crstats/routing.go
@@ -206,16 +206,6 @@ func getCRSStats(respond chan<- RouterResp, wg *sync.WaitGroup, routerFQDN, cdn
 	respond <- r
 }
 
-func getRouterForwardProxy(tx *sql.Tx) (string, error) {
-	forwardProxy, forwardProxyExists, err := dbhelpers.GetGlobalParam(tx, RouterProxyParameter)
-	if err != nil {
-		return "", errors.New("getting global router proxy parameter: " + err.Error())
-	} else if !forwardProxyExists {
-		forwardProxy = ""
-	}
-	return forwardProxy, nil
-}
-
 // getCDNRouterFQDNs returns an FQDN, including port, of an online router for each CDN, for each router. If a CDN has no online routers, that CDN will not have an entry in the map. The port returned is the API port.
 func getCDNRouterFQDNs(tx *sql.Tx, requiredCDN *string) (map[tc.CDNName][]string, error) {
 	rows, err := tx.Query(`
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
index 4be1d89..5b0dd00 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
@@ -323,12 +323,6 @@ status
 	return query
 }
 
-func deleteRequestQuery() string {
-	query := `DELETE FROM deliveryservice_request
-WHERE id=:id`
-	return query
-}
-
 ////////////////////////////////////////////////////////////////
 // Assignment change
 
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go b/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
index 348a0c7..ab34290 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
@@ -269,12 +269,6 @@ AND s.server = ANY(:serverids)
 	return selectStmt, nil
 }
 
-func deleteQuery() string {
-	query := `DELETE FROM deliveryservice_server
-	WHERE deliveryservice=:deliveryservice and server=:server`
-	return query
-}
-
 type DSServerIds struct {
 	DsId    *int  `json:"dsId" db:"deliveryservice"`
 	Servers []int `json:"servers"`
@@ -283,11 +277,6 @@ type DSServerIds struct {
 
 type TODSServerIds DSServerIds
 
-func createServersForDsIdRef() *TODSServerIds {
-	var dsserversRef = TODSServerIds(DSServerIds{})
-	return &dsserversRef
-}
-
 func GetReplaceHandler(w http.ResponseWriter, r *http.Request) {
 	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, []string{"limit", "page"})
 	if userErr != nil || sysErr != nil {
@@ -376,11 +365,6 @@ func GetReplaceHandler(w http.ResponseWriter, r *http.Request) {
 
 type TODeliveryServiceServers tc.DeliveryServiceServers
 
-func createServersRef() *TODeliveryServiceServers {
-	serversRef := TODeliveryServiceServers(tc.DeliveryServiceServers{})
-	return &serversRef
-}
-
 // GetCreateHandler assigns an existing Server to and existing Deliveryservice in response to api/1.1/deliveryservices/{xml_id}/servers
 func GetCreateHandler(w http.ResponseWriter, r *http.Request) {
 	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"xml_id"}, nil)
@@ -494,11 +478,6 @@ VALUES (:id, :server )`
 	return query
 }
 
-func selectServerIds() string {
-	query := `SELECT id FROM server WHERE host_name in (?)`
-	return query
-}
-
 // GetReadAssigned retrieves lists of servers  based in the filter identified in the request: api/1.1/deliveryservices/{id}/servers|unassigned_servers|eligible
 func GetReadAssigned(w http.ResponseWriter, r *http.Request) {
 	getRead(w, r, false)
@@ -676,17 +655,6 @@ func (dss *TODSSDeliveryService) Read() ([]interface{}, error, error, int) {
 	return returnable, nil, nil, http.StatusOK
 }
 
-func updateQuery() string {
-	query := `UPDATE
-	profile_parameter SET
-	profile=:profile_id,
-	parameter=:parameter_id
-	WHERE profile=:profile_id AND
-      parameter = :parameter_id
-      RETURNING last_updated`
-	return query
-}
-
 type DSInfo struct {
 	ID                   int
 	Name                 string
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers_test.go b/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers_test.go
deleted file mode 100644
index c87bd0a..0000000
--- a/traffic_ops/traffic_ops_golang/deliveryservice/servers/servers_test.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package servers
-
-/*
- * 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.
- */
diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
index 56d11de..a85006f 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -169,17 +169,6 @@ JOIN parameter param ON param.id = pp.parameter`
 	return query
 }
 
-func updateQuery() string {
-	query := `UPDATE
-profile_parameter SET
-profile=:profile_id,
-parameter=:parameter_id
-WHERE profile=:profile_id AND
-      parameter = :parameter_id
-      RETURNING last_updated`
-	return query
-}
-
 func deleteQuery() string {
 	query := `DELETE FROM profile_parameter
 	WHERE profile=:profile_id and parameter=:parameter_id`
diff --git a/traffic_ops/traffic_ops_golang/user/deliveryservices.go b/traffic_ops/traffic_ops_golang/user/deliveryservices.go
index 2970f5a..8a6e483 100644
--- a/traffic_ops/traffic_ops_golang/user/deliveryservices.go
+++ b/traffic_ops/traffic_ops_golang/user/deliveryservices.go
@@ -236,14 +236,3 @@ WHERE dsu.tm_user_id = $1
 	}
 	return dses, nil
 }
-
-func getUserTenantIDByID(tx *sql.Tx, id int) (*int, bool, error) {
-	tenantID := (*int)(nil)
-	if err := tx.QueryRow(`SELECT tenant_id FROM tm_user WHERE id = $1`, id).Scan(&tenantID); err != nil {
-		if err == sql.ErrNoRows {
-			return nil, false, nil
-		}
-		return nil, false, errors.New("querying user: " + err.Error())
-	}
-	return tenantID, true, nil
-}
diff --git a/traffic_ops/traffic_ops_golang/user/user.go b/traffic_ops/traffic_ops_golang/user/user.go
index 06f5e2a..198c1a2 100644
--- a/traffic_ops/traffic_ops_golang/user/user.go
+++ b/traffic_ops/traffic_ops_golang/user/user.go
@@ -171,17 +171,6 @@ func (user *TOUser) Create() (error, error, int) {
 	return nil, nil, http.StatusOK
 }
 
-// returning true indicates the data related to the given tenantID should be visible
-// this is just a linear search;`tenantIDs` is presumed to be unsorted
-func checkTenancy(tenantID *int, tenantIDs []int) bool {
-	for _, id := range tenantIDs {
-		if id == *tenantID {
-			return true
-		}
-	}
-	return false
-}
-
 // This is not using GenericRead because of this tenancy check. Maybe we can add tenancy functionality to the generic case?
 func (this *TOUser) Read() ([]interface{}, error, error, int) {