aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-08-05 18:28:19 +0100
committerFrancisco Javier Paradela Vila <javier.paradela.vila@est.tech>2023-08-17 13:15:28 +0000
commit7c61c7bb0369bc27d05c8801c8cb0cca41e494bf (patch)
tree1ed171980ca863d486a8830c1fe591d581bbc1fa /catalog-be/src/main
parenta54910e9b98e78cf543c5245417eeaf9256b242e (diff)
Fix 'Import use case fails when interfaces in template do not exist in system'-bug (p.2)
No interfaces defined on the VFC: - SDC create the basic interface operations on the VFC - Create / Delete etc - with no implementation details - Add the implementations to the interface on the Service side If interfaces are defined on the VFC with no implementation details defined: - SDC import successfully and add the implementation details to the interface on the Service side Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: If966a64b865791eed0cf29c8da8f04e44eb32e50 Issue-ID: SDC-4591
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java3
7 files changed, 64 insertions, 32 deletions
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 be3a408bfa..2ce03f3d1c 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
@@ -65,7 +65,7 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
private static final String FAILED = " failed";
private final YamlTemplateParsingHandler yamlHandler;
private CsarOperation csarOperation;
- private ModelOperation modelOperation;
+ private final ModelOperation modelOperation;
@Autowired
public CsarBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
@@ -164,6 +164,10 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
toscaYamlCsarStatus.getValue(), true, modelOperation);
}
+ public ParsedToscaYamlInfo getParsedToscaYamlInfo(final ServiceCsarInfo csarInfo, final Service service){
+ return getParsedToscaYamlInfo(csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(), csarInfo.extractTypesInfo(), csarInfo, null, service);
+ }
+
public ParsedToscaYamlInfo getParsedToscaYamlInfo(String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
CsarInfo csarInfo, String nodeName, Component component) {
return yamlHandler
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 7e7348d89e..6e385b200a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -1346,7 +1346,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Function<Resource, Boolean> validator = resource -> validateResourceCreationFromNodeType(resource, creator);
return resourceImportManager
.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock,
- nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested);
+ nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested, null);
}
/**
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index 8976753638..99dea8f04d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -66,6 +66,7 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -84,10 +85,11 @@ import org.openecomp.sdc.be.model.DefaultUploadResourceInfo;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.NodeTypesMetadataList;
-import org.openecomp.sdc.be.model.NullNodeTypeMetadata;
import org.openecomp.sdc.be.model.PropertyDefinition;
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.UploadInterfaceInfo;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
@@ -154,13 +156,14 @@ public class ResourceImportManager {
}
public ImmutablePair<Resource, ActionStatus> importNormativeResource(final String resourceYml, final UploadResourceInfo resourceMetaData,
+ final Map<String, UploadComponentInstanceInfo> instancesFromCsar,
final User creator, final boolean createNewVersion, final boolean needLock,
final boolean isInTransaction) {
LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
lifecycleChangeInfo.setUserRemarks("certification on import");
Function<Resource, Boolean> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, createNewVersion,
- needLock, null, null, false, null, null, false);
+ needLock, null, null, false, null, null, false, instancesFromCsar);
}
public void importAllNormativeResource(final String resourcesYaml, final NodeTypesMetadataList nodeTypesMetadataList, final User user,
@@ -176,11 +179,11 @@ public class ResourceImportManager {
return;
}
final Map<String, Object> nodeTypesMap = (Map<String, Object>) nodeTypesYamlMap.get(ToscaTagNamesEnum.NODE_TYPES.getElementName());
- importAllNormativeResource(nodeTypesMap, nodeTypesMetadataList, user, "", createNewVersion,needLock);
+ importAllNormativeResource(nodeTypesMap, nodeTypesMetadataList, null, user, "", createNewVersion,needLock);
}
public void importAllNormativeResource(final Map<String, Object> nodeTypesMap, final NodeTypesMetadataList nodeTypesMetadataList,
- final User user, String model, final boolean createNewVersion, final boolean needLock) {
+ Map<String, UploadComponentInstanceInfo> instancesFromCsar, final User user, String model, final boolean createNewVersion, final boolean needLock) {
try {
nodeTypesMetadataList.getNodeMetadataList().forEach(nodeTypeMetadata -> {
final String nodeTypeToscaName = nodeTypeMetadata.getToscaName();
@@ -199,7 +202,7 @@ public class ResourceImportManager {
uploadResourceInfo.setModel(model);
uploadResourceInfo.setContactId(user.getUserId());
}
- importNormativeResource(nodeTypeYaml, uploadResourceInfo, user, createNewVersion, needLock, true);
+ importNormativeResource(nodeTypeYaml, uploadResourceInfo, instancesFromCsar, user, createNewVersion, needLock, true);
}
});
janusGraphDao.commit();
@@ -209,6 +212,15 @@ public class ResourceImportManager {
}
}
+ public ImmutablePair<Resource, ActionStatus> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData,
+ User creator, boolean createNewVersion, boolean needLock) {
+ LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
+ lifecycleChangeInfo.setUserRemarks("certification on import");
+ Function<Resource, Boolean> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+ return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock,
+ null, null, false, null, null, false, null);
+ }
+
public ImmutablePair<Resource, ActionStatus> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator,
Function<Resource, Boolean> validationFunction,
LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction,
@@ -216,7 +228,7 @@ public class ResourceImportManager {
Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
boolean forceCertificationAllowed, CsarInfo csarInfo, String nodeName,
- boolean isNested) {
+ boolean isNested, Map<String, UploadComponentInstanceInfo> instancesFromCsar) {
Resource resource = new Resource();
ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
@@ -225,7 +237,7 @@ public class ResourceImportManager {
boolean shouldBeCertified = nodeTypeArtifactsToHandle == null || nodeTypeArtifactsToHandle.isEmpty();
setConstantMetaData(resource, shouldBeCertified);
setResourceMetaData(resource, resourceYml, resourceMetaData);
- populateResourceFromYaml(resourceYml, resource);
+ populateResourceFromYaml(resourceYml, resource, instancesFromCsar);
validationFunction.apply(resource);
resource.getComponentMetadataDefinition().getMetadataDataDefinition().setNormative(resourceMetaData.isNormative());
checkResourceExists(createNewVersion, csarInfo, resource);
@@ -341,7 +353,7 @@ public class ResourceImportManager {
ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
try {
setMetaDataFromJson(resourceMetaData, resource);
- populateResourceFromYaml(resourceYml, resource);
+ populateResourceFromYaml(resourceYml, resource, null);
// currently import VF isn't supported. In future will be supported import VF only with CSAR file!!
if (ResourceTypeEnum.VF == resource.getResourceType()) {
log.debug("Now import VF isn't supported. It will be supported in future with CSAR file only");
@@ -356,7 +368,7 @@ public class ResourceImportManager {
return responsePair;
}
- private void populateResourceFromYaml(final String resourceYml, Resource resource) {
+ private void populateResourceFromYaml(final String resourceYml, Resource resource, Map<String, UploadComponentInstanceInfo> instancesFromCsar) {
@SuppressWarnings("unchecked") Object ymlObj = new Yaml().load(resourceYml);
if (ymlObj instanceof Map) {
final Either<Resource, StorageOperationStatus> existingResource = getExistingResource(resource);
@@ -383,7 +395,7 @@ public class ResourceImportManager {
setProperties(toscaJson, resource, existingResource);
setAttributes(toscaJson, resource);
setRequirements(toscaJson, resource, parentResource);
- setInterfaceLifecycle(toscaJson, resource, existingResource);
+ setInterfaceLifecycle(toscaJson, resource, existingResource, instancesFromCsar);
} else {
throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
@@ -441,20 +453,29 @@ public class ResourceImportManager {
return null;
}
- private void setInterfaceLifecycle(Map<String, Object> toscaJson, Resource resource, Either<Resource, StorageOperationStatus> existingResource) {
+ private void setInterfaceLifecycle(Map<String, Object> toscaJson, Resource resource, Either<Resource, StorageOperationStatus> existingResource,
+ Map<String, UploadComponentInstanceInfo> instancesFromCsar) {
final Either<Map<String, Object>, ResultStatusEnum> toscaInterfaces = ImportUtils
.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES);
final Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<>();
final Map<String, Object> map;
+ List<UploadInterfaceInfo> interfaceInfoList = null;
+ if (MapUtils.isNotEmpty(instancesFromCsar)) {
+ interfaceInfoList = instancesFromCsar.values().stream().filter(i -> MapUtils.isNotEmpty(i.getInterfaces()))
+ .flatMap(i -> i.getInterfaces().values().stream()).collect(Collectors.toList());
+ }
if (toscaInterfaces.isLeft()) {
map = toscaInterfaces.left().value();
for (final Entry<String, Object> interfaceNameValue : map.entrySet()) {
- final Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue.getValue(),
- resource.getModel());
+ final Either<InterfaceDefinition, ResultStatusEnum> eitherInterface =
+ createModuleInterface(interfaceNameValue.getValue(), resource.getModel());
if (eitherInterface.isRight()) {
log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), resource.getName());
} else {
final InterfaceDefinition interfaceDefinition = eitherInterface.left().value();
+ if (CollectionUtils.isNotEmpty(interfaceInfoList)) {
+ updateInterfaceDefinition(interfaceDefinition, interfaceInfoList);
+ }
moduleInterfaces.put(interfaceDefinition.getType(), interfaceDefinition);
}
}
@@ -480,6 +501,17 @@ public class ResourceImportManager {
}
}
+ private void updateInterfaceDefinition(InterfaceDefinition interfaceDefinition, List<UploadInterfaceInfo> interfaceInfoList) {
+ Map<String, OperationDataDefinition> operations = new HashMap<>();
+ interfaceInfoList.stream().filter(i -> interfaceDefinition.getType().endsWith(i.getKey())).forEach(i -> {
+ i.getOperations().values().forEach(o -> {
+ o.setImplementation(null);
+ });
+ operations.putAll(i.getOperations());
+ });
+ interfaceDefinition.setOperations(operations);
+ }
+
private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(final Object interfaceJson, final String model) {
try {
if (interfaceJson instanceof String) {
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 641e294e42..1ba74a1594 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
@@ -46,7 +46,6 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -389,7 +388,8 @@ public class ServiceImportBusinessLogic {
final List<NodeTypeDefinition> nodeTypesToCreate = getNodeTypesToCreate(serviceModel, csarInfo);
if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) {
- createNodeTypes(nodeTypesToCreate, serviceModel, csarInfo.getModifier());
+ ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic.getParsedToscaYamlInfo(csarInfo, service);
+ createNodeTypes(nodeTypesToCreate, parsedToscaYamlInfo.getInstances(), serviceModel, csarInfo.getModifier());
}
final Map<String, Object> groupTypesToCreate = getGroupTypesToCreate(serviceModel, csarInfo);
@@ -539,7 +539,7 @@ public class ServiceImportBusinessLogic {
&& result.left().value().getProperties().size() != dataType.get("properties").size();
}
- private void createNodeTypes(List<NodeTypeDefinition> nodeTypesToCreate, String model, User user) {
+ private void createNodeTypes(List<NodeTypeDefinition> nodeTypesToCreate, Map<String, UploadComponentInstanceInfo> instancesFromCsar, String model, User user) {
NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList();
List<NodeTypeMetadata> nodeTypeMetadataList = new ArrayList<>();
final Map<String, Object> allTypesToCreate = new HashMap<>();
@@ -548,7 +548,7 @@ public class ServiceImportBusinessLogic {
nodeTypeMetadataList.add(nodeType.getNodeTypeMetadata());
});
nodeTypesMetadataList.setNodeMetadataList(nodeTypeMetadataList);
- resourceImportManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, user, model, true, false);
+ resourceImportManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, instancesFromCsar, user, model, true, false);
}
private List<NodeTypeDefinition> getNodeTypesToCreate(final String model, final ServiceCsarInfo csarInfo) {
@@ -874,23 +874,20 @@ public class ServiceImportBusinessLogic {
private boolean isInputFromComponentInstanceProperty(final String inputName, final List<ComponentInstance> componentInstances) {
- AtomicBoolean isInputFromCIProp = new AtomicBoolean(false);
if (CollectionUtils.isNotEmpty(componentInstances)) {
- outer:
for (ComponentInstance instance : componentInstances) {
for (PropertyDefinition instanceProperty : instance.getProperties()) {
if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
if (inputName.equals(getInputValueDataDefinition.getInputName())) {
- isInputFromCIProp.set(true);
- break outer;
+ return true;
}
}
}
}
}
}
- return isInputFromCIProp.get();
+ return false;
}
private void associateInputToComponentInstanceProperty(final String userId, final InputDefinition input,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
index 3c82df4a50..5bde56de80 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
@@ -1774,7 +1774,7 @@ public class ServiceImportParseLogic {
Function<Resource, Boolean> validator = resource -> validateResourceCreationFromNodeType(resource, creator);
return resourceImportManager
.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock,
- nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested);
+ nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested, null);
}
public ImmutablePair<Resource, ActionStatus> createNodeTypeResourceFromYaml(String yamlName, Map.Entry<String, Object> nodeNameValue, User user,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
index ade8637715..58756642c1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
@@ -659,13 +659,13 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
if (CsarValidationUtils.isCsarPayloadName(resourceInfoObject.getPayloadName())) {
log.debug("import resource from csar");
importedResourceStatus = importResourceFromUICsar(resourceInfoObject, user, resourceUniqueId);
- } else if (!authority.isUserTypeResource()) {
- log.debug("import normative type resource");
- createOrUpdateResponse =
- resourceImportManager.importNormativeResource(yamlAsString, resourceInfoObject, user, createNewVersion, true, false);
- } else {
+ } else if (authority.isUserTypeResource()) {
log.debug("import user resource (not normative type)");
createOrUpdateResponse = resourceImportManager.importUserDefinedResource(yamlAsString, resourceInfoObject, user, false);
+ } else {
+ log.debug("import normative type resource");
+ createOrUpdateResponse =
+ resourceImportManager.importNormativeResource(yamlAsString, resourceInfoObject, null, user, createNewVersion, true, false);
}
if (createOrUpdateResponse != null) {
importedResourceStatus = createOrUpdateResponse;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
index c1eccdbef0..00500888cb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
@@ -197,8 +197,7 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
}
try {
- resourceImportManager
- .importAllNormativeResource(nodeTypesYamlString, nodeTypeMetadata, user, createNewVersion, false);
+ resourceImportManager.importAllNormativeResource(nodeTypesYamlString, nodeTypeMetadata, user, createNewVersion, false);
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), null);
} catch (final BusinessException e) {
throw e;