Skip to content

Commit

Permalink
Updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Anjali-NEC committed Jul 20, 2023
1 parent 51a71bb commit 1ebccb6
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 26 deletions.
2 changes: 2 additions & 0 deletions doc/manuals/admin/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ The list of available options is the following:
to the `-k` or `--insecure` parameteres of the curl command.
- **-mqttMaxAge**. Max time (in minutes) that an unused MQTT connection is kept. Default: 60
- **-logDeprecate**. Log deprecation usages as warnings. More information in [this section of the documentation](../deprecated.md#log-deprecation-warnings). Default is: false. It can be changed after Orion startup with the [log admin REST API](management_api.md#log-configs-and-trace-levels), with the `deprecated` field
- **-notifAlarmThreshold**. Maximum threshold for notification queue alarms, as a percentage of the maximum queue size, default 0 (meaning no queue alarms are used)

## Configuration using environment variables

Expand Down Expand Up @@ -263,3 +264,4 @@ Two facts have to be taken into account:
| ORION_NGSIV1_AUTOCAST | ngsiv1Autocast |
| ORION_MQTT_MAX_AGE | mqttMaxAge |
| ORION_LOG_DEPRECATE | logDeprecate |
| ORION_NOTIF_ALARM_THRESHOLD | notifAlarmThreshold |
15 changes: 3 additions & 12 deletions src/app/contextBroker/contextBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ unsigned long fcMaxInterval;
int mqttMaxAge;

bool logDeprecate;
long int maxthreshold;
long unsigned int notifAlarmThreshold;



Expand Down Expand Up @@ -277,7 +277,7 @@ long int maxthreshold;
#define NGSIV1_AUTOCAST_DESC "automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations"
#define MQTT_MAX_AGE_DESC "max time (in minutes) that an unused MQTT connection is kept, default: 60"
#define LOG_DEPRECATE_DESC "log deprecation usages as warnings"
#define MAX_THRESHOLD_DESC "maximum threshold for notification queue, default: 80%"
#define NOTIF_ALARM_THRESHOLD_DESC "maximum threshold for notification queue alarms, as a percentage of the maximum queue size, default 0 (meaning no queue alarms are used)"



Expand Down Expand Up @@ -368,7 +368,7 @@ PaArgument paArgs[] =

{ "-logDeprecate", &logDeprecate, "LOG_DEPRECATE", PaBool, PaOpt, false, false, true, LOG_DEPRECATE_DESC },

{ "-maxthreshold", &maxthreshold, "MAX_THRESHOLD", PaInt, PaOpt, 0, PaNL, PaNL, MAX_THRESHOLD_DESC },
{ "-notifAlarmThreshold", &notifAlarmThreshold, "NOTIF_ALARM_THRESHOLD", PaInt, PaOpt, 0, PaNL, PaNL, NOTIF_ALARM_THRESHOLD_DESC },

PA_END_OF_ARGS
};
Expand Down Expand Up @@ -660,15 +660,6 @@ static void contextBrokerInit(void)
QueueNotifier* pQNotifier = new QueueNotifier(notificationQueueSize, notificationThreadNum, serviceV, serviceQueueSizeV, serviceNumThreadV);
int rc = pQNotifier->start();

if (maxthreshold > 0)
{
maxthreshold=notificationQueueSize*maxthreshold/100;
}
else
{
maxthreshold=notificationQueueSize*80;
}

if (rc != 0)
{
LM_X(1,("Runtime Error starting notification queue workers (%d)", rc));
Expand Down
32 changes: 19 additions & 13 deletions src/lib/ngsiNotify/QueueNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,30 @@ void QueueNotifier::sendNotifyContextRequest

bool enqueued = sq->try_push(paramsP);

if (enqueued)
if (!enqueued)
{
QueueStatistics::incReject(1);
LM_E(("Runtime Error (%s notification queue is full)", queueName.c_str()));
delete paramsP;

extern long int maxthreshold;
extern int notificationQueueSize;
return;
}

extern long unsigned int notifAlarmThreshold;

if (notifAlarmThreshold != 0)
{
std::string details = ("notification queue reached maximum threshold");

if (maxthreshold >= notificationQueueSize)
if (notifAlarmThreshold > 0)
{
notifAlarmThreshold=queueSize(service)*notifAlarmThreshold/100;
}
if (notifAlarmThreshold > 100)
{
LM_X(1, ("Fatal Error (notifAlarmThreshol value is greater than 100%)"));
}
if (notifAlarmThreshold >= queueSize(service))
{
alarmMgr.notificationQueue(queueName.c_str(), details);
}
Expand All @@ -196,14 +211,5 @@ void QueueNotifier::sendNotifyContextRequest
}
}

if (!enqueued)
{
QueueStatistics::incReject(1);
LM_E(("Runtime Error (%s notification queue is full)", queueName.c_str()));
delete paramsP;

return;
}

QueueStatistics::incIn(1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ Usage: contextBroker [option '-U' (extended usage)]
[option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)]
[option '-mqttMaxAge' <max time (in minutes) that an unused MQTT connection is kept, default: 60>]
[option '-logDeprecate' (log deprecation usages as warnings)]
[option '-notifAlarmThreshold' <maximum threshold for notification queue alarms, as a percentage of the maximum queue size, default 0 (meaning no queue alarms are used)>]

--TEARDOWN--
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ Usage: contextBroker [option '-U' (extended usage)]
[option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)]
[option '-mqttMaxAge' <max time (in minutes) that an unused MQTT connection is kept, default: 60>]
[option '-logDeprecate' (log deprecation usages as warnings)]
[option '-notifAlarmThreshold' <maximum threshold for notification queue alarms, as a percentage of the maximum queue size, default 0 (meaning no queue alarms are used)>]

--TEARDOWN--
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ Usage: contextBroker [option '-U' (extended usage)]
[option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)]
[option '-mqttMaxAge' <max time (in minutes) that an unused MQTT connection is kept, default: 60>]
[option '-logDeprecate' (log deprecation usages as warnings)]
[option '-notifAlarmThreshold' <maximum threshold for notification queue alarms, as a percentage of the maximum queue size, default 0 (meaning no queue alarms are used)>]

--TEARDOWN--
1 change: 1 addition & 0 deletions test/functionalTest/cases/3658_env_vars/env_vars.test
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Extended Usage: contextBroker [option '-U' (extended usage)]
[option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSI] ORION_NGSIV1_AUTOCAST FALSE /FALSE/
[option '-mqttMaxAge' <max time (in minutes) that an unused MQTT connection is k] ORION_MQTT_MAX_AGE 60 /60/
[option '-logDeprecate' (log deprecation usages as warnings)] ORION_LOG_DEPRECATE FALSE /FALSE/
[option '-notifAlarmThreshold' <maximum threshold for notification queue alarms,] ORION_NOTIF_ALARM_THRESHOLD 0 /0/



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ alarm for notification queue overpassing a given threshold
dbInit ${CB_DB_NAME} serv1
dbInit ${CB_DB_NAME} serv2
dbInit ${CB_DB_NAME} serv3
brokerStart CB 0 IPv4 -multiservice -maxthreshold 100 -notificationMode threadpool:3:2,serv1:3:2,serv2:3:2,serv3:3:2
brokerStart CB 0 IPv4 -multiservice -notifAlarmThreshold 90 -notificationMode threadpool:3:2,serv1:3:2,serv2:3:2,serv3:3:2
accumulatorStart --pretty-print localhost $LISTENER_PORT

--SHELL--
Expand Down

0 comments on commit 1ebccb6

Please sign in to comment.