aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2022-09-02 15:47:46 +0100
committerMichael Morris <michael.morris@est.tech>2022-09-16 07:50:40 +0000
commit38d98f8852f3e1e15300946aef95c65d3fca70b4 (patch)
treebb899470daaf9a9e8508735d25baf13b7290621b /catalog-be
parent37012ca30c1a3b706af5544080edbc222e07d3fe (diff)
Import unknown artifact types on Service Import
creating non existing artifact types added in the import files on service import Issue-ID: SDC-4153 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: I477cbc76dece828bc9eee96e66cd24a71fc8c2bb
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java14
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java32
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java14
-rw-r--r--catalog-be/src/test/resources/csars/service-Ser09080002-csar.csarbin64137 -> 63901 bytes
7 files changed, 70 insertions, 5 deletions
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 0bc6224273..b845b104fe 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
@@ -90,6 +90,7 @@ public abstract class CsarInfo {
@Getter
private Map<String, Resource> createdNodes;
protected Map<String, Object> datatypeDefinitions;
+ protected Map<String, Object> artifacttypeDefinitions;
private Map<String, Object> policytypeDefinitions;
@@ -178,6 +179,8 @@ public abstract class CsarInfo {
*/
public abstract Map<String, Object> getDataTypes();
+ public abstract Map<String, Object> getArtifactTypes();
+
public Map<String, Object> getPolicyTypes() {
if (policytypeDefinitions == null) {
policytypeDefinitions = new HashMap<>();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java
index 85f64699d4..8ab05b9bc8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java
@@ -189,6 +189,20 @@ public class OnboardedCsarInfo extends CsarInfo {
}
@Override
+ public Map<String, Object> getArtifactTypes() {
+ if (artifacttypeDefinitions == null) {
+ artifacttypeDefinitions = new HashMap<>();
+ for (Map.Entry<String, byte[]> entry : globalSubstitutes) {
+ final String yamlFileContents = new String(entry.getValue());
+ final Map<String, Object> mappedToscaTemplate = new Yaml().load(yamlFileContents);
+ artifacttypeDefinitions.putAll(getTypesFromTemplate(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.ARTIFACT_TYPES));
+ }
+ artifacttypeDefinitions.putAll(getTypesFromTemplate(mappedToscaMainTemplate, TypeUtils.ToscaTagNamesEnum.ARTIFACT_TYPES));
+ }
+ return artifacttypeDefinitions;
+ }
+
+ @Override
public Map<String, Object> getDataTypes() {
if (datatypeDefinitions == null) {
datatypeDefinitions = new HashMap<>();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
index 08f777db1f..4a9fa5eb18 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
@@ -152,6 +152,14 @@ public class ServiceCsarInfo extends CsarInfo {
return definitions;
}
+ public Map<String, Object> getArtifactTypes() {
+ final Map<String, Object> artifactsTypes = new HashMap<>();
+ mainTemplateImports.entrySet().stream()
+ .forEach(entry -> artifactsTypes.putAll(getTypesFromTemplate(entry.getValue(), TypeUtils.ToscaTagNamesEnum.ARTIFACT_TYPES)));
+ artifactsTypes.putAll(getTypesFromTemplate(getMappedToscaMainTemplate(), TypeUtils.ToscaTagNamesEnum.ARTIFACT_TYPES));
+ return artifactsTypes;
+ }
+
public List<NodeTypeDefinition> getNodeTypesUsed() {
if (nodeTypeDefinitions == null) {
nodeTypeDefinitions = new ArrayList<>();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java
index 441dfa741a..83e8ae77b6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java
@@ -39,7 +39,7 @@ public class ArtifactTypeImportManager {
private final ArtifactTypeOperation artifactTypeOperation;
private final ComponentsUtils componentsUtils;
- private final CommonImportManager commonImportManager;;
+ private final CommonImportManager commonImportManager;
@Autowired
public ArtifactTypeImportManager(final ArtifactTypeOperation artifactTypeOperation, final ComponentsUtils componentsUtils,
@@ -67,7 +67,7 @@ public class ArtifactTypeImportManager {
}
private Either<List<ArtifactTypeDefinition>, ActionStatus> createArtifactTypeFromYml(
- final String artifactTypesYml, final String modelName) {
+ final String artifactTypesYml, final String modelName) {
final Either<List<ArtifactTypeDefinition>, ActionStatus> artifactTypes =
commonImportManager.createElementTypesFromYml(artifactTypesYml, this::createArtifactTypeDefinition);
if (artifactTypes.isLeft()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index ccf7e5cb73..1e867e66da 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -90,6 +90,7 @@ import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts;
import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactTypeDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
@@ -135,6 +136,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -184,10 +186,12 @@ public class ServiceImportBusinessLogic {
private final ResourceImportManager resourceImportManager;
private final JanusGraphDao janusGraphDao;
private final ArtifactsBusinessLogic artifactsBusinessLogic;
+ private final ArtifactTypeImportManager artifactTypeImportManager;
private final IGraphLockOperation graphLockOperation;
private final ToscaFunctionService toscaFunctionService;
private final DataTypeBusinessLogic dataTypeBusinessLogic;
private ApplicationDataTypeCache applicationDataTypeCache;
+ private final ArtifactTypeOperation artifactTypeOperation;
public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic,
final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade,
@@ -198,7 +202,8 @@ public class ServiceImportBusinessLogic {
final ServiceImportParseLogic serviceImportParseLogic, final PolicyBusinessLogic policyBusinessLogic,
final ResourceImportManager resourceImportManager, final JanusGraphDao janusGraphDao,
final IGraphLockOperation graphLockOperation, final ToscaFunctionService toscaFunctionService,
- final DataTypeBusinessLogic dataTypeBusinessLogic) {
+ final DataTypeBusinessLogic dataTypeBusinessLogic, final ArtifactTypeOperation artifactTypeOperation,
+ ArtifactTypeImportManager artifactTypeImportManager) {
this.componentsUtils = componentsUtils;
this.toscaOperationFacade = toscaOperationFacade;
this.serviceBusinessLogic = serviceBusinessLogic;
@@ -216,6 +221,8 @@ public class ServiceImportBusinessLogic {
this.graphLockOperation = graphLockOperation;
this.toscaFunctionService = toscaFunctionService;
this.dataTypeBusinessLogic = dataTypeBusinessLogic;
+ this.artifactTypeOperation = artifactTypeOperation;
+ this.artifactTypeImportManager = artifactTypeImportManager;
}
@Autowired
@@ -263,6 +270,12 @@ public class ServiceImportBusinessLogic {
applicationDataTypeCache.reload(service.getModel(), UniqueIdBuilder.buildDataTypeUid(service.getModel(), createdOrUpdatedDataType.getKey()));
});
}
+
+ final Map<String, Object> artifactTypesToCreate = getArtifactTypesToCreate(service.getModel(), csarInfo);
+ if (MapUtils.isNotEmpty(artifactTypesToCreate)) {
+ artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), service.getModel(),true);
+ }
+
final List<NodeTypeDefinition> nodeTypesToCreate = getNodeTypesToCreate(service.getModel(), csarInfo);
if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) {
createNodeTypes(nodeTypesToCreate, service.getModel(), csarInfo.getModifier());
@@ -302,6 +315,23 @@ public class ServiceImportBusinessLogic {
}
return dataTypesToCreate;
}
+
+ private Map<String, Object> getArtifactTypesToCreate(final String model, final CsarInfo csarInfo) {
+ final Map<String, Object> artifactTypesToCreate = new HashMap<>();
+ final Map<String, Object> artifactTypesMap = csarInfo.getArtifactTypes();
+ if (MapUtils.isNotEmpty(artifactTypesMap)) {
+ for (final Entry<String, Object> artifactTypeEntry : artifactTypesMap.entrySet()) {
+ final Either<ArtifactTypeDefinition, StorageOperationStatus> result =
+ artifactTypeOperation.getArtifactTypeByUid(UniqueIdBuilder.buildArtifactTypeUid(model,artifactTypeEntry.getKey()));
+ if (result.isRight() && StorageOperationStatus.NOT_FOUND.equals(result.right().value())) {
+ artifactTypesToCreate.put(artifactTypeEntry.getKey(), artifactTypeEntry.getValue());
+ log.info("Deploying new artifact type={}, to model={}, from package={}",
+ artifactTypeEntry.getKey(), model, csarInfo.getCsarUUID());
+ }
+ }
+ }
+ return artifactTypesToCreate;
+ }
private boolean hasNewProperties(final Either<DataTypeDefinition, JanusGraphOperationStatus> result, final Map<String, Map<String, Object>> dataType) {
return result.isLeft() && dataType.containsKey("properties") && result.left().value().getProperties() != null
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
index a77ef5bd76..6b92c4a3ea 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
@@ -80,6 +80,7 @@ import org.openecomp.sdc.be.externalapi.servlet.ArtifactExternalServlet;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts;
import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactTypeDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
@@ -112,6 +113,7 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
import org.openecomp.sdc.be.tosca.CsarUtils;
@@ -134,7 +136,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
private final AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic,
componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic);
private final ApplicationDataTypeCache applicationDataTypeCache = mock(ApplicationDataTypeCache.class);
+ private final ArtifactTypeOperation artifactTypeOperation = mock(ArtifactTypeOperation.class);
private final DataTypeBusinessLogic dataTypeBusinessLogic = mock(DataTypeBusinessLogic.class);
+ private final ArtifactTypeImportManager artifactTypeImportManager = mock(ArtifactTypeImportManager.class);
@InjectMocks
private ServiceImportBusinessLogic sIBL;
@@ -245,8 +249,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(applicationDataTypeCache.get(any(), eq("onap.datatypes.ToscaConceptIdentifier.datatype"))).thenReturn(Either.left(typeToBeUpdated));
when(applicationDataTypeCache.get(any(), matches("^((?!(tosca.datatypes.test_|onap.datatypes.ToscaConceptIdentifier)).)*$"))).thenReturn(Either.left(new DataTypeDefinition()));
-
-
+ when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.artifacts"))).thenReturn(Either.left(null));
when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull()))
@@ -277,6 +281,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
assertNotNull(yamlMap.get("tosca.datatypes.test_b"));
assertNotNull(yamlMap.get("onap.datatypes.ToscaConceptIdentifier"));
+ ArgumentCaptor<String> artifactTypes = ArgumentCaptor.forClass(String.class);
+ verify(artifactTypeImportManager).createArtifactTypes(artifactTypes.capture(),isNull(), anyBoolean());
+ Map<String, Object> artifactTypesMap = new Yaml().load(artifactTypes.getValue());
+ assertEquals(1, artifactTypesMap.size());
+ assertNotNull(artifactTypesMap.get("tosca.testartifacts.Name"));
+
ArgumentCaptor<Map<String, Object>> nodeTypes = ArgumentCaptor.forClass(Map.class);
verify(resourceImportManager).importAllNormativeResource(nodeTypes.capture(), any(), any(), any(),
anyBoolean(), anyBoolean());
diff --git a/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar b/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar
index 00a6981272..815b798ec3 100644
--- a/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar
+++ b/catalog-be/src/test/resources/csars/service-Ser09080002-csar.csar
Binary files differ