models

package
v0.0.0-...-6a25cbf Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Licensed under the Apache License, Version 2.0 (the "License"); you may not use p 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.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use p 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.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use p 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.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use p 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.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use p 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.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use p 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.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use p 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 (
	DEPLOYMENT_STATUS_CREATED = "created"
	DEPLOYMENT_STATUS_RUNNING = "running"
	DEPLOYMENT_STATUS_STOPPED = "stopped"
	DEPLOYMENT_STATUS_UNKNOWN = "unknown"
)
View Source
const (
	METADATA_DEVICE_TYPE = "deviceType"
	METADATA_DEVICE_NAME = "deviceName"
	METADATA_REQUEST_ID  = "requestId"
	METADATA_USER_NAME   = "userName"
	METADATA_USER_ID     = "userId"
	METADATA_TIMESTAMP   = "timestamp"
)

Predefined metadata key

View Source
const (
	MESSAGE_TYPE_POST_ATTRIBUTES_REQUEST = "Post attributes"
	MESSAGE_TYPE_POST_TELEMETRY_REQUEST  = "Post telemetry"
	MESSAGE_TYPE_ACTIVITY_EVENT          = "Activity event"
	MESSAGE_TYPE_INACTIVITY_EVENT        = "Inactivity event"
	MESSAGE_TYPE_CONNECT_EVENT           = "Connect event"
	MESSAGE_TYPE_DISCONNECT_EVENT        = "Disconnect event"
)

Predefined message types

View Source
const (
	ModelActionCreated = "created"
	ModelActionUpdated = "updated"
	ModelActionDeleted = "deleted"
)
View Source
const (
	RULESTATUS_CREATED = "created"
	RULESTATUS_STARTED = "started"
	RULESTATUS_STOPPED = "stopped"
	RULESTATUS_UNKNOWN = "unknown"
)

Variables

View Source
var (
	ErrModelNotFound      = errors.New("model not found")
	ErrModelInternalError = errors.New("internal model error")
	ErrModelBadRequest    = errors.New("bad request")
	ErrModelInvalidStatus = errors.New("invalid model status")
)

Functions

func DeleteDeployment

func DeleteDeployment(userId string, deploymentId string) error

DeleteDeployment delete an existed deployment and notify peer nodes

func DeleteRuleChain

func DeleteRuleChain(userId string, chainId string) error

Delete will delete a specified rule chain

func GetRuleChainMetadata

func GetRuleChainMetadata(userId string, chainId string) ([]byte, error)

GetRuleChainMetadata return a chain's metadata

func Initialize

func Initialize()

Initialize initialize the models environment, a global repository must be created successfully

func SaveRuleChain

func SaveRuleChain(userId string, chain *RuleChain) error

SaveRuleChain update an existed rule chain

func SaveRuleChainMetadata

func SaveRuleChainMetadata(userId string, chainId string, metadata []byte) error

SaveRuleChainMetadata will save a rule chain's metadata

func SetDeploymentStatus

func SetDeploymentStatus(userId string, deploymentId string, status string) error

SetDeploymentStatus set a deployment status according to user's request

func UpdateDeployment

func UpdateDeployment(userId string, deployment *Deployment) error

UpdateDeployment update an existed deployment

Types

type Deployment

type Deployment struct {
	gorm.Model
	UserId        string            `json:"userId" yaml:"userId" gorm:"size:255"`
	Name          string            `json:"name" yaml:"name" gorm:"size:255"`
	RuleChainId   string            `json:"ruleChainId" yaml:"ruleChainId" gorm:type:vchar(100)`
	Reader        string            `json:"reader" yaml:"reader"`
	ReaderConfigs map[string]string `json:"readerConfigs" yaml:"readerConfigs"`
	Status        string            `json:"status" yaml:"status"`
	CreatedAt     *time.Time        `json:"createdAt" yaml:"createdAt"`
	Id            string            `json:"id" yaml:"id" gorm:"type:vchar(100),unique_index"`
}

func AddDeployment

func AddDeployment(userId string, deployment *Deployment) (*Deployment, error)

AddDeployment create a new deployment

func GetDeployment

func GetDeployment(userId string, deploymentId string) (*Deployment, error)

GetDeploynent return a specified deployment

func ListDeployments

func ListDeployments(query Query) ([]*Deployment, error)

ListDeployments return all deployments

func (Deployment) Path

func (obj Deployment) Path() string

type Message

type Message interface {
	GetId() string
	GetOriginator() string
	GetType() string
	GetPayload() []byte
	GetMetadata() Metadata
	SetType(string)
	SetPayload([]byte)
	SetMetadata(Metadata)
	SetOriginator(string)
}

func NewMessage

func NewMessage() Message

func NewMessageWithDetail

func NewMessageWithDetail(id string, originator string, messageType string, payload []byte, metadata Metadata) Message

type Metadata

type Metadata interface {
	Keys() []string
	GetKeyValue(key string) interface{}
	SetKeyValue(key string, val interface{})
}

func NewMetadata

func NewMetadata() Metadata

type Model

type Model interface {
	Path() string
}

type Query

type Query struct {
	UserId string
	Offset int32
	Limit  int32
}

type Reader

type Reader interface {
	Name() string
	Config() map[string]interface{}
	Start() error
	RegisterObserver(ReaderObserver)
	GracefulShutdown() error
}

type ReaderObserver

type ReaderObserver interface {
	OnDataAvailable(Reader, []byte, interface{})
}

type RuleChain

type RuleChain struct {
	gorm.Model
	DebugMode   bool   `json:"debugMode" yaml:"debugMode"`
	Description string `json:"description" yaml:"description" gorm:"size:255"`
	Name        string `json:"name" yaml:"name" gorm:"size:255"`
	Id          string `json:"chainId" yaml:"chainId" gorm:"size:100,unique_index"`
	UserId      string `json:"userId" yaml:"userId" gorm:"size:255"`
	Type        string `json:"type" yaml:"type" gorm:"type:char(100)"`
	Domain      string `json:"domain" yaml:"domain"`
	Status      string `json:"status" yaml:"status"`
	Metadata    []byte `json:"metadata" yaml:"metadata"`
	Root        bool   `json:"bool" yaml:"bool"`
}

func GetRuleChain

func GetRuleChain(userId string, chainId string) (*RuleChain, error)

GetRuleChain return a specified rule chain

func ListRuleChains

func ListRuleChains(query Query) ([]*RuleChain, error)

ListRuleChains return a user's rule chains

func (RuleChain) Path

func (obj RuleChain) Path() string

Jump to

Keyboard shortcuts

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