Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MF-488 - Remove Thing type (app or device) #718

Merged
merged 6 commits into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Mainflux is modern, scalable, secure open source and patent-free IoT cloud platform written in Go.

It accepts user, device, and application connections over various network protocols (i.e. HTTP,
It accepts user and thing connections over various network protocols (i.e. HTTP,
MQTT, WebSocket, CoAP), thus making a seamless bridge between them. It is used as the IoT middleware
for building complex IoT solutions.

Expand Down
2 changes: 1 addition & 1 deletion bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Enabling and disabling Thing (adding Thing to/from whitelist) is as simple as co

Switching between states `Active` and `Inactive` enables and disables Thing, respectively.

Thing configuration also contains the so-called `external ID` and `external key`. An external ID is a unique identifier of the device/app for the corresponding Thing. For example, the device MAC address is a good choice for external ID. External key is a secret key that is used for authentication during the bootstrapping procedure.
Thing configuration also contains the so-called `external ID` and `external key`. An external ID is a unique identifier of corresponding Thing. For example, a device MAC address is a good choice for external ID. External key is a secret key that is used for authentication during the bootstrapping procedure.

## Configuration

Expand Down
7 changes: 1 addition & 6 deletions bootstrap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import (
mfsdk "github.com/mainflux/mainflux/sdk/go"
)

const (
thingType = "device"
chanName = "channel"
)

var (
// ErrNotFound indicates a non-existent entity request.
ErrNotFound = errors.New("non-existent entity")
Expand Down Expand Up @@ -332,7 +327,7 @@ func (bs bootstrapService) thing(key, id string) (mfsdk.Thing, error) {
var err error

if id == "" {
thingID, err = bs.sdk.CreateThing(mfsdk.Thing{Type: thingType}, key)
thingID, err = bs.sdk.CreateThing(mfsdk.Thing{}, key)
if err != nil {
return mfsdk.Thing{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions bootstrap/swagger.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
swagger: "2.0"
info:
title: Mainflux Bootstrap service
description: HTTP API for managing platform devices and applications configuration.
description: HTTP API for managing platform things configuration.
version: "1.0.0"
consumes:
- "application/json"
Expand Down Expand Up @@ -56,7 +56,7 @@ paths:
- $ref: "#/parameters/Name"
responses:
200:
description: |
description: |
Data retrieved. Configs from this list don't contain channels.
schema:
$ref: "#/definitions/ConfigList"
Expand Down Expand Up @@ -160,7 +160,7 @@ paths:
put:
summary: Updates channels the thing is connected to
description: |
Update connections performs update of the channel list corresponding
Update connections performs update of the channel list corresponding
Thing is connected to.
tags:
- configs
Expand Down Expand Up @@ -435,4 +435,4 @@ definitions:
type: string
required:
- content
- name
- name
4 changes: 2 additions & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ mainflux-cli users token john.doe@email.com password
### System Provisioning
#### Create Thing (type Device)
```
mainflux-cli things create '{"type":"device", "name":"myDevice"}' <user_auth_token>
mainflux-cli things create '{"name":"myDevice"}' <user_auth_token>
```

#### Create Thing (type Application)
```
mainflux-cli things create '{"type":"app", "name":"myDevice"}' <user_auth_token>
mainflux-cli things create '{"name":"myDevice"}' <user_auth_token>
```

#### Update Thing
Expand Down
15 changes: 5 additions & 10 deletions cli/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

var errMalformedCSV = errors.New("malformed CSV")

func createThing(name, kind, token string) (mfxsdk.Thing, error) {
id, err := sdk.CreateThing(mfxsdk.Thing{Name: name, Type: kind}, token)
func createThing(name, token string) (mfxsdk.Thing, error) {
id, err := sdk.CreateThing(mfxsdk.Thing{Name: name}, token)
if err != nil {
return mfxsdk.Thing{}, err
}
Expand All @@ -36,7 +36,6 @@ func createThing(name, kind, token string) (mfxsdk.Thing, error) {
m := mfxsdk.Thing{
ID: id,
Name: name,
Type: kind,
Key: t.Key,
}

Expand Down Expand Up @@ -87,12 +86,12 @@ var cmdProvision = []cobra.Command{
return
}

if len(l) < 2 {
if len(l) < 1 {
logError(errMalformedCSV)
return
}

m, err := createThing(l[0], l[1], args[1])
m, err := createThing(l[0], args[1])
if err != nil {
logError(err)
return
Expand Down Expand Up @@ -187,12 +186,8 @@ var cmdProvision = []cobra.Command{
// Create things
for i := 0; i < numThings; i++ {
n := fmt.Sprintf("d%d", i)
k := "device"
if i%2 != 0 {
k = "app"
}

m, err := createThing(n, k, ut)
m, err := createThing(n, ut)
if err != nil {
logError(err)
return
Expand Down
Binary file added cmd/cli/cli
Binary file not shown.
7 changes: 2 additions & 5 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ an access token. Once logged into the system, user can manage his resources (i.e
things and channels) in CRUD fashion, and define access control policies by
connecting them.

`Thing` represents devices and applications connected to Mainflux. There are
two types of "things" supported at the moment: `device` and `app`. While device
is used to represent any physical device connected to the platform, app represents
any 3rd party service that uses the platform for message exchange with other
"things".
`Thing` represents devices (or applications) connected to Mainflux that uses the
platform for message exchange with other "things".

`Channel` represents a communication channel. It serves as message topic that
can be consumed by all of the things connected to it.
Expand Down
9 changes: 2 additions & 7 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,9 @@ mainflux-cli users token john.doe@email.com password
```

### System Provisioning
#### Create Thing (type Device)
#### Create Thing
```
mainflux-cli things create '{"type":"device", "name":"myDevice"}' <user_auth_token>
```

#### Create Thing (type Application)
```
mainflux-cli things create '{"type":"app", "name":"myDevice"}' <user_auth_token>
mainflux-cli things create '{"name":"myThing"}' <user_auth_token>
```

#### Update Thing
Expand Down
65 changes: 30 additions & 35 deletions docs/dev-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ Please assure that MQTT microservice has `node_modules` installed, as explained
> N.B. `make rundev` actually calls helper script `scripts/run.sh`, so you can inspect this script for the details.

## Events
In order to be easily integratable system, Mainflux is using [Redis Streams](https://redis.io/topics/streams-intro)
as an event log for event sourcing. Services that are publishing events to Redis Streams
In order to be easily integratable system, Mainflux is using [Redis Streams](https://redis.io/topics/streams-intro)
as an event log for event sourcing. Services that are publishing events to Redis Streams
are `things` service, `bootstrap` service, and `mqtt` adapter.

### Things Service
For every operation that has side effects (that is changing service state) `things`
service will generate new event and publish it to Redis Stream called `mainflux.things`.
Every event has its own event ID that is automatically generated and `operation`
For every operation that has side effects (that is changing service state) `things`
service will generate new event and publish it to Redis Stream called `mainflux.things`.
Every event has its own event ID that is automatically generated and `operation`
field that can have one of the following values:
- `thing.create` for thing creation,
- `thing.update` for thing update,
Expand All @@ -253,34 +253,32 @@ field that can have one of the following values:
- `channel.update` for channel update,
- `channel.remove` for channel removal.

By fetching and processing these events you can reconstruct `things` service state.
If you store some of your custom data in `metadata` field, this is the perfect
way to fetch it and process it. If you want to integrate through
By fetching and processing these events you can reconstruct `things` service state.
If you store some of your custom data in `metadata` field, this is the perfect
way to fetch it and process it. If you want to integrate through
[docker-compose.yml](https://github.com/mainflux/mainflux/blob/master/docker/docker-compose.yml)
you can use `mainflux-es-redis` service. Just connect to it and consume events
you can use `mainflux-es-redis` service. Just connect to it and consume events
from Redis Stream named `mainflux.things`.

#### Thing create event

Whenever thing is created, `things` service will generate new `create` event. This
Whenever thing is created, `things` service will generate new `create` event. This
event will have the following format:
```
1) "1555334740911-0"
2) 1) "type"
2) "device"
3) "operation"
4) "thing.create"
5) "name"
6) "d0"
7) "id"
8) "3c36273a-94ea-4802-84d6-a51de140112e"
9) "owner"
10) "john.doe@email.com"
11) "metadata"
12) "{}"
```

As you can see from this example, every odd field represents field name while every
2) 1) "operation"
2) "thing.create"
3) "name"
4) "d0"
5) "id"
6) "3c36273a-94ea-4802-84d6-a51de140112e"
7) "owner"
8) "john.doe@email.com"
9) "metadata"
10) "{}"
```

As you can see from this example, every odd field represents field name while every
even field represents field value. This is standard event format for Redis Streams.
If you want to extract `metadata` field from this event, you'll have to read it as
string first, and then you can deserialize it to some structured format.
Expand All @@ -296,8 +294,6 @@ This event will have the following format:
4) "weio"
5) "id"
6) "3c36273a-94ea-4802-84d6-a51de140112e"
7) "type"
8) "device"
```
Note that thing update event will contain only those fields that were updated using
update endpoint.
Expand Down Expand Up @@ -340,7 +336,7 @@ Whenever channel instance is updated, `things` service will generate and publish
5) "operation"
6) "channel.update"
```
Note that update channel event will contain only those fields that were updated using
Note that update channel event will contain only those fields that were updated using
update channel endpoint.

#### Channel remove event
Expand Down Expand Up @@ -381,8 +377,8 @@ format:
6) "thing.disconnect"
```

> **Note:** Every one of these events will omit fields that were not used or are not
relevant for specific operation. Also, field ordering is not guaranteed, so DO NOT
> **Note:** Every one of these events will omit fields that were not used or are not
relevant for specific operation. Also, field ordering is not guaranteed, so DO NOT
rely on it.

### Bootstrap Service
Expand All @@ -396,9 +392,9 @@ the following event types:
- `thing.state_change` for device state change,
- `thing.update_connections` for device connection update.

If you want to integrate through
If you want to integrate through
[docker-compose.yml](https://github.com/mainflux/mainflux/blob/master/docker/addons/bootstrap/docker-compose.yml)
you can use `mainflux-es-redis` service. Just connect to it and consume events
you can use `mainflux-es-redis` service. Just connect to it and consume events
from Redis Stream named `mainflux.bootstrap`.

#### Configuration create event
Expand Down Expand Up @@ -510,9 +506,9 @@ Events that are coming from MQTT adapter have following fields:
- `event_type` can have two possible values, connect and disconnect,
- `instance` represents MQTT adapter instance.

If you want to integrate through
If you want to integrate through
[docker-compose.yml](https://github.com/mainflux/mainflux/blob/master/docker/docker-compose.yml)
you can use `mainflux-es-redis` service. Just connect to it and consume events
you can use `mainflux-es-redis` service. Just connect to it and consume events
from Redis Stream named `mainflux.mqtt`.

Example of connect event:
Expand All @@ -526,7 +522,6 @@ Example of connect event:
6) "connect"
7) "instance"
8) "mqtt-adapter-1"

```

Example of disconnect event:
Expand Down
4 changes: 1 addition & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ Output of the command is something like this:
"id": "513d02d2-16c1-4f23-98be-9e12f8fee898",
"key": "69590b3a-9d76-4baa-adae-9b5fec0ea14f",
"name": "d0",
"type": "device"
},
{
"id": "bf78ca98-2fef-4cfc-9f26-e02da5ecdf67",
"key": "840c1ea1-2e8d-4809-a6d3-3433a5c489d2",
"name": "d1",
"type": "app"
}
]

Expand Down Expand Up @@ -106,4 +104,4 @@ mainflux-http | {"level":"info","message":"Method publish took 336.685µs to c
mainflux-normalizer | {"level":"info","message":"Method normalize took 108.126µs to complete without errors.","ts":"2019-01-08T22:19:30.149500543Z"}
```

This proves that messages have been well send through the system, via protocol adapter (`mainflux-http`) and `normalizer` service which corectly parsed messages.
This proves that messages have been well send through the system, via protocol adapter (`mainflux-http`) and `normalizer` service which correctly parsed messages.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Mainflux is modern, scalable, secure open source and patent-free IoT cloud platform written in Go.

It accepts user, device, and application connections over various network protocols (i.e. HTTP,
It accepts user and thing connections over various network protocols (i.e. HTTP,
MQTT, WebSocket, CoAP), thus making a seamless bridge between them. It is used as the IoT middleware
for building complex IoT solutions.

Expand Down
Loading