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

Add device:mUnlink API action #60

Merged
merged 5 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions doc/1/controllers/device/m-attach/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The device document will be duplicated inside the tenant "devices" collection.
### HTTP

``` http
URL: http://kuzzle:7512/_/device-manager/devices/_mAttach
URL: http://kuzzle:7512/_/device-manager/devices/_mAttach[?refresh=wait_for][&strict=true|false]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean flag are true if set and false if not set, they can't have explicit value

Method: PUT
Body:
```
Expand All @@ -31,7 +31,7 @@ Body:
"deviceId": "test-id"
}],
// Using CSV syntax
"csv": "tenant,id\ntenant-kuzzle,test-id"
"csv": "tenantId,deviceId\ntenant-kuzzle,test-id"
}
```

Expand Down Expand Up @@ -61,13 +61,13 @@ Body properties, must contain at least one of

- `records`: an array of object containing `tenantId` and `deviceId`
- `csv`: a csv syntax compatible containing at least this two headers `tenantId,deviceId` with their corresponding values
- `strict`: a boolean value that indicate if the process should fail at first error

---

### Optional:

* `refresh`: if set to `wait_for`, Kuzzle will not respond until the documents are indexed
* `strict`: (boolean) if set, makes the process fail preemptively if at least one link cannot be applied (e.g. devices that aren't attached to a tenant, or because of non-existing assets)
Copy link
Contributor

@Yoann-Abbes Yoann-Abbes Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be true by default?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it's better not because some of the device can still be attached and you can correct the errors and then reimport the same document


---

Expand Down
6 changes: 2 additions & 4 deletions doc/1/controllers/device/m-detach/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Detach multiple devices from multiple tenants.
### HTTP

``` http
URL: http://kuzzle:7512/_/device-manager/device-manager/devices/_mDetach[?refresh=wait_for]
URL: http://kuzzle:7512/_/device-manager/device-manager/devices/_mDetach[?refresh=wait_for][&strict]
Method: PUT
Body:
```
Expand Down Expand Up @@ -53,15 +53,13 @@ Body properties, must contain at least one of

* `deviceIds`: an array of string containing identifiers of a device already attached
* `csv`: a csv syntax compatible containing at least one header `deviceId` with his corresponding values
* `strict`: a boolean value that indicate if the process should fail at first error

---

## Arguments

### Optional:

* `refresh`: if set to `wait_for`, Kuzzle will not respond until the documents are indexed
* `strict`: (boolean) if set, makes the process fail preemptively if at least one link cannot be applied (e.g. devices that aren't attached to a tenant, or because of non-existing assets)

---

Expand Down
86 changes: 86 additions & 0 deletions doc/1/controllers/device/m-link/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
code: true
type: page
title: mLink
description: Link multiple devices to multiple assets
---

# mLink

Link multiple devices to multiple assets

---

## Query Syntax

### HTTP

``` http
URL: http://kuzzle:7512/_/device-manager/devices/_mLink[?refresh=wait_for][&strict]
Method: PUT
Body:
```

``` js
{
// Using JSON
"records" [{
"assetId": "myAssetId",
"deviceId": "test-id"
}],
// Using CSV syntax
"csv": "assetId, deviceId\nmyAssetId,test-id"
}
```

### Other protocols

``` js
{
"controller": "device-manager/device",
"action": "mLink",
"body": {
// Using JSON
"records" [{
"assetId": "myAssetId",
"deviceId": "test-id"
}],
// Using CSV syntax
"csv": "assetId,deviceId\nmyAssetId,test-id",
}
}
```

---

## Body properties

Body properties, must contain at least one of the following:

- `records`: an array of objects, each containing an `assetId` and a `deviceId` properties
- `csv`: a csv syntax compatible containing at least this two headers `assetId,deviceId` with their corresponding values

---

### Optional:

* `refresh`: if set to `wait_for`, Kuzzle will not respond until the documents are indexed
* `strict`: (boolean) if set, makes the process fail preemptively if at least one link cannot be applied (e.g. devices that aren't attached to a tenant, or because of non-existing assets)

---

## Response

``` js
{
"status": 200,
"error": null,
"controller": "device-manager/device",
"action": "mLink",
"requestId": "<unique request identifier>",
"result": {
"errors": [],
"successes": []
}
}
```
84 changes: 84 additions & 0 deletions doc/1/controllers/device/m-unlink/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
code: true
type: page
title: mUnlink
description: Unlink multiple devices from multiple assets
---

# mUnlink

Unlink multiple devices from multiple assets

---

## Query Syntax

### HTTP

``` http
URL: http://kuzzle:7512/_/device-manager/devices/_mUnlink[?refresh=wait_for][&strict]
Method: PUT
Body:
```

``` js
{
// Using JSON
"records" [{
"deviceId": "test-id"
}],
// Using CSV syntax
"csv": " deviceId\ntest-id"
}
```

### Other protocols

``` js
{
"controller": "device-manager/device",
"action": "mUnlink",
"body": {
// Using JSON
"records" [{
"deviceId": "test-id"
}],
// Using CSV syntax
"csv": "deviceId\ntest-id",
}
}
```

---

## Body properties

Body properties, must contain at least one of the following:

- `records`: an array of objects, each containing a `deviceId` properties
- `csv`: a csv syntax compatible containing at least this header `deviceId` with his corresponding values

---

### Optional:

* `refresh`: if set to `wait_for`, Kuzzle will not respond until the documents are indexed
* `strict`: (boolean) if set, makes the process fail preemptively if at least one Unlink cannot be applied (e.g. devices that aren't attached to a tenant, or because of non-existing assets)

---

## Response

``` js
{
"status": 200,
"error": null,
"controller": "device-manager/device",
"action": "mUnlink",
"requestId": "<unique request identifier>",
"result": {
"errors": [],
"successes": []
}
}
```
21 changes: 21 additions & 0 deletions doc/1/guides/devices/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ When linked, the device measures are copied inside the asset document.

New measures received by the device will be propagated inside the asset document.

## Link Multiple Devices to Multiple Assets

Multiple Devices can be linked at the same time to multiple assets by using the [device-manager/device:mLink](/kuzzle-iot-platform/device-manager/1/controllers/device/m-link) API action.

Once linked, each device's measures are copied inside their corresponding asset document.

New measures received by the device will be propagated inside each assets documents.


## unlink from an asset

Devices can be unlinked from an asset by using the [device-manager/device:unlink](/kuzzle-iot-platform/device-manager/1/controllers/device/unlink) API action.

When unlinked, the device measures are erased inside the asset document.

## unlink Multiple Devices to Multiple Assets

Multiple Devices can be unlinked at the same time from multiple assets by using the [device-manager/device:mUnlink](/kuzzle-iot-platform/device-manager/1/controllers/device/m-unlink) API action.

Once unlinked, each device's measures are erased inside their corresponding asset document.

## Metadata

It is possible to attach metadata to the devices within the `metadata` property.
Expand Down
65 changes: 62 additions & 3 deletions features/DeviceController.feature
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,50 @@ Feature: Device Manager device controller
| measures.temperature.degree | 23.3 |
| measures.temperature.qos.battery | 80 |

Scenario: Link multiple device to multiple assets using JSON
When I successfully execute the action "device-manager/device":"mLink" with args:
| body.records.0.deviceId | "DummyTemp_attached-ayse-unlinked" |
| body.records.0.assetId | "PERFO-unlinked" |
Then The document "device-manager":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | "PERFO-unlinked" |
And The document "tenant-ayse":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | "PERFO-unlinked" |
And The document "tenant-ayse":"assets":"PERFO-unlinked" content match:
| measures.temperature.id | "DummyTemp_attached-ayse-unlinked" |
| measures.temperature.model | "DummyTemp" |
| measures.temperature.reference | "attached-ayse-unlinked" |
| measures.temperature.updatedAt | 1610793427950 |
| measures.temperature.payloadUuid | "_STRING_" |
| measures.temperature.degree | 23.3 |
| measures.temperature.qos.battery | 80 |

Scenario: Link multiple device to multiple assets using CSV
When I successfully execute the action "device-manager/device":"mLink" with args:
| body.csv | "deviceId,assetId\\nDummyTemp_attached-ayse-unlinked,PERFO-unlinked" |
Then The document "device-manager":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | "PERFO-unlinked" |
And The document "tenant-ayse":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | "PERFO-unlinked" |
And The document "tenant-ayse":"assets":"PERFO-unlinked" content match:
| measures.temperature.id | "DummyTemp_attached-ayse-unlinked" |
| measures.temperature.model | "DummyTemp" |
| measures.temperature.reference | "attached-ayse-unlinked" |
| measures.temperature.updatedAt | 1610793427950 |
| measures.temperature.payloadUuid | "_STRING_" |
| measures.temperature.degree | 23.3 |
| measures.temperature.qos.battery | 80 |

Scenario: Error when linking device to an asset
When I execute the action "device-manager/device":"linkAsset" with args:
| _id | "DummyTemp_detached" |
| assetId | "PERFO-unlinked" |
Then I should receive an error matching:
| message | "Device \"DummyTemp_detached\" is not attached to a tenant" |
| message | "Devices \"DummyTemp_detached\" are not attached to a tenant" |
When I execute the action "device-manager/device":"linkAsset" with args:
| _id | "DummyTemp_attached-ayse-unlinked" |
| assetId | "PERFO-non-existing" |
Then I should receive an error matching:
| message | "Asset \"PERFO-non-existing\" does not exists" |
| message | "Assets \"PERFO-non-existing\" do not exist" |

Scenario: Unlink device from an asset
Given I successfully execute the action "device-manager/device":"linkAsset" with args:
Expand All @@ -163,4 +196,30 @@ Feature: Device Manager device controller
When I execute the action "device-manager/device":"unlink" with args:
| _id | "DummyTemp_attached-ayse-unlinked" |
Then I should receive an error matching:
| message | "Device \"DummyTemp_attached-ayse-unlinked\" is not linked to an asset" |
| message | "Devices \"DummyTemp_attached-ayse-unlinked\" are not linked to an asset" |

Scenario: Unlink multiple devices from multiple assets using JSON
Given I successfully execute the action "device-manager/device":"linkAsset" with args:
| _id | "DummyTemp_attached-ayse-unlinked" |
| assetId | "PERFO-unlinked" |
When I successfully execute the action "device-manager/device":"mUnlink" with args:
| body.records.0.deviceId | "DummyTemp_attached-ayse-unlinked" |
Then The document "device-manager":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | null |
Then The document "tenant-ayse":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | null |
And The document "tenant-ayse":"assets":"PERFO-unlinked" content match:
| measures | null |

Scenario: Unlink multiple devices from multiple assets using CSV
Given I successfully execute the action "device-manager/device":"linkAsset" with args:
| _id | "DummyTemp_attached-ayse-unlinked" |
| assetId | "PERFO-unlinked" |
When I successfully execute the action "device-manager/device":"mUnlink" with args:
| body.csv | "deviceId\\nDummyTemp_attached-ayse-unlinked" |
Then The document "device-manager":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | null |
Then The document "tenant-ayse":"devices":"DummyTemp_attached-ayse-unlinked" content match:
| assetId | null |
And The document "tenant-ayse":"assets":"PERFO-unlinked" content match:
| measures | null |
Loading