Пример #1
0
// Register permite registrar a una implementación de Framework, de esta
// manera estara disponible mediante su ID para poder ser instanciado
func Register(name string, factory FrameworkFactory) {
	if factory == nil {
		logger.Instance().Fatal("Se debe pasar como argumento un SchedulerFactory")
	}
	_, registered := frameworkFactories[name]
	if registered {
		logger.Instance().Fatalf("SchedulerFactory %s ya está registrado", name)
	}

	frameworkFactories[name] = factory
}
Пример #2
0
func newMarathon(params *Parameters) (*Marathon, error) {
	config := marathon.NewDefaultConfig()
	config.URL = params.EndpointUrl
	config.HTTPClient = &http.Client{
		Timeout: (time.Duration(10) * time.Second),
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		},
	}

	config.HTTPBasicAuthUser = params.HTTPBasicAuthUser
	config.HTTPBasicPassword = params.HTTPBasicAuthPassword

	client, err := marathon.NewClient(config)
	if err != nil {
		return nil, framework.NewFrameworkClientError(frameworkID, err)
	}

	helper := &Marathon{
		deployTimeout:          params.DeployTimeout,
		logEntry:               logger.Instance().WithFields(params.LogMetadata),
		dockerCfg:              params.DockerCfg,
		retryTimes:             params.RetryTimes,
		defaultHealthCheckConf: params.defaultHealthCheckConf,
		client:                 client,
	}
	return helper, nil
}
Пример #3
0
func (scb *ServiceConfigurationBuilder) BuildForCluster(cluster string) framework.ServiceConfig {
	if cluster != "" {
		scb.log = logger.Instance().WithField("cluster", cluster)
	}

	/*
		if recreateCache {
			scb.logger().Infoln("Recreating ServiceConfig cache")
			delete(configs, cluster)
		}

		if cfg, ok := configs[cluster]; ok {
			scb.logger().Infoln("Using ServiceConfig cache")
			return cfg
		}
	*/
	scb.logger().Debugf("Configuring service")

	_, err := valid.ValidateStruct(scb)
	if err != nil {
		scb.logger().Panicf(err.Error())
	}

	if !envValidator(scb.EnvironmentVars, nil) {
		scb.logger().Panicln("Invalid Env vars")
	}

	scb.buildServiceId()

	serviceConfig := framework.ServiceConfig{
		Registry:              scb.RegistryDomain,
		Namespace:             scb.Namespace,
		ServiceName:           scb.serviceName,
		CompatibilityVersion:  scb.compatibilityVersion,
		Tag:                   scb.Tag,
		CPUShares:             scb.Cpu,
		Memory:                scb.Memory,
		Instances:             scb.Instances,
		Labels:                util.KeyValueArrayToMap(util.KeyValueArray(cluster, scb.Labels)),
		Constraints:           scb.setupConstraints(scb.Constraints),
		MinimumHealthCapacity: scb.MinimumHealthCapacity,
		MaximumOverCapacity:   scb.checkMaximumOverCapacity(scb.MaximumOverCapacity, scb.Instances),
		SyslogTag:             scb.SyslogTag,
	}

	if err := serviceConfig.SetupPorts(scb.Ports); err != nil {
		scb.logger().Panicln(err)
	}

	envs := util.KeyValueArrayToMap(util.KeyValueArray(cluster, scb.EnvironmentVars))
	envs["SERVICE_NAME"] = scb.registratorServiceEnvironment(serviceConfig)
	serviceConfig.Envs = envs

	for k, v := range scb.setupLabels(serviceConfig.Image()) {
		serviceConfig.Labels[k] = v
	}

	scb.logger().Debugln("Service Configuration successful")

	//configs[cluster] = serviceConfig
	return serviceConfig
}
Пример #4
0
func (scb *ServiceConfigurationBuilder) logger() *log.Entry {
	if scb.log == nil {
		scb.log = logger.Instance().WithFields(map[string]interface{}{})
	}
	return scb.log
}