aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java')
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java339
1 files changed, 167 insertions, 172 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java
index 7a2dfc971b..8c6d1354c4 100644
--- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java
+++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java
@@ -12,11 +12,17 @@
* 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.
-*/
+ */
package org.openecomp.sdc.heat.services.tree;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.utilities.file.FileContentHandler;
@@ -30,196 +36,185 @@ import org.openecomp.sdc.heat.datatypes.model.PropertiesMapKeyTypes;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.heat.services.HeatStructureUtil;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
public class HeatTreeManagerUtil {
- private static final String TYPE = "type";
- private HeatTreeManagerUtil() {
-
- }
-
- /**
- * Init heat tree manager heat tree manager.
- *
- * @param fileContentMap the file content map
- * @return the heat tree manager
- */
- public static HeatTreeManager initHeatTreeManager(FileContentHandler fileContentMap) {
-
- HeatTreeManager heatTreeManager = new HeatTreeManager();
- fileContentMap.getFileList().stream().forEach(
- fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContent(fileName)));
-
- return heatTreeManager;
- }
-
- /**
- * 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<>();
- hot.getResources().values().stream().filter(
- resource -> resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml"))
- .forEach(resource -> nestedFileList.add(resource.getType()));
-
- Set<String> resourceDefNestedFiles = getResourceDefNestedFiles(hot);
- nestedFileList.addAll(resourceDefNestedFiles);
- return nestedFileList;
- }
-
- /**
- * 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();
-
- artifactSet.addAll(getArtifactsFromPropertiesAndAddInArtifactSet(properties,
- filename, globalContext));
- }
+ private static final String TYPE = "type";
+
+ private HeatTreeManagerUtil() {
+
}
- return artifactSet;
- }
-
- private static Set<String> getArtifactsFromPropertiesAndAddInArtifactSet(Collection<Object> properties,
- String filename,
- GlobalValidationContext globalContext ){
- Set<String> artifactSet = new HashSet<>();
- if (CollectionUtils.isNotEmpty(properties)) {
-
- for (Object property : properties) {
- Set<String> artifactNames =
- HeatStructureUtil.getReferencedValuesByFunctionName(filename, "get_file", property,
- globalContext);
- artifactSet.addAll(artifactNames);
- }
+
+ /**
+ * Init heat tree manager heat tree manager.
+ *
+ * @param fileContentMap the file content map
+ * @return the heat tree manager
+ */
+ public static HeatTreeManager initHeatTreeManager(FileContentHandler fileContentMap) {
+
+ HeatTreeManager heatTreeManager = new HeatTreeManager();
+ fileContentMap.getFileList().forEach(
+ fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContent(fileName)));
+
+ return heatTreeManager;
}
- return artifactSet;
- }
-
- private static Set<String> getResourceDefNestedFiles(HeatOrchestrationTemplate hot) {
- Set<String> resourceDefNestedFiles = new HashSet<>();
- hot.getResources()
- .entrySet().stream().filter(entry -> entry.getValue().getType()
- .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()))
- .filter(entry ->
- getResourceDef(entry.getValue()) != null
- && HeatStructureUtil.isNestedResource(
- getResourceDef(entry.getValue())
- .getType()))
- .forEach(entry -> resourceDefNestedFiles.add(
- getResourceDef( entry.getValue()).getType()));
- return resourceDefNestedFiles;
- }
-
- /**
- * Gets resource def.
- *
- * @param resource the resource
- * @return the resource def
- */
- @SuppressWarnings("unchecked")
- public static Resource getResourceDef( Resource resource) {
- Resource resourceDef = null;
- Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null
- : (Map<String, Object>) resource.getProperties().get(
- PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap());
- if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) {
- Object resourceDefType = resourceDefValueMap.get(TYPE);
- if ( resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) {
- resourceDef = new Resource();
- resourceDef.setType((String) resourceDefType);
- //noinspection unchecked
- resourceDef.setProperties((Map<String, Object>) resourceDefValueMap.get("properties"));
- }
+ /**
+ * Will verify the resource type and if type is of nested will return the nested file name
+ *
+ * @param hot Containing all translated data from heat file
+ * @return the nested files
+ */
+ public static Set<String> getNestedFiles(HeatOrchestrationTemplate hot) {
+ Set<String> nestedFileList = new HashSet<>();
+ hot.getResources().values().stream().filter(
+ resource -> resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml"))
+ .forEach(resource -> nestedFileList.add(resource.getType()));
+
+ Set<String> resourceDefNestedFiles = getResourceDefNestedFiles(hot);
+ nestedFileList.addAll(resourceDefNestedFiles);
+ return nestedFileList;
+ }
+
+ /**
+ * Verify if any artifact present in file whose detail is provided and return Artifact name
+ *
+ * @param filename name of file where artifact is too be looked for
+ * @param hot translated heat data
+ * @param globalContext the global context
+ * @return the artifact files name
+ */
+ 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();
+
+ artifactSet.addAll(getArtifactsFromPropertiesAndAddInArtifactSet(properties,
+ filename, globalContext));
+ }
+ }
+ return artifactSet;
+ }
+
+ private static Set<String> getArtifactsFromPropertiesAndAddInArtifactSet(Collection<Object> properties,
+ String filename,
+ GlobalValidationContext globalContext) {
+ Set<String> artifactSet = new HashSet<>();
+ if (CollectionUtils.isNotEmpty(properties)) {
+
+ for (Object property : properties) {
+ Set<String> artifactNames =
+ HeatStructureUtil.getReferencedValuesByFunctionName(filename, "get_file", property,
+ globalContext);
+ artifactSet.addAll(artifactNames);
+ }
+ }
+
+ return artifactSet;
+ }
+ private static Set<String> getResourceDefNestedFiles(HeatOrchestrationTemplate hot) {
+ Set<String> resourceDefNestedFiles = new HashSet<>();
+ hot.getResources()
+ .entrySet().stream().filter(entry -> entry.getValue().getType()
+ .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()))
+ .filter(entry ->
+ getResourceDef(entry.getValue()) != null
+ && HeatStructureUtil.isNestedResource(
+ getResourceDef(entry.getValue())
+ .getType()))
+ .forEach(entry -> resourceDefNestedFiles.add(
+ getResourceDef(entry.getValue()).getType()));
+ return resourceDefNestedFiles;
}
- return resourceDef;
- }
-
- @SuppressWarnings("unchecked")
- public static void checkResourceGroupTypeValid(String filename, String resourceName,
- Resource resource,
- GlobalValidationContext globalContext) {
- Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null
- : (Map<String, Object>) resource.getProperties().get(
- PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap());
- if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) {
- Object resourceDefType = resourceDefValueMap.get(TYPE);
- if (Objects.nonNull(resourceDefType) && !(resourceDefType instanceof String) ) {
- globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+
+ /**
+ * Gets resource def.
+ *
+ * @param resource the resource
+ * @return the resource def
+ */
+ @SuppressWarnings("unchecked")
+ public static Resource getResourceDef(Resource resource) {
+ 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 (resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) {
+ resourceDef = new Resource();
+ resourceDef.setType((String) resourceDefType);
+ //noinspection unchecked
+ resourceDef.setProperties((Map<String, Object>) resourceDefValueMap.get("properties"));
+ }
+
+ }
+ return resourceDef;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void checkResourceGroupTypeValid(String filename, String resourceName,
+ Resource resource,
+ GlobalValidationContext globalContext) {
+ 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) && !(resourceDefType instanceof String)) {
+ globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
.getErrorWithParameters(
globalContext.getMessageCode(),
Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(),
resourceName, resourceDefType.toString()));
- }
+ }
+ }
}
- }
-
- @SuppressWarnings("unchecked")
- public static void checkResourceTypeValid(String filename, String resourceName,
- Resource resource,
- GlobalValidationContext globalContext) {
- Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null
- : (Map<String, Object>) resource.getProperties().get(
- PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap());
- if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) {
- Object resourceDefType = resourceDefValueMap.get(TYPE);
- if (Objects.isNull(resourceDefType)) {
- globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+
+ @SuppressWarnings("unchecked")
+ public static void checkResourceTypeValid(String filename, String resourceName,
+ Resource resource,
+ GlobalValidationContext globalContext) {
+ 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.isNull(resourceDefType)) {
+ globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
.getErrorWithParameters(
globalContext.getMessageCode(), Messages.INVALID_RESOURCE_TYPE.getErrorMessage(),
"null", resourceName));
- }
+ }
+ }
}
- }
-
- public static boolean isResourceGroupTypeNested(String resourceDefType) {
- return HeatStructureUtil.isNestedResource(resourceDefType);
- }
-
- public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName,
- Resource resource,
- GlobalValidationContext globalContext) {
- //noinspection unchecked
- Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null
- : (Map<String, Object>) resource.getProperties().get(
- PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap());
- if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) {
- Object resourceDefType = resourceDefValueMap.get(TYPE);
- if (resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) {
-
- globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+
+ public static boolean isResourceGroupTypeNested(String resourceDefType) {
+ return HeatStructureUtil.isNestedResource(resourceDefType);
+ }
+
+ public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName,
+ Resource resource,
+ GlobalValidationContext globalContext) {
+ //noinspection unchecked
+ 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 (resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) {
+ globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
.getErrorWithParameters(
globalContext.getMessageCode(),
Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(),
resourceName, resourceDefType.toString()));
- return true;
- }
+ return true;
+ }
+ }
+ return false;
}
- return false;
- }
}