diff options
author | Jim Hahn <jrh3@att.com> | 2019-05-08 15:39:37 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-05-09 10:38:47 -0400 |
commit | 9eb34d921839ef5e32d2dd29d5af043e7dfe73dc (patch) | |
tree | 56084cac1a82fb6ebd87ae9bede0c2cb58546459 /models-interactions/model-actors/actor.appc/src | |
parent | f53879588a464c727ece62f87c7625b47e6de7f1 (diff) |
Change vFW payload from pg-streams to streams
Changed APPC payload from pg-streams to streams.
Also removed trafficgenerator.
Updated licenses.
Added log message when payload is null.
Replaced "ref$" with real payload values in yaml and docs.
Change-Id: I4b38b0f64784d5fffc8f62f3a26cd007e500fbc7
Issue-ID: POLICY-1752
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.appc/src')
2 files changed, 96 insertions, 24 deletions
diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java index e90ca400a..e2c997bca 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java @@ -23,22 +23,27 @@ package org.onap.policy.controlloop.actor.appc; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; - import java.util.Collections; import java.util.List; - +import java.util.Map; +import java.util.Map.Entry; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Request; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.vnf.trafficgenerator.PgRequest; -import org.onap.policy.vnf.trafficgenerator.PgStream; -import org.onap.policy.vnf.trafficgenerator.PgStreams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class AppcActorServiceProvider implements Actor { + private static final Logger logger = LoggerFactory.getLogger(AppcActorServiceProvider.class); + + private static final StandardCoder coder = new StandardCoder(); + // Strings for targets private static final String TARGET_VM = "VM"; private static final String TARGET_VNF = "VNF"; @@ -98,23 +103,15 @@ public class AppcActorServiceProvider implements Actor { request.getCommonHeader().setSubRequestId(operation.getSubRequestId()); request.setAction(policy.getRecipe().substring(0, 1).toUpperCase() + policy.getRecipe().substring(1)); - /* - * For now Policy generates the PG Streams as a demo, in the future the payload can be - * provided by CLAMP - */ - request.getPayload().put("generic-vnf.vnf-id", targetVnf); - - PgRequest pgRequest = new PgRequest(); - pgRequest.pgStreams = new PgStreams(); - - PgStream pgStream; - for (int i = 0; i < 5; i++) { - pgStream = new PgStream(); - pgStream.streamId = "fw_udp" + (i + 1); - pgStream.isEnabled = "true"; - pgRequest.pgStreams.pgStream.add(pgStream); + // convert policy payload strings to objects + if (policy.getPayload() == null) { + logger.info("no APPC payload specified for policy {}", policy.getName()); + } else { + convertPayload(policy.getPayload(), request.getPayload()); } - request.getPayload().put("pg-streams", pgRequest.pgStreams); + + // add/replace specific values + request.getPayload().put("generic-vnf.vnf-id", targetVnf); /* * Return the request @@ -123,5 +120,22 @@ public class AppcActorServiceProvider implements Actor { return request; } + /** + * Converts a payload. The original value is assumed to be a JSON string, which is + * decoded into an object. + * + * @param source source from which to get the values + * @param target where to place the decoded values + */ + private static void convertPayload(Map<String, String> source, Map<String, Object> target) { + for (Entry<String, String> ent : source.entrySet()) { + try { + target.put(ent.getKey(), coder.decode(ent.getValue(), Object.class)); + + } catch (CoderException e) { + logger.warn("cannot decode JSON value {}: {}", ent.getKey(), ent.getValue(), e); + } + } + } } diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index fc57d50ef..b917406cd 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * AppcServiceProviderTest * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,6 +57,14 @@ public class AppcServiceProviderTest { private static final ControlLoopOperation operation; private static final Policy policy; + private static final String KEY1 = "my-keyA"; + private static final String KEY2 = "my-keyB"; + private static final String SUBKEY = "sub-key"; + + private static final String VALUE1 = "'my-value'".replace('\'', '"'); + private static final String VALUE2 = "{'sub-key':20}".replace('\'', '"'); + private static final String SUBVALUE = "20"; + static { /* * Construct an onset with an AAI subtag containing generic-vnf.vnf-id and a target type of @@ -118,6 +126,58 @@ public class AppcServiceProviderTest { @Test public void constructModifyConfigRequestTest() { + policy.setPayload(new HashMap<>()); + policy.getPayload().put(KEY1, VALUE1); + policy.getPayload().put(KEY2, VALUE2); + + Request appcRequest; + appcRequest = AppcActorServiceProvider.constructRequest(onsetEvent, operation, policy, "vnf01"); + + /* The service provider must return a non null APPC request */ + assertNotNull(appcRequest); + + /* A common header is required and cannot be null */ + assertNotNull(appcRequest.getCommonHeader()); + assertEquals(appcRequest.getCommonHeader().getRequestId(), onsetEvent.getRequestId()); + + /* An action is required and cannot be null */ + assertNotNull(appcRequest.getAction()); + assertEquals("ModifyConfig", appcRequest.getAction()); + + /* A payload is required and cannot be null */ + assertNotNull(appcRequest.getPayload()); + assertTrue(appcRequest.getPayload().containsKey("generic-vnf.vnf-id")); + assertNotNull(appcRequest.getPayload().get("generic-vnf.vnf-id")); + assertTrue(appcRequest.getPayload().containsKey(KEY1)); + assertTrue(appcRequest.getPayload().containsKey(KEY2)); + + logger.debug("APPC Request: \n" + appcRequest.toString()); + + /* Print out request as json to make sure serialization works */ + String jsonRequest = Serialization.gsonPretty.toJson(appcRequest); + logger.debug("JSON Output: \n" + jsonRequest); + + /* The JSON string must contain the following fields */ + assertTrue(jsonRequest.contains("CommonHeader")); + assertTrue(jsonRequest.contains("Action")); + assertTrue(jsonRequest.contains("ModifyConfig")); + assertTrue(jsonRequest.contains("Payload")); + assertTrue(jsonRequest.contains("generic-vnf.vnf-id")); + assertTrue(jsonRequest.contains(KEY1)); + assertTrue(jsonRequest.contains(KEY2)); + assertTrue(jsonRequest.contains(SUBKEY)); + assertTrue(jsonRequest.contains(SUBVALUE)); + + Response appcResponse = new Response(appcRequest); + appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue()); + appcResponse.getStatus().setDescription("AppC success"); + /* Print out request as json to make sure serialization works */ + String jsonResponse = Serialization.gsonPretty.toJson(appcResponse); + logger.debug("JSON Output: \n" + jsonResponse); + } + + @Test + public void constructModifyConfigRequestTest_NullPayload() { Request appcRequest; appcRequest = AppcActorServiceProvider.constructRequest(onsetEvent, operation, policy, "vnf01"); @@ -137,7 +197,6 @@ public class AppcServiceProviderTest { assertNotNull(appcRequest.getPayload()); assertTrue(appcRequest.getPayload().containsKey("generic-vnf.vnf-id")); assertNotNull(appcRequest.getPayload().get("generic-vnf.vnf-id")); - assertTrue(appcRequest.getPayload().containsKey("pg-streams")); logger.debug("APPC Request: \n" + appcRequest.toString()); @@ -151,7 +210,6 @@ public class AppcServiceProviderTest { assertTrue(jsonRequest.contains("ModifyConfig")); assertTrue(jsonRequest.contains("Payload")); assertTrue(jsonRequest.contains("generic-vnf.vnf-id")); - assertTrue(jsonRequest.contains("pg-streams")); Response appcResponse = new Response(appcRequest); appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue()); |