aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.vfc/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-01-22 12:13:47 +0000
committerliamfallon <liam.fallon@ericsson.com>2018-01-22 16:27:17 +0000
commit45325103d88638ef5f1a4c5c7fdb785a182442c1 (patch)
tree03379ee107afba53d32779ff9deba85448cf3d8a /controlloop/common/actors/actor.vfc/src
parent3c7c997c6f081d749bc0973d1249a18356280e71 (diff)
Fix Tech Debt/JUnit on VFC actor
Unit test for VFC actor added. Some minor chages to actor service provider class to remove technical debt. Change-Id: I54ee24bcfa1c82f4a18c0035bdff186d4d3ebdf7 Issue-ID: POLICY-455 Signed-off-by: liamfallon <liam.fallon@ericsson.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.java164
1 files changed, 86 insertions, 78 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 71c7cea25..cf32abf38 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
@@ -40,90 +40,98 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class VFCActorServiceProvider implements Actor {
+ private static final Logger logger = LoggerFactory.getLogger(VFCActorServiceProvider.class);
- private static final Logger logger = LoggerFactory.getLogger(VFCActorServiceProvider.class);
- private static final ImmutableList<String> recipes = ImmutableList.of("Restart");
- private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
- .put("Restart", ImmutableList.of("VM")).build();
+ // Strings for VFC Actor
+ private static final String VFC_ACTOR = "VFC";
- @Override
- public String actor() {
- return "VFC";
- }
+ // Strings for targets
+ private static final String TARGET_VM = "VM";
- @Override
- public List<String> recipes() {
- return ImmutableList.copyOf(recipes);
- }
+ // Strings for recipes
+ private static final String RECIPE_RESTART = "Restart";
- @Override
- public List<String> recipeTargets(String recipe) {
- return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
- }
+ private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_RESTART);
+ private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
+ .put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).build();
- @Override
- public List<String> recipePayloads(String recipe) {
- return Collections.emptyList();
- }
+ @Override
+ public String actor() {
+ return VFC_ACTOR;
+ }
- public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
- Policy policy, AAIGETVnfResponse vnfResponse) {
- // Construct an VFC request
- VFCRequest request = new VFCRequest();
- String serviceInstance = onset.getAAI().get("service-instance.service-instance-id");
- if (serviceInstance == null || "".equals(serviceInstance))
- {
- AAIGETVnfResponse tempVnfResp = vnfResponse;
- if(tempVnfResp == null) //if the response is null, we haven't queried
- {
- tempVnfResp = getAAIServiceInstance(onset); //This does the AAI query since we haven't already
- if (tempVnfResp == null)
- return null;
- }
- serviceInstance = tempVnfResp.getServiceId();
- }
- request.setNSInstanceId(serviceInstance);
- request.setRequestId(onset.getRequestID());
- request.setHealRequest(new VFCHealRequest());
- request.getHealRequest().setVnfInstanceId(onset.getAAI().get("generic-vnf.vnf-id"));
- request.getHealRequest().setCause(operation.getMessage());
- request.getHealRequest().setAdditionalParams(new VFCHealAdditionalParams());
-
- switch (policy.getRecipe().toLowerCase()) {
- case "restart":
- request.getHealRequest().getAdditionalParams().setAction("restartvm");
- request.getHealRequest().getAdditionalParams().setActionInfo(new VFCHealActionVmInfo());
- request.getHealRequest().getAdditionalParams().getActionInfo().setVmid(onset.getAAI().get("vserver.vserver-id"));
- request.getHealRequest().getAdditionalParams().getActionInfo().setVmname(onset.getAAI().get("vserver.vserver-name"));
- break;
- default:
- return null;
- }
- return request;
- }
+ @Override
+ public List<String> recipes() {
+ return ImmutableList.copyOf(recipes);
+ }
+ @Override
+ public List<String> recipeTargets(String recipe) {
+ return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
+ }
- private static AAIGETVnfResponse getAAIServiceInstance(VirtualControlLoopEvent event) {
- AAIGETVnfResponse response = null;
- UUID requestID = event.getRequestID();
- String vnfName = event.getAAI().get("generic-vnf.vnf-name");
- String vnfID = event.getAAI().get("generic-vnf.vnf-id");
- 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 = new AAIManager(new RESTManager()).getQueryByVnfName(url, aaiUsername, aaiPassword, requestID, vnfName);
- } else if (vnfID != null) {
- String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/";
- response = new AAIManager(new RESTManager()).getQueryByVnfID(url, aaiUsername, aaiPassword, requestID, vnfID);
- } else {
- logger.error("getAAIServiceInstance failed");
- }
- } catch (Exception e) {
- logger.error("getAAIServiceInstance exception: ", e);
- }
- return response;
- }
+ @Override
+ public List<String> recipePayloads(String recipe) {
+ return Collections.emptyList();
+ }
+
+ public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
+ Policy policy, AAIGETVnfResponse vnfResponse) {
+
+ // Construct an VFC request
+ VFCRequest request = new VFCRequest();
+ String serviceInstance = onset.getAAI().get("service-instance.service-instance-id");
+ if (serviceInstance == null || "".equals(serviceInstance))
+ {
+ AAIGETVnfResponse tempVnfResp = vnfResponse;
+ if(tempVnfResp == null) //if the response is null, we haven't queried
+ {
+ tempVnfResp = getAAIServiceInstance(onset); //This does the AAI query since we haven't already
+ if (tempVnfResp == null)
+ return null;
+ }
+ serviceInstance = tempVnfResp.getServiceId();
+ }
+ request.setNSInstanceId(serviceInstance);
+ request.setRequestId(onset.getRequestID());
+ request.setHealRequest(new VFCHealRequest());
+ request.getHealRequest().setVnfInstanceId(onset.getAAI().get("generic-vnf.vnf-id"));
+ request.getHealRequest().setCause(operation.getMessage());
+ request.getHealRequest().setAdditionalParams(new VFCHealAdditionalParams());
+
+ if (policy.getRecipe().toLowerCase().equalsIgnoreCase(RECIPE_RESTART)) {
+ request.getHealRequest().getAdditionalParams().setAction("restartvm");
+ request.getHealRequest().getAdditionalParams().setActionInfo(new VFCHealActionVmInfo());
+ request.getHealRequest().getAdditionalParams().getActionInfo().setVmid(onset.getAAI().get("vserver.vserver-id"));
+ request.getHealRequest().getAdditionalParams().getActionInfo().setVmname(onset.getAAI().get("vserver.vserver-name"));
+ }
+ else {
+ return null;
+ }
+ return request;
+ }
+
+ private static AAIGETVnfResponse getAAIServiceInstance(VirtualControlLoopEvent event) {
+ AAIGETVnfResponse response = null;
+ UUID requestID = event.getRequestID();
+ String vnfName = event.getAAI().get("generic-vnf.vnf-name");
+ String vnfID = event.getAAI().get("generic-vnf.vnf-id");
+ 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 = new AAIManager(new RESTManager()).getQueryByVnfName(url, aaiUsername, aaiPassword, requestID, vnfName);
+ } else if (vnfID != null) {
+ String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/";
+ response = new AAIManager(new RESTManager()).getQueryByVnfID(url, aaiUsername, aaiPassword, requestID, vnfID);
+ } else {
+ logger.error("getAAIServiceInstance failed");
+ }
+ } catch (Exception e) {
+ logger.error("getAAIServiceInstance exception: ", e);
+ }
+ return response;
+ }
}