diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-10 15:44:29 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-11 12:28:45 -0400 |
commit | abba1c2f8fc792b63392302fec99ee27147362aa (patch) | |
tree | 93310e97ab67820e2f6ffde946afa7c259e1a7a1 /models-interactions | |
parent | eeb8d3b9c25e792e08ffe2d10b3f4b1d983a46fd (diff) |
Default ActorImpl should have an "operations" property
Added "operations" level to actor properties. Also renamed CommonActorParams
to ActorParams, in the process.
Note: This impacts the properties specified in drools-apps.
Issue-ID: POLICY-2629
Change-Id: I155bcb6ced73cb54e656d34e0b184fb2ed6250d1
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions')
16 files changed, 61 insertions, 50 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/test/resources/service.yaml b/models-interactions/model-actors/actor.cds/src/test/resources/service.yaml index 0d3c76f48..19ff698a3 100644 --- a/models-interactions/model-actors/actor.cds/src/test/resources/service.yaml +++ b/models-interactions/model-actors/actor.cds/src/test/resources/service.yaml @@ -19,9 +19,10 @@ # actors: CDS: - any: - timeout: 10 - port: 6700 - host: my-host - username: my-user - password: my-pass + operations: + any: + timeout: 10 + port: 6700 + host: my-host + username: my-user + password: my-pass diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java index 0fef3bd29..71c75b8cf 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java @@ -32,7 +32,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Util; -import org.onap.policy.controlloop.actorserviceprovider.parameters.CommonActorParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams; public class GuardActorParamsTest { private static final String CONTAINER = "my-container"; @@ -75,14 +75,14 @@ public class GuardActorParamsTest { assertTrue(params.validate(CONTAINER).isValid()); // only a few fields are required - GuardActorParams sparse = Util.translate(CONTAINER, Map.of(CommonActorParams.OPERATIONS_FIELD, operations), + GuardActorParams sparse = Util.translate(CONTAINER, Map.of(ActorParams.OPERATIONS_FIELD, operations), GuardActorParams.class); assertTrue(sparse.validate(CONTAINER).isValid()); assertEquals(GuardActorParams.DEFAULT_ACTION, sparse.getAction()); // check fields from superclass - testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); + testValidateField(ActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1)); } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java index 5fb647253..93f305550 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java @@ -31,7 +31,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Util; -import org.onap.policy.controlloop.actorserviceprovider.parameters.CommonActorParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams; public class SoActorParamsTest { @@ -68,7 +68,7 @@ public class SoActorParamsTest { assertTrue(params.validate(CONTAINER).isValid()); // only a few fields are required - SoActorParams sparse = Util.translate(CONTAINER, Map.of(CommonActorParams.OPERATIONS_FIELD, operations), + SoActorParams sparse = Util.translate(CONTAINER, Map.of(ActorParams.OPERATIONS_FIELD, operations), SoActorParams.class); assertTrue(sparse.validate(CONTAINER).isValid()); @@ -76,7 +76,7 @@ public class SoActorParamsTest { testValidateField("waitSecGet", "minimum", params2 -> params2.setWaitSecGet(0)); // check fields from superclass - testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); + testValidateField(ActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1)); // check edge cases diff --git a/models-interactions/model-actors/actor.test/src/test/resources/service.yaml b/models-interactions/model-actors/actor.test/src/test/resources/service.yaml index 49de7da51..1d1604034 100644 --- a/models-interactions/model-actors/actor.test/src/test/resources/service.yaml +++ b/models-interactions/model-actors/actor.test/src/test/resources/service.yaml @@ -19,5 +19,6 @@ # actors: MyActor: - MyOperationA: {} - MyOperationB: {}
\ No newline at end of file + operations: + MyOperationA: {} + MyOperationB: {} diff --git a/models-interactions/model-actors/actor.test/src/test/resources/serviceFull.yaml b/models-interactions/model-actors/actor.test/src/test/resources/serviceFull.yaml index 9818215be..8c6271e85 100644 --- a/models-interactions/model-actors/actor.test/src/test/resources/serviceFull.yaml +++ b/models-interactions/model-actors/actor.test/src/test/resources/serviceFull.yaml @@ -38,5 +38,6 @@ topics: managed: true actors: MyActor: - MyOperationA: {} - MyOperationB: {}
\ No newline at end of file + operations: + MyOperationA: {} + MyOperationB: {} diff --git a/models-interactions/model-actors/actor.test/src/test/resources/serviceInvalidHttp.yaml b/models-interactions/model-actors/actor.test/src/test/resources/serviceInvalidHttp.yaml index b31e8e81e..416126893 100644 --- a/models-interactions/model-actors/actor.test/src/test/resources/serviceInvalidHttp.yaml +++ b/models-interactions/model-actors/actor.test/src/test/resources/serviceInvalidHttp.yaml @@ -25,5 +25,6 @@ httpClients: managed: true actors: MyActor: - MyOperationA: {} - MyOperationB: {}
\ No newline at end of file + operations: + MyOperationA: {} + MyOperationB: {} diff --git a/models-interactions/model-actors/actor.vfc/src/test/resources/service.yaml b/models-interactions/model-actors/actor.vfc/src/test/resources/service.yaml index 26192e013..f6988517b 100644 --- a/models-interactions/model-actors/actor.vfc/src/test/resources/service.yaml +++ b/models-interactions/model-actors/actor.vfc/src/test/resources/service.yaml @@ -25,7 +25,8 @@ httpClients: managed: true actors: VFC: - Restart: + operations: + Restart: clientName: my-client pathGet: jobs maxGets: 20 diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java index 6113f9391..c3c815e80 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImpl.java @@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import org.onap.policy.controlloop.actorserviceprovider.Operator; import org.onap.policy.controlloop.actorserviceprovider.Util; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.slf4j.Logger; @@ -156,7 +157,8 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement /** * Extracts the operator parameters from the actor parameters, for a given operator. - * This method assumes each operation has its own set of parameters. + * This method translates the parameters to an {@link ActorParams} and then creates a function + * that will extract operator-specific parameters. * * @param actorParameters actor parameters * @return a function to extract the operator parameters from the actor parameters. @@ -164,8 +166,13 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement * the given operation name */ protected Function<String, Map<String, Object>> makeOperatorParameters(Map<String, Object> actorParameters) { + String actorName = getName(); - return operName -> Util.translateToMap(getName() + "." + operName, actorParameters.get(operName)); + // @formatter:off + return Util.translate(actorName, actorParameters, ActorParams.class) + .doValidation(actorName) + .makeOperationParameters(actorName); + // @formatter:on } /** diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParams.java index b8218e53b..948677fa4 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParams.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParams.java @@ -38,7 +38,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util; @Getter @Setter @EqualsAndHashCode -public class CommonActorParams { +public class ActorParams { /** * Name of the "operations" field contained within actor parameters. */ @@ -84,7 +84,7 @@ public class CommonActorParams { * @return "this" * @throws IllegalArgumentException if the parameters are invalid */ - public CommonActorParams doValidation(String name) { + public ActorParams doValidation(String name) { ValidationResult result = validate(name); if (!result.isValid()) { throw new ParameterValidationRuntimeException("invalid parameters", result); diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParams.java index 291aeeb23..3e65e4729 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParams.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParams.java @@ -31,7 +31,7 @@ import org.onap.policy.common.parameters.annotations.Min; @Getter @Setter @EqualsAndHashCode(callSuper = true) -public class BidirectionalTopicActorParams extends CommonActorParams { +public class BidirectionalTopicActorParams extends ActorParams { /* * Optional, default values that are used if missing from the operation-specific diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParams.java index d589e1d7e..616f674c5 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParams.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParams.java @@ -31,7 +31,7 @@ import org.onap.policy.common.parameters.annotations.Min; @Getter @Setter @EqualsAndHashCode(callSuper = true) -public class HttpActorParams extends CommonActorParams { +public class HttpActorParams extends ActorParams { /* * Optional, default values that are used if missing from the operation-specific diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java index 0f282f662..97f6bbacf 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java @@ -36,6 +36,7 @@ import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.TreeMap; @@ -46,6 +47,7 @@ import org.junit.Test; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.controlloop.actorserviceprovider.impl.ActorImpl; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; @@ -80,10 +82,10 @@ public class ActorServiceTest { actor3 = spy(new ActorImpl(ACTOR3)); actor4 = spy(new ActorImpl(ACTOR4)); - sub1 = Map.of("sub A", "value A"); - sub2 = Map.of("sub B", "value B"); - sub3 = Map.of("sub C", "value C"); - sub4 = Map.of("sub D", "value D"); + sub1 = Map.of("sub A", "value A", ActorParams.OPERATIONS_FIELD, Collections.emptyMap()); + sub2 = Map.of("sub B", "value B", ActorParams.OPERATIONS_FIELD, Collections.emptyMap()); + sub3 = Map.of("sub C", "value C", ActorParams.OPERATIONS_FIELD, Collections.emptyMap()); + sub4 = Map.of("sub D", "value D", ActorParams.OPERATIONS_FIELD, Collections.emptyMap()); params = Map.of(ACTOR1, sub1, ACTOR2, sub2, ACTOR3, sub3, ACTOR4, sub4); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java index 681378de4..cf07d3b2b 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/ActorImplTest.java @@ -36,7 +36,6 @@ import static org.mockito.Mockito.when; import java.util.Iterator; import java.util.Map; -import java.util.TreeMap; import java.util.stream.Collectors; import org.junit.Before; import org.junit.Test; @@ -44,6 +43,7 @@ import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.Operator; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; @@ -84,7 +84,7 @@ public class ActorImplTest { sub3 = Map.of("sub C", "value C"); sub4 = Map.of("sub D", "value D"); - params = Map.of(OPER1, sub1, OPER2, sub2, OPER3, sub3, OPER4, sub4); + params = Map.of(ActorParams.OPERATIONS_FIELD, Map.of(OPER1, sub1, OPER2, sub2, OPER3, sub3, OPER4, sub4)); actor = makeActor(oper1, oper2, oper3, oper4); } @@ -285,15 +285,12 @@ public class ActorImplTest { */ @Test public void testDoConfigureConfigure() { - // need mutable parameters - params = new TreeMap<>(params); - // configure one operator oper1.configure(sub1); // configure another and remove its parameters oper2.configure(sub2); - params.remove(OPER2); + params = Map.of(ActorParams.OPERATIONS_FIELD, Map.of(OPER1, sub1, OPER3, sub3, OPER4, sub4)); // create a new, unconfigured actor Operator oper5 = spy(new MyOper("UNCONFIGURED")); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParamsTest.java index 99b441064..0304ef3be 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ActorParamsTest.java @@ -39,7 +39,7 @@ import org.junit.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Util; -public class CommonActorParamsTest { +public class ActorParamsTest { private static final String CONTAINER = "my-container"; @@ -52,7 +52,7 @@ public class CommonActorParamsTest { private static final String TEXT2B = "bye"; private Map<String, Map<String, Object>> operations; - private CommonActorParams params; + private ActorParams params; /** * Initializes {@link #operations} with two items and {@link params} with a fully @@ -64,7 +64,7 @@ public class CommonActorParamsTest { operations.put(PATH1, Map.of("path", URI1)); operations.put(PATH2, Map.of("path", URI2, "text2", TEXT2B)); - params = makeCommonActorParams(); + params = makeActorParams(); } @Test @@ -96,29 +96,29 @@ public class CommonActorParamsTest { assertTrue(params.validate(CONTAINER).isValid()); // only a few fields are required - CommonActorParams sparse = Util.translate(CONTAINER, - Map.of(CommonActorParams.OPERATIONS_FIELD, operations, "timeoutSec", 1), - CommonActorParams.class); + ActorParams sparse = Util.translate(CONTAINER, + Map.of(ActorParams.OPERATIONS_FIELD, operations, "timeoutSec", 1), + ActorParams.class); assertTrue(sparse.validate(CONTAINER).isValid()); - testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); + testValidateField(ActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); } - private void testValidateField(String fieldName, String expected, Consumer<CommonActorParams> makeInvalid) { + private void testValidateField(String fieldName, String expected, Consumer<ActorParams> makeInvalid) { // original params should be valid ValidationResult result = params.validate(CONTAINER); assertTrue(fieldName, result.isValid()); // make invalid params - CommonActorParams params2 = makeCommonActorParams(); + ActorParams params2 = makeActorParams(); makeInvalid.accept(params2); result = params2.validate(CONTAINER); assertFalse(fieldName, result.isValid()); assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected); } - private CommonActorParams makeCommonActorParams() { + private ActorParams makeActorParams() { MyParams params2 = new MyParams(); params2.setOperations(operations); params2.setText1(TEXT1); @@ -128,7 +128,7 @@ public class CommonActorParamsTest { } @Setter - public static class MyParams extends CommonActorParams { + public static class MyParams extends ActorParams { @SuppressWarnings("unused") private String text1; diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java index 1276950a5..769e0fca5 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java @@ -77,11 +77,11 @@ public class BidirectionalTopicActorParamsTest { // only a few fields are required BidirectionalTopicActorParams sparse = - Util.translate(CONTAINER, Map.of(CommonActorParams.OPERATIONS_FIELD, operMap, "timeoutSec", 1), + Util.translate(CONTAINER, Map.of(ActorParams.OPERATIONS_FIELD, operMap, "timeoutSec", 1), BidirectionalTopicActorParams.class); assertTrue(sparse.validate(CONTAINER).isValid()); - testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); + testValidateField(ActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1)); // check edge cases diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java index 99bf63305..5812b0437 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java @@ -65,10 +65,10 @@ public class HttpActorParamsTest { // only a few fields are required HttpActorParams sparse = Util.translate(CONTAINER, - Map.of(CommonActorParams.OPERATIONS_FIELD, operations, "timeoutSec", 1), HttpActorParams.class); + Map.of(ActorParams.OPERATIONS_FIELD, operations, "timeoutSec", 1), HttpActorParams.class); assertTrue(sparse.validate(CONTAINER).isValid()); - testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); + testValidateField(ActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null)); testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1)); // check edge cases |