Exemplo n.º 1
0
func NewAgentServer(option *AgentServerOption) *AgentServer {
	absoluteDir, err := filepath.Abs(util.CleanPath(*option.Dir))
	if err != nil {
		panic(err)
	}
	println("starting in", absoluteDir)
	option.Dir = &absoluteDir

	as := &AgentServer{
		Option:         option,
		Master:         *option.Master,
		Port:           *option.Port,
		storageBackend: NewManagedDatasetShards(*option.Dir, *option.Port),
		computeResource: &resource.ComputeResource{
			CPUCount: *option.MaxExecutor,
			CPULevel: *option.CPULevel,
			MemoryMB: *option.MemoryMB,
		},
		allocatedResource: &resource.ComputeResource{},
	}

	err = as.Init()
	if err != nil {
		panic(err)
	}

	return as
}
Exemplo n.º 2
0
func NewAgentServer(option *AgentServerOption) *AgentServer {
	absoluteDir, err := filepath.Abs(util.CleanPath(*option.Dir))
	if err != nil {
		panic(err)
	}
	println("starting in", absoluteDir)
	option.Dir = &absoluteDir

	var lock sync.Mutex

	as := &AgentServer{
		Option:         option,
		Master:         *option.Master,
		Port:           *option.Port,
		dir:            absoluteDir,
		name2Store:     make(map[string]*LiveDataStore),
		name2StoreCond: sync.NewCond(&lock),
		computeResource: &resource.ComputeResource{
			CPUCount: *option.MaxExecutor,
			CPULevel: *option.CPULevel,
			MemoryMB: *option.MemoryMB,
		},
		allocatedResource: &resource.ComputeResource{},
	}

	err = as.Init()
	if err != nil {
		panic(err)
	}

	return as
}
Exemplo n.º 3
0
func (c *CertFiles) MakeTLSConfig() *tls.Config {
	if !c.IsEnabled() {
		return nil
	}

	certFile, err := filepath.Abs(util.CleanPath(c.CertFile))
	if err != nil {
		panic(fmt.Errorf("Failed to load cert file %s: %v", c.CertFile, err))
	}
	keyFile, err := filepath.Abs(util.CleanPath(c.KeyFile))
	if err != nil {
		panic(fmt.Errorf("Failed to load cert file %s: %v", c.KeyFile, err))
	}
	caFile, err := filepath.Abs(util.CleanPath(c.CaFile))
	if err != nil {
		panic(fmt.Errorf("Failed to load cert file %s: %v", c.CaFile, err))
	}

	// Load cert
	cert, err := tls.LoadX509KeyPair(certFile, keyFile)
	if err != nil {
		log.Fatal(err)
	}

	// Load CA cert
	caCert, err := ioutil.ReadFile(caFile)
	if err != nil {
		log.Fatal(err)
	}
	caCertPool := x509.NewCertPool()
	caCertPool.AppendCertsFromPEM(caCert)

	// Create tls config
	tlsConfig := &tls.Config{
		Certificates:       []tls.Certificate{cert},
		RootCAs:            caCertPool,
		ClientCAs:          caCertPool,
		ClientAuth:         tls.RequireAndVerifyClientCert, // server side setting
		InsecureSkipVerify: false,                          // client side setting
	}
	tlsConfig.BuildNameToCertificate()

	return tlsConfig
}