예제 #1
0
func (m *Manager) init() []*shipyard.Engine {
	engines := []*shipyard.Engine{}
	res, err := r.Table(tblNameConfig).Run(m.session)
	if err != nil {
		logger.Fatalf("error getting configuration: %s", err)
	}
	if err := res.All(&engines); err != nil {
		logger.Fatalf("error loading configuration: %s", err)
	}
	m.engines = engines
	var engs []*citadel.Engine
	for _, d := range engines {
		tlsConfig := &tls.Config{}
		if d.CACertificate != "" && d.SSLCertificate != "" && d.SSLKey != "" {
			caCert := []byte(d.CACertificate)
			sslCert := []byte(d.SSLCertificate)
			sslKey := []byte(d.SSLKey)
			c, err := getTLSConfig(caCert, sslCert, sslKey)
			if err != nil {
				logger.Errorf("error getting tls config: %s", err)
			}
			tlsConfig = c
		}
		if err := setEngineClient(d.Engine, tlsConfig); err != nil {
			logger.Errorf("error setting tls config for engine: %s", err)
		}
		engs = append(engs, d.Engine)
		logger.Infof("loaded engine id=%s addr=%s", d.Engine.ID, d.Engine.Addr)
	}
	clusterManager, err := cluster.New(scheduler.NewResourceManager(), engs...)
	if err != nil {
		logger.Fatal(err)
	}
	if err := clusterManager.Events(&EventHandler{Manager: m}); err != nil {
		logger.Fatalf("unable to register event handler: %s", err)
	}
	var (
		labelScheduler  = &scheduler.LabelScheduler{}
		uniqueScheduler = &scheduler.UniqueScheduler{}
		hostScheduler   = &scheduler.HostScheduler{}

		multiScheduler = scheduler.NewMultiScheduler(
			labelScheduler,
			uniqueScheduler,
		)
	)
	// TODO: refactor to be configurable
	clusterManager.RegisterScheduler("service", labelScheduler)
	clusterManager.RegisterScheduler("unique", uniqueScheduler)
	clusterManager.RegisterScheduler("multi", multiScheduler)
	clusterManager.RegisterScheduler("host", hostScheduler)
	m.clusterManager = clusterManager
	// start extension health check
	go m.extensionHealthCheck()
	// start engine check
	go m.engineCheck()
	// anonymous usage info
	go m.usageReport()
	return engines
}
예제 #2
0
func (m *Manager) init() error {
	var engines []*citadel.Engine
	if m.config.ShipyardUrl != "" {
		cfg := &client.ShipyardConfig{
			Url:        m.config.ShipyardUrl,
			ServiceKey: m.config.ShipyardServiceKey,
		}
		mgr := client.NewManager(cfg)
		eng, err := mgr.Engines()
		if err != nil {
			return err
		}
		for _, e := range eng {
			engines = append(engines, e.Engine)
		}
	} else {
		engines = m.engines
	}
	for _, e := range engines {
		if err := e.Connect(nil); err != nil {
			return err
		}
		logger.Infof("loaded engine: %s", e.ID)
	}
	c, err := cluster.New(scheduler.NewResourceManager(), engines...)
	if err != nil {
		return err
	}
	m.cluster = c
	// register handler
	if err := m.cluster.Events(&EventHandler{Manager: m}); err != nil {
		return err
	}
	return nil
}
예제 #3
0
파일: cluster.go 프로젝트: shipyard/citadel
func main() {
	boot2docker := &citadel.Engine{
		ID:     "boot2docker",
		Addr:   "http://192.168.56.102:2375",
		Memory: 2048,
		Cpus:   4,
		Labels: []string{"local"},
	}

	if err := boot2docker.Connect(nil); err != nil {
		log.Fatal(err)
	}

	c, err := cluster.New(scheduler.NewResourceManager(), boot2docker)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	if err := c.RegisterScheduler("service", &scheduler.LabelScheduler{}); err != nil {
		log.Fatal(err)
	}

	if err := c.Events(&logHandler{}); err != nil {
		log.Fatal(err)
	}

	image := &citadel.Image{
		Name:   "crosbymichael/redis",
		Memory: 256,
		Cpus:   0.4,
		Type:   "service",
	}

	container, err := c.Start(image, false)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("ran container %s\n", container.ID)

	containers, err := c.ListContainers(false)
	if err != nil {
		log.Fatal(err)
	}

	c1 := containers[0]

	if err := c.Kill(c1, 9); err != nil {
		log.Fatal(err)
	}

	if err := c.Remove(c1); err != nil {
		log.Fatal(err)
	}
}
예제 #4
0
func main() {
	if err := loadConfig(); err != nil {
		log.Fatal(err)
	}

	tlsConfig, err := getTLSConfig()
	if err != nil {
		log.Fatal(err)
	}

	for _, d := range config.Engines {
		if err := setEngineClient(d, tlsConfig); err != nil {
			log.Fatal(err)
		}
	}

	clusterManager, err = cluster.New(scheduler.NewResourceManager(), config.Engines...)
	if err != nil {
		log.Fatal(err)
	}

	var (
		labelScheduler  = &scheduler.LabelScheduler{}
		uniqueScheduler = &scheduler.UniqueScheduler{}
		hostScheduler   = &scheduler.HostScheduler{}

		multiScheduler = scheduler.NewMultiScheduler(
			labelScheduler,
			uniqueScheduler,
		)
	)

	clusterManager.RegisterScheduler("service", labelScheduler)
	clusterManager.RegisterScheduler("unique", uniqueScheduler)
	clusterManager.RegisterScheduler("multi", multiScheduler)
	clusterManager.RegisterScheduler("host", hostScheduler)

	r := mux.NewRouter()
	r.HandleFunc("/containers", containers).Methods("GET")
	r.HandleFunc("/run", run).Methods("POST")
	r.HandleFunc("/destroy", destroy).Methods("DELETE")
	r.HandleFunc("/engines", engines).Methods("GET")

	log.Printf("bastion listening on %s\n", config.ListenAddr)

	if err := http.ListenAndServe(config.ListenAddr, r); err != nil {
		log.Fatal(err)
	}
}