aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Determe <sd378r@intl.att.com>2018-03-21 14:05:17 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-21 14:05:17 +0000
commitaf455560f39b716a8d770a39012e4004ac03e9f3 (patch)
tree853cc2dee561c9f121f783bd9b4d71aa4b3403ae
parent3dc5f2a4a5c066a57ef0ce346be884b045ae73c9 (diff)
parent69785b88e46c6bcf5f94f2db2a1c097b08bacc7c (diff)
Merge changes from topic 'feature/sdc-controller'
* changes: Rework the code CsarHandler rework Add new config classes
-rw-r--r--src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserFilesConfiguration.java52
-rw-r--r--src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserMappingConfiguration.java65
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java60
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java13
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java9
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java17
7 files changed, 174 insertions, 44 deletions
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 000000000..10306b433
--- /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 000000000..b26310400
--- /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<BlueprintParserMappingConfiguration> createFromJson(InputStream json) throws IOException {
+ TypeReference<List<BlueprintParserMappingConfiguration>> mapType = new TypeReference<List<BlueprintParserMappingConfiguration>>() {
+ };
+ return new ObjectMapper().readValue(json, mapType);
+ }
+}
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;
+ }
}
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 675f3cfe5..9d6cb0820 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -68,13 +68,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 1b03922d1..7a9ee70e5 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 1caa637c5..be2997a31 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
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 d1b177d22..34805d87a 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);
}
}