From 46a9238f48695d25066e2e351c275f0594f2eb9a Mon Sep 17 00:00:00 2001 From: vasraz Date: Tue, 31 Jan 2023 17:13:55 +0000 Subject: Stop auto-generation of inputs from substitution mapping node Signed-off-by: Vasyl Razinkov Change-Id: I0ecdfe1f22790b0fc23fa99b9a85cdaca3b23515 Issue-ID: SDC-4361 --- .../sdc/be/components/csar/CsarBusinessLogic.java | 6 +- .../sdc/be/components/csar/ServiceCsarInfo.java | 9 +-- .../be/components/impl/ServiceBusinessLogic.java | 4 +- .../impl/ServiceImportBusinessLogic.java | 64 +++++++++++----------- .../openecomp/sdc/be/servlets/DataTypeServlet.java | 7 ++- .../config/ContainerInstanceTypesData.java | 5 +- .../operations/ToscaOperationFacade.java | 2 +- 7 files changed, 51 insertions(+), 46 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 e4b54c18b5..0df8555b47 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 @@ -21,6 +21,8 @@ */ package org.openecomp.sdc.be.components.csar; +import static org.openecomp.sdc.common.api.Constants.DEFAULT_MODEL_NAME; + import fj.data.Either; import java.util.Map; import java.util.Optional; @@ -133,13 +135,13 @@ public class CsarBusinessLogic extends BaseBusinessLogic { if (resource.getModel() == null) { if (!vendorSoftwareProduct.getModelList().isEmpty()) { var modelStringList = String.join(", ", vendorSoftwareProduct.getModelList()); - throw new ByActionStatusComponentException(ActionStatus.VSP_MODEL_NOT_ALLOWED, "SDC AID", modelStringList); + throw new ByActionStatusComponentException(ActionStatus.VSP_MODEL_NOT_ALLOWED, DEFAULT_MODEL_NAME, modelStringList); } return; } if (!vendorSoftwareProduct.getModelList().contains(resource.getModel())) { var modelStringList = - vendorSoftwareProduct.getModelList().isEmpty() ? "SDC AID" : String.join(", ", vendorSoftwareProduct.getModelList()); + vendorSoftwareProduct.getModelList().isEmpty() ? DEFAULT_MODEL_NAME : String.join(", ", vendorSoftwareProduct.getModelList()); throw new ByActionStatusComponentException(ActionStatus.VSP_MODEL_NOT_ALLOWED, resource.getModel(), modelStringList); } } 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 af4d6e48e0..dc77c6044f 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 @@ -83,14 +83,15 @@ public class ServiceCsarInfo extends CsarInfo { importFilePaths.stream().filter(path -> !filesHandled.contains(path)).forEach( importFilePath -> { - byte[] importFile = csar.get(importFilePath.toString()); + final String importFilePathString = importFilePath.toString(); + final byte[] importFile = csar.get(importFilePathString); if (importFile != null) { filesHandled.add(importFilePath); - Map mappedImportFile = new Yaml().load(new String(csar.get(importFilePath.toString()))); - templateImports.put(importFilePath.toString(), mappedImportFile); + final Map mappedImportFile = new Yaml().load(new String(importFile)); + templateImports.put(importFilePathString, mappedImportFile); templateImports.putAll(getTemplateImports(csar, mappedImportFile, importFilePath.getParent(), filesHandled)); } else { - log.info("Import {} cannot be found in CSAR", importFilePath.toString()); + log.warn("Import {} cannot be found in CSAR", importFilePathString); } }); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index f5db6be6bd..187d7b8491 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -707,7 +707,9 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { if (service.isSubstituteCandidate() || genericTypeBusinessLogic.hasMandatorySubstitutionType(service)) { final Resource genericType = fetchAndSetDerivedFromGenericType(service); generatePropertiesFromGenericType(service, genericType); - generateAndAddInputsFromGenericTypeProperties(service, genericType); + if (Constants.DEFAULT_MODEL_NAME.equals(service.getModel()) || service.getModel() == null) { + generateAndAddInputsFromGenericTypeProperties(service, genericType); + } } beforeCreate(service); Either dataModelResponse = toscaOperationFacade.createToscaComponent(service); 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 7bdaaee9a6..828439e44b 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 @@ -291,48 +291,47 @@ public class ServiceImportBusinessLogic { protected Service createServiceFromCsar(Service service, User user, Map csarUIPayload, String csarUUID) { log.trace("************* created successfully from YAML, resource TOSCA "); try { - ServiceCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID); - - final Map dataTypesToCreate = getDatatypesToCreate(service.getModel(), csarInfo); + final ServiceCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID); + final String serviceModel = service.getModel(); + final Map dataTypesToCreate = getDatatypesToCreate(serviceModel, csarInfo); if (MapUtils.isNotEmpty(dataTypesToCreate)) { - dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), service.getModel(), true); + dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), serviceModel, true); dataTypesToCreate.keySet().forEach(key -> - applicationDataTypeCache.reload(service.getModel(), UniqueIdBuilder.buildDataTypeUid(service.getModel(), key)) + applicationDataTypeCache.reload(serviceModel, UniqueIdBuilder.buildDataTypeUid(serviceModel, key)) ); } - final Map artifactTypesToCreate = getArtifactTypesToCreate(service.getModel(), csarInfo); + final Map artifactTypesToCreate = getArtifactTypesToCreate(serviceModel, csarInfo); if (MapUtils.isNotEmpty(artifactTypesToCreate)) { - artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), service.getModel(), true); + artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), serviceModel, true); } - final List nodeTypesToCreate = getNodeTypesToCreate(service.getModel(), csarInfo); + final List nodeTypesToCreate = getNodeTypesToCreate(serviceModel, csarInfo); if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) { - createNodeTypes(nodeTypesToCreate, service.getModel(), csarInfo.getModifier()); + createNodeTypes(nodeTypesToCreate, serviceModel, csarInfo.getModifier()); } - final Map groupTypesToCreate = getGroupTypesToCreate(service.getModel(), csarInfo); + final Map groupTypesToCreate = getGroupTypesToCreate(serviceModel, csarInfo); if (MapUtils.isNotEmpty(groupTypesToCreate)) { final Map toscaTypeMetadata = fillToscaTypeMetadata(groupTypesToCreate); final ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(new Yaml().dump(groupTypesToCreate), toscaTypeMetadata); - groupTypeImportManager.createGroupTypes(toscaTypeImportData, service.getModel(), true); + groupTypeImportManager.createGroupTypes(toscaTypeImportData, serviceModel, true); } - final Map interfaceTypesToCreate = getInterfaceTypesToCreate(service.getModel(), csarInfo); + final Map interfaceTypesToCreate = getInterfaceTypesToCreate(serviceModel, csarInfo); if (MapUtils.isNotEmpty(interfaceTypesToCreate)) { - interfaceLifecycleTypeImportManager - .createLifecycleTypes(new Yaml().dump(interfaceTypesToCreate), service.getModel(), true); + interfaceLifecycleTypeImportManager.createLifecycleTypes(new Yaml().dump(interfaceTypesToCreate), serviceModel, true); } - final Map capabilityTypesToCreate = getCapabilityTypesToCreate(service.getModel(), csarInfo); + final Map capabilityTypesToCreate = getCapabilityTypesToCreate(serviceModel, csarInfo); if (MapUtils.isNotEmpty(capabilityTypesToCreate)) { - capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), service.getModel(), true); + capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), serviceModel, true); } Map nodeTypesInfo = csarInfo.extractTypesInfo(); - Either>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = serviceImportParseLogic - .findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service); + Either>>, ResponseFormat> findNodeTypesArtifactsToHandleRes + = serviceImportParseLogic.findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service); if (findNodeTypesArtifactsToHandleRes.isRight()) { log.debug("failed to find node types for update with artifacts during import csar {}. ", csarInfo.getCsarUUID()); throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value()); @@ -761,23 +760,22 @@ public class ServiceImportBusinessLogic { private Service updateInputs(final Service component, final String userId) { final List inputs = component.getInputs(); - final List componentInstances = component.getComponentInstances(); - final String componentUniqueId = component.getUniqueId(); - final Map> componentInstancesProperties = component.getComponentInstancesProperties(); - for (final InputDefinition input : inputs) { - if (isInputFromComponentInstanceProperty(input.getName(), componentInstances, componentInstancesProperties)) { - associateInputToComponentInstanceProperty(userId, input, componentInstances, componentInstancesProperties, - componentUniqueId); - } else { - associateInputToServiceProperty(userId, input, component); + if (CollectionUtils.isNotEmpty(inputs)) { + final List componentInstances = component.getComponentInstances(); + final String componentUniqueId = component.getUniqueId(); + final Map> componentInstancesProperties = component.getComponentInstancesProperties(); + for (final InputDefinition input : inputs) { + if (isInputFromComponentInstanceProperty(input.getName(), componentInstances, componentInstancesProperties)) { + associateInputToComponentInstanceProperty(userId, input, componentInstances, componentInstancesProperties, componentUniqueId); + } else { + associateInputToServiceProperty(userId, input, component); + } } - } - - final Either, StorageOperationStatus> either - = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId); - if (either.isRight()) { - throw new ComponentException(ActionStatus.GENERAL_ERROR); + Either, StorageOperationStatus> either = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId); + if (either.isRight()) { + throw new ComponentException(ActionStatus.GENERAL_ERROR); + } } return component; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java index 13e2ba3259..2e67a9bb47 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java @@ -45,6 +45,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic; import org.openecomp.sdc.be.components.impl.aaf.AafPermission; import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed; @@ -152,11 +153,11 @@ public class DataTypeServlet extends BeGenericServlet { String model = dataType.getModel(); Optional propertyDataType = dataTypeOperation.getDataTypeByNameAndModel(propertyDefinitionDto.getType(), model); if (propertyDataType.isEmpty()) { - if (model == null || model.isEmpty()) { - model = "SDC AID"; + if (StringUtils.isEmpty(model)) { + model = Constants.DEFAULT_MODEL_NAME; } throw new OperationException(ActionStatus.INVALID_MODEL, - String.format("Property model is not the same as the data type model. Must be be '%s'", model)); + String.format("Property model is not the same as the data type model. Must be '%s'", model)); } final PropertyDefinitionDto property = dataTypeOperation.createProperty(id, propertyDefinitionDto); dataTypeOperation.addPropertyToAdditionalTypeDataType(dataType, property); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java index 7bf528105c..75a0cd625e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java @@ -27,6 +27,7 @@ import org.apache.commons.collections4.MapUtils; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.common.api.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -74,12 +75,12 @@ public class ContainerInstanceTypesData { /** * Gets the list of allowed component instances for a service of the given model. * - * @param model the model + * @param modelName the model * @return the list of allowed component instances */ public List getServiceAllowedList(final String modelName) { List allowedInstanceResourceType = getComponentAllowedList(ComponentTypeEnum.SERVICE, null); - if (modelName == null || modelName.isEmpty() || modelName.equals("SDC AID")){ + if (modelName == null || modelName.isEmpty() || modelName.equals(Constants.DEFAULT_MODEL_NAME)){ allowedInstanceResourceType.remove("VFC"); } return allowedInstanceResourceType; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index ceb505ac3c..31aea03a8e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -1534,7 +1534,7 @@ public class ToscaOperationFacade { if (StorageOperationStatus.OK == status) { log.debug(COMPONENT_CREATED_SUCCESSFULLY); List inputsResList = null; - if (inputsAsDataDef != null && !inputsAsDataDef.isEmpty()) { + if (CollectionUtils.isNotEmpty(inputsAsDataDef)) { inputsResList = inputsAsDataDef.stream().map(InputDefinition::new).collect(Collectors.toList()); } return Either.left(inputsResList); -- cgit 1.2.3-korg