aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Wudzinski <adam.wudzinski@nokia.com>2020-12-02 18:07:22 +0100
committerMaciej Malewski <maciej.malewski@nokia.com>2020-12-03 16:23:32 +0100
commit5700275b3e147e0053ae7872271a9f2fbfa13e06 (patch)
tree4659630516c209ca79148bb15c8a4b978eec6f19
parent562577c33c08d1c6716676d6d7501693b08b9f21 (diff)
[SDC] Validate PMDictionary content in Deployment artifacts tab
Validate PMDictionary file content when adding or updating PMDictionary in Deployment artifacts tab. Fix dependencies conflict. Issue-ID: SDC-3390 Signed-off-by: Adam Wudzinski <adam.wudzinski@nokia.com> Change-Id: I6f6bb196ef061419a309a8ded5fdbe116982a037
-rw-r--r--catalog-be/pom.xml11
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnum.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidator.java73
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidatorTest.java87
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java6
-rw-r--r--integration-tests/src/test/resources/Files/PNFs/pmDictionary.yml6
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml6
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml6
11 files changed, 225 insertions, 7 deletions
diff --git a/catalog-be/pom.xml b/catalog-be/pom.xml
index 399e45c0ca..fd25bc2956 100644
--- a/catalog-be/pom.xml
+++ b/catalog-be/pom.xml
@@ -781,6 +781,17 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.onap.vnfsdk.validation</groupId>
+ <artifactId>validation-pmdictionary</artifactId>
+ <version>${onap.vnfsdk.validation.pmdictionary.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
index a4491de352..d2a79909d6 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
@@ -2398,3 +2398,10 @@ errors:
message: 'Error: Invalid Content. %1 has invalid format.',
messageId: "SVC4723"
}
+#---------SVC4732------------------------------
+ # %1 - list of validation errors
+ INVALID_PM_DICTIONARY_FILE: {
+ code: 400,
+ message: 'Error: Invalid PM Dictionary File. %1',
+ messageId: "SVC4732"
+ }
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index b6efd3ef0b..374e98e61f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- * Modifications copyright (c) 2019 Nokia
+ * Modifications copyright (c) 2020 Nokia
* ================================================================================
*/
@@ -69,6 +69,7 @@ import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentEx
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.ComponentUtils;
+import org.openecomp.sdc.be.components.impl.validation.PMDictionaryValidator;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
@@ -2630,6 +2631,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String artifactType = artifactInfo.getArtifactType();
String fileExtension = GeneralUtility.getFilenameExtension(artifactInfo.getArtifactName());
PayloadTypeEnum payloadType = ArtifactTypeToPayloadTypeSelector.getPayloadType(artifactType, fileExtension);
+
+ final Optional<ResponseFormat> pmDictionaryError = validateIfPmDictionary(artifactType, decodedPayload);
+ if (pmDictionaryError.isPresent()) {
+ return Either.right(pmDictionaryError.get());
+ }
+
Either<Boolean, ActionStatus> isPayloadValid = payloadType.isValid(decodedPayload);
if (isPayloadValid.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(isPayloadValid.right().value(), artifactType);
@@ -2659,6 +2666,16 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(decodedPayload);
}
+ private Optional<ResponseFormat> validateIfPmDictionary(String artifactType, byte[] decodedPayload) {
+ return new PMDictionaryValidator()
+ .validateIfPmDictionary(artifactType, decodedPayload)
+ .map(this::preparePmDictionaryResponse);
+ }
+
+ private ResponseFormat preparePmDictionaryResponse(String errorMessage) {
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_PM_DICTIONARY_FILE, errorMessage);
+ }
+
public Either<ArtifactDefinition, ResponseFormat> deleteArtifactByInterface(
String resourceId, String userUserId, String artifactId, boolean inTransaction) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnum.java
index df6a552917..4a71d4bc86 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnum.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnum.java
@@ -17,7 +17,7 @@
* *
* * SPDX-License-Identifier: Apache-2.0
* * ============LICENSE_END=========================================================
- *
+ * * Modifications copyright (c) 2020 Nokia
*/
package org.openecomp.sdc.be.components.impl.artifact;
@@ -144,9 +144,9 @@ public enum PayloadTypeEnum {
private static Either<Boolean, ActionStatus> isValidYaml(byte[] payload) {
YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
if (yamlToObjectConverter.isValidYaml(payload)) {
- log.debug("Invalid YAML format");
return Either.left(true);
}
+ log.debug("Invalid YAML format");
return Either.right(ActionStatus.INVALID_YAML);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidator.java
new file mode 100644
index 0000000000..84bebe3bf6
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidator.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * 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.be.components.impl.validation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import org.onap.validation.yaml.YamlContentValidator;
+import org.onap.validation.yaml.error.YamlDocumentValidationError;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+
+public class PMDictionaryValidator {
+
+ private final YamlContentValidator yamlContentValidator;
+
+ public PMDictionaryValidator() {
+ this(new YamlContentValidator());
+ }
+
+ PMDictionaryValidator(YamlContentValidator yamlContentValidator) {
+ this.yamlContentValidator = yamlContentValidator;
+ }
+
+ public Optional<String> validateIfPmDictionary(String artifactType, byte[] decodedPayload) {
+ if (isPmDictionary(artifactType)) {
+ return validate(decodedPayload).stream()
+ .reduce((a, b) -> a + "; " + b);
+ }
+ return Optional.empty();
+ }
+
+ private boolean isPmDictionary(String artifactType) {
+ return ArtifactTypeEnum.PM_DICTIONARY.name().equals(artifactType);
+ }
+
+ private List<String> validate(byte[] fileContent) {
+ List<String> errors = new ArrayList<>();
+ try {
+ List<YamlDocumentValidationError> validationErrors = yamlContentValidator.validate(fileContent);
+ validationErrors.stream()
+ .map(this::formatErrorMessage)
+ .forEach(errors::add);
+ } catch (Exception e) {
+ errors.add(e.getMessage());
+ }
+ return errors;
+ }
+
+ private String formatErrorMessage(YamlDocumentValidationError error) {
+ return String.format("Line number: %d, Path: %s, Message: %s",
+ error.getYamlDocumentNumber(),
+ error.getPath(),
+ error.getMessage());
+ }
+
+}
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index a4491de352..14b4ece4b0 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -2398,3 +2398,10 @@ errors:
message: 'Error: Invalid Content. %1 has invalid format.',
messageId: "SVC4723"
}
+#---------SVC4732------------------------------
+ # %1 - list of validation errors
+ INVALID_PM_DICTIONARY_FILE: {
+ code: 400,
+ message: 'Error: Invalid PM Dictionary File. %1',
+ messageId: "SVC4732"
+ } \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidatorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidatorTest.java
new file mode 100644
index 0000000000..7e62e6dace
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/validation/PMDictionaryValidatorTest.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * 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.be.components.impl.validation;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.validation.yaml.YamlContentValidator;
+import org.onap.validation.yaml.error.YamlDocumentValidationError;
+import org.onap.validation.yaml.exception.YamlProcessingException;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+
+class PMDictionaryValidatorTest {
+
+ private YamlContentValidator yamlContentValidator;
+
+ @BeforeEach
+ void setUp() {
+ yamlContentValidator = mock(YamlContentValidator.class);
+ }
+
+ @Test
+ void shouldNotReturnErrors_whenArtifactTypeDoNotMatch() {
+ // when
+ Optional<String> errors = new PMDictionaryValidator(yamlContentValidator)
+ .validateIfPmDictionary(ArtifactTypeEnum.DCAE_INVENTORY_BLUEPRINT.name(), "".getBytes());
+
+ // then
+ assertTrue(errors.isEmpty());
+ verifyNoInteractions(yamlContentValidator);
+ }
+
+ @Test
+ void shouldReturnErrors_whenArtifactTypeIsPmDictionaryAndFileIsInvalid() throws YamlProcessingException {
+ // given
+ byte[] fileContent = "".getBytes();
+ YamlDocumentValidationError validationError = new YamlDocumentValidationError(1, "/", "error");
+ when(yamlContentValidator.validate(fileContent)).thenReturn(List.of(validationError));
+
+ // when
+ Optional<String> errors = new PMDictionaryValidator(yamlContentValidator)
+ .validateIfPmDictionary(ArtifactTypeEnum.PM_DICTIONARY.name(), fileContent);
+
+ // then
+ assertTrue(errors.isPresent());
+ assertThat(errors.get(), is("Line number: 1, Path: /, Message: error"));
+ }
+
+ @Test
+ void shouldNotReturnErrors_whenArtifactTypeIsPmDictionaryAndFileIsValid() throws YamlProcessingException {
+ // given
+ byte[] fileContent = "".getBytes();
+ when(yamlContentValidator.validate(fileContent)).thenReturn(List.of());
+
+ // when
+ Optional<String> errors = new PMDictionaryValidator(yamlContentValidator)
+ .validateIfPmDictionary(ArtifactTypeEnum.PM_DICTIONARY.name(), fileContent);
+
+ // then
+ assertTrue(errors.isEmpty());
+ }
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
index cdb10a7588..78d6c63e4c 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
@@ -16,6 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2020 Nokia
*/
package org.openecomp.sdc.be.dao.api;
@@ -29,7 +30,7 @@ public enum ActionStatus {
CAPABILITY_TYPE_ALREADY_EXIST, MISSING_CAPABILITY_TYPE, MISSING_CAPABILITIES, REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION, IMPORT_DUPLICATE_REQ_CAP_NAME, IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED,
CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, REQUIREMENT_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, RELATION_NOT_FOUND,
// Resource related
- RESOURCE_NOT_FOUND, MISSING_DERIVED_FROM_TEMPLATE, PARENT_RESOURCE_NOT_FOUND, PARENT_RESOURCE_DOES_NOT_EXTEND, INVALID_DEFAULT_VALUE, INVALID_COMPLEX_DEFAULT_VALUE, MULTIPLE_PARENT_RESOURCE_FOUND, INVALID_RESOURCE_PAYLOAD, INVALID_TOSCA_FILE_EXTENSION, INVALID_YAML_FILE, INVALID_TOSCA_TEMPLATE, NOT_RESOURCE_TOSCA_TEMPLATE, NOT_SINGLE_RESOURCE, INVALID_RESOURCE_NAMESPACE, RESOURCE_ALREADY_EXISTS, INVALID_RESOURCE_CHECKSUM, RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, NO_ASSETS_FOUND, GENERIC_TYPE_NOT_FOUND, INVALID_RESOURCE_TYPE, TOSCA_PARSE_ERROR,
+ RESOURCE_NOT_FOUND, MISSING_DERIVED_FROM_TEMPLATE, PARENT_RESOURCE_NOT_FOUND, PARENT_RESOURCE_DOES_NOT_EXTEND, INVALID_DEFAULT_VALUE, INVALID_COMPLEX_DEFAULT_VALUE, MULTIPLE_PARENT_RESOURCE_FOUND, INVALID_RESOURCE_PAYLOAD, INVALID_TOSCA_FILE_EXTENSION, INVALID_YAML_FILE, INVALID_TOSCA_TEMPLATE, NOT_RESOURCE_TOSCA_TEMPLATE, NOT_SINGLE_RESOURCE, INVALID_RESOURCE_NAMESPACE, RESOURCE_ALREADY_EXISTS, INVALID_RESOURCE_CHECKSUM, RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, NO_ASSETS_FOUND, GENERIC_TYPE_NOT_FOUND, INVALID_RESOURCE_TYPE, TOSCA_PARSE_ERROR, INVALID_PM_DICTIONARY_FILE,
// Service related
SERVICE_TYPE_EXCEEDS_LIMIT, INVALID_SERVICE_TYPE, SERVICE_ROLE_EXCEEDS_LIMIT, INVALID_SERVICE_ROLE, INVALID_INSTANTIATION_TYPE, NOT_SERVICE_TOSCA_TEMPLATE,NOT_SINGLE_SERVICE,INVALID_SERVICE_CHECKSUM,INVALID_SERVICE_PAYLOAD,INVALID_SERVICE_NAMESPACE,SERVICE_ALREADY_EXISTS,
UNSUPPORTED_DISTRIBUTION_STATUS, INVALID_NAMING_POLICY, INVALID_ENVIRONMENT_CONTEXT, NAMING_POLICY_EXCEEDS_LIMIT, MISSING_ECOMP_GENERATED_NAMING, PROPERTY_EXCEEDS_LIMIT, INVALID_PROPERY,
@@ -180,8 +181,5 @@ public enum ActionStatus {
//Abstract template related
ABSTRACT, NORMAL
-
;
-
-
}
diff --git a/integration-tests/src/test/resources/Files/PNFs/pmDictionary.yml b/integration-tests/src/test/resources/Files/PNFs/pmDictionary.yml
index fa3ed531e7..3e3b3d1010 100644
--- a/integration-tests/src/test/resources/Files/PNFs/pmDictionary.yml
+++ b/integration-tests/src/test/resources/Files/PNFs/pmDictionary.yml
@@ -50,6 +50,8 @@ pmMetaData:
measAdditionalFields:
vendorField1: X
vendorField2: B
+ measAggregationLevels: NRCellCU
+ measChangeType: added
---
pmMetaData:
pmHeader:
@@ -72,6 +74,8 @@ pmMetaData:
measType: VS.NINFC.IntraFrPscelChFailTdcExp
measAdditionalFields:
vendorField1: Y
+ measAggregationLevels: NRCellCU
+ measChangeType: added
---
pmMetaData:
pmHeader:
@@ -95,4 +99,6 @@ pmMetaData:
measAdditionalFields:
vendorField1: Z
vendorField2: A
+ measAggregationLevels: NRCellCU
+ measChangeType: added
...
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml
index 98092c79fd..e185f78229 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml
@@ -211,6 +211,12 @@
<groupId>org.onap.vnfsdk.validation</groupId>
<artifactId>validation-pmdictionary</artifactId>
<version>${onap.vnfsdk.validation.pmdictionary.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml
index 2119ee8108..c8f0622b13 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml
@@ -83,6 +83,12 @@
<groupId>org.onap.vnfsdk.validation</groupId>
<artifactId>validation-pmdictionary</artifactId>
<version>${onap.vnfsdk.validation.pmdictionary.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>io.vavr</groupId>