diff options
author | Liang Ding <liang.ding@intel.com> | 2019-04-15 00:05:05 -0700 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-10-30 07:56:21 +0000 |
commit | 8ff60789e080dd99c604d31a6e754be164fba11e (patch) | |
tree | bae4286ab2b19a0d0a3a6ebedd57e17aa42dceea /catalog-be/src/main/java | |
parent | c42c9f75adb72f80e57694b5bf67db7c94f33a89 (diff) |
add artifacts support in TOSCA exported yml file
Change-Id: I56f8a6a1ce758876e83a7ee8318b79644ae7d5cb
Issue-ID: SDC-1952
Signed-off-by: Liang Ding <liang.ding@intel.com>
Diffstat (limited to 'catalog-be/src/main/java')
6 files changed, 148 insertions, 67 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 7b3d4fac25..cff6c26e58 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -467,6 +467,7 @@ public class YamlTemplateParsingHandler { setToscaResourceType(createdNodesToscaResourceNames, nodeTemplateInfo, nodeTemplateJsonMap); setRequirements(nodeTemplateInfo, nodeTemplateJsonMap); setCapabilities(nodeTemplateInfo, nodeTemplateJsonMap); + setArtifacts(nodeTemplateInfo, nodeTemplateJsonMap); updateProperties(nodeTemplateInfo, nodeTemplateJsonMap); setDirectives(nodeTemplateInfo, nodeTemplateJsonMap); setNodeFilter(nodeTemplateInfo, nodeTemplateJsonMap); @@ -515,6 +516,15 @@ public class YamlTemplateParsingHandler { } } + private void setArtifacts(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) { + if (nodeTemplateJsonMap.containsKey(ARTIFACTS.getElementName())) { + Map<String, Map<String, UploadArtifactInfo>> eitherArtifactsRes = createArtifactsModuleFromYaml(nodeTemplateJsonMap); + if (!eitherArtifactsRes.isEmpty()) { + nodeTemplateInfo.setArtifacts(eitherArtifactsRes); + } + } + } + private void setRequirements(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) { if (nodeTemplateJsonMap.containsKey(REQUIREMENTS.getElementName())) { Map<String, List<UploadReqInfo>> regResponse = createReqModuleFromYaml(nodeTemplateJsonMap); @@ -591,6 +601,63 @@ public class YamlTemplateParsingHandler { } @SuppressWarnings("unchecked") + private Map<String, Map<String, UploadArtifactInfo>> createArtifactsModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) { + Map<String, Map<String, UploadArtifactInfo>> moduleArtifacts = new HashMap<>(); + Either<List<Object>, ResultStatusEnum> ArtifactsListRes = + findFirstToscaListElement(nodeTemplateJsonMap, ARTIFACTS); + if (ArtifactsListRes.isLeft()) { + for (Object jsonArtifactObj : ArtifactsListRes.left().value()) { + String key = ((Map<String, Object>) jsonArtifactObj).keySet().iterator().next(); + Object artifactJson = ((Map<String, Object>) jsonArtifactObj).get(key); + addModuleNodeTemplateArtifacts(moduleArtifacts, artifactJson, key); + } + } else { + Either<Map<String, Map<String, Object>>, ResultStatusEnum> ArtifactsMapRes = + findFirstToscaMapElement(nodeTemplateJsonMap, ARTIFACTS); + if (ArtifactsMapRes.isLeft()) { + for (Map.Entry<String, Map<String, Object>> entry : ArtifactsMapRes.left().value().entrySet()) { + String artifactName = entry.getKey(); + Object artifactJson = entry.getValue(); + addModuleNodeTemplateArtifacts(moduleArtifacts, artifactJson, artifactName); + } + } + } + return moduleArtifacts; + } + + private void addModuleNodeTemplateArtifacts(Map<String, Map<String, UploadArtifactInfo>> moduleArtifacts, Object artifactJson, String artifactName) { + + UploadArtifactInfo artifact = buildModuleNodeTemplateArtifact(artifactJson); + artifact.setName(artifactName); + if (moduleArtifacts.containsKey(ARTIFACTS.getElementName())) { + moduleArtifacts.get(ARTIFACTS.getElementName()).put(artifactName, artifact); + } else { + Map<String, UploadArtifactInfo> map = new HashMap<>(); + map.put(artifactName, artifact); + moduleArtifacts.put(ARTIFACTS.getElementName(), map); + } + } + + @SuppressWarnings("unchecked") + private UploadArtifactInfo buildModuleNodeTemplateArtifact(Object artifactObject) { + UploadArtifactInfo artifactTemplateInfo = new UploadArtifactInfo(); + if (artifactObject instanceof Map) { + fillArtifact(artifactTemplateInfo, (Map<String, Object>) artifactObject); + } + return artifactTemplateInfo; + } + + private void fillArtifact(UploadArtifactInfo artifactTemplateInfo, Map<String, Object> nodeTemplateJsonMap) { + if (nodeTemplateJsonMap.containsKey(TYPE.getElementName())) { + artifactTemplateInfo.setType((String) nodeTemplateJsonMap.get(TYPE.getElementName())); + } + if (nodeTemplateJsonMap.containsKey(FILE.getElementName())) { + artifactTemplateInfo.setFile((String) nodeTemplateJsonMap.get(FILE.getElementName())); + } + } + + + @SuppressWarnings("unchecked") private Map<String, List<UploadCapInfo>> createCapModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) { Map<String, List<UploadCapInfo>> moduleCap = new HashMap<>(); Either<List<Object>, ResultStatusEnum> capabilitiesListRes = diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index 3d149f79e6..9eae363afb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -52,6 +52,7 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; @@ -388,8 +389,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { .equals(ArtifactTypeEnum.TOSCA_CSAR.getType()) && StringUtils.isEmpty(artifactInfo.getArtifactChecksum()); } - public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateAndSaveToscaArtifact(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest, - boolean shouldLock, boolean inTransaction, boolean fetchTemplatesFromDB) { + public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateAndSaveToscaArtifact( + ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, + User user, boolean isInCertificationRequest, boolean shouldLock, boolean inTransaction, + boolean fetchTemplatesFromDB) { Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generated = generateToscaArtifact(component, artifactDefinition, isInCertificationRequest, fetchTemplatesFromDB); if (generated.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 5a997205ea..12345e7802 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -47,6 +47,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.regex.Pattern; +import java.util.stream.Collectors; import fj.data.Either; import org.apache.commons.codec.binary.Base64; @@ -83,6 +84,7 @@ import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.CreatedFrom; @@ -115,6 +117,7 @@ import org.openecomp.sdc.be.model.RelationshipInfo; import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.UploadArtifactInfo; import org.openecomp.sdc.be.model.UploadCapInfo; import org.openecomp.sdc.be.model.UploadComponentInstanceInfo; import org.openecomp.sdc.be.model.UploadInfo; @@ -3113,6 +3116,23 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { uploadComponentInstanceInfo.getCapabilities()); componentInstance.setCapabilities(validComponentInstanceCapabilities); } + + if (isNotEmpty(uploadComponentInstanceInfo.getArtifacts())) { + Map<String, Map<String, UploadArtifactInfo>> artifacts = uploadComponentInstanceInfo.getArtifacts(); + Map<String, ToscaArtifactDataDefinition> toscaArtifacts = new HashMap<>(); + Map<String, Map<String, UploadArtifactInfo>> arts = artifacts.entrySet().stream() + .filter(e -> e.getKey().contains(TypeUtils.ToscaTagNamesEnum.ARTIFACTS.getElementName())) + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); + Map<String, UploadArtifactInfo> artifact = arts.get(TypeUtils.ToscaTagNamesEnum.ARTIFACTS.getElementName()); + for (Map.Entry<String, UploadArtifactInfo> entry : artifact.entrySet()) { + ToscaArtifactDataDefinition to = new ToscaArtifactDataDefinition(); + to.setFile(entry.getValue().getFile()); + to.setType(entry.getValue().getType()); + toscaArtifacts.put(entry.getKey(), to); + } + componentInstance.setToscaArtifacts(toscaArtifacts); + } + if (!existingnodeTypeMap.containsKey(uploadComponentInstanceInfo.getType())) { log.debug( "createResourceInstances - not found lates version for resource instance with name {} and type ", diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 0d3836b1c9..257ea3675d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -658,6 +658,9 @@ public class ToscaExportHandler { Map<String, ToscaGroupTemplate> groupsMap = null; for (ComponentInstance componentInstance : componentInstances) { ToscaNodeTemplate nodeTemplate = new ToscaNodeTemplate(); + if (MapUtils.isNotEmpty(componentInstance.getToscaArtifacts())) { + nodeTemplate.setArtifacts(convertToNodeTemplateArtifacts(componentInstance.getToscaArtifacts())); + } nodeTemplate.setType(componentInstance.getToscaComponentName()); nodeTemplate.setDirectives(componentInstance.getDirectives()); nodeTemplate.setNode_filter(convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter())); @@ -1249,6 +1252,19 @@ public class ToscaExportHandler { return Either.left(nodeType); } + private Map<String, ToscaTemplateArtifact> convertToNodeTemplateArtifacts(Map<String, ToscaArtifactDataDefinition> artifacts) { + if (artifacts == null) { + return null; + } + Map<String, ToscaTemplateArtifact> arts = new HashMap<>(); + for (Map.Entry<String, ToscaArtifactDataDefinition> entry : artifacts.entrySet()) { + ToscaTemplateArtifact artifact = new ToscaTemplateArtifact(); + artifact.setFile(entry.getValue().getFile()); + artifact.setType(entry.getValue().getType()); + arts.put(entry.getKey(), artifact); + } + return arts; + } protected NodeFilter convertToNodeTemplateNodeFilterComponent(CINodeFilterDataDefinition inNodeFilter) { if (inNodeFilter == null){ diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java index b17dc3a43f..d757cec36c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java @@ -27,6 +27,11 @@ import java.util.List; import java.util.Map; import org.apache.commons.collections.CollectionUtils; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter public class ToscaNodeTemplate { private String type; @@ -36,61 +41,10 @@ public class ToscaNodeTemplate { private Map<String, Object> properties; private List<Map<String, ToscaTemplateRequirement>> requirements; private Map<String, ToscaTemplateCapability> capabilities; + private Map<String, ToscaTemplateArtifact> artifacts; private NodeFilter node_filter; private Map<String, Object> interfaces; - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Map<String, Object> getProperties() { - return properties; - } - - public void setProperties(Map<String, Object> properties) { - this.properties = properties; - } - - public List<Map<String, ToscaTemplateRequirement>> getRequirements() { - return requirements; - } - - public void setRequirements(List<Map<String, ToscaTemplateRequirement>> requirements) { - this.requirements = requirements; - } - - public Map<String, ToscaTemplateCapability> getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map<String, ToscaTemplateCapability> capabilities) { - this.capabilities = capabilities; - } - - public ToscaMetadata getMetadata() { - return metadata; - } - - public void setMetadata(ToscaMetadata metadata) { - this.metadata = metadata; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public List<String> getDirectives() { - return directives; - } - public void setDirectives(List<String> directives) { if (CollectionUtils.isEmpty(directives)) { this.directives = null; @@ -99,19 +53,6 @@ public class ToscaNodeTemplate { this.directives = directives; } - public NodeFilter getNode_filter() { - return node_filter; - } - - public void setNode_filter(NodeFilter node_filter) { - this.node_filter = node_filter; - } - - public void setInterfaces( - Map<String, Object> interfaces) { - this.interfaces = interfaces; - } - public void addInterface(String interfaceName, Object interfaceDataDefinition) { if (MapUtils.isEmpty(this.interfaces)) { this.interfaces = new HashMap<>(); @@ -120,3 +61,4 @@ public class ToscaNodeTemplate { this.interfaces.put(interfaceName, interfaceDataDefinition); } } + diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateArtifact.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateArtifact.java new file mode 100644 index 0000000000..58432ba29b --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateArtifact.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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========================================================= + */ + +package org.openecomp.sdc.be.tosca.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ToscaTemplateArtifact { + + private String file; + private String type; + +} |