summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-08-18 14:34:33 +0100
committerMichael Morris <michael.morris@est.tech>2021-08-26 12:13:58 +0000
commitaea64ba99fa9c9b51112b30aeb0872c4cdb89759 (patch)
tree8645ba4b820f8615e54ecd053f7232c2fcd7dca9 /catalog-be
parent5a0703ffad1492ec6b6c78143f63dca83ee030d2 (diff)
Validate the Resource Model before importing VSP
Validates the Resource Model selected during the Import VSP. This model must be aligned with one of the models that the imported VSP relates to. Fix VSP package retrieval to get the exact version from the VSP chosen during the Import VSP process. Introduces a client in the Catalog to retrieve from the Onboarding backend a VSP information using its Id and version Id. Change-Id: Ic8fb52b6daadc0e7203c81a9c15c3e46d5b9fffb Issue-ID: SDC-3675 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml26
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java64
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java11
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java272
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java11
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/configuration.yaml1
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml26
-rw-r--r--catalog-be/src/test/resources/paths/path-context.xml1
9 files changed, 321 insertions, 95 deletions
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 6d243d2e94..563594a728 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
@@ -2554,3 +2554,29 @@ errors:
messageId: "SVC4154"
}
+ #-----------SVC4155---------------------------
+ # %1 - "VSP id"
+ # %2 - "VSP version id"
+ VSP_FIND_ERROR: {
+ code: 500,
+ message: "An error has occurred while retrieving the Vendor Software Product of id '%1', version id '%2'",
+ messageId: "SVC4155"
+ }
+
+ #-----------SVC4156---------------------------
+ # %1 - "VSP id"
+ # %2 - "VSP version id"
+ VSP_NOT_FOUND: {
+ code: 404,
+ message: "Could not find Vendor Software Product of id '%1', version id '%2'",
+ messageId: "SVC4156"
+ }
+
+ #-----------SVC4157---------------------------
+ # %1 - "The model name"
+ # %2 - "List of allowed models"
+ VSP_MODEL_NOT_ALLOWED: {
+ code: 400,
+ message: "The Model '%1' is not allowed for the imported Vendor Software Product. Allowed Models: '%2'",
+ messageId: "SVC4157"
+ } \ No newline at end of file
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
index 9f49bc52e1..60616c2709 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
@@ -945,7 +945,9 @@ onboarding:
protocol: http
port: <%= node['ONBOARDING_BE'][:http_port] %>
<% end -%>
- downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages"
+ getVspPackageUri: "/onboarding-api/v1.0/vendor-software-products/packages/%s?versionId=%s" # /onboarding-api/v1.0/vendor-software-products/packages/:vspId?versionId=:vspVersionId
+ getLatestVspPackageUri: "/onboarding-api/v1.0/vendor-software-products/packages/%s" # /onboarding-api/v1.0/vendor-software-products/packages/:vspId
+ getVspUri: "/onboarding-api/v1.0/vendor-software-products/%s/versions/%s" # /onboarding-api/v1.0/vendor-software-products/:vspId/versions/:vspVersionId
healthCheckUri: "/onboarding-api/v1.0/healthcheck"
# #GSS IDNS
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
index 6f530ccd3a..b8a5d67d4a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
@@ -23,10 +23,10 @@ package org.openecomp.sdc.be.components.csar;
import fj.data.Either;
import java.util.Map;
+import java.util.Optional;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -37,6 +37,7 @@ import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.operations.StorageException;
@@ -48,6 +49,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
@@ -63,7 +65,7 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
@Autowired
public CsarBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
- IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic, InterfaceOperation interfaceOperation,
+ IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
InterfaceLifecycleOperation interfaceLifecycleTypeOperation, YamlTemplateParsingHandler yamlHandler,
ArtifactsOperations artifactToscaOperation) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
@@ -99,13 +101,19 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
if (status == StorageOperationStatus.ENTITY_ALREADY_EXISTS) {
log.debug("Failed to create resource {}, csarUUID {} already exist for a different VF ", resource.getSystemName(), csarUUID);
} else if (status != StorageOperationStatus.OK) {
- log.debug("Failed to validate uniqueness of CsarUUID {} for resource", csarUUID, resource.getSystemName());
+ log.debug("Failed to validate uniqueness of CsarUUID '{}' for resource '{}'", csarUUID, resource.getSystemName());
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
}
}
public CsarInfo getCsarInfo(Resource resource, Resource oldResource, User user, Map<String, byte[]> payload, String csarUUID) {
- Map<String, byte[]> csar = getCsar(resource, user, payload, csarUUID);
+ Map<String, byte[]> csar = payload;
+ if (csar == null) {
+ final var vendorSoftwareProduct = getCsar(resource, user);
+ validateModel(resource, vendorSoftwareProduct);
+
+ csar = vendorSoftwareProduct.getFileMap();
+ }
ImmutablePair<String, String> toscaYamlCsarStatus = validateAndParseCsar(resource, user, csar, csarUUID).left()
.on(this::throwComponentException);
String checksum = CsarValidationUtils.getToscaYamlChecksum(csar, csarUUID, componentsUtils).left()
@@ -117,7 +125,23 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
csarUUID, oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().getImportedToscaChecksum(), checksum);
oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().setImportedToscaChecksum(checksum);
}
- return new CsarInfo(user, csarUUID, csar, resource.getName(), toscaYamlCsarStatus.getKey(), toscaYamlCsarStatus.getValue(), true);
+ return new CsarInfo(user, csarUUID, resource.getCsarVersionId(), csar, resource.getName(), toscaYamlCsarStatus.getKey(),
+ toscaYamlCsarStatus.getValue(), true);
+ }
+
+ private void validateModel(final Resource resource, final VendorSoftwareProduct vendorSoftwareProduct) {
+ if (resource.getModel() == null) {
+ if (!vendorSoftwareProduct.getModelList().isEmpty()) {
+ var modelStringList = String.join(", ", vendorSoftwareProduct.getModelList());
+ throw new ByActionStatusComponentException(ActionStatus.VSP_MODEL_NOT_ALLOWED, "SDC AID", modelStringList);
+ }
+ return;
+ }
+ if (!vendorSoftwareProduct.getModelList().contains(resource.getModel())) {
+ var modelStringList =
+ vendorSoftwareProduct.getModelList().isEmpty() ? "SDC AID" : String.join(", ", vendorSoftwareProduct.getModelList());
+ throw new ByActionStatusComponentException(ActionStatus.VSP_MODEL_NOT_ALLOWED, resource.getModel(), modelStringList);
+ }
}
public CsarInfo getCsarInfo(Service service, Service oldResource, User user, Map<String, byte[]> payload, String csarUUID) {
@@ -152,9 +176,8 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
throw new ByResponseFormatComponentException(responseFormat);
}
- private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Component component, User user, Map<String, byte[]> payload,
+ private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Component component, User user, Map<String, byte[]> csar,
String csarUUID) {
- Map<String, byte[]> csar = getCsar(component, user, payload, csarUUID);
Either<Boolean, ResponseFormat> validateCsarStatus = CsarValidationUtils.validateCsar(csar, csarUUID, componentsUtils);
if (validateCsarStatus.isRight()) {
ResponseFormat responseFormat = validateCsarStatus.right().value();
@@ -182,7 +205,7 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
if (payload != null) {
return payload;
}
- Either<Map<String, byte[]>, StorageOperationStatus> csar = csarOperation.getCsar(csarUUID, user);
+ Either<Map<String, byte[]>, StorageOperationStatus> csar = csarOperation.findVspLatestPackage(csarUUID, user);
if (csar.isRight()) {
StorageOperationStatus value = csar.right().value();
log.debug("#getCsar - failed to fetch csar with ID {}, error: {}", csarUUID, value);
@@ -197,6 +220,31 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
return csar.left().value();
}
+ private VendorSoftwareProduct getCsar(final Resource resource, final User user) {
+ final Optional<VendorSoftwareProduct> vendorSoftwareProductOpt;
+ try {
+ vendorSoftwareProductOpt = csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user);
+ } catch (final Exception exception) {
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, CsarBusinessLogic.class.getName(), exception.getMessage());
+ auditGetCsarError(resource, user, resource.getCsarUUID(), StorageOperationStatus.GENERAL_ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.VSP_FIND_ERROR, resource.getCsarUUID(), resource.getCsarVersionId());
+ }
+ if (vendorSoftwareProductOpt.isEmpty()) {
+ auditGetCsarError(resource, user, resource.getCsarUUID(), StorageOperationStatus.CSAR_NOT_FOUND);
+ throw new ByActionStatusComponentException(ActionStatus.VSP_NOT_FOUND, resource.getCsarUUID(), resource.getCsarVersionId());
+ }
+ return vendorSoftwareProductOpt.get();
+ }
+
+ private void auditGetCsarError(Component component, User user, String csarUUID, StorageOperationStatus storageOperationStatus) {
+ log.debug("#getCsar - failed to fetch csar with ID {}, error: {}", csarUUID, storageOperationStatus);
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(CREATING_RESOURCE_FROM_CSAR_FETCHING_CSAR_WITH_ID + csarUUID + FAILED);
+ var responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageOperationStatus), csarUUID);
+ if (component instanceof Resource) {
+ componentsUtils.auditResource(responseFormat, user, (Resource) component, AuditingActionEnum.CREATE_RESOURCE);
+ }
+ }
+
private void auditAndThrowException(Resource resource, User user, AuditingActionEnum auditingAction, ActionStatus status, String... params) {
ResponseFormat errorResponse = componentsUtils.getResponseFormat(status, params);
componentsUtils.auditResource(errorResponse, user, resource, auditingAction);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
index 14ede6305b..0571f55c32 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
@@ -71,6 +71,8 @@ public class CsarInfo {
@Setter
private String csarUUID;
@Getter
+ private String csarVersionId;
+ @Getter
@Setter
private Map<String, byte[]> csar;
@Getter
@@ -89,7 +91,6 @@ public class CsarInfo {
private List<Map.Entry<String, byte[]>> globalSubstitutes;
- @SuppressWarnings("unchecked")
public CsarInfo(User modifier, String csarUUID, Map<String, byte[]> csar, String vfResourceName, String mainTemplateName,
String mainTemplateContent, boolean isUpdate) {
this.vfResourceName = vfResourceName;
@@ -98,7 +99,7 @@ public class CsarInfo {
this.csar = csar;
this.mainTemplateName = mainTemplateName;
this.mainTemplateContent = mainTemplateContent;
- this.mappedToscaMainTemplate = (Map<String, Object>) new Yaml().load(mainTemplateContent);
+ this.mappedToscaMainTemplate = new Yaml().load(mainTemplateContent);
this.createdNodesToscaResourceNames = new HashMap<>();
this.cvfcToCreateQueue = new PriorityQueue<>();
this.isUpdate = isUpdate;
@@ -117,6 +118,12 @@ public class CsarInfo {
return globalSubstitutesInCsar;
}
+ public CsarInfo(final User modifier, final String csarUUID, final String csarVersionId, final Map<String, byte[]> csarContent,
+ final String vfResourceName, final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) {
+ this(modifier, csarUUID, csarContent, vfResourceName, mainTemplateName, mainTemplateContent, isUpdate);
+ this.csarVersionId = csarVersionId;
+ }
+
@VisibleForTesting
CsarInfo(final NonManoConfiguration nonManoConfiguration) {
this.nonManoConfiguration = nonManoConfiguration;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
index 91ec89540c..66c8a51471 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
@@ -1,45 +1,62 @@
/*
-
- * Copyright (c) 2018 Huawei Intellectual Property.
-
- * Modifications Copyright (c) 2019 Samsung
-
- * 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
-
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2018 Huawei Intellectual Property.
+ * Modifications Copyright (c) 2019 Samsung.
+ * Modifications Copyright (c) 2021 Nordix Foundation.
+ * ================================================================================
+ * 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
-
+ * 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.
-
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.be.components.csar;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
-import org.junit.Before;
-import org.junit.Test;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogicMock;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
@@ -48,33 +65,17 @@ import org.openecomp.sdc.common.zip.ZipUtils;
import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
+class CsarBusinessLogicTest extends BaseBusinessLogicMock {
-public class CsarBusinessLogicTest extends BaseBusinessLogicMock {
+ private final CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
+ private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+ private final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+ private final User user = Mockito.mock(User.class);
+ private final YamlTemplateParsingHandler yamlHandler = Mockito.mock(YamlTemplateParsingHandler.class);
- private CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
- private ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
- private ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
- private User user = Mockito.mock(User.class);
- private YamlTemplateParsingHandler yamlHandler = Mockito.mock(YamlTemplateParsingHandler.class);
-
- private CsarBusinessLogic test = new CsarBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, yamlHandler, artifactToscaOperation);
+ private final CsarBusinessLogic csarBusinessLogic = new CsarBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
+ interfaceOperation, interfaceLifecycleTypeOperation, yamlHandler, artifactToscaOperation);
private static final String CSAR_UUID = "csarUUID";
private static final String CSAR_ENTRY = "Definitions/tosca_mock_vf.yaml";
@@ -88,31 +89,38 @@ public class CsarBusinessLogicTest extends BaseBusinessLogicMock {
private static final String RESOURCE_NAME = "resourceName";
private static final String PAYLOAD_NAME = "mock_vf.csar";
- @Before
- public void setUp() throws Exception {
- test.setCsarOperation(csarOperation);
- test.setToscaOperationFacade(toscaOperationFacade);
- test.setComponentsUtils(componentsUtils);
+ @BeforeEach
+ void setUp() throws Exception {
+ csarBusinessLogic.setCsarOperation(csarOperation);
+ csarBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
+ csarBusinessLogic.setComponentsUtils(componentsUtils);
}
- @Test()
- public void testGetCsarInfo() {
+ @Test
+ void testGetCsarInfo() {
// given
Resource resource = new Resource();
resource.setName(RESOURCE_NAME);
+ resource.setCsarUUID(CSAR_UUID);
+ resource.setCsarVersionId("csarVersionId");
Map<String, byte[]> csar_data = new HashMap<>();
csar_data.put(CSAR_METADATA, CSAR_METADATA_CONTENT.getBytes());
csar_data.put(CSAR_ENTRY, CSAR_ENTRY_CONTENT.getBytes());
- when(csarOperation.getCsar(anyString(), any(User.class))).thenReturn(Either.left(csar_data));
+ final var vendorSoftwareProduct = new VendorSoftwareProduct();
+ vendorSoftwareProduct.setFileMap(csar_data);
+ vendorSoftwareProduct.setModelList(Collections.emptyList());
+ when(csarOperation.findVsp(eq(resource.getCsarUUID()), eq(resource.getCsarVersionId()), any(User.class)))
+ .thenReturn(Optional.of(vendorSoftwareProduct));
// when
- CsarInfo csarInfo = test.getCsarInfo(resource, null, user, null, CSAR_UUID);
+ final CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID);
// then
assertNotNull(csarInfo);
- assertEquals(CSAR_UUID, csarInfo.getCsarUUID());
+ assertEquals(resource.getCsarUUID(), csarInfo.getCsarUUID());
+ assertEquals(resource.getCsarVersionId(), csarInfo.getCsarVersionId());
assertEquals(CSAR_ENTRY, csarInfo.getMainTemplateName());
assertEquals(RESOURCE_NAME, csarInfo.getVfResourceName());
@@ -120,8 +128,92 @@ public class CsarBusinessLogicTest extends BaseBusinessLogicMock {
assertTrue(csarInfo.getCsar().keySet().containsAll(Arrays.asList(CSAR_ENTRY, CSAR_METADATA)));
}
- @Test()
- public void testGetCsarInfoWithPayload() throws IOException, URISyntaxException, ZipException {
+ @Test
+ void testGetCsarInfo_vspWithModelAndResourceWithInvalidModel() {
+ final var resource = new Resource();
+ resource.setCsarUUID(CSAR_UUID);
+ final String csarVersionId = "csarVersionId";
+ resource.setCsarVersionId(csarVersionId);
+ resource.setModel("model1");
+ var vendorSoftwareProduct = new VendorSoftwareProduct();
+ final List<String> modelList = List.of("model2", "model3");
+ vendorSoftwareProduct.setModelList(modelList);
+
+ when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenReturn(Optional.of(vendorSoftwareProduct));
+
+ final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ assertEquals(ActionStatus.VSP_MODEL_NOT_ALLOWED, actualException.getActionStatus());
+ assertEquals(2, actualException.getParams().length);
+ assertEquals(resource.getModel(), actualException.getParams()[0]);
+ assertEquals(String.join(", ", modelList), actualException.getParams()[1]);
+ }
+
+
+ @Test
+ void testGetCsarInfo_vspWithNoModelAndResourceWithInvalidModel() {
+ final var resource = new Resource();
+ resource.setCsarUUID(CSAR_UUID);
+ final String csarVersionId = "csarVersionId";
+ resource.setCsarVersionId(csarVersionId);
+ resource.setModel("model1");
+ var vendorSoftwareProduct = new VendorSoftwareProduct();
+ final List<String> modelList = new ArrayList<>();
+ vendorSoftwareProduct.setModelList(modelList);
+
+ when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenReturn(Optional.of(vendorSoftwareProduct));
+
+ final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ assertEquals(ActionStatus.VSP_MODEL_NOT_ALLOWED, actualException.getActionStatus());
+ assertEquals(2, actualException.getParams().length);
+ assertEquals(resource.getModel(), actualException.getParams()[0]);
+ assertEquals("SDC AID", actualException.getParams()[1]);
+ }
+
+ @Test
+ void testGetCsarInfo_vspWithModelAndResourceWithNoModel() {
+ final var resource = new Resource();
+ resource.setCsarUUID(CSAR_UUID);
+ final String csarVersionId = "csarVersionId";
+ resource.setCsarVersionId(csarVersionId);
+ resource.setModel(null);
+ var vendorSoftwareProduct = new VendorSoftwareProduct();
+ final List<String> modelList = List.of("model2", "model3");
+ vendorSoftwareProduct.setModelList(modelList);
+
+ when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenReturn(Optional.of(vendorSoftwareProduct));
+
+ final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ assertEquals(ActionStatus.VSP_MODEL_NOT_ALLOWED, actualException.getActionStatus());
+ assertEquals(2, actualException.getParams().length);
+ assertEquals("SDC AID", actualException.getParams()[0]);
+ assertEquals(String.join(", ", modelList), actualException.getParams()[1]);
+ }
+
+ @Test
+ void testGetCsarInfo_vspWithNoModelAndResourceWithNoModel() {
+ final var resource = new Resource();
+ resource.setCsarUUID(CSAR_UUID);
+ final String csarVersionId = "csarVersionId";
+ resource.setCsarVersionId(csarVersionId);
+ resource.setModel(null);
+ var vendorSoftwareProduct = new VendorSoftwareProduct();
+ final List<String> modelList = new ArrayList<>();
+ vendorSoftwareProduct.setModelList(modelList);
+ when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenThrow(new RuntimeException());
+
+ final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ assertEquals(ActionStatus.VSP_FIND_ERROR, actualException.getActionStatus());
+ assertEquals(2, actualException.getParams().length);
+ assertEquals(resource.getCsarUUID(), actualException.getParams()[0]);
+ assertEquals(resource.getCsarVersionId(), actualException.getParams()[1]);
+ }
+
+ @Test
+ void testGetCsarInfoWithPayload() throws IOException, URISyntaxException, ZipException {
// given
Resource resource = new Resource();
resource.setName(RESOURCE_NAME);
@@ -129,7 +221,7 @@ public class CsarBusinessLogicTest extends BaseBusinessLogicMock {
Map<String, byte[]> payload = loadPayload(PAYLOAD_NAME);
// when
- CsarInfo csarInfo = test.getCsarInfo(resource, null, user, payload, CSAR_UUID);
+ CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, payload, CSAR_UUID);
// then
assertNotNull(csarInfo);
@@ -142,49 +234,69 @@ public class CsarBusinessLogicTest extends BaseBusinessLogicMock {
assertTrue(csarInfo.getCsar().keySet().containsAll(Arrays.asList(CSAR_ENTRY, CSAR_METADATA)));
}
- @Test(expected = ComponentException.class)
- public void testGetCsarInfoWithBadData(){
+ @Test
+ void testGetCsarInfoWithBadData(){
// given
Resource resource = new Resource();
resource.setName(RESOURCE_NAME);
Map<String, byte[]> csar_data = new HashMap<>();
- when(csarOperation.getCsar(anyString(), any(User.class))).thenReturn(Either.left(csar_data));
+ when(csarOperation.findVspLatestPackage(anyString(), any(User.class))).thenReturn(Either.left(csar_data));
- // when
- test.getCsarInfo(resource, null, user, null, CSAR_UUID);
+ // when/then
+ assertThrows(ComponentException.class, () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
}
@Test
- public void testValidateCsarBeforeCreate() {
+ void testValidateCsarBeforeCreate() {
Resource resource = new Resource();
StorageOperationStatus status = StorageOperationStatus.OK;
when(toscaOperationFacade.validateCsarUuidUniqueness(CSAR_UUID)).thenReturn(status);
- test.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, CSAR_UUID);
+ csarBusinessLogic.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, CSAR_UUID);
}
- @Test(expected = ComponentException.class)
- public void testValidateCsarBeforeCreate_Exists() {
+ @Test
+ void testValidateCsarBeforeCreate_ResourceExists() {
Resource resource = new Resource();
ResponseFormat responseFormat = new ResponseFormat();
StorageOperationStatus status = StorageOperationStatus.ENTITY_ALREADY_EXISTS;
when(toscaOperationFacade.validateCsarUuidUniqueness(CSAR_UUID)).thenReturn(status);
when(componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, CSAR_UUID)).thenReturn(responseFormat);
- test.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, "csarUUID");
+ assertThrows(ComponentException.class, () -> csarBusinessLogic
+ .validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, CSAR_UUID));
+ }
+
+ @Test
+ void testValidateCsarBeforeCreate_ServiceExists() {
+ final var service = new Service();
+ final var status = StorageOperationStatus.ENTITY_ALREADY_EXISTS;
+ when(toscaOperationFacade.validateCsarUuidUniqueness(CSAR_UUID)).thenReturn(status);
+ csarBusinessLogic.validateCsarBeforeCreate(service, CSAR_UUID);
+ verify(toscaOperationFacade).validateCsarUuidUniqueness(CSAR_UUID);
+ }
+
+ @Test
+ void testValidateCsarBeforeCreate_ServiceValidateError() {
+ final var service = new Service();
+ final var status = StorageOperationStatus.GENERAL_ERROR;
+ when(toscaOperationFacade.validateCsarUuidUniqueness(CSAR_UUID)).thenReturn(status);
+ when(componentsUtils.convertFromStorageResponse(status)).thenReturn(ActionStatus.GENERAL_ERROR);
+ assertThrows(ComponentException.class, () -> csarBusinessLogic.validateCsarBeforeCreate(service, CSAR_UUID));
+ verify(toscaOperationFacade).validateCsarUuidUniqueness(CSAR_UUID);
}
- @Test(expected = ComponentException.class)
- public void testValidateCsarBeforeCreate_Fail() {
+ @Test
+ void testValidateCsarBeforeCreate_Fail() {
Resource resource = new Resource();
String csarUUID = "csarUUID";
when(toscaOperationFacade.validateCsarUuidUniqueness(csarUUID)).thenReturn(StorageOperationStatus.EXEUCTION_FAILED);
when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.EXEUCTION_FAILED)).thenReturn(ActionStatus.GENERAL_ERROR);
- test.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, "csarUUID");
+ assertThrows(ComponentException.class, () -> csarBusinessLogic
+ .validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, "csarUUID"));
}
- public Map<String, byte[]> loadPayload(String payloadName) throws IOException, URISyntaxException, ZipException {
-
- Path path = Paths.get(getClass().getResource("/" + payloadName).toURI());
+ private Map<String, byte[]> loadPayload(String payloadName) throws IOException, URISyntaxException, ZipException {
+ var path = Paths.get(getClass().getResource("/" + payloadName).toURI());
byte[] data = Files.readAllBytes(path);
return ZipUtils.readZip(data, false);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 09aae40244..b369773892 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -112,6 +112,7 @@ import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.VendorSoftwareProduct;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
@@ -545,6 +546,12 @@ public class ResourceBusinessLogicTest {
@Test
public void testUpdateUnhappyScenario() {
Resource resource = createResourceObjectCsar(true);
+ final var csarVersionId = "csarVersionId";
+ resource.setCsarVersionId(csarVersionId);
+
+ final var vendorSoftwareProduct = new VendorSoftwareProduct();
+ vendorSoftwareProduct.setFileMap(new HashMap<>());
+ vendorSoftwareProduct.setModelList(Collections.emptyList());
setCanWorkOnResource(resource);
validateUserRoles(Role.ADMIN, Role.DESIGNER);
@@ -552,9 +559,7 @@ public class ResourceBusinessLogicTest {
when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(Either.left(true));
when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(Either.left(setCanWorkOnResource(resource)));
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(Either.left(resource));
-
- when(csarOperation.getCsar("valid_vf.csar", user)).thenReturn(Either.left(new HashMap<>()));
-
+ when(csarOperation.findVsp("valid_vf.csar", csarVersionId, user)).thenReturn(Optional.of(vendorSoftwareProduct));
try {
Resource createdResource = bl.validateAndUpdateResourceFromCsar(resource, user, null, "", resource.getUniqueId());
diff --git a/catalog-be/src/test/resources/config/catalog-be/configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/configuration.yaml
index 78d3722806..4692342722 100644
--- a/catalog-be/src/test/resources/config/catalog-be/configuration.yaml
+++ b/catalog-be/src/test/resources/config/catalog-be/configuration.yaml
@@ -346,7 +346,6 @@ onboarding:
protocol: http
host: localhost
port: 8080
- downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages"
healthCheckUri: "/onboarding-api/v1.0/healthcheck"
ecompPortal:
diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
index b363bacd73..aeab3018b8 100644
--- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
+++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
@@ -2293,4 +2293,30 @@ errors:
code: 500,
message: "An unexpected error occurred while updating the capability '%1'.",
messageId: "SVC4143"
+ }
+ #-----------SVC4154---------------------------
+ # %1 - "VSP id"
+ # %2 - "VSP version id"
+ VSP_FIND_ERROR: {
+ code: 500,
+ message: "An error has occurred while retrieving the Vendor Software Product of id '%1', version id '%2'",
+ messageId: "SVC4154"
+ }
+
+ #-----------SVC4155---------------------------
+ # %1 - "VSP id"
+ # %2 - "VSP version id"
+ VSP_NOT_FOUND: {
+ code: 404,
+ message: "Could not find Vendor Software Product of id '%1', version id '%2'",
+ messageId: "SVC4155"
+ }
+
+ #-----------SVC4156---------------------------
+ # %1 - "The model name"
+ # %2 - "List of allowed models"
+ VSP_MODEL_NOT_ALLOWED: {
+ code: 400,
+ message: "The Model '%1' is not allowed for the imported Vendor Software Product. Allowed Models: '%2'",
+ messageId: "SVC4156"
} \ No newline at end of file
diff --git a/catalog-be/src/test/resources/paths/path-context.xml b/catalog-be/src/test/resources/paths/path-context.xml
index 7994b0c44d..f6306d0f67 100644
--- a/catalog-be/src/test/resources/paths/path-context.xml
+++ b/catalog-be/src/test/resources/paths/path-context.xml
@@ -50,6 +50,7 @@ Modifications copyright (c) 2018 Nokia
org.openecomp.sdc.be.components.validation,
org.openecomp.sdc.be.switchover.detector,
org.openecomp.sdc.be.tosca,
+ org.openecomp.sdc.be.client,
org.openecomp.sdc.be.model.operations.impl,
org.openecomp.sdc.be.model.jsonjanusgraph.operations,
org.openecomp.sdc.be.model.jsonjanusgraph.utils,