Re: [devel] [PATCH 1 of 1] smfd: add support for detection of asynchronous failures of AMF entities [#2145]

2016-11-10 Thread Alex Jones
Thanks for the comments Rafael.

1) I will look at that page, and refactor that part of the code. I agree
that it is difficult to read.

2) The reason setting the maintenance status was moved to after the node
up, is because AMF will generate the operational state change
notification with the saAmfSUMaintenanceCampaign object set in the
notification for the old software when the node is brought down. SMF
would detect this as a failure, even though it is not, because it is the
old software going down. It was being set too early. According to
4.2.1.3 it should be set right before the activation unit is activated
with the new software.

I will submit a new patch soon.

Alex

On 11/10/2016 05:17 AM, Rafael Odzakow wrote:
> 
> NOTICE: This email was received from an EXTERNAL sender
> 
> 
> Hello,
> 
> looks good to me. Got a question and a comment below under the [rafael] tag.
> 
> 
> On 10/31/2016 09:31 PM, Alex Jones wrote:
>> osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc | 175
> +-
>> osaf/services/saf/smfsv/smfd/SmfCampaignThread.hh | 3 +
>> osaf/services/saf/smfsv/smfd/SmfStepTypes.cc | 32 ++-
>> 3 files changed, 191 insertions(+), 19 deletions(-)
>>
>>
>> This patch adds support for section 4.2.1.3 of SMF A.01.02 spec.
>>
>> diff --git a/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc
> b/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc
>> --- a/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc
>> +++ b/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc
>> @@ -39,6 +39,7 @@
>> #include "SmfUtils.hh"
>>
>> SmfCampaignThread *SmfCampaignThread::s_instance = NULL;
>> +SaNtfSubscriptionIdT SmfCampaignThread::operStateSubId(1);
>>
>> #define SMF_RDA_RETRY_COUNT 25 /* This is taken as the csi's are
> assigned in parallel */
>>
>> @@ -140,7 +141,12 @@ void SmfCampaignThread::main(NCSCONTEXT
>> SmfCampaignThread::~SmfCampaignThread()
>> {
>> TRACE_ENTER();
>> - SaAisErrorT rc = saNtfFinalize(m_ntfHandle);
>> + SaAisErrorT rc(saNtfNotificationUnsubscribe(operStateSubId));
>> + if (rc != SA_AIS_OK) {
>> + LOG_ER("Failed to unsubscribe to oper state notifications %u", rc);
>> + }
>> +
>> + rc = saNtfFinalize(m_ntfHandle);
>> if (rc != SA_AIS_OK) {
>> LOG_ER("Failed to finalize NTF handle %u", rc);
>> }
>> @@ -303,10 +309,14 @@ int SmfCampaignThread::initNtf(void)
>> {
>> SaAisErrorT rc = SA_AIS_ERR_TRY_AGAIN;
>> SaVersionT ntfVersion = { 'A', 1, 1 };
>> + SaNtfCallbacksT callbacks = {
>> + ntfNotificationCallback,
>> + 0
>> + };
>> unsigned int numOfTries = 50;
>>
>> while (rc == SA_AIS_ERR_TRY_AGAIN && numOfTries > 0) {
>> - rc = saNtfInitialize(_ntfHandle, NULL, );
>> + rc = saNtfInitialize(_ntfHandle, , );
>> if (rc != SA_AIS_ERR_TRY_AGAIN) {
>> break;
>> }
>> @@ -319,9 +329,142 @@ int SmfCampaignThread::initNtf(void)
>> return -1;
>> }
>>
>> + // subscribe to operational state change notifications generated by AMF
>> + rc = initNtfSubscriptions();
>> + if (rc != SA_AIS_OK) {
>> + LOG_ER("initNtfSubscriptions FAILED rc=%s", saf_error(rc));
>> + return -1;
>> + }
>> +
>> return 0;
>> }
>>
>> +SaAisErrorT SmfCampaignThread::initNtfSubscriptions(void) {
>> + TRACE_ENTER();
>> + SaAisErrorT rc(SA_AIS_OK);
>> +
>> + do {
>> + SaNtfStateChangeNotificationFilterT stateChangeFilter;
>> +
>> + SaAisErrorT rc(saNtfStateChangeNotificationFilterAllocate(
>> + m_ntfHandle,
>> + ,
>> + 0,
>> + 0,
>> + 0,
>> + 0,
>> + 0,
>> + 0));
>> +
>> + if (rc != SA_AIS_OK) {
>> + LOG_ER("saNtfAttributeChangeNotificationFilterAllocate FAILED rc=%s",
>> + saf_error(rc));
>> + break;
>> + }
>> +
>> + SaNtfNotificationTypeFilterHandlesT notificationFilterHandles = {
>> + 0,
>> + 0,
>> + stateChangeFilter.notificationFilterHandle,
>> + 0,
>> + 0
>> + };
>> +
>> + rc = saNtfNotificationSubscribe(,
> operStateSubId);
>> +
>> + if (rc != SA_AIS_OK) {
>> + LOG_ER("saNtfNotificationSubscribe FAILED rc=%s", saf_error(rc));
>> + break;
>> + }
>> +
>> + rc =
> saNtfNotificationFilterFree(stateChangeFilter.notificationFilterHandle);
>> + if (rc != SA_AIS_OK) {
>> + LOG_ER("saNtfNotificationFilterFree FAILED rc=%s", saf_error(rc));
>> + break;
>> + }
>> + } while (false);
>> +
>> + TRACE_LEAVE();
>> + return rc;
>> +}
>> +
>> +void SmfCampaignThread::ntfNotificationCallback(
>> + SaNtfSubscriptionIdT subId,
>> + const SaNtfNotificationsT *notification) {
>> + TRACE_ENTER();
>> +
>> + do {
>> + if (subId != operStateSubId) {
>> + TRACE("unknown subscription id received in ntfNotificationCallback:
> %d", subId);
>> + break;
>> + }
>> +
>> + // check if an SU was disabled after it had been upgraded
>> + if (notification->notificationType == SA_NTF_TYPE_STATE_CHANGE) {
>> + const SaNtfStateChangeNotificationT& stateChangeNotification(
>> + notification->notification.stateChangeNotification);
>> +
>> + if (stateChangeNotification.notificationHeader.eventType &&
>> + 

[devel] [PATCH 1 of 1] smfd: add support for detection of asynchronous failures of AMF entities [#2145]

2016-10-31 Thread Alex Jones
 osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc |  175 +-
 osaf/services/saf/smfsv/smfd/SmfCampaignThread.hh |3 +
 osaf/services/saf/smfsv/smfd/SmfStepTypes.cc  |   32 ++-
 3 files changed, 191 insertions(+), 19 deletions(-)


This patch adds support for section 4.2.1.3 of SMF A.01.02 spec.

diff --git a/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc 
b/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc
--- a/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc
+++ b/osaf/services/saf/smfsv/smfd/SmfCampaignThread.cc
@@ -39,6 +39,7 @@
 #include "SmfUtils.hh"
 
 SmfCampaignThread *SmfCampaignThread::s_instance = NULL;
+SaNtfSubscriptionIdT SmfCampaignThread::operStateSubId(1);
 
 #define SMF_RDA_RETRY_COUNT 25 /* This is taken as the csi's are assigned in 
parallel */
 
@@ -140,7 +141,12 @@ void SmfCampaignThread::main(NCSCONTEXT 
 SmfCampaignThread::~SmfCampaignThread()
 {
TRACE_ENTER();
-   SaAisErrorT rc = saNtfFinalize(m_ntfHandle);
+  SaAisErrorT rc(saNtfNotificationUnsubscribe(operStateSubId));
+   if (rc != SA_AIS_OK) {
+   LOG_ER("Failed to unsubscribe to oper state notifications %u", 
rc);
+   }
+
+   rc = saNtfFinalize(m_ntfHandle);
if (rc != SA_AIS_OK) {
LOG_ER("Failed to finalize NTF handle %u", rc);
}
@@ -303,10 +309,14 @@ int SmfCampaignThread::initNtf(void)
 {
SaAisErrorT rc = SA_AIS_ERR_TRY_AGAIN;
SaVersionT ntfVersion = { 'A', 1, 1 };
+  SaNtfCallbacksT callbacks = {
+ntfNotificationCallback,
+0
+  };
unsigned int numOfTries = 50;
 
while (rc == SA_AIS_ERR_TRY_AGAIN && numOfTries > 0) {
-   rc = saNtfInitialize(_ntfHandle, NULL, );
+   rc = saNtfInitialize(_ntfHandle, , );
if (rc != SA_AIS_ERR_TRY_AGAIN) {
break;
}
@@ -319,9 +329,142 @@ int SmfCampaignThread::initNtf(void)
return -1;
}
 
+  // subscribe to operational state change notifications generated by AMF
+  rc = initNtfSubscriptions();
+   if (rc != SA_AIS_OK) {
+   LOG_ER("initNtfSubscriptions FAILED rc=%s", saf_error(rc));
+   return -1;
+   }
+
return 0;
 }
 
+SaAisErrorT SmfCampaignThread::initNtfSubscriptions(void) {
+  TRACE_ENTER();
+  SaAisErrorT rc(SA_AIS_OK);
+
+  do {
+SaNtfStateChangeNotificationFilterT stateChangeFilter;
+
+SaAisErrorT rc(saNtfStateChangeNotificationFilterAllocate(
+  m_ntfHandle,
+  ,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0));
+
+if (rc != SA_AIS_OK) {
+  LOG_ER("saNtfAttributeChangeNotificationFilterAllocate FAILED rc=%s",
+ saf_error(rc));
+  break;
+}
+
+SaNtfNotificationTypeFilterHandlesT notificationFilterHandles = {
+  0,
+  0,
+  stateChangeFilter.notificationFilterHandle,
+  0,
+  0
+};
+
+rc = saNtfNotificationSubscribe(, 
operStateSubId);
+
+if (rc != SA_AIS_OK) {
+  LOG_ER("saNtfNotificationSubscribe FAILED rc=%s", saf_error(rc));
+  break;
+}
+
+rc = 
saNtfNotificationFilterFree(stateChangeFilter.notificationFilterHandle);
+if (rc != SA_AIS_OK) {
+  LOG_ER("saNtfNotificationFilterFree FAILED rc=%s", saf_error(rc));
+  break;
+}
+  } while (false);
+
+  TRACE_LEAVE();
+  return rc;
+}
+
+void SmfCampaignThread::ntfNotificationCallback(
+  SaNtfSubscriptionIdT subId,
+  const SaNtfNotificationsT *notification) {
+  TRACE_ENTER();
+
+  do {
+if (subId != operStateSubId) {
+  TRACE("unknown subscription id received in ntfNotificationCallback: %d", 
subId);
+  break;
+}
+
+// check if an SU was disabled after it had been upgraded
+if (notification->notificationType == SA_NTF_TYPE_STATE_CHANGE) {
+  const SaNtfStateChangeNotificationT& stateChangeNotification(
+notification->notification.stateChangeNotification);
+
+  if (stateChangeNotification.notificationHeader.eventType &&
+  *stateChangeNotification.notificationHeader.eventType ==
+SA_NTF_OBJECT_STATE_CHANGE) {
+if (stateChangeNotification.notificationHeader.notificationClassId &&
+
stateChangeNotification.notificationHeader.notificationClassId->vendorId ==
+  SA_NTF_VENDOR_ID_SAF &&
+
stateChangeNotification.notificationHeader.notificationClassId->majorId ==
+  SA_SVC_AMF &&
+
stateChangeNotification.notificationHeader.notificationClassId->minorId ==
+  SA_AMF_NTFID_SU_OP_STATE) {
+  for (SaUint16T i(0); i < stateChangeNotification.numStateChanges; 
i++) {
+if (stateChangeNotification.changedStates[i].newState ==
+  SA_AMF_OPERATIONAL_DISABLED &&
+stateChangeNotification.notificationHeader.additionalInfo) {
+  for (SaUint16T j(0);
+   j < 
stateChangeNotification.notificationHeader.numAdditionalInfo;
+