示例#1
0
// SetVars sets up the environment for InsertStatement to call it's Run function
func (i *InsertStatement) SetVars(s *ponyExpress.StoreFront) chan<- string {
	// Set the #series at 1 to start
	i.series = 1

	// Num series is the product of the cardinality of the tags
	for _, tmpl := range i.Templates[0:i.TagCount] {
		i.series *= tmpl.numSeries()
	}

	// make stringers from the templates
	i.stringers = i.Templates.Init(i.series)

	// Set the time function, keeps track of 'time' of the points being created
	i.time = i.Timestamp.Time(s.StartDate, i.series, s.Precision)

	// Set a commune on the StoreFront
	s.Lock()
	comCh := s.SetCommune(i.Name)
	s.Unlock()

	// Set the tracer
	i.Tracer = ponyExpress.NewTracer(i.tags())

	return comCh
}
示例#2
0
// Run statisfies the Statement Interface
func (i *QueryStatement) Run(s *ponyExpress.StoreFront) {

	// Set the tracer
	i.Tracer = ponyExpress.NewTracer(i.tags())

	vals := make(map[string]interface{})

	var point models.Point

	runtime := time.Now()

	for j := 0; j < i.Count; j++ {

		// If the query is a simple query, send it.
		if len(i.Args) == 0 {
			b := []byte(i.TemplateString)

			// Make the package
			p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer)

			// Increment the tracer
			i.Tracer.Add(1)

			// Send the package
			s.SendPackage(p)

		} else {
			// Otherwise cherry pick field values from the commune?

			// TODO: Currently the program lock up here if s.GetPoint
			//       cannot return a value, which can happen.
			// Seee insert.go
			s.Lock()
			point = s.GetPoint(i.Name, s.Precision)
			s.Unlock()

			setMapValues(vals, point)

			// Set the template string with args from the commune
			b := []byte(fmt.Sprintf(i.TemplateString, setArgs(vals, i.Args)...))

			// Make the package
			p := ponyExpress.NewPackage(ponyExpress.Query, b, i.StatementID, i.Tracer)

			// Increment the tracer
			i.Tracer.Add(1)

			// Send the package
			s.SendPackage(p)

		}
	}

	// Wait for all operations to finish
	i.Tracer.Wait()

	// Stop time timer
	i.runtime = time.Since(runtime)
}
示例#3
0
// Run statisfies the Statement Interface
func (i *SetStatement) Run(s *ponyExpress.StoreFront) {

	// Set the Tracer
	i.Tracer = ponyExpress.NewTracer(make(map[string]string))

	// Create a new Directive
	d := ponyExpress.NewDirective(strings.ToLower(i.Var), strings.ToLower(i.Value), i.Tracer)

	switch d.Property {

	// Needs to be set on both StoreFront and ponyExpress
	// Set the write percison for points generated
	case "precision":
		s.Precision = d.Value

		// Increment the tracer
		i.Tracer.Add(1)
		s.SendDirective(d)

	// Lives on StoreFront
	// Set the date for the first point entered into the database
	case "startdate":
		s.Lock()
		s.StartDate = d.Value
		s.Unlock()

	// Lives on StoreFront
	// Set the BatchSize for writes
	case "batchsize":
		s.Lock()
		s.BatchSize = parseInt(d.Value)
		s.Unlock()

	// Lives on StoreFront
	// Reset the ResultsClient to have a new address
	case "resultsaddress":
		s.Lock()
		s.SetResultsClient(influx.HTTPConfig{Addr: fmt.Sprintf("http://%v/", d.Value)})
		s.Unlock()

	// TODO: Make TestName actually change the reporting DB
	// Lives on StoreFront
	// Set the TestName that controls reporting DB
	case "testname":
		s.Lock()
		s.TestName = d.Value
		s.Unlock()

	// All other variables live on ponyExpress
	default:
		// Increment the tracer
		i.Tracer.Add(1)
		s.SendDirective(d)
	}
	i.Tracer.Wait()
}