eclipse-hono / hono

Eclipse Hono™ Project
https://eclipse.dev/hono
Eclipse Public License 2.0
446 stars 138 forks source link

Management API : bulk operations for devices #1959

Open jbtrystram opened 4 years ago

jbtrystram commented 4 years ago

Having an operation to do bulk operation on devices would be helpful to allow UI to manage multiple devices.

I propose to have a PATCH operation working similarly to the kubernetes API :

For example, to enable devices 4711 and 4722 :

PATCH on /v1/devices/{tenantId} with the following json body :

{
    "id" : [4711, 4712],
    "op" : "edit",
    "value": {"enabled": true}
}

Where value is a JSON object describing the change.

The answer would contain the operation result for each resource :

{ 
    4711: 
      {
        "result" : "204",
        "resource-version" : "6b2f9335-03d9-48c9-ad5b-f23277902305"
      }
    4712:
      {
        "result" : "404",
        "error-message": "device 4712 does not exist.",
        "resource-version" : " f7281122-aa1b-11ea-bb37-0242ac130002"
      }
}

The "op" field would be one of : "add, edit, delete".

Here are a couple of other examples :

update the viagroup field : PATCH on /v1/devices/{tenantId}:

{
    "id" : [4711,4712],
    "op" : "edit",
    "value": {"viaGroups": [group1, group2]}
}

response :

{ 
    4711: 
      {
        "result" : "204",
        "resource-version" : "6b2f9335-03d9-48c9-ad5b-f23277902305"
      }
    4712:
      {
        "result" : "204",
        "resource-version" : " f7281122-aa1b-11ea-bb37-0242ac130002 "
      }
}

delete a group of gateways in memberOf :

PATCH on /v1/devices/{tenantId}:

{
    "id" : [4711,4712],
    "op" : "delete",
    "value": {"memberOf": [aGroup]}
}

response :

{ 
    4711: 
      {
        "result" : "204",
        "resource-version" : "6b2f9335-03d9-48c9-ad5b-f23277902305"
      }
    4712:
      {
        "result" : "204",
        "resource-version" : " f7281122-aa1b-11ea-bb37-0242ac130002 "
      }
}

Add a field in "ext" : PATCH on /v1/devices/{tenantId}:

{
    "id" : [4711,4712],
    "op" : "add",
    "value": {"ext": {"location": {"altitude": "9001"}}}
}

response :

{ 
    4711: 
      {
        "result" : "204",
        "resource-version" : "6b2f9335-03d9-48c9-ad5b-f23277902305"
      }
    4712:
      {
        "result" : "404",]
        "error-message": "device 4712 does not exist.",
        "resource-version" : ""
      }
}
ctron commented 4 years ago

That looks great! :+1: I like the idea of reusing existing concepts. Maybe you can add a link to the Kubernetes API as a reference.

dejanb commented 4 years ago

I like it as well. I would propose to add one more field that would contain description of the error for the result if needed.

StFS commented 8 months ago

This is a pretty old issue. Did it ever go anywhere?

Also, bulk adding of devices would be nice. Any reason for not including that in this issue?

sophokles73 commented 8 months ago

In the end, I guess there was not enough interest to go through with it.

Bulk adding of devices is, however, a different use case. This issue is about providing a PATCH operation for existing devices.

FMPOV adding large numbers of entities is probably best done at the DB level using corresponding ETL tools.