package org.onap.policy.controlloop.actorserviceprovider.parameters;
+import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.BeanValidator;
import org.onap.policy.common.parameters.annotations.NotNull;
-import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
-import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.controlloop.policy.Target;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@AllArgsConstructor
@EqualsAndHashCode
public class ControlLoopOperationParams {
-
private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationParams.class);
- public static final String UNKNOWN = "-unknown-";
-
+ /**
+ * Actor name.
+ */
+ @NotNull
+ private String actor;
/**
- * The actor service in which to find the actor/operation.
+ * Actor service in which to find the actor/operation.
*/
@NotNull
private ActorService actorService;
/**
- * The event for which the operation applies.
+ * Event for which the operation applies.
*/
@NotNull
private ControlLoopEventContext context;
/**
- * The executor to use to run the operation.
+ * Executor to use to run the operation.
*/
@NotNull
@Builder.Default
private Executor executor = ForkJoinPool.commonPool();
/**
- * The policy associated with the operation.
+ * Operation name.
+ */
+ @NotNull
+ private String operation;
+
+ /**
+ * Payload data for the request.
+ */
+ private Map<String, String> payload;
+
+ /**
+ * Number of retries allowed, or {@code null} if no retries.
+ */
+ private Integer retry;
+
+ /**
+ * The entity's target information. May be {@code null}, depending on the requirement
+ * of the operation to be invoked.
+ */
+ private Target target;
+
+ /**
+ * Target entity.
*/
@NotNull
- private Policy policy;
+ private String targetEntity;
+
+ /**
+ * Timeout, in seconds, or {@code null} if no timeout. Zero and negative values also
+ * imply no timeout.
+ */
+ @Builder.Default
+ private Integer timeoutSec = 300;
/**
* The function to invoke when the operation starts. This is optional.
* may happen if the current operation requires other operations to be performed first
* (e.g., A&AI queries, guard checks).
*/
- private Consumer<ControlLoopOperation> startCallback;
+ private Consumer<OperationOutcome> startCallback;
/**
* The function to invoke when the operation completes. This is optional.
* may happen if the current operation requires other operations to be performed first
* (e.g., A&AI queries, guard checks).
*/
- private Consumer<ControlLoopOperation> completeCallback;
-
- /**
- * Target entity.
- */
- @NotNull
- private String target;
+ private Consumer<OperationOutcome> completeCallback;
/**
* Starts the specified operation.
* @return a future that will return the result of the operation
* @throws IllegalArgumentException if the parameters are invalid
*/
- public CompletableFuture<ControlLoopOperation> start() {
+ public CompletableFuture<OperationOutcome> start() {
BeanValidationResult result = validate();
if (!result.isValid()) {
logger.warn("parameter error in operation {}.{} for {}:\n{}", getActor(), getOperation(), getRequestId(),
// @formatter:off
return actorService
- .getActor(policy.getActor())
- .getOperator(policy.getRecipe())
+ .getActor(getActor())
+ .getOperator(getOperation())
.startOperation(this);
// @formatter:on
}
- /**
- * Gets the name of the actor from the policy.
- *
- * @return the actor name, or {@link #UNKNOWN} if no name is available
- */
- public String getActor() {
- return (policy == null || policy.getActor() == null ? UNKNOWN : policy.getActor());
- }
-
- /**
- * Gets the name of the operation from the policy.
- *
- * @return the operation name, or {@link #UNKNOWN} if no name is available
- */
- public String getOperation() {
- return (policy == null || policy.getRecipe() == null ? UNKNOWN : policy.getRecipe());
- }
-
/**
* Gets the requested ID of the associated event.
*
*
* @return a new operation outcome
*/
- public ControlLoopOperation makeOutcome() {
- ControlLoopOperation operation = new ControlLoopOperation();
- operation.setActor(getActor());
- operation.setOperation(getOperation());
- operation.setTarget(target);
+ public OperationOutcome makeOutcome() {
+ OperationOutcome outcome = new OperationOutcome();
+ outcome.setActor(getActor());
+ outcome.setOperation(getOperation());
+ outcome.setTarget(targetEntity);
- return operation;
+ return outcome;
}
/**
*
* @param operation the operation that is being started
*/
- public void callbackStarted(ControlLoopOperation operation) {
+ public void callbackStarted(OperationOutcome operation) {
logger.info("started operation {}.{} for {}", operation.getActor(), operation.getOperation(), getRequestId());
if (startCallback != null) {
- Util.logException(() -> startCallback.accept(operation), "{}.{}: start-callback threw an exception for {}",
+ Util.runFunction(() -> startCallback.accept(operation), "{}.{}: start-callback threw an exception for {}",
operation.getActor(), operation.getOperation(), getRequestId());
}
}
*
* @param operation the operation that is being started
*/
- public void callbackCompleted(ControlLoopOperation operation) {
+ public void callbackCompleted(OperationOutcome operation) {
logger.info("completed operation {}.{} outcome={} for {}", operation.getActor(), operation.getOperation(),
- operation.getOutcome(), getRequestId());
+ operation.getResult(), getRequestId());
if (completeCallback != null) {
- Util.logException(() -> completeCallback.accept(operation),
+ Util.runFunction(() -> completeCallback.accept(operation),
"{}.{}: complete-callback threw an exception for {}", operation.getActor(),
operation.getOperation(), getRequestId());
}