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

Remove legacy NGSIv1 code - discover function #256

Closed
mapedraza opened this issue Oct 25, 2021 · 6 comments
Closed

Remove legacy NGSIv1 code - discover function #256

mapedraza opened this issue Oct 25, 2021 · 6 comments
Assignees

Comments

@mapedraza
Copy link
Collaborator

mapedraza commented Oct 25, 2021

Some legacy NGSIv1 requests remain in the codebase after merging #253

This function returns the registrations for a given entity.

function discoverContextAvailability(host, port, service, subservice, id, type, attributes, callback) {
const options = {
url: 'http://' + host + ':' + port + '/v1/registry/discoverContextAvailability ',
method: 'POST',
headers: {
'fiware-service': service,
'fiware-servicepath': subservice
},
json: {
entities: [
{
type,
id,
isPattern: 'false'
}
],
attributes
}
};
request(options, callback);
}

Having in mind the NGSIv2 spec does not allow to query for a specific entity, there is not a direct equivalent. But this function is only used at test/unit/ngsiv2/registration-test.js

ngsiClient.discover('TestClient:Light', 'Light', undefined, function(error, response, body) {

Since the purpose of the function is just to check if the registration was created properly (and used just for testing), making the request GET v2/registrations in this case have the same effect (since the DB is cleaned between tests)

It was discovered here

@jason-fox
Copy link
Contributor

lib/ngsiUtils.js should be deleted - it really doesn't deserve to exist within the IoT Agent itself. If it is just a test expectation, the code should be moved to the test itself, if this a common NGSI need then it should be pushed into the iotagent-node-lib.

IoT Agents should never make direct NGSI requests, that is the job of iotagent-node-lib.

@fgalan
Copy link
Member

fgalan commented Oct 26, 2021

lib/ngsiUtils.js should be deleted - it really doesn't deserve to exist within the IoT Agent itself. If it is just a test expectation, the code should be moved to the test itself, if this a common NGSI need then it should be pushed into the iotagent-node-lib.

IoT Agents should never make direct NGSI requests, that is the job of iotagent-node-lib.

Is lightweightm2m-iotagent the only one in this situation? Is there a lib/ngsiUtils.js file in other agents (UL, JSON, etc.)?

@jason-fox
Copy link
Contributor

It is the only one of the Telefónica IoT Agents with lib/ngsiUtils.js - I guess it is one of the oldest codebases

@mapedraza
Copy link
Collaborator Author

mapedraza commented Oct 26, 2021

This IoTA or, at least, these tests, are a bit different compared with the other IoTAS. In the other IoTAS, the tests are executed without the need of having a CB running, verifying the requests that the IoTA makes with the mock server. In this case the agent is connected to a real CB, and what is checked is that the action has had an effect on the CB itself.

Moving ngsiUtils.jsto test/ folder would make more sense since the usage of those function are exclusively for testing purposes as helpers.

@fgalan
Copy link
Member

fgalan commented Oct 27, 2021

PR #257

@fgalan
Copy link
Member

fgalan commented Oct 27, 2021

After merging PR #257, this issue can be now closed. Some bits moved to #235 (comment)

@fgalan fgalan closed this as completed Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants