Update CDS grpc request generation in CDS Actor service provider
- CDS payload requires resolution-key (random UUID)
- Update the CDS request object to rename the payload child node key name from config-deploy-properties to policy-payload.
- Generate dynamic childnode key name from the policy recipe-name aka CDS action-name. action-name itself is never included in serialization as is.
Below is a sample:
{
"commonHeader": {
"subRequestId": "$subReqId",
"requestId": "$reqId",
"originatorId": "POLICY"
},
"actionIdentifiers": {
"mode": "sync",
"blueprintName": "$bpName",
"blueprintVersion": "$bpVer",
"actionName": "$recipeName"
},
"payload": {
"$recipeName-request": {
"resolution-key": "{{$guid}}",
"aai-properties": {
"$key": "$value",
...
},
"policy-payload": {
"$clamp-payload"
}
}
}
}
Issue-ID: POLICY-2120
Signed-off-by: Rashmi Pujar <rashmi.pujar@bell.ca>
Change-Id: Ia7f0551f94755bbe73b48ae387b4c53842729a81
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 aaf07ac..1ad184e 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
@@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -42,7 +43,7 @@
import org.onap.policy.cds.properties.CdsServerProperties;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actor.cds.beans.ConfigDeployRequest;
+import org.onap.policy.controlloop.actor.cds.beans.CdsActionRequest;
import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.policy.Policy;
@@ -112,8 +113,10 @@
String cbaActionName = policy.getRecipe();
// Embed payload from policy to ConfigDeployRequest object, serialize and inject into grpc request.
- ConfigDeployRequest request = new ConfigDeployRequest();
+ CdsActionRequest request = new CdsActionRequest();
request.setConfigDeployProperties(payload);
+ request.setActionName(cbaActionName);
+ request.setResolutionKey(UUID.randomUUID().toString());
// Inject AAI properties into payload map. Offer flexibility to the usecase
// implementation to inject whatever AAI parameters are of interest to them.
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/ConfigDeployRequest.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java
similarity index 61%
rename from models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/ConfigDeployRequest.java
rename to models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java
index f33f226..8aac67b 100644
--- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/ConfigDeployRequest.java
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java
@@ -18,26 +18,41 @@
package org.onap.policy.controlloop.actor.cds.beans;
-import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
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 ConfigDeployRequest {
+public class CdsActionRequest {
- private static final Gson GSON = new Gson();
+ private static final Logger LOGGER = LoggerFactory.getLogger(CdsActionRequest.class);
+ private static final Coder CODER = new StandardCoder();
- @SerializedName("config-deploy-properties")
+ @SerializedName("policy-payload")
private Map<String, String> configDeployProperties;
@SerializedName("aai-properties")
private Map<String, String> aaiProperties;
+ @SerializedName("resolution-key")
+ private String resolutionKey;
+
+ private transient String actionName;
+
@Override
public String toString() {
- return "{\"config-deploy-request\":" + GSON.toJson(this) + '}';
+ 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/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java
index 65fd602..0152521 100644
--- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java
@@ -29,6 +29,7 @@
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
+import com.google.protobuf.Struct;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -63,6 +64,7 @@
private static final String CDS_BLUEPRINT_VERSION = "1.0.0";
private static final UUID REQUEST_ID = UUID.randomUUID();
private static final String SUBREQUEST_ID = "123456";
+ private static final String CDS_RECIPE = "test-cds-recipe";
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@@ -90,7 +92,7 @@
}
};
policy.setPayload(payloadMap);
- policy.setRecipe("CDS");
+ policy.setRecipe(CDS_RECIPE);
// Setup the CDS properties
cdsProps = new CdsServerProperties();
@@ -124,7 +126,7 @@
}
@Test
- public void testConstructRequest() {
+ public void testConstructRequestWhenMissingCdsParamsInPolicyPayload() {
policy.setPayload(new HashMap<>());
Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor
.constructRequest(onset, operation, policy, aaiParams);
@@ -133,7 +135,7 @@
}
@Test
- public void testConstructRequestWhenMissingCdsParamsInPolicyPayload() {
+ public void testConstructRequest() {
Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor
.constructRequest(onset, operation, policy, aaiParams);
@@ -146,10 +148,12 @@
assertEquals(commonHeader.getSubRequestId(), SUBREQUEST_ID);
assertTrue(cdsRequest.hasPayload());
+ Struct cdsPayload = cdsRequest.getPayload();
+ assertTrue(cdsPayload.containsFields(CDS_RECIPE + "-request"));
assertTrue(cdsRequest.hasActionIdentifiers());
ActionIdentifiers actionIdentifiers = cdsRequest.getActionIdentifiers();
- assertEquals(actionIdentifiers.getActionName(), CdsActorConstants.CDS_ACTOR);
+ assertEquals(actionIdentifiers.getActionName(), CDS_RECIPE);
assertEquals(actionIdentifiers.getBlueprintName(), CDS_BLUEPRINT_NAME);
assertEquals(actionIdentifiers.getBlueprintVersion(), CDS_BLUEPRINT_VERSION);
}