diff options
author | ojasdubey <ojas.dubey@amdocs.com> | 2018-10-17 15:10:48 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-10-21 07:25:04 +0000 |
commit | 5cc93c4c9e4750a4630afa6f4509438ca4925f51 (patch) | |
tree | cdd1c6b89b3a2e39a52be6e391e03fb5723c773a /catalog-be/src/main | |
parent | c4e49e8e97cff5a051415448650d80ecd3207c10 (diff) |
Bugfix - VF workflow artifacts in service csar
1. Added implementation for packing VF workflow
artifacts to service csar
2. Updated the paths of workflow artifacts in
VF csar as agreed
3. Updated the implementation to pack the artifact
only once based on the artifact name
Change-Id: I7ab22153e5a4877e6b727e0eb28831ac4e60894f
Issue-ID: SDC-1845
Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'catalog-be/src/main')
6 files changed, 121 insertions, 98 deletions
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 4ef2e06205..ebdbcea535 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 @@ -3145,9 +3145,11 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { Operation operation = optionalOperation.get(); ArtifactDefinition implementationArtifact = operation.getImplementationArtifact(); - implementationArtifact.setArtifactName(operation.getName() + "_" + artifactInfo.getArtifactName()); + implementationArtifact.setArtifactName(artifactInfo.getArtifactName()); implementationArtifact.setDescription(artifactInfo.getDescription()); implementationArtifact.setArtifactType(artifactInfo.getArtifactType()); + implementationArtifact.setArtifactLabel(artifactInfo.getUniqueId()); + implementationArtifact.setEsId(artifactInfo.getEsId()); operation.setImplementation(implementationArtifact); gotInterface.setOperationsMap(operationsMap); Either<InterfaceDefinition, StorageOperationStatus> interfaceDefinitionStorageOperationStatusEither = diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index 6f822fd7e3..26e256fb00 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -259,8 +259,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { String artifactUUID = UUID.randomUUID().toString(); artifactDefinition.setArtifactUUID(artifactUUID); artifactDefinition.setUniqueId(artifactUUID); - artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType()); - artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE); + artifactDefinition.setArtifactType(ArtifactTypeEnum.WORKFLOW.getType()); + artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); operation.setUniqueId(UUID.randomUUID().toString()); operation.setImplementation(artifactDefinition); } 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 066b657068..bea65cf187 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 @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.tosca; import fj.data.Either; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.collections.MapUtils; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.lang.WordUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -35,7 +36,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; 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.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.*; @@ -94,8 +94,6 @@ public class CsarUtils { public static final String RESOURCES_PATH = "Resources/"; public static final String INFORMATIONAL_ARTIFACTS = "Informational/"; public static final String DEPLOYMENT_ARTIFACTS = "Deployment/"; - public static final String WORKFLOW_ARTIFACT_DIR = "Workflows" + File.separator + "BPMN" + File.separator; - public static final String DEPLOYMENT_ARTIFACTS_DIR = "Deployment" + File.separator; public static final String DEFINITIONS_PATH = "Definitions/"; private static final String CSAR_META_VERSION = "1.0"; @@ -249,7 +247,7 @@ public class CsarUtils { // US798487 - Abstraction of complex types if (!ModelConverter.isAtomicComponent(component)) { log.debug("Component {} is complex - generating abstract type for it..", component.getName()); - writeComponentInterface(component, zip, fileName); + writeComponentInterface(component, zip, fileName, false); } if (dependencies == null) { @@ -308,7 +306,7 @@ public class CsarUtils { // add component interface to zip if (!ModelConverter.isAtomicComponent(innerComponent)) { - writeComponentInterface(innerComponent, zip, icFileName); + writeComponentInterface(innerComponent, zip, icFileName, true); } } } @@ -433,10 +431,10 @@ public class CsarUtils { } private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(Component component, ZipOutputStream zip, - String fileName) { + String fileName, boolean isAssociatedResourceComponent) { try { Either<ToscaRepresentation, ToscaError> componentInterface = toscaExportUtils - .exportComponentInterface(component); + .exportComponentInterface(component, isAssociatedResourceComponent); ToscaRepresentation componentInterfaceYaml = componentInterface.left().value(); String mainYaml = componentInterfaceYaml.getMainYaml(); String interfaceFileName = DEFINITIONS_PATH + ToscaExportHandler.getInterfaceFilename(fileName); @@ -858,74 +856,9 @@ public class CsarUtils { return Either.right(writeComponentArtifactsToSpecifiedPath.right().value()); } } - writeComponentArtifactsToSpecifiedPath = writeOperationsArtifactsToCsar(mainComponent, zipstream); - - if (writeComponentArtifactsToSpecifiedPath.isRight()) { - return Either.right(writeComponentArtifactsToSpecifiedPath.right().value()); - } return Either.left(zipstream); } - private Either<ZipOutputStream, ResponseFormat> writeOperationsArtifactsToCsar(Component component, - ZipOutputStream zipstream) { - if (component instanceof Service) { - return Either.left(zipstream); - } - if (Objects.isNull(((Resource) component).getInterfaces())) { - log.debug("Component Name {}- no interfaces found", component.getNormalizedName()); - return Either.left(zipstream); - } - final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces(); - - for (Map.Entry<String, InterfaceDefinition> interfaceEntry : interfaces.entrySet()) { - for (OperationDataDefinition operation : interfaceEntry.getValue().getOperations().values()) { - try { - if (Objects.isNull(operation.getImplementation())) { - log.debug( - "Component Name {}, Interface Id {}, Operation Name {} - no Operation Implementation found", - component.getNormalizedName(), interfaceEntry.getValue().getUniqueId(), - operation.getName()); - continue; - } - if (Objects.isNull(operation.getImplementation().getArtifactName())) { - log.debug("Component Name {}, Interface Id {}, Operation Name {} - no artifact found", - component.getNormalizedName(), interfaceEntry.getValue().getUniqueId(), - operation.getName()); - continue; - } - - final String artifactUUID = operation.getImplementation().getArtifactUUID(); - - final Either<byte[], ActionStatus> artifactFromCassandra = getFromCassandra(artifactUUID); - final String artifactName = operation.getImplementation().getArtifactName(); - if (artifactFromCassandra.isRight()) { - log.error("ArtifactName {}, 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)); - } - - final byte[] payloadData = artifactFromCassandra.left().value(); - zipstream.putNextEntry(new ZipEntry( - OperationArtifactUtil.createOperationArtifactPath(component.getNormalizedName(), - interfaceEntry.getValue().getToscaResourceName(), operation))); - zipstream.write(payloadData); - - } catch (IOException | NullPointerException 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())); - } - } - } - return Either.left(zipstream); - - } - private Either<ZipOutputStream, ResponseFormat> writeComponentArtifactsToSpecifiedPath(Component mainComponent, ComponentArtifacts componentArtifacts, ZipOutputStream zipstream, String currentPath, boolean isInCertificationRequest) throws IOException { @@ -958,14 +891,17 @@ public class CsarUtils { Set<ArtifactGroupTypeEnum> groupTypeEnumKeySet = artifactsInfo.keySet(); for (ArtifactGroupTypeEnum artifactGroupTypeEnum : groupTypeEnumKeySet) { - String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + "/"; + String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + File.separator; Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypesMap = artifactsInfo.get(artifactGroupTypeEnum); Set<ArtifactTypeEnum> artifactTypeEnumKeySet = artifactTypesMap.keySet(); for (ArtifactTypeEnum artifactTypeEnum : artifactTypeEnumKeySet) { List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactTypeEnum); - String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + "/"; + String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + File.separator; + if (artifactTypeEnum == ArtifactTypeEnum.WORKFLOW) { + artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator; + } Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition = writeArtifactDefinition(mainComponent, zip, artifactDefinitionList, artifactTypeFolder, isInCertificationRequest); @@ -1046,7 +982,15 @@ public class CsarUtils { public void addArtifactsToGroup(ArtifactGroupTypeEnum artifactGroup, Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsDefinition) { - artifactsInfoField.put(artifactGroup, artifactsDefinition); + if (artifactsInfoField.get(artifactGroup) == null) { + artifactsInfoField.put(artifactGroup, artifactsDefinition); + } else { + Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypeEnumListMap = + artifactsInfoField.get(artifactGroup); + artifactTypeEnumListMap.putAll(artifactsDefinition); + artifactsInfoField.put(artifactGroup, artifactTypeEnumListMap); + } + } public boolean isEmpty() { @@ -1356,6 +1300,10 @@ public class CsarUtils { Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts(); Map<ArtifactTypeEnum, List<ArtifactDefinition>> deploymentArtifactsByType = collectGroupArtifacts( deploymentArtifacts); + Map<String, ArtifactDefinition> interfaceOperationArtifacts = + OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component); + Map<ArtifactTypeEnum, List<ArtifactDefinition>> interfaceOperationArtifactsByType = collectGroupArtifacts( + interfaceOperationArtifacts); ArtifactsInfo artifactsInfo = new ArtifactsInfo(); if (!informationalArtifactsByType.isEmpty()) { artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.INFORMATIONAL, informationalArtifactsByType); @@ -1363,6 +1311,10 @@ public class CsarUtils { if (!deploymentArtifactsByType.isEmpty()) { artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, deploymentArtifactsByType); } + //Add component interface operation artifacts + if(MapUtils.isNotEmpty(interfaceOperationArtifacts)) { + artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, interfaceOperationArtifactsByType); + } return artifactsInfo; } 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 41b29e3517..69c4cec42b 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 @@ -151,7 +151,8 @@ public class ToscaExportHandler { return Either.left(toscaRepresentation); } - public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component) { + public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component, + boolean isAssociatedResourceComponent) { if (null == DEFAULT_IMPORTS) { log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION); return Either.right(ToscaError.GENERAL_ERROR); @@ -160,8 +161,8 @@ public class ToscaExportHandler { ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION); toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS)); Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); - Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, toscaTemplate, - nodeTypes); + Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, + toscaTemplate, nodeTypes, isAssociatedResourceComponent); if (toscaTemplateRes.isRight()) { return Either.right(toscaTemplateRes.right().value()); } @@ -546,8 +547,10 @@ public class ToscaExportHandler { return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes); } - private Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode, - Map<String, ToscaNodeType> nodeTypes) { + private Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache, + Component component, ToscaTemplate toscaNode, + Map<String, ToscaNodeType> nodeTypes, + boolean isAssociatedResourceComponent) { log.debug("start convert node type for {}", component.getUniqueId()); ToscaNodeType toscaNodeType = createNodeType(component); toscaNode.setInterface_types(addInterfaceTypeElement(component)); @@ -561,7 +564,7 @@ public class ToscaExportHandler { List<InputDefinition> inputDef = component.getInputs(); Map<String, ToscaProperty> inputs = new HashMap<>(); - addInterfaceDefinitionElement(component, toscaNodeType); + addInterfaceDefinitionElement(component, toscaNodeType, isAssociatedResourceComponent); if (inputDef != null) { inputDef.forEach(i -> { ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false); 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 70fd2575f0..c3628df17b 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 @@ -95,7 +95,8 @@ public class InterfacesOperationsToscaUtil { * @param component to work on * @param nodeType to which the interfaces element will be added */ - public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType) { + public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType, + boolean isAssociatedResourceComponent) { if (component instanceof Product) { return; } @@ -116,9 +117,8 @@ public class InterfacesOperationsToscaUtil { ToscaLifecycleOperationDefinition toscaOperation = new ToscaLifecycleOperationDefinition(); if (isArtifactPresent(operationEntry)) { operationArtifactPath = OperationArtifactUtil - .createOperationArtifactPath(component.getNormalizedName(), - interfaceDefinition.getToscaResourceName(), - operationEntry.getValue()); + .createOperationArtifactPath(component, operationEntry.getValue(), + isAssociatedResourceComponent); 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 5d0b4466c6..b70ae90f7c 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 @@ -16,28 +16,94 @@ package org.openecomp.sdc.be.tosca.utils; +import java.io.File; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.WordUtils; +import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; +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.InterfaceDefinition; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.tosca.CsarUtils; - -import java.io.File; +import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; public class OperationArtifactUtil { + public static final String BPMN_ARTIFACT_PATH = "BPMN"; + + private OperationArtifactUtil() { + //Hiding implicit public constructor + } /** * This method assumes that operation.getImplementation() is not NULL ( it should be verified by the caller method) * - * @param componentName component's normalized name - * @param interfaceType the specific interface type * @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) { + if (!(component instanceof Resource)) { + return null; + } + if (isAssociatedResourceComponent) { + ResourceMetadataDataDefinition resourceMetadataDataDefinition = (ResourceMetadataDataDefinition) + component.getComponentMetadataDefinition().getMetadataDataDefinition(); + return createOperationArtifactPathInService(resourceMetadataDataDefinition.getToscaResourceName() + + "_v" + component.getVersion(), operation); + } + return createOperationArtifactPathInResource(operation); + } + + + private static String createOperationArtifactPathInResource(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(); + } + + private static String createOperationArtifactPathInService(String toscaComponentName, + OperationDataDefinition operation) { + return CsarUtils.ARTIFACTS + File.separator + toscaComponentName + File.separator + + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator + + ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH + File.separator + + operation.getImplementation().getArtifactName(); + } + + public static Map<String, ArtifactDefinition> getDistinctInterfaceOperationArtifactsByName(Component originComponent) { + Map<String, ArtifactDefinition> distinctInterfaceArtifactsByName = new HashMap<>(); + Map<String, InterfaceDefinition> interfaces = originComponent.getInterfaces(); + if (MapUtils.isEmpty(interfaces)) { + return distinctInterfaceArtifactsByName; + } + Map<String, ArtifactDefinition> interfaceArtifacts = interfaces.values().stream() + .flatMap(interfaceDefinition -> interfaceDefinition.getOperationsMap().values().stream()) + .map(Operation::getImplementationArtifact) + .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId, + artifactDefinition -> artifactDefinition)); + if (MapUtils.isNotEmpty(interfaceArtifacts)) { + Set<String> artifactNameSet = new HashSet<>(); + for (Map.Entry<String, ArtifactDefinition> interfaceArtifactEntry : interfaceArtifacts.entrySet()) { + String artifactName = interfaceArtifactEntry.getValue().getArtifactName(); + if (artifactNameSet.contains(artifactName)) { + continue; + } + distinctInterfaceArtifactsByName.put(interfaceArtifactEntry.getKey(), + interfaceArtifactEntry.getValue()); + artifactNameSet.add(artifactName); + } - public static String createOperationArtifactPath(String componentName, String interfaceType, - OperationDataDefinition operation) { - return CsarUtils.ARTIFACTS + File.separator + componentName + File.separator + interfaceType + File.separator - + CsarUtils.DEPLOYMENT_ARTIFACTS_DIR + CsarUtils.WORKFLOW_ARTIFACT_DIR + operation - .getImplementation() - .getArtifactName(); + } + return distinctInterfaceArtifactsByName; } } |