diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2020-08-27 08:44:12 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2020-08-27 14:29:09 -0400 |
commit | f456cc5c8e1efd15edb6da718e1428d8fd7c66c5 (patch) | |
tree | b7b4ba3fc6255b056e00f6e203d7ec8fd6a7c194 /models-interactions/model-actors/actorServiceProvider/src | |
parent | 68a60a45f27287a4a523c82ef466cbeec655f641 (diff) |
Remove Target and TargetType
The dependency should have been removed in the last review to
remove SDC and policy-yaml legacy code.
It was revealed that usage of TargetType and Type were spread out over the
actor code. Those fields are represented differently in the new
TOSCA Operational Policy Type, so fields were created to capture
those values to be used by actor code.
Issue-ID: POLICY-2428
Change-Id: Ib783526a518ca7942ae9e38019bd343639f4dd98
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider/src')
14 files changed, 378 insertions, 114 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationFinalResult.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationFinalResult.java new file mode 100644 index 000000000..67d25f2a9 --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationFinalResult.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * models + * ================================================================================ + * Copyright (C) 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actorserviceprovider; + +public enum OperationFinalResult { + /** + * The Control Loop Policy successfully completed its Operations. + */ + FINAL_SUCCESS("Final_Success"), + /** + * The Control Loop Policy was an Open Loop and is finished. + */ + FINAL_OPENLOOP("Final_OpenLoop"), + /** + * The Control Loop Policy failed in its last Operation Policy. NOTE: Previous Operation Policies may have been + * successful. + */ + FINAL_FAILURE("Final_Failure"), + /** + * The Control Loop Policy failed because the overall timeout was met. + */ + FINAL_FAILURE_TIMEOUT("Final_Failure_Timeout"), + /** + * The Control Loop Policy failed because an Operation Policy met its retry limit. + */ + FINAL_FAILURE_RETRIES("Final_Failure_Retries"), + /** + * The Control Loop Policy failed due to an exception. + */ + FINAL_FAILURE_EXCEPTION("Final_Failure_Exception"), + /** + * The Control Loop Policy failed due to guard denied. + */ + FINAL_FAILURE_GUARD("Final_Failure_Guard"); + + String result; + + private OperationFinalResult(String result) { + this.result = result; + } + + /** + * Converts to a result object. + * + * @param result input string + * @return result object + */ + public static OperationFinalResult toResult(String result) { + if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) { + return FINAL_SUCCESS; + } + if (result.equalsIgnoreCase(FINAL_OPENLOOP.toString())) { + return FINAL_OPENLOOP; + } + if (result.equalsIgnoreCase(FINAL_FAILURE.toString())) { + return FINAL_FAILURE; + } + if (result.equalsIgnoreCase(FINAL_FAILURE_TIMEOUT.toString())) { + return FINAL_FAILURE_TIMEOUT; + } + if (result.equalsIgnoreCase(FINAL_FAILURE_RETRIES.toString())) { + return FINAL_FAILURE_RETRIES; + } + if (result.equalsIgnoreCase(FINAL_FAILURE_EXCEPTION.toString())) { + return FINAL_FAILURE_EXCEPTION; + } + if (result.equalsIgnoreCase(FINAL_FAILURE_GUARD.toString())) { + return FINAL_FAILURE_GUARD; + } + return null; + } + + /** + * Check if the result really is a result. + * + * @param result string + * @param finalResult result object + * @return true if a result + */ + public static boolean isResult(String result, OperationFinalResult finalResult) { + OperationFinalResult toResult = OperationFinalResult.toResult(result); + if (toResult == null) { + return false; + } + return toResult.equals(finalResult); + } + +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java index 0c4350c63..2d6a61249 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java @@ -25,7 +25,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.policy.PolicyResult; /** * Outcome from an operation. Objects of this type are passed from one stage to the next. @@ -39,7 +38,7 @@ public class OperationOutcome { private Instant start; private Instant end; private String subRequestId; - private PolicyResult result = PolicyResult.SUCCESS; + private OperationResult result = OperationResult.SUCCESS; private String message; private boolean finalOutcome; private Object response; @@ -119,7 +118,7 @@ public class OperationOutcome { * * @param result new result */ - public void setResult(@NonNull PolicyResult result) { + public void setResult(@NonNull OperationResult result) { this.result = result; } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationResult.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationResult.java new file mode 100644 index 000000000..4577617a2 --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationResult.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actorserviceprovider; + +public enum OperationResult { + /** + * Operation was successful. + */ + SUCCESS("Success"), + /** + * Operation failed. + */ + FAILURE("Failure"), + /** + * Operation failed due to maximum retries being met. + */ + FAILURE_RETRIES("Failure_Retries"), + /** + * Operation failed due to timeout occurring. + */ + FAILURE_TIMEOUT("Failure_Timeout"), + /** + * Operation failed due to an exception. + */ + FAILURE_EXCEPTION("Failure_Exception"), + /** + * Operation failed since Guard did not permit. + */ + FAILURE_GUARD("Failure_Guard") + ; + + + private String result; + private OperationResult(String result) { + this.result = result; + } + + @Override + public String toString() { + return this.result; + } + + /** + * Convert to a result. + * + * @param result result string + * @return Result object + */ + public static OperationResult toResult(String result) { + if (result.equalsIgnoreCase(SUCCESS.toString())) { + return SUCCESS; + } + if (result.equalsIgnoreCase(FAILURE.toString())) { + return FAILURE; + } + if (result.equalsIgnoreCase(FAILURE_RETRIES.toString())) { + return FAILURE_RETRIES; + } + if (result.equalsIgnoreCase(FAILURE_TIMEOUT.toString())) { + return FAILURE_TIMEOUT; + } + if (result.equalsIgnoreCase(FAILURE_EXCEPTION.toString())) { + return FAILURE_EXCEPTION; + } + if (result.equalsIgnoreCase(FAILURE_GUARD.toString())) { + return FAILURE_GUARD; + } + return null; + } +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/TargetType.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/TargetType.java new file mode 100644 index 000000000..605445c57 --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/TargetType.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actorserviceprovider; + +public enum TargetType { + VM("VM"), PNF("PNF"), VFC("VFC"), VNF("VNF"), VFMODULE("VFMODULE"); + + private String target; + + private TargetType(String targetType) { + this.target = targetType; + } + + @Override + public String toString() { + return this.target; + } + + /** + * Converts a string to TargetType object if it matches. + * + * @param targetType String + * @return TargetType object + */ + public static TargetType toTargetType(String targetType) { + if (targetType == null) { + return null; + } + if (targetType.equalsIgnoreCase(VM.toString())) { + return VM; + } + if (targetType.equalsIgnoreCase(PNF.toString())) { + return PNF; + } + if (targetType.equalsIgnoreCase(VFC.toString())) { + return VFC; + } + if (targetType.equalsIgnoreCase(VNF.toString())) { + return VNF; + } + if (targetType.equalsIgnoreCase(VFMODULE.toString())) { + return VFMODULE; + } + + return null; + } +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java index a3f3a6905..e02e59239 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java @@ -29,12 +29,12 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; -import org.onap.policy.controlloop.policy.PolicyResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -215,14 +215,14 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial case SUCCESS: logger.info("{}.{} request succeeded for {}", params.getActor(), params.getOperation(), params.getRequestId()); - setOutcome(outcome, PolicyResult.SUCCESS, response); + setOutcome(outcome, OperationResult.SUCCESS, response); postProcessResponse(outcome, rawResponse, response); return outcome; case FAILURE: logger.info("{}.{} request failed for {}", params.getActor(), params.getOperation(), params.getRequestId()); - return setOutcome(outcome, PolicyResult.FAILURE, response); + return setOutcome(outcome, OperationResult.FAILURE, response); case STILL_WAITING: default: @@ -240,7 +240,7 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial * @param response response used to populate the outcome * @return the updated operation */ - public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, S response) { + public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, S response) { outcome.setResponse(response); return setOutcome(outcome, result); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java index 09c876d41..c75ca1d4f 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java @@ -37,12 +37,12 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture; -import org.onap.policy.controlloop.policy.PolicyResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -243,11 +243,12 @@ public abstract class HttpOperation<T> extends OperationPartial { if (!isSuccess(rawResponse, response)) { logger.info("{}.{} request failed with http error code {} for {}", params.getActor(), params.getOperation(), rawResponse.getStatus(), params.getRequestId()); - return CompletableFuture.completedFuture(setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response)); + return CompletableFuture.completedFuture( + setOutcome(outcome, OperationResult.FAILURE, rawResponse, response)); } logger.info("{}.{} request succeeded for {}", params.getActor(), params.getOperation(), params.getRequestId()); - setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response); + setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response); return postProcessResponse(outcome, url, rawResponse, response); } @@ -260,7 +261,7 @@ public abstract class HttpOperation<T> extends OperationPartial { * @param response decoded response * @return the updated operation */ - public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, Response rawResponse, + public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, Response rawResponse, T response) { outcome.setResponse(response); @@ -292,13 +293,13 @@ public abstract class HttpOperation<T> extends OperationPartial { logger.info("{}.{} request succeeded for {}", params.getActor(), params.getOperation(), params.getRequestId()); return CompletableFuture - .completedFuture(setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response)); + .completedFuture(setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response)); case FAILURE: logger.info("{}.{} request failed for {}", params.getActor(), params.getOperation(), params.getRequestId()); return CompletableFuture - .completedFuture(setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response)); + .completedFuture(setOutcome(outcome, OperationResult.FAILURE, rawResponse, response)); case STILL_WAITING: default: @@ -313,7 +314,7 @@ public abstract class HttpOperation<T> extends OperationPartial { if (pollCount++ >= cfg.getMaxPolls()) { logger.warn("{}: execeeded 'poll' limit {} for {}", getFullName(), cfg.getMaxPolls(), params.getRequestId()); - setOutcome(outcome, PolicyResult.FAILURE_TIMEOUT); + setOutcome(outcome, OperationResult.FAILURE_TIMEOUT); return CompletableFuture.completedFuture(outcome); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java index b5cc15e19..c81575f62 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java @@ -54,10 +54,10 @@ import org.onap.policy.controlloop.actorserviceprovider.CallbackManager; import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfig; import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture; -import org.onap.policy.controlloop.policy.PolicyResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -132,10 +132,12 @@ public abstract class OperationPartial implements Operation { return config.getBlockingExecutor(); } + @Override public String getActorName() { return params.getActor(); } + @Override public String getName() { return params.getOperation(); } @@ -221,7 +223,7 @@ public abstract class OperationPartial implements Operation { // TODO need a FAILURE_MISSING_DATA (e.g., A&AI) outcome2.setFinalOutcome(true); - outcome2.setResult(PolicyResult.FAILURE_GUARD); + outcome2.setResult(OperationResult.FAILURE_GUARD); outcome2.setMessage(outcome != null ? outcome.getMessage() : null); // @formatter:off @@ -392,7 +394,7 @@ public abstract class OperationPartial implements Operation { * @return {@code true} if the outcome was successful */ protected boolean isSuccess(OperationOutcome outcome) { - return (outcome != null && outcome.getResult() == PolicyResult.SUCCESS); + return (outcome != null && outcome.getResult() == OperationResult.SUCCESS); } /** @@ -403,7 +405,7 @@ public abstract class OperationPartial implements Operation { * <i>and</i> was associated with this operator, {@code false} otherwise */ protected boolean isActorFailed(OperationOutcome outcome) { - return (isSameOperation(outcome) && outcome.getResult() == PolicyResult.FAILURE); + return (isSameOperation(outcome) && outcome.getResult() == OperationResult.FAILURE); } /** @@ -475,7 +477,7 @@ public abstract class OperationPartial implements Operation { outcome = origOutcome; } else { logger.warn("{}: null outcome; treating as a failure for {}", getFullName(), params.getRequestId()); - outcome = this.setOutcome(params.makeOutcome(getTargetEntity()), PolicyResult.FAILURE); + outcome = this.setOutcome(params.makeOutcome(getTargetEntity()), OperationResult.FAILURE); } // ensure correct actor/operation @@ -483,7 +485,7 @@ public abstract class OperationPartial implements Operation { outcome.setOperation(getName()); // determine if we should retry, based on the result - if (outcome.getResult() != PolicyResult.FAILURE) { + if (outcome.getResult() != OperationResult.FAILURE) { // do not retry success or other failure types (e.g., exception) outcome.setFinalOutcome(true); return outcome; @@ -504,7 +506,7 @@ public abstract class OperationPartial implements Operation { * FAILURE_RETRIES */ logger.info("operation {} retries exhausted for {}", getFullName(), params.getRequestId()); - outcome.setResult(PolicyResult.FAILURE_RETRIES); + outcome.setResult(OperationResult.FAILURE_RETRIES); outcome.setFinalOutcome(true); } @@ -989,7 +991,8 @@ public abstract class OperationPartial implements Operation { * @return the updated operation */ public OperationOutcome setOutcome(OperationOutcome operation, Throwable thrown) { - PolicyResult result = (isTimeout(thrown) ? PolicyResult.FAILURE_TIMEOUT : PolicyResult.FAILURE_EXCEPTION); + OperationResult result = (isTimeout(thrown) ? OperationResult.FAILURE_TIMEOUT + : OperationResult.FAILURE_EXCEPTION); return setOutcome(operation, result); } @@ -1000,10 +1003,10 @@ public abstract class OperationPartial implements Operation { * @param result result of the operation * @return the updated operation */ - public OperationOutcome setOutcome(OperationOutcome operation, PolicyResult result) { + public OperationOutcome setOutcome(OperationOutcome operation, OperationResult result) { logger.trace("{}: set outcome {} for {}", getFullName(), result, params.getRequestId()); operation.setResult(result); - operation.setMessage(result == PolicyResult.SUCCESS ? ControlLoopOperation.SUCCESS_MSG + operation.setMessage(result == OperationResult.SUCCESS ? ControlLoopOperation.SUCCESS_MSG : ControlLoopOperation.FAILED_MSG); return operation; diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java index 66573f38a..0e4f09b66 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java @@ -37,9 +37,9 @@ 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.TargetType; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; -import org.onap.policy.controlloop.policy.Target; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +54,13 @@ import org.slf4j.LoggerFactory; public class ControlLoopOperationParams { private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationParams.class); + 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. */ @@ -107,10 +114,16 @@ public class ControlLoopOperationParams { private Integer retry; /** - * The Target information, extracted from the Policy. May be {@code null}, depending + * The Target Type information, extracted from the Policy. May be {@code null}, depending * on the requirement of the operation to be invoked. */ - private Target target; + 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. diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java index 5820becc5..605a7330c 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java @@ -30,7 +30,6 @@ import java.time.Instant; import org.junit.Before; import org.junit.Test; import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.policy.PolicyResult; public class OperationOutcomeTest { private static final String ACTOR = "my-actor"; @@ -39,7 +38,7 @@ public class OperationOutcomeTest { private static final Instant START = Instant.ofEpochMilli(10); private static final Instant END = Instant.ofEpochMilli(20); private static final String SUB_REQ_ID = "my-sub-request-id"; - private static final PolicyResult RESULT = PolicyResult.FAILURE_GUARD; + private static final OperationResult RESULT = OperationResult.FAILURE_GUARD; private static final String MESSAGE = "my-message"; private static final String RESPONSE = "my-response"; @@ -124,8 +123,8 @@ public class OperationOutcomeTest { @Test public void testSetResult() { - outcome.setResult(PolicyResult.FAILURE_EXCEPTION); - assertEquals(PolicyResult.FAILURE_EXCEPTION, outcome.getResult()); + outcome.setResult(OperationResult.FAILURE_EXCEPTION); + assertEquals(OperationResult.FAILURE_EXCEPTION, outcome.getResult()); assertThatThrownBy(() -> outcome.setResult(null)); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index f63e07e57..14b1daf49 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -55,11 +55,11 @@ import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.common.utils.time.PseudoExecutor; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; -import org.onap.policy.controlloop.policy.PolicyResult; public class BidirectionalTopicOperationTest { private static final CommInfrastructure SINK_INFRA = CommInfrastructure.NOOP; @@ -163,7 +163,7 @@ public class BidirectionalTopicOperationTest { assertTrue(future.isDone()); assertSame(outcome, future.get()); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(response, outcome.getResponse()); verify(forwarder).unregister(eq(Arrays.asList(REQ_ID)), eq(listenerCaptor.getValue())); @@ -263,7 +263,7 @@ public class BidirectionalTopicOperationTest { MyStringOperation oper2 = new MyStringOperation(); assertSame(outcome, oper2.processResponse(outcome, TEXT, null)); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(TEXT, outcome.getResponse()); } @@ -276,7 +276,7 @@ public class BidirectionalTopicOperationTest { MyScoOperation oper2 = new MyScoOperation(); assertSame(outcome, oper2.processResponse(outcome, responseText, stdResponse)); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(stdResponse, outcome.getResponse()); } @@ -293,7 +293,7 @@ public class BidirectionalTopicOperationTest { stdResponse = coder.decode(responseText, StandardCoderObject.class); assertSame(outcome, oper.processResponse(outcome, responseText, stdResponse)); - assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertEquals(OperationResult.FAILURE, outcome.getResult()); assertEquals(resp, outcome.getResponse()); } @@ -303,7 +303,7 @@ public class BidirectionalTopicOperationTest { @Test public void testProcessResponseDecodeOk() throws CoderException { assertSame(outcome, oper.processResponse(outcome, responseText, stdResponse)); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(response, outcome.getResponse()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java index daabaa237..453592d2b 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java @@ -79,11 +79,11 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.controlloop.VirtualControlLoopEvent; 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.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; -import org.onap.policy.controlloop.policy.PolicyResult; public class HttpOperationTest { @@ -257,7 +257,7 @@ public class HttpOperationTest { assertSame(outcome, future2.get(5, TimeUnit.SECONDS)); assertSame(TEXT, outcome.getResponse()); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); } /** @@ -289,7 +289,7 @@ public class HttpOperationTest { CompletableFuture<OperationOutcome> result = oper.processResponse(outcome, PATH, response); assertTrue(result.isDone()); assertSame(outcome, result.get()); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertSame(TEXT, outcome.getResponse()); } @@ -302,7 +302,7 @@ public class HttpOperationTest { CompletableFuture<OperationOutcome> result = oper.processResponse(outcome, PATH, response); assertTrue(result.isDone()); assertSame(outcome, result.get()); - assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertEquals(OperationResult.FAILURE, outcome.getResult()); assertSame(TEXT, outcome.getResponse()); } @@ -318,7 +318,7 @@ public class HttpOperationTest { CompletableFuture<OperationOutcome> result = oper2.processResponse(outcome, PATH, response); assertTrue(result.isDone()); assertSame(outcome, result.get()); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(Integer.valueOf(10), outcome.getResponse()); } @@ -359,7 +359,7 @@ public class HttpOperationTest { OperationOutcome outcome = runOperation(oper2); assertNotNull(outcome); assertEquals(1, nget); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof MyResponse); } @@ -376,7 +376,7 @@ public class HttpOperationTest { OperationOutcome outcome = runOperation(oper2); assertNotNull(outcome); assertEquals(1, ndelete); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof String); } @@ -392,7 +392,7 @@ public class HttpOperationTest { OperationOutcome outcome = runOperation(oper2); assertNotNull(outcome); assertEquals(1, npost); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof MyResponse); } @@ -409,7 +409,7 @@ public class HttpOperationTest { OperationOutcome outcome = runOperation(oper2); assertNotNull(outcome); assertEquals(1, nput); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof MyResponse); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java index ede2b7966..845758a48 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java @@ -44,10 +44,10 @@ import org.mockito.MockitoAnnotations; import org.mockito.stubbing.Answer; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; -import org.onap.policy.controlloop.policy.PolicyResult; /** * Tests HttpOperation when polling is enabled. @@ -134,7 +134,7 @@ public class HttpPollingOperationTest { oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertNotNull(oper.getSubRequestId()); assertSame(response, outcome.getResponse()); @@ -144,7 +144,7 @@ public class HttpPollingOperationTest { future2 = oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); - assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertEquals(OperationResult.FAILURE, outcome.getResult()); assertNotNull(oper.getSubRequestId()); assertSame(response, outcome.getResponse()); } @@ -175,7 +175,7 @@ public class HttpPollingOperationTest { oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response); assertSame(outcome, future2.get(5, TimeUnit.SECONDS)); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(2, oper.getPollCount()); /* @@ -186,7 +186,7 @@ public class HttpPollingOperationTest { future2 = oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response); assertSame(outcome, future2.get(5, TimeUnit.SECONDS)); - assertEquals(PolicyResult.FAILURE_TIMEOUT, outcome.getResult()); + assertEquals(OperationResult.FAILURE_TIMEOUT, outcome.getResult()); assertEquals(MAX_POLLS + 1, oper.getPollCount()); oper.resetPollCount(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index 6db824f98..455393c93 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -76,12 +76,12 @@ 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.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.Operator; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfig; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; -import org.onap.policy.controlloop.policy.PolicyResult; import org.slf4j.LoggerFactory; public class OperationPartialTest { @@ -99,8 +99,8 @@ public class OperationPartialTest { private static final int TIMEOUT = 1000; private static final UUID REQ_ID = UUID.randomUUID(); - private static final List<PolicyResult> FAILURE_RESULTS = Arrays.asList(PolicyResult.values()).stream() - .filter(result -> result != PolicyResult.SUCCESS).collect(Collectors.toList()); + private static final List<OperationResult> FAILURE_RESULTS = Arrays.asList(OperationResult.values()).stream() + .filter(result -> result != OperationResult.SUCCESS).collect(Collectors.toList()); /** * Used to attach an appender to the class' logger. @@ -238,7 +238,7 @@ public class OperationPartialTest { @Test public void testStart() { - verifyRun("testStart", 1, 1, PolicyResult.SUCCESS); + verifyRun("testStart", 1, 1, OperationResult.SUCCESS); } /** @@ -254,7 +254,7 @@ public class OperationPartialTest { assertNotNull(opstart); assertNotNull(opend); - assertEquals(PolicyResult.SUCCESS, opend.getResult()); + assertEquals(OperationResult.SUCCESS, opend.getResult()); assertEquals(MAX_PARALLEL, numStart); assertEquals(MAX_PARALLEL, oper.getCount()); @@ -268,7 +268,7 @@ public class OperationPartialTest { public void testStartPreprocessorFailure() { oper.setPreProc(CompletableFuture.completedFuture(makeFailure())); - verifyRun("testStartPreprocessorFailure", 1, 0, PolicyResult.FAILURE_GUARD); + verifyRun("testStartPreprocessorFailure", 1, 0, OperationResult.FAILURE_GUARD); } /** @@ -279,7 +279,7 @@ public class OperationPartialTest { // arrange for the preprocessor to throw an exception oper.setPreProc(CompletableFuture.failedFuture(new IllegalStateException(EXPECTED_EXCEPTION))); - verifyRun("testStartPreprocessorException", 1, 0, PolicyResult.FAILURE_GUARD); + verifyRun("testStartPreprocessorException", 1, 0, OperationResult.FAILURE_GUARD); } /** @@ -328,7 +328,7 @@ public class OperationPartialTest { public void testStartGuardAsync() throws Exception { CompletableFuture<OperationOutcome> future = oper.startGuardAsync(); assertTrue(future.isDone()); - assertEquals(PolicyResult.SUCCESS, future.get().getResult()); + assertEquals(OperationResult.SUCCESS, future.get().getResult()); // verify the parameters that were passed ArgumentCaptor<ControlLoopOperationParams> paramsCaptor = @@ -387,10 +387,10 @@ public class OperationPartialTest { OperationOutcome outcome = new OperationOutcome(); - outcome.setResult(PolicyResult.SUCCESS); + outcome.setResult(OperationResult.SUCCESS); assertTrue(oper.isSuccess(outcome)); - for (PolicyResult failure : FAILURE_RESULTS) { + for (OperationResult failure : FAILURE_RESULTS) { outcome.setResult(failure); assertFalse("testIsSuccess-" + failure, oper.isSuccess(outcome)); } @@ -403,14 +403,14 @@ public class OperationPartialTest { OperationOutcome outcome = params.makeOutcome(null); // incorrect outcome - outcome.setResult(PolicyResult.SUCCESS); + outcome.setResult(OperationResult.SUCCESS); assertFalse(oper.isActorFailed(outcome)); - outcome.setResult(PolicyResult.FAILURE_RETRIES); + outcome.setResult(OperationResult.FAILURE_RETRIES); assertFalse(oper.isActorFailed(outcome)); // correct outcome - outcome.setResult(PolicyResult.FAILURE); + outcome.setResult(OperationResult.FAILURE); // incorrect actor outcome.setActor(MY_SINK); @@ -441,7 +441,7 @@ public class OperationPartialTest { assertTrue(executor.runAll(MAX_REQUESTS)); assertNotNull(opend); - assertEquals(PolicyResult.FAILURE_EXCEPTION, opend.getResult()); + assertEquals(OperationResult.FAILURE_EXCEPTION, opend.getResult()); } @Test @@ -461,7 +461,7 @@ public class OperationPartialTest { protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) { OperationOutcome outcome2 = params.makeOutcome(null); - outcome2.setResult(PolicyResult.SUCCESS); + outcome2.setResult(OperationResult.SUCCESS); /* * Create an incomplete future that will timeout after the operation's @@ -476,7 +476,7 @@ public class OperationPartialTest { } }; - assertEquals(PolicyResult.FAILURE_TIMEOUT, oper.start().get().getResult()); + assertEquals(OperationResult.FAILURE_TIMEOUT, oper.start().get().getResult()); } /** @@ -491,7 +491,7 @@ public class OperationPartialTest { oper.setMaxFailures(10); - verifyRun("testSetRetryFlag_testRetryOnFailure_ZeroRetries", 1, 1, PolicyResult.FAILURE); + verifyRun("testSetRetryFlag_testRetryOnFailure_ZeroRetries", 1, 1, OperationResult.FAILURE); } /** @@ -506,7 +506,7 @@ public class OperationPartialTest { oper.setMaxFailures(10); - verifyRun("testSetRetryFlag_testRetryOnFailure_NullRetries", 1, 1, PolicyResult.FAILURE); + verifyRun("testSetRetryFlag_testRetryOnFailure_NullRetries", 1, 1, OperationResult.FAILURE); } /** @@ -523,7 +523,7 @@ public class OperationPartialTest { oper.setMaxFailures(10); verifyRun("testSetRetryFlag_testRetryOnFailure_RetriesExhausted", maxRetries + 1, maxRetries + 1, - PolicyResult.FAILURE_RETRIES); + OperationResult.FAILURE_RETRIES); } /** @@ -540,7 +540,7 @@ public class OperationPartialTest { oper.setMaxFailures(maxFailures); verifyRun("testSetRetryFlag_testRetryOnFailure_SuccessAfterRetries", maxFailures + 1, maxFailures + 1, - PolicyResult.SUCCESS); + OperationResult.SUCCESS); } /** @@ -560,7 +560,7 @@ public class OperationPartialTest { } }; - verifyRun("testSetRetryFlag_testRetryOnFailure_NullOutcome", 1, 1, PolicyResult.FAILURE, noop()); + verifyRun("testSetRetryFlag_testRetryOnFailure_NullOutcome", 1, 1, OperationResult.FAILURE, noop()); } @Test @@ -622,7 +622,7 @@ public class OperationPartialTest { @Test public void testHandlePreprocessorFailureSuccess() { oper.setPreProc(CompletableFuture.completedFuture(makeSuccess())); - verifyRun("testHandlePreprocessorFailureTrue", 1, 1, PolicyResult.SUCCESS); + verifyRun("testHandlePreprocessorFailureTrue", 1, 1, OperationResult.SUCCESS); } /** @@ -631,7 +631,7 @@ public class OperationPartialTest { @Test public void testHandlePreprocessorFailureFailed() throws Exception { oper.setPreProc(CompletableFuture.completedFuture(makeFailure())); - verifyRun("testHandlePreprocessorFailureFalse", 1, 0, PolicyResult.FAILURE_GUARD); + verifyRun("testHandlePreprocessorFailureFalse", 1, 0, OperationResult.FAILURE_GUARD); } /** @@ -641,7 +641,7 @@ public class OperationPartialTest { public void testHandlePreprocessorFailureNull() throws Exception { // arrange to return a null outcome from the preprocessor oper.setPreProc(CompletableFuture.completedFuture(null)); - verifyRun("testHandlePreprocessorFailureNull", 1, 0, PolicyResult.FAILURE_GUARD); + verifyRun("testHandlePreprocessorFailureNull", 1, 0, OperationResult.FAILURE_GUARD); } @Test @@ -649,7 +649,7 @@ public class OperationPartialTest { // arrange to generate an exception when operation runs oper.setGenException(true); - verifyRun("testFromException", 1, 1, PolicyResult.FAILURE_EXCEPTION); + verifyRun("testFromException", 1, 1, OperationResult.FAILURE_EXCEPTION); } /** @@ -657,7 +657,7 @@ public class OperationPartialTest { */ @Test public void testFromExceptionNoExcept() { - verifyRun("testFromExceptionNoExcept", 1, 1, PolicyResult.SUCCESS); + verifyRun("testFromExceptionNoExcept", 1, 1, OperationResult.SUCCESS); } /** @@ -843,13 +843,13 @@ public class OperationPartialTest { @Test public void testCombineOutcomes() throws Exception { // only one outcome - verifyOutcomes(0, PolicyResult.SUCCESS); - verifyOutcomes(0, PolicyResult.FAILURE_EXCEPTION); + verifyOutcomes(0, OperationResult.SUCCESS); + verifyOutcomes(0, OperationResult.FAILURE_EXCEPTION); // maximum is in different positions - verifyOutcomes(0, PolicyResult.FAILURE, PolicyResult.SUCCESS, PolicyResult.FAILURE_GUARD); - verifyOutcomes(1, PolicyResult.SUCCESS, PolicyResult.FAILURE, PolicyResult.FAILURE_GUARD); - verifyOutcomes(2, PolicyResult.SUCCESS, PolicyResult.FAILURE_GUARD, PolicyResult.FAILURE); + verifyOutcomes(0, OperationResult.FAILURE, OperationResult.SUCCESS, OperationResult.FAILURE_GUARD); + verifyOutcomes(1, OperationResult.SUCCESS, OperationResult.FAILURE, OperationResult.FAILURE_GUARD); + verifyOutcomes(2, OperationResult.SUCCESS, OperationResult.FAILURE_GUARD, OperationResult.FAILURE); // null outcome - takes precedence over a success List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); @@ -904,7 +904,7 @@ public class OperationPartialTest { // second task fails, third should not run OperationOutcome failure = params.makeOutcome(null); - failure.setResult(PolicyResult.FAILURE); + failure.setResult(OperationResult.FAILURE); tasks.clear(); tasks.add(() -> CompletableFuture.completedFuture(outcome)); tasks.add(() -> CompletableFuture.completedFuture(failure)); @@ -936,7 +936,7 @@ public class OperationPartialTest { assertSame(future1, oper.sequence(() -> future1)); } - private void verifyOutcomes(int expected, PolicyResult... results) throws Exception { + private void verifyOutcomes(int expected, OperationResult... results) throws Exception { List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>(); OperationOutcome expectedOutcome = null; @@ -964,11 +964,11 @@ public class OperationPartialTest { OperationOutcome outcome = params.makeOutcome(null); - Map<PolicyResult, Integer> map = Map.of(PolicyResult.SUCCESS, 0, PolicyResult.FAILURE_GUARD, 2, - PolicyResult.FAILURE_RETRIES, 3, PolicyResult.FAILURE, 4, PolicyResult.FAILURE_TIMEOUT, 5, - PolicyResult.FAILURE_EXCEPTION, 6); + Map<OperationResult, Integer> map = Map.of(OperationResult.SUCCESS, 0, OperationResult.FAILURE_GUARD, 2, + OperationResult.FAILURE_RETRIES, 3, OperationResult.FAILURE, 4, OperationResult.FAILURE_TIMEOUT, 5, + OperationResult.FAILURE_EXCEPTION, 6); - for (Entry<PolicyResult, Integer> ent : map.entrySet()) { + for (Entry<OperationResult, Integer> ent : map.entrySet()) { outcome.setResult(ent.getKey()); assertEquals(ent.getKey().toString(), ent.getValue().intValue(), oper.detmPriority(outcome)); } @@ -1039,12 +1039,12 @@ public class OperationPartialTest { outcome = new OperationOutcome(); oper.setOutcome(outcome, timex); assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage()); - assertEquals(PolicyResult.FAILURE_TIMEOUT, outcome.getResult()); + assertEquals(OperationResult.FAILURE_TIMEOUT, outcome.getResult()); outcome = new OperationOutcome(); oper.setOutcome(outcome, new IllegalStateException(EXPECTED_EXCEPTION)); assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage()); - assertEquals(PolicyResult.FAILURE_EXCEPTION, outcome.getResult()); + assertEquals(OperationResult.FAILURE_EXCEPTION, outcome.getResult()); } @Test @@ -1052,15 +1052,15 @@ public class OperationPartialTest { OperationOutcome outcome; outcome = new OperationOutcome(); - oper.setOutcome(outcome, PolicyResult.SUCCESS); + oper.setOutcome(outcome, OperationResult.SUCCESS); assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage()); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); - oper.setOutcome(outcome, PolicyResult.SUCCESS); + oper.setOutcome(outcome, OperationResult.SUCCESS); assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage()); - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(OperationResult.SUCCESS, outcome.getResult()); - for (PolicyResult result : FAILURE_RESULTS) { + for (OperationResult result : FAILURE_RESULTS) { outcome = new OperationOutcome(); oper.setOutcome(outcome, result); assertEquals(result.toString(), ControlLoopOperation.FAILED_MSG, outcome.getMessage()); @@ -1199,14 +1199,14 @@ public class OperationPartialTest { private OperationOutcome makeSuccess() { OperationOutcome outcome = params.makeOutcome(null); - outcome.setResult(PolicyResult.SUCCESS); + outcome.setResult(OperationResult.SUCCESS); return outcome; } private OperationOutcome makeFailure() { OperationOutcome outcome = params.makeOutcome(null); - outcome.setResult(PolicyResult.FAILURE); + outcome.setResult(OperationResult.FAILURE); return outcome; } @@ -1220,7 +1220,7 @@ public class OperationPartialTest { * @param expectedResult expected outcome */ private void verifyRun(String testName, int expectedCallbacks, int expectedOperations, - PolicyResult expectedResult) { + OperationResult expectedResult) { verifyRun(testName, expectedCallbacks, expectedOperations, expectedResult, noop()); } @@ -1236,8 +1236,8 @@ public class OperationPartialTest { * {@link OperationPartial#start(ControlLoopOperationParams)} before the tasks * in the executor are run */ - private void verifyRun(String testName, int expectedCallbacks, int expectedOperations, PolicyResult expectedResult, - Consumer<CompletableFuture<OperationOutcome>> manipulator) { + private void verifyRun(String testName, int expectedCallbacks, int expectedOperations, + OperationResult expectedResult, Consumer<CompletableFuture<OperationOutcome>> manipulator) { tstart = null; opstart = null; @@ -1342,9 +1342,9 @@ public class OperationPartialTest { operation.setSubRequestId(String.valueOf(attempt)); if (count > maxFailures) { - operation.setResult(PolicyResult.SUCCESS); + operation.setResult(OperationResult.SUCCESS); } else { - operation.setResult(PolicyResult.FAILURE); + operation.setResult(OperationResult.FAILURE); } return operation; diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java index 5e79247ed..caa840891 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java @@ -57,7 +57,6 @@ import org.onap.policy.controlloop.actorserviceprovider.Operator; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams.ControlLoopOperationParamsBuilder; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; -import org.onap.policy.controlloop.policy.Target; public class ControlLoopOperationParamsTest { private static final String NULL_MSG = "null"; @@ -65,7 +64,6 @@ public class ControlLoopOperationParamsTest { private static final String EXPECTED_EXCEPTION = "expected exception"; private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-operation"; - private static final Target TARGET = new Target(); private static final String TARGET_ENTITY = "my-target"; private static final Integer RETRY = 3; private static final Integer TIMEOUT = 100; @@ -128,7 +126,7 @@ public class ControlLoopOperationParamsTest { params = ControlLoopOperationParams.builder().actorService(actorService).completeCallback(completer) .context(context).executor(executor).actor(ACTOR).operation(OPERATION).payload(payload) - .retry(RETRY).target(TARGET).targetEntity(TARGET_ENTITY).timeoutSec(TIMEOUT) + .retry(RETRY).targetEntity(TARGET_ENTITY).timeoutSec(TIMEOUT) .startCallback(starter).preprocessed(true).build(); outcome = params.makeOutcome(TARGET_ENTITY); @@ -257,7 +255,7 @@ public class ControlLoopOperationParamsTest { assertTrue(params.toBuilder().build().validate().isValid()); // these can be null - assertTrue(params.toBuilder().payload(null).retry(null).target(null).timeoutSec(null).startCallback(null) + assertTrue(params.toBuilder().payload(null).retry(null).timeoutSec(null).startCallback(null) .completeCallback(null).build().validate().isValid()); // test with minimal fields @@ -356,14 +354,6 @@ public class ControlLoopOperationParamsTest { } @Test - public void testTarget() { - assertSame(TARGET, params.getTarget()); - - // should be null when unspecified - assertNull(ControlLoopOperationParams.builder().build().getTarget()); - } - - @Test public void testGetTimeoutSec() { assertSame(TIMEOUT, params.getTimeoutSec()); |