rob05c closed pull request #2372: Remove dead delivery service Handler code
URL: https://github.com/apache/incubator-trafficcontrol/pull/2372
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/handlers.go 
b/traffic_ops/traffic_ops_golang/deliveryservice/handlers.go
deleted file mode 100644
index 0344fbb15..000000000
--- a/traffic_ops/traffic_ops_golang/deliveryservice/handlers.go
+++ /dev/null
@@ -1,165 +0,0 @@
-package deliveryservice
-
-/*
- * 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.
- */
-
-import (
-       "encoding/json"
-       "fmt"
-       "net/http"
-
-       "github.com/apache/incubator-trafficcontrol/lib/go-log"
-       "github.com/apache/incubator-trafficcontrol/lib/go-tc"
-       
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
-       
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
-       "github.com/jmoiron/sqlx"
-)
-
-const DeliveryServicsPrivLevel = 10
-
-func Handler(db *sqlx.DB) http.HandlerFunc {
-       return func(w http.ResponseWriter, r *http.Request) {
-               handleErrs := tc.GetHandleErrorsFunc(w, r)
-
-               // Load the the query and path params with path params 
overriding query params
-               params, err := api.GetCombinedParams(r)
-               if err != nil {
-                       log.Errorf("unable to get parameters from request: %s", 
err)
-                       handleErrs(http.StatusInternalServerError, err)
-               }
-
-               resp, errs, errType := getDeliveryServicesResponse(params, db)
-               tc.HandleErrorsWithType(errs, errType, handleErrs)
-
-               respBts, err := json.Marshal(resp)
-               if err != nil {
-                       handleErrs(http.StatusInternalServerError, err)
-                       return
-               }
-
-               w.Header().Set("Content-Type", "application/json")
-               fmt.Fprintf(w, "%s", respBts)
-       }
-}
-
-func getDeliveryServicesResponse(parameters map[string]string, db *sqlx.DB) 
(*tc.DeliveryServicesResponse, []error, tc.ApiErrorType) {
-       dses, errs, errType := getDeliveryServices(parameters, db)
-       if len(errs) > 0 {
-               return nil, errs, errType
-       }
-
-       resp := tc.DeliveryServicesResponse{
-               Response: dses,
-       }
-       return &resp, nil, tc.NoError
-}
-
-func getDeliveryServices(parameters map[string]string, db *sqlx.DB) 
([]tc.DeliveryService, []error, tc.ApiErrorType) {
-       var rows *sqlx.Rows
-       var err error
-
-       // Query Parameters to Database Query column mappings
-       // see the fields mapped in the SQL query
-       queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-               "xmlId": dbhelpers.WhereColumnInfo{"xml_id", nil},
-       }
-
-       where, orderBy, queryValues, errs := 
dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
-       if len(errs) > 0 {
-               return nil, errs, tc.DataConflictError
-       }
-       query := selectDSesQuery() + where + orderBy
-
-       rows, err = db.NamedQuery(query, queryValues)
-       fmt.Printf("rows ---> %v\n", rows)
-       fmt.Printf("err ---> %v\n", err)
-       if err != nil {
-               return nil, []error{err}, tc.SystemError
-       }
-       defer rows.Close()
-
-       dses := []tc.DeliveryService{}
-       for rows.Next() {
-               var s tc.DeliveryService
-               if err = rows.StructScan(&s); err != nil {
-                       return nil, []error{fmt.Errorf("getting Delivery 
Services: %v", err)}, tc.SystemError
-               }
-               dses = append(dses, s)
-       }
-       return dses, nil, tc.NoError
-}
-
-func selectDSesQuery() string {
-       query := `SELECT
- active,
- anonymous_blocking_enabled,
- ccr_dns_ttl,
- cdn_id,
- cacheurl,
- check_path,
- dns_bypass_cname,
- dns_bypass_ip,
- dns_bypass_ip6,
- dns_bypass_ttl,
- dscp,
- display_name,
- edge_header_rewrite,
- geo_limit,
- geo_limit_countries,
- geolimit_redirect_url,
- geo_provider,
- global_max_mbps,
- global_max_tps,
- http_bypass_fqdn,
- id,
- ipv6_routing_enabled,
- info_url,
- initial_dispersion,
- last_updated,
- logs_enabled,
- long_desc,
- long_desc_1,
- long_desc_2,
- max_dns_answers,
- mid_header_rewrite,
- miss_lat,
- miss_long,
- multi_site_origin,
- multi_site_origin_algorithm,
- org_server_fqdn,
- origin_shield,
- profile,
- protocol,
- qstring_ignore,
- range_request_handling,
- regex_remap,
- regional_geo_blocking,
- remap_text,
- routing_name,
- ssl_key_version,
- signing_algorithm,
- tr_request_headers,
- tr_response_headers,
- tenant_id,
- type,
- xml_id
-
-FROM deliveryservice d`
-       return query
-}
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/handlers_test.go 
b/traffic_ops/traffic_ops_golang/deliveryservice/handlers_test.go
deleted file mode 100644
index c9ea6a72f..000000000
--- a/traffic_ops/traffic_ops_golang/deliveryservice/handlers_test.go
+++ /dev/null
@@ -1,142 +0,0 @@
-package deliveryservice
-
-/*
- * 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.
- */
-
-import (
-       "encoding/json"
-       "fmt"
-       "sort"
-       "strings"
-       "testing"
-
-       
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/utils"
-)
-
-// TestValidateErrors ...
-func TestValidateErrors(t *testing.T) {
-
-       ds := &TODeliveryServiceV13{}
-       if err := json.Unmarshal([]byte(errorTestCase()), &ds); err != nil {
-               fmt.Printf("err ---> %v\n", err)
-               return
-       }
-
-       errors := ds.Validate(nil)
-       errorStrs := utils.ErrorsToStrings(errors)
-       sort.Strings(errorStrs)
-       errorsFmt, _ := json.MarshalIndent(errorStrs, "", "  ")
-
-       expected := []string{
-               "'active' is required",
-               "'anonymousBlockingEnabled' is required",
-               "'cdnId' cannot be blank",
-               "'displayName' the length must be between 1 and 48",
-               "'dscp' is required",
-               "'geoLimit' is required",
-               "'geoProvider' is required",
-               "'infoUrl' must be a valid URL",
-               "'initialDispersion' must be greater than zero",
-               "'logsEnabled' is required",
-               "'orgServerFqdn' must be a valid URL",
-               "'regionalGeoBlocking' is required",
-               "'routingName' cannot contain periods",
-               "'typeId' cannot be blank",
-               "'xmlId' cannot contain spaces",
-       }
-       sort.Strings(expected)
-       expectedFmt, _ := json.MarshalIndent(expected, "", "  ")
-
-       for _, e := range errorStrs {
-               if !findNeedle(e, expected) {
-                       t.Errorf("\nExpected %s \n Actual %v", 
string(expectedFmt), string(errorsFmt))
-                       break
-               }
-       }
-
-}
-
-func errorTestCase() string {
-
-       routingName := strings.Repeat("X", 1) + "." + strings.Repeat("X", 48)
-
-       // Test the xmlId length
-       xmlId := strings.Repeat("X", 1) + " " + strings.Repeat("X", 48)
-
-       displayName := strings.Repeat("X", 49)
-
-       errorTestCase := `
-{
-   "ccrDnsTtl": 1,
-   "checkPath": "/crossdomain.xml",
-   "displayName": "` + displayName + `",
-   "dnsBypassCname": "cname",
-   "dnsBypassIp": "127.0.0.1",
-   "dnsBypassIp6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
-   "dnsBypassTTL": 10,
-   "dscp": null,
-   "edgeHeaderRewrite": "cond %{REMAP_PSEUDO_HOOK} __RETURN__ set-config 
proxy.config.http.transaction_active_timeout_in 10800 [L]",
-   "geoLimitCountries": "Can,Mex",
-   "geoRedirectURL": "http://localhost/redirect";,
-   "globalMaxMBPS": 0,
-   "globalMaxTPS": 0,
-   "httpBypassFqdn": "http://bypass";,
-   "id": 1,
-   "initialDispersion": 0,
-   "infoUrl": "htt://info.url",
-   "lastUpdated": "2017-01-05 15:04:05+00",
-   "longDesc": "longdesc",
-   "longDesc1": "longdesc1",
-   "longDesc2": "longdesc2",
-   "maxDnsAnswers": 5,
-   "midHeaderRewrite": "cond %{REMAP_PSEUDO_HOOK} __RETURN__ set-config 
proxy.config.http.cache.ignore_authentication 1 __RETURN__ set-config 
proxy.config.http.auth_server_session_private 0 __RETURN__ set-config 
proxy.config.http.transaction_no_activity_timeout_out 10 __RETURN__ set-config 
proxy.config.http.transaction_active_timeout_out 10  [L] __RETURN__",
-   "missLat": -2.0,
-   "missLong": -1.0,
-   "multiSiteOrigin": false,
-   "multiSiteOriginAlgorithm": 1,
-   "orgServerFqdn": "htt://localhost",
-   "profile": 1,
-   "protocol": 2,
-   "qstringIgnore": 1,
-   "rangeRequestHandling": 1,
-   "regexRemap": "^/([^\/]+)/(.*) http://$1.foo.com/$2";,
-   "regionalGeoBlocking": false,
-   "remapText": "@action=allow @src_ip=127.0.0.1-127.0.0.1",
-   "routingName": "` + routingName + `",
-   "signingAlgorithm": "url_sig",
-   "sslKeyVersion": 1,
-   "tenantId": 1,
-   "trRequestHeaders": "xyz",
-   "trResponseHeaders": "Access-Control-Allow-Origin: *",
-   "xmlId": "` + xmlId + `"
- }
-`
-       return errorTestCase
-}
-
-func findNeedle(needle string, haystack []string) bool {
-       found := false
-       for _, s := range haystack {
-               if s == needle {
-                       found = true
-                       break
-               }
-       }
-       return found
-}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to