From ab5c816e1578d8f0dba231e0026e5175a84c31c3 Mon Sep 17 00:00:00 2001 From: priyanshu Date: Wed, 10 Apr 2019 12:18:24 +0530 Subject: Tosca artifacts - Error 500 Tosca artifacts - Error 500 - Service proxy with WF assigned Change-Id: I1d75c0b9980ab42c7c825e4423ff4994600dd6fa Issue-ID: SDC-2232 Signed-off-by: priyanshu --- .../validation/InterfaceOperationValidation.java | 2 +- .../java/org/openecomp/sdc/be/tosca/CsarUtils.java | 27 ++++++++++++------- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 10 +++---- .../tosca/utils/InterfacesOperationsToscaUtil.java | 16 ++++++----- .../sdc/be/tosca/utils/OperationArtifactUtil.java | 31 +++++++++++++++------- .../utils/InterfacesOperationsToscaUtilTest.java | 2 +- .../be/tosca/utils/OperationArtifactUtilTest.java | 13 +++++---- 7 files changed, 60 insertions(+), 41 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java index f84c9a4d86..30d006f501 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java @@ -589,7 +589,7 @@ public class InterfaceOperationValidation { ListDataDefinition inputs = operationEntry.getValue().getInputs(); String expectedOperationIdentifier = interfaceDefinitionEntry.getValue().getType() + "." + operationEntry.getValue().getName(); - if (!currentOperationIdentifier.equals(expectedOperationIdentifier) && !inputs.isEmpty()) { + if (!currentOperationIdentifier.equals(expectedOperationIdentifier) && Objects.nonNull(inputs) && !inputs.isEmpty()) { otherOperationInputs.addAll(inputs.getListToscaDataDefinition()); } } 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 bea65cf187..c6dec0bcc4 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 @@ -37,6 +37,7 @@ import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; @@ -431,10 +432,10 @@ public class CsarUtils { } private Either writeComponentInterface(Component component, ZipOutputStream zip, - String fileName, boolean isAssociatedResourceComponent) { + String fileName, boolean isAssociatedComponent) { try { Either componentInterface = toscaExportUtils - .exportComponentInterface(component, isAssociatedResourceComponent); + .exportComponentInterface(component, isAssociatedComponent); ToscaRepresentation componentInterfaceYaml = componentInterface.left().value(); String mainYaml = componentInterfaceYaml.getMainYaml(); String interfaceFileName = DEFINITIONS_PATH + ToscaExportHandler.getInterfaceFilename(fileName); @@ -872,11 +873,11 @@ public class CsarUtils { ComponentTypeArtifacts componentInstanceArtifacts = componentTypeArtifacts.get(keyAssetName); ArtifactsInfo componentArtifacts2 = componentInstanceArtifacts.getComponentArtifacts(); String pathWithAssetName = currentPath + keyAssetName + "/"; - Either writeArtifactsInfoToSpecifiedtPath = writeArtifactsInfoToSpecifiedPath( + Either writeArtifactsInfoToSpecifiedPath = writeArtifactsInfoToSpecifiedPath( mainComponent, componentArtifacts2, zipstream, pathWithAssetName, isInCertificationRequest); - if (writeArtifactsInfoToSpecifiedtPath.isRight()) { - return writeArtifactsInfoToSpecifiedtPath; + if (writeArtifactsInfoToSpecifiedPath.isRight()) { + return writeArtifactsInfoToSpecifiedPath; } } @@ -1188,7 +1189,7 @@ public class CsarUtils { } private ComponentTypeArtifacts collectComponentTypeArtifacts(Map resourcesArtifacts, - ComponentInstance componentInstance, Resource fetchedComponent) { + ComponentInstance componentInstance, Component fetchedComponent) { String toscaComponentName = componentInstance.getToscaComponentName() + "_v" + componentInstance.getComponentVersion(); @@ -1210,15 +1211,21 @@ public class CsarUtils { ComponentInstance componentInstance, Map resourcesTypeArtifacts, ComponentTypeArtifacts instanceArtifactsLocation) { // 1. get the component instance component - String componentUid = componentInstance.getComponentUid(); - Either resource = toscaOperationFacade.getToscaElement(componentUid); - if (resource.isRight()) { + String componentUid; + if (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) { + componentUid = componentInstance.getSourceModelUid(); + } + else { + componentUid = componentInstance.getComponentUid(); + } + Either component = toscaOperationFacade.getToscaElement(componentUid); + if (component.isRight()) { log.error("Failed to fetch resource with id {} for instance {}", componentUid, parentComponent.getUUID()); return Either.right(componentsUtils.getResponseFormat(ActionStatus.ASSET_NOT_FOUND_DURING_CSAR_CREATION, parentComponent.getComponentType().getValue(), parentComponent.getUUID(), componentInstance.getOriginType().getComponentType().getValue(), componentUid)); } - Resource fetchedComponent = resource.left().value(); + Component fetchedComponent = component.left().value(); // 2. fill the artifacts for the current component parent type ComponentTypeArtifacts componentParentArtifacts = collectComponentTypeArtifacts(resourcesTypeArtifacts, 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 d3d4c2d073..54cf4cf096 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 @@ -135,7 +135,7 @@ public class ToscaExportHandler { } public Either exportComponentInterface(Component component, - boolean isAssociatedResourceComponent) { + boolean isAssociatedComponent) { if (null == DEFAULT_IMPORTS) { log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION); return Either.right(ToscaError.GENERAL_ERROR); @@ -145,7 +145,7 @@ public class ToscaExportHandler { toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS)); Map nodeTypes = new HashMap<>(); Either toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, - toscaTemplate, nodeTypes, isAssociatedResourceComponent); + toscaTemplate, nodeTypes, isAssociatedComponent); if (toscaTemplateRes.isRight()) { return Either.right(toscaTemplateRes.right().value()); } @@ -517,7 +517,7 @@ public class ToscaExportHandler { private Either convertInterfaceNodeType(Map componentsCache, Component component, ToscaTemplate toscaNode, Map nodeTypes, - boolean isAssociatedResourceComponent) { + boolean isAssociatedComponent) { log.debug("start convert node type for {}", component.getUniqueId()); ToscaNodeType toscaNodeType = createNodeType(component); @@ -544,7 +544,7 @@ public class ToscaExportHandler { List inputDef = component.getInputs(); Map mergedProperties = new HashMap<>(); - addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedResourceComponent); + addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedComponent); if (inputDef != null) { addInputsToProperties(dataTypes, inputDef, mergedProperties); } @@ -780,7 +780,7 @@ public class ToscaExportHandler { .getUniqueId(), instInterface)); interfaces = InterfacesOperationsToscaUtil - .getInterfacesMap(parentComponent, tmpInterfaces, dataTypes, true, true); + .getInterfacesMap(parentComponent, componentInstance, tmpInterfaces, dataTypes, true, true); } } else { interfaces = diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java index d69e4f67b3..87c4bfa2a6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java @@ -29,6 +29,7 @@ import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Product; @@ -104,7 +105,7 @@ public class InterfacesOperationsToscaUtil { */ public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType, Map dataTypes, - boolean isAssociatedResourceComponent) { + boolean isAssociatedComponent) { if (component instanceof Product) { return; } @@ -113,7 +114,7 @@ public class InterfacesOperationsToscaUtil { return; } Map toscaInterfaceDefinitions = getInterfacesMap(component, dataTypes, - isAssociatedResourceComponent); + isAssociatedComponent); if (MapUtils.isNotEmpty(toscaInterfaceDefinitions)) { nodeType.setInterfaces(toscaInterfaceDefinitions); } @@ -121,14 +122,15 @@ public class InterfacesOperationsToscaUtil { private static Map getInterfacesMap(Component component, Map dataTypes, - boolean isAssociatedResourceComponent) { - return getInterfacesMap(component, component.getInterfaces(), dataTypes, isAssociatedResourceComponent, false); + boolean isAssociatedComponent) { + return getInterfacesMap(component, null, component.getInterfaces(), dataTypes, isAssociatedComponent, false); } public static Map getInterfacesMap(Component component, + ComponentInstance componentInstance, Map interfaces, Map dataTypes, - boolean isAssociatedResourceComponent, + boolean isAssociatedComponent, boolean isServiceProxyInterface) { if(MapUtils.isEmpty(interfaces)) { return null; @@ -147,8 +149,8 @@ public class InterfacesOperationsToscaUtil { ToscaLifecycleOperationDefinition toscaOperation = new ToscaLifecycleOperationDefinition(); if (isArtifactPresent(operationEntry)) { operationArtifactPath = OperationArtifactUtil - .createOperationArtifactPath(component, operationEntry.getValue(), - isAssociatedResourceComponent); + .createOperationArtifactPath(component, componentInstance, operationEntry.getValue(), + isAssociatedComponent); toscaOperation.setImplementation(operationArtifactPath); } toscaOperation.setDescription(operationEntry.getValue().getDescription()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java index 0d772cfcab..b10a8883d2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java @@ -20,6 +20,7 @@ import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -30,6 +31,7 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.Resource; @@ -52,22 +54,31 @@ public class OperationArtifactUtil { * @param operation the specific operation name * @return the full path including file name for operation's artifacts */ - static String createOperationArtifactPath(Component component, OperationDataDefinition operation, - boolean isAssociatedResourceComponent) { + static String createOperationArtifactPath(Component component, ComponentInstance componentInstance, + OperationDataDefinition operation, boolean isAssociatedComponent) { if (!(component instanceof Resource || component instanceof Service)) { return null; } - if (isAssociatedResourceComponent) { - ResourceMetadataDataDefinition resourceMetadataDataDefinition = (ResourceMetadataDataDefinition) - component.getComponentMetadataDefinition().getMetadataDataDefinition(); - return createOperationArtifactPathInService(resourceMetadataDataDefinition.getToscaResourceName() + - "_v" + component.getVersion(), operation); + + if (isAssociatedComponent) { + // Service Proxy is only in Node Template interface + if(componentInstance != null) { + return createOperationArtifactPathInService(componentInstance.getToscaComponentName() + + "_v" + component.getVersion(), operation); + } + // Resource Instance is part of Node Type interface + else { + ResourceMetadataDataDefinition resourceMetadataDataDefinition = + (ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition(); + return createOperationArtifactPathInService(resourceMetadataDataDefinition.getToscaResourceName() + + "_v" + component.getVersion(), operation); + } } - return createOperationArtifactPathInResource(operation); + return createOperationArtifactPathInComponent(operation); } - private static String createOperationArtifactPathInResource(OperationDataDefinition operation) { + private static String createOperationArtifactPathInComponent(OperationDataDefinition operation) { return CsarUtils.ARTIFACTS + File.separator + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator + ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH + File.separator + operation.getImplementation().getArtifactName(); @@ -89,7 +100,7 @@ public class OperationArtifactUtil { } Map interfaceArtifacts = interfaces.values().stream() .flatMap(interfaceDefinition -> interfaceDefinition.getOperationsMap().values().stream()) - .map(Operation::getImplementationArtifact) + .map(Operation::getImplementationArtifact).filter(Objects::nonNull) .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId, artifactDefinition -> artifactDefinition)); if (MapUtils.isNotEmpty(interfaceArtifacts)) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java index 3922bc83a9..7ddf71a04a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java @@ -192,7 +192,7 @@ public class InterfacesOperationsToscaUtilTest { component.setInterfaces(new HashMap<>()); component.getInterfaces().put(interfaceType, addedInterface); Map interfacesMap = InterfacesOperationsToscaUtil - .getInterfacesMap(component, component.getInterfaces(), null, false, true); + .getInterfacesMap(component, null, component.getInterfaces(), null, false, true); ToscaNodeType nodeType = new ToscaNodeType(); nodeType.setInterfaces(interfacesMap); ToscaExportHandler handler = new ToscaExportHandler(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java index 99988224c8..32d0acc640 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java @@ -33,6 +33,7 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentMetadataDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Resource; @@ -58,7 +59,7 @@ public class OperationArtifactUtilTest { final ArtifactDataDefinition implementation = new ArtifactDataDefinition(); implementation.setArtifactName("createBPMN.bpmn"); op.setImplementation(implementation); - final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, op, false); + final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, null, op, false); String expectedArtifactPath = CsarUtils.ARTIFACTS + File.separator + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator + ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH + File.separator + @@ -70,17 +71,15 @@ public class OperationArtifactUtilTest { @Test public void testCorrectPathForOperationArtifactsInService() { - ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition(); - componentMetadataDataDefinition.setToscaResourceName("org.openecomp.resource.vf.TestResource"); - final ComponentMetadataDefinition componentMetadataDefinition = - new ComponentMetadataDefinition(componentMetadataDataDefinition); - Component component = new Resource(componentMetadataDefinition); + Component component = new Resource(); component.setVersion("1.0"); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setToscaComponentName("org.openecomp.resource.vf.TestResource"); final OperationDataDefinition op = new OperationDataDefinition(); final ArtifactDataDefinition implementation = new ArtifactDataDefinition(); implementation.setArtifactName("createBPMN.bpmn"); op.setImplementation(implementation); - final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, op, true); + final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, componentInstance, op, true); String expectedArtifactPath = CsarUtils.ARTIFACTS + File.separator + "org.openecomp.resource.vf.TestResource_v1.0" + File.separator + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator + -- cgit 1.2.3-korg