summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
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/src/main/java
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/src/main/java')
-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
5 files changed, 58 insertions, 3 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