aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorMatthieu Geerebaert <matthieu.geerebaert@orange.com>2018-12-10 16:41:01 +0000
committerGerrit Code Review <gerrit@onap.org>2018-12-10 16:41:01 +0000
commit09d6ce6112d61a7fc98c3038afce636b3e494f29 (patch)
tree2139febfbd9ced2b99b68ae19ee3515f73fff993 /src/main/java
parent2a99e77756091311c29f2dae96c55d5005a27cee (diff)
parentaef15be24def0fbabfcf4aeb80d43a9e6ff3d7cc (diff)
Merge "Integrate sdc-tosca parser jar"
Diffstat (limited to 'src/main/java')
-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);