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.Operation;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
-import org.onap.policy.controlloop.policy.Policy;
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-";
+ public static final String PARAMS_ENTITY_RESOURCEID = "resourceID";
+ public static final String PARAMS_ENTITY_MODEL_INVARIANT_ID = "modelInvariantId";
+ public static final String PARAMS_ENTITY_MODEL_VERSION_ID = "modelVersionId";
+ public static final String PARAMS_ENTITY_MODEL_NAME = "modelName";
+ public static final String PARAMS_ENTITY_MODEL_VERSION = "modelVersion";
+ public static final String PARAMS_ENTITY_MODEL_CUSTOMIZATION_ID = "modelCustomizationId";
+ /**
+ * 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.
+ * Request ID with which all actor operations are associated. Used to track requests
+ * across various components/servers.
*/
@NotNull
- private ControlLoopEventContext context;
+ private UUID requestId;
/**
- * 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 Policy policy;
+ private String operation;
+
+ /**
+ * Payload data for the request.
+ */
+ private Map<String, Object> payload;
+
+ /**
+ * {@code True} if the preprocessing steps have already been executed, {@code false}
+ * otherwise.
+ */
+ // TODO remove this once the rules no longer reference it
+ private boolean preprocessed;
+
+ /**
+ * Number of retries allowed, or {@code null} if no retries.
+ */
+ private Integer retry;
+
+ /**
+ * The Target Type information, extracted from the Policy. May be {@code null}, depending
+ * on the requirement of the operation to be invoked.
+ */
+ private TargetType targetType;
+
+ /**
+ * Target entitiy ids, extracted from the Policy. May be (@code null}, depending on
+ * the requirement of the operation to be invoked.
+ */
+ private Map<String, String> targetEntityIds;
+
+ /**
+ * Target entity.
+ */
+ // TODO to be removed
+ 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;
+ private Consumer<OperationOutcome> completeCallback;
/**
- * Target entity.
+ * Starts the specified operation.
+ *
+ * @return a future that will return the result of the operation
+ * @throws IllegalArgumentException if the parameters are invalid
*/
- @NotNull
- private String target;
+ public CompletableFuture<OperationOutcome> start() {
+ return build().start();
+ }
/**
- * Starts the specified operation.
+ * Builds the specified operation.
*
- * @return a future that will return the result of the operation
+ * @return a new operation
* @throws IllegalArgumentException if the parameters are invalid
*/
- public CompletableFuture<ControlLoopOperation> start() {
+ public Operation build() {
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())
- .startOperation(this);
+ .getActor(getActor())
+ .getOperator(getOperation())
+ .buildOperation(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.
+ * Gets the requested ID of the associated event.
*
- * @return the operation name, or {@link #UNKNOWN} if no name is available
+ * @return the event's request ID, or {@code null} if no request ID is available
*/
- public String getOperation() {
- return (policy == null || policy.getRecipe() == null ? UNKNOWN : policy.getRecipe());
+ public UUID getRequestId() {
+ return requestId;
}
/**
- * Gets the requested ID of the associated event.
+ * Makes an operation outcome, populating it from the parameters.
*
- * @return the event's request ID, or {@code null} if no request ID is available
+ * @return a new operation outcome
*/
- public UUID getRequestId() {
- return (context == null || context.getEvent() == null ? null : context.getEvent().getRequestId());
+ // TODO to be removed
+ public OperationOutcome makeOutcome() {
+ return makeOutcome(getTargetEntity());
}
/**
* Makes an operation outcome, populating it from the parameters.
*
+ * @param targetEntity the target entity
+ *
* @return a new operation outcome
*/
- public ControlLoopOperation makeOutcome() {
- ControlLoopOperation operation = new ControlLoopOperation();
- operation.setActor(getActor());
- operation.setOperation(getOperation());
- operation.setTarget(target);
+ public OperationOutcome makeOutcome(String targetEntity) {
+ 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());
}