This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
/
main.go
83 lines (69 loc) · 2.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"github.com/cloudfoundry/gunk/timeprovider"
"github.com/pivotal-cf-experimental/executor-tester/etcd_logger"
"github.com/pivotal-cf-experimental/executor-tester/stampede"
datadog "github.com/xb95/go-datadog-api"
"log"
"os"
"strings"
"time"
"github.com/cloudfoundry-incubator/runtime-schema/bbs"
"github.com/cloudfoundry-incubator/runtime-schema/models"
"github.com/cloudfoundry/storeadapter/etcdstoreadapter"
"github.com/cloudfoundry/storeadapter/workerpool"
)
var etcdMachines = flag.String("etcdMachines", "", "comma-separated list of http:// etcd endpoints")
var runOnceCount = flag.Int("runOnceCount", 1, "number of RunOnces to create")
var timeout = flag.Duration("timeout", 10*time.Second, "maximum runtime of the RunOnce (0 for no limit)")
var script = flag.String("script", `echo hello, world`, "script to run in RunOnce")
var memoryMB = flag.Int("memoryMB", 0, "memory limit of the RunOnce (0 for no limit)")
var diskMB = flag.Int("diskMB", 0, "disk limit of the RunOnce (0 for no limit)")
var stack = flag.String("stack", "lucid64", "stack")
var logGuid = flag.String("logGuid", "", "guid for logs (empty for no logs)")
var logSourceName = flag.String("logSourceName", "TST", "source name for logs")
var emitStates = flag.Bool("emitStates", false, "emit state of RunOnces to datadog")
func main() {
flag.Parse()
datadogApiKey := os.Getenv("DATADOG_API_KEY")
datadogAppKey := os.Getenv("DATADOG_APP_KEY")
var datadogClient *datadog.Client
if datadogApiKey != "" {
datadogClient = datadog.NewClient(datadogApiKey, datadogAppKey)
}
store := etcdstoreadapter.NewETCDStoreAdapter(
strings.Split(*etcdMachines, ","),
workerpool.NewWorkerPool(50),
)
err := store.Connect()
if err != nil {
log.Fatalln("failed to connect to store:", err)
}
if *emitStates {
// logging mode
etcd_logger.EmitRunOnceStates(datadogClient, store, strings.Split(*etcdMachines, ","))
} else {
// stampede mode
runOnce := &models.RunOnce{
Actions: []models.ExecutorAction{
{
models.RunAction{
Script: *script,
Timeout: *timeout,
},
},
},
Stack: *stack,
MemoryMB: *memoryMB,
DiskMB: *diskMB,
}
if *logGuid != "" {
runOnce.Log = models.LogConfig{
Guid: *logGuid,
SourceName: *logSourceName,
}
}
stampede.RunonceStampede(bbs.New(store, timeprovider.NewTimeProvider()), datadogClient, runOnce, *runOnceCount)
}
}