From 61af63956d0fa9022667c56c8874d83be35c8102 Mon Sep 17 00:00:00 2001 From: Charles Cole Date: Tue, 26 Sep 2017 14:43:58 -0500 Subject: Fix Sonar criticals Fixed two Sonar criticals. Changed VFC actor service provider to eliminate redundant AAI queries. Issue-ID: POLICY-115 Change-Id: Ic4993b5d498a1cb3d3fc51ce1d2b4e90bb26353d Signed-off-by: Charles Cole --- controlloop/common/actors/actor.vfc/pom.xml | 2 +- .../actor/vfc/VFCActorServiceProvider.java | 81 +++++++++++----------- 2 files changed, 43 insertions(+), 40 deletions(-) (limited to 'controlloop/common/actors') diff --git a/controlloop/common/actors/actor.vfc/pom.xml b/controlloop/common/actors/actor.vfc/pom.xml index 223be4bda..81505957f 100644 --- a/controlloop/common/actors/actor.vfc/pom.xml +++ b/controlloop/common/actors/actor.vfc/pom.xml @@ -28,7 +28,7 @@ 1.1.0-SNAPSHOT provided - + org.onap.policy.drools-applications aai 1.1.0-SNAPSHOT diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java index 469faa46c..814726256 100644 --- a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java +++ b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java @@ -66,59 +66,62 @@ public class VFCActorServiceProvider implements Actor { } public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, - Policy policy) { + Policy policy, AAIGETVnfResponse vnfResponse) { // Construct an VFC request VFCRequest request = new VFCRequest(); - request.nsInstanceId = getAAIServiceInstance(onset); - request.requestId = onset.requestID; + String serviceInstance = onset.AAI.get("service-instance.service-instance-id"); + if (serviceInstance == null || "".equals(serviceInstance)) + { + if(vnfResponse == null) //if the response is null, we haven't queried + { + vnfResponse = getAAIServiceInstance(onset); //This does the AAI query since we haven't already + if (vnfResponse == null) + return null; + } + serviceInstance = vnfResponse.serviceId; + } + request.nsInstanceId = serviceInstance; + request.requestId = onset.requestID; request.healRequest = new VFCHealRequest(); request.healRequest.vnfInstanceId = onset.AAI.get("generic-vnf.vnf-id"); request.healRequest.cause = operation.message; - request.healRequest.additionalParams = new VFCHealAdditionalParams(); - if ("Restart".equalsIgnoreCase(policy.getRecipe())) { - request.healRequest.additionalParams.action = "restartvm"; - request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo(); - request.healRequest.additionalParams.actionInfo.vmid = onset.AAI.get("vserver.vserver-id"); - request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name"); - } else { - request = null; + + switch (policy.getRecipe().toLowerCase()) { + case "restart": + request.healRequest.additionalParams.action = "restartvm"; + request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo(); + request.healRequest.additionalParams.actionInfo.vmid = onset.AAI.get("vserver.vserver-id"); + request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name"); + break; + default: + return null; } return request; } - private static String getAAIServiceInstance(VirtualControlLoopEvent event) { - AAIGETVnfResponse response; + + private static AAIGETVnfResponse getAAIServiceInstance(VirtualControlLoopEvent event) { + AAIGETVnfResponse response = null; UUID requestID = event.requestID; - String serviceInstance = event.AAI.get("service-instance.service-instance-id"); String vnfName = event.AAI.get("generic-vnf.vnf-name"); String vnfID = event.AAI.get("generic-vnf.vnf-id"); - - if (serviceInstance == null) { - String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); - String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); - String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); - try { - if (vnfName != null) { - String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; - response = AAIManager.getQueryByVnfName(url, aaiUsername, aaiPassword, requestID, vnfName); - if (response != null) { - serviceInstance = response.serviceId; - } - } else if (vnfID != null) { - String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/"; - response = AAIManager.getQueryByVnfID(url, aaiUsername, aaiPassword, requestID, vnfID); - if (response != null) { - serviceInstance = response.serviceId; - } - } else { - logger.error("getAAIServiceInstance failed"); - - } - } catch (Exception e) { - logger.error("getAAIServiceInstance exception: ", e); + String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); + String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); + String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); + try { + if (vnfName != null) { + String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; + response = AAIManager.getQueryByVnfName(url, aaiUsername, aaiPassword, requestID, vnfName); + } else if (vnfID != null) { + String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/"; + response = AAIManager.getQueryByVnfID(url, aaiUsername, aaiPassword, requestID, vnfID); + } else { + logger.error("getAAIServiceInstance failed"); } + } catch (Exception e) { + logger.error("getAAIServiceInstance exception: ", e); } - return serviceInstance; + return response; } } -- cgit 1.2.3-korg