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

Improve path routing logic #3109

Open
fgalan opened this issue Feb 13, 2018 · 5 comments
Open

Improve path routing logic #3109

fgalan opened this issue Feb 13, 2018 · 5 comments
Assignees
Labels

Comments

@fgalan
Copy link
Member

fgalan commented Feb 13, 2018

Current path routing vector (in contextBroker.cpp) is pretty old and can be improved. We consider three incremental enhancements:

  • Step 1: refactor the current code in contextBroker.cpp with the routing vector, moving out to another file. Implement a two-level vector (first level: verb, second level: path) for search and remove the redundant usage of bad verb methods. The search order will be exactly the same at it is now.
  • Step 2: reorder the search orther to priority operations that users will use more likely (i.e. NGSI10 operations with more priority than NGSI9 ones). Order stills being static.
  • Step 3: implement a dynamic mechanism, so the operations that are used most (measure with counters) will be first in the search logic.

Each step will be done separately (i.e. its own PR) and will be split among different Orion releases (i.e. the same Orion release will not include more than one step).

@kzangeli
Copy link
Member

kzangeli commented Mar 7, 2018

More stuff for Step 1 ...

  1. Move all defines into the RestService vectors:
    Instead of
     #define EPS                     EntryPointsRequest
     #define EPS_COMPS_V2            1, { "v2"             }
     #define ENT_COMPS_WORD          ""

     static RestService getServiceV[] =
     {
       { EPS, EPS_COMPS_V2, ENT_COMPS_WORD, entryPointsTreat },
       ...
     };

It will look like this (the lines will be long, not in this case, but in others):

     static RestService getServiceV[] =
     {
       { EntryPointsRequest, 1, { "v2" }, "", entryPointsTreat },
       ...
     }:
  1. Move the RestService vectors to inside librest and make sure even the special badVerb vector can be static (try at least)

  2. Remove the payloadWord (from old XML times ... :-(), in the example: ENT_COMPS_WORD.
    This is a lot tougher than I expected but ...

  3. Instead of giving the string vector, e.g. { "v2", "entity", "*" }, give just a string, e.g. "/v2/entity/*" and have the logic extract the string vector, if needed. ONLY URLs containing wildcards will need the string vector. Others, like "/v2/entities" can be string-compared right away, without need of the string vector (URL path components).
    The logic needs to check for '*' inside the URL and save a boolean to hold the info on "with wildcard or not".
    There will be TWO structs for RestService. One external one, to feed the library with RestService vectors:

   typedef struct RestService
   {
     RequestType     reqType;
     const char*     url;
     ServiceRoutine  sr;
   } RestService;

Internally, librest will translate this info into:

   typedef struct RestServiceInternally  // NOT the final name of the type!
   {
     RequestType     reqType;
     const char*     url;
     ServiceRoutine  sr;
     bool            wildcards;
     int             components;
     char*           compV[10];  // If ever 10 is not enough the logic will ASSERT - no need to worry
     int             usageCounter;
     ...
   } RestServiceInternally;

... You get it ...
This is BIG change, gonna take some time ...

Alternative to storing compV
The string-compare function for service matching could be smart and when found a '*', skip all chars until next '/' (or end-of-string). Doing that, char* compV[10] AND int components would not be nneded anymore

  1. Remove the badVerb service vector and make the logic find the allowed verbs itself

@fgalan
Copy link
Member Author

fgalan commented Mar 10, 2018

Step 1 stage 0 done in PR #3128

@fgalan fgalan added this to the 1.13.0 milestone Mar 10, 2018
@fgalan
Copy link
Member Author

fgalan commented Mar 10, 2018

Step 1 stage 1 done in PR #3129

@fgalan
Copy link
Member Author

fgalan commented Mar 17, 2018

Step 1 stage 2 done in PR #3261

@fgalan fgalan modified the milestones: 1.13.0, 1.14.0 Apr 16, 2018
@fgalan fgalan modified the milestones: 1.14.0, 1.15.0 Jun 15, 2018
@fgalan fgalan removed this from the 1.15.0 milestone Jul 16, 2018
@fgalan
Copy link
Member Author

fgalan commented Aug 6, 2018

Step 1 stage 3 done in PR #3261

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants