diff options
author | Sébastien Determe <sebastien.determe@intl.att.com> | 2019-04-05 13:31:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-05 13:31:34 +0000 |
commit | 3ae0ad2234422c6660ae4fbdcf37e8e78dbf7e61 (patch) | |
tree | 3bacf0d71923d6675124f46ec5657c8306cdee78 /src/main/java/org/onap | |
parent | d10114aeb050d7a3e1e782e48ad446dfeebf388f (diff) | |
parent | ed8e2a71029088ecc7f29b484ef1b7a71d536604 (diff) |
Merge "Update Csar handler"
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r-- | src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java index b65a994ac..65d5592a8 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java @@ -42,6 +42,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.apache.commons.io.IOUtils; +import org.codehaus.plexus.util.StringUtils; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.sdc.api.notification.IArtifactInfo; @@ -71,6 +72,8 @@ public class CsarHandler { public static final String RESOURCE_INSTANCE_NAME_PREFIX = "/Artifacts/Resources/"; public static final String RESOURCE_INSTANCE_NAME_SUFFIX = "/Deployment/"; public static final String POLICY_DEFINITION_NAME_SUFFIX = "Definitions/policies.yml"; + public static final String DATA_DEFINITION_NAME_SUFFIX = "Definitions/data.yml"; + public static final String DATA_DEFINITION_KEY = "data_types:"; public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException { this.sdcNotification = iNotif; @@ -159,6 +162,10 @@ public class CsarHandler { return csarFilePath; } + public String setFilePath(String newPath) { + return csarFilePath = newPath; + } + public synchronized ISdcCsarHelper getSdcCsarHelper() { return sdcCsarHelper; } @@ -171,12 +178,26 @@ public class CsarHandler { return mapOfBlueprints; } + /** + * Get the whole policy model Yaml. It combines the content of policies.yaml and data.yaml. + * @return The whole policy model yaml + * @throws IOException The IO Exception + */ public Optional<String> getPolicyModelYaml() throws IOException { String result = null; try (ZipFile zipFile = new ZipFile(csarFilePath)) { ZipEntry entry = zipFile.getEntry(POLICY_DEFINITION_NAME_SUFFIX); if (entry != null) { - result = IOUtils.toString(zipFile.getInputStream(entry), StandardCharsets.UTF_8); + ZipEntry data = zipFile.getEntry(DATA_DEFINITION_NAME_SUFFIX); + if (data != null) { + String dataStr = IOUtils.toString(zipFile.getInputStream(data), StandardCharsets.UTF_8); + String dataStrWithoutHeader = dataStr.substring(dataStr.indexOf(DATA_DEFINITION_KEY)); + String policyStr = IOUtils.toString(zipFile.getInputStream(entry), StandardCharsets.UTF_8); + StringUtils.chomp(policyStr); + result = policyStr.concat(dataStrWithoutHeader); + } else { + result = IOUtils.toString(zipFile.getInputStream(entry), StandardCharsets.UTF_8); + } } else { logger.info("Policy model not found inside the CSAR file: " + csarFilePath); } |