aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src/main/java')
-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
5 files changed, 101 insertions, 153 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;
}
}