summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/main/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-02-20 09:40:14 -0500
committerJim Hahn <jrh3@att.com>2020-02-20 16:29:08 -0500
commit467247c7970f9ae83464d78929ed970bbf03c593 (patch)
tree54b78e6505b664c3a61e532bf6f7c276307d6591 /models-interactions/model-actors/actor.so/src/main/java
parentf6da7772d9dc01ce4ddd21a55b0f1c5fb7ad814f (diff)
More actor clean-up
Currently, Operator classes refer to Operation classes, and vice versa, creating a dependency cycle. In addition, there is a slight problem in that if an operator is reconfigured, any running operation may get inconsistent configuration data. Modified the code to create Config objects that are passed to the operation, instead of passing the Operator to the operations. This solved both issues. Replaceed makeOperator() with constructors. Added parameter type to HttpActors. Modified guard to get "ONAP" properties from its configuration, as a default. Changed setUp() to setUpBasic(), so "throws Exception" could be removed, thus resolving a sonar issue. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I21eb8798acfbc636ff1bd8741b21c7278365b6e4
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/main/java')
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java2
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConfig.java63
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java37
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperator.java62
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java9
5 files changed, 105 insertions, 68 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
index c7c6b00e9..1dbad623b 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
@@ -98,7 +98,7 @@ public class SoActorServiceProvider extends ActorImpl {
public SoActorServiceProvider() {
super(NAME);
- addOperator(SoOperator.makeSoOperator(NAME, VfModuleCreate.NAME, VfModuleCreate::new));
+ addOperator(new SoOperator(NAME, VfModuleCreate.NAME, VfModuleCreate::new));
}
// TODO old code: remove lines down to **HERE**
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConfig.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConfig.java
new file mode 100644
index 000000000..959cd454a
--- /dev/null
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoConfig.java
@@ -0,0 +1,63 @@
+/*-
+ * ============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.so;
+
+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 SoConfig 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;
+
+
+ /**
+ * 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 SoConfig(Executor blockingExecutor, SoParams 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.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java
index 510a737a6..d8d960e54 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java
@@ -41,6 +41,7 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.so.SoModelInfo;
@@ -68,8 +69,7 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
public static final String REQ_PARAM_NM = "requestParameters";
public static final String CONFIG_PARAM_NM = "configurationParameters";
- @Getter
- private final SoOperator operator;
+ private final SoConfig config;
/**
* Number of "get" requests issued so far, on the current operation attempt.
@@ -82,11 +82,11 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
* Constructs the object.
*
* @param params operation parameters
- * @param operator operator that created this operation
+ * @param config configuration for this operation
*/
- public SoOperation(ControlLoopOperationParams params, SoOperator operator) {
- super(params, operator, SoResponse.class);
- this.operator = operator;
+ public SoOperation(ControlLoopOperationParams params, HttpConfig config) {
+ super(params, config, SoResponse.class);
+ this.config = (SoConfig) config;
}
/**
@@ -134,9 +134,8 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
}
// see if the limit for the number of "gets" has been reached
- if (getCount++ >= operator.getMaxGets()) {
- logger.warn("{}: execeeded 'get' limit {} for {}", getFullName(), operator.getMaxGets(),
- params.getRequestId());
+ if (getCount++ >= getMaxGets()) {
+ logger.warn("{}: execeeded 'get' limit {} for {}", getFullName(), getMaxGets(), params.getRequestId());
setOutcome(outcome, PolicyResult.FAILURE_TIMEOUT);
outcome.setMessage(SO_RESPONSE_CODE + " " + outcome.getMessage());
return CompletableFuture.completedFuture(outcome);
@@ -155,15 +154,15 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
* @return a future that can be used to cancel the "get" request or await its response
*/
private CompletableFuture<OperationOutcome> issueGet(OperationOutcome outcome, SoResponse response) {
- String path = operator.getPathGet() + response.getRequestReferences().getRequestId();
- String url = operator.getClient().getBaseUrl() + path;
+ String path = getPathGet() + response.getRequestReferences().getRequestId();
+ String url = getClient().getBaseUrl() + path;
logger.debug("{}: 'get' count {} for {}", getFullName(), getCount, params.getRequestId());
logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
// TODO should this use "path" or the full "url"?
- return handleResponse(outcome, url, callback -> operator.getClient().get(callback, path, null));
+ return handleResponse(outcome, url, callback -> getClient().get(callback, path, null));
}
/**
@@ -335,6 +334,18 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
* @return the wait time, in milliseconds, between "get" requests
*/
public long getWaitMsGet() {
- return TimeUnit.MILLISECONDS.convert(operator.getWaitSecGet(), TimeUnit.SECONDS);
+ 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.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperator.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperator.java
index 011201f23..b8d0e652a 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperator.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperator.java
@@ -21,70 +21,32 @@
package org.onap.policy.controlloop.actor.so;
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.impl.HttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.impl.OperationMaker;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
-@Getter
-public abstract class SoOperator extends HttpOperator {
-
- /**
- * 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;
-
+/**
+ * SO Operator.
+ */
+public class SoOperator extends HttpOperator {
- public SoOperator(String actorName, String name) {
- super(actorName, name);
+ public SoOperator(String actorName, String name,
+ @SuppressWarnings("rawtypes") OperationMaker<HttpConfig, HttpOperation> operationMaker) {
+ super(actorName, name, operationMaker);
}
@Override
- protected void doConfigure(Map<String, Object> parameters) {
+ protected HttpConfig makeConfiguration(Map<String, Object> parameters) {
SoParams params = Util.translate(getFullName(), parameters, SoParams.class);
ValidationResult result = params.validate(getFullName());
if (!result.isValid()) {
throw new ParameterValidationRuntimeException("invalid parameters", result);
}
- this.pathGet = params.getPathGet() + (params.getPathGet().endsWith("/") ? "" : "/");
- this.maxGets = params.getMaxGets();
- this.waitSecGet = params.getWaitSecGet();
-
- super.doConfigure(params);
- }
-
- /**
- * Makes an operator that will construct operations.
- *
- * @param actorName actor name
- * @param operation operation name
- * @param operationMaker function to make an operation
- * @return a new operator
- */
- public static SoOperator makeSoOperator(String actorName, String operation,
- BiFunction<ControlLoopOperationParams, SoOperator, SoOperation> operationMaker) {
-
- return new SoOperator(actorName, operation) {
- @Override
- public Operation buildOperation(ControlLoopOperationParams params) {
- return operationMaker.apply(params, this);
- }
- };
+ return new SoConfig(getBlockingExecutor(), params, getClientFactory());
}
}
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
index f356dcefc..c17d25211 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java
@@ -35,6 +35,7 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.controlloop.actor.aai.AaiCustomQueryOperation;
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.so.SoCloudConfiguration;
import org.onap.policy.so.SoModelInfo;
import org.onap.policy.so.SoOperationType;
@@ -47,8 +48,8 @@ import org.onap.policy.so.SoRequestParameters;
public class VfModuleCreate extends SoOperation {
public static final String NAME = "VF Module Create";
- public VfModuleCreate(ControlLoopOperationParams params, SoOperator operator) {
- super(params, operator);
+ public VfModuleCreate(ControlLoopOperationParams params, HttpConfig config) {
+ super(params, config);
}
/**
@@ -75,13 +76,13 @@ public class VfModuleCreate extends SoOperation {
SoRequest request = pair.getRight();
Entity<SoRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
- String url = getOperator().getClient().getBaseUrl() + path;
+ String url = getClient().getBaseUrl() + path;
logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
// TODO should this use "path" or the full "url"?
- return handleResponse(outcome, url, callback -> getOperator().getClient().post(callback, path, entity, null));
+ return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, null));
}
/**