summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2022-09-21 15:39:47 +0100
committerMichael Morris <michael.morris@est.tech>2022-09-26 15:57:27 +0000
commit467338ad23721809b1f95cb9d2920740b83acb5f (patch)
tree762c7d8501c5d49d0d4d30408f3a96533095526b /catalog-be/src/main
parent02b910764f71ce7ad64a582e91bcb92c73fd33a6 (diff)
Service import - Import unknown capability types
When an unknown capability is found in the csar used to import a service, this capability will be added to the model to which the service is being imported Issue-ID: SDC-4187 Signed-off-by: franciscovila <javier.paradela.vila@est.tech> Change-Id: If43b14008e18195bff237c35c5fc1154e57239ff
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java33
4 files changed, 44 insertions, 1 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 5f49bd7bf2..f92c1d10d2 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
@@ -179,6 +179,8 @@ public abstract class CsarInfo {
public abstract Map<String, Object> getGroupTypes();
+ public abstract Map<String, Object> getCapabilityTypes();
+
public abstract Map<String, Object> getArtifactTypes();
public Map<String, Object> getPolicyTypes() {
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 68a51e3ed3..9ab767876d 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
@@ -216,6 +216,11 @@ public class OnboardedCsarInfo extends CsarInfo {
return getTypes(GROUP_TYPES);
}
+ @Override
+ public Map<String, Object> getCapabilityTypes() {
+ return getTypes(ToscaTagNamesEnum.CAPABILITY_TYPES);
+ }
+
private Map<String, Object> getTypes(ToscaTagNamesEnum toscaTag) {
final Map<String, Object> types = new HashMap<>();
for (Map.Entry<String, byte[]> entry : globalSubstitutes) {
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 aeef3acd64..54cd29868b 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
@@ -154,6 +154,11 @@ public class ServiceCsarInfo extends CsarInfo {
return getTypes(ToscaTagNamesEnum.GROUP_TYPES);
}
+ @Override
+ public Map<String, Object> getCapabilityTypes() {
+ return getTypes(ToscaTagNamesEnum.CAPABILITY_TYPES);
+ }
+
private Map<String, Object> getTypes(ToscaTagNamesEnum toscaTag) {
final Map<String, Object> types = new HashMap<>();
mainTemplateImports.entrySet().stream().forEach(entry -> types.putAll(getTypesFromTemplate(entry.getValue(), toscaTag)));
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 a5e20f30eb..151717f9cd 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
@@ -96,6 +96,7 @@ 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;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
@@ -141,6 +142,7 @@ 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.CapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
@@ -202,6 +204,9 @@ public class ServiceImportBusinessLogic {
private final GroupTypeImportManager groupTypeImportManager;
private final GroupTypeOperation groupTypeOperation;
+ private final CapabilityTypeImportManager capabilityTypeImportManager;
+ private final CapabilityTypeOperation capabilityTypeOperation;
+
public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic,
final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade,
final ServiceBusinessLogic serviceBusinessLogic, final CsarBusinessLogic csarBusinessLogic,
@@ -213,7 +218,9 @@ public class ServiceImportBusinessLogic {
final IGraphLockOperation graphLockOperation, final ToscaFunctionService toscaFunctionService,
final DataTypeBusinessLogic dataTypeBusinessLogic, final ArtifactTypeOperation artifactTypeOperation,
final ArtifactTypeImportManager artifactTypeImportManager, final GroupTypeImportManager groupTypeImportManager,
- final GroupTypeOperation groupTypeOperation) {
+ final GroupTypeOperation groupTypeOperation,
+ final CapabilityTypeImportManager capabilityTypeImportManager,
+ final CapabilityTypeOperation capabilityTypeOperation) {
this.componentsUtils = componentsUtils;
this.toscaOperationFacade = toscaOperationFacade;
this.serviceBusinessLogic = serviceBusinessLogic;
@@ -235,6 +242,8 @@ public class ServiceImportBusinessLogic {
this.artifactTypeImportManager = artifactTypeImportManager;
this.groupTypeImportManager = groupTypeImportManager;
this.groupTypeOperation = groupTypeOperation;
+ this.capabilityTypeImportManager = capabilityTypeImportManager;
+ this.capabilityTypeOperation = capabilityTypeOperation;
}
@Autowired
@@ -301,6 +310,12 @@ public class ServiceImportBusinessLogic {
groupTypeImportManager.createGroupTypes(toscaTypeImportData, service.getModel(), true);
}
+ final Map<String, Object> capabilityTypesToCreate = getCapabilityTypesToCreate(service.getModel(), csarInfo);
+
+ if (MapUtils.isNotEmpty(capabilityTypesToCreate)) {
+ capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), service.getModel(), true);
+ }
+
Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = serviceImportParseLogic
.findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service);
@@ -360,6 +375,22 @@ public class ServiceImportBusinessLogic {
return groupTypesToCreate;
}
+ private Map<String, Object> getCapabilityTypesToCreate(final String model, final CsarInfo csarInfo) {
+ final Map<String, Object> capabilityTypesToCreate = new HashMap<>();
+ final Map<String, Object> capabilityTypes = csarInfo.getCapabilityTypes();
+ if (MapUtils.isNotEmpty(capabilityTypes)) {
+ for (final Entry<String, Object> entry : capabilityTypes.entrySet()) {
+ final Either<CapabilityTypeDefinition, StorageOperationStatus> result
+ = capabilityTypeOperation.getCapabilityType(UniqueIdBuilder.buildCapabilityTypeUid(model, entry.getKey()));
+ if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ capabilityTypesToCreate.put(entry.getKey(), entry.getValue());
+ log.info("Deploying new capability type {} to model {} from package {}", entry.getKey(), model, csarInfo.getCsarUUID());
+ }
+ }
+ }
+ return capabilityTypesToCreate;
+ }
+
private Map<String, Object> getDatatypesToCreate(final String model, final CsarInfo csarInfo) {
final Map<String, Object> dataTypesToCreate = new HashMap<>();