1 package evel_javalibrary.att.com;
\r
3 /**************************************************************************//**
\r
5 * Evel Fault Event class extends EvelHeader class
\r
7 * This file implements the Evel Fault Event class 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 to send Fault events.
\r
13 * Unless otherwise specified, all software contained herein is
\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
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
26 import java.text.MessageFormat;
\r
27 import java.util.ArrayList;
\r
29 import javax.json.Json;
\r
30 import javax.json.JsonArrayBuilder;
\r
31 import javax.json.JsonObject;
\r
32 import javax.json.JsonObjectBuilder;
\r
34 import org.apache.log4j.Logger;
\r
35 import org.slf4j.helpers.MessageFormatter;
\r
38 public class EvelFault extends EvelHeader {
\r
39 //version of EvelFault format revisions
\r
40 int major_version = 2;
\r
41 int minor_version = 1;
\r
43 /**************************************************************************//**
\r
44 * Fault / Threshold severities.
\r
45 * JSON equivalent field: eventSeverity
\r
46 *****************************************************************************/
\r
47 public enum EVEL_SEVERITIES{
\r
48 EVEL_SEVERITY_CRITICAL,
\r
49 EVEL_SEVERITY_MAJOR,
\r
50 EVEL_SEVERITY_MINOR,
\r
51 EVEL_SEVERITY_WARNING,
\r
52 EVEL_SEVERITY_NORMAL,
\r
56 /**************************************************************************//**
\r
57 * Fault source types.
\r
58 * JSON equivalent field: eventSourceType
\r
59 *****************************************************************************/
\r
60 public enum EVEL_SOURCE_TYPES{
\r
67 EVEL_SOURCE_SLOT_THRESHOLD,
\r
68 EVEL_SOURCE_PORT_THRESHOLD,
\r
69 EVEL_SOURCE_VIRTUAL_MACHINE,
\r
70 EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
\r
71 /***************************************************************************/
\r
72 /* START OF VENDOR-SPECIFIC VALUES */
\r
74 /* Vendor-specific values should be added here, and handled appropriately */
\r
75 /* in evel_event.c. */
\r
76 /***************************************************************************/
\r
78 /***************************************************************************/
\r
79 /* END OF VENDOR-SPECIFIC VALUES */
\r
80 /***************************************************************************/
\r
81 EVEL_MAX_SOURCE_TYPES
\r
84 /**************************************************************************//**
\r
86 * JSON equivalent field: vfStatus
\r
87 *****************************************************************************/
\r
88 public enum EVEL_VF_STATUSES{
\r
89 EVEL_VF_STATUS_ACTIVE,
\r
90 EVEL_VF_STATUS_IDLE,
\r
91 EVEL_VF_STATUS_PREP_TERMINATE,
\r
92 EVEL_VF_STATUS_READY_TERMINATE,
\r
93 EVEL_VF_STATUS_REQ_TERMINATE,
\r
94 EVEL_MAX_VF_STATUSES
\r
98 /***************************************************************************/
\r
99 /* Mandatory fields */
\r
100 /***************************************************************************/
\r
101 EVEL_SEVERITIES event_severity;
\r
102 EVEL_SOURCE_TYPES event_source_type;
\r
103 String alarm_condition;
\r
104 String specific_problem;
\r
105 EVEL_VF_STATUSES vf_status;
\r
107 /***************************************************************************/
\r
108 /* Optional fields */
\r
109 /***************************************************************************/
\r
110 EvelOptionString category;
\r
111 EvelOptionString alarm_interface_a;
\r
112 ArrayList<String[]> additional_info;
\r
114 private static final Logger LOGGER = Logger.getLogger( EvelFault.class.getName() );
\r
116 /**************************************************************************//**
\r
117 * Create a new fault event.
\r
119 * @note The mandatory fields on the Fault must be supplied to this factory
\r
120 * function and are immutable once set. Optional fields have explicit
\r
121 * setter functions, but again values may only be set once so that the
\r
122 * Fault has immutable properties.
\r
123 * @param condition The condition indicated by the Fault.
\r
124 * @param specproblem The specific problem triggering the fault.
\r
125 * @param priority The priority of the event.
\r
126 * @param severity The severity of the Fault.
\r
127 * @param ev_source_type Source of Alarm event
\r
128 * @param status status of Virtual Function
\r
129 *****************************************************************************/
\r
130 public EvelFault(String evname, String ev_id,
\r
131 String condition, String specproblem,
\r
132 EvelHeader.PRIORITIES tpriority,
\r
133 EVEL_SEVERITIES severity,
\r
134 EVEL_SOURCE_TYPES ev_source_type,
\r
135 EVEL_VF_STATUSES status)
\r
137 //Initializes Evel Header and Domain
\r
138 super(evname,ev_id);
\r
139 event_domain = EvelHeader.DOMAINS.EVEL_DOMAIN_FAULT;
\r
141 assert( condition != null);
\r
142 assert( specific_problem != null);
\r
143 assert(EvelHeader.PRIORITIES.EVEL_MAX_PRIORITIES.compareTo(tpriority) < 0 );
\r
144 assert(EVEL_SEVERITIES.EVEL_MAX_SEVERITIES.compareTo(severity) < 0 );
\r
145 assert(EVEL_VF_STATUSES.EVEL_MAX_VF_STATUSES.compareTo(status) < 0 );
\r
146 //Init mandatory fields
\r
147 event_severity = severity;
\r
148 event_source_type = ev_source_type;
\r
149 alarm_condition = condition;
\r
150 specific_problem = specproblem;
\r
151 vf_status = status;
\r
152 priority = tpriority;
\r
153 //Init optional fields
\r
154 category = new EvelOptionString(false, null);
\r
155 alarm_interface_a = new EvelOptionString(false, null);
\r
156 additional_info = null;
\r
159 /**************************************************************************//**
\r
160 * Add an additional value name/value pair to the Fault.
\r
162 * The name and value are null delimited ASCII strings. The library takes
\r
163 * a copy so the caller does not have to preserve values after the function
\r
166 * @param fault Pointer to the fault.
\r
167 * @param name ASCIIZ string with the attribute's name. The caller
\r
168 * does not need to preserve the value once the function
\r
170 * @param value ASCIIZ string with the attribute's value. The caller
\r
171 * does not need to preserve the value once the function
\r
173 *****************************************************************************/
\r
174 public void evel_fault_addl_info_add(String name, String value)
\r
176 String[] addl_info = null;
\r
179 /***************************************************************************/
\r
180 /* Check preconditions. */
\r
181 /***************************************************************************/
\r
182 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_FAULT);
\r
183 assert(name != null);
\r
184 assert(value != null);
\r
186 if( additional_info == null )
\r
188 additional_info = new ArrayList<String[]>();
\r
191 LOGGER.debug(MessageFormat.format("Adding name={0} value={1}", name, value));
\r
192 addl_info = new String[2];
\r
193 assert(addl_info != null);
\r
194 addl_info[0] = name;
\r
195 addl_info[1] = value;
\r
197 additional_info.add(addl_info);
\r
202 /**************************************************************************//**
\r
203 * Set the Fault Category property of the Fault.
\r
205 * @note The property is treated as immutable: it is only valid to call
\r
206 * the setter once. However, we don't assert if the caller tries to
\r
207 * overwrite, just ignoring the update instead.
\r
209 * @param fault Pointer to the fault.
\r
210 * @param category Category : license, link, routing, security, signaling.
\r
211 * ASCIIZ string. The caller
\r
212 * does not need to preserve the value once the function
\r
214 *****************************************************************************/
\r
215 public void evel_fault_category_set( String categ)
\r
219 /***************************************************************************/
\r
220 /* Check preconditions. */
\r
221 /***************************************************************************/
\r
222 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_FAULT);
\r
223 assert(categ != null);
\r
225 category.SetValuePr(categ,"Fault Category set");
\r
230 /**************************************************************************//**
\r
231 * Set the Alarm Interface A property of the Fault.
\r
233 * @note The property is treated as immutable: it is only valid to call
\r
234 * the setter once. However, we don't assert if the caller tries to
\r
235 * overwrite, just ignoring the update instead.
\r
237 * @param fault Pointer to the fault.
\r
238 * @param interface The Alarm Interface A to be set. ASCIIZ string. The caller
\r
239 * does not need to preserve the value once the function
\r
241 *****************************************************************************/
\r
242 public void evel_fault_interface_set(String intf)
\r
246 /***************************************************************************/
\r
247 /* Check preconditions. */
\r
248 /***************************************************************************/
\r
249 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_FAULT);
\r
250 assert(intf != null);
\r
252 alarm_interface_a.SetValuePr(intf,"Alarm Interface A");
\r
257 /**************************************************************************//**
\r
258 * Set the Event Type property of the Fault.
\r
260 * @note The property is treated as immutable: it is only valid to call
\r
261 * the setter once. However, we don't assert if the caller tries to
\r
262 * overwrite, just ignoring the update instead.
\r
264 * @param fault Pointer to the fault.
\r
265 * @param type The Event Type to be set. ASCIIZ string. The caller
\r
266 * does not need to preserve the value once the function
\r
268 *****************************************************************************/
\r
269 public void evel_fault_type_set(String type)
\r
273 /***************************************************************************/
\r
274 /* Check preconditions and call evel_header_type_set. */
\r
275 /***************************************************************************/
\r
276 assert(type != null);
\r
277 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_FAULT);
\r
279 evel_header_type_set(type);
\r
285 /**************************************************************************//**
\r
286 * Map an ::EVEL_SOURCE_TYPES enum value to the equivalent string.
\r
288 * @param source_type The source type to convert.
\r
289 * @returns The equivalent string.
\r
290 *****************************************************************************/
\r
291 String evel_source_type(EVEL_SOURCE_TYPES source_type)
\r
297 switch (source_type)
\r
299 case EVEL_SOURCE_OTHER:
\r
303 case EVEL_SOURCE_ROUTER:
\r
307 case EVEL_SOURCE_SWITCH:
\r
311 case EVEL_SOURCE_HOST:
\r
315 case EVEL_SOURCE_CARD:
\r
319 case EVEL_SOURCE_PORT:
\r
323 case EVEL_SOURCE_SLOT_THRESHOLD:
\r
324 result = "slotThreshold";
\r
327 case EVEL_SOURCE_PORT_THRESHOLD:
\r
328 result = "portThreshold";
\r
331 case EVEL_SOURCE_VIRTUAL_MACHINE:
\r
332 result = "virtualMachine";
\r
335 case EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION:
\r
336 result = "virtualNetworkFunction";
\r
341 LOGGER.error(MessageFormatter.format("Unexpected Event Source Type {0}", source_type));
\r
350 /**************************************************************************//**
\r
351 * Map an ::EVEL_SEVERITIES enum value to the equivalent string.
\r
353 * @param severity The severity to convert.
\r
354 * @returns The equivalent string.
\r
355 *****************************************************************************/
\r
356 String evel_severity(EVEL_SEVERITIES severity)
\r
358 String result = null;
\r
364 case EVEL_SEVERITY_CRITICAL:
\r
365 result = "CRITICAL";
\r
368 case EVEL_SEVERITY_MAJOR:
\r
372 case EVEL_SEVERITY_MINOR:
\r
376 case EVEL_SEVERITY_WARNING:
\r
377 result = "WARNING";
\r
380 case EVEL_SEVERITY_NORMAL:
\r
385 LOGGER.error("Unexpected event severity "+severity);
\r
395 /**************************************************************************//**
\r
396 * Map an ::EVEL_VF_STATUSES enum value to the equivalent string.
\r
398 * @param vf_status The vf_status to convert.
\r
399 * @returns The equivalent string.
\r
400 *****************************************************************************/
\r
401 String evel_vf_status(EVEL_VF_STATUSES vf_status)
\r
409 case EVEL_VF_STATUS_ACTIVE:
\r
413 case EVEL_VF_STATUS_IDLE:
\r
417 case EVEL_VF_STATUS_PREP_TERMINATE:
\r
418 result = "Preparing to terminate";
\r
421 case EVEL_VF_STATUS_READY_TERMINATE:
\r
422 result = "Ready to terminate";
\r
425 case EVEL_VF_STATUS_REQ_TERMINATE:
\r
426 result = "Requesting termination";
\r
431 LOGGER.error("Unexpected VF Status "+vf_status);
\r
440 /**************************************************************************//**
\r
441 * Encode the fault in JSON according to AT&T's schema for the fault type.
\r
443 * @retval JsonObjectBuilder of fault body portion of message
\r
444 *****************************************************************************/
\r
445 JsonObjectBuilder evelFaultObject()
\r
447 String fault_severity;
\r
448 String fault_source_type;
\r
449 String fault_vf_status;
\r
450 double version = major_version+(double)minor_version/10;
\r
454 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_FAULT);
\r
456 /***************************************************************************/
\r
457 /* Check preconditions. */
\r
458 /***************************************************************************/
\r
460 fault_severity = evel_severity(event_severity);
\r
461 fault_source_type = evel_source_type(event_source_type);
\r
462 fault_vf_status = evel_vf_status(vf_status);
\r
464 JsonObjectBuilder evelfault = Json.createObjectBuilder()
\r
465 .add("alarmCondition", alarm_condition);
\r
467 /***************************************************************************/
\r
468 /* Optional fields. */
\r
469 /***************************************************************************/
\r
471 if( category.is_set )
\r
472 evelfault.add("eventCategory", category.GetValue());
\r
473 if( alarm_interface_a.is_set )
\r
474 evelfault.add("eventCategory", alarm_interface_a.GetValue());
\r
477 /***************************************************************************/
\r
478 /* Mandatory fields. */
\r
479 /***************************************************************************/
\r
480 evelfault.add( "eventSeverity", fault_severity);
\r
481 evelfault.add( "eventSourceType", fault_source_type);
\r
482 evelfault.add( "specificProblem", specific_problem);
\r
483 evelfault.add( "vfStatus", fault_vf_status);
\r
484 evelfault.add( "faultFieldsVersion", version);
\r
486 /***************************************************************************/
\r
487 /* Encode additional Name value pairs if any. */
\r
488 /***************************************************************************/
\r
489 if( additional_info != null )
\r
491 JsonArrayBuilder builder = Json.createArrayBuilder();
\r
492 for(int i=0;i<additional_info.size();i++) {
\r
493 String[] addl_info = additional_info.get(i);
\r
494 JsonObject obj = Json.createObjectBuilder()
\r
495 .add("name", addl_info[0])
\r
496 .add("value", addl_info[1]).build();
\r
499 evelfault.add("alarmAdditionalInformation", builder);
\r
508 /**************************************************************************//**
\r
509 * Encode the event as a JSON event object according to AT&T's schema.
\r
510 * retval : String of JSON event message
\r
511 *****************************************************************************/
\r
512 String evel_json_encode_event()
\r
514 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_FAULT);
\r
515 //encode common event header and body
\r
516 JsonObject obj = Json.createObjectBuilder()
\r
517 .add("event", Json.createObjectBuilder()
\r
518 .add( "commonEventHeader",eventHeaderObject() )
\r
519 .add( "faultFields",evelFaultObject() )
\r
524 return obj.toString();
\r