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

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

commit 8f6e9085b5e23881c51fc4de9cb082e939e48116
Author: Dewayne Richardson <dewr...@apache.org>
AuthorDate: Mon Feb 19 14:40:38 2018 -0700

    updated to use the CRUD interface
    
    moved the status_test to v13 dir
    
    copied from branch
    
    moved to v13
---
 traffic_ops/testing/api/{ => v13}/region_test.go |  2 +-
 traffic_ops/testing/api/{ => v13}/status_test.go |  2 +-
 traffic_ops/testing/api/v13/tc-fixtures.json     | 26 +++++++
 traffic_ops/traffic_ops_golang/region/regions.go | 92 ++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/traffic_ops/testing/api/region_test.go 
b/traffic_ops/testing/api/v13/region_test.go
similarity index 99%
rename from traffic_ops/testing/api/region_test.go
rename to traffic_ops/testing/api/v13/region_test.go
index 2d0d78a..3ac07c2 100644
--- a/traffic_ops/testing/api/region_test.go
+++ b/traffic_ops/testing/api/v13/region_test.go
@@ -13,7 +13,7 @@
    limitations under the License.
 */
 
-package api
+package v13
 
 import (
        "fmt"
diff --git a/traffic_ops/testing/api/status_test.go 
b/traffic_ops/testing/api/v13/status_test.go
similarity index 99%
rename from traffic_ops/testing/api/status_test.go
rename to traffic_ops/testing/api/v13/status_test.go
index a2ae9fc..199bfc4 100644
--- a/traffic_ops/testing/api/status_test.go
+++ b/traffic_ops/testing/api/v13/status_test.go
@@ -13,7 +13,7 @@
    limitations under the License.
 */
 
-package api
+package v13
 
 import (
        "testing"
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json 
b/traffic_ops/testing/api/v13/tc-fixtures.json
index dc121fd..617de72 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -220,6 +220,32 @@
             "name": "region2"
         }
     ],
+    "statuses": [
+        {
+            "name": "OFFLINE",
+            "description": "Edge: Puts server in CCR config file in this 
state, but CCR will never route traffic to it. Mid: Server will not be included 
in parent.config files for its edge caches"
+        },
+        {
+            "name": "ONLINE",
+            "description": "Edge: Puts server in CCR config file in this 
state, and CCR will always route traffic to it. Mid: Server will be included in 
parent.config files for its edges"
+        },
+        {
+            "name": "REPORTED",
+            "description": "Edge: Puts server in CCR config file in this 
state, and CCR will adhere to the health protocol. Mid: N/A for now"
+        },
+        {
+            "name": "ADMIN_DOWN",
+            "description": "Temporary down. Edge: XMPP client will send status 
OFFLINE to CCR, otherwise similar to REPORTED. Mid: Server will not be included 
in parent.config files for its edge caches"
+        },
+        {
+            "name": "CCR_IGNORE",
+            "description": "Edge: 12M will not include caches in this state in 
CCR config files. Mid: N/A for now"
+        },
+        {
+            "name": "PRE_PROD",
+            "description": "Pre Production. Not active in any configuration."
+        }
+    ],
     "tenants": [
         {
             "active": true,
diff --git a/traffic_ops/traffic_ops_golang/region/regions.go 
b/traffic_ops/traffic_ops_golang/region/regions.go
index 52d881d..331fd2c 100644
--- a/traffic_ops/traffic_ops_golang/region/regions.go
+++ b/traffic_ops/traffic_ops_golang/region/regions.go
@@ -43,8 +43,13 @@ func GetRefType() *TORegion {
 }
 
 //Implementation of the Identifier, Validator interface functions
+<<<<<<< HEAD
 func (region *TORegion) GetID() (int, bool) {
        return region.ID, true
+=======
+func (region *TORegion) GetID() int {
+       return region.ID
+>>>>>>> updated to use the CRUD interface
 }
 
 func (region *TORegion) GetAuditName() string {
@@ -73,16 +78,27 @@ func (region *TORegion) Read(db *sqlx.DB, parameters 
map[string]string, user aut
        // Query Parameters to Database Query column mappings
        // see the fields mapped in the SQL query
        queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+<<<<<<< HEAD
                "name":     dbhelpers.WhereColumnInfo{"r.name", nil},
                "division": dbhelpers.WhereColumnInfo{"r.division", nil},
                "id":       dbhelpers.WhereColumnInfo{"r.id", api.IsInt},
+=======
+               "domainName":    dbhelpers.WhereColumnInfo{"domain_name", nil},
+               "dnssecEnabled": dbhelpers.WhereColumnInfo{"dnssec_enabled", 
nil},
+               "id":            dbhelpers.WhereColumnInfo{"id", api.IsInt},
+               "name":          dbhelpers.WhereColumnInfo{"name", nil},
+>>>>>>> updated to use the CRUD interface
        }
        where, orderBy, queryValues, errs := 
dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
        if len(errs) > 0 {
                return nil, errs, tc.DataConflictError
        }
 
+<<<<<<< HEAD
        query := selectQuery() + where + orderBy
+=======
+       query := selectRegionsQuery() + where + orderBy
+>>>>>>> updated to use the CRUD interface
        log.Debugln("Query is ", query)
 
        rows, err := db.NamedQuery(query, queryValues)
@@ -92,13 +108,18 @@ func (region *TORegion) Read(db *sqlx.DB, parameters 
map[string]string, user aut
        }
        defer rows.Close()
 
+<<<<<<< HEAD
        regions := []interface{}{}
+=======
+       Regions := []interface{}{}
+>>>>>>> updated to use the CRUD interface
        for rows.Next() {
                var s tc.Region
                if err = rows.StructScan(&s); err != nil {
                        log.Errorf("error parsing Region rows: %v", err)
                        return nil, []error{tc.DBError}, tc.SystemError
                }
+<<<<<<< HEAD
                regions = append(regions, s)
        }
 
@@ -115,6 +136,23 @@ r.last_updated,
 r.name
 FROM region r
 JOIN division d ON r.division = d.id`
+=======
+               Regions = append(Regions, s)
+       }
+
+       return Regions, []error{}, tc.NoError
+}
+
+func selectRegionsQuery() string {
+       query := `SELECT
+description,
+division,
+id,
+last_updated,
+name
+
+FROM region r`
+>>>>>>> updated to use the CRUD interface
        return query
 }
 
@@ -149,9 +187,16 @@ func (region *TORegion) Update(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
                                return errors.New("a region with " + 
err.Error()), eType
                        }
                        return err, eType
+<<<<<<< HEAD
                }
                log.Errorf("received error: %++v from update execution", err)
                return tc.DBError, tc.SystemError
+=======
+               } else {
+                       log.Errorf("received error: %++v from update 
execution", err)
+                       return tc.DBError, tc.SystemError
+               }
+>>>>>>> updated to use the CRUD interface
        }
        defer resultRows.Close()
 
@@ -169,8 +214,14 @@ func (region *TORegion) Update(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
        if rowsAffected != 1 {
                if rowsAffected < 1 {
                        return errors.New("no region found with this id"), 
tc.DataMissingError
+<<<<<<< HEAD
                }
                return fmt.Errorf("this update affected too many rows: %d", 
rowsAffected), tc.SystemError
+=======
+               } else {
+                       return fmt.Errorf("this update affected too many rows: 
%d", rowsAffected), tc.SystemError
+               }
+>>>>>>> updated to use the CRUD interface
        }
        err = tx.Commit()
        if err != nil {
@@ -181,14 +232,23 @@ func (region *TORegion) Update(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
        return nil, tc.NoError
 }
 
+<<<<<<< HEAD
 //The TORegion implementation of the Creator interface
 //all implementations of Creator should use transactions and return the proper 
errorType
+=======
+//The TORegion implementation of the Inserter interface
+//all implementations of Inserter should use transactions and return the 
proper errorType
+>>>>>>> updated to use the CRUD interface
 //ParsePQUniqueConstraintError is used to determine if a region 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 id and lastUpdated values of the newly inserted 
region and have
 //to be added to the struct
+<<<<<<< HEAD
 func (region *TORegion) Create(db *sqlx.DB, user auth.CurrentUser) (error, 
tc.ApiErrorType) {
+=======
+func (region *TORegion) Insert(db *sqlx.DB, user auth.CurrentUser) (error, 
tc.ApiErrorType) {
+>>>>>>> updated to use the CRUD interface
        rollbackTransaction := true
        tx, err := db.Beginx()
        defer func() {
@@ -213,9 +273,16 @@ func (region *TORegion) Create(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
                                return errors.New("a region with " + 
err.Error()), eType
                        }
                        return err, eType
+<<<<<<< HEAD
                }
                log.Errorf("received non pq error: %++v from create execution", 
err)
                return tc.DBError, tc.SystemError
+=======
+               } else {
+                       log.Errorf("received non pq error: %++v from create 
execution", err)
+                       return tc.DBError, tc.SystemError
+               }
+>>>>>>> updated to use the CRUD interface
        }
        defer resultRows.Close()
 
@@ -233,8 +300,12 @@ func (region *TORegion) Create(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
                err = errors.New("no region was inserted, no id was returned")
                log.Errorln(err)
                return tc.DBError, tc.SystemError
+<<<<<<< HEAD
        }
        if rowsAffected > 1 {
+=======
+       } else if rowsAffected > 1 {
+>>>>>>> updated to use the CRUD interface
                err = errors.New("too many ids returned from region insert")
                log.Errorln(err)
                return tc.DBError, tc.SystemError
@@ -279,6 +350,7 @@ func (region *TORegion) Delete(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
        if err != nil {
                return tc.DBError, tc.SystemError
        }
+<<<<<<< HEAD
        if rowsAffected < 1 {
                return errors.New("no region with that id found"), 
tc.DataMissingError
        }
@@ -286,6 +358,15 @@ func (region *TORegion) Delete(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
                return fmt.Errorf("this create affected too many rows: %d", 
rowsAffected), tc.SystemError
        }
 
+=======
+       if rowsAffected != 1 {
+               if rowsAffected < 1 {
+                       return errors.New("no region with that id found"), 
tc.DataMissingError
+               } else {
+                       return fmt.Errorf("this create affected too many rows: 
%d", rowsAffected), tc.SystemError
+               }
+       }
+>>>>>>> updated to use the CRUD interface
        err = tx.Commit()
        if err != nil {
                log.Errorln("Could not commit transaction: ", err)
@@ -298,6 +379,10 @@ func (region *TORegion) Delete(db *sqlx.DB, user 
auth.CurrentUser) (error, tc.Ap
 func updateQuery() string {
        query := `UPDATE
 region SET
+<<<<<<< HEAD
+=======
+description=:description,
+>>>>>>> updated to use the CRUD interface
 division=:division,
 name=:name
 WHERE id=:id RETURNING last_updated`
@@ -306,8 +391,15 @@ WHERE id=:id RETURNING last_updated`
 
 func insertQuery() string {
        query := `INSERT INTO region (
+<<<<<<< HEAD
+division,
+name) VALUES (
+=======
+description,
 division,
 name) VALUES (
+:description,
+>>>>>>> updated to use the CRUD interface
 :division,
 :name) RETURNING id,last_updated`
        return query

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

Reply via email to