Esempio n. 1
0
func TestEtcdBackendClusterRecoverNode(t *testing.T) {

	log.InitLogger(os.Stdout, os.Stdout, os.Stdout, os.Stderr)
	test1 := uuid.NewV4().String()
	localM := cluster.LocalMachine(test1, []string{})
	localM.Id = test1
	var localCluster cluster.Cluster
	localBackend := new(EtcdBackend)
	localCluster.Init(localBackend, "../tests")

	var fakeMachines [10]TestingMachine
	for i := 0; i < 10; i++ {
		u1 := uuid.NewV4().String()
		var clstr cluster.Cluster
		backend := new(EtcdBackend)
		clstr.Init(backend, "../tests")
		m := cluster.LocalMachine(u1, []string{})
		m.Id = u1
		backend.Init(&clstr, m)
		backend.setupTestNode(test1)
		for x := 0; x < (10 - i); x++ {
			u1 := uuid.NewV4().String()
			deployment := deployment.Deployment{
				Id:        u1,
				PackageId: "test_noop",
			}
			backend.DeploymentComplete(&deployment)
		}

		fakeMachines[i] = TestingMachine{Backend: backend, Id: u1, Cluster: &clstr}
	}

	localBackend.Init(&localCluster, localM)
	localBackend.setupTestNodeWithRecovery(test1)
	assert.Equal(t, len(localCluster.Machines), 10, "")

	// Take down a machine
	fakeMachines[5].Backend.Signal <- 1

	for {
		status := <-localBackend.Status
		log.Info.Printf("Got Status: %s", status)
		if status == "Not Recovering" || status == "Recovered" {
			break
		}
	}
	assert.Equal(t, len(localCluster.Machines), 11, "")
	localBackend.Signal <- 1
	for x := 0; x < len(fakeMachines); x++ {
		fakeMachines[x].Backend.Signal <- 1
	}
	localBackend.cleanupEtcd()
}
Esempio n. 2
0
func main() {
	// TODO refactor this, probably split it out into a separate file
	// TODO handle environment variables for alternative mechanism to set flags
	var configFlag = flag.String("config", "/etc/deployd", "Directory for deployd to search for packages.json in")
	var configFromFlag = flag.String("config-from", "", "Load configuration from backend (-config-from=\"etcd,10.250.250.100:4100,/deployd/config\")")
	var endpointFlag = flag.String("endpoint", "", "Endpoint for this instance of deployd (-endpoint=10.250.200.12:8200)")
	var dFlag = flag.Bool("d", false, "Display all available output during runtime")
	var debugFlag = flag.Bool("debug", false, "Display all available output during runtime")
	var verboseFlag = flag.Bool("verbose", false, "Display info and warning messages during runtime")
	var clusterFlag = flag.Bool("nocluster", false, "Set true to disable clustering")
	var journalFlag = flag.Bool("nojournal", false, "Set true to disable journaling")
	flag.Parse()

	if *dFlag || *debugFlag {
		log.InitLogger(os.Stdout, os.Stdout, os.Stdout, os.Stderr)
	} else if *verboseFlag {
		log.InitLogger(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr)
	} else {
		log.InitLogger(ioutil.Discard, ioutil.Discard, ioutil.Discard, os.Stderr)
	}
	var config *conf.ServerConfiguration
	if configFromFlag != nil && len(*configFromFlag) > 0 {
		if endpointFlag == nil || len(*endpointFlag) == 0 {
			golog.Fatal("config-from cannot be used without specifing an endpoint")
		}
		config = conf.ConfigurationFromBackend(*configFromFlag)
	} else {
		config = conf.ConfigurationFromBackend("default," + *configFlag)
	}
	if config == nil {
		golog.Fatal("deployd cannot be started without a valid configuration")
	}

	log.Info.Printf("Starting... %s", config.Addr+":"+strconv.Itoa(config.Port))

	// This whole setup has code smell...
	// TODO refactor this
	if !*clusterFlag {
		log.Info.Printf("Starting with clustering")
		var backend = new(backends.EtcdBackend)
		if configFromFlag != nil && len(*configFromFlag) > 0 {
			clstr.InitFromConfig(backend, *config)
		} else {
			clstr.Init(backend, *configFlag)
		}
		backend.Init(&clstr, cluster.LocalMachine(config.Addr+":"+strconv.Itoa(config.Port), config.AllowedTags))

	}
	// Initialize repo
	repo = new(deployment.Repository)

	var journal log.Journal
	if !*journalFlag {
		log.Info.Printf("Starting with journaling")
		journal = log.JournalFromConfig(config.Journal)
	}

	var funcMap GoTemplate.FuncMap
	if !*clusterFlag {
		funcMap = GoTemplate.FuncMap{"getv": clstr.Backend.GetValue, "getvs": clstr.Backend.GetValues, "gets": clstr.Backend.GetString}
	}

	repo.Init(*configFlag, config.AllowUntagged, config.AllowedTags, journal, funcMap, clstr.Backend)

	// Intialize the router
	router := NewRouter()

	// Start the server
	golog.Fatal(http.ListenAndServe(config.Addr+":"+strconv.Itoa(config.Port), router))
}