From 7c61c7bb0369bc27d05c8801c8cb0cca41e494bf Mon Sep 17 00:00:00 2001 From: vasraz Date: Sat, 5 Aug 2023 18:28:19 +0100 Subject: 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 Change-Id: If966a64b865791eed0cf29c8da8f04e44eb32e50 Issue-ID: SDC-4591 --- .../sdc/be/components/csar/CsarBusinessLogic.java | 6 ++- .../be/components/impl/ResourceBusinessLogic.java | 2 +- .../be/components/impl/ResourceImportManager.java | 58 +++++++++++++++++----- .../impl/ServiceImportBusinessLogic.java | 15 +++--- .../components/impl/ServiceImportParseLogic.java | 2 +- .../be/servlets/AbstractValidationsServlet.java | 10 ++-- .../sdc/be/servlets/ResourceUploadServlet.java | 3 +- 7 files changed, 64 insertions(+), 32 deletions(-) (limited to 'catalog-be/src/main') 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 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 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 importNormativeResource(final String resourceYml, final UploadResourceInfo resourceMetaData, + final Map instancesFromCsar, final User creator, final boolean createNewVersion, final boolean needLock, final boolean isInTransaction) { LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(); lifecycleChangeInfo.setUserRemarks("certification on import"); Function 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 nodeTypesMap = (Map) nodeTypesYamlMap.get(ToscaTagNamesEnum.NODE_TYPES.getElementName()); - importAllNormativeResource(nodeTypesMap, nodeTypesMetadataList, user, "", createNewVersion,needLock); + importAllNormativeResource(nodeTypesMap, nodeTypesMetadataList, null, user, "", createNewVersion,needLock); } public void importAllNormativeResource(final Map nodeTypesMap, final NodeTypesMetadataList nodeTypesMetadataList, - final User user, String model, final boolean createNewVersion, final boolean needLock) { + Map 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 importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, + User creator, boolean createNewVersion, boolean needLock) { + LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(); + lifecycleChangeInfo.setUserRemarks("certification on import"); + Function validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource); + return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, + null, null, false, null, null, false, null); + } + public ImmutablePair importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function validationFunction, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, @@ -216,7 +228,7 @@ public class ResourceImportManager { Map> nodeTypeArtifactsToHandle, List nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo, String nodeName, - boolean isNested) { + boolean isNested, Map instancesFromCsar) { Resource resource = new Resource(); ImmutablePair responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED); Either, 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 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 instancesFromCsar) { @SuppressWarnings("unchecked") Object ymlObj = new Yaml().load(resourceYml); if (ymlObj instanceof Map) { final Either 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 toscaJson, Resource resource, Either existingResource) { + private void setInterfaceLifecycle(Map toscaJson, Resource resource, Either existingResource, + Map instancesFromCsar) { final Either, ResultStatusEnum> toscaInterfaces = ImportUtils .findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES); final Map moduleInterfaces = new HashMap<>(); final Map map; + List 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 interfaceNameValue : map.entrySet()) { - final Either eitherInterface = createModuleInterface(interfaceNameValue.getValue(), - resource.getModel()); + final Either 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 interfaceInfoList) { + Map 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 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 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 groupTypesToCreate = getGroupTypesToCreate(serviceModel, csarInfo); @@ -539,7 +539,7 @@ public class ServiceImportBusinessLogic { && result.left().value().getProperties().size() != dataType.get("properties").size(); } - private void createNodeTypes(List nodeTypesToCreate, String model, User user) { + private void createNodeTypes(List nodeTypesToCreate, Map instancesFromCsar, String model, User user) { NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList(); List nodeTypeMetadataList = new ArrayList<>(); final Map 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 getNodeTypesToCreate(final String model, final ServiceCsarInfo csarInfo) { @@ -874,23 +874,20 @@ public class ServiceImportBusinessLogic { private boolean isInputFromComponentInstanceProperty(final String inputName, final List 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 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 createNodeTypeResourceFromYaml(String yamlName, Map.Entry 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; -- cgit 1.2.3-korg