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

modify a namemapping implies a cygnus restart? #2121

Closed
AlvaroVega opened this issue Jan 14, 2022 · 6 comments
Closed

modify a namemapping implies a cygnus restart? #2121

AlvaroVega opened this issue Jan 14, 2022 · 6 comments

Comments

@AlvaroVega
Copy link
Member

Some questions to clarify:

  • Cygnus need be restarted after modify a namemapping?
  • If cygnus namemapping is in a file volume, cygnus container needs be restarted?
  • How apply this over kubernetes pods?
@AlvaroVega
Copy link
Member Author

@AlvaroVega
Copy link
Member Author

AlvaroVega commented Feb 7, 2022

NM doc:
https://github.com/telefonicaid/fiware-cygnus/blob/master/doc/cygnus-ngsi/flume_extensions_catalogue/ngsi_name_mappings_interceptor.md
https://fiware-cygnus.readthedocs.io/en/latest/cygnus-ngsi/installation_and_administration_guide/name_mappings/index.html

NM are read each 30 seconds:

// Create and start a periodical name mappings reader
periodicalNameMappingsReader = new PeriodicalNameMappingsReader(30000);

/**
* Class in charge or periodically reading the NGSINameMappingsInterceptor
* configuration file.
*/
private class PeriodicalNameMappingsReader extends Thread {
private final CygnusLogger logger = new CygnusLogger(PeriodicalNameMappingsReader.class);
private final int interval;
private long lastModified;
private boolean stop;
PeriodicalNameMappingsReader(int interval) {
this.interval = interval;
this.lastModified = 0;
this.stop = false;
} // PeriodicalNameMappingsReader
@Override
public void run() {
while (!stop) {
// Check if the configuration has changed
File groupingRulesFile = new File(nameMappingsConfFile);
long modified = groupingRulesFile.lastModified();
if (lastModified != 0 && modified == lastModified) {
logger.debug("[nmi] The configuration has not changed");
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
logger.error(
"[nmi] There was a problem with the checking interval. Details: " + e.getMessage());
} // try catch
continue;
} // if
// Reload the name mappings
lastModified = modified;
loadNameMappings();
// Sleep the configured interval of time
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
logger.error("There was a problem with the checking interval. Details: " + e.getMessage());
} // try catch
} // while
} // run
public void signalForStop() {
this.stop = true;
} // signalForStop
} // PeriodicalNameMappingsReader

@AlvaroVega
Copy link
Member Author

AlvaroVega commented Feb 7, 2022

Cygnus is able to read a namemmapping file modified without restart in a docker:

time=2022-02-07T14:34:28.988Z | lvl=DEBUG | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadNameMappings | msg=com.telefonica.iot.cygnus.interceptors.NGSINameMappingsInterceptor[242] : [nmi] Reading name mappings, Json read: { "serviceMappings": [ { "originalService": "smartcity", "newService": "smartcityXXXXX", "servicePathMappings": [ { "originalServicePath": "", "newServicePath": "", "entityMappings": [ { "originalEntityId": "", "originalEntityType": "", "newEntityId": "", "newEntityType": "", "attributeMappings": [ { "originalAttributeName": "", "originalAttributeType": "", "newAttributeName": "", "newAttributeType": "" } ] } ] } ] } ]}
time=2022-02-07T14:34:28.992Z | lvl=DEBUG | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadNameMappings | msg=com.telefonica.iot.cygnus.interceptors.NGSINameMappingsInterceptor[270] : [nmi] Reading attribute mappings, Json parsed
time=2022-02-07T14:34:28.992Z | lvl=DEBUG | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadNameMappings | msg=com.telefonica.iot.cygnus.interceptors.NGSINameMappingsInterceptor[284] : [nmi] Reading name mappings, Json purged
time=2022-02-07T14:34:28.992Z | lvl=DEBUG | corr=N/A | trans=N/A | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=loadNameMappings | msg=com.telefonica.iot.cygnus.interceptors.NGSINameMappingsInterceptor[294] : [nmi] Reading name mappings, regular expressions pre-compiled

ls -la name_mappings_mysql.conf
-rw-r--r-- 1 avega avega 881 Feb 7 15:34 name_mappings_mysql.conf

@AlvaroVega
Copy link
Member Author

Given a cygnus configured with a NM in a volume like:
volumes:
- ${PATH_CYGNUS_CONF}/name_mappings_mysql.conf:/opt/apache-flume/conf/name_mappings_mysql.conf

After change NM file ${PATH_CYGNUS_CONF}/name_mappings_mysql.conf from

{
   "serviceMappings": [
      {
         "originalService": "smartcity",
         "newService": "smartcityXXXXX",
         "servicePathMappings": []
      }
   ]
}

to

{
   "serviceMappings": [
      {
         "originalService": "smartcity",
         "newService": "smartcityXXXXX",
         "servicePathMappings": []
      }
   ]
}

No restart iot-cygnus container is needed, cygnus reads NM each 30 seconds and after then applies the new NM.

@AlvaroVega
Copy link
Member Author

AlvaroVega commented Feb 9, 2022

But the importat detail is modify NM file (or any cygnus config file) without changing i-node (i.e. vim editor does it: moby/moby#15793 (comment))
Recommended editor is Nano.

@AlvaroVega
Copy link
Member Author

#2136

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

No branches or pull requests

2 participants