diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-11 19:00:41 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-12 18:40:29 -0400 |
commit | e9af3a2b3a430626c740b18ccf8592706db1dfb1 (patch) | |
tree | ff0d351b54f4862de8512666d3a7c1371ef73118 /models-interactions/model-actors/actorServiceProvider/src/main | |
parent | c34fdc19686d70af12e8873b0b01b96dd54c1aa3 (diff) |
Moving common polling code into HttpOperation
SO and VFC have duplicate code for polling. Moved it into the
common superclass.
Issue-ID: POLICY-2632
Change-Id: I27128bfb2d54ef522b6b44ff569819a8463f3454
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider/src/main')
9 files changed, 503 insertions, 89 deletions
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 43c8b8872..0745c3aba 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,14 +23,10 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import java.util.Arrays; import java.util.List; import java.util.Map; -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; @@ -40,13 +36,8 @@ import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey; * Operator that uses a bidirectional topic. Topic operators may share a * {@link BidirectionalTopicHandler}. */ -public class BidirectionalTopicOperator extends OperatorPartial { - - /** - * Function to make an operation. - */ - @SuppressWarnings("rawtypes") - private final OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation> operationMaker; +public class BidirectionalTopicOperator + extends TypedOperator<BidirectionalTopicConfig, BidirectionalTopicOperation<?, ?>> { /** * Manager from which to get the topic handlers. @@ -58,12 +49,6 @@ public class BidirectionalTopicOperator extends OperatorPartial { */ private final List<SelectorKey> selectorKeys; - /** - * Current configuration. This is set by {@link #doConfigure(Map)}. - */ - @Getter - private BidirectionalTopicConfig currentConfig; - /** * Constructs the object. @@ -88,17 +73,13 @@ public 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, - @SuppressWarnings("rawtypes") OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation> - operationMaker) { - // @formatter:on + OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation<?, ?>> operationMaker) { - super(actorName, name); + super(actorName, name, operationMaker); this.topicManager = topicManager; this.selectorKeys = selectorKeys; - this.operationMaker = operationMaker; } /** @@ -110,25 +91,13 @@ public 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, - @SuppressWarnings("rawtypes") OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation> - operationMaker, + 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 a new configuration using the specified parameters. * * @param parameters operator parameters @@ -143,15 +112,4 @@ public class BidirectionalTopicOperator extends OperatorPartial { 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 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 eb5662f23..5a6081611 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 @@ -34,7 +34,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorPara public class HttpActor<P extends HttpActorParams> extends ActorImpl { /** - * Class of parameters. + * Class of Actor parameters. */ private final Class<P> paramsClass; 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 fb6d38292..4800b3a4b 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 @@ -25,6 +25,7 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import javax.ws.rs.client.InvocationCallback; import javax.ws.rs.core.Response; @@ -38,6 +39,7 @@ 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.parameters.HttpPollingConfig; import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture; import org.onap.policy.controlloop.policy.PolicyResult; import org.slf4j.Logger; @@ -53,6 +55,13 @@ public abstract class HttpOperation<T> extends OperationPartial { private static final Logger logger = LoggerFactory.getLogger(HttpOperation.class); /** + * Response status. + */ + public enum Status { + SUCCESS, FAILURE, STILL_WAITING + } + + /** * Configuration for this operation. */ private final HttpConfig config; @@ -62,6 +71,18 @@ public abstract class HttpOperation<T> extends OperationPartial { */ private final Class<T> responseClass; + /** + * {@code True} to use polling, {@code false} otherwise. + */ + @Getter + private boolean usePolling; + + /** + * Number of polls issued so far, on the current operation attempt. + */ + @Getter + private int pollCount; + /** * Constructs the object. @@ -76,6 +97,17 @@ public abstract class HttpOperation<T> extends OperationPartial { this.responseClass = clazz; } + /** + * Indicates that polling should be used. + */ + protected void setUsePolling() { + if (!(config instanceof HttpPollingConfig)) { + throw new IllegalStateException("cannot poll without polling parameters"); + } + + usePolling = true; + } + public HttpClient getClient() { return config.getClient(); } @@ -123,6 +155,17 @@ public abstract class HttpOperation<T> extends OperationPartial { } /** + * Resets the polling count + * + * <p/> + * Note: This should be invoked at the start of each operation (i.e., in + * {@link #startOperationAsync(int, OperationOutcome)}. + */ + protected void resetPollCount() { + pollCount = 0; + } + + /** * Arranges to handle a response. * * @param outcome outcome to be populate @@ -234,7 +277,88 @@ public abstract class HttpOperation<T> extends OperationPartial { protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url, Response rawResponse, T response) { - return CompletableFuture.completedFuture(outcome); + if (!usePolling) { + // doesn't use polling - just return the completed future + return CompletableFuture.completedFuture(outcome); + } + + HttpPollingConfig cfg = (HttpPollingConfig) config; + + switch (detmStatus(rawResponse, response)) { + case SUCCESS: + logger.info("{}.{} request succeeded for {}", params.getActor(), params.getOperation(), + params.getRequestId()); + return CompletableFuture + .completedFuture(setOutcome(outcome, PolicyResult.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)); + + case STILL_WAITING: + default: + logger.info("{}.{} request incomplete for {}", params.getActor(), params.getOperation(), + params.getRequestId()); + break; + } + + // still incomplete + + // see if the limit for the number of polls has been reached + if (pollCount++ >= cfg.getMaxPolls()) { + logger.warn("{}: execeeded 'poll' limit {} for {}", getFullName(), cfg.getMaxPolls(), + params.getRequestId()); + setOutcome(outcome, PolicyResult.FAILURE_TIMEOUT); + return CompletableFuture.completedFuture(outcome); + } + + // sleep and then poll + Function<Void, CompletableFuture<OperationOutcome>> doPoll = unused -> issuePoll(outcome); + return sleep(getPollWaitMs(), TimeUnit.MILLISECONDS).thenComposeAsync(doPoll); + } + + /** + * Polls to see if the original request is complete. This method polls using an HTTP + * "get" request whose URL is constructed by appending the extracted "poll ID" to the + * poll path from the configuration data. + * + * @param outcome outcome to be populated with the response + * @return a future that can be used to cancel the poll or await its response + */ + protected CompletableFuture<OperationOutcome> issuePoll(OperationOutcome outcome) { + String path = getPollingPath(); + String url = getClient().getBaseUrl() + path; + + logger.debug("{}: 'poll' count {} for {}", getFullName(), pollCount, params.getRequestId()); + + logMessage(EventType.OUT, CommInfrastructure.REST, url, null); + + return handleResponse(outcome, url, callback -> getClient().get(callback, path, null)); + } + + /** + * Determines the status of the response. This particular method simply throws an + * exception. + * + * @param rawResponse raw response + * @param response decoded response + * @return the status of the response + */ + protected Status detmStatus(Response rawResponse, T response) { + throw new UnsupportedOperationException("cannot determine response status"); + } + + /** + * Gets the URL to use when polling. Typically, this is some unique ID appended to the + * polling path found within the configuration data. This particular method simply + * returns the polling path from the configuration data. + * + * @return the URL to use when polling + */ + protected String getPollingPath() { + return ((HttpPollingConfig) config).getPollPath(); } /** @@ -255,4 +379,12 @@ public abstract class HttpOperation<T> extends OperationPartial { NetLoggerUtil.log(direction, infra, sink, json); return json; } + + // these may be overridden by junit tests + + protected long getPollWaitMs() { + HttpPollingConfig cfg = (HttpPollingConfig) config; + + return TimeUnit.MILLISECONDS.convert(cfg.getPollWaitSec(), TimeUnit.SECONDS); + } } 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 9e446a7c8..f731a2c84 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,13 +21,10 @@ package org.onap.policy.controlloop.actorserviceprovider.impl; import java.util.Map; -import lombok.Getter; 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; @@ -35,20 +32,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterVali /** * Operator that uses HTTP. The operator's parameters must be an {@link HttpParams}. */ -public class HttpOperator extends OperatorPartial { - - /** - * Function to make an operation. - */ - @SuppressWarnings("rawtypes") - private final OperationMaker<HttpConfig, HttpOperation> operationMaker; - - /** - * Current configuration. This is set by {@link #doConfigure(Map)}. - */ - @Getter - private HttpConfig currentConfig; - +public class HttpOperator extends TypedOperator<HttpConfig,HttpOperation<?>> { /** * Constructs the object. @@ -68,18 +52,8 @@ public class HttpOperator extends OperatorPartial { * @param operationMaker function to make an operation */ public HttpOperator(String actorName, String name, - @SuppressWarnings("rawtypes") OperationMaker<HttpConfig, HttpOperation> operationMaker) { - super(actorName, name); - this.operationMaker = 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); + OperationMaker<HttpConfig, HttpOperation<?>> operationMaker) { + super(actorName, name, operationMaker); } /** @@ -98,17 +72,6 @@ public class HttpOperator extends OperatorPartial { return new HttpConfig(getBlockingExecutor(), params, getClientFactory()); } - @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 protected HttpClientFactory getClientFactory() { diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperator.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperator.java new file mode 100644 index 000000000..9e681ceeb --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperator.java @@ -0,0 +1,81 @@ +/*- + * ============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 java.util.Map; +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.Util; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; + +/** + * Operator that uses HTTP and polls for the request completion status. The operator's + * parameters must be an {@link HttpPollingParams}. + */ +public class HttpPollingOperator extends TypedOperator<HttpPollingConfig, HttpOperation<?>> { + + /** + * Constructs the object. + * + * @param actorName name of the actor with which this operator is associated + * @param name operation name + */ + protected HttpPollingOperator(String actorName, String name) { + this(actorName, name, null); + } + + /** + * Constructs the object. + * + * @param actorName name of the actor with which this operator is associated + * @param name operation name + * @param operationMaker function to make an operation + */ + public HttpPollingOperator(String actorName, String name, + OperationMaker<HttpPollingConfig, HttpOperation<?>> operationMaker) { + super(actorName, name, operationMaker); + } + + /** + * Makes a new configuration using the specified parameters. + * + * @param parameters operator parameters + * @return a new configuration + */ + protected HttpPollingConfig makeConfiguration(Map<String, Object> parameters) { + HttpPollingParams params = Util.translate(getFullName(), parameters, HttpPollingParams.class); + ValidationResult result = params.validate(getFullName()); + if (!result.isValid()) { + throw new ParameterValidationRuntimeException("invalid parameters", result); + } + + return new HttpPollingConfig(getBlockingExecutor(), params, getClientFactory()); + } + + // these may be overridden by junit tests + + protected HttpClientFactory getClientFactory() { + return HttpClientFactoryInstance.getClientFactory(); + } +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/TypedOperator.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/TypedOperator.java new file mode 100644 index 000000000..5561a97ef --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/TypedOperator.java @@ -0,0 +1,97 @@ +/*- + * ============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 java.util.Map; +import lombok.Getter; +import org.onap.policy.controlloop.actorserviceprovider.Operation; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; + +/** + * Operator with typed parameter information. + * + * @param <C> type of configuration data + * @param <T> type of operation that the operator creates + */ +public abstract class TypedOperator<C, T extends Operation> extends OperatorPartial { + + /** + * Function to make an operation. + */ + private final OperationMaker<C, T> operationMaker; + + /** + * Current configuration. This is set by {@link #doConfigure(Map)}. + */ + @Getter + private C currentConfig; + + + /** + * Constructs the object. + * + * @param actorName name of the actor with which this operator is associated + * @param name operation name + */ + protected TypedOperator(String actorName, String name) { + this(actorName, name, null); + } + + /** + * Constructs the object. + * + * @param actorName name of the actor with which this operator is associated + * @param name operation name + * @param operationMaker function to make an operation + */ + public TypedOperator(String actorName, String name, OperationMaker<C, T> operationMaker) { + super(actorName, name); + this.operationMaker = operationMaker; + } + + /** + * Translates the parameters, saving the relevant configuration data. + */ + @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 abstract C makeConfiguration(Map<String, Object> parameters); + + @Override + public T buildOperation(ControlLoopOperationParams params) { + if (operationMaker == null) { + throw new UnsupportedOperationException("cannot make operation for " + getFullName()); + } + + verifyRunning(); + + return operationMaker.apply(params, currentConfig); + } +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingActorParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingActorParams.java new file mode 100644 index 000000000..3343c5b3c --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingActorParams.java @@ -0,0 +1,59 @@ +/*- + * ============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 lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import org.onap.policy.common.parameters.annotations.Min; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorParams; + +/** + * Parameters used by Actors that, after issuing an HTTP request, must poll the target + * server to determine the request completion status. + */ +@Getter +@Setter +@EqualsAndHashCode(callSuper = true) +public class HttpPollingActorParams extends HttpActorParams { + + /* + * Optional, default values that are used if missing from the operation-specific + * parameters. + */ + + /** + * Path to use when polling for request completion. + */ + private String pollPath; + + /** + * Maximum number of times to poll to retrieve the response. + */ + @Min(0) + private int maxPolls = 3; + + /** + * Time, in seconds, to wait between polling. + */ + @Min(1) + private int pollWaitSec = 20; +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfig.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfig.java new file mode 100644 index 000000000..8e0daa07c --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfig.java @@ -0,0 +1,66 @@ +/*- + * ============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.Getter; +import org.onap.policy.common.endpoints.http.client.HttpClient; +import org.onap.policy.common.endpoints.http.client.HttpClientFactory; + +/** + * Configuration for HTTP Operators that, after issuing a request, must poll the target + * server to determine the request completion status. + */ +@Getter +public class HttpPollingConfig extends HttpConfig { + + /** + * Path to use when polling for request completion. A trailing "/" is added, if it is + * missing. + */ + private String pollPath; + + /** + * Maximum number of times to poll to retrieve the response. + */ + private int maxPolls; + + /** + * Time, in seconds, to wait between polling. + */ + private int pollWaitSec; + + + /** + * 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 HttpPollingConfig(Executor blockingExecutor, HttpPollingParams params, HttpClientFactory clientFactory) { + super(blockingExecutor, params, clientFactory); + + this.pollPath = params.getPollPath() + (params.getPollPath().endsWith("/") ? "" : "/"); + this.maxPolls = params.getMaxPolls(); + this.pollWaitSec = params.getPollWaitSec(); + } +} diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingParams.java new file mode 100644 index 000000000..2f33bd217 --- /dev/null +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingParams.java @@ -0,0 +1,58 @@ +/*- + * ============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 lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.SuperBuilder; +import org.onap.policy.common.parameters.annotations.Min; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; + +/** + * Parameters used by Operators that, after issuing an HTTP request, must poll the target + * server to determine the request completion status. + */ +@NotNull +@NotBlank +@Data +@EqualsAndHashCode(callSuper = true) +@SuperBuilder(toBuilder = true) +public class HttpPollingParams extends HttpParams { + + /** + * Path to use when polling for request completion. + */ + private String pollPath; + + /** + * Maximum number of times to poll to retrieve the response. + */ + @Min(0) + private int maxPolls; + + /** + * Time, in seconds, to wait between polling. + */ + @Min(1) + private int pollWaitSec; +} |