Openhab-addons: [REST / persistence] API request for persistence items returns empty list

Created on 28 Mar 2017  路  10Comments  路  Source: openhab/openhab-addons

I installed two persistence extensions: rrd4j and InfluxDB.

A GET request to "/rest/persistence" returns the following result:

[[ { "id": "rrd4j", "label": "rrd4j", "type": "Queryable" }, { "id": "influxdb", "label": "influxdb", "type": "Queryable" } ]]

A GET request to "/rest/persistence/items?serviceId=rrd4j" and "/rest/persistence/items?serviceId=influxdb" returns an empty list with status code 200:

[]

Expected result: A list of all available items as defined in the *.rules file.

The data for a specific item is available at "/rest/persistence/items/{ITEMID}?serviceId=influxdb".

The behaviour can be reproduced with a clean install of openHAB 2.0.0.

@sjka and @maggu2810 confirmed this issue to be a problem of the OH1 compatibility layer.

For previous discussion see issue at ESH#3186.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Most helpful comment

Yes, that is better. Throwing an exception would result in interface changes too.

I will change the JavaDoc to use this wording:

    /**
     * Returns a set of {@link PersistenceItemInfo} about items that are stored in the persistence service. This allows
     * the persistence service to return information about items that are no long available as an {@link Item} in
     * openHAB. If it is not possible to retrieve the information an empty set should be returned.
     *
     * @return a set of information about the persisted items
     */
    Set<PersistenceItemInfo> getItemInfo();

All 10 comments

I think this issue should have an impact to HABPanel when configuring dashboard data sources. I wonder if this was not noticed before? Can anyone who uses HABPanel clarify please.

Same problem with openHAB 2.4 and jdbc/jdbc-mysql persistence service.

This problem still persists on openhab 2.5, on ALL persitence layers, including default mapdb

We can try to implement a solution for this once https://github.com/openhab/openhab-addons/pull/5275 will have been merged. But it has to be done for each persistence service separately. They all have to implement the getItemInfo() method of QueryablePersistenceService interface properly:

https://github.com/openhab/openhab-core/blob/3811cb95604f69f6a3d77da2caf391d81b05458e/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/QueryablePersistenceService.java#L38-L46

They all have to implement the getItemInfo() method of QueryablePersistenceService interface properly

Only the ones that are queryable, I hope. And for some of them, it simply isn't possible to know, which items exist in the database, so only some of those will be able to implement it properly.

I transferred this issue to openHAB Add-ons repository and submitted PR https://github.com/openhab/openhab-addons/pull/8137 for JDBC implementation.

Most of the existing persistence services already provide an implementation. The following are missing:

  • [x] org.openhab.persistence.dynamodb (see code) - not possible, see below
  • [ ] org.openhab.persistence.jpa (see code)
  • [ ] org.openhab.persistence.mongodb (see code)
  • [ ] org.openhab.persistence.rrd4j (see code)

Maybe we can ask one of the bundle maintainers (@ssalonen and others) to implement the missing feature.

Thanks @cweitkamp for the ping. It looks like there is no "sensible" implementation possible for DynamoDB (see here) since querying all the item names would require scanning all the values (cost / perf implications) or adding additional table for book-keeping item names.

Unlike SQL databases there is no such thing as finding out all unique values of the index even though we do have item name as the "hash key" of the table.

What would to be the preferred approach in these kind of cases?

That is a good question. The JavaDoc does not tell us much about such a situation. I think returning an empty set like now is okay. We should maybe add a comment why we cannot return something.

But an empty set can be misleading too - that is why we have this issue. Do you think we should throw an exception? Something like UnsupportedOperationException? I will change the JavaDoc accordingly after we reached an agreement.

I am against throwing exceptions - we specifically introduced different PersistenceService interfaces with different feature sets to avoid that. I don't think this method is worth adding yet another interface, though - I'd simply go with an empty list and possibly adapt the JavaDoc of the method on the interface. Afair, the main use case for this method was HABmin, which has been deprecated now anyhow...

Yes, that is better. Throwing an exception would result in interface changes too.

I will change the JavaDoc to use this wording:

    /**
     * Returns a set of {@link PersistenceItemInfo} about items that are stored in the persistence service. This allows
     * the persistence service to return information about items that are no long available as an {@link Item} in
     * openHAB. If it is not possible to retrieve the information an empty set should be returned.
     *
     * @return a set of information about the persisted items
     */
    Set<PersistenceItemInfo> getItemInfo();
Was this page helpful?
0 / 5 - 0 ratings