aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.vfc
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-21 13:43:08 -0400
committerJim Hahn <jrh3@att.com>2020-10-27 14:55:15 -0400
commit19ef8b24a98c09a349e6ae7309f535a0135463f6 (patch)
treed988e5a58865ae6f3a38dcb31e4f195f18e59946 /models-interactions/model-actors/actor.vfc
parent6b29d2c19e288148171db0c0e446e18dcd46effd (diff)
Make Actors event-agnostic
Removed event and event-context code from the Actor code. Also removed the preprocessing steps from the Actor code, giving the application complete control over any preprocessing. Also fixed a bug wherein the APPC actor was treating the AAI_RESOURCE_VNF property as a String instead of as a GenericVnf. Issue-ID: POLICY-2746-actor Change-Id: Ibc05fe39ffedc0bc461abf10e6a960861ac70119 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.vfc')
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java37
-rw-r--r--models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java39
-rw-r--r--models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java40
3 files changed, 16 insertions, 100 deletions
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
index 0a1136d2f..65c7318ff 100644
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
+++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
@@ -21,7 +21,6 @@
package org.onap.policy.controlloop.actor.vfc;
import java.util.List;
-import java.util.concurrent.CompletableFuture;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -82,14 +81,6 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
return super.getPollingPath() + jobId;
}
- /**
- * Starts the GUARD.
- */
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- return startGuardAsync();
- }
-
@Override
protected Status detmStatus(Response rawResponse, VfcResponse response) {
if (rawResponse.getStatus() == 200) {
@@ -170,16 +161,15 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
* @return request
*/
protected VfcRequest constructVfcRequest() {
- final String serviceInstance = getOptProperty(OperationProperties.ENRICHMENT_SERVICE_ID,
- "service-instance.service-instance-id");
- final String vmId = getOptProperty(OperationProperties.ENRICHMENT_VSERVER_ID, "vserver.vserver-id");
- final String vmName = getOptProperty(OperationProperties.ENRICHMENT_VSERVER_NAME, "vserver.vserver-name");
- final String vnfId = getOptProperty(OperationProperties.ENRICHMENT_GENERIC_VNF_ID, GENERIC_VNF_ID);
+ final String serviceInstance = getProperty(OperationProperties.ENRICHMENT_SERVICE_ID);
+ final String vmId = getProperty(OperationProperties.ENRICHMENT_VSERVER_ID);
+ final String vmName = getProperty(OperationProperties.ENRICHMENT_VSERVER_NAME);
+ final String vnfId = getProperty(OperationProperties.ENRICHMENT_GENERIC_VNF_ID);
if (StringUtils.isBlank(serviceInstance) || StringUtils.isBlank(vmId) || StringUtils.isBlank(vmName)) {
// original code did not check the VNF id, so we won't check it either
throw new IllegalArgumentException(
- "Cannot extract enrichment data for service instance, server id, or server name.");
+ "Missing enrichment data for service instance, server id, or server name.");
}
VfcHealActionVmInfo vmActionInfo = new VfcHealActionVmInfo();
@@ -202,21 +192,4 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
return request;
}
-
- /**
- * Gets an optional property, first checking the properties, then checking the
- * enrichment data.
- *
- * @param propName property name
- * @param enrichmentName property name within the enrichment data
- * @return the property's value, or {@code null} if it is not found
- */
- protected String getOptProperty(String propName, String enrichmentName) {
- if (containsProperty(propName)) {
- // return the value, even if it's null
- return getProperty(propName);
- }
-
- return params.getContext().getEnrichment().get(enrichmentName);
- }
}
diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java
index 9a4677d79..fab7636ba 100644
--- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java
+++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java
@@ -32,7 +32,6 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
@@ -67,49 +66,26 @@ public class RestartTest extends BasicVfcOperation {
@Before
public void setup() throws Exception {
super.setUp();
- params.getContext().getEnrichment().put("service-instance.service-instance-id", TEST_SERVICE_INSTANCE_ID);
- params.getContext().getEnrichment().put("vserver.vserver-id", TEST_VSERVER_ID);
- params.getContext().getEnrichment().put("vserver.vserver-name", TEST_VSERVER_NAME);
- restartOper = new Restart(params, config);
- }
-
- /**
- * Tests "success" case with simulator.
- */
- @Test
- public void testSuccess() throws Exception {
- HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("ns").pollPath("jobs")
- .maxPolls(1).build();
- config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
-
- params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
restartOper = new Restart(params, config);
- outcome = restartOper.start().get();
- assertEquals(OperationResult.SUCCESS, outcome.getResult());
- assertTrue(outcome.getResponse() instanceof VfcResponse);
+ loadProperties();
}
/**
- * Tests "success" case with simulator, using properties instead of custom query data.
+ * Tests "success" case with simulator.
*/
@Test
- public void testSuccessViaProperties() throws Exception {
+ public void testSuccess() throws Exception {
HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("ns").pollPath("jobs")
.maxPolls(1).build();
config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build();
- params.getContext().removeProperty(AaiCqResponse.CONTEXT_KEY);
restartOper = new Restart(params, config);
- // set the properties
- restartOper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, TEST_SERVICE_INSTANCE_ID);
- restartOper.setProperty(OperationProperties.ENRICHMENT_VSERVER_ID, TEST_VSERVER_ID);
- restartOper.setProperty(OperationProperties.ENRICHMENT_VSERVER_NAME, TEST_VSERVER_NAME);
- restartOper.setProperty(OperationProperties.ENRICHMENT_GENERIC_VNF_ID, TEST_GENERIC_VNF_ID);
+ loadProperties();
// run the operation
outcome = restartOper.start().get();
@@ -142,4 +118,11 @@ public class RestartTest extends BasicVfcOperation {
assertNotNull(resultPair.getLeft());
assertNotNull(resultPair.getRight());
}
+
+ private void loadProperties() {
+ restartOper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, TEST_SERVICE_INSTANCE_ID);
+ restartOper.setProperty(OperationProperties.ENRICHMENT_VSERVER_ID, TEST_VSERVER_ID);
+ restartOper.setProperty(OperationProperties.ENRICHMENT_VSERVER_NAME, TEST_VSERVER_NAME);
+ restartOper.setProperty(OperationProperties.ENRICHMENT_GENERIC_VNF_ID, TEST_GENERIC_VNF_ID);
+ }
}
diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
index 6f8956f6f..4f20c12d4 100644
--- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
+++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
@@ -26,11 +26,9 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.vfc.VfcResponse;
import org.onap.policy.vfc.VfcResponseDescriptor;
@@ -60,11 +58,6 @@ public class VfcOperationTest extends BasicVfcOperation {
}
@Test
- public void testStartPreprocessorAsync() {
- assertNotNull(oper.startPreprocessorAsync());
- }
-
- @Test
public void testResetPollCount() {
oper.resetPollCount();
assertEquals(0, oper.getPollCount());
@@ -88,37 +81,4 @@ public class VfcOperationTest extends BasicVfcOperation {
public void testIsSuccess() {
assertTrue(oper.isSuccess(rawResponse, response));
}
-
- @Test
- public void testGetOptProperty() {
- // in neither property nor enrichment
- assertNull(oper.getOptProperty("propA", "propA2"));
-
- // both - should choose the property
- remakeOper(Map.of("propB2", "valueB2"));
- oper.setProperty("propB", "valueB");
- assertEquals("valueB", oper.getOptProperty("propB", "propB2"));
-
- // both - should choose the property, even if it's null
- remakeOper(Map.of("propC2", "valueC2"));
- oper.setProperty("propC", null);
- assertNull(oper.getOptProperty("propC", "propC2"));
-
- // only in enrichment data
- remakeOper(Map.of("propD2", "valueD2"));
- assertEquals("valueD2", oper.getOptProperty("propD", "propD2"));
- }
-
- /**
- * Remakes the operation, with the specified A&AI enrichment data.
- *
- * @param aai A&AI enrichment data
- */
- private void remakeOper(Map<String, String> aai) {
- event.setAai(aai);
- context = new ControlLoopEventContext(event);
- params = params.toBuilder().context(context).build();
-
- oper = new VfcOperation(params, config) {};
- }
}