diff options
author | Rashmi Pujar <rashmi.pujar@bell.ca> | 2019-09-30 12:12:07 -0400 |
---|---|---|
committer | Rashmi Pujar <rashmi.pujar@bell.ca> | 2019-10-01 12:01:14 +0000 |
commit | 5af913104ec412086deab4d599359751246e4ba3 (patch) | |
tree | 436e10c0bb6e02aa354ffaf93714069309e2e611 /models-interactions/model-actors/actor.cds | |
parent | f70ddacbd97e34ad0d1373466367115982a251db (diff) |
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
Diffstat (limited to 'models-interactions/model-actors/actor.cds')
-rw-r--r-- | models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java | 7 | ||||
-rw-r--r-- | models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java (renamed from models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/ConfigDeployRequest.java) | 25 | ||||
-rw-r--r-- | models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java | 12 |
3 files changed, 33 insertions, 11 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 aaf07ac21..1ad184e49 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.ArrayList; 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.client.CdsProcessorGrpcClient; 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 @@ public class CdsActorServiceProvider implements Actor { 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 index f33f226f9..8aac67bb0 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 65fd60239..0152521af 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.verify; 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 @@ public class CdsActorServiceProviderTest { 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 @@ public class CdsActorServiceProviderTest { } }; policy.setPayload(payloadMap); - policy.setRecipe("CDS"); + policy.setRecipe(CDS_RECIPE); // Setup the CDS properties cdsProps = new CdsServerProperties(); @@ -124,7 +126,7 @@ public class CdsActorServiceProviderTest { } @Test - public void testConstructRequest() { + public void testConstructRequestWhenMissingCdsParamsInPolicyPayload() { policy.setPayload(new HashMap<>()); Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor .constructRequest(onset, operation, policy, aaiParams); @@ -133,7 +135,7 @@ public class CdsActorServiceProviderTest { } @Test - public void testConstructRequestWhenMissingCdsParamsInPolicyPayload() { + public void testConstructRequest() { Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor .constructRequest(onset, operation, policy, aaiParams); @@ -146,10 +148,12 @@ public class CdsActorServiceProviderTest { 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); } |