Пример #1
0
func translateServiceConfig(config *framework.ServiceConfig, instances int) *marathon.Application {
	application := marathon.NewDockerApplication()
	imageWithTag := config.ImageName + ":" + config.Tag
	labels := map[string]string{
		"image_name": config.ImageName,
		"image_tag":  config.Tag,
	}

	application.Name(config.ServiceID)

	if config.Constraints["slave_name"] != "" {
		labels["slave_name"] = config.Constraints["slave_name"]
	}

	// default value for CPU
	if config.CPUShares != 0.0 {
		application.CPU(config.CPUShares)
	} else {
		application.CPU(0.25)
	}

	if config.DockerCfg != "" {
		//uris := make([]string, 1)
		//uris = append(uris, config.DockerCfg)
		//application.Uris = []string{config.DockerCfg}
		application.Uris = append(application.Uris, config.DockerCfg)
	}
	application.Memory(float64(config.Memory))
	application.Count(instances)
	application.Env = utils.StringSlice2Map(config.Envs)
	application.Env["SERVICE_NAME"] = config.ServiceID
	application.Labels = labels

	//upgradeStrategy
	application.UpgradeStrategy = &marathon.UpgradeStrategy{
		MinimumHealthCapacity: config.MinimumHealthCapacity,
		MaximumOverCapacity:   config.MaximumOverCapacity,
	}

	//application.RequirePorts = true
	populateConstraints(application, config)
	// add the docker container
	application.Container.Docker.Container(imageWithTag)
	application.Container.Docker.PortMappings = createPorMappings(config.Publish)
	application.Container.Docker.Parameters = populateParameters(config)
	// Http Health Check
	addHealthCheck(application, config)
	return application
}
func TestEnvFilter(t *testing.T) {

	app := marathon.NewDockerApplication()
	filteredApp := filterApp4Debug(app)
	assert.Nil(t, filteredApp.Env)
	assert.Equal(t, app, filteredApp)

	app.Env = utils.StringSlice2Map([]string{"APP_db.password=Jlka8L%BA", "APP_db.user=dbuser", "KEY1=value1", "APP_db.passwd=Jlka8L%BA", "APP_db.pwd=Jlka8L%BA", "APP_mongodb.usr=mongouser"})
	filteredApp = filterApp4Debug(app)
	assert.NotEqual(t, app, filteredApp)
	assert.Equal(t, 6, len(filteredApp.Env))
	assert.Equal(t, s3cr3t, filteredApp.Env["APP_db.password"])
	assert.Equal(t, s3cr3t, filteredApp.Env["APP_db.user"])
	assert.Equal(t, "value1", filteredApp.Env["KEY1"])
	assert.Equal(t, s3cr3t, filteredApp.Env["APP_db.passwd"])
	assert.Equal(t, s3cr3t, filteredApp.Env["APP_db.pwd"])
	assert.Equal(t, s3cr3t, filteredApp.Env["APP_mongodb.usr"])
}
func translateServiceConfig(config framework.ServiceConfig, instances int) (*marathon.Application, error) {
	application := marathon.NewDockerApplication()
	imageWithTag := config.ImageName + ":" + config.Tag

	application.Name(config.ServiceID)

	// default value for CPU
	application.CPU(0.25)
	if config.CPUShares != 0.0 {
		application.CPU(config.CPUShares)
	}

	if config.DockerCfg != "" {
		application.Uris = append(application.Uris, config.DockerCfg)
	}
	application.Memory(float64(config.Memory))
	application.Count(instances)
	application.Env = utils.StringSlice2Map(config.Envs)

	//upgradeStrategy
	application.UpgradeStrategy = &marathon.UpgradeStrategy{
		MinimumHealthCapacity: config.MinimumHealthCapacity,
		MaximumOverCapacity:   config.MaximumOverCapacity,
	}

	populateLabels(application, config)

	//application.RequirePorts = true
	if err := populateConstraints(application, config); err != nil {
		return nil, err
	}

	// add the docker container
	application.Container.Docker.Container(imageWithTag)
	application.Container.Docker.PortMappings = createPorMappings(config.Publish)
	application.Container.Docker.Parameters = populateParameters(config)
	// Http Health Check
	if err := addHealthCheck(application, config); err != nil {
		return nil, err
	}

	return application, nil
}