diff options
author | ramverma <ram.krishna.verma@est.tech> | 2019-07-17 11:03:26 +0000 |
---|---|---|
committer | ramverma <ram.krishna.verma@est.tech> | 2019-07-17 11:03:26 +0000 |
commit | cf748512392e5d3257de629dc57fb353dc073c92 (patch) | |
tree | 8e81a773d1f9556669b344d5f31dd139999ef2f6 /plugins/reception-plugins/src/main/java | |
parent | 5f032e0363703239f30dff29914dc41dd3abca48 (diff) |
Changing policy/distribution to use policy/models
1) Changed policy distribution framework to use entities from
policy/models
2) Changed all the test cases.
3) Commented few test cases which will be fixed along with code fixes.
4) Will be removing the old policy entities once all the pieces are
ready.
Change-Id: I1fd7b975b2e072c0b24e429903c9ca4796173929
Issue-ID: POLICY-1888
Signed-off-by: ramverma <ram.krishna.verma@est.tech>
Diffstat (limited to 'plugins/reception-plugins/src/main/java')
3 files changed, 21 insertions, 18 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java index 705968ae..165d105a 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java @@ -31,10 +31,10 @@ import java.util.List; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.model.Csar; -import org.onap.policy.distribution.model.OptimizationPolicy; import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -44,15 +44,15 @@ import org.slf4j.LoggerFactory; /** * Decodes PDP-X policies from a CSAR file. */ -public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, OptimizationPolicy> { +public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, ToscaPolicy> { private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarPdpx.class); private final Gson gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().create(); private PolicyDecoderCsarPdpxConfigurationParameterGroup decoderParameters; @Override - public Collection<OptimizationPolicy> decode(final Csar csar) throws PolicyDecodingException { - final List<OptimizationPolicy> policys = new ArrayList<>(); + public Collection<ToscaPolicy> decode(final Csar csar) throws PolicyDecodingException { + final List<ToscaPolicy> policies = new ArrayList<>(); final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); final List<NodeTemplate> lnodeVf = sdcCsarHelper.getServiceVfList(); LOGGER.debug("the size of Vf = {}", lnodeVf.size()); @@ -63,10 +63,10 @@ public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, OptimizationPo for (final NodeTemplate node : lnodeVf) { final Content content = extractFromNode.extractInfo(node); if (content != null) { - final OptimizationPolicy policy = new OptimizationPolicy(); + final ToscaPolicy policy = new ToscaPolicy(); final String policyName = decoderParameters.getPolicyNamePrefix() + "." + content.getIdentity(); - policy.setOnapName(decoderParameters.getOnapName()); - policy.setPolicyName(policyName); + // policy.setOnapName(decoderParameters.getOnapName()); + policy.setName(policyName); final ConfigBody configBody = new ConfigBody(); configBody.setService("hpaPolicy"); configBody.setPolicyName(policyName); @@ -81,11 +81,11 @@ public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, OptimizationPo content.getPolicyScope().add("HPA"); content.getPolicyScope().add(serviceName); configBody.setContent(content); - policy.setConfigBody(gson.toJson(configBody)); - policys.add(policy); + // policy.setConfigBody(gson.toJson(configBody)); + policies.add(policy); } } - return policys; + return policies; } @Override diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java index 41793ebf..8cd6ecc1 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java @@ -26,14 +26,15 @@ import java.util.Collections; import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.model.Tosca; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** * Decodes PDP-X policies from a TOSCA file. */ -public class PolicyDecoderToscaPdpx implements PolicyDecoder<Tosca, PdpxPolicy> { +public class PolicyDecoderToscaPdpx implements PolicyDecoder<Tosca, ToscaPolicy> { @Override - public Collection<PdpxPolicy> decode(final Tosca tosca) { + public Collection<ToscaPolicy> decode(final Tosca tosca) { // Add logic for generating the policies from the TOSCA return Collections.emptySet(); } diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java index 22b626f8..7f1e53ae 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java @@ -32,10 +32,10 @@ import java.util.zip.ZipFile; import org.apache.commons.io.IOUtils; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.model.Csar; -import org.onap.policy.distribution.model.PolicyAsString; import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory; * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ -public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, PolicyAsString> { +public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, ToscaPolicy> { private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderFileInCsarToPolicy.class); PolicyDecoderFileInCsarToPolicyParameterGroup decoderParameters; @@ -69,8 +69,8 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, Poli * {@inheritDoc}. */ @Override - public Collection<PolicyAsString> decode(final Csar csar) throws PolicyDecodingException { - final Collection<PolicyAsString> policyList = new ArrayList<>(); + public Collection<ToscaPolicy> decode(final Csar csar) throws PolicyDecodingException { + final Collection<ToscaPolicy> policyList = new ArrayList<>(); try (ZipFile zipFile = new ZipFile(csar.getCsarPath())) { final Enumeration<? extends ZipEntry> entries = zipFile.entries(); @@ -79,8 +79,10 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, Poli if (entry.getName().contains(decoderParameters.getPolicyFileName())) { final StringWriter writer = new StringWriter(); IOUtils.copy(zipFile.getInputStream(entry), writer, "UTF-8"); - final PolicyAsString policy = new PolicyAsString(decoderParameters.getPolicyFileName(), - decoderParameters.getPolicyType(), writer.toString()); + final ToscaPolicy policy = new ToscaPolicy(); + policy.setName(decoderParameters.getPolicyFileName()); + policy.setType(decoderParameters.getPolicyType()); + policy.setDescription(writer.toString()); policyList.add(policy); } } |