diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-16 19:44:41 +0100 |
---|---|---|
committer | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-16 19:44:41 +0100 |
commit | 23f4383ad441f5afa363941d2aab980f64dbf7f3 (patch) | |
tree | 5b29968a95ee1264150cb9a4a8707fb14e6a3eef /src/main/java | |
parent | 2ff12cf396e3ea6ab166e8c9bc7fc1cab93e8cd5 (diff) |
CsarHandler rework
Reworking of the csarHandler to support cache of dcae blueprint
Issue-ID: CLAMP-81
Change-Id: Ic9c71d8f23ac75a6273781991f5ac7a60c4f328d
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java | 60 |
1 files changed, 45 insertions, 15 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 270286bcb..940b7cfaf 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 @@ -23,15 +23,21 @@ package org.onap.clamp.clds.sdc.controller.installer; +import com.att.aft.dme2.internal.apache.commons.io.IOUtils; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Enumeration; import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; @@ -43,28 +49,28 @@ import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; /** - * CsarDescriptor that will be used to deploy in CLAMP. + * CsarDescriptor that will be used to deploy file in CLAMP file system. Some + * methods can also be used to get some data from it. */ public class CsarHandler { private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarHandler.class); private IArtifactInfo artifactElement; - private String filePath; + private String csarFilePath; private String controllerName; private SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); private ISdcCsarHelper sdcCsarHelper; + private String dcaeBlueprint; public static final String CSAR_TYPE = "TOSCA_CSAR"; - private String csarPath; - public CsarHandler(INotificationData iNotif, String controller, String sdcCsarPath) throws CsarHandlerException { - this.csarPath = sdcCsarPath; + public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException { this.controllerName = controller; this.artifactElement = searchForUniqueCsar(iNotif); - this.filePath = buildFilePathForCsar(artifactElement); + this.csarFilePath = buildFilePathForCsar(artifactElement, clampCsarPath); } - private String buildFilePathForCsar(IArtifactInfo artifactElement) { - return csarPath + "/" + controllerName + "/" + artifactElement.getArtifactName(); + private String buildFilePathForCsar(IArtifactInfo artifactElement, String clampCsarPath) { + return clampCsarPath + "/" + controllerName + "/" + artifactElement.getArtifactName(); } private IArtifactInfo searchForUniqueCsar(INotificationData iNotif) throws CsarHandlerException { @@ -77,21 +83,41 @@ public class CsarHandler { throw new CsarHandlerException("Unable to find a CSAR in the Sdc Notification"); } - public void save(IDistributionClientDownloadResult resultArtifact) + public synchronized void save(IDistributionClientDownloadResult resultArtifact) throws SdcArtifactInstallerException, SdcToscaParserException { try { logger.info("Writing CSAR file : " + artifactElement.getArtifactURL() + " UUID " + artifactElement.getArtifactUUID() + ")"); - Path path = Paths.get(filePath); + Path path = Paths.get(csarFilePath); Files.createDirectories(path.getParent()); Files.createFile(path); - try (FileOutputStream outFile = new FileOutputStream(filePath)) { + try (FileOutputStream outFile = new FileOutputStream(csarFilePath)) { outFile.write(resultArtifact.getArtifactPayload(), 0, resultArtifact.getArtifactPayload().length); } - sdcCsarHelper = factory.getSdcCsarHelper(filePath); + sdcCsarHelper = factory.getSdcCsarHelper(csarFilePath); + this.loadDcaeBlueprint(); } catch (IOException e) { throw new SdcArtifactInstallerException( - "Exception caught when trying to write the CSAR on the file system to " + filePath, e); + "Exception caught when trying to write the CSAR on the file system to " + csarFilePath, e); + } + } + + private void loadDcaeBlueprint() throws IOException, SdcArtifactInstallerException { + List<ZipEntry> listEntries = new ArrayList<>(); + try (ZipFile zipFile = new ZipFile(csarFilePath)) { + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + if (entry.getName().contains("DCAE_INVENTORY_BLUEPRINT")) { + listEntries.add(entry); + } + } + if (listEntries.size() > 1) { + throw new SdcArtifactInstallerException("There are multiple entries in the DCAE inventory"); + } + try (InputStream stream = zipFile.getInputStream(listEntries.get(0))) { + this.dcaeBlueprint = IOUtils.toString(stream); + } } } @@ -100,10 +126,14 @@ public class CsarHandler { } public String getFilePath() { - return filePath; + return csarFilePath; } - public ISdcCsarHelper getSdcCsarHelper() { + public synchronized ISdcCsarHelper getSdcCsarHelper() { return sdcCsarHelper; } + + public synchronized String getDcaeBlueprint() { + return dcaeBlueprint; + } } |