tm

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2019 License: Apache-2.0 Imports: 9 Imported by: 2

README

tm

WIP: TXN2 types model API

Configuration

Configuration is inherited from txn2/micro. The following configuration is specific to tm:

Flag Environment Variable Description
-esServer ELASTIC_SERVER Elasticsearch Server (default "http://elasticsearch:9200")

Examples

The following creates model called test and will result in a record with the id test in the xorg-models index. A mapping template will be also be generated and stored at _template/xorg-data-test:

curl -X POST \
  http://localhost:8080/model/xorg \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{
    "machine_name": "test",
    "display_name": "",
    "description_brief": "",
    "description": "",
    "data_type": "",
    "format": "",
    "parsers": null,
    "type_class": "",
    "group": "",
    "parse": false,
    "index": 0,
    "fields": [
    	{
		    "machine_name": "event_type",
		    "display_name": "Event Type",
		    "description_brief": "",
		    "description": "",
		    "data_type": "keyword",
		    "format": "",
		    "parsers": null,
		    "type_class": "",
		    "group": "",
		    "parse": false,
		    "index": 0
		},
    	{
		    "machine_name": "gps_utc_time",
		    "display_name": "GPS UTC Time",
		    "description_brief": "",
		    "description": "",
		    "data_type": "date",
		    "format": "yyyyMMddHHmmss",
		    "parsers": null,
		    "type_class": "",
		    "group": "",
		    "parse": false,
		    "index": 0
		},
		{
		    "machine_name": "location",
		    "display_name": "",
		    "description_brief": "",
		    "description": "",
		    "data_type": "nested",
		    "format": "",
		    "parsers": null,
		    "type_class": "",
		    "group": "",
		    "parse": false,
		    "index": 0,
		    "fields": [
    	    	{
				    "machine_name": "lat",
				    "display_name": "",
				    "description_brief": "",
				    "description": "",
				    "data_type": "float",
				    "format": "",
				    "parsers": null,
				    "type_class": "",
				    "group": "",
				    "parse": false,
				    "index": 0
				},
    	    	{
				    "machine_name": "lon",
				    "display_name": "",
				    "description_brief": "",
				    "description": "",
				    "data_type": "float",
				    "format": "",
				    "parsers": null,
				    "type_class": "",
				    "group": "",
				    "parse": false,
				    "index": 0
				},				
		    ]
		}
	]
}'

Release Packaging

Build test release:

goreleaser --skip-publish --rm-dist --skip-validate

Build and release:

GITHUB_TOKEN=$GITHUB_TOKEN goreleaser --rm-dist

Documentation

Overview

Copyright 2019 txn2 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const IdxModel = "models"

Variables

This section is empty.

Functions

func GetModelsTemplateMapping

func GetModelsTemplateMapping() es.IndexTemplate

GetModelsTemplateMapping

func MakeModelTemplateMapping

func MakeModelTemplateMapping(account string, model *Model) es.IndexTemplate

MakeModelTemplateMapping creates a template for modeled data coming in from rxtx.

Types

type Api

type Api struct {
	*Config
}

Api

func NewApi

func NewApi(cfg *Config) (*Api, error)

NewApi

func (*Api) GetModel

func (a *Api) GetModel(account string, id string) (int, *ModelResult, error)

GetModel

func (*Api) GetModelHandler

func (a *Api) GetModelHandler(c *gin.Context)

GetModelHandler

func (*Api) SearchModels added in v0.0.4

func (a *Api) SearchModels(account string, searchObj *es.Obj) (int, ModelSearchResults, error)

SearchModels

func (*Api) SearchModelsHandler added in v0.0.4

func (a *Api) SearchModelsHandler(c *gin.Context)

SearchAccountsHandler

func (*Api) SendEsMapping

func (a *Api) SendEsMapping(mapping es.IndexTemplate) (int, es.Result, error)

SetupModelIndexTemplate

func (*Api) UpsertModel

func (a *Api) UpsertModel(account string, model *Model) (int, es.Result, error)

UpsertModel

func (*Api) UpsertModelHandler

func (a *Api) UpsertModelHandler(c *gin.Context)

UpsertModelHandler

type Config

type Config struct {
	Logger     *zap.Logger
	HttpClient *micro.Client

	// used for communication with Elasticsearch
	// if nil, HttpClient will be used.
	Elastic       *es.Client
	ElasticServer string
}

Config

type Model

type Model struct {
	// a lowercase under score delimited uniq id
	MachineName string `json:"machine_name" mapstructure:"machine_name"`

	// short human readable display name
	DisplayName string `json:"display_name" mapstructure:"display_name"`

	// a single sentence description
	BriefDescription string `json:"description_brief" mapstructure:"description_brief"`

	// full documentation in markdown
	Description string `json:"description" mapstructure:"description"`

	// integer, float, date, binary, text and keyword
	DataType string `json:"data_type" mapstructure:"data_type"`

	// used for data formats
	Format string `json:"format" mapstructure:"format"`

	// named parsers
	Parsers []string `json:"parsers" mapstructure:"parsers"`

	// belongs to a class of models
	TypeClass string `json:"type_class" mapstructure:"type_class"`

	// groups models
	Group string `json:"group" mapstructure:"group"`

	// false to ignore inbound parsing
	Parse bool `json:"parse" mapstructure:"parse"`

	// used by parsers of element ordered inbound data
	Index int `json:"index" mapstructure:"index"`

	// children of this model
	Fields []Model `json:"fields" mapstructure:"fields"`
}

Model

type ModelResult

type ModelResult struct {
	es.Result
	Source Model `json:"_source"`
}

ModelResult returned from Elastic

type ModelSearchResults added in v0.0.4

type ModelSearchResults struct {
	es.SearchResults
	Hits struct {
		Total    int           `json:"total"`
		MaxScore float64       `json:"max_score"`
		Hits     []ModelResult `json:"hits"`
	} `json:"hits"`
}

ModelSearchResults

type ModelSearchResultsAck added in v0.0.4

type ModelSearchResultsAck struct {
	ack.Ack
	Payload ModelSearchResults `json:"payload"`
}

AccountSearchResultsAck

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL