Esempio n. 1
0
func (this *Server) SetPlusServicers(plusServicers int) {
	this.Lock()
	defer this.Unlock()
	// Stop the current set of servicers
	close(this.plusDone)
	logging.Infop("SetPlusServicers - waiting for current plusServicers to finish")
	this.plusWg.Wait()
	// Set plus servicer count and recreate plus servicers
	atomic.StoreInt64(&this.plusServicers, int64(plusServicers))
	logging.Infop("SetPlusServicers - starting new plusServicers")
	// Start new set of servicers
	this.plusDone = make(chan bool)
	go this.PlusServe()
}
Esempio n. 2
0
func (this *HttpEndpoint) ListenTLS() error {
	// create tls configuration
	tlsCert, err := tls.LoadX509KeyPair(this.certFile, this.keyFile)
	if err != nil {
		return err
	}

	ln, err := net.Listen("tcp", this.httpsAddr)
	if err == nil {
		cfg := &tls.Config{
			Certificates: []tls.Certificate{tlsCert},
			ClientAuth:   tls.NoClientCert,
			MinVersion:   tls.VersionTLS10,
			CipherSuites: []uint16{tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
				tls.TLS_RSA_WITH_AES_128_CBC_SHA,
				tls.TLS_RSA_WITH_AES_256_CBC_SHA,
				tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
				tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
				tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
		}
		tls_ln := tls.NewListener(ln, cfg)
		this.listenerTLS = tls_ln
		go http.Serve(tls_ln, this.mux)
		logging.Infop("HttpEndpoint: ListenTLS", logging.Pair{"Address", ln.Addr()})
	}
	return err
}
Esempio n. 3
0
func TestStub(t *testing.T) {
	logger := NewLogger(os.Stdout, logging.DEBUG, false)
	logging.SetLogger(logger)

	logger.Infof("This is a message from %s", "test")
	logging.Infof("This is a message from %s", "test")
	logger.Infop("This is a message from ", logging.Pair{"name", "test"}, logging.Pair{"Queue Size", 10}, logging.Pair{"Debug Mode", false})
	logging.Infop("This is a message from ", logging.Pair{"name", "test"})

	logger.Infom("This is a message from ", logging.Map{"name": "test", "Queue Size": 10, "Debug Mode": false})
	logging.Infom("This is a message from ", logging.Map{"name": "test"})

	logger.Requestf(logging.WARN, "This is a Request from %s", "test")
	logging.Requestf(logging.INFO, "This is a Request from %s", "test")
	logger.Requestp(logging.DEBUG, "This is a Request from ", logging.Pair{"name", "test"})
	logging.Requestp(logging.ERROR, "This is a Request from ", logging.Pair{"name", "test"})

	logger.SetLevel(logging.WARN)
	fmt.Printf("Log level is %s\n", logger.Level())

	logger.Requestf(logging.WARN, "This is a Request from %s", "test")
	logging.Requestf(logging.INFO, "This is a Request from %s", "test")
	logger.Requestp(logging.DEBUG, "This is a Request from ", logging.Pair{"name", "test"})
	logging.Requestp(logging.ERROR, "This is a Request from ", logging.Pair{"name", "test"})

	logger.Warnf("This is a message from %s", "test")
	logging.Infof("This is a message from %s", "test")
	logger.Debugp("This is a message from ", logging.Pair{"name", "test"})
	logging.Errorp("This is a message from ", logging.Pair{"name", "test"})

	fmt.Printf("Changing to json formatter\n")
	logger.entryFormatter = &jsonFormatter{}
	logger.SetLevel(logging.DEBUG)

	logger.Infof("This is a message from %s", "test")
	logging.Infof("This is a message from %s", "test")
	logger.Infop("This is a message from ", logging.Pair{"name", "test"}, logging.Pair{"Queue Size", 10}, logging.Pair{"Debug Mode", false})
	logging.Infop("This is a message from ", logging.Pair{"name", "test"})

	logger.Infom("This is a message from ", logging.Map{"name": "test", "Queue Size": 10, "Debug Mode": false})
	logging.Infom("This is a message from ", logging.Map{"name": "test"})

	logger.Requestf(logging.WARN, "This is a Request from %s", "test")
	logging.Requestf(logging.INFO, "This is a Request from %s", "test")
	logger.Requestp(logging.DEBUG, "This is a Request from ", logging.Pair{"name", "test"})
	logging.Requestp(logging.ERROR, "This is a Request from ", logging.Pair{"name", "test"})
}
Esempio n. 4
0
func (this *HttpEndpoint) closeListener(l net.Listener) error {
	var err error
	if l != nil {
		err = l.Close()
		logging.Infop("HttpEndpoint: close listener ", logging.Pair{"Address", l.Addr()}, logging.Pair{"err", err})
	}
	return err
}
Esempio n. 5
0
func (this *HttpEndpoint) Listen() error {
	ln, err := net.Listen("tcp", this.httpAddr)
	if err == nil {
		this.listener = ln
		go http.Serve(ln, this.mux)
		logging.Infop("HttpEndpoint: Listen", logging.Pair{"Address", ln.Addr()})
	}
	return err
}
Esempio n. 6
0
func pollStdin() {
	reader := bufio.NewReader(os.Stdin)
	logging.Infop("pollEOF: About to start stdin polling")
	for {
		ch, err := reader.ReadByte()
		if err == io.EOF {
			logging.Infop("Received EOF; Exiting...")
			os.Exit(0)
		}
		if err != nil {
			logging.Errorp("Unexpected error polling stdin",
				logging.Pair{"error", err})
			os.Exit(1)
		}
		if ch == '\n' || ch == '\r' {
			logging.Infop("Received EOL; Exiting...")
			// TODO: "graceful" shutdown should be placed here
			os.Exit(0)
		}
	}
}
Esempio n. 7
0
func TestRequestDefaults(t *testing.T) {
	statement := "select 1"
	logging.Infop("message", logging.Pair{"statement", statement})
	doUrlRequest(t, map[string]string{
		"statement": statement,
	})
	if test_server.request().State() != server.COMPLETED {
		t.Errorf("Expected request state: %v, actual: %v\n", server.COMPLETED, test_server.request().State())
	}
	if test_server.request().Statement() != statement {
		t.Errorf("Expected request statement: %v, actual: %v\n", statement, test_server.request().Statement())
	}
}
Esempio n. 8
0
// signalCatcher blocks until a signal is recieved and then takes appropriate action
func signalCatcher(server *server.Server, endpoint *http.HttpEndpoint) {
	sig_chan := make(chan os.Signal, 4)
	signal.Notify(sig_chan, os.Interrupt, syscall.SIGTERM)

	var s os.Signal
	select {
	case s = <-sig_chan:
	}
	if server.CpuProfile() != "" {
		logging.Infop("Stopping CPU profile")
		pprof.StopCPUProfile()
	}
	if server.MemProfile() != "" {
		f, err := os.Create(server.MemProfile())
		if err != nil {
			logging.Errorp("Cannot create memory profile file", logging.Pair{"error", err})
		} else {

			logging.Infop("Writing  Memory profile")
			pprof.WriteHeapProfile(f)
			f.Close()
		}
	}
	if s == os.Interrupt {
		// Interrupt (ctrl-C) => Immediate (ungraceful) exit
		logging.Infop("Shutting down immediately")
		os.Exit(0)
	}
	logging.Infop("Attempting graceful exit")
	// Stop accepting new requests
	err := endpoint.Close()
	if err != nil {
		logging.Errorp("error closing http listener", logging.Pair{"err", err})
	}
	err = endpoint.CloseTLS()
	if err != nil {
		logging.Errorp("error closing https listener", logging.Pair{"err", err})
	}
}
Esempio n. 9
0
func (this *Fetch) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_     string `json:"#operator"`
		Proj  string `json:"projection"`
		Names string `json:"namespace"`
		Keys  string `json:"keyspace"`
		As    string `json:"as"`
	}
	var proj_expr expression.Path

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return err
	}

	if _unmarshalled.Proj != "" {
		expr, err := parser.Parse(_unmarshalled.Proj)

		logging.Infop("Fetch", logging.Pair{"_unmarshalled.Proj", _unmarshalled.Proj},
			logging.Pair{"err", err},
			logging.Pair{"expr", expr},
		)
		if err != nil {
			return err
		}

		_proj_expr, is_path := expr.(expression.Path)
		if !is_path {
			return fmt.Errorf("Fetch.UnmarshalJSON: cannot resolve path expression from %s", _unmarshalled.Proj)
		}
		proj_expr = _proj_expr
	}
	this.term = algebra.NewKeyspaceTerm(_unmarshalled.Names, _unmarshalled.Keys,
		proj_expr, _unmarshalled.As, nil, nil)

	this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys)

	return err
}
Esempio n. 10
0
func main() {
	HideConsole(true)
	defer HideConsole(false)

	// useful for getting list of go-routines
	go go_http.ListenAndServe("localhost:6060", nil)

	flag.Parse()

	if *LOGGER != "" {
		logger, _ := log_resolver.NewLogger(*LOGGER)
		if logger == nil {
			fmt.Printf("Invalid logger: %s\n", *LOGGER)
			os.Exit(1)
		}

		logging.SetLogger(logger)
	}

	if *DEBUG {
		logging.SetLevel(logging.DEBUG)
	} else {
		level := logging.INFO

		if *LOG_LEVEL != "" {
			lvl, ok := logging.ParseLevel(*LOG_LEVEL)
			if ok {
				level = lvl
			}
		}

		logging.SetLevel(level)
	}

	datastore, err := resolver.NewDatastore(*DATASTORE)
	if err != nil {
		logging.Errorp(err.Error())
		os.Exit(1)
	}
	datastore_package.SetDatastore(datastore)

	configstore, err := config_resolver.NewConfigstore(*CONFIGSTORE)
	if err != nil {
		logging.Errorp("Could not connect to configstore",
			logging.Pair{"error", err},
		)
	}
	acctstore, err := acct_resolver.NewAcctstore(*ACCTSTORE)
	if err != nil {
		logging.Errorp("Could not connect to acctstore",
			logging.Pair{"error", err},
		)
	} else {
		// Create the metrics we are interested in
		accounting.RegisterMetrics(acctstore)
		// Make metrics available
		acctstore.MetricReporter().Start(1, 1)
	}

	channel := make(server.RequestChannel, *REQUEST_CAP)
	plusChannel := make(server.RequestChannel, *REQUEST_CAP)

	sys, err := system.NewDatastore(datastore)
	if err != nil {
		logging.Errorp(err.Error())
		os.Exit(1)
	}

	server, err := server.NewServer(datastore, sys, configstore, acctstore, *NAMESPACE,
		*READONLY, channel, plusChannel, *SERVICERS, *PLUS_SERVICERS,
		*MAX_PARALLELISM, *TIMEOUT, *SIGNATURE, *METRICS, *ENTERPRISE)
	if err != nil {
		logging.Errorp(err.Error())
		os.Exit(1)
	}

	datastore_package.SetSystemstore(server.Systemstore())

	server.SetCpuProfile(*CPU_PROFILE)
	server.SetKeepAlive(*KEEP_ALIVE_LENGTH)
	server.SetMemProfile(*MEM_PROFILE)
	server.SetPipelineCap(*PIPELINE_CAP)
	server.SetPipelineBatch(*PIPELINE_BATCH)
	server.SetRequestSizeCap(*REQUEST_SIZE_CAP)
	server.SetScanCap(*SCAN_CAP)

	if server.Enterprise() && os.Getenv("GOMAXPROCS") == "" {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}

	if !server.Enterprise() {
		var numCPU int
		if os.Getenv("GOMAXPROCS") == "" {
			numCPU = runtime.NumCPU()
		} else {
			numCPU = runtime.GOMAXPROCS(0)
		}

		// Use at most 4 cpus in non-enterprise mode
		runtime.GOMAXPROCS(util.MinInt(numCPU, 4))
	}

	go server.Serve()
	go server.PlusServe()

	logging.Infop("cbq-engine started",
		logging.Pair{"version", util.VERSION},
		logging.Pair{"datastore", *DATASTORE},
		logging.Pair{"max-concurrency", runtime.GOMAXPROCS(0)},
		logging.Pair{"loglevel", logging.LogLevel().String()},
		logging.Pair{"servicers", server.Servicers()},
		logging.Pair{"plus-servicers", server.PlusServicers()},
		logging.Pair{"pipeline-cap", server.PipelineCap()},
		logging.Pair{"pipeline-batch", *PIPELINE_BATCH},
		logging.Pair{"request-cap", *REQUEST_CAP},
		logging.Pair{"request-size-cap", server.RequestSizeCap()},
		logging.Pair{"timeout", server.Timeout()},
	)

	// Create http endpoint
	endpoint := http.NewServiceEndpoint(server, *STATIC_PATH, *METRICS,
		*HTTP_ADDR, *HTTPS_ADDR, *CERT_FILE, *KEY_FILE)
	er := endpoint.Listen()
	if er != nil {
		logging.Errorp("cbq-engine exiting with error",
			logging.Pair{"error", er},
			logging.Pair{"HTTP_ADDR", *HTTP_ADDR},
		)
		os.Exit(1)
	}
	if server.Enterprise() && *CERT_FILE != "" && *KEY_FILE != "" {
		er := endpoint.ListenTLS()
		if er != nil {
			logging.Errorp("cbq-engine exiting with error",
				logging.Pair{"error", er},
				logging.Pair{"HTTPS_ADDR", *HTTPS_ADDR},
			)
			os.Exit(1)
		}
	}
	signalCatcher(server, endpoint)
}