From 36582b71676428a30810f206729d9a21cbd87f1a Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 7 Nov 2022 22:10:37 +0000 Subject: Interface is formatted using extended notation when no implementation added at VFC level Signed-off-by: Vasyl Razinkov Change-Id: I4e6e6d61b851fe2efaa47c9f8fad0cb546f2fcb7 Issue-ID: SDC-4255 --- .../be/components/impl/ArtifactsBusinessLogic.java | 7 +-- .../java/org/openecomp/sdc/be/tosca/CsarUtils.java | 46 +++++----------- .../be/tosca/InterfacesOperationsConverter.java | 64 ++++++++++++---------- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 28 ++++------ 4 files changed, 61 insertions(+), 84 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index a978154224..9f5436d152 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -704,11 +704,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { new ArtifactOperationInfo(false, false, ArtifactOperationEnum.DOWNLOAD), artifactId, null, null, null, null, null, parentId, containerComponentType); ArtifactDefinition artifactDefinition; - Either insideValue = result; - if (insideValue.isLeft()) { - artifactDefinition = insideValue.left().value(); + if (result.isLeft()) { + artifactDefinition = result.left().value(); } else { - artifactDefinition = insideValue.right().value().getImplementationArtifact(); + artifactDefinition = result.right().value().getImplementationArtifact(); } // for tosca artifacts and heat env on VF level generated on download without saving if (artifactDefinition.getPayloadData() != null) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java index 81d9e5d077..6bfceb44fa 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java @@ -19,6 +19,8 @@ */ package org.openecomp.sdc.be.tosca; +import static org.openecomp.sdc.be.dao.api.ActionStatus.ARTIFACT_PAYLOAD_NOT_FOUND_DURING_CSAR_CREATION; +import static org.openecomp.sdc.be.dao.api.ActionStatus.ERROR_DURING_CSAR_CREATION; import static org.openecomp.sdc.be.tosca.ComponentCache.MergeStrategy.overwriteIfSameVersions; import static org.openecomp.sdc.be.tosca.FJToVavrHelper.Try0.fromEither; @@ -116,9 +118,6 @@ import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; import org.yaml.snakeyaml.Yaml; -/** - * @author tg851x - */ @org.springframework.stereotype.Component("csar-utils") public class CsarUtils { @@ -195,7 +194,6 @@ public class CsarUtils { return matcher.group(0); } - private static F> iff(Predicate p, Function> ifTrue) { return l -> p.test(l) ? ifTrue.apply(l) : Either.left(l); } @@ -635,7 +633,7 @@ public class CsarUtils { String cassandraId = d.getMiddle(); Component childComponent = d.getRight(); Either entryData = getEntryData(cassandraId, childComponent).right() - .map(x -> componentsUtils.getResponseFormat(x)); + .map(componentsUtils::getResponseFormat); if (entryData.isRight()) { return Either.right(entryData.right().value()); } @@ -835,7 +833,7 @@ public class CsarUtils { } private Either getLatestSchemaFilesFromCassandra() { - String fto = getVersionFirstThreeOctets(); + String fto = versionFirstThreeOctets; return sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(fto, CONFORMANCE_LEVEL).right().map(schemaFilesFetchDBError(fto)).left() .bind(iff(List::isEmpty, () -> schemaFileFetchError(fto), s -> Either.left(s.iterator().next().getPayloadAsArray()))); } @@ -880,9 +878,9 @@ public class CsarUtils { return Either.right(componentsUtils.getResponseFormat(ActionStatus.TOSCA_SCHEMA_FILES_NOT_FOUND, firstThreeOctets, CONFORMANCE_LEVEL)); } - private Either getFromCassandra(String cassandraId) { + private Either getFromCassandra(String cassandraId) { return artifactCassandraDao.getArtifact(cassandraId).right().map(operationstatus -> { - log.info("Failed to fetch artifact from Cassandra by id {} error {}.", cassandraId, operationstatus); + log.info("Failed to fetch artifact from Cassandra by id {} error {}.", cassandraId, operationstatus); StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(operationstatus); return componentsUtils.convertFromStorageResponse(storageStatus); }).left().map(DAOArtifactData::getDataAsArray); @@ -900,7 +898,6 @@ public class CsarUtils { private String createNsMfBlock0(String serviceName, String createdBy, String serviceVersion, String releaseTime, String serviceType, String description, String serviceTemplate, String hash) { final String block0template = "metadata??\n" + "ns_product_name: %s\n" + "ns_provider_id: %s\n" + "ns_package_version: %s\n" + - //"ns_create_date_time: %s\n" + "ns_release_data_time: %s\n" + "ns_type: %s\n" + "ns_package_description: %s\n\n" + "Source: %s\n" + "Algorithm: MD5\n" + "Hash: %s\n\n"; return String.format(block0template, serviceName, createdBy, serviceVersion, releaseTime, serviceType, description, serviceTemplate, hash); } @@ -921,9 +918,8 @@ public class CsarUtils { return Either.right(writeComponentArtifactsToSpecifiedPath.right().value()); } Map componentInstancesArtifacts = mainTypeAndCIArtifacts.getComponentInstancesArtifacts(); - Set keySet = componentInstancesArtifacts.keySet(); String currentPath = ARTIFACTS_PATH + RESOURCES_PATH; - for (String keyAssetName : keySet) { + for (String keyAssetName : componentInstancesArtifacts.keySet()) { ArtifactsInfo artifactsInfo = componentInstancesArtifacts.get(keyAssetName); String pathWithAssetName = currentPath + keyAssetName + PATH_DELIMITER; writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedPath(mainComponent, artifactsInfo, zipstream, pathWithAssetName, @@ -943,8 +939,7 @@ public class CsarUtils { if (checkComponentBeforeOperation(component)) { return Either.left(zipstream); } - final Map interfaces = ((Resource) component).getInterfaces(); - for (Map.Entry interfaceEntry : interfaces.entrySet()) { + for (Map.Entry interfaceEntry : ((Resource) component).getInterfaces().entrySet()) { for (OperationDataDefinition operation : interfaceEntry.getValue().getOperations().values()) { try { if (checkComponentBeforeWrite(component, interfaceEntry, operation)) { @@ -959,19 +954,16 @@ public class CsarUtils { if (artifactFromCassandra.isRight()) { log.error(ARTIFACT_NAME_UNIQUE_ID, artifactName, artifactUUID); log.error("Failed to get {} payload from DB reason: {}", artifactName, artifactFromCassandra.right().value()); - return Either.right(componentsUtils - .getResponseFormat(ActionStatus.ARTIFACT_PAYLOAD_NOT_FOUND_DURING_CSAR_CREATION, "Resource", component.getUniqueId(), - artifactName, artifactUUID)); + return Either.right(componentsUtils.getResponseFormat( + ARTIFACT_PAYLOAD_NOT_FOUND_DURING_CSAR_CREATION, "Resource", component.getUniqueId(), artifactName, artifactUUID)); } - final byte[] payloadData = artifactFromCassandra.left().value(); zipstream.putNextEntry(new ZipEntry(OperationArtifactUtil.createOperationArtifactPath(component, null, operation, true))); - zipstream.write(payloadData); + zipstream.write(artifactFromCassandra.left().value()); } catch (IOException e) { log.error("Component Name {}, Interface Name {}, Operation Name {}", component.getNormalizedName(), interfaceEntry.getKey(), operation.getName()); - log.error("Error while writing the operation's artifacts to the CSAR " + "{}", e); - return Either - .right(componentsUtils.getResponseFormat(ActionStatus.ERROR_DURING_CSAR_CREATION, "Resource", component.getUniqueId())); + log.error("Error while writing the operation's artifacts to the CSAR", e); + return Either.right(componentsUtils.getResponseFormat(ERROR_DURING_CSAR_CREATION, "Resource", component.getUniqueId())); } } } @@ -1191,9 +1183,7 @@ public class CsarUtils { return result.toString(); } - private ComponentTypeArtifacts collectComponentTypeArtifacts( - Component fetchedComponent - ) { + private ComponentTypeArtifacts collectComponentTypeArtifacts(Component fetchedComponent) { ArtifactsInfo componentArtifacts = collectComponentArtifacts(fetchedComponent); ComponentTypeArtifacts componentArtifactsInfo = new ComponentTypeArtifacts(); if (componentArtifacts.isNotEmpty()) { @@ -1269,10 +1259,6 @@ public class CsarUtils { return Either.left(true); } - public String getVersionFirstThreeOctets() { - return versionFirstThreeOctets; - } - private Map> getComponentInstanceSpecificArtifacts(Map componentArtifacts, Map>> componentTypeArtifacts, ArtifactGroupTypeEnum artifactGroupTypeEnum) { @@ -1306,10 +1292,6 @@ public class CsarUtils { Map> informationalArtifactsByType = collectGroupArtifacts(informationalArtifacts); Map deploymentArtifacts = component.getDeploymentArtifacts(); Map> deploymentArtifactsByType = collectGroupArtifacts(deploymentArtifacts); - Map interfaceOperationArtifacts = - OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component); - Map> interfaceOperationArtifactsByType = collectGroupArtifacts( - interfaceOperationArtifacts); ArtifactsInfo artifactsInfo = new ArtifactsInfo(); if (!informationalArtifactsByType.isEmpty()) { artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.INFORMATIONAL, informationalArtifactsByType); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java index ce5038771b..54e61da41a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java @@ -36,6 +36,7 @@ import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; @@ -151,12 +152,13 @@ public class InterfacesOperationsConverter { return toscaResourceName.substring(toscaResourceName.lastIndexOf(DOT) + 1); } - private static boolean isArtifactPresent(final OperationDataDefinition operationDataDefinition) { - return operationDataDefinition.getImplementation() != null && operationDataDefinition.getImplementation().getArtifactName() != null; + private boolean isArtifactPresent(final OperationDataDefinition operationDataDefinition) { + return operationDataDefinition.getImplementation() != null + && StringUtils.isNotEmpty(operationDataDefinition.getImplementation().getArtifactName()); } private static String getInputValue(final OperationInputDefinition input) { - String inputValue = input.getValue() == null ? input.getToscaDefaultValue(): input.getValue(); + String inputValue = input.getValue() == null ? input.getToscaDefaultValue() : input.getValue(); if (inputValue != null && inputValue.contains(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName())) { Gson gson = new Gson(); Map> consumptionValue = gson.fromJson(inputValue, Map.class); @@ -223,18 +225,18 @@ public class InterfacesOperationsConverter { } private Map getInterfacesMap(Component component, Map dataTypes, boolean isAssociatedComponent) { - return getInterfacesMap(component, null, component.getInterfaces(), dataTypes, isAssociatedComponent, false); + return getInterfacesMap(component, null, component.getInterfaces(), dataTypes, isAssociatedComponent); } public Map getInterfacesMap(final Component component, final ComponentInstance componentInstance, final Map interfaces, final Map dataTypes, - final boolean isAssociatedComponent, final boolean isServiceProxyInterface) { + final boolean isAssociatedComponent) { if (MapUtils.isEmpty(interfaces)) { return null; } final Map toscaInterfaceDefinitions = new HashMap<>(); for (InterfaceDefinition interfaceDefinition : interfaces.values()) { - handleInterfaceOperations(component, componentInstance, dataTypes, isAssociatedComponent, isServiceProxyInterface, + handleInterfaceOperations(component, componentInstance, dataTypes, isAssociatedComponent, toscaInterfaceDefinitions, interfaceDefinition); } return toscaInterfaceDefinitions; @@ -242,13 +244,13 @@ public class InterfacesOperationsConverter { public Map getInterfacesMapFromComponentInstance(final Component component, final ComponentInstance componentInstance, final Map dataTypes, - final boolean isAssociatedComponent, final boolean isServiceProxyInterface) { + final boolean isAssociatedComponent) { final Map toscaInterfaceDefinitions = new HashMap<>(); final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); for (final Map.Entry interfaceEntry : componentInstance.getInterfaces().entrySet()) { final InterfaceDefinition interfaceDefinition = objectMapper.convertValue(interfaceEntry.getValue(), InterfaceDefinition.class); - handleInterfaceOperations(component, componentInstance, dataTypes, isAssociatedComponent, isServiceProxyInterface, + handleInterfaceOperations(component, componentInstance, dataTypes, isAssociatedComponent, toscaInterfaceDefinitions, interfaceDefinition); } return toscaInterfaceDefinitions; @@ -256,7 +258,7 @@ public class InterfacesOperationsConverter { private void handleInterfaceOperations(final Component component, final ComponentInstance componentInstance, final Map dataTypes, final boolean isAssociatedComponent, - final boolean isServiceProxyInterface, final Map toscaInterfaceDefinitions, + final Map toscaInterfaceDefinitions, final InterfaceDefinition interfaceDefinition) { final String interfaceType; if (componentInstance != null && LOCAL_INTERFACE_TYPE.equals(interfaceDefinition.getType())) { @@ -280,7 +282,7 @@ public class InterfacesOperationsConverter { } toscaInterfaceDefinition.setOperations(toscaOperationMap); final Map interfaceInputMap = createInterfaceInputMap(interfaceDefinition, dataTypes); - if (!interfaceInputMap.isEmpty()) { + if (MapUtils.isNotEmpty(interfaceInputMap)) { toscaInterfaceDefinition.setInputs(interfaceInputMap); } final Map interfaceDefinitionAsMap = getObjectAsMap(toscaInterfaceDefinition); @@ -298,29 +300,31 @@ public class InterfacesOperationsConverter { final OperationDataDefinition operationDataDefinition, final ToscaLifecycleOperationDefinition toscaOperation, final Map dataTypes) { - if (operationDataDefinition.getImplementation() == null) { + final ArtifactDataDefinition implementation = operationDataDefinition.getImplementation(); + if (implementation == null) { return; } - final String operationArtifactPath; - final ToscaInterfaceOperationImplementation toscaInterfaceOperationImplementation = new ToscaInterfaceOperationImplementation(); - toscaInterfaceOperationImplementation.setPrimary(new ToscaArtifactDefinition()); - final ToscaArtifactDefinition toscaArtifactDefinition = toscaInterfaceOperationImplementation.getPrimary(); - if (isArtifactPresent(operationDataDefinition) && StringUtils.isNotEmpty(operationDataDefinition.getImplementation().getArtifactName())) { - operationArtifactPath = OperationArtifactUtil - .createOperationArtifactPath(component, componentInstance, operationDataDefinition, isAssociatedComponent); - toscaArtifactDefinition.setFile(operationArtifactPath); - toscaArtifactDefinition.setArtifact_version(!operationDataDefinition.getImplementation().getArtifactVersion() - .equals(NumberUtils.INTEGER_ZERO.toString()) ? operationDataDefinition.getImplementation().getArtifactVersion() : null); - toscaArtifactDefinition.setType(operationDataDefinition.getImplementation().getArtifactType()); - final Map propertiesMap = handleImplementationProperties(operationDataDefinition, dataTypes); - if (!propertiesMap.isEmpty()) { - toscaArtifactDefinition.setProperties(propertiesMap); + + if (isArtifactPresent(operationDataDefinition)) { + final String operationArtifactPath = + OperationArtifactUtil.createOperationArtifactPath(component, componentInstance, operationDataDefinition, isAssociatedComponent); + if (implementation.getArtifactType() != null) { + final ToscaArtifactDefinition toscaArtifactDefinition = new ToscaArtifactDefinition(); + toscaArtifactDefinition.setFile(operationArtifactPath); + final String artifactVersion = implementation.getArtifactVersion(); + toscaArtifactDefinition.setArtifact_version(!artifactVersion.equals(NumberUtils.INTEGER_ZERO.toString()) ? artifactVersion : null); + toscaArtifactDefinition.setType(implementation.getArtifactType()); + final Map propertiesMap = handleImplementationProperties(operationDataDefinition, dataTypes); + if (MapUtils.isNotEmpty(propertiesMap)) { + toscaArtifactDefinition.setProperties(propertiesMap); + } + final ToscaInterfaceOperationImplementation toscaInterfaceOperationImplementation = new ToscaInterfaceOperationImplementation(); + toscaInterfaceOperationImplementation.setPrimary(toscaArtifactDefinition); + toscaOperation.setImplementation(toscaInterfaceOperationImplementation); + } else { + toscaOperation.setImplementation( + StringUtils.isBlank(operationArtifactPath) || "null".equals(operationArtifactPath) ? null : operationArtifactPath); } - toscaOperation.setImplementation( - toscaArtifactDefinition.getType() != null ? toscaInterfaceOperationImplementation : operationArtifactPath); - } else { - toscaArtifactDefinition.setFile(operationDataDefinition.getImplementation().getArtifactName()); - toscaOperation.setImplementation(toscaInterfaceOperationImplementation); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 5f21f52960..ff6d015d62 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -1071,28 +1071,22 @@ public class ToscaExportHandler { return intValue == null ? value : intValue; } - private void handleInstanceInterfaces( - Map> componentInstanceInterfaces, - ComponentInstance componentInstance, Map dataTypes, ToscaNodeTemplate nodeTemplate, - String instanceUniqueId, - Component parentComponent) { - - if (MapUtils.isEmpty(componentInstanceInterfaces) - || !componentInstanceInterfaces.containsKey(instanceUniqueId)) { + private void handleInstanceInterfaces(Map> componentInstanceInterfaces, + ComponentInstance componentInstance, Map dataTypes, + ToscaNodeTemplate nodeTemplate, String instanceUniqueId, Component parentComponent) { + + if (MapUtils.isEmpty(componentInstanceInterfaces) || !componentInstanceInterfaces.containsKey(instanceUniqueId)) { nodeTemplate.setInterfaces(null); return; } - final List currServiceInterfaces = - componentInstanceInterfaces.get(instanceUniqueId); + final List currServiceInterfaces = componentInstanceInterfaces.get(instanceUniqueId); final Map tmpInterfaces = new HashMap<>(); - currServiceInterfaces.forEach(instInterface -> tmpInterfaces.put(instInterface - .getUniqueId(), instInterface)); + currServiceInterfaces.forEach(instInterface -> tmpInterfaces.put(instInterface.getUniqueId(), instInterface)); final Map interfaceMap = interfacesOperationsConverter - .getInterfacesMap(parentComponent, componentInstance, tmpInterfaces, dataTypes, isComponentOfTypeServiceProxy(componentInstance), - isComponentOfTypeServiceProxy(componentInstance)); + .getInterfacesMap(parentComponent, componentInstance, tmpInterfaces, dataTypes, isComponentOfTypeServiceProxy(componentInstance)); interfacesOperationsConverter.removeInterfacesWithoutOperations(interfaceMap); nodeTemplate.setInterfaces(MapUtils.isEmpty(interfaceMap) ? null : interfaceMap); @@ -1342,8 +1336,7 @@ public class ToscaExportHandler { interfaceMap = proxyInterfaces.get(); } } else { - interfaceMap = interfacesOperationsConverter - .getInterfacesMapFromComponentInstance(proxyComponent, componentInstance, dataTypes, false, false); + interfaceMap = interfacesOperationsConverter.getInterfacesMapFromComponentInstance(proxyComponent, componentInstance, dataTypes, false); } interfacesOperationsConverter.removeInterfacesWithoutOperations(interfaceMap); @@ -1775,8 +1768,7 @@ public class ToscaExportHandler { // always available in the proxy node template removeOperationImplementationForProxyNodeType(proxyComponentInterfaces); - return Optional - .ofNullable(interfacesOperationsConverter.getInterfacesMap(proxyComponent, null, proxyComponentInterfaces, dataTypes, false, false)); + return Optional.ofNullable(interfacesOperationsConverter.getInterfacesMap(proxyComponent, null, proxyComponentInterfaces, dataTypes, false)); } private static class CustomRepresenter extends Representer { -- cgit 1.2.3-korg