简体   繁体   中英

How to query all services (groups) from an iotagent

We have a hard time understanding the meaning of the different hierarchy levels provided by the iotagent. There is the fiware-service, the fiware-servicepath and underneath it is a bunch of services that in turn have a bunch of devices associated.

Now we understood how to query for all devices and all services underneath a given fiware-service and fiware-servicepath. We also understood how to query for all fiware-servicepaths given a certain fiware-service. But how to query for all those "top level" fiware-services?

Our goal is to create a device management user interface which enables an end user to provision and unprovision the devices he is managing. Maybe we have a misconception of the fiware-service here but since one can add such services with a certain POST request our expectation would be that we can somehow query for all those services. What are we missing?

If there really is no way to query the top level services, I'd like to ask for the reasoning of this as I cannot find that in the docs.

Under NGSI-v2, all context brokers are implicitly multitenant. Using a different fiware-service for your provisioned devices should imply that the devices and their data are owned by separate business concern, so there should be no need to retrieve and combine provisioned devices from separated concerns.

When using the mongo-DB option with an IoT Agent, the fiware-service helps to provide a unique database name for each tenanted service.

There should be no need to combine the IoT Agent data (services and devices), however there may be a valid use case for combining Context Data coming from separate Tenants (after securing legal agreement from each party of course) - in this case you could create a simple proxy handler which is capable of handling the /v2/op/query and/or /v2/op/update endpoints and forwarding the request with amended headers.

const express = require('express');
const router = express.Router();
const request = require('request-promise');

const BASE_PATH =
  process.env.CONTEXT_BROKER || 'http://localhost:1026/v2';

function forwardRequest(req, res) {

// Add necessary validation

  const headers = req.headers;
  headers['fiware-service' : 'XXXX'];
  headers['fiware-servicepath': 'YYYY'];
  headers['Accept': 'application/json'];

  const options = {
    url: BASE_PATH + req.path,
    method: req.method,
    headers,
    json: true
  };

  request(options)
    .then(async function(cbResponse) {
      return res.send(compacted);
    })
    .catch(function(err) {
      return res.send(err);
    });
}

router.post(
  '/op/query', forwardRequest
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM