diff options
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider/src/main')
12 files changed, 402 insertions, 162 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActor.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActor.java index 1e44a170c..564bbc346 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActor.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActor.java @@ -27,14 +27,23 @@ import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.common.endpoints.event.comm.client.BidirectionalTopicClientException; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicActorParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager; /** - * Actor that uses a bidirectional topic. The actor's parameters must be a - * {@link BidirectionalTopicActorParams}. + * Actor that uses a bidirectional topic. The actor's operator parameters are expected to + * be an {@link BidirectionalTopicParams}. + * + * @param <P> type of parameters */ -public class BidirectionalTopicActor extends ActorImpl implements BidirectionalTopicManager { +public class BidirectionalTopicActor<P extends BidirectionalTopicActorParams> extends ActorImpl + implements BidirectionalTopicManager { + + /** + * Class of parameters. + */ + private final Class<P> paramsClass; /** * Maps a pair of sink and source topic names to their bidirectional topic. @@ -47,8 +56,9 @@ public class BidirectionalTopicActor extends ActorImpl implements BidirectionalT * * @param name actor's name */ - public BidirectionalTopicActor(String name) { + public BidirectionalTopicActor(String name, Class<P> paramsClass) { super(name); + this.paramsClass = paramsClass; } @Override @@ -92,7 +102,7 @@ public class BidirectionalTopicActor extends ActorImpl implements BidirectionalT String actorName = getName(); // @formatter:off - return Util.translate(actorName, actorParameters, BidirectionalTopicActorParams.class) + return Util.translate(actorName, actorParameters, paramsClass) .doValidation(actorName) .makeOperationParameters(actorName); // @formatter:on 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 d1e21f8fd..1ae80490c 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 @@ -23,14 +23,13 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; import lombok.Getter; 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.parameters.BidirectionalTopicParams; +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; @@ -55,34 +54,40 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial SUCCESS, FAILURE, STILL_WAITING } - // fields extracted from the operator - - private final BidirectionalTopicHandler topicHandler; - private final Forwarder forwarder; - private final BidirectionalTopicParams topicParams; - private final long timeoutMs; + /** + * Configuration for this operation. + */ + private final BidirectionalTopicConfig config; /** * Response class. */ private final Class<S> responseClass; + // fields extracted from "config" + + private final BidirectionalTopicHandler topicHandler; + private final Forwarder forwarder; + /** * Constructs the object. * * @param params operation parameters - * @param operator operator that created this operation + * @param config configuration for this operation * @param clazz response class */ - public BidirectionalTopicOperation(ControlLoopOperationParams params, BidirectionalTopicOperator operator, + public BidirectionalTopicOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config, Class<S> clazz) { - super(params, operator); - this.topicHandler = operator.getTopicHandler(); - this.forwarder = operator.getForwarder(); - this.topicParams = operator.getParams(); + super(params, config); + this.config = config; this.responseClass = clazz; - this.timeoutMs = TimeUnit.MILLISECONDS.convert(topicParams.getTimeoutSec(), TimeUnit.SECONDS); + this.forwarder = config.getForwarder(); + this.topicHandler = config.getTopicHandler(); + } + + public long getTimeoutMs() { + return config.getTimeoutMs(); } /** @@ -91,7 +96,7 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial @Override protected long getTimeoutMs(Integer timeoutSec) { // TODO move this method to the superclass - return (timeoutSec == null || timeoutSec == 0 ? this.timeoutMs : super.getTimeoutMs(timeoutSec)); + return (timeoutSec == null || timeoutSec == 0 ? getTimeoutMs() : super.getTimeoutMs(timeoutSec)); } /** diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperator.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperator.java index 51689e49b..43c8b8872 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperator.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperator.java @@ -23,24 +23,30 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.function.BiFunction; import lombok.Getter; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.Util; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager; -import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey; /** * Operator that uses a bidirectional topic. Topic operators may share a * {@link BidirectionalTopicHandler}. */ -public abstract class BidirectionalTopicOperator extends OperatorPartial { +public class BidirectionalTopicOperator extends OperatorPartial { + + /** + * Function to make an operation. + */ + @SuppressWarnings("rawtypes") + private final OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation> operationMaker; /** * Manager from which to get the topic handlers. @@ -52,30 +58,26 @@ public abstract class BidirectionalTopicOperator extends OperatorPartial { */ private final List<SelectorKey> selectorKeys; - /* - * The remaining fields are initialized when configure() is invoked, thus they may - * change. - */ - /** - * Current parameters. While {@link params} may change, the values contained within it - * will not, thus operations may copy it. + * Current configuration. This is set by {@link #doConfigure(Map)}. */ @Getter - private BidirectionalTopicParams params; + private BidirectionalTopicConfig currentConfig; - /** - * Topic handler associated with the parameters. - */ - @Getter - private BidirectionalTopicHandler topicHandler; /** - * Forwarder associated with the parameters. + * Constructs the object. + * + * @param actorName name of the actor with which this operator is associated + * @param name operation name + * @param topicManager manager from which to get the topic handler + * @param selectorKeys keys used to extract the fields used to select responses for + * this operator */ - @Getter - private Forwarder forwarder; - + protected BidirectionalTopicOperator(String actorName, String name, BidirectionalTopicManager topicManager, + List<SelectorKey> selectorKeys) { + this(actorName, name, topicManager, selectorKeys, null); + } /** * Constructs the object. @@ -86,75 +88,70 @@ public abstract class BidirectionalTopicOperator extends OperatorPartial { * @param selectorKeys keys used to extract the fields used to select responses for * this operator */ + // @formatter:off public BidirectionalTopicOperator(String actorName, String name, BidirectionalTopicManager topicManager, - List<SelectorKey> selectorKeys) { + List<SelectorKey> selectorKeys, + @SuppressWarnings("rawtypes") OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation> + operationMaker) { + // @formatter:on + super(actorName, name); this.topicManager = topicManager; this.selectorKeys = selectorKeys; - } - - @Override - protected void doConfigure(Map<String, Object> parameters) { - params = Util.translate(getFullName(), parameters, BidirectionalTopicParams.class); - ValidationResult result = params.validate(getFullName()); - if (!result.isValid()) { - throw new ParameterValidationRuntimeException("invalid parameters", result); - } - - topicHandler = topicManager.getTopicHandler(params.getSinkTopic(), params.getSourceTopic()); - forwarder = topicHandler.addForwarder(selectorKeys); + this.operationMaker = operationMaker; } /** - * Makes an operator that will construct operations. + * Constructs the object. * - * @param <Q> request type - * @param <S> response type - * @param actorName actor name - * @param operation operation name + * @param actorName name of the actor with which this operator is associated + * @param name operation name * @param topicManager manager from which to get the topic handler - * @param operationMaker function to make an operation - * @param keys keys used to extract the fields used to select responses for this - * operator - * @return a new operator + * @param selectorKeys keys used to extract the fields used to select responses for + * this operator */ // @formatter:off - public static <Q, S> BidirectionalTopicOperator makeOperator(String actorName, String operation, - BidirectionalTopicManager topicManager, - BiFunction<ControlLoopOperationParams, BidirectionalTopicOperator, - BidirectionalTopicOperation<Q, S>> operationMaker, - SelectorKey... keys) { - // @formatter:off - - return makeOperator(actorName, operation, topicManager, Arrays.asList(keys), operationMaker); + public BidirectionalTopicOperator(String actorName, String name, BidirectionalTopicManager topicManager, + @SuppressWarnings("rawtypes") OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation> + operationMaker, + SelectorKey... selectorKeys) { + // @formatter:on + this(actorName, name, topicManager, Arrays.asList(selectorKeys), operationMaker); + } + + /** + * Translates the parameters to an {@link HttpParams} and then extracts the relevant + * values. + */ + @Override + protected void doConfigure(Map<String, Object> parameters) { + currentConfig = makeConfiguration(parameters); } /** - * Makes an operator that will construct operations. + * Makes a new configuration using the specified parameters. * - * @param <Q> request type - * @param <S> response type - * @param actorName actor name - * @param operation operation name - * @param topicManager manager from which to get the topic handler - * @param keys keys used to extract the fields used to select responses for - * this operator - * @param operationMaker function to make an operation - * @return a new operator + * @param parameters operator parameters + * @return a new configuration */ - // @formatter:off - public static <Q,S> BidirectionalTopicOperator makeOperator(String actorName, String operation, - BidirectionalTopicManager topicManager, - List<SelectorKey> keys, - BiFunction<ControlLoopOperationParams, BidirectionalTopicOperator, - BidirectionalTopicOperation<Q,S>> operationMaker) { - // @formatter:on + protected BidirectionalTopicConfig makeConfiguration(Map<String, Object> parameters) { + BidirectionalTopicParams params = Util.translate(getFullName(), parameters, BidirectionalTopicParams.class); + ValidationResult result = params.validate(getFullName()); + if (!result.isValid()) { + throw new ParameterValidationRuntimeException("invalid parameters", result); + } + + return new BidirectionalTopicConfig(getBlockingExecutor(), params, topicManager, selectorKeys); + } + + @Override + public Operation buildOperation(ControlLoopOperationParams params) { + if (operationMaker == null) { + throw new UnsupportedOperationException("cannot make operation for " + getFullName()); + } + + verifyRunning(); - return new BidirectionalTopicOperator(actorName, operation, topicManager, keys) { - @Override - public synchronized Operation buildOperation(ControlLoopOperationParams params) { - return operationMaker.apply(params, this); - } - }; + return operationMaker.apply(params, currentConfig); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActor.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActor.java index 28b7b3924..eb5662f23 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActor.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActor.java @@ -27,18 +27,26 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorPara /** * Actor that uses HTTP, where the only additional property that an operator needs is a - * URL. The actor's parameters must be an {@link HttpActorParams} and its operator - * parameters are expected to be an {@link HttpParams}. + * URL. The actor's operator parameters are expected to be an {@link HttpParams}. + * + * @param <P> type of parameters */ -public class HttpActor extends ActorImpl { +public class HttpActor<P extends HttpActorParams> extends ActorImpl { + + /** + * Class of parameters. + */ + private final Class<P> paramsClass; /** * Constructs the object. * * @param name actor's name + * @param paramsClass class of parameters */ - public HttpActor(String name) { + public HttpActor(String name, Class<P> paramsClass) { super(name); + this.paramsClass = paramsClass; } /** @@ -50,7 +58,7 @@ public class HttpActor extends ActorImpl { String actorName = getName(); // @formatter:off - return Util.translate(actorName, actorParameters, HttpActorParams.class) + return Util.translate(actorName, actorParameters, paramsClass) .doValidation(actorName) .makeOperationParameters(actorName); // @formatter:on 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 da4887e15..4c007ea19 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 @@ -36,6 +36,7 @@ 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.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture; import org.onap.policy.controlloop.policy.PolicyResult; @@ -52,9 +53,9 @@ public abstract class HttpOperation<T> extends OperationPartial { private static final Logger logger = LoggerFactory.getLogger(HttpOperation.class); /** - * Operator that created this operation. + * Configuration for this operation. */ - private final HttpOperator operator; + private final HttpConfig config; /** * Response class. @@ -66,21 +67,33 @@ public abstract class HttpOperation<T> extends OperationPartial { * Constructs the object. * * @param params operation parameters - * @param operator operator that created this operation + * @param config configuration for this operation * @param clazz response class */ - public HttpOperation(ControlLoopOperationParams params, HttpOperator operator, Class<T> clazz) { - super(params, operator); - this.operator = operator; + public HttpOperation(ControlLoopOperationParams params, HttpConfig config, Class<T> clazz) { + super(params, config); + this.config = config; this.responseClass = clazz; } + public HttpClient getClient() { + return config.getClient(); + } + + public String getPath() { + return config.getPath(); + } + + public long getTimeoutMs() { + return config.getTimeoutMs(); + } + /** * If no timeout is specified, then it returns the operator's configured timeout. */ @Override protected long getTimeoutMs(Integer timeoutSec) { - return (timeoutSec == null || timeoutSec == 0 ? operator.getTimeoutMs() : super.getTimeoutMs(timeoutSec)); + return (timeoutSec == null || timeoutSec == 0 ? getTimeoutMs() : super.getTimeoutMs(timeoutSec)); } /** @@ -99,7 +112,7 @@ public abstract class HttpOperation<T> extends OperationPartial { * @return the path URI suffix */ public String makePath() { - return operator.getPath(); + return getPath(); } /** @@ -110,7 +123,7 @@ public abstract class HttpOperation<T> extends OperationPartial { * @return the URL to which from which to get */ public String makeUrl() { - return (operator.getClient().getBaseUrl() + makePath()); + return (getClient().getBaseUrl() + makePath()); } /** diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperator.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperator.java index b4a3318e7..9e446a7c8 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperator.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperator.java @@ -21,36 +21,33 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.function.BiFunction; import lombok.Getter; -import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.Util; 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.ParameterValidationRuntimeException; /** * Operator that uses HTTP. The operator's parameters must be an {@link HttpParams}. */ -@Getter -public abstract class HttpOperator extends OperatorPartial { - - private HttpClient client; +public class HttpOperator extends OperatorPartial { /** - * Default timeout, in milliseconds, if none specified in the request. + * Function to make an operation. */ - private long timeoutMs; + @SuppressWarnings("rawtypes") + private final OperationMaker<HttpConfig, HttpOperation> operationMaker; /** - * URI path for this particular operation. Includes a leading "/". + * Current configuration. This is set by {@link #doConfigure(Map)}. */ - private String path; + @Getter + private HttpConfig currentConfig; /** @@ -59,28 +56,21 @@ public abstract class HttpOperator extends OperatorPartial { * @param actorName name of the actor with which this operator is associated * @param name operation name */ - public HttpOperator(String actorName, String name) { - super(actorName, name); + protected HttpOperator(String actorName, String name) { + this(actorName, name, null); } /** - * Makes an operator that will construct operations. + * Constructs the object. * - * @param <T> response type - * @param actorName actor name - * @param operation operation name + * @param actorName name of the actor with which this operator is associated + * @param name operation name * @param operationMaker function to make an operation - * @return a new operator */ - public static <T> HttpOperator makeOperator(String actorName, String operation, - BiFunction<ControlLoopOperationParams, HttpOperator, HttpOperation<T>> operationMaker) { - - return new HttpOperator(actorName, operation) { - @Override - public Operation buildOperation(ControlLoopOperationParams params) { - return operationMaker.apply(params, this); - } - }; + public HttpOperator(String actorName, String name, + @SuppressWarnings("rawtypes") OperationMaker<HttpConfig, HttpOperation> operationMaker) { + super(actorName, name); + this.operationMaker = operationMaker; } /** @@ -89,24 +79,34 @@ public abstract class HttpOperator extends OperatorPartial { */ @Override protected void doConfigure(Map<String, Object> parameters) { + currentConfig = makeConfiguration(parameters); + } + + /** + * Makes a new configuration using the specified parameters. + * + * @param parameters operator parameters + * @return a new configuration + */ + protected HttpConfig makeConfiguration(Map<String, Object> parameters) { HttpParams params = Util.translate(getFullName(), parameters, HttpParams.class); ValidationResult result = params.validate(getFullName()); if (!result.isValid()) { throw new ParameterValidationRuntimeException("invalid parameters", result); } - doConfigure(params); + return new HttpConfig(getBlockingExecutor(), params, getClientFactory()); } - /** - * Configures the operator using the specified parameters. - * - * @param params operator parameters - */ - protected void doConfigure(HttpParams params) { - client = getClientFactory().get(params.getClientName()); - path = params.getPath(); - timeoutMs = TimeUnit.MILLISECONDS.convert(params.getTimeoutSec(), TimeUnit.SECONDS); + @Override + public Operation buildOperation(ControlLoopOperationParams params) { + if (operationMaker == null) { + throw new UnsupportedOperationException("cannot make operation for " + getFullName()); + } + + verifyRunning(); + + return operationMaker.apply(params, currentConfig); } // these may be overridden by junit tests diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationMaker.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationMaker.java new file mode 100644 index 000000000..ae95097b0 --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationMaker.java @@ -0,0 +1,34 @@ +/*- + * ============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.impl; + +import org.onap.policy.controlloop.actorserviceprovider.Operation; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; + +/** + * Function to make an operation. + * + * @param <C> configuration type + * @param <T> type of operation it creates + */ +public interface OperationMaker<C, T extends Operation> { + T apply(ControlLoopOperationParams params, C config); +} 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 680a56f89..e636228f6 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 @@ -35,6 +35,7 @@ import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.Supplier; import java.util.function.UnaryOperator; +import lombok.Getter; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.utils.NetLoggerUtil; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; @@ -46,6 +47,7 @@ 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.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; @@ -71,49 +73,43 @@ public abstract class OperationPartial implements Operation { public static final long DEFAULT_RETRY_WAIT_MS = 1000L; - // values extracted from the operator - - private final OperatorPartial operator; + private final OperatorConfig config; /** * Operation parameters. */ protected final ControlLoopOperationParams params; + @Getter + private final String fullName; + /** * Constructs the object. * * @param params operation parameters - * @param operator operator that created this operation + * @param config configuration for this operation */ - public OperationPartial(ControlLoopOperationParams params, OperatorPartial operator) { + public OperationPartial(ControlLoopOperationParams params, OperatorConfig config) { this.params = params; - this.operator = operator; + this.config = config; + this.fullName = params.getActor() + "." + params.getOperation(); } public Executor getBlockingExecutor() { - return operator.getBlockingExecutor(); - } - - public String getFullName() { - return operator.getFullName(); + return config.getBlockingExecutor(); } public String getActorName() { - return operator.getActorName(); + return params.getActor(); } public String getName() { - return operator.getName(); + return params.getOperation(); } @Override public final CompletableFuture<OperationOutcome> start() { - if (!operator.isAlive()) { - throw new IllegalStateException("operation is not running: " + getFullName()); - } - // allocate a controller for the entire operation final PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java index 3e15c1be4..8007c24f9 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java @@ -62,6 +62,17 @@ public abstract class OperatorPartial extends StartConfigPartial<Map<String, Obj } /** + * Verifies that the operator is running. + * + * @throws IllegalStateException if it is not running + */ + public void verifyRunning() { + if (!isAlive()) { + throw new IllegalStateException("operation is not running: " + getFullName()); + } + } + + /** * This method does nothing. */ @Override diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfig.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfig.java new file mode 100644 index 000000000..458314850 --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfig.java @@ -0,0 +1,70 @@ +/*- + * ============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.parameters; + +import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import lombok.Getter; +import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; +import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager; +import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; +import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey; + +/** + * Configuration for Bidirectional Topic Operators. + */ +@Getter +public class BidirectionalTopicConfig extends OperatorConfig { + + /** + * Topic handler associated with the parameters. + */ + private BidirectionalTopicHandler topicHandler; + + /** + * Forwarder associated with the parameters. + */ + private Forwarder forwarder; + + /** + * Default timeout, in milliseconds, if none specified in the request. + */ + private final long timeoutMs; + + + /** + * Constructs the object. + * + * @param blockingExecutor executor to be used for tasks that may perform blocking I/O + * @param params operator parameters + * @param topicManager manager from which to get the topic handler + * @param selectorKeys keys used to extract the fields used to select responses for + * this operator + */ + public BidirectionalTopicConfig(Executor blockingExecutor, BidirectionalTopicParams params, + BidirectionalTopicManager topicManager, List<SelectorKey> selectorKeys) { + super(blockingExecutor); + topicHandler = topicManager.getTopicHandler(params.getSinkTopic(), params.getSourceTopic()); + forwarder = topicHandler.addForwarder(selectorKeys); + timeoutMs = TimeUnit.MILLISECONDS.convert(params.getTimeoutSec(), TimeUnit.SECONDS); + } +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfig.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfig.java new file mode 100644 index 000000000..b3e08f707 --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfig.java @@ -0,0 +1,61 @@ +/*- + * ============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.parameters; + +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import lombok.Getter; +import org.onap.policy.common.endpoints.http.client.HttpClient; +import org.onap.policy.common.endpoints.http.client.HttpClientFactory; + +/** + * Configuration for HTTP Operators. + */ +@Getter +public class HttpConfig extends OperatorConfig { + + private final HttpClient client; + + /** + * Default timeout, in milliseconds, if none specified in the request. + */ + private final long timeoutMs; + + /** + * URI path for this particular operation. Includes a leading "/". + */ + private final String path; + + + /** + * Constructs the object. + * + * @param blockingExecutor executor to be used for tasks that may perform blocking I/O + * @param params operator parameters + * @param clientFactory factory from which to obtain the {@link HttpClient} + */ + public HttpConfig(Executor blockingExecutor, HttpParams params, HttpClientFactory clientFactory) { + super(blockingExecutor); + client = clientFactory.get(params.getClientName()); + path = params.getPath(); + timeoutMs = TimeUnit.MILLISECONDS.convert(params.getTimeoutSec(), TimeUnit.SECONDS); + } +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/OperatorConfig.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/OperatorConfig.java new file mode 100644 index 000000000..e5bd5f5ea --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/OperatorConfig.java @@ -0,0 +1,35 @@ +/*- + * ============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.parameters; + +import java.util.concurrent.Executor; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +public class OperatorConfig { + + /** + * Executor to be used for tasks that may perform blocking I/O. + */ + @Getter + private final Executor blockingExecutor; +} |