diff options
Diffstat (limited to 'veslibrary')
6 files changed, 539 insertions, 484 deletions
diff --git a/veslibrary/ves_javalibrary/evel_javalib2/dependency-reduced-pom.xml b/veslibrary/ves_javalibrary/evel_javalib2/dependency-reduced-pom.xml index aca722a..08e9da1 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/dependency-reduced-pom.xml +++ b/veslibrary/ves_javalibrary/evel_javalib2/dependency-reduced-pom.xml @@ -228,6 +228,7 @@ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<releaseNexusPath>content/repositories/releases/</releaseNexusPath>
<maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
+ <sonar.exclusions>src_test/evel_javalibrary/att/com/maindir/Main.java, src/test/java/*</sonar.exclusions>
<swagger-core.version>1.5.8</swagger-core.version>
<snapshots.path>content/repositories/snapshots/</snapshots.path>
<logback.version>1.2.3</logback.version>
diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/AgentMain.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/AgentMain.java index 23a1b4d..5e21c6c 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/AgentMain.java +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/AgentMain.java @@ -57,221 +57,238 @@ import org.apache.log4j.BasicConfigurator; public class AgentMain { - -/**************************************************************************//** - * Error codes - * - * Error codes for EVEL low level interface - *****************************************************************************/ -public enum EVEL_ERR_CODES { - EVEL_SUCCESS, /** The operation was successful. */ - EVEL_ERR_GEN_FAIL, /** Non-specific failure. */ - EVEL_CURL_LIBRARY_FAIL, /** A cURL library operation failed. */ - EVEL_PTHREAD_LIBRARY_FAIL, /** A Posix threads operation failed. */ - EVEL_OUT_OF_MEMORY, /** A memory allocation failure occurred. */ - EVEL_EVENT_BUFFER_FULL, /** Too many events in the ring-buffer. */ - EVEL_EVENT_HANDLER_INACTIVE, /** Attempt to raise event when inactive. */ - EVEL_NO_METADATA, /** Failed to retrieve OpenStack metadata. */ - EVEL_BAD_METADATA, /** OpenStack metadata invalid format. */ - EVEL_BAD_JSON_FORMAT, /** JSON failed to parse correctly. */ - EVEL_JSON_KEY_NOT_FOUND, /** Failed to find the specified JSON key. */ - EVEL_MAX_ERROR_CODES /** Maximum number of valid error codes. */ -} - - private static final Logger logger = Logger.getLogger(AgentMain.class); - - private static String url = null; - private static URL vesurl = null; - private static URL vesbatchurl = null; - private static HttpURLConnection con = null; - private static String userpass = null; - private static String keystore_pth = null; - private static String jks_passw = null; - private static String key_passw = null; - private static String version = "5"; - - /* RingBuffer to forward messages on sending AgentDispatcher thread */ - private static RingBuffer ringb = new RingBuffer(100); - - Thread thr; - - /* AgentDispatcher loops on messages in RingBuffer and POSTs them - * to external Collector - */ + + /**************************************************************************//** + * Error codes + * + * Error codes for EVEL low level interface + *****************************************************************************/ + public enum EVEL_ERR_CODES { + EVEL_SUCCESS, /** The operation was successful. */ + EVEL_ERR_GEN_FAIL, /** Non-specific failure. */ + EVEL_CURL_LIBRARY_FAIL, /** A cURL library operation failed. */ + EVEL_PTHREAD_LIBRARY_FAIL, /** A Posix threads operation failed. */ + EVEL_OUT_OF_MEMORY, /** A memory allocation failure occurred. */ + EVEL_EVENT_BUFFER_FULL, /** Too many events in the ring-buffer. */ + EVEL_EVENT_HANDLER_INACTIVE, /** Attempt to raise event when inactive. */ + EVEL_NO_METADATA, /** Failed to retrieve OpenStack metadata. */ + EVEL_BAD_METADATA, /** OpenStack metadata invalid format. */ + EVEL_BAD_JSON_FORMAT, /** JSON failed to parse correctly. */ + EVEL_JSON_KEY_NOT_FOUND, /** Failed to find the specified JSON key. */ + EVEL_MAX_ERROR_CODES /** Maximum number of valid error codes. */ + } + + private static final Logger logger = Logger.getLogger(AgentMain.class); + + private static String url = null; + private static URL vesurl = null; + private static URL vesbatchurl = null; + private static HttpURLConnection con = null; + private static String userpass = null; + private static String keystore_pth = null; + private static String jks_passw = null; + private static String key_passw = null; + private static String version = "5"; + + /* RingBuffer to forward messages on sending AgentDispatcher thread */ + private static RingBuffer ringb = new RingBuffer(100); + private static volatile boolean should_stop = false; + + private static Thread thr; + + /* AgentDispatcher loops on messages in RingBuffer and POSTs them + * to external Collector + */ private static class AgentDispatcher implements Runnable { - - private String readStream(InputStream stream) throws Exception { - StringBuilder builder = new StringBuilder(); - try (BufferedReader in = new BufferedReader(new InputStreamReader(stream))) { - String line; - while ((line = in.readLine()) != null) { - builder.append(line); // + "\r\n"(no need, json has no line breaks!) - } - in.close(); - } - logger.error("Resp: " + builder.toString()); - //System.out.println("Resp: " + builder.toString()); - return builder.toString(); - } - - // Create a trust manager that does not validate certificate chains - TrustManager[] trustAllCerts = new TrustManager[] { - new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return new java.security.cert.X509Certificate[0]; - } - public void checkClientTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - public void checkServerTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - } - }; - - public void run() { - - String datatosend=null; - for(;;){ - EvelObject tosend = ringb.take(); - if( tosend != null && ((datatosend = (String) tosend.datastr) != null)) - { - //process data - logger.trace(url + "Got an event size "+datatosend.length()); - logger.trace(datatosend); - - try { - - if( tosend.type == false) - con = (HttpURLConnection) vesurl.openConnection(); - else - con = (HttpURLConnection) vesbatchurl.openConnection(); - - if (con instanceof HttpsURLConnection) { - HttpsURLConnection httpsConnection = (HttpsURLConnection) con; - - try { - - SSLContext sc = SSLContext.getInstance("TLSv1.2"); - /* Get the JKS contents */ - if( !keystore_pth.isEmpty() && !jks_passw.isEmpty() && !key_passw.isEmpty() ) - { - final KeyStore keyStore = KeyStore.getInstance("JKS"); - try (final InputStream is = new FileInputStream(keystore_pth)) { - keyStore.load(is, jks_passw.toCharArray()); - } - final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory - .getDefaultAlgorithm()); - kmf.init(keyStore, key_passw.toCharArray()); - final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory - .getDefaultAlgorithm()); - tmf.init(keyStore); - sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new java.security.SecureRandom()); - } - else - { - // Init the SSLContext with a TrustManager[] and SecureRandom() - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - } + + private String readStream(InputStream stream) throws Exception { + StringBuilder builder = new StringBuilder(); + try (BufferedReader in = new BufferedReader(new InputStreamReader(stream))) { + String line; + while ((line = in.readLine()) != null) { + builder.append(line); // + "\r\n"(no need, json has no line breaks!) + } + in.close(); + } + logger.error("Resp: " + builder.toString()); + //System.out.println("Resp: " + builder.toString()); + return builder.toString(); + } + + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[] { + new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return new java.security.cert.X509Certificate[0]; + } + public void checkClientTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + public void checkServerTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + } + }; + + private void send_object(EvelObject tosend){ + String datatosend = (String) tosend.datastr; + //process data + logger.trace(url + "Got an event size "+datatosend.length()); + logger.trace(datatosend); + + try { + + if( tosend.type == false) + con = (HttpURLConnection) vesurl.openConnection(); + else + con = (HttpURLConnection) vesbatchurl.openConnection(); + + if (con instanceof HttpsURLConnection) { + HttpsURLConnection httpsConnection = (HttpsURLConnection) con; + + try { + + SSLContext sc = SSLContext.getInstance("TLSv1.2"); + /* Get the JKS contents */ + if( !keystore_pth.isEmpty() && !jks_passw.isEmpty() && !key_passw.isEmpty() ) + { + final KeyStore keyStore = KeyStore.getInstance("JKS"); + try (final InputStream is = new FileInputStream(keystore_pth)) { + keyStore.load(is, jks_passw.toCharArray()); + } + final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory + .getDefaultAlgorithm()); + kmf.init(keyStore, key_passw.toCharArray()); + final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory + .getDefaultAlgorithm()); + tmf.init(keyStore); + sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new java.security.SecureRandom()); + } + else + { + // Init the SSLContext with a TrustManager[] and SecureRandom() + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + } httpsConnection.setDefaultHostnameVerifier(new HostnameVerifier() + { + public boolean verify(String hostname, SSLSession session) { - public boolean verify(String hostname, SSLSession session) - { - return true; - } + return true; + } }); - httpsConnection.setSSLSocketFactory(sc.getSocketFactory()); - con = httpsConnection; - - } - catch (final Exception exc) { - exc.printStackTrace(); - logger.error("SSL/TLS connection error"); - } - } - - //add reuqest header - con.setRequestMethod("POST"); - // No caching, we want the real thing. - con.setUseCaches (false); - // Specify the content type. - con.setRequestProperty("Content-Type", "application/json"); - con.setInstanceFollowRedirects( false ); - //Basic username password authentication - String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes("UTF-8")); - con.setRequestProperty ("Authorization", basicAuth); - - con.setReadTimeout(15000 /* milliseconds */); - con.setConnectTimeout(15000 /* milliseconds */); - // Send post request - con.setDoOutput(true); - con.setDoInput(true); - - con.setFixedLengthStreamingMode(datatosend.length()); - OutputStream os = con.getOutputStream(); - BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(os, "UTF-8")); - //Call writer POST - writer.write(datatosend); - writer.flush(); - writer.close(); - os.close(); - //Handle the response code for POST request - int respCode = con.getResponseCode(); - logger.trace(url + "Connection HTTP Response code :"+respCode); - if(respCode < HttpURLConnection.HTTP_OK ) { - logger.trace(url + " **INFO**"); - } - else if(respCode >= HttpURLConnection.HTTP_OK && respCode < HttpURLConnection.HTTP_MULT_CHOICE ) - { + httpsConnection.setSSLSocketFactory(sc.getSocketFactory()); + con = httpsConnection; + + } + catch (final Exception exc) { + exc.printStackTrace(); + logger.error("SSL/TLS connection error"); + } + } + + //add reuqest header + con.setRequestMethod("POST"); + // No caching, we want the real thing. + con.setUseCaches (false); + // Specify the content type. + con.setRequestProperty("Content-Type", "application/json"); + con.setInstanceFollowRedirects( false ); + //Basic username password authentication + String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes("UTF-8")); + con.setRequestProperty ("Authorization", basicAuth); + + con.setReadTimeout(15000 /* milliseconds */); + con.setConnectTimeout(15000 /* milliseconds */); + // Send post request + con.setDoOutput(true); + con.setDoInput(true); + + con.setFixedLengthStreamingMode(datatosend.length()); + OutputStream os = con.getOutputStream(); + BufferedWriter writer = new BufferedWriter( + new OutputStreamWriter(os, "UTF-8")); + //Call writer POST + writer.write(datatosend); + writer.flush(); + writer.close(); + os.close(); + //Handle the response code for POST request + int respCode = con.getResponseCode(); + logger.trace(url + "Connection HTTP Response code :"+respCode); + if(respCode < HttpURLConnection.HTTP_OK ) { + logger.trace(url + " **INFO**"); + } + else if(respCode >= HttpURLConnection.HTTP_OK && respCode < HttpURLConnection.HTTP_MULT_CHOICE ) + { logger.trace(url + " **OK**"); - } - else if(respCode >= HttpURLConnection.HTTP_MULT_CHOICE && respCode < HttpURLConnection.HTTP_BAD_REQUEST ) - { - logger.warn(url + " **REDIRECTION**"); - } - else if(respCode >= HttpURLConnection.HTTP_BAD_REQUEST ) - { - logger.warn(url + " **SERVER ERROR**"); + } + else if(respCode >= HttpURLConnection.HTTP_MULT_CHOICE && respCode < HttpURLConnection.HTTP_BAD_REQUEST ) + { + logger.warn(url + " **REDIRECTION**"); + } + else if(respCode >= HttpURLConnection.HTTP_BAD_REQUEST ) + { + logger.warn(url + " **SERVER ERROR**"); InputStream es = con.getErrorStream(); readStream(es); - } - - - } catch (IOException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - - } - else - { - logger.trace(url + "Waiting for events"); - try { - Thread.sleep(5); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - logger.trace("Interrupted on "+url); - System.out.println("Interrupted on "+url); - //e.printStackTrace(); - } - } - }//end for - }//end run - }//end AgentDispatcher + } + + + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void run() { + + String datatosend=null; + while (!should_stop){ + EvelObject tosend = ringb.take(); + if( tosend != null && ((datatosend = (String) tosend.datastr) != null)) + { + send_object(tosend); + } + else + { + logger.trace(url + "Waiting for events"); + try { + Thread.sleep(5); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.trace("Interrupted on "+url); + System.out.println("Interrupted on "+url); + //e.printStackTrace(); + } + } + }//end while + + logger.trace("Caught stop event, emptying buffer before exiting"); + + while (!ringb.isEmpty()){ + EvelObject tosend = ringb.take(); + if( tosend != null && ((datatosend = (String) tosend.datastr) != null)) + { + send_object(tosend); + } + } + logger.trace("Send buffer is empty, shutting down"); + }//end run + }//end AgentDispatcher + // Validate URL public static boolean isValidURL(String urlStr) { try { - URL url = new URL(urlStr); - return true; + URL url = new URL(urlStr); + return true; } catch (MalformedURLException e) { return false; } } - + /**************************************************************************//** * Library initialization. * @@ -293,8 +310,8 @@ public enum EVEL_ERR_CODES { * @retval ::EVEL_ERR_CODES On failure. *****************************************************************************/ public static EVEL_ERR_CODES evel_initialize( - String event_api_url, - int port, + String event_api_url, + int port, String path, String topic, String username, @@ -304,67 +321,76 @@ public enum EVEL_ERR_CODES { String key_password, Level level) throws IOException { - EVEL_ERR_CODES rc = EVEL_ERR_CODES.EVEL_SUCCESS; - - EVEL_ENTER(); - - BasicConfigurator.configure(); - - /***************************************************************************/ - /* Check assumptions. */ - /***************************************************************************/ - assert(event_api_url != null); - assert(port > 1024); - assert(username != null); - - logger.setLevel(level); - - if( !isValidURL(event_api_url) ){ - System.out.println("Invalid Event API URL"); - logger.error("Invalid Event API URL"); - rc = EVEL_ERR_CODES.EVEL_ERR_GEN_FAIL; - System.exit(1); - } - - if(path == null){ - path = ""; - } else { - version += "/example_vnf"; - } - - keystore_pth = keystore_path; - jks_passw = jks_password; - key_passw = key_password; - - url = event_api_url+":"+Integer.toString(port)+path+"/eventListener/v"+version; - vesurl = null; - try { - vesurl = new URL(url); - vesbatchurl = new URL(url+"/eventBatch"); - } catch (MalformedURLException e) { - logger.info("Error in url input"); - e.printStackTrace(); - System.exit(1); - } - userpass = username + ":" + password; + EVEL_ERR_CODES rc = EVEL_ERR_CODES.EVEL_SUCCESS; + + EVEL_ENTER(); + + BasicConfigurator.configure(); + + /***************************************************************************/ + /* Check assumptions. */ + /***************************************************************************/ + assert(event_api_url != null); + assert(port > 1024); + assert(username != null); + + logger.setLevel(level); + + if( !isValidURL(event_api_url) ){ + System.out.println("Invalid Event API URL"); + logger.error("Invalid Event API URL"); + rc = EVEL_ERR_CODES.EVEL_ERR_GEN_FAIL; + System.exit(1); + } + + if(path == null){ + path = ""; + } else { + version += "/example_vnf"; + } + + keystore_pth = keystore_path; + jks_passw = jks_password; + key_passw = key_password; + + url = event_api_url+":"+Integer.toString(port)+path+"/eventListener/v"+version; + vesurl = null; + try { + vesurl = new URL(url); + vesbatchurl = new URL(url+"/eventBatch"); + } catch (MalformedURLException e) { + logger.info("Error in url input"); + e.printStackTrace(); + System.exit(1); + } + userpass = username + ":" + password; logger.info("Starting Agent Dispatcher thread"); - Thread t = new Thread(new AgentDispatcher()); - t.start(); - + thr = new Thread(new AgentDispatcher()); + thr.start(); + EVEL_EXIT(); - return rc; - + return rc; + + } + + public static void evel_shutdown() { + if(should_stop){ + logger.warn("evel_shutdown was called whilst the agent was already stopping - this has no effect"); + } + should_stop = true; + logger.debug("Called evel_shutdown, will shutdown when the buffer is empty"); + } + + + private static void EVEL_EXIT() { + logger.trace("Exit VES Agent Main"); + } + + private static void EVEL_ENTER() { + logger.trace("Enter VES Agent Main"); } - - private static void EVEL_EXIT() { - logger.trace("Exit VES Agent Main"); - } - - private static void EVEL_ENTER() { - logger.trace("Enter VES Agent Main"); - } - + /**************************************************************************//** * Handle user formatted post message * @@ -377,16 +403,20 @@ public enum EVEL_ERR_CODES { * @retval boolean True On successful acceptance False on failure *****************************************************************************/ - public static boolean evel_post_event(EvelHeader obj) + public static boolean evel_post_event(EvelHeader obj) { - String data = obj.evel_json_encode_event().toString(); - EvelObject myobj = new EvelObject(data,false); - boolean ret = ringb.put(myobj); - logger.info("Evel Post event ret:"+ret); - return ret; + if (should_stop){ + logger.error("evel_post_event called whilst agent is shutting down - event will not be posted"); + return false; + } + String data = obj.evel_json_encode_event().toString(); + EvelObject myobj = new EvelObject(data,false); + boolean ret = ringb.put(myobj); + logger.info("Evel Post event ret:"+ret); + return ret; } - + /**************************************************************************//** * Handle user formatted post message * @@ -399,14 +429,16 @@ public enum EVEL_ERR_CODES { * @retval boolean True On successful acceptance False on failure *****************************************************************************/ - public static boolean evel_post_event(EvelBatch obj) + public static boolean evel_post_event(EvelBatch obj) { - String data = obj.evel_json_encode_event().toString(); - EvelObject myobj = new EvelObject(data,true); - boolean ret = ringb.put(myobj); - logger.info("Evel Post batch event ret:"+ret); - return ret; + if (should_stop){ + logger.error("evel_post_event called whilst agent is shutting down - event will not be posted"); + return false; + } + String data = obj.evel_json_encode_event().toString(); + EvelObject myobj = new EvelObject(data,true); + boolean ret = ringb.put(myobj); + logger.info("Evel Post batch event ret:"+ret); + return ret; } - - } diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/EvelScalingMeasurement.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/EvelScalingMeasurement.java index 1312eed..6c39d13 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/EvelScalingMeasurement.java +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/EvelScalingMeasurement.java @@ -2088,6 +2088,8 @@ public class EvelScalingMeasurement extends EvelHeader { {
EVEL_ENTER();
+ LOGGER.warn("Called evel_measurement_vnfc_scaling_metric_set with 2 arguments. The first argument is unused and callers should use the single-parameter version instead");
+
/***************************************************************************/
/* Check preconditions. */
/***************************************************************************/
@@ -2101,6 +2103,22 @@ public class EvelScalingMeasurement extends EvelHeader { EVEL_EXIT();
}
+ public void evel_measurement_vnfc_scaling_metric_set(int scaling_metric)
+ {
+ EVEL_ENTER();
+
+ /***************************************************************************/
+ /* Check preconditions. */
+ /***************************************************************************/
+ assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_MEASUREMENT);
+ assert(scaling_metric >= 0.0);
+
+ vnfc_scaling_metric.SetValuePr(
+ scaling_metric,
+ "VNFC Scaling Metric");
+ EVEL_EXIT();
+ }
+
/**************************************************************************//**
* Create a new Latency Bucket to be added to a Measurement event.
*
diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/RingBuffer.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/RingBuffer.java index 460e84a..872160f 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/RingBuffer.java +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/RingBuffer.java @@ -57,6 +57,10 @@ public class RingBuffer { this.available = 0;
}
+ public boolean isEmpty() {
+ return this.remainingCapacity() == this.capacity;
+ }
+
//returns available capacity
public int remainingCapacity() {
return this.capacity - this.available;
diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src_test/evel_javalibrary/att/com/maindir/Main.java b/veslibrary/ves_javalibrary/evel_javalib2/src_test/evel_javalibrary/att/com/maindir/Main.java index e49e003..5ec01fd 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/src_test/evel_javalibrary/att/com/maindir/Main.java +++ b/veslibrary/ves_javalibrary/evel_javalib2/src_test/evel_javalibrary/att/com/maindir/Main.java @@ -51,222 +51,222 @@ import java.util.Date; public class Main { - public static void main(String[] args) - { + public static void main(String[] args) + { + + try{ - try{ - - AgentMain.evel_initialize("http://127.0.0.1", 30000, - // "http://1.2.3.4", 8080, - //"/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(); - } + AgentMain.evel_initialize("http://127.0.0.1", 30000, + // "http://1.2.3.4", 8080, + //"/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(); + } for(int i= 0; i < 2; i++) { - EvelHeader header = EvelHeader.evel_new_heartbeat("Hearbeat_vAFX","vmname_ip"); - header.evel_nfnamingcode_set("vVNF"); - header.evel_nfcnamingcode_set("vVNF"); - AgentMain.evel_post_event(header); - try { + EvelHeader header = EvelHeader.evel_new_heartbeat("Hearbeat_vAFX","vmname_ip"); + header.evel_nfnamingcode_set("vVNF"); + header.evel_nfcnamingcode_set("vVNF"); + AgentMain.evel_post_event(header); + try { Thread.sleep(1); - } catch( Exception e ) - { - e.printStackTrace(); - } - - EvelFault flt = new EvelFault("Fault_vVNF", "vmname_ip", - "NIC error", "Hardware failed", - EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH, - EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, - EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD, - EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE); - flt.evel_fault_addl_info_add("nichw", "fail"); - flt.evel_fault_addl_info_add("nicsw", "fail"); - AgentMain.evel_post_event(flt); - - EvelBatch be = new EvelBatch(); - EvelFault flt2 = new EvelFault("Fault_vVNF", "vmname_ip", - "NIC error", "Hardware failed", - EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH, - EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, - EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD, - EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE); - flt2.evel_fault_addl_info_add("nichw", "fail"); - flt2.evel_fault_addl_info_add("nicsw", "fail"); - be.addEvent(flt2); - - EvelFault flt3 = new EvelFault("Fault_vVNF", "vmname_ip2", - "NIC error", "Hardware failed", - EvelHeader.PRIORITIES.EVEL_PRIORITY_NORMAL, - EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, - EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD, - EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE); - flt3.evel_fault_type_set("Interface fault"); - flt3.evel_fault_category_set("Failed category"); - flt3.evel_fault_interface_set("An Interface Card"); - flt3.evel_fault_addl_info_add("nichw", "fail"); - flt3.evel_fault_addl_info_add("nicsw", "fail"); - be.addEvent(flt3); - - - EvelStateChange stc = new EvelStateChange("StateChange_vVNF", "vmname_ip", - EvelStateChange.EVEL_ENTITY_STATE.EVEL_ENTITY_STATE_IN_SERVICE, - EvelStateChange.EVEL_ENTITY_STATE.EVEL_ENTITY_STATE_OUT_OF_SERVICE,"bgp"); - stc.evel_statechange_addl_info_add("bgpa", "fail"); - stc.evel_statechange_addl_info_add("bgpb", "fail"); - //AgentMain.evel_post_event(stc); - - be.addEvent(stc); - AgentMain.evel_post_event(be); - - EvelScalingMeasurement sm = new EvelScalingMeasurement(10.0,"Measurements_vVNF", "vmname_ip"); - sm.evel_measurement_myerrors_set(10,20,30,40); - MEASUREMENT_CPU_USE my1 = sm.evel_measurement_new_cpu_use_add("cpu1", 100.0); - my1.idle.SetValue(20.0); - my1.sys.SetValue(21.0); - MEASUREMENT_CPU_USE my2 = sm.evel_measurement_new_cpu_use_add("cpu2", 10.0); - my2.steal.SetValue(34.0); - my2.user.SetValue(32.0); - sm.evel_measurement_custom_measurement_add("group1","name1","val1"); - sm.evel_measurement_custom_measurement_add("group1","name2","val2"); - sm.evel_measurement_custom_measurement_add("group2","name1","val1"); - sm.evel_measurement_custom_measurement_add("group2","name2","val2"); - - - MEASUREMENT_VNIC_PERFORMANCE vnic_p = sm.evel_measurement_new_vnic_performance("vnic1","true"); - vnic_p.recvd_bcast_packets_acc.SetValue(2400000.0); - vnic_p.recvd_mcast_packets_delta.SetValue(5677888.0); - vnic_p.recvd_mcast_packets_acc.SetValue(5677888.0); - vnic_p.tx_ucast_packets_acc.SetValue(547856576.0); - vnic_p.tx_ucast_packets_delta.SetValue(540000.0); - sm.evel_meas_vnic_performance_add(vnic_p); - - AgentMain.evel_post_event(sm); - - EvelSyslog sysl = new EvelSyslog("Syslog_vVNF", "vmname_ip", - EvelFault.EVEL_SOURCE_TYPES.EVEL_SOURCE_ROUTER, - "Router failed","JUNIPER"); - sysl.evel_syslog_proc_id_set(456); - sysl.evel_syslog_proc_set("routed"); - AgentMain.evel_post_event(sysl); - - EvelHeartbeatField hfld = new EvelHeartbeatField(123,"HeartbeatField_vVNF", "vmname_ip"); - hfld.evel_hrtbt_interval_set(23); - AgentMain.evel_post_event(hfld); - - - EvelSipSignaling sip = new EvelSipSignaling("SipSignaling_vVNF", "vmname_ip","aricent","corlator","127.0.0.1","5647","10.1.1.124","5678"); - AgentMain.evel_post_event(sip); - - EvelVoiceQuality vq = new EvelVoiceQuality("VoiceQuality_vVNF", "vmname_ip", - "calleeSideCodc", - "callerSideCodc", "corlator", - "midCllRtcp", "juniper"); - vq.evel_voice_quality_end_metrics_set("adjname", "Caller", 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 15.1, 160.12, 170, 180, 190); - AgentMain.evel_post_event(vq); - - EvelOther ev = new EvelOther("MyCustomEvent_vVNF", "vmname_ip"); - ev.evel_other_field_add("a1", "b1"); - ev.evel_other_field_add("a1", "b2"); - - ev.evel_other_field_add_namedarray("a1", "b1", "c1"); - ev.evel_other_field_add_namedarray("a1", "b2", "c2"); - ev.evel_other_field_add_namedarray("a2", "b1", "c1"); - ev.evel_other_field_add_namedarray("a2", "b1", "c1"); - AgentMain.evel_post_event(ev); - - String dateStart = "01/14/2012 09:29:58"; - String dateStop = "01/15/2012 10:31:48"; - - //HH converts hour in 24 hours format (0-23), day calculation - SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); - - Date d1 = null; - Date d2 = null; - - try { - d1 = format.parse(dateStart); - d2 = format.parse(dateStop); - }catch (Exception e) { - e.printStackTrace(); - } - - - EvelThresholdCross tca = new EvelThresholdCross("ThresholdCross_vVNF", "vmname_ip", - "CRIT", - "mcast Limit reached", - "mcastRxPackets", - "1250000000", - EvelThresholdCross.EVEL_EVENT_ACTION.EVEL_EVENT_ACTION_SET, - "Mcast Rx breached", - EvelThresholdCross.EVEL_ALERT_TYPE.EVEL_ELEMENT_ANOMALY, - d1, - EvelThresholdCross.EVEL_SEVERITIES.EVEL_SEVERITY_CRITICAL, - d2); - tca.evel_threshold_cross_interfacename_set("ns345"); - tca.evel_thresholdcross_addl_info_add("n1", "v1"); - tca.evel_thresholdcross_addl_info_add("n2", "v2"); - tca.evel_thresholdcross_alertid_add("alert1"); - tca.evel_thresholdcross_alertid_add("alert2"); - - AgentMain.evel_post_event(tca); - - - EvelMobileFlow mf = new EvelMobileFlow("MobileFlow_vVNF", "vmname_ip", - "In", - null, - "GTP", - "v2.3", - "1.2.3.4", - 345556, - "5.6.7.8", - 334344); - MOBILE_GTP_PER_FLOW_METRICS mygtp = mf.new MOBILE_GTP_PER_FLOW_METRICS( - 1.01, - 2.02, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - d1, - "ACTIVE", - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28); - mf.gtp_per_flow_metrics = mygtp; - AgentMain.evel_post_event(mf); + } catch( Exception e ) + { + e.printStackTrace(); + } + EvelFault flt = new EvelFault("Fault_vVNF", "vmname_ip", + "NIC error", "Hardware failed", + EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH, + EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, + EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD, + EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE); + flt.evel_fault_addl_info_add("nichw", "fail"); + flt.evel_fault_addl_info_add("nicsw", "fail"); + AgentMain.evel_post_event(flt); + + EvelBatch be = new EvelBatch(); + EvelFault flt2 = new EvelFault("Fault_vVNF", "vmname_ip", + "NIC error", "Hardware failed", + EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH, + EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, + EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD, + EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE); + flt2.evel_fault_addl_info_add("nichw", "fail"); + flt2.evel_fault_addl_info_add("nicsw", "fail"); + be.addEvent(flt2); + + EvelFault flt3 = new EvelFault("Fault_vVNF", "vmname_ip2", + "NIC error", "Hardware failed", + EvelHeader.PRIORITIES.EVEL_PRIORITY_NORMAL, + EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, + EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD, + EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE); + flt3.evel_fault_type_set("Interface fault"); + flt3.evel_fault_category_set("Failed category"); + flt3.evel_fault_interface_set("An Interface Card"); + flt3.evel_fault_addl_info_add("nichw", "fail"); + flt3.evel_fault_addl_info_add("nicsw", "fail"); + be.addEvent(flt3); + + + EvelStateChange stc = new EvelStateChange("StateChange_vVNF", "vmname_ip", + EvelStateChange.EVEL_ENTITY_STATE.EVEL_ENTITY_STATE_IN_SERVICE, + EvelStateChange.EVEL_ENTITY_STATE.EVEL_ENTITY_STATE_OUT_OF_SERVICE,"bgp"); + stc.evel_statechange_addl_info_add("bgpa", "fail"); + stc.evel_statechange_addl_info_add("bgpb", "fail"); + //AgentMain.evel_post_event(stc); + + be.addEvent(stc); + AgentMain.evel_post_event(be); + + EvelScalingMeasurement sm = new EvelScalingMeasurement(10.0,"Measurements_vVNF", "vmname_ip"); + sm.evel_measurement_myerrors_set(10,20,30,40); + MEASUREMENT_CPU_USE my1 = sm.evel_measurement_new_cpu_use_add("cpu1", 100.0); + my1.idle.SetValue(20.0); + my1.sys.SetValue(21.0); + MEASUREMENT_CPU_USE my2 = sm.evel_measurement_new_cpu_use_add("cpu2", 10.0); + my2.steal.SetValue(34.0); + my2.user.SetValue(32.0); + sm.evel_measurement_custom_measurement_add("group1","name1","val1"); + sm.evel_measurement_custom_measurement_add("group1","name2","val2"); + sm.evel_measurement_custom_measurement_add("group2","name1","val1"); + sm.evel_measurement_custom_measurement_add("group2","name2","val2"); + + + MEASUREMENT_VNIC_PERFORMANCE vnic_p = sm.evel_measurement_new_vnic_performance("vnic1","true"); + vnic_p.recvd_bcast_packets_acc.SetValue(2400000.0); + vnic_p.recvd_mcast_packets_delta.SetValue(5677888.0); + vnic_p.recvd_mcast_packets_acc.SetValue(5677888.0); + vnic_p.tx_ucast_packets_acc.SetValue(547856576.0); + vnic_p.tx_ucast_packets_delta.SetValue(540000.0); + sm.evel_meas_vnic_performance_add(vnic_p); + + AgentMain.evel_post_event(sm); + + EvelSyslog sysl = new EvelSyslog("Syslog_vVNF", "vmname_ip", + EvelFault.EVEL_SOURCE_TYPES.EVEL_SOURCE_ROUTER, + "Router failed","JUNIPER"); + sysl.evel_syslog_proc_id_set(456); + sysl.evel_syslog_proc_set("routed"); + AgentMain.evel_post_event(sysl); + + EvelHeartbeatField hfld = new EvelHeartbeatField(123,"HeartbeatField_vVNF", "vmname_ip"); + hfld.evel_hrtbt_interval_set(23); + AgentMain.evel_post_event(hfld); - } - } + EvelSipSignaling sip = new EvelSipSignaling("SipSignaling_vVNF", "vmname_ip","aricent","corlator","127.0.0.1","5647","10.1.1.124","5678"); + AgentMain.evel_post_event(sip); + + EvelVoiceQuality vq = new EvelVoiceQuality("VoiceQuality_vVNF", "vmname_ip", + "calleeSideCodc", + "callerSideCodc", "corlator", + "midCllRtcp", "juniper"); + vq.evel_voice_quality_end_metrics_set("adjname", "Caller", 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 15.1, 160.12, 170, 180, 190); + AgentMain.evel_post_event(vq); + + EvelOther ev = new EvelOther("MyCustomEvent_vVNF", "vmname_ip"); + ev.evel_other_field_add("a1", "b1"); + ev.evel_other_field_add("a1", "b2"); + + ev.evel_other_field_add_namedarray("a1", "b1", "c1"); + ev.evel_other_field_add_namedarray("a1", "b2", "c2"); + ev.evel_other_field_add_namedarray("a2", "b1", "c1"); + ev.evel_other_field_add_namedarray("a2", "b1", "c1"); + AgentMain.evel_post_event(ev); + + String dateStart = "01/14/2012 09:29:58"; + String dateStop = "01/15/2012 10:31:48"; + + //HH converts hour in 24 hours format (0-23), day calculation + SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); + + Date d1 = null; + Date d2 = null; + + try { + d1 = format.parse(dateStart); + d2 = format.parse(dateStop); + }catch (Exception e) { + e.printStackTrace(); + } + + + EvelThresholdCross tca = new EvelThresholdCross("ThresholdCross_vVNF", "vmname_ip", + "CRIT", + "mcast Limit reached", + "mcastRxPackets", + "1250000000", + EvelThresholdCross.EVEL_EVENT_ACTION.EVEL_EVENT_ACTION_SET, + "Mcast Rx breached", + EvelThresholdCross.EVEL_ALERT_TYPE.EVEL_ELEMENT_ANOMALY, + d1, + EvelThresholdCross.EVEL_SEVERITIES.EVEL_SEVERITY_CRITICAL, + d2); + tca.evel_threshold_cross_interfacename_set("ns345"); + tca.evel_thresholdcross_addl_info_add("n1", "v1"); + tca.evel_thresholdcross_addl_info_add("n2", "v2"); + tca.evel_thresholdcross_alertid_add("alert1"); + tca.evel_thresholdcross_alertid_add("alert2"); + + AgentMain.evel_post_event(tca); + + + EvelMobileFlow mf = new EvelMobileFlow("MobileFlow_vVNF", "vmname_ip", + "In", + null, + "GTP", + "v2.3", + "1.2.3.4", + 345556, + "5.6.7.8", + 334344); + MOBILE_GTP_PER_FLOW_METRICS mygtp = mf.new MOBILE_GTP_PER_FLOW_METRICS( + 1.01, + 2.02, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + d1, + "ACTIVE", + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28); + mf.gtp_per_flow_metrics = mygtp; + AgentMain.evel_post_event(mf); + } + + AgentMain.evel_shutdown(); + + } } diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src_test/java_agent_test b/veslibrary/ves_javalibrary/evel_javalib2/src_test/java_agent_test index 9f00451..351a4f4 100755 --- a/veslibrary/ves_javalibrary/evel_javalib2/src_test/java_agent_test +++ b/veslibrary/ves_javalibrary/evel_javalib2/src_test/java_agent_test @@ -1,2 +1,2 @@ -javac -cp .:../target/evel_javalib2-0.0.1-SNAPSHOT.jar:./log4j.jar:slf4j-api.jar:slf4j-log4j12-1.6.0.jar:./javax.json-1.0.jar ./evel_javalibrary/att/com/maindir/Main.java -java -cp .:../target/evel_javalib2-0.0.1-SNAPSHOT.jar:./log4j.jar:slf4j-api.jar:slf4j-log4j12-1.6.0.jar:./javax.json-1.0.jar evel_javalibrary.att.com.maindir.Main +javac -cp .:../target/evel_javalib2-1.1.0.jar:./log4j.jar:slf4j-api.jar:slf4j-log4j12-1.6.0.jar:./javax.json-1.0.jar ./evel_javalibrary/att/com/maindir/Main.java +java -cp .:../target/evel_javalib2-1.1.0.jar:./log4j.jar:slf4j-api.jar:slf4j-log4j12-1.6.0.jar:./javax.json-1.0.jar evel_javalibrary.att.com.maindir.Main |