aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authoraosull01 <adrian.osullivan@huawei.com>2018-11-23 10:39:04 +0000
committeraosull01 <adrian.osullivan@huawei.com>2018-12-05 10:48:10 +0000
commitaef15be24def0fbabfcf4aeb80d43a9e6ff3d7cc (patch)
tree2933b412f381f2caef1dcc275a163314a54c80f2 /src/main
parent953984ee0ccb656e851907bd16d9217dd6057695 (diff)
Integrate sdc-tosca parser jar
Change-Id: Ieef1c4fe9d71164c7696bdb0bd93579a87bc09dc Issue-ID: EXTAPI-171 Signed-off-by: aosull01 <adrian.osullivan@huawei.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java24
-rw-r--r--src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java71
2 files changed, 94 insertions, 1 deletions
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java b/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java
index 1c4546b..e25ab4e 100644
--- a/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java
+++ b/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java
@@ -16,7 +16,11 @@ package org.onap.nbi.apis.servicecatalog;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -129,6 +133,26 @@ public class SdcClient {
return toscaFile;
}
+
+ public Path getServiceToscaModel(String uuid) throws IOException {
+ StringBuilder urlBuilder = new StringBuilder().append(sdcHost).append(OnapComponentsUrlPaths.SDC_ROOT_URL)
+ .append("/").append(uuid).append(OnapComponentsUrlPaths.SDC_TOSCA_PATH);
+
+ UriComponentsBuilder callURI = UriComponentsBuilder.fromHttpUrl(urlBuilder.toString());
+
+ InputStream inputStream = (InputStream) callSdc(callURI.build().encode().toUri()).getBody();
+
+ return createTmpFile(inputStream);
+ }
+
+ private Path createTmpFile(InputStream csarInputStream) throws IOException {
+ Path csarFile = Files.createTempFile("csar", ".zip");
+ Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING);
+
+ LOGGER.debug("Tosca file was saved at: {} ", csarFile.toAbsolutePath());
+
+ return csarFile;
+ }
private HttpEntity<String> buildRequestHeader() {
HttpHeaders httpHeaders = new HttpHeaders();
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java
index 54b5486..99a1657 100644
--- a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java
+++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java
@@ -19,6 +19,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.file.Path;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -30,6 +31,11 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.FileUtils;
import org.onap.nbi.exceptions.TechnicalException;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.parameters.Input;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -88,8 +94,71 @@ public class ToscaInfosProcessor {
}
}
}
+
+ public void buildResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse) throws SdcToscaParserException {
- private List<LinkedHashMap> buildServiceSpecCharacteristicsValues(LinkedHashMap parameter, String parameterType) {
+ SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
+ ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(),false);
+ List<Input> inputs = sdcCsarHelper.getServiceInputs();
+ if(inputs != null && inputs.size() > 0) {
+ ArrayList serviceSpecCharacteristic = new ArrayList();
+ for(Input input : inputs) {
+ LinkedHashMap mapParameter = new LinkedHashMap();
+ mapParameter.put("name", input.getName());
+ mapParameter.put("description", input.getDescription());
+ mapParameter.put("valueType", input.getType());
+ mapParameter.put("@type", "ONAPserviceCharacteristic");
+ mapParameter.put("required", input.isRequired());
+ mapParameter.put("status", null);
+ mapParameter.put("serviceSpecCharacteristicValue", null);
+ // If this Input has a default value, then put it in serviceSpecCharacteristicValue
+ if (input.getDefault() != null)
+ {
+ List<LinkedHashMap> serviceSpecCharacteristicValues =
+ buildServiceSpecCharacteristicsValuesFromSdc(input);
+ mapParameter.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValues);
+ }
+ serviceSpecCharacteristic.add(mapParameter);
+ }
+ serviceCatalogResponse.put("serviceSpecCharacteristic", serviceSpecCharacteristic);
+ }
+ List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates();
+
+ List<LinkedHashMap> resourceSpecifications =
+ (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification");
+ for (LinkedHashMap resourceSpecification : resourceSpecifications) {
+ if(resourceSpecification.get("id")!=null){
+ String id = (String) resourceSpecification.get("id");
+ LOGGER.debug("get tosca infos for service id: {}", id);
+ NodeTemplate nodeTemplate = null;
+ for(NodeTemplate node : nodeTemplates) {
+ if(node.getMetaData().getValue("UUID").equals(id)) {
+ nodeTemplate = node;
+ break;
+ }
+ }
+ if(nodeTemplate == null)
+ continue;
+ resourceSpecification.put("modelCustomizationId", sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate));
+ }
+ }
+ }
+
+
+ private List<LinkedHashMap> buildServiceSpecCharacteristicsValuesFromSdc(Input input) {
+
+ List<LinkedHashMap> serviceSpecCharacteristicValues = new ArrayList<>();
+ LinkedHashMap serviceSpecCharacteristicValue = new LinkedHashMap();
+
+ serviceSpecCharacteristicValue.put("isDefault", true);
+ serviceSpecCharacteristicValue.put("value", input.getDefault());
+ serviceSpecCharacteristicValue.put("valueType", input.getType());
+ serviceSpecCharacteristicValues.add(serviceSpecCharacteristicValue);
+
+ return serviceSpecCharacteristicValues;
+ }
+
+ private List<LinkedHashMap> buildServiceSpecCharacteristicsValues(LinkedHashMap parameter, String parameterType) {
List<LinkedHashMap> serviceSpecCharacteristicValues = new ArrayList<>();
if (!"map".equalsIgnoreCase(parameterType) && !"list".equalsIgnoreCase(parameterType)) {
LOGGER.debug("get tosca infos for serviceSpecCharacteristicValues of type map or string : {}", parameter);