You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2017/01/13 23:36:07 UTC

[11/29] incubator-trafficcontrol git commit: Have sync script use the new config object for flags and client creation.

Have sync script use the new config object for flags and client creation.


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

Branch: refs/heads/master
Commit: d11ddc20f1d99dd6fac79fec366addb3ce53e669
Parents: ab22b38
Author: sbogacz <sb...@zvelo.com>
Authored: Wed Jan 11 22:36:39 2017 -0700
Committer: David Neuman <da...@gmail.com>
Committed: Fri Jan 13 23:33:56 2017 +0000

----------------------------------------------------------------------
 .../create/create_ts_databases.go               |   1 +
 traffic_stats/influxdb_tools/sync/main.go       |  37 -------
 .../influxdb_tools/sync/sync_ts_databases.go    | 102 +++++--------------
 3 files changed, 25 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d11ddc20/traffic_stats/influxdb_tools/create/create_ts_databases.go
----------------------------------------------------------------------
diff --git a/traffic_stats/influxdb_tools/create/create_ts_databases.go b/traffic_stats/influxdb_tools/create/create_ts_databases.go
index 64d1de4..72a3a01 100644
--- a/traffic_stats/influxdb_tools/create/create_ts_databases.go
+++ b/traffic_stats/influxdb_tools/create/create_ts_databases.go
@@ -39,6 +39,7 @@ func main() {
 	config.Flags("")
 	var replication int
 	flag.IntVar(&replication, "replication", 3, "The number of nodes in the cluster")
+	flag.Parse()
 
 	fmt.Printf("creating datbases for influxUrl: %s with a replication of %d using user %s\n", config.URL, replication, config.User)
 	client, err := config.NewHTTPClient()

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d11ddc20/traffic_stats/influxdb_tools/sync/main.go
----------------------------------------------------------------------
diff --git a/traffic_stats/influxdb_tools/sync/main.go b/traffic_stats/influxdb_tools/sync/main.go
deleted file mode 100644
index 717f655..0000000
--- a/traffic_stats/influxdb_tools/sync/main.go
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-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.
-*/
-
-package main
-
-import (
-	"os"
-
-	"github.com/urfave/cli"
-)
-
-func main() {
-	app := cli.NewApp()
-	app.Name = "sync_ts_databases"
-	app.Version = "0.1.0"
-	app.Usage = "sync_ts_databases provides a cli tool syncing the requisite influxdb databases"
-	app.Flags = syncFlags()
-	app.Action = sync
-
-	app.Run(os.Args)
-}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d11ddc20/traffic_stats/influxdb_tools/sync/sync_ts_databases.go
----------------------------------------------------------------------
diff --git a/traffic_stats/influxdb_tools/sync/sync_ts_databases.go b/traffic_stats/influxdb_tools/sync/sync_ts_databases.go
index 00cd13b..122ff86 100644
--- a/traffic_stats/influxdb_tools/sync/sync_ts_databases.go
+++ b/traffic_stats/influxdb_tools/sync/sync_ts_databases.go
@@ -21,12 +21,12 @@ package main
 
 import (
 	"encoding/json"
+	"flag"
 	"fmt"
 	"time"
 
+	"github.com/apache/incubator-trafficcontrol/traffic_stats/influxdb"
 	influx "github.com/influxdata/influxdb/client/v2"
-	"github.com/pkg/errors"
-	"github.com/urfave/cli"
 )
 
 const (
@@ -58,86 +58,32 @@ type dailyStats struct {
 	value           float64
 }
 
-func syncFlags() []cli.Flag {
-	return []cli.Flag{
-		cli.StringFlag{
-			Name:  "sourceUrl",
-			Usage: "The source influxdb url and port",
-			Value: "http://server1.kabletown.net:8086",
-		},
-		cli.StringFlag{
-			Name:  "targetUrl",
-			Usage: "The target influxdb url and port",
-			Value: "http://server2.kabletown.net:8086",
-		},
-		cli.StringFlag{
-			Name:  "database",
-			Usage: "Sync a specific database",
-			Value: "all",
-		},
-		cli.IntFlag{
-			Name:  "days",
-			Usage: "Number of days in the past to sync (today - x days), 0 is all",
-			Value: 0,
-		},
-		cli.StringFlag{
-			Name:  "sourceUser",
-			Usage: "The source influxdb username",
-			Value: "",
-		},
-		cli.StringFlag{
-			Name:  "sourcePass",
-			Usage: "The source influxdb password",
-			Value: "",
-		},
-		cli.StringFlag{
-			Name:  "targetUser",
-			Usage: "The target influxdb username",
-			Value: "",
-		},
-		cli.StringFlag{
-			Name:  "targetPass",
-			Usage: "The target influxdb password",
-			Value: "",
-		},
-	}
-}
+func main() {
+	// get influx db flags for source influxdb
+	sourceConfig := &influxdb.Config{}
+	sourceConfig.Flags("source")
 
-func sync(c *cli.Context) error {
-
-	sourceURL := c.String("sourceUrl")
-	targetURL := c.String("targetUrl")
-	database := c.String("database")
-	days := c.Int("days")
-	sourceUser := c.String("sourceUser")
-	sourcePass := c.String("sourcePass")
-	targetUser := c.String("targetUser")
-	targetPass := c.String("targetPass")
-	fmt.Printf("syncing %s to %s for %s database(s) for the past %d day(s)\n", sourceURL, targetURL, database, days)
-	sourceClient, err := influx.NewHTTPClient(influx.HTTPConfig{
-		Addr:     sourceURL,
-		Username: sourceUser,
-		Password: sourcePass,
-	})
-	if err != nil {
-		return errors.Wrap(err, "Error creating influx sourceClient")
-	}
+	// get influx db flags for source influxdb
+	targetConfig := &influxdb.Config{}
+	targetConfig.Flags("target")
 
-	if _, _, err = sourceClient.Ping(10); err != nil {
-		return errors.Wrap(err, "Error creating influx sourceClient")
-	}
+	var days int
+	var database string
+	flag.IntVar(&days, "days", 0, "Number of days in the past to sync (today - x days), 0 is all")
+	flag.StringVar(&database, "database", "all", "Sync a specific database")
+	flag.Parse()
 
-	targetClient, err := influx.NewHTTPClient(influx.HTTPConfig{
-		Addr:     targetURL,
-		Username: targetUser,
-		Password: targetPass,
-	})
+	fmt.Printf("syncing %s to %s for %s database(s) for the past %d day(s)\n", sourceConfig.URL, targetConfig.URL, database, days)
+	sourceClient, err := sourceConfig.NewHTTPClient()
 	if err != nil {
-		return errors.Wrap(err, "Error creating influx targetClient")
+		fmt.Printf("Error creating influx sourceClient: %v\n", err)
+		return
 	}
 
-	if _, _, err = targetClient.Ping(10); err != nil {
-		return errors.Wrap(err, "Error creating influx targetClient")
+	targetClient, err := targetConfig.NewHTTPClient()
+	if err != nil {
+		fmt.Printf("Error creating influx targetClient: %v\n", err)
+		return
 	}
 
 	chSize := 1
@@ -159,7 +105,7 @@ func sync(c *cli.Context) error {
 	case daily:
 		go syncDailyDb(ch, sourceClient, targetClient, days)
 	default:
-		return errors.New("No database selected")
+		fmt.Println("No database selected")
 	}
 
 	for i := 1; i <= chSize; i++ {
@@ -167,7 +113,7 @@ func sync(c *cli.Context) error {
 	}
 
 	fmt.Println("Traffic Stats have been synced!")
-	return nil
+	return
 }
 
 func syncCsDb(ch chan string, sourceClient influx.Client, targetClient influx.Client, days int) {