From 2ff12cf396e3ea6ab166e8c9bc7fc1cab93e8cd5 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 16 Mar 2018 19:42:39 +0100 Subject: Add new config classes Add classes to support the Blueprint mapping configuration Issue-ID: CLAMP-81 Change-Id: I78b42f90993700c299fd75a20f39aa16f632ff9d Signed-off-by: Determe, Sebastien (sd378r) --- .../sdc/BlueprintParserFilesConfiguration.java | 52 +++++++++++++++++ .../sdc/BlueprintParserMappingConfiguration.java | 65 ++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserFilesConfiguration.java create mode 100644 src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserMappingConfiguration.java (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserFilesConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserFilesConfiguration.java new file mode 100644 index 00000000..10306b43 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserFilesConfiguration.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.config.sdc; + +/** + * This class is used to decode the configuration found in + * application.properties, this is related to the blueprint mapping + * configuration that is used to create data in database, according to the + * blueprint content coming from SDC. + */ +public class BlueprintParserFilesConfiguration { + + private String svgXmlFilePath; + private String bpmnXmlFilePath; + + public String getBpmnXmlFilePath() { + return bpmnXmlFilePath; + } + + public void setBpmnXmlFilePath(String bpmnXmlFilePath) { + this.bpmnXmlFilePath = bpmnXmlFilePath; + } + + public String getSvgXmlFilePath() { + return svgXmlFilePath; + } + + public void setSvgXmlFilePath(String svgXmlFilePath) { + this.svgXmlFilePath = svgXmlFilePath; + } +} diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserMappingConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserMappingConfiguration.java new file mode 100644 index 00000000..b2631040 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserMappingConfiguration.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.config.sdc; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * This class is used to decode the configuration found in + * application.properties, this is related to the blueprint mapping + * configuration that is used to create data in database, according to the + * blueprint content coming from SDC. + */ +public class BlueprintParserMappingConfiguration { + + private String blueprintKey; + private BlueprintParserFilesConfiguration files; + + public String getBlueprintKey() { + return blueprintKey; + } + + public void setBlueprintKey(String blueprintKey) { + this.blueprintKey = blueprintKey; + } + + public BlueprintParserFilesConfiguration getFiles() { + return files; + } + + public void setFiles(BlueprintParserFilesConfiguration filesConfig) { + this.files = filesConfig; + } + + public static List createFromJson(InputStream json) throws IOException { + TypeReference> mapType = new TypeReference>() { + }; + return new ObjectMapper().readValue(json, mapType); + } +} -- cgit 1.2.3-korg From 23f4383ad441f5afa363941d2aab980f64dbf7f3 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 16 Mar 2018 19:44:41 +0100 Subject: 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) --- .../clds/sdc/controller/installer/CsarHandler.java | 60 ++++++++++++++++------ .../sdc/controller/installer/CsarHandlerTest.java | 17 +++--- 2 files changed, 54 insertions(+), 23 deletions(-) (limited to 'src') 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 270286bc..940b7cfa 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 listEntries = new ArrayList<>(); + try (ZipFile zipFile = new ZipFile(csarFilePath)) { + Enumeration 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; + } } diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java index d1b177d2..34805d87 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java @@ -38,7 +38,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import org.junit.AfterClass; import org.junit.Test; import org.mockito.Mockito; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; @@ -54,13 +53,6 @@ public class CsarHandlerTest { private static final String sdcFolder = "/tmp/csar-handler-tests"; private static final String csarArtifactName = "testArtifact.csar"; - @AfterClass - public static void removeAllFiles() throws IOException { - // Do some cleanup - Path path = Paths.get(sdcFolder + "/test-controller/" + csarArtifactName); - Files.deleteIfExists(path); - } - @Test public void testConstructor() throws CsarHandlerException { IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class); @@ -96,9 +88,18 @@ public class CsarHandlerTest { IDistributionClientDownloadResult resultArtifact = Mockito.mock(IDistributionClientDownloadResult.class); Mockito.when(resultArtifact.getArtifactPayload()).thenReturn( IOUtils.toByteArray(ResourceFileUtil.getResourceAsStream("example/sdc/service-Simsfoimap0112.csar"))); + // Test the save csar.save(resultArtifact); assertTrue((new File(sdcFolder + "/test-controller/" + csarArtifactName)).exists()); assertEquals(csarArtifactName, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); + // Test dcaeBlueprint + String blueprint = csar.getDcaeBlueprint(); + assertNotNull(blueprint); + assertTrue(!blueprint.isEmpty()); + assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); + // Do some cleanup + Path path = Paths.get(sdcFolder + "/test-controller/" + csarArtifactName); + Files.deleteIfExists(path); } } -- cgit 1.2.3-korg From 69785b88e46c6bcf5f94f2db2a1c097b08bacc7c Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 16 Mar 2018 19:46:33 +0100 Subject: Rework the code Some reworking of different services classes Issue-ID: CLAMP-81 Change-Id: I7815e805f2a41954d633d3e3453af02d0de6b283 Signed-off-by: Determe, Sebastien (sd378r) --- src/main/java/org/onap/clamp/clds/service/CldsService.java | 2 +- .../org/onap/clamp/clds/service/CldsTemplateService.java | 13 +------------ .../org/onap/clamp/clds/it/CldsTemplateServiceItCase.java | 9 +-------- 3 files changed, 3 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index 34bd3d78..a9c81dbb 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -67,13 +67,13 @@ import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.exception.CldsConfigException; import org.onap.clamp.clds.exception.policy.PolicyClientException; import org.onap.clamp.clds.exception.sdc.SdcCommunicationException; -import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsDbServiceCache; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsHealthCheck; import org.onap.clamp.clds.model.CldsInfo; import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.model.CldsModelProp; +import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsServiceData; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.model.DcaeEvent; diff --git a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java index 1b03922d..7a9ee70e 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java @@ -38,7 +38,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import javax.xml.transform.TransformerException; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.model.CldsTemplate; @@ -156,8 +155,7 @@ public class CldsTemplateService extends SecureServiceBase { @Path("/template/{templateName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - public CldsTemplate putTemplate(@PathParam("templateName") String templateName, CldsTemplate cldsTemplate) - throws TransformerException, IOException { + public CldsTemplate putTemplate(@PathParam("templateName") String templateName, CldsTemplate cldsTemplate) { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsTemplateService: PUT template", getPrincipalName()); isAuthorized(permissionUpdateTemplate); @@ -166,15 +164,6 @@ public class CldsTemplateService extends SecureServiceBase { logger.info("PUT propText=" + cldsTemplate.getPropText()); logger.info("PUT imageText=" + cldsTemplate.getImageText()); cldsTemplate.setName(templateName); - String bpmnText = cldsTemplate.getBpmnText(); - String imageText = cldsTemplate.getImageText(); - String propText = cldsTemplate.getPropText(); - cldsTemplate.setBpmnText(bpmnText); - cldsTemplate.setImageText(imageText); - cldsTemplate.setPropText(propText); - logger.info(" bpmnText : " + cldsTemplate.getBpmnText()); - logger.info(" Image Text : " + cldsTemplate.getImageText()); - logger.info(" Prop Text : " + cldsTemplate.getPropText()); cldsTemplate.save(cldsDao, null); // audit log LoggingUtils.setTimeContext(startTime, new Date()); diff --git a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java index 1caa637c..be2997a3 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java @@ -35,7 +35,6 @@ import java.security.Principal; import java.util.List; import javax.ws.rs.core.SecurityContext; -import javax.xml.transform.TransformerException; import org.junit.Before; import org.junit.Test; @@ -93,13 +92,7 @@ public class CldsTemplateServiceItCase { cldsTemplate.setBpmnText(bpmnText); cldsTemplate.setImageText(imageText); cldsTemplate.setPropText(bpmnPropText); - try { - cldsTemplateService.putTemplate("testModel", cldsTemplate); - } catch (IOException e) { - logger.error("IOException while saving template", e); - } catch (TransformerException ex) { - logger.error("Transforming exception while saving template.", ex); - } + cldsTemplateService.putTemplate("testModel", cldsTemplate); } @Test -- cgit 1.2.3-korg