diff options
Diffstat (limited to 'controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager')
4 files changed, 58 insertions, 41 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); } |