A set of fixes and features
Some updates to handle errors in certain scenarios.
Formatted code
Initial work to parse json.
Added code to map certain json values from incoming data into parts of the VES format.
Added lines to map type and severity to VES
Completed support for mapping alarm messages. Also added timing functionality for tracking message send times
Change-Id: Iaf9ce372552fce3f744476719f5fd79548d22ef4
Signed-off-by: William Kurkian <wkurkian@cisco.com>
diff --git a/src/main/java/ves/VesAgent.java b/src/main/java/ves/VesAgent.java
index b0465f7..a9a723d 100644
--- a/src/main/java/ves/VesAgent.java
+++ b/src/main/java/ves/VesAgent.java
@@ -1,18 +1,18 @@
/*
- * Copyright 2018- Cisco
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2018- Cisco
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
package ves;
import evel_javalibrary.att.com.*;
@@ -32,17 +32,24 @@
import org.apache.log4j.Level;
import config.Config;
+import mapper.VesVolthaMapper;
+import mapper.VesVolthaMessage;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.gson.JsonSyntaxException;
public class VesAgent {
- private static final Logger logger = LoggerFactory.getLogger("VesAgent");
+ private static final Logger logger = LoggerFactory.getLogger("VesAgent");
- public static void initVes() {
- logger.info("Initializing VES Agent");
- try {
- AgentMain.evel_initialize("http://"+Config.getVesAddress(),
+ private static VesVolthaMapper mapper;
+
+ public static void initVes() {
+ logger.info("Initializing VES Agent");
+ try {
+ mapper = new VesVolthaMapper();
+ AgentMain.evel_initialize("http://"+Config.getVesAddress(),
Integer.parseInt(Config.getVesPort()),
// "http://1.2.3.4", 8080,
//"/vendor_event_listener","/example_vnf",
@@ -52,31 +59,62 @@
null, null, null,
//"/home/gokul/newwk/demo/vnfs/VES5.0/evel/sslcerts2/my-keystore.jks", "changeit", "changeit",
Level.TRACE);
- } catch( Exception e ) {
- e.printStackTrace();
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
}
- }
- public static boolean sendToVES(String json) {
-
- EvelFault flt = new EvelFault("Fault_VOLTHA_failed", "tbd_event_key_unique_to_source",
- "NIC error", "Hardware failed",
+ public static boolean sendToVES(String json) throws JsonSyntaxException {
+ VesVolthaMessage message = mapper.parseJson(json);
+ String id = message.getId();
+ String ldeviceId = message.getLogicalDeviceId();
+ String ts = message.getRaisedTS();
+ String description = message.getDescription();
+ //Type in Voltha needs to be category in VES
+ String category = message.getType();
+ //Category in VOLTHA needs to be type in VES
+ String type = message.getCategory();
+ String severity = message.getSeverity();
+ String state = message.getState();
+ String resourceId = message.getResourceId();
+
+ EVEL_SEVERITIES vesSeverity = mapSeverity(severity);
+ EVEL_SOURCE_TYPES vesType = mapType(type);
+ EvelFault flt = new EvelFault(
+ "Fault_VOLTHA_" + id,
+ ldeviceId + ":" + ts,
+ id,
+ description,
EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH,
- EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR,
- EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD,
+ vesSeverity,
+ vesType,
EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE);
- flt.evel_fault_addl_info_add("voltha", json);
- //flt.evel_fault_addl_info_add("nicsw", "fail");
- flt.evel_fault_category_set("Communication");
- logger.info("Sending fault event");
- int code = AgentMain.evel_post_event_immediate(flt);
- logger.info("Fault event http code received: " + code);
- if(code == 0 || code >= HttpURLConnection.HTTP_BAD_REQUEST )
- {
- return false;
- } else {
- return true;
- }
- }
+ flt.evel_fault_addl_info_add("voltha", json);
+ flt.evel_fault_addl_info_add("state", state);
+ flt.evel_fault_addl_info_add("resourceId", resourceId);
+ flt.evel_fault_category_set(category);
+ logger.info("Sending fault event");
+ int code = AgentMain.evel_post_event_immediate(flt);
+ logger.info("Fault event http code received: " + code);
+ if(code == 0 || code >= HttpURLConnection.HTTP_BAD_REQUEST ) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ private static EVEL_SEVERITIES mapSeverity(String severity) {
+ String severityUpper = severity.toUpperCase();
+ switch (severityUpper) {
+ case "INDETERMINATE":
+ return EVEL_SEVERITIES.EVEL_SEVERITY_NORMAL;
+ default:
+ return EVEL_SEVERITIES.valueOf("EVEL_SEVERITY_" + severityUpper);
+ }
+ }
+
+ private static EVEL_SOURCE_TYPES mapType(String type) {
+ return EVEL_SOURCE_TYPES.valueOf("EVEL_SOURCE_" + type.toUpperCase());
+ }
}