aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/controller-usecases/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-08-28 17:28:37 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-28 17:28:37 +0000
commit383201bf1f1c81a6affd1cf4ad22121869b95513 (patch)
tree07ddcab3dda5431b8f3edba2a60e486732e12cc3 /controlloop/common/controller-usecases/src
parentffdf210ad1e3f18dcc612e2587ed6d3742ab1e24 (diff)
parent3052f10337897ea25983f35f4158c5626febbe7d (diff)
Merge "Use ToscaPolicy instead of legacy Policy"
Diffstat (limited to 'controlloop/common/controller-usecases/src')
-rw-r--r--controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java16
-rw-r--r--controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java46
-rw-r--r--controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java24
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java51
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java9
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java43
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java57
7 files changed, 111 insertions, 135 deletions
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java
index e1259e48d..f9d90af4d 100644
--- a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java
+++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java
@@ -33,10 +33,10 @@ import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.eventmanager.StepContext;
-import org.onap.policy.controlloop.policy.Target;
/**
* An operation to get the target entity. This is a "pseudo" operation; it is not found
@@ -65,7 +65,7 @@ public class GetTargetEntityOperation2 extends OperationPartial {
@Override
public List<String> getPropertyNames() {
- String propName = detmTarget(params.getTarget());
+ String propName = detmTarget(params.getTargetType());
return (propName == null ? Collections.emptyList() : List.of(propName));
}
@@ -77,26 +77,22 @@ public class GetTargetEntityOperation2 extends OperationPartial {
/**
* Determines the target entity.
*
- * @param target policy target
+ * @param targetType policy target type
*
* @return the property containing the target entity, or {@code null} if the target
* entity is already known
*/
- private String detmTarget(Target target) {
+ private String detmTarget(TargetType targetType) {
if (stepContext.contains(OperationProperties.AAI_TARGET_ENTITY)) {
// the target entity has already been determined
return null;
}
- if (target == null) {
- throw new IllegalArgumentException("The target is null");
- }
-
- if (target.getType() == null) {
+ if (targetType == null) {
throw new IllegalArgumentException("The target type is null");
}
- switch (target.getType()) {
+ switch (targetType) {
case PNF:
return detmPnfTarget();
case VM:
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java
index cf8cc8ee3..d92fbcfad 100644
--- a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java
+++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java
@@ -58,16 +58,16 @@ import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
+import org.onap.policy.controlloop.actorserviceprovider.OperationFinalResult;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ActorConstants;
import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
import org.onap.policy.controlloop.eventmanager.StepContext;
-import org.onap.policy.controlloop.policy.FinalResult;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.drools.apps.controller.usecases.step.AaiCqStep2;
import org.onap.policy.drools.apps.controller.usecases.step.AaiGetPnfStep2;
import org.onap.policy.drools.apps.controller.usecases.step.AaiGetTenantStep2;
@@ -75,6 +75,9 @@ import org.onap.policy.drools.apps.controller.usecases.step.GetTargetEntityStep2
import org.onap.policy.drools.apps.controller.usecases.step.GuardStep2;
import org.onap.policy.drools.apps.controller.usecases.step.LockStep2;
import org.onap.policy.drools.apps.controller.usecases.step.Step2;
+import org.onap.policy.drools.domain.models.operational.ActorOperation;
+import org.onap.policy.drools.domain.models.operational.Operation;
+import org.onap.policy.drools.domain.models.operational.OperationalTarget;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.sdnr.PciMessage;
@@ -172,7 +175,7 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
/**
* Policy currently being processed.
*/
- private Policy policy;
+ private Operation policy;
/**
* Result of the last policy operation. This is just a place where the rules can store
@@ -180,7 +183,7 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
*/
@Getter
@Setter
- private PolicyResult result = PolicyResult.SUCCESS;
+ private OperationResult result = OperationResult.SUCCESS;
@ToString.Include
private int numOnsets = 1;
@@ -205,7 +208,7 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
private final transient Deque<OperationOutcome2> partialHistory = new LinkedList<>();
@Getter
- private FinalResult finalResult = null;
+ private OperationFinalResult finalResult = null;
/**
* Message to be placed into the final notification. Typically used when something
@@ -284,7 +287,7 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
* @param finalResult final result
* @param finalMessage final message
*/
- public void abort(@NonNull State finalState, FinalResult finalResult, String finalMessage) {
+ public void abort(@NonNull State finalState, OperationFinalResult finalResult, String finalMessage) {
this.state = finalState;
this.finalResult = finalResult;
this.finalMessage = finalMessage;
@@ -297,7 +300,7 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
*
* @throws ControlLoopException if the processor cannot get a policy
*/
- public void loadNextPolicy(@NonNull PolicyResult lastResult) throws ControlLoopException {
+ public void loadNextPolicy(@NonNull OperationResult lastResult) throws ControlLoopException {
getProcessor().nextPolicyForResult(lastResult);
loadPolicy();
}
@@ -317,23 +320,30 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
policy = getProcessor().getCurrentPolicy();
+ ActorOperation actor = policy.getActorOperation();
+
+ OperationalTarget target = actor.getTarget();
+ String targetType = (target != null ? target.getTargetType() : null);
+ Map<String, String> entityIds = (target != null ? target.getEntityIds() : null);
+
// convert policy payload from Map<String,String> to Map<String,Object>
Map<String, Object> payload = new LinkedHashMap<>();
- if (policy.getPayload() != null) {
- payload.putAll(policy.getPayload());
+ if (actor.getPayload() != null) {
+ payload.putAll(actor.getPayload());
}
// @formatter:off
ControlLoopOperationParams params = ControlLoopOperationParams.builder()
.actorService(getActorService())
- .actor(policy.getActor())
- .operation(policy.getRecipe())
+ .actor(actor.getActor())
+ .operation(actor.getOperation())
.requestId(event.getRequestId())
.preprocessed(true)
.executor(getExecutor())
- .target(policy.getTarget())
- .retry(policy.getRetry())
+ .retry(policy.getRetries())
.timeoutSec(policy.getTimeout())
+ .targetType(TargetType.toTargetType(targetType))
+ .targetEntityIds(entityIds)
.payload(payload)
.startCallback(this::onStart)
.completeCallback(this::onComplete)
@@ -450,7 +460,7 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
* @return {@code true} if the TOSCA should be aborted, {@code false} otherwise
*/
public boolean isAbort(OperationOutcome outcome) {
- return (outcome.getResult() != PolicyResult.SUCCESS && ABORT_ACTORS.contains(outcome.getActor()));
+ return (outcome.getResult() != OperationResult.SUCCESS && ABORT_ACTORS.contains(outcome.getActor()));
}
/**
@@ -741,7 +751,11 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste
this.attempt = attempts;
clOperation = outcome.toControlLoopOperation();
- clOperation.setTarget(policy.getTarget().toString());
+
+ // TODO encode()?
+ OperationalTarget target = policy.getActorOperation().getTarget();
+ String targetStr = (target != null ? target.toString() : null);
+ clOperation.setTarget(targetStr);
if (outcome.getEnd() == null) {
clOperation.setOutcome("Started");
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java
index 9275f791d..5d80ea5f4 100644
--- a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java
+++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/step/Step2.java
@@ -59,7 +59,11 @@ import org.onap.policy.drools.apps.controller.usecases.UsecasesConstants;
* steps.
*/
public class Step2 extends Step {
- public static final String TARGET_INFO_MSG = "Target information";
+ public static final String TARGET_MODEL_VERSION_ID = "modelVersionId";
+ public static final String TARGET_MODEL_CUSTOMIZATION_ID = "modelCustomizationId";
+ public static final String TARGET_MODEL_INVARIANT_ID = "modelInvariantId";
+ public static final String TARGET_RESOURCE_ID = "resourceID";
+ public static final String TARGET_INFO_MSG = "Target Entity IDs";
public static final String ENRICHMENT_PREFIX = "enrichment/";
public static final String VSERVER_VSERVER_NAME = "vserver.vserver-name";
public static final String RESOURCE_LINK = "resource-link";
@@ -293,9 +297,9 @@ public class Step2 extends Step {
}
protected GenericVnf getResourceVnf() {
- verifyNotNull(TARGET_INFO_MSG, params.getTarget());
+ verifyNotNull(TARGET_INFO_MSG, params.getTargetEntityIds());
- String resourceId = params.getTarget().getResourceID();
+ String resourceId = params.getTargetEntityIds().get(TARGET_RESOURCE_ID);
verifyNotNull("Target resource ID", resourceId);
@@ -323,11 +327,11 @@ public class Step2 extends Step {
}
protected GenericVnf getVnf() {
- verifyNotNull(TARGET_INFO_MSG, params.getTarget());
+ verifyNotNull(TARGET_INFO_MSG, params.getTargetEntityIds());
- String modelInvariantId = params.getTarget().getModelInvariantId();
+ String modelInvariantId = params.getTargetEntityIds().get(TARGET_MODEL_INVARIANT_ID);
- verifyNotNull("modelInvariantId", modelInvariantId);
+ verifyNotNull(TARGET_MODEL_INVARIANT_ID, modelInvariantId);
AaiCqResponse aaicq = getCustomQueryData();
return aaicq.getGenericVnfByVfModuleModelInvariantId(modelInvariantId);
@@ -359,11 +363,11 @@ public class Step2 extends Step {
return stepContext.getProperty(OperationProperties.DATA_VF_COUNT);
}
- verifyNotNull(TARGET_INFO_MSG, params.getTarget());
+ verifyNotNull(TARGET_INFO_MSG, params.getTargetEntityIds());
- String modelCustomizationId = params.getTarget().getModelCustomizationId();
- String modelInvariantId = params.getTarget().getModelInvariantId();
- String modelVersionId = params.getTarget().getModelVersionId();
+ String modelCustomizationId = params.getTargetEntityIds().get(TARGET_MODEL_CUSTOMIZATION_ID);
+ String modelInvariantId = params.getTargetEntityIds().get(TARGET_MODEL_INVARIANT_ID);
+ String modelVersionId = params.getTargetEntityIds().get(TARGET_MODEL_VERSION_ID);
verifyNotNull("target modelCustomizationId", modelCustomizationId);
verifyNotNull("target modelInvariantId", modelInvariantId);
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java
index 238ac3d70..efa27a6ec 100644
--- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java
+++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java
@@ -39,10 +39,9 @@ import org.mockito.MockitoAnnotations;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.eventmanager.StepContext;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
public class GetTargetEntityOperation2Test {
private static final String GENERIC_VNF_ID = "generic-vnf.vnf-id";
@@ -59,7 +58,6 @@ public class GetTargetEntityOperation2Test {
private ControlLoopOperationParams params;
private VirtualControlLoopEvent event;
- private Target target;
private GenericVnf vnf;
private GetTargetEntityOperation2 oper;
@@ -74,13 +72,10 @@ public class GetTargetEntityOperation2Test {
event.setTarget("pnf.pnf-name");
event.setAai(Map.of("pnf.pnf-name", MY_PNF));
- target = new Target();
- target.setType(TargetType.PNF);
-
vnf = new GenericVnf();
vnf.setVnfId(MY_VNF);
- when(params.getTarget()).thenReturn(target);
+ when(params.getTargetType()).thenReturn(TargetType.PNF);
when(params.getActor()).thenReturn(MY_ACTOR);
when(params.getOperation()).thenReturn(MY_OPERATION);
@@ -124,24 +119,12 @@ public class GetTargetEntityOperation2Test {
}
/**
- * Tests detmTarget() when the target is {@code null}.
- */
- @Test
- public void testDetmTargetNull() {
- remakeWithoutData();
- when(params.getTarget()).thenReturn(null);
-
- assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
- .withMessage("The target is null");
- }
-
- /**
* Tests detmTarget() when the target type is {@code null}.
*/
@Test
public void testDetmTargetNullType() {
remakeWithoutData();
- target.setType(null);
+ when(params.getTargetType()).thenReturn(null);
assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
.withMessage("The target type is null");
@@ -152,7 +135,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmTargetVm() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
enrichTarget(VSERVER_NAME);
assertThat(oper.getPropertyNames()).isEmpty();
verifyTarget(MY_VNF);
@@ -163,7 +146,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmTargetVnf() {
- target.setType(TargetType.VNF);
+ when(params.getTargetType()).thenReturn(TargetType.VNF);
enrichTarget(VSERVER_NAME);
assertThat(oper.getPropertyNames()).isEmpty();
verifyTarget(MY_VNF);
@@ -175,7 +158,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmTargetVfModule() {
- target.setType(TargetType.VFMODULE);
+ when(params.getTargetType()).thenReturn(TargetType.VFMODULE);
enrichTarget(VSERVER_NAME);
assertThat(oper.getPropertyNames()).isEmpty();
verifyTarget(MY_VNF);
@@ -186,7 +169,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmTargetUnknownType() {
- target.setType(TargetType.VFC);
+ when(params.getTargetType()).thenReturn(TargetType.VFC);
enrichTarget(VSERVER_NAME);
assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
.withMessage("The target type is not supported");
@@ -223,7 +206,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVfModuleTargetNullTarget() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
event.setTarget(null);
assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames()).withMessage("Target is null");
}
@@ -233,7 +216,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVfModuleTargetVserverName() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
enrichTarget(VSERVER_NAME);
assertThat(oper.getPropertyNames()).isEmpty();
verifyTarget(MY_VNF);
@@ -244,7 +227,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVfModuleTargetVnfId() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
enrichTarget(GENERIC_VNF_ID);
assertThat(oper.getPropertyNames()).isEmpty();
verifyTarget(MY_VNF);
@@ -256,7 +239,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVfModuleTargetVnfName() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
enrichTarget(GENERIC_VNF_ID);
// set this AFTER setting enrichment data
@@ -271,7 +254,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVfModuleTargetUnknown() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
enrichTarget(VSERVER_NAME);
event.setTarget("unknown-vnf");
assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
@@ -283,7 +266,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVfModuleTargetMissingEnrichment() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
event.setTarget(VSERVER_NAME);
assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
.withMessage("Enrichment data is missing " + VSERVER_NAME);
@@ -294,7 +277,7 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVnfNameHaveData() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
event.setTarget(GENERIC_VNF_NAME);
event.setAai(Map.of(GENERIC_VNF_ID, MY_VNF));
assertThat(oper.getPropertyNames()).isEmpty();
@@ -306,14 +289,14 @@ public class GetTargetEntityOperation2Test {
*/
@Test
public void testDetmVnfNameNoData() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
event.setTarget(GENERIC_VNF_NAME);
assertThat(oper.getPropertyNames()).isEqualTo(List.of(UsecasesConstants.AAI_DEFAULT_GENERIC_VNF));
}
@Test
public void testSetProperty() {
- target.setType(TargetType.VM);
+ when(params.getTargetType()).thenReturn(TargetType.VM);
event.setTarget(GENERIC_VNF_NAME);
// not a property of interest - should be ignored
@@ -336,7 +319,7 @@ public class GetTargetEntityOperation2Test {
}
private void remakeWithoutData() {
- target.setType(TargetType.VNF);
+ when(params.getTargetType()).thenReturn(TargetType.VNF);
event.setTarget(GENERIC_VNF_NAME);
oper = new GetTargetEntityOperation2(stepContext, event, params);
}
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java
index dfbedc2c7..42fd9e4e4 100644
--- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java
+++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java
@@ -39,10 +39,9 @@ import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.eventmanager.StepContext;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
public class LockOperation2Test {
private static final String MY_PNF = "my-pnf";
@@ -56,7 +55,6 @@ public class LockOperation2Test {
private ControlLoopOperationParams params;
private VirtualControlLoopEvent event;
- private Target target;
private CompletableFuture<OperationOutcome> future;
private GenericVnf vnf;
private LockOperation2 oper;
@@ -72,9 +70,6 @@ public class LockOperation2Test {
event.setTarget("pnf.pnf-name");
event.setAai(Map.of("pnf.pnf-name", MY_PNF));
- target = new Target();
- target.setType(TargetType.PNF);
-
future = new CompletableFuture<>();
vnf = new GenericVnf();
@@ -82,7 +77,7 @@ public class LockOperation2Test {
when(stepContext.requestLock(anyString())).thenReturn(future);
- when(params.getTarget()).thenReturn(target);
+ when(params.getTargetType()).thenReturn(TargetType.PNF);
when(params.getActor()).thenReturn(MY_ACTOR);
when(params.getOperation()).thenReturn(MY_OPERATION);
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java
index 05bc03a60..6681c3ef3 100644
--- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java
+++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java
@@ -66,19 +66,18 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
+import org.onap.policy.controlloop.actorserviceprovider.OperationFinalResult;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.Operator;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ActorConstants;
import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager2;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
-import org.onap.policy.controlloop.policy.FinalResult;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.drools.apps.controller.usecases.UsecasesEventManager.NewEventStatus;
import org.onap.policy.drools.apps.controller.usecases.step.AaiCqStep2;
import org.onap.policy.drools.apps.controller.usecases.step.AaiGetPnfStep2;
@@ -137,7 +136,6 @@ public class UsecasesEventManagerTest {
private Step2 stepb;
private List<LockImpl> locks;
- private Target target;
private ToscaPolicy tosca;
private ControlLoopParams params;
private VirtualControlLoopEvent event;
@@ -163,10 +161,7 @@ public class UsecasesEventManagerTest {
event.setAai(new TreeMap<>(Map.of(UsecasesConstants.VSERVER_VSERVER_NAME, MY_TARGET)));
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setClosedLoopControlName(CL_NAME);
- event.setTargetType(TargetType.VNF.toString());
-
- target = new Target();
- target.setType(TargetType.VNF);
+ event.setTargetType(ControlLoopTargetType.VNF);
params = new ControlLoopParams();
params.setClosedLoopControlName(CL_NAME);
@@ -299,14 +294,14 @@ public class UsecasesEventManagerTest {
@Test
public void testAbort() {
- mgr.abort(UsecasesEventManager.State.DONE, FinalResult.FINAL_FAILURE_GUARD, "some message");
+ mgr.abort(UsecasesEventManager.State.DONE, OperationFinalResult.FINAL_FAILURE_GUARD, "some message");
assertEquals(UsecasesEventManager.State.DONE, mgr.getState());
- assertEquals(FinalResult.FINAL_FAILURE_GUARD, mgr.getFinalResult());
+ assertEquals(OperationFinalResult.FINAL_FAILURE_GUARD, mgr.getFinalResult());
assertEquals("some message", mgr.getFinalMessage());
// try null state
- assertThatThrownBy(() -> mgr.abort(null, FinalResult.FINAL_FAILURE_GUARD, ""))
+ assertThatThrownBy(() -> mgr.abort(null, OperationFinalResult.FINAL_FAILURE_GUARD, ""))
.isInstanceOf(NullPointerException.class).hasMessageContaining("finalState");
}
@@ -325,7 +320,7 @@ public class UsecasesEventManagerTest {
mgr.addToHistory(outcome);
// indicate success and load next policy
- mgr.loadNextPolicy(PolicyResult.SUCCESS);
+ mgr.loadNextPolicy(OperationResult.SUCCESS);
assertEquals("OperationB", mgr.getSteps().poll().getOperationName());
assertNull(mgr.getFinalResult());
@@ -334,8 +329,8 @@ public class UsecasesEventManagerTest {
assertThat(mgr.getFullHistory()).hasSize(1);
// indicate failure - should go to final failure
- mgr.loadNextPolicy(PolicyResult.FAILURE);
- assertEquals(FinalResult.FINAL_FAILURE, mgr.getFinalResult());
+ mgr.loadNextPolicy(OperationResult.FAILURE);
+ assertEquals(OperationFinalResult.FINAL_FAILURE, mgr.getFinalResult());
}
@Test
@@ -354,7 +349,8 @@ public class UsecasesEventManagerTest {
assertSame(actors, params2.getActorService());
assertSame(REQ_ID, params2.getRequestId());
assertSame(ForkJoinPool.commonPool(), params2.getExecutor());
- assertNotNull(params2.getTarget());
+ assertNotNull(params2.getTargetType());
+ assertNotNull(params2.getTargetEntityIds());
assertEquals(Integer.valueOf(300), params2.getTimeoutSec());
assertEquals(Integer.valueOf(0), params2.getRetry());
assertThat(params2.getPayload()).isEmpty();
@@ -508,7 +504,10 @@ public class UsecasesEventManagerTest {
*/
@Test
public void testLoadPreprocessorStepsNeedTargetEntity() {
- stepa = new Step2(mgr, ControlLoopOperationParams.builder().target(target).build(), event) {
+ stepa = new Step2(mgr,
+ ControlLoopOperationParams.builder()
+ .targetType(TargetType.toTargetType(event.getTargetType()))
+ .targetEntityIds(Map.of()).build(), event) {
@Override
public List<String> getPropertyNames() {
return List.of(OperationProperties.AAI_TARGET_ENTITY);
@@ -586,7 +585,7 @@ public class UsecasesEventManagerTest {
@Test
public void testIsAbort() {
OperationOutcome outcome = makeCompletedOutcome();
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
// closed loop timeout
outcome.setActor(ActorConstants.CL_TIMEOUT_ACTOR);
@@ -597,7 +596,7 @@ public class UsecasesEventManagerTest {
assertTrue(mgr.isAbort(outcome));
// no effect for success
- outcome.setResult(PolicyResult.SUCCESS);
+ outcome.setResult(OperationResult.SUCCESS);
assertFalse(mgr.isAbort(outcome));
}
@@ -673,7 +672,7 @@ public class UsecasesEventManagerTest {
assertThat(notif.getHistory()).hasSize(3);
// indicate success and load the next policy - should clear the partial history
- mgr.loadNextPolicy(PolicyResult.SUCCESS);
+ mgr.loadNextPolicy(OperationResult.SUCCESS);
// check notification
notif = mgr.makeNotification();
@@ -691,7 +690,7 @@ public class UsecasesEventManagerTest {
assertThat(notif.getHistory()).hasSize(2);
// indicate failure - should go to final state
- mgr.loadNextPolicy(PolicyResult.FAILURE);
+ mgr.loadNextPolicy(OperationResult.FAILURE);
// check notification
notif = mgr.makeNotification();
@@ -1016,7 +1015,7 @@ public class UsecasesEventManagerTest {
outcome.setActor(SIMPLE_ACTOR);
outcome.setOperation(SIMPLE_OPERATION);
outcome.setMessage(OUTCOME_MSG);
- outcome.setResult(PolicyResult.SUCCESS);
+ outcome.setResult(OperationResult.SUCCESS);
outcome.setStart(Instant.now());
outcome.setTarget(MY_TARGET);
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java
index 75fe486ed..d01e2b5a0 100644
--- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java
+++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -62,26 +63,21 @@ import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.Operator;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager2;
import org.onap.policy.controlloop.eventmanager.StepContext;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.drools.apps.controller.usecases.UsecasesConstants;
public class Step2Test {
private static final UUID REQ_ID = UUID.randomUUID();
- private static final String POLICY_ID = "my-policy";
private static final String POLICY_ACTOR = "my-actor";
private static final String POLICY_OPERATION = "my-operation";
private static final String MY_TARGET = "my-target";
private static final String PAYLOAD_KEY = "payload-key";
private static final String PAYLOAD_VALUE = "payload-value";
- private static final Integer POLICY_RETRY = 3;
- private static final Integer POLICY_TIMEOUT = 20;
private static final String NO_SLASH = "noslash";
private static final String ONE_SLASH = "/one";
@@ -99,9 +95,7 @@ public class Step2Test {
private AaiCqResponse aaicq;
private CompletableFuture<OperationOutcome> future;
- private Target target;
private Map<String, String> payload;
- private Policy policy;
private VirtualControlLoopEvent event;
private ControlLoopEventContext context;
private BlockingQueue<OperationOutcome> starts;
@@ -128,20 +122,8 @@ public class Step2Test {
when(stepContext.getProperty(AaiCqResponse.CONTEXT_KEY)).thenReturn(aaicq);
- target = new Target();
- target.setType(TargetType.VM);
-
payload = Map.of(PAYLOAD_KEY, PAYLOAD_VALUE);
- policy = new Policy();
- policy.setId(POLICY_ID);
- policy.setActor(POLICY_ACTOR);
- policy.setRecipe(POLICY_OPERATION);
- policy.setTarget(target);
- policy.setPayload(payload);
- policy.setRetry(POLICY_RETRY);
- policy.setTimeout(POLICY_TIMEOUT);
-
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
event.setTarget(ControlLoopOperationManager2.VSERVER_VSERVER_NAME);
@@ -152,10 +134,13 @@ public class Step2Test {
starts = new LinkedBlockingQueue<>();
completions = new LinkedBlockingQueue<>();
+ Map<String, String> entityIds = new HashMap<>();
+
params = ControlLoopOperationParams.builder().actor(POLICY_ACTOR).actorService(actors)
.completeCallback(completions::add).context(context).executor(ForkJoinPool.commonPool())
.operation(POLICY_OPERATION).payload(new TreeMap<>(payload)).startCallback(starts::add)
- .target(target).targetEntity(MY_TARGET).build();
+ .targetType(TargetType.VM).targetEntityIds(entityIds).targetEntity(MY_TARGET)
+ .build();
step = new Step2(stepContext, params, event);
step.init();
@@ -268,7 +253,7 @@ public class Step2Test {
@Test
public void testLoadResourceVnf_testGetResourceVnf() {
- target.setResourceID("my-resource");
+ params.getTargetEntityIds().put(Step2.TARGET_RESOURCE_ID, "my-resource");
GenericVnf data = new GenericVnf();
when(aaicq.getGenericVnfByModelInvariantId("my-resource")).thenReturn(data);
when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_RESOURCE_VNF));
@@ -277,12 +262,12 @@ public class Step2Test {
verify(policyOperation).setProperty(OperationProperties.AAI_RESOURCE_VNF, data);
// missing resource ID
- target.setResourceID(null);
+ params.getTargetEntityIds().put(Step2.TARGET_RESOURCE_ID, null);
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())
.withMessageContaining("missing Target resource ID");
- // missing target
- params = params.toBuilder().target(null).build();
+ // missing target entity IDs
+ params = params.toBuilder().targetEntityIds(null).build();
step = new Step2(stepContext, params, event);
step.init();
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())
@@ -315,7 +300,7 @@ public class Step2Test {
@Test
public void testLoadVnf_testGetVnf() {
- target.setModelInvariantId("my-model-invariant");
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, "my-model-invariant");
GenericVnf data = new GenericVnf();
when(aaicq.getGenericVnfByVfModuleModelInvariantId("my-model-invariant")).thenReturn(data);
when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_VNF));
@@ -324,12 +309,12 @@ public class Step2Test {
verify(policyOperation).setProperty(OperationProperties.AAI_VNF, data);
// missing model invariant ID
- target.setModelInvariantId(null);
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, null);
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())
.withMessageContaining("missing modelInvariantId");
// missing target
- params = params.toBuilder().target(null).build();
+ params = params.toBuilder().targetEntityIds(null).build();
step = new Step2(stepContext, params, event);
step.init();
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())
@@ -338,7 +323,7 @@ public class Step2Test {
@Test
public void testLoadVnfModel_testGetVnfModel() {
- target.setModelInvariantId("my-model-invariant");
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, "my-model-invariant");
GenericVnf vnf = new GenericVnf();
when(aaicq.getGenericVnfByVfModuleModelInvariantId("my-model-invariant")).thenReturn(vnf);
@@ -388,9 +373,9 @@ public class Step2Test {
@Test
public void testLoadVfCount_testGetVfCount() {
- target.setModelCustomizationId("vf-count-customization");
- target.setModelInvariantId("vf-count-invariant");
- target.setModelVersionId("vf-count-version");
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_CUSTOMIZATION_ID, "vf-count-customization");
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, "vf-count-invariant");
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_VERSION_ID, "vf-count-version");
when(aaicq.getVfModuleCount("vf-count-customization", "vf-count-invariant", "vf-count-version")).thenReturn(11);
when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.DATA_VF_COUNT));
@@ -398,22 +383,22 @@ public class Step2Test {
verify(policyOperation).setProperty(OperationProperties.DATA_VF_COUNT, 11);
// missing model version id
- target.setModelVersionId(null);
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_VERSION_ID, null);
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())
.withMessageContaining("missing target modelVersionId");
// missing model invariant id
- target.setModelInvariantId(null);
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, null);
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())
.withMessageContaining("missing target modelInvariantId");
// missing model customization id
- target.setModelCustomizationId(null);
+ params.getTargetEntityIds().put(Step2.TARGET_MODEL_CUSTOMIZATION_ID, null);
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())
.withMessageContaining("missing target modelCustomizationId");
// missing target
- params = params.toBuilder().target(null).build();
+ params = params.toBuilder().targetEntityIds(null).build();
step = new Step2(stepContext, params, event);
step.init();
assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties())