diff options
author | Arun Arora <aroraarun@vmware.com> | 2017-11-07 16:06:41 +0530 |
---|---|---|
committer | Arun Arora <aroraarun@vmware.com> | 2017-11-08 18:25:52 +0530 |
commit | 60644a0117ee7f55930ecf2fdd5f03551b703c9f (patch) | |
tree | 94c11735a1d9fa8ec0a159680c12e66cb8d3c98b /vesagent | |
parent | 5e860945c64f5e5476b91bcfafcad7911cf8c138 (diff) |
VMWare VESAgent bug fix checkin
1. Fix for string comparision bug
2. Fix for NPE
3. Fix for map data population
Change-Id: I6884aac2021cc31dfaf16b9a350c1f830cb9b0c0
Issue-ID: MULTICLOUD-8
Signed-off-by: Arun Arora <aroraarun@vmware.com>
Diffstat (limited to 'vesagent')
5 files changed, 60 insertions, 37 deletions
diff --git a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/JsonStoreMap.java b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/JsonStoreMap.java index 32c6bc8..95950f6 100644 --- a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/JsonStoreMap.java +++ b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/JsonStoreMap.java @@ -90,21 +90,34 @@ public class JsonStoreMap { { String key = i.next().toString(); List<JsonAlarmStorage> value = map.get(key); - String value1=value.get(0).alarm+""+value.get(0).json.toString(); - log.info("Key : " + key +" value :"+value1); - JSONObject json = value.get(0).json; - log.info(line); - log.info(json.get("event").toString()); - JSONObject obj = (JSONObject) json.get("event"); - list.add(obj); + if(value.get(0).vesSendStatus.equals("failed") || value.get(0).vesSendStatus.equals("new")){ + String value1=value.get(0).alarm+""+value.get(0).json.toString(); + log.info("Key : " + key +" value :"+value1); + JSONObject json = value.get(0).json; + log.info(json.get("event").toString()); + JSONObject obj = (JSONObject) json.get("event"); + list.add(obj); + } } - log.info(line); eventList.put("eventList", list); log.info(eventList.toString()); - log.info(line); return eventList; } + @SuppressWarnings({ "rawtypes", "unchecked" }) + public boolean AnyVesEventSendFailed(){ + log.info("If Any VES Event Exists for which Send Attempt Failed"); + Iterator i = map.keySet().iterator(); + while(i.hasNext()) + { + String key = i.next().toString(); + List<JsonAlarmStorage> value = map.get(key); + if(value.get(0).vesSendStatus.equals("failed")){ + return true; + } + } + return false; + } @SuppressWarnings("rawtypes") public void displayALLEntriesInMap(){ diff --git a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VESRestAPI.java b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VESRestAPI.java index d2450cb..9fef06e 100644 --- a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VESRestAPI.java +++ b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VESRestAPI.java @@ -43,15 +43,15 @@ public class VESRestAPI{ try{ eventType = anyEvent; log.info("inside publish any event method"); - sock = new Socket(ves.getVesip(), ves.getPort()); + sock = new Socket(ves.getVesip(), ves.getVesPort()); log.info(String.valueOf(sock.isConnected())); if(sock.isConnected()){ log.info("list "+list.get(0).json.toString()); client = new DefaultHttpClient(); /* check the vesStructure whether each of the variable like ip address , portnumber , user name and password contains something or is null */ if(vesEntitycredentialCheckSuccess(ves)){ - post = new HttpPost("http://"+ves.getVesip()+":"+ves.getPort()+"/eventListener/v5"); - log.info(ves.getPort().toString()); + post = new HttpPost("http://"+ves.getVesip()+":"+ves.getVesPort()+"/eventListener/v5"); + log.info(ves.getVesPort().toString()); }else{ log.info("Null"); } @@ -85,13 +85,13 @@ public class VESRestAPI{ try { eventType = batchEvent; log.info("inside publish batch event method"); - sock = new Socket(ves.getVesip(), ves.getPort()); + sock = new Socket(ves.getVesip(), ves.getVesPort()); if(sock.isConnected()){ log.info("Sending batch"); client = new DefaultHttpClient(); if(vesEntitycredentialCheckSuccess(ves)) { - post = new HttpPost("http://"+ves.getVesip()+":"+ves.getPort()+"/eventListener/v5/eventBatch"); + post = new HttpPost("http://"+ves.getVesip()+":"+ves.getVesPort()+"/eventListener/v5/eventBatch"); }else{ log.info("Null"); } @@ -128,7 +128,7 @@ public class VESRestAPI{ } public boolean vesEntitycredentialCheckSuccess(VesEntity ves){ - if(ves.getPort()==null || ves.getVesip()==null || ves.getVesPassword()==null || ves.getVesUsername()==null){ + if(ves.getVesPort()==null || ves.getVesip()==null){ return false; } return true; diff --git a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesAgent.java b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesAgent.java index b5e5577..b6b536f 100644 --- a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesAgent.java +++ b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesAgent.java @@ -31,6 +31,7 @@ public class VesAgent { private static final String ERROR = "error"; private static final Integer TIMERDURATION=360000; private static final String GREEN="green"; + private VesAgent(){ } public static void main(String[] args) throws InterruptedException { @@ -67,10 +68,6 @@ public class VesAgent { if(file.readProperties(vsphereEntity,filePath) && getEnv(vsphereEntity, vesEntity)) { VESRestAPI vesRestAPI= new VESRestAPI(); - JSONObject eventObj = new JSONObject(); - JSONObject event = new JSONObject(); - JSONObject commonEventHeader = new JSONObject(); - JSONObject faultFields = new JSONObject(); VesTimer timer = new VesTimer(map); int i=0; while(true) @@ -92,21 +89,32 @@ public class VesAgent { JSONArray jsonObject = (JSONArray) obj; log.info(jsonObject.toString()); log.info("Iterating Json files-vms"); + count = 0; for(int j = 0;j<=jsonObject.size()-1;j++){ - log.info("Is timer running: ",timer.isTimerRunning()); - log.info("Is timed out happen: ",timer.isTimeout()); + JSONObject event = new JSONObject(); + JSONObject eventObj = new JSONObject(); + JSONObject commonEventHeader = new JSONObject(); + JSONObject faultFields = new JSONObject(); + log.info("Is timer running: "+String.valueOf(timer.isTimerRunning())); + log.info("Is timed out happen: "+String.valueOf(timer.isTimeout())); JSONObject js = (JSONObject) jsonObject.get(j); count++; log.info("////////////////////////////////////////////////////////////////////////////"); - log.info("Total entries in map: ",map.totalEntriesInMap()); - log.info("Count for checking vms :",count); + log.info("Total entries in map: "+String.valueOf(map.totalEntriesInMap())); + log.info("Count for checking vms :"+String.valueOf(count)); VsphereDataEntity entity = vsphereData.gettingVMInfo(js,vsphereDataEntity,vsphereEntity); + + if(entity.getSourceId() == null || entity.getSourceId().length() == 0) + { + log.info("UUID for VM not found, VM entry not added in map"); + continue; + } String heartBeatStatus = vsphereDataEntity.getStatus(); String uuidKey = vsphereDataEntity.getSourceId(); log.info("Heart beat status of vm",heartBeatStatus); - if(heartBeatStatus!=GREEN){ + if(!heartBeatStatus.equals(GREEN)){ //encode json - if(map.isJsonFound(uuidKey) && map.retrieveFromMap(uuidKey, "ALARM") == "ON"){ + if(map.isJsonFound(uuidKey) && map.retrieveFromMap(uuidKey, "ALARM").equals("ON")){ log.info("Alarm ON already raised..."); } else if(!map.isJsonFound(uuidKey)){ @@ -116,7 +124,7 @@ public class VesAgent { log.info("json, alarm and vesSend status: "+list.get(0).json.toString()+" :"+list.get(0).alarm+" :"+list.get(0).vesSendStatus); map.addToMap(uuidKey, list); - if(map.totalEntriesInMap()>1) + if(map.AnyVesEventSendFailed()) { JSONObject alarmJsonConstructArray = map.retrieveALLFromMapBatch(); vesRestAPI.publishBatchEventToVES(vesEntity, alarmJsonConstructArray, map, timer, uuidKey, list, TIMERDURATION,vesSendStatus); @@ -128,11 +136,11 @@ public class VesAgent { } } } - else if(heartBeatStatus == GREEN){ /* if the alarm on entry is found in Map then check for the vesSendStatus + else if(heartBeatStatus.equals(GREEN)){ /* if the alarm on entry is found in Map then check for the vesSendStatus * IF the VesSendStatus ==failed for Alarm On * in the case remove the entries from MAP and * donot encode the alarm off and donot send it to VESCollector */ - if((map.isJsonFound(uuidKey) && map.retrieveFromMap(uuidKey, "ALARM") == "ON") && map.retrieveFromMap(uuidKey,"VES_STATUS")!="failed"){ + if((map.isJsonFound(uuidKey) && map.retrieveFromMap(uuidKey, "ALARM").equals("ON")) && map.retrieveFromMap(uuidKey,"VES_STATUS")!="failed"){ log.info("heart beat status is green, uuid found in map "); alarmCondition = "OFF"; vsphereData.encodeJson(entity, event, eventObj, commonEventHeader, faultFields,map); @@ -140,9 +148,9 @@ public class VesAgent { String json = event.toJSONString(); map.addToMap(uuidKey, list); - if(map.totalEntriesInMap()>1){ - //sending only entry having vesSendStatus = failed + if(map.AnyVesEventSendFailed()){ JSONObject alarmJsonConstructArray = map.retrieveALLFromMapBatch(); + //sending only entry having vesSendStatus = failed along with vesSendStatus = new vesRestAPI.publishBatchEventToVES(vesEntity, alarmJsonConstructArray, map, timer, json, list, TIMERDURATION,vesSendStatus); } else{ @@ -150,7 +158,7 @@ public class VesAgent { } } else{ - log.info("ALarm ON not found, ves Send status is failed"); + log.info("ALarm ON not found for the VM"); } } Thread.sleep(2000); @@ -211,7 +219,7 @@ public class VesAgent { vsphereEntity.setVsphereUsername(System.getenv("Vsphere_Username")); vsphereEntity.setVsperePassword(System.getenv("Vsphere_Password")); vesEntity.setVesip(System.getenv("VesCollector_Ip")); - vesEntity.setVesPassword(System.getenv("VesCollector_Port")); + vesEntity.setVesPort(Integer.parseInt(System.getenv("VesCollector_Port"))); return true; } }catch(NullPointerException e){ diff --git a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesEntity.java b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesEntity.java index 1f3e863..3bacc55 100644 --- a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesEntity.java +++ b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VesEntity.java @@ -19,20 +19,21 @@ package org.onap.multicloud.openstack.vmware; public class VesEntity { private String vesip; private Integer port; - private String vesUsername; - private String vesPassword; + //private String vesUsername; + //private String vesPassword; public String getVesip() { return vesip; } public void setVesip(String vesip) { this.vesip = vesip; } - public Integer getPort() { + public Integer getVesPort() { return port; } - public void setPort(Integer port) { + public void setVesPort(Integer port) { this.port = port; } +/* public String getVesUsername() { return vesUsername; } @@ -45,4 +46,5 @@ public class VesEntity { public void setVesPassword(String vesPassword) { this.vesPassword = vesPassword; } +*/ } diff --git a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VsphereData.java b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VsphereData.java index ddb963e..f3dce32 100644 --- a/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VsphereData.java +++ b/vesagent/src/main/java/org/onap/multicloud/openstack/vmware/VsphereData.java @@ -68,7 +68,7 @@ public class VsphereData { String eventId; String sourceId =vsphereDataEntity.getSourceId(); Double faultFieldsVersion=2.0; - if (vsphereDataEntity.getStatus() !="green") { + if (!vsphereDataEntity.getStatus().equals("green")) { eventName="Fault_MultiCloud_VMFailure"; priority="High"; eventSeverity="CRITICAL" ; //it should be in caps |