KV Store / States

Receiver

This module implements a kvstore for ingrid and is used for state management

docker pull registry-dev.goingrid.io/services/kvstore:latest:v0.0.1

Table of Content

Properties

The kvstore service accepts following properties:

  • Class = Objectclass to work with
  • Operation = Operation to perform with the given Data

Valid Operations

Operation Description
CreateType Creates the Class given in Data with the Definition of the Config in the Storage
DeleteType Deletes the Class from the Storage (Destructive)
ListType List all Types available
Add / Insert / Update Saves the given Data in the Class on the Storage
Del / Delete Deletes the given Object from the Storage
Get / Fetch Fetches an Object from the Storage
List Lists all Object of a given Class
Search / Find / Query Search for all the Keys by the given query Attribute on the Class
Backup Backups the current Storage. A Filename can be given via attribute filename

CreateType

Creates the Class given in Data. Beside Class / Operation no Data is needed. You can define the Parameter ObjectTypes to create some defaults on service start.

DeleteType

Deletes the Class from the Storage (Destructive)
Besides Class / Operation no Data is needed

Add / Insert / Update

Saves the given Data in the Class on the Storage

Key Multivalue Required Description
key no yes Key for this Object
* yes no Will be stored as type Class in the Storage

To Save / Store an Object

{
    "Class": "state",
    "Operation": "add",
    "Data": {
         "key": ["001"],
         "system1": ["ok"],
         "system2": ["failed"]
    }
}

Response

{
  "Code": 200,
  "Message": "Success",
  "Data": {
    "message": [
      "Object Saved"
    ]
  },
  "List": []
}

Del / Delete

Deletes the given Object from the Storage

Key Multivalue Required Description
key no yes Attribute with the key for the given Class

If you like to delete an object from the store, you have to pass the class of the object and the key / value pair of it.

To Delete an Object

{
  "Class": "user",
  "Operation": "delete",
  "Data": {
    "key": ["myuser"]
  },
}

Response

{
  "Code": 200,
  "Message": "Success",
  "Data": {
    "message": [
      "Object Deleted"
    ]
  },
  "List": []
}

Get / Fetch

Fetch the given Object from the Storage

Key Multivalue Required Description
key no yes Attribute with the key for the given Class

If you like to get / fetch an object from the store, you have to pass the class of the object and the key / value pair of it.

To Fetch an Object

{
    "Class": "state",
    "Operation": "get",
    "Data": {
        "key": ["state2356"]
    }
}

List

Lists all Object of a given Class

Key Multivalue Required Description
start no no
size no no
sortdir no no

If you like to list objects from the store, you have to pass the class of the object.

To List Objects

{
    "Class": "state",
    "Operation": "list",
    "Data": {
        "size":["100"]
     }
}

Response

{
  "Code": 200,
  "Message": "Success",
  "Data": {
    "keys": [
      "group1",
      "group11",
      "group12",
      "group13",
      "group14",
      "group7"
    ]
  },
  "List": []
}

Search / Find / Regex / Query

Search for all the Keys by the given Query on the Class The Parmeters can be passed via Control or Data by the following Names

Key Multivalue Required Logic Default Description
prefix yes no OR Prefix for the key to search for
suffix yes no OR Suffix for the key
fields yes no fields to retrieve or * for all
keyexists yes no OR True if the Obj contains this Key
keynotexists yes no AND True if the Obj does not contain the Key
valueexists yes no OR True if the Obj has contains Value
valuenotexists yes no AND True if the Value doe not exist in the Obj
haskeyvalue yes no OR True if the Obj has this Key Value pair
hasnotkeyvalue yes no AND True if the Obj lacks this Key Value pair
start no no 0 Return Objects start from object #
size no no 0 Limit of Objects to retrieve
sort no no Sort by this key
sortdir no no ‘de’ Sort descending or ascending ‘de’ / ‘as’

To Search Objectkeys

{
    "Class": "state",
    "Operation": "search",
    "Data": { 
        "suffix": ["113"],
        "size": ["100"]
    }
}

Or

{
    "Class": "state",
    "Operation": "search",
    "Data": { 
        "suffix": ["13"],
        "sort": ["system1"],
        "size": ["10"],
        "start": ["0"],
        "valueexists": ["ok"],
        "haskeyvalue": ["system2=unknown"],
        "hasnotkeyvalue": ["system1=error"],
        "fields": ["key","system1"]
    }
}

or

{
    "Class": "state",
    "Operation": "search",
    "Data": { 
        "suffix": ["13"],
        "fields": ["*"],
        "sort": ["system1"],
        "size": ["100"],
        "start": ["0"],
        "valueexists": ["ok"],
        "haskeyvalue": ["system2=unknown"],
        "hasnotkeyvalue": ["system1=error","system2=error","system3=error","system4=error"]
    }
}

Backup

Backups the current Storage. A Filename can be given via attribute filename

Key Multivalue Required Description
filename no no Filename for the Backup. If not given, default will be used

To Backup the Storage

{
    "Operation": "backup",
    "Data": {
        "filename": ["newbackup.db"]
    }
}

Response

{
  "Code": 200,
  "Message": "Success",
  "Data": {
    "message": [
      "Backup successfuly completed"
    ]
  },
  "List": []
}

Service configuration

Like every other service, the log service includes all properties of the service configuration and since it listens on input the input configuration.

CLI / ENV

The following parameters are specific to this worker. They can be either used environment variables (all uppercase) or within the CLI (- as prefix).

Parameter Default Description
BackendConfig "file://bbolt.cfg" Backend Configuration
Backend bbolt Backend Type. ‘bbolt’ / ‘etcd’
ObjectTypes `` Default Type to create on service start. Comma delimited. e.G: ‘User,Group’

Configuration File for BBolt

{ 
  "_comment": "BBolt Configuration",
  "PathFile" : "test.db",
  "BackupPath" : "."
}

Config for etcd

https://github.com/etcd-io/etcd/blob/master/clientv3/config.go/

{
  "endpoints": [
    "localhost:1234"
  ],
  "dial-timeout": 1000000,
  "username": "admin",
  "password": "placeholder"
}

Timeouts are in usec

Example

docker run -e "LOGLEVEL=INFO" kvstore:latest -ServerURL "hive:c3Iu.....6L@10.0.0.1" -InputChannel kv_store

Additional

Rest Tests