From f981fb475bc70ea016a6a1eca43d346825e65f8f Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Fri, 27 Oct 2017 15:00:14 +0300 Subject: Nodes in service template fix Fail to get correct labels of requirements of nodes in service template fixed Change-Id: I696fd74e2a74c08a652339a25da95f01a7da9d0f Issue-ID: SDC-533 Signed-off-by: Tal Gitelman --- .../be/tosca/CapabiltyRequirementConvertor.java | 124 +++++++++++++++------ sdc-os-chef/scripts/docker_run.sh | 2 +- sdc-os-chef/sdc-sanity/startup.sh | 2 + 3 files changed, 96 insertions(+), 32 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java index 649f083903..d9ed6a295b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -37,6 +38,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.RequirementDefinition; +import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter; import org.openecomp.sdc.be.tosca.model.SubstitutionMapping; import org.openecomp.sdc.be.tosca.model.ToscaCapability; import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate; @@ -92,7 +94,7 @@ public class CapabiltyRequirementConvertor { private void convertOverridenProperties(ComponentInstance componentInstance, Map dataTypes, Map capabilties, CapabilityDefinition c) { List properties = c.getProperties(); if (properties != null && !properties.isEmpty()) { - properties.stream().filter(p -> (p.getValueUniqueUid() != null)).forEach(p -> { + properties.stream().filter(p -> (p.getValue() != null || p.getDefaultValue() != null)).forEach(p -> { convertOverridenProperty(componentInstance, dataTypes, capabilties, c, p); }); } @@ -123,7 +125,8 @@ public class CapabiltyRequirementConvertor { if (prop.getSchema() != null && prop.getSchema().getProperty() != null) { innerType = prop.getSchema().getProperty().getType(); } - Object convertedValue = PropertyConvertor.getInstance().convertToToscaObject(propertyType, prop.getValue(), innerType, dataTypes); + String propValue = prop.getValue() == null ? prop.getDefaultValue() : prop.getValue(); + Object convertedValue = PropertyConvertor.getInstance().convertToToscaObject(propertyType, propValue, innerType, dataTypes); return convertedValue; } @@ -151,7 +154,7 @@ public class CapabiltyRequirementConvertor { Map> requirements = component.getRequirements(); List> toscaRequirements = new ArrayList<>(); if (requirements != null) { - boolean isNodeType = ToscaUtils.isAtomicType(component); + boolean isNodeType = ModelConverter.isAtomicComponent(component); for (Map.Entry> entry : requirements.entrySet()) { entry.getValue().stream().filter(r -> (!isNodeType || (isNodeType && component.getUniqueId().equals(r.getOwnerId())) || (isNodeType && r.getOwnerId() == null))).forEach(r -> { ImmutablePair pair = convertRequirement(component, isNodeType, r); @@ -190,12 +193,21 @@ public class CapabiltyRequirementConvertor { fullReqName = r.getName(); sourceCapName = r.getParentName(); } else { - fullReqName = getRequirementPath(r); + fullReqName = getRequirementPath(component, r); sourceCapName = getSubPathByFirstDelimiterAppearance(fullReqName); } log.debug("the requirement {} belongs to resource {} ", fullReqName, component.getUniqueId()); - if(sourceCapName!= null){ - toscaRequirements.put(fullReqName, new String[]{r.getOwnerName(), sourceCapName}); + if (sourceCapName != null) { + String owner = ""; + + List capPath = r.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst(); + if (findFirst.isPresent()) { + owner = findFirst.get().getNormalizedName(); + } + + toscaRequirements.put(fullReqName, new String[] { owner, sourceCapName }); } }); log.debug("Finish convert Requirements for node type"); @@ -206,18 +218,31 @@ public class CapabiltyRequirementConvertor { return toscaRequirements; } - private String getRequirementPath(RequirementDefinition r) { - List pathArray = Lists.reverse(r.getPath().stream() - .map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))) - .collect(Collectors.toList())); - return new StringBuilder().append(String.join(PATH_DELIMITER, pathArray)).append(PATH_DELIMITER).append(r.getName()).toString(); - + private String getRequirementPath(Component component, RequirementDefinition r) { + + // Evg : for the last in path take real instance name and not "decrypt" unique id. ( instance name can be change and not equal to id..) + // dirty quick fix. must be changed as capability redesign + List capPath = r.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst(); + if (findFirst.isPresent()) { + String LastInPathName = findFirst.get().getNormalizedName(); + + if (capPath.size() > 1) { + List pathArray = Lists.reverse(capPath.stream().map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))).collect(Collectors.toList())); + + return new StringBuilder().append(LastInPathName).append(PATH_DELIMITER).append(String.join(PATH_DELIMITER, pathArray.subList(1, pathArray.size() ))).append(PATH_DELIMITER).append(r.getName()).toString(); + }else{ + return new StringBuilder().append(LastInPathName).append(PATH_DELIMITER).append(r.getName()).toString(); + } + } + return ""; } - + private ImmutablePair convertRequirement(Component component, boolean isNodeType, RequirementDefinition r) { String name = r.getName(); if (!isNodeType) { - name = getRequirementPath(r); + name = getRequirementPath(component, r); } log.debug("the requirement {} belongs to resource {} ", name, component.getUniqueId()); ToscaRequirement toscaRequirement = new ToscaRequirement(); @@ -244,7 +269,7 @@ public class CapabiltyRequirementConvertor { Map> capabilities = component.getCapabilities(); Map toscaCapabilities = new HashMap<>(); if (capabilities != null) { - boolean isNodeType = ToscaUtils.isAtomicType(component); + boolean isNodeType = ModelConverter.isAtomicComponent(component); for (Map.Entry> entry : capabilities.entrySet()) { entry.getValue().stream().filter(c -> (!isNodeType || (isNodeType && component.getUniqueId().equals(c.getOwnerId())) || (isNodeType && c.getOwnerId() == null) )).forEach(c -> { convertCapabilty(component, toscaCapabilities, isNodeType, c, dataTypes); @@ -257,8 +282,26 @@ public class CapabiltyRequirementConvertor { return toscaCapabilities; } - - //This function calls on Substitution Mapping region - the component is always non-atomic + + public Map convertProxyCapabilities(Component component, Component proxyComponent, ComponentInstance instanceProxy, Map dataTypes) { + Map> capabilities = instanceProxy.getCapabilities(); + Map toscaCapabilities = new HashMap<>(); + if (capabilities != null) { + boolean isNodeType = ModelConverter.isAtomicComponent(component); + for (Map.Entry> entry : capabilities.entrySet()) { + entry.getValue().stream().forEach(c -> { + convertCapabilty(proxyComponent, toscaCapabilities, isNodeType, c, dataTypes); + + }); + } + } else { + log.debug("No Capabilities for node type"); + } + + return toscaCapabilities; + } + + // This function calls on Substitution Mapping region - the component is always non-atomic public Map convertSubstitutionMappingCapabilities(Component component, Map dataTypes) { Map> capabilities = component.getCapabilities(); Map toscaCapabilities = new HashMap<>(); @@ -267,16 +310,24 @@ public class CapabiltyRequirementConvertor { entry.getValue().stream().forEach(c -> { String fullCapName; String sourceReqName; - if(ToscaUtils.isComplexVfc(component)){ + if (ToscaUtils.isComplexVfc(component)) { fullCapName = c.getName(); sourceReqName = c.getParentName(); } else { - fullCapName = getCapabilityPath(c); + fullCapName = getCapabilityPath(c, component); sourceReqName = getSubPathByFirstDelimiterAppearance(fullCapName); } log.debug("the capabilty {} belongs to resource {} ", fullCapName, component.getUniqueId()); - if(sourceReqName!= null){ - toscaCapabilities.put(fullCapName, new String[]{c.getOwnerName(), sourceReqName}); + if (sourceReqName != null) { + String owner = ""; + + List capPath = c.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst(); + if (findFirst.isPresent()) { + owner = findFirst.get().getNormalizedName(); + } + toscaCapabilities.put(fullCapName, new String[] { owner, sourceReqName }); } }); } @@ -286,20 +337,31 @@ public class CapabiltyRequirementConvertor { return toscaCapabilities; } - - private String getCapabilityPath(CapabilityDefinition c) { - List pathArray = Lists.reverse(c.getPath().stream() - .map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))) - .collect(Collectors.toList())); - return new StringBuilder().append(String.join(PATH_DELIMITER, pathArray)).append(PATH_DELIMITER).append(c.getName()).toString(); + + private String getCapabilityPath(CapabilityDefinition c, Component component) { + // Evg : for the last in path take real instance name and not "decrypt" unique id. ( instance name can be change and not equal to id..) + // dirty quick fix. must be changed as capability redesign + List capPath = c.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst(); + if (findFirst.isPresent()) { + String LastInPathName = findFirst.get().getNormalizedName(); + + if (capPath.size() > 1) { + List pathArray = Lists.reverse(capPath.stream().map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))).collect(Collectors.toList())); + + return new StringBuilder().append(LastInPathName).append(PATH_DELIMITER).append(String.join(PATH_DELIMITER, pathArray.subList(1, pathArray.size() ))).append(PATH_DELIMITER).append(c.getName()).toString(); + }else{ + return new StringBuilder().append(LastInPathName).append(PATH_DELIMITER).append(c.getName()).toString(); + } + } + return ""; } - - - + private void convertCapabilty(Component component, Map toscaCapabilities, boolean isNodeType, CapabilityDefinition c, Map dataTypes) { String name = c.getName(); if (!isNodeType) { - name = getCapabilityPath(c); + name = getCapabilityPath(c, component); } log.debug("the capabilty {} belongs to resource {} ", name, component.getUniqueId()); ToscaCapability toscaCapability = new ToscaCapability(); diff --git a/sdc-os-chef/scripts/docker_run.sh b/sdc-os-chef/scripts/docker_run.sh index c0ee35f068..53ee6bafe6 100755 --- a/sdc-os-chef/scripts/docker_run.sh +++ b/sdc-os-chef/scripts/docker_run.sh @@ -26,7 +26,7 @@ function monitor_docker { echo monitor $1 Docker sleep 5 -TIME_OUT=600 +TIME_OUT=240 INTERVAL=20 TIME=0 while [ "$TIME" -lt "$TIME_OUT" ]; do diff --git a/sdc-os-chef/sdc-sanity/startup.sh b/sdc-os-chef/sdc-sanity/startup.sh index e4edfc67e6..dc881fed51 100644 --- a/sdc-os-chef/sdc-sanity/startup.sh +++ b/sdc-os-chef/sdc-sanity/startup.sh @@ -1,5 +1,7 @@ #!/bin/bash +sleep 300 + export CHEFNAME=${ENVNAME} cd /root/chef-solo chef-solo -c solo.rb -E ${CHEFNAME} -- cgit 1.2.3-korg