aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.vfc
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-09-28 18:14:53 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-28 18:14:53 +0000
commitf1ad599b0b0542853905d02e7726866301b65438 (patch)
tree21fb7ecec4ec7c807f3701de690e9dbc4863b623 /controlloop/common/actors/actor.vfc
parent788289af4cbe6d288f6dadb9e1eca4ee2740a30d (diff)
parent61af63956d0fa9022667c56c8874d83be35c8102 (diff)
Merge "Fix Sonar criticals"
Diffstat (limited to 'controlloop/common/actors/actor.vfc')
-rw-r--r--controlloop/common/actors/actor.vfc/pom.xml2
-rw-r--r--controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java81
2 files changed, 43 insertions, 40 deletions
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 @@
<version>1.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.onap.policy.drools-applications</groupId>
<artifactId>aai</artifactId>
<version>1.1.0-SNAPSHOT</version>
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;
}
}