コード例 #1
0
ファイル: agent.go プロジェクト: zanella/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf, err := a.clientConfig()
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}

	// Reserve some ports for the plugins if we are on Windows
	if runtime.GOOS == "windows" {
		if err := a.reservePortsForClient(conf); err != nil {
			return err
		}
	}

	// Create the client
	client, err := client.NewClient(conf, a.consulSyncer, a.logger)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client

	// Resolve the http check address
	httpCheckAddr := a.config.normalizedAddrs.HTTP
	if a.config.Consul.ChecksUseAdvertise {
		httpCheckAddr = a.config.AdvertiseAddrs.HTTP
	}

	// Create the Nomad Client  services for Consul
	// TODO think how we can re-introduce HTTP/S checks when Consul 0.7.1 comes
	// out
	if a.config.Consul.AutoAdvertise {
		httpServ := &structs.Service{
			Name:      a.config.Consul.ClientServiceName,
			PortLabel: a.config.AdvertiseAddrs.HTTP,
			Tags:      []string{consul.ServiceTagHTTP},
			Checks: []*structs.ServiceCheck{
				&structs.ServiceCheck{
					Name:      "Nomad Client HTTP Check",
					Type:      "http",
					Path:      "/v1/agent/servers",
					Protocol:  "http",
					Interval:  clientHttpCheckInterval,
					Timeout:   clientHttpCheckTimeout,
					PortLabel: httpCheckAddr,
				},
			},
		}
		if !conf.TLSConfig.EnableHTTP {
			a.consulSyncer.SetServices(consul.ClientDomain, map[consul.ServiceKey]*structs.Service{
				consul.GenerateServiceKey(httpServ): httpServ,
			})
		}
	}

	return nil
}
コード例 #2
0
ファイル: agent.go プロジェクト: carriercomm/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf, err := a.clientConfig()
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}

	// Reserve some ports for the plugins if we are on Windows
	if runtime.GOOS == "windows" {
		if err := a.reservePortsForClient(conf); err != nil {
			return err
		}
	}

	// Create the client
	client, err := client.NewClient(conf)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client
	return nil
}
コード例 #3
0
ファイル: agent.go プロジェクト: bastiaanb/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf := a.config.ClientConfig
	if conf == nil {
		conf = client.DefaultConfig()
	}
	if a.server != nil {
		conf.RPCHandler = a.server
	}
	conf.LogOutput = a.logOutput
	conf.DevMode = a.config.DevMode
	if a.config.Region != "" {
		conf.Region = a.config.Region
	}
	if a.config.DataDir != "" {
		conf.StateDir = filepath.Join(a.config.DataDir, "client")
		conf.AllocDir = filepath.Join(a.config.DataDir, "alloc")
	}
	if a.config.Client.StateDir != "" {
		conf.StateDir = a.config.Client.StateDir
	}
	if a.config.Client.AllocDir != "" {
		conf.AllocDir = a.config.Client.AllocDir
	}
	conf.Servers = a.config.Client.Servers
	if a.config.Client.NetworkInterface != "" {
		conf.NetworkInterface = a.config.Client.NetworkInterface
	}
	conf.Options = a.config.Client.Options
	if a.config.Client.NetworkSpeed != 0 {
		conf.NetworkSpeed = a.config.Client.NetworkSpeed
	}
	if a.config.Client.MaxKillTimeout != "" {
		dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout)
		if err != nil {
			return fmt.Errorf("Error parsing retry interval: %s", err)
		}
		conf.MaxKillTimeout = dur
	}

	// Setup the node
	conf.Node = new(structs.Node)
	conf.Node.Datacenter = a.config.Datacenter
	conf.Node.Name = a.config.NodeName
	conf.Node.ID = a.config.Client.NodeID
	conf.Node.Meta = a.config.Client.Meta
	conf.Node.NodeClass = a.config.Client.NodeClass

	// Create the client
	client, err := client.NewClient(conf)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client
	return nil
}
コード例 #4
0
ファイル: agent.go プロジェクト: nak3/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf, err := a.clientConfig()
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}

	// Reserve some ports for the plugins if we are on Windows
	if runtime.GOOS == "windows" {
		if err := a.reservePortsForClient(conf); err != nil {
			return err
		}
	}

	// Create the client
	client, err := client.NewClient(conf, a.consulSyncer, a.logger)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client

	// Create the Nomad Client  services for Consul
	if a.config.Consul.AutoAdvertise {
		httpServ := &structs.Service{
			Name:      a.config.Consul.ClientServiceName,
			PortLabel: a.clientHTTPAddr,
			Tags:      []string{consul.ServiceTagHTTP},
			Checks: []*structs.ServiceCheck{
				&structs.ServiceCheck{
					Name:     "Nomad Client HTTP Check",
					Type:     "http",
					Path:     "/v1/agent/servers",
					Protocol: "http", // TODO TLS
					Interval: clientHttpCheckInterval,
					Timeout:  clientHttpCheckTimeout,
				},
			},
		}
		a.consulSyncer.SetServices(consul.ClientDomain, map[consul.ServiceKey]*structs.Service{
			consul.GenerateServiceKey(httpServ): httpServ,
		})
	}

	return nil
}
コード例 #5
0
ファイル: agent.go プロジェクト: rbramwell/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf := a.config.ClientConfig
	if conf == nil {
		conf = client.DefaultConfig()
	}
	if a.server != nil {
		conf.RPCHandler = a.server
	}
	conf.LogOutput = a.logOutput
	conf.DevMode = a.config.DevMode
	if a.config.Region != "" {
		conf.Region = a.config.Region
	}
	if a.config.DataDir != "" {
		conf.StateDir = filepath.Join(a.config.DataDir, "client")
		conf.AllocDir = filepath.Join(a.config.DataDir, "alloc")
	}
	if a.config.Client.StateDir != "" {
		conf.StateDir = a.config.Client.StateDir
	}
	if a.config.Client.AllocDir != "" {
		conf.AllocDir = a.config.Client.AllocDir
	}
	conf.Servers = a.config.Client.Servers

	// Setup the node
	conf.Node = new(structs.Node)
	conf.Node.Datacenter = a.config.Datacenter
	conf.Node.Name = a.config.NodeName
	conf.Node.ID = a.config.Client.NodeID
	conf.Node.Meta = a.config.Client.Meta
	conf.Node.NodeClass = a.config.Client.NodeClass

	// Create the client
	client, err := client.NewClient(conf)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client
	return nil
}
コード例 #6
0
ファイル: agent.go プロジェクト: hooklift/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf, err := a.clientConfig()
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}

	// Reserve some ports for the plugins if we are on Windows
	if runtime.GOOS == "windows" {
		if err := a.reservePortsForClient(conf); err != nil {
			return err
		}
	}

	// Create the client
	client, err := client.NewClient(conf, a.consulSyncer)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client

	// Create the Nomad Client  services for Consul
	if a.config.Consul.AutoAdvertise {
		httpServ := &structs.Service{
			Name:      a.config.Consul.ClientServiceName,
			PortLabel: a.clientHTTPAddr,
			Tags:      []string{consul.ServiceTagHTTP},
		}
		rpcServ := &structs.Service{
			Name:      a.config.Consul.ClientServiceName,
			PortLabel: a.clientRPCAddr,
			Tags:      []string{consul.ServiceTagRPC},
		}
		a.consulSyncer.SetServices(consul.ClientDomain, map[consul.ServiceKey]*structs.Service{
			consul.GenerateServiceKey(httpServ): httpServ,
			consul.GenerateServiceKey(rpcServ):  rpcServ,
		})
	}

	return nil
}
コード例 #7
0
ファイル: agent.go プロジェクト: stigkj/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf := a.config.ClientConfig
	if conf == nil {
		conf = client.DefaultConfig()
	}
	if a.server != nil {
		conf.RPCHandler = a.server
	}
	conf.LogOutput = a.logOutput
	conf.DevMode = a.config.DevMode
	if a.config.Region != "" {
		conf.Region = a.config.Region
	}
	if a.config.DataDir != "" {
		conf.StateDir = filepath.Join(a.config.DataDir, "client")
		conf.AllocDir = filepath.Join(a.config.DataDir, "alloc")
	}
	if a.config.Client.StateDir != "" {
		conf.StateDir = a.config.Client.StateDir
	}
	if a.config.Client.AllocDir != "" {
		conf.AllocDir = a.config.Client.AllocDir
	}
	conf.Servers = a.config.Client.Servers
	if a.config.Client.NetworkInterface != "" {
		conf.NetworkInterface = a.config.Client.NetworkInterface
	}
	conf.Options = a.config.Client.Options
	if a.config.Client.NetworkSpeed != 0 {
		conf.NetworkSpeed = a.config.Client.NetworkSpeed
	}
	if a.config.Client.MaxKillTimeout != "" {
		dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout)
		if err != nil {
			return fmt.Errorf("Error parsing retry interval: %s", err)
		}
		conf.MaxKillTimeout = dur
	}
	conf.ClientMaxPort = a.config.Client.ClientMaxPort
	conf.ClientMinPort = a.config.Client.ClientMinPort

	// Setup the node
	conf.Node = new(structs.Node)
	conf.Node.Datacenter = a.config.Datacenter
	conf.Node.Name = a.config.NodeName
	conf.Node.Meta = a.config.Client.Meta
	conf.Node.NodeClass = a.config.Client.NodeClass
	httpAddr := fmt.Sprintf("%s:%d", a.config.BindAddr, a.config.Ports.HTTP)
	if a.config.Addresses.HTTP != "" && a.config.AdvertiseAddrs.HTTP == "" {
		addr, err := net.ResolveTCPAddr("tcp", a.config.Addresses.HTTP)
		if err != nil {
			return fmt.Errorf("error resolving http addr: %v:", err)
		}
		httpAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)
	} else if a.config.AdvertiseAddrs.HTTP != "" {
		addr, err := net.ResolveTCPAddr("tcp", a.config.AdvertiseAddrs.HTTP)
		if err != nil {
			return fmt.Errorf("error resolving advertise http addr: %v", err)
		}
		httpAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)
	}
	conf.Node.HTTPAddr = httpAddr

	// Reserve some ports for the plugins
	if err := a.reservePortsForClient(conf); err != nil {
		return err
	}

	// Create the client
	client, err := client.NewClient(conf)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client
	return nil
}
コード例 #8
0
ファイル: agent.go プロジェクト: shadabahmed/nomad
// setupClient is used to setup the client if enabled
func (a *Agent) setupClient() error {
	if !a.config.Client.Enabled {
		return nil
	}

	// Setup the configuration
	conf := a.config.ClientConfig
	if conf == nil {
		conf = client.DefaultConfig()
	}
	if a.server != nil {
		conf.RPCHandler = a.server
	}
	conf.LogOutput = a.logOutput
	conf.DevMode = a.config.DevMode
	if a.config.Region != "" {
		conf.Region = a.config.Region
	}
	if a.config.DataDir != "" {
		conf.StateDir = filepath.Join(a.config.DataDir, "client")
		conf.AllocDir = filepath.Join(a.config.DataDir, "alloc")
	}
	if a.config.Client.StateDir != "" {
		conf.StateDir = a.config.Client.StateDir
	}
	if a.config.Client.AllocDir != "" {
		conf.AllocDir = a.config.Client.AllocDir
	}
	conf.Servers = a.config.Client.Servers
	if a.config.Client.NetworkInterface != "" {
		conf.NetworkInterface = a.config.Client.NetworkInterface
	}
	conf.Options = a.config.Client.Options
	if a.config.Client.NetworkSpeed != 0 {
		conf.NetworkSpeed = a.config.Client.NetworkSpeed
	}
	if a.config.Client.MaxKillTimeout != "" {
		dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout)
		if err != nil {
			return fmt.Errorf("Error parsing retry interval: %s", err)
		}
		conf.MaxKillTimeout = dur
	}
	conf.ClientMaxPort = a.config.Client.ClientMaxPort
	conf.ClientMinPort = a.config.Client.ClientMinPort

	// Setup the node
	conf.Node = new(structs.Node)
	conf.Node.Datacenter = a.config.Datacenter
	conf.Node.Name = a.config.NodeName
	conf.Node.Meta = a.config.Client.Meta
	conf.Node.NodeClass = a.config.Client.NodeClass
	httpAddr := fmt.Sprintf("%s:%d", a.config.BindAddr, a.config.Ports.HTTP)
	if a.config.Addresses.HTTP != "" && a.config.AdvertiseAddrs.HTTP == "" {
		addr, err := net.ResolveTCPAddr("tcp", a.config.Addresses.HTTP)
		if err != nil {
			return fmt.Errorf("error resolving http addr: %v:", err)
		}
		httpAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)
	} else if a.config.AdvertiseAddrs.HTTP != "" {
		addr, err := net.ResolveTCPAddr("tcp", a.config.AdvertiseAddrs.HTTP)
		if err != nil {
			return fmt.Errorf("error resolving advertise http addr: %v", err)
		}
		httpAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)
	}
	conf.Node.HTTPAddr = httpAddr

	// Reserve some ports for the plugins
	if runtime.GOOS == "windows" {
		deviceName, err := a.findLoopbackDevice()
		if err != nil {
			return fmt.Errorf("error finding the device name for loopback: %v", err)
		}
		var nr *structs.NetworkResource
		for _, n := range conf.Node.Reserved.Networks {
			if n.Device == deviceName {
				nr = n
			}
		}
		if nr == nil {
			nr = &structs.NetworkResource{
				Device:        deviceName,
				ReservedPorts: make([]structs.Port, 0),
			}
		}
		for i := conf.ClientMinPort; i <= conf.ClientMaxPort; i++ {
			nr.ReservedPorts = append(nr.ReservedPorts, structs.Port{Label: fmt.Sprintf("plugin-%d", i), Value: int(i)})
		}
	}

	// Create the client
	client, err := client.NewClient(conf)
	if err != nil {
		return fmt.Errorf("client setup failed: %v", err)
	}
	a.client = client
	return nil
}