summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java
diff options
context:
space:
mode:
authormojahidi <mojahidul.islam@amdocs.com>2017-12-11 15:24:11 +0530
committerAvi Gaffa <avi.gaffa@amdocs.com>2017-12-13 09:56:50 +0000
commit4b1c2aaab1c3200076138d8702bc324d78a69fa8 (patch)
tree2da433920b70dad02e544a46bc31502403620a33 /openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java
parentb61cc21c17744ef927d4fca32aef6149f1b3910c (diff)
Adding Error code in HEAT Validators
added error code in NestedResourceValidator and ResourceGroupResourceValidator fixed sonar issues Change-Id: I1705b7103a3b3c42338f97cb4a7a255a6c85e88f Issue-ID: SDC-572 Signed-off-by: mojahidi <mojahidul.islam@amdocs.com> Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java334
-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.java81
-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.java118
3 files changed, 316 insertions, 217 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 d59d0a8def..90750a48ec 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
@@ -1,36 +1,29 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.validation.impl.util;
import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.sdc.heat.datatypes.model.*;
import org.openecomp.sdc.tosca.services.YamlUtil;
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.DefinedHeatParameterTypes;
-import org.openecomp.sdc.heat.datatypes.model.Environment;
-import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.openecomp.sdc.heat.datatypes.model.Parameter;
-import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
@@ -42,45 +35,43 @@ import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
import org.openecomp.sdc.validation.impl.validators.HeatValidator;
import java.io.InputStream;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
public class HeatValidationService {
- private static final Logger logger = (Logger) LoggerFactory.getLogger(HeatValidator.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(HeatValidator.class);
private static final String NESTED_FILE = "nested file";
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final String NO_CONTENT_IN_FILE_MSG = "The file ' %s ' has no content";
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ private HeatValidationService(){
+ }
/**
* Check artifacts existence.
*
- * @param fileName the file name
+ * @param fileName the file name
* @param artifactsNames the artifacts names
- * @param globalContext the global context
+ * @param globalContext the global context
*/
public static void checkArtifactsExistence(String fileName, Set<String> artifactsNames,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
artifactsNames
- .stream()
- .filter(artifactName -> !globalContext.getFileContextMap().containsKey(artifactName))
- .forEach(artifactName -> {
- globalContext.addMessage(fileName,
- ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(globalContext.getMessageCode(),Messages.MISSING_ARTIFACT.getErrorMessage()
- ,artifactName),
- LoggerTragetServiceName.VALIDATE_ARTIFACTS_EXISTENCE,
- LoggerErrorDescription.MISSING_FILE);
- });
-
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ .stream()
+ .filter(artifactName -> !globalContext.getFileContextMap().containsKey(artifactName))
+ .forEach(artifactName ->
+ globalContext.addMessage(fileName,
+ ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(
+ globalContext.getMessageCode(),
+ Messages.MISSING_ARTIFACT.getErrorMessage(), artifactName),
+ LoggerTragetServiceName.VALIDATE_ARTIFACTS_EXISTENCE,
+ LoggerErrorDescription.MISSING_FILE));
+
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
/**
@@ -109,74 +100,98 @@ public class HeatValidationService {
return stringBuilder.toString();
}
-
/**
* Check nested parameters.
*
- * @param parentFileName the calling nested file name
- * @param nestedFileName the nested file name
- * @param resourceName the resource name
- * @param globalContext the global context
- * @param resourceFileProperties the resource file properties
+ * @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.
*/
public static void checkNestedParameters(String parentFileName, String nestedFileName,
- String resourceName, Resource resource,
- Set<String> resourceFileProperties,
- Optional<String> indexVarValue,
- GlobalValidationContext globalContext) {
-
+ GlobalValidationContext globalContext,
+ Map<String, Parameter> parentParameters,
+ Map<String, Parameter> nestedParameters,
+ Set<String> nestedParametersNames) {
- mdcDataDebugMessage.debugEntryMessage("file", parentFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", parentFileName);
HeatOrchestrationTemplate parentHeatOrchestrationTemplate;
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
+
try {
- Optional<InputStream> fileContent = globalContext.getFileContent(nestedFileName);
- if (fileContent.isPresent()) {
- nestedHeatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
- LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
- ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(),
- LoggerErrorDescription.EMPTY_FILE);
- throw new Exception("The file '" + nestedFileName + "' has no content");
- }
+ nestedHeatOrchestrationTemplate = getHeatOrchestrationTemplate(nestedFileName, globalContext);
+ parentHeatOrchestrationTemplate = getHeatOrchestrationTemplate(parentFileName, globalContext);
} catch (Exception exception) {
- logger.debug("",exception);
- mdcDataDebugMessage.debugExitMessage("file", parentFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", parentFileName);
return;
}
- try {
- Optional<InputStream> fileContent = globalContext.getFileContent(parentFileName);
- if (fileContent.isPresent()) {
- parentHeatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
- LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
- ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(),
- LoggerErrorDescription.EMPTY_FILE);
- throw new Exception("The file '" + parentFileName + "' has no content");
- }
- } catch (Exception exception) {
- logger.debug("",exception);
- mdcDataDebugMessage.debugExitMessage("file", parentFileName);
- return;
+ parentParameters.putAll(parentHeatOrchestrationTemplate.getParameters());
+ nestedParameters.putAll(nestedHeatOrchestrationTemplate.getParameters());
+ if (!nestedParameters.isEmpty()) {
+ nestedParametersNames.addAll(nestedHeatOrchestrationTemplate.getParameters().keySet());
+ }
+
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", parentFileName);
+ }
+
+ 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 {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
+ LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
+ ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(),
+ LoggerErrorDescription.EMPTY_FILE);
+ Exception exception = new Exception(String.format(NO_CONTENT_IN_FILE_MSG, fileName));
+ LOGGER.error("Error while reading file : " + fileName , exception);
+ throw exception;
}
- Map<String, Parameter> parentParameters = parentHeatOrchestrationTemplate.getParameters();
- Map<String, Parameter> nestedParameters = nestedHeatOrchestrationTemplate.getParameters();
- Set<String> nestedParametersNames =
- nestedParameters == null ? null : nestedHeatOrchestrationTemplate.getParameters().keySet();
+ }
+
+ public static void checkNestedParametersNoMissingParameterInNested(String parentFileName,
+ String nestedFileName,
+ String resourceName,
+ Set<String> resourceFileProperties,
+ GlobalValidationContext globalContext) {
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", parentFileName);
+
+ 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);
- checkNestedInputValuesAlignWithType(parentFileName, nestedFileName, parentParameters,
- nestedParameters, resourceName, resource, indexVarValue, globalContext);
+ resourceFileProperties, nestedParametersNames, globalContext);
- mdcDataDebugMessage.debugExitMessage("file", parentFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", parentFileName);
+ }
+
+ public static void checkNestedInputValuesAlignWithType(String parentFileName,
+ String nestedFileName,
+ String resourceName, Resource resource,
+ Optional<String> indexVarValue,
+ GlobalValidationContext globalContext) {
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", parentFileName);
+
+ 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);
+
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", parentFileName);
}
private static void checkNoMissingParameterInNested(String parentFileName, String nestedFileName,
@@ -185,54 +200,49 @@ public class HeatValidationService {
Set<String> nestedParametersNames,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("nested file", nestedFileName);
if (CollectionUtils.isNotEmpty(nestedParametersNames)) {
resourceFileProperties
- .stream()
- .filter(propertyName -> !nestedParametersNames.contains(propertyName))
- .forEach(propertyName -> globalContext
- .addMessage(parentFileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages
- .MISSING_PARAMETER_IN_NESTED.getErrorMessage(),
- nestedFileName, resourceName, propertyName),
- LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
- LoggerErrorDescription.MISSING_PARAMETER_IN_NESTED));
+ .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),
+ LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
+ LoggerErrorDescription.MISSING_PARAMETER_IN_NESTED));
}
- mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(NESTED_FILE, nestedFileName);
}
-
private static void checkNestedInputValuesAlignWithType(String parentFileName,
String nestedFileName,
- Map<String, Parameter> parentParameters,
Map<String, Parameter> nestedParameters,
String resourceName, Resource resource,
Optional<String> indexVarValue,
GlobalValidationContext globalContext) {
-
- mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(NESTED_FILE, nestedFileName);
Map<String, Object> properties = resource.getProperties();
for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
String parameterName = propertyEntry.getKey();
Object parameterInputValue = propertyEntry.getValue();
-
- if (Objects.nonNull(parameterInputValue)) {
- 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);
+ 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);
}
}
- mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(NESTED_FILE, nestedFileName);
}
private static void validateStaticValueForNestedInputParameter(String parentFileName,
@@ -242,25 +252,24 @@ public class HeatValidationService {
Object staticValue,
Parameter parameterInNested,
GlobalValidationContext
- globalContext) {
-
+ globalContext) {
- mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(NESTED_FILE, nestedFileName);
if (parameterInNested == null) {
return;
}
if (!DefinedHeatParameterTypes
- .isValueIsFromGivenType(staticValue, parameterInNested.getType())) {
+ .isValueIsFromGivenType(staticValue, parameterInNested.getType())) {
globalContext.addMessage(parentFileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages
- .WRONG_VALUE_TYPE_ASSIGNED_NESTED_INPUT.getErrorMessage(),
- resourceName, parameterName, nestedFileName),
- LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
- LoggerErrorDescription.WRONG_VALUE_ASSIGNED_NESTED_PARAMETER);
+ .getErrorWithParameters(globalContext.getMessageCode(),
+ Messages.WRONG_VALUE_TYPE_ASSIGNED_NESTED_INPUT.getErrorMessage(),
+ resourceName, parameterName, nestedFileName),
+ LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
+ LoggerErrorDescription.WRONG_VALUE_ASSIGNED_NESTED_PARAMETER);
}
- mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(NESTED_FILE, nestedFileName);
}
@@ -268,58 +277,72 @@ public class HeatValidationService {
* 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
+ * @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) {
-
- mdcDataDebugMessage.debugEntryMessage("file", callingFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", callingFileName);
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
try {
- Optional<InputStream> fileContent = globalContext.getFileContent(nestedFileName);
- if (fileContent.isPresent()) {
- nestedHeatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
- LoggerTragetServiceName.VALIDATE_NESTING_LOOPS, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.EMPTY_FILE);
- throw new Exception("The file '" + nestedFileName + "' has no content");
- }
-
+ nestedHeatOrchestrationTemplate = getNestedHeatOrchestrationTemplate(nestedFileName,
+ globalContext);
} catch (Exception exception) {
- logger.debug("",exception);
- logger.warn("HEAT Validator will not be executed on file " + nestedFileName
- + " due to illegal HEAT format");
+ LOGGER.error("Error while reading file : " + nestedFileName, exception);
+ LOGGER.warn("HEAT Validator will not be executed on file " + nestedFileName
+ + " due to illegal HEAT format");
- mdcDataDebugMessage.debugExitMessage("file", callingFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", callingFileName);
return false;
}
filesInLoop.add(nestedFileName);
Collection<Resource> nestedResources =
- nestedHeatOrchestrationTemplate.getResources() == null ? null
- : nestedHeatOrchestrationTemplate.getResources().values();
+ nestedHeatOrchestrationTemplate.getResources() == null ? null
+ : nestedHeatOrchestrationTemplate.getResources().values();
+ boolean isNestedLoopExist = addNestedFilesInLoopAndCheckIfNestedLoopExist(nestedResources,
+ callingFileName, filesInLoop, globalContext);
+
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", callingFileName);
+ return isNestedLoopExist;
+ }
+ 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)) {
- mdcDataDebugMessage.debugExitMessage("file", callingFileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", callingFileName);
return resourceType.equals(callingFileName) || !filesInLoop.contains(resourceType)
- && isNestedLoopExistInFile(callingFileName, resourceType, filesInLoop, globalContext);
+ && isNestedLoopExistInFile(callingFileName, resourceType, filesInLoop, globalContext);
}
}
}
-
- mdcDataDebugMessage.debugExitMessage("file", callingFileName);
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 {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
+ LoggerTragetServiceName.VALIDATE_NESTING_LOOPS, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.EMPTY_FILE);
+ throw new Exception(String.format(NO_CONTENT_IN_FILE_MSG, nestedFileName));
+ }
+
+ return nestedHeatOrchestrationTemplate;
+ }
public static boolean isNestedResource(String resourceType) {
return resourceType.contains(".yaml") || resourceType.contains(".yml");
@@ -328,31 +351,30 @@ public class HeatValidationService {
/**
* Validate env content environment.
*
- * @param fileName the file name
- * @param envFileName the env file name
+ * @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) {
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("env file", envFileName);
- mdcDataDebugMessage.debugEntryMessage("env file", envFileName);
-
- Environment envContent = null;
+ Environment envContent;
try {
Optional<InputStream> fileContent = globalContext.getFileContent(envFileName);
if (fileContent.isPresent()) {
envContent = new YamlUtil().yamlToObject(fileContent.get(), Environment.class);
} else {
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
- LoggerTragetServiceName.VALIDATE_ENV_FILE, ErrorLevel.ERROR.name(),
- LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.EMPTY_FILE);
- throw new Exception("The file '" + envFileName + "' has no content");
+ LoggerTragetServiceName.VALIDATE_ENV_FILE, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.EMPTY_FILE);
+ throw new Exception(String.format(NO_CONTENT_IN_FILE_MSG, envFileName));
}
} catch (Exception exception) {
- logger.debug("",exception);
- mdcDataDebugMessage.debugExitMessage("env file", envFileName);
+ LOGGER.error("Error while reading env file : " + envFileName, exception);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("env file", envFileName);
return null;
}
return envContent;
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 aa7b91826c..41897f4563 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
@@ -1,6 +1,23 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.openecomp.sdc.validation.impl.validators.heatresource;
import org.apache.commons.collections4.CollectionUtils;
+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;
@@ -24,71 +41,83 @@ import java.util.Set;
* Created by TALIO on 2/22/2017.
*/
public class NestedResourceValidator implements ResourceValidator {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ 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){
+ GlobalValidationContext globalContext, ValidationContext validationContext) {
handleNestedResourceType(fileName, resourceEntry.getKey(), resourceEntry.getValue(),
- Optional.empty(), globalContext);
+ Optional.empty(), globalContext);
}
private static void handleNestedResourceType(String fileName, String resourceName,
Resource resource, Optional<String> indexVarValue,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue,
- globalContext);
+ globalContext);
validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
public static void validateAllPropertiesMatchNestedParameters(String fileName,
- String resourceName,
- Resource resource,
- Optional<String> indexVarValue,
- GlobalValidationContext
- globalContext) {
+ String resourceName,
+ Resource resource,
+ Optional<String> indexVarValue,
+ GlobalValidationContext
+ globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
String resourceType = resource.getType();
if (globalContext.getFileContextMap().containsKey(resourceType)) {
Set<String> propertiesNames =
- resource.getProperties() == null ? null : resource.getProperties().keySet();
+ 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
- .checkNestedParameters(fileName, resourceType, resourceName, resource, propertiesNames,
- indexVarValue, globalContext);
+ .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource,
+ indexVarValue, globalContext);
}
} else {
globalContext.addMessage(resourceType, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_NESTED_FILE.getErrorMessage(), resourceType),
- LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
- LoggerErrorDescription.MISSING_FILE);
+ .getErrorWithParameters(ERROR_CODE_HNR1,
+ Messages.MISSING_NESTED_FILE.getErrorMessage(),
+ resourceType),
+ LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
+ LoggerErrorDescription.MISSING_FILE);
}
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
public static void validateLoopsOfNestingFromFile(String fileName, String resourceType,
- GlobalValidationContext globalContext) {
+ GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
if (HeatValidationService
- .isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
+ .isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.NESTED_LOOP.getErrorMessage(),
- HeatValidationService.drawFilesLoop(filesInLoop)),
- LoggerTragetServiceName.VALIDATE_NESTING_LOOPS, LoggerErrorDescription.NESTED_LOOP);
+ .getErrorWithParameters(ERROR_CODE_HNR2, Messages.NESTED_LOOP.getErrorMessage(),
+ HeatValidationService.drawFilesLoop(filesInLoop)),
+ LoggerTragetServiceName.VALIDATE_NESTING_LOOPS, LoggerErrorDescription.NESTED_LOOP);
}
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
}
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 c94875c9f2..06794923cf 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
@@ -1,6 +1,23 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.openecomp.sdc.validation.impl.validators.heatresource;
import org.apache.commons.collections4.CollectionUtils;
+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;
@@ -27,7 +44,16 @@ import java.util.Set;
* Created by TALIO on 2/22/2017.
*/
public class ResourceGroupResourceValidator implements ResourceValidator {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+
+ 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,
@@ -39,28 +65,39 @@ public class ResourceGroupResourceValidator implements ResourceValidator {
Map.Entry<String, Resource> resourceEntry,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
-
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
+
+ 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(fileName, resourceEntry.getKey(), resourceEntry.getValue(), globalContext);
- if (resourceDef != null) {
- if (Objects.nonNull(resourceDef.getType())
- && HeatValidationService.isNestedResource(resourceDef.getType())) {
+ .getResourceDef( resourceEntry.getValue());
+
+ if (resourceDef != null && Objects.nonNull(resourceDef.getType())
+ && HeatValidationService.isNestedResource(resourceDef.getType())) {
Optional<String> indexVarValue =
- getResourceGroupIndexVarValue(resourceEntry, fileName, globalContext);
+ getResourceGroupIndexVarValue(resourceEntry, fileName, globalContext);
handleNestedResourceType(fileName, resourceEntry.getKey(), resourceDef, indexVarValue,
- globalContext);
- }
+ globalContext);
+
}
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
private static Optional<String> getResourceGroupIndexVarValue(
- Map.Entry<String, Resource> resourceEntry, String fileName,
- GlobalValidationContext globalContext) {
+ Map.Entry<String, Resource> resourceEntry, String fileName,
+ GlobalValidationContext globalContext) {
Object indexVar =
- resourceEntry.getValue().getProperties().get(HeatConstants.INDEX_PROPERTY_NAME);
+ resourceEntry.getValue().getProperties().get(HeatConstants.INDEX_PROPERTY_NAME);
if (indexVar == null) {
return Optional.of(HeatConstants.RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE);
}
@@ -69,9 +106,11 @@ public class ResourceGroupResourceValidator implements ResourceValidator {
return Optional.of((String) indexVar);
} else {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.RESOURCE_GROUP_INVALID_INDEX_VAR.getErrorMessage(),
- resourceEntry.getKey()), LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE,
- LoggerErrorDescription.INVALID_INDEX_VAR);
+ .getErrorWithParameters(
+ ERROR_CODE_HRR1, Messages.RESOURCE_GROUP_INVALID_INDEX_VAR.getErrorMessage(),
+ resourceEntry.getKey()),
+ LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE,
+ LoggerErrorDescription.INVALID_INDEX_VAR);
return Optional.empty();
}
}
@@ -80,13 +119,13 @@ public class ResourceGroupResourceValidator implements ResourceValidator {
Resource resource, Optional<String> indexVarValue,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue,
- globalContext);
+ globalContext);
validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
private static void validateAllPropertiesMatchNestedParameters(String fileName,
@@ -94,43 +133,52 @@ public class ResourceGroupResourceValidator implements ResourceValidator {
Resource resource,
Optional<String> indexVarValue,
GlobalValidationContext
- globalContext) {
+ globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
String resourceType = resource.getType();
if (globalContext.getFileContextMap().containsKey(resourceType)) {
Set<String> propertiesNames =
- resource.getProperties() == null ? null : resource.getProperties().keySet();
+ 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
- .checkNestedParameters(fileName, resourceType, resourceName, resource, propertiesNames,
- indexVarValue, globalContext);
+ .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource,
+ indexVarValue, globalContext);
}
} else {
globalContext.addMessage(resourceType, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_NESTED_FILE.getErrorMessage(), resourceType),
- LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
- LoggerErrorDescription.MISSING_FILE);
+ .getErrorWithParameters(
+ ERROR_CODE_HRR2, Messages.MISSING_NESTED_FILE.getErrorMessage(),
+ resourceType),
+ LoggerTragetServiceName.VALIDATE_PROPERTIES_MATCH_NESTED_PARAMETERS,
+ LoggerErrorDescription.MISSING_FILE);
}
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
private static void validateLoopsOfNestingFromFile(String fileName, String resourceType,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
if (HeatValidationService
- .isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
+ .isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.NESTED_LOOP.getErrorMessage(),
- HeatValidationService.drawFilesLoop(filesInLoop)),
- LoggerTragetServiceName.VALIDATE_NESTING_LOOPS, LoggerErrorDescription.NESTED_LOOP);
+ .getErrorWithParameters(
+ ERROR_CODE_HRR3, Messages.NESTED_LOOP.getErrorMessage(),
+ HeatValidationService.drawFilesLoop(filesInLoop)),
+ LoggerTragetServiceName.VALIDATE_NESTING_LOOPS, LoggerErrorDescription.NESTED_LOOP);
}
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
}