summaryrefslogtreecommitdiffstats
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
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
-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
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java24
-rw-r--r--catalog-be/src/test/resources/csars/service-Ser09080002-csar.csarbin63901 -> 63922 bytes
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java2
7 files changed, 65 insertions, 6 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<>();
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 e4b6dd4021..944f51c244 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,9 +80,9 @@ 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.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
@@ -114,8 +114,9 @@ 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.GroupTypeOperation;
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.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
import org.openecomp.sdc.be.tosca.CsarUtils;
@@ -130,8 +131,6 @@ import org.yaml.snakeyaml.Yaml;
class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup {
- private static final String DEFAULT_ICON = "defaulticon";
-
private final ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class);
private final ResourceImportManager resourceImportManager = mock(ResourceImportManager.class);
private final ServletUtils servletUtils = mock(ServletUtils.class);
@@ -142,6 +141,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
private final DataTypeBusinessLogic dataTypeBusinessLogic = mock(DataTypeBusinessLogic.class);
private final ArtifactTypeImportManager artifactTypeImportManager = mock(ArtifactTypeImportManager.class);
private final GroupTypeOperation groupTypeOperation = mock(GroupTypeOperation.class);
+ private final CapabilityTypeOperation capabilityTypeOperation = mock(CapabilityTypeOperation.class);
+ private final CapabilityTypeImportManager capabilityTypeImportManager = mock(CapabilityTypeImportManager.class);
@InjectMocks
private ServiceImportBusinessLogic sIBL;
@@ -254,6 +255,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.artifacts"))).thenReturn(Either.left(null));
+
+ when(capabilityTypeOperation.getCapabilityType(anyString()))
+ .thenReturn(Either.left(new CapabilityTypeDefinition()));
+ when(capabilityTypeOperation.getCapabilityType(contains("tosca.testcapabilitytypes.Name")))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull()))
@@ -291,6 +298,15 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
assertEquals(1, artifactTypesMap.size());
assertNotNull(artifactTypesMap.get("tosca.testartifacts.Name"));
+ ArgumentCaptor<String> capabilityTypes = ArgumentCaptor.forClass(String.class);
+ verify(capabilityTypeImportManager).createCapabilityTypes(
+ capabilityTypes.capture(),
+ isNull(),
+ anyBoolean());
+ Map<String, Object> capabilityTypesMap = new Yaml().load(capabilityTypes.getValue());
+ assertEquals(1, capabilityTypesMap.size());
+ assertNotNull(capabilityTypesMap.get("tosca.testcapabilitytypes.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 815b798ec3..c780e3484c 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
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
index 1d1bfa6eb9..3f6f0cd0fb 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
@@ -55,7 +55,7 @@ public class TypeUtils {
// Policy Types
POLICIES("policies"), TARGETS("targets"),
// Capabilities
- CAPABILITIES("capabilities"), VALID_SOURCE_TYPES("valid_source_types"),
+ CAPABILITIES("capabilities"), CAPABILITY_TYPES("capability_types"), VALID_SOURCE_TYPES("valid_source_types"),
// Requirements
REQUIREMENTS("requirements"), NODE("node"), RELATIONSHIP("relationship"), CAPABILITY("capability"), INTERFACES("interfaces"),
NODE_FILTER("node_filter"), TOSCA_ID("tosca_id"),