summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.vfc/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-06-11 19:00:41 -0400
committerJim Hahn <jrh3@att.com>2020-06-12 18:40:29 -0400
commite9af3a2b3a430626c740b18ccf8592706db1dfb1 (patch)
treeff0d351b54f4862de8512666d3a7c1371ef73118 /models-interactions/model-actors/actor.vfc/src/main
parentc34fdc19686d70af12e8873b0b01b96dd54c1aa3 (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/actor.vfc/src/main')
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java2
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java10
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcConfig.java63
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java115
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperator.java49
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcParams.java55
6 files changed, 38 insertions, 256 deletions
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java
index b6b82d14f..bc9642888 100644
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java
+++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java
@@ -41,7 +41,7 @@ public class Restart extends VfcOperation {
protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
// starting a whole new attempt - reset the count
- resetGetCount();
+ resetPollCount();
Pair<String, VfcRequest> pair = makeRequest();
Entity<VfcRequest> entity = Entity.entity(pair.getRight(), MediaType.APPLICATION_JSON);
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java
index 5bd6b59ad..768ad4c11 100644
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java
@@ -27,14 +27,16 @@ import java.util.List;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actorserviceprovider.impl.ActorImpl;
+import org.onap.policy.controlloop.actorserviceprovider.impl.HttpActor;
+import org.onap.policy.controlloop.actorserviceprovider.impl.HttpPollingOperator;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingActorParams;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.vfc.VfcHealActionVmInfo;
import org.onap.policy.vfc.VfcHealAdditionalParams;
import org.onap.policy.vfc.VfcHealRequest;
import org.onap.policy.vfc.VfcRequest;
-public class VfcActorServiceProvider extends ActorImpl {
+public class VfcActorServiceProvider extends HttpActor<HttpPollingActorParams> {
private static final String GENERIC_VNF_ID = "generic-vnf.vnf-id";
// TODO old code: remove lines down to **HERE**
@@ -60,9 +62,9 @@ public class VfcActorServiceProvider extends ActorImpl {
* Constructor.
*/
public VfcActorServiceProvider() {
- super(NAME);
+ super(NAME, HttpPollingActorParams.class);
- addOperator(new VfcOperator(NAME, Restart.NAME, Restart::new));
+ addOperator(new HttpPollingOperator(NAME, Restart.NAME, Restart::new));
}
// TODO old code: remove lines down to **HERE**
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcConfig.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcConfig.java
deleted file mode 100644
index 4b5088a3a..000000000
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcConfig.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * ============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.actor.vfc;
-
-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;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
-
-@Getter
-public class VfcConfig extends HttpConfig {
-
- /**
- * Path to use for the "get" request. A trailing "/" is added, if it is missing.
- */
- private String pathGet;
-
- /**
- * Maximum number of "get" requests permitted, after the initial request, to retrieve
- * the response.
- */
- private int maxGets;
-
- /**
- * Time, in seconds, to wait between issuing "get" requests.
- */
- private int waitSecGet;
-
- /**
- * Constructor.
- *
- * @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 VfcConfig(Executor blockingExecutor, VfcParams params, HttpClientFactory clientFactory) {
- super(blockingExecutor, params, clientFactory);
-
- this.pathGet = params.getPathGet() + (params.getPathGet().endsWith("/") ? "" : "/");
- this.maxGets = params.getMaxGets();
- this.waitSecGet = params.getWaitSecGet();
- }
-
-}
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
index 573ee2698..d5ee44a5d 100644
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
+++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java
@@ -21,13 +21,8 @@
package org.onap.policy.controlloop.actor.vfc;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Function;
import javax.ws.rs.core.Response;
-import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
@@ -39,12 +34,8 @@ import org.onap.policy.vfc.VfcHealAdditionalParams;
import org.onap.policy.vfc.VfcHealRequest;
import org.onap.policy.vfc.VfcRequest;
import org.onap.policy.vfc.VfcResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public abstract class VfcOperation extends HttpOperation<VfcResponse> {
- private static final Logger logger = LoggerFactory.getLogger(VfcOperation.class);
-
public static final String FAILED = "FAILED";
public static final String COMPLETE = "COMPLETE";
public static final int VFC_RESPONSE_CODE = 999;
@@ -53,13 +44,11 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
public static final String REQ_PARAM_NM = "requestParameters";
public static final String CONFIG_PARAM_NM = "configurationParameters";
- private final VfcConfig config;
-
/**
- * Number of "get" requests issued so far, on the current operation attempt.
+ * Job ID extracted from the first response.
*/
- @Getter
- private int getCount;
+ private String jobId;
+
/**
* Constructs the object.
@@ -69,14 +58,19 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
*/
public VfcOperation(ControlLoopOperationParams params, HttpConfig config) {
super(params, config, VfcResponse.class);
- this.config = (VfcConfig) config;
+
+ setUsePolling();
}
- /**
- * Subclasses should invoke this before issuing their first HTTP request.
- */
- protected void resetGetCount() {
- getCount = 0;
+ @Override
+ protected void resetPollCount() {
+ super.resetPollCount();
+ jobId = null;
+ }
+
+ @Override
+ protected String getPollingPath() {
+ return super.getPollingPath() + jobId;
}
/**
@@ -87,64 +81,38 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
return startGuardAsync();
}
- /**
- * If the response does not indicate that the request has been completed, then sleep a
- * bit and issue a "get".
- */
@Override
- protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url,
- Response rawResponse, VfcResponse response) {
- // Determine if the request has "completed" and determine if it was successful
+ protected Status detmStatus(Response rawResponse, VfcResponse response) {
if (rawResponse.getStatus() == 200) {
String requestState = getRequestState(response);
if ("finished".equalsIgnoreCase(requestState)) {
- return CompletableFuture
- .completedFuture(setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response));
+ extractJobId(response);
+ return Status.SUCCESS;
}
if ("error".equalsIgnoreCase(requestState)) {
- return CompletableFuture
- .completedFuture(setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response));
+ extractJobId(response);
+ return Status.FAILURE;
}
}
// still incomplete
- // need a request ID with which to query
- if (response == null || response.getJobId() == null) {
+ // need a job ID with which to query
+ if (jobId == null && !extractJobId(response)) {
throw new IllegalArgumentException("missing job ID in response");
}
- // see if the limit for the number of "gets" has been reached
- if (getCount++ >= getMaxGets()) {
- logger.warn("{}: execeeded 'get' limit {} for {}", getFullName(), getMaxGets(), params.getRequestId());
- setOutcome(outcome, PolicyResult.FAILURE_TIMEOUT);
- outcome.setResponse(response);
- outcome.setMessage(VFC_RESPONSE_CODE + " " + outcome.getMessage());
- return CompletableFuture.completedFuture(outcome);
- }
-
- // sleep and then perform a "get" operation
- Function<Void, CompletableFuture<OperationOutcome>> doGet = unused -> issueGet(outcome, response);
- return sleep(getWaitMsGet(), TimeUnit.MILLISECONDS).thenComposeAsync(doGet);
+ return Status.STILL_WAITING;
}
- /**
- * Issues a "get" request to see if the original request is complete yet.
- *
- * @param outcome outcome to be populated with the response
- * @param response previous response
- * @return a future that can be used to cancel the "get" request or await its response
- */
- private CompletableFuture<OperationOutcome> issueGet(OperationOutcome outcome, VfcResponse response) {
- String path = getPathGet() + response.getJobId();
- String url = getClient().getBaseUrl() + path;
-
- logger.debug("{}: 'get' count {} for {}", getFullName(), getCount, params.getRequestId());
-
- logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
+ private boolean extractJobId(VfcResponse response) {
+ if (response == null || response.getJobId() == null) {
+ return false;
+ }
- return handleResponse(outcome, url, callback -> getClient().get(callback, path, null));
+ jobId = response.getJobId();
+ return true;
}
/**
@@ -180,8 +148,10 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
// set default result and message
setOutcome(outcome, result);
+ int code = (result == PolicyResult.FAILURE_TIMEOUT ? VFC_RESPONSE_CODE : rawResponse.getStatus());
+
outcome.setResponse(response);
- outcome.setMessage(rawResponse.getStatus() + " " + outcome.getMessage());
+ outcome.setMessage(code + " " + outcome.getMessage());
return outcome;
}
@@ -221,27 +191,4 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> {
return request;
}
-
- // These may be overridden by jUnit tests
-
- /**
- * Gets the wait time, in milliseconds, between "get" requests.
- *
- * @return the wait time, in milliseconds, between "get" requests
- */
- public long getWaitMsGet() {
- return TimeUnit.MILLISECONDS.convert(getWaitSecGet(), TimeUnit.SECONDS);
- }
-
- public int getMaxGets() {
- return config.getMaxGets();
- }
-
- public String getPathGet() {
- return config.getPathGet();
- }
-
- public int getWaitSecGet() {
- return config.getWaitSecGet();
- }
}
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperator.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperator.java
deleted file mode 100644
index 4e70d6550..000000000
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * ============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.actor.vfc;
-
-import java.util.Map;
-import org.onap.policy.common.parameters.ValidationResult;
-import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
-import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator;
-import org.onap.policy.controlloop.actorserviceprovider.impl.OperationMaker;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
-
-public class VfcOperator extends HttpOperator {
-
- public VfcOperator(String actorName, String name,
- @SuppressWarnings("rawtypes") OperationMaker<HttpConfig, HttpOperation> operationMaker) {
- super(actorName, name, operationMaker);
- }
-
- @Override
- protected HttpConfig makeConfiguration(Map<String, Object> parameters) {
- VfcParams params = Util.translate(getFullName(), parameters, VfcParams.class);
- ValidationResult result = params.validate(getFullName());
- if (!result.isValid()) {
- throw new ParameterValidationRuntimeException("invalid parameters", result);
- }
-
- return new VfcConfig(getBlockingExecutor(), params, getClientFactory());
- }
-}
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcParams.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcParams.java
deleted file mode 100644
index 31c2a9441..000000000
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcParams.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * ============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.actor.vfc;
-
-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;
-
-@NotNull
-@NotBlank
-@Data
-@EqualsAndHashCode(callSuper = true)
-@SuperBuilder(toBuilder = true)
-public class VfcParams extends HttpParams {
-
- /**
- * Path to use for the "get" request.
- */
- private String pathGet;
-
- /**
- * Maximum number of "get" requests permitted, after the initial request, to retrieve
- * the response.
- */
- @Min(0)
- private int maxGets;
-
- /**
- * Time, in seconds, to wait between issuing "get" requests.
- */
- @Min(1)
- private int waitSecGet;
-}