diff options
Diffstat (limited to 'models-interactions/model-actors/actor.vfc')
2 files changed, 1 insertions, 202 deletions
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActor.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActor.java index cf4173176..c3b9028be 100644 --- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActor.java +++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActor.java @@ -20,43 +20,12 @@ package org.onap.policy.controlloop.actor.vfc; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import java.util.Collections; -import java.util.List; -import org.onap.policy.aai.AaiCqResponse; -import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.impl.HttpActor; import org.onap.policy.controlloop.actorserviceprovider.impl.HttpPollingOperator; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingActorParams; -import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.vfc.VfcHealActionVmInfo; -import org.onap.policy.vfc.VfcHealAdditionalParams; -import org.onap.policy.vfc.VfcHealRequest; -import org.onap.policy.vfc.VfcRequest; public class VfcActor extends HttpActor<HttpPollingActorParams> { - private static final String GENERIC_VNF_ID = "generic-vnf.vnf-id"; - - // TODO old code: remove lines down to **HERE** - - // Strings for VFC Actor - private static final String VFC_ACTOR = "VFC"; - - public static final String NAME = VFC_ACTOR; - - // Strings for targets - private static final String TARGET_VM = "VM"; - - // Strings for recipes - private static final String RECIPE_RESTART = "Restart"; - - 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(); - - // **HERE** + public static final String NAME = "VFC"; /** * Constructor. @@ -66,76 +35,4 @@ public class VfcActor extends HttpActor<HttpPollingActorParams> { addOperator(new HttpPollingOperator(NAME, Restart.NAME, Restart::new)); } - - // TODO old code: remove lines down to **HERE** - - @Override - public String actor() { - return VFC_ACTOR; - } - - @Override - public List<String> recipes() { - return ImmutableList.copyOf(recipes); - } - - @Override - public List<String> recipeTargets(String recipe) { - return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); - } - - @Override - public List<String> recipePayloads(String recipe) { - return Collections.emptyList(); - } - - /** - * This method constructs the VFC request. - * - * @param onset onset object - * @param operation operation object - * @param policy policy object - * @param aaiCqResponse response from aai custom query - * @return VfcRequest - */ - public static VfcRequest constructRequestCq(VirtualControlLoopEvent onset, ControlLoopOperation operation, - Policy policy, AaiCqResponse aaiCqResponse) { - - // Construct an VFC request - VfcRequest request = new VfcRequest(); - String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); - if (serviceInstance == null || "".equals(serviceInstance)) { - // get service instance from AaiCqResponse - if (aaiCqResponse == null) { - return null; - } - serviceInstance = aaiCqResponse.getServiceInstance().getServiceInstanceId(); - // If the serviceInstanceId returned is null then return null - if (serviceInstance == null) { - return null; - } - - } - request.setNsInstanceId(serviceInstance); - request.setRequestId(onset.getRequestId()); - request.setHealRequest(new VfcHealRequest()); - request.getHealRequest().setVnfInstanceId(onset.getAai().get(GENERIC_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; - } - - // **HERE** - } diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorTest.java index bd4bb0980..08ce8e194 100644 --- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorTest.java +++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorTest.java @@ -23,48 +23,14 @@ package org.onap.policy.controlloop.actor.vfc; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Arrays; -import java.util.Objects; -import java.util.UUID; import java.util.stream.Collectors; -import org.apache.commons.io.IOUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.aai.AaiCqResponse; -import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; -import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actor.test.BasicActor; -import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.simulators.Util; -import org.onap.policy.vfc.VfcRequest; public class VfcActorTest extends BasicActor { - private static final String DOROTHY_GALE_1939 = "dorothy.gale.1939"; - private static final String CQ_RESPONSE_JSON = "aai/AaiCqResponse.json"; - private static final String RESTART = "Restart"; - - /** - * Set up before test class. - * @throws Exception if the A&AI simulator cannot be started - */ - @BeforeClass - public static void setUpSimulator() throws Exception { - Util.buildAaiSim(); - } - - @AfterClass - public static void tearDownSimulator() { - HttpServletServerFactoryInstance.getServerFactory().destroy(); - } - @Test public void testConstructor() { VfcActor prov = new VfcActor(); @@ -82,68 +48,4 @@ public class VfcActorTest extends BasicActor { // verify that it all plugs into the ActorService verifyActorService(VfcActor.NAME, "service.yaml"); } - - @Test - public void testMethods() { - VfcActor sp = new VfcActor(); - - assertEquals("VFC", sp.actor()); - assertEquals(1, sp.recipes().size()); - assertEquals(RESTART, sp.recipes().get(0)); - assertEquals("VM", sp.recipeTargets(RESTART).get(0)); - assertEquals(0, sp.recipePayloads(RESTART).size()); - } - - @Test - public void testConstructRequestCq() throws IOException { - VirtualControlLoopEvent onset = new VirtualControlLoopEvent(); - ControlLoopOperation operation = new ControlLoopOperation(); - - Policy policy = new Policy(); - policy.setRecipe("GoToOz"); - - assertNull(VfcActor.constructRequestCq(onset, operation, policy, null)); - - onset.getAai().put("generic-vnf.vnf-id", DOROTHY_GALE_1939); - assertNull(VfcActor.constructRequestCq(onset, operation, policy, null)); - - - UUID requestId = UUID.randomUUID(); - onset.setRequestId(requestId); - assertNull(VfcActor.constructRequestCq(onset, operation, policy, null)); - - onset.getAai().put("generic-vnf.vnf-name", "Dorothy"); - assertNull(VfcActor.constructRequestCq(onset, operation, policy, null)); - - - onset.getAai().put("service-instance.service-instance-id", ""); - assertNull(VfcActor.constructRequestCq(onset, operation, policy, null)); - - assertNull(VfcActor.constructRequestCq(onset, operation, policy, - loadAaiResponse(CQ_RESPONSE_JSON))); - - policy.setRecipe(RESTART); - assertNotNull(VfcActor.constructRequestCq(onset, operation, policy, - loadAaiResponse(CQ_RESPONSE_JSON))); - - VfcRequest request = VfcActor.constructRequestCq(onset, operation, policy, - loadAaiResponse(CQ_RESPONSE_JSON)); - - assertEquals(requestId, Objects.requireNonNull(request).getRequestId()); - assertEquals(DOROTHY_GALE_1939, request.getHealRequest().getVnfInstanceId()); - assertEquals("restartvm", request.getHealRequest().getAdditionalParams().getAction()); - } - - /** - * Reads an AAI vserver named-query response from a file. - * - * @param fileName name of the file containing the JSON response - * @return output from the AAI vserver named-query - * @throws IOException if the file cannot be read - */ - private AaiCqResponse loadAaiResponse(String fileName) throws IOException { - String resp = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8); - return new AaiCqResponse(resp); - } - } |