aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop
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
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')
-rw-r--r--controlloop/common/actors/actor.vfc/pom.xml45
-rw-r--r--controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java164
-rw-r--r--controlloop/common/simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java24
3 files changed, 126 insertions, 107 deletions
diff --git a/controlloop/common/actors/actor.vfc/pom.xml b/controlloop/common/actors/actor.vfc/pom.xml
index 4eef436c4..45d1e899e 100644
--- a/controlloop/common/actors/actor.vfc/pom.xml
+++ b/controlloop/common/actors/actor.vfc/pom.xml
@@ -1,17 +1,16 @@
<?xml version="1.0"?>
-<project
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
- xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.onap.policy.drools-applications</groupId>
- <artifactId>actors</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>actors</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>actor.vfc</artifactId>
<dependencies>
<dependency>
- <groupId>org.onap.policy.drools-applications</groupId>
+ <groupId>org.onap.policy.drools-applications</groupId>
<artifactId>actorServiceProvider</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
@@ -29,16 +28,28 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.onap.policy.drools-applications</groupId>
- <artifactId>aai</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
+ <groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>aai</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-management</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
+ <groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>simulators</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
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;
+ }
}
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 0602717c7..b8c0683d5 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
@@ -35,26 +35,26 @@ import org.slf4j.LoggerFactory;
@Path("/api/nslcm/v1")
public class VfcSimulatorJaxRs {
-
+
@POST
@Path("/ns/{nsInstanceId}/heal")
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
public String vfcPostQuery(@PathParam("nsInstanceId") String nsInstanceId,
- @Context final HttpServletResponse response)
+ @Context final HttpServletResponse response)
{
- response.setStatus(HttpServletResponse.SC_ACCEPTED);
- try {
- response.flushBuffer();
- }catch(Exception e){
- final Logger logger = LoggerFactory.getLogger(VfcSimulatorJaxRs.class);
- logger.error("flushBuffer threw: ", e);
- return "";
- }
+ response.setStatus(HttpServletResponse.SC_ACCEPTED);
+ try {
+ response.flushBuffer();
+ } catch(Exception e){
+ final Logger logger = LoggerFactory.getLogger(VfcSimulatorJaxRs.class);
+ logger.error("flushBuffer threw: ", e);
+ return "";
+ }
return "{\"jobId\":\"1\"}";
}
-
+
@GET
@Path("/jobs/{jobId}")
@Consumes(MediaType.APPLICATION_JSON)
@@ -62,6 +62,6 @@ public class VfcSimulatorJaxRs {
public String vfcGetQuery(@PathParam("jobId") String jobId) {
return "{\"jobId\" : "+jobId+",\"responseDescriptor\" : {\"progress\" : \"40\",\"status\" : \"finished\",\"statusDescription\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\": 101 ,\"responseHistoryList\": [{\"progress\" : \"40\",\"status\" : \"proccessing\",\"statusDescription\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"1\"}, {\"progress\" : \"41\",\"status\" : \"proccessing\",\"statusDescription\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"2\"}]}}";
}
-
+
}