Beispiel #1
0
func main() {
	logger := log15.New("component", "scheduler")
	logger.SetHandler(log15.LvlFilterHandler(log15.LvlInfo, log15.StdoutHandler))
	log := logger.New("fn", "main")

	log.Info("creating cluster and controller clients")
	hc := &http.Client{Timeout: 5 * time.Second}
	clusterClient := utils.ClusterClientWrapper(cluster.NewClientWithHTTP(nil, hc))
	controllerClient, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
	if err != nil {
		log.Error("error creating controller client", "err", err)
		shutdown.Fatal(err)
	}

	log.Info("waiting for controller API to come up")
	if _, err := discoverd.GetInstances("controller", 5*time.Minute); err != nil {
		log.Error("error waiting for controller API", "err", err)
		shutdown.Fatal(err)
	}

	s := NewScheduler(clusterClient, controllerClient, newDiscoverdWrapper(logger), logger)
	log.Info("started scheduler", "backoffPeriod", s.backoffPeriod)

	go s.startHTTPServer(os.Getenv("PORT"))

	if err := s.Run(); err != nil {
		shutdown.Fatal(err)
	}
	shutdown.Exit()
}
Beispiel #2
0
func main() {
	log := logger.New("fn", "main")

	log.Info("creating cluster and controller clients")
	hc := &http.Client{Timeout: 5 * time.Second}
	clusterClient := utils.ClusterClientWrapper(cluster.NewClientWithHTTP(nil, hc))
	controllerClient, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
	if err != nil {
		log.Error("error creating controller client", "err", err)
		shutdown.Fatal(err)
	}
	s := NewScheduler(clusterClient, controllerClient, newDiscoverdWrapper())
	log.Info("started scheduler", "backoffPeriod", s.backoffPeriod)

	go s.startHTTPServer(os.Getenv("PORT"))

	if err := s.Run(); err != nil {
		shutdown.Fatal(err)
	}
	shutdown.Exit()
}
Beispiel #3
0
func main() {
	conf, err := loadConfigFromEnv()
	if err != nil {
		log.Fatal(err)
	}

	err = discoverd.Connect(conf.controllerDomain + ":1111")
	if err != nil {
		log.Fatal(err)
	}

	client, err = cc.NewClient("http://"+conf.controllerDomain, conf.controllerKey)
	if err != nil {
		log.Fatal(err)
	}
	client.HTTP.Transport = &roundTripRecorder{roundTripper: &http.Transport{}}

	e := &generator{
		conf:        conf,
		client:      client,
		resourceIds: make(map[string]string),
	}

	providerLog := log.New(os.Stdout, "provider: ", 1)
	go e.listenAndServe(providerLog)

	examples := []example{
		{"key_create", e.createKey},
		{"key_get", e.getKey},
		{"key_list", e.listKeys},
		{"key_delete", e.deleteKey},
		{"app_create", e.createApp},
		{"app_initial_release_get", e.getInitialAppRelease},
		{"app_get", e.getApp},
		{"app_list", e.listApps},
		{"app_update", e.updateApp},
		{"app_resource_list", e.listAppResources},
		{"route_create", e.createRoute},
		{"route_get", e.getRoute},
		{"route_list", e.listRoutes},
		{"route_delete", e.deleteRoute},
		{"artifact_create", e.createArtifact},
		{"release_create", e.createRelease},
		{"artifact_list", e.listArtifacts},
		{"release_list", e.listReleases},
		{"app_release_set", e.setAppRelease},
		{"app_release_get", e.getAppRelease},
		{"formation_put", e.putFormation},
		{"formation_get", e.getFormation},
		{"formation_list", e.listFormations},
		{"formation_delete", e.deleteFormation},
		{"job_run", e.runJob},
		{"job_log", e.getJobLog},
		{"job_list", e.listJobs},
		{"job_update", e.updateJob},
		{"job_delete", e.deleteJob},
		{"provider_create", e.createProvider},
		{"provider_get", e.getProvider},
		{"provider_list", e.listProviders},
		{"provider_resource_create", e.createProviderResource},
		{"provider_resource_get", e.getProviderResource},
		{"provider_resource_list", e.listProviderResources},
		{"app_delete", e.deleteApp},
	}

	// TODO: GET /apps/:app_id/jobs/:job_id/log (event-stream)

	res := make(map[string]*compiledRequest)
	for _, ex := range examples {
		ex.f()
		res[ex.name] = compileRequest(getRequests()[0])
	}

	var out io.Writer
	if len(os.Args) > 1 {
		out, err = os.Create(os.Args[1])
		if err != nil {
			log.Fatal(err)
		}
	} else {
		out = os.Stdout
	}
	data, err := json.MarshalIndent(res, "", "\t")
	if err != nil {
		log.Fatal(err)
	}
	_, err = out.Write(data)
	if err != nil {
		log.Fatal(err)
	}
}