aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/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-sdk/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-sdk/src')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/ResourceValidator.java7
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/Validator.java11
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/base/ResourceBaseValidator.java203
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/ConfigConstants.java17
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/HeatResourceValidationContext.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/NamingConventionValidationContext.java9
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java304
7 files changed, 260 insertions, 324 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/ResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/ResourceValidator.java
index ff0e65c9e3..f5c33c48ec 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/ResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/ResourceValidator.java
@@ -19,16 +19,15 @@
*/
package org.openecomp.sdc.validation;
+import java.util.Map;
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.heat.datatypes.model.Resource;
-import java.util.Map;
-
/**
* Created by TALIO on 2/23/2017.
*/
public interface ResourceValidator {
- void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext);
+ void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext);
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/Validator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/Validator.java
index 3ed7e74749..5ab83c5854 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/Validator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/Validator.java
@@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation;
-import org.openecomp.core.validation.types.GlobalValidationContext;
-
import java.util.Map;
-
+import org.openecomp.core.validation.types.GlobalValidationContext;
public interface Validator {
- void validate(GlobalValidationContext globalContext);
- default void init(Map<String, Object> properties){ }
+ void validate(GlobalValidationContext globalContext);
+
+ default void init(Map<String, Object> properties) {
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/base/ResourceBaseValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/base/ResourceBaseValidator.java
index a15c7678f7..50d8a86954 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/base/ResourceBaseValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/base/ResourceBaseValidator.java
@@ -12,10 +12,12 @@
* 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.base;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.core.validation.ErrorMessageCode;
@@ -38,145 +40,108 @@ import org.openecomp.sdc.validation.Validator;
import org.openecomp.sdc.validation.type.ConfigConstants;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
/**
* Created by TALIO on 2/16/2017.
*/
public class ResourceBaseValidator implements Validator {
- protected final Map<String, ImplementationConfiguration> resourceTypeToImpl = new HashMap<>();
- private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBaseValidator.class);
- private static final ErrorMessageCode ERROR_CODE_RBV_1 = new ErrorMessageCode("RBV1");
- private static final ErrorMessageCode ERROR_CODE_RBV_2 = new ErrorMessageCode("RBV2");
-
- Map<String, ImplementationConfiguration> getResourceTypeToImpl() {
- return MapUtils.unmodifiableMap(this.resourceTypeToImpl);
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBaseValidator.class);
+ private static final ErrorMessageCode ERROR_CODE_RBV_1 = new ErrorMessageCode("RBV1");
+ private static final ErrorMessageCode ERROR_CODE_RBV_2 = new ErrorMessageCode("RBV2");
+ protected final Map<String, ImplementationConfiguration> resourceTypeToImpl = new HashMap<>();
- @Override
- public void init(Map<String, Object> properties) {
- if (MapUtils.isEmpty(properties)) {
- return;
+ private static boolean isSupportedResourceType(String resourceType, Map<String, ImplementationConfiguration> resourceTypeToImpl) {
+ return resourceTypeToImpl.containsKey(resourceType) && resourceTypeToImpl.get(resourceType).isEnable();
}
- properties.entrySet().stream()
- .filter(entry -> getImplementationConfigurationFromProperties(entry.getValue()) != null)
- .forEach(entry -> resourceTypeToImpl
- .put(entry.getKey(), getImplementationConfigurationFromProperties(entry.getValue())));
- }
-
- @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 ResourceValidator getResourceValidatorInstance(String resourceType, Map<String, ImplementationConfiguration> resourceTypeToImpl) {
+ ResourceValidator resourceBaseValidator = null;
+ if (isSupportedResourceType(resourceType, resourceTypeToImpl)) {
+ return getValidatorImpl(resourceType, resourceTypeToImpl);
+ }
+ if (HeatStructureUtil.isNestedResource(resourceType)) {
+ return getValidatorImpl("nestedResource", resourceTypeToImpl);
+ }
+ return resourceBaseValidator;
}
- Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
- Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent);
- globalContext.getFiles().stream()
- .filter(fileName -> FileData
- .isHeatFile(fileTypeMap.get(fileName)))
- .forEach(fileName -> validate(fileName,
- fileEnvMap.get(fileName) != null ? fileEnvMap.get(fileName).getFile() : null,
- globalContext));
- }
-
- private void validate(String fileName, String envFileName,
- GlobalValidationContext globalContext) {
- globalContext.setMessageCode(ERROR_CODE_RBV_2);
- HeatOrchestrationTemplate heatOrchestrationTemplate =
- ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
- if (heatOrchestrationTemplate == null) {
- return;
+ private static ResourceValidator getValidatorImpl(String resourceType, Map<String, ImplementationConfiguration> resourceTypeToImpl) {
+ String implementationClass =
+ resourceTypeToImpl.get(resourceType) != null ? resourceTypeToImpl.get(resourceType).getImplementationClass() : null;
+ return implementationClass == null ? null : CommonMethods.newInstance(implementationClass, ResourceValidator.class);
}
- ValidationContext validationContext =
- createValidationContext(fileName, envFileName, heatOrchestrationTemplate, globalContext);
-
- Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
- if (MapUtils.isEmpty(resourcesMap)) {
- return;
+ Map<String, ImplementationConfiguration> getResourceTypeToImpl() {
+ return MapUtils.unmodifiableMap(this.resourceTypeToImpl);
}
- 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_RBV_1,
- Messages.INVALID_RESOURCE_TYPE.getErrorMessage(),"null",
- resourceEntry.getKey()));
- } else {
- ResourceValidator
- resourceValidatorImpl = getResourceValidatorInstance(resourceType, resourceTypeToImpl);
- if (Objects.nonNull(resourceValidatorImpl)) {
- resourceValidatorImpl.validate(fileName, resourceEntry, globalContext,
- validationContext);
+ @Override
+ public void init(Map<String, Object> properties) {
+ if (MapUtils.isEmpty(properties)) {
+ return;
}
- }
+ properties.entrySet().stream().filter(entry -> getImplementationConfigurationFromProperties(entry.getValue()) != null)
+ .forEach(entry -> resourceTypeToImpl.put(entry.getKey(), getImplementationConfigurationFromProperties(entry.getValue())));
}
- }
-
- public ValidationContext createValidationContext(String fileName,
- String envFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- return null;
- }
-
- private static boolean isSupportedResourceType(String resourceType,
- Map<String, ImplementationConfiguration> resourceTypeToImpl) {
- return resourceTypeToImpl.containsKey(resourceType) && resourceTypeToImpl.get(resourceType)
- .isEnable();
-
- }
- private static ResourceValidator getResourceValidatorInstance(String resourceType,
- Map<String, ImplementationConfiguration> resourceTypeToImpl) {
- ResourceValidator resourceBaseValidator = null;
- if (isSupportedResourceType(resourceType, resourceTypeToImpl)) {
- return getValidatorImpl(resourceType, resourceTypeToImpl);
- }
- if (HeatStructureUtil.isNestedResource(resourceType)) {
- return getValidatorImpl("nestedResource", resourceTypeToImpl);
+ @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);
+ globalContext.getFiles().stream().filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName)))
+ .forEach(fileName -> validate(fileName, fileEnvMap.get(fileName) != null ? fileEnvMap.get(fileName).getFile() : null, globalContext));
}
- return resourceBaseValidator;
- }
-
- private static ResourceValidator getValidatorImpl(String resourceType,
- Map<String, ImplementationConfiguration> resourceTypeToImpl) {
- String implementationClass = resourceTypeToImpl.get(resourceType) != null ?
- resourceTypeToImpl.get(resourceType).getImplementationClass() : null;
- return implementationClass == null ? null : CommonMethods
- .newInstance(implementationClass, ResourceValidator.class);
- }
-
- private ImplementationConfiguration getImplementationConfigurationFromProperties(Object value) {
- ImplementationConfiguration implementationConfiguration = new ImplementationConfiguration();
- if (!(value instanceof Map)) {
- return null;
+ private void validate(String fileName, String envFileName, GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_RBV_2);
+ HeatOrchestrationTemplate heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ if (heatOrchestrationTemplate == null) {
+ return;
+ }
+ ValidationContext validationContext = createValidationContext(fileName, envFileName, heatOrchestrationTemplate, 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_RBV_1, Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", resourceEntry.getKey()));
+ } else {
+ ResourceValidator resourceValidatorImpl = getResourceValidatorInstance(resourceType, resourceTypeToImpl);
+ if (Objects.nonNull(resourceValidatorImpl)) {
+ resourceValidatorImpl.validate(fileName, resourceEntry, globalContext, validationContext);
+ }
+ }
+ }
}
- Map<String, Object> valueAsMap = (Map<String, Object>) value;
- if (!(valueAsMap.containsKey(ConfigConstants.Impl_Class))) {
- return null;
+ public ValidationContext createValidationContext(String fileName, String envFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ return null;
}
- implementationConfiguration.setImplementationClass(
- valueAsMap.get(ConfigConstants.Impl_Class).toString());
- if (valueAsMap.containsKey(ConfigConstants.Enable)) {
- implementationConfiguration.setEnable(Boolean.
- valueOf(valueAsMap.get(ConfigConstants.Enable).toString()));
+ private ImplementationConfiguration getImplementationConfigurationFromProperties(Object value) {
+ ImplementationConfiguration implementationConfiguration = new ImplementationConfiguration();
+ if (!(value instanceof Map)) {
+ return null;
+ }
+ Map<String, Object> valueAsMap = (Map<String, Object>) value;
+ if (!(valueAsMap.containsKey(ConfigConstants.Impl_Class))) {
+ return null;
+ }
+ implementationConfiguration.setImplementationClass(valueAsMap.get(ConfigConstants.Impl_Class).toString());
+ if (valueAsMap.containsKey(ConfigConstants.Enable)) {
+ implementationConfiguration.setEnable(Boolean.valueOf(valueAsMap.get(ConfigConstants.Enable).toString()));
+ }
+ return implementationConfiguration;
}
-
- return implementationConfiguration;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/ConfigConstants.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/ConfigConstants.java
index aacaa10c11..45ac08edeb 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/ConfigConstants.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/ConfigConstants.java
@@ -23,14 +23,15 @@ package org.openecomp.sdc.validation.type;
* Created by TALIO on 1/30/2017.
*/
public class ConfigConstants {
- public static final String Enable = "enable";
- public static final String Impl_Class = "implementationClass";
- public static final String Resource_Base_Validator = "resourceBaseValidator";
- public static final String Namespace = "validation";
- public static final String Mandatory_Namespace = "mandatoryValidation";
- public static final String Validator_Impl_Key = "validatorImplementations";
- public static final String Nested_Resource_Key = "nestedResource";
+ public static final String Enable = "enable";
+ public static final String Impl_Class = "implementationClass";
+ public static final String Resource_Base_Validator = "resourceBaseValidator";
+ public static final String Namespace = "validation";
+ public static final String Mandatory_Namespace = "mandatoryValidation";
+ public static final String Validator_Impl_Key = "validatorImplementations";
+ public static final String Nested_Resource_Key = "nestedResource";
- private ConfigConstants(){}
+ private ConfigConstants() {
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/HeatResourceValidationContext.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/HeatResourceValidationContext.java
index 97703b1de0..5921b51c77 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/HeatResourceValidationContext.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/HeatResourceValidationContext.java
@@ -15,13 +15,12 @@
*/
package org.openecomp.sdc.validation.type;
-import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.openecomp.sdc.validation.ValidationContext;
-
import java.util.List;
import java.util.Map;
-import lombok.Getter;
import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.validation.ValidationContext;
/**
* Created by TALIO on 2/23/2017.
@@ -30,21 +29,19 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class HeatResourceValidationContext implements ValidationContext {
- private HeatOrchestrationTemplate heatOrchestrationTemplate;
- // key - resource type, value - map with key = resource id and
- // value = map with key = pointing / pointed resource type and
- // value = pointing / pointed resource id
- private Map<String, Map<String, Map<String, List<String>>>> fileLevelResourceDependencies;
- private String envFileName;
+ private HeatOrchestrationTemplate heatOrchestrationTemplate;
+ // key - resource type, value - map with key = resource id and
+ // value = map with key = pointing / pointed resource type and
- public HeatResourceValidationContext(
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Map<String, Map<String, Map<String, List<String>>>> fileLevelResourceDependencies,
- String envFileName) {
+ // value = pointing / pointed resource id
+ private Map<String, Map<String, Map<String, List<String>>>> fileLevelResourceDependencies;
+ private String envFileName;
- this.heatOrchestrationTemplate = heatOrchestrationTemplate;
- this.fileLevelResourceDependencies = fileLevelResourceDependencies;
- this.envFileName = envFileName;
- }
+ public HeatResourceValidationContext(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ Map<String, Map<String, Map<String, List<String>>>> fileLevelResourceDependencies, String envFileName) {
+ this.heatOrchestrationTemplate = heatOrchestrationTemplate;
+ this.fileLevelResourceDependencies = fileLevelResourceDependencies;
+ this.envFileName = envFileName;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/NamingConventionValidationContext.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/NamingConventionValidationContext.java
index 7bad45f5fd..3058d36ed3 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/NamingConventionValidationContext.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/type/NamingConventionValidationContext.java
@@ -16,12 +16,11 @@
package org.openecomp.sdc.validation.type;
import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.validation.ValidationContext;
-import lombok.Getter;
-import lombok.EqualsAndHashCode;
-
/**
* Created by TALIO on 2/23/2017.
*/
@@ -30,6 +29,6 @@ import lombok.EqualsAndHashCode;
@AllArgsConstructor
public class NamingConventionValidationContext implements ValidationContext {
- private HeatOrchestrationTemplate heatOrchestrationTemplate;
- private String envFileName;
+ private HeatOrchestrationTemplate heatOrchestrationTemplate;
+ private String envFileName;
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java
index a741df1b79..28613c96df 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java
@@ -12,10 +12,17 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-*/
-
+ */
package org.openecomp.sdc.validation.util;
+import static java.util.Objects.nonNull;
+
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Pattern;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.utilities.json.JsonUtil;
@@ -26,190 +33,159 @@ import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
-import org.openecomp.sdc.heat.datatypes.model.*;
+import org.openecomp.sdc.heat.datatypes.model.Environment;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions;
import org.openecomp.sdc.heat.services.HeatStructureUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import static java.util.Objects.nonNull;
-
public class ValidationUtil {
- private static final Logger LOG = LoggerFactory.getLogger(ValidationUtil.class.getName());
-
- private ValidationUtil(){}
-
- public static void removeExposedResourcesCalledByGetResource(String fileName,
- Set<String> actualExposedResources,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
- for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
- Set<String> referencedResources =
- HeatStructureUtil.getReferencedValuesByFunctionName(fileName, ResourceReferenceFunctions
- .GET_RESOURCE
- .getFunction(), resourceEntry.getValue().getProperties(), globalContext);
+ private static final Logger LOG = LoggerFactory.getLogger(ValidationUtil.class.getName());
- removeExposedResourcesCalledByGetResource(referencedResources, actualExposedResources,
- resourcesMap);
+ private ValidationUtil() {
}
- }
-
- private static void removeExposedResourcesCalledByGetResource(Set<String> referencedResources,
- Set<String>
- actualExposedResources,
- Map<String, Resource> resourcesMap) {
- for (String referencedResourceName : referencedResources) {
- Resource currResource = resourcesMap.get(referencedResourceName);
- if (Objects.nonNull(currResource) && isExpectedToBeExposed(currResource.getType())) {
- actualExposedResources.add(referencedResourceName);
- }
- }
- }
-
- public static boolean isExpectedToBeExposed(String type) {
- return HeatResourcesTypes.isResourceExpectedToBeExposed(type);
- }
-
- public static String getWantedNameFromPropertyValueGetParam(Object value) {
- Set<String> paramName = HeatStructureUtil
- .getReferencedValuesByFunctionName(null, ResourceReferenceFunctions.GET_PARAM.getFunction(),
- value, null);
- if (paramName != null && CollectionUtils.isNotEmpty(paramName)) {
- return (String) paramName.toArray()[0];
- }
- return null;
- }
- public static boolean evalPattern(Object paramVal, String[] regexList) {
- String value = "";
- if (paramVal instanceof String) {
- value = (String) paramVal;
+ public static void removeExposedResourcesCalledByGetResource(String fileName, Set<String> actualExposedResources,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
+ for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
+ Set<String> referencedResources = HeatStructureUtil
+ .getReferencedValuesByFunctionName(fileName, ResourceReferenceFunctions.GET_RESOURCE.getFunction(),
+ resourceEntry.getValue().getProperties(), globalContext);
+ removeExposedResourcesCalledByGetResource(referencedResources, actualExposedResources, resourcesMap);
+ }
}
- if (paramVal instanceof Integer) {
- value = paramVal.toString();
- }
- return evalPattern(value, regexList);
- }
-
- private static boolean evalPattern(String paramVal, String[] regexList) {
- for (String regex : regexList) {
- if (Pattern.matches(regex, paramVal)) {
- return true;
- }
+ private static void removeExposedResourcesCalledByGetResource(Set<String> referencedResources, Set<String> actualExposedResources,
+ Map<String, Resource> resourcesMap) {
+ for (String referencedResourceName : referencedResources) {
+ Resource currResource = resourcesMap.get(referencedResourceName);
+ if (Objects.nonNull(currResource) && isExpectedToBeExposed(currResource.getType())) {
+ actualExposedResources.add(referencedResourceName);
+ }
+ }
}
- return false;
- }
-
- public static String getMessagePartAccordingToResourceType(Map.Entry<String, Resource>
- resourceEntry) {
- HeatResourcesTypes resourcesType =
- HeatResourcesTypes.findByHeatResource(resourceEntry.getValue().getType());
- if (resourcesType == HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE) {
- return "Server";
- } else if (resourcesType == HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE) {
- return "Service Template";
- } else if (resourcesType == HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE) {
- return "Service Instance";
- } else {
- return "";
+ public static boolean isExpectedToBeExposed(String type) {
+ return HeatResourcesTypes.isResourceExpectedToBeExposed(type);
}
- }
-
- public static Environment validateEnvContent(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("The file '" + envFileName + "' has no content");
- }
- } catch (Exception exception) {
- LOG.error("Invalid envFile name : " + envFileName, exception);
- return null;
+
+ public static String getWantedNameFromPropertyValueGetParam(Object value) {
+ Set<String> paramName = HeatStructureUtil
+ .getReferencedValuesByFunctionName(null, ResourceReferenceFunctions.GET_PARAM.getFunction(), value, null);
+ if (paramName != null && CollectionUtils.isNotEmpty(paramName)) {
+ return (String) paramName.toArray()[0];
+ }
+ return null;
}
- return envContent;
- }
-
- public static boolean validateMapPropertyValue(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- String propertyName, Object nameValue,
- String[] regexList) {
- String propertyValue = getWantedNameFromPropertyValueGetParam(nameValue);
- if (nonNull(propertyValue) && !evalPattern(propertyValue, regexList)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder.getErrorWithParameters(globalContext.getMessageCode(),
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- getMessagePartAccordingToResourceType(resourceEntry), propertyName, propertyValue,
- resourceEntry.getKey()));
- return true;
- }
- return false;
- }
-
- public static ManifestContent validateManifest(GlobalValidationContext globalContext) {
- Optional<InputStream> manifest = globalContext.getFileContent(SdcCommon.MANIFEST_NAME);
- if (!manifest.isPresent()) {
- throw new RuntimeException("Can't load manifest file for Heat Validator");
+
+ public static boolean evalPattern(Object paramVal, String[] regexList) {
+ String value = "";
+ if (paramVal instanceof String) {
+ value = (String) paramVal;
+ }
+ if (paramVal instanceof Integer) {
+ value = paramVal.toString();
+ }
+ return evalPattern(value, regexList);
}
- ManifestContent manifestContent;
- try {
- manifestContent = JsonUtil.json2Object(manifest.get(), ManifestContent.class);
- } catch (Exception exception) {
- throw new SdcRuntimeException("Can't load manifest file for Heat Validator", exception);
+
+ private static boolean evalPattern(String paramVal, String[] regexList) {
+ for (String regex : regexList) {
+ if (Pattern.matches(regex, paramVal)) {
+ return true;
+ }
+ }
+ return false;
}
- return manifestContent;
- }
+ public static String getMessagePartAccordingToResourceType(Map.Entry<String, Resource> resourceEntry) {
+ HeatResourcesTypes resourcesType = HeatResourcesTypes.findByHeatResource(resourceEntry.getValue().getType());
+ if (resourcesType == HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE) {
+ return "Server";
+ } else if (resourcesType == HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE) {
+ return "Service Template";
+ } else if (resourcesType == HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE) {
+ return "Service Instance";
+ } else {
+ return "";
+ }
+ }
- public static String getParserExceptionReason(Exception exception) {
- String reason;
+ public static Environment validateEnvContent(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("The file '" + envFileName + "' has no content");
+ }
+ } catch (Exception exception) {
+ LOG.error("Invalid envFile name : " + envFileName, exception);
+ return null;
+ }
+ return envContent;
+ }
- if (exception.getCause() != null && exception.getCause().getCause() != null) {
- reason = exception.getCause().getCause().getMessage();
- } else if (exception.getCause() != null) {
- reason = exception.getCause().getMessage();
- } else {
- reason = Messages.GENERAL_HEAT_PARSER_ERROR.getErrorMessage();
+ public static boolean validateMapPropertyValue(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ String propertyName, Object nameValue, String[] regexList) {
+ String propertyValue = getWantedNameFromPropertyValueGetParam(nameValue);
+ if (nonNull(propertyValue) && !evalPattern(propertyValue, regexList)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(globalContext.getMessageCode(), Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
+ getMessagePartAccordingToResourceType(resourceEntry), propertyName, propertyValue, resourceEntry.getKey()));
+ return true;
+ }
+ return false;
}
- return reason;
- }
-
- public static HeatOrchestrationTemplate checkHeatOrchestrationPreCondition(String fileName,
- GlobalValidationContext globalContext) {
- HeatOrchestrationTemplate heatOrchestrationTemplate;
- try {
- Optional<InputStream> fileContent = globalContext.getFileContent(fileName);
- if (fileContent.isPresent()) {
- heatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- heatOrchestrationTemplate = null;
- }
- } catch (Exception exception) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(globalContext.getMessageCode(),
- Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage()
- , getParserExceptionReason(exception)));
- return null;
+
+ public static ManifestContent validateManifest(GlobalValidationContext globalContext) {
+ Optional<InputStream> manifest = globalContext.getFileContent(SdcCommon.MANIFEST_NAME);
+ if (!manifest.isPresent()) {
+ throw new RuntimeException("Can't load manifest file for Heat Validator");
+ }
+ ManifestContent manifestContent;
+ try {
+ manifestContent = JsonUtil.json2Object(manifest.get(), ManifestContent.class);
+ } catch (Exception exception) {
+ throw new SdcRuntimeException("Can't load manifest file for Heat Validator", exception);
+ }
+ return manifestContent;
}
- return heatOrchestrationTemplate;
- }
+ public static String getParserExceptionReason(Exception exception) {
+ String reason;
+ if (exception.getCause() != null && exception.getCause().getCause() != null) {
+ reason = exception.getCause().getCause().getMessage();
+ } else if (exception.getCause() != null) {
+ reason = exception.getCause().getMessage();
+ } else {
+ reason = Messages.GENERAL_HEAT_PARSER_ERROR.getErrorMessage();
+ }
+ return reason;
+ }
+ public static HeatOrchestrationTemplate checkHeatOrchestrationPreCondition(String fileName, GlobalValidationContext globalContext) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate;
+ try {
+ Optional<InputStream> fileContent = globalContext.getFileContent(fileName);
+ if (fileContent.isPresent()) {
+ heatOrchestrationTemplate = new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
+ } else {
+ heatOrchestrationTemplate = null;
+ }
+ } catch (Exception exception) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(globalContext.getMessageCode(), Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
+ getParserExceptionReason(exception)));
+ return null;
+ }
+ return heatOrchestrationTemplate;
+ }
}