summaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/main/java
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@est.tech>2019-07-21 13:15:10 +0000
committerramverma <ram.krishna.verma@est.tech>2019-07-21 13:15:10 +0000
commit38c95a9e7810bb6563667df1933f7ed22cda0db1 (patch)
tree48c9e4b817e4e3f3b01100cc097ca5b690c9fa4f /plugins/reception-plugins/src/main/java
parent538a204455ca708eaf20785972be3ac1c2a7ed3f (diff)
Changing policy decoder to support Tosca
1) Updated PolicyDecoderFileInCsarToPolicy to parse ToscaPolicy & TocsaPolicyType from the given csar. 2) Change the parameters 3) Tests cases updated/added. Change-Id: Ic8d652ae8043d5d332f663a6862eb08e282591cf Issue-ID: POLICY-1889 Signed-off-by: ramverma <ram.krishna.verma@est.tech>
Diffstat (limited to 'plugins/reception-plugins/src/main/java')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java30
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java16
2 files changed, 21 insertions, 25 deletions
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 7f1e53ae..4b58d2da 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
@@ -22,20 +22,21 @@
package org.onap.policy.distribution.reception.decoding.policy.file;
import java.io.IOException;
-import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import org.apache.commons.io.IOUtils;
import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.distribution.model.Csar;
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.policy.models.tosca.authorative.concepts.ToscaEntity;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,10 +45,11 @@ import org.slf4j.LoggerFactory;
*
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
-public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, ToscaPolicy> {
+public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, ToscaEntity> {
private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderFileInCsarToPolicy.class);
- PolicyDecoderFileInCsarToPolicyParameterGroup decoderParameters;
+ private PolicyDecoderFileInCsarToPolicyParameterGroup decoderParameters;
+ private StandardCoder coder;
/**
* {@inheritDoc}.
@@ -55,6 +57,7 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, Tosc
@Override
public void configure(final String parameterGroupName) {
decoderParameters = ParameterService.get(parameterGroupName);
+ coder = new StandardCoder();
}
/**
@@ -69,24 +72,21 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, Tosc
* {@inheritDoc}.
*/
@Override
- public Collection<ToscaPolicy> decode(final Csar csar) throws PolicyDecodingException {
- final Collection<ToscaPolicy> policyList = new ArrayList<>();
+ public Collection<ToscaEntity> decode(final Csar csar) throws PolicyDecodingException {
+ final Collection<ToscaEntity> policyList = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(csar.getCsarPath())) {
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
final ZipEntry entry = entries.nextElement();
- if (entry.getName().contains(decoderParameters.getPolicyFileName())) {
- final StringWriter writer = new StringWriter();
- IOUtils.copy(zipFile.getInputStream(entry), writer, "UTF-8");
- final ToscaPolicy policy = new ToscaPolicy();
- policy.setName(decoderParameters.getPolicyFileName());
- policy.setType(decoderParameters.getPolicyType());
- policy.setDescription(writer.toString());
+ if (entry.getName().contains(decoderParameters.getPolicyTypeFileName())
+ || entry.getName().contains(decoderParameters.getPolicyFileName())) {
+ final ToscaServiceTemplate policy =
+ coder.decode(zipFile.getInputStream(entry), ToscaServiceTemplate.class);
policyList.add(policy);
}
}
- } catch (final IOException exp) {
+ } catch (final IOException | CoderException exp) {
final String message = "Failed decoding the policy";
LOGGER.error(message, exp);
throw new PolicyDecodingException(message, exp);
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java
index 958180db..1df563c3 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java
@@ -33,25 +33,25 @@ import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurat
public class PolicyDecoderFileInCsarToPolicyParameterGroup extends PolicyDecoderConfigurationParameterGroup {
private String policyFileName;
- private String policyType;
+ private String policyTypeFileName;
/**
* Constructor for instantiating {@link PolicyDecoderFileInCsarToPolicyParameterGroup} class.
*
* @param policyFileName the policy file name
- * @param policyType the policy type
+ * @param policyTypeFileName the policy type file name
*/
- public PolicyDecoderFileInCsarToPolicyParameterGroup(final String policyFileName, final String policyType) {
+ public PolicyDecoderFileInCsarToPolicyParameterGroup(final String policyFileName, final String policyTypeFileName) {
this.policyFileName = policyFileName;
- this.policyType = policyType;
+ this.policyTypeFileName = policyTypeFileName;
}
public String getPolicyFileName() {
return policyFileName;
}
- public String getPolicyType() {
- return policyType;
+ public String getPolicyTypeFileName() {
+ return policyTypeFileName;
}
@Override
@@ -61,10 +61,6 @@ public class PolicyDecoderFileInCsarToPolicyParameterGroup extends PolicyDecoder
validationResult.setResult("policyFileName", ValidationStatus.INVALID,
"must be a non-blank string containing the policy file name");
}
- if (!ParameterValidationUtils.validateStringParameter(policyType)) {
- validationResult.setResult("policyType", ValidationStatus.INVALID,
- "must be a non-blank string containing the policy type");
- }
return validationResult;
}
}