summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2020-02-12 14:59:19 +0000
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-03-24 14:19:28 +0000
commite224d76e1558a31818badc60af59dc02e0fb268a (patch)
treee928a5d2b46dd2519c70fe95be7f165246740914 /catalog-be/src/main/java
parent97930ffc459281aa11c8e3fb1ffacafdc3d161be (diff)
Import of VFC will maintain interface implementations
Issue-ID: SDC-2772 Signed-off-by: MichaelMorris <michael.morris@est.tech> Change-Id: Id387ebd67ff0b136d532df70fe8b2b8760edc433
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java88
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java17
4 files changed, 103 insertions, 10 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index d557de1dec..687b18ecf6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -169,6 +169,7 @@ public final class ImportUtils {
public static final String USER_DEFINED_RESOURCE_NAMESPACE_PREFIX = "org.openecomp.resource.";
public static final String UI_JSON_PAYLOAD_NAME = "payloadName";
public static final String CVFC_DESCRIPTION = "Complex node type that is used as nested type in VF";
+ public static final String ESCAPED_DOUBLE_QUOTE = "\"";
private Constants() {}
}
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 7e26cb329f..6b0b6bf81c 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
@@ -39,6 +39,8 @@ import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -92,11 +94,14 @@ import java.util.stream.Collectors;
@Component("resourceImportManager")
public class ResourceImportManager {
static final Pattern PROPERTY_NAME_PATTERN_IGNORE_LENGTH = Pattern.compile("[\\w\\-\\_\\d\\:]+");
+ private static final String IMPLEMENTATION = "implementation";
private ServletContext servletContext;
private AuditingManager auditingManager;
private ResourceBusinessLogic resourceBusinessLogic;
+ private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+
private IGraphLockOperation graphLockOperation;
protected ToscaOperationFacade toscaOperationFacade;
@@ -310,7 +315,7 @@ public class ResourceImportManager {
while (interfacesNameValue.hasNext()) {
Entry<String, Object> interfaceNameValue = interfacesNameValue.next();
Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue
- .getValue());
+ .getValue(), resource);
if (eitherInterface.isRight()) {
log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), resource.getName());
}
@@ -325,7 +330,7 @@ public class ResourceImportManager {
}
}
- private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(Object interfaceJson) {
+ private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(Object interfaceJson, Resource resource) {
InterfaceDefinition interf = new InterfaceDefinition();
Either<InterfaceDefinition, ResultStatusEnum> result = Either.left(interf);
@@ -334,12 +339,31 @@ public class ResourceImportManager {
String requirementJsonString = (String) interfaceJson;
interf.setType(requirementJsonString);
}
- else if (interfaceJson instanceof Map) {
+ else if (interfaceJson instanceof Map && ResourceTypeEnum.VFC.equals(resource.getResourceType())) {
Map<String, Object> requirementJsonMap = (Map<String, Object>) interfaceJson;
- if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) {
- String type = (String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName());
- interf.setType(type);
- interf.setUniqueId(type.toLowerCase());
+ Map<String, OperationDataDefinition> operations = new HashMap<>();
+
+ for (final Entry<String, Object> entry : requirementJsonMap.entrySet()) {
+ if (entryIsInterfaceType(entry)) {
+ String type = (String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName());
+ interf.setType(type);
+ interf.setUniqueId(type.toLowerCase());
+ } else if (entryContainsImplementationForAKnownOperation(entry, interf.getType())){
+
+ OperationDataDefinition operation = new OperationDataDefinition();
+ operation.setName(entry.getKey());
+
+ ArtifactDataDefinition implementation = new ArtifactDataDefinition();
+ // Adding the artifact name in quotes to indicate that this is a literal value, rather than a reference to
+ // an SDC artifact
+ implementation.setArtifactName(Constants.ESCAPED_DOUBLE_QUOTE + ((Map<String, String>)entry.getValue()).get(IMPLEMENTATION) + Constants.ESCAPED_DOUBLE_QUOTE);
+ operation.setImplementation(implementation);
+
+ operations.put(entry.getKey(), operation);
+ }
+ }
+ if (!operations.isEmpty()) {
+ interf.setOperations(operations);
}
}
else {
@@ -355,6 +379,51 @@ public class ResourceImportManager {
return result;
}
+
+ private boolean entryIsInterfaceType(final Entry<String, Object> entry) {
+ if(entry.getKey().equals(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) {
+ if (entry.getValue() instanceof String) {
+ return true;
+ }
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML);
+ }
+ return false;
+ }
+
+ private boolean entryContainsImplementationForAKnownOperation(final Entry<String, Object> entry, final String interfaceType) {
+ if (entry.getValue() instanceof Map && ((Map<?, ?>)entry.getValue()).containsKey(IMPLEMENTATION)) {
+ if (isAKnownOperation(interfaceType, entry.getKey())){
+ return true;
+ }
+ throw new ByActionStatusComponentException(ActionStatus.INTERFACE_OPERATION_NOT_FOUND);
+ }
+ return false;
+ }
+
+ private boolean isAKnownOperation(String interfaceType, String operation) {
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes = interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
+ if (interfaceLifecycleTypes.isRight() || interfaceLifecycleTypes.left().value() == null) {
+ return false;
+ }
+
+ for (Entry<String, InterfaceDefinition> interfaceLifecycleType : interfaceLifecycleTypes.left().value().entrySet()) {
+ if (interfaceTypeAndOperationMatches(interfaceLifecycleType, interfaceType, operation)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean interfaceTypeAndOperationMatches(Entry<String, InterfaceDefinition> interfaceLifecycleType, String interfaceType, String operation) {
+ if (interfaceLifecycleType.getKey().equalsIgnoreCase(interfaceType) && interfaceLifecycleType.getValue().getOperations() != null) {
+ for (String interfaceLifecycleTypeOperation : interfaceLifecycleType.getValue().getOperations().keySet()) {
+ if (interfaceLifecycleTypeOperation != null && interfaceLifecycleTypeOperation.equalsIgnoreCase(operation)){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
private void setRequirements(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(toscaJson, TypeUtils.ToscaTagNamesEnum.REQUIREMENTS);
@@ -898,6 +967,11 @@ public class ResourceImportManager {
public void setResourceBusinessLogic(ResourceBusinessLogic resourceBusinessLogic) {
this.resourceBusinessLogic = resourceBusinessLogic;
}
+
+ @Autowired
+ public void setInterfaceOperationBusinessLogic(InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) {
+ this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
+ }
public IGraphLockOperation getGraphLockOperation() {
return graphLockOperation;
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 e50523854d..604715d05d 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
@@ -51,6 +51,7 @@ import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -1004,6 +1005,12 @@ public class CsarUtils {
operation.getName());
return true;
}
+ if (operation.getImplementation().getArtifactName().startsWith(Constants.ESCAPED_DOUBLE_QUOTE) && operation.getImplementation().getArtifactName().endsWith(Constants.ESCAPED_DOUBLE_QUOTE)) {
+ log.debug("Component Name {}, Interface Id {}, Operation Name {} - artifact name is a literal value rather than an SDC artifact",
+ component.getNormalizedName(), interfaceEntry.getValue().getUniqueId(),
+ operation.getName());
+ return true;
+ }
return false;
}
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 a58d035c3d..bab82ada1b 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
@@ -18,6 +18,7 @@ package org.openecomp.sdc.be.tosca.utils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.WordUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
@@ -32,6 +33,7 @@ import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
@@ -79,9 +81,18 @@ public class OperationArtifactUtil {
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();
+ if (artifactNameIsALiteralValue(operation.getImplementation().getArtifactName())) {
+ final String implementationArtifactName = operation.getImplementation().getArtifactName();
+ return implementationArtifactName.substring(1, implementationArtifactName.length()-1);
+ } else {
+ 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 boolean artifactNameIsALiteralValue(final String artifactName) {
+ return artifactName.startsWith(Constants.ESCAPED_DOUBLE_QUOTE) && artifactName.endsWith(Constants.ESCAPED_DOUBLE_QUOTE);
}
private static String createOperationArtifactPathInService(String toscaComponentName,