summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.aai/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-17 15:09:21 -0400
committerJim Hahn <jrh3@att.com>2020-04-17 19:31:23 -0400
commite887a0c6c415a00888e17d1bbfe4acf548a2cfa5 (patch)
tree1cccd49d453eb1cf94b0f8f7fd7d14eae02404d9 /models-interactions/model-actors/actor.aai/src/main
parentbed21af59885a954e3facf7226c4678f4b69b153 (diff)
Add PNF support to new CDS actor
Made the following updates: - added new A&AI get-PNF Operation by refactoring AaiGetOperation, separating out Tenant and PNF operations - added PNF support to the CDS actor - added logging to the CDS Handler - added get-pnf to the A&AI simulator Issue-ID: POLICY-2505 Change-Id: Iff140e7c864f762790d8e2ecaba62c161c859e6e Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.aai/src/main')
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiActorServiceProvider.java7
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java6
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java78
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java92
-rw-r--r--models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java90
5 files changed, 210 insertions, 63 deletions
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiActorServiceProvider.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiActorServiceProvider.java
index a65a000ed..0fe70b7ea 100644
--- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiActorServiceProvider.java
@@ -38,10 +38,7 @@ public class AaiActorServiceProvider extends HttpActor<HttpActorParams> {
super(NAME, HttpActorParams.class);
addOperator(new HttpOperator(NAME, AaiCustomQueryOperation.NAME, AaiCustomQueryOperation::new));
-
- // add all "get" operators
- for (String operation : AaiGetOperation.OPERATIONS) {
- addOperator(new HttpOperator(NAME, operation, AaiGetOperation::new));
- }
+ addOperator(new HttpOperator(NAME, AaiGetTenantOperation.NAME, AaiGetTenantOperation::new));
+ addOperator(new HttpOperator(NAME, AaiGetPnfOperation.NAME, AaiGetPnfOperation::new));
}
}
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java
index b00928847..2cc2a69f4 100644
--- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java
@@ -84,10 +84,10 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
@Override
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
ControlLoopOperationParams tenantParams =
- params.toBuilder().actor(AaiConstants.ACTOR_NAME).operation(AaiGetOperation.TENANT)
+ params.toBuilder().actor(AaiConstants.ACTOR_NAME).operation(AaiGetTenantOperation.NAME)
.targetEntity(vserver).payload(null).retry(null).timeoutSec(null).build();
- return params.getContext().obtain(AaiGetOperation.getTenantKey(vserver), tenantParams);
+ return params.getContext().obtain(AaiGetTenantOperation.getKey(vserver), tenantParams);
}
@Override
@@ -137,7 +137,7 @@ public class AaiCustomQueryOperation extends HttpOperation<String> {
* Constructs the custom query using the previously retrieved tenant data.
*/
private Map<String, String> makeRequest() {
- StandardCoderObject tenant = params.getContext().getProperty(AaiGetOperation.getTenantKey(vserver));
+ StandardCoderObject tenant = params.getContext().getProperty(AaiGetTenantOperation.getKey(vserver));
String resourceLink = tenant.getString(RESULT_DATA, 0, RESOURCE_LINK);
if (resourceLink == null) {
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java
index a20200807..07738b084 100644
--- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java
@@ -22,15 +22,10 @@ package org.onap.policy.controlloop.actor.aai;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.onap.policy.aai.AaiConstants;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
@@ -49,17 +44,6 @@ public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
public static final int DEFAULT_RETRY = 3;
- // operation names
- public static final String TENANT = "Tenant";
-
- // property prefixes
- private static final String TENANT_KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + TENANT + ".";
-
- /**
- * Operation names supported by this operator.
- */
- public static final Set<String> OPERATIONS = Set.of(TENANT);
-
/**
* Responses that are retrieved from A&AI are placed in the operation context under
@@ -78,50 +62,22 @@ public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
this.propertyPrefix = getFullName() + ".";
}
- /**
- * Gets the "context key" for the tenant query response associated with the given
- * target entity.
- *
- * @param targetEntity target entity
- * @return the "context key" for the response associated with the given target
- */
- public static String getTenantKey(String targetEntity) {
- return (TENANT_KEY_PREFIX + targetEntity);
- }
-
@Override
public void generateSubRequestId(int attempt) {
setSubRequestId(String.valueOf(attempt));
}
- @Override
- protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
- Map<String, Object> headers = makeHeaders();
-
- headers.put("Accept", MediaType.APPLICATION_JSON);
-
- StringBuilder str = new StringBuilder(getClient().getBaseUrl());
-
- String path = getPath();
- WebTarget web = getClient().getWebTarget().path(path);
- str.append(path);
-
- web = addQuery(web, str, "?", "search-node-type", "vserver");
- web = addQuery(web, str, "&", "filter", "vserver-name:EQUALS:" + params.getTargetEntity());
-
- Builder webldr = web.request();
- for (Entry<String, Object> header : headers.entrySet()) {
- webldr.header(header.getKey(), header.getValue());
- }
-
- String url = str.toString();
-
- logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
-
- return handleResponse(outcome, url, callback -> webldr.async().get(callback));
- }
-
- private WebTarget addQuery(WebTarget web, StringBuilder str, String separator, String name, String value) {
+ /**
+ * Adds a query parameter to a web target.
+ *
+ * @param web target to which the parameter should be added
+ * @param str the separator and parameter are appended here, for logging purposes
+ * @param separator separator to be added to "str"; that's its only use
+ * @param name parameter name
+ * @param value parameter value
+ * @return "web"
+ */
+ protected WebTarget addQuery(WebTarget web, StringBuilder str, String separator, String name, String value) {
str.append(separator);
str.append(name);
str.append('=');
@@ -130,6 +86,18 @@ public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
return web.queryParam(name, value);
}
+ /**
+ * Adds headers to the web builder.
+ *
+ * @param webldr builder to which the headers should be added
+ * @param headers headers to be added
+ */
+ protected void addHeaders(Builder webldr, Map<String, Object> headers) {
+ for (Entry<String, Object> header : headers.entrySet()) {
+ webldr.header(header.getKey(), header.getValue());
+ }
+ }
+
@Override
protected Map<String, Object> makeHeaders() {
return AaiUtil.makeHeaders(params);
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java
new file mode 100644
index 000000000..fbf40967c
--- /dev/null
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperation.java
@@ -0,0 +1,92 @@
+/*-
+ * ============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.aai;
+
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import org.onap.policy.aai.AaiConstants;
+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.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+
+/**
+ * A&AI get-pnf operator.
+ */
+public class AaiGetPnfOperation extends AaiGetOperation {
+ private static final String URI_SEP = "/";
+
+ public static final String NAME = "Pnf";
+
+ // property prefixes
+ private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
+
+ /**
+ * Constructs the object.
+ *
+ * @param params operation parameters
+ * @param config configuration for this operation
+ */
+ public AaiGetPnfOperation(ControlLoopOperationParams params, HttpConfig config) {
+ super(params, config);
+ }
+
+ /**
+ * Gets the "context key" for the PNF query response associated with the given
+ * target entity.
+ *
+ * @param targetEntity target entity
+ * @return the "context key" for the response associated with the given target
+ */
+ public static String getKey(String targetEntity) {
+ return (KEY_PREFIX + targetEntity);
+ }
+
+ @Override
+ protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
+ Map<String, Object> headers = makeHeaders();
+
+ headers.put("Accept", MediaType.APPLICATION_JSON);
+
+ StringBuilder str = new StringBuilder(getClient().getBaseUrl());
+
+ String path = getPath() + URI_SEP + URLEncoder.encode(params.getTargetEntity(), StandardCharsets.UTF_8);
+ WebTarget web = getClient().getWebTarget().path(path);
+ str.append(path);
+
+ web = addQuery(web, str, "?", "depth", "0");
+
+ Builder webldr = web.request();
+ addHeaders(webldr, headers);
+
+ String url = str.toString();
+
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
+
+ return handleResponse(outcome, url, callback -> webldr.async().get(callback));
+ }
+}
diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java
new file mode 100644
index 000000000..cbd179189
--- /dev/null
+++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperation.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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.aai;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import org.onap.policy.aai.AaiConstants;
+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.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+
+/**
+ * A&AI get-tenant operator.
+ */
+public class AaiGetTenantOperation extends AaiGetOperation {
+
+ public static final String NAME = "Tenant";
+
+ // property prefixes
+ private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
+
+ /**
+ * Constructs the object.
+ *
+ * @param params operation parameters
+ * @param config configuration for this operation
+ */
+ public AaiGetTenantOperation(ControlLoopOperationParams params, HttpConfig config) {
+ super(params, config);
+ }
+
+ /**
+ * Gets the "context key" for the tenant query response associated with the given
+ * target entity.
+ *
+ * @param targetEntity target entity
+ * @return the "context key" for the response associated with the given target
+ */
+ public static String getKey(String targetEntity) {
+ return (KEY_PREFIX + targetEntity);
+ }
+
+ @Override
+ protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
+ Map<String, Object> headers = makeHeaders();
+
+ headers.put("Accept", MediaType.APPLICATION_JSON);
+
+ StringBuilder str = new StringBuilder(getClient().getBaseUrl());
+
+ String path = getPath();
+ WebTarget web = getClient().getWebTarget().path(path);
+ str.append(path);
+
+ web = addQuery(web, str, "?", "search-node-type", "vserver");
+ web = addQuery(web, str, "&", "filter", "vserver-name:EQUALS:" + params.getTargetEntity());
+
+ Builder webldr = web.request();
+ addHeaders(webldr, headers);
+
+ String url = str.toString();
+
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
+
+ return handleResponse(outcome, url, callback -> webldr.async().get(callback));
+ }
+}