summaryrefslogtreecommitdiffstats
path: root/models-interactions
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar@bell.ca>2019-10-22 15:58:38 -0400
committerRashmi Pujar <rashmi.pujar@bell.ca>2019-10-23 13:29:15 -0400
commitfc3c22635307c5ff534a7f5673fcf2307e64a8ef (patch)
tree834b53e2af43ad53d42602513ec8ae540dc88fac /models-interactions
parentd0cca771fa39943a46470240cd0106941056e974 (diff)
Flatten the CDS grpc request payload
Before: { "vfw-modify-config-request":{ "resolution-key":"1234567890", "aai-properties":{ "service-instance.service-instance-id":"1234", "generic-vnf.vnf-id":"5678" }, "policy-payload":{ "data":"{\"active-streams\":\"5\"}" } } } After: { "vfw-modify-config-request":{ "resolution-key":"1234567890", "vfw-modify-config-properties":{ "service-instance.service-instance-id":"1234", "generic-vnf.vnf-id":"5678", "data":"{\"active-streams\":\"5\"}" } } } Issue-ID: POLICY-2089 Signed-off-by: Rashmi Pujar <rashmi.pujar@bell.ca> Change-Id: I139a7ca3e1e2d0cd50bbd86d0cdf499f215be74f
Diffstat (limited to 'models-interactions')
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java11
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java61
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java3
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java83
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java54
5 files changed, 146 insertions, 66 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java
index 5501f8618..65cc03931 100644
--- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java
@@ -42,10 +42,11 @@ import org.onap.policy.cds.CdsResponse;
import org.onap.policy.cds.api.CdsProcessorListener;
import org.onap.policy.cds.client.CdsProcessorGrpcClient;
import org.onap.policy.cds.properties.CdsServerProperties;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actor.cds.beans.CdsActionRequest;
import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
+import org.onap.policy.controlloop.actor.cds.request.CdsActionRequest;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.policy.Policy;
import org.slf4j.Logger;
@@ -131,13 +132,13 @@ public class CdsActorServiceProvider implements Actor {
Builder struct = Struct.newBuilder();
try {
- String requestStr = request.toString();
+ String requestStr = request.generateCdsPayload();
Preconditions.checkState(!Strings.isNullOrEmpty(requestStr), "Unable to build "
+ "config-deploy-request from payload parameters: {}", payload);
JsonFormat.parser().merge(requestStr, struct);
- } catch (InvalidProtocolBufferException e) {
- LOGGER.error("Failed to parse received message. blueprint({}:{}) for action({})", cbaName, cbaVersion,
- cbaActionName, e);
+ } catch (InvalidProtocolBufferException | CoderException e) {
+ LOGGER.error("Failed to embed CDS payload string into the input request. blueprint({}:{}) for action({})",
+ cbaName, cbaVersion, cbaActionName, e);
return Optional.empty();
}
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java
deleted file mode 100644
index 32f102382..000000000
--- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Bell Canada. 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.cds.beans;
-
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Getter
-@Setter
-public class CdsActionRequest implements Serializable {
- private static final long serialVersionUID = -4172157702597791493L;
-
- private static final Logger LOGGER = LoggerFactory.getLogger(CdsActionRequest.class);
- private static final Coder CODER = new StandardCoder();
-
- @SerializedName("policy-payload")
- private Map<String, String> policyPayload;
-
- @SerializedName("aai-properties")
- private Map<String, String> aaiProperties;
-
- @SerializedName("resolution-key")
- private String resolutionKey;
-
- private transient String actionName;
-
- @Override
- public String toString() {
- try {
- return "{" + "\"" + actionName + "-request\":" + CODER.encode(this) + '}';
- } catch (CoderException e) {
- LOGGER.error("Failure serializing CdsActionRequest object: ", e);
- return "";
- }
- }
-}
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java
index 9adb69232..8f929c83e 100644
--- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java
@@ -32,6 +32,9 @@ public class CdsActorConstants {
// CDS blueprint archive parameters
public static final String KEY_CBA_NAME = "artifact_name";
public static final String KEY_CBA_VERSION = "artifact_version";
+ public static final String KEY_RESOLUTION_KEY = "resolution-key";
+ public static final String CDS_REQUEST_SUFFIX = "-request";
+ public static final String CDS_REQUEST_PROPERTIES_SUFFIX = "-properties";
public static final String ORIGINATOR_ID = "POLICY";
// Temporarily set to synchronous mode to support current rules, since callbacks aren't supported yet
public static final String CDS_MODE = "sync";
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java
new file mode 100644
index 000000000..38ab2bdc7
--- /dev/null
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada. 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.cds.request;
+
+import java.io.Serializable;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
+
+@Getter
+@Setter
+public class CdsActionRequest implements Serializable {
+
+ private static final long serialVersionUID = -4172157702597791493L;
+ private static final StandardCoder CODER = new StandardCoder();
+
+ private String actionName;
+ private String resolutionKey;
+ private Map<String, String> aaiProperties;
+ private Map<String, String> policyPayload;
+
+ /**
+ * Generate the CDS gRPC request payload from the action-name (aka operational policy recipe).
+ * The CDS gRPC request payload generation follows the below pattern:
+ * {
+ * "{@link CdsActionRequest#getActionName()}-request": {
+ * "resolution-key": "{@link CdsActionRequest#getResolutionKey()} ()}",
+ * "{@link CdsActionRequest#getActionName()}-properties": {
+ * "{@link CdsActionRequest#getAaiProperties()} ()}",
+ * "{@link CdsActionRequest#getPolicyPayload()} ()}"
+ * }
+ * }
+ * }
+ * @return JSON string equivalent of the CDS request object
+ * @throws CoderException if error occurs when serializing to JSON string
+ */
+ public String generateCdsPayload() throws CoderException {
+ // 1. Build the innermost object to include AAI properties and policy payload information
+ Map<String, String> cdsActionPropsMap = new LinkedHashMap<>();
+ cdsActionPropsMap.putAll(aaiProperties);
+ cdsActionPropsMap.putAll(policyPayload);
+
+ // 2. Build the enclosing CDS action request properties object to contain (1) and the resolution-key
+ Map<String, Object> cdsActionRequestMap = new LinkedHashMap<>();
+ cdsActionRequestMap.put(CdsActorConstants.KEY_RESOLUTION_KEY, resolutionKey);
+ cdsActionRequestMap.put(generateCdsActionPropertiesKey(), cdsActionPropsMap);
+
+ // 3. Finally build the CDS action request object
+ Map<String, Object> cdsActionRequestObj = new LinkedHashMap<>();
+ cdsActionRequestObj.put(generateCdsActionRequestKey(), cdsActionRequestMap);
+
+ // 4. Serialize the CDS action request object
+ return CODER.encode(cdsActionRequestObj);
+ }
+
+ private String generateCdsActionPropertiesKey() {
+ return actionName + CdsActorConstants.CDS_REQUEST_PROPERTIES_SUFFIX;
+ }
+
+ private String generateCdsActionRequestKey() {
+ return actionName + CdsActorConstants.CDS_REQUEST_SUFFIX;
+ }
+}
diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java
new file mode 100644
index 000000000..3f28bada4
--- /dev/null
+++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada. 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.cds.request;
+
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
+
+public class CdsActionRequestTest {
+
+ private static final String TEST_ACTION_NAME = "vfw-modify-config";
+
+ @Test
+ public void testGenerateCdsPayload() throws CoderException {
+ // Setup the CdsActionRequest object
+ CdsActionRequest req = new CdsActionRequest();
+ req.setActionName(TEST_ACTION_NAME);
+ req.setResolutionKey("1234567890");
+ Map<String, String> payloadProps = ImmutableMap.of("data", "{\"active-streams\":\"5\"}");
+ req.setPolicyPayload(payloadProps);
+
+ Map<String, String> aaiParams =
+ ImmutableMap.of("service-instance.service-instance-id", "1234", "generic-vnf.vnf-id", "5678");
+ req.setAaiProperties(aaiParams);
+
+ // Act
+ String result = req.generateCdsPayload();
+
+ // Assert
+ assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_PROPERTIES_SUFFIX));
+ assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_SUFFIX));
+ assertTrue(result.contains(CdsActorConstants.KEY_RESOLUTION_KEY));
+ }
+}