Supports 3rd party json for measurements 29/44929/1
authorGokul Singaraju <gs244f@att.com>
Thu, 26 Apr 2018 16:42:18 +0000 (12:42 -0400)
committerGokul Singaraju <gs244f@att.com>
Thu, 26 Apr 2018 16:44:37 +0000 (12:44 -0400)
Issue-ID: CERT-14
Change-Id: Ib0fa11fc5978a4785a056f37198947120b3979a8
Signed-off-by: Gokul Singaraju <gs244f@att.com>
vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h
vnfs/VES5.0/evel/evel-library/code/evel_library/evel_jsonobject.c
vnfs/VES5.0/evel/evel-library/code/evel_library/evel_other.c
vnfs/VES5.0/evel/evel-library/code/evel_library/evel_scaling_measurement.c

index 5c05993..b483b1f 100644 (file)
@@ -703,6 +703,37 @@ typedef struct event_measurement {
 
 } EVENT_MEASUREMENT;
 
+
+
+/**************************************************************************//**
+ * Add an additional value name/value pair to the Measurement.
+ *
+ * The name and value are null delimited ASCII strings.  The library takes
+ * a copy so the caller does not have to preserve values after the function
+ * returns.
+ *
+ * @param measurement     Pointer to the measurement.
+ * @param name      ASCIIZ string with the attribute's name.  The caller
+ *                  does not need to preserve the value once the function
+ *                  returns.
+ * @param value     ASCIIZ string with the attribute's value.  The caller
+ *                  does not need to preserve the value once the function
+ *                  returns.
+ *****************************************************************************/
+void evel_measurement_addl_info_add(EVENT_MEASUREMENT * measurement, char * name, char * value);
+
+/**************************************************************************//**
+ * Add a json object to jsonObject list.
+ *
+ * The name and value are null delimited ASCII strings.  The library takes
+ * a copy so the caller does not have to preserve values after the function
+ * returns.
+ *
+ * @param measurement     Pointer to the ScalingMeasurement
+ * @param jsonobj   Pointer to json object
+ *****************************************************************************/
+void evel_measurement_addl_object_add(EVENT_MEASUREMENT * measurement, EVEL_JSON_OBJECT *jsonobj);
+
 /**************************************************************************//**
  * CPU Usage.
  * JSON equivalent field: cpuUsage
index 4f788bd..8bf2b70 100644 (file)
@@ -321,7 +321,7 @@ void evel_jsonobject_add_jsoninstance(EVEL_JSON_OBJECT * pobj, EVEL_JSON_OBJECT_
   assert(pobj != NULL);
   assert(jinst != NULL);
 
-  EVEL_DEBUG("Adding json object instance");
+  EVEL_DEBUG("Adding json object instance %p",jinst);
 
   dlist_push_last(&pobj->jsonobjectinstances, jinst);
 
@@ -375,6 +375,7 @@ void evel_free_internal_key(EVEL_INTERNAL_KEY * keyp)
 
   free(keyp->keyname);
   evel_free_option_string(&keyp->keyvalue);
+  free(keyp);
   EVEL_EXIT();
 }
 
@@ -407,6 +408,7 @@ void evel_free_jsonobjinst(EVEL_JSON_OBJECT_INSTANCE * objinst)
     evel_free_internal_key(other_field);
     other_field = dlist_pop_last(&objinst->object_keys);
   }
+  free(objinst);
 
   EVEL_EXIT();
 }
@@ -425,6 +427,7 @@ void evel_free_jsonobject(EVEL_JSON_OBJECT * jsobj)
   EVEL_ENTER();
   assert(jsobj != NULL);
 
+  EVEL_DEBUG("Freeing Json Object (%s)", jsobj->object_name);
   free(jsobj->object_name);
   evel_free_option_string(&jsobj->objectschema);
   evel_free_option_string(&jsobj->objectschemaurl);
@@ -437,11 +440,12 @@ void evel_free_jsonobject(EVEL_JSON_OBJECT * jsobj)
   other_field = dlist_pop_last(&jsobj->jsonobjectinstances);
   while (other_field != NULL)
   {
-    EVEL_DEBUG("Freeing Object Instance Field (%s)",
-               other_field->jsonstring);
+    EVEL_DEBUG("Freeing jsonObject Instance Field %p (%s)",
+               other_field,other_field->jsonstring);
     evel_free_jsonobjinst(other_field);
     other_field = dlist_pop_last(&jsobj->jsonobjectinstances);
   }
+  free(jsobj);
 
   EVEL_EXIT();
 }
index b238e38..360f5b9 100644 (file)
@@ -200,7 +200,6 @@ void evel_other_field_add_namedarray(EVENT_OTHER * other, const char *hashname,
  *****************************************************************************/
 void evel_other_field_add_jsonobj(EVENT_OTHER * other, EVEL_JSON_OBJECT *jsonobj)
 {
-  OTHER_FIELD * other_field = NULL;
   EVEL_ENTER();
 
   /***************************************************************************/
@@ -471,6 +470,8 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
 void evel_free_other(EVENT_OTHER * event)
 {
   OTHER_FIELD * other_field = NULL;
+  EVEL_JSON_OBJECT * jsonobjp = NULL;
+  DLIST_ITEM * other_field_item = NULL;
 
   EVEL_ENTER();
 
@@ -495,6 +496,15 @@ void evel_free_other(EVENT_OTHER * event)
     free(other_field);
     other_field = dlist_pop_last(&event->namedvalues);
   }
+
+  jsonobjp = dlist_pop_last(&event->jsonobjects);
+  while (jsonobjp != NULL)
+  {
+    evel_free_jsonobject( jsonobjp );
+
+    jsonobjp = dlist_pop_last(&event->jsonobjects);
+  }
+
   evel_free_header(&event->header);
 
   EVEL_EXIT();
index d484b2e..84d2564 100644 (file)
@@ -169,6 +169,35 @@ void evel_measurement_addl_info_add(EVENT_MEASUREMENT * measurement, char * name
   EVEL_EXIT();
 }
 
+/**************************************************************************//**
+ * Add a json object to jsonObject list.
+ *
+ * The name and value are null delimited ASCII strings.  The library takes
+ * a copy so the caller does not have to preserve values after the function
+ * returns.
+ *
+ * @param measurement     Pointer to the ScalingMeasurement
+ * @param jsonobj   Pointer to json object
+ *****************************************************************************/
+void evel_measurement_addl_object_add(EVENT_MEASUREMENT * measurement, EVEL_JSON_OBJECT *jsonobj)
+{
+  EVEL_ENTER();
+
+  /***************************************************************************/
+  /* Check preconditions.                                                    */
+  /***************************************************************************/
+  assert(measurement != NULL);
+  assert(measurement->header.event_domain == EVEL_DOMAIN_MEASUREMENT);
+  assert(jsonobj != NULL);
+
+  EVEL_DEBUG("Adding jsonObject %p",jsonobj);
+
+  dlist_push_last(&measurement->additional_objects, jsonobj);
+
+  EVEL_EXIT();
+}
+
+
 /**************************************************************************//**
  * Set the Concurrent Sessions property of the Measurement.
  *
@@ -2820,17 +2849,17 @@ void evel_vnic_performance_tx_total_pkt_delta_set(MEASUREMENT_VNIC_PERFORMANCE *
  * @param tx_ucast_packets_acc
  *****************************************************************************/
 void evel_vnic_performance_tx_ucast_pkt_acc_set(MEASUREMENT_VNIC_PERFORMANCE * const vnic_performance,
-                                    const double tx_ucast_packets_acc)
+                                    const double mtx_ucast_packets_acc)
 {
   EVEL_ENTER();
 
   /***************************************************************************/
   /* Check preconditions.                                                    */
   /***************************************************************************/
-  assert(tx_ucast_packets_acc >= 0.0);
+  assert(mtx_ucast_packets_acc >= 0.0);
 
   evel_set_option_double(&vnic_performance->tx_ucast_packets_acc,
-                      tx_ucast_packets_acc,
+                      mtx_ucast_packets_acc,
                       "Transmitted Unicast Packets accumulated");
 
   EVEL_EXIT();
@@ -3023,6 +3052,13 @@ void evel_json_encode_measurement(EVEL_JSON_BUFFER * jbuf,
   DLIST_ITEM * nested_item = NULL;
   DLIST_ITEM * addl_info_item = NULL;
   OTHER_FIELD *addl_info = NULL;
+  DLIST_ITEM * other_field_item = NULL;
+  EVEL_JSON_OBJECT_INSTANCE * jsonobjinst = NULL;
+  EVEL_JSON_OBJECT * jsonobjp = NULL;
+  DLIST_ITEM * jsobj_field_item = NULL;
+  EVEL_INTERNAL_KEY * keyinst = NULL;
+  DLIST_ITEM * keyinst_field_item = NULL;
+
 
   EVEL_ENTER();
 
@@ -3078,6 +3114,92 @@ void evel_json_encode_measurement(EVEL_JSON_BUFFER * jbuf,
     }
   }
 
+
+  evel_json_checkpoint(jbuf);
+  if(evel_json_open_opt_named_list(jbuf, "additionalObjects"))
+  {
+  bool item_added = false;
+  other_field_item = dlist_get_first(&event->additional_objects);
+  while (other_field_item != NULL)
+  {
+    jsonobjp = (EVEL_JSON_OBJECT *) other_field_item->item;
+    if(jsonobjp != NULL)
+    {
+     evel_json_open_object(jbuf);
+
+       if( evel_json_open_opt_named_list(jbuf, "objectInstances"))
+       {
+        bool item_added2 = false;
+        jsobj_field_item = dlist_get_first(&jsonobjp->jsonobjectinstances);
+        while (jsobj_field_item != NULL)
+        {
+           jsonobjinst = (EVEL_JSON_OBJECT_INSTANCE *) jsobj_field_item->item;
+           if( jsonobjinst != NULL )
+           {
+              evel_json_open_object(jbuf);
+              evel_enc_kv_object(jbuf, "objectInstance", jsonobjinst->jsonstring);
+              evel_enc_kv_ull(jbuf, "objectInstanceEpochMicrosec", jsonobjinst->objinst_epoch_microsec);
+  //evel_json_checkpoint(jbuf);
+  if (evel_json_open_opt_named_list(jbuf, "objectKeys"))
+  {
+    bool item_added3 = false;
+
+    keyinst_field_item = dlist_get_first(&jsonobjinst->object_keys);
+    while (keyinst_field_item != NULL)
+    {
+      keyinst = (EVEL_INTERNAL_KEY *)keyinst_field_item->item;
+      if(keyinst != NULL)
+      {
+        evel_json_open_object(jbuf);
+        evel_enc_kv_string(jbuf, "keyName", keyinst->keyname);
+        evel_enc_kv_opt_int(jbuf, "keyOrder", &keyinst->keyorder);
+        evel_enc_kv_opt_string(jbuf, "keyValue", &keyinst->keyvalue);
+        evel_json_close_object(jbuf);
+        item_added3 = true;
+      }
+      keyinst_field_item = dlist_get_next(keyinst_field_item);
+    }
+    evel_json_close_list(jbuf);
+
+    /*************************************************************************/
+    /* If we've not written anything, rewind to before we opened the list.   */
+    /*************************************************************************/
+    //if (!item_added3)
+    //{
+    //  evel_json_rewind(jbuf);
+    //}
+  }
+               evel_json_close_object(jbuf);
+            }
+            item_added2 = true;
+            jsobj_field_item = dlist_get_next(jsobj_field_item);
+        }
+        evel_json_close_list(jbuf);
+        if( !item_added2 )
+        {
+          evel_json_rewind(jbuf);
+        }
+       }
+
+    evel_enc_kv_string(jbuf, "objectName", jsonobjp->object_name);
+    evel_enc_kv_opt_string(jbuf, "objectSchema", &jsonobjp->objectschema);
+    evel_enc_kv_opt_string(jbuf, "objectSchemaUrl", &jsonobjp->objectschemaurl);
+    evel_enc_kv_opt_string(jbuf, "nfSubscribedObjectName", &jsonobjp->nfsubscribedobjname);
+    evel_enc_kv_opt_string(jbuf, "nfSubscriptionId", &jsonobjp->nfsubscriptionid);
+    evel_json_close_object(jbuf);
+    item_added = true;
+  }
+  other_field_item = dlist_get_next(other_field_item);
+  }
+  evel_json_close_list(jbuf);
+
+  if (!item_added)
+  {
+     evel_json_rewind(jbuf);
+  }
+  }
+
+
   // TBD additional json objects
   evel_enc_kv_opt_int(jbuf, "concurrentSessions", &event->concurrent_sessions);
   evel_enc_kv_opt_int(jbuf, "configuredEntities", &event->configured_entities);
@@ -3607,6 +3729,7 @@ void evel_free_measurement(EVENT_MEASUREMENT * event)
   MEASUREMENT_GROUP * measurement_group = NULL;
   CUSTOM_MEASUREMENT * measurement = NULL;
   OTHER_FIELD *addl_info = NULL;
+  EVEL_JSON_OBJECT * jsonobjp = NULL;
 
   EVEL_ENTER();
 
@@ -3632,7 +3755,13 @@ void evel_free_measurement(EVENT_MEASUREMENT * event)
     addl_info = dlist_pop_last(&event->additional_info);
   }
 
-
+  jsonobjp = dlist_pop_last(&event->additional_objects);
+  while (jsonobjp != NULL)
+  {
+    EVEL_DEBUG("Freeing jsonObject %p",jsonobjp);
+    evel_free_jsonobject( jsonobjp );
+    jsonobjp = dlist_pop_last(&event->additional_objects);
+  }
 
   cpu_use = dlist_pop_last(&event->cpu_usage);
   while (cpu_use != NULL)