summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorxg353y <xg353y@intl.att.com>2019-04-03 15:54:21 +0200
committerxg353y <xg353y@intl.att.com>2019-04-03 15:54:21 +0200
commited8e2a71029088ecc7f29b484ef1b7a71d536604 (patch)
treefa48dc2d59e7d5f46ca65a2142e5acc2f88ca390 /src/main/java
parent8d36cfd7ccec9ea9a55894eeafba00da6037747d (diff)
Update Csar handler
Update Csar handler, return the content of policies.yaml concatenateed with data.yaml while getting the policy model yaml. Issue-ID: CLAMP-261 Change-Id: I8ef7bcb9b2daaea37f13ca9d3ad9f38b889d6041 Signed-off-by: xg353y <xg353y@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java23
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);
}