Replaced vnfsdk ves-aent library

Change-Id: I33b80abe0215eef8818b7bc9004f4de4b4f3aac3
Signed-off-by: William Kurkian <wkurkian@cisco.com>
diff --git a/src/main/java/controller/Application.java b/src/main/java/controller/Application.java
index ce6ef9d..380d716 100644
--- a/src/main/java/controller/Application.java
+++ b/src/main/java/controller/Application.java
@@ -45,7 +45,7 @@
         kafkaAlarms.start();
         KafkaKpisThread kafkaKpis = new KafkaKpisThread();
         kafkaKpis.start();
-        //SpringApplication.run(Application.class, args);
+        SpringApplication.run(Application.class, args);
     }
 
 }
diff --git a/src/main/java/kafka/VolthaKafkaConsumer.java b/src/main/java/kafka/VolthaKafkaConsumer.java
index 11deb81..ba121e6 100644
--- a/src/main/java/kafka/VolthaKafkaConsumer.java
+++ b/src/main/java/kafka/VolthaKafkaConsumer.java
@@ -49,10 +49,12 @@
 
     private KafkaConsumerType type;
 
+    private VesAgent vesAgent;
+
     public VolthaKafkaConsumer(KafkaConsumerType type) {
         logger.debug("VolthaKafkaConsumer constructor called");
-        initVesAgent();
         this.type = type;
+        vesAgent = new VesAgent();
         try {
             consumer = createConsumer();
         } catch (Exception e) {
@@ -62,10 +64,6 @@
         }
     }
 
-    private void initVesAgent() {
-        VesAgent.initVes();
-    }
-
     private KafkaConsumer<Long, String> createConsumer() {
         logger.debug("Creating Kafka Consumer");
 
@@ -124,7 +122,7 @@
                     record.key(), record.value(),
                     record.partition(), record.offset());
                     logger.info("Attempting to send data to VES");
-                    boolean success = VesAgent.sendToVES(type, record.value());
+                    boolean success = vesAgent.sendToVES(type, record.value());
                     if (!success) {
                         throw new HTTPException(0);
                     } else {
diff --git a/src/main/java/ves/EventFault.java b/src/main/java/ves/EventFault.java
new file mode 100644
index 0000000..d054267
--- /dev/null
+++ b/src/main/java/ves/EventFault.java
@@ -0,0 +1,186 @@
+/*

+* 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 java.util.List;

+import java.util.Map;

+import java.util.ArrayList;

+import java.util.HashMap;

+

+public class EventFault implements VesBlock {

+    private List<Map<String, String>> alarmAdditionalInformation;

+    private String alarmCondition;

+    private String eventCategory;

+    private String eventSeverity;

+    private String eventSourceType;

+    private int faultFieldsVersion = 2;

+    private String specificProblem;

+    private String vfStatus;

+

+    public EventFault(String alarmCondition, String eventCategory, String eventSeverity,

+                            String eventSourceType, String specificProblem, String vfStatus) {

+        this.alarmCondition = alarmCondition;

+        this.eventCategory = eventCategory;

+        this.eventSeverity = eventSeverity;

+        this.eventSourceType = eventSourceType;

+        this.specificProblem = specificProblem;

+        this.vfStatus = vfStatus;

+        this.alarmAdditionalInformation = new ArrayList<>();

+    }

+

+    public void addAdditionalValues(String name, String value) {

+        HashMap<String, String> newValue = new HashMap<>();

+        newValue.put("name", name);

+        newValue.put("value", value);

+        this.alarmAdditionalInformation.add(newValue);

+    }

+

+    public String getName() {

+        return "faultFields";

+    }

+

+    public Class getType() {

+        return EventHeader.class;

+    }

+
+	/**
+	* Returns value of alarmAdditionalInformation
+	* @return
+	*/
+	public List<Map<String, String>> getAlarmAdditionalInformation() {
+		return alarmAdditionalInformation;
+	}
+
+	/**
+	* Sets new value of alarmAdditionalInformation
+	* @param
+	*/
+	public void setAlarmAdditionalInformation(List<Map<String, String>> alarmAdditionalInformation) {
+		this.alarmAdditionalInformation = alarmAdditionalInformation;
+	}
+
+	/**
+	* Returns value of alarmCondition
+	* @return
+	*/
+	public String getAlarmCondition() {
+		return alarmCondition;
+	}
+
+	/**
+	* Sets new value of alarmCondition
+	* @param
+	*/
+	public void setAlarmCondition(String alarmCondition) {
+		this.alarmCondition = alarmCondition;
+	}
+
+	/**
+	* Returns value of eventCategory
+	* @return
+	*/
+	public String getEventCategory() {
+		return eventCategory;
+	}
+
+	/**
+	* Sets new value of eventCategory
+	* @param
+	*/
+	public void setEventCategory(String eventCategory) {
+		this.eventCategory = eventCategory;
+	}
+
+	/**
+	* Returns value of eventSeverity
+	* @return
+	*/
+	public String getEventSeverity() {
+		return eventSeverity;
+	}
+
+	/**
+	* Sets new value of eventSeverity
+	* @param
+	*/
+	public void setEventSeverity(String eventSeverity) {
+		this.eventSeverity = eventSeverity;
+	}
+
+	/**
+	* Returns value of eventSourceType
+	* @return
+	*/
+	public String getEventSourceType() {
+		return eventSourceType;
+	}
+
+	/**
+	* Sets new value of eventSourceType
+	* @param
+	*/
+	public void setEventSourceType(String eventSourceType) {
+		this.eventSourceType = eventSourceType;
+	}
+
+	/**
+	* Returns value of faultFieldsVersion
+	* @return
+	*/
+	public int getFaultFieldsVersion() {
+		return faultFieldsVersion;
+	}
+
+	/**
+	* Sets new value of faultFieldsVersion
+	* @param
+	*/
+	public void setFaultFieldsVersion(int faultFieldsVersion) {
+		this.faultFieldsVersion = faultFieldsVersion;
+	}
+
+	/**
+	* Returns value of specificProblem
+	* @return
+	*/
+	public String getSpecificProblem() {
+		return specificProblem;
+	}
+
+	/**
+	* Sets new value of specificProblem
+	* @param
+	*/
+	public void setSpecificProblem(String specificProblem) {
+		this.specificProblem = specificProblem;
+	}
+
+	/**
+	* Returns value of vfStatus
+	* @return
+	*/
+	public String getVfStatus() {
+		return vfStatus;
+	}
+
+	/**
+	* Sets new value of vfStatus
+	* @param
+	*/
+	public void setVfStatus(String vfStatus) {
+		this.vfStatus = vfStatus;
+	}
+}

diff --git a/src/main/java/ves/EventHeader.java b/src/main/java/ves/EventHeader.java
new file mode 100644
index 0000000..8c3a014
--- /dev/null
+++ b/src/main/java/ves/EventHeader.java
@@ -0,0 +1,320 @@
+/*

+* 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 java.util.List;

+import java.util.Map;

+import java.net.InetAddress;

+import java.net.UnknownHostException;

+import java.net.SocketException;

+import java.util.Enumeration;

+import java.net.NetworkInterface;

+import org.slf4j.Logger;

+import org.slf4j.LoggerFactory;

+

+public class EventHeader implements VesBlock {

+    private transient static String hostname = "";

+    private transient static String uuid = "";

+

+    private transient final Logger logger = LoggerFactory.getLogger("EventHeader");

+

+    private String domain;

+    private String eventId;

+    private String eventName;

+    private long lastEpochMicrosec;

+    private String priority;

+    private String reportingEntityId;

+    private String reportingEntityName;

+    private int sequence;

+    private String sourceId;

+    private String sourceName;

+    private long startEpochMicrosec = 0;

+    private int version = 3;

+
+    public EventHeader(String domain, String eventId, String eventName) {
+        this.domain = domain;
+        this.eventId = eventId;
+        this.eventName = eventName;
+        this.priority = "High";
+        this.sequence = 1;
+        //microseconds are not supported in java 8. So just approximating it.
+        this.lastEpochMicrosec = (long)(System.nanoTime()/1000.0);
+
+        setIdAndName();
+    }
+
+    private void setIdAndName() {
+        if (!EventHeader.hostname.equals("") && !EventHeader.uuid.equals("")) {
+            this.reportingEntityId = uuid;
+            this.sourceId = uuid;
+            this.reportingEntityName = hostname;
+            this.sourceName = hostname;
+            return;
+        }
+
+        try {
+            InetAddress addr;
+            addr = InetAddress.getLocalHost();
+            EventHeader.hostname = addr.getHostName();
+        }
+        catch (UnknownHostException ex)
+        {
+            System.out.println("Hostname can not be resolved");
+        }
+
+        try {
+            Enumeration<NetworkInterface> networks =
+                NetworkInterface.getNetworkInterfaces();
+            while(networks.hasMoreElements()) {
+                NetworkInterface network = networks.nextElement();
+                byte[] mac = network.getHardwareAddress();
+
+                if(hostname.equalsIgnoreCase("")) {
+                    Enumeration inetAddrs = network.getInetAddresses();
+                    while(inetAddrs.hasMoreElements()){
+                        InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
+                        if (!inetAddr.isLoopbackAddress()) {
+                            EventHeader.hostname = inetAddr.getHostAddress();
+                            break;
+                        }
+                    }
+                }
+
+                if (mac != null) {
+                    EventHeader.uuid = bytesToHex(mac);
+                }
+            }

+        } catch (SocketException e) {

+            logger.error(e.toString());

+        }
+
+        this.reportingEntityId = uuid;
+        this.sourceId = uuid;
+        this.reportingEntityName = hostname;
+        this.sourceName = hostname;
+    }
+
+    private final transient char[] hexArray = "0123456789ABCDEF".toCharArray();
+    private String bytesToHex(byte[] bytes) {
+        char[] hexChars = new char[bytes.length * 2];
+        for ( int j = 0; j < bytes.length; j++ ) {
+            int v = bytes[j] & 0xFF;
+            hexChars[j * 2] = hexArray[v >>> 4];
+            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
+        }
+        return new String(hexChars);
+    }
+
+    public String getName() {
+        return "commonEventHeader";
+    }
+
+    public Class getType() {
+        return EventHeader.class;
+    }
+
+	/**
+	* Returns value of domain
+	* @return
+	*/
+	public String getDomain() {
+		return domain;
+	}
+
+	/**
+	* Sets new value of domain
+	* @param
+	*/
+	public void setDomain(String domain) {
+		this.domain = domain;
+	}
+
+	/**
+	* Returns value of eventId
+	* @return
+	*/
+	public String getEventId() {
+		return eventId;
+	}
+
+	/**
+	* Sets new value of eventId
+	* @param
+	*/
+	public void setEventId(String eventId) {
+		this.eventId = eventId;
+	}
+
+	/**
+	* Returns value of eventName
+	* @return
+	*/
+	public String getEventName() {
+		return eventName;
+	}
+
+	/**
+	* Sets new value of eventName
+	* @param
+	*/
+	public void setEventName(String eventName) {
+		this.eventName = eventName;
+	}
+
+	/**
+	* Returns value of lastEpochMicrosec
+	* @return
+	*/
+	public long getLastEpochMicrosec() {
+		return lastEpochMicrosec;
+	}
+
+	/**
+	* Sets new value of lastEpochMicrosec
+	* @param
+	*/
+	public void setLastEpochMicrosec(long lastEpochMicrosec) {
+		this.lastEpochMicrosec = lastEpochMicrosec;
+	}
+
+	/**
+	* Returns value of priority
+	* @return
+	*/
+	public String getPriority() {
+		return priority;
+	}
+
+	/**
+	* Sets new value of priority
+	* @param
+	*/
+	public void setPriority(String priority) {
+		this.priority = priority;
+	}
+
+	/**
+	* Returns value of reportingEntityId
+	* @return
+	*/
+	public String getReportingEntityId() {
+		return reportingEntityId;
+	}
+
+	/**
+	* Sets new value of reportingEntityId
+	* @param
+	*/
+	public void setReportingEntityId(String reportingEntityId) {
+		this.reportingEntityId = reportingEntityId;
+	}
+
+	/**
+	* Returns value of reportingEntityName
+	* @return
+	*/
+	public String getReportingEntityName() {
+		return reportingEntityName;
+	}
+
+	/**
+	* Sets new value of reportingEntityName
+	* @param
+	*/
+	public void setReportingEntityName(String reportingEntityName) {
+		this.reportingEntityName = reportingEntityName;
+	}
+
+	/**
+	* Returns value of sequence
+	* @return
+	*/
+	public int getSequence() {
+		return sequence;
+	}
+
+	/**
+	* Sets new value of sequence
+	* @param
+	*/
+	public void setSequence(int sequence) {
+		this.sequence = sequence;
+	}
+
+	/**
+	* Returns value of sourceId
+	* @return
+	*/
+	public String getSourceId() {
+		return sourceId;
+	}
+
+	/**
+	* Sets new value of sourceId
+	* @param
+	*/
+	public void setSourceId(String sourceId) {
+		this.sourceId = sourceId;
+	}
+
+	/**
+	* Returns value of sourceName
+	* @return
+	*/
+	public String getSourceName() {
+		return sourceName;
+	}
+
+	/**
+	* Sets new value of sourceName
+	* @param
+	*/
+	public void setSourceName(String sourceName) {
+		this.sourceName = sourceName;
+	}
+
+	/**
+	* Returns value of startEpochMicrosec
+	* @return
+	*/
+	public long getStartEpochMicrosec() {
+		return startEpochMicrosec;
+	}
+
+	/**
+	* Sets new value of startEpochMicrosec
+	* @param
+	*/
+	public void setStartEpochMicrosec(long startEpochMicrosec) {
+		this.startEpochMicrosec = startEpochMicrosec;
+	}
+
+	/**
+	* Returns value of version
+	* @return
+	*/
+	public int getVersion() {
+		return version;
+	}
+
+	/**
+	* Sets new value of version
+	* @param
+	*/
+	public void setVersion(int version) {
+		this.version = version;
+	}
+}

diff --git a/src/main/java/ves/EventKpi.java b/src/main/java/ves/EventKpi.java
new file mode 100644
index 0000000..5f84a45
--- /dev/null
+++ b/src/main/java/ves/EventKpi.java
@@ -0,0 +1,45 @@
+/*

+* 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 java.util.List;

+import java.util.Map;

+import java.util.ArrayList;

+import java.util.HashMap;

+

+public class EventKpi implements VesBlock {

+    private List<Map<String, String>> nameValuePairs;

+    private int otherFieldsVersion = 1;

+

+    public EventKpi() {

+        nameValuePairs = new ArrayList<>();

+    }

+

+    public void addAdditionalValues(String name, String value) {

+        HashMap<String, String> newValue = new HashMap<>();

+        newValue.put("name", name);

+        newValue.put("value", value);

+        this.nameValuePairs.add(newValue);

+    }

+

+    public String getName() {

+        return "otherFields";

+    }

+

+    public Class getType() {

+        return EventKpi.class;

+    }

+}

diff --git a/src/main/java/ves/VesAgent.java b/src/main/java/ves/VesAgent.java
index 7b6be8e..d043832 100644
--- a/src/main/java/ves/VesAgent.java
+++ b/src/main/java/ves/VesAgent.java
@@ -15,21 +15,8 @@
 */
 package ves;

 

-import evel_javalibrary.att.com.*;

-import evel_javalibrary.att.com.AgentMain.EVEL_ERR_CODES;

-import evel_javalibrary.att.com.EvelFault.EVEL_SEVERITIES;

-import evel_javalibrary.att.com.EvelFault.EVEL_SOURCE_TYPES;

-import evel_javalibrary.att.com.EvelFault.EVEL_VF_STATUSES;

-import evel_javalibrary.att.com.EvelHeader.PRIORITIES;

-import evel_javalibrary.att.com.EvelMobileFlow.MOBILE_GTP_PER_FLOW_METRICS;

-import evel_javalibrary.att.com.EvelScalingMeasurement.MEASUREMENT_CPU_USE;

-import evel_javalibrary.att.com.EvelScalingMeasurement.MEASUREMENT_VNIC_PERFORMANCE;

-import evel_javalibrary.att.com.EvelStateChange.EVEL_ENTITY_STATE;

-import evel_javalibrary.att.com.EvelThresholdCross.EVEL_ALERT_TYPE;

-import evel_javalibrary.att.com.EvelThresholdCross.EVEL_EVENT_ACTION;

 import java.net.HttpURLConnection;

 

-import org.apache.log4j.Level;

 import config.Config;

 

 import mapper.VesVolthaMapper;

@@ -41,31 +28,30 @@
 import org.slf4j.LoggerFactory;

 import com.google.gson.JsonSyntaxException;

 

+import java.util.List;

+import java.util.ArrayList;

+

 public class VesAgent {

 

     private static final Logger logger = LoggerFactory.getLogger("VesAgent");

 

-    private static VesVolthaMapper mapper;

+    private VesVolthaMapper mapper;

 

-    public static void initVes() {

+    private VesDispatcher dispatcher;

+

+    public VesAgent() {

         logger.info("Initializing VES Agent");

         try {

             mapper = new VesVolthaMapper();

-            AgentMain.evel_initialize("http://"+Config.getVesAddress(),

-                Integer.parseInt(Config.getVesPort()),

-                //"/vendor_event_listener","/example_vnf",

-                null,null,

-                "will",

-                "pill",

-                null, null, null,

-                //"/home/gokul/newwk/demo/vnfs/VES5.0/evel/sslcerts2/my-keystore.jks", "changeit", "changeit",

-                Level.TRACE);

-        } catch( Exception e ) {

-            e.printStackTrace();

+            dispatcher = new VesDispatcher("http://"+Config.getVesAddress(),

+                Config.getVesPort());

+        } catch(Exception e) {

+            logger.error("Failed to initialize VES", e);

+            logger.error(e.toString());

         }

     }

 

-    public static boolean sendToVES(KafkaConsumerType type, String json) throws JsonSyntaxException {

+    public boolean sendToVES(KafkaConsumerType type, String json) throws JsonSyntaxException {

         int code = 0;

 

         switch (type) {

@@ -84,7 +70,7 @@
         }

     }

 

-    private static int sendFault(String json) {

+    private int sendFault(String json) {

         VesVolthaAlarm message = mapper.parseAlarm(json);

 

         String id = message.getId();

@@ -101,60 +87,49 @@
         String state = message.getState();

         String resourceId = message.getResourceId();

 

-        EVEL_SEVERITIES vesSeverity = mapSeverity(severity);

-        EVEL_SOURCE_TYPES vesType = getSourceType();

-        EvelFault flt  = new EvelFault(

-            "Fault_VOLTHA_" + eventType,

-            ldeviceId + ":" + ts,

-            id,

-            description,

-            EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH,

-            vesSeverity,

-            vesType,

-            EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE);

-        flt.evel_fault_addl_info_add("voltha", json);

-        flt.evel_fault_addl_info_add("state", state);

-        flt.evel_fault_addl_info_add("co_id", Config.getCoId());

-        flt.evel_fault_addl_info_add("pod_id", Config.getPodId());

-        flt.evel_fault_addl_info_add("type", type);

-        flt.evel_fault_addl_info_add("resourceId", resourceId);

-        flt.evel_fault_category_set(category);

+        EventHeader header = new EventHeader("fault", ldeviceId + ":" + ts,

+                                                "Fault_VOLTHA_" + eventType);

+        EventFault flt  = new EventFault(

+            id, //alarm conidition

+            category, //eventCategory

+            severity, //event severity

+            type, //source type

+            description, //specificProblem

+            "Active" //getVfStatus

+            );

+        flt.addAdditionalValues("voltha", json);

+        flt.addAdditionalValues("state", state);

+        flt.addAdditionalValues("co_id", Config.getCoId());

+        flt.addAdditionalValues("pod_id", Config.getPodId());

+        flt.addAdditionalValues("resourceId", resourceId);

 

         logger.info("Sending fault event");

-        int code = AgentMain.evel_post_event_immediate(flt);

+        List<VesBlock> blocks = new ArrayList<>();

+        blocks.add(header);

+        blocks.add(flt);

+        int code = dispatcher.sendEvent(blocks);

         logger.info("Fault event http code received: " + code);

         return code;

     }

 

-    private static int sendKpi(String json) {

+    private int sendKpi(String json) {

         VesVolthaKpi message = mapper.parseKpi(json);

 

-        EvelOther ev = new EvelOther("measurement_VOLTHA_KPI", "vmname_ip");

-        ev.evel_other_field_add("co_id", Config.getCoId());

-        ev.evel_other_field_add("pod_id", Config.getPodId());

-        ev.evel_other_field_add("type", message.getType());

-        ev.evel_other_field_add("ts", message.getTs());

-        ev.evel_other_field_add("slices", message.getSliceData());

+        EventHeader header = new EventHeader("other", System.currentTimeMillis() + ":" + message.getTs(),

+                                                "other_VOLTHA_KPI");

+        EventKpi ev = new EventKpi();

+        ev.addAdditionalValues("voltha", json);

+        ev.addAdditionalValues("slices", message.getSliceData());

+        ev.addAdditionalValues("co_id", Config.getCoId());

+        ev.addAdditionalValues("pod_id", Config.getPodId());

+        ev.addAdditionalValues("type", message.getType());

+        ev.addAdditionalValues("ts", message.getTs());

 

-        ev.evel_other_field_add("voltha", json);

-

-        logger.info("Sending fault event");

-        int code = AgentMain.evel_post_event_immediate(ev);

-        logger.info("Fault event http code received: " + code);

+        logger.info("Sending KPI event");

+        List<VesBlock> blocks = new ArrayList<>();

+        blocks.add(header);

+        blocks.add(ev);

+        int code = dispatcher.sendEvent(blocks);logger.info("KPI event http code received: " + code);

         return code;

     }

-

-    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 getSourceType() {

-        return EVEL_SOURCE_TYPES.valueOf("EVEL_SOURCE_OLT");

-    }

 }

diff --git a/src/main/java/ves/VesBlock.java b/src/main/java/ves/VesBlock.java
new file mode 100644
index 0000000..8940f26
--- /dev/null
+++ b/src/main/java/ves/VesBlock.java
@@ -0,0 +1,21 @@
+/*

+* 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;

+

+public interface VesBlock {

+    public String getName();

+    public Class getType();

+}

diff --git a/src/main/java/ves/VesDispatcher.java b/src/main/java/ves/VesDispatcher.java
new file mode 100644
index 0000000..a019cde
--- /dev/null
+++ b/src/main/java/ves/VesDispatcher.java
@@ -0,0 +1,91 @@
+/*
+* 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 config.Config;

+import java.util.List;

+import org.slf4j.Logger;

+import org.slf4j.LoggerFactory;

+import com.google.gson.Gson;

+import com.google.gson.GsonBuilder;

+import com.google.gson.JsonObject;

+import com.google.gson.JsonElement;

+import org.apache.http.HttpResponse;

+import org.apache.http.client.methods.HttpPost;

+import org.apache.http.entity.StringEntity;

+import org.apache.http.impl.client.CloseableHttpClient;

+import org.apache.http.impl.client.HttpClients;

+import org.apache.http.client.HttpClient;

+import org.apache.http.client.methods.CloseableHttpResponse;

+import java.io.IOException;

+import java.io.UnsupportedEncodingException;

+

+public class VesDispatcher {

+

+    private static final Logger logger = LoggerFactory.getLogger("VesDispatcher");

+

+    private String url;

+    private String port;

+

+    private Gson gson;

+

+    private CloseableHttpClient httpClient;

+

+    public VesDispatcher(String url, String port) {

+        this.url = url;

+        this.port = port;

+

+        gson = new GsonBuilder().create();

+

+        httpClient = HttpClients.createDefault();

+    }

+

+    public int sendEvent(List<VesBlock> blocks) {

+        JsonObject root = new JsonObject();

+        JsonObject event = new JsonObject();

+        for (VesBlock block : blocks) {

+            JsonElement element = gson.toJsonTree(block);

+            event.add(block.getName(), element);

+        }

+        root.add("event", event);

+        String json = root.toString();

+        System.out.println(json);

+        int code = 0;

+

+        try {

+            HttpPost httpPost = new HttpPost(url + ":" + port+ "/eventListener/v5");

+            StringEntity input = new StringEntity(json);

+            input.setContentType("application/json");

+            httpPost.setEntity(input);

+            CloseableHttpResponse response = httpClient.execute(httpPost);

+

+            try {

+                System.out.println(response.getStatusLine());

+                code = response.getStatusLine().getStatusCode();

+            } finally {

+                response.close();

+            }

+        } catch (UnsupportedEncodingException e) {

+            logger.error("Error during http post", e);

+            logger.error(e.toString());

+        } catch (IOException e) {

+            logger.error("Error during http post", e);

+            logger.error(e.toString());

+        }

+

+        return code;

+    }

+}