Ejemplo n.º 1
0
func main() {
	flag.Parse()
	config := marathon.NewDefaultConfig()
	config.URL = marathon_url
	config.LogOutput = os.Stdout
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Fatalf("Failed to create a client for marathon, error: %s", err)
	}
	for {
		if application, err := client.Applications(nil); err != nil {
			glog.Errorf("Failed to retrieve a list of applications, error: %s", err)
		} else {
			glog.Infof("Retrieved a list of applications, %v", application)
		}
		glog.Infof("Going to sleep for 20 seconds")
		time.Sleep(5 * time.Second)
	}
}
Ejemplo n.º 2
0
func Assert(err error) {
	if err != nil {
		glog.Fatalf("Failed, error: %s", err)
	}
}
Ejemplo n.º 3
0
func main() {
	flag.Parse()
	config := marathon.NewDefaultConfig()
	config.URL = marathon_url
	config.LogOutput = os.Stdout
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Fatalf("Failed to create a client for marathon, error: %s", err)
	}

	glog.Infof("Retrieving a list of groups")
	if groups, err := client.Groups(); err != nil {
		glog.Errorf("Failed to retrieve the groups from maratho, error: %s", err)
	} else {
		for _, group := range groups.Groups {
			glog.Infof("Found group: %s", group.ID)
		}
	}

	GROUP_NAME := "/product/group"

	found, err := client.HasGroup(GROUP_NAME)
	Assert(err)
	if found {
		glog.Infof("Deleting the grouy: %s, as it already exists", GROUP_NAME)
		id, err := client.DeleteGroup(GROUP_NAME)
		Assert(err)
		err = client.WaitOnDeployment(id.DeploymentID, 0)
		Assert(err)
	}

	/* step: the frontend app */
	frontend := marathon.NewDockerApplication()
	frontend.Name("/product/group/frontend")
	frontend.CPU(0.1).Memory(64).Storage(0.0).Count(2)
	frontend.Arg("/usr/sbin/apache2ctl").Arg("-D").Arg("FOREGROUND")
	frontend.AddEnv("NAME", "frontend_http")
	frontend.AddEnv("SERVICE_80_NAME", "frontend_http")
	frontend.AddEnv("SERVICE_443_NAME", "frontend_https")
	frontend.AddEnv("BACKEND_MYSQL", "/product/group/mysql/3306;3306")
	frontend.AddEnv("BACKEND_CACHE", "/product/group/cache/6379;6379")
	frontend.DependsOn("/product/group/cache")
	frontend.DependsOn("/product/group/mysql")
	frontend.Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80).Expose(443)
	_, err = frontend.CheckHTTP("/hostname.php", 80, 10)
	Assert(err)

	mysql := marathon.NewDockerApplication()
	mysql.Name("/product/group/mysql")
	mysql.CPU(0.1).Memory(128).Storage(0.0).Count(1)
	mysql.AddEnv("NAME", "group_cache")
	mysql.AddEnv("SERVICE_3306_NAME", "mysql")
	mysql.AddEnv("MYSQL_PASS", "mysql")
	mysql.Container.Docker.Container("tutum/mysql").Expose(3306)
	_, err = mysql.CheckTCP(3306, 10)
	Assert(err)

	redis := marathon.NewDockerApplication()
	redis.Name("/product/group/cache")
	redis.CPU(0.1).Memory(64).Storage(0.0).Count(2)
	redis.AddEnv("NAME", "group_cache")
	redis.AddEnv("SERVICE_6379_NAME", "redis")
	redis.Container.Docker.Container("redis:latest").Expose(6379)
	_, err = redis.CheckTCP(6379, 10)
	Assert(err)

	group := marathon.NewApplicationGroup(GROUP_NAME)
	group.App(frontend).App(redis).App(mysql)

	Assert(client.CreateGroup(group))
	glog.Infof("Successfully created the group: %s", group.ID)

	glog.Infof("Updating the group paramaters")
	frontend.Count(4)

	id, err := client.UpdateGroup(GROUP_NAME, group)
	Assert(err)
	glog.Infof("Successfully updated the group: %s, version: %s", group.ID, id.DeploymentID)
	Assert(client.WaitOnGroup(GROUP_NAME, 500*time.Second))
}