summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-heat-lib/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src')
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java235
1 files changed, 132 insertions, 103 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 3802018c99..3749846626 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
@@ -1,22 +1,19 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
* 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.heat.services.tree;
@@ -43,7 +40,11 @@ import java.util.Set;
public class HeatTreeManagerUtil {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final String TYPE = "type";
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ private HeatTreeManagerUtil() {
+
+ }
/**
* Init heat tree manager heat tree manager.
@@ -55,7 +56,7 @@ public class HeatTreeManagerUtil {
HeatTreeManager heatTreeManager = new HeatTreeManager();
fileContentMap.getFileList().stream().forEach(
- fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContent(fileName)));
+ fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContent(fileName)));
return heatTreeManager;
}
@@ -63,161 +64,189 @@ public class HeatTreeManagerUtil {
/**
* Gets nested files.
*
- * @param filename the filename
- * @param hot the hot
+ * @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) {
-
- mdcDataDebugMessage.debugEntryMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, null);
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()));
+ resource -> resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml"))
+ .forEach(resource -> nestedFileList.add(resource.getType()));
- resourceDefNestedFiles = getResourceDefNestedFiles(filename, hot, globalContext);
+ Set<String> resourceDefNestedFiles = getResourceDefNestedFiles(hot);
nestedFileList.addAll(resourceDefNestedFiles);
- mdcDataDebugMessage.debugExitMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, null);
return nestedFileList;
}
/**
* Gets artifact files.
*
- * @param filename the filename
- * @param hot the hot
+ * @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) {
-
- mdcDataDebugMessage.debugEntryMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, null);
Set<String> artifactSet = new HashSet<>();
Collection<Resource> resourcesValue =
- hot.getResources() == null ? null : hot.getResources().values();
+ 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 =
- HeatStructureUtil.getReferencedValuesByFunctionName(filename, "get_file", property,
- globalContext);
- artifactSet.addAll(artifactNames);
- }
- }
+ resource.getProperties() == null ? null : resource.getProperties().values();
+
+ artifactSet = getArtifactsFromPropertiesAndAddInArtifactSet(properties,
+ filename, globalContext);
}
}
- mdcDataDebugMessage.debugExitMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, null);
return artifactSet;
}
- private static Set<String> getResourceDefNestedFiles(String filename,
- HeatOrchestrationTemplate hot,
- GlobalValidationContext globalContext) {
+ 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) {
- mdcDataDebugMessage.debugEntryMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, null);
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
- && HeatStructureUtil.isNestedResource(
- getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext)
- .getType()))
- .forEach(entry -> resourceDefNestedFiles.add(
- getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext).getType()));
-
- mdcDataDebugMessage.debugExitMessage(null, null);
+ .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()));
+
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, null);
return resourceDefNestedFiles;
}
/**
* Gets resource def.
*
- * @param filename the filename
- * @param resourceName the resource name
- * @param resource the resource
- * @param globalContext the global context
+ * @param resource the resource
* @return the resource def
*/
@SuppressWarnings("unchecked")
- public static Resource getResourceDef(String filename, String resourceName, Resource resource,
- GlobalValidationContext globalContext) {
-
+ public static Resource getResourceDef( Resource resource) {
- mdcDataDebugMessage.debugEntryMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, null);
Resource resourceDef = null;
Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null
- : (Map<String, Object>) resource.getProperties().get(
+ : (Map<String, Object>) resource.getProperties().get(
PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap());
- if (MapUtils.isNotEmpty(resourceDefValueMap) && resourceDefValueMap != null) {
- 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()),
- LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE, "Invalid resource group type");
- }
- } else {
- globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null",
- resourceName), LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE,
- "Invalid resource type");
+ 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"));
}
}
- mdcDataDebugMessage.debugExitMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, null);
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
- */
+ @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
+ .getErrorWithParameters(
+ globalContext.getMessageCode(),
+ Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(),
+ resourceName, resourceDefType.toString()),
+ LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE, "Invalid resource group type");
+ }
+ }
+ }
+
+ @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
+ .getErrorWithParameters(
+ globalContext.getMessageCode(), Messages.INVALID_RESOURCE_TYPE.getErrorMessage(),
+ "null", resourceName), LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE,
+ "Invalid resource type");
+ }
+ }
+ }
+
+ public static boolean isResourceGroupTypeNested(String resourceDefType) {
+ return HeatStructureUtil.isNestedResource(resourceDefType);
+ }
+
public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName,
- String resourceDefType,
+ Resource resource,
GlobalValidationContext globalContext) {
- if (!HeatStructureUtil.isNestedResource(resourceDefType)) {
- globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(),
- resourceName, resourceDefType),
- LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE,
- "Invalid resource group type");
- return false;
+ //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
+ .getErrorWithParameters(
+ globalContext.getMessageCode(),
+ Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(),
+ resourceName, resourceDefType.toString()),
+ LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE,
+ "Invalid resource group type");
+ return true;
+ }
}
- return true;
+ return false;
}
}