aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.vfc/src
diff options
context:
space:
mode:
authorCharles Cole <cc847m@att.com>2017-09-26 14:43:58 -0500
committerCharles Cole <cc847m@att.com>2017-09-28 11:19:28 -0500
commit61af63956d0fa9022667c56c8874d83be35c8102 (patch)
treeba5be7e0c8f573fa38714b4d8389a7c080ace9ce /controlloop/common/actors/actor.vfc/src
parent400ca9b5ebb98c42c0c497d917f3cf139b03888a (diff)
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 <cc847m@att.com>
Diffstat (limited to 'controlloop/common/actors/actor.vfc/src')
-rw-r--r--controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java81
1 files changed, 42 insertions, 39 deletions
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;
}
}