aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.guard/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actor.guard/src/main')
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java43
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorServiceProvider.java7
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java72
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java16
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperator.java52
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java44
6 files changed, 223 insertions, 11 deletions
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java
new file mode 100644
index 000000000..b8eb85c03
--- /dev/null
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java
@@ -0,0 +1,43 @@
+/*-
+ * ============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.guard;
+
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorParams;
+
+@Getter
+@Setter
+@EqualsAndHashCode(callSuper = true)
+public class GuardActorParams extends HttpActorParams {
+ public static final String DEFAULT_ACTION = "guard";
+
+ /*
+ * Optional, default values that are used if missing from the operation-specific
+ * parameters.
+ */
+
+ private String onapName;
+ private String onapComponent;
+ private String onapInstance;
+ private String action = DEFAULT_ACTION;
+}
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorServiceProvider.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorServiceProvider.java
index 104c3830c..ea08d13da 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorServiceProvider.java
@@ -25,7 +25,7 @@ package org.onap.policy.controlloop.actor.guard;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpActor;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator;
-public class GuardActorServiceProvider extends HttpActor {
+public class GuardActorServiceProvider extends HttpActor<GuardActorParams> {
// actor name
public static final String NAME = "GUARD";
@@ -33,9 +33,8 @@ public class GuardActorServiceProvider extends HttpActor {
* Constructs the object.
*/
public GuardActorServiceProvider() {
- super(NAME);
+ super(NAME, GuardActorParams.class);
- addOperator(HttpOperator.makeOperator(NAME, GuardOperation.NAME,
- GuardOperation::new));
+ addOperator(new HttpOperator(NAME, GuardOperation.NAME, GuardOperation::new));
}
}
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java
new file mode 100644
index 000000000..c6bf32635
--- /dev/null
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java
@@ -0,0 +1,72 @@
+/*-
+ * ============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.guard;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.Executor;
+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;
+
+/**
+ * Configuration for Guard Operators.
+ */
+public class GuardConfig extends HttpConfig {
+ private final Map<String, Object> defaultRequest = new LinkedHashMap<>();
+
+ /**
+ * 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 GuardConfig(Executor blockingExecutor, GuardParams params, HttpClientFactory clientFactory) {
+ super(blockingExecutor, params, clientFactory);
+
+ addProperty("ONAPComponent", params.getOnapComponent());
+ addProperty("ONAPInstance", params.getOnapInstance());
+ addProperty("ONAPName", params.getOnapName());
+ addProperty("action", params.getAction());
+ }
+
+ /**
+ * Adds a property to the default request, if the value is not {@code null}.
+ *
+ * @param key property key
+ * @param value property value, or {@code null}
+ */
+ private void addProperty(String key, String value) {
+ if (value != null) {
+ defaultRequest.put(key, value);
+ }
+ }
+
+ /**
+ * Creates a new request, with the default values.
+ *
+ * @return a new request map
+ */
+ public Map<String, Object> makeRequest() {
+ return new LinkedHashMap<>(defaultRequest);
+ }
+}
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
index 941838f00..453a3e377 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
@@ -33,8 +33,8 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
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.parameters.HttpConfig;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
@@ -74,15 +74,18 @@ public class GuardOperation extends HttpOperation<DecisionResponse> {
*/
public static final String RESOURCE_PREFIX = "resource.";
+ private final GuardConfig config;
+
/**
* Constructs the object.
*
* @param params operation parameters
- * @param operator operator that created this operation
+ * @param config configuration for this operation
*/
- public GuardOperation(ControlLoopOperationParams params, HttpOperator operator) {
- super(params, operator, DecisionResponse.class);
+ public GuardOperation(ControlLoopOperationParams params, HttpConfig config) {
+ super(params, config, DecisionResponse.class);
+ this.config = (GuardConfig) config;
}
@Override
@@ -101,7 +104,7 @@ public class GuardOperation extends HttpOperation<DecisionResponse> {
// @formatter:off
return handleResponse(outcome, url,
- callback -> getOperator().getClient().post(callback, makePath(), entity, headers));
+ callback -> getClient().post(callback, makePath(), entity, headers));
// @formatter:on
}
@@ -121,7 +124,7 @@ public class GuardOperation extends HttpOperation<DecisionResponse> {
* appropriate field.
*/
- Map<String, Object> req = new LinkedHashMap<>();
+ Map<String, Object> req = config.makeRequest();
Map<String, Object> resource = new LinkedHashMap<>();
for (Entry<String, String> ent : params.getPayload().entrySet()) {
@@ -141,7 +144,6 @@ public class GuardOperation extends HttpOperation<DecisionResponse> {
}
}
- req.putIfAbsent("action", "guard");
req.computeIfAbsent("requestId", key -> UUID.randomUUID().toString());
req.put(RESOURCE, resource);
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperator.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperator.java
new file mode 100644
index 000000000..b3a47fd71
--- /dev/null
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperator.java
@@ -0,0 +1,52 @@
+/*-
+ * ============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.guard;
+
+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;
+
+/**
+ * Guard Operator.
+ */
+public class GuardOperator extends HttpOperator {
+
+ public GuardOperator(String actorName, String name,
+ @SuppressWarnings("rawtypes") OperationMaker<HttpConfig, HttpOperation> operationMaker) {
+ super(actorName, name, operationMaker);
+ }
+
+ @Override
+ protected HttpConfig makeConfiguration(Map<String, Object> parameters) {
+ GuardParams params = Util.translate(getFullName(), parameters, GuardParams.class);
+ ValidationResult result = params.validate(getFullName());
+ if (!result.isValid()) {
+ throw new ParameterValidationRuntimeException("invalid parameters", result);
+ }
+
+ return new GuardConfig(getBlockingExecutor(), params, getClientFactory());
+ }
+}
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java
new file mode 100644
index 000000000..251482525
--- /dev/null
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java
@@ -0,0 +1,44 @@
+/*-
+ * ============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.guard;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.SuperBuilder;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
+
+/**
+ * Default values to be included if not specified in the payload.
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@SuperBuilder(toBuilder = true)
+public class GuardParams extends HttpParams {
+
+ /*
+ * Optional, default values that are used if missing from the payload.
+ */
+
+ private String onapName;
+ private String onapComponent;
+ private String onapInstance;
+ private String action;
+}