summaryrefslogtreecommitdiffstats
path: root/controlloop/common
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
parent788289af4cbe6d288f6dadb9e1eca4ee2740a30d (diff)
parent61af63956d0fa9022667c56c8874d83be35c8102 (diff)
Merge "Fix Sonar criticals"
Diffstat (limited to 'controlloop/common')
-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
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java11
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java2
-rw-r--r--controlloop/common/simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java9
5 files changed, 56 insertions, 49 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;
}
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index 7aaac9ead..f8f3b4cc8 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -72,14 +72,11 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
private ControlLoopOperationManager currentOperation = null;
private transient TargetLock targetLock = null;
- private static AAIGETVnfResponse vnfResponse = null;
- private static AAIGETVserverResponse vserverResponse = null;
+ private AAIGETVnfResponse vnfResponse = null;
+ private AAIGETVserverResponse vserverResponse = null;
private static String aaiHostURL;
private static String aaiUser;
private static String aaiPassword;
- private static String aaiGetQueryByVserver;
- private static String aaiGetQueryByVnfID;
- private static String aaiGetQueryByVnfName;
private static Collection<String> requiredAAIKeys = new ArrayList<>();
static {
@@ -438,7 +435,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
public NEW_EVENT_STATUS onNewEvent(VirtualControlLoopEvent event) {
try {
- ControlLoopEventManager.checkEventSyntax(event);
+ this.checkEventSyntax(event);
if (event.closedLoopEventStatus == ControlLoopEventStatus.ONSET) {
//
// Check if this is our original ONSET
@@ -521,7 +518,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return vserverResponse;
}
- public static void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
+ public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
if (event.closedLoopEventStatus == null ||
(event.closedLoopEventStatus != ControlLoopEventStatus.ONSET &&
event.closedLoopEventStatus != ControlLoopEventStatus.ABATED)) {
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index 590e32439..6e57b5ef0 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -225,7 +225,7 @@ public class ControlLoopOperationManager implements Serializable {
return operationRequest;
case "VFC":
- this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy);
+ this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy, this.eventManager.getVnfResponse());
this.currentOperation = operation;
return operationRequest;
diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java
index 53ae7bc4b..0602717c7 100644
--- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java
+++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java
@@ -30,6 +30,9 @@ import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
@Path("/api/nslcm/v1")
public class VfcSimulatorJaxRs {
@@ -43,7 +46,11 @@ public class VfcSimulatorJaxRs {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
try {
response.flushBuffer();
- }catch(Exception e){}
+ }catch(Exception e){
+ final Logger logger = LoggerFactory.getLogger(VfcSimulatorJaxRs.class);
+ logger.error("flushBuffer threw: ", e);
+ return "";
+ }
return "{\"jobId\":\"1\"}";
}