func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Config, error) {
	conf := agentConfig.NomadConfig
	if conf == nil {
		conf = nomad.DefaultConfig()
	}
	conf.LogOutput = logOutput
	conf.DevMode = agentConfig.DevMode
	conf.Build = fmt.Sprintf("%s%s", agentConfig.Version, agentConfig.VersionPrerelease)
	if agentConfig.Region != "" {
		conf.Region = agentConfig.Region
	}
	if agentConfig.Datacenter != "" {
		conf.Datacenter = agentConfig.Datacenter
	}
	if agentConfig.NodeName != "" {
		conf.NodeName = agentConfig.NodeName
	}
	if agentConfig.Server.BootstrapExpect > 0 {
		if agentConfig.Server.BootstrapExpect == 1 {
			conf.Bootstrap = true
		} else {
			atomic.StoreInt32(&conf.BootstrapExpect, int32(agentConfig.Server.BootstrapExpect))
		}
	}
	if agentConfig.DataDir != "" {
		conf.DataDir = filepath.Join(agentConfig.DataDir, "server")
	}
	if agentConfig.Server.DataDir != "" {
		conf.DataDir = agentConfig.Server.DataDir
	}
	if agentConfig.Server.ProtocolVersion != 0 {
		conf.ProtocolVersion = uint8(agentConfig.Server.ProtocolVersion)
	}
	if agentConfig.Server.NumSchedulers != 0 {
		conf.NumSchedulers = agentConfig.Server.NumSchedulers
	}
	if len(agentConfig.Server.EnabledSchedulers) != 0 {
		conf.EnabledSchedulers = agentConfig.Server.EnabledSchedulers
	}

	// Set up the bind addresses
	rpcAddr, err := net.ResolveTCPAddr("tcp", agentConfig.normalizedAddrs.RPC)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse RPC address %q: %v", agentConfig.normalizedAddrs.RPC, err)
	}
	serfAddr, err := net.ResolveTCPAddr("tcp", agentConfig.normalizedAddrs.Serf)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse Serf address %q: %v", agentConfig.normalizedAddrs.Serf, err)
	}
	conf.RPCAddr.Port = rpcAddr.Port
	conf.RPCAddr.IP = rpcAddr.IP
	conf.SerfConfig.MemberlistConfig.BindPort = serfAddr.Port
	conf.SerfConfig.MemberlistConfig.BindAddr = serfAddr.IP.String()

	// Set up the advertise addresses
	rpcAddr, err = net.ResolveTCPAddr("tcp", agentConfig.AdvertiseAddrs.RPC)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse RPC advertise address %q: %v", agentConfig.AdvertiseAddrs.RPC, err)
	}
	serfAddr, err = net.ResolveTCPAddr("tcp", agentConfig.AdvertiseAddrs.Serf)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse Serf advertise address %q: %v", agentConfig.AdvertiseAddrs.Serf, err)
	}
	conf.RPCAdvertise = rpcAddr
	conf.SerfConfig.MemberlistConfig.AdvertiseAddr = serfAddr.IP.String()
	conf.SerfConfig.MemberlistConfig.AdvertisePort = serfAddr.Port

	// Set up gc threshold and heartbeat grace period
	if gcThreshold := agentConfig.Server.NodeGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.NodeGCThreshold = dur
	}
	if gcThreshold := agentConfig.Server.JobGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.JobGCThreshold = dur
	}
	if gcThreshold := agentConfig.Server.EvalGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.EvalGCThreshold = dur
	}
	if gcThreshold := agentConfig.Server.DeploymentGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.DeploymentGCThreshold = dur
	}

	if heartbeatGrace := agentConfig.Server.HeartbeatGrace; heartbeatGrace != 0 {
		conf.HeartbeatGrace = heartbeatGrace
	}
	if min := agentConfig.Server.MinHeartbeatTTL; min != 0 {
		conf.MinHeartbeatTTL = min
	}
	if maxHPS := agentConfig.Server.MaxHeartbeatsPerSecond; maxHPS != 0 {
		conf.MaxHeartbeatsPerSecond = maxHPS
	}

	if *agentConfig.Consul.AutoAdvertise && agentConfig.Consul.ServerServiceName == "" {
		return nil, fmt.Errorf("server_service_name must be set when auto_advertise is enabled")
	}

	// Add the Consul and Vault configs
	conf.ConsulConfig = agentConfig.Consul
	conf.VaultConfig = agentConfig.Vault

	// Set the TLS config
	conf.TLSConfig = agentConfig.TLSConfig

	return conf, nil
}
// convertServerConfig takes an agent config and log output and returns a Nomad
// Config.
convertServerConfig takes an agent config and log output and returns a Nomad
Config.
// convertServerConfig takes an agent config and log output and returns a Nomad // Config .
func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Config, error) {
	conf := agentConfig.NomadConfig
	if conf == nil {
		conf = nomad.DefaultConfig()
	}
	conf.LogOutput = logOutput
	conf.DevMode = agentConfig.DevMode
	conf.Build = fmt.Sprintf("%s%s", agentConfig.Version, agentConfig.VersionPrerelease)
	if agentConfig.Region != "" {
		conf.Region = agentConfig.Region
	}
	if agentConfig.Datacenter != "" {
		conf.Datacenter = agentConfig.Datacenter
	}
	if agentConfig.NodeName != "" {
		conf.NodeName = agentConfig.NodeName
	}
	if agentConfig.Server.BootstrapExpect > 0 {
		if agentConfig.Server.BootstrapExpect == 1 {
			conf.Bootstrap = true
		} else {
			atomic.StoreInt32(&conf.BootstrapExpect, int32(agentConfig.Server.BootstrapExpect))
		}
	}
	if agentConfig.DataDir != "" {
		conf.DataDir = filepath.Join(agentConfig.DataDir, "server")
	}
	if agentConfig.Server.DataDir != "" {
		conf.DataDir = agentConfig.Server.DataDir
	}
	if agentConfig.Server.ProtocolVersion != 0 {
		conf.ProtocolVersion = uint8(agentConfig.Server.ProtocolVersion)
	}
	if agentConfig.Server.NumSchedulers != 0 {
		conf.NumSchedulers = agentConfig.Server.NumSchedulers
	}
	if len(agentConfig.Server.EnabledSchedulers) != 0 {
		conf.EnabledSchedulers = agentConfig.Server.EnabledSchedulers
	}
	rpcAddr, err := net.ResolveTCPAddr("tcp", agentConfig.normalizedAddrs.RPC)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse RPC address %q: %v", agentConfig.normalizedAddrs.RPC, err)
	}
	serfAddr, err := net.ResolveTCPAddr("tcp", agentConfig.normalizedAddrs.Serf)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse Serf address %q: %v", agentConfig.normalizedAddrs.Serf, err)
	}
	conf.RPCAddr.Port = rpcAddr.Port
	conf.RPCAddr.IP = rpcAddr.IP
	conf.SerfConfig.MemberlistConfig.BindPort = serfAddr.Port
	conf.SerfConfig.MemberlistConfig.BindAddr = serfAddr.IP.String()
	rpcAddr, err = net.ResolveTCPAddr("tcp", agentConfig.AdvertiseAddrs.RPC)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse RPC advertise address %q: %v", agentConfig.AdvertiseAddrs.RPC, err)
	}
	serfAddr, err = net.ResolveTCPAddr("tcp", agentConfig.AdvertiseAddrs.Serf)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse Serf advertise address %q: %v", agentConfig.AdvertiseAddrs.Serf, err)
	}
	conf.RPCAdvertise = rpcAddr
	conf.SerfConfig.MemberlistConfig.AdvertiseAddr = serfAddr.IP.String()
	conf.SerfConfig.MemberlistConfig.AdvertisePort = serfAddr.Port
	if gcThreshold := agentConfig.Server.NodeGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.NodeGCThreshold = dur
	}
	if gcThreshold := agentConfig.Server.JobGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.JobGCThreshold = dur
	}
	if gcThreshold := agentConfig.Server.EvalGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.EvalGCThreshold = dur
	}
	if gcThreshold := agentConfig.Server.DeploymentGCThreshold; gcThreshold != "" {
		dur, err := time.ParseDuration(gcThreshold)
		if err != nil {
			return nil, err
		}
		conf.DeploymentGCThreshold = dur
	}
	if heartbeatGrace := agentConfig.Server.HeartbeatGrace; heartbeatGrace != 0 {
		conf.HeartbeatGrace = heartbeatGrace
	}
	if min := agentConfig.Server.MinHeartbeatTTL; min != 0 {
		conf.MinHeartbeatTTL = min
	}
	if maxHPS := agentConfig.Server.MaxHeartbeatsPerSecond; maxHPS != 0 {
		conf.MaxHeartbeatsPerSecond = maxHPS
	}
	if *agentConfig.Consul.AutoAdvertise && agentConfig.Consul.ServerServiceName == "" {
		return nil, fmt.Errorf("server_service_name must be set when auto_advertise is enabled")
	}
	conf.ConsulConfig = agentConfig.Consul
	conf.VaultConfig = agentConfig.Vault
	conf.TLSConfig = agentConfig.TLSConfig
	return conf, nil
}
func convertServerConfig ( agentConfig * Config , logOutput io . Writer ) ( * nomad . Config , error ) { conf := agentConfig . NomadConfig if conf == nil { conf = nomad . DefaultConfig ( ) } conf . LogOutput = logOutput conf . DevMode = agentConfig . DevMode conf . Build = fmt . Sprintf ( " " , agentConfig . Version , agentConfig . VersionPrerelease ) if agentConfig . Region != " " { conf . Region = agentConfig . Region } if agentConfig . Datacenter != " " { conf . Datacenter = agentConfig . Datacenter } if agentConfig . NodeName != " " { conf . NodeName = agentConfig . NodeName } if agentConfig . Server . BootstrapExpect > 0 { if agentConfig . Server . BootstrapExpect == 1 { conf . Bootstrap = true } else { atomic . StoreInt32 ( & conf . BootstrapExpect , int32 ( agentConfig . Server . BootstrapExpect ) ) } } if agentConfig . DataDir != " " { conf . DataDir = filepath . Join ( agentConfig . DataDir , " " ) } if agentConfig . Server . DataDir != " " { conf . DataDir = agentConfig . Server . DataDir } if agentConfig . Server . ProtocolVersion != 0 { conf . ProtocolVersion = uint8 ( agentConfig . Server . ProtocolVersion ) } if agentConfig . Server . NumSchedulers != 0 { conf . NumSchedulers = agentConfig . Server . NumSchedulers } if len ( agentConfig . Server . EnabledSchedulers ) != 0 { conf . EnabledSchedulers = agentConfig . Server . EnabledSchedulers } rpcAddr , err := net . ResolveTCPAddr ( " " , agentConfig . normalizedAddrs . RPC ) if err != nil { return nil , fmt . Errorf ( " " , agentConfig . normalizedAddrs . RPC , err ) } serfAddr , err := net . ResolveTCPAddr ( " " , agentConfig . normalizedAddrs . Serf ) if err != nil { return nil , fmt . Errorf ( " " , agentConfig . normalizedAddrs . Serf , err ) } conf . RPCAddr . Port = rpcAddr . Port conf . RPCAddr . IP = rpcAddr . IP conf . SerfConfig . MemberlistConfig . BindPort = serfAddr . Port conf . SerfConfig . MemberlistConfig . BindAddr = serfAddr . IP . String ( ) rpcAddr , err = net . ResolveTCPAddr ( " " , agentConfig . AdvertiseAddrs . RPC ) if err != nil { return nil , fmt . Errorf ( " " , agentConfig . AdvertiseAddrs . RPC , err ) } serfAddr , err = net . ResolveTCPAddr ( " " , agentConfig . AdvertiseAddrs . Serf ) if err != nil { return nil , fmt . Errorf ( " " , agentConfig . AdvertiseAddrs . Serf , err ) } conf . RPCAdvertise = rpcAddr conf . SerfConfig . MemberlistConfig . AdvertiseAddr = serfAddr . IP . String ( ) conf . SerfConfig . MemberlistConfig . AdvertisePort = serfAddr . Port if gcThreshold := agentConfig . Server . NodeGCThreshold ; gcThreshold != " " { dur , err := time . ParseDuration ( gcThreshold ) if err != nil { return nil , err } conf . NodeGCThreshold = dur } if gcThreshold := agentConfig . Server . JobGCThreshold ; gcThreshold != " " { dur , err := time . ParseDuration ( gcThreshold ) if err != nil { return nil , err } conf . JobGCThreshold = dur } if gcThreshold := agentConfig . Server . EvalGCThreshold ; gcThreshold != " " { dur , err := time . ParseDuration ( gcThreshold ) if err != nil { return nil , err } conf . EvalGCThreshold = dur } if gcThreshold := agentConfig . Server . DeploymentGCThreshold ; gcThreshold != " " { dur , err := time . ParseDuration ( gcThreshold ) if err != nil { return nil , err } conf . DeploymentGCThreshold = dur } if heartbeatGrace := agentConfig . Server . HeartbeatGrace ; heartbeatGrace != 0 { conf . HeartbeatGrace = heartbeatGrace } if min := agentConfig . Server . MinHeartbeatTTL ; min != 0 { conf . MinHeartbeatTTL = min } if maxHPS := agentConfig . Server . MaxHeartbeatsPerSecond ; maxHPS != 0 { conf . MaxHeartbeatsPerSecond = maxHPS } if * agentConfig . Consul . AutoAdvertise && agentConfig . Consul . ServerServiceName == " " { return nil , fmt . Errorf ( " " ) } conf . ConsulConfig = agentConfig . Consul conf . VaultConfig = agentConfig . Vault conf . TLSConfig = agentConfig . TLSConfig return conf , nil }
convertServerConfig takes an agent config and log output and returns a Nomad
Config.
convertServerConfig takes an agent config and log output and returns a Nomad Config .
// Set up the bind addresses // Set up the advertise addresses // Set up gc threshold and heartbeat grace period // Add the Consul and Vault configs // Set the TLS config