github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/hack/integration-cli-on-swarm/agent/master/master.go (about)

     1  package main
     2  
     3  import (
     4  	"errors"
     5  	"flag"
     6  	"io/ioutil"
     7  	"log"
     8  	"strings"
     9  )
    10  
    11  func main() {
    12  	if err := xmain(); err != nil {
    13  		log.Fatalf("fatal error: %v", err)
    14  	}
    15  }
    16  
    17  func xmain() error {
    18  	workerService := flag.String("worker-service", "", "Name of worker service")
    19  	chunks := flag.Int("chunks", 0, "Number of chunks")
    20  	input := flag.String("input", "", "Path to input file")
    21  	randSeed := flag.Int64("rand-seed", int64(0), "Random seed")
    22  	shuffle := flag.Bool("shuffle", false, "Shuffle the input so as to mitigate makespan nonuniformity")
    23  	flag.Parse()
    24  	if *workerService == "" {
    25  		return errors.New("worker-service unset")
    26  	}
    27  	if *chunks == 0 {
    28  		return errors.New("chunks unset")
    29  	}
    30  	if *input == "" {
    31  		return errors.New("input unset")
    32  	}
    33  
    34  	tests, err := loadTests(*input)
    35  	if err != nil {
    36  		return err
    37  	}
    38  	testChunks := chunkTests(tests, *chunks, *shuffle, *randSeed)
    39  	log.Printf("Loaded %d tests (%d chunks)", len(tests), len(testChunks))
    40  	return executeTests(*workerService, testChunks)
    41  }
    42  
    43  func chunkTests(tests []string, numChunks int, shuffle bool, randSeed int64) [][]string {
    44  	// shuffling (experimental) mitigates makespan nonuniformity
    45  	// Not sure this can cause some locality problem..
    46  	if shuffle {
    47  		shuffleStrings(tests, randSeed)
    48  	}
    49  	return chunkStrings(tests, numChunks)
    50  }
    51  
    52  func loadTests(filename string) ([]string, error) {
    53  	b, err := ioutil.ReadFile(filename)
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  	var tests []string
    58  	for _, line := range strings.Split(string(b), "\n") {
    59  		s := strings.TrimSpace(line)
    60  		if s != "" {
    61  			tests = append(tests, s)
    62  		}
    63  	}
    64  	return tests, nil
    65  }