diff options
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java | 124 | ||||
-rwxr-xr-x | sdc-os-chef/scripts/docker_run.sh | 2 | ||||
-rw-r--r-- | 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<String, DataTypeDefinition> dataTypes, Map<String, ToscaTemplateCapability> capabilties, CapabilityDefinition c) { List<ComponentInstanceProperty> 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<String, List<RequirementDefinition>> requirements = component.getRequirements(); List<Map<String, ToscaRequirement>> toscaRequirements = new ArrayList<>(); if (requirements != null) { - boolean isNodeType = ToscaUtils.isAtomicType(component); + boolean isNodeType = ModelConverter.isAtomicComponent(component); for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) { entry.getValue().stream().filter(r -> (!isNodeType || (isNodeType && component.getUniqueId().equals(r.getOwnerId())) || (isNodeType && r.getOwnerId() == null))).forEach(r -> { ImmutablePair<String, ToscaRequirement> 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<String> capPath = r.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional<ComponentInstance> 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<String> 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<String> capPath = r.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional<ComponentInstance> findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst(); + if (findFirst.isPresent()) { + String LastInPathName = findFirst.get().getNormalizedName(); + + if (capPath.size() > 1) { + List<String> 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<String, ToscaRequirement> 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<String, List<CapabilityDefinition>> capabilities = component.getCapabilities(); Map<String, ToscaCapability> toscaCapabilities = new HashMap<>(); if (capabilities != null) { - boolean isNodeType = ToscaUtils.isAtomicType(component); + boolean isNodeType = ModelConverter.isAtomicComponent(component); for (Map.Entry<String, List<CapabilityDefinition>> 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<String, ToscaCapability> convertProxyCapabilities(Component component, Component proxyComponent, ComponentInstance instanceProxy, Map<String, DataTypeDefinition> dataTypes) { + Map<String, List<CapabilityDefinition>> capabilities = instanceProxy.getCapabilities(); + Map<String, ToscaCapability> toscaCapabilities = new HashMap<>(); + if (capabilities != null) { + boolean isNodeType = ModelConverter.isAtomicComponent(component); + for (Map.Entry<String, List<CapabilityDefinition>> 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<String, String[]> convertSubstitutionMappingCapabilities(Component component, Map<String, DataTypeDefinition> dataTypes) { Map<String, List<CapabilityDefinition>> capabilities = component.getCapabilities(); Map<String, String[]> 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<String> capPath = c.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional<ComponentInstance> 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<String> 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<String> capPath = c.getPath(); + String lastInPath = capPath.get(capPath.size() - 1); + Optional<ComponentInstance> findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst(); + if (findFirst.isPresent()) { + String LastInPathName = findFirst.get().getNormalizedName(); + + if (capPath.size() > 1) { + List<String> 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<String, ToscaCapability> toscaCapabilities, boolean isNodeType, CapabilityDefinition c, Map<String, DataTypeDefinition> 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 417db0994c..dc6b075f8d 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 -TIME_OUT=180 +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 d4316c383f..e06cf84b88 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} |