summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-22 15:33:06 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-24 06:59:47 +0000
commitd378c37fbd1ecec7b43394926f1ca32a695e07de (patch)
tree5c8a085f8732f980d871d966ac49361644efa698 /openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src
parenta6ae7294ecd336d7e88f915710b08e2658eaee00 (diff)
Reformat openecomp-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java518
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/YamlValidatorUtil.java37
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java206
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/FileExtensionUtils.java10
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java152
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtil.java25
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java307
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java888
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java251
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java23
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/PmDictionaryValidator.java38
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java284
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java32
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ContrailNetworkPolicyResourceValidator.java87
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java92
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java122
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronSecurityGroupResourceValidator.java66
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java141
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java132
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ResourceGroupResourceValidator.java165
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java201
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java81
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java242
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java81
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java769
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java290
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/tos/ContrailResourcesMappingTo.java148
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/type/ValidatorConstants.java7
28 files changed, 2233 insertions, 3162 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java
index 6f647bf04b..3a0485cbd5 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java
@@ -13,9 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.util;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -33,333 +41,251 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.validation.impl.validators.HeatValidator;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-
-
public class HeatValidationService {
- private static final Logger LOGGER = LoggerFactory.getLogger(HeatValidator.class);
- private static final String NO_CONTENT_IN_FILE_MSG = "The file ' %s ' has no content";
- private HeatValidationService(){
-
- }
- /**
- * Check artifacts existence.
- *
- * @param fileName the file name
- * @param artifactsNames the artifacts names
- * @param globalContext the global context
- */
- public static void checkArtifactsExistence(String fileName, Set<String> artifactsNames,
- GlobalValidationContext globalContext) {
- artifactsNames
- .stream()
- .filter(artifactName -> !globalContext.getFileContextMap().containsKey(artifactName))
- .forEach(artifactName ->
- globalContext.addMessage(fileName,
- ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- globalContext.getMessageCode(),
- Messages.MISSING_ARTIFACT.getErrorMessage(), artifactName)));
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(HeatValidator.class);
+ private static final String NO_CONTENT_IN_FILE_MSG = "The file ' %s ' has no content";
- /**
- * Draw files loop string.
- *
- * @param filesInPath the files in path
- * @return the string
- */
- public static String drawFilesLoop(List<String> filesInPath) {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append("[");
- int pathSize = filesInPath.size();
-
- for (int i = 0; i < pathSize; i++) {
- stringBuilder.append(filesInPath.get(i));
- if (i != pathSize - 1) {
- stringBuilder.append(" -- ");
- }
- }
- if (!filesInPath.get(0).equals(filesInPath.get(pathSize - 1))) {
- stringBuilder.append(" -- ");
- stringBuilder.append(filesInPath.get(0));
+ private HeatValidationService() {
}
- stringBuilder.append("]");
-
- return stringBuilder.toString();
- }
-
- /**
- * Check nested parameters.
- *
- * @param parentFileName the calling nested file name
- * @param nestedFileName the nested file name
- * @param globalContext the global context
- * @param parentParameters parent parameters.
- * @param nestedParameters nested parameters.
- * @param nestedParametersNames nested parameter names.
- */
- private static void checkNestedParameters(String parentFileName, String nestedFileName,
- GlobalValidationContext globalContext,
- Map<String, Parameter> parentParameters,
- Map<String, Parameter> nestedParameters,
- Set<String> nestedParametersNames) {
- HeatOrchestrationTemplate parentHeatOrchestrationTemplate;
- HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
- try {
- nestedHeatOrchestrationTemplate = getHeatOrchestrationTemplate(nestedFileName, globalContext);
- parentHeatOrchestrationTemplate = getHeatOrchestrationTemplate(parentFileName, globalContext);
- } catch (Exception exception) {
- return;
+ /**
+ * Check artifacts existence.
+ *
+ * @param fileName the file name
+ * @param artifactsNames the artifacts names
+ * @param globalContext the global context
+ */
+ public static void checkArtifactsExistence(String fileName, Set<String> artifactsNames, GlobalValidationContext globalContext) {
+ artifactsNames.stream().filter(artifactName -> !globalContext.getFileContextMap().containsKey(artifactName)).forEach(
+ artifactName -> globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(globalContext.getMessageCode(), Messages.MISSING_ARTIFACT.getErrorMessage(), artifactName)));
}
- parentParameters.putAll(parentHeatOrchestrationTemplate.getParameters());
- nestedParameters.putAll(nestedHeatOrchestrationTemplate.getParameters());
- if (!nestedParameters.isEmpty()) {
- nestedParametersNames.addAll(nestedHeatOrchestrationTemplate.getParameters().keySet());
+ /**
+ * Draw files loop string.
+ *
+ * @param filesInPath the files in path
+ * @return the string
+ */
+ public static String drawFilesLoop(List<String> filesInPath) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("[");
+ int pathSize = filesInPath.size();
+ for (int i = 0; i < pathSize; i++) {
+ stringBuilder.append(filesInPath.get(i));
+ if (i != pathSize - 1) {
+ stringBuilder.append(" -- ");
+ }
+ }
+ if (!filesInPath.get(0).equals(filesInPath.get(pathSize - 1))) {
+ stringBuilder.append(" -- ");
+ stringBuilder.append(filesInPath.get(0));
+ }
+ stringBuilder.append("]");
+ return stringBuilder.toString();
}
- }
-
- private static HeatOrchestrationTemplate getHeatOrchestrationTemplate(String fileName,
- GlobalValidationContext globalContext)
- throws Exception {
- Optional<InputStream> fileContent = globalContext.getFileContent(fileName);
- if (fileContent.isPresent()) {
- return new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- Exception exception = new Exception(String.format(NO_CONTENT_IN_FILE_MSG, fileName));
- LOGGER.error("Error while reading file : " + fileName , exception);
- throw exception;
+ /**
+ * Check nested parameters.
+ *
+ * @param parentFileName the calling nested file name
+ * @param nestedFileName the nested file name
+ * @param globalContext the global context
+ * @param parentParameters parent parameters.
+ * @param nestedParameters nested parameters.
+ * @param nestedParametersNames nested parameter names.
+ */
+ private static void checkNestedParameters(String parentFileName, String nestedFileName, GlobalValidationContext globalContext,
+ Map<String, Parameter> parentParameters, Map<String, Parameter> nestedParameters,
+ Set<String> nestedParametersNames) {
+ HeatOrchestrationTemplate parentHeatOrchestrationTemplate;
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
+ try {
+ nestedHeatOrchestrationTemplate = getHeatOrchestrationTemplate(nestedFileName, globalContext);
+ parentHeatOrchestrationTemplate = getHeatOrchestrationTemplate(parentFileName, globalContext);
+ } catch (Exception exception) {
+ return;
+ }
+ parentParameters.putAll(parentHeatOrchestrationTemplate.getParameters());
+ nestedParameters.putAll(nestedHeatOrchestrationTemplate.getParameters());
+ if (!nestedParameters.isEmpty()) {
+ nestedParametersNames.addAll(nestedHeatOrchestrationTemplate.getParameters().keySet());
+ }
}
- }
-
- public static void checkNestedParametersNoMissingParameterInNested(String parentFileName,
- String nestedFileName,
- String resourceName,
- Set<String> resourceFileProperties,
- GlobalValidationContext globalContext) {
- Map<String, Parameter> parentParameters = new HashMap<>();
- Map<String, Parameter> nestedParameters = new HashMap<>();
- Set<String> nestedParametersNames = new HashSet<>();
- checkNestedParameters(parentFileName, nestedFileName, globalContext, parentParameters,
- nestedParameters, nestedParametersNames);
-
- checkNoMissingParameterInNested(parentFileName, nestedFileName, resourceName,
- resourceFileProperties, nestedParametersNames, globalContext);
- }
- public static void checkNestedInputValuesAlignWithType(String parentFileName,
- String nestedFileName,
- String resourceName, Resource resource,
- Optional<String> indexVarValue,
- GlobalValidationContext globalContext) {
- Map<String, Parameter> parentParameters = new HashMap<>();
- Map<String, Parameter> nestedParameters = new HashMap<>();
- Set<String> nestedParametersNames = new HashSet<>();
- checkNestedParameters(parentFileName, nestedFileName, globalContext, parentParameters,
- nestedParameters, nestedParametersNames);
+ private static HeatOrchestrationTemplate getHeatOrchestrationTemplate(String fileName, GlobalValidationContext globalContext) throws Exception {
+ Optional<InputStream> fileContent = globalContext.getFileContent(fileName);
+ if (fileContent.isPresent()) {
+ return new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
+ } else {
+ Exception exception = new Exception(String.format(NO_CONTENT_IN_FILE_MSG, fileName));
+ LOGGER.error("Error while reading file : " + fileName, exception);
+ throw exception;
+ }
+ }
- checkNestedInputValuesAlignWithType(parentFileName, nestedFileName,
- nestedParameters, resourceName, resource, indexVarValue, globalContext);
- }
+ public static void checkNestedParametersNoMissingParameterInNested(String parentFileName, String nestedFileName, String resourceName,
+ Set<String> resourceFileProperties, GlobalValidationContext globalContext) {
+ Map<String, Parameter> parentParameters = new HashMap<>();
+ Map<String, Parameter> nestedParameters = new HashMap<>();
+ Set<String> nestedParametersNames = new HashSet<>();
+ checkNestedParameters(parentFileName, nestedFileName, globalContext, parentParameters, nestedParameters, nestedParametersNames);
+ checkNoMissingParameterInNested(parentFileName, nestedFileName, resourceName, resourceFileProperties, nestedParametersNames, globalContext);
+ }
- private static void checkNoMissingParameterInNested(String parentFileName, String nestedFileName,
- String resourceName,
- Set<String> resourceFileProperties,
- Set<String> nestedParametersNames,
- GlobalValidationContext globalContext) {
- if (CollectionUtils.isNotEmpty(nestedParametersNames)) {
- resourceFileProperties
- .stream()
- .filter(propertyName -> !nestedParametersNames.contains(propertyName))
- .forEach(propertyName -> globalContext
- .addMessage(parentFileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- globalContext.getMessageCode(),
- Messages.MISSING_PARAMETER_IN_NESTED.getErrorMessage(),
- nestedFileName, resourceName, propertyName)));
+ public static void checkNestedInputValuesAlignWithType(String parentFileName, String nestedFileName, String resourceName, Resource resource,
+ Optional<String> indexVarValue, GlobalValidationContext globalContext) {
+ Map<String, Parameter> parentParameters = new HashMap<>();
+ Map<String, Parameter> nestedParameters = new HashMap<>();
+ Set<String> nestedParametersNames = new HashSet<>();
+ checkNestedParameters(parentFileName, nestedFileName, globalContext, parentParameters, nestedParameters, nestedParametersNames);
+ checkNestedInputValuesAlignWithType(parentFileName, nestedFileName, nestedParameters, resourceName, resource, indexVarValue, globalContext);
}
- }
- private static void checkNestedInputValuesAlignWithType(String parentFileName,
- String nestedFileName,
- Map<String, Parameter> nestedParameters,
- String resourceName, Resource resource,
- Optional<String> indexVarValue,
- GlobalValidationContext globalContext) {
- Map<String, Object> properties = resource.getProperties();
- for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
- String parameterName = propertyEntry.getKey();
- Object parameterInputValue = propertyEntry.getValue();
- if (parameterInputValue instanceof String) {
- if (indexVarValue.isPresent() && indexVarValue.get().equals(parameterInputValue)) {
- parameterInputValue = 3; //indexVarValue is actually number value in runtime
+ private static void checkNoMissingParameterInNested(String parentFileName, String nestedFileName, String resourceName,
+ Set<String> resourceFileProperties, Set<String> nestedParametersNames,
+ GlobalValidationContext globalContext) {
+ if (CollectionUtils.isNotEmpty(nestedParametersNames)) {
+ resourceFileProperties.stream().filter(propertyName -> !nestedParametersNames.contains(propertyName)).forEach(
+ propertyName -> globalContext.addMessage(parentFileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(globalContext.getMessageCode(), Messages.MISSING_PARAMETER_IN_NESTED.getErrorMessage(), nestedFileName,
+ resourceName, propertyName)));
}
- validateStaticValueForNestedInputParameter(parentFileName, nestedFileName, resourceName,
- parameterName, parameterInputValue, nestedParameters.get(parameterName),
- globalContext);
- }
}
- }
- private static void validateStaticValueForNestedInputParameter(String parentFileName,
- String nestedFileName,
- String resourceName,
- String parameterName,
- Object staticValue,
- Parameter parameterInNested,
- GlobalValidationContext
- globalContext) {
- if (parameterInNested == null) {
- return;
- }
- if (!DefinedHeatParameterTypes
- .isValueIsFromGivenType(staticValue, parameterInNested.getType())) {
- globalContext.addMessage(parentFileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(globalContext.getMessageCode(),
- Messages.WRONG_VALUE_TYPE_ASSIGNED_NESTED_INPUT.getErrorMessage(),
- resourceName, parameterName, nestedFileName));
+ private static void checkNestedInputValuesAlignWithType(String parentFileName, String nestedFileName, Map<String, Parameter> nestedParameters,
+ String resourceName, Resource resource, Optional<String> indexVarValue,
+ GlobalValidationContext globalContext) {
+ Map<String, Object> properties = resource.getProperties();
+ for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
+ String parameterName = propertyEntry.getKey();
+ Object parameterInputValue = propertyEntry.getValue();
+ if (parameterInputValue instanceof String) {
+ if (indexVarValue.isPresent() && indexVarValue.get().equals(parameterInputValue)) {
+ parameterInputValue = 3; //indexVarValue is actually number value in runtime
+ }
+ validateStaticValueForNestedInputParameter(parentFileName, nestedFileName, resourceName, parameterName, parameterInputValue,
+ nestedParameters.get(parameterName), globalContext);
+ }
+ }
}
- }
-
- /**
- * Is nested loop exist in file boolean.
- *
- * @param callingFileName the calling file name
- * @param nestedFileName the nested file name
- * @param filesInLoop the files in loop
- * @param globalContext the global context
- * @return the boolean
- */
- public static boolean isNestedLoopExistInFile(String callingFileName, String nestedFileName,
- List<String> filesInLoop,
- GlobalValidationContext globalContext) {
- HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
- try {
- nestedHeatOrchestrationTemplate = getNestedHeatOrchestrationTemplate(nestedFileName,
- globalContext);
- } catch (Exception exception) {
- LOGGER.error("Error while reading file : " + nestedFileName, exception);
- LOGGER.warn("HEAT Validator will not be executed on file " + nestedFileName
- + " due to illegal HEAT format");
- return false;
+ private static void validateStaticValueForNestedInputParameter(String parentFileName, String nestedFileName, String resourceName,
+ String parameterName, Object staticValue, Parameter parameterInNested,
+ GlobalValidationContext globalContext) {
+ if (parameterInNested == null) {
+ return;
+ }
+ if (!DefinedHeatParameterTypes.isValueIsFromGivenType(staticValue, parameterInNested.getType())) {
+ globalContext.addMessage(parentFileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(globalContext.getMessageCode(), Messages.WRONG_VALUE_TYPE_ASSIGNED_NESTED_INPUT.getErrorMessage(),
+ resourceName, parameterName, nestedFileName));
+ }
}
- filesInLoop.add(nestedFileName);
- Collection<Resource> nestedResources =
- nestedHeatOrchestrationTemplate.getResources() == null ? null
- : nestedHeatOrchestrationTemplate.getResources().values();
- return addNestedFilesInLoopAndCheckIfNestedLoopExist(nestedResources,
- callingFileName, filesInLoop, globalContext);
- }
- private static boolean addNestedFilesInLoopAndCheckIfNestedLoopExist(
- Collection<Resource> nestedResources,String callingFileName,
- List<String> filesInLoop,
- GlobalValidationContext globalContext){
- if (CollectionUtils.isNotEmpty(nestedResources)) {
- for (Resource resource : nestedResources) {
- String resourceType = resource.getType();
- if (Objects.nonNull(resourceType) && isNestedResource(resourceType)) {
- return resourceType.equals(callingFileName) || !filesInLoop.contains(resourceType)
- && isNestedLoopExistInFile(callingFileName, resourceType, filesInLoop, globalContext);
+ /**
+ * Is nested loop exist in file boolean.
+ *
+ * @param callingFileName the calling file name
+ * @param nestedFileName the nested file name
+ * @param filesInLoop the files in loop
+ * @param globalContext the global context
+ * @return the boolean
+ */
+ public static boolean isNestedLoopExistInFile(String callingFileName, String nestedFileName, List<String> filesInLoop,
+ GlobalValidationContext globalContext) {
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
+ try {
+ nestedHeatOrchestrationTemplate = getNestedHeatOrchestrationTemplate(nestedFileName, globalContext);
+ } catch (Exception exception) {
+ LOGGER.error("Error while reading file : " + nestedFileName, exception);
+ LOGGER.warn("HEAT Validator will not be executed on file " + nestedFileName + " due to illegal HEAT format");
+ return false;
}
- }
+ filesInLoop.add(nestedFileName);
+ Collection<Resource> nestedResources =
+ nestedHeatOrchestrationTemplate.getResources() == null ? null : nestedHeatOrchestrationTemplate.getResources().values();
+ return addNestedFilesInLoopAndCheckIfNestedLoopExist(nestedResources, callingFileName, filesInLoop, globalContext);
}
- return false;
- }
-
-
-
- private static HeatOrchestrationTemplate getNestedHeatOrchestrationTemplate( String nestedFileName,
- GlobalValidationContext globalContext) throws Exception {
- Optional<InputStream> fileContent = globalContext.getFileContent(nestedFileName);
- HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
- if (fileContent.isPresent()) {
- nestedHeatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- throw new Exception(String.format(NO_CONTENT_IN_FILE_MSG, nestedFileName));
+ private static boolean addNestedFilesInLoopAndCheckIfNestedLoopExist(Collection<Resource> nestedResources, String callingFileName,
+ List<String> filesInLoop, GlobalValidationContext globalContext) {
+ if (CollectionUtils.isNotEmpty(nestedResources)) {
+ for (Resource resource : nestedResources) {
+ String resourceType = resource.getType();
+ if (Objects.nonNull(resourceType) && isNestedResource(resourceType)) {
+ return resourceType.equals(callingFileName) || !filesInLoop.contains(resourceType) && isNestedLoopExistInFile(callingFileName,
+ resourceType, filesInLoop, globalContext);
+ }
+ }
+ }
+ return false;
}
- return nestedHeatOrchestrationTemplate;
- }
-
- public static boolean isNestedResource(String resourceType) {
- return resourceType.contains(".yaml") || resourceType.contains(".yml");
- }
-
- /**
- * Validate env content environment.
- *
- * @param fileName the file name
- * @param envFileName the env file name
- * @param globalContext the global context
- * @return the environment
- */
- public static Environment validateEnvContent(String fileName, String envFileName,
- GlobalValidationContext globalContext) {
- Environment envContent;
- try {
- Optional<InputStream> fileContent = globalContext.getFileContent(envFileName);
- if (fileContent.isPresent()) {
- envContent = new YamlUtil().yamlToObject(fileContent.get(), Environment.class);
- } else {
- throw new Exception(String.format(NO_CONTENT_IN_FILE_MSG, envFileName));
- }
- } catch (Exception exception) {
- LOGGER.error("Error while reading env file : " + envFileName, exception);
- return null;
+ private static HeatOrchestrationTemplate getNestedHeatOrchestrationTemplate(String nestedFileName, GlobalValidationContext globalContext)
+ throws Exception {
+ Optional<InputStream> fileContent = globalContext.getFileContent(nestedFileName);
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
+ if (fileContent.isPresent()) {
+ nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
+ } else {
+ throw new Exception(String.format(NO_CONTENT_IN_FILE_MSG, nestedFileName));
+ }
+ return nestedHeatOrchestrationTemplate;
}
- return envContent;
- }
- /**
- * This method verifies whether the propertyValue contains a single parent port
- * @param fileName on which the validation is currently run
- * @param globalContext global validation context
- * @param heatResourceValidationContext heat resource validation context
- * @param propertyValue the value which is examined
- * @return whether the vlan has single parent port
- */
- public static boolean hasSingleParentPort(String fileName, GlobalValidationContext globalContext,
- HeatResourceValidationContext heatResourceValidationContext,
- Object propertyValue) {
- final boolean isList = propertyValue instanceof List;
- if (!isList || ((List) propertyValue).size() != 1) {
- return false;
+ public static boolean isNestedResource(String resourceType) {
+ return resourceType.contains(".yaml") || resourceType.contains(".yml");
}
- final Object listValue = ((List) propertyValue).get(0);
-
- final Set<String> getParamValues =
- HeatStructureUtil.getReferencedValuesByFunctionName(fileName, "get_param",
- listValue, globalContext);
+ /**
+ * Validate env content environment.
+ *
+ * @param fileName the file name
+ * @param envFileName the env file name
+ * @param globalContext the global context
+ * @return the environment
+ */
+ public static Environment validateEnvContent(String fileName, String envFileName, GlobalValidationContext globalContext) {
+ Environment envContent;
+ try {
+ Optional<InputStream> fileContent = globalContext.getFileContent(envFileName);
+ if (fileContent.isPresent()) {
+ envContent = new YamlUtil().yamlToObject(fileContent.get(), Environment.class);
+ } else {
+ throw new Exception(String.format(NO_CONTENT_IN_FILE_MSG, envFileName));
+ }
+ } catch (Exception exception) {
+ LOGGER.error("Error while reading env file : " + envFileName, exception);
+ return null;
+ }
+ return envContent;
+ }
- return getParamValues.isEmpty() || (getParamValues.size() == 1) &&
- validateGetParamValueOfType(getParamValues, heatResourceValidationContext,
+ /**
+ * This method verifies whether the propertyValue contains a single parent port
+ *
+ * @param fileName on which the validation is currently run
+ * @param globalContext global validation context
+ * @param heatResourceValidationContext heat resource validation context
+ * @param propertyValue the value which is examined
+ * @return whether the vlan has single parent port
+ */
+ public static boolean hasSingleParentPort(String fileName, GlobalValidationContext globalContext,
+ HeatResourceValidationContext heatResourceValidationContext, Object propertyValue) {
+ final boolean isList = propertyValue instanceof List;
+ if (!isList || ((List) propertyValue).size() != 1) {
+ return false;
+ }
+ final Object listValue = ((List) propertyValue).get(0);
+ final Set<String> getParamValues = HeatStructureUtil.getReferencedValuesByFunctionName(fileName, "get_param", listValue, globalContext);
+ return getParamValues.isEmpty() || (getParamValues.size() == 1) && validateGetParamValueOfType(getParamValues, heatResourceValidationContext,
DefinedHeatParameterTypes.STRING.getType());
+ }
- }
-
-
- private static boolean validateGetParamValueOfType(Set<String> values,
- HeatResourceValidationContext
- heatResourceValidationContext, String type) {
-
- return values.stream().anyMatch(e -> Objects.equals(
- heatResourceValidationContext.getHeatOrchestrationTemplate().getParameters().get(e).getType(), type));
- }
-
+ private static boolean validateGetParamValueOfType(Set<String> values, HeatResourceValidationContext heatResourceValidationContext, String type) {
+ return values.stream()
+ .anyMatch(e -> Objects.equals(heatResourceValidationContext.getHeatOrchestrationTemplate().getParameters().get(e).getType(), type));
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/YamlValidatorUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/YamlValidatorUtil.java
index bd049b2dfb..9c33c1b97f 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/YamlValidatorUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/YamlValidatorUtil.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.util;
import org.openecomp.sdc.common.errors.Messages;
@@ -21,29 +20,25 @@ import org.yaml.snakeyaml.error.MarkedYAMLException;
import org.yaml.snakeyaml.parser.ParserException;
public class YamlValidatorUtil {
- private YamlValidatorUtil() {
-
- }
-
- public static String getParserExceptionReason(Exception exception) {
- String reason = null;
+ private YamlValidatorUtil() {
+ }
- if (exception.getCause() instanceof MarkedYAMLException) {
- if (exception.getCause() != null) {
- if (exception.getCause().getCause() instanceof ParserException) {
- reason = exception.getCause().getCause().getMessage();
+ public static String getParserExceptionReason(Exception exception) {
+ String reason = null;
+ if (exception.getCause() instanceof MarkedYAMLException) {
+ if (exception.getCause() != null) {
+ if (exception.getCause().getCause() instanceof ParserException) {
+ reason = exception.getCause().getCause().getMessage();
+ } else {
+ reason = exception.getCause().getMessage();
+ }
+ }
+ } else if (exception instanceof MarkedYAMLException) {
+ reason = exception.getMessage();
} else {
- reason = exception.getCause().getMessage();
+ reason = Messages.GENERAL_YAML_PARSER_ERROR.getErrorMessage();
}
- }
- } else if (exception instanceof MarkedYAMLException) {
-
- reason = exception.getMessage();
-
- } else {
- reason = Messages.GENERAL_YAML_PARSER_ERROR.getErrorMessage();
+ return reason;
}
- return reason;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java
index 3feeea8c7b..895c5ee56e 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java
@@ -12,10 +12,13 @@
* 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.validation.impl.validators;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.validation.ErrorMessageCode;
@@ -35,135 +38,104 @@ import org.openecomp.sdc.validation.Validator;
import org.openecomp.sdc.validation.tos.ContrailResourcesMappingTo;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
-
public class ContrailValidator implements Validator {
- private static final Logger LOGGER = LoggerFactory.getLogger(ContrailValidator.class);
- private static final ErrorMessageCode ERROR_CODE_CTL_1 = new ErrorMessageCode("CTL1");
- private static final ErrorMessageCode ERROR_CODE_CTL_2 = new ErrorMessageCode("CTL2");
- private static final ErrorMessageCode ERROR_CODE_CTL_3 = new ErrorMessageCode("CTL3");
- private static final ErrorMessageCode ERROR_CODE_CTL_4 = new ErrorMessageCode("CTL4");
- @Override
- public void validate(GlobalValidationContext globalContext) {
- ManifestContent manifestContent;
- try {
- manifestContent = ValidationUtil.validateManifest(globalContext);
- } catch (Exception exception) {
- LOGGER.error("Failed to validate manifest file", exception);
- return;
+ private static final Logger LOGGER = LoggerFactory.getLogger(ContrailValidator.class);
+ private static final ErrorMessageCode ERROR_CODE_CTL_1 = new ErrorMessageCode("CTL1");
+ private static final ErrorMessageCode ERROR_CODE_CTL_2 = new ErrorMessageCode("CTL2");
+ private static final ErrorMessageCode ERROR_CODE_CTL_3 = new ErrorMessageCode("CTL3");
+ private static final ErrorMessageCode ERROR_CODE_CTL_4 = new ErrorMessageCode("CTL4");
+
+ @Override
+ public void validate(GlobalValidationContext globalContext) {
+ ManifestContent manifestContent;
+ try {
+ manifestContent = ValidationUtil.validateManifest(globalContext);
+ } catch (Exception exception) {
+ LOGGER.error("Failed to validate manifest file", exception);
+ return;
+ }
+ Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
+ ContrailResourcesMappingTo contrailResourcesMappingTo = new ContrailResourcesMappingTo();
+ globalContext.getFiles().stream().filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName)))
+ .forEach(fileName -> validate(fileName, contrailResourcesMappingTo, globalContext));
}
- Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
- ContrailResourcesMappingTo contrailResourcesMappingTo = new ContrailResourcesMappingTo();
-
- globalContext.getFiles().stream()
- .filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName)))
- .forEach(fileName -> validate(fileName,
- contrailResourcesMappingTo, globalContext));
- }
-
- private void validate(String fileName,
- ContrailResourcesMappingTo contrailResourcesMappingTo,
- GlobalValidationContext globalContext) {
- handleContrailV1AndContrailV2ResourceMerging(fileName, contrailResourcesMappingTo,
- globalContext);
- validateNoContrailResourceTypeIsInUse(fileName, globalContext);
- }
-
-
- private void handleContrailV1AndContrailV2ResourceMerging(String fileName,
- ContrailResourcesMappingTo contrailResourcesMappingTo,
- GlobalValidationContext globalContext) {
- Optional<ContrailResourcesMappingTo> fileContrailResourcesMappingTo =
- collectHeatFileContrailResources(globalContext, fileName);
- fileContrailResourcesMappingTo.ifPresent(contrailResourcesMappingTo::addAll);
- addContrailMergeValidationMessageToGlobalContext(globalContext, contrailResourcesMappingTo);
- }
-
- private void addContrailMergeValidationMessageToGlobalContext(
- GlobalValidationContext globalContext,
- ContrailResourcesMappingTo contrailResourcesMappingTo) {
- if (!MapUtils.isEmpty(contrailResourcesMappingTo.getContrailV1Resources())
- && !MapUtils.isEmpty(contrailResourcesMappingTo.getContrailV2Resources())) {
- globalContext.addMessage(
- contrailResourcesMappingTo.getContrailV1Resources().keySet().iterator().next(),
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_CTL_2, Messages.MERGE_OF_CONTRAIL2_AND_CONTRAIL3_RESOURCES.getErrorMessage(),
- contrailResourcesMappingTo.fetchContrailV1Resources(),
- contrailResourcesMappingTo.fetchContrailV2Resources()));
+ private void validate(String fileName, ContrailResourcesMappingTo contrailResourcesMappingTo, GlobalValidationContext globalContext) {
+ handleContrailV1AndContrailV2ResourceMerging(fileName, contrailResourcesMappingTo, globalContext);
+ validateNoContrailResourceTypeIsInUse(fileName, globalContext);
}
- }
- private Optional<ContrailResourcesMappingTo> collectHeatFileContrailResources(
- GlobalValidationContext globalContext, String fileName) {
- Optional<InputStream> fileContent = globalContext.getFileContent(fileName);
- if (!fileContent.isPresent()) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_CTL_1, Messages.INVALID_HEAT_FORMAT_REASON
- .getErrorMessage(),
- "The file '" + fileName + "' has no content"));
- return Optional.empty();
+ private void handleContrailV1AndContrailV2ResourceMerging(String fileName, ContrailResourcesMappingTo contrailResourcesMappingTo,
+ GlobalValidationContext globalContext) {
+ Optional<ContrailResourcesMappingTo> fileContrailResourcesMappingTo = collectHeatFileContrailResources(globalContext, fileName);
+ fileContrailResourcesMappingTo.ifPresent(contrailResourcesMappingTo::addAll);
+ addContrailMergeValidationMessageToGlobalContext(globalContext, contrailResourcesMappingTo);
}
- return fetchContrailResourcesMapping(fileName, fileContent.get());
- }
- private Optional<ContrailResourcesMappingTo> fetchContrailResourcesMapping(String fileName,
- InputStream fileContent ) {
- ContrailResourcesMappingTo contrailResourcesMappingTo = new ContrailResourcesMappingTo();
- HeatOrchestrationTemplate heatOrchestrationTemplate;
- try {
- heatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent, HeatOrchestrationTemplate.class);
- } catch (Exception ignored) {
- LOGGER.error("Invalid file content : " + fileContent, ignored);
- // the HeatValidator should handle file that is failing to parse
- return Optional.empty();
- }
- if( !MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
- heatOrchestrationTemplate.getResources().entrySet()
- .forEach(entry -> {
- if (entry.getValue().getType().startsWith(HeatConstants.CONTRAIL_RESOURCE_PREFIX)) {
- contrailResourcesMappingTo.addContrailV1Resource(fileName, entry.getKey());
- } else if (entry.getValue().getType()
- .startsWith(HeatConstants.CONTRAIL_V2_RESOURCE_PREFIX)) {
- contrailResourcesMappingTo.addContrailV2Resource(fileName, entry.getKey());
- }
- });
+ private void addContrailMergeValidationMessageToGlobalContext(GlobalValidationContext globalContext,
+ ContrailResourcesMappingTo contrailResourcesMappingTo) {
+ if (!MapUtils.isEmpty(contrailResourcesMappingTo.getContrailV1Resources()) && !MapUtils
+ .isEmpty(contrailResourcesMappingTo.getContrailV2Resources())) {
+ globalContext.addMessage(contrailResourcesMappingTo.getContrailV1Resources().keySet().iterator().next(), ErrorLevel.WARNING,
+ ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_CTL_2, Messages.MERGE_OF_CONTRAIL2_AND_CONTRAIL3_RESOURCES.getErrorMessage(),
+ contrailResourcesMappingTo.fetchContrailV1Resources(), contrailResourcesMappingTo.fetchContrailV2Resources()));
+ }
}
- return Optional.of(contrailResourcesMappingTo);
- }
-
- private void validateNoContrailResourceTypeIsInUse(String fileName,
- GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_CTL_4);
- HeatOrchestrationTemplate heatOrchestrationTemplate =
- ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ private Optional<ContrailResourcesMappingTo> collectHeatFileContrailResources(GlobalValidationContext globalContext, String fileName) {
+ Optional<InputStream> fileContent = globalContext.getFileContent(fileName);
+ if (!fileContent.isPresent()) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_CTL_1, Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
+ "The file '" + fileName + "' has no content"));
+ return Optional.empty();
+ }
+ return fetchContrailResourcesMapping(fileName, fileContent.get());
+ }
- if (heatOrchestrationTemplate == null) {
- return;
+ private Optional<ContrailResourcesMappingTo> fetchContrailResourcesMapping(String fileName, InputStream fileContent) {
+ ContrailResourcesMappingTo contrailResourcesMappingTo = new ContrailResourcesMappingTo();
+ HeatOrchestrationTemplate heatOrchestrationTemplate;
+ try {
+ heatOrchestrationTemplate = new YamlUtil().yamlToObject(fileContent, HeatOrchestrationTemplate.class);
+ } catch (Exception ignored) {
+ LOGGER.error("Invalid file content : " + fileContent, ignored);
+ // the HeatValidator should handle file that is failing to parse
+ return Optional.empty();
+ }
+ if (!MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
+ heatOrchestrationTemplate.getResources().entrySet().forEach(entry -> {
+ if (entry.getValue().getType().startsWith(HeatConstants.CONTRAIL_RESOURCE_PREFIX)) {
+ contrailResourcesMappingTo.addContrailV1Resource(fileName, entry.getKey());
+ } else if (entry.getValue().getType().startsWith(HeatConstants.CONTRAIL_V2_RESOURCE_PREFIX)) {
+ contrailResourcesMappingTo.addContrailV2Resource(fileName, entry.getKey());
+ }
+ });
+ }
+ return Optional.of(contrailResourcesMappingTo);
}
- validateResourcePrefix(fileName, globalContext, heatOrchestrationTemplate);
- }
- private void validateResourcePrefix(String fileName, GlobalValidationContext globalContext,
- HeatOrchestrationTemplate heatOrchestrationTemplate) {
- Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
- if(!MapUtils.isEmpty(resourcesMap)) {
- for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
- String type = resourceEntry.getValue().getType();
- if (Objects.nonNull(type) && type.startsWith(HeatConstants.CONTRAIL_RESOURCE_PREFIX)) {
- globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_CTL_3, Messages.CONTRAIL_2_IN_USE.getErrorMessage(),
- resourceEntry.getKey()));
+ private void validateNoContrailResourceTypeIsInUse(String fileName, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_CTL_4);
+ HeatOrchestrationTemplate heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ if (heatOrchestrationTemplate == null) {
+ return;
}
- }
+ validateResourcePrefix(fileName, globalContext, heatOrchestrationTemplate);
}
- }
+ private void validateResourcePrefix(String fileName, GlobalValidationContext globalContext, HeatOrchestrationTemplate heatOrchestrationTemplate) {
+ Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
+ if (!MapUtils.isEmpty(resourcesMap)) {
+ for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
+ String type = resourceEntry.getValue().getType();
+ if (Objects.nonNull(type) && type.startsWith(HeatConstants.CONTRAIL_RESOURCE_PREFIX)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_CTL_3, Messages.CONTRAIL_2_IN_USE.getErrorMessage(), resourceEntry.getKey()));
+ }
+ }
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/FileExtensionUtils.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/FileExtensionUtils.java
index c4215c9783..9915f91acf 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/FileExtensionUtils.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/FileExtensionUtils.java
@@ -23,16 +23,10 @@ import java.util.Set;
class FileExtensionUtils {
- private static final Set<String> VALID_YAML_EXTENSIONS = Set.of(
- ".yaml",
- ".yml",
- ".env"
- );
+ private static final Set<String> VALID_YAML_EXTENSIONS = Set.of(".yaml", ".yml", ".env");
static boolean isYaml(String fileName) {
String fileNameLower = fileName.toLowerCase();
- return FileExtensionUtils.VALID_YAML_EXTENSIONS.stream()
- .anyMatch(fileNameLower::endsWith);
+ return FileExtensionUtils.VALID_YAML_EXTENSIONS.stream().anyMatch(fileNameLower::endsWith);
}
-
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java
index 5ce9aa7aa5..9c8c10a7fe 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java
@@ -12,10 +12,13 @@
* 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.validation.impl.validators;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -32,103 +35,76 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.validation.Validator;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
public class ForbiddenResourceGuideLineValidator implements Validator {
- private static Set<String> forbiddenResources = new HashSet<>();
- private static final ErrorMessageCode ERROR_CODE_FRG_1 = new ErrorMessageCode("FRG1");
- private static final ErrorMessageCode ERROR_CODE_FRG_2 = new ErrorMessageCode("FRG2");
- private static final ErrorMessageCode ERROR_CODE_FRG_3 = new ErrorMessageCode("FRG3");
-
- private static final Logger LOGGER = LoggerFactory
- .getLogger(ForbiddenResourceGuideLineValidator.class);
-
- @Override
- public void init(Map<String, Object> properties) {
- Map<String, Map<String, Object>> forbiddenResourcesMap =
- (Map<String, Map<String, Object>>) properties.get("forbiddenResourceTypes");
-
- forbiddenResourcesMap.entrySet().stream()
- .filter(entry -> isResourceEnabled(entry.getValue().get("enable")))
- .forEach(entry -> forbiddenResources.add(entry.getKey()));
- }
- private boolean isResourceEnabled(Object enableValue) {
- if (Objects.isNull(enableValue)) {
- return true;
+ private static final ErrorMessageCode ERROR_CODE_FRG_1 = new ErrorMessageCode("FRG1");
+ private static final ErrorMessageCode ERROR_CODE_FRG_2 = new ErrorMessageCode("FRG2");
+ private static final ErrorMessageCode ERROR_CODE_FRG_3 = new ErrorMessageCode("FRG3");
+ private static final Logger LOGGER = LoggerFactory.getLogger(ForbiddenResourceGuideLineValidator.class);
+ private static Set<String> forbiddenResources = new HashSet<>();
+
+ @Override
+ public void init(Map<String, Object> properties) {
+ Map<String, Map<String, Object>> forbiddenResourcesMap = (Map<String, Map<String, Object>>) properties.get("forbiddenResourceTypes");
+ forbiddenResourcesMap.entrySet().stream().filter(entry -> isResourceEnabled(entry.getValue().get("enable")))
+ .forEach(entry -> forbiddenResources.add(entry.getKey()));
}
- if (enableValue instanceof Boolean) {
- return (Boolean)enableValue;
- }
-
- return Boolean.valueOf((String) enableValue);
- }
-
-
- @Override
- public void validate(GlobalValidationContext globalContext) {
- ManifestContent manifestContent;
- try {
- manifestContent = ValidationUtil.validateManifest(globalContext);
- } catch (Exception exception) {
- LOGGER.error("Failed to validate manifest file", exception);
- return;
+ private boolean isResourceEnabled(Object enableValue) {
+ if (Objects.isNull(enableValue)) {
+ return true;
+ }
+ if (enableValue instanceof Boolean) {
+ return (Boolean) enableValue;
+ }
+ return Boolean.valueOf((String) enableValue);
}
- Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
-
- globalContext.getFiles().stream()
- .filter(fileName -> FileData
- .isHeatFile(fileTypeMap.get(fileName)))
- .forEach(fileName -> validate(fileName, globalContext));
- }
-
- private void validate(String fileName, GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_FRG_3);
- HeatOrchestrationTemplate
- heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(
- fileName, globalContext);
- if (heatOrchestrationTemplate == null) {
- return;
+ @Override
+ public void validate(GlobalValidationContext globalContext) {
+ ManifestContent manifestContent;
+ try {
+ manifestContent = ValidationUtil.validateManifest(globalContext);
+ } catch (Exception exception) {
+ LOGGER.error("Failed to validate manifest file", exception);
+ return;
+ }
+ Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
+ globalContext.getFiles().stream().filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName)))
+ .forEach(fileName -> validate(fileName, globalContext));
}
- validateResourceTypeIsForbidden(fileName, heatOrchestrationTemplate, globalContext);
- }
-
- private void validateResourceTypeIsForbidden(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
- if (MapUtils.isEmpty(resourcesMap)) {
- return;
+ private void validate(String fileName, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_FRG_3);
+ HeatOrchestrationTemplate heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ if (heatOrchestrationTemplate == null) {
+ return;
+ }
+ validateResourceTypeIsForbidden(fileName, heatOrchestrationTemplate, globalContext);
}
- for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
- String resourceType = resourceEntry.getValue().getType();
- if (Objects.isNull(resourceType)) {
- globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_FRG_1,
- Messages.INVALID_RESOURCE_TYPE.getErrorMessage(),"null",
- resourceEntry.getKey()));
- } else {
- if (isResourceForbidden(resourceType)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_FRG_2, Messages.FORBIDDEN_RESOURCE_IN_USE
- .getErrorMessage(),
- resourceType, resourceEntry.getKey()));
+ private void validateResourceTypeIsForbidden(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
+ if (MapUtils.isEmpty(resourcesMap)) {
+ return;
+ }
+ for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
+ String resourceType = resourceEntry.getValue().getType();
+ if (Objects.isNull(resourceType)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_FRG_1, Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", resourceEntry.getKey()));
+ } else {
+ if (isResourceForbidden(resourceType)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_FRG_2, Messages.FORBIDDEN_RESOURCE_IN_USE.getErrorMessage(), resourceType,
+ resourceEntry.getKey()));
+ }
+ }
}
- }
}
- }
- private boolean isResourceForbidden(String resourceType) {
- return forbiddenResources.contains(resourceType);
- }
+ private boolean isResourceForbidden(String resourceType) {
+ return forbiddenResources.contains(resourceType);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtil.java
index 4467bd1311..0e199cc472 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtil.java
@@ -17,43 +17,37 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.validation.impl.validators;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.heat.datatypes.manifest.FileData;
import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
import org.openecomp.sdc.heat.services.manifest.ManifestUtil;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
class GlobalContextUtil {
- private GlobalContextUtil() {}
+ private GlobalContextUtil() {
+ }
static Set<String> findPmDictionaryFiles(GlobalValidationContext globalContext) {
if (isManifestMissing(globalContext)) {
return Set.of();
}
-
Map<String, FileData.Type> filesWithTypes = readAllFilesWithTypes(globalContext);
return filterPmDictionaryFiles(filesWithTypes);
}
private static boolean isManifestMissing(GlobalValidationContext globalContext) {
- return globalContext.getFileContent("MANIFEST.json")
- .isEmpty();
+ return globalContext.getFileContent("MANIFEST.json").isEmpty();
}
private static Set<String> filterPmDictionaryFiles(Map<String, FileData.Type> filesWithTypes) {
- return filesWithTypes.entrySet().stream()
- .filter(isPmDictionaryType())
- .map(Map.Entry::getKey)
- .collect(Collectors.toSet());
+ return filesWithTypes.entrySet().stream().filter(isPmDictionaryType()).map(Map.Entry::getKey).collect(Collectors.toSet());
}
private static Map<String, FileData.Type> readAllFilesWithTypes(GlobalValidationContext globalContext) {
@@ -62,7 +56,6 @@ class GlobalContextUtil {
}
private static Predicate<Map.Entry<String, FileData.Type>> isPmDictionaryType() {
- return entry -> entry.getValue()
- .equals(FileData.Type.PM_DICTIONARY);
+ return entry -> entry.getValue().equals(FileData.Type.PM_DICTIONARY);
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java
index e445477498..abdb65670e 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators;
import java.util.ArrayList;
@@ -24,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Output;
@@ -39,210 +37,147 @@ import org.openecomp.sdc.validation.type.ConfigConstants;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
public class HeatResourceValidator extends ResourceBaseValidator {
- private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBaseValidator.class);
- private static final String GET_ATTR = "get_attr";
-
- @Override
- public void init(Map<String, Object> properties) {
- super.init((Map<String, Object>) properties.get(ConfigConstants.Resource_Base_Validator));
- }
-
- @Override
- public ValidationContext createValidationContext(String fileName,
- String envFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Map<String, Resource> resourcesMap =
- heatOrchestrationTemplate.getResources() == null ? new HashMap<>()
- : heatOrchestrationTemplate.getResources();
-
- Map<String, Output> outputMap = heatOrchestrationTemplate.getOutputs() == null ? new HashMap<>()
- : heatOrchestrationTemplate.getOutputs();
-
- Map<String, Map<String, Map<String, List<String>>>>
- typeToPointingResourcesMap = new HashMap<>();
-
- initTypeRelationsMap (fileName, resourcesMap, outputMap,
- typeToPointingResourcesMap, globalContext);
-
- return new HeatResourceValidationContext (heatOrchestrationTemplate, typeToPointingResourcesMap,
- envFileName );
- }
-
- private void initTypeRelationsMap (String fileName,
- Map<String, Resource> resourceMap,
- Map<String, Output> outputMap,
- Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap,
- GlobalValidationContext globalContext ) {
- initTypeRelationsMapFromResourcesMap (fileName, resourceMap,
- typeToPointingResourcesMap, globalContext);
-
- initTypeRelationsMapFromOutputsMap (fileName, resourceMap, outputMap,
- typeToPointingResourcesMap, globalContext);
- }
-
- private void initTypeRelationsMapFromOutputsMap (String fileName,
- Map<String, Resource> resourceMap,
- Map<String, Output> outputMap,
- Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap,
- GlobalValidationContext globalContext ) {
- for (Map.Entry<String, Output> outputEntry : outputMap.entrySet()) {
- Object outputValue = outputEntry.getValue().getValue();
- Set<String> referencedResources = HeatStructureUtil
- .getReferencedValuesByFunctionName(fileName,
- ResourceReferenceFunctions.GET_RESOURCE.getFunction(), outputValue, globalContext);
-
- updateRelationsMapWithOutputsReferences (outputEntry, resourceMap, referencedResources, typeToPointingResourcesMap);
- }
- }
- private void updateRelationsMapWithOutputsReferences (Map.Entry<String, Output> outputEntry,
- Map<String, Resource> resourceMap,
- Set<String> referencedResources,
- Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap ) {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBaseValidator.class);
+ private static final String GET_ATTR = "get_attr";
- for (String pointedResourceName : referencedResources) {
- Resource pointedResource = resourceMap.get(pointedResourceName);
+ @Override
+ public void init(Map<String, Object> properties) {
+ super.init((Map<String, Object>) properties.get(ConfigConstants.Resource_Base_Validator));
+ }
- if (Objects.nonNull(pointedResource)) {
- initCurrentResourceTypeInMap(pointedResourceName, pointedResource.getType(),
- "output", typeToPointingResourcesMap);
+ @Override
+ public ValidationContext createValidationContext(String fileName, String envFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Map<String, Resource> resourcesMap =
+ heatOrchestrationTemplate.getResources() == null ? new HashMap<>() : heatOrchestrationTemplate.getResources();
+ Map<String, Output> outputMap = heatOrchestrationTemplate.getOutputs() == null ? new HashMap<>() : heatOrchestrationTemplate.getOutputs();
+ Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap = new HashMap<>();
+ initTypeRelationsMap(fileName, resourcesMap, outputMap, typeToPointingResourcesMap, globalContext);
+ return new HeatResourceValidationContext(heatOrchestrationTemplate, typeToPointingResourcesMap, envFileName);
+ }
- typeToPointingResourcesMap
- .get(pointedResource.getType()).get(pointedResourceName)
- .get("output").add(outputEntry.getKey());
- }
+ private void initTypeRelationsMap(String fileName, Map<String, Resource> resourceMap, Map<String, Output> outputMap,
+ Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap,
+ GlobalValidationContext globalContext) {
+ initTypeRelationsMapFromResourcesMap(fileName, resourceMap, typeToPointingResourcesMap, globalContext);
+ initTypeRelationsMapFromOutputsMap(fileName, resourceMap, outputMap, typeToPointingResourcesMap, globalContext);
}
- }
- private void initTypeRelationsMapFromResourcesMap(String fileName,
- Map<String, Resource> resourceMap,
+ private void initTypeRelationsMapFromOutputsMap(String fileName, Map<String, Resource> resourceMap, Map<String, Output> outputMap,
Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap,
GlobalValidationContext globalContext) {
- for (Map.Entry<String, Resource> resourceEntry : resourceMap.entrySet()) {
- Resource pointingResource = resourceEntry.getValue();
- Map<String, Object> properties =
- pointingResource.getProperties() == null ? new HashMap<>()
- : pointingResource.getProperties();
-
- Set<String> referencedResourcesByGetResource =
- getResourcesIdsPointedByCurrentResource(fileName, ResourceReferenceFunctions.GET_RESOURCE,
- properties, globalContext);
-
- Set<String> referencedResourcesByGetAttr =
- handleGetAttrBetweenResources(properties);
-
- referencedResourcesByGetResource.addAll(referencedResourcesByGetAttr);
-
- updateRelationsMapWithCurrentResourceReferences
- (resourceMap, resourceEntry, referencedResourcesByGetResource, typeToPointingResourcesMap);
+ for (Map.Entry<String, Output> outputEntry : outputMap.entrySet()) {
+ Object outputValue = outputEntry.getValue().getValue();
+ Set<String> referencedResources = HeatStructureUtil
+ .getReferencedValuesByFunctionName(fileName, ResourceReferenceFunctions.GET_RESOURCE.getFunction(), outputValue, globalContext);
+ updateRelationsMapWithOutputsReferences(outputEntry, resourceMap, referencedResources, typeToPointingResourcesMap);
+ }
}
- }
-
- private void updateRelationsMapWithCurrentResourceReferences(Map<String, Resource> resourceMap,
- Map.Entry<String, Resource> currentResourceEntry,
- Set<String> referencedResourcesFromCurrentResource,
- Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap) {
-
- for (String pointedResourceName : referencedResourcesFromCurrentResource) {
- Resource pointedResource = resourceMap.get(pointedResourceName);
- if (Objects.nonNull(pointedResource)) {
- String pointedResourceType = pointedResource.getType();
- updateMapWithRelationsBetweenResources (pointedResourceName, pointedResourceType,
- currentResourceEntry, typeToPointingResourcesMap);
- }
+ private void updateRelationsMapWithOutputsReferences(Map.Entry<String, Output> outputEntry, Map<String, Resource> resourceMap,
+ Set<String> referencedResources,
+ Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap) {
+ for (String pointedResourceName : referencedResources) {
+ Resource pointedResource = resourceMap.get(pointedResourceName);
+ if (Objects.nonNull(pointedResource)) {
+ initCurrentResourceTypeInMap(pointedResourceName, pointedResource.getType(), "output", typeToPointingResourcesMap);
+ typeToPointingResourcesMap.get(pointedResource.getType()).get(pointedResourceName).get("output").add(outputEntry.getKey());
+ }
+ }
}
- }
-
- private void updateMapWithRelationsBetweenResources(String pointedResourceName,
- String pointedResourceType,
- Map.Entry<String, Resource> currentResourceEntry,
- Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap) {
-
- initCurrentResourceTypeInMap(pointedResourceName, pointedResourceType,
- currentResourceEntry.getValue().getType(), typeToPointingResourcesMap);
-
- typeToPointingResourcesMap.get(pointedResourceType).get(pointedResourceName)
- .get(currentResourceEntry.getValue().getType()).add(currentResourceEntry.getKey());
- }
-
- private void initCurrentResourceTypeInMap(String resourceName, String resourceType,
- String pointingResourceType,
- Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap) {
-
- typeToPointingResourcesMap.putIfAbsent(resourceType, new HashMap<>());
- typeToPointingResourcesMap.get(resourceType).putIfAbsent(resourceName, new HashMap<>());
- typeToPointingResourcesMap.get(resourceType).get(resourceName)
- .putIfAbsent (pointingResourceType, new ArrayList<>());
- }
-
- private Set<String> handleGetAttrBetweenResources (Map<String, Object> properties) {
- Set<String> referencedResourcesByGetAttr = new HashSet<>();
- for (Map.Entry<String, Object> proprtyEntry : properties.entrySet()) {
- referencedResourcesByGetAttr.addAll(getGetAttrReferencesInCaseOfContrail(proprtyEntry
- .getValue()));
+
+ private void initTypeRelationsMapFromResourcesMap(String fileName, Map<String, Resource> resourceMap,
+ Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap,
+ GlobalValidationContext globalContext) {
+ for (Map.Entry<String, Resource> resourceEntry : resourceMap.entrySet()) {
+ Resource pointingResource = resourceEntry.getValue();
+ Map<String, Object> properties = pointingResource.getProperties() == null ? new HashMap<>() : pointingResource.getProperties();
+ Set<String> referencedResourcesByGetResource = getResourcesIdsPointedByCurrentResource(fileName, ResourceReferenceFunctions.GET_RESOURCE,
+ properties, globalContext);
+ Set<String> referencedResourcesByGetAttr = handleGetAttrBetweenResources(properties);
+ referencedResourcesByGetResource.addAll(referencedResourcesByGetAttr);
+ updateRelationsMapWithCurrentResourceReferences(resourceMap, resourceEntry, referencedResourcesByGetResource, typeToPointingResourcesMap);
+ }
}
- return referencedResourcesByGetAttr;
- }
+ private void updateRelationsMapWithCurrentResourceReferences(Map<String, Resource> resourceMap, Map.Entry<String, Resource> currentResourceEntry,
+ Set<String> referencedResourcesFromCurrentResource,
+ Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap) {
+ for (String pointedResourceName : referencedResourcesFromCurrentResource) {
+ Resource pointedResource = resourceMap.get(pointedResourceName);
+ if (Objects.nonNull(pointedResource)) {
+ String pointedResourceType = pointedResource.getType();
+ updateMapWithRelationsBetweenResources(pointedResourceName, pointedResourceType, currentResourceEntry, typeToPointingResourcesMap);
+ }
+ }
+ }
+ private void updateMapWithRelationsBetweenResources(String pointedResourceName, String pointedResourceType,
+ Map.Entry<String, Resource> currentResourceEntry,
+ Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap) {
+ initCurrentResourceTypeInMap(pointedResourceName, pointedResourceType, currentResourceEntry.getValue().getType(), typeToPointingResourcesMap);
+ typeToPointingResourcesMap.get(pointedResourceType).get(pointedResourceName).get(currentResourceEntry.getValue().getType())
+ .add(currentResourceEntry.getKey());
+ }
- private Set<String> getGetAttrReferencesInCaseOfContrail(Object propertyValue) {
- Set<String> getAttrReferences = new HashSet<>();
+ private void initCurrentResourceTypeInMap(String resourceName, String resourceType, String pointingResourceType,
+ Map<String, Map<String, Map<String, List<String>>>> typeToPointingResourcesMap) {
+ typeToPointingResourcesMap.putIfAbsent(resourceType, new HashMap<>());
+ typeToPointingResourcesMap.get(resourceType).putIfAbsent(resourceName, new HashMap<>());
+ typeToPointingResourcesMap.get(resourceType).get(resourceName).putIfAbsent(pointingResourceType, new ArrayList<>());
+ }
- if (propertyValue instanceof Map) {
- if (((Map) propertyValue).containsKey(GET_ATTR)) {
- if (validatePropertyValueAndAddAttrReferencesInSet(propertyValue, getAttrReferences)) {
- return getAttrReferences;
+ private Set<String> handleGetAttrBetweenResources(Map<String, Object> properties) {
+ Set<String> referencedResourcesByGetAttr = new HashSet<>();
+ for (Map.Entry<String, Object> proprtyEntry : properties.entrySet()) {
+ referencedResourcesByGetAttr.addAll(getGetAttrReferencesInCaseOfContrail(proprtyEntry.getValue()));
}
- } else {
- Collection<Object> valCollection = ((Map) propertyValue).values();
- for (Object entryValue : valCollection) {
- getAttrReferences.addAll(getGetAttrReferencesInCaseOfContrail(entryValue));
+ return referencedResourcesByGetAttr;
+ }
+
+ private Set<String> getGetAttrReferencesInCaseOfContrail(Object propertyValue) {
+ Set<String> getAttrReferences = new HashSet<>();
+ if (propertyValue instanceof Map) {
+ if (((Map) propertyValue).containsKey(GET_ATTR)) {
+ if (validatePropertyValueAndAddAttrReferencesInSet(propertyValue, getAttrReferences)) {
+ return getAttrReferences;
+ }
+ } else {
+ Collection<Object> valCollection = ((Map) propertyValue).values();
+ for (Object entryValue : valCollection) {
+ getAttrReferences.addAll(getGetAttrReferencesInCaseOfContrail(entryValue));
+ }
+ }
+ } else if (propertyValue instanceof List) {
+ for (Object prop : (List) propertyValue) {
+ getAttrReferences.addAll(getGetAttrReferencesInCaseOfContrail(prop));
+ }
}
- }
- } else if (propertyValue instanceof List) {
- for (Object prop : (List) propertyValue) {
- getAttrReferences.addAll(getGetAttrReferencesInCaseOfContrail(prop));
- }
+ return getAttrReferences;
}
- return getAttrReferences;
- }
-
- private boolean validatePropertyValueAndAddAttrReferencesInSet(Object propertyValue,
- Set<String> getAttrReferences) {
- Object value = ((Map) propertyValue).get(GET_ATTR );
- if (value instanceof List && ((List) value).size() == 2
- && ("fq_name").equals(((List) value).get(1))) {
- if (((List) value).get(0) instanceof String) {
- String attrReference = (((List) value).get(0)).toString();
- getAttrReferences.add(attrReference);
- return true;
- } else {
- LOGGER.warn("invalid format of 'get_attr' function - " + propertyValue.toString());
- }
- }
- return false;
- }
-
-
- private Set<String> getResourcesIdsPointedByCurrentResource(String fileName,
- ResourceReferenceFunctions function,
- Map<String, Object> properties,
- GlobalValidationContext globalContext) {
-
- Set<String> referencedResources = new HashSet<>();
- for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
- referencedResources
- .addAll(HeatStructureUtil
- .getReferencedValuesByFunctionName(fileName,
- function.getFunction(),
- propertyEntry.getValue(),
- globalContext));
+ private boolean validatePropertyValueAndAddAttrReferencesInSet(Object propertyValue, Set<String> getAttrReferences) {
+ Object value = ((Map) propertyValue).get(GET_ATTR);
+ if (value instanceof List && ((List) value).size() == 2 && ("fq_name").equals(((List) value).get(1))) {
+ if (((List) value).get(0) instanceof String) {
+ String attrReference = (((List) value).get(0)).toString();
+ getAttrReferences.add(attrReference);
+ return true;
+ } else {
+ LOGGER.warn("invalid format of 'get_attr' function - " + propertyValue.toString());
+ }
+ }
+ return false;
}
- return referencedResources;
- }
+ private Set<String> getResourcesIdsPointedByCurrentResource(String fileName, ResourceReferenceFunctions function, Map<String, Object> properties,
+ GlobalValidationContext globalContext) {
+ Set<String> referencedResources = new HashSet<>();
+ for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
+ referencedResources.addAll(
+ HeatStructureUtil.getReferencedValuesByFunctionName(fileName, function.getFunction(), propertyEntry.getValue(), globalContext));
+ }
+ return referencedResources;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java
index 5fb2953b6a..19b8892182 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators;
import java.io.InputStream;
@@ -51,6 +50,11 @@ import org.openecomp.sdc.validation.impl.util.HeatValidationService;
import org.openecomp.sdc.validation.util.ValidationUtil;
public class HeatValidator implements Validator {
+
+ // The Artifacts generated by SDC - not allowed to be in HEAT
+ static final String VF_LICENSE_MODEL_XML = "vf-license-model.xml";
+ static final String VENDOR_LICENSE_MODEL_XML = "vendor-license-model.xml";
+ static final String HEAT_META = "HEAT.meta";
private static final Logger LOGGER = LoggerFactory.getLogger(HeatValidator.class);
private static final ErrorMessageCode ERROR_CODE_HOT_1 = new ErrorMessageCode("HOT1");
private static final ErrorMessageCode ERROR_CODE_HOT_2 = new ErrorMessageCode("HOT2");
@@ -69,224 +73,191 @@ public class HeatValidator implements Validator {
private static final ErrorMessageCode ERROR_CODE_HOT_15 = new ErrorMessageCode("HOT15");
private static final ErrorMessageCode ERROR_CODE_HOT_16 = new ErrorMessageCode("HOT16");
private static final ErrorMessageCode ERROR_CODE_HOT_17 = new ErrorMessageCode("HOT17");
-
private static final ErrorMessageCode ERROR_CODE_HOT_18 = new ErrorMessageCode("HOT18");
-
- // The Artifacts generated by SDC - not allowed to be in HEAT
- static final String VF_LICENSE_MODEL_XML = "vf-license-model.xml";
- static final String VENDOR_LICENSE_MODEL_XML = "vendor-license-model.xml";
- static final String HEAT_META = "HEAT.meta";
-
private static final Set<String> GENERATED_ARTIFACTS;
static {
GENERATED_ARTIFACTS = getGeneratedArtifactNames();
}
- private static void validateAllRequiredArtifactsExist(String fileName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- Set<String> artifacts,
- GlobalValidationContext globalContext) {
- Collection<Resource> resourcesValues = heatOrchestrationTemplate.getResources() == null ? null
- : heatOrchestrationTemplate.getResources().values();
-
- if (CollectionUtils.isNotEmpty(resourcesValues)) {
- for (Resource resource : resourcesValues) {
- Collection<Object> properties =
- resource.getProperties() == null ? null : resource.getProperties().values();
- validatePropertiesForAllRequiredArtifactsExist(properties, fileName,
- artifacts, globalContext);
- }
- }
- }
-
- private static void validatePropertiesForAllRequiredArtifactsExist(Collection<Object> properties,
- String fileName,
- Set<String> artifacts,
- GlobalValidationContext globalContext) {
- if (CollectionUtils.isNotEmpty(properties)) {
- for (Object property : properties) {
- if (property instanceof Map) {
- globalContext.setMessageCode(ERROR_CODE_HOT_14);
- Set<String> artifactNames = HeatStructureUtil
- .getReferencedValuesByFunctionName(fileName,
- ResourceReferenceFunctions.GET_FILE.getFunction(), property, globalContext);
- artifacts.addAll(artifactNames);
- globalContext.setMessageCode(ERROR_CODE_HOT_15);
- HeatValidationService.checkArtifactsExistence(fileName, artifactNames,
- globalContext);
- }
- }
- }
- }
- /* validation 14 */
-
- private static void validateAllResourceReferencesExist(String fileName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Set<String> resourcesNames = heatOrchestrationTemplate.getResources() == null ? null
- : heatOrchestrationTemplate.getResources().keySet();
- Collection<Resource> resourcesValues = heatOrchestrationTemplate.getResources() == null ? null
- : heatOrchestrationTemplate.getResources().values();
- Collection<Output> outputsValues = heatOrchestrationTemplate.getOutputs() == null ? null
- : heatOrchestrationTemplate.getOutputs().values();
- checkResourceExistenceFromResourcesMap(fileName, resourcesNames, resourcesValues,
- globalContext);
- checkResourceExistenceFromResourcesMap(fileName, resourcesNames, outputsValues,
- globalContext);
- }
-
- private static void checkResourceExistenceFromResourcesMap(String fileName,
- Set<String> resourcesNames,
- Collection<?> valuesToSearchIn,
- GlobalValidationContext globalContext) {
- if (CollectionUtils.isNotEmpty(valuesToSearchIn)) {
- for (Object value : valuesToSearchIn) {
- if (value instanceof Resource) {
- extractResourceProperty(fileName, resourcesNames, globalContext,
- (Resource) value);
- } else if (value instanceof Output) {
- Output output = (Output) value;
- Object outputsValue = output.getValue();
- handleReferencedResources(fileName, outputsValue, resourcesNames,
- globalContext);
+ private static void validateAllRequiredArtifactsExist(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate, Set<String> artifacts,
+ GlobalValidationContext globalContext) {
+ Collection<Resource> resourcesValues =
+ heatOrchestrationTemplate.getResources() == null ? null : heatOrchestrationTemplate.getResources().values();
+ if (CollectionUtils.isNotEmpty(resourcesValues)) {
+ for (Resource resource : resourcesValues) {
+ Collection<Object> properties = resource.getProperties() == null ? null : resource.getProperties().values();
+ validatePropertiesForAllRequiredArtifactsExist(properties, fileName, artifacts, globalContext);
+ }
}
- }
- }
- }
-
- private static void extractResourceProperty(String fileName, Set<String> resourcesNames,
- GlobalValidationContext globalContext,
- Resource value) {
- Collection<Object> resourcePropertiesValues =
- value.getProperties() == null ? null : value.getProperties()
- .values();
- if (CollectionUtils.isNotEmpty(resourcePropertiesValues)) {
- for (Object propertyValue : resourcePropertiesValues) {
- handleReferencedResources(fileName, propertyValue, resourcesNames,
+ }
+
+ private static void validatePropertiesForAllRequiredArtifactsExist(Collection<Object> properties, String fileName, Set<String> artifacts,
+ GlobalValidationContext globalContext) {
+ if (CollectionUtils.isNotEmpty(properties)) {
+ for (Object property : properties) {
+ if (property instanceof Map) {
+ globalContext.setMessageCode(ERROR_CODE_HOT_14);
+ Set<String> artifactNames = HeatStructureUtil
+ .getReferencedValuesByFunctionName(fileName, ResourceReferenceFunctions.GET_FILE.getFunction(), property, globalContext);
+ artifacts.addAll(artifactNames);
+ globalContext.setMessageCode(ERROR_CODE_HOT_15);
+ HeatValidationService.checkArtifactsExistence(fileName, artifactNames, globalContext);
+ }
+ }
+ }
+ }
+ /* validation 14 */
+
+ private static void validateAllResourceReferencesExist(String fileName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Set<String> resourcesNames = heatOrchestrationTemplate.getResources() == null ? null
+ : heatOrchestrationTemplate.getResources().keySet();
+ Collection<Resource> resourcesValues = heatOrchestrationTemplate.getResources() == null ? null
+ : heatOrchestrationTemplate.getResources().values();
+ Collection<Output> outputsValues = heatOrchestrationTemplate.getOutputs() == null ? null
+ : heatOrchestrationTemplate.getOutputs().values();
+ checkResourceExistenceFromResourcesMap(fileName, resourcesNames, resourcesValues,
+ globalContext);
+ checkResourceExistenceFromResourcesMap(fileName, resourcesNames, outputsValues,
globalContext);
- }
- }
- }
-
- private static void handleReferencedResources(String fileName, Object valueToSearchReferencesIn,
- Set<String> resourcesNames,
- GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_HOT_13);
- Set<String> referencedResourcesNames = HeatStructureUtil
- .getReferencedValuesByFunctionName(fileName,
- ResourceReferenceFunctions.GET_RESOURCE.getFunction(),
- valueToSearchReferencesIn, globalContext);
- if (CollectionUtils.isNotEmpty(referencedResourcesNames)) {
- checkIfResourceReferenceExist(fileName, resourcesNames, referencedResourcesNames,
- globalContext);
- }
- }
-
- private static void checkIfResourceReferenceExist(String fileName,
- Set<String> referencedResourcesNames,
- Set<String> referencedResources,
- GlobalValidationContext globalContext) {
- referencedResources.stream()
- .filter(referencedResource -> !referencedResourcesNames
+ }
+
+ private static void checkResourceExistenceFromResourcesMap(String fileName,
+ Set<String> resourcesNames,
+ Collection<?> valuesToSearchIn,
+ GlobalValidationContext globalContext) {
+ if (CollectionUtils.isNotEmpty(valuesToSearchIn)) {
+ for (Object value : valuesToSearchIn) {
+ if (value instanceof Resource) {
+ extractResourceProperty(fileName, resourcesNames, globalContext,
+ (Resource) value);
+ } else if (value instanceof Output) {
+ Output output = (Output) value;
+ Object outputsValue = output.getValue();
+ handleReferencedResources(fileName, outputsValue, resourcesNames,
+ globalContext);
+ }
+ }
+ }
+ }
+
+ private static void extractResourceProperty(String fileName, Set<String> resourcesNames,
+ GlobalValidationContext globalContext,
+ Resource value) {
+ Collection<Object> resourcePropertiesValues =
+ value.getProperties() == null ? null : value.getProperties()
+ .values();
+ if (CollectionUtils.isNotEmpty(resourcePropertiesValues)) {
+ for (Object propertyValue : resourcePropertiesValues) {
+ handleReferencedResources(fileName, propertyValue, resourcesNames,
+ globalContext);
+ }
+ }
+ }
+
+ private static void handleReferencedResources(String fileName, Object valueToSearchReferencesIn,
+ Set<String> resourcesNames,
+ GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_HOT_13);
+ Set<String> referencedResourcesNames = HeatStructureUtil
+ .getReferencedValuesByFunctionName(fileName,
+ ResourceReferenceFunctions.GET_RESOURCE.getFunction(),
+ valueToSearchReferencesIn, globalContext);
+ if (CollectionUtils.isNotEmpty(referencedResourcesNames)) {
+ checkIfResourceReferenceExist(fileName, resourcesNames, referencedResourcesNames,
+ globalContext);
+ }
+ }
+
+ private static void checkIfResourceReferenceExist(String fileName,
+ Set<String> referencedResourcesNames,
+ Set<String> referencedResources,
+ GlobalValidationContext globalContext) {
+ referencedResources.stream()
+ .filter(referencedResource -> !referencedResourcesNames
.contains(referencedResource))
- .forEach(referencedResource ->
- globalContext.addMessage(fileName,
- ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_16,Messages
- .REFERENCED_RESOURCE_NOT_FOUND.getErrorMessage(), referencedResource)));
- }
-
- /* validation 16 */
-
- private static void validateGetParamPointToParameter(String fileName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Set<String> parametersNames = heatOrchestrationTemplate.getParameters() == null ? null
- : heatOrchestrationTemplate.getParameters().keySet();
- Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
-
- if (CollectionUtils.isNotEmpty(parametersNames) && MapUtils.isNotEmpty(resourcesMap)) {
- for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
- Resource resource = resourceEntry.getValue();
- Map<String, Object> properties = resource.getProperties();
- validatePropertiesForGetParamPointToParameter(properties, fileName, parametersNames,
- resourceEntry, globalContext);
- }
- }
- }
-
- private static void validatePropertiesForGetParamPointToParameter(Map<String,
- Object> properties,
- String fileName, Set<String> parametersNames,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- if (MapUtils.isNotEmpty(properties)) {
- Collection<Object> propertiesValues = properties.values();
- if (CollectionUtils.isNotEmpty(propertiesValues)) {
- for (Object propertyObject : propertiesValues) {
- Set<String> referencedParameterNames = HeatStructureUtil
- .getReferencedValuesByFunctionName(fileName, "get_param", propertyObject,
- globalContext);
-
- validateReferenceParams(fileName, resourceEntry.getKey(), parametersNames,
- referencedParameterNames, globalContext);
- }
- }
- }
- }
-
- private static void validateReferenceParams(String fileName, String resourceName,
- Set<String> parametersNamesFromFile,
- Set<String> referencedParametersNames,
- GlobalValidationContext globalContext) {
- for (String parameterName : referencedParametersNames) {
- if (!isHeatPseudoParameter(parameterName)
- && !parametersNamesFromFile.contains(parameterName)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_1,Messages
- .REFERENCED_PARAMETER_NOT_FOUND.getErrorMessage(),
- parameterName, resourceName));
- }
- }
- }
-
- private static boolean isHeatPseudoParameter(String parameterName) {
- return HeatPseudoParameters.getPseudoParameterNames().contains(parameterName);
- }
-
- /* validation 18*/
-
- private static void validateGetAttr(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Map<String, Output> outputMap;
- outputMap = heatOrchestrationTemplate.getOutputs();
-
- if (MapUtils.isNotEmpty(outputMap)) {
- loopOverOutputMapAndValidateGetAttrFromNested(fileName, outputMap,
- heatOrchestrationTemplate, globalContext);
- }
- }
-
- private static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName,
- Map<String, Output> outputMap,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- GlobalValidationContext
- globalContext) {
- for (Output output : outputMap.values()) {
- Object outputValue = output.getValue();
- if (outputValue instanceof Map) {
- Map<String, Object> outputValueMap = (Map<String, Object>) outputValue;
- List<String> getAttrValue =
- (List<String>) outputValueMap.get(
- ResourceReferenceFunctions.GET_ATTR.getFunction());
+ .forEach(referencedResource ->
+ globalContext.addMessage(fileName,
+ ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_16, Messages
+ .REFERENCED_RESOURCE_NOT_FOUND.getErrorMessage(), referencedResource)));
+ }
+
+ /* validation 16 */
+ private static void validateGetParamPointToParameter(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Set<String> parametersNames = heatOrchestrationTemplate.getParameters() == null ? null : heatOrchestrationTemplate.getParameters().keySet();
+ Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
+ if (CollectionUtils.isNotEmpty(parametersNames) && MapUtils.isNotEmpty(resourcesMap)) {
+ for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
+ Resource resource = resourceEntry.getValue();
+ Map<String, Object> properties = resource.getProperties();
+ validatePropertiesForGetParamPointToParameter(properties, fileName, parametersNames, resourceEntry, globalContext);
+ }
+ }
+ }
+
+ private static void validatePropertiesForGetParamPointToParameter(Map<String, Object> properties, String fileName, Set<String> parametersNames,
+ Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ if (MapUtils.isNotEmpty(properties)) {
+ Collection<Object> propertiesValues = properties.values();
+ if (CollectionUtils.isNotEmpty(propertiesValues)) {
+ for (Object propertyObject : propertiesValues) {
+ Set<String> referencedParameterNames = HeatStructureUtil
+ .getReferencedValuesByFunctionName(fileName, "get_param", propertyObject, globalContext);
+ validateReferenceParams(fileName, resourceEntry.getKey(), parametersNames, referencedParameterNames, globalContext);
+ }
+ }
+ }
+ }
+
+ private static void validateReferenceParams(String fileName, String resourceName, Set<String> parametersNamesFromFile,
+ Set<String> referencedParametersNames, GlobalValidationContext globalContext) {
+ for (String parameterName : referencedParametersNames) {
+ if (!isHeatPseudoParameter(parameterName) && !parametersNamesFromFile.contains(parameterName)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_1, Messages.REFERENCED_PARAMETER_NOT_FOUND.getErrorMessage(), parameterName,
+ resourceName));
+ }
+ }
+ }
+
+ private static boolean isHeatPseudoParameter(String parameterName) {
+ return HeatPseudoParameters.getPseudoParameterNames().contains(parameterName);
+ }
+ /* validation 18*/
+
+ private static void validateGetAttr(String fileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Map<String, Output> outputMap;
+ outputMap = heatOrchestrationTemplate.getOutputs();
+
+ if (MapUtils.isNotEmpty(outputMap)) {
+ loopOverOutputMapAndValidateGetAttrFromNested(fileName, outputMap,
+ heatOrchestrationTemplate, globalContext);
+ }
+ }
+
+ private static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName,
+ Map<String, Output> outputMap,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ GlobalValidationContext
+ globalContext) {
+ for (Output output : outputMap.values()) {
+ Object outputValue = output.getValue();
+ if (outputValue instanceof Map) {
+ Map<String, Object> outputValueMap = (Map<String, Object>) outputValue;
+ List<String> getAttrValue =
+ (List<String>) outputValueMap.get(
+ ResourceReferenceFunctions.GET_ATTR.getFunction());
handleGetAttrValueList(getAttrValue, fileName, heatOrchestrationTemplate,
- globalContext);
+ globalContext);
}
}
@@ -303,328 +274,249 @@ public class HeatValidator implements Validator {
}
String attName = getAttrValue.get(1);
String resourceType =
- getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate);
+ getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate);
if (Objects.nonNull(resourceType)
- && HeatValidationService.isNestedResource(resourceType)) {
+ && HeatValidationService.isNestedResource(resourceType)) {
handleGetAttrNestedResource(fileName, globalContext, resourceName, attName,
- resourceType);
+ resourceType);
}
}
}
- private static void handleGetAttrNestedResource(String fileName,
- GlobalValidationContext globalContext,
- String resourceName, String attName,
- String resourceType) {
- Map<String, Output> nestedOutputMap;
- HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
- try {
- Optional<InputStream> fileContent = globalContext.getFileContent(resourceType);
- if (fileContent.isPresent()) {
- nestedHeatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- throw new Exception("The file '" + resourceType + "' has no content");
- }
- } catch (Exception exception) {
+
+ private static void handleGetAttrNestedResource(String fileName,
+ GlobalValidationContext globalContext,
+ String resourceName, String attName,
+ String resourceType) {
+ Map<String, Output> nestedOutputMap;
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
+ try {
+ Optional<InputStream> fileContent = globalContext.getFileContent(resourceType);
+ if (fileContent.isPresent()) {
+ nestedHeatOrchestrationTemplate =
+ new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
+ } else {
+ throw new Exception("The file '" + resourceType + "' has no content");
+ }
+ } catch (Exception exception) {
LOGGER.error("Invalid yaml file", exception);
- return;
- }
- nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs();
-
- if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(attName)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_17,Messages
- .GET_ATTR_NOT_FOUND.getErrorMessage(),
- attName, resourceName));
- }
- }
-
- private static String getResourceTypeFromResourcesMap(String resourceName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate) {
- Resource resource = heatOrchestrationTemplate.getResources().get(resourceName);
- if (Objects.nonNull(resource)) {
- return resource.getType();
- } else {
- return null;
- }
- }
-
- /* validation 17 + */
- private static void validateEnvFile(String fileName, String envFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Environment envContent;
-
- if (!envFileName.contains(".env")) {
- globalContext.addMessage(envFileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_2,Messages
- .WRONG_ENV_FILE_EXTENSION.getErrorMessage(), envFileName));
- }
-
- envContent = HeatValidationService.validateEnvContent(fileName, envFileName, globalContext);
- if (envContent != null) {
- validateEnvContentIsSubSetOfHeatParameters(envFileName, envContent, globalContext,
- heatOrchestrationTemplate);
- validateEnvParametersMatchDefinedHeatParameterTypes(envFileName, envContent, globalContext,
- heatOrchestrationTemplate);
- }
- }
-
- private static void validateEnvContentIsSubSetOfHeatParameters(String envFile,
- Environment envContent,
- GlobalValidationContext
- globalContext,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate) {
- Set<String> parametersNames = heatOrchestrationTemplate.getParameters() == null ? null
- : heatOrchestrationTemplate.getParameters().keySet();
-
- if (MapUtils.isNotEmpty(envContent.getParameters())) {
- if (CollectionUtils.isNotEmpty(parametersNames)) {
- for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) {
+ return;
+ }
+ nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs();
+ if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(attName)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_17, Messages
+ .GET_ATTR_NOT_FOUND.getErrorMessage(),
+ attName, resourceName));
+ }
+ }
- validateEnvEntryForvalidateEnvContentIsSubSetOfHeatParameters(envEntry,
- parametersNames, envFile, globalContext);
+ private static String getResourceTypeFromResourcesMap(String resourceName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate) {
+ Resource resource = heatOrchestrationTemplate.getResources().get(resourceName);
+ if (Objects.nonNull(resource)) {
+ return resource.getType();
+ } else {
+ return null;
}
- } else {
- for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) {
- globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_3,Messages
- .ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(),
- envFile, envEntry.getKey()));
+ }
+
+ /* validation 17 + */
+ private static void validateEnvFile(String fileName, String envFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Environment envContent;
+ if (!envFileName.contains(".env")) {
+ globalContext.addMessage(envFileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_2, Messages.WRONG_ENV_FILE_EXTENSION.getErrorMessage(), envFileName));
+ }
+ envContent = HeatValidationService.validateEnvContent(fileName, envFileName, globalContext);
+ if (envContent != null) {
+ validateEnvContentIsSubSetOfHeatParameters(envFileName, envContent, globalContext, heatOrchestrationTemplate);
+ validateEnvParametersMatchDefinedHeatParameterTypes(envFileName, envContent, globalContext, heatOrchestrationTemplate);
}
- }
- }
- }
-
- private static void validateEnvEntryForvalidateEnvContentIsSubSetOfHeatParameters(
- Map.Entry<String, Object> envEntry,
- Set<String> parametersNames,
- String envFile,
- GlobalValidationContext globalContext) {
- String envParameter = envEntry.getKey();
- if (parametersNames != null && !parametersNames.contains(envParameter)) {
- globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HOT_3,Messages
- .ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile,
- envParameter));
}
-}
- private static void validateParameterDefaultTypeAlignWithType(String fileName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- GlobalValidationContext
- globalContext) {
- Map<String, Parameter> parametersMap = heatOrchestrationTemplate.getParameters();
-
- if (MapUtils.isNotEmpty(parametersMap)) {
- for (Map.Entry<String, Parameter> parameterEntry : parametersMap.entrySet()) {
- validateParameterEntryForParameterDefaultTypeAlignWithType(parameterEntry,
- fileName, globalContext);
- }
- }
- }
- private static void validateParameterEntryForParameterDefaultTypeAlignWithType(
- Map.Entry<String, Parameter> parameterEntry,
- String fileName, GlobalValidationContext globalContext){
+
+ private static void validateEnvContentIsSubSetOfHeatParameters(String envFile, Environment envContent, GlobalValidationContext globalContext,
+ HeatOrchestrationTemplate heatOrchestrationTemplate) {
+ Set<String> parametersNames = heatOrchestrationTemplate.getParameters() == null ? null : heatOrchestrationTemplate.getParameters().keySet();
+ if (MapUtils.isNotEmpty(envContent.getParameters())) {
+ if (CollectionUtils.isNotEmpty(parametersNames)) {
+ for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) {
+ validateEnvEntryForvalidateEnvContentIsSubSetOfHeatParameters(envEntry, parametersNames, envFile, globalContext);
+ }
+ } else {
+ for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) {
+ globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_3, Messages.ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile,
+ envEntry.getKey()));
+ }
+ }
+ }
+ }
+
+ private static void validateEnvEntryForvalidateEnvContentIsSubSetOfHeatParameters(Map.Entry<String, Object> envEntry, Set<String> parametersNames,
+ String envFile, GlobalValidationContext globalContext) {
+ String envParameter = envEntry.getKey();
+ if (parametersNames != null && !parametersNames.contains(envParameter)) {
+ globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_3, Messages.ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile, envParameter));
+ }
+ }
+
+ private static void validateParameterDefaultTypeAlignWithType(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Map<String, Parameter> parametersMap = heatOrchestrationTemplate.getParameters();
+ if (MapUtils.isNotEmpty(parametersMap)) {
+ for (Map.Entry<String, Parameter> parameterEntry : parametersMap.entrySet()) {
+ validateParameterEntryForParameterDefaultTypeAlignWithType(parameterEntry, fileName, globalContext);
+ }
+ }
+ }
+
+ private static void validateParameterEntryForParameterDefaultTypeAlignWithType(Map.Entry<String, Parameter> parameterEntry, String fileName,
+ GlobalValidationContext globalContext) {
Parameter parameter = parameterEntry.getValue();
String parameterType = parameter.getType();
Object parameterDefault = parameter.get_default();
if (parameterDefault != null && parameterType != null) {
- boolean isValueMatchDefault =
- DefinedHeatParameterTypes.isValueIsFromGivenType(parameterDefault,
- parameterType);
+ boolean isValueMatchDefault = DefinedHeatParameterTypes.isValueIsFromGivenType(parameterDefault, parameterType);
if (!isValueMatchDefault) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HOT_4,Messages
- .PARAMETER_DEFAULT_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(),
- parameterEntry.getKey(), parameterType));
+ .getErrorWithParameters(ERROR_CODE_HOT_4, Messages.PARAMETER_DEFAULT_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(),
+ parameterEntry.getKey(), parameterType));
}
}
}
- private static void validateEnvParametersMatchDefinedHeatParameterTypes(String envFile,
- Environment envContent,
- GlobalValidationContext globalContext,
- HeatOrchestrationTemplate heatOrchestrationTemplate) {
- Map<String, Parameter> heatParameters = heatOrchestrationTemplate.getParameters();
+ private static void validateEnvParametersMatchDefinedHeatParameterTypes(String envFile, Environment envContent,
+ GlobalValidationContext globalContext,
+ HeatOrchestrationTemplate heatOrchestrationTemplate) {
+ Map<String, Parameter> heatParameters = heatOrchestrationTemplate.getParameters();
+ if (MapUtils.isNotEmpty(heatParameters) && MapUtils.isNotEmpty(envContent.getParameters())) {
+ validateEnvEntryForEnvParametersMatchDefinedHeatParameterTypes(envContent, heatParameters, envFile, globalContext);
+ }
+ }
- if (MapUtils.isNotEmpty(heatParameters) && MapUtils.isNotEmpty(envContent.getParameters())) {
- validateEnvEntryForEnvParametersMatchDefinedHeatParameterTypes(envContent,
- heatParameters, envFile, globalContext);
+ private static void validateEnvEntryForEnvParametersMatchDefinedHeatParameterTypes(Environment envContent, Map<String, Parameter> heatParameters,
+ String envFile, GlobalValidationContext globalContext) {
+ for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) {
+ String parameterName = envEntry.getKey();
+ Object parameterEnvValue = envEntry.getValue();
+ Parameter parameterFromHeatFile = heatParameters.get(parameterName);
+ if (parameterFromHeatFile != null) {
+ String parameterType = parameterFromHeatFile.getType();
+ if (!DefinedHeatParameterTypes.isEmptyValueInEnv(parameterEnvValue) && !DefinedHeatParameterTypes
+ .isValueIsFromGivenType(parameterEnvValue, parameterType)) {
+ globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_5, Messages.PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(), parameterName));
+ }
+ }
+ }
+ }
+ private static Set<String> getGeneratedArtifactNames() {
+ Set<String> predefinedArtifactNames = new HashSet<>();
+ predefinedArtifactNames.add(VF_LICENSE_MODEL_XML);
+ predefinedArtifactNames.add(VENDOR_LICENSE_MODEL_XML);
+ predefinedArtifactNames.add(HEAT_META);
+ return predefinedArtifactNames;
+ }
+ @SuppressWarnings("unchecked")
+ private static void checkResourceDependsOn(String fileName, Resource resource, Set<String> resourcesNames,
+ GlobalValidationContext globalContext) {
+ Object dependencies = resource.getDepends_on();
+ if (dependencies instanceof Collection) {
+ ((Collection<String>) dependencies).stream().filter(resourceId -> !resourcesNames.contains(resourceId)).forEach(
+ resourceId -> globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_7, Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), resourceId)));
+ } else if (dependencies instanceof String && !resourcesNames.contains(dependencies)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_8, Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), String.valueOf(dependencies)));
+ }
}
- }
- private static void validateEnvEntryForEnvParametersMatchDefinedHeatParameterTypes(
- Environment envContent,
- Map<String, Parameter> heatParameters,
- String envFile,
- GlobalValidationContext globalContext) {
- for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) {
- String parameterName = envEntry.getKey();
- Object parameterEnvValue = envEntry.getValue();
- Parameter parameterFromHeatFile = heatParameters.get(parameterName);
- if (parameterFromHeatFile != null) {
- String parameterType = parameterFromHeatFile.getType();
- if (!DefinedHeatParameterTypes.isEmptyValueInEnv(parameterEnvValue)
- && !DefinedHeatParameterTypes
- .isValueIsFromGivenType(parameterEnvValue, parameterType)) {
- globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HOT_5,Messages
- .PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(),
- parameterName));
- }
- }
- }
- }
-
- @Override
- public void validate(GlobalValidationContext globalContext) {
- ManifestContent manifestContent;
- try {
- manifestContent = ValidationUtil.validateManifest(globalContext);
- } catch (Exception exception) {
- LOGGER.error("Failed to validate manifest file", exception);
- return;
- }
- Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
- Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent);
- Set<String> artifacts = new HashSet<>();
-
- globalContext.getFiles().stream()
- .filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName))).forEach(
- fileName -> validate(fileName, fileEnvMap.get(fileName) == null ? null : fileEnvMap.get(
- fileName).getFile(), artifacts,
- globalContext));
-
- Set<String> manifestArtifacts = ManifestUtil.getArtifacts(manifestContent);
-
- globalContext.getFiles().stream().filter(fileName -> isManifestArtifact(manifestArtifacts, fileName)
- && isNotArtifact(artifacts, fileName)).forEach(fileName -> {
+ @Override
+ public void validate(GlobalValidationContext globalContext) {
+ ManifestContent manifestContent;
+ try {
+ manifestContent = ValidationUtil.validateManifest(globalContext);
+ } catch (Exception exception) {
+ LOGGER.error("Failed to validate manifest file", exception);
+ return;
+ }
+ Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
+ Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent);
+ Set<String> artifacts = new HashSet<>();
+ globalContext.getFiles().stream().filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName))).forEach(
+ fileName -> validate(fileName, fileEnvMap.get(fileName) == null ? null : fileEnvMap.get(fileName).getFile(), artifacts, globalContext));
+ Set<String> manifestArtifacts = ManifestUtil.getArtifacts(manifestContent);
+ globalContext.getFiles().stream().filter(fileName -> isManifestArtifact(manifestArtifacts, fileName) && isNotArtifact(artifacts, fileName))
+ .forEach(fileName -> {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_HOT_11, Messages.ARTIFACT_FILE_NOT_REFERENCED.getErrorMessage()));
+ validateGeneratedArtifact(fileName, globalContext);
+ });
+ }
- globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_11,
- Messages.ARTIFACT_FILE_NOT_REFERENCED.getErrorMessage()));
+ private void validateGeneratedArtifact(String fileName, GlobalValidationContext globalContext) {
+ if (GENERATED_ARTIFACTS.contains(fileName)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_HOT_18, Messages.GENERATED_ARTIFACT_IN_USE.getErrorMessage(), fileName));
+ }
+ }
- validateGeneratedArtifact(fileName, globalContext);
+ private boolean isManifestArtifact(Set<String> manifestArtifacts, String fileName) {
+ return manifestArtifacts.contains(fileName);
+ }
- });
+ private boolean isNotArtifact(Set<String> artifacts, String fileName) {
+ return !artifacts.contains(fileName);
}
- private void validateGeneratedArtifact(String fileName, GlobalValidationContext globalContext) {
- if (GENERATED_ARTIFACTS.contains(fileName)) {
+ private void validate(String fileName, String envFileName, Set<String> artifacts, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_HOT_12);
+ HeatOrchestrationTemplate heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ if (heatOrchestrationTemplate != null) {
+ if (!(fileName.contains(".yaml") || fileName.contains(".yml"))) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_6, Messages.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(), fileName));
+ }
+ validateHeatBaseStructure(fileName, heatOrchestrationTemplate, globalContext);
+ validateParameterDefaultTypeAlignWithType(fileName, heatOrchestrationTemplate, globalContext);
+ validateAllResourceReferencesExist(fileName, heatOrchestrationTemplate, globalContext);
+ validateResourceDependsOn(fileName, heatOrchestrationTemplate, globalContext);
+ validateGetParamPointToParameter(fileName, heatOrchestrationTemplate, globalContext);
+ validateGetAttr(fileName, heatOrchestrationTemplate, globalContext);
+ validateAllRequiredArtifactsExist(fileName, heatOrchestrationTemplate, artifacts, globalContext);
+ if (envFileName != null) {
+ validateEnvFile(fileName, envFileName, heatOrchestrationTemplate, globalContext);
+ }
+ }
+ }
+
+ private void validateResourceDependsOn(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
+ if (MapUtils.isEmpty(resourcesMap)) {
+ return;
+ }
+ Set<String> resourcesNames = resourcesMap.keySet();
+ resourcesMap.entrySet().stream().forEach(entry -> checkResourceDependsOn(fileName, entry.getValue(), resourcesNames, globalContext));
+ }
+
+ private void validateHeatBaseStructure(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ if (heatOrchestrationTemplate.getHeat_template_version() == null) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_18,
- Messages.GENERATED_ARTIFACT_IN_USE.getErrorMessage(), fileName));
+ .getErrorWithParameters(ERROR_CODE_HOT_9, Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(), "missing template version"));
}
- }
-
- private static Set<String> getGeneratedArtifactNames() {
- Set<String> predefinedArtifactNames = new HashSet<>();
- predefinedArtifactNames.add(VF_LICENSE_MODEL_XML);
- predefinedArtifactNames.add(VENDOR_LICENSE_MODEL_XML);
- predefinedArtifactNames.add(HEAT_META);
- return predefinedArtifactNames;
- }
-
- private boolean isManifestArtifact(Set<String> manifestArtifacts, String fileName) {
- return manifestArtifacts.contains(fileName);
- }
-
- private boolean isNotArtifact(Set<String> artifacts, String fileName) {
- return !artifacts.contains(fileName);
- }
-
- private void validate(String fileName, String envFileName,
- Set<String> artifacts,
- GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_HOT_12);
- HeatOrchestrationTemplate
- heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(
- fileName, globalContext);
-
-
- if (heatOrchestrationTemplate != null) {
- if (!(fileName.contains(".yaml") || fileName.contains(".yml"))) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_6,Messages
- .WRONG_HEAT_FILE_EXTENSION.getErrorMessage(), fileName));
- }
-
- validateHeatBaseStructure(fileName, heatOrchestrationTemplate, globalContext);
- validateParameterDefaultTypeAlignWithType(fileName, heatOrchestrationTemplate, globalContext);
- validateAllResourceReferencesExist(fileName, heatOrchestrationTemplate, globalContext);
- validateResourceDependsOn(fileName, heatOrchestrationTemplate, globalContext);
- validateGetParamPointToParameter(fileName, heatOrchestrationTemplate, globalContext);
- validateGetAttr(fileName, heatOrchestrationTemplate, globalContext);
- validateAllRequiredArtifactsExist(fileName, heatOrchestrationTemplate, artifacts,
- globalContext);
-
- if (envFileName != null) {
- validateEnvFile(fileName, envFileName, heatOrchestrationTemplate, globalContext);
- }
- }
- }
-
- private void validateResourceDependsOn(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
- if(MapUtils.isEmpty(resourcesMap)) {
- return;
- }
-
- Set<String> resourcesNames = resourcesMap.keySet();
-
- resourcesMap.entrySet().stream()
- .forEach(entry -> checkResourceDependsOn(fileName, entry.getValue(),
- resourcesNames, globalContext));
- }
-
- @SuppressWarnings("unchecked")
- private static void checkResourceDependsOn(String fileName, Resource resource,
- Set<String> resourcesNames,
- GlobalValidationContext globalContext) {
- Object dependencies = resource.getDepends_on();
- if (dependencies instanceof Collection) {
- ((Collection<String>) dependencies)
- .stream()
- .filter(resourceId -> !resourcesNames.contains(resourceId))
- .forEach(resourceId -> globalContext.addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_7,
- Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), resourceId)));
- } else if (dependencies instanceof String && !resourcesNames.contains(dependencies)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_8,
- Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), String.valueOf(dependencies)));
- }
- }
-
-
- private void validateHeatBaseStructure(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- if (heatOrchestrationTemplate.getHeat_template_version() == null) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_9,
- Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
- "missing template version"));
- }
- if (heatOrchestrationTemplate.getResources() == null
- || heatOrchestrationTemplate.getResources().size() == 0) {
- globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HOT_10,
- Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
- "The heat file does not contain any resources"));
- }
- }
+ if (heatOrchestrationTemplate.getResources() == null || heatOrchestrationTemplate.getResources().size() == 0) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_10, Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
+ "The heat file does not contain any resources"));
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java
index 675aa8adaf..ca01448a43 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java
@@ -12,10 +12,13 @@
* 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.validation.impl.validators;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -29,161 +32,121 @@ import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.validation.Validator;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
public class ManifestValidator implements Validator {
- private static final Logger LOGGER = LoggerFactory.getLogger(YamlValidator.class);
- private static final ErrorMessageCode ERROR_CODE_MNF_1 = new ErrorMessageCode("MNF1");
- private static final ErrorMessageCode ERROR_CODE_MNF_2 = new ErrorMessageCode("MNF2");
- private static final ErrorMessageCode ERROR_CODE_MNF_3 = new ErrorMessageCode("MNF3");
- private static final ErrorMessageCode ERROR_CODE_MNF_4 = new ErrorMessageCode("MNF4");
- private static final ErrorMessageCode ERROR_CODE_MNF_5 = new ErrorMessageCode("MNF5");
- private static final ErrorMessageCode ERROR_CODE_MNF_6 = new ErrorMessageCode("MNF6");
- private static final ErrorMessageCode ERROR_CODE_MNF_7 = new ErrorMessageCode("MNF7");
- private static final ErrorMessageCode ERROR_CODE_MNF_8 = new ErrorMessageCode("MNF8");
-
- @Override
- public void validate(GlobalValidationContext globalContext) {
- Optional<InputStream> content = globalContext.getFileContent(SdcCommon.MANIFEST_NAME);
- ManifestContent manifestContent;
-
- try {
- if (content.isPresent()) {
- manifestContent = JsonUtil.json2Object(content.get(), ManifestContent.class);
- } else {
- throw new Exception("The manifest file '" + SdcCommon.MANIFEST_NAME + "' has no content");
- }
- } catch (Exception re) {
- LOGGER.error("Invalid manifest file", re);
- globalContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_6,
- Messages.INVALID_MANIFEST_FILE.getErrorMessage()));
- return;
- }
- List<String> manifestFiles = getManifestFileList(manifestContent, globalContext);
- manifestFiles.stream().filter(name ->
- !globalContext.getFileContextMap().containsKey(name)
- ).forEach(name -> globalContext
- .addMessage(name, ErrorLevel.ERROR,ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_4,
- Messages.MISSING_FILE_IN_ZIP.getErrorMessage())));
-
- globalContext.getFileContextMap().keySet().stream().filter(name ->
- isNotManifestFiles(manifestFiles, name) && isNotManifestName(name)
- ).forEach(name ->
- globalContext.addMessage(name, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_5,
- Messages.MISSING_FILE_IN_MANIFEST.getErrorMessage())));
- }
-
- private boolean isNotManifestFiles(List<String> manifestFiles, String name) {
- return !manifestFiles.contains(name);
- }
-
- private boolean isNotManifestName(String name) {
- return !SdcCommon.MANIFEST_NAME.equals(name);
- }
-
-
- private List<String> getManifestFileList(ManifestContent manifestContent,
- GlobalValidationContext context) {
- ManifestScanner manifestScanner = new ManifestScanner();
- manifestScanner.scan(null, manifestContent.getData(), context);
- return manifestScanner.getFileList();
- }
-
-
- private class ManifestScanner {
- private final List<String> fileList = new ArrayList<>();
-
- public void scan(FileData fileData, List<FileData> data,
- GlobalValidationContext globalContext) {
- if (fileData == null) {
- for (FileData childFileData : data) {
- validateIfEnvIsAssociatedToHeat(globalContext, childFileData);
+ private static final Logger LOGGER = LoggerFactory.getLogger(YamlValidator.class);
+ private static final ErrorMessageCode ERROR_CODE_MNF_1 = new ErrorMessageCode("MNF1");
+ private static final ErrorMessageCode ERROR_CODE_MNF_2 = new ErrorMessageCode("MNF2");
+ private static final ErrorMessageCode ERROR_CODE_MNF_3 = new ErrorMessageCode("MNF3");
+ private static final ErrorMessageCode ERROR_CODE_MNF_4 = new ErrorMessageCode("MNF4");
+ private static final ErrorMessageCode ERROR_CODE_MNF_5 = new ErrorMessageCode("MNF5");
+ private static final ErrorMessageCode ERROR_CODE_MNF_6 = new ErrorMessageCode("MNF6");
+ private static final ErrorMessageCode ERROR_CODE_MNF_7 = new ErrorMessageCode("MNF7");
+ private static final ErrorMessageCode ERROR_CODE_MNF_8 = new ErrorMessageCode("MNF8");
+
+ @Override
+ public void validate(GlobalValidationContext globalContext) {
+ Optional<InputStream> content = globalContext.getFileContent(SdcCommon.MANIFEST_NAME);
+ ManifestContent manifestContent;
+ try {
+ if (content.isPresent()) {
+ manifestContent = JsonUtil.json2Object(content.get(), ManifestContent.class);
+ } else {
+ throw new Exception("The manifest file '" + SdcCommon.MANIFEST_NAME + "' has no content");
+ }
+ } catch (Exception re) {
+ LOGGER.error("Invalid manifest file", re);
+ globalContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_6, Messages.INVALID_MANIFEST_FILE.getErrorMessage()));
+ return;
}
- }
- if (fileData != null) {
- fileList.add(fileData.getFile());
- validateFileTypeVsFileName(globalContext,fileData);
- }
- if (data == null) {
- return;
- }
- data.forEach(chileFileData -> scan(chileFileData, chileFileData.getData(), globalContext));
+ List<String> manifestFiles = getManifestFileList(manifestContent, globalContext);
+ manifestFiles.stream().filter(name -> !globalContext.getFileContextMap().containsKey(name)).forEach(name -> globalContext
+ .addMessage(name, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_4, Messages.MISSING_FILE_IN_ZIP.getErrorMessage())));
+ globalContext.getFileContextMap().keySet().stream().filter(name -> isNotManifestFiles(manifestFiles, name) && isNotManifestName(name))
+ .forEach(name -> globalContext.addMessage(name, ErrorLevel.WARNING,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_5, Messages.MISSING_FILE_IN_MANIFEST.getErrorMessage())));
}
- public List<String> getFileList() {
- return this.fileList;
+ private boolean isNotManifestFiles(List<String> manifestFiles, String name) {
+ return !manifestFiles.contains(name);
}
- private void validateFileTypeVsFileName(GlobalValidationContext globalValidationContext,
- FileData fileData) {
- String fileName = fileData.getFile();
- validateIfFileExists(globalValidationContext,fileName);
- FileData.Type type = fileData.getType();
- if (type == null) {
- globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_8,
- Messages.INVALID_FILE_TYPE.getErrorMessage()));
- } else if (type.equals(FileData.Type.HEAT_NET) || type.equals(FileData.Type.HEAT_VOL)
- || type.equals(FileData.Type.HEAT)) {
- validateIfFileHasYamlExtenstion(globalValidationContext,fileName);
- } else if (type.equals(FileData.Type.HEAT_ENV)) {
- validateIfFileHasEnvExtension(globalValidationContext,fileName);
- }
+ private boolean isNotManifestName(String name) {
+ return !SdcCommon.MANIFEST_NAME.equals(name);
}
- private void validateIfEnvIsAssociatedToHeat(GlobalValidationContext globalContext,
- FileData childFileData) {
- if (childFileData.getType() != null
- && childFileData.getType().equals(FileData.Type.HEAT_ENV)) {
- globalContext.addMessage(childFileData.getFile(), ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_1,
- Messages.ENV_NOT_ASSOCIATED_TO_HEAT.getErrorMessage()));
- }
+ private List<String> getManifestFileList(ManifestContent manifestContent, GlobalValidationContext context) {
+ ManifestScanner manifestScanner = new ManifestScanner();
+ manifestScanner.scan(null, manifestContent.getData(), context);
+ return manifestScanner.getFileList();
}
- private void validateIfFileHasEnvExtension(GlobalValidationContext globalValidationContext,
- String fileName) {
- if (fileName != null && !fileName.endsWith(".env")) {
- globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_3,
- Messages.WRONG_ENV_FILE_EXTENSION.getErrorMessage(),
- fileName));
- }
- }
+ private class ManifestScanner {
+
+ private final List<String> fileList = new ArrayList<>();
+
+ public void scan(FileData fileData, List<FileData> data, GlobalValidationContext globalContext) {
+ if (fileData == null) {
+ for (FileData childFileData : data) {
+ validateIfEnvIsAssociatedToHeat(globalContext, childFileData);
+ }
+ }
+ if (fileData != null) {
+ fileList.add(fileData.getFile());
+ validateFileTypeVsFileName(globalContext, fileData);
+ }
+ if (data == null) {
+ return;
+ }
+ data.forEach(chileFileData -> scan(chileFileData, chileFileData.getData(), globalContext));
+ }
- private void validateIfFileHasYamlExtenstion(GlobalValidationContext globalValidationContext,
- String fileName) {
- if (fileName != null && !fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
- globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_2,
- Messages.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(),
- fileName));
- }
- }
+ public List<String> getFileList() {
+ return this.fileList;
+ }
- private void validateIfFileExists(GlobalValidationContext globalValidationContext,
- String fileName) {
- if (fileName == null) {
- globalValidationContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_7,
- Messages.MISSING_FILE_NAME_IN_MANIFEST.getErrorMessage()));
+ private void validateFileTypeVsFileName(GlobalValidationContext globalValidationContext, FileData fileData) {
+ String fileName = fileData.getFile();
+ validateIfFileExists(globalValidationContext, fileName);
+ FileData.Type type = fileData.getType();
+ if (type == null) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_8, Messages.INVALID_FILE_TYPE.getErrorMessage()));
+ } else if (type.equals(FileData.Type.HEAT_NET) || type.equals(FileData.Type.HEAT_VOL) || type.equals(FileData.Type.HEAT)) {
+ validateIfFileHasYamlExtenstion(globalValidationContext, fileName);
+ } else if (type.equals(FileData.Type.HEAT_ENV)) {
+ validateIfFileHasEnvExtension(globalValidationContext, fileName);
+ }
+ }
- }
- }
+ private void validateIfEnvIsAssociatedToHeat(GlobalValidationContext globalContext, FileData childFileData) {
+ if (childFileData.getType() != null && childFileData.getType().equals(FileData.Type.HEAT_ENV)) {
+ globalContext.addMessage(childFileData.getFile(), ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_1, Messages.ENV_NOT_ASSOCIATED_TO_HEAT.getErrorMessage()));
+ }
+ }
- }
-
+ private void validateIfFileHasEnvExtension(GlobalValidationContext globalValidationContext, String fileName) {
+ if (fileName != null && !fileName.endsWith(".env")) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_MNF_3, Messages.WRONG_ENV_FILE_EXTENSION.getErrorMessage(), fileName));
+ }
+ }
+
+ private void validateIfFileHasYamlExtenstion(GlobalValidationContext globalValidationContext, String fileName) {
+ if (fileName != null && !fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_MNF_2, Messages.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(), fileName));
+ }
+ }
+
+ private void validateIfFileExists(GlobalValidationContext globalValidationContext, String fileName) {
+ if (fileName == null) {
+ globalValidationContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_7, Messages.MISSING_FILE_NAME_IN_MANIFEST.getErrorMessage()));
+ }
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java
index 81f7c61eee..b65199758d 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java
@@ -19,6 +19,7 @@
*/
package org.openecomp.sdc.validation.impl.validators;
+import java.util.Map;
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.validation.ValidationContext;
@@ -26,23 +27,19 @@ import org.openecomp.sdc.validation.base.ResourceBaseValidator;
import org.openecomp.sdc.validation.type.ConfigConstants;
import org.openecomp.sdc.validation.type.NamingConventionValidationContext;
-import java.util.Map;
-
/**
* Created by TALIO on 2/15/2017.
*/
public class NamingConventionGuideLineValidator extends ResourceBaseValidator {
- @Override
- public void init(Map<String, Object> properties){
- super.init((Map<String, Object>) properties.get(ConfigConstants.Resource_Base_Validator));
- }
+ @Override
+ public void init(Map<String, Object> properties) {
+ super.init((Map<String, Object>) properties.get(ConfigConstants.Resource_Base_Validator));
+ }
- @Override
- public ValidationContext createValidationContext(String fileName, String envFileName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- GlobalValidationContext globalContext){
- return new NamingConventionValidationContext(heatOrchestrationTemplate, envFileName);
- }
+ @Override
+ public ValidationContext createValidationContext(String fileName, String envFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ return new NamingConventionValidationContext(heatOrchestrationTemplate, envFileName);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/PmDictionaryValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/PmDictionaryValidator.java
index 05021fdf4f..4dad4afc16 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/PmDictionaryValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/PmDictionaryValidator.java
@@ -17,11 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.validation.impl.validators;
import io.vavr.control.Option;
import io.vavr.control.Try;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Set;
import org.onap.validation.yaml.YamlContentValidator;
import org.onap.validation.yaml.error.YamlDocumentValidationError;
import org.openecomp.core.validation.ErrorMessageCode;
@@ -30,10 +32,6 @@ import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.validation.Validator;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Set;
-
public class PmDictionaryValidator implements Validator {
private static final ErrorMessageCode PM_DICT_ERROR_CODE = new ErrorMessageCode("PM_DICT");
@@ -44,11 +42,8 @@ public class PmDictionaryValidator implements Validator {
validatePmDictionaryFiles(globalContext, pmDictionaryFiles);
}
-
private void validatePmDictionaryFiles(GlobalValidationContext globalContext, Set<String> pmDictionaryFiles) {
- pmDictionaryFiles.stream()
- .map(fileName -> new ValidationHelper(globalContext, fileName))
- .forEach(ValidationHelper::validate);
+ pmDictionaryFiles.stream().map(fileName -> new ValidationHelper(globalContext, fileName)).forEach(ValidationHelper::validate);
}
private static class ValidationHelper {
@@ -62,36 +57,27 @@ public class PmDictionaryValidator implements Validator {
}
public void validate() {
- Option.ofOptional(globalContext.getFileContent(fileName))
- .peek(this::validateFileContent)
- .onEmpty(() -> addErrorToContext(formatMessage("File is empty")));
+ Option.ofOptional(globalContext.getFileContent(fileName)).peek(this::validateFileContent)
+ .onEmpty(() -> addErrorToContext(formatMessage("File is empty")));
}
private void validateFileContent(InputStream inputStream) {
- Try.of(inputStream::readAllBytes)
- .mapTry(fileContent -> new YamlContentValidator().validate(fileContent))
- .onSuccess(this::reportValidationErrorsIfPresent)
- .onFailure(e -> addErrorToContext(formatMessage(e.getMessage())));
+ Try.of(inputStream::readAllBytes).mapTry(fileContent -> new YamlContentValidator().validate(fileContent))
+ .onSuccess(this::reportValidationErrorsIfPresent).onFailure(e -> addErrorToContext(formatMessage(e.getMessage())));
}
private void reportValidationErrorsIfPresent(List<YamlDocumentValidationError> validationErrors) {
- validationErrors.stream()
- .map(this::prepareValidationMessage)
- .forEach(this::addErrorToContext);
+ validationErrors.stream().map(this::prepareValidationMessage).forEach(this::addErrorToContext);
}
private String prepareValidationMessage(YamlDocumentValidationError error) {
- final String errorMessage = String.format("Document Number: %s, Path: %s, Problem: %s",
- error.getYamlDocumentNumber(),
- error.getPath(),
- error.getMessage()
- );
+ final String errorMessage = String
+ .format("Document Number: %s, Path: %s, Problem: %s", error.getYamlDocumentNumber(), error.getPath(), error.getMessage());
return formatMessage(errorMessage);
}
private String formatMessage(String message) {
- return ErrorMessagesFormatBuilder
- .getErrorWithParameters(PM_DICT_ERROR_CODE, message);
+ return ErrorMessagesFormatBuilder.getErrorWithParameters(PM_DICT_ERROR_CODE, message);
}
private void addErrorToContext(String message) {
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java
index 0c279c23ee..3bac4c786d 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.core.validation.ErrorMessageCode;
@@ -36,198 +38,126 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.validation.Validator;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
public class SharedResourceGuideLineValidator implements Validator {
- private static final Logger LOGGER = LoggerFactory.getLogger(
- SharedResourceGuideLineValidator.class);
- private static final ErrorMessageCode ERROR_CODE_SRG_1 = new ErrorMessageCode("SRG1");
- private static final ErrorMessageCode ERROR_CODE_SRG_2 = new ErrorMessageCode("SRG2");
- private static final ErrorMessageCode ERROR_CODE_SRG_3 = new ErrorMessageCode("SRG3");
- private static final ErrorMessageCode ERROR_CODE_SRG_4 = new ErrorMessageCode("SRG4");
- private static final ErrorMessageCode ERROR_CODE_SRG_5 = new ErrorMessageCode("SRG5");
- private static final ErrorMessageCode ERROR_CODE_SRG_6 = new ErrorMessageCode("SRG6");
-
- @Override
- public void validate(GlobalValidationContext globalContext) {
- ManifestContent manifestContent;
- try {
- manifestContent = ValidationUtil.validateManifest(globalContext);
- } catch (Exception exception) {
- LOGGER.error("Fialed to check Validation PreCondition ",exception);
- return;
- }
-
- Set<String> baseFiles = validateManifest(manifestContent, globalContext);
-
- Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
- globalContext.getFiles().stream()
- .filter(fileName -> FileData
- .isHeatFile(fileTypeMap.get(fileName)))
- .forEach(fileName -> validate(fileName,
- fileTypeMap, baseFiles, globalContext));
+ private static final Logger LOGGER = LoggerFactory.getLogger(SharedResourceGuideLineValidator.class);
+ private static final ErrorMessageCode ERROR_CODE_SRG_1 = new ErrorMessageCode("SRG1");
+ private static final ErrorMessageCode ERROR_CODE_SRG_2 = new ErrorMessageCode("SRG2");
+ private static final ErrorMessageCode ERROR_CODE_SRG_3 = new ErrorMessageCode("SRG3");
+ private static final ErrorMessageCode ERROR_CODE_SRG_4 = new ErrorMessageCode("SRG4");
+ private static final ErrorMessageCode ERROR_CODE_SRG_5 = new ErrorMessageCode("SRG5");
+ private static final ErrorMessageCode ERROR_CODE_SRG_6 = new ErrorMessageCode("SRG6");
- }
-
- private Set<String> validateManifest(ManifestContent manifestContent,
- GlobalValidationContext globalContext) {
- Set<String> baseFiles = ManifestUtil.getBaseFiles(manifestContent);
- if (baseFiles == null || baseFiles.isEmpty()) {
- globalContext.addMessage(
- SdcCommon.MANIFEST_NAME,
- ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_SRG_3,Messages
- .MISSIN_BASE_HEAT_FILE.getErrorMessage()));
- } else if (baseFiles.size() > 1) {
- String baseFileList = getElementListAsString(baseFiles);
- globalContext.addMessage(
- SdcCommon.MANIFEST_NAME,
- ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_SRG_4,Messages
- .MULTI_BASE_HEAT_FILE.getErrorMessage(),
- baseFileList));
+ private static String getElementListAsString(Set<String> elementCollection) {
+ return "[" + CommonMethods.collectionToCommaSeparatedString(elementCollection) + "]";
}
- return baseFiles;
- }
-
- private static String getElementListAsString(Set<String> elementCollection) {
- return "["
- + CommonMethods.collectionToCommaSeparatedString(elementCollection)
- + "]";
- }
- private void validate(String fileName, Map<String, FileData.Type> fileTypeMap,
- Set<String> baseFiles, GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_SRG_5);
- HeatOrchestrationTemplate
- heatOrchestrationTemplate = ValidationUtil
- .checkHeatOrchestrationPreCondition(fileName, globalContext);
- if (heatOrchestrationTemplate == null) {
- return;
+ @Override
+ public void validate(GlobalValidationContext globalContext) {
+ ManifestContent manifestContent;
+ try {
+ manifestContent = ValidationUtil.validateManifest(globalContext);
+ } catch (Exception exception) {
+ LOGGER.error("Fialed to check Validation PreCondition ", exception);
+ return;
+ }
+ Set<String> baseFiles = validateManifest(manifestContent, globalContext);
+ Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
+ globalContext.getFiles().stream().filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName)))
+ .forEach(fileName -> validate(fileName, fileTypeMap, baseFiles, globalContext));
}
- validateBaseFile(fileName, baseFiles, heatOrchestrationTemplate, globalContext);
- validateHeatVolumeFile(fileName, fileTypeMap, heatOrchestrationTemplate, globalContext);
- }
-
-
- private void validateBaseFile(String fileName, Set<String> baseFiles,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- //if not base return
- if (baseFiles == null || !baseFiles.contains(fileName)) {
- return;
- }
-
- //if no resources exist return
- if (heatOrchestrationTemplate.getResources() == null
- || heatOrchestrationTemplate.getResources().size() == 0) {
- return;
- }
-
- Set<String> expectedExposedResources = new HashSet<>();
- heatOrchestrationTemplate.getResources()
- .entrySet()
- .stream()
- .filter(entry -> ValidationUtil.isExpectedToBeExposed(entry.getValue().getType()))
- .forEach(entry -> expectedExposedResources.add(entry.getKey()));
- Set<String> actualExposedResources = new HashSet<>();
-
- if (heatOrchestrationTemplate.getOutputs() != null) {
- globalContext.setMessageCode(ERROR_CODE_SRG_6);
- heatOrchestrationTemplate.getOutputs().entrySet()
- .stream()
- .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(),
- globalContext))
- .forEach(entry -> actualExposedResources.add(
- getResourceIdFromPropertyValue(fileName, entry.getValue().getValue(),
- globalContext)));
- }
- ValidationUtil.removeExposedResourcesCalledByGetResource(fileName, actualExposedResources,
- heatOrchestrationTemplate, globalContext);
-
- actualExposedResources.forEach(expectedExposedResources::remove);
-
- if (CollectionUtils.isNotEmpty(expectedExposedResources)) {
- expectedExposedResources
- .stream()
- .forEach(name -> globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_SRG_1,
- Messages.RESOURCE_NOT_DEFINED_IN_OUTPUT.getErrorMessage(),
- name)));
+ private Set<String> validateManifest(ManifestContent manifestContent, GlobalValidationContext globalContext) {
+ Set<String> baseFiles = ManifestUtil.getBaseFiles(manifestContent);
+ if (baseFiles == null || baseFiles.isEmpty()) {
+ globalContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_SRG_3, Messages.MISSIN_BASE_HEAT_FILE.getErrorMessage()));
+ } else if (baseFiles.size() > 1) {
+ String baseFileList = getElementListAsString(baseFiles);
+ globalContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_SRG_4, Messages.MULTI_BASE_HEAT_FILE.getErrorMessage(), baseFileList));
+ }
+ return baseFiles;
}
- }
- private void validateHeatVolumeFile(String fileName, Map<String, FileData.Type> fileTypeMap,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- //if not heat volume return
- if (!fileTypeMap.get(fileName).equals(FileData.Type.HEAT_VOL)) {
- return;
+ private void validate(String fileName, Map<String, FileData.Type> fileTypeMap, Set<String> baseFiles, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_SRG_5);
+ HeatOrchestrationTemplate heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ if (heatOrchestrationTemplate == null) {
+ return;
+ }
+ validateBaseFile(fileName, baseFiles, heatOrchestrationTemplate, globalContext);
+ validateHeatVolumeFile(fileName, fileTypeMap, heatOrchestrationTemplate, globalContext);
}
- //if no resources exist return
- if (heatOrchestrationTemplate.getResources() == null
- || heatOrchestrationTemplate.getResources().size() == 0) {
- return;
+ private void validateBaseFile(String fileName, Set<String> baseFiles, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ //if not base return
+ if (baseFiles == null || !baseFiles.contains(fileName)) {
+ return;
+ }
+ //if no resources exist return
+ if (heatOrchestrationTemplate.getResources() == null || heatOrchestrationTemplate.getResources().size() == 0) {
+ return;
+ }
+ Set<String> expectedExposedResources = new HashSet<>();
+ heatOrchestrationTemplate.getResources().entrySet().stream().filter(entry -> ValidationUtil.isExpectedToBeExposed(entry.getValue().getType()))
+ .forEach(entry -> expectedExposedResources.add(entry.getKey()));
+ Set<String> actualExposedResources = new HashSet<>();
+ if (heatOrchestrationTemplate.getOutputs() != null) {
+ globalContext.setMessageCode(ERROR_CODE_SRG_6);
+ heatOrchestrationTemplate.getOutputs().entrySet().stream()
+ .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(), globalContext))
+ .forEach(entry -> actualExposedResources.add(getResourceIdFromPropertyValue(fileName, entry.getValue().getValue(), globalContext)));
+ }
+ ValidationUtil.removeExposedResourcesCalledByGetResource(fileName, actualExposedResources, heatOrchestrationTemplate, globalContext);
+ actualExposedResources.forEach(expectedExposedResources::remove);
+ if (CollectionUtils.isNotEmpty(expectedExposedResources)) {
+ expectedExposedResources.stream().forEach(name -> globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_SRG_1, Messages.RESOURCE_NOT_DEFINED_IN_OUTPUT.getErrorMessage(), name)));
+ }
}
- Set<String> expectedExposedResources = new HashSet<>();
- Set<String> actualExposedResources = new HashSet<>();
- heatOrchestrationTemplate.getResources()
- .entrySet()
- .stream()
- .filter(entry -> entry.getValue().getType()
- .equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()))
- .forEach(entry -> expectedExposedResources.add(entry.getKey()));
-
- if (heatOrchestrationTemplate.getOutputs() != null) {
- globalContext.setMessageCode(ERROR_CODE_SRG_6);
- heatOrchestrationTemplate.getOutputs().entrySet()
- .stream()
- .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(),
- globalContext))
- .forEach(entry -> actualExposedResources.add(
- getResourceIdFromPropertyValue(fileName, entry.getValue().getValue(),
- globalContext)));
+ private void validateHeatVolumeFile(String fileName, Map<String, FileData.Type> fileTypeMap, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ //if not heat volume return
+ if (!fileTypeMap.get(fileName).equals(FileData.Type.HEAT_VOL)) {
+ return;
+ }
+ //if no resources exist return
+ if (heatOrchestrationTemplate.getResources() == null || heatOrchestrationTemplate.getResources().size() == 0) {
+ return;
+ }
+ Set<String> expectedExposedResources = new HashSet<>();
+ Set<String> actualExposedResources = new HashSet<>();
+ heatOrchestrationTemplate.getResources().entrySet().stream()
+ .filter(entry -> entry.getValue().getType().equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()))
+ .forEach(entry -> expectedExposedResources.add(entry.getKey()));
+ if (heatOrchestrationTemplate.getOutputs() != null) {
+ globalContext.setMessageCode(ERROR_CODE_SRG_6);
+ heatOrchestrationTemplate.getOutputs().entrySet().stream()
+ .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(), globalContext))
+ .forEach(entry -> actualExposedResources.add(getResourceIdFromPropertyValue(fileName, entry.getValue().getValue(), globalContext)));
+ }
+ actualExposedResources.forEach(expectedExposedResources::remove);
+ if (CollectionUtils.isNotEmpty(expectedExposedResources)) {
+ expectedExposedResources.stream().forEach(name -> globalContext.addMessage(fileName, ErrorLevel.WARNING,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_SRG_2, Messages.VOLUME_HEAT_NOT_EXPOSED.getErrorMessage(), name)));
+ }
}
- actualExposedResources.forEach(expectedExposedResources::remove);
-
- if (CollectionUtils.isNotEmpty(expectedExposedResources)) {
- expectedExposedResources
- .stream()
- .forEach(name -> globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_SRG_2,
- Messages.VOLUME_HEAT_NOT_EXPOSED.getErrorMessage(), name)));
+ private boolean isPropertyValueGetResource(String filename, Object value, GlobalValidationContext globalContext) {
+ Set<String> referenceValues = HeatStructureUtil
+ .getReferencedValuesByFunctionName(filename, ResourceReferenceFunctions.GET_RESOURCE.getFunction(), value, globalContext);
+ return referenceValues != null && (CollectionUtils.isNotEmpty(referenceValues));
}
- }
-
- private boolean isPropertyValueGetResource(String filename, Object value,
- GlobalValidationContext globalContext) {
- Set<String> referenceValues = HeatStructureUtil.getReferencedValuesByFunctionName(filename,
- ResourceReferenceFunctions.GET_RESOURCE.getFunction(), value, globalContext);
- return referenceValues != null && (CollectionUtils.isNotEmpty(referenceValues));
- }
-
- private String getResourceIdFromPropertyValue(String filename, Object value,
- GlobalValidationContext globalContext) {
- Set<String> referenceValues = HeatStructureUtil.getReferencedValuesByFunctionName(filename,
- ResourceReferenceFunctions.GET_RESOURCE.getFunction(), value, globalContext);
- if (referenceValues != null && CollectionUtils.isNotEmpty(referenceValues)) {
- return (String) referenceValues.toArray()[0];
+ private String getResourceIdFromPropertyValue(String filename, Object value, GlobalValidationContext globalContext) {
+ Set<String> referenceValues = HeatStructureUtil
+ .getReferencedValuesByFunctionName(filename, ResourceReferenceFunctions.GET_RESOURCE.getFunction(), value, globalContext);
+ if (referenceValues != null && CollectionUtils.isNotEmpty(referenceValues)) {
+ return (String) referenceValues.toArray()[0];
+ }
+ return null;
}
- return null;
- }
-
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java
index c433c3e7d4..cb9469a146 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java
@@ -14,9 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import org.onap.sdc.tosca.services.MyPropertyUtils;
import org.onap.sdc.tosca.services.StrictMapAppenderConstructor;
import org.openecomp.core.validation.ErrorMessageCode;
@@ -33,24 +37,16 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.representer.Representer;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
public class YamlValidator implements Validator {
+
private static final ErrorMessageCode ERROR_CODE_YML_1 = new ErrorMessageCode("YML1");
private static final ErrorMessageCode ERROR_CODE_YML_2 = new ErrorMessageCode("YML2");
@Override
public void validate(GlobalValidationContext globalContext) {
Set<String> pmDictionaryFiles = GlobalContextUtil.findPmDictionaryFiles(globalContext);
-
- Collection<String> files = globalContext.files(
- (fileName, globalValidationContext) -> FileExtensionUtils.isYaml(fileName)
- && !pmDictionaryFiles.contains(fileName));
-
+ Collection<String> files = globalContext
+ .files((fileName, globalValidationContext) -> FileExtensionUtils.isYaml(fileName) && !pmDictionaryFiles.contains(fileName));
files.forEach(fileName -> validate(fileName, globalContext));
}
@@ -58,9 +54,8 @@ public class YamlValidator implements Validator {
Optional<InputStream> rowContent = globalContext.getFileContent(fileName);
if (rowContent.isEmpty()) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_YML_1, Messages
- .INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- Messages.EMPTY_YAML_FILE.getErrorMessage()));
+ .getErrorWithParameters(ERROR_CODE_YML_1, Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
+ Messages.EMPTY_YAML_FILE.getErrorMessage()));
return; /* no need to continue validation */
}
@@ -80,10 +75,11 @@ public class YamlValidator implements Validator {
}
} catch (Exception exception) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_YML_2, Messages
- .INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- YamlValidatorUtil.getParserExceptionReason(exception)));
+ .getErrorWithParameters(ERROR_CODE_YML_2, Messages
+ .INVALID_YAML_FORMAT_REASON.getErrorMessage(),
+ YamlValidatorUtil.getParserExceptionReason(exception)));
}
}
}
+
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ContrailNetworkPolicyResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ContrailNetworkPolicyResourceValidator.java
index 190ae3d2c0..a7b1f47862 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ContrailNetworkPolicyResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ContrailNetworkPolicyResourceValidator.java
@@ -19,6 +19,8 @@
*/
package org.openecomp.sdc.validation.impl.validators.heatresource;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -32,70 +34,45 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
import org.openecomp.sdc.validation.type.ValidatorConstants;
-import java.util.List;
-import java.util.Map;
-
/**
* Created by TALIO on 2/28/2017.
*/
public class ContrailNetworkPolicyResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_HNP1 = new ErrorMessageCode("HNP1");
- private static final ErrorMessageCode ERROR_CODE_HNP2 = new ErrorMessageCode("HNP2");
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- validateNetworkPolicyIsUsed(fileName, resourceEntry, globalContext,
- (HeatResourceValidationContext) validationContext);
- }
+ private static final ErrorMessageCode ERROR_CODE_HNP1 = new ErrorMessageCode("HNP1");
+ private static final ErrorMessageCode ERROR_CODE_HNP2 = new ErrorMessageCode("HNP2");
- private static void validateNetworkPolicyIsUsed(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- HeatResourceValidationContext validationContext) {
- Map<String, Map<String, List<String>>> referencedNetworkAttachPoliciesResources =
- validationContext.getFileLevelResourceDependencies()
- .get(HeatResourcesTypes.CONTRAIL_NETWORK_RULE_RESOURCE_TYPE.getHeatResource());
-
- if (MapUtils.isEmpty(referencedNetworkAttachPoliciesResources)) {
- globalContext
- .addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNP1,
- Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
- ValidatorConstants.Network_Policy, resourceEntry.getKey()));
- return;
+ private static void validateNetworkPolicyIsUsed(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ HeatResourceValidationContext validationContext) {
+ Map<String, Map<String, List<String>>> referencedNetworkAttachPoliciesResources = validationContext.getFileLevelResourceDependencies()
+ .get(HeatResourcesTypes.CONTRAIL_NETWORK_RULE_RESOURCE_TYPE.getHeatResource());
+ if (MapUtils.isEmpty(referencedNetworkAttachPoliciesResources)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNP1, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), ValidatorConstants.Network_Policy,
+ resourceEntry.getKey()));
+ return;
+ }
+ handleNetworkAttachPolicyReferences(fileName, resourceEntry, referencedNetworkAttachPoliciesResources, globalContext);
}
- handleNetworkAttachPolicyReferences(fileName, resourceEntry,
- referencedNetworkAttachPoliciesResources, globalContext);
- }
-
- private static void handleNetworkAttachPolicyReferences(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- Map<String, Map<String, List<String>>> pointedNetworkAttachPolicies,
- GlobalValidationContext globalContext) {
-
- Map<String, List<String>> resourcesPointingToCurrNetworkAttachPolicy =
- pointedNetworkAttachPolicies.get(resourceEntry.getKey());
- if (isNetworkAttachPolicyNotInUse(resourcesPointingToCurrNetworkAttachPolicy)) {
- globalContext
- .addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNP2,
- Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
- ValidatorConstants.Network_Policy, resourceEntry.getKey()));
+ private static void handleNetworkAttachPolicyReferences(String fileName, Map.Entry<String, Resource> resourceEntry,
+ Map<String, Map<String, List<String>>> pointedNetworkAttachPolicies,
+ GlobalValidationContext globalContext) {
+ Map<String, List<String>> resourcesPointingToCurrNetworkAttachPolicy = pointedNetworkAttachPolicies.get(resourceEntry.getKey());
+ if (isNetworkAttachPolicyNotInUse(resourcesPointingToCurrNetworkAttachPolicy)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNP2, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), ValidatorConstants.Network_Policy,
+ resourceEntry.getKey()));
+ }
}
- }
- private static boolean isNetworkAttachPolicyNotInUse(
- Map<String, List<String>> resourcesPointingToCurrNetworkAttachPolicy) {
- return MapUtils.isEmpty(resourcesPointingToCurrNetworkAttachPolicy);
- }
+ private static boolean isNetworkAttachPolicyNotInUse(Map<String, List<String>> resourcesPointingToCurrNetworkAttachPolicy) {
+ return MapUtils.isEmpty(resourcesPointingToCurrNetworkAttachPolicy);
+ }
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ validateNetworkPolicyIsUsed(fileName, resourceEntry, globalContext, (HeatResourceValidationContext) validationContext);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java
index 4a5a996777..06d1f8942f 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
import java.util.ArrayList;
@@ -22,7 +21,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -38,64 +36,48 @@ import org.openecomp.sdc.validation.impl.util.HeatValidationService;
* Created by TALIO on 2/22/2017.
*/
public class NestedResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_HNR1 = new ErrorMessageCode("HNR1");
- private static final ErrorMessageCode ERROR_CODE_HNR2 = new ErrorMessageCode("HNR2");
- private static final ErrorMessageCode ERROR_CODE_HNR3 = new ErrorMessageCode("HNR3");
- private static final ErrorMessageCode ERROR_CODE_HNR4 = new ErrorMessageCode("HNR4");
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
+ private static final ErrorMessageCode ERROR_CODE_HNR1 = new ErrorMessageCode("HNR1");
+ private static final ErrorMessageCode ERROR_CODE_HNR2 = new ErrorMessageCode("HNR2");
+ private static final ErrorMessageCode ERROR_CODE_HNR3 = new ErrorMessageCode("HNR3");
+ private static final ErrorMessageCode ERROR_CODE_HNR4 = new ErrorMessageCode("HNR4");
- handleNestedResourceType(fileName, resourceEntry.getKey(), resourceEntry.getValue(),
- Optional.empty(), globalContext);
- }
+ private static void handleNestedResourceType(String fileName, String resourceName, Resource resource, Optional<String> indexVarValue,
+ GlobalValidationContext globalContext) {
+ validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue, globalContext);
+ validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
+ }
- private static void handleNestedResourceType(String fileName, String resourceName,
- Resource resource, Optional<String> indexVarValue,
- GlobalValidationContext globalContext) {
- validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue,
- globalContext);
- validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
- }
+ public static void validateAllPropertiesMatchNestedParameters(String fileName, String resourceName, Resource resource,
+ Optional<String> indexVarValue, GlobalValidationContext globalContext) {
+ String resourceType = resource.getType();
+ if (globalContext.getFileContextMap().containsKey(resourceType)) {
+ Set<String> propertiesNames = resource.getProperties() == null ? null : resource.getProperties().keySet();
+ if (CollectionUtils.isNotEmpty(propertiesNames)) {
+ globalContext.setMessageCode(ERROR_CODE_HNR3);
+ HeatValidationService
+ .checkNestedParametersNoMissingParameterInNested(fileName, resourceType, resourceName, propertiesNames, globalContext);
+ globalContext.setMessageCode(ERROR_CODE_HNR4);
+ HeatValidationService
+ .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource, indexVarValue, globalContext);
+ }
+ } else {
+ globalContext.addMessage(resourceType, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_HNR1, Messages.MISSING_NESTED_FILE.getErrorMessage(), resourceType));
+ }
+ }
- public static void validateAllPropertiesMatchNestedParameters(String fileName,
- String resourceName,
- Resource resource,
- Optional<String> indexVarValue,
- GlobalValidationContext
- globalContext) {
- String resourceType = resource.getType();
- if (globalContext.getFileContextMap().containsKey(resourceType)) {
- Set<String> propertiesNames =
- resource.getProperties() == null ? null : resource.getProperties().keySet();
- if (CollectionUtils.isNotEmpty(propertiesNames)) {
- globalContext.setMessageCode(ERROR_CODE_HNR3);
- HeatValidationService
- .checkNestedParametersNoMissingParameterInNested(fileName, resourceType, resourceName,
- propertiesNames,
- globalContext);
- globalContext.setMessageCode(ERROR_CODE_HNR4);
- HeatValidationService
- .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource,
- indexVarValue, globalContext);
- }
- } else {
- globalContext.addMessage(resourceType, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNR1,
- Messages.MISSING_NESTED_FILE.getErrorMessage(),
- resourceType));
+ public static void validateLoopsOfNestingFromFile(String fileName, String resourceType, GlobalValidationContext globalContext) {
+ List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
+ if (HeatValidationService.isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNR2, Messages.NESTED_LOOP.getErrorMessage(), HeatValidationService.drawFilesLoop(filesInLoop)));
+ }
}
- }
- public static void validateLoopsOfNestingFromFile(String fileName, String resourceType,
- GlobalValidationContext globalContext) {
- List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
- if (HeatValidationService
- .isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNR2, Messages.NESTED_LOOP.getErrorMessage(),
- HeatValidationService.drawFilesLoop(filesInLoop)));
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ handleNestedResourceType(fileName, resourceEntry.getKey(), resourceEntry.getValue(), Optional.empty(), globalContext);
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java
index a21173a6b2..08177a158e 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
import java.util.ArrayList;
@@ -33,90 +32,57 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
public class NeutronPortResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_HPRODE_HPR1 = new ErrorMessageCode("HPR1");
- private static final ErrorMessageCode ERROR_HPRODE_HPR2 = new ErrorMessageCode("HPR2");
- private static final ErrorMessageCode ERROR_HPRODE_HPR3 = new ErrorMessageCode("HPR3");
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
-
- validateNovaServerPortBinding(fileName,
- resourceEntry, (HeatResourceValidationContext) validationContext, globalContext);
- }
-
- @SuppressWarnings("unchecked")
- private static void validateNovaServerPortBinding(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- HeatResourceValidationContext heatResourceValidationContext,
- GlobalValidationContext globalContext) {
- Map<String, Map<String, List<String>>> portIdToPointingResources =
- heatResourceValidationContext.getFileLevelResourceDependencies()
- .get(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource());
-
- String portResourceId = resourceEntry.getKey();
- if (MapUtils.isEmpty(portIdToPointingResources)) {
- globalContext
- .addMessage(fileName, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_HPRODE_HPR1, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(),
- portResourceId));
-
- return;
+ private static final ErrorMessageCode ERROR_HPRODE_HPR1 = new ErrorMessageCode("HPR1");
+ private static final ErrorMessageCode ERROR_HPRODE_HPR2 = new ErrorMessageCode("HPR2");
+ private static final ErrorMessageCode ERROR_HPRODE_HPR3 = new ErrorMessageCode("HPR3");
+
+ @SuppressWarnings("unchecked")
+ private static void validateNovaServerPortBinding(String fileName, Map.Entry<String, Resource> resourceEntry,
+ HeatResourceValidationContext heatResourceValidationContext,
+ GlobalValidationContext globalContext) {
+ Map<String, Map<String, List<String>>> portIdToPointingResources = heatResourceValidationContext.getFileLevelResourceDependencies()
+ .get(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource());
+ String portResourceId = resourceEntry.getKey();
+ if (MapUtils.isEmpty(portIdToPointingResources)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_HPRODE_HPR1, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), portResourceId));
+ return;
+ }
+ Map<String, List<String>> pointingResourcesToCurrPort = portIdToPointingResources.get(portResourceId);
+ checkPortBindingFromMap(fileName, portResourceId, pointingResourcesToCurrPort, globalContext);
}
- Map<String, List<String>> pointingResourcesToCurrPort =
- portIdToPointingResources.get(portResourceId);
- checkPortBindingFromMap(
- fileName, portResourceId, pointingResourcesToCurrPort, globalContext);
- }
-
- private static void checkPortBindingFromMap(String fileName,
- String portResourceId,
- Map<String, List<String>> resourcesPointingToCurrPort,
- GlobalValidationContext globalContext) {
- List<String> pointingNovaServers =
- MapUtils.isEmpty(resourcesPointingToCurrPort) ? new ArrayList<>()
- : resourcesPointingToCurrPort.get(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource());
-
- handleErrorEventsForPortBinding(
- fileName, portResourceId, globalContext, pointingNovaServers);
-
-
- }
+ private static void checkPortBindingFromMap(String fileName, String portResourceId, Map<String, List<String>> resourcesPointingToCurrPort,
+ GlobalValidationContext globalContext) {
+ List<String> pointingNovaServers = MapUtils.isEmpty(resourcesPointingToCurrPort) ? new ArrayList<>()
+ : resourcesPointingToCurrPort.get(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource());
+ handleErrorEventsForPortBinding(fileName, portResourceId, globalContext, pointingNovaServers);
+ }
- private static void handleErrorEventsForPortBinding(String fileName,
- String portResourceId,
- GlobalValidationContext globalContext,
- List<String> pointingNovaServers) {
- if (isThereMoreThanOneBindFromNovaToPort(pointingNovaServers)) {
- globalContext
- .addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_HPRODE_HPR2,
- Messages.MORE_THAN_ONE_BIND_FROM_NOVA_TO_PORT.getErrorMessage(),
- portResourceId));
+ private static void handleErrorEventsForPortBinding(String fileName, String portResourceId, GlobalValidationContext globalContext,
+ List<String> pointingNovaServers) {
+ if (isThereMoreThanOneBindFromNovaToPort(pointingNovaServers)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_HPRODE_HPR2, Messages.MORE_THAN_ONE_BIND_FROM_NOVA_TO_PORT.getErrorMessage(), portResourceId));
+ }
+ if (isNoNovaPointingToPort(pointingNovaServers)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_HPRODE_HPR3, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), portResourceId));
+ }
}
- if (isNoNovaPointingToPort(pointingNovaServers)) {
- globalContext
- .addMessage(fileName, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_HPRODE_HPR3, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(),
- portResourceId));
+ private static boolean isNoNovaPointingToPort(List<String> pointingNovaServers) {
+ return CollectionUtils.isEmpty(pointingNovaServers);
}
- }
- private static boolean isNoNovaPointingToPort(List<String> pointingNovaServers) {
- return CollectionUtils.isEmpty(pointingNovaServers);
- }
+ private static boolean isThereMoreThanOneBindFromNovaToPort(List<String> pointingNovaServers) {
+ return CollectionUtils.isNotEmpty(pointingNovaServers) && pointingNovaServers.size() > 1;
+ }
- private static boolean isThereMoreThanOneBindFromNovaToPort(List<String> pointingNovaServers) {
- return CollectionUtils.isNotEmpty(pointingNovaServers)
- && pointingNovaServers.size() > 1;
- }
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ validateNovaServerPortBinding(fileName, resourceEntry, (HeatResourceValidationContext) validationContext, globalContext);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronSecurityGroupResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronSecurityGroupResourceValidator.java
index d9ba1aeaed..48a6d01143 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronSecurityGroupResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronSecurityGroupResourceValidator.java
@@ -19,6 +19,8 @@
*/
package org.openecomp.sdc.validation.impl.validators.heatresource;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -32,56 +34,36 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
import org.openecomp.sdc.validation.type.ValidatorConstants;
-import java.util.List;
-import java.util.Map;
-
/**
* Created by TALIO on 2/27/2017.
*/
public class NeutronSecurityGroupResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_HSG1 = new ErrorMessageCode("HSG1");
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- HeatResourceValidationContext heatResourceValidationContext =
- (HeatResourceValidationContext) validationContext;
- validateSecurityGroupIsUsed(fileName, resourceEntry, heatResourceValidationContext,
- globalContext);
- }
+ private static final ErrorMessageCode ERROR_CODE_HSG1 = new ErrorMessageCode("HSG1");
- private void validateSecurityGroupIsUsed(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- HeatResourceValidationContext
- heatResourceValidationContext,
- GlobalValidationContext globalContext) {
-
- Map<String, Map<String, List<String>>> securityGroupsPointedByOtherResources =
- heatResourceValidationContext.getFileLevelResourceDependencies()
- .get(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
-
- if (MapUtils.isEmpty(securityGroupsPointedByOtherResources)) {
- return;
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ HeatResourceValidationContext heatResourceValidationContext = (HeatResourceValidationContext) validationContext;
+ validateSecurityGroupIsUsed(fileName, resourceEntry, heatResourceValidationContext, globalContext);
}
- Map<String, List<String>> resourcesPointingCurrSecurityGroup =
- securityGroupsPointedByOtherResources.get(resourceEntry.getKey());
-
- if (isSecurityGroupNotInUse(resourcesPointingCurrSecurityGroup)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HSG1, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
- ValidatorConstants.Security_Group, resourceEntry.getKey()));
+ private void validateSecurityGroupIsUsed(String fileName, Map.Entry<String, Resource> resourceEntry,
+ HeatResourceValidationContext heatResourceValidationContext, GlobalValidationContext globalContext) {
+ Map<String, Map<String, List<String>>> securityGroupsPointedByOtherResources = heatResourceValidationContext
+ .getFileLevelResourceDependencies().get(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource());
+ if (MapUtils.isEmpty(securityGroupsPointedByOtherResources)) {
+ return;
+ }
+ Map<String, List<String>> resourcesPointingCurrSecurityGroup = securityGroupsPointedByOtherResources.get(resourceEntry.getKey());
+ if (isSecurityGroupNotInUse(resourcesPointingCurrSecurityGroup)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HSG1, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), ValidatorConstants.Security_Group,
+ resourceEntry.getKey()));
+ }
}
- }
-
- private boolean isSecurityGroupNotInUse(Map<String, List<String>>
- referencingResourcesToCurrSecurityGroup) {
- return MapUtils.isEmpty(referencingResourcesToCurrSecurityGroup);
- }
+ private boolean isSecurityGroupNotInUse(Map<String, List<String>> referencingResourcesToCurrSecurityGroup) {
+ return MapUtils.isEmpty(referencingResourcesToCurrSecurityGroup);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java
index 72226d96f4..6083670481 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -30,100 +32,69 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
import org.openecomp.sdc.validation.type.ValidatorConstants;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
public class NovaServerGroupResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_HNG1 = new ErrorMessageCode("HNG1");
- private static final ErrorMessageCode ERROR_CODE_HNG2 = new ErrorMessageCode("HNG2");
- private static final ErrorMessageCode ERROR_CODE_HNG3 = new ErrorMessageCode("HNG3");
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- validateNovaServerGroupPolicy(fileName, resourceEntry, globalContext);
- validateServerGroupIsUsed(fileName, resourceEntry, globalContext,
- (HeatResourceValidationContext) validationContext);
- }
+ private static final ErrorMessageCode ERROR_CODE_HNG1 = new ErrorMessageCode("HNG1");
+ private static final ErrorMessageCode ERROR_CODE_HNG2 = new ErrorMessageCode("HNG2");
+ private static final ErrorMessageCode ERROR_CODE_HNG3 = new ErrorMessageCode("HNG3");
- @SuppressWarnings("unchecked")
- private static void validateNovaServerGroupPolicy(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- Resource resource = resourceEntry.getValue();
- Object policies =
- resource.getProperties() == null ? null : resource.getProperties().get("policies");
-
- if (Objects.nonNull(policies) && policies instanceof List) {
- List<Object> policiesList = (List<Object>) policies;
- if (policiesList.size() == 1) {
- Object policy = policiesList.get(0);
- if (!isGivenPolicyValid(policy)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HNG1, Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(),
- resourceEntry.getKey()));
+ @SuppressWarnings("unchecked")
+ private static void validateNovaServerGroupPolicy(String fileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ Resource resource = resourceEntry.getValue();
+ Object policies = resource.getProperties() == null ? null : resource.getProperties().get("policies");
+ if (Objects.nonNull(policies) && policies instanceof List) {
+ List<Object> policiesList = (List<Object>) policies;
+ if (policiesList.size() == 1) {
+ Object policy = policiesList.get(0);
+ if (!isGivenPolicyValid(policy)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNG1, Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(), resourceEntry.getKey()));
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNG1, Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(), resourceEntry.getKey()));
+ }
}
- } else {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNG1,
- Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(),
- resourceEntry.getKey()));
- }
}
- }
- private static boolean isGivenPolicyValid(Object policy) {
- if (policy instanceof Map) {
- return true;
- }
- if (policy instanceof String) {
- return PolicyTypes.isGivenPolicyValid((String) policy);
+ private static boolean isGivenPolicyValid(Object policy) {
+ if (policy instanceof Map) {
+ return true;
+ }
+ if (policy instanceof String) {
+ return PolicyTypes.isGivenPolicyValid((String) policy);
+ }
+ return false;
}
- return false;
- }
-
- public void validateServerGroupIsUsed(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- HeatResourceValidationContext validationContext) {
- Map<String, Map<String, List<String>>> pointedServerGroups =
- validationContext.getFileLevelResourceDependencies().get(HeatResourcesTypes
- .NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource());
-
- if (MapUtils.isEmpty(pointedServerGroups)) {
- globalContext
- .addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HNG2, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
- ValidatorConstants.Server_Group, resourceEntry.getKey()));
- return;
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ validateNovaServerGroupPolicy(fileName, resourceEntry, globalContext);
+ validateServerGroupIsUsed(fileName, resourceEntry, globalContext, (HeatResourceValidationContext) validationContext);
}
- handleServerGroupReferences(fileName, resourceEntry, pointedServerGroups, globalContext);
- }
-
- private void handleServerGroupReferences(String fileName, Map.Entry<String, Resource>
- resourceEntry, Map<String, Map<String, List<String>>> pointedServerGroups,
- GlobalValidationContext globalContext) {
- Map<String, List<String>> resourcesPointingToCurrServerGroup =
- pointedServerGroups.get(resourceEntry.getKey());
-
- if (MapUtils.isEmpty(resourcesPointingToCurrServerGroup)) {
- globalContext
- .addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HNG3, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(),
- ValidatorConstants.Server_Group, resourceEntry.getKey()));
+ public void validateServerGroupIsUsed(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ HeatResourceValidationContext validationContext) {
+ Map<String, Map<String, List<String>>> pointedServerGroups = validationContext.getFileLevelResourceDependencies()
+ .get(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource());
+ if (MapUtils.isEmpty(pointedServerGroups)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNG2, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), ValidatorConstants.Server_Group,
+ resourceEntry.getKey()));
+ return;
+ }
+ handleServerGroupReferences(fileName, resourceEntry, pointedServerGroups, globalContext);
}
- }
+ private void handleServerGroupReferences(String fileName, Map.Entry<String, Resource> resourceEntry,
+ Map<String, Map<String, List<String>>> pointedServerGroups, GlobalValidationContext globalContext) {
+ Map<String, List<String>> resourcesPointingToCurrServerGroup = pointedServerGroups.get(resourceEntry.getKey());
+ if (MapUtils.isEmpty(resourcesPointingToCurrServerGroup)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNG3, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), ValidatorConstants.Server_Group,
+ resourceEntry.getKey()));
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java
index d261c8e9eb..bf5f1256d5 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java
@@ -13,102 +13,86 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
+import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
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.*;
+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.validation.ResourceValidator;
import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
-import java.util.Map;
-
public class NovaServerResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_HNS1 = new ErrorMessageCode("HNS1");
- private static final ErrorMessageCode ERROR_CODE_HNS2 = new ErrorMessageCode("HNS2");
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
+ private static final ErrorMessageCode ERROR_CODE_HNS1 = new ErrorMessageCode("HNS1");
+ private static final ErrorMessageCode ERROR_CODE_HNS2 = new ErrorMessageCode("HNS2");
- HeatResourceValidationContext heatResourceValidationContext = (HeatResourceValidationContext)
- validationContext;
- validateNovaServerResourceType (fileName,
- resourceEntry, heatResourceValidationContext, globalContext );
- }
-
- private static void validateNovaServerResourceType(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- HeatResourceValidationContext heatResourceValidationContext,
- GlobalValidationContext globalContext) {
- validateAssignedValueForImageOrFlavorFromNova(fileName, resourceEntry, globalContext);
- validateAllServerGroupsPointedByServerExistAndDefined (fileName,
- resourceEntry, heatResourceValidationContext.getHeatOrchestrationTemplate(), globalContext );
- }
-
- private static void validateAssignedValueForImageOrFlavorFromNova(String fileName,
- Map.Entry<String, Resource>
- resourceEntry,
- GlobalValidationContext
- globalContext) {
- Resource resource = resourceEntry.getValue();
- Map<String, Object> propertiesMap = resource.getProperties();
- if (propertiesMap.get(PropertiesMapKeyTypes.IMAGE.getKeyMap()) == null
- && propertiesMap.get(PropertiesMapKeyTypes.FLAVOR.getKeyMap()) == null) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNS1, Messages.MISSING_IMAGE_AND_FLAVOR.getErrorMessage(),
- resourceEntry.getKey()));
+ private static void validateNovaServerResourceType(String fileName, Map.Entry<String, Resource> resourceEntry,
+ HeatResourceValidationContext heatResourceValidationContext,
+ GlobalValidationContext globalContext) {
+ validateAssignedValueForImageOrFlavorFromNova(fileName, resourceEntry, globalContext);
+ validateAllServerGroupsPointedByServerExistAndDefined(fileName, resourceEntry, heatResourceValidationContext.getHeatOrchestrationTemplate(),
+ globalContext);
}
- }
- @SuppressWarnings("unchecked")
- private static void validateAllServerGroupsPointedByServerExistAndDefined(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
- Map<String, Object> resourceProperties = resourceEntry.getValue().getProperties();
- Map<String, Object> schedulerHintsMap =
- resourceProperties == null ? null : (Map<String, Object>) resourceProperties.get(
- ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction());
-
- if (MapUtils.isEmpty(schedulerHintsMap)) {
- return;
+ private static void validateAssignedValueForImageOrFlavorFromNova(String fileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ Resource resource = resourceEntry.getValue();
+ Map<String, Object> propertiesMap = resource.getProperties();
+ if (propertiesMap.get(PropertiesMapKeyTypes.IMAGE.getKeyMap()) == null
+ && propertiesMap.get(PropertiesMapKeyTypes.FLAVOR.getKeyMap()) == null) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNS1, Messages.MISSING_IMAGE_AND_FLAVOR.getErrorMessage(), resourceEntry.getKey()));
+ }
}
- validateServerGroupValue(fileName, resourceEntry, globalContext, resourcesMap, schedulerHintsMap);
- }
-
- private static void validateServerGroupValue(String fileName, Map.Entry<String,
- Resource> resourceEntry, GlobalValidationContext globalContext,
- Map<String, Resource> resourcesMap, Map<String, Object> schedulerHintsMap) {
- if (schedulerHintsMap != null) {
- for (Object serverGroupValue : schedulerHintsMap.values()) {
- if (!(serverGroupValue instanceof Map)) {
- continue;
+ @SuppressWarnings("unchecked")
+ private static void validateAllServerGroupsPointedByServerExistAndDefined(String fileName, Map.Entry<String, Resource> resourceEntry,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
+ Map<String, Object> resourceProperties = resourceEntry.getValue().getProperties();
+ Map<String, Object> schedulerHintsMap = resourceProperties == null ? null
+ : (Map<String, Object>) resourceProperties.get(ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction());
+ if (MapUtils.isEmpty(schedulerHintsMap)) {
+ return;
}
- Map<String, Object> currentServerMap = (Map<String, Object>) serverGroupValue;
- String serverResourceName = (String) currentServerMap
- .get(ResourceReferenceFunctions.GET_RESOURCE.getFunction());
- Resource serverResource =
- serverResourceName == null || resourcesMap == null ? null
- : resourcesMap.get(serverResourceName);
+ validateServerGroupValue(fileName, resourceEntry, globalContext, resourcesMap, schedulerHintsMap);
+ }
- if (serverResource != null && !serverResource.getType()
- .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource())) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNS2,
- Messages.SERVER_NOT_DEFINED_FROM_NOVA.getErrorMessage(),
- serverResourceName, resourceEntry.getKey()));
+ private static void validateServerGroupValue(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ Map<String, Resource> resourcesMap, Map<String, Object> schedulerHintsMap) {
+ if (schedulerHintsMap != null) {
+ for (Object serverGroupValue : schedulerHintsMap.values()) {
+ if (!(serverGroupValue instanceof Map)) {
+ continue;
+ }
+ Map<String, Object> currentServerMap = (Map<String, Object>) serverGroupValue;
+ String serverResourceName = (String) currentServerMap.get(ResourceReferenceFunctions.GET_RESOURCE.getFunction());
+ Resource serverResource = serverResourceName == null || resourcesMap == null ? null : resourcesMap.get(serverResourceName);
+ if (serverResource != null && !serverResource.getType()
+ .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource())) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNS2, Messages.SERVER_NOT_DEFINED_FROM_NOVA.getErrorMessage(), serverResourceName,
+ resourceEntry.getKey()));
+ }
+ }
}
- }
}
- }
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ HeatResourceValidationContext heatResourceValidationContext = (HeatResourceValidationContext) validationContext;
+ validateNovaServerResourceType(fileName, resourceEntry, heatResourceValidationContext, globalContext);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ResourceGroupResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ResourceGroupResourceValidator.java
index be0d1e2f88..98776c65fc 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ResourceGroupResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/ResourceGroupResourceValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
import java.util.ArrayList;
@@ -23,7 +22,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -41,114 +39,81 @@ import org.openecomp.sdc.validation.impl.util.HeatValidationService;
* Created by TALIO on 2/22/2017.
*/
public class ResourceGroupResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_HRR1 = new ErrorMessageCode("HRR1");
- private static final ErrorMessageCode ERROR_CODE_HRR2 = new ErrorMessageCode("HRR2");
- private static final ErrorMessageCode ERROR_CODE_HRR3 = new ErrorMessageCode("HRR3");
- private static final ErrorMessageCode ERROR_CODE_HRR4 = new ErrorMessageCode("HRR4");
- private static final ErrorMessageCode ERROR_CODE_HRR5 = new ErrorMessageCode("HRR5");
- private static final ErrorMessageCode ERROR_CODE_HRR6 = new ErrorMessageCode("HRR6");
- private static final ErrorMessageCode ERROR_CODE_HRR7 = new ErrorMessageCode("HRR7");
- private static final ErrorMessageCode ERROR_CODE_HRR8 = new ErrorMessageCode("HRR8");
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- validateResourceGroupType(fileName, resourceEntry, globalContext);
- }
- private static void validateResourceGroupType(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_HRR6);
- HeatTreeManagerUtil
- .checkResourceTypeValid(fileName, resourceEntry.getKey(), resourceEntry.getValue(),
- globalContext);
- globalContext.setMessageCode(ERROR_CODE_HRR7);
- HeatTreeManagerUtil
- .checkResourceGroupTypeValid(fileName, resourceEntry.getKey(), resourceEntry.getValue(),
- globalContext);
- globalContext.setMessageCode(ERROR_CODE_HRR8);
- HeatTreeManagerUtil.checkIfResourceGroupTypeIsNested(fileName, resourceEntry.getKey(),
- resourceEntry.getValue(), globalContext);
- Resource resourceDef = HeatTreeManagerUtil
- .getResourceDef( resourceEntry.getValue());
-
- if (resourceDef != null && Objects.nonNull(resourceDef.getType())
- && HeatValidationService.isNestedResource(resourceDef.getType())) {
- Optional<String> indexVarValue =
- getResourceGroupIndexVarValue(resourceEntry, fileName, globalContext);
- handleNestedResourceType(fileName, resourceEntry.getKey(), resourceDef, indexVarValue,
- globalContext);
+ private static final ErrorMessageCode ERROR_CODE_HRR1 = new ErrorMessageCode("HRR1");
+ private static final ErrorMessageCode ERROR_CODE_HRR2 = new ErrorMessageCode("HRR2");
+ private static final ErrorMessageCode ERROR_CODE_HRR3 = new ErrorMessageCode("HRR3");
+ private static final ErrorMessageCode ERROR_CODE_HRR4 = new ErrorMessageCode("HRR4");
+ private static final ErrorMessageCode ERROR_CODE_HRR5 = new ErrorMessageCode("HRR5");
+ private static final ErrorMessageCode ERROR_CODE_HRR6 = new ErrorMessageCode("HRR6");
+ private static final ErrorMessageCode ERROR_CODE_HRR7 = new ErrorMessageCode("HRR7");
+ private static final ErrorMessageCode ERROR_CODE_HRR8 = new ErrorMessageCode("HRR8");
+ private static void validateResourceGroupType(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_HRR6);
+ HeatTreeManagerUtil.checkResourceTypeValid(fileName, resourceEntry.getKey(), resourceEntry.getValue(), globalContext);
+ globalContext.setMessageCode(ERROR_CODE_HRR7);
+ HeatTreeManagerUtil.checkResourceGroupTypeValid(fileName, resourceEntry.getKey(), resourceEntry.getValue(), globalContext);
+ globalContext.setMessageCode(ERROR_CODE_HRR8);
+ HeatTreeManagerUtil.checkIfResourceGroupTypeIsNested(fileName, resourceEntry.getKey(), resourceEntry.getValue(), globalContext);
+ Resource resourceDef = HeatTreeManagerUtil.getResourceDef(resourceEntry.getValue());
+ if (resourceDef != null && Objects.nonNull(resourceDef.getType()) && HeatValidationService.isNestedResource(resourceDef.getType())) {
+ Optional<String> indexVarValue = getResourceGroupIndexVarValue(resourceEntry, fileName, globalContext);
+ handleNestedResourceType(fileName, resourceEntry.getKey(), resourceDef, indexVarValue, globalContext);
+ }
}
- }
- private static Optional<String> getResourceGroupIndexVarValue(
- Map.Entry<String, Resource> resourceEntry, String fileName,
- GlobalValidationContext globalContext) {
- Object indexVar =
- resourceEntry.getValue().getProperties().get(HeatConstants.INDEX_PROPERTY_NAME);
- if (indexVar == null) {
- return Optional.of(HeatConstants.RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE);
+ private static Optional<String> getResourceGroupIndexVarValue(Map.Entry<String, Resource> resourceEntry, String fileName,
+ GlobalValidationContext globalContext) {
+ Object indexVar = resourceEntry.getValue().getProperties().get(HeatConstants.INDEX_PROPERTY_NAME);
+ if (indexVar == null) {
+ return Optional.of(HeatConstants.RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE);
+ }
+ if (indexVar instanceof String) {
+ return Optional.of((String) indexVar);
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HRR1, Messages.RESOURCE_GROUP_INVALID_INDEX_VAR.getErrorMessage(), resourceEntry.getKey()));
+ return Optional.empty();
+ }
}
- if (indexVar instanceof String) {
- return Optional.of((String) indexVar);
- } else {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HRR1, Messages.RESOURCE_GROUP_INVALID_INDEX_VAR.getErrorMessage(),
- resourceEntry.getKey()));
- return Optional.empty();
+ private static void handleNestedResourceType(String fileName, String resourceName, Resource resource, Optional<String> indexVarValue,
+ GlobalValidationContext globalContext) {
+ validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue, globalContext);
+ validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
}
- }
- private static void handleNestedResourceType(String fileName, String resourceName,
- Resource resource, Optional<String> indexVarValue,
- GlobalValidationContext globalContext) {
- validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue,
- globalContext);
- validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
- }
+ private static void validateAllPropertiesMatchNestedParameters(String fileName, String resourceName, Resource resource,
+ Optional<String> indexVarValue, GlobalValidationContext globalContext) {
+ String resourceType = resource.getType();
+ if (globalContext.getFileContextMap().containsKey(resourceType)) {
+ Set<String> propertiesNames = resource.getProperties() == null ? null : resource.getProperties().keySet();
+ if (CollectionUtils.isNotEmpty(propertiesNames)) {
+ globalContext.setMessageCode(ERROR_CODE_HRR4);
+ HeatValidationService
+ .checkNestedParametersNoMissingParameterInNested(fileName, resourceType, resourceName, propertiesNames, globalContext);
+ globalContext.setMessageCode(ERROR_CODE_HRR5);
+ HeatValidationService
+ .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource, indexVarValue, globalContext);
+ }
+ } else {
+ globalContext.addMessage(resourceType, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_HRR2, Messages.MISSING_NESTED_FILE.getErrorMessage(), resourceType));
+ }
+ }
- private static void validateAllPropertiesMatchNestedParameters(String fileName,
- String resourceName,
- Resource resource,
- Optional<String> indexVarValue,
- GlobalValidationContext
- globalContext) {
- String resourceType = resource.getType();
- if (globalContext.getFileContextMap().containsKey(resourceType)) {
- Set<String> propertiesNames =
- resource.getProperties() == null ? null : resource.getProperties().keySet();
- if (CollectionUtils.isNotEmpty(propertiesNames)) {
- globalContext.setMessageCode(ERROR_CODE_HRR4);
- HeatValidationService
- .checkNestedParametersNoMissingParameterInNested(fileName, resourceType, resourceName,
- propertiesNames,
- globalContext);
- globalContext.setMessageCode(ERROR_CODE_HRR5);
- HeatValidationService
- .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource,
- indexVarValue, globalContext);
- }
- } else {
- globalContext.addMessage(resourceType, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HRR2, Messages.MISSING_NESTED_FILE.getErrorMessage(),
- resourceType));
+ private static void validateLoopsOfNestingFromFile(String fileName, String resourceType, GlobalValidationContext globalContext) {
+ List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
+ if (HeatValidationService.isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HRR3, Messages.NESTED_LOOP.getErrorMessage(), HeatValidationService.drawFilesLoop(filesInLoop)));
+ }
}
- }
- private static void validateLoopsOfNestingFromFile(String fileName, String resourceType,
- GlobalValidationContext globalContext) {
- List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
- if (HeatValidationService
- .isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_HRR3, Messages.NESTED_LOOP.getErrorMessage(),
- HeatValidationService.drawFilesLoop(filesInLoop)));
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ validateResourceGroupType(fileName, resourceEntry, globalContext);
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java
index 016b911c81..d1b3d9bad3 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/VirtualMachineInterfaceValidator.java
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
@@ -27,138 +29,97 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.impl.util.HeatValidationService;
import org.openecomp.sdc.validation.type.HeatResourceValidationContext;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
public class VirtualMachineInterfaceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_VLAN1 = new ErrorMessageCode("VLAN1");
- private static final ErrorMessageCode ERROR_CODE_VLAN2 = new ErrorMessageCode("VLAN2");
-
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- HeatResourceValidationContext heatResourceValidationContext =
- (HeatResourceValidationContext) validationContext;
- final ValidityStatus status = calculateValidityStatus(resourceEntry.getValue());
- switch (status) {
- case BOTH_PROPERTIES_PRESENT:
- validateHasSingleParentPort(fileName, resourceEntry, globalContext,
- heatResourceValidationContext);
- break;
- case REFS_PROPERTY_MISSING:
- globalContext
- .addMessage(fileName, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_VLAN2,
- Messages.VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY.getErrorMessage(),
- resourceEntry.getKey()));
- break;
- case VLAN_TAG_PROPERTY_MISSING:
- globalContext
- .addMessage(fileName, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_VLAN2,
- Messages.VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY.getErrorMessage(),
- resourceEntry.getKey()));
- validateHasSingleParentPort(fileName, resourceEntry, globalContext,
- heatResourceValidationContext);
- break;
- case BOTH_PROPERTIES_MISSING:
- // this is a port and not a VLAN, no further validation required
- break;
- default :
- throw new IllegalArgumentException("Received a value for which no handling is " +
- "available " + status);
- }
- }
-
- private ValidityStatus calculateValidityStatus(Resource resource) {
- Optional<Object> refsPropertyValue = getRefsPropertyValue(resource);
- Optional<Object> tagPropertyValue = getVlanTagPropertyValue(resource);
-
- if (refsPropertyValue.isPresent() && tagPropertyValue.isPresent()) {
- return ValidityStatus.BOTH_PROPERTIES_PRESENT;
- }
- if (!refsPropertyValue.isPresent() && !tagPropertyValue.isPresent()) {
- return ValidityStatus.BOTH_PROPERTIES_MISSING;
+ private static final ErrorMessageCode ERROR_CODE_VLAN1 = new ErrorMessageCode("VLAN1");
+ private static final ErrorMessageCode ERROR_CODE_VLAN2 = new ErrorMessageCode("VLAN2");
+
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ HeatResourceValidationContext heatResourceValidationContext = (HeatResourceValidationContext) validationContext;
+ final ValidityStatus status = calculateValidityStatus(resourceEntry.getValue());
+ switch (status) {
+ case BOTH_PROPERTIES_PRESENT:
+ validateHasSingleParentPort(fileName, resourceEntry, globalContext, heatResourceValidationContext);
+ break;
+ case REFS_PROPERTY_MISSING:
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_VLAN2, Messages.VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY.getErrorMessage(),
+ resourceEntry.getKey()));
+ break;
+ case VLAN_TAG_PROPERTY_MISSING:
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_VLAN2, Messages.VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY.getErrorMessage(),
+ resourceEntry.getKey()));
+ validateHasSingleParentPort(fileName, resourceEntry, globalContext, heatResourceValidationContext);
+ break;
+ case BOTH_PROPERTIES_MISSING:
+ // this is a port and not a VLAN, no further validation required
+ break;
+ default:
+ throw new IllegalArgumentException("Received a value for which no handling is " + "available " + status);
+ }
}
- return refsPropertyValue.map(o -> ValidityStatus.VLAN_TAG_PROPERTY_MISSING)
- .orElse(ValidityStatus.REFS_PROPERTY_MISSING);
- }
-
- private void validateHasSingleParentPort(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- HeatResourceValidationContext heatResourceValidationContext) {
- Object refsPropertyValue = resourceEntry.getValue().getProperties()
- .get(HeatConstants.VMI_REFS_PROPERTY_NAME);
- if (Objects.isNull(refsPropertyValue)) {
- return;
- }
- boolean hasSingleParentPort = HeatValidationService.hasSingleParentPort(fileName, globalContext,
- heatResourceValidationContext,
- refsPropertyValue);
- if (!hasSingleParentPort) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_VLAN1,
- Messages.VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT.getErrorMessage(),
- resourceEntry.getKey()));
+ private ValidityStatus calculateValidityStatus(Resource resource) {
+ Optional<Object> refsPropertyValue = getRefsPropertyValue(resource);
+ Optional<Object> tagPropertyValue = getVlanTagPropertyValue(resource);
+ if (refsPropertyValue.isPresent() && tagPropertyValue.isPresent()) {
+ return ValidityStatus.BOTH_PROPERTIES_PRESENT;
+ }
+ if (!refsPropertyValue.isPresent() && !tagPropertyValue.isPresent()) {
+ return ValidityStatus.BOTH_PROPERTIES_MISSING;
+ }
+ return refsPropertyValue.map(o -> ValidityStatus.VLAN_TAG_PROPERTY_MISSING).orElse(ValidityStatus.REFS_PROPERTY_MISSING);
}
-
- }
-
-
- private Optional<Object> getVlanTagPropertyValue(Resource resource) {
- Object vmiProperties = resource.getProperties()
- .get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME);
- if (Objects.nonNull(vmiProperties) && vmiProperties instanceof Map) {
- return Optional.ofNullable(((Map) vmiProperties)
- .get(HeatConstants.VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME));
+ private void validateHasSingleParentPort(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ HeatResourceValidationContext heatResourceValidationContext) {
+ Object refsPropertyValue = resourceEntry.getValue().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
+ if (Objects.isNull(refsPropertyValue)) {
+ return;
+ }
+ boolean hasSingleParentPort = HeatValidationService
+ .hasSingleParentPort(fileName, globalContext, heatResourceValidationContext, refsPropertyValue);
+ if (!hasSingleParentPort) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_VLAN1, Messages.VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT.getErrorMessage(), resourceEntry.getKey()));
+ }
}
- return Optional.empty();
- }
-
- private Optional<Object> getRefsPropertyValue(Resource resource) {
- Object refsProperty = resource.getProperties()
- .get(HeatConstants.VMI_REFS_PROPERTY_NAME);
- return Optional.ofNullable(refsProperty);
-
- }
+ private Optional<Object> getVlanTagPropertyValue(Resource resource) {
+ Object vmiProperties = resource.getProperties().get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME);
+ if (Objects.nonNull(vmiProperties) && vmiProperties instanceof Map) {
+ return Optional.ofNullable(((Map) vmiProperties).get(HeatConstants.VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME));
+ }
+ return Optional.empty();
+ }
- private enum ValidityStatus {
- BOTH_PROPERTIES_MISSING,
- BOTH_PROPERTIES_PRESENT,
- REFS_PROPERTY_MISSING,
- VLAN_TAG_PROPERTY_MISSING
+ private Optional<Object> getRefsPropertyValue(Resource resource) {
+ Object refsProperty = resource.getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
+ return Optional.ofNullable(refsProperty);
+ }
- }
+ private enum ValidityStatus {BOTH_PROPERTIES_MISSING, BOTH_PROPERTIES_PRESENT, REFS_PROPERTY_MISSING, VLAN_TAG_PROPERTY_MISSING}
- private enum Messages {
- VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT(
- "More than one parent port found, there should be only one parent port for a VLAN sub-interface ID [%s]"),
- VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY("VLAN Tag property " +
- "virtual_machine_interface_properties_sub_interface_vlan_tag is missing in VLAN Resource ID [%s]"),
- VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY("Parent port property virtual_machine_interface_refs " +
- "is missing in VLAN Resource ID [%s]");
+ private enum Messages {
+ // @formatter:off
+ VLAN_SUBINTERFACE_MORE_THAN_ONE_PORT("More than one parent port found, there should be only one parent port for "
+ + "a VLAN sub-interface ID [%s]"),
+ VLAN_SUBINTERFACE_MISSING_TAG_PROPERTY("VLAN Tag property virtual_machine_interface_properties_sub_interface_vlan_tag is missing "
+ + "in VLAN Resource ID [%s]"),
+ VLAN_SUBINTERFACE_MISSING_REFS_PROPERTY("Parent port property virtual_machine_interface_refs is missing in VLAN Resource ID [%s]");
+ // @formatter:on
- String getErrorMessage() {
- return errorMessage;
- }
+ private final String errorMessage;
- private final String errorMessage;
+ Messages(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
- Messages(String errorMessage) {
- this.errorMessage = errorMessage;
+ String getErrorMessage() {
+ return errorMessage;
+ }
}
-
- }
-
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java
index bd430bf2eb..a3325fae78 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceInstanceNamingConventionValidator.java
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.namingconvention;
+import static java.util.Objects.nonNull;
+
+import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -27,57 +29,40 @@ import org.openecomp.sdc.validation.ResourceValidator;
import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.Map;
-
-import static java.util.Objects.nonNull;
-
-
public class ContrailServiceInstanceNamingConventionValidator implements ResourceValidator {
- private static final String AVAILABILITY_ZONE = "availability_zone";
- private static final ErrorMessageCode ERROR_CODE_NSI1 = new ErrorMessageCode("NSI1");
- private static final ErrorMessageCode ERROR_CODE_NSI2 = new ErrorMessageCode("NSI2");
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- validateAvailabilityZoneName(fileName, resourceEntry, globalContext);
- }
+ private static final String AVAILABILITY_ZONE = "availability_zone";
+ private static final ErrorMessageCode ERROR_CODE_NSI1 = new ErrorMessageCode("NSI1");
+ private static final ErrorMessageCode ERROR_CODE_NSI2 = new ErrorMessageCode("NSI2");
- private void validateAvailabilityZoneName(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- String[] regexList = new String[]{"availability_zone_(\\d+)"};
- if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
- return;
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ validateAvailabilityZoneName(fileName, resourceEntry, globalContext);
}
- Object availabilityZoneMap =
- resourceEntry.getValue().getProperties().containsKey(AVAILABILITY_ZONE) ? resourceEntry
- .getValue().getProperties().get(AVAILABILITY_ZONE) : null;
-
- if (nonNull(availabilityZoneMap)) {
- if (availabilityZoneMap instanceof Map) {
- String availabilityZoneName = ValidationUtil
- .getWantedNameFromPropertyValueGetParam (availabilityZoneMap);
-
- if (availabilityZoneName != null && !ValidationUtil
- .evalPattern(availabilityZoneName, regexList)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_NSI1,
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- ValidationUtil.getMessagePartAccordingToResourceType(resourceEntry),
- "Availability Zone",
- availabilityZoneName, resourceEntry.getKey()));
- }
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_NSI2, Messages.MISSING_GET_PARAM.getErrorMessage(),
- AVAILABILITY_ZONE, resourceEntry.getKey()));
- }
+ private void validateAvailabilityZoneName(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
+ String[] regexList = new String[]{"availability_zone_(\\d+)"};
+ if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
+ return;
+ }
+ Object availabilityZoneMap =
+ resourceEntry.getValue().getProperties().containsKey(AVAILABILITY_ZONE) ? resourceEntry.getValue().getProperties().get(AVAILABILITY_ZONE)
+ : null;
+ if (nonNull(availabilityZoneMap)) {
+ if (availabilityZoneMap instanceof Map) {
+ String availabilityZoneName = ValidationUtil.getWantedNameFromPropertyValueGetParam(availabilityZoneMap);
+ if (availabilityZoneName != null && !ValidationUtil.evalPattern(availabilityZoneName, regexList)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NSI1, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
+ ValidationUtil.getMessagePartAccordingToResourceType(resourceEntry), "Availability Zone", availabilityZoneName,
+ resourceEntry.getKey()));
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NSI2, Messages.MISSING_GET_PARAM.getErrorMessage(), AVAILABILITY_ZONE,
+ resourceEntry.getKey()));
+ }
+ }
}
- }
-
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java
index 547e38f62b..7895c12ae2 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.namingconvention;
import static java.util.Objects.nonNull;
@@ -24,7 +23,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
-
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -39,168 +37,124 @@ import org.openecomp.sdc.validation.ResourceValidator;
import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.util.ValidationUtil;
-
public class ContrailServiceTemplateNamingConventionValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_NST1 = new ErrorMessageCode("NST1");
- private static final ErrorMessageCode ERROR_CODE_NST2 = new ErrorMessageCode("NST2");
- private static final ErrorMessageCode ERROR_CODE_NST3 = new ErrorMessageCode("NST3");
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- validateServiceTemplateImageAndFlavor(fileName, resourceEntry, globalContext);
- }
+ private static final ErrorMessageCode ERROR_CODE_NST1 = new ErrorMessageCode("NST1");
+ private static final ErrorMessageCode ERROR_CODE_NST2 = new ErrorMessageCode("NST2");
+ private static final ErrorMessageCode ERROR_CODE_NST3 = new ErrorMessageCode("NST3");
- private void validateServiceTemplateImageAndFlavor(String fileName,
- Map.Entry<String, Resource> entry,
- GlobalValidationContext globalContext) {
- if (MapUtils.isEmpty(entry.getValue().getProperties())) {
- return;
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ validateServiceTemplateImageAndFlavor(fileName, resourceEntry, globalContext);
}
- Pair<String, String> imagePair = new ImmutablePair<>("image_name", ".*_image_name");
- Pair<String, String> flavorPair = new ImmutablePair<>("flavor", ".*_flavor_name");
- List<Pair<String, String>> imageFlavorPairs = Arrays.asList(imagePair, flavorPair);
-
- Map<String, Object> propertiesMap = entry.getValue().getProperties();
-
- boolean errorExistValidatingImageOrFlavor = false;
- for (Pair<String, String> imageOrFlavor : imageFlavorPairs) {
- boolean errorExistWhenValidatingImageOrFlavorNames =
- isErrorExistWhenValidatingImageOrFlavorNames(fileName, imageOrFlavor, entry,
- propertiesMap, globalContext);
- errorExistValidatingImageOrFlavor =
- errorExistValidatingImageOrFlavor || errorExistWhenValidatingImageOrFlavorNames;
- }
-
- if (!errorExistValidatingImageOrFlavor) {
- validateServiceTemplatePropertiesValuesVmtypesAreIdentical(fileName, entry, globalContext,
- propertiesMap);
+ private void validateServiceTemplateImageAndFlavor(String fileName, Map.Entry<String, Resource> entry, GlobalValidationContext globalContext) {
+ if (MapUtils.isEmpty(entry.getValue().getProperties())) {
+ return;
+ }
+ Pair<String, String> imagePair = new ImmutablePair<>("image_name", ".*_image_name");
+ Pair<String, String> flavorPair = new ImmutablePair<>("flavor", ".*_flavor_name");
+ List<Pair<String, String>> imageFlavorPairs = Arrays.asList(imagePair, flavorPair);
+ Map<String, Object> propertiesMap = entry.getValue().getProperties();
+ boolean errorExistValidatingImageOrFlavor = false;
+ for (Pair<String, String> imageOrFlavor : imageFlavorPairs) {
+ boolean errorExistWhenValidatingImageOrFlavorNames = isErrorExistWhenValidatingImageOrFlavorNames(fileName, imageOrFlavor, entry,
+ propertiesMap, globalContext);
+ errorExistValidatingImageOrFlavor = errorExistValidatingImageOrFlavor || errorExistWhenValidatingImageOrFlavorNames;
+ }
+ if (!errorExistValidatingImageOrFlavor) {
+ validateServiceTemplatePropertiesValuesVmtypesAreIdentical(fileName, entry, globalContext, propertiesMap);
+ }
}
- }
-
- private void validateServiceTemplatePropertiesValuesVmtypesAreIdentical(String fileName,
- Map.Entry<String, Resource> entry,
- GlobalValidationContext globalContext,
- Map<String, Object> propertiesMap) {
- Pair<String, String> vmTypeImagePair = new ImmutablePair<>("image_name", "\\_image\\_name");
- Pair<String, String> vmTypeFlavorPair = new ImmutablePair<>("flavor", "\\_flavor\\_name");
- validatePropertiesValuesVmtypesAreIdentical(Arrays.asList(vmTypeImagePair, vmTypeFlavorPair),
- fileName, entry, propertiesMap, globalContext);
- }
- private void validatePropertiesValuesVmtypesAreIdentical(List<Pair> propertiesToMatch,
- String fileName,
- Map.Entry<String, Resource> resourceEntry,
- Map<String, Object> propertiesMap,
- GlobalValidationContext globalContext) {
- if (CollectionUtils.isEmpty(propertiesToMatch)) {
- return;
+ private void validateServiceTemplatePropertiesValuesVmtypesAreIdentical(String fileName, Map.Entry<String, Resource> entry,
+ GlobalValidationContext globalContext,
+ Map<String, Object> propertiesMap) {
+ Pair<String, String> vmTypeImagePair = new ImmutablePair<>("image_name", "\\_image\\_name");
+ Pair<String, String> vmTypeFlavorPair = new ImmutablePair<>("flavor", "\\_flavor\\_name");
+ validatePropertiesValuesVmtypesAreIdentical(Arrays.asList(vmTypeImagePair, vmTypeFlavorPair), fileName, entry, propertiesMap, globalContext);
}
- String previousPropertyValueValue = null;
- for (Pair propertyToMatch : propertiesToMatch) {
- Optional<String> propertyVmType =
- extractVmTypeFromProperty(fileName, resourceEntry, propertiesMap, globalContext,
- propertyToMatch);
- if (propertyVmType.isPresent()) {
- String currentPropVmType = propertyVmType.get();
- previousPropertyValueValue =
- handleFirstIteration(previousPropertyValueValue, currentPropVmType);
- if (addWarningIfCurrentVmTypeIsDifferentFromPrevious(fileName, resourceEntry, globalContext,
- previousPropertyValueValue, currentPropVmType)) {
- return;
+ private void validatePropertiesValuesVmtypesAreIdentical(List<Pair> propertiesToMatch, String fileName, Map.Entry<String, Resource> resourceEntry,
+ Map<String, Object> propertiesMap, GlobalValidationContext globalContext) {
+ if (CollectionUtils.isEmpty(propertiesToMatch)) {
+ return;
+ }
+ String previousPropertyValueValue = null;
+ for (Pair propertyToMatch : propertiesToMatch) {
+ Optional<String> propertyVmType = extractVmTypeFromProperty(fileName, resourceEntry, propertiesMap, globalContext, propertyToMatch);
+ if (propertyVmType.isPresent()) {
+ String currentPropVmType = propertyVmType.get();
+ previousPropertyValueValue = handleFirstIteration(previousPropertyValueValue, currentPropVmType);
+ if (addWarningIfCurrentVmTypeIsDifferentFromPrevious(fileName, resourceEntry, globalContext, previousPropertyValueValue,
+ currentPropVmType)) {
+ return;
+ }
+ }
}
- }
}
- }
- private boolean addWarningIfCurrentVmTypeIsDifferentFromPrevious(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- String previousPropertyValueValue,
- String currentPropVmType) {
- if (!Objects.equals(previousPropertyValueValue, currentPropVmType)) {
- globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NST1, Messages.CONTRAIL_VM_TYPE_NAME_NOT_ALIGNED_WITH_NAMING_CONVENSION
- .getErrorMessage(),
- resourceEntry.getKey()));
- return true;
+ private boolean addWarningIfCurrentVmTypeIsDifferentFromPrevious(String fileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext, String previousPropertyValueValue,
+ String currentPropVmType) {
+ if (!Objects.equals(previousPropertyValueValue, currentPropVmType)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NST1, Messages.CONTRAIL_VM_TYPE_NAME_NOT_ALIGNED_WITH_NAMING_CONVENSION.getErrorMessage(),
+ resourceEntry.getKey()));
+ return true;
+ }
+ return false;
}
- return false;
- }
-
- private boolean isErrorExistWhenValidatingImageOrFlavorNames(String fileName,
- Pair<String, String> propertyNameAndRegex,
- Map.Entry<String, Resource> resourceEntry,
- Map<String, Object> propertiesMap,
- GlobalValidationContext globalContext) {
- String propertyName = propertyNameAndRegex.getKey();
- Object nameValue = propertiesMap.get(propertyName);
- String[] regexList = new String[]{propertyNameAndRegex.getValue()};
- if (nonNull(nameValue)) {
- if (nameValue instanceof Map) {
- globalContext.setMessageCode(ERROR_CODE_NST3);
- if (ValidationUtil.validateMapPropertyValue(fileName, resourceEntry, globalContext,
- propertyName,
- nameValue, regexList)) {
- return true;
+ private boolean isErrorExistWhenValidatingImageOrFlavorNames(String fileName, Pair<String, String> propertyNameAndRegex,
+ Map.Entry<String, Resource> resourceEntry, Map<String, Object> propertiesMap,
+ GlobalValidationContext globalContext) {
+ String propertyName = propertyNameAndRegex.getKey();
+ Object nameValue = propertiesMap.get(propertyName);
+ String[] regexList = new String[]{propertyNameAndRegex.getValue()};
+ if (nonNull(nameValue)) {
+ if (nameValue instanceof Map) {
+ globalContext.setMessageCode(ERROR_CODE_NST3);
+ if (ValidationUtil.validateMapPropertyValue(fileName, resourceEntry, globalContext, propertyName, nameValue, regexList)) {
+ return true;
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NST2, Messages.MISSING_GET_PARAM.getErrorMessage(), propertyName, resourceEntry.getKey()));
+ return true;
+ }
+ return false;
}
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NST2, Messages.MISSING_GET_PARAM.getErrorMessage(),
- propertyName,
- resourceEntry.getKey()));
- return true;
- }
-
- return false;
+ return false;
}
- return false;
- }
-
- private Optional<String> extractVmTypeFromProperty(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- Map<String, Object> propertiesMap,
- GlobalValidationContext globalContext,
- Pair propertyKeyRegex) {
- String propertyName = (String) propertyKeyRegex.getKey();
- Object propertyVal = propertiesMap.get(propertyName);
- if (nonNull(propertyVal)) {
- if (propertyVal instanceof Map) {
- String propertyValFromGetParam = ValidationUtil.getWantedNameFromPropertyValueGetParam
- (propertyVal);
- if (nonNull(propertyValFromGetParam)) {
- Pattern pattern = Pattern.compile("" + propertyKeyRegex.getValue());
- return Optional.ofNullable(pattern.split(propertyValFromGetParam)[0]);
+ private Optional<String> extractVmTypeFromProperty(String fileName, Map.Entry<String, Resource> resourceEntry, Map<String, Object> propertiesMap,
+ GlobalValidationContext globalContext, Pair propertyKeyRegex) {
+ String propertyName = (String) propertyKeyRegex.getKey();
+ Object propertyVal = propertiesMap.get(propertyName);
+ if (nonNull(propertyVal)) {
+ if (propertyVal instanceof Map) {
+ String propertyValFromGetParam = ValidationUtil.getWantedNameFromPropertyValueGetParam(propertyVal);
+ if (nonNull(propertyValFromGetParam)) {
+ Pattern pattern = Pattern.compile("" + propertyKeyRegex.getValue());
+ return Optional.ofNullable(pattern.split(propertyValFromGetParam)[0]);
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NST2, Messages.MISSING_GET_PARAM.getErrorMessage(), propertyName, resourceEntry.getKey()));
+ return Optional.empty();
+ }
}
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NST2, Messages.MISSING_GET_PARAM.getErrorMessage(),
- propertyName,
- resourceEntry.getKey()));
return Optional.empty();
- }
}
- return Optional.empty();
- }
- private String handleFirstIteration(String previousPropertyValueValue, String currentPropVmType) {
- String previousPropertyValue;
- if (Objects.isNull(previousPropertyValueValue)) {
- previousPropertyValue = currentPropVmType;
- return previousPropertyValue;
+ private String handleFirstIteration(String previousPropertyValueValue, String currentPropVmType) {
+ String previousPropertyValue;
+ if (Objects.isNull(previousPropertyValueValue)) {
+ previousPropertyValue = currentPropVmType;
+ return previousPropertyValue;
+ }
+ return previousPropertyValueValue;
}
-
- return previousPropertyValueValue;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java
index 760c73a52b..4a886fb1eb 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java
@@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.namingconvention;
+import static java.util.Objects.nonNull;
+
+import java.util.List;
+import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -30,75 +33,51 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.type.NamingConventionValidationContext;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import static java.util.Objects.nonNull;
-
public class NeutronPortNamingConventionValidator implements ResourceValidator {
+
private static final ErrorMessageCode ERROR_CODE_NNP1 = new ErrorMessageCode("NNP1");
private static final ErrorMessageCode ERROR_CODE_NNP2 = new ErrorMessageCode("NNP2");
private static final ErrorMessageCode ERROR_CODE_NNP3 = new ErrorMessageCode("NNP3");
@Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
NamingConventionValidationContext namingConventionValidationContext = (NamingConventionValidationContext) validationContext;
validatePortNetworkNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(), globalContext);
validateFixedIpsNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(), globalContext);
}
- private void validatePortNetworkNamingConvention(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
+ private void validatePortNetworkNamingConvention(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
GlobalValidationContext globalContext) {
if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
return;
}
String[] regexList = {".*_net_id", ".*_net_name", ".*_net_fqdn"};
-
- heatOrchestrationTemplate
- .getResources()
- .entrySet()
- .stream()
- .filter(entry -> entry.getValue().getType().equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()))
- .forEach(entry -> entry.getValue()
- .getProperties()
- .entrySet()
- .stream()
- .filter(propertyEntry -> ("network").equalsIgnoreCase(propertyEntry.getKey()) || ("network_id").equals(propertyEntry.getKey()))
- .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(),
- propertyEntry.getValue(), regexList,
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES, globalContext)));
+ heatOrchestrationTemplate.getResources().entrySet().stream()
+ .filter(entry -> entry.getValue().getType().equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())).forEach(
+ entry -> entry.getValue().getProperties().entrySet().stream()
+ .filter(propertyEntry -> ("network").equalsIgnoreCase(propertyEntry.getKey()) || ("network_id").equals(propertyEntry.getKey()))
+ .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(), propertyEntry.getValue(), regexList,
+ Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES, globalContext)));
}
- private void validateFixedIpsNamingConvention(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
+ private void validateFixedIpsNamingConvention(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
GlobalValidationContext globalContext) {
if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
return;
}
-
- heatOrchestrationTemplate.getResources()
- .entrySet()
- .stream()
- .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()) != null)
- .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType())
- .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
- .forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
+ heatOrchestrationTemplate.getResources().entrySet().stream()
+ .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()) != null)
+ .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()).equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
+ .forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
}
- private void checkNeutronPortFixedIpsName(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- String[] regexList = {"[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)",
- "[^_]+_[^_]+_v6_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_ips", "[^_]+_[^_]+_[^_]+_v6_ips",
- "[^_]+_[^_]+_[^_]+_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_v6_ip_(\\d+)"};
-
+ private void checkNeutronPortFixedIpsName(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
+ String[] regexList = {"[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)", "[^_]+_[^_]+_v6_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_ips",
+ "[^_]+_[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_[^_]+_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_v6_ip_(\\d+)"};
if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
return;
}
-
Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
Object fixedIps = propertiesMap.get("fixed_ips");
if (nonNull(fixedIps) && fixedIps instanceof List) {
@@ -117,27 +96,27 @@ public class NeutronPortNamingConventionValidator implements ResourceValidator {
String fixedIpsName = ValidationUtil.getWantedNameFromPropertyValueGetParam(fixedIpsEntry.getValue());
if (nonNull(fixedIpsName) && !ValidationUtil.evalPattern(fixedIpsName, regexList)) {
globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_NNP1, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- "Port", "Fixed_IPS", fixedIpsName, resourceEntry.getKey()));
+ .getErrorWithParameters(ERROR_CODE_NNP1, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(), "Port",
+ "Fixed_IPS", fixedIpsName, resourceEntry.getKey()));
}
} else {
- globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder.
- getErrorWithParameters(ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(), "fixed_ips", resourceEntry.getKey()));
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(), "fixed_ips", resourceEntry.getKey()));
}
}
}
- private void validateParamNamingConvention(String fileName, String resourceId, Object propertyValue, String[] regexList,
- Messages message, GlobalValidationContext globalContext) {
+ private void validateParamNamingConvention(String fileName, String resourceId, Object propertyValue, String[] regexList, Messages message,
+ GlobalValidationContext globalContext) {
if (propertyValue instanceof Map) {
Object paramName = ((Map) propertyValue).get("get_param");
if (paramName instanceof String && !ValidationUtil.evalPattern(paramName, regexList)) {
globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_NNP3, message.getErrorMessage(), "Port", "Network", (String) paramName, resourceId));
+ .getErrorWithParameters(ERROR_CODE_NNP3, message.getErrorMessage(), "Port", "Network", (String) paramName, resourceId));
}
} else {
globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(), "network or network_id", resourceId));
+ .getErrorWithParameters(ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(), "network or network_id", resourceId));
}
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java
index e9f6257a88..e2ce555caa 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.namingconvention;
import static java.util.Objects.nonNull;
@@ -28,7 +27,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
-
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@@ -50,508 +48,371 @@ import org.openecomp.sdc.validation.type.NamingConventionValidationContext;
import org.openecomp.sdc.validation.util.ValidationUtil;
public class NovaServerNamingConventionGuideLineValidator implements ResourceValidator {
- private static final String AVAILABILITY_ZONE = "availability_zone";
- private static final String SERVER = "Server";
- private static final ErrorMessageCode ERROR_CODE_NNS1 = new ErrorMessageCode("NNS1");
- private static final ErrorMessageCode ERROR_CODE_NNS2 = new ErrorMessageCode("NNS2");
- private static final ErrorMessageCode ERROR_CODE_NNS3 = new ErrorMessageCode("NNS3");
- private static final ErrorMessageCode ERROR_CODE_NNS4 = new ErrorMessageCode("NNS4");
- private static final ErrorMessageCode ERROR_CODE_NNS5 = new ErrorMessageCode("NNS5");
- private static final ErrorMessageCode ERROR_CODE_NNS6 = new ErrorMessageCode("NNS6");
- private static final ErrorMessageCode ERROR_CODE_NNS7 = new ErrorMessageCode("NNS7");
- private static final ErrorMessageCode ERROR_CODE_NNS8 = new ErrorMessageCode("NNS8");
- private static final ErrorMessageCode ERROR_CODE_NNS9 = new ErrorMessageCode("NNS9");
- private static final ErrorMessageCode ERROR_CODE_NNS10 = new ErrorMessageCode("NNS10");
- private static final ErrorMessageCode ERROR_CODE_NNS11 = new ErrorMessageCode("NNS11");
- private static final ErrorMessageCode ERROR_CODE_NNS12 = new ErrorMessageCode("NNS12");
- private static final ErrorMessageCode ERROR_CODE_NNS13 = new ErrorMessageCode("NNS13");
- private static final ErrorMessageCode ERROR_CODE_NNS14 = new ErrorMessageCode("NNS14");
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- NamingConventionValidationContext namingConventionValidationContext =
- (NamingConventionValidationContext)validationContext;
- validateHeatNovaResource(fileName, namingConventionValidationContext.getEnvFileName(),
- namingConventionValidationContext.getHeatOrchestrationTemplate(),
- globalContext);
- }
-
- private void validateHeatNovaResource(String fileName, String envFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- //if no resources exist return
- if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
- return;
+ private static final String AVAILABILITY_ZONE = "availability_zone";
+ private static final String SERVER = "Server";
+ private static final ErrorMessageCode ERROR_CODE_NNS1 = new ErrorMessageCode("NNS1");
+ private static final ErrorMessageCode ERROR_CODE_NNS2 = new ErrorMessageCode("NNS2");
+ private static final ErrorMessageCode ERROR_CODE_NNS3 = new ErrorMessageCode("NNS3");
+ private static final ErrorMessageCode ERROR_CODE_NNS4 = new ErrorMessageCode("NNS4");
+ private static final ErrorMessageCode ERROR_CODE_NNS5 = new ErrorMessageCode("NNS5");
+ private static final ErrorMessageCode ERROR_CODE_NNS6 = new ErrorMessageCode("NNS6");
+ private static final ErrorMessageCode ERROR_CODE_NNS7 = new ErrorMessageCode("NNS7");
+ private static final ErrorMessageCode ERROR_CODE_NNS8 = new ErrorMessageCode("NNS8");
+ private static final ErrorMessageCode ERROR_CODE_NNS9 = new ErrorMessageCode("NNS9");
+ private static final ErrorMessageCode ERROR_CODE_NNS10 = new ErrorMessageCode("NNS10");
+ private static final ErrorMessageCode ERROR_CODE_NNS11 = new ErrorMessageCode("NNS11");
+ private static final ErrorMessageCode ERROR_CODE_NNS12 = new ErrorMessageCode("NNS12");
+ private static final ErrorMessageCode ERROR_CODE_NNS13 = new ErrorMessageCode("NNS13");
+ private static final ErrorMessageCode ERROR_CODE_NNS14 = new ErrorMessageCode("NNS14");
+
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ NamingConventionValidationContext namingConventionValidationContext = (NamingConventionValidationContext) validationContext;
+ validateHeatNovaResource(fileName, namingConventionValidationContext.getEnvFileName(),
+ namingConventionValidationContext.getHeatOrchestrationTemplate(), globalContext);
}
- heatOrchestrationTemplate
- .getResources()
- .entrySet()
- .stream()
- .filter(entry -> entry.getValue().getType()
- .equals(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource()))
- .forEach( entry -> validateNovaServerResourceType(entry.getKey(), fileName, envFileName,
- entry, new HashMap<String, String>(), heatOrchestrationTemplate, globalContext));
- }
-
- private void validateNovaServerResourceType(String resourceId, String fileName,
- String envFileName,
- Map.Entry<String, Resource> resourceEntry,
- Map<String, String> uniqueResourcePortNetworkRole,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- validateNovaServerResourceMetaData(fileName, resourceId,
- heatOrchestrationTemplate.getResources().get(resourceId), globalContext);
- validateNovaServerResourceNetworkUniqueRole(fileName, resourceId, uniqueResourcePortNetworkRole,
- heatOrchestrationTemplate, globalContext);
- validateAvailabilityZoneName(fileName, resourceEntry, globalContext);
- validateNovaServerNameImageAndFlavor(fileName, envFileName, resourceEntry, globalContext);
- }
-
- @SuppressWarnings("unchecked")
- private void validateNovaServerResourceMetaData(String fileName, String resourceId,
- Resource resource,
- GlobalValidationContext globalValidationContext) {
- Map<String, Object> novaServerProp = resource.getProperties();
- Object novaServerPropMetadata;
- if (MapUtils.isNotEmpty(novaServerProp)) {
- novaServerPropMetadata = novaServerProp.get("metadata");
- if (novaServerPropMetadata == null) {
- globalValidationContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNS1, Messages.MISSING_NOVA_SERVER_METADATA.getErrorMessage(),
- resourceId));
- } else if (novaServerPropMetadata instanceof Map) {
- TreeMap<String, Object> propertyMap = new TreeMap((Comparator<String>) String::compareToIgnoreCase);
- propertyMap.putAll((Map) novaServerPropMetadata);
- if (!propertyMap.containsKey("vf_module_id")) {
- globalValidationContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNS2, Messages.MISSING_NOVA_SERVER_VF_MODULE_ID.getErrorMessage(),
- resourceId));
- }
- if (!propertyMap.containsKey("vnf_id")) {
- globalValidationContext.addMessage(
- fileName, ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNS3, Messages.MISSING_NOVA_SERVER_VNF_ID.getErrorMessage(),
- resourceId));
+ private void validateHeatNovaResource(String fileName, String envFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ //if no resources exist return
+ if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
+ return;
}
- }
+ heatOrchestrationTemplate.getResources().entrySet().stream()
+ .filter(entry -> entry.getValue().getType().equals(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource())).forEach(
+ entry -> validateNovaServerResourceType(entry.getKey(), fileName, envFileName, entry, new HashMap<String, String>(),
+ heatOrchestrationTemplate, globalContext));
}
- }
- private void validateNovaServerResourceNetworkUniqueRole(String fileName, String resourceId,
- Map<String, String> uniqueResourcePortNetworkRole,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalValidationContext) {
- if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources().get(resourceId).getProperties())) {
- return;
- }
- Object propertyNetworkValue =
- heatOrchestrationTemplate.getResources().get(resourceId).getProperties().get("networks");
- if (propertyNetworkValue != null && propertyNetworkValue instanceof List) {
- List<String> portResourceIdList =
- getNovaNetworkPortResourceList(fileName, (List) propertyNetworkValue,
- globalValidationContext);
- for (String portResourceId : portResourceIdList) {
- Resource portResource = heatOrchestrationTemplate.getResources().get(portResourceId);
+ private void validateNovaServerResourceType(String resourceId, String fileName, String envFileName, Map.Entry<String, Resource> resourceEntry,
+ Map<String, String> uniqueResourcePortNetworkRole,
+ HeatOrchestrationTemplate heatOrchestrationTemplate, GlobalValidationContext globalContext) {
+ validateNovaServerResourceMetaData(fileName, resourceId, heatOrchestrationTemplate.getResources().get(resourceId), globalContext);
+ validateNovaServerResourceNetworkUniqueRole(fileName, resourceId, uniqueResourcePortNetworkRole, heatOrchestrationTemplate, globalContext);
+ validateAvailabilityZoneName(fileName, resourceEntry, globalContext);
+ validateNovaServerNameImageAndFlavor(fileName, envFileName, resourceEntry, globalContext);
+ }
- if (portResource != null && portResource.getType()
- .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) {
- validateUniqueResourcePortNetworkRole(fileName, resourceId,
- uniqueResourcePortNetworkRole, globalValidationContext,
- portResourceId, portResource);
+ @SuppressWarnings("unchecked")
+ private void validateNovaServerResourceMetaData(String fileName, String resourceId, Resource resource,
+ GlobalValidationContext globalValidationContext) {
+ Map<String, Object> novaServerProp = resource.getProperties();
+ Object novaServerPropMetadata;
+ if (MapUtils.isNotEmpty(novaServerProp)) {
+ novaServerPropMetadata = novaServerProp.get("metadata");
+ if (novaServerPropMetadata == null) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS1, Messages.MISSING_NOVA_SERVER_METADATA.getErrorMessage(), resourceId));
+ } else if (novaServerPropMetadata instanceof Map) {
+ TreeMap<String, Object> propertyMap = new TreeMap((Comparator<String>) String::compareToIgnoreCase);
+ propertyMap.putAll((Map) novaServerPropMetadata);
+ if (!propertyMap.containsKey("vf_module_id")) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS2, Messages.MISSING_NOVA_SERVER_VF_MODULE_ID.getErrorMessage(), resourceId));
+ }
+ if (!propertyMap.containsKey("vnf_id")) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS3, Messages.MISSING_NOVA_SERVER_VNF_ID.getErrorMessage(), resourceId));
+ }
+ }
}
- }
}
- }
- private void validateUniqueResourcePortNetworkRole(String fileName, String resourceId,
- Map<String, String> uniqueResourcePortNetworkRole,
- GlobalValidationContext globalValidationContext,
- String portResourceId, Resource portResource) {
- String role = null;
- Object network;
- Map portNetwork =
- getPortNetwork(fileName, resourceId, portResource, globalValidationContext);
- if (Objects.nonNull(portNetwork)) {
- network = portNetwork.get("get_param");
- if (Objects.nonNull(network)) {
- if (network instanceof String ){
- role = getNetworkRole((String)network);
- }else if (network instanceof List){
- role = getNetworkRole((String)((List) network).get(0));
+ private void validateNovaServerResourceNetworkUniqueRole(String fileName, String resourceId, Map<String, String> uniqueResourcePortNetworkRole,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalValidationContext) {
+ if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources().get(resourceId).getProperties())) {
+ return;
}
- if (role != null && uniqueResourcePortNetworkRole.containsKey(role)) {
- globalValidationContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNS12, Messages.RESOURCE_CONNECTED_TO_TWO_EXTERNAL_NETWORKS_WITH_SAME_ROLE
- .getErrorMessage(), role, resourceId));
- } else {
- uniqueResourcePortNetworkRole.put(role, resourceId);
+ Object propertyNetworkValue = heatOrchestrationTemplate.getResources().get(resourceId).getProperties().get("networks");
+ if (propertyNetworkValue != null && propertyNetworkValue instanceof List) {
+ List<String> portResourceIdList = getNovaNetworkPortResourceList(fileName, (List) propertyNetworkValue, globalValidationContext);
+ for (String portResourceId : portResourceIdList) {
+ Resource portResource = heatOrchestrationTemplate.getResources().get(portResourceId);
+ if (portResource != null && portResource.getType().equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) {
+ validateUniqueResourcePortNetworkRole(fileName, resourceId, uniqueResourcePortNetworkRole, globalValidationContext,
+ portResourceId, portResource);
+ }
+ }
}
- }
}
- }
- private List<String> getNovaNetworkPortResourceList(String filename, List propertyNetworkValue,
- GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_NNS14);
- List<String> portResourceIdList = new ArrayList<>();
- for (Object propValue : propertyNetworkValue) {
- Object portPropValue = ((Map) propValue).get("port");
- Collection<String> portResourceIds = HeatStructureUtil
- .getReferencedValuesByFunctionName(filename, "get_resource", portPropValue,
- globalContext);
- if (portResourceIds != null) {
- portResourceIdList.addAll(portResourceIds);
- }
- }
-
- return portResourceIdList;
- }
-
- private String getNetworkRole(String network) {
- if (network == null) {
- return null;
- }
- if (network.contains("_net_id")) {
- return network.substring(0, network.indexOf("_net_id"));
- } else if (network.contains("_net_name")) {
- return network.substring(0, network.indexOf("_net_name"));
- } else if (network.contains("_net_fqdn")) {
- return network.substring(0, network.indexOf("_net_fqdn"));
- }
- return null;
- }
-
- private Map getPortNetwork(String fileName, String resourceId, Resource portResource,
- GlobalValidationContext globalValidationContext) {
- Object portNetwork = portResource.getProperties().get("network_id");
- if (portNetwork == null) {
- portNetwork = portResource.getProperties().get("network");
- }
- if (!(portNetwork instanceof Map)) {
- globalValidationContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNS4, Messages.MISSING_GET_PARAM.getErrorMessage(),
- "network or network_id", resourceId));
- return null;
+ private void validateUniqueResourcePortNetworkRole(String fileName, String resourceId, Map<String, String> uniqueResourcePortNetworkRole,
+ GlobalValidationContext globalValidationContext, String portResourceId,
+ Resource portResource) {
+ String role = null;
+ Object network;
+ Map portNetwork = getPortNetwork(fileName, resourceId, portResource, globalValidationContext);
+ if (Objects.nonNull(portNetwork)) {
+ network = portNetwork.get("get_param");
+ if (Objects.nonNull(network)) {
+ if (network instanceof String) {
+ role = getNetworkRole((String) network);
+ } else if (network instanceof List) {
+ role = getNetworkRole((String) ((List) network).get(0));
+ }
+ if (role != null && uniqueResourcePortNetworkRole.containsKey(role)) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS12,
+ Messages.RESOURCE_CONNECTED_TO_TWO_EXTERNAL_NETWORKS_WITH_SAME_ROLE.getErrorMessage(), role, resourceId));
+ } else {
+ uniqueResourcePortNetworkRole.put(role, resourceId);
+ }
+ }
+ }
}
- return (Map) portNetwork;
- }
- private void validateAvailabilityZoneName(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- String[] regexList = new String[]{"availability_zone_(\\d+)"};
-
- if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
- return;
+ private List<String> getNovaNetworkPortResourceList(String filename, List propertyNetworkValue, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_NNS14);
+ List<String> portResourceIdList = new ArrayList<>();
+ for (Object propValue : propertyNetworkValue) {
+ Object portPropValue = ((Map) propValue).get("port");
+ Collection<String> portResourceIds = HeatStructureUtil
+ .getReferencedValuesByFunctionName(filename, "get_resource", portPropValue, globalContext);
+ if (portResourceIds != null) {
+ portResourceIdList.addAll(portResourceIds);
+ }
+ }
+ return portResourceIdList;
}
- Object availabilityZoneMap = resourceEntry.getValue().getProperties()
- .get(AVAILABILITY_ZONE);
-
- if (nonNull(availabilityZoneMap)) {
- if (availabilityZoneMap instanceof Map) {
- String availabilityZoneName = ValidationUtil.getWantedNameFromPropertyValueGetParam
- (availabilityZoneMap);
-
- if (availabilityZoneName != null && !ValidationUtil
- .evalPattern(availabilityZoneName, regexList)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNS5, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- ValidationUtil.getMessagePartAccordingToResourceType(resourceEntry),
- "Availability Zone", availabilityZoneName, resourceEntry.getKey()));
- }
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNS6, Messages.MISSING_GET_PARAM.getErrorMessage(),
- AVAILABILITY_ZONE, resourceEntry.getKey()));
- }
+ private String getNetworkRole(String network) {
+ if (network == null) {
+ return null;
+ }
+ if (network.contains("_net_id")) {
+ return network.substring(0, network.indexOf("_net_id"));
+ } else if (network.contains("_net_name")) {
+ return network.substring(0, network.indexOf("_net_name"));
+ } else if (network.contains("_net_fqdn")) {
+ return network.substring(0, network.indexOf("_net_fqdn"));
+ }
+ return null;
}
- }
-
- private void validateNovaServerNameImageAndFlavor(String fileName, String envFileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- String novaName =
- validateNovaServerNamingConvention(fileName, envFileName, resourceEntry, globalContext);
- Map<String, String> legalNovaNamingConventionMap =
- validateImageAndFlavorFromNovaServer(fileName, resourceEntry, globalContext);
- if (Objects.nonNull(novaName)) {
- legalNovaNamingConventionMap.put("name", novaName);
+ private Map getPortNetwork(String fileName, String resourceId, Resource portResource, GlobalValidationContext globalValidationContext) {
+ Object portNetwork = portResource.getProperties().get("network_id");
+ if (portNetwork == null) {
+ portNetwork = portResource.getProperties().get("network");
+ }
+ if (!(portNetwork instanceof Map)) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS4, Messages.MISSING_GET_PARAM.getErrorMessage(), "network or network_id", resourceId));
+ return null;
+ }
+ return (Map) portNetwork;
}
- if (legalNovaNamingConventionMap.keySet().size() > 1) {
- validateNovaServerNameImageAndFlavorSync(fileName, resourceEntry,
- legalNovaNamingConventionMap, globalContext);
+ private void validateAvailabilityZoneName(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
+ String[] regexList = new String[]{"availability_zone_(\\d+)"};
+ if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
+ return;
+ }
+ Object availabilityZoneMap = resourceEntry.getValue().getProperties().get(AVAILABILITY_ZONE);
+ if (nonNull(availabilityZoneMap)) {
+ if (availabilityZoneMap instanceof Map) {
+ String availabilityZoneName = ValidationUtil.getWantedNameFromPropertyValueGetParam(availabilityZoneMap);
+ if (availabilityZoneName != null && !ValidationUtil.evalPattern(availabilityZoneName, regexList)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS5, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
+ ValidationUtil.getMessagePartAccordingToResourceType(resourceEntry), "Availability Zone", availabilityZoneName,
+ resourceEntry.getKey()));
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS6, Messages.MISSING_GET_PARAM.getErrorMessage(), AVAILABILITY_ZONE,
+ resourceEntry.getKey()));
+ }
+ }
}
- }
- private String validateNovaServerNamingConvention(String fileName, String envFileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
- return null;
+ private void validateNovaServerNameImageAndFlavor(String fileName, String envFileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ String novaName = validateNovaServerNamingConvention(fileName, envFileName, resourceEntry, globalContext);
+ Map<String, String> legalNovaNamingConventionMap = validateImageAndFlavorFromNovaServer(fileName, resourceEntry, globalContext);
+ if (Objects.nonNull(novaName)) {
+ legalNovaNamingConventionMap.put("name", novaName);
+ }
+ if (legalNovaNamingConventionMap.keySet().size() > 1) {
+ validateNovaServerNameImageAndFlavorSync(fileName, resourceEntry, legalNovaNamingConventionMap, globalContext);
+ }
}
- return checkIfNovaNameByGuidelines(fileName, envFileName, resourceEntry, globalContext);
- }
- private Map<String, String> validateImageAndFlavorFromNovaServer(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- Map<String, String> imageAndFlavorLegalNames = new HashMap<>();
-
- if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
- return imageAndFlavorLegalNames;
+ private String validateNovaServerNamingConvention(String fileName, String envFileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
+ return null;
+ }
+ return checkIfNovaNameByGuidelines(fileName, envFileName, resourceEntry, globalContext);
}
- Pair<String, String> imagePair = new ImmutablePair<>("image", ".*_image_name");
- Pair<String, String> flavorPair = new ImmutablePair<>("flavor", ".*_flavor_name");
- List<Pair<String, String>> imageFlavorPairs = Arrays.asList(imagePair, flavorPair);
- Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
-
- for (Pair<String, String> imageOrFlavor : imageFlavorPairs) {
- boolean isErrorInImageOrFlavor =
- isErrorExistWhenValidatingImageOrFlavorNames(fileName, imageOrFlavor, resourceEntry,
- propertiesMap, globalContext);
- if (!isErrorInImageOrFlavor) {
- Object nameValue = propertiesMap.get(imageOrFlavor.getKey());
- String imageOrFlavorName = ValidationUtil.getWantedNameFromPropertyValueGetParam
- (nameValue);
- imageAndFlavorLegalNames.put(imageOrFlavor.getKey(), imageOrFlavorName);
- }
+ private Map<String, String> validateImageAndFlavorFromNovaServer(String fileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ Map<String, String> imageAndFlavorLegalNames = new HashMap<>();
+ if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
+ return imageAndFlavorLegalNames;
+ }
+ Pair<String, String> imagePair = new ImmutablePair<>("image", ".*_image_name");
+ Pair<String, String> flavorPair = new ImmutablePair<>("flavor", ".*_flavor_name");
+ List<Pair<String, String>> imageFlavorPairs = Arrays.asList(imagePair, flavorPair);
+ Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
+ for (Pair<String, String> imageOrFlavor : imageFlavorPairs) {
+ boolean isErrorInImageOrFlavor = isErrorExistWhenValidatingImageOrFlavorNames(fileName, imageOrFlavor, resourceEntry, propertiesMap,
+ globalContext);
+ if (!isErrorInImageOrFlavor) {
+ Object nameValue = propertiesMap.get(imageOrFlavor.getKey());
+ String imageOrFlavorName = ValidationUtil.getWantedNameFromPropertyValueGetParam(nameValue);
+ imageAndFlavorLegalNames.put(imageOrFlavor.getKey(), imageOrFlavorName);
+ }
+ }
+ return imageAndFlavorLegalNames;
}
- return imageAndFlavorLegalNames;
- }
- private String checkIfNovaNameByGuidelines(String fileName, String envFileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
- return null;
- }
- Object novaNameGetParam = getNovaServerName(resourceEntry);
- String novaName = null;
- if (nonNull(novaNameGetParam)) {
- novaName =
- checkNovaNameGetParamValueMap(fileName, novaNameGetParam, resourceEntry, globalContext);
- checkIfNovaNameParameterInEnvIsStringOrList(fileName, envFileName, novaName, resourceEntry,
- globalContext);
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNS7, Messages.MISSING_GET_PARAM.getErrorMessage(),
- "nova server name", resourceEntry.getKey()));
+ private String checkIfNovaNameByGuidelines(String fileName, String envFileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
+ return null;
+ }
+ Object novaNameGetParam = getNovaServerName(resourceEntry);
+ String novaName = null;
+ if (nonNull(novaNameGetParam)) {
+ novaName = checkNovaNameGetParamValueMap(fileName, novaNameGetParam, resourceEntry, globalContext);
+ checkIfNovaNameParameterInEnvIsStringOrList(fileName, envFileName, novaName, resourceEntry, globalContext);
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS7, Messages.MISSING_GET_PARAM.getErrorMessage(), "nova server name", resourceEntry.getKey()));
+ }
+ return novaName;
}
- return novaName;
- }
-
- private boolean isErrorExistWhenValidatingImageOrFlavorNames(String fileName,
- Pair<String, String> propertyNameAndRegex,
- Map.Entry<String, Resource> resourceEntry,
- Map<String, Object> propertiesMap,
- GlobalValidationContext globalContext) {
- String propertyName = propertyNameAndRegex.getKey();
- Object nameValue = propertiesMap.get(propertyName);
- String[] regexList = new String[]{propertyNameAndRegex.getValue()};
-
-
- if (nonNull(nameValue)) {
- if (nameValue instanceof Map) {
- globalContext.setMessageCode(ERROR_CODE_NNS13);
- if (ValidationUtil.validateMapPropertyValue(fileName, resourceEntry, globalContext,
- propertyName,
- nameValue, regexList)) {
- return true;
+ private boolean isErrorExistWhenValidatingImageOrFlavorNames(String fileName, Pair<String, String> propertyNameAndRegex,
+ Map.Entry<String, Resource> resourceEntry, Map<String, Object> propertiesMap,
+ GlobalValidationContext globalContext) {
+ String propertyName = propertyNameAndRegex.getKey();
+ Object nameValue = propertiesMap.get(propertyName);
+ String[] regexList = new String[]{propertyNameAndRegex.getValue()};
+ if (nonNull(nameValue)) {
+ if (nameValue instanceof Map) {
+ globalContext.setMessageCode(ERROR_CODE_NNS13);
+ if (ValidationUtil.validateMapPropertyValue(fileName, resourceEntry, globalContext, propertyName, nameValue, regexList)) {
+ return true;
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS8, Messages.MISSING_GET_PARAM.getErrorMessage(), propertyName, resourceEntry.getKey()));
+ return true;
+ }
+ return false;
}
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNS8, Messages.MISSING_GET_PARAM.getErrorMessage(),
- propertyName, resourceEntry.getKey()));
- return true;
- }
-
- return false;
+ return false;
}
- return false;
- }
-
- private Object getNovaServerName(Map.Entry<String, Resource> resourceEntry) {
- Object novaServerName = resourceEntry.getValue().getProperties().get("name");
- Map novaNameMap;
- if (nonNull(novaServerName) && novaServerName instanceof Map) {
- novaNameMap = (Map) novaServerName;
- return novaNameMap.get(ResourceReferenceFunctions.GET_PARAM.getFunction());
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- private String checkNovaNameGetParamValueMap(String fileName, Object getParamValue,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- if (getParamValue instanceof List) {
- List<Object> getParamNameList = (List) getParamValue;
- String[] regexName = new String[]{".*_names"};
- return isNovaNameAsListLegal(fileName, regexName, getParamNameList, resourceEntry,
- globalContext);
- } else if (getParamValue instanceof String) {
- String[] regexName = new String[]{".*_name_(\\d+)"};
- return isNovaNameAsStringLegal(fileName, (String) getParamValue, regexName, resourceEntry,
- globalContext);
+ private Object getNovaServerName(Map.Entry<String, Resource> resourceEntry) {
+ Object novaServerName = resourceEntry.getValue().getProperties().get("name");
+ Map novaNameMap;
+ if (nonNull(novaServerName) && novaServerName instanceof Map) {
+ novaNameMap = (Map) novaServerName;
+ return novaNameMap.get(ResourceReferenceFunctions.GET_PARAM.getFunction());
+ }
+ return null;
}
- return null;
- }
-
- private void checkIfNovaNameParameterInEnvIsStringOrList(String fileName,
- String envFileName,
- String novaServerName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- if (nonNull(envFileName)) {
- Environment environment = ValidationUtil.validateEnvContent(envFileName, globalContext);
-
- if (environment != null && MapUtils.isNotEmpty(environment.getParameters())) {
- Object novaServerNameEnvValue = environment.getParameters()
- .get(novaServerName);
- if (Objects.nonNull(novaServerNameEnvValue) && !DefinedHeatParameterTypes
- .isNovaServerEnvValueIsFromRightType(novaServerNameEnvValue)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNS9, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- SERVER, "Name",
- novaServerNameEnvValue.toString(), resourceEntry.getKey()));
- }
- }
+ @SuppressWarnings("unchecked")
+ private String checkNovaNameGetParamValueMap(String fileName, Object getParamValue, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ if (getParamValue instanceof List) {
+ List<Object> getParamNameList = (List) getParamValue;
+ String[] regexName = new String[]{".*_names"};
+ return isNovaNameAsListLegal(fileName, regexName, getParamNameList, resourceEntry, globalContext);
+ } else if (getParamValue instanceof String) {
+ String[] regexName = new String[]{".*_name_(\\d+)"};
+ return isNovaNameAsStringLegal(fileName, (String) getParamValue, regexName, resourceEntry, globalContext);
+ }
+ return null;
}
- }
-
- private String isNovaNameAsListLegal(String fileName,
- String[] regexName,
- List<Object> getParamNameList,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- if (getParamNameList.size() != 2 || !ValidationUtil.evalPattern(getParamNameList.get(0),
- regexName)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNS10, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- SERVER,
- "name", getParamNameList.toString(), resourceEntry.getKey()));
- return null;
+ private void checkIfNovaNameParameterInEnvIsStringOrList(String fileName, String envFileName, String novaServerName,
+ Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
+ if (nonNull(envFileName)) {
+ Environment environment = ValidationUtil.validateEnvContent(envFileName, globalContext);
+ if (environment != null && MapUtils.isNotEmpty(environment.getParameters())) {
+ Object novaServerNameEnvValue = environment.getParameters().get(novaServerName);
+ if (Objects.nonNull(novaServerNameEnvValue) && !DefinedHeatParameterTypes
+ .isNovaServerEnvValueIsFromRightType(novaServerNameEnvValue)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS9, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(), SERVER,
+ "Name", novaServerNameEnvValue.toString(), resourceEntry.getKey()));
+ }
+ }
+ }
}
- return (String) getParamNameList.get(0);
- }
-
- private String isNovaNameAsStringLegal(String fileName,
- String novaName,
- String[] regexName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- if (!ValidationUtil.evalPattern(novaName, regexName)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNS10, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- SERVER,
- "name", novaName, resourceEntry.getKey()));
- return null;
+ private String isNovaNameAsListLegal(String fileName, String[] regexName, List<Object> getParamNameList,
+ Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
+ if (getParamNameList.size() != 2 || !ValidationUtil.evalPattern(getParamNameList.get(0), regexName)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS10, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(), SERVER, "name",
+ getParamNameList.toString(), resourceEntry.getKey()));
+ return null;
+ }
+ return (String) getParamNameList.get(0);
}
- return novaName;
- }
-
- private void validateNovaServerNameImageAndFlavorSync(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- Map<String, String> legalNovaNamingConventionNames,
- GlobalValidationContext globalContext) {
- List<String> vmNames = new LinkedList<>();
- for (Map.Entry<String, String> nameEntry : legalNovaNamingConventionNames.entrySet()) {
- vmNames.add(getVmName(nameEntry.getValue(), nameEntry.getKey()));
+ private String isNovaNameAsStringLegal(String fileName, String novaName, String[] regexName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ if (!ValidationUtil.evalPattern(novaName, regexName)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS10, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(), SERVER, "name",
+ novaName, resourceEntry.getKey()));
+ return null;
+ }
+ return novaName;
}
- vmNames.removeIf(Objects::isNull);
-
- if (!isVmNameSync(vmNames)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNS11, Messages.NOVA_NAME_IMAGE_FLAVOR_NOT_CONSISTENT.getErrorMessage(),
- resourceEntry.getKey()));
+ private void validateNovaServerNameImageAndFlavorSync(String fileName, Map.Entry<String, Resource> resourceEntry,
+ Map<String, String> legalNovaNamingConventionNames, GlobalValidationContext globalContext) {
+ List<String> vmNames = new LinkedList<>();
+ for (Map.Entry<String, String> nameEntry : legalNovaNamingConventionNames.entrySet()) {
+ vmNames.add(getVmName(nameEntry.getValue(), nameEntry.getKey()));
+ }
+ vmNames.removeIf(Objects::isNull);
+ if (!isVmNameSync(vmNames)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNS11, Messages.NOVA_NAME_IMAGE_FLAVOR_NOT_CONSISTENT.getErrorMessage(), resourceEntry.getKey()));
+ }
}
- }
- private String getVmName(String nameToGetVmNameFrom, String stringToGetIndexOf) {
- int vmIndex =
- nameToGetVmNameFrom == null ? -1 : nameToGetVmNameFrom.indexOf(stringToGetIndexOf);
- String vmName = null;
- if (nameToGetVmNameFrom != null) {
- vmName = vmIndex < 0 ? null
- : trimNonAlphaNumericCharactersFromEndOfString(nameToGetVmNameFrom.substring(0, vmIndex));
+ private String getVmName(String nameToGetVmNameFrom, String stringToGetIndexOf) {
+ int vmIndex = nameToGetVmNameFrom == null ? -1 : nameToGetVmNameFrom.indexOf(stringToGetIndexOf);
+ String vmName = null;
+ if (nameToGetVmNameFrom != null) {
+ vmName = vmIndex < 0 ? null : trimNonAlphaNumericCharactersFromEndOfString(nameToGetVmNameFrom.substring(0, vmIndex));
+ }
+ return vmName;
}
- return vmName;
- }
- private boolean isVmNameSync(List<String> namesToCompare) {
- int size = namesToCompare.size();
- for (int i = 0; i < size - 1; i++) {
- if (!namesToCompare.get(i).equals(namesToCompare.get(i + 1))) {
- return false;
- }
+ private boolean isVmNameSync(List<String> namesToCompare) {
+ int size = namesToCompare.size();
+ for (int i = 0; i < size - 1; i++) {
+ if (!namesToCompare.get(i).equals(namesToCompare.get(i + 1))) {
+ return false;
+ }
+ }
+ return true;
}
- return true;
- }
-
- private String trimNonAlphaNumericCharactersFromEndOfString(String toTrim) {
- int stringSize = toTrim.length();
- int stringLength = stringSize - 1;
- String[] regexList = new String[]{"[^a-zA-Z0-9]"};
- while (stringLength >= 0) {
- if (!ValidationUtil.evalPattern(String.valueOf(toTrim.charAt(stringLength)), regexList)) {
- break;
- }
- stringLength--;
+ private String trimNonAlphaNumericCharactersFromEndOfString(String toTrim) {
+ int stringSize = toTrim.length();
+ int stringLength = stringSize - 1;
+ String[] regexList = new String[]{"[^a-zA-Z0-9]"};
+ while (stringLength >= 0) {
+ if (!ValidationUtil.evalPattern(String.valueOf(toTrim.charAt(stringLength)), regexList)) {
+ break;
+ }
+ stringLength--;
+ }
+ return toTrim.substring(0, stringLength + 1);
}
-
- return toTrim.substring(0, stringLength + 1);
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java
index 3662acfde3..ef87d9e66e 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/VirtualMachineInterfaceGuidelineValidator.java
@@ -30,7 +30,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
@@ -45,191 +44,142 @@ import org.openecomp.sdc.validation.ValidationContext;
import org.openecomp.sdc.validation.type.NamingConventionValidationContext;
public class VirtualMachineInterfaceGuidelineValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE1 = new ErrorMessageCode
- ("VlANG1");
- private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE2 = new ErrorMessageCode
- ("VlANG2");
- private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE3 = new ErrorMessageCode
- ("VlANG3");
-
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
- NamingConventionValidationContext namingConventionValidationContext =
- (NamingConventionValidationContext) validationContext;
- Optional<Object> tagPropertyValue = getVlanTagPropertyValue(resourceEntry.getValue());
-
- if (tagPropertyValue.isPresent()) {
- validateModeledByResourceGroup(fileName, resourceEntry, globalContext,
- namingConventionValidationContext);
- validateSingleVirtualMachineInterfaceInFile(fileName, globalContext,
- namingConventionValidationContext);
- validateSubInterfaceNamingConvention(fileName, resourceEntry, globalContext);
- }
- }
-
- private void validateModeledByResourceGroup(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- NamingConventionValidationContext namingConventionValidationContext) {
-
- Object refsPropertyValue = resourceEntry.getValue().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
- if (Objects.isNull(refsPropertyValue)) {
- addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE1,
- Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, resourceEntry.getKey());
- return;
- }
- final boolean modeledThroughResourceGroup = isModeledThroughResourceGroup(fileName, globalContext,
- namingConventionValidationContext, refsPropertyValue);
- if (!modeledThroughResourceGroup) {
- addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE1,
- Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, resourceEntry.getKey());
- }
-
- }
-
- private void validateSubInterfaceNamingConvention(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- final String resourceId = resourceEntry.getKey();
- final Optional<String> networkRole = HeatResourceUtil.extractNetworkRoleFromSubInterfaceId(resourceId, resourceEntry
- .getValue().getType());
- if (!networkRole.isPresent()) {
- addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE3,
- Messages.VLAN_GUIDELINE_VALIDATION_NAMING_CONVENTION, resourceId);
- }
- }
-
- private void validateSingleVirtualMachineInterfaceInFile(String fileName,
- GlobalValidationContext globalContext,
- NamingConventionValidationContext
- namingConventionValidationContext) {
- Set<String> forbiddenTypes = Stream.of(NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
- NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()).collect(Collectors.toSet());
-
- final Map<String, Resource> resources =
- namingConventionValidationContext.getHeatOrchestrationTemplate().getResources();
-
- if ((countVlanResources(resources) > 1) || fileContainsNonVlanResources(resources,
- forbiddenTypes)) {
- addViolationToContext(fileName, globalContext, ErrorLevel.ERROR, ERROR_CODE_VLAN_GUIDELINE2,
- Messages.VLAN_GUIDELINE_VALIDATION_SINGLE_VLAN, fileName);
+ private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE1 = new ErrorMessageCode("VlANG1");
+ private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE2 = new ErrorMessageCode("VlANG2");
+ private static final ErrorMessageCode ERROR_CODE_VLAN_GUIDELINE3 = new ErrorMessageCode("VlANG3");
+
+ /**
+ * This method verifies whether the propertyValue is a list containing a single get_param whose value is string
+ *
+ * @param fileName on which the validation is currently run
+ * @param globalContext global validation context
+ * @param namingConventionValidationContext heat resource validation context
+ * @param propertyValue the value which is examined
+ * @return whether the propertyValue is a list containing a single get_param whose value is string
+ */
+ private static boolean isModeledThroughResourceGroup(String fileName, GlobalValidationContext globalContext,
+ NamingConventionValidationContext namingConventionValidationContext, Object propertyValue) {
+ final boolean isList = propertyValue instanceof List;
+ if (!isList || ((List) propertyValue).size() != 1) {
+ return false;
+ }
+ final Object listValue = ((List) propertyValue).get(0);
+ final Set<String> getParamValues = HeatStructureUtil.getReferencedValuesByFunctionName(fileName, "get_param", listValue, globalContext);
+ if (getParamValues.isEmpty()) {
+ return false; //this is not a get_param
+ }
+ //validating get_param value
+ return (getParamValues.size() == 1) && validateGetParamValueOfType(getParamValues, namingConventionValidationContext,
+ DefinedHeatParameterTypes.STRING.getType());
}
-
- }
-
- private boolean fileContainsNonVlanResources(Map<String, Resource> resources,
- Set<String> forbiddenTypes) {
- for (Map.Entry<String, Resource> resourceEntry : resources.entrySet()) {
- if (forbiddenTypes.contains(resourceEntry.getValue().getType())) {
- return true;
- }
- }
- return false;
- }
-
- private int countVlanResources(Map<String, Resource> resources) {
- int numVlanResources = 0;
- for (Map.Entry<String, Resource> resourceEntry : resources.entrySet()) {
- final String resourceType = resourceEntry.getValue().getType();
- if (resourceType.equals
- (CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) {
- numVlanResources++;
- }
+ private static boolean validateGetParamValueOfType(Set<String> values, NamingConventionValidationContext namingConventionValidationContext,
+ String type) {
+ return values.stream()
+ .anyMatch(e -> Objects.equals(namingConventionValidationContext.getHeatOrchestrationTemplate().getParameters().get(e).getType(), type));
}
- return numVlanResources;
- }
-
-
- private void addViolationToContext(String fileName, GlobalValidationContext globalContext,
- ErrorLevel error, ErrorMessageCode errorCodeVlanGuideline1,
- Messages vlanGuidelineValidationNotModeledThroughResourceGroup,
- String key) {
- globalContext.addMessage(fileName, error, ErrorMessagesFormatBuilder
- .getErrorWithParameters(errorCodeVlanGuideline1,
- vlanGuidelineValidationNotModeledThroughResourceGroup.getErrorMessage(),
- key));
- }
-
-
- private Optional<Object> getVlanTagPropertyValue(Resource resource) {
- Object vmiProperties = resource.getProperties().get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME);
- if (Objects.nonNull(vmiProperties) && vmiProperties instanceof Map) {
- return Optional.ofNullable(((Map) vmiProperties)
- .get(HeatConstants.VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME));
- }
- return Optional.empty();
- }
-
-
- /**
- * This method verifies whether the propertyValue is a list containing a single get_param
- * whose value is string
- *
- * @param fileName on which the validation is currently run
- * @param globalContext global validation context
- * @param namingConventionValidationContext heat resource validation context
- * @param propertyValue the value which is examined
- * @return whether the propertyValue is a list containing a single get_param
- * whose value is string
- */
- private static boolean isModeledThroughResourceGroup(String fileName, GlobalValidationContext
- globalContext, NamingConventionValidationContext namingConventionValidationContext,
- Object propertyValue) {
- final boolean isList = propertyValue instanceof List;
- if (!isList || ((List) propertyValue).size() != 1) {
- return false;
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ NamingConventionValidationContext namingConventionValidationContext = (NamingConventionValidationContext) validationContext;
+ Optional<Object> tagPropertyValue = getVlanTagPropertyValue(resourceEntry.getValue());
+ if (tagPropertyValue.isPresent()) {
+ validateModeledByResourceGroup(fileName, resourceEntry, globalContext, namingConventionValidationContext);
+ validateSingleVirtualMachineInterfaceInFile(fileName, globalContext, namingConventionValidationContext);
+ validateSubInterfaceNamingConvention(fileName, resourceEntry, globalContext);
+ }
}
- final Object listValue = ((List) propertyValue).get(0);
-
- final Set<String> getParamValues =
- HeatStructureUtil.getReferencedValuesByFunctionName(fileName, "get_param",
- listValue, globalContext);
- if (getParamValues.isEmpty()) {
- return false; //this is not a get_param
+ private void validateModeledByResourceGroup(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ NamingConventionValidationContext namingConventionValidationContext) {
+ Object refsPropertyValue = resourceEntry.getValue().getProperties().get(HeatConstants.VMI_REFS_PROPERTY_NAME);
+ if (Objects.isNull(refsPropertyValue)) {
+ addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE1,
+ Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, resourceEntry.getKey());
+ return;
+ }
+ final boolean modeledThroughResourceGroup = isModeledThroughResourceGroup(fileName, globalContext, namingConventionValidationContext,
+ refsPropertyValue);
+ if (!modeledThroughResourceGroup) {
+ addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE1,
+ Messages.VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP, resourceEntry.getKey());
+ }
}
- //validating get_param value
- return (getParamValues.size() == 1) &&
- validateGetParamValueOfType(getParamValues, namingConventionValidationContext,
- DefinedHeatParameterTypes.STRING.getType());
+ private void validateSubInterfaceNamingConvention(String fileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ final String resourceId = resourceEntry.getKey();
+ final Optional<String> networkRole = HeatResourceUtil.extractNetworkRoleFromSubInterfaceId(resourceId, resourceEntry.getValue().getType());
+ if (!networkRole.isPresent()) {
+ addViolationToContext(fileName, globalContext, ErrorLevel.WARNING, ERROR_CODE_VLAN_GUIDELINE3,
+ Messages.VLAN_GUIDELINE_VALIDATION_NAMING_CONVENTION, resourceId);
+ }
+ }
- }
+ private void validateSingleVirtualMachineInterfaceInFile(String fileName, GlobalValidationContext globalContext,
+ NamingConventionValidationContext namingConventionValidationContext) {
+ Set<String> forbiddenTypes = Stream.of(NOVA_SERVER_RESOURCE_TYPE.getHeatResource(), NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())
+ .collect(Collectors.toSet());
+ final Map<String, Resource> resources = namingConventionValidationContext.getHeatOrchestrationTemplate().getResources();
+ if ((countVlanResources(resources) > 1) || fileContainsNonVlanResources(resources, forbiddenTypes)) {
+ addViolationToContext(fileName, globalContext, ErrorLevel.ERROR, ERROR_CODE_VLAN_GUIDELINE2,
+ Messages.VLAN_GUIDELINE_VALIDATION_SINGLE_VLAN, fileName);
+ }
+ }
- private static boolean validateGetParamValueOfType(Set<String> values,
- NamingConventionValidationContext
- namingConventionValidationContext,
- String type) {
+ private boolean fileContainsNonVlanResources(Map<String, Resource> resources, Set<String> forbiddenTypes) {
+ for (Map.Entry<String, Resource> resourceEntry : resources.entrySet()) {
+ if (forbiddenTypes.contains(resourceEntry.getValue().getType())) {
+ return true;
+ }
+ }
+ return false;
+ }
- return values.stream().anyMatch(e -> Objects.equals(
- namingConventionValidationContext.getHeatOrchestrationTemplate().getParameters().get(e)
- .getType(), type));
- }
+ private int countVlanResources(Map<String, Resource> resources) {
+ int numVlanResources = 0;
+ for (Map.Entry<String, Resource> resourceEntry : resources.entrySet()) {
+ final String resourceType = resourceEntry.getValue().getType();
+ if (resourceType.equals(CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) {
+ numVlanResources++;
+ }
+ }
+ return numVlanResources;
+ }
+ private void addViolationToContext(String fileName, GlobalValidationContext globalContext, ErrorLevel error,
+ ErrorMessageCode errorCodeVlanGuideline1, Messages vlanGuidelineValidationNotModeledThroughResourceGroup,
+ String key) {
+ globalContext.addMessage(fileName, error, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(errorCodeVlanGuideline1, vlanGuidelineValidationNotModeledThroughResourceGroup.getErrorMessage(), key));
+ }
+ private Optional<Object> getVlanTagPropertyValue(Resource resource) {
+ Object vmiProperties = resource.getProperties().get(HeatConstants.VMI_PROPERTIES_PROPERTY_NAME);
+ if (Objects.nonNull(vmiProperties) && vmiProperties instanceof Map) {
+ return Optional.ofNullable(((Map) vmiProperties).get(HeatConstants.VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME));
+ }
+ return Optional.empty();
+ }
- private enum Messages {
- VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP("VLAN Resource will not be " +
- "translated as the VLAN Sub-interface [%s] is not modeled as resource group"),
- VLAN_GUIDELINE_VALIDATION_SINGLE_VLAN("There should not be any Compute Server Node, Port, " +
- "Parent Port in nested file [%s]"),
- VLAN_GUIDELINE_VALIDATION_NAMING_CONVENTION(
- "Network role associated with VLAN Sub-interface id[%s] is not following the naming convention");
+ private enum Messages {
+ // @formatter:off
+ VLAN_GUIDELINE_VALIDATION_NOT_MODELED_THROUGH_RESOURCE_GROUP("VLAN Resource will not be translated as the VLAN Sub-interface [%s] is not "
+ + "modeled as resource group"),
+ VLAN_GUIDELINE_VALIDATION_SINGLE_VLAN("There should not be any Compute Server Node, Port, Parent Port in nested file [%s]"),
+ VLAN_GUIDELINE_VALIDATION_NAMING_CONVENTION("Network role associated with VLAN Sub-interface id[%s] is not following the naming convention");
+ // @formatter:on
- private final String errorMessage;
+ private final String errorMessage;
- Messages(String errorMessage) {
- this.errorMessage = errorMessage;
- }
+ Messages(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
- String getErrorMessage() {
- return errorMessage;
+ String getErrorMessage() {
+ return errorMessage;
+ }
}
- }
-
-
-} \ No newline at end of file
+}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/tos/ContrailResourcesMappingTo.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/tos/ContrailResourcesMappingTo.java
index f351af0992..3b7d37105d 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/tos/ContrailResourcesMappingTo.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/tos/ContrailResourcesMappingTo.java
@@ -7,9 +7,9 @@
* 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.
@@ -17,102 +17,100 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.validation.tos;
-import org.apache.commons.collections4.MapUtils;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
+import org.apache.commons.collections4.MapUtils;
public class ContrailResourcesMappingTo {
- private Map<String, List<String>> contrailV1Resources;
- private Map<String, List<String>> contrailV2Resources;
- /**
- * Add ContrailV1Resource.
- *
- * @param fileName the file name
- * @param resourceName the resource name
- */
- public void addContrailV1Resource(String fileName, String resourceName) {
- if (MapUtils.isEmpty(contrailV1Resources)) {
- contrailV1Resources = new HashMap<>();
+ private Map<String, List<String>> contrailV1Resources;
+ private Map<String, List<String>> contrailV2Resources;
+
+ /**
+ * Add ContrailV1Resource.
+ *
+ * @param fileName the file name
+ * @param resourceName the resource name
+ */
+ public void addContrailV1Resource(String fileName, String resourceName) {
+ if (MapUtils.isEmpty(contrailV1Resources)) {
+ contrailV1Resources = new HashMap<>();
+ }
+ contrailV1Resources.putIfAbsent(fileName, new ArrayList<>());
+ contrailV1Resources.get(fileName).add(resourceName);
}
- contrailV1Resources.putIfAbsent(fileName, new ArrayList<>());
- contrailV1Resources.get(fileName).add(resourceName);
- }
- /**
- * Add ContrailV1Resource.
- *
- * @param fileName the file name
- * @param resourceName the resource name
- */
- public void addContrailV2Resource(String fileName, String resourceName) {
- if (MapUtils.isEmpty(contrailV2Resources)) {
- contrailV2Resources = new HashMap<>();
+ /**
+ * Add ContrailV1Resource.
+ *
+ * @param fileName the file name
+ * @param resourceName the resource name
+ */
+ public void addContrailV2Resource(String fileName, String resourceName) {
+ if (MapUtils.isEmpty(contrailV2Resources)) {
+ contrailV2Resources = new HashMap<>();
+ }
+ contrailV2Resources.putIfAbsent(fileName, new ArrayList<>());
+ contrailV2Resources.get(fileName).add(resourceName);
}
- contrailV2Resources.putIfAbsent(fileName, new ArrayList<>());
- contrailV2Resources.get(fileName).add(resourceName);
- }
- public void addAll(ContrailResourcesMappingTo contrailResourcesMappingTo) {
- addContrailV1Resources(contrailResourcesMappingTo.getContrailV1Resources());
- addContrailV2Resources(contrailResourcesMappingTo.getContrailV2Resources());
- }
+ public void addAll(ContrailResourcesMappingTo contrailResourcesMappingTo) {
+ addContrailV1Resources(contrailResourcesMappingTo.getContrailV1Resources());
+ addContrailV2Resources(contrailResourcesMappingTo.getContrailV2Resources());
+ }
- public String fetchContrailV1Resources() {
- return fetchContrailResources(contrailV1Resources);
- }
+ public String fetchContrailV1Resources() {
+ return fetchContrailResources(contrailV1Resources);
+ }
- public String fetchContrailV2Resources() {
- return fetchContrailResources(contrailV2Resources);
- }
+ public String fetchContrailV2Resources() {
+ return fetchContrailResources(contrailV2Resources);
+ }
- private void addContrailV1Resources(Map<String, List<String>> contrailV1Resources) {
- if (!MapUtils.isEmpty(contrailV1Resources)) {
- for (Map.Entry<String, List<String>> fileResourcesEntry : contrailV1Resources.entrySet()) {
- for (String resourceName : fileResourcesEntry.getValue()) {
- this.addContrailV1Resource(fileResourcesEntry.getKey(), resourceName);
+ private void addContrailV1Resources(Map<String, List<String>> contrailV1Resources) {
+ if (!MapUtils.isEmpty(contrailV1Resources)) {
+ for (Map.Entry<String, List<String>> fileResourcesEntry : contrailV1Resources.entrySet()) {
+ for (String resourceName : fileResourcesEntry.getValue()) {
+ this.addContrailV1Resource(fileResourcesEntry.getKey(), resourceName);
+ }
+ }
}
- }
}
- }
- private void addContrailV2Resources(Map<String, List<String>> contrailV2Resources) {
- if (!MapUtils.isEmpty(contrailV2Resources)) {
- for (Map.Entry<String, List<String>> fileResourcesEntry : contrailV2Resources.entrySet()) {
- for (String resourceName : fileResourcesEntry.getValue()) {
- this.addContrailV2Resource(fileResourcesEntry.getKey(), resourceName);
+ private void addContrailV2Resources(Map<String, List<String>> contrailV2Resources) {
+ if (!MapUtils.isEmpty(contrailV2Resources)) {
+ for (Map.Entry<String, List<String>> fileResourcesEntry : contrailV2Resources.entrySet()) {
+ for (String resourceName : fileResourcesEntry.getValue()) {
+ this.addContrailV2Resource(fileResourcesEntry.getKey(), resourceName);
+ }
+ }
}
- }
}
- }
- private String fetchContrailResources(Map<String, List<String>> contrailResources) {
- StringBuilder buffer = new StringBuilder();
- if (MapUtils.isEmpty(contrailResources)) {
- return "";
- }
- for (Map.Entry<String, List<String>> fileResourcesEntry : contrailResources.entrySet()) {
- buffer.append(" file '").append(fileResourcesEntry.getKey()).append("' , resources :");
- for (String resourceName : fileResourcesEntry.getValue()) {
- buffer.append("'").append(resourceName).append("', ");
- }
+ private String fetchContrailResources(Map<String, List<String>> contrailResources) {
+ StringBuilder buffer = new StringBuilder();
+ if (MapUtils.isEmpty(contrailResources)) {
+ return "";
+ }
+ for (Map.Entry<String, List<String>> fileResourcesEntry : contrailResources.entrySet()) {
+ buffer.append(" file '").append(fileResourcesEntry.getKey()).append("' , resources :");
+ for (String resourceName : fileResourcesEntry.getValue()) {
+ buffer.append("'").append(resourceName).append("', ");
+ }
+ }
+ buffer.deleteCharAt(buffer.lastIndexOf(","));
+ return buffer.toString();
}
- buffer.deleteCharAt(buffer.lastIndexOf(","));
- return buffer.toString();
- }
- public Map<String, List<String>> getContrailV1Resources() {
- return contrailV1Resources;
- }
+ public Map<String, List<String>> getContrailV1Resources() {
+ return contrailV1Resources;
+ }
- public Map<String, List<String>> getContrailV2Resources() {
- return contrailV2Resources;
- }
+ public Map<String, List<String>> getContrailV2Resources() {
+ return contrailV2Resources;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/type/ValidatorConstants.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/type/ValidatorConstants.java
index 7912dbd393..6197bda119 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/type/ValidatorConstants.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/type/ValidatorConstants.java
@@ -23,7 +23,8 @@ package org.openecomp.sdc.validation.type;
* Created by TALIO on 2/22/2017.
*/
public class ValidatorConstants {
- public static final String Security_Group = "SecurityGroup";
- public static final String Server_Group = "ServerGroup";
- public static final String Network_Policy = "NetworkPolicy";
+
+ public static final String Security_Group = "SecurityGroup";
+ public static final String Server_Group = "ServerGroup";
+ public static final String Network_Policy = "NetworkPolicy";
}