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

Hardening/3109 url parse refactor #20

Merged
merged 10 commits into from
Mar 10, 2018
Merged

Conversation

kzangeli
Copy link

Part 1 of refactoring of the url parse

@@ -783,495 +783,393 @@ static const char* validLogLevels[] =

Copy link
Collaborator

@fgalan fgalan Mar 6, 2018

Choose a reason for hiding this comment

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

I undesrtand this is the first of a series of PRs that will end with telefonicaid#3109 step 1 covered. Could you elaborate on your "PR plan" (I mean, the topic for the next PRs after this one)? Maybe the two-levels branch approach (feature/ and task/ branches) should be applied if this is going be a long work?

Copy link
Author

Choose a reason for hiding this comment

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

No real reason to do all this work in a separate branch, pretty much only me working on the broker anyway ... :-)
It is not a problem to me to finish every PR leaving the broker in a 100% working state.
There is nothing about "half-working functionalities" here, only refactors.
Doing it in a feature branch would only add extra work.

The next step is to remove the 'payloadWord' from the RestService vector and after that more simplifications of the vector

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case, then CHANGES_NEXT_RELEASE entry should be "inaugurated" in the first PR addressing this, eg.:

- Hardening: refactor request routing logic (#3109, step 1)

or a similar wording.

Copy link
Author

Choose a reason for hiding this comment

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

There is no impact on the usage of the broker ...
Normally, when we refactor stuff we don't mention it in the CNR.
The only thing users will notice is that the broker is faster after these changes ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree there is no impact for the user from a functional perspetive, but even in that case it would be interesing to mark it in the changelog (specially when there could be a potentiall impact, non-functional, in the form of performance increase). That's way we use Hardening as prefix instead of Add or Fix. It doesn't hurt and may be useful.

Note we have already done this in the past, eg:

- Hardening: NGSIv1 responses don't use pretty-print JSON format any longer, as NGSIv2 responses work (potentially saving around 50% size) (#2760)

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 74c7a9c

@@ -783,495 +783,393 @@ static const char* validLogLevels[] =



#define API_V2 \
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand, the change in contextBroker.cpp consists on spliting the global routes vector is a per-verb vector.

Is my intepretation correct? Any other change that I may be missing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe for the same price these loooong vectors could be moved out of contextBroker.cpp (to some new .h or something)

Copy link
Author

Choose a reason for hiding this comment

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

Yes, the PR is all about removing the VERB/METHOD from the vector and splitting the ONE vector into X vectors, one per verb (the last one is special, the one I call badVerbV, containing the service routines where no adequate verb/method has been found)

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I could move the vector to another CPP file (and its header), but ... what do we gain with that?
Just more complexity, in my opinion

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think is more clear to have all routes in the same place, not mixed with the rest of logic of the contextBroker.cpp (initialization functions, etc.).

Copy link
Author

Choose a reason for hiding this comment

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

Mixed?
Not sure what you mean with that ...
The service routine vectors are where they have always been, right where they should be and right where they are used.
It's been like this since 2011, so ... very hard to understand why we should move them out to a different file (where they are not used) now ...
The vectors are needed in the call to restInit(), that will stay inside contextBroker.cpp.
I see no reason whatsoever to create another file only with the service vectors.

Copy link
Collaborator

@fgalan fgalan Mar 7, 2018

Choose a reason for hiding this comment

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

I wouldn't use the "it has been that way from a time long" argument because if we follow it, then even the refactor done by this PR could be put on doubt :)

Routes configuration is pretty much static and could be considered part of the rest library, so the movement could make sense, changing the way restInit() works, i.e. restInit() wouldn't pass the vector as arguments (as much it would select the mode to use, e.g. cors, no-cors, etc.).

However, it is not so important at the present moment, so we can keep it as it is now and think again in the future.

NTC

Copy link
Author

Choose a reason for hiding this comment

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

If we do the refactoring mentioned in this PR, about having restInit less "flexible", which we needed yeara ago but no longer, then the service vectors would go into the rest library, no doubt.
It's not a bad idea, let's do it. But, in a different PR ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe adding // FIXME PR: to be removed within #3109 refactor task would be useful. I think I will not forget about this but... never knows :)

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 74c7a9c

static RestService* patchServiceV = NULL;
static RestService* deleteServiceV = NULL;
static RestService* optionsServiceV = NULL;
RestService* restBadVerbV = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this one is not static? Why the name uses a different pattern (versus badVerbServiceV for instance)?

Copy link
Author

Choose a reason for hiding this comment

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

This vector is needed in another file (use grep to see which), and as it is not static, it needs a prefix.
As it is in the rest-library, I used the prefix "rest".
Perhaps restBadVerbServiceV would have been a better name. A bit long though

Copy link
Author

Choose a reason for hiding this comment

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

In the next-coming refactoring, all RestService vectors will be moved to RestService.cpp or rest.cpp, and then perhaps all of them can be made static ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

FIXME PR for this or NTC... As you prefer :)

Copy link
Author

Choose a reason for hiding this comment

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

NTC (I am preparing a list of nextcoming PRs about this)

*
* serviceVectorsSet - only for unit tests
*/
void serviceVectorsSet
Copy link
Collaborator

Choose a reason for hiding this comment

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

If only used in unit tests, then use #ifdef UNIT_TEST.

Copy link
Author

Choose a reason for hiding this comment

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

Sure

Copy link
Author

Choose a reason for hiding this comment

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

Actually, the function is used, by restInit() to set the vectors.
It wasn't like that in the beginning, that's why I added the comment.
But now the function is used both for the normal broker compilation as for the unit test compilation so ...

NTC

@@ -445,7 +487,7 @@ static bool compErrorDetect
*
* restService -
*/
std::string restService(ConnectionInfo* ciP, RestService* serviceV)
static std::string restService(ConnectionInfo* ciP, RestService* serviceV, const char* serviceVectorName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is the new parameter serviceVectorName being used in this function?

Maybe github diff is fooling me, but I cannot find any ocurrence in the diff page appart from this one...

Copy link
Author

Choose a reason for hiding this comment

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

Not easy to find this kind of things in the github jungle ...

% find . -name "*.cpp" -exec grep "restService(" {} /dev/null
./src/lib/rest/RestService.cpp:static std::string restService(ConnectionInfo* ciP, RestService* serviceV, const char* serviceVectorName)
./src/lib/rest/RestService.cpp:    return restService(ciP, restBadVerbV, "BAD VERB");
./src/lib/rest/RestService.cpp:  if      ((ciP->verb == GET)     && (getServiceV     != NULL))    return restService(ciP, getServiceV,     "GET");
./src/lib/rest/RestService.cpp:  else if ((ciP->verb == POST)    && (postServiceV    != NULL))    return restService(ciP, postServiceV,    "POST");
./src/lib/rest/RestService.cpp:  else if ((ciP->verb == PUT)     && (putServiceV     != NULL))    return restService(ciP, putServiceV,     "PUT");
./src/lib/rest/RestService.cpp:  else if ((ciP->verb == PATCH)   && (patchServiceV   != NULL))    return restService(ciP, patchServiceV,   "PATCH");
./src/lib/rest/RestService.cpp:  else if ((ciP->verb == DELETE)  && (deleteServiceV  != NULL))    return restService(ciP, deleteServiceV,  "DELETE");
./src/lib/rest/RestService.cpp:  else if ((ciP->verb == OPTIONS) && (optionsServiceV != NULL))    return restService(ciP, optionsServiceV, "OPTIONS");
./src/lib/rest/RestService.cpp:  else                                                             return restService(ciP, restBadVerbV,    "BADVERB");

If I'm not mistaken, I used the "serviceVectorName" fior debugging purposes.
Need to make sure, but if so, it will be removed.

Copy link
Author

@kzangeli kzangeli Mar 6, 2018

Choose a reason for hiding this comment

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

The parameter is no longer used.
Removed in 64983d1

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 64983d1

ipVersionUsed = _ipVersion;
serveFunction = (_serveFunction != NULL)? _serveFunction : serve;
serveFunction = (_serveFunction != NULL)? _serveFunction : orionServe;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have looked for usages of restInit() and it seems that we neever use _serveFunction parameter. Thus, maybe we should avoid the complexity of this function selection function and hardwire orionServer() function as routing logic.

Copy link
Author

Choose a reason for hiding this comment

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

This is old stuff from when orion was both ContextBroker and IotAgent and ConfiguratrionManager at the same time.
So, yes, it definitely could be removed, but that is another refactoring. restInit() will change completely etc, etc.
Not for this PR

Copy link
Collaborator

@fgalan fgalan Mar 6, 2018

Choose a reason for hiding this comment

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

Ok. I'd suggest to mark it with a // FIXME PR: to be removed within #3109 refactor task or a similar wording.

Copy link
Author

Choose a reason for hiding this comment

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

This has nothing to do with the current refactoring.
I could mark it with a FIXME saying something like "this might be refactored, or not, in the future" ... Really don't see the need of it though.
What would help here if we really want to make this change, is a new issue about it

Copy link
Author

Choose a reason for hiding this comment

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

Name changed from orionServe to orion::requestServe in 02d46a8

Copy link
Author

@kzangeli kzangeli Mar 7, 2018

Choose a reason for hiding this comment

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

Next refactoring on my list is exactly this - move RestService vectors into rest lib. No FIXME needed ... Right?

Copy link
Collaborator

@fgalan fgalan Mar 7, 2018

Choose a reason for hiding this comment

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

Current situation is that there is an parameter, the one named _serveFunction in a function that is never used. I think that is a "weird" situation that worth the one-line of effort ;) that a FIXME PR require.

But you have more neurons on this than me right now, so as you prefer...

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I can fix that. Almost easier than putting it in the issue ... :)

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 124c24a (the variable serveFunction is removed as well - which makes us have to modify images ...)

Copy link
Author

Choose a reason for hiding this comment

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

Images modified in eaa194d

*
* serve -
*/
extern std::string serve(ConnectionInfo* ciP);
Copy link
Collaborator

Choose a reason for hiding this comment

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

After the change from

serveFunction    = (_serveFunction != NULL)? _serveFunction : serve;

to

serveFunction    = (_serveFunction != NULL)? _serveFunction : orionServe;

Is the serve() function actually used in some place? Should it be removed?

Copy link
Author

Choose a reason for hiding this comment

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

The serve()function changed name to orionServe(), that's all.
And yes, it is used :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok. Github diff is not always as smart as it should be with renamings... ;)

Copy link
Author

Choose a reason for hiding this comment

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

NTC

*
* serviceVectorsSet - only for unit tests
*/
extern void serviceVectorsSet
Copy link
Collaborator

Choose a reason for hiding this comment

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

If only used in unit tests, then use #ifdef UNIT_TEST.

(Maybe I'm repeating myself too much... sorry :)

Copy link
Author

Choose a reason for hiding this comment

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

As mentioned, the comment is no longer valid.

NTC

@@ -783,495 +783,393 @@ static const char* validLogLevels[] =



Copy link
Collaborator

Choose a reason for hiding this comment

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

This PR impacts in development manual. At least, the following should be reviewed:

However, a grep -i ... *.md in the doc/manuals/devel with the name of the key functions being modified will help to locate other possible changes needed.

Copy link
Author

Choose a reason for hiding this comment

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

ok :-( :-D

Copy link
Author

Choose a reason for hiding this comment

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

sourceCode.md modified in 7c82dd8.

RQ-01 and RQ-02 ... images?

Copy link
Author

Choose a reason for hiding this comment

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

ok, took a look at RQ-01 and 02.
Not sure why you mention these images. No changes to be made there.

NTC (after changes in sourceCode.md in commit 7c82dd8).

@@ -73,14 +73,23 @@ extern bool multitenant;
extern bool corsEnabled;
extern char corsOrigin[64];
extern int corsMaxAge;
extern RestService* restBadVerbV;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this addition to global variables?

Copy link
Author

Choose a reason for hiding this comment

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

I answered before. The vector for bad verbs is needed in RestService.cpp

Copy link
Author

Choose a reason for hiding this comment

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

NTC


/* ****************************************************************************
*
* serviceVectorsSet - only for unit tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that at the end this function is not only used only for unit tests, as restInit() also uses it. Thus the "- only for unit tests" fragment should be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Same in the .ccp file)

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in a265c79


/* ****************************************************************************
*
* serviceVectorsSet - only for unit tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

Repeated declaration? (in seems is also at RestService.h)

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in a265c79

@fgalan
Copy link
Collaborator

fgalan commented Mar 9, 2018

Except for some minor issues with serviceVectorsSet that should be reviewed, LGTM

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

Successfully merging this pull request may close these issues.

2 participants