aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-26 16:57:52 -0400
committerPamela Dragosh <pdragosh@research.att.com>2020-08-27 14:29:28 -0400
commit3052f10337897ea25983f35f4158c5626febbe7d (patch)
tree19da96c57189c04f1b6dd8cf17702b7ff36f367f /controlloop/common/eventmanager/src
parent14c9b3e48963d9283d77d140bcbe1ee4d4d24200 (diff)
Use ToscaPolicy instead of legacy Policy
Removed usage of policy-yaml and old targetType definition. Switched to using TOSCA operational policy classes and new definitions for Target type enum. Issue-ID: POLICY-2428 Change-Id: I25d1c5219764df27bdae7f2cbeb7ada7bcef4e1e Signed-off-by: Jim Hahn <jrh3@att.com> Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java6
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java16
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java71
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/LockData.java6
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java155
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java10
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java45
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java12
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java105
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java1
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java6
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java46
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java42
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java2
-rw-r--r--controlloop/common/eventmanager/src/test/resources/badtriggerpolicy.yaml105
-rw-r--r--controlloop/common/eventmanager/src/test/resources/nopolicy.yaml37
-rw-r--r--controlloop/common/eventmanager/src/test/resources/test.yaml105
17 files changed, 333 insertions, 437 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index 5cf087abd..c0116c952 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -178,7 +178,7 @@ public class ControlLoopEventManager implements StepContext, Serializable {
*/
private long detmControlLoopTimeoutMs() {
// validation checks preclude null or 0 timeout values in the policy
- Integer timeout = processor.getControlLoop().getTimeout();
+ Integer timeout = processor.getPolicy().getProperties().getTimeout();
return TimeUnit.MILLISECONDS.convert(timeout, TimeUnit.SECONDS);
}
@@ -221,6 +221,7 @@ public class ControlLoopEventManager implements StepContext, Serializable {
* @param name name of the property of interest
* @return {@code true} if the context contains the property, {@code false} otherwise
*/
+ @Override
public boolean contains(String name) {
return properties.containsKey(name);
}
@@ -232,6 +233,7 @@ public class ControlLoopEventManager implements StepContext, Serializable {
* @param name name of the property whose value is to be retrieved
* @return the property's value, or {@code null} if it does not yet have a value
*/
+ @Override
@SuppressWarnings("unchecked")
public <T> T getProperty(String name) {
return (T) properties.get(name);
@@ -243,6 +245,7 @@ public class ControlLoopEventManager implements StepContext, Serializable {
* @param name property name
* @param value new property value
*/
+ @Override
public void setProperty(String name, Serializable value) {
logger.error("set property {}={} manager={}", name, value, this);
properties.put(name, value);
@@ -253,6 +256,7 @@ public class ControlLoopEventManager implements StepContext, Serializable {
*
* @param name property name
*/
+ @Override
public void removeProperty(String name) {
properties.remove(name);
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
index 5f611c098..556fa31d5 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
@@ -54,14 +54,14 @@ import org.onap.policy.controlloop.ControlLoopResponse;
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.OperationFinalResult;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
-import org.onap.policy.controlloop.policy.FinalResult;
-import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.processor.ControlLoopProcessor;
import org.onap.policy.drools.core.lock.LockCallback;
+import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -151,7 +151,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
private final ControlLoopProcessor processor;
private final AtomicReference<ControlLoopOperationManager2> currentOperation = new AtomicReference<>();
- private FinalResult finalResult = null;
+ private OperationFinalResult finalResult = null;
@Getter
private VirtualControlLoopNotification notification;
@@ -289,7 +289,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
} catch (ControlLoopException | RuntimeException e) {
// processor problem - this is fatal
logger.warn("{}: cannot start next step for {}", closedLoopControlName, requestId, e);
- finalResult = FinalResult.FINAL_FAILURE_EXCEPTION;
+ finalResult = OperationFinalResult.FINAL_FAILURE_EXCEPTION;
controlLoopResponse = null;
notification = makeNotification();
notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
@@ -363,7 +363,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
notification.setMessage("Control Loop timed out");
notification.setHistory(controlLoopHistory);
- finalResult = FinalResult.FINAL_FAILURE;
+ finalResult = OperationFinalResult.FINAL_FAILURE;
break;
case OPERATION_FAILURE:
@@ -460,7 +460,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
*/
private long detmControlLoopTimeoutMs() {
// validation checks preclude null or 0 timeout values in the policy
- Integer timeout = processor.getControlLoop().getTimeout();
+ Integer timeout = processor.getPolicy().getProperties().getTimeout();
return TimeUnit.MILLISECONDS.convert(timeout, TimeUnit.SECONDS);
}
@@ -612,8 +612,8 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
// the following methods may be overridden by junit tests
- protected ControlLoopOperationManager2 makeOperationManager(ControlLoopEventContext ctx, Policy policy) {
- return new ControlLoopOperationManager2(this, ctx, policy, getExecutor());
+ protected ControlLoopOperationManager2 makeOperationManager(ControlLoopEventContext ctx, Operation operation) {
+ return new ControlLoopOperationManager2(this, ctx, operation, getExecutor());
}
protected Executor getExecutor() {
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
index 7672622d3..31402f4cf 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
@@ -28,6 +28,7 @@ import java.time.Instant;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedDeque;
@@ -46,11 +47,12 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actor.guard.GuardActor;
import org.onap.policy.controlloop.actor.sdnr.SdnrActor;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
+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.pipeline.PipelineUtil;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.drools.domain.models.operational.OperationalTarget;
import org.onap.policy.sdnr.PciMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -90,7 +92,7 @@ public class ControlLoopOperationManager2 implements Serializable {
private final transient ManagerContext operContext;
private final transient ControlLoopEventContext eventContext;
- private final Policy policy;
+ private final org.onap.policy.drools.domain.models.operational.Operation policy;
@Getter
@ToString.Include
@@ -156,25 +158,35 @@ public class ControlLoopOperationManager2 implements Serializable {
@Getter
private final String operation;
+ private final String targetStr;
+ private final OperationalTarget target;
+
/**
* Construct an instance.
*
* @param operContext this operation's context
* @param context event context
- * @param policy operation's policy
+ * @param operation2 operation's policy
* @param executor executor for the Operation
*/
- public ControlLoopOperationManager2(ManagerContext operContext, ControlLoopEventContext context, Policy policy,
- Executor executor) {
+ public ControlLoopOperationManager2(ManagerContext operContext, ControlLoopEventContext context,
+ org.onap.policy.drools.domain.models.operational.Operation operation2, Executor executor) {
this.operContext = operContext;
this.eventContext = context;
- this.policy = policy;
+ this.policy = operation2;
this.requestId = context.getEvent().getRequestId().toString();
- this.policyId = "" + policy.getId();
- this.actor = policy.getActor();
- this.operation = policy.getRecipe();
+ this.policyId = "" + operation2.getId();
+ this.actor = operation2.getActorOperation().getActor();
+ this.operation = operation2.getActorOperation().getOperation();
+ this.target = operation2.getActorOperation().getTarget();
+
+ String targetType = (target != null ? target.getTargetType() : null);
+ Map<String, String> entityIds = (target != null ? target.getEntityIds() : null);
+
+ // TODO encode()?
+ this.targetStr = (target != null ? target.toString() : null);
// @formatter:off
params = ControlLoopOperationParams.builder()
@@ -183,7 +195,8 @@ public class ControlLoopOperationManager2 implements Serializable {
.operation(operation)
.context(context)
.executor(executor)
- .target(policy.getTarget())
+ .targetType(TargetType.toTargetType(targetType))
+ .targetEntityIds(entityIds)
.startCallback(this::onStart)
.completeCallback(this::onComplete)
.build();
@@ -201,7 +214,7 @@ public class ControlLoopOperationManager2 implements Serializable {
private static final long serialVersionUID = 1L;
private int attempt;
- private PolicyResult policyResult;
+ private OperationResult policyResult;
private ControlLoopOperation clOperation;
private ControlLoopResponse clResponse;
@@ -214,7 +227,7 @@ public class ControlLoopOperationManager2 implements Serializable {
attempt = ControlLoopOperationManager2.this.attempts;
policyResult = outcome.getResult();
clOperation = outcome.toControlLoopOperation();
- clOperation.setTarget(policy.getTarget().toString());
+ clOperation.setTarget(targetStr);
clResponse = makeControlLoopResponse(outcome);
if (outcome.getEnd() == null) {
@@ -268,14 +281,14 @@ public class ControlLoopOperationManager2 implements Serializable {
// @formatter:off
ControlLoopOperationParams params2 = params.toBuilder()
.payload(new LinkedHashMap<>())
- .retry(policy.getRetry())
+ .retry(policy.getRetries())
.timeoutSec(policy.getTimeout())
.targetEntity(targetEntity)
.build();
// @formatter:on
- if (policy.getPayload() != null) {
- params2.getPayload().putAll(policy.getPayload());
+ if (policy.getActorOperation().getPayload() != null) {
+ params2.getPayload().putAll(policy.getActorOperation().getPayload());
}
return params2.start();
@@ -481,28 +494,28 @@ public class ControlLoopOperationManager2 implements Serializable {
case CL_TIMEOUT_ACTOR:
state = State.CONTROL_LOOP_TIMEOUT;
- processAbort(outcome, PolicyResult.FAILURE, "Control loop timed out");
+ processAbort(outcome, OperationResult.FAILURE, "Control loop timed out");
break;
case LOCK_ACTOR:
// lock is no longer available
if (state == State.ACTIVE) {
state = State.LOCK_DENIED;
- storeFailureInDataBase(outcome, PolicyResult.FAILURE_GUARD, "Operation denied by Lock");
+ storeFailureInDataBase(outcome, OperationResult.FAILURE_GUARD, "Operation denied by Lock");
} else {
state = State.LOCK_LOST;
- processAbort(outcome, PolicyResult.FAILURE, "Operation aborted by Lock");
+ processAbort(outcome, OperationResult.FAILURE, "Operation aborted by Lock");
}
break;
case GUARD_ACTOR:
if (outcome.getEnd() == null) {
state = State.GUARD_STARTED;
- } else if (outcome.getResult() == PolicyResult.SUCCESS) {
+ } else if (outcome.getResult() == OperationResult.SUCCESS) {
state = State.GUARD_PERMITTED;
} else {
state = State.GUARD_DENIED;
- storeFailureInDataBase(outcome, PolicyResult.FAILURE_GUARD, "Operation denied by Guard");
+ storeFailureInDataBase(outcome, OperationResult.FAILURE_GUARD, "Operation denied by Guard");
}
break;
@@ -517,7 +530,7 @@ public class ControlLoopOperationManager2 implements Serializable {
* Operation completed. If the last entry was a "start" (i.e., "end" field
* is null), then replace it. Otherwise, just add the completion.
*/
- state = (outcome.getResult() == PolicyResult.SUCCESS ? State.OPERATION_SUCCESS
+ state = (outcome.getResult() == OperationResult.SUCCESS ? State.OPERATION_SUCCESS
: State.OPERATION_FAILURE);
controlLoopResponse = makeControlLoopResponse(outcome);
if (!operationHistory.isEmpty() && operationHistory.peekLast().getClOperation().getEnd() == null) {
@@ -542,7 +555,7 @@ public class ControlLoopOperationManager2 implements Serializable {
* @param result result to put into the DB
* @param message message to put into the DB
*/
- private void processAbort(OperationOutcome outcome, PolicyResult result, String message) {
+ private void processAbort(OperationOutcome outcome, OperationResult result, String message) {
if (operationHistory.isEmpty() || operationHistory.peekLast().getClOperation().getEnd() != null) {
// last item was not a "start" operation
@@ -612,9 +625,9 @@ public class ControlLoopOperationManager2 implements Serializable {
*
* @return the operation result
*/
- public PolicyResult getOperationResult() {
+ public OperationResult getOperationResult() {
Operation last = operationHistory.peekLast();
- return (last == null ? PolicyResult.FAILURE_EXCEPTION : last.getPolicyResult());
+ return (last == null ? OperationResult.FAILURE_EXCEPTION : last.getPolicyResult());
}
/**
@@ -652,7 +665,7 @@ public class ControlLoopOperationManager2 implements Serializable {
* @param result result to put into the DB
* @param message message to put into the DB
*/
- private void storeFailureInDataBase(OperationOutcome outcome, PolicyResult result, String message) {
+ private void storeFailureInDataBase(OperationOutcome outcome, OperationResult result, String message) {
// don't include this in history yet
holdLast = true;
@@ -680,15 +693,15 @@ public class ControlLoopOperationManager2 implements Serializable {
* already been determined
*/
protected CompletableFuture<OperationOutcome> detmTarget() {
- if (policy.getTarget() == null) {
+ if (target == null) {
throw new IllegalArgumentException("The target is null");
}
- if (policy.getTarget().getType() == null) {
+ if (target.getTargetType() == null) {
throw new IllegalArgumentException("The target type is null");
}
- switch (policy.getTarget().getType()) {
+ switch (TargetType.toTargetType(target.getTargetType())) {
case PNF:
return detmPnfTarget();
case VM:
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/LockData.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/LockData.java
index 835600086..91b5325e2 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/LockData.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/LockData.java
@@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.drools.core.lock.Lock;
import org.onap.policy.drools.core.lock.LockCallback;
import org.slf4j.Logger;
@@ -130,7 +130,7 @@ public class LockData implements LockCallback {
theLock = lock;
OperationOutcome outcome = makeOutcome();
- outcome.setResult(PolicyResult.SUCCESS);
+ outcome.setResult(OperationResult.SUCCESS);
outcome.setMessage(ControlLoopOperation.SUCCESS_MSG);
future.get().complete(outcome);
@@ -141,7 +141,7 @@ public class LockData implements LockCallback {
synchronized (this) {
logger.warn("lock unavailable on {} for {}", targetEntity, requestId);
failedOutcome = makeOutcome();
- failedOutcome.setResult(PolicyResult.FAILURE);
+ failedOutcome.setResult(OperationResult.FAILURE);
failedOutcome.setMessage(ControlLoopOperation.FAILED_MSG);
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
index f578c8a85..153b081a1 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
@@ -21,47 +21,34 @@
package org.onap.policy.controlloop.processor;
import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.util.stream.Collectors;
import lombok.Getter;
-import org.apache.commons.beanutils.BeanUtils;
import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.controlloop.ControlLoopException;
+import org.onap.policy.controlloop.actorserviceprovider.OperationFinalResult;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
-import org.onap.policy.controlloop.policy.ControlLoop;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.FinalResult;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyParam;
-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.domain.models.DroolsPolicy;
import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.drools.domain.models.operational.OperationalPolicy;
-import org.onap.policy.drools.domain.models.operational.OperationalTarget;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
public class ControlLoopProcessor implements Serializable {
private static final long serialVersionUID = 1L;
- private static final Logger logger = LoggerFactory.getLogger(ControlLoopProcessor.class);
+
+ private static final StandardYamlCoder coder = new StandardYamlCoder();
@Getter
- private final ControlLoopPolicy policy;
+ private final OperationalPolicy policy;
private String currentNestedPolicyId;
// not serializable, thus must be transient
@Getter
private transient ToscaPolicy toscaOpPolicy;
- // not serializable, thus must be transient
- @Getter
- private transient DroolsPolicy domainOpPolicy;
+ //@Getter
+ //private ControlLoop controlLoop;
/**
* Construct an instance from yaml.
@@ -70,19 +57,7 @@ public class ControlLoopProcessor implements Serializable {
* @throws ControlLoopException if an error occurs
*/
public ControlLoopProcessor(String yaml) throws ControlLoopException {
- try {
- final Yaml y = new Yaml(new CustomClassLoaderConstructor(ControlLoopPolicy.class,
- ControlLoopPolicy.class.getClassLoader()));
- final Object obj = y.load(yaml);
-
- this.policy = (ControlLoopPolicy) obj;
- this.currentNestedPolicyId = this.policy.getControlLoop().getTrigger_policy();
- } catch (final Exception e) {
- //
- // Most likely this is a YAML Exception
- //
- throw new ControlLoopException(e);
- }
+ this(decodeTosca(yaml));
}
/**
@@ -90,72 +65,30 @@ public class ControlLoopProcessor implements Serializable {
*/
public ControlLoopProcessor(ToscaPolicy toscaPolicy) throws ControlLoopException {
try {
- this.policy = buildPolicyFromToscaCompliant(toscaPolicy);
-
- this.currentNestedPolicyId = this.policy.getControlLoop().getTrigger_policy();
+ this.policy =
+ PolicyEngineConstants.getManager().getDomainMaker().convertTo(toscaPolicy, OperationalPolicy.class);
+ this.currentNestedPolicyId = this.policy.getProperties().getTrigger();
this.toscaOpPolicy = toscaPolicy;
} catch (RuntimeException | CoderException e) {
throw new ControlLoopException(e);
}
}
- private Target toStandardTarget(OperationalTarget opTarget) {
- Target target = new Target(TargetType.valueOf(opTarget.getTargetType()));
+ private static ToscaPolicy decodeTosca(String yaml) throws ControlLoopException {
try {
- BeanUtils.populate(target, opTarget.getEntityIds());
- } catch (IllegalAccessException | InvocationTargetException e) {
- logger.warn("target entityIds cannot be mapped (unexpected): {}", opTarget, e);
- }
- return target;
- }
-
- protected ControlLoopPolicy buildPolicyFromToscaCompliant(ToscaPolicy policy) throws CoderException {
- OperationalPolicy domainPolicy =
- PolicyEngineConstants.getManager().getDomainMaker().convertTo(policy, OperationalPolicy.class);
-
- ControlLoopPolicy backwardsCompatiblePolicy = new ControlLoopPolicy();
-
- // @formatter:off
- backwardsCompatiblePolicy.setPolicies(
- domainPolicy.getProperties().getOperations().stream().map(this::convertPolicy)
- .collect(Collectors.toList()));
- // @formatter:on
-
- ControlLoop controlLoop = new ControlLoop();
- controlLoop.setAbatement(domainPolicy.getProperties().isAbatement());
- controlLoop.setControlLoopName(domainPolicy.getProperties().getId());
- controlLoop.setTimeout(domainPolicy.getProperties().getTimeout());
- controlLoop.setTrigger_policy(domainPolicy.getProperties().getTrigger());
- controlLoop.setVersion(domainPolicy.getVersion());
+ ToscaServiceTemplate template = coder.decode(yaml, ToscaServiceTemplate.class);
+ if (template == null || template.getToscaTopologyTemplate() == null) {
+ throw new IllegalArgumentException("Cannot decode yaml into ToscaServiceTemplate");
+ }
- backwardsCompatiblePolicy.setControlLoop(controlLoop);
- this.domainOpPolicy = domainPolicy;
- return backwardsCompatiblePolicy;
- }
+ return template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
- private Policy convertPolicy(Operation operation) {
- // @formatter:off
- Policy newPolicy = new Policy(PolicyParam.builder()
- .id(operation.getId())
- .name(operation.getActorOperation().getOperation())
- .description(operation.getDescription())
- .actor(operation.getActorOperation().getActor())
- .payload(operation.getActorOperation().getPayload())
- .recipe(operation.getActorOperation().getOperation())
- .retries(operation.getRetries())
- .timeout(operation.getTimeout())
- .target(toStandardTarget(operation.getActorOperation().getTarget()))
- .build());
- // @formatter:on
-
- newPolicy.setSuccess(operation.getSuccess());
- newPolicy.setFailure(operation.getFailure());
- newPolicy.setFailure_exception(operation.getFailureException());
- newPolicy.setFailure_guard(operation.getFailureGuard());
- newPolicy.setFailure_retries(operation.getFailureRetries());
- newPolicy.setFailure_timeout(operation.getFailureTimeout());
-
- return newPolicy;
+ } catch (final Exception e) {
+ //
+ // Most likely this is a YAML Exception
+ //
+ throw new ControlLoopException(e);
+ }
}
/**
@@ -164,21 +97,17 @@ public class ControlLoopProcessor implements Serializable {
public ControlLoopParams getControlLoopParams() {
ControlLoopParams controlLoopParams = new ControlLoopParams();
- controlLoopParams.setClosedLoopControlName(this.getControlLoop().getControlLoopName());
- controlLoopParams.setPolicyScope(domainOpPolicy.getType() + ":" + domainOpPolicy.getTypeVersion());
- controlLoopParams.setPolicyName(domainOpPolicy.getName());
- controlLoopParams.setPolicyVersion(domainOpPolicy.getVersion());
+ controlLoopParams.setClosedLoopControlName(this.policy.getProperties().getId());
+ controlLoopParams.setPolicyScope(policy.getType() + ":" + policy.getTypeVersion());
+ controlLoopParams.setPolicyName(policy.getName());
+ controlLoopParams.setPolicyVersion(policy.getVersion());
controlLoopParams.setToscaPolicy(toscaOpPolicy);
return controlLoopParams;
}
- public ControlLoop getControlLoop() {
- return this.policy.getControlLoop();
- }
-
- public FinalResult checkIsCurrentPolicyFinal() {
- return FinalResult.toResult(this.currentNestedPolicyId);
+ public OperationFinalResult checkIsCurrentPolicyFinal() {
+ return OperationFinalResult.toResult(this.currentNestedPolicyId);
}
/**
@@ -187,12 +116,14 @@ public class ControlLoopProcessor implements Serializable {
* @return the current policy
* @throws ControlLoopException if an error occurs
*/
- public Policy getCurrentPolicy() throws ControlLoopException {
- if (this.policy == null || this.policy.getPolicies() == null) {
+ public Operation getCurrentPolicy() throws ControlLoopException {
+ if (this.policy == null || this.policy.getProperties() == null
+ || this.policy.getProperties().getOperations() == null
+ || this.policy.getProperties().getOperations().isEmpty()) {
throw new ControlLoopException("There are no policies defined.");
}
- for (final Policy nestedPolicy : this.policy.getPolicies()) {
+ for (final Operation nestedPolicy : this.policy.getProperties().getOperations()) {
if (nestedPolicy.getId().equals(this.currentNestedPolicyId)) {
return nestedPolicy;
}
@@ -206,8 +137,8 @@ public class ControlLoopProcessor implements Serializable {
* @param result the result of the current policy
* @throws ControlLoopException if an error occurs
*/
- public void nextPolicyForResult(PolicyResult result) throws ControlLoopException {
- final Policy currentPolicy = this.getCurrentPolicy();
+ public void nextPolicyForResult(OperationResult result) throws ControlLoopException {
+ final Operation currentPolicy = this.getCurrentPolicy();
try {
if (currentPolicy == null) {
throw new ControlLoopException("There is no current policy to determine where to go to.");
@@ -220,21 +151,21 @@ public class ControlLoopProcessor implements Serializable {
this.currentNestedPolicyId = currentPolicy.getFailure();
break;
case FAILURE_TIMEOUT:
- this.currentNestedPolicyId = currentPolicy.getFailure_timeout();
+ this.currentNestedPolicyId = currentPolicy.getFailureTimeout();
break;
case FAILURE_RETRIES:
- this.currentNestedPolicyId = currentPolicy.getFailure_retries();
+ this.currentNestedPolicyId = currentPolicy.getFailureRetries();
break;
case FAILURE_EXCEPTION:
- this.currentNestedPolicyId = currentPolicy.getFailure_exception();
+ this.currentNestedPolicyId = currentPolicy.getFailureException();
break;
case FAILURE_GUARD:
default:
- this.currentNestedPolicyId = currentPolicy.getFailure_guard();
+ this.currentNestedPolicyId = currentPolicy.getFailureGuard();
break;
}
} catch (final ControlLoopException e) {
- this.currentNestedPolicyId = FinalResult.FINAL_FAILURE_EXCEPTION.toString();
+ this.currentNestedPolicyId = OperationFinalResult.FINAL_FAILURE_EXCEPTION.toString();
throw e;
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
index 9534f938a..05eba6450 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
@@ -26,7 +26,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
@@ -53,15 +53,15 @@ public final class SupportUtil {
* @return a Pair
* @throws IOException if the file cannot be read
*/
- public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) throws IOException {
+ public static Pair<ToscaPolicy, String> loadYaml(String testFile) throws IOException {
try (InputStream is = new FileInputStream(new File(testFile))) {
String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
//
// Read the yaml into our Java Object
//
- Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- Object obj = yaml.load(contents);
- return new Pair<>((ControlLoopPolicy) obj, contents);
+ Yaml yaml = new Yaml(new Constructor(ToscaPolicy.class));
+ ToscaPolicy obj = yaml.load(contents);
+ return new Pair<>(obj, contents);
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
index 86381ebec..1c4030c08 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
@@ -47,7 +47,6 @@ import java.util.function.Consumer;
import org.drools.core.WorkingMemory;
import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.kie.api.runtime.rule.FactHandle;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
@@ -66,18 +65,16 @@ 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.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager2.NewEventStatus;
import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager2.State;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
-import org.onap.policy.controlloop.policy.Policy;
-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.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
+import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -117,7 +114,6 @@ public class ControlLoopEventManager2Test {
private long preCreateTimeMs;
private List<LockImpl> locks;
- private Target target;
private ToscaPolicy tosca;
private ControlLoopParams params;
private VirtualControlLoopEvent event;
@@ -158,10 +154,7 @@ public class ControlLoopEventManager2Test {
event.setAai(new TreeMap<>(Map.of(ControlLoopOperationManager2.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);
@@ -217,11 +210,11 @@ public class ControlLoopEventManager2Test {
for (ControlLoopOperationManager2 oper : Arrays.asList(oper1, oper2, oper3)) {
assertTrue(mgr.isActive());
- nextStep(oper, true, PolicyResult.SUCCESS);
+ nextStep(oper, true, OperationResult.SUCCESS);
runRule();
assertTrue(mgr.isActive());
- nextStep(oper, false, PolicyResult.SUCCESS);
+ nextStep(oper, false, OperationResult.SUCCESS);
runRule();
}
@@ -257,7 +250,7 @@ public class ControlLoopEventManager2Test {
@Test
public void testNextStep_testStartOperationSuccess() throws ControlLoopException {
- runOperation(PolicyResult.SUCCESS);
+ runOperation(OperationResult.SUCCESS);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notif.getNotification());
@@ -291,7 +284,7 @@ public class ControlLoopEventManager2Test {
*/
@Test
public void testStartOperationException() throws ControlLoopException {
- runOperation(PolicyResult.FAILURE_EXCEPTION);
+ runOperation(OperationResult.FAILURE_EXCEPTION);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notif.getNotification());
@@ -303,7 +296,7 @@ public class ControlLoopEventManager2Test {
*/
@Test
public void testStartOperationFailure() throws ControlLoopException {
- runOperation(PolicyResult.FAILURE);
+ runOperation(OperationResult.FAILURE);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notif.getNotification());
@@ -315,7 +308,7 @@ public class ControlLoopEventManager2Test {
*/
@Test
public void testStartOperationOpenLoop() throws ControlLoopException {
- runOperation(PolicyResult.FAILURE_GUARD);
+ runOperation(OperationResult.FAILURE_GUARD);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_OPENLOOP, notif.getNotification());
@@ -441,7 +434,7 @@ public class ControlLoopEventManager2Test {
mgr.start();
- nextStep(oper1, true, PolicyResult.SUCCESS);
+ nextStep(oper1, true, OperationResult.SUCCESS);
runRule();
// check notification while running
@@ -451,7 +444,7 @@ public class ControlLoopEventManager2Test {
List<ControlLoopOperation> history = notif.getHistory();
assertNotNull(history);
- nextStep(oper1, false, PolicyResult.SUCCESS);
+ nextStep(oper1, false, OperationResult.SUCCESS);
runRule();
assertFalse(mgr.isActive());
@@ -635,7 +628,7 @@ public class ControlLoopEventManager2Test {
event.setAai(addAai(orig, ControlLoopEventManager2.GENERIC_VNF_PROV_STATUS, "ACTIVE"));
assertThatCode(() -> new ControlLoopEventManager2(params, event, workMem)).doesNotThrowAnyException();
-
+
event.setAai(addAai(orig, ControlLoopEventManager2.GENERIC_VNF_PROV_STATUS, "inactive"));
assertThatThrownBy(() -> new ControlLoopEventManager2(params, event, workMem))
.isInstanceOf(IllegalStateException.class);
@@ -701,11 +694,11 @@ public class ControlLoopEventManager2Test {
}
- private void nextStep(ControlLoopOperationManager2 oper, boolean moreSteps, PolicyResult result) {
+ private void nextStep(ControlLoopOperationManager2 oper, boolean moreSteps, OperationResult result) {
when(oper.nextStep()).thenReturn(moreSteps);
when(oper.getOperationResult()).thenReturn(result);
- if (result == PolicyResult.SUCCESS) {
+ if (result == OperationResult.SUCCESS) {
when(oper.getState()).thenReturn(State.OPERATION_SUCCESS);
} else {
when(oper.getState()).thenReturn(State.OPERATION_FAILURE);
@@ -723,13 +716,13 @@ public class ControlLoopEventManager2Test {
mgr.nextStep();
}
- private void runOperation(PolicyResult finalResult) throws ControlLoopException {
+ private void runOperation(OperationResult finalResult) throws ControlLoopException {
mgr.start();
verify(oper1).start(anyLong());
assertTrue(mgr.isActive());
- nextStep(oper1, true, PolicyResult.SUCCESS);
+ nextStep(oper1, true, OperationResult.SUCCESS);
runRule();
nextStep(oper1, false, finalResult);
@@ -814,8 +807,8 @@ public class ControlLoopEventManager2Test {
}
@Override
- protected ControlLoopOperationManager2 makeOperationManager(ControlLoopEventContext ctx, Policy policy) {
- switch (policy.getActor()) {
+ protected ControlLoopOperationManager2 makeOperationManager(ControlLoopEventContext ctx, Operation policy) {
+ switch (policy.getActorOperation().getActor()) {
case "First":
return oper1;
case "Second":
@@ -823,7 +816,7 @@ public class ControlLoopEventManager2Test {
case "Third":
return oper3;
default:
- throw new IllegalArgumentException("unknown policy actor " + policy.getActor());
+ throw new IllegalArgumentException("unknown policy actor " + policy.getActorOperation().getActor());
}
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index 0b37abb14..e4c233281 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -47,10 +47,8 @@ import org.onap.policy.common.utils.io.Serializer;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
-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.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
@@ -73,7 +71,6 @@ public class ControlLoopEventManagerTest {
private long preCreateTimeMs;
private List<LockImpl> locks;
- private Target target;
private ToscaPolicy tosca;
private ControlLoopParams params;
private ControlLoopEventManager mgr;
@@ -85,9 +82,6 @@ public class ControlLoopEventManagerTest {
public void setUp() throws ControlLoopException, CoderException {
MockitoAnnotations.initMocks(this);
- target = new Target();
- target.setType(TargetType.VNF);
-
params = new ControlLoopParams();
params.setClosedLoopControlName(CL_NAME);
params.setPolicyName(POLICY_NAME);
@@ -189,11 +183,11 @@ public class ControlLoopEventManagerTest {
// indicate that the first lock failed
locks.get(0).notifyUnavailable();
- verifyLock(PolicyResult.FAILURE);
+ verifyLock(OperationResult.FAILURE);
assertTrue(mgr.getOutcomes().isEmpty());
}
- private void verifyLock(PolicyResult result) {
+ private void verifyLock(OperationResult result) {
OperationOutcome outcome = mgr.getOutcomes().poll();
assertNotNull(outcome);
assertEquals(ActorConstants.LOCK_ACTOR, outcome.getActor());
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
index add4c41aa..0b066651b 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
@@ -61,15 +61,15 @@ import org.onap.policy.controlloop.actor.guard.GuardActor;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+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.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
-import org.onap.policy.controlloop.policy.Policy;
-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.domain.models.operational.ActorOperation;
+import org.onap.policy.drools.domain.models.operational.OperationalTarget;
import org.onap.policy.sdnr.PciBody;
import org.onap.policy.sdnr.PciMessage;
import org.onap.policy.sdnr.PciResponse;
@@ -114,9 +114,11 @@ public class ControlLoopOperationManager2Test {
private CompletableFuture<OperationOutcome> lockFuture;
private CompletableFuture<OperationOutcome> policyFuture;
- private Target target;
+ private ActorOperation operation;
+ private OperationalTarget target;
+ private Map<String, String> entityIds;
private Map<String, String> payload;
- private Policy policy;
+ private org.onap.policy.drools.domain.models.operational.Operation policy;
private VirtualControlLoopEvent event;
private ControlLoopEventContext context;
private PseudoExecutor executor;
@@ -145,19 +147,28 @@ public class ControlLoopOperationManager2Test {
when(vnf.getVnfId()).thenReturn(MY_VNF_ID);
when(cqdata.getDefaultGenericVnf()).thenReturn(vnf);
- target = new Target();
- target.setType(TargetType.VM);
+ entityIds = Map.of("entity-name-A", "entity-value-A");
+
+ target = OperationalTarget.builder()
+ .targetType(TargetType.VM.toString())
+ .entityIds(entityIds)
+ .build();
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);
+ operation = ActorOperation.builder()
+ .actor(POLICY_ACTOR)
+ .operation(POLICY_OPERATION)
+ .payload(payload)
+ .target(target)
+ .build();
+
+ policy = org.onap.policy.drools.domain.models.operational.Operation.builder()
+ .id(POLICY_ID)
+ .actorOperation(operation)
+ .retries(POLICY_RETRY)
+ .timeout(POLICY_TIMEOUT)
+ .build();
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
@@ -200,7 +211,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
OperationOutcome outcome = mgr.getOutcomes().peek();
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertTrue(outcome.isFinalOutcome());
verify(mgrctx, times(4)).updated(mgr);
@@ -211,7 +222,8 @@ public class ControlLoopOperationManager2Test {
*/
@Test
public void testStartDetmTargetException() {
- policy.setTarget(new Target());
+ operation.setTarget(OperationalTarget.builder().build());
+ mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor);
mgr.start(REMAINING_MS);
runToCompletion();
@@ -309,14 +321,15 @@ public class ControlLoopOperationManager2Test {
assertSame(REQ_ID, params.getRequestId());
assertSame(POLICY_RETRY, params.getRetry());
assertNotNull(params.getStartCallback());
- assertSame(target, params.getTarget());
+ assertEquals(target.getTargetType().toString(), params.getTargetType().toString());
+ assertSame(entityIds, params.getTargetEntityIds());
assertEquals(MY_TARGET, params.getTargetEntity());
assertSame(POLICY_TIMEOUT, params.getTimeoutSec());
}
@Test
public void testStartOperationNullPayload() {
- policy.setPayload(null);
+ operation.setPayload(null);
mgr.start(REMAINING_MS);
lockFuture.complete(new OperationOutcome());
@@ -341,7 +354,8 @@ public class ControlLoopOperationManager2Test {
assertSame(REQ_ID, params.getRequestId());
assertSame(POLICY_RETRY, params.getRetry());
assertNotNull(params.getStartCallback());
- assertSame(target, params.getTarget());
+ assertEquals(target.getTargetType().toString(), params.getTargetType().toString());
+ assertSame(entityIds, params.getTargetEntityIds());
assertEquals(MY_TARGET, params.getTargetEntity());
assertSame(POLICY_TIMEOUT, params.getTimeoutSec());
}
@@ -367,7 +381,7 @@ public class ControlLoopOperationManager2Test {
/*
* now work with SDNR actor
*/
- policy.setActor("SDNR");
+ operation.setActor("SDNR");
mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor);
// should return null for a null input
@@ -407,7 +421,7 @@ public class ControlLoopOperationManager2Test {
assertNotNull(mgr.getOperationResult());
runCyle();
- assertEquals(PolicyResult.SUCCESS, mgr.getOperationResult());
+ assertEquals(OperationResult.SUCCESS, mgr.getOperationResult());
}
/**
@@ -420,7 +434,7 @@ public class ControlLoopOperationManager2Test {
genLockFailure();
runToCompletion();
- assertEquals(PolicyResult.FAILURE_GUARD, mgr.getOperationResult());
+ assertEquals(OperationResult.FAILURE_GUARD, mgr.getOperationResult());
}
/**
@@ -490,7 +504,7 @@ public class ControlLoopOperationManager2Test {
// generate failure outcome for ANOTHER actor - should be ignored
OperationOutcome outcome = mgr.getParams().makeOutcome();
outcome.setActor(OTHER_ACTOR);
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
outcome.setStart(Instant.now());
mgr.getParams().callbackStarted(new OperationOutcome(outcome));
@@ -514,7 +528,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
- assertEquals(PolicyResult.SUCCESS, mgr.getOutcomes().peek().getResult());
+ assertEquals(OperationResult.SUCCESS, mgr.getOutcomes().peek().getResult());
verify(mgrctx, times(4)).updated(mgr);
}
@@ -556,7 +570,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx).updated(mgr);
- verifyDb(1, PolicyResult.FAILURE_GUARD, "Operation denied by Lock");
+ verifyDb(1, OperationResult.FAILURE_GUARD, "Operation denied by Lock");
}
/**
@@ -588,7 +602,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx, times(3)).updated(mgr);
- verifyDb(1, PolicyResult.FAILURE, "Operation aborted by Lock");
+ verifyDb(1, OperationResult.FAILURE, "Operation aborted by Lock");
}
/**
@@ -634,7 +648,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx, times(2)).updated(mgr);
- verifyDb(1, PolicyResult.FAILURE_GUARD, "Operation denied by Guard");
+ verifyDb(1, OperationResult.FAILURE_GUARD, "Operation denied by Guard");
}
/**
@@ -664,7 +678,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx, times(4)).updated(mgr);
- verifyDb(2, PolicyResult.SUCCESS, null);
+ verifyDb(2, OperationResult.SUCCESS, null);
}
/**
@@ -690,7 +704,7 @@ public class ControlLoopOperationManager2Test {
assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState());
- verifyDb(2, PolicyResult.FAILURE, null);
+ verifyDb(2, OperationResult.FAILURE, null);
assertThat(mgr.toString()).contains("attempts=1");
@@ -703,7 +717,7 @@ public class ControlLoopOperationManager2Test {
assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState());
- verifyDb(4, PolicyResult.FAILURE, null);
+ verifyDb(4, OperationResult.FAILURE, null);
assertThat(mgr.toString()).contains("attempts=2");
@@ -715,7 +729,7 @@ public class ControlLoopOperationManager2Test {
assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState());
- verifyDb(6, PolicyResult.SUCCESS, null);
+ verifyDb(6, OperationResult.SUCCESS, null);
assertThat(mgr.toString()).contains("attempts=3");
@@ -744,29 +758,30 @@ public class ControlLoopOperationManager2Test {
@Test
public void testDetmTargetVm() {
- target.setType(TargetType.VM);
+ target.setTargetType(TargetType.VM.toString());
assertNull(mgr.detmTarget());
assertEquals(MY_TARGET, mgr.getTargetEntity());
- target.setType(TargetType.VNF);
+ target.setTargetType(TargetType.VNF.toString());
assertNull(mgr.detmTarget());
assertEquals(MY_TARGET, mgr.getTargetEntity());
- target.setType(TargetType.VFMODULE);
+ target.setTargetType(TargetType.VFMODULE.toString());
assertNull(mgr.detmTarget());
assertEquals(MY_TARGET, mgr.getTargetEntity());
// unsupported type
- target.setType(TargetType.VFC);
+ target.setTargetType(TargetType.VFC.toString());
assertThatIllegalArgumentException().isThrownBy(() -> mgr.detmTarget())
.withMessage("The target type is not supported");
// null type
- target.setType(null);
+ target.setTargetType(null);
assertThatIllegalArgumentException().isThrownBy(() -> mgr.detmTarget()).withMessage("The target type is null");
// null target
- policy.setTarget(null);
+ operation.setTarget(null);
+ mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor);
assertThatIllegalArgumentException().isThrownBy(() -> mgr.detmTarget()).withMessage("The target is null");
}
@@ -899,7 +914,7 @@ public class ControlLoopOperationManager2Test {
OperationOutcome outcome = new OperationOutcome();
outcome.setActor(ControlLoopOperationManager2.LOCK_ACTOR);
outcome.setOperation(ControlLoopOperationManager2.LOCK_OPERATION);
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
outcome.setStart(Instant.now());
outcome.setEnd(Instant.now());
outcome.setFinalOutcome(true);
@@ -936,7 +951,7 @@ public class ControlLoopOperationManager2Test {
mgr.getParams().callbackStarted(new OperationOutcome(outcome));
if (!permit) {
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
}
outcome.setEnd(Instant.now());
@@ -969,7 +984,7 @@ public class ControlLoopOperationManager2Test {
if (success) {
outcome.setFinalOutcome(true);
} else {
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
}
outcome.setEnd(Instant.now());
@@ -986,7 +1001,7 @@ public class ControlLoopOperationManager2Test {
event.getAai().clear();
event.getAai().putAll(Map.of(ControlLoopOperationManager2.PNF_NAME, MY_TARGET));
- target.setType(TargetType.PNF);
+ target.setTargetType(TargetType.PNF.toString());
}
/**
@@ -997,7 +1012,7 @@ public class ControlLoopOperationManager2Test {
event.getAai().clear();
event.getAai().putAll(Map.of(ControlLoopOperationManager2.GENERIC_VNF_VNF_ID, MY_TARGET));
- target.setType(TargetType.VNF);
+ target.setTargetType(TargetType.VNF.toString());
}
private void checkResp(OperationOutcome outcome, String expectedPayload) {
@@ -1007,7 +1022,7 @@ public class ControlLoopOperationManager2Test {
assertEquals(expectedPayload, resp.getPayload());
}
- private void verifyDb(int nrecords, PolicyResult expectedResult, String expectedMsg) {
+ private void verifyDb(int nrecords, OperationResult expectedResult, String expectedMsg) {
ArgumentCaptor<String> entityCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ControlLoopOperation> opCaptor = ArgumentCaptor.forClass(ControlLoopOperation.class);
verify(dataMgr, times(nrecords)).store(any(), any(), entityCaptor.capture(), opCaptor.capture());
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
index 13ad56259..a2f01344f 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
@@ -33,7 +33,6 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerImpl;
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
index dc470e7c8..98ff04da5 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
@@ -43,7 +43,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.drools.core.lock.Lock;
public class LockDataTest {
@@ -135,7 +135,7 @@ public class LockDataTest {
assertEquals(ControlLoopOperationManager2.LOCK_ACTOR, outcome.getActor());
assertEquals(ControlLoopOperationManager2.LOCK_OPERATION, outcome.getOperation());
assertEquals(ENTITY, outcome.getTarget());
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
Instant start = outcome.getStart();
@@ -176,7 +176,7 @@ public class LockDataTest {
assertEquals(ControlLoopOperationManager2.LOCK_ACTOR, outcome.getActor());
assertEquals(ControlLoopOperationManager2.LOCK_OPERATION, outcome.getOperation());
assertEquals(ENTITY, outcome.getTarget());
- assertEquals(PolicyResult.FAILURE, outcome.getResult());
+ assertEquals(OperationResult.FAILURE, outcome.getResult());
assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage());
Instant start = outcome.getStart();
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
index c4121bb38..efcc6101a 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
@@ -47,30 +47,27 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+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.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
-import org.onap.policy.controlloop.policy.Policy;
-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.domain.models.operational.OperationalTarget;
public class StepTest {
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 long REMAINING_MS = 5000;
- private static final Integer POLICY_RETRY = 3;
- private static final Integer POLICY_TIMEOUT = 20;
private static final String EXPECTED_EXCEPTION = "expected exception";
@Mock
@@ -83,9 +80,9 @@ public class StepTest {
private ActorService actors;
private CompletableFuture<OperationOutcome> future;
- private Target target;
+ private OperationalTarget target;
+ private Map<String, String> entityIds;
private Map<String, String> payload;
- private Policy policy;
private VirtualControlLoopEvent event;
private ControlLoopEventContext context;
private BlockingQueue<OperationOutcome> starts;
@@ -109,19 +106,14 @@ public class StepTest {
when(policyOperator.buildOperation(any())).thenReturn(policyOperation);
when(policyOperation.start()).thenReturn(future);
- target = new Target();
- target.setType(TargetType.VM);
+ entityIds = Map.of("entity-name-A", "entity-value-A");
- payload = Map.of(PAYLOAD_KEY, PAYLOAD_VALUE);
+ target = OperationalTarget.builder()
+ .targetType(ControlLoopTargetType.VM)
+ .entityIds(entityIds)
+ .build();
- 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);
+ payload = Map.of(PAYLOAD_KEY, PAYLOAD_VALUE);
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
@@ -136,7 +128,8 @@ public class StepTest {
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.valueOf(target.getTargetType())).targetEntityIds(target.getEntityIds())
+ .targetEntity(MY_TARGET).build();
startTime = new AtomicReference<>();
@@ -171,7 +164,8 @@ public class StepTest {
assertEquals("operB", params2.getOperation());
assertNull(params2.getRetry());
assertNull(params2.getTimeoutSec());
- assertSame(target, params2.getTarget());
+ assertEquals(target.getTargetType().toString(), params2.getTargetType().toString());
+ assertSame(entityIds, params2.getTargetEntityIds());
assertEquals(MY_TARGET, params2.getTargetEntity());
assertTrue(params2.getPayload().isEmpty());
@@ -257,7 +251,7 @@ public class StepTest {
OperationOutcome outcome = completions.poll();
assertNotNull(outcome);
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(POLICY_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
}
@@ -276,7 +270,7 @@ public class StepTest {
OperationOutcome outcome = completions.poll();
assertNotNull(outcome);
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(POLICY_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
}
@@ -318,7 +312,7 @@ public class StepTest {
OperationOutcome outcome = completions.poll();
assertNotNull(outcome);
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(POLICY_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
assertEquals(POLICY_OPERATION, outcome.getOperation());
@@ -348,7 +342,7 @@ public class StepTest {
// verify that the future was cancelled
assertTrue(future.isCancelled());
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(ActorConstants.CL_TIMEOUT_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
assertNull(outcome.getOperation());
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
index 1031c86c7..0ca98720c 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
@@ -30,7 +30,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.nio.file.Paths;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
@@ -38,9 +37,9 @@ import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopException;
-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.controlloop.actorserviceprovider.OperationFinalResult;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
+import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
@@ -52,8 +51,7 @@ public class ControlLoopProcessorTest {
@Test
public void testControlLoopProcessor() throws IOException, ControlLoopException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
- String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+ String yamlString = Files.readString(new File("src/test/resources/test.yaml").toPath(), StandardCharsets.UTF_8);
this.testSuccess(yamlString);
this.testFailure(yamlString);
}
@@ -116,18 +114,18 @@ public class ControlLoopProcessorTest {
String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
assertThatThrownBy(() -> new ControlLoopProcessor(yamlString))
- .hasMessageStartingWith("Cannot create property=string for JavaBean=ControlLoopPolicy");
+ .hasMessageEndingWith("Cannot decode yaml into ToscaServiceTemplate");
}
@Test
public void testControlLoopProcessorBadTriggerYaml() throws IOException, ControlLoopException {
- InputStream is = new FileInputStream(new File("src/test/resources/badtriggerpolicy.yaml"));
- String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+ String yamlString = Files.readString(new File("src/test/resources/badtriggerpolicy.yaml").toPath(),
+ StandardCharsets.UTF_8);
ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
assertNull(clProcessor.getCurrentPolicy());
- assertThatThrownBy(() -> clProcessor.nextPolicyForResult(PolicyResult.SUCCESS))
+ assertThatThrownBy(() -> clProcessor.nextPolicyForResult(OperationResult.SUCCESS))
.hasMessageStartingWith("There is no current policy to determine where to go to.");
}
@@ -146,12 +144,12 @@ public class ControlLoopProcessorTest {
InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- for (PolicyResult result : PolicyResult.values()) {
+ for (OperationResult result : OperationResult.values()) {
checkResult(yamlString, result);
}
}
- private void checkResult(String yamlString, PolicyResult result) throws ControlLoopException {
+ private void checkResult(String yamlString, OperationResult result) throws ControlLoopException {
ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
clProcessor.getCurrentPolicy();
clProcessor.nextPolicyForResult(result);
@@ -165,17 +163,17 @@ public class ControlLoopProcessorTest {
*/
public void testSuccess(String yaml) throws ControlLoopException {
ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
- logger.debug("testSuccess: {}", processor.getControlLoop());
+ logger.debug("testSuccess: {}", processor.getCurrentPolicy());
while (true) {
- FinalResult result = processor.checkIsCurrentPolicyFinal();
+ OperationFinalResult result = processor.checkIsCurrentPolicyFinal();
if (result != null) {
logger.debug("{}", result);
break;
}
- Policy policy = processor.getCurrentPolicy();
+ Operation policy = processor.getCurrentPolicy();
assertNotNull(policy);
- logger.debug("current policy is: {} {}", policy.getId(), policy.getName());
- processor.nextPolicyForResult(PolicyResult.SUCCESS);
+ logger.debug("current policy is: {}", policy.getId());
+ processor.nextPolicyForResult(OperationResult.SUCCESS);
}
}
@@ -187,17 +185,17 @@ public class ControlLoopProcessorTest {
*/
public void testFailure(String yaml) throws ControlLoopException {
ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
- logger.debug("testFailure: {}", processor.getControlLoop());
+ logger.debug("testFailure: {}", processor.getCurrentPolicy());
while (true) {
- FinalResult result = processor.checkIsCurrentPolicyFinal();
+ OperationFinalResult result = processor.checkIsCurrentPolicyFinal();
if (result != null) {
logger.debug("{}", result);
break;
}
- Policy policy = processor.getCurrentPolicy();
+ Operation policy = processor.getCurrentPolicy();
assertNotNull(policy);
- logger.debug("current policy is: {} {}", policy.getId(), policy.getName());
- processor.nextPolicyForResult(PolicyResult.FAILURE);
+ logger.debug("current policy is: {}", policy.getId());
+ processor.nextPolicyForResult(OperationResult.FAILURE);
}
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
index c590741f2..9e29af511 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
@@ -24,8 +24,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
diff --git a/controlloop/common/eventmanager/src/test/resources/badtriggerpolicy.yaml b/controlloop/common/eventmanager/src/test/resources/badtriggerpolicy.yaml
index 8044c9eb8..e4db8c646 100644
--- a/controlloop/common/eventmanager/src/test/resources/badtriggerpolicy.yaml
+++ b/controlloop/common/eventmanager/src/test/resources/badtriggerpolicy.yaml
@@ -1,4 +1,4 @@
-# Copyright 2018 AT&T Intellectual Property. All rights reserved
+# Copyright 2018, 2020 AT&T Intellectual Property. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,65 +11,44 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-controlLoop:
- version: 1.0.0
- controlLoopName: ControlLoop-vService-cbed919f-2212-4ef7-8051-fe6308da1bda
- services:
- - serviceName: service1
- resources:
- - resourceName: resource1
- resourceType: VF
- - resourceName: resource2
- resourceType: VF
- - resourceName: resource3
- resourceType: VF
- - resourceName: resource4
- resourceType: VF
- - resourceName: resource5
- resourceType: VF
- trigger_policy: a-policy-that-does-not-exist
- timeout: 60
-
-policies:
- - id: unique-policy-id-1-restart
- name: Restart Policy
- description:
- actor: APPC
- recipe: Restart
- target:
- type: VNF
- retry: 1
- timeout: 20
- success: final_success
- failure: unique-policy-id-2-rebuild
- failure_timeout: unique-policy-id-2-rebuild
- failure_retries: unique-policy-id-2-rebuild
- failure_exception: final_failure_exception
-
- - id: unique-policy-id-2-rebuild
- name: Rebuild Policy
- description:
- actor: APPC
- recipe: Rebuild
- target: VM
- retry: 0
- timeout: 10
- success: final_success
- failure: unique-policy-id-3-migrate
- failure_timeout: unique-policy-id-3-migrate
- failure_retries: unique-policy-id-3-migrate
- failure_exception: final_failure_exception
-
- - id: unique-policy-id-3-migrate
- name: Migrate Policy
- description:
- actor: APPC
- recipe: Migrate
- target: VM
- retry: 0
- timeout: 30
- success: final_success
- failure: final_failure
- failure_timeout: final_failure_timeout
- failure_retries: final_failure_retries
- failure_exception: final_failure_exception
+tosca_definitions_version: tosca_simple_yaml_1_1_0
+topology_template:
+ policies:
+ - operational.scaleout:
+ type: onap.policies.controlloop.operational.common.Drools
+ type_version: 1.0.0
+ version: 1.0.0
+ name: operational.scaleout
+ metadata:
+ policy-id: operational.scaleout
+ properties:
+ id: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+ timeout: 1200
+ abatement: false
+ trigger: a-policy-id-that-does-not-exist
+ operations:
+ - id: unique-policy-id-1-scale-up
+ description: Create a new VF Module
+ operation:
+ actor: SO
+ operation: VF Module Create
+ target:
+ targetType: VFMODULE
+ entityIds:
+ modelInvariantId: e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e
+ modelVersionId: 94b18b1d-cc91-4f43-911a-e6348665f292
+ modelName: VfwclVfwsnkBbefb8ce2bde..base_vfw..module-0
+ modelVersion: "1"
+ modelCustomizationId: 47958575-138f-452a-8c8d-d89b595f8164
+ payload:
+ requestParameters: '{"usePreload":true,"userParams":[]}'
+ configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[9]","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[16]","enabled":"$.vf-module-topology.vf-module-parameters.param[23]"}]'
+ timeout: 1200
+ retries: 0
+ success: final_success
+ failure: final_failure
+ failure_timeout: final_failure_timeout
+ failure_retries: final_failure_retries
+ failure_exception: final_failure_exception
+ failure_guard: final_failure_guard
+ controllerName: frankfurt
diff --git a/controlloop/common/eventmanager/src/test/resources/nopolicy.yaml b/controlloop/common/eventmanager/src/test/resources/nopolicy.yaml
index 85f8aebab..f69299ee4 100644
--- a/controlloop/common/eventmanager/src/test/resources/nopolicy.yaml
+++ b/controlloop/common/eventmanager/src/test/resources/nopolicy.yaml
@@ -1,4 +1,4 @@
-# Copyright 2018 AT&T Intellectual Property. All rights reserved
+# Copyright 2018, 2020 AT&T Intellectual Property. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,21 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-controlLoop:
- version: 1.0.0
- controlLoopName: ControlLoop-vService-cbed919f-2212-4ef7-8051-fe6308da1bda
- services:
- - serviceName: service1
- resources:
- - resourceName: resource1
- resourceType: VF
- - resourceName: resource2
- resourceType: VF
- - resourceName: resource3
- resourceType: VF
- - resourceName: resource4
- resourceType: VF
- - resourceName: resource5
- resourceType: VF
- trigger_policy: a-policy-that-does-not-exist
- timeout: 60
+tosca_definitions_version: tosca_simple_yaml_1_1_0
+topology_template:
+ policies:
+ - operational.scaleout:
+ type: onap.policies.controlloop.operational.common.Drools
+ type_version: 1.0.0
+ version: 1.0.0
+ name: operational.scaleout
+ metadata:
+ policy-id: operational.scaleout
+ properties:
+ id: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+ timeout: 1200
+ abatement: false
+ trigger: unique-policy-id-1-scale-up
+ operations: []
+ controllerName: frankfurt
diff --git a/controlloop/common/eventmanager/src/test/resources/test.yaml b/controlloop/common/eventmanager/src/test/resources/test.yaml
index aac390ce4..02d51e2a5 100644
--- a/controlloop/common/eventmanager/src/test/resources/test.yaml
+++ b/controlloop/common/eventmanager/src/test/resources/test.yaml
@@ -1,4 +1,4 @@
-# Copyright 2018 AT&T Intellectual Property. All rights reserved
+# Copyright 2018, 2020 AT&T Intellectual Property. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,65 +11,44 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-controlLoop:
- version: 1.0.0
- controlLoopName: ControlLoop-vService-cbed919f-2212-4ef7-8051-fe6308da1bda
- services:
- - serviceName: service1
- resources:
- - resourceName: resource1
- resourceType: VF
- - resourceName: resource2
- resourceType: VF
- - resourceName: resource3
- resourceType: VF
- - resourceName: resource4
- resourceType: VF
- - resourceName: resource5
- resourceType: VF
- trigger_policy: unique-policy-id-1-restart
- timeout: 60
-
-policies:
- - id: unique-policy-id-1-restart
- name: Restart Policy
- description:
- actor: APPC
- recipe: Restart
- target:
- type: VNF
- retry: 1
- timeout: 20
- success: final_success
- failure: unique-policy-id-2-rebuild
- failure_timeout: unique-policy-id-2-rebuild
- failure_retries: unique-policy-id-2-rebuild
- failure_exception: final_failure_exception
-
- - id: unique-policy-id-2-rebuild
- name: Rebuild Policy
- description:
- actor: APPC
- recipe: Rebuild
- target: VM
- retry: 0
- timeout: 10
- success: final_success
- failure: unique-policy-id-3-migrate
- failure_timeout: unique-policy-id-3-migrate
- failure_retries: unique-policy-id-3-migrate
- failure_exception: final_failure_exception
-
- - id: unique-policy-id-3-migrate
- name: Migrate Policy
- description:
- actor: APPC
- recipe: Migrate
- target: VM
- retry: 0
- timeout: 30
- success: final_success
- failure: final_failure
- failure_timeout: final_failure_timeout
- failure_retries: final_failure_retries
- failure_exception: final_failure_exception
+tosca_definitions_version: tosca_simple_yaml_1_1_0
+topology_template:
+ policies:
+ - operational.scaleout:
+ type: onap.policies.controlloop.operational.common.Drools
+ type_version: 1.0.0
+ version: 1.0.0
+ name: operational.scaleout
+ metadata:
+ policy-id: operational.scaleout
+ properties:
+ id: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+ timeout: 1200
+ abatement: false
+ trigger: unique-policy-id-1-scale-up
+ operations:
+ - id: unique-policy-id-1-scale-up
+ description: Create a new VF Module
+ operation:
+ actor: SO
+ operation: VF Module Create
+ target:
+ targetType: VFMODULE
+ entityIds:
+ modelInvariantId: e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e
+ modelVersionId: 94b18b1d-cc91-4f43-911a-e6348665f292
+ modelName: VfwclVfwsnkBbefb8ce2bde..base_vfw..module-0
+ modelVersion: "1"
+ modelCustomizationId: 47958575-138f-452a-8c8d-d89b595f8164
+ payload:
+ requestParameters: '{"usePreload":true,"userParams":[]}'
+ configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[9]","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[16]","enabled":"$.vf-module-topology.vf-module-parameters.param[23]"}]'
+ timeout: 1200
+ retries: 0
+ success: final_success
+ failure: final_failure
+ failure_timeout: final_failure_timeout
+ failure_retries: final_failure_retries
+ failure_exception: final_failure_exception
+ failure_guard: final_failure_guard
+ controllerName: frankfurt