You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/04/06 20:45:50 UTC

[incubator-trafficcontrol] branch master updated (74b4c77 -> eab39fb)

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

mitchell852 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git.


    from 74b4c77  makes api calls for ds requests using query params instead of route params
     new 413e109  work in progress until CRUD Interfaces support compound keys
     new 03f434f  hooked in the profileparameters routes with a successful Read
     new 8087858  fixed the unit test for profile_parameters
     new 54c04d0  updated to use the v13 structs
     new fa479f8  created the v13 profileparameters
     new 95f7a1e  removed the PUT for profileparameters because it isnt relevant
     new 3fdc473  added the API tests and TO Client methods for profileparameters
     new b8b09fc  updated for swagger documentation
     new 46d7087  updated the CHANGELOG.md
     new e586577  updated formatting
     new 8601b0f  updated for cachegroups
     new e3db333  removed unused struct
     new de8f4ec  updated for the v13 struct
     new 7f74064  updated the test case for the v13 struct
     new eab39fb  updated the routes per the API guidelines

The 15 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGELOG.md                                       |  56 ++--
 lib/go-tc/v13/profile_parameters.go                |  53 ++++
 .../v13/{profile.go => profile_parameter.go}       |  74 ++---
 .../testing/api/v13/profile_parameters_test.go     | 132 +++++++++
 traffic_ops/testing/api/v13/tc-fixtures.json       |  10 +
 traffic_ops/testing/api/v13/traffic_control.go     |  33 +--
 .../parameter/parameters_test.go                   |   8 +-
 .../profileparameter/profile_parameters.go         | 300 +++++++++++++++++++++
 .../profile_parameters_test.go}                    |  74 ++---
 .../traffic_ops_golang/region/regions_test.go      |   2 +-
 traffic_ops/traffic_ops_golang/routes.go           |   7 +
 .../traffic_ops_golang/swaggerdocs/v13/docs.go     |   2 +-
 .../swaggerdocs/v13/profileparameters.go           | 119 ++++++++
 13 files changed, 730 insertions(+), 140 deletions(-)
 create mode 100644 lib/go-tc/v13/profile_parameters.go
 copy traffic_ops/client/v13/{profile.go => profile_parameter.go} (52%)
 create mode 100644 traffic_ops/testing/api/v13/profile_parameters_test.go
 create mode 100644 traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
 copy traffic_ops/traffic_ops_golang/{status/statuses_test.go => profileparameter/profile_parameters_test.go} (58%)
 create mode 100644 traffic_ops/traffic_ops_golang/swaggerdocs/v13/profileparameters.go

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 11/15: updated for cachegroups

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8601b0f23f092c016d722d042e413b82771ab811
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 10:00:11 2018 -0600

    updated for cachegroups
---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 247d10f..54f6450 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Traffic Ops Golang Proxy Endpoints
   - /api/1.3/about `(GET)`
   - /api/1.3/asns `(GET,POST,PUT,DELETE)`
+  - /api/1.3/cachegroups `(GET,POST,PUT,DELETE)`
   - /api/1.3/cdns `(GET,POST,PUT,DELETE)`
   - /api/1.3/cdns/capacity `(GET)`
   - /api/1.3/cdns/configs `(GET)`

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 03/15: fixed the unit test for profile_parameters

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 80878582dc2ef3913ced663e61a546c32b35b63c
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Apr 2 10:44:41 2018 -0600

    fixed the unit test for profile_parameters
---
 .../profileparameter/profile_parameters_test.go            | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
index ced1a11..a066c2e 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
@@ -36,19 +36,19 @@ func getTestProfileParameters() []tc.ProfileParameterNullable {
 	pps := []tc.ProfileParameterNullable{}
 	lastUpdated := tc.TimeNoMod{}
 	lastUpdated.Scan(time.Now())
-	profile := 1
-	parameter := 1
+	profileId := 1
+	parameterId := 1
 
 	pp := tc.ProfileParameterNullable{
 		LastUpdated: &lastUpdated,
-		Profile:     &profile,
-		Parameter:   &parameter,
+		ProfileId:   &profileId,
+		ParameterId: &parameterId,
 	}
 	pps = append(pps, pp)
 
 	pp2 := pp
-	pp2.Profile = &profile
-	pp2.Parameter = &parameter
+	pp2.ProfileId = &profileId
+	pp2.ParameterId = &parameterId
 	pps = append(pps, pp2)
 
 	return pps
@@ -72,7 +72,9 @@ func TestGetProfileParameters(t *testing.T) {
 		rows = rows.AddRow(
 			ts.LastUpdated,
 			ts.Profile,
+			ts.ProfileId,
 			ts.Parameter,
+			ts.ParameterId,
 		)
 	}
 	mock.ExpectQuery("SELECT").WillReturnRows(rows)

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 10/15: updated formatting

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e586577b720bd6aa9a55d0eb07f3d422324661c5
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 09:59:10 2018 -0600

    updated formatting
---
 CHANGELOG.md | 54 +++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index eedbc36..247d10f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,33 +8,33 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Per-DeliveryService Routing Names: you can now choose a Delivery Service's Routing Name (rather than a hardcoded "tr" or "edge" name). This might require a few pre-upgrade steps detailed [here](http://traffic-control-cdn.readthedocs.io/en/latest/admin/traffic_ops/migration_from_20_to_22.html#per-deliveryservice-routing-names)
 - [Delivery Service Requests](http://traffic-control-cdn.readthedocs.io/en/latest/admin/quick_howto/ds_requests.html#ds-requests): When enabled, delivery service requests are created when ALL users attempt to create, update or delete a delivery service. This allows users with higher level permissions to review delivery service changes for completeness and accuracy before deploying the changes.
 - Traffic Ops Golang Proxy Endpoints
-  - /api/1.3/about
-  - /api/1.3/asns (GET,POST,PUT,DELETE)
-  - /api/1.3/cdns (GET,POST,PUT,DELETE)
-  - /api/1.3/cdns/capacity (GET)
-  - /api/1.3/cdns/configs (GET)
-  - /api/1.3/cdns/dnsseckeys (GET)
-  - /api/1.3/cdns/domain (GET)
-  - /api/1.3/cdns/monitoring (GET)
-  - /api/1.3/cdns/health (GET)
-  - /api/1.3/cdns/routing (GET)
-  - /api/1.3/deliveryservice_requests (GET,POST,PUT,DELETE)
-  - /api/1.3/divisions (GET,POST,PUT,DELETE) 
-  - /api/1.3/hwinfos (GET)
-  - /api/1.3/parameters (GET,POST,PUT,DELETE)
-  - /api/1.3/profileparameters (GET,POST,PUT,DELETE)
-  - /api/1.3/phys_locations (GET,POST,PUT,DELETE)
-  - /api/1.3/ping (GET)
-  - /api/1.3/profiles (GET,POST,PUT,DELETE)
-  - /api/1.3/regions (GET,POST,PUT,DELETE)
-  - /api/1.3/servers (GET,POST,PUT,DELETE)
-  - /api/1.3/servers/checks (GET)
-  - /api/1.3/servers/details (GET)
-  - /api/1.3/servers/status (GET)
-  - /api/1.3/servers/totals (GET)
-  - /api/1.3/statuses (GET,POST,PUT,DELETE)
-  - /api/1.3/system/info (GET)
-  - /api/1.3/types (GET,POST,PUT,DELETE)
+  - /api/1.3/about `(GET)`
+  - /api/1.3/asns `(GET,POST,PUT,DELETE)`
+  - /api/1.3/cdns `(GET,POST,PUT,DELETE)`
+  - /api/1.3/cdns/capacity `(GET)`
+  - /api/1.3/cdns/configs `(GET)`
+  - /api/1.3/cdns/dnsseckeys `(GET)`
+  - /api/1.3/cdns/domain `(GET)`
+  - /api/1.3/cdns/monitoring `(GET)`
+  - /api/1.3/cdns/health `(GET)`
+  - /api/1.3/cdns/routing `(GET)`
+  - /api/1.3/deliveryservice_requests `(GET,POST,PUT,DELETE)`
+  - /api/1.3/divisions `(GET,POST,PUT,DELETE)`
+  - /api/1.3/hwinfos `(GET)`
+  - /api/1.3/parameters `(GET,POST,PUT,DELETE)`
+  - /api/1.3/profileparameters `(GET,POST,PUT,DELETE)`
+  - /api/1.3/phys_locations `(GET,POST,PUT,DELETE)`
+  - /api/1.3/ping `(GET)`
+  - /api/1.3/profiles `(GET,POST,PUT,DELETE)`
+  - /api/1.3/regions `(GET,POST,PUT,DELETE)`
+  - /api/1.3/servers `(GET,POST,PUT,DELETE)`
+  - /api/1.3/servers/checks `(GET)`
+  - /api/1.3/servers/details `(GET)`
+  - /api/1.3/servers/status `(GET)`
+  - /api/1.3/servers/totals `(GET)`
+  - /api/1.3/statuses `(GET,POST,PUT,DELETE)`
+  - /api/1.3/system/info `(GET)`
+  - /api/1.3/types `(GET,POST,PUT,DELETE)`
 - Fair Queuing Pacing: Using the FQ Pacing Rate parameter in Delivery Services allows operators to limit the rate of individual sessions to the edge cache. This feature requires a Trafficserver RPM containing the fq_pacing experimental plugin AND setting 'fq' as the default Linux qdisc in sysctl. 
 
 ### Changed

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 08/15: updated for swagger documentation

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b8b09fc348e5019cd7c47b7bc49ad3bcc792ab16
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Apr 3 14:38:08 2018 -0600

    updated for swagger documentation
---
 lib/go-tc/v13/profile_parameters.go                |   8 ++
 .../traffic_ops_golang/swaggerdocs/v13/docs.go     |   2 +-
 .../swaggerdocs/v13/profileparameters.go           | 119 +++++++++++++++++++++
 3 files changed, 128 insertions(+), 1 deletion(-)

diff --git a/lib/go-tc/v13/profile_parameters.go b/lib/go-tc/v13/profile_parameters.go
index 954d6f0..67afa6c 100644
--- a/lib/go-tc/v13/profile_parameters.go
+++ b/lib/go-tc/v13/profile_parameters.go
@@ -26,6 +26,14 @@ type ProfileParametersResponse struct {
 	Response []ProfileParameter `json:"response"`
 }
 
+// A Single ProfileParameter Response for Create to depict what changed
+// swagger:response ProfileParameterResponse
+// in: body
+type ProfileParameterResponse struct {
+	// in: body
+	Response ProfileParameter `json:"response"`
+}
+
 // ProfileParameter ...
 type ProfileParameter struct {
 	LastUpdated tc.TimeNoMod `json:"lastUpdated"`
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docs.go b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docs.go
index ee55e9c..730a8c7 100644
--- a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docs.go
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/docs.go
@@ -1,5 +1,5 @@
 /*
- Package docs Traffic Ops API v1.3
+ Package docs Traffic Ops API
 
  The following REST APIs are used by the Traffic Portal UI along with several Traffic Control backend component and services.
 
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/profileparameters.go b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/profileparameters.go
new file mode 100644
index 0000000..04a5408
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/profileparameters.go
@@ -0,0 +1,119 @@
+package v13
+
+import v13 "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
+
+/*
+ * 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.
+ */
+
+// ProfileParameters -  ProfileParametersResponse to get the "response" top level key
+// swagger:response ProfileParameters
+// in: body
+type ProfileParameters struct {
+	// ProfileParameter Response Body
+	// in: body
+	ProfileParametersResponse v13.ProfileParametersResponse `json:"response"`
+}
+
+// ProfileParameter -  ProfileParameterResponse to get the "response" top level key
+// swagger:response ProfileParameter
+// in: body
+type ProfileParameter struct {
+	// ProfileParameter Response Body
+	// in: body
+	ProfileParameterResponse v13.ProfileParameterResponse
+}
+
+// ProfileParameterQueryParams
+//
+// swagger:parameters GetProfileParameters
+type ProfileParameterQueryParams struct {
+
+	// ProfileParametersQueryParams
+
+	// Unique identifier for the ProfileParameter
+	//
+	ProfileID string `json:"profileId"`
+
+	// Unique identifier for the ProfileParameter
+	//
+	ParameterID string `json:"parameterId"`
+
+	// The field in the response to sort the response by
+	//
+	Orderby string `json:"orderby"`
+}
+
+// swagger:parameters PostProfileParameter
+type ProfileParameterPostParam struct {
+	// ProfileParameter Request Body
+	//
+	// in: body
+	// required: true
+	ProfileParameter v13.ProfileParameter
+}
+
+// PostProfileParameter swagger:route POST /profileparameters ProfileParameter PostProfileParameter
+//
+// Create a ProfileParameter
+//
+// A ProfileParameter is a join of the Profile and Parameters
+//
+// Responses:
+//          200: Alerts
+func PostProfileParameter(entity ProfileParameterPostParam) (ProfileParameter, Alerts) {
+	return ProfileParameter{}, Alerts{}
+}
+
+// GetProfileParameters swagger:route GET /profileparameters ProfileParameter GetProfileParameters
+//
+// Retrieve a list of ProfileParameters by narrowing down with query parameters
+//
+// List of ProfileParameters
+//
+// Responses:
+//          200: ProfileParameters
+//          400: Alerts
+func GetProfileParameters() (ProfileParameters, Alerts) {
+	return ProfileParameters{}, Alerts{}
+}
+
+// GetProfileParameterById swagger:route GET /profileparameters?id={id} ProfileParameter GetProfileParameterById
+//
+// Retrieve a specific ProfileParameter by Id
+//
+// Retrieve a single division
+//
+// Responses:
+//          200: ProfileParameters
+//          400: Alerts
+func GetProfileParameterById() (ProfileParameters, Alerts) {
+	return ProfileParameters{}, Alerts{}
+}
+
+// DeleteProfileParameter swagger:route DELETE /profileparameters/{id} ProfileParameter DeleteProfileParameter
+//
+// Delete a ProfileParameter by Id
+//
+// Delete a single ProfileParameter
+//
+// Responses:
+//          200: Alerts
+func DeleteProfileParameter(entityId int) Alerts {
+	return Alerts{}
+}

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 07/15: added the API tests and TO Client methods for profileparameters

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3fdc4732dce4320383b080954ba5530bfed518e9
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Apr 3 12:32:33 2018 -0600

    added the API tests and TO Client methods for profileparameters
---
 lib/go-tc/profile_parameters.go                    |  8 +--
 lib/go-tc/v13/profile_parameters.go                |  8 +--
 traffic_ops/client/v13/profile_parameter.go        | 60 ++++--------------
 .../testing/api/v13/profile_parameters_test.go     | 74 +++++++++++-----------
 traffic_ops/testing/api/v13/tc-fixtures.json       | 10 +++
 traffic_ops/testing/api/v13/traffic_control.go     | 34 +++++-----
 6 files changed, 84 insertions(+), 110 deletions(-)

diff --git a/lib/go-tc/profile_parameters.go b/lib/go-tc/profile_parameters.go
index a2d7dee..c31eb9f 100644
--- a/lib/go-tc/profile_parameters.go
+++ b/lib/go-tc/profile_parameters.go
@@ -28,16 +28,16 @@ type ProfileParametersResponse struct {
 type ProfileParameter struct {
 	LastUpdated TimeNoMod `json:"lastUpdated"`
 	Profile     string    `json:"profile"`
-	ProfileId   int       `json:"profileId"`
+	ProfileID   int       `json:"profileId"`
 	Parameter   string    `json:"parameter"`
-	ParameterId int       `json:"profileId"`
+	ParameterID int       `json:"profileId"`
 }
 
 // ProfileParameterNullable ...
 type ProfileParameterNullable struct {
 	LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
 	Profile     *string    `json:"profile" db:"profile"`
-	ProfileId   *int       `json:"profileId" db:"profile_id"`
+	ProfileID   *int       `json:"profileId" db:"profile_id"`
 	Parameter   *string    `json:"parameter" db:"parameter"`
-	ParameterId *int       `json:"parameterId" db:"parameter_id"`
+	ParameterID *int       `json:"parameterId" db:"parameter_id"`
 }
diff --git a/lib/go-tc/v13/profile_parameters.go b/lib/go-tc/v13/profile_parameters.go
index be3d1a2..954d6f0 100644
--- a/lib/go-tc/v13/profile_parameters.go
+++ b/lib/go-tc/v13/profile_parameters.go
@@ -30,16 +30,16 @@ type ProfileParametersResponse struct {
 type ProfileParameter struct {
 	LastUpdated tc.TimeNoMod `json:"lastUpdated"`
 	Profile     string       `json:"profile"`
-	ProfileId   int          `json:"profileId"`
+	ProfileID   int          `json:"profileId"`
 	Parameter   string       `json:"parameter"`
-	ParameterId int          `json:"profileId"`
+	ParameterID int          `json:"parameterId"`
 }
 
 // ProfileParameterNullable ...
 type ProfileParameterNullable struct {
 	LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
 	Profile     *string       `json:"profile" db:"profile"`
-	ProfileId   *int          `json:"profileId" db:"profile_id"`
+	ProfileID   *int          `json:"profileId" db:"profile_id"`
 	Parameter   *string       `json:"parameter" db:"parameter"`
-	ParameterId *int          `json:"parameterId" db:"parameter_id"`
+	ParameterID *int          `json:"parameterId" db:"parameter_id"`
 }
diff --git a/traffic_ops/client/v13/profile_parameter.go b/traffic_ops/client/v13/profile_parameter.go
index aaa3fac..f4af45e 100644
--- a/traffic_ops/client/v13/profile_parameter.go
+++ b/traffic_ops/client/v13/profile_parameter.go
@@ -20,17 +20,19 @@ import (
 	"fmt"
 	"net"
 	"net/http"
-	"strconv"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
 )
 
 const (
-	API_v13_Profile_Parameters = "/api/1.3/profile_parameters"
+	API_v13_Profile_Parameters = "/api/1.3/profileparameters"
+	ProfileIdQueryParam        = "profileId"
+	ParameterIdQueryParam      = "parameterId"
 )
 
 // Create a ProfileParameter
-func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, ReqInf, error) {
+func (to *Session) CreateProfileParameter(pp v13.ProfileParameter) (tc.Alerts, ReqInf, error) {
 
 	var remoteAddr net.Addr
 	reqBody, err := json.Marshal(pp)
@@ -48,28 +50,8 @@ func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, Re
 	return alerts, reqInf, nil
 }
 
-// Update a Profile Parameter by Profile
-func (to *Session) UpdateParameterByProfile(id int, pp tc.ProfileParameter) (tc.Alerts, ReqInf, error) {
-
-	var remoteAddr net.Addr
-	reqBody, err := json.Marshal(pp)
-	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
-	if err != nil {
-		return tc.Alerts{}, reqInf, err
-	}
-	URI := fmt.Sprintf("%s/%d", API_v13_Profile_Parameters, id)
-	resp, remoteAddr, err := to.request(http.MethodPut, URI, reqBody)
-	if err != nil {
-		return tc.Alerts{}, reqInf, err
-	}
-	defer resp.Body.Close()
-	var alerts tc.Alerts
-	err = json.NewDecoder(resp.Body).Decode(&alerts)
-	return alerts, reqInf, nil
-}
-
 // Returns a list of Profile Parameters
-func (to *Session) GetProfileParameters() ([]tc.ProfileParameter, ReqInf, error) {
+func (to *Session) GetProfileParameters() ([]v13.ProfileParameter, ReqInf, error) {
 	resp, remoteAddr, err := to.request(http.MethodGet, API_v13_Profile_Parameters, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
 	if err != nil {
@@ -77,32 +59,14 @@ func (to *Session) GetProfileParameters() ([]tc.ProfileParameter, ReqInf, error)
 	}
 	defer resp.Body.Close()
 
-	var data tc.ProfileParametersResponse
+	var data v13.ProfileParametersResponse
 	err = json.NewDecoder(resp.Body).Decode(&data)
 	return data.Response, reqInf, nil
 }
 
-// GET a Profile Parameter by the Profile
-func (to *Session) GetProfileParameterByIDs(profile int, parameter int) ([]tc.ProfileParameter, ReqInf, error) {
-	URI := fmt.Sprintf("%s?profile=%d&parameter=%d", API_v13_Profile_Parameters, profile)
-	resp, remoteAddr, err := to.request(http.MethodGet, URI, nil)
-	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
-	if err != nil {
-		return nil, reqInf, err
-	}
-	defer resp.Body.Close()
-
-	var data tc.ProfileParametersResponse
-	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
-		return nil, reqInf, err
-	}
-
-	return data.Response, reqInf, nil
-}
-
 // GET a Profile Parameter by the Parameter
-func (to *Session) GetProfileParameterByParameter(parameter int) ([]tc.ProfileParameter, ReqInf, error) {
-	URI := API_v13_Profile_Parameters + "?parameter=" + strconv.Itoa(parameter)
+func (to *Session) GetProfileParameterByQueryParams(queryParams string) ([]v13.ProfileParameter, ReqInf, error) {
+	URI := API_v13_Profile_Parameters + queryParams
 	resp, remoteAddr, err := to.request(http.MethodGet, URI, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
 	if err != nil {
@@ -110,7 +74,7 @@ func (to *Session) GetProfileParameterByParameter(parameter int) ([]tc.ProfilePa
 	}
 	defer resp.Body.Close()
 
-	var data tc.ProfileParametersResponse
+	var data v13.ProfileParametersResponse
 	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
 		return nil, reqInf, err
 	}
@@ -119,8 +83,8 @@ func (to *Session) GetProfileParameterByParameter(parameter int) ([]tc.ProfilePa
 }
 
 // DELETE a Parameter by Parameter
-func (to *Session) DeleteParameterByParameter(parameter int) (tc.Alerts, ReqInf, error) {
-	URI := fmt.Sprintf("%s/%d", API_v13_Profile_Parameters, parameter)
+func (to *Session) DeleteParameterByProfileParameter(profile int, parameter int) (tc.Alerts, ReqInf, error) {
+	URI := fmt.Sprintf("%s/profile/%d/parameter/%d", API_v13_Profile_Parameters, profile, parameter)
 	resp, remoteAddr, err := to.request(http.MethodDelete, URI, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
 	if err != nil {
diff --git a/traffic_ops/testing/api/v13/profile_parameters_test.go b/traffic_ops/testing/api/v13/profile_parameters_test.go
index e4b5f4f..00b8035 100644
--- a/traffic_ops/testing/api/v13/profile_parameters_test.go
+++ b/traffic_ops/testing/api/v13/profile_parameters_test.go
@@ -16,59 +16,57 @@
 package v13
 
 import (
+	"fmt"
 	"sync"
 	"testing"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-log"
-	tc "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
 )
 
+const queryParamFormat = "?profileId=%d&parameterId=%d"
+
 func TestProfileParameters(t *testing.T) {
 
+	CreateTestCDNs(t)
+	CreateTestTypes(t)
+	CreateTestParameters(t)
+	CreateTestProfiles(t)
 	CreateTestProfileParameters(t)
-	UpdateTestProfileParameters(t)
 	GetTestProfileParameters(t)
 	DeleteTestProfileParameters(t)
+	DeleteTestParameters(t)
+	DeleteTestProfiles(t)
+	DeleteTestTypes(t)
+	DeleteTestCDNs(t)
 
 }
 
 func CreateTestProfileParameters(t *testing.T) {
 
-	for _, pp := range testData.ProfileParameters {
-		resp, _, err := TOSession.CreateProfileParameter(pp)
-		log.Debugln("Response: ", resp)
-		if err != nil {
-			t.Errorf("could not CREATE profile parameters: %v\n", err)
-		}
-	}
-
-}
-
-func UpdateTestProfileParameters(t *testing.T) {
-
-	firstPP := testData.ProfileParameters[0]
-	// Retrieve the Parameter by profile so we can get the id for the Update
-	resp, _, err := TOSession.GetProfileParameterByParameter(firstPP.Profile)
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
 	if err != nil {
-		t.Errorf("cannot GET Parameter by name: %v - %v\n", firstPP.Profile, err)
+		t.Errorf("cannot GET Profile by name: %v - %v\n", firstProfile.Name, err)
 	}
-	remotePP := resp[0]
-	expectedPP := 1
-	remotePP.Profile = expectedPP
-	var alert tc.Alerts
-	alert, _, err = TOSession.UpdateParameterByProfile(remotePP.Profile, remotePP)
+
+	firstParameter := testData.Parameters[0]
+	paramResp, _, err := TOSession.GetParameterByName(firstParameter.Name)
 	if err != nil {
-		t.Errorf("cannot UPDATE Parameter by profile: %v - %v\n", err, alert)
+		t.Errorf("cannot GET Parameter by name: %v - %v\n", firstParameter.Name, err)
 	}
 
-	// Retrieve the Parameter to check Parameter name got updated
-	resp, _, err = TOSession.GetProfileParameterByProfile(remotePP.Profile)
-	if err != nil {
-		t.Errorf("cannot GET Parameter by profile: %v - %v\n", firstPP.Profile, err)
+	profileID := profileResp[0].ID
+	parameterID := paramResp[0].ID
+
+	pp := v13.ProfileParameter{
+		ProfileID:   profileID,
+		ParameterID: parameterID,
 	}
-	respParameter := resp[0]
-	if respParameter.Profile != expectedPP {
-		t.Errorf("results do not match actual: %s, expected: %s\n", respParameter.Profile, expectedPP)
+	resp, _, err := TOSession.CreateProfileParameter(pp)
+	log.Debugln("Response: ", resp)
+	if err != nil {
+		t.Errorf("could not CREATE profile parameters: %v\n", err)
 	}
 
 }
@@ -76,7 +74,8 @@ func UpdateTestProfileParameters(t *testing.T) {
 func GetTestProfileParameters(t *testing.T) {
 
 	for _, pp := range testData.ProfileParameters {
-		resp, _, err := TOSession.GetProfileParameterByProfile(pp.Profile)
+		queryParams := fmt.Sprintf(queryParamFormat, pp.ProfileID, pp.ParameterID)
+		resp, _, err := TOSession.GetProfileParameterByQueryParams(queryParams)
 		if err != nil {
 			t.Errorf("cannot GET Parameter by name: %v - %v\n", err, resp)
 		}
@@ -105,27 +104,28 @@ func DeleteTestProfileParameters(t *testing.T) {
 	}
 }
 
-func DeleteTestProfileParameter(t *testing.T, pp tc.ProfileParameter) {
+func DeleteTestProfileParameter(t *testing.T, pp v13.ProfileParameter) {
 
+	queryParams := fmt.Sprintf(queryParamFormat, pp.ProfileID, pp.ParameterID)
 	// Retrieve the PtofileParameter by profile so we can get the id for the Update
-	resp, _, err := TOSession.GetProfileParameterByIDs(pp.Profile, pp.Parameter)
+	resp, _, err := TOSession.GetProfileParameterByQueryParams(queryParams)
 	if err != nil {
 		t.Errorf("cannot GET Parameter by profile: %v - %v\n", pp.Profile, err)
 	}
 	if len(resp) > 0 {
 		respPP := resp[0]
 
-		delResp, _, err := TOSession.DeleteProfileParameterByProfile(respPP.Profile)
+		delResp, _, err := TOSession.DeleteParameterByProfileParameter(respPP.ProfileID, respPP.ParameterID)
 		if err != nil {
 			t.Errorf("cannot DELETE Parameter by profile: %v - %v\n", err, delResp)
 		}
 
 		// Retrieve the Parameter to see if it got deleted
-		pls, _, err := TOSession.GetProfileParameterByIDs(pp.Profile)
+		pps, _, err := TOSession.GetProfileParameterByQueryParams(queryParams)
 		if err != nil {
 			t.Errorf("error deleting Parameter name: %s\n", err.Error())
 		}
-		if len(pls) > 0 {
+		if len(pps) > 0 {
 			t.Errorf("expected Parameter Name: %s and ConfigFile: %s to be deleted\n", pp.Profile, pp.Parameter)
 		}
 	}
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index 27012b9..9462ee2 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -595,6 +595,16 @@
             "type": "ATS_PROFILE"
         }
     ],
+    "profileParameters": [
+        {
+            "profileId": 100,
+            "parameterId": 100
+        },
+        {
+            "profileId": 200,
+            "parameterId": 200
+        }
+    ],
     "regions": [
         {
             "divisionName": "division1",
diff --git a/traffic_ops/testing/api/v13/traffic_control.go b/traffic_ops/testing/api/v13/traffic_control.go
index 0036803..cba0b48 100644
--- a/traffic_ops/testing/api/v13/traffic_control.go
+++ b/traffic_ops/testing/api/v13/traffic_control.go
@@ -16,26 +16,26 @@
 package v13
 
 import (
-	tcapi "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	v12 "github.com/apache/incubator-trafficcontrol/lib/go-tc"
 	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
 )
 
 // TrafficControl - maps to the tc-fixtures.json file
 type TrafficControl struct {
-	ASNs                           []tcapi.ASN                           `json:"asns"`
-	CDNs                           []v13.CDN                             `json:"cdns"`
-	CacheGroups                    []tcapi.CacheGroup                    `json:"cachegroups"`
-	DeliveryServiceRequests        []tcapi.DeliveryServiceRequest        `json:"deliveryServiceRequests"`
-	DeliveryServiceRequestComments []tcapi.DeliveryServiceRequestComment `json:"deliveryServiceRequestComments"`
-	DeliveryServices               []tcapi.DeliveryService               `json:"deliveryservices"`
-	Divisions                      []tcapi.Division                      `json:"divisions"`
-	Profiles                       []tcapi.Profile                       `json:"profiles"`
-	Parameters                     []tcapi.Parameter                     `json:"parameters"`
-	ProfileParameters              []tcapi.ProfileParameter              `json:"profileParameters"`
-	PhysLocations                  []tcapi.PhysLocation                  `json:"physLocations"`
-	Regions                        []tcapi.Region                        `json:"regions"`
-	Servers                        []v13.Server                          `json:"servers"`
-	Statuses                       []tcapi.Status                        `json:"statuses"`
-	Tenants                        []tcapi.Tenant                        `json:"tenants"`
-	Types                          []tcapi.Type                          `json:"types"`
+	ASNs                           []v12.ASN                           `json:"asns"`
+	CDNs                           []v13.CDN                           `json:"cdns"`
+	CacheGroups                    []v12.CacheGroup                    `json:"cachegroups"`
+	DeliveryServiceRequests        []v12.DeliveryServiceRequest        `json:"deliveryServiceRequests"`
+	DeliveryServiceRequestComments []v12.DeliveryServiceRequestComment `json:"deliveryServiceRequestComments"`
+	DeliveryServices               []v12.DeliveryService               `json:"deliveryservices"`
+	Divisions                      []v12.Division                      `json:"divisions"`
+	Profiles                       []v12.Profile                       `json:"profiles"`
+	Parameters                     []v12.Parameter                     `json:"parameters"`
+	ProfileParameters              []v13.ProfileParameter              `json:"profileParameters"`
+	PhysLocations                  []v12.PhysLocation                  `json:"physLocations"`
+	Regions                        []v12.Region                        `json:"regions"`
+	Servers                        []v13.Server                        `json:"servers"`
+	Statuses                       []v12.Status                        `json:"statuses"`
+	Tenants                        []v12.Tenant                        `json:"tenants"`
+	Types                          []v12.Type                          `json:"types"`
 }

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 09/15: updated the CHANGELOG.md

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 46d7087e5f88b822bd3d16d07fc931e07ee3e15a
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 09:56:26 2018 -0600

    updated the CHANGELOG.md
---
 CHANGELOG.md | 53 +++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a3cc28b..eedbc36 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,33 +7,34 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 ### Added
 - Per-DeliveryService Routing Names: you can now choose a Delivery Service's Routing Name (rather than a hardcoded "tr" or "edge" name). This might require a few pre-upgrade steps detailed [here](http://traffic-control-cdn.readthedocs.io/en/latest/admin/traffic_ops/migration_from_20_to_22.html#per-deliveryservice-routing-names)
 - [Delivery Service Requests](http://traffic-control-cdn.readthedocs.io/en/latest/admin/quick_howto/ds_requests.html#ds-requests): When enabled, delivery service requests are created when ALL users attempt to create, update or delete a delivery service. This allows users with higher level permissions to review delivery service changes for completeness and accuracy before deploying the changes.
-- Traffic Ops Golang Proxy Endpoints (R=REST endpoints for GET, POST, PUT, DELETE)
+- Traffic Ops Golang Proxy Endpoints
   - /api/1.3/about
-  - /api/1.3/asns (R)
-  - /api/1.3/cdns (R)
-  - /api/1.3/cdns/capacity
-  - /api/1.3/cdns/configs
-  - /api/1.3/cdns/dnsseckeys
-  - /api/1.3/cdns/domain
-  - /api/1.3/cdns/monitoring
-  - /api/1.3/cdns/health
-  - /api/1.3/cdns/routing
-  - /api/1.3/deliveryservice_requests (R)
-  - /api/1.3/divisions (R)
-  - /api/1.3/hwinfos
-  - /api/1.3/parameters (R)
-  - /api/1.3/phys_locations (R)
-  - /api/1.3/ping
-  - /api/1.3/profiles (R)
-  - /api/1.3/regions (R)
-  - /api/1.3/servers (R)
-  - /api/1.3/servers/checks
-  - /api/1.3/servers/details
-  - /api/1.3/servers/status
-  - /api/1.3/servers/totals
-  - /api/1.3/statuses (R)
-  - /api/1.3/system/info
-  - /api/1.3/types (R)
+  - /api/1.3/asns (GET,POST,PUT,DELETE)
+  - /api/1.3/cdns (GET,POST,PUT,DELETE)
+  - /api/1.3/cdns/capacity (GET)
+  - /api/1.3/cdns/configs (GET)
+  - /api/1.3/cdns/dnsseckeys (GET)
+  - /api/1.3/cdns/domain (GET)
+  - /api/1.3/cdns/monitoring (GET)
+  - /api/1.3/cdns/health (GET)
+  - /api/1.3/cdns/routing (GET)
+  - /api/1.3/deliveryservice_requests (GET,POST,PUT,DELETE)
+  - /api/1.3/divisions (GET,POST,PUT,DELETE) 
+  - /api/1.3/hwinfos (GET)
+  - /api/1.3/parameters (GET,POST,PUT,DELETE)
+  - /api/1.3/profileparameters (GET,POST,PUT,DELETE)
+  - /api/1.3/phys_locations (GET,POST,PUT,DELETE)
+  - /api/1.3/ping (GET)
+  - /api/1.3/profiles (GET,POST,PUT,DELETE)
+  - /api/1.3/regions (GET,POST,PUT,DELETE)
+  - /api/1.3/servers (GET,POST,PUT,DELETE)
+  - /api/1.3/servers/checks (GET)
+  - /api/1.3/servers/details (GET)
+  - /api/1.3/servers/status (GET)
+  - /api/1.3/servers/totals (GET)
+  - /api/1.3/statuses (GET,POST,PUT,DELETE)
+  - /api/1.3/system/info (GET)
+  - /api/1.3/types (GET,POST,PUT,DELETE)
 - Fair Queuing Pacing: Using the FQ Pacing Rate parameter in Delivery Services allows operators to limit the rate of individual sessions to the edge cache. This feature requires a Trafficserver RPM containing the fq_pacing experimental plugin AND setting 'fq' as the default Linux qdisc in sysctl. 
 
 ### Changed

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 05/15: created the v13 profileparameters

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fa479f86eb1e33b37299e30d47d51c77fc368e86
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Apr 2 11:09:43 2018 -0600

    created the v13 profileparameters
---
 lib/go-tc/v13/profile_parameters.go | 45 +++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/lib/go-tc/v13/profile_parameters.go b/lib/go-tc/v13/profile_parameters.go
new file mode 100644
index 0000000..be3d1a2
--- /dev/null
+++ b/lib/go-tc/v13/profile_parameters.go
@@ -0,0 +1,45 @@
+package v13
+
+import tc "github.com/apache/incubator-trafficcontrol/lib/go-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.
+ */
+
+// ProfileParametersResponse ...
+type ProfileParametersResponse struct {
+	Response []ProfileParameter `json:"response"`
+}
+
+// ProfileParameter ...
+type ProfileParameter struct {
+	LastUpdated tc.TimeNoMod `json:"lastUpdated"`
+	Profile     string       `json:"profile"`
+	ProfileId   int          `json:"profileId"`
+	Parameter   string       `json:"parameter"`
+	ParameterId int          `json:"profileId"`
+}
+
+// ProfileParameterNullable ...
+type ProfileParameterNullable struct {
+	LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+	Profile     *string       `json:"profile" db:"profile"`
+	ProfileId   *int          `json:"profileId" db:"profile_id"`
+	Parameter   *string       `json:"parameter" db:"parameter"`
+	ParameterId *int          `json:"parameterId" db:"parameter_id"`
+}

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 04/15: updated to use the v13 structs

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 54c04d073223682f378f0f92c606001f3014154e
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Apr 2 11:09:19 2018 -0600

    updated to use the v13 structs
---
 .../traffic_ops_golang/profileparameter/profile_parameters.go      | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
index 7af58f8..893a792 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -25,7 +25,8 @@ import (
 	"strconv"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-log"
-	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	tc "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
@@ -37,10 +38,10 @@ import (
 )
 
 //we need a type alias to define functions on
-type TOProfileParameter tc.ProfileParameterNullable
+type TOProfileParameter v13.ProfileParameterNullable
 
 //the refType is passed into the handlers where a copy of its type is used to decode the json.
-var refType = TOProfileParameter(tc.ProfileParameterNullable{})
+var refType = TOProfileParameter(v13.ProfileParameterNullable{})
 
 func GetRefType() *TOProfileParameter {
 	return &refType

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 14/15: updated the test case for the v13 struct

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7f740643a80f9cbeca5ac4d2ded42306af76ea8d
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 13:54:29 2018 -0600

    updated the test case for the v13 struct
---
 .../profileparameter/profile_parameters_test.go                  | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
index 5ad3d28..9e7ce20 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
@@ -24,6 +24,7 @@ import (
 	"time"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/test"
@@ -32,14 +33,14 @@ import (
 	sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
 )
 
-func getTestProfileParameters() []tc.ProfileParameterNullable {
-	pps := []tc.ProfileParameterNullable{}
+func getTestProfileParameters() []v13.ProfileParameterNullable {
+	pps := []v13.ProfileParameterNullable{}
 	lastUpdated := tc.TimeNoMod{}
 	lastUpdated.Scan(time.Now())
 	profileID := 1
 	parameterID := 1
 
-	pp := tc.ProfileParameterNullable{
+	pp := v13.ProfileParameterNullable{
 		LastUpdated: &lastUpdated,
 		ProfileID:   &profileID,
 		ParameterID: &parameterID,
@@ -65,7 +66,7 @@ func TestGetProfileParameters(t *testing.T) {
 	defer db.Close()
 
 	testPPs := getTestProfileParameters()
-	cols := test.ColsFromStructByTag("db", tc.ProfileParameterNullable{})
+	cols := test.ColsFromStructByTag("db", v13.ProfileParameterNullable{})
 	rows := sqlmock.NewRows(cols)
 
 	for _, ts := range testPPs {

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 02/15: hooked in the profileparameters routes with a successful Read

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 03f434f885b1d5719e7f26e8e67fb7105c6b1bdf
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Apr 2 10:41:29 2018 -0600

    hooked in the profileparameters routes with a successful Read
---
 lib/go-tc/profile_parameters.go                    | 12 ++--
 .../profileparameter/profile_parameters.go         | 66 ++++++++++++----------
 traffic_ops/traffic_ops_golang/routes.go           |  8 +++
 3 files changed, 51 insertions(+), 35 deletions(-)

diff --git a/lib/go-tc/profile_parameters.go b/lib/go-tc/profile_parameters.go
index 4902faf..a2d7dee 100644
--- a/lib/go-tc/profile_parameters.go
+++ b/lib/go-tc/profile_parameters.go
@@ -27,13 +27,17 @@ type ProfileParametersResponse struct {
 // ProfileParameter ...
 type ProfileParameter struct {
 	LastUpdated TimeNoMod `json:"lastUpdated"`
-	Profile     int       `json:"profile"`
-	Parameter   int       `json:"parameter"`
+	Profile     string    `json:"profile"`
+	ProfileId   int       `json:"profileId"`
+	Parameter   string    `json:"parameter"`
+	ParameterId int       `json:"profileId"`
 }
 
 // ProfileParameterNullable ...
 type ProfileParameterNullable struct {
 	LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
-	Profile     *int       `json:"profile" db:"profile"`
-	Parameter   *int       `json:"parameter "db:"parameter"`
+	Profile     *string    `json:"profile" db:"profile"`
+	ProfileId   *int       `json:"profileId" db:"profile_id"`
+	Parameter   *string    `json:"parameter" db:"parameter"`
+	ParameterId *int       `json:"parameterId" db:"parameter_id"`
 }
diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
index 3576ca0..7af58f8 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -46,17 +46,24 @@ func GetRefType() *TOProfileParameter {
 	return &refType
 }
 
+func (pp TOProfileParameter) GetKeyFieldsInfo() []api.KeyFieldInfo {
+	return []api.KeyFieldInfo{{"profile", api.GetIntKey}, {"parameter", api.GetIntKey}}
+}
+
 //Implementation of the Identifier, Validator interface functions
-func (pp *TOProfileParameter) GetID() (int, bool) {
-	if pp.Profile == nil {
-		return 0, false
+func (pp TOProfileParameter) GetKeys() (map[string]interface{}, bool) {
+	if pp.ProfileId == nil {
+		return map[string]interface{}{"profile": 0}, false
 	}
-	return *pp.Profile, true
+	if pp.ParameterId == nil {
+		return map[string]interface{}{"parameter": 0}, false
+	}
+	return map[string]interface{}{"id": *pp.Profile}, true
 }
 
 func (pp *TOProfileParameter) GetAuditName() string {
-	if pp.Profile != nil {
-		return strconv.Itoa(*pp.Profile)
+	if pp.ProfileId != nil {
+		return strconv.Itoa(*pp.ProfileId) + "-" + strconv.Itoa(*pp.ParameterId)
 	}
 	return "unknown"
 }
@@ -65,8 +72,12 @@ func (pp *TOProfileParameter) GetType() string {
 	return "profileParameter"
 }
 
-func (pp *TOProfileParameter) SetID(i int) {
-	pp.Profile = &i
+func (pp *TOProfileParameter) SetKeys(keys map[string]interface{}) {
+	profId, _ := keys["profile"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	pp.ProfileId = &profId
+
+	paramId, _ := keys["parameter"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	pp.ParameterId = &paramId
 }
 
 // Validate fulfills the api.Validator interface
@@ -119,17 +130,18 @@ func (pp *TOProfileParameter) Create(db *sqlx.DB, user auth.CurrentUser) (error,
 	defer resultRows.Close()
 
 	var profile int
+	var parameter int
 	var lastUpdated tc.TimeNoMod
 	rowsAffected := 0
 	for resultRows.Next() {
 		rowsAffected++
-		if err := resultRows.Scan(&profile, &lastUpdated); err != nil {
+		if err := resultRows.Scan(&profile, &parameter, &lastUpdated); err != nil {
 			log.Error.Printf("could not scan profile from insert: %s\n", err)
 			return tc.DBError, tc.SystemError
 		}
 	}
 	if rowsAffected == 0 {
-		err = errors.New("no parameter was inserted, no profile was returned")
+		err = errors.New("no profile_parameter was inserted, no profile+parameter was returned")
 		log.Errorln(err)
 		return tc.DBError, tc.SystemError
 	}
@@ -139,7 +151,7 @@ func (pp *TOProfileParameter) Create(db *sqlx.DB, user auth.CurrentUser) (error,
 		return tc.DBError, tc.SystemError
 	}
 
-	pp.SetID(profile)
+	pp.SetKeys(map[string]interface{}{"profile": profile, "parameter": parameter})
 	pp.LastUpdated = &lastUpdated
 	err = tx.Commit()
 	if err != nil {
@@ -162,14 +174,12 @@ parameter) VALUES (
 func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters map[string]string, user auth.CurrentUser) ([]interface{}, []error, tc.ApiErrorType) {
 	var rows *sqlx.Rows
 
-	privLevel := user.PrivLevel
-
 	// Query Parameters to Database Query column mappings
 	// see the fields mapped in the SQL query
 	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-		"profile":      dbhelpers.WhereColumnInfo{"pp.profile", api.IsInt},
+		"profile":      dbhelpers.WhereColumnInfo{"pp.profile", nil},
+		"parameter":    dbhelpers.WhereColumnInfo{"pp.parameter", nil},
 		"last_updated": dbhelpers.WhereColumnInfo{"pp.last_updated", nil},
-		"name":         dbhelpers.WhereColumnInfo{"p.parameter", nil},
 	}
 
 	where, orderBy, queryValues, errs := dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
@@ -188,21 +198,12 @@ func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters map[string]string, us
 	defer rows.Close()
 
 	params := []interface{}{}
-	hiddenField := "********"
 	for rows.Next() {
-		var p tc.ParameterNullable
+		var p tc.ProfileParameterNullable
 		if err = rows.StructScan(&p); err != nil {
 			log.Errorf("error parsing pp rows: %v", err)
 			return nil, []error{tc.DBError}, tc.SystemError
 		}
-		var isSecure bool
-		if p.Secure != nil {
-			isSecure = *p.Secure
-		}
-
-		if isSecure && (privLevel < auth.PrivLevelAdmin) {
-			p.Value = &hiddenField
-		}
 		params = append(params, p)
 	}
 
@@ -322,11 +323,14 @@ func (pp *TOProfileParameter) Delete(db *sqlx.DB, user auth.CurrentUser) (error,
 func selectQuery() string {
 
 	query := `SELECT
-p.last_updated,
-p.profile,
-p.id,
-p.parameter
-FROM profile_parameter p`
+pp.last_updated,
+pp.profile profile_id,
+pp.parameter parameter_id,
+prof.name profile,
+param.name parameter
+FROM profile_parameter pp
+JOIN profile prof ON prof.id = pp.profile
+JOIN parameter param ON param.id = pp.parameter`
 	return query
 }
 
@@ -341,6 +345,6 @@ WHERE id=:id RETURNING last_updated`
 
 func deleteQuery() string {
 	query := `DELETE FROM profile_parameter
-WHERE id=:id`
+	WHERE profile=:profile and parameter=:parameter`
 	return query
 }
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 4d9619b..d981111 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -42,6 +42,7 @@ import (
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/physlocation"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/ping"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/profile"
+	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/profileparameter"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/region"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/server"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/status"
@@ -191,6 +192,13 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
 		{1.3, http.MethodPost, `profiles-wip/?$`, api.CreateHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 		{1.3, http.MethodDelete, `profiles-wip/{id}$`, api.DeleteHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 
+		//ProfileParameters
+		{1.3, http.MethodGet, `profileparameters/?(\.json)?$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodGet, `profileparameters/{id}$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodPut, `profileparameters/{id}$`, api.UpdateHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodPost, `profileparameters/?$`, api.CreateHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodDelete, `profilesparameters/{id}$`, api.DeleteHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+
 		//SSLKeys deliveryservice endpoints here that are marked  marked as '-wip' need to have tenancy checks added
 		{1.2, http.MethodGet, `deliveryservices-wip/xmlId/{xmlID}/sslkeys$`, getDeliveryServiceSSLKeysByXMLIDHandler(d.DB, d.Config), auth.PrivLevelAdmin, Authenticated, nil},
 		{1.2, http.MethodGet, `deliveryservices-wip/hostname/{hostName}/sslkeys$`, getDeliveryServiceSSLKeysByHostNameHandler(d.DB, d.Config), auth.PrivLevelAdmin, Authenticated, nil},

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 06/15: removed the PUT for profileparameters because it isnt relevant

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 95f7a1ef269aebab537dca29b0efa127ebb3b0d8
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Apr 3 12:30:50 2018 -0600

    removed the PUT for profileparameters because it isnt relevant
---
 .../profileparameter/profile_parameters.go         | 127 ++++++---------------
 .../profileparameter/profile_parameters_test.go    |  19 ++-
 traffic_ops/traffic_ops_golang/routes.go           |   1 -
 3 files changed, 46 insertions(+), 101 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
index 893a792..696cfef 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -37,6 +37,11 @@ import (
 	"github.com/lib/pq"
 )
 
+const (
+	ProfileIDQueryParam   = "profileId"
+	ParameterIDQueryParam = "parameterId"
+)
+
 //we need a type alias to define functions on
 type TOProfileParameter v13.ProfileParameterNullable
 
@@ -48,23 +53,29 @@ func GetRefType() *TOProfileParameter {
 }
 
 func (pp TOProfileParameter) GetKeyFieldsInfo() []api.KeyFieldInfo {
-	return []api.KeyFieldInfo{{"profile", api.GetIntKey}, {"parameter", api.GetIntKey}}
+	return []api.KeyFieldInfo{{ProfileIDQueryParam, api.GetIntKey}, {ParameterIDQueryParam, api.GetIntKey}}
 }
 
 //Implementation of the Identifier, Validator interface functions
 func (pp TOProfileParameter) GetKeys() (map[string]interface{}, bool) {
-	if pp.ProfileId == nil {
-		return map[string]interface{}{"profile": 0}, false
+	if pp.ProfileID == nil {
+		return map[string]interface{}{ProfileIDQueryParam: 0}, false
 	}
-	if pp.ParameterId == nil {
-		return map[string]interface{}{"parameter": 0}, false
+	if pp.ParameterID == nil {
+		return map[string]interface{}{ParameterIDQueryParam: 0}, false
 	}
-	return map[string]interface{}{"id": *pp.Profile}, true
+	keys := make(map[string]interface{})
+	profileID := *pp.ProfileID
+	parameterID := *pp.ParameterID
+
+	keys[ProfileIDQueryParam] = profileID
+	keys[ParameterIDQueryParam] = parameterID
+	return keys, true
 }
 
 func (pp *TOProfileParameter) GetAuditName() string {
-	if pp.ProfileId != nil {
-		return strconv.Itoa(*pp.ProfileId) + "-" + strconv.Itoa(*pp.ParameterId)
+	if pp.ProfileID != nil {
+		return strconv.Itoa(*pp.ProfileID) + "-" + strconv.Itoa(*pp.ParameterID)
 	}
 	return "unknown"
 }
@@ -74,19 +85,19 @@ func (pp *TOProfileParameter) GetType() string {
 }
 
 func (pp *TOProfileParameter) SetKeys(keys map[string]interface{}) {
-	profId, _ := keys["profile"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
-	pp.ProfileId = &profId
+	profId, _ := keys[ProfileIDQueryParam].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	pp.ProfileID = &profId
 
-	paramId, _ := keys["parameter"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
-	pp.ParameterId = &paramId
+	paramId, _ := keys[ParameterIDQueryParam].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	pp.ParameterID = &paramId
 }
 
 // Validate fulfills the api.Validator interface
-func (pp TOProfileParameter) Validate(db *sqlx.DB) []error {
+func (pp *TOProfileParameter) Validate(db *sqlx.DB) []error {
 
 	errs := validation.Errors{
-		"profile":   validation.Validate(pp.Profile, validation.Required),
-		"parameter": validation.Validate(pp.Parameter, validation.Required),
+		"profile":   validation.Validate(pp.ProfileID, validation.Required),
+		"parameter": validation.Validate(pp.ParameterID, validation.Required),
 	}
 
 	return tovalidate.ToErrors(errs)
@@ -152,7 +163,7 @@ func (pp *TOProfileParameter) Create(db *sqlx.DB, user auth.CurrentUser) (error,
 		return tc.DBError, tc.SystemError
 	}
 
-	pp.SetKeys(map[string]interface{}{"profile": profile, "parameter": parameter})
+	pp.SetKeys(map[string]interface{}{ProfileIDQueryParam: profile, ParameterIDQueryParam: parameter})
 	pp.LastUpdated = &lastUpdated
 	err = tx.Commit()
 	if err != nil {
@@ -167,8 +178,8 @@ func insertQuery() string {
 	query := `INSERT INTO profile_parameter (
 profile,
 parameter) VALUES (
-:profile,
-:parameter) RETURNING profile_profile,last_updated`
+:profile_id,
+:parameter_id) RETURNING profile, parameter, last_updated`
 	return query
 }
 
@@ -178,9 +189,9 @@ func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters map[string]string, us
 	// Query Parameters to Database Query column mappings
 	// see the fields mapped in the SQL query
 	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-		"profile":      dbhelpers.WhereColumnInfo{"pp.profile", nil},
-		"parameter":    dbhelpers.WhereColumnInfo{"pp.parameter", nil},
-		"last_updated": dbhelpers.WhereColumnInfo{"pp.last_updated", nil},
+		"profileId":   dbhelpers.WhereColumnInfo{"pp.profile", nil},
+		"parameterId": dbhelpers.WhereColumnInfo{"pp.parameter", nil},
+		"lastUpdated": dbhelpers.WhereColumnInfo{"pp.last_updated", nil},
 	}
 
 	where, orderBy, queryValues, errs := dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
@@ -212,70 +223,6 @@ func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters map[string]string, us
 
 }
 
-//The TOProfileParameter implementation of the Updater interface
-//all implementations of Updater should use transactions and return the proper errorType
-//ParsePQUniqueConstraintError is used to determine if a parameter with conflicting values exists
-//if so, it will return an errorType of DataConflict and the type should be appended to the
-//generic error message returned
-func (pp *TOProfileParameter) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
-	rollbackTransaction := true
-	tx, err := db.Beginx()
-	defer func() {
-		if tx == nil || !rollbackTransaction {
-			return
-		}
-		err := tx.Rollback()
-		if err != nil {
-			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
-		}
-	}()
-
-	if err != nil {
-		log.Error.Printf("could not begin transaction: %v", err)
-		return tc.DBError, tc.SystemError
-	}
-	log.Debugf("about to run exec query: %s with parameter: %++v", updateQuery(), pp)
-	resultRows, err := tx.NamedQuery(updateQuery(), pp)
-	if err != nil {
-		if pqErr, ok := err.(*pq.Error); ok {
-			err, eType := dbhelpers.ParsePQUniqueConstraintError(pqErr)
-			if eType == tc.DataConflictError {
-				return errors.New("a parameter with " + err.Error()), eType
-			}
-			return err, eType
-		}
-		log.Errorf("received error: %++v from update execution", err)
-		return tc.DBError, tc.SystemError
-	}
-	defer resultRows.Close()
-
-	// get LastUpdated field -- updated by trigger in the db
-	var lastUpdated tc.TimeNoMod
-	rowsAffected := 0
-	for resultRows.Next() {
-		rowsAffected++
-		if err := resultRows.Scan(&lastUpdated); err != nil {
-			log.Error.Printf("could not scan lastUpdated from insert: %s\n", err)
-			return tc.DBError, tc.SystemError
-		}
-	}
-	log.Debugf("lastUpdated: %++v", lastUpdated)
-	pp.LastUpdated = &lastUpdated
-	if rowsAffected != 1 {
-		if rowsAffected < 1 {
-			return errors.New("no parameter found with this id"), tc.DataMissingError
-		}
-		return fmt.Errorf("this update affected too many rows: %d", rowsAffected), tc.SystemError
-	}
-	err = tx.Commit()
-	if err != nil {
-		log.Errorln("Could not commit transaction: ", err)
-		return tc.DBError, tc.SystemError
-	}
-	rollbackTransaction = false
-	return nil, tc.NoError
-}
-
 //The Parameter implementation of the Deleter interface
 //all implementations of Deleter should use transactions and return the proper errorType
 func (pp *TOProfileParameter) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
@@ -338,14 +285,16 @@ JOIN parameter param ON param.id = pp.parameter`
 func updateQuery() string {
 	query := `UPDATE
 profile_parameter SET
-profile=:profile,
-parameter=:parameter
-WHERE id=:id RETURNING last_updated`
+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 and parameter=:parameter`
+	WHERE profile=:profile_id and parameter=:parameter_id`
 	return query
 }
diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
index a066c2e..5ad3d28 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
@@ -36,19 +36,19 @@ func getTestProfileParameters() []tc.ProfileParameterNullable {
 	pps := []tc.ProfileParameterNullable{}
 	lastUpdated := tc.TimeNoMod{}
 	lastUpdated.Scan(time.Now())
-	profileId := 1
-	parameterId := 1
+	profileID := 1
+	parameterID := 1
 
 	pp := tc.ProfileParameterNullable{
 		LastUpdated: &lastUpdated,
-		ProfileId:   &profileId,
-		ParameterId: &parameterId,
+		ProfileID:   &profileID,
+		ParameterID: &parameterID,
 	}
 	pps = append(pps, pp)
 
 	pp2 := pp
-	pp2.ProfileId = &profileId
-	pp2.ParameterId = &parameterId
+	pp2.ProfileID = &profileID
+	pp2.ParameterID = &parameterID
 	pps = append(pps, pp2)
 
 	return pps
@@ -72,9 +72,9 @@ func TestGetProfileParameters(t *testing.T) {
 		rows = rows.AddRow(
 			ts.LastUpdated,
 			ts.Profile,
-			ts.ProfileId,
+			ts.ProfileID,
 			ts.Parameter,
-			ts.ParameterId,
+			ts.ParameterID,
 		)
 	}
 	mock.ExpectQuery("SELECT").WillReturnRows(rows)
@@ -101,9 +101,6 @@ func TestInterfaces(t *testing.T) {
 	if _, ok := i.(api.Reader); !ok {
 		t.Errorf("ProfileParameter must be Reader")
 	}
-	if _, ok := i.(api.Updater); !ok {
-		t.Errorf("ProfileParameter must be Updater")
-	}
 	if _, ok := i.(api.Deleter); !ok {
 		t.Errorf("ProfileParameter must be Deleter")
 	}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index d981111..6eac8bc 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -195,7 +195,6 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
 		//ProfileParameters
 		{1.3, http.MethodGet, `profileparameters/?(\.json)?$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
 		{1.3, http.MethodGet, `profileparameters/{id}$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodPut, `profileparameters/{id}$`, api.UpdateHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 		{1.3, http.MethodPost, `profileparameters/?$`, api.CreateHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 		{1.3, http.MethodDelete, `profilesparameters/{id}$`, api.DeleteHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 13/15: updated for the v13 struct

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit de8f4ec9ea0458de39a8585e6453be6d8a10b661
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 13:53:40 2018 -0600

    updated for the v13 struct
---
 traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
index 696cfef..463ff06 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -211,7 +211,7 @@ func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters map[string]string, us
 
 	params := []interface{}{}
 	for rows.Next() {
-		var p tc.ProfileParameterNullable
+		var p v13.ProfileParameterNullable
 		if err = rows.StructScan(&p); err != nil {
 			log.Errorf("error parsing pp rows: %v", err)
 			return nil, []error{tc.DBError}, tc.SystemError

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 15/15: updated the routes per the API guidelines

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit eab39fb78113c580d2c3597409059c66ba39f806
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Fri Apr 6 14:15:53 2018 -0600

    updated the routes per the API guidelines
---
 traffic_ops/client/v13/profile_parameter.go | 2 +-
 traffic_ops/traffic_ops_golang/routes.go    | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/traffic_ops/client/v13/profile_parameter.go b/traffic_ops/client/v13/profile_parameter.go
index f4af45e..5f9b558 100644
--- a/traffic_ops/client/v13/profile_parameter.go
+++ b/traffic_ops/client/v13/profile_parameter.go
@@ -26,7 +26,7 @@ import (
 )
 
 const (
-	API_v13_Profile_Parameters = "/api/1.3/profileparameters"
+	API_v13_Profile_Parameters = "/api/1.3/profile_parameters"
 	ProfileIdQueryParam        = "profileId"
 	ParameterIdQueryParam      = "parameterId"
 )
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 6eac8bc..1551d2c 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -193,10 +193,10 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
 		{1.3, http.MethodDelete, `profiles-wip/{id}$`, api.DeleteHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 
 		//ProfileParameters
-		{1.3, http.MethodGet, `profileparameters/?(\.json)?$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodGet, `profileparameters/{id}$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodPost, `profileparameters/?$`, api.CreateHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
-		{1.3, http.MethodDelete, `profilesparameters/{id}$`, api.DeleteHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodGet, `profile_parameters/?(\.json)?$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodGet, `profile_parameters/{id}$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodPost, `profile_parameters/?$`, api.CreateHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodDelete, `profile_parameters/{id}$`, api.DeleteHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 
 		//SSLKeys deliveryservice endpoints here that are marked  marked as '-wip' need to have tenancy checks added
 		{1.2, http.MethodGet, `deliveryservices-wip/xmlId/{xmlID}/sslkeys$`, getDeliveryServiceSSLKeysByXMLIDHandler(d.DB, d.Config), auth.PrivLevelAdmin, Authenticated, nil},

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 01/15: work in progress until CRUD Interfaces support compound keys

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 413e109742abab2af43e9bac6b9ca4df5a7d9da1
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Fri Mar 9 08:40:10 2018 -0700

    work in progress until CRUD Interfaces support compound keys
---
 lib/go-tc/profile_parameters.go                    |  39 +++
 traffic_ops/client/v13/profile_parameter.go        | 133 ++++++++
 .../testing/api/v13/profile_parameters_test.go     | 132 ++++++++
 traffic_ops/testing/api/v13/traffic_control.go     |   1 +
 .../parameter/parameters_test.go                   |   8 +-
 .../profileparameter/profile_parameters.go         | 346 +++++++++++++++++++++
 .../profile_parameters_test.go}                    |  69 ++--
 .../traffic_ops_golang/region/regions_test.go      |   2 +-
 8 files changed, 692 insertions(+), 38 deletions(-)

diff --git a/lib/go-tc/profile_parameters.go b/lib/go-tc/profile_parameters.go
new file mode 100644
index 0000000..4902faf
--- /dev/null
+++ b/lib/go-tc/profile_parameters.go
@@ -0,0 +1,39 @@
+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.
+ */
+
+// ProfileParametersResponse ...
+type ProfileParametersResponse struct {
+	Response []ProfileParameter `json:"response"`
+}
+
+// ProfileParameter ...
+type ProfileParameter struct {
+	LastUpdated TimeNoMod `json:"lastUpdated"`
+	Profile     int       `json:"profile"`
+	Parameter   int       `json:"parameter"`
+}
+
+// ProfileParameterNullable ...
+type ProfileParameterNullable struct {
+	LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
+	Profile     *int       `json:"profile" db:"profile"`
+	Parameter   *int       `json:"parameter "db:"parameter"`
+}
diff --git a/traffic_ops/client/v13/profile_parameter.go b/traffic_ops/client/v13/profile_parameter.go
new file mode 100644
index 0000000..aaa3fac
--- /dev/null
+++ b/traffic_ops/client/v13/profile_parameter.go
@@ -0,0 +1,133 @@
+/*
+
+   Licensed 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.
+*/
+
+package v13
+
+import (
+	"encoding/json"
+	"fmt"
+	"net"
+	"net/http"
+	"strconv"
+
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+)
+
+const (
+	API_v13_Profile_Parameters = "/api/1.3/profile_parameters"
+)
+
+// Create a ProfileParameter
+func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(pp)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	resp, remoteAddr, err := to.request(http.MethodPost, API_v13_Profile_Parameters, reqBody)
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	defer resp.Body.Close()
+	var alerts tc.Alerts
+	err = json.NewDecoder(resp.Body).Decode(&alerts)
+	return alerts, reqInf, nil
+}
+
+// Update a Profile Parameter by Profile
+func (to *Session) UpdateParameterByProfile(id int, pp tc.ProfileParameter) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(pp)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	URI := fmt.Sprintf("%s/%d", API_v13_Profile_Parameters, id)
+	resp, remoteAddr, err := to.request(http.MethodPut, URI, reqBody)
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	defer resp.Body.Close()
+	var alerts tc.Alerts
+	err = json.NewDecoder(resp.Body).Decode(&alerts)
+	return alerts, reqInf, nil
+}
+
+// Returns a list of Profile Parameters
+func (to *Session) GetProfileParameters() ([]tc.ProfileParameter, ReqInf, error) {
+	resp, remoteAddr, err := to.request(http.MethodGet, API_v13_Profile_Parameters, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return nil, reqInf, err
+	}
+	defer resp.Body.Close()
+
+	var data tc.ProfileParametersResponse
+	err = json.NewDecoder(resp.Body).Decode(&data)
+	return data.Response, reqInf, nil
+}
+
+// GET a Profile Parameter by the Profile
+func (to *Session) GetProfileParameterByIDs(profile int, parameter int) ([]tc.ProfileParameter, ReqInf, error) {
+	URI := fmt.Sprintf("%s?profile=%d&parameter=%d", API_v13_Profile_Parameters, profile)
+	resp, remoteAddr, err := to.request(http.MethodGet, URI, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return nil, reqInf, err
+	}
+	defer resp.Body.Close()
+
+	var data tc.ProfileParametersResponse
+	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
+		return nil, reqInf, err
+	}
+
+	return data.Response, reqInf, nil
+}
+
+// GET a Profile Parameter by the Parameter
+func (to *Session) GetProfileParameterByParameter(parameter int) ([]tc.ProfileParameter, ReqInf, error) {
+	URI := API_v13_Profile_Parameters + "?parameter=" + strconv.Itoa(parameter)
+	resp, remoteAddr, err := to.request(http.MethodGet, URI, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return nil, reqInf, err
+	}
+	defer resp.Body.Close()
+
+	var data tc.ProfileParametersResponse
+	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
+		return nil, reqInf, err
+	}
+
+	return data.Response, reqInf, nil
+}
+
+// DELETE a Parameter by Parameter
+func (to *Session) DeleteParameterByParameter(parameter int) (tc.Alerts, ReqInf, error) {
+	URI := fmt.Sprintf("%s/%d", API_v13_Profile_Parameters, parameter)
+	resp, remoteAddr, err := to.request(http.MethodDelete, URI, nil)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	defer resp.Body.Close()
+	var alerts tc.Alerts
+	err = json.NewDecoder(resp.Body).Decode(&alerts)
+	return alerts, reqInf, nil
+}
diff --git a/traffic_ops/testing/api/v13/profile_parameters_test.go b/traffic_ops/testing/api/v13/profile_parameters_test.go
new file mode 100644
index 0000000..e4b5f4f
--- /dev/null
+++ b/traffic_ops/testing/api/v13/profile_parameters_test.go
@@ -0,0 +1,132 @@
+/*
+
+   Licensed 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.
+*/
+
+package v13
+
+import (
+	"sync"
+	"testing"
+
+	"github.com/apache/incubator-trafficcontrol/lib/go-log"
+	tc "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+)
+
+func TestProfileParameters(t *testing.T) {
+
+	CreateTestProfileParameters(t)
+	UpdateTestProfileParameters(t)
+	GetTestProfileParameters(t)
+	DeleteTestProfileParameters(t)
+
+}
+
+func CreateTestProfileParameters(t *testing.T) {
+
+	for _, pp := range testData.ProfileParameters {
+		resp, _, err := TOSession.CreateProfileParameter(pp)
+		log.Debugln("Response: ", resp)
+		if err != nil {
+			t.Errorf("could not CREATE profile parameters: %v\n", err)
+		}
+	}
+
+}
+
+func UpdateTestProfileParameters(t *testing.T) {
+
+	firstPP := testData.ProfileParameters[0]
+	// Retrieve the Parameter by profile so we can get the id for the Update
+	resp, _, err := TOSession.GetProfileParameterByParameter(firstPP.Profile)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v\n", firstPP.Profile, err)
+	}
+	remotePP := resp[0]
+	expectedPP := 1
+	remotePP.Profile = expectedPP
+	var alert tc.Alerts
+	alert, _, err = TOSession.UpdateParameterByProfile(remotePP.Profile, remotePP)
+	if err != nil {
+		t.Errorf("cannot UPDATE Parameter by profile: %v - %v\n", err, alert)
+	}
+
+	// Retrieve the Parameter to check Parameter name got updated
+	resp, _, err = TOSession.GetProfileParameterByProfile(remotePP.Profile)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by profile: %v - %v\n", firstPP.Profile, err)
+	}
+	respParameter := resp[0]
+	if respParameter.Profile != expectedPP {
+		t.Errorf("results do not match actual: %s, expected: %s\n", respParameter.Profile, expectedPP)
+	}
+
+}
+
+func GetTestProfileParameters(t *testing.T) {
+
+	for _, pp := range testData.ProfileParameters {
+		resp, _, err := TOSession.GetProfileParameterByProfile(pp.Profile)
+		if err != nil {
+			t.Errorf("cannot GET Parameter by name: %v - %v\n", err, resp)
+		}
+	}
+}
+
+func DeleteTestProfileParametersParallel(t *testing.T) {
+
+	var wg sync.WaitGroup
+	for _, pp := range testData.ProfileParameters {
+
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+			DeleteTestProfileParameter(t, pp)
+		}()
+
+	}
+	wg.Wait()
+}
+
+func DeleteTestProfileParameters(t *testing.T) {
+
+	for _, pp := range testData.ProfileParameters {
+		DeleteTestProfileParameter(t, pp)
+	}
+}
+
+func DeleteTestProfileParameter(t *testing.T, pp tc.ProfileParameter) {
+
+	// Retrieve the PtofileParameter by profile so we can get the id for the Update
+	resp, _, err := TOSession.GetProfileParameterByIDs(pp.Profile, pp.Parameter)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by profile: %v - %v\n", pp.Profile, err)
+	}
+	if len(resp) > 0 {
+		respPP := resp[0]
+
+		delResp, _, err := TOSession.DeleteProfileParameterByProfile(respPP.Profile)
+		if err != nil {
+			t.Errorf("cannot DELETE Parameter by profile: %v - %v\n", err, delResp)
+		}
+
+		// Retrieve the Parameter to see if it got deleted
+		pls, _, err := TOSession.GetProfileParameterByIDs(pp.Profile)
+		if err != nil {
+			t.Errorf("error deleting Parameter name: %s\n", err.Error())
+		}
+		if len(pls) > 0 {
+			t.Errorf("expected Parameter Name: %s and ConfigFile: %s to be deleted\n", pp.Profile, pp.Parameter)
+		}
+	}
+}
diff --git a/traffic_ops/testing/api/v13/traffic_control.go b/traffic_ops/testing/api/v13/traffic_control.go
index b804ca0..0036803 100644
--- a/traffic_ops/testing/api/v13/traffic_control.go
+++ b/traffic_ops/testing/api/v13/traffic_control.go
@@ -31,6 +31,7 @@ type TrafficControl struct {
 	Divisions                      []tcapi.Division                      `json:"divisions"`
 	Profiles                       []tcapi.Profile                       `json:"profiles"`
 	Parameters                     []tcapi.Parameter                     `json:"parameters"`
+	ProfileParameters              []tcapi.ProfileParameter              `json:"profileParameters"`
 	PhysLocations                  []tcapi.PhysLocation                  `json:"physLocations"`
 	Regions                        []tcapi.Region                        `json:"regions"`
 	Servers                        []v13.Server                          `json:"servers"`
diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters_test.go b/traffic_ops/traffic_ops_golang/parameter/parameters_test.go
index 4cbfc89..a16df6e 100644
--- a/traffic_ops/traffic_ops_golang/parameter/parameters_test.go
+++ b/traffic_ops/traffic_ops_golang/parameter/parameters_test.go
@@ -91,15 +91,15 @@ func TestGetParameters(t *testing.T) {
 		)
 	}
 	mock.ExpectQuery("SELECT").WillReturnRows(rows)
-	v := map[string]string{"dsId": "1"}
+	v := map[string]string{"name": "1"}
 
-	parameters, errs, _ := refType.Read(db, v, auth.CurrentUser{})
+	pps, errs, _ := refType.Read(db, v, auth.CurrentUser{})
 	if len(errs) > 0 {
 		t.Errorf("parameter.Read expected: no errors, actual: %v", errs)
 	}
 
-	if len(parameters) != 2 {
-		t.Errorf("parameter.Read expected: len(parameters) == 2, actual: %v", len(parameters))
+	if len(pps) != 2 {
+		t.Errorf("parameter.Read expected: len(pps) == 2, actual: %v", len(pps))
 	}
 
 }
diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
new file mode 100644
index 0000000..3576ca0
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -0,0 +1,346 @@
+package profileparameter
+
+/*
+ * 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 (
+	"errors"
+	"fmt"
+	"strconv"
+
+	"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/auth"
+	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/tovalidate"
+	validation "github.com/go-ozzo/ozzo-validation"
+
+	"github.com/jmoiron/sqlx"
+	"github.com/lib/pq"
+)
+
+//we need a type alias to define functions on
+type TOProfileParameter tc.ProfileParameterNullable
+
+//the refType is passed into the handlers where a copy of its type is used to decode the json.
+var refType = TOProfileParameter(tc.ProfileParameterNullable{})
+
+func GetRefType() *TOProfileParameter {
+	return &refType
+}
+
+//Implementation of the Identifier, Validator interface functions
+func (pp *TOProfileParameter) GetID() (int, bool) {
+	if pp.Profile == nil {
+		return 0, false
+	}
+	return *pp.Profile, true
+}
+
+func (pp *TOProfileParameter) GetAuditName() string {
+	if pp.Profile != nil {
+		return strconv.Itoa(*pp.Profile)
+	}
+	return "unknown"
+}
+
+func (pp *TOProfileParameter) GetType() string {
+	return "profileParameter"
+}
+
+func (pp *TOProfileParameter) SetID(i int) {
+	pp.Profile = &i
+}
+
+// Validate fulfills the api.Validator interface
+func (pp TOProfileParameter) Validate(db *sqlx.DB) []error {
+
+	errs := validation.Errors{
+		"profile":   validation.Validate(pp.Profile, validation.Required),
+		"parameter": validation.Validate(pp.Parameter, validation.Required),
+	}
+
+	return tovalidate.ToErrors(errs)
+}
+
+//The TOProfileParameter implementation of the Creator interface
+//all implementations of Creator should use transactions and return the proper errorType
+//ParsePQUniqueConstraintError is used to determine if a profileparameter with conflicting values exists
+//if so, it will return an errorType of DataConflict and the type should be appended to the
+//generic error message returned
+//The insert sql returns the profile and lastUpdated values of the newly inserted profileparameter and have
+//to be added to the struct
+func (pp *TOProfileParameter) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
+	rollbackTransaction := true
+	tx, err := db.Beginx()
+	defer func() {
+		if tx == nil || !rollbackTransaction {
+			return
+		}
+		err := tx.Rollback()
+		if err != nil {
+			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
+		}
+	}()
+
+	if err != nil {
+		log.Error.Printf("could not begin transaction: %v", err)
+		return tc.DBError, tc.SystemError
+	}
+	resultRows, err := tx.NamedQuery(insertQuery(), pp)
+	if err != nil {
+		if pqErr, ok := err.(*pq.Error); ok {
+			err, eType := dbhelpers.ParsePQUniqueConstraintError(pqErr)
+			if eType == tc.DataConflictError {
+				return errors.New("a parameter with " + err.Error()), eType
+			}
+			return err, eType
+		}
+		log.Errorf("received non pq error: %++v from create execution", err)
+		return tc.DBError, tc.SystemError
+	}
+	defer resultRows.Close()
+
+	var profile int
+	var lastUpdated tc.TimeNoMod
+	rowsAffected := 0
+	for resultRows.Next() {
+		rowsAffected++
+		if err := resultRows.Scan(&profile, &lastUpdated); err != nil {
+			log.Error.Printf("could not scan profile from insert: %s\n", err)
+			return tc.DBError, tc.SystemError
+		}
+	}
+	if rowsAffected == 0 {
+		err = errors.New("no parameter was inserted, no profile was returned")
+		log.Errorln(err)
+		return tc.DBError, tc.SystemError
+	}
+	if rowsAffected > 1 {
+		err = errors.New("too many ids returned from parameter insert")
+		log.Errorln(err)
+		return tc.DBError, tc.SystemError
+	}
+
+	pp.SetID(profile)
+	pp.LastUpdated = &lastUpdated
+	err = tx.Commit()
+	if err != nil {
+		log.Errorln("Could not commit transaction: ", err)
+		return tc.DBError, tc.SystemError
+	}
+	rollbackTransaction = false
+	return nil, tc.NoError
+}
+
+func insertQuery() string {
+	query := `INSERT INTO profile_parameter (
+profile,
+parameter) VALUES (
+:profile,
+:parameter) RETURNING profile_profile,last_updated`
+	return query
+}
+
+func (pp *TOProfileParameter) Read(db *sqlx.DB, parameters map[string]string, user auth.CurrentUser) ([]interface{}, []error, tc.ApiErrorType) {
+	var rows *sqlx.Rows
+
+	privLevel := user.PrivLevel
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"profile":      dbhelpers.WhereColumnInfo{"pp.profile", api.IsInt},
+		"last_updated": dbhelpers.WhereColumnInfo{"pp.last_updated", nil},
+		"name":         dbhelpers.WhereColumnInfo{"p.parameter", nil},
+	}
+
+	where, orderBy, queryValues, errs := dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		return nil, errs, tc.DataConflictError
+	}
+
+	query := selectQuery() + where + orderBy
+	log.Debugln("Query is ", query)
+
+	rows, err := db.NamedQuery(query, queryValues)
+	if err != nil {
+		log.Errorf("Error querying Parameters: %v", err)
+		return nil, []error{tc.DBError}, tc.SystemError
+	}
+	defer rows.Close()
+
+	params := []interface{}{}
+	hiddenField := "********"
+	for rows.Next() {
+		var p tc.ParameterNullable
+		if err = rows.StructScan(&p); err != nil {
+			log.Errorf("error parsing pp rows: %v", err)
+			return nil, []error{tc.DBError}, tc.SystemError
+		}
+		var isSecure bool
+		if p.Secure != nil {
+			isSecure = *p.Secure
+		}
+
+		if isSecure && (privLevel < auth.PrivLevelAdmin) {
+			p.Value = &hiddenField
+		}
+		params = append(params, p)
+	}
+
+	return params, []error{}, tc.NoError
+
+}
+
+//The TOProfileParameter implementation of the Updater interface
+//all implementations of Updater should use transactions and return the proper errorType
+//ParsePQUniqueConstraintError is used to determine if a parameter with conflicting values exists
+//if so, it will return an errorType of DataConflict and the type should be appended to the
+//generic error message returned
+func (pp *TOProfileParameter) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
+	rollbackTransaction := true
+	tx, err := db.Beginx()
+	defer func() {
+		if tx == nil || !rollbackTransaction {
+			return
+		}
+		err := tx.Rollback()
+		if err != nil {
+			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
+		}
+	}()
+
+	if err != nil {
+		log.Error.Printf("could not begin transaction: %v", err)
+		return tc.DBError, tc.SystemError
+	}
+	log.Debugf("about to run exec query: %s with parameter: %++v", updateQuery(), pp)
+	resultRows, err := tx.NamedQuery(updateQuery(), pp)
+	if err != nil {
+		if pqErr, ok := err.(*pq.Error); ok {
+			err, eType := dbhelpers.ParsePQUniqueConstraintError(pqErr)
+			if eType == tc.DataConflictError {
+				return errors.New("a parameter with " + err.Error()), eType
+			}
+			return err, eType
+		}
+		log.Errorf("received error: %++v from update execution", err)
+		return tc.DBError, tc.SystemError
+	}
+	defer resultRows.Close()
+
+	// get LastUpdated field -- updated by trigger in the db
+	var lastUpdated tc.TimeNoMod
+	rowsAffected := 0
+	for resultRows.Next() {
+		rowsAffected++
+		if err := resultRows.Scan(&lastUpdated); err != nil {
+			log.Error.Printf("could not scan lastUpdated from insert: %s\n", err)
+			return tc.DBError, tc.SystemError
+		}
+	}
+	log.Debugf("lastUpdated: %++v", lastUpdated)
+	pp.LastUpdated = &lastUpdated
+	if rowsAffected != 1 {
+		if rowsAffected < 1 {
+			return errors.New("no parameter found with this id"), tc.DataMissingError
+		}
+		return fmt.Errorf("this update affected too many rows: %d", rowsAffected), tc.SystemError
+	}
+	err = tx.Commit()
+	if err != nil {
+		log.Errorln("Could not commit transaction: ", err)
+		return tc.DBError, tc.SystemError
+	}
+	rollbackTransaction = false
+	return nil, tc.NoError
+}
+
+//The Parameter implementation of the Deleter interface
+//all implementations of Deleter should use transactions and return the proper errorType
+func (pp *TOProfileParameter) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) {
+	rollbackTransaction := true
+	tx, err := db.Beginx()
+	defer func() {
+		if tx == nil || !rollbackTransaction {
+			return
+		}
+		err := tx.Rollback()
+		if err != nil {
+			log.Errorln(errors.New("rolling back transaction: " + err.Error()))
+		}
+	}()
+
+	if err != nil {
+		log.Error.Printf("could not begin transaction: %v", err)
+		return tc.DBError, tc.SystemError
+	}
+	log.Debugf("about to run exec query: %s with parameter: %++v", deleteQuery(), pp)
+	result, err := tx.NamedExec(deleteQuery(), pp)
+	if err != nil {
+		log.Errorf("received error: %++v from delete execution", err)
+		return tc.DBError, tc.SystemError
+	}
+	rowsAffected, err := result.RowsAffected()
+	if err != nil {
+		return tc.DBError, tc.SystemError
+	}
+	if rowsAffected < 1 {
+		return errors.New("no parameter with that id found"), tc.DataMissingError
+	}
+	if rowsAffected > 1 {
+		return fmt.Errorf("this create affected too many rows: %d", rowsAffected), tc.SystemError
+	}
+
+	err = tx.Commit()
+	if err != nil {
+		log.Errorln("Could not commit transaction: ", err)
+		return tc.DBError, tc.SystemError
+	}
+	rollbackTransaction = false
+	return nil, tc.NoError
+}
+
+func selectQuery() string {
+
+	query := `SELECT
+p.last_updated,
+p.profile,
+p.id,
+p.parameter
+FROM profile_parameter p`
+	return query
+}
+
+func updateQuery() string {
+	query := `UPDATE
+profile_parameter SET
+profile=:profile,
+parameter=:parameter
+WHERE id=:id RETURNING last_updated`
+	return query
+}
+
+func deleteQuery() string {
+	query := `DELETE FROM profile_parameter
+WHERE id=:id`
+	return query
+}
diff --git a/traffic_ops/traffic_ops_golang/region/regions_test.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
similarity index 60%
copy from traffic_ops/traffic_ops_golang/region/regions_test.go
copy to traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
index 3f08cc1..ced1a11 100644
--- a/traffic_ops/traffic_ops_golang/region/regions_test.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters_test.go
@@ -1,4 +1,4 @@
-package region
+package profileparameter
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -32,24 +32,29 @@ import (
 	sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
 )
 
-func getTestRegions() []tc.Region {
-	regions := []tc.Region{}
-	testCase := tc.Region{
-		DivisionName: "west",
-		ID:           1,
-		Name:         "region1",
-		LastUpdated:  tc.TimeNoMod{Time: time.Now()},
+func getTestProfileParameters() []tc.ProfileParameterNullable {
+	pps := []tc.ProfileParameterNullable{}
+	lastUpdated := tc.TimeNoMod{}
+	lastUpdated.Scan(time.Now())
+	profile := 1
+	parameter := 1
+
+	pp := tc.ProfileParameterNullable{
+		LastUpdated: &lastUpdated,
+		Profile:     &profile,
+		Parameter:   &parameter,
 	}
-	regions = append(regions, testCase)
+	pps = append(pps, pp)
 
-	testCase2 := testCase
-	testCase2.Name = "region2"
-	regions = append(regions, testCase2)
+	pp2 := pp
+	pp2.Profile = &profile
+	pp2.Parameter = &parameter
+	pps = append(pps, pp2)
 
-	return regions
+	return pps
 }
 
-func TestReadRegions(t *testing.T) {
+func TestGetProfileParameters(t *testing.T) {
 	mockDB, mock, err := sqlmock.New()
 	if err != nil {
 		t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
@@ -59,50 +64,48 @@ func TestReadRegions(t *testing.T) {
 	db := sqlx.NewDb(mockDB, "sqlmock")
 	defer db.Close()
 
-	refType := GetRefType()
-
-	testRegions := getTestRegions()
-	cols := test.ColsFromStructByTag("db", tc.Region{})
+	testPPs := getTestProfileParameters()
+	cols := test.ColsFromStructByTag("db", tc.ProfileParameterNullable{})
 	rows := sqlmock.NewRows(cols)
 
-	for _, ts := range testRegions {
+	for _, ts := range testPPs {
 		rows = rows.AddRow(
-			ts.Division,
-			ts.ID,
 			ts.LastUpdated,
-			ts.Name,
+			ts.Profile,
+			ts.Parameter,
 		)
 	}
 	mock.ExpectQuery("SELECT").WillReturnRows(rows)
-	v := map[string]string{"dsId": "1"}
+	v := map[string]string{"profile": "1"}
 
-	regions, errs, _ := refType.Read(db, v, auth.CurrentUser{})
+	pps, errs, _ := refType.Read(db, v, auth.CurrentUser{})
 	if len(errs) > 0 {
-		t.Errorf("region.Read expected: no errors, actual: %v", errs)
+		t.Errorf("profileparameter.Read expected: no errors, actual: %v", errs)
 	}
 
-	if len(regions) != 2 {
-		t.Errorf("region.Read expected: len(regions) == 2, actual: %v", len(regions))
+	if len(pps) != 2 {
+		t.Errorf("profileparameter.Read expected: len(pps) == 2, actual: %v", len(pps))
 	}
+
 }
 
 func TestInterfaces(t *testing.T) {
 	var i interface{}
-	i = &TORegion{}
+	i = &TOProfileParameter{}
 
 	if _, ok := i.(api.Creator); !ok {
-		t.Errorf("Region must be Creator")
+		t.Errorf("ProfileParameter must be Creator")
 	}
 	if _, ok := i.(api.Reader); !ok {
-		t.Errorf("Region must be Reader")
+		t.Errorf("ProfileParameter must be Reader")
 	}
 	if _, ok := i.(api.Updater); !ok {
-		t.Errorf("Region must be Updater")
+		t.Errorf("ProfileParameter must be Updater")
 	}
 	if _, ok := i.(api.Deleter); !ok {
-		t.Errorf("Region must be Deleter")
+		t.Errorf("ProfileParameter must be Deleter")
 	}
 	if _, ok := i.(api.Identifier); !ok {
-		t.Errorf("Region must be Identifier")
+		t.Errorf("ProfileParameter must be Identifier")
 	}
 }
diff --git a/traffic_ops/traffic_ops_golang/region/regions_test.go b/traffic_ops/traffic_ops_golang/region/regions_test.go
index 3f08cc1..0720840 100644
--- a/traffic_ops/traffic_ops_golang/region/regions_test.go
+++ b/traffic_ops/traffic_ops_golang/region/regions_test.go
@@ -74,7 +74,7 @@ func TestReadRegions(t *testing.T) {
 		)
 	}
 	mock.ExpectQuery("SELECT").WillReturnRows(rows)
-	v := map[string]string{"dsId": "1"}
+	v := map[string]string{"id": "1"}
 
 	regions, errs, _ := refType.Read(db, v, auth.CurrentUser{})
 	if len(errs) > 0 {

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.

[incubator-trafficcontrol] 12/15: removed unused struct

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e3db33339ac2723cb9c838f754442f4fd280d6a4
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 13:53:27 2018 -0600

    removed unused struct
---
 lib/go-tc/profile_parameters.go | 43 -----------------------------------------
 1 file changed, 43 deletions(-)

diff --git a/lib/go-tc/profile_parameters.go b/lib/go-tc/profile_parameters.go
deleted file mode 100644
index c31eb9f..0000000
--- a/lib/go-tc/profile_parameters.go
+++ /dev/null
@@ -1,43 +0,0 @@
-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.
- */
-
-// ProfileParametersResponse ...
-type ProfileParametersResponse struct {
-	Response []ProfileParameter `json:"response"`
-}
-
-// ProfileParameter ...
-type ProfileParameter struct {
-	LastUpdated TimeNoMod `json:"lastUpdated"`
-	Profile     string    `json:"profile"`
-	ProfileID   int       `json:"profileId"`
-	Parameter   string    `json:"parameter"`
-	ParameterID int       `json:"profileId"`
-}
-
-// ProfileParameterNullable ...
-type ProfileParameterNullable struct {
-	LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
-	Profile     *string    `json:"profile" db:"profile"`
-	ProfileID   *int       `json:"profileId" db:"profile_id"`
-	Parameter   *string    `json:"parameter" db:"parameter"`
-	ParameterID *int       `json:"parameterId" db:"parameter_id"`
-}

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.