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 2017/01/18 18:58:57 UTC

[1/2] incubator-trafficcontrol git commit: remove go programs for mysql init

Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master 03610c8fb -> 64c595513


remove go programs for mysql init


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/43216a44
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/43216a44
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/43216a44

Branch: refs/heads/master
Commit: 43216a441e13817fe02bcc7b6d713f6230858fd6
Parents: 03610c8
Author: Dan Kirkwood <da...@gmail.com>
Authored: Wed Jan 18 09:13:41 2017 -0700
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Wed Jan 18 09:13:41 2017 -0700

----------------------------------------------------------------------
 .../go/src/comcast.com/create_db/create_db.go   | 172 -------
 .../go/src/comcast.com/csv2json/csv2json.go     | 167 -------
 .../go/src/comcast.com/dataload/dataload.go     | 477 -------------------
 .../go/src/comcast.com/systemtest/systemtest.go | 285 -----------
 4 files changed, 1101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/43216a44/traffic_ops/install/go/src/comcast.com/create_db/create_db.go
----------------------------------------------------------------------
diff --git a/traffic_ops/install/go/src/comcast.com/create_db/create_db.go b/traffic_ops/install/go/src/comcast.com/create_db/create_db.go
deleted file mode 100644
index b239a4d..0000000
--- a/traffic_ops/install/go/src/comcast.com/create_db/create_db.go
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
-
-     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 main
-
-import (
-	"database/sql"
-	"encoding/json"
-	"fmt"
-	"os"
-
-	_ "github.com/go-sql-driver/mysql"
-)
-
-type Configuration struct {
-	Description string `json:"description"`
-	DbName      string `json:"dbname"`
-	DbHostname  string `json:"hostname"`
-	DbUser      string `json:"user"`
-	DbPassword  string `json:"password"`
-	DbPort      string `json:"port"`
-	DbType      string `json:"type"`
-}
-
-func main() {
-	//use command line args
-	var adminUser string
-	var adminPassword string
-	if len(os.Args) != 3 {
-		fmt.Println("Usage ./create_db AdminUserName AdminPassword")
-		os.Exit(1)
-	} else {
-		adminUser = os.Args[1]
-		adminPassword = os.Args[2]
-	}
-
-	//read prop file for database credentials
-	//file, _ := os.Open("conf/database.conf")
-	file, _ := os.Open("/opt/traffic_ops/app/conf/production/database.conf")
-	decoder := json.NewDecoder(file)
-	configuration := Configuration{}
-	err := decoder.Decode(&configuration)
-	if err != nil {
-		fmt.Println("error:", err)
-	}
-	dbHostname := configuration.DbHostname
-	dbUsername := configuration.DbUser
-	dbPassword := configuration.DbPassword
-	dbPort := configuration.DbPort
-	dbName := configuration.DbName
-	debug := false
-
-	//connect to DB
-	connectString := adminUser + ":" + adminPassword + "@" + "tcp(" + dbHostname + ":" + dbPort + ")" + "/mysql"
-	if debug {
-		fmt.Println("connect string:" + connectString)
-	}
-
-	db, err := sql.Open("mysql", connectString)
-	if err != nil {
-		fmt.Println("An error occurred")
-		panic(err)
-	}
-	err = db.Ping()
-	if err != nil {
-		fmt.Println("Can't ping the database")
-		panic(err)
-	}
-	//create database
-	connectString = adminUser + ":" + adminPassword + "@" + "tcp(" + dbHostname + ":" + dbPort + ")" + "/mysql"
-	if debug {
-		fmt.Println("connect string:" + connectString)
-	}
-
-	db, err = sql.Open("mysql", connectString)
-	if err != nil {
-		fmt.Println("An error occurred")
-		panic(err)
-	}
-	err = db.Ping()
-	if err != nil {
-		fmt.Println("Can't ping the database")
-		panic(err)
-	}
-
-	fmt.Println("Creating database...")
-	createResult, err := db.Exec("create database if not exists " + dbName)
-	if err != nil {
-		fmt.Println("An error occured creating the database")
-		panic(err)
-	}
-	if debug {
-		fmt.Println("the database create result was", createResult)
-	}
-
-	fmt.Println("Creating user...")
-	createResult, err = db.Exec("GRANT ALL PRIVILEGES ON " + dbName + ".* TO '" + dbUsername + "'@'%' IDENTIFIED BY '" + dbPassword + "' WITH GRANT OPTION")
-	if err != nil {
-		fmt.Println("An error occurred creating the user")
-		panic(err)
-	}
-
-	createResult, err = db.Exec("GRANT ALL PRIVILEGES ON " + dbName + ".* TO '" + dbUsername + "'@'localhost' IDENTIFIED BY '" + dbPassword + "' WITH GRANT OPTION")
-	if err != nil {
-		fmt.Println("An error occurred granting privs")
-		panic(err)
-	}
-
-	fmt.Println("Flushing privileges...")
-	createResult, err = db.Exec("flush privileges")
-	if err != nil {
-		fmt.Println("An error occurred flushing privileges")
-		panic(err)
-	}
-	//create schema
-	// fmt.Println("Creating schema...")
-	// createResult, err = db.Exec("use twelve_monkeys")
-	// if err != nil {
-	// 	fmt.Println("An error occured setting the database to use")
-	// 	panic(err)
-	// }
-	// //	//TODO Couldn't get this to work via the commented-out attempts;
-	// //	createResult, err = db.Exec("source /opt/traffic_ops/install/schema.sql")
-	// //	if err != nil {
-	// //		fmt.Println("An error occured creating the schema", err)
-	// //	}
-	// output, err := exec.Command("/bin/bash", "-c", "mysql --user="+adminUser+" --password="+adminPassword+" "+dbName+" < /opt/traffic_ops/install/data/sql/schema.sql").Output()
-	// if err != nil {
-	// 	println("exec error:  " + err.Error())
-	// 	panic(err)
-	// } else {
-	// 	fmt.Println(string(output))
-	// }
-
-	// if debug {
-	// 	fmt.Println("createResult: ", createResult)
-	// }
-
-	err = db.Close()
-	if err != nil {
-		fmt.Println("couldn't close the database connection")
-		panic(err)
-	}
-	//connect to newly created database
-	connectString = dbUsername + ":" + dbPassword + "@" + "tcp(" + dbHostname + ":" + dbPort + ")" + "/" + dbName
-	if debug {
-		fmt.Println("new connect string:" + connectString)
-	}
-
-	db, err = sql.Open("mysql", connectString)
-	if err != nil {
-		fmt.Println("Couldnt create db handle")
-		panic(err)
-	}
-	err = db.Ping()
-	if err != nil {
-		fmt.Println("Can't ping the new database")
-		panic(err)
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/43216a44/traffic_ops/install/go/src/comcast.com/csv2json/csv2json.go
----------------------------------------------------------------------
diff --git a/traffic_ops/install/go/src/comcast.com/csv2json/csv2json.go b/traffic_ops/install/go/src/comcast.com/csv2json/csv2json.go
deleted file mode 100755
index 7287467..0000000
--- a/traffic_ops/install/go/src/comcast.com/csv2json/csv2json.go
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
-
-     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 main
-
-import (
-	"encoding/csv"
-	"encoding/json"
-	"fmt"
-	"io"
-	"os"
-)
-
-type Profile struct {
-	Name        string `json:"name"`
-	Description string `json:"description"`
-}
-
-type Parameter struct {
-	Name        string `json:"name"`
-	Config_File string `json:"config_file"`
-	Value       string `json:"value"`
-}
-
-type ProfileParameter struct {
-	Profile    string `json:"profile"`
-	Parameter  string `json:"parameter"`
-	ConfigFile string `json:"config_file"`
-	Value      string `json:"value"`
-}
-
-func main() {
-	createProfileData()
-	createParameterData()
-	createProfileParameterData()
-}
-
-func writeToFile(message []byte, fileName string) {
-	f, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0755)
-	if err != nil {
-		fmt.Println(err)
-		return
-	}
-	s := string(message) + "\n"
-	n, err := io.WriteString(f, s)
-	if err != nil {
-		fmt.Println(n, err)
-		return
-	}
-	f.Close()
-}
-
-func check(e error) {
-	if e != nil {
-		panic(e)
-	}
-}
-
-//TODO:  break out reading of csv file into it's own func
-
-func createProfileData() {
-	fileName := "/opt/traffic_ops/install/data/csv/profile.csv"
-	fmt.Println("converting profile data json csv")
-	file, err := os.Open(fileName)
-	if err != nil {
-		fmt.Println("Error:", err)
-		return
-	}
-	// automatically call Close() at the end of current method
-	defer file.Close()
-	reader := csv.NewReader(file)
-	reader.Comma = ','
-	lineCount := 0
-	for {
-		record, err := reader.Read()
-		// end-of-file is fitted into err
-		if err == io.EOF {
-			break
-		} else if err != nil {
-			fmt.Println("Error:", err)
-			return
-		}
-		fmt.Println("name", record[0], "description", record[1])
-		//convert to json
-		p := Profile{record[0], record[1]}
-		b, err := json.Marshal(p)
-		//write json file
-		writeToFile(b, "/opt/traffic_ops/install/data/json/profile.json")
-		lineCount += 1
-	}
-}
-
-func createParameterData() {
-	fileName := "/opt/traffic_ops/install/data/csv/parameter.csv"
-	fmt.Println("converting parameter data json csv")
-	file, err := os.Open(fileName)
-	if err != nil {
-		fmt.Println("Error:", err)
-		return
-	}
-	// automatically call Close() at the end of current method
-	defer file.Close()
-	reader := csv.NewReader(file)
-	reader.Comma = ','
-	lineCount := 0
-	for {
-		record, err := reader.Read()
-		// end-of-file is fitted into err
-		if err == io.EOF {
-			break
-		} else if err != nil {
-			fmt.Println("Error:", err)
-			return
-		}
-		fmt.Println("name=", record[0], "config_file=", record[1], "value=", record[2])
-		//convert to json
-		p := Parameter{record[0], record[1], record[2]}
-		b, err := json.Marshal(p)
-		//write json file
-		writeToFile(b, "/opt/traffic_ops/install/data/json/parameter.json")
-		lineCount += 1
-	}
-}
-
-func createProfileParameterData() {
-	fileName := "/opt/traffic_ops/install/data/csv/profile_parameter.csv"
-	fmt.Println("converting profile_parameter data json csv")
-	file, err := os.Open(fileName)
-	if err != nil {
-		fmt.Println("Error:", err)
-		return
-	}
-	// automatically call Close() at the end of current method
-	defer file.Close()
-	reader := csv.NewReader(file)
-	reader.Comma = ','
-	lineCount := 0
-	for {
-		record, err := reader.Read()
-		// end-of-file is fitted into err
-		if err == io.EOF {
-			break
-		} else if err != nil {
-			fmt.Println("Error:", err)
-			return
-		}
-		fmt.Println("profile=", record[0], "parameter=", record[1], "config_file=", record[2], "value", record[3])
-		//convert to json
-		p := ProfileParameter{record[0], record[1], record[2], record[3]}
-		b, err := json.Marshal(p)
-		//write json file
-		writeToFile(b, "/opt/traffic_ops/install/data/json/profile_parameter.json")
-		lineCount += 1
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/43216a44/traffic_ops/install/go/src/comcast.com/dataload/dataload.go
----------------------------------------------------------------------
diff --git a/traffic_ops/install/go/src/comcast.com/dataload/dataload.go b/traffic_ops/install/go/src/comcast.com/dataload/dataload.go
deleted file mode 100644
index 15549b5..0000000
--- a/traffic_ops/install/go/src/comcast.com/dataload/dataload.go
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
-
-   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 main
-
-import (
-	"database/sql"
-	"encoding/json"
-	"fmt"
-	"io"
-	"os"
-
-	_ "github.com/go-sql-driver/mysql"
-)
-
-// Configuration contains parameters needed to connect to the Traffic Ops Database.
-type Configuration struct {
-	Description string `json:"description"`
-	DbName      string `json:"dbname"`
-	DbHostname  string `json:"hostname"`
-	DbUser      string `json:"user"`
-	DbPassword  string `json:"password"`
-	DbPort      string `json:"port"`
-	DbType      string `json:"type"`
-}
-
-func loadCdn(db *sql.DB, dbName string) (sql.Result, error) {
-	fmt.Println("Seeding cdn data...")
-
-	file, err := os.Open("/opt/traffic_ops/install/data/json/cdn.json")
-	if err != nil {
-		return nil, err
-	}
-
-	type cdnData struct {
-		Name string `json:"name"`
-	}
-	var c cdnData
-	if err := json.NewDecoder(file).Decode(&c); err != nil && err != io.EOF {
-		return nil, err
-	}
-
-	fmt.Printf("\t Inserting cdn: %+v \n", c)
-	cdn, err := db.Exec("insert ignore into "+dbName+".cdn (name) values (?)", c.Name)
-	if err != nil {
-		fmt.Println("\t An error occured inserting cdn with name ", c.Name)
-		return nil, err
-	}
-	return cdn, nil
-}
-
-func loadProfile(db *sql.DB, dbName string) error {
-	fmt.Println("Seeding profile data...")
-
-	stmt, err := db.Prepare("insert ignore into " + dbName + ".profile (name, description) values (?,?)")
-	if err != nil {
-		fmt.Println("Couldn't prepare profile insert statment")
-		return err
-	}
-
-	file, err := os.Open("/opt/traffic_ops/install/data/json/profile.json")
-	if err != nil {
-		return err
-	}
-	decoder := json.NewDecoder(file)
-
-	type profileData struct {
-		Name        string `json:"name"`
-		Description string `json:"description"`
-	}
-
-	for {
-		var p profileData
-		if err = decoder.Decode(&p); err == io.EOF {
-			break
-		} else if err != nil {
-			return err
-		}
-
-		fmt.Printf("\t Inserting profile: %+v \n", p)
-		_, err = stmt.Exec(p.Name, p.Description)
-		if err != nil {
-			fmt.Println("\t An error occured inserting profile with name ", p.Name)
-			return err
-		}
-	}
-	return nil
-}
-
-func loadParameter(db *sql.DB, dbName string) error {
-	fmt.Println("Seeding parameter data...")
-
-	stmt, err := db.Prepare("insert ignore into " + dbName + ".parameter (name, config_file, value) values (?,?,?)")
-	if err != nil {
-		fmt.Println("Couldn't prepare parameter insert statment")
-		return err
-	}
-
-	file, err := os.Open("/opt/traffic_ops/install/data/json/parameter.json")
-	if err != nil {
-		return err
-	}
-	decoder := json.NewDecoder(file)
-
-	type parameterData struct {
-		Name       string `json:"name"`
-		ConfigFile string `json:"config_file"`
-		Value      string `json:"value"`
-	}
-
-	for {
-		var p parameterData
-		if err = decoder.Decode(&p); err == io.EOF {
-			break
-		} else if err != nil {
-			return err
-		}
-
-		query := "select count(name) from " + dbName + ".parameter where name = ? and config_file = ? and value = ?"
-		rows, err := db.Query(query, p.Name, p.ConfigFile, p.Value)
-		if err != nil {
-			return err
-		}
-		defer rows.Close()
-
-		var count int
-		for rows.Next() {
-			if err := rows.Scan(&count); err != nil {
-				return err
-			}
-		}
-
-		if count != 0 {
-			fmt.Printf("\t Parameter already exists: %+v \n", p)
-			count = 0
-		} else {
-			fmt.Printf("\t Inserting parameter: %+v \n", p)
-			_, err = stmt.Exec(p.Name, p.ConfigFile, p.Value)
-			if err != nil {
-				fmt.Println("\t An error occured inserting parameter with name ", p.Name)
-				return err
-			}
-		}
-	}
-	return nil
-}
-
-func loadProfileParameter(db *sql.DB, dbName string) error {
-	fmt.Println("Seeding profile_parameter data...")
-
-	stmt, err := db.Prepare("insert ignore into " + dbName + ".profile_parameter (profile, parameter) values ((select id from profile where name = ?), (select id from parameter where name = ? and config_file = ? and value = ?))")
-	if err != nil {
-		fmt.Println("Couldn't prepare profile_parameter insert statment")
-		return err
-	}
-
-	file, err := os.Open("/opt/traffic_ops/install/data/json/profile_parameter.json")
-	if err != nil {
-		return err
-	}
-	decoder := json.NewDecoder(file)
-
-	type profileParameterData struct {
-		Profile    string `json:"profile"`
-		Parameter  string `json:"parameter"`
-		ConfigFile string `json:"config_file"`
-		Value      string `json:"value"`
-	}
-
-	for {
-		var p profileParameterData
-		if err = decoder.Decode(&p); err == io.EOF {
-			break
-		} else if err != nil {
-			return err
-		}
-
-		query := "select count(profile) from " + dbName + ".profile_parameter where profile = (select id from profile where name = ?) and parameter = (select id from parameter where name = ? and config_file = ? and value = ?)"
-		rows, err := db.Query(query, p.Profile, p.Parameter, p.ConfigFile, p.Value)
-		if err != nil {
-			return err
-		}
-		defer rows.Close()
-
-		var count int
-		for rows.Next() {
-			if err := rows.Scan(&count); err != nil {
-				return err
-			}
-		}
-
-		if count != 0 {
-			fmt.Printf("\t Profile Parameter combination already exists:  %+v \n", p)
-			count = 0
-		} else {
-			fmt.Printf("\t Inserting profile parameter: %+v \n", p)
-			_, err = stmt.Exec(p.Profile, p.Parameter, p.ConfigFile, p.Value)
-			if err != nil {
-				fmt.Println("\t An error occured inserting profile parameter with profile", p.Profile, "parameter", p.Parameter)
-				return err
-			}
-		}
-	}
-	return nil
-}
-
-func loadType(db *sql.DB, dbName string) error {
-	fmt.Println("Seeding type data...")
-
-	stmt, err := db.Prepare("insert ignore into " + dbName + ".type (name, description, use_in_table) values (?,?,?)")
-	if err != nil {
-		fmt.Println("Couldn't prepare type insert statment")
-		return err
-	}
-
-	file, err := os.Open("/opt/traffic_ops/install/data/json/type.json")
-	if err != nil {
-		return err
-	}
-	decoder := json.NewDecoder(file)
-
-	type typeData struct {
-		Name        string `json:"name"`
-		Description string `json:"description"`
-		UseInTable  string `json:"use_in_table"`
-	}
-
-	for {
-		var t typeData
-		if err = decoder.Decode(&t); err == io.EOF {
-			break
-		} else if err != nil {
-			return err
-		}
-
-		fmt.Printf("\t Inserting type: %+v \n", t)
-		_, err = stmt.Exec(t.Name, t.Description, t.UseInTable)
-		if err != nil {
-			fmt.Println("\t An error occured inserting type with name ", t.Name)
-			return err
-		}
-	}
-	return nil
-}
-
-func loadStatus(db *sql.DB, dbName string) error {
-	fmt.Println("Seeding status data...")
-
-	stmt, err := db.Prepare("insert ignore into " + dbName + ".status (name, description) values (?,?)")
-	if err != nil {
-		fmt.Println("Couldn't prepare status insert statment")
-		panic(err)
-	}
-
-	file, err := os.Open("/opt/traffic_ops/install/data/json/status.json")
-	if err != nil {
-		return err
-	}
-	decoder := json.NewDecoder(file)
-
-	type statusData struct {
-		Name        string `json:"name"`
-		Description string `json:"description"`
-	}
-
-	for {
-		var s statusData
-		if err = decoder.Decode(&s); err == io.EOF {
-			break
-		} else if err != nil {
-			return err
-		}
-
-		fmt.Printf("\t Inserting status: %+v \n", s)
-		_, err = stmt.Exec(s.Name, s.Description)
-		if err != nil {
-			fmt.Println("\t An error occured inserting status with name ", s.Name)
-			return err
-		}
-	}
-	return nil
-}
-
-func loadCustomParams(db *sql.DB, dbName string) error {
-	fmt.Println("creating custom parameters...")
-
-	//setup constants
-	var (
-		tmInfoURL              = "tm.infourl"
-		coverageZonePollingURL = "coveragezone.polling.url"
-		geoLocationPollingURL  = "geolocation.polling.url"
-		domainName             = "domain_name"
-		tmURL                  = "tm.url"
-		geoLocation6PollingURL = "geolocation6.polling.url"
-		crConfig               = "CRConfig.json"
-	)
-
-	updateParam, err := db.Prepare("UPDATE parameter SET value=? WHERE name = ? and config_file = ?")
-	if err != nil {
-		return err
-	}
-
-	file, err := os.Open("/opt/traffic_ops/install/data/json/post_install.json")
-	if err != nil {
-		return err
-	}
-	decoder := json.NewDecoder(file)
-
-	type customParams struct {
-		TmInfoURL              string `json:"tminfo.url"`
-		CoverageZonePollingURL string `json:"coveragezone.polling.url"`
-		GeoLocationPollingURL  string `json:"geolocation.polling.url"`
-		DomainName             string `json:"domainname"`
-		TmURL                  string `json:"tmurl.url"`
-		GeoLocation6PollingURL string `json:"geolocation6.polling.url"`
-	}
-
-	for {
-		var c customParams
-		if err = decoder.Decode(&c); err != nil {
-			return err
-		}
-
-		tx, err := db.Begin()
-		if err != nil {
-			return err
-		}
-
-		fmt.Printf("\t Inserting custom param: value=%s, name=global, config_file=%s \n", c.TmInfoURL, tmInfoURL)
-		_, err = tx.Stmt(updateParam).Exec(c.TmInfoURL, "global", tmInfoURL)
-		if err != nil {
-			fmt.Println("\t An error occured inserting parameter for", tmInfoURL, " with a value of ", c.TmInfoURL)
-			return err
-		}
-
-		fmt.Printf("\t Inserting custom param: value=%s, name=%s, config_file=%s \n", c.CoverageZonePollingURL, crConfig, coverageZonePollingURL)
-		_, err = tx.Stmt(updateParam).Exec(c.CoverageZonePollingURL, crConfig, coverageZonePollingURL)
-		if err != nil {
-			fmt.Println("\t An error occured inserting parameter for", coverageZonePollingURL, " with a value of ", c.CoverageZonePollingURL)
-			return err
-		}
-
-		fmt.Printf("\t Inserting custom param: value=%s, name=%s, config_file=%s \n", c.GeoLocationPollingURL, crConfig, geoLocationPollingURL)
-		_, err = tx.Stmt(updateParam).Exec(c.GeoLocationPollingURL, crConfig, geoLocationPollingURL)
-		if err != nil {
-			fmt.Println("\t An error occured inserting paramter for", geoLocationPollingURL, " with a value of ", c.GeoLocationPollingURL)
-			return err
-		}
-
-		fmt.Printf("\t Inserting custom param: value=%s, name=%s, config_file=%s \n", c.DomainName, crConfig, domainName)
-		_, err = tx.Stmt(updateParam).Exec(c.DomainName, crConfig, domainName)
-		if err != nil {
-			fmt.Println("\t An error occured inserting paramter for", domainName, " with a value of ", c.DomainName)
-			return err
-		}
-
-		fmt.Printf("\t Inserting custom param: value=%s, name=global, config_file=%s \n", c.TmURL, tmURL)
-		_, err = tx.Stmt(updateParam).Exec(c.TmURL, "global", tmURL)
-		if err != nil {
-			fmt.Println("\t An error occured inserting paramter for", tmURL, " with a value of ", c.TmURL)
-			return err
-		}
-
-		fmt.Printf("\t Inserting custom param: value=%s, name=%s, config_file=%s \n", c.GeoLocation6PollingURL, crConfig, geoLocation6PollingURL)
-		_, err = tx.Stmt(updateParam).Exec(c.GeoLocation6PollingURL, crConfig, geoLocation6PollingURL)
-		if err != nil {
-			fmt.Println("\t An error occured inserting paramter for", geoLocation6PollingURL, " with a value of ", c.GeoLocation6PollingURL)
-			return err
-		}
-
-		if err = tx.Commit(); err != nil {
-			return err
-		}
-	}
-}
-
-func loadUsers(db *sql.DB, dbName string) error {
-	fmt.Println("Adding default user data")
-	file, err := os.Open("/opt/traffic_ops/install/data/json/users.json") //should probably rename this file to be more meaningful
-	if err != nil {
-		return err
-	}
-
-	type users struct {
-		Username string `json:"username"`
-		Password string `json:"password"`
-	}
-	decoder := json.NewDecoder(file)
-
-	for {
-		var u users
-		if err = decoder.Decode(&u); err == io.EOF {
-			break
-		} else if err != nil {
-			return err
-		}
-
-		query := "insert ignore into " + dbName + ".tm_user (username, role, local_passwd, new_user) values (?,(select id from role where name = ?), ?, 1)"
-		_, err = db.Exec(query, u.Username, "admin", u.Password)
-		if err != nil {
-			fmt.Println("\t An error occured inserting user with name ", u.Username)
-			return err
-		}
-	}
-	return nil
-}
-
-func main() {
-	//read prop file for database credentials
-	file, err := os.Open("/opt/traffic_ops/app/conf/production/database.conf")
-	if err != nil {
-		panic(err)
-	}
-	decoder := json.NewDecoder(file)
-
-	var c Configuration
-	if err = decoder.Decode(&c); err != nil {
-		panic(err)
-	}
-
-	debug := false
-
-	//connect to database
-	connectString := c.DbUser + ":" + c.DbPassword + "@" + "tcp(" + c.DbHostname + ":" + c.DbPort + ")" + "/" + c.DbName
-	if debug {
-		fmt.Println("new connect string:" + connectString)
-	}
-
-	db, err := sql.Open("mysql", connectString)
-	if err != nil {
-		fmt.Println("Couldnt create db handle")
-		panic(err)
-	}
-
-	if err = db.Ping(); err != nil {
-		fmt.Println("Can't ping the new database")
-		panic(err)
-	}
-
-	// read cdn json file
-	_, err = loadCdn(db, c.DbName)
-	if err != nil {
-		fmt.Println(err)
-	}
-
-	// read type json file
-	if err = loadType(db, c.DbName); err != nil {
-		fmt.Println(err)
-	}
-
-	// read status json file
-	if err = loadStatus(db, c.DbName); err != nil {
-		fmt.Println(err)
-	}
-
-	// read params json file
-	if err = loadCustomParams(db, c.DbName); err != nil {
-		fmt.Println(err)
-	}
-
-	// read params json file
-	if err = loadUsers(db, c.DbName); err != nil {
-		fmt.Println(err)
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/43216a44/traffic_ops/install/go/src/comcast.com/systemtest/systemtest.go
----------------------------------------------------------------------
diff --git a/traffic_ops/install/go/src/comcast.com/systemtest/systemtest.go b/traffic_ops/install/go/src/comcast.com/systemtest/systemtest.go
deleted file mode 100644
index d3cc480..0000000
--- a/traffic_ops/install/go/src/comcast.com/systemtest/systemtest.go
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
-
-   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 main
-
-import (
-	"bytes"
-	"crypto/tls"
-	"errors"
-	"fmt"
-	"golang.org/x/net/html"
-	"golang.org/x/net/publicsuffix"
-	"io"
-	"net/http"
-	"net/http/cookiejar"
-	"net/url"
-	"os"
-	"strconv"
-)
-
-const (
-	LANDING_PAGE_TITLE    = "Edge Health"
-	PROFILES_PAGE_TITLE   = "Profiles"
-	PARAMETERS_PAGE_TITLE = "Parameters"
-)
-
-var verbose bool
-
-//TODO
-// Command-line switches, default host to localhost and verbose to false
-// Prompt for password if not supplied
-// Optionally use generated cert
-
-func main() {
-	var host string
-	var username string
-	var password string
-	if len(os.Args) != 5 {
-		fmt.Println("Usage ./systemtest host username password verbose-flag")
-		os.Exit(1)
-	}
-
-	host = os.Args[1]
-	username = os.Args[2]
-	password = os.Args[3]
-	var err error
-	verbose, err = strconv.ParseBool(os.Args[4])
-	if err != nil {
-		fmt.Println("Usage ./systemtest host username password verbose-flag")
-		os.Exit(1)
-	}
-
-	if verbose {
-		fmt.Println("host:", host, "username:", username, "password:", password, "verbose:", verbose)
-	}
-
-	options := cookiejar.Options{
-		PublicSuffixList: publicsuffix.List,
-	}
-	jar, err := cookiejar.New(&options)
-	if err != nil {
-		fmt.Println("Error creating cookie jar:", err)
-		os.Exit(1)
-	}
-
-	tr := &http.Transport{
-		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
-	}
-
-	client := &http.Client{Transport: tr, Jar: jar}
-
-	site := "https://" + host
-
-	testOkay := true
-
-	err = Login(client, site, username, password)
-	if err == nil {
-		fmt.Println("Login:           Ok")
-	} else {
-		testOkay = false
-		fmt.Printf("Login:           %s\n", err)
-	}
-
-	err = GetProfiles(client, site)
-	if err == nil {
-		fmt.Println("Get Profiles:    Ok")
-	} else {
-		testOkay = false
-		fmt.Printf("Get Profiles:    %s\n", err)
-	}
-
-	err = GetParameters(client, site)
-	if err == nil {
-		fmt.Println("Get Parameters:  Ok")
-	} else {
-		testOkay = false
-		fmt.Printf("Get Parameters:  %s\n", err)
-	}
-
-	if !testOkay {
-		os.Exit(1)
-	}
-}
-
-func Login(client *http.Client, site string, username string, password string) error {
-	data := url.Values{}
-	data.Set("u", username)
-	data.Add("p", password)
-
-	url, err := url.ParseRequestURI(site)
-	if err != nil {
-		return err
-	}
-
-	url.Path = "/login/"
-
-	header := make(http.Header)
-	header.Add("Content-Type", "application/x-www-form-urlencoded")
-	header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
-
-	respBody, err := DoRequest(client, url, "POST", header, data)
-	if err != nil {
-		return err
-	}
-
-	defer respBody.Close()
-
-	doc, err := html.Parse(respBody)
-	if err != nil {
-		return err
-	}
-
-	if verbose {
-		fmt.Println("HTML doc parsed ok", "type:", doc.Type, "data:", doc.Data)
-	}
-
-	err = CheckHtml(doc, LANDING_PAGE_TITLE)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func GetProfiles(client *http.Client, site string) error {
-	url, err := url.ParseRequestURI(site)
-	if err != nil {
-		return err
-	}
-
-	url.Path = "/profiles"
-
-	respBody, err := DoRequest(client, url, "GET", nil, nil)
-	if err != nil {
-		return err
-	}
-
-	url.Path = "/profiles"
-
-	defer respBody.Close()
-
-	doc, err := html.Parse(respBody)
-	if err != nil {
-		return err
-	}
-
-	if verbose {
-		fmt.Println("HTML doc parsed ok", "type:", doc.Type, "data:", doc.Data)
-	}
-
-	err = CheckHtml(doc, PROFILES_PAGE_TITLE)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func GetParameters(client *http.Client, site string) error {
-	url, err := url.ParseRequestURI(site)
-	if err != nil {
-		return err
-	}
-
-	url.Path = "/parameters/profile/all"
-
-	respBody, err := DoRequest(client, url, "GET", nil, nil)
-	if err != nil {
-		return err
-	}
-
-	defer respBody.Close()
-
-	doc, err := html.Parse(respBody)
-	if err != nil {
-		return err
-	}
-
-	if verbose {
-		fmt.Println("HTML doc parsed ok", "type:", doc.Type, "data:", doc.Data)
-	}
-
-	err = CheckHtml(doc, PARAMETERS_PAGE_TITLE)
-	if err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func DoRequest(client *http.Client, url *url.URL, method string, header http.Header, data url.Values) (io.ReadCloser, error) {
-	urlStr := fmt.Sprintf("%v", url)
-
-	request, err := http.NewRequest(method, urlStr, bytes.NewBufferString(data.Encode()))
-	if err != nil {
-		return nil, err
-	}
-
-	if header != nil {
-		request.Header = header
-	}
-
-	resp, err := client.Do(request)
-	if err != nil {
-		return nil, err
-	}
-
-	if verbose {
-		fmt.Println("resp:", resp)
-		fmt.Println("status:", resp.Status)
-	}
-
-	if resp.StatusCode != 200 {
-		return nil, errors.New(fmt.Sprintf("Response status code = %d", resp.StatusCode))
-	}
-
-	return resp.Body, nil
-}
-
-//TODO Make this better before JvD sees it
-func CheckHtml(doc *html.Node, pageTitle string) error {
-	gotTitle := false
-	gotBody := false
-
-	var f func(*html.Node)
-	f = func(n *html.Node) {
-		if n.Type == html.ElementNode && n.Data == "title" {
-			if n.FirstChild != nil && n.FirstChild.Type == html.TextNode && n.FirstChild.Data == pageTitle {
-				gotTitle = true
-			}
-		} else if gotTitle && n.Type == html.ElementNode && n.Data == "body" {
-			gotBody = true
-		}
-		if verbose {
-			fmt.Println("node", "type:", n.Type, "data:", n.Data)
-		}
-		if !gotTitle || !gotBody {
-			for c := n.FirstChild; c != nil; c = c.NextSibling {
-				f(c)
-				if gotBody {
-					break
-				}
-			}
-		}
-	}
-	f(doc)
-
-	if !gotTitle || !gotBody {
-		return errors.New("Could not locate expected page title and body")
-	}
-
-	return nil
-}


[2/2] incubator-trafficcontrol git commit: This closes #196

Posted by mi...@apache.org.
This closes #196


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/64c59551
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/64c59551
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/64c59551

Branch: refs/heads/master
Commit: 64c5955135dd7882699b9cbe4daac790bc9744d0
Parents: 43216a4
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Wed Jan 18 11:58:42 2017 -0700
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Wed Jan 18 11:58:42 2017 -0700

----------------------------------------------------------------------

----------------------------------------------------------------------