示例#1
0
文件: sky.go 项目: carriercomm/sky-1
func criteriaFromArgs(args []string) (*skynet.Criteria, []string) {
	flagset := flag.NewFlagSet("deploy", flag.ExitOnError)
	services := flagset.String("services", "", "services")
	regions := flagset.String("regions", "", "regions")
	instances := flagset.String("instances", "", "instances")
	hosts := flagset.String("hosts", "", "hosts")
	registered := flagset.String("registered", "", "registered")

	flagsetArgs, args := config.SplitFlagsetFromArgs(flagset, args)

	err := flagset.Parse(flagsetArgs)
	if err != nil {
		log.Fatal(err)
	}

	regionCriteria := make([]string, 0, 0)

	if len(*regions) > 0 {
		regionCriteria = strings.Split(*regions, ",")
	}

	hostCriteria := make([]string, 0, 0)

	if len(*hosts) > 0 {
		hostCriteria = strings.Split(*hosts, ",")
	}

	instanceCriteria := make([]string, 0, 0)

	if len(*instances) > 0 {
		instanceCriteria = strings.Split(*instances, ",")
	}

	var reg *bool
	if *registered == "true" {
		*reg = true
	} else if *registered == "false" {
		*reg = false
	}

	return &skynet.Criteria{
		Regions:    regionCriteria,
		Hosts:      hostCriteria,
		Instances:  instanceCriteria,
		Registered: reg,
		Services:   serviceCriteriaFromCsv(*services),
	}, args
}
示例#2
0
func main() {
	flagset := flag.NewFlagSet("simple", flag.ContinueOnError)
	flagset.IntVar(&requests, "requests", 10, "number of concurrent requests")
	flagset.IntVar(&goMaxProcs, "maxprocs", 1, "GOMAXPROCS")

	runtime.GOMAXPROCS(goMaxProcs)

	c := make(chan os.Signal, 1)
	quitChan := make(chan bool, 1)
	requestChan := make(chan string, requests*3)
	workerWaitGroup := new(sync.WaitGroup)

	go watchSignals(c, quitChan)

	simpleArgs, _ := config.SplitFlagsetFromArgs(flagset, os.Args[1:])
	flagset.Parse(simpleArgs)

	simpleClient = client.GetService("TestService", "", "", "")

	startTime := time.Now().UnixNano()
	fmt.Printf("Starting %d Workers\n", requests)
	for i := 0; i < requests; i++ {
		go worker(requestChan, workerWaitGroup)
	}

	requestNum := 0

	for {
		select {
		case <-quitChan:
			close(requestChan)
			workerWaitGroup.Wait()
			stopTime := time.Now().UnixNano()

			successful, _ := strconv.Atoi(successfulRequests.String())
			total, _ := strconv.Atoi(totalRequests.String())
			failed, _ := strconv.Atoi(failedRequests.String())

			lost := total - successful - failed

			percentSuccess := float64(successful) / float64(total) * 100
			percentFailed := float64(failed) / float64(total) * 100
			percentLost := float64(lost) / float64(total) * 100

			runtime := (stopTime - startTime) / 1000000
			rqps := float64(total) / (float64(runtime) / 1000)

			fmt.Printf("======================================")
			fmt.Printf("======================================\n")
			fmt.Printf("Completed in %d Milliseconds, %f Requests/s\n",
				runtime, rqps)
			fmt.Printf("\nTotal Requests: %d, Successful: %d (%f%%)",
				total, successful, percentSuccess)
			fmt.Printf(", Failed: %d (%f%%)", failed, percentFailed)
			fmt.Printf(", Lost: %d (%f%%)\n\n", lost, percentLost)
			return

		default:
			requestChan <- "simple"
			requestNum++
		}
	}
}
示例#3
0
文件: sky.go 项目: carriercomm/sky-1
func main() {
	log.SetLogLevel(log.ERROR)

	var args []string
	criteria, args := criteriaFromArgs(os.Args[1:])

	if len(args) == 0 {
		CommandLineHelp()
		return
	}

	switch args[0] {
	case "help", "h":
		CommandLineHelp()
	case "build", "b":
		flagset := flag.NewFlagSet("build", flag.ExitOnError)
		configFile := flagset.String("build", "./build.cfg", "build config file")
		flagsetArgs, _ := config.SplitFlagsetFromArgs(flagset, args)

		err := flagset.Parse(flagsetArgs)
		if err != nil {
			log.Fatal(err)
			return
		}

		Build(*configFile)
	case "deploy", "d":
		flagset := flag.NewFlagSet("deploy", flag.ExitOnError)
		configFile := flagset.String("build", "./build.cfg", "build config file")
		flagsetArgs, _ := config.SplitFlagsetFromArgs(flagset, args)

		err := flagset.Parse(flagsetArgs)
		if err != nil {
			log.Fatal(err)
			return
		}

		Deploy(*configFile, criteria)
	case "hosts":
		ListHosts(criteria)
	case "regions":
		ListRegions(criteria)
	case "services":
		ListServices(criteria)
	case "versions":
		ListVersions(criteria)
	case "instances":
		ListInstances(criteria)
	case "start":
		Start(criteria, args[1:])
	case "stop":
		Stop(criteria)
	case "restart":
		Restart(criteria)
	case "register":
		Register(criteria)
	case "unregister":
		Unregister(criteria)
	case "log":
		SetLogLevel(criteria, args[1])
	case "daemon":
		if len(args) >= 2 {
			switch args[1] {
			case "log":
				if len(args) >= 3 {
					SetDaemonLogLevel(criteria, args[2])
				} else {
					fmt.Println("Must supply a log level")
				}
			case "stop":
				StopDaemon(criteria)
			}
		} else {
			fmt.Println("Supported subcommands for daemon are log, and stop")
		}
	case "cli":
		InteractiveShell()
	default:
		fmt.Println("Unknown Command: ", args[0])
		CommandLineHelp()
	}
}