diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java')
-rw-r--r-- | openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java | 178 |
1 files changed, 16 insertions, 162 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java index a216b224af..cd217a50ef 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java @@ -21,18 +21,13 @@ package org.openecomp.sdc.heat.services; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; -import org.openecomp.core.validation.errors.Messages; import org.openecomp.core.validation.types.GlobalValidationContext; +import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorLevel; -import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; -import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; -import org.openecomp.sdc.heat.datatypes.model.PropertiesMapKeyTypes; -import org.openecomp.sdc.heat.datatypes.model.Resource; import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; -import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -40,151 +35,11 @@ import java.util.Objects; import java.util.Set; /** - * The type Heat structure util. + * Created by TALIO on 2/19/2017. */ public class HeatStructureUtil { /** - * Gets nested files. - * - * @param filename the filename - * @param hot the hot - * @param globalContext the global context - * @return the nested files - */ - public static Set<String> getNestedFiles(String filename, HeatOrchestrationTemplate hot, - GlobalValidationContext globalContext) { - - Set<String> nestedFileList = new HashSet<>(); - Set<String> resourceDefNestedFiles; - hot.getResources().values().stream().filter( - resource -> (resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml"))) - .forEach(resource -> nestedFileList.add(resource.getType())); - - resourceDefNestedFiles = getResourceDefNestedFiles(filename, hot, globalContext); - nestedFileList.addAll(resourceDefNestedFiles); - - return nestedFileList; - } - - - private static Set<String> getResourceDefNestedFiles(String filename, - HeatOrchestrationTemplate hot, - GlobalValidationContext globalContext) { - Set<String> resourceDefNestedFiles = new HashSet<>(); - hot.getResources() - .entrySet() - .stream() - .filter(entry -> entry.getValue().getType() - .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) - .filter(entry -> - getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext) != null - && isNestedResource( - getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext) - .getType())) - .forEach(entry -> resourceDefNestedFiles.add( - getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext).getType())); - - return resourceDefNestedFiles; - } - - - /** - * Gets resource def. - * - * @param filename the filename - * @param resourceName the resource name - * @param resource the resource - * @param globalContext the global context - * @return the resource def - */ - @SuppressWarnings("unchecked") - public static Resource getResourceDef(String filename, String resourceName, Resource resource, - GlobalValidationContext globalContext) { - Resource resourceDef = null; - Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null - : (Map<String, Object>) resource.getProperties() - .get(PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); - if (MapUtils.isNotEmpty(resourceDefValueMap)) { - Object resourceDefType = resourceDefValueMap.get("type"); - if (Objects.nonNull(resourceDefType)) { - if (resourceDefType instanceof String) { - boolean isNested = - checkIfResourceGroupTypeIsNested(filename, resourceName, (String) resourceDefType, - globalContext); - if (isNested) { - resourceDef = new Resource(); - resourceDef.setType((String) resourceDefType); - //noinspection unchecked - resourceDef.setProperties((Map<String, Object>) resourceDefValueMap.get("properties")); - } - } else { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), - resourceName, resourceDefType.toString())); - } - } else { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", - resourceName)); - } - - } - return resourceDef; - } - - - /** - * Check if resource group type is nested boolean. - * - * @param filename the filename - * @param resourceName the resource name - * @param resourceDefType the resource def type - * @param globalContext the global context - * @return the boolean - */ - public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName, - String resourceDefType, - GlobalValidationContext globalContext) { - if (!HeatStructureUtil.isNestedResource(resourceDefType)) { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), - resourceName, resourceDefType)); - return false; - } - return true; - } - - /** - * Gets artifact files. - * - * @param filename the filename - * @param hot the hot - * @param globalContext the global context - * @return the artifact files - */ - public static Set<String> getArtifactFiles(String filename, HeatOrchestrationTemplate hot, - GlobalValidationContext globalContext) { - Set<String> artifactSet = new HashSet<>(); - Collection<Resource> resourcesValue = - hot.getResources() == null ? null : hot.getResources().values(); - if (CollectionUtils.isNotEmpty(resourcesValue)) { - for (Resource resource : resourcesValue) { - Collection<Object> properties = - resource.getProperties() == null ? null : resource.getProperties().values(); - if (CollectionUtils.isNotEmpty(properties)) { - for (Object property : properties) { - Set<String> artifactNames = - getReferencedValuesByFunctionName(filename, "get_file", property, globalContext); - artifactSet.addAll(artifactNames); - } - } - } - } - return artifactSet; - } - - /** * Gets referenced values by function name. * * @param filename the filename @@ -194,18 +49,19 @@ public class HeatStructureUtil { * @return the referenced values by function name */ public static Set<String> getReferencedValuesByFunctionName(String filename, String functionName, - Object propertyValue, - GlobalValidationContext globalContext) { + Object propertyValue, + GlobalValidationContext globalContext) { Set<String> valuesNames = new HashSet<>(); if (propertyValue instanceof Map) { Map<String, Object> currPropertyMap = (Map<String, Object>) propertyValue; if (currPropertyMap.containsKey(functionName)) { Object getFunctionValue = currPropertyMap.get(functionName); - if (!(getFunctionValue instanceof String) - && functionName.equals(ResourceReferenceFunctions.GET_RESOURCE.getFunction())) { + if (!(getFunctionValue instanceof String) && functionName.equals( + ResourceReferenceFunctions.GET_RESOURCE.getFunction())) { globalContext.addMessage(filename, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_GET_RESOURCE_SYNTAX.getErrorMessage(), - getFunctionValue == null ? "null" : getFunctionValue.toString())); + .getErrorWithParameters(Messages.INVALID_GET_RESOURCE_SYNTAX.getErrorMessage(), + getFunctionValue == null ? "null" : getFunctionValue.toString()), + LoggerTragetServiceName.VALIDATE_GET_RESOURCE, "Invalid get_resource syntax"); return valuesNames; } if (getFunctionValue instanceof String) { @@ -238,9 +94,9 @@ public class HeatStructureUtil { } } else if (propertyValue instanceof List) { List propertyValueArray = (List) propertyValue; - for (Object propertyValueArrayInstance : propertyValueArray) { + for (Object propValue : propertyValueArray) { valuesNames.addAll( - getReferencedValuesByFunctionName(filename, functionName, propertyValueArrayInstance, + getReferencedValuesByFunctionName(filename, functionName, propValue, globalContext)); } } @@ -249,13 +105,11 @@ public class HeatStructureUtil { } - /** - * Is nested resource boolean. - * - * @param resourceType the resource type - * @return the boolean - */ public static boolean isNestedResource(String resourceType) { + if(Objects.isNull(resourceType)){ + return false; + } return resourceType.endsWith(".yaml") || resourceType.endsWith(".yml"); } + } |