cd1ac0b3781ff1c2174e5e40f6eeae0b6b2722fd
[vnfsdk/compliance.git] / veslibrary / ves_javalibrary / evel_javalib2 / src / evel_javalibrary / att / com / EvelHeader.java
1 package evel_javalibrary.att.com;\r
2 \r
3 /**************************************************************************//**\r
4  * @file\r
5  * Header for EVEL Header library\r
6  *\r
7  * This file implements the EVEL library which is intended to provide a\r
8  * simple wrapper around the complexity of AT&T's Vendor Event Listener API so\r
9  * that VNFs can use it without worrying about details of the API transport.\r
10  *\r
11  * License\r
12  * -------\r
13  *\r
14  * Licensed under the Apache License, Version 2.0 (the "License");\r
15  * you may not use this file except in compliance with the License.\r
16  * You may obtain a copy of the License at\r
17  *        http://www.apache.org/licenses/LICENSE-2.0\r
18  *\r
19  * Unless required by applicable law or agreed to in writing, software\r
20  * distributed under the License is distributed on an "AS IS" BASIS,\r
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
22  * See the License for the specific language governing permissions and\r
23  * limitations under the License.\r
24  *****************************************************************************/\r
25 \r
26 \r
27 import java.text.MessageFormat;\r
28 import java.util.Enumeration;\r
29 import java.util.logging.Logger;\r
30 import java.io.StringWriter;\r
31 import java.net.InetAddress;\r
32 import java.net.NetworkInterface;\r
33 import java.net.SocketException;\r
34 import java.net.UnknownHostException;\r
35 \r
36 import javax.json.Json;\r
37 import javax.json.JsonObject;\r
38 import javax.json.JsonObjectBuilder;\r
39 import javax.json.JsonString;\r
40 import javax.json.JsonWriter;\r
41 \r
42 import org.slf4j.helpers.MessageFormatter;\r
43 \r
44 \r
45 public class EvelHeader {\r
46         \r
47         /**************************************************************************//**\r
48          * Event domains for the various events we support.\r
49          * JSON equivalent field: domain\r
50          *****************************************************************************/\r
51         public enum DOMAINS {\r
52           EVEL_DOMAIN_INTERNAL,       /** Internal event, not for external routing.  */\r
53           EVEL_DOMAIN_FAULT,          /** A Fault event.                             */\r
54           EVEL_DOMAIN_HEARTBEAT,      /** A Heartbeat event (event header only).     */\r
55           EVEL_DOMAIN_MEASUREMENT,    /** A Measurement for VF Scaling event.        */\r
56           EVEL_DOMAIN_MOBILE_FLOW,    /** A Mobile Flow event.                       */\r
57           EVEL_DOMAIN_OTHER,          /** Another event.                             */\r
58           EVEL_DOMAIN_REPORT,         /** A Measurement for VF Reporting event.      */\r
59           EVEL_DOMAIN_SIPSIGNALING,   /** A Signaling event.                         */\r
60           EVEL_DOMAIN_STATE_CHANGE,   /** A State Change event.                      */\r
61           EVEL_DOMAIN_SYSLOG,         /** A Syslog event.                            */\r
62           EVEL_DOMAIN_THRESHOLD_CROSSING,  /** A Threshold crossing alert Event     */\r
63           EVEL_DOMAIN_VOICE_QUALITY,  /** A Voice Quality Event                      */\r
64           EVEL_DOMAIN_HEARTBEAT_FIELD,/** A Heartbeat field event.                   */\r
65           EVEL_MAX_DOMAINS            /** Maximum number of recognized Event types.  */\r
66         }\r
67         \r
68         /**************************************************************************//**\r
69          * Event priorities.\r
70          * JSON equivalent field: priority\r
71          *****************************************************************************/\r
72         public enum PRIORITIES {\r
73           EVEL_PRIORITY_HIGH,\r
74           EVEL_PRIORITY_MEDIUM,\r
75           EVEL_PRIORITY_NORMAL,\r
76           EVEL_PRIORITY_LOW,\r
77           EVEL_MAX_PRIORITIES\r
78         }\r
79         \r
80         final int EVEL_HEADER_MAJOR_VERSION = 1;\r
81         final int EVEL_HEADER_MINOR_VERSION = 1;\r
82           /***************************************************************************/\r
83           /* Version                                                                 */\r
84           /***************************************************************************/\r
85           int major_version;\r
86           int minor_version;\r
87 \r
88           /***************************************************************************/\r
89           /* Mandatory fields                                                        */\r
90           /***************************************************************************/\r
91           DOMAINS event_domain;\r
92           String event_id=null;\r
93           String event_name=null;\r
94           String source_name=null;\r
95           String reporting_entity_name=null;\r
96           PRIORITIES priority;\r
97           Long start_epoch_microsec = 0L;\r
98           Long last_epoch_microsec = 0L;\r
99           int sequence;\r
100 \r
101           /***************************************************************************/\r
102           /* Optional fields                                                         */\r
103           /***************************************************************************/\r
104           EvelOptionString event_type;\r
105           EvelOptionString source_id;\r
106           EvelOptionString reporting_entity_id;\r
107           EvelOptionIntHeader internal_field;\r
108           EvelOptionString nfcnaming_code;\r
109           EvelOptionString nfnaming_code;\r
110           \r
111           /**************************************************************************//**\r
112            * Unique sequence number for events from this VNF.\r
113            *****************************************************************************/\r
114           static int event_sequence = 1;\r
115           private static final Logger LOGGER = Logger.getLogger( EvelHeader.class.getName() );\r
116 \r
117                 protected static void EVEL_EXIT() {\r
118                         // TODO Auto-generated method stub\r
119                         \r
120                 }\r
121 \r
122                 protected static void EVEL_ENTER() {\r
123                         // TODO Auto-generated method stub\r
124                 }\r
125 \r
126           /**************************************************************************//**\r
127            * Set the next event_sequence to use.\r
128            *\r
129            * @param sequence      The next sequence number to use.\r
130            *****************************************************************************/\r
131           void evel_set_next_event_sequence( int sequence)\r
132           {\r
133             EVEL_ENTER();\r
134 \r
135             LOGGER.info(MessageFormat.format("Setting event sequence to {0}, was {1} ", sequence, event_sequence));\r
136             event_sequence = sequence;\r
137 \r
138             EVEL_EXIT();\r
139           }\r
140           \r
141           private final static char[] hexArray = "0123456789ABCDEF".toCharArray();\r
142           private static String bytesToHex(byte[] bytes) {\r
143               char[] hexChars = new char[bytes.length * 2];\r
144               for ( int j = 0; j < bytes.length; j++ ) {\r
145                   int v = bytes[j] & 0xFF;\r
146                   hexChars[j * 2] = hexArray[v >>> 4];\r
147                   hexChars[j * 2 + 1] = hexArray[v & 0x0F];\r
148               }\r
149               return new String(hexChars);\r
150           }\r
151 \r
152           /**************************************************************************//**\r
153            * Initialize a newly created event header.\r
154            *\r
155            * @param header  Pointer to the header being initialized.\r
156            *****************************************************************************/\r
157           public EvelHeader(String eventname,String ev_id)\r
158           {\r
159             EVEL_ENTER();\r
160 \r
161             assert(eventname != null);\r
162 \r
163             /***************************************************************************/\r
164             /* Initialize the header.  Get a new event sequence number.  Note that if  */\r
165             /* any memory allocation fails in here we will fail gracefully because     */\r
166             /* everything downstream can cope with nulls.                              */\r
167             /***************************************************************************/\r
168             this.event_domain = DOMAINS.EVEL_DOMAIN_HEARTBEAT;\r
169             if(ev_id == null){\r
170                 event_id = MessageFormat.format("{0}", event_sequence);\r
171                 LOGGER.warning("WARNING:not confirming to Common Event Format 28.3 standard");\r
172             } else\r
173                 event_id = ev_id;\r
174             event_name = eventname;\r
175             start_epoch_microsec = last_epoch_microsec;\r
176             last_epoch_microsec = System.nanoTime()/1000;\r
177             priority = PRIORITIES.EVEL_PRIORITY_NORMAL;\r
178             \r
179             String hostname = "Unknown";\r
180             String uuid = "Unknown";\r
181 \r
182             try\r
183             {\r
184                 InetAddress addr;\r
185                 addr = InetAddress.getLocalHost();\r
186                 hostname = addr.getHostName();\r
187             }\r
188             catch (UnknownHostException ex)\r
189             {\r
190                 System.out.println("Hostname can not be resolved");\r
191             }\r
192             \r
193             try{\r
194                 \r
195           Enumeration<NetworkInterface> networks =\r
196                 NetworkInterface.getNetworkInterfaces();\r
197           while(networks.hasMoreElements()) {\r
198             NetworkInterface network = networks.nextElement();\r
199             byte[] mac = network.getHardwareAddress();\r
200             \r
201             if(hostname.equalsIgnoreCase("unknown"))\r
202             {\r
203                 Enumeration inetAddrs = network.getInetAddresses();\r
204                 while(inetAddrs.hasMoreElements()){\r
205                 InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();\r
206                 if (!inetAddr.isLoopbackAddress()) {\r
207                         hostname = inetAddr.getHostAddress();\r
208                         break;\r
209                 }\r
210              }\r
211             }\r
212 \r
213             if (mac != null) {\r
214                 /* System.out.print("Current MAC address : ");\r
215 \r
216                 StringBuilder sb = new StringBuilder();\r
217                 for (int i = 0; i < mac.length; i++) {\r
218                     sb.append(String.format("%02X%s", mac[i],\r
219                                  (i < mac.length - 1) ? "-" : ""));\r
220                 } */\r
221                 \r
222                 uuid = bytesToHex(mac);\r
223             }\r
224           }\r
225         \r
226             } catch (SocketException e) {\r
227                         // TODO Auto-generated catch block\r
228                         e.printStackTrace();\r
229                 }\r
230             \r
231             \r
232             reporting_entity_name = hostname;\r
233             source_name = hostname;\r
234             sequence = event_sequence;\r
235 \r
236             major_version = EVEL_HEADER_MAJOR_VERSION;\r
237             minor_version = EVEL_HEADER_MINOR_VERSION;\r
238             event_sequence++;\r
239 \r
240             /***************************************************************************/\r
241             /* Optional parameters.                                                    */\r
242             /***************************************************************************/\r
243             event_type = new EvelOptionString(false, null);\r
244             nfcnaming_code = new EvelOptionString(false, null);\r
245             nfnaming_code = new EvelOptionString(false, null);\r
246             reporting_entity_id = new EvelOptionString(true, uuid);\r
247             source_id = new EvelOptionString(true, uuid);\r
248             internal_field = new EvelOptionIntHeader(false, null);\r
249 \r
250             EVEL_EXIT();\r
251           }\r
252 \r
253           \r
254           /**************************************************************************//**\r
255            * Create a new heartbeat event.\r
256            *\r
257            * @note that the heartbeat is just a "naked" commonEventHeader!\r
258            *\r
259            * @returns pointer to the newly manufactured ::EVENT_HEADER.  \r
260            * @retval  null  Failed to create the event.\r
261            ****************************************************************************/\r
262 \r
263 \r
264           public static EvelHeader evel_new_heartbeat()\r
265           {\r
266                 EvelHeader header = null;\r
267             EVEL_ENTER();\r
268             /***************************************************************************/\r
269             /* Initialize the header.  Get a new event sequence number.  Note that if  */\r
270             /* any memory allocation fails in here we will fail gracefully because     */\r
271             /* everything downstream can cope with nulls.                              */\r
272             /***************************************************************************/\r
273             header = new EvelHeader("Heartbeat",null);\r
274             header.event_type.set_option(true);\r
275             header.event_type.SetValue("HEARTBEAT");\r
276             LOGGER.info(header.event_type.value);\r
277 \r
278             EVEL_EXIT();\r
279             return header;\r
280           }\r
281           \r
282           /**************************************************************************//**\r
283            * Create a new heartbeat event.\r
284            *\r
285            * @note that the heartbeat is just a "naked" commonEventHeader!\r
286            *\r
287            * @returns pointer to the newly manufactured ::EVENT_HEADER.  \r
288            * @retval  null  Failed to create the event.\r
289            ****************************************************************************/\r
290 \r
291 \r
292           public static EvelHeader evel_new_heartbeat(String evname,String evid)\r
293           {\r
294                 EvelHeader header = null;\r
295             EVEL_ENTER();\r
296             /***************************************************************************/\r
297             /* Initialize the header.  Get a new event sequence number.  Note that if  */\r
298             /* any memory allocation fails in here we will fail gracefully because     */\r
299             /* everything downstream can cope with nulls.                              */\r
300             /***************************************************************************/\r
301             header = new EvelHeader(evname,evid);\r
302             header.event_type.set_option(true);\r
303             header.event_type.SetValue("HEARTBEAT");;\r
304             LOGGER.info(header.event_type.value);\r
305 \r
306             EVEL_EXIT();\r
307             return header;\r
308           }\r
309 \r
310 \r
311         /**************************************************************************//**\r
312            * Set the Event Type property of the event header.\r
313            *\r
314            * @note  The property is treated as immutable: it is only valid to call\r
315            *        the setter once.  However, we don't assert if the caller tries to\r
316            *        overwrite, just ignoring the update instead.\r
317            *\r
318            * @param header        Pointer to the ::EVENT_HEADER.\r
319            * @param type          The Event Type to be set. ASCIIZ string. The caller\r
320            *                      does not need to preserve the value once the function\r
321            *                      returns.\r
322            *****************************************************************************/\r
323           public void evel_header_type_set(String type)\r
324           {\r
325             EVEL_ENTER();\r
326 \r
327             /***************************************************************************/\r
328             /* Check preconditions.                                                    */\r
329             /***************************************************************************/\r
330             assert(type != null);\r
331 \r
332             event_type.set_option(true);\r
333             event_type.SetValue(type);\r
334 \r
335             EVEL_EXIT();\r
336           }\r
337 \r
338           /**************************************************************************//**\r
339            * Set the Start Epoch property of the event header.\r
340            *\r
341            * @note The Start Epoch defaults to the time of event creation.\r
342            *\r
343            * @param header        Pointer to the ::EVENT_HEADER.\r
344            * @param start_epoch_microsec\r
345            *                      The start epoch to set, in microseconds.\r
346            *****************************************************************************/\r
347           public void evel_start_epoch_set(Long epoch_microsec)\r
348           {\r
349             EVEL_ENTER();\r
350 \r
351             /***************************************************************************/\r
352             /* Check preconditions and assign the new value.                           */\r
353             /***************************************************************************/\r
354             start_epoch_microsec = epoch_microsec;\r
355 \r
356             EVEL_EXIT();\r
357           }\r
358 \r
359           /**************************************************************************//**\r
360            * Set the Last Epoch property of the event header.\r
361            *\r
362            * @note The Last Epoch defaults to the time of event creation.\r
363            *\r
364            * @param header        Pointer to the ::EVENT_HEADER.\r
365            * @param last_epoch_microsec\r
366            *                      The last epoch to set, in microseconds.\r
367            *****************************************************************************/\r
368           public void evel_last_epoch_set(Long epoch_microsec)\r
369           {\r
370             EVEL_ENTER();\r
371 \r
372             /***************************************************************************/\r
373             /* Check preconditions and assign the new value.                           */\r
374             /***************************************************************************/\r
375             last_epoch_microsec = epoch_microsec;\r
376 \r
377             EVEL_EXIT();\r
378           }\r
379 \r
380           /**************************************************************************//**\r
381            * Set the NFC Naming code property of the event header.\r
382            *\r
383            * @param header        Pointer to the ::EVENT_HEADER.\r
384            * @param nfcnamingcode String\r
385            *****************************************************************************/\r
386           public void evel_nfcnamingcode_set(String nfcnam)\r
387           {\r
388             EVEL_ENTER();\r
389 \r
390             /***************************************************************************/\r
391             /* Check preconditions and assign the new value.                           */\r
392             /***************************************************************************/\r
393             assert(nfcnam != null);\r
394             nfcnaming_code.set_option(true);\r
395             nfcnaming_code.SetValue(nfcnam);\r
396         \r
397             EVEL_EXIT();\r
398           }\r
399 \r
400           /**************************************************************************//**\r
401            * Set the NF Naming code property of the event header.\r
402            *\r
403            * @param header        Pointer to the ::EVENT_HEADER.\r
404            * @param nfnamingcode String\r
405            *****************************************************************************/\r
406           public void evel_nfnamingcode_set(String nfnam)\r
407           {\r
408             EVEL_ENTER();\r
409 \r
410             /***************************************************************************/\r
411             /* Check preconditions and assign the new value.                           */\r
412             /***************************************************************************/\r
413             assert(nfnam != null);\r
414             nfnaming_code.set_option(true);\r
415             nfnaming_code.SetValue(nfnam);\r
416 \r
417             EVEL_EXIT();\r
418           }\r
419 \r
420 \r
421           /**************************************************************************//**\r
422            * Set the Reporting Entity Name property of the event header.\r
423            *\r
424            * @note The Reporting Entity Name defaults to the OpenStack VM Name.\r
425            *\r
426            * @param header        Pointer to the ::EVENT_HEADER.\r
427            * @param entity_name   The entity name to set.\r
428            *****************************************************************************/\r
429           public void evel_reporting_entity_name_set(String entity_name)\r
430           {\r
431             EVEL_ENTER();\r
432 \r
433             /***************************************************************************/\r
434             /* Check preconditions and assign the new value.                           */\r
435             /***************************************************************************/\r
436             assert(entity_name != null);\r
437 \r
438             /***************************************************************************/\r
439             /* Free the previously allocated memory and replace it with a copy of the  */\r
440             /* provided one.                                                           */\r
441             /***************************************************************************/\r
442             reporting_entity_name = entity_name;\r
443 \r
444             EVEL_EXIT();\r
445           }\r
446 \r
447           /**************************************************************************//**\r
448            * Set the Reporting Entity Id property of the event header.\r
449            *\r
450            * @note The Reporting Entity Id defaults to the OpenStack VM UUID.\r
451            *\r
452            * @param header        Pointer to the ::EVENT_HEADER.\r
453            * @param entity_id     The entity id to set.\r
454            *****************************************************************************/\r
455           public void evel_reporting_entity_id_set(String entity_id)\r
456           {\r
457             EVEL_ENTER();\r
458 \r
459             /***************************************************************************/\r
460             /* Check preconditions and assign the new value.                           */\r
461             /***************************************************************************/\r
462             assert(entity_id != null);\r
463 \r
464             /***************************************************************************/\r
465             /* Free the previously allocated memory and replace it with a copy of the  */\r
466             /* provided one.  Note that evel_force_option_string strdups entity_id.    */\r
467             /***************************************************************************/\r
468             reporting_entity_id.set_option(true);\r
469             reporting_entity_id.SetValue(entity_id);\r
470 \r
471             EVEL_EXIT();\r
472           }\r
473           \r
474           /**************************************************************************//**\r
475            * Set the Priority property of the event header.\r
476            *\r
477            * @note The Priority of event being reported.\r
478            *\r
479            * @param priorityval    Value of priority.\r
480            * \r
481            *****************************************************************************/\r
482           public void evel_header_set_priority(PRIORITIES priority_val)\r
483           {\r
484             EVEL_ENTER();\r
485             \r
486             assert(EvelHeader.PRIORITIES.EVEL_MAX_PRIORITIES.compareTo(priority_val) < 0 );\r
487             \r
488             priority = priority_val;\r
489 \r
490             EVEL_EXIT();\r
491           }\r
492           \r
493           /**************************************************************************//**\r
494            * Set the Priority property of the event header.\r
495            *\r
496            * @note The Reporting Entity Id defaults to the OpenStack VM UUID.\r
497            *\r
498            * @param val       Optional true or false.\r
499            * @param srcid     The source id to set.\r
500            *****************************************************************************/\r
501           public void evel_header_set_sourceid(boolean val, String srcid)\r
502           {\r
503             EVEL_ENTER();\r
504             \r
505             assert(srcid != null);\r
506             \r
507             source_id.set_option(val);\r
508             \r
509             source_id.SetValue(srcid);\r
510 \r
511             EVEL_EXIT();\r
512           }\r
513           \r
514           /**************************************************************************//**\r
515            * Set the Source name property of the event header.\r
516            *\r
517            * @note Source name should identify the IP address or Source Event originator\r
518            *       for inventory\r
519            *\r
520            * @param srcname  String for sourcename.\r
521            *****************************************************************************/\r
522           public void evel_header_set_source_name(String srcname)\r
523           {\r
524             EVEL_ENTER();\r
525             \r
526             assert(srcname != null);\r
527             \r
528             source_name = srcname;\r
529 \r
530             EVEL_EXIT();\r
531           }\r
532           \r
533           /**************************************************************************//**\r
534            * Map an ::EVEL_EVENT_DOMAINS enum value to the equivalent string.\r
535            *\r
536            * @param domain        The domain to convert.\r
537            * @returns The equivalent string.\r
538            *****************************************************************************/\r
539           String evel_event_domain(DOMAINS domain)\r
540           {\r
541             String result;\r
542 \r
543             EVEL_ENTER();\r
544 \r
545             switch (domain)\r
546             {\r
547               case EVEL_DOMAIN_HEARTBEAT:\r
548                 result = "heartbeat";\r
549                 break;\r
550 \r
551               case EVEL_DOMAIN_FAULT:\r
552                 result = "fault";\r
553                 break;\r
554 \r
555               case EVEL_DOMAIN_MEASUREMENT:\r
556                 result = "measurementsForVfScaling";\r
557                 break;\r
558 \r
559               case EVEL_DOMAIN_REPORT:\r
560                 result = "measurementsForVfReporting";\r
561                 break;\r
562 \r
563               case EVEL_DOMAIN_MOBILE_FLOW:\r
564                 result = "mobileFlow";\r
565                 break;\r
566 \r
567               case EVEL_DOMAIN_HEARTBEAT_FIELD:\r
568                 result = "heartbeat";\r
569                 break;\r
570 \r
571               case EVEL_DOMAIN_SIPSIGNALING:\r
572                 result = "sipSignaling";\r
573                 break;\r
574 \r
575               case EVEL_DOMAIN_STATE_CHANGE:\r
576                 result = "stateChange";\r
577                 break;\r
578 \r
579               case EVEL_DOMAIN_SYSLOG:\r
580                 result = "syslog";\r
581                 break;\r
582 \r
583               case EVEL_DOMAIN_OTHER:\r
584                 result = "other";\r
585                 break;\r
586 \r
587               case EVEL_DOMAIN_VOICE_QUALITY:\r
588                 result = "voiceQuality";\r
589                 break;\r
590 \r
591               case EVEL_DOMAIN_THRESHOLD_CROSSING:\r
592                         result = "thresholdCrossingAlert";\r
593                         break;\r
594                         \r
595               default:\r
596                 result = null;\r
597                 LOGGER.severe(MessageFormat.format("Unexpected domain {0}", domain));\r
598             }\r
599 \r
600             EVEL_EXIT();\r
601 \r
602             return result;\r
603           }\r
604 \r
605           /**************************************************************************//**\r
606            * Map an ::EVEL_EVENT_PRIORITIES enum value to the equivalent string.\r
607            *\r
608            * @param priority      The priority to convert.\r
609            * @returns The equivalent string.\r
610            *****************************************************************************/\r
611           String evel_event_priority(PRIORITIES priority)\r
612           {\r
613             String result;\r
614 \r
615             EVEL_ENTER();\r
616 \r
617             switch (priority)\r
618             {\r
619               case EVEL_PRIORITY_HIGH:\r
620                 result = "High";\r
621                 break;\r
622 \r
623               case EVEL_PRIORITY_MEDIUM:\r
624                 result = "Medium";\r
625                 break;\r
626 \r
627               case EVEL_PRIORITY_NORMAL:\r
628                 result = "Normal";\r
629                 break;\r
630 \r
631               case EVEL_PRIORITY_LOW:\r
632                 result = "Low";\r
633                 break;\r
634 \r
635               default:\r
636                 result = null;\r
637                 LOGGER.severe(MessageFormat.format("Unexpected priority {0}", priority));\r
638             }\r
639 \r
640             EVEL_EXIT();\r
641 \r
642             return result;\r
643           }\r
644           \r
645           /**************************************************************************//**\r
646            * Encode the CommonEventHeaeder as a JSON event object builder\r
647            * according to AT&T's schema.\r
648            *\r
649            * @retval JsonObjectBuilder of fault body portion of message   \r
650            *****************************************************************************/\r
651           JsonObjectBuilder eventHeaderObject()\r
652           {\r
653             String domain = evel_event_domain(event_domain);\r
654             String prity = evel_event_priority(priority);\r
655             double version = major_version+(double)minor_version/10;\r
656             \r
657             EVEL_ENTER();\r
658             \r
659             /***************************************************************************/\r
660             /* Required fields.                                                        */\r
661             /***************************************************************************/\r
662             \r
663             JsonObjectBuilder commheader = Json.createObjectBuilder()\r
664                          .add("domain", domain)\r
665                          .add("eventId", event_id)\r
666                          .add("eventName", event_name)\r
667                          .add("lastEpochMicrosec", last_epoch_microsec)\r
668                          .add("priority", prity)\r
669                          .add("reportingEntityName", reporting_entity_name)\r
670                          .add("sequence", sequence)\r
671                          .add("sourceName", source_name)\r
672                          .add("startEpochMicrosec", start_epoch_microsec)\r
673                          .add("version", version)\r
674                          .add("reportingEntityId", reporting_entity_id.GetValue())\r
675                          .add("sourceId", source_id.GetValue());\r
676             \r
677             /***************************************************************************/\r
678             /* Optional fields.                                                        */\r
679             /***************************************************************************/\r
680             \r
681             if( event_type.is_set )\r
682                 commheader.add("eventType", event_type.GetValue());\r
683             if( source_id.is_set )\r
684                 commheader.add("sourceId", source_id.GetValue());\r
685             if( reporting_entity_id.is_set )\r
686                 commheader.add("reportingEntityId", reporting_entity_id.GetValue());\r
687             \r
688             if( internal_field.is_set )\r
689                 commheader.add("internalField",internal_field.toString());          \r
690             \r
691             if( nfcnaming_code.is_set )\r
692                 commheader.add("nfcNamingCode", nfcnaming_code.GetValue());\r
693             if( nfnaming_code.is_set )\r
694                 commheader.add("nfNamingCode", nfnaming_code.GetValue());\r
695             \r
696             EVEL_EXIT();\r
697             \r
698             return commheader;\r
699 \r
700           }\r
701 \r
702 \r
703           /**************************************************************************//**\r
704            * Encode the event as a JSON event object according to AT&T's schema.\r
705            * retval : String of JSON event header only message\r
706            *****************************************************************************/\r
707           String evel_json_encode_event()\r
708           {\r
709                 \r
710             JsonObject obj = Json.createObjectBuilder()\r
711                      .add("event", Json.createObjectBuilder()\r
712                                  .add( "commonEventHeader",eventHeaderObject() )\r
713                                  ).build();\r
714 \r
715             EVEL_EXIT();\r
716             \r
717             return obj.toString();\r
718 \r
719           }\r
720           \r
721           \r
722 \r
723 }\r