aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2020-07-30 13:06:42 +0100
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-07 10:06:59 +0000
commit26cba80ddf5e97e1df856ed013ea69c45c5c0976 (patch)
treea88c4b3c6f45254d0fec97b0d148414beb7130fd /catalog-model
parentde805023e2d1c8565efc9a707a82c9fc3903ab38 (diff)
Add 'data_types' during import VFCs
Change-Id: Ib9974bbc1eb88633e7e6834cc7ef8ae95deda539 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3191
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java44
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java102
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java45
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java168
6 files changed, 233 insertions, 129 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
index a54e3264e2..7cdf932ce9 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
@@ -20,13 +20,19 @@
package org.openecomp.sdc.be.model;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
import org.openecomp.sdc.be.dao.utils.CollectionUtils;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import java.util.List;
-import java.util.stream.Collectors;
+@Getter
+@Setter
+@NoArgsConstructor
+@ToString
public class DataTypeDefinition extends DataTypeDataDefinition {
private DataTypeDefinition derivedFrom;
@@ -35,10 +41,6 @@ public class DataTypeDefinition extends DataTypeDataDefinition {
private List<PropertyDefinition> properties;
- public DataTypeDefinition() {
- super();
- }
-
public DataTypeDefinition(DataTypeDataDefinition p) {
super(p);
}
@@ -52,38 +54,8 @@ public class DataTypeDefinition extends DataTypeDataDefinition {
this.setDescription(pd.getDescription());
}
- public List<PropertyConstraint> getConstraints() {
- return constraints;
- }
-
public List<PropertyConstraint> safeGetConstraints() {
return CollectionUtils.safeGetList(constraints);
}
- public void setConstraints(List<PropertyConstraint> constraints) {
- this.constraints = constraints;
- }
-
- public DataTypeDefinition getDerivedFrom() {
- return derivedFrom;
- }
-
- public void setDerivedFrom(DataTypeDefinition derivedFrom) {
- this.derivedFrom = derivedFrom;
- }
-
- public List<PropertyDefinition> getProperties() {
- return properties;
- }
-
- public void setProperties(List<PropertyDefinition> properties) {
- this.properties = properties;
- }
-
- @Override
- public String toString() {
- return super.toString() + " DataTypeDefinition [derivedFrom=" + derivedFrom + ", constraints=" + constraints
- + ", properties=" + properties + "]";
- }
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java
index 7b9fd6fa05..1bf35fbd9f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java
@@ -79,7 +79,6 @@ public class TopologyTemplate extends ToscaElement {
private Map<String, InterfaceDataDefinition> interfaces;
private Map<String, MapInterfaceInstanceDataDefinition> instInterfaces;
private Map<String, MapInterfaceDataDefinition> componentInstInterfaces;
- private Map<String, DataTypeDataDefinition> dataTypes;
private Map<String, CINodeFilterDataDefinition> nodeFilterComponents;
private Map<String, SubstitutionFilterDataDefinition> substitutionFilterDataDefinitionMap;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java
index d6d3347000..ce9e5e0c43 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java
@@ -28,6 +28,7 @@ import lombok.Getter;
import lombok.Setter;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
@@ -56,6 +57,7 @@ public abstract class ToscaElement {
private Map<String, ListCapabilityDataDefinition> capabilities;
private Map<String, MapPropertiesDataDefinition> capabilitiesProperties;
private Map<String, ListRequirementDataDefinition> requirements;
+ private Map<String, DataTypeDataDefinition> dataTypes;
// User
private String creatorUserId;
private String creatorFullName;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
index ba488fe2af..6798af42db 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
@@ -20,11 +20,13 @@
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
+import static org.openecomp.sdc.be.utils.TypeUtils.setField;
+
import java.lang.reflect.Type;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
-import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -43,6 +45,7 @@ import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
@@ -51,6 +54,7 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
@@ -62,6 +66,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
@@ -167,7 +172,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
if (createNextVersionRes.isRight()) {
status = createNextVersionRes.right().value();
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create tosca element vertex {} with version {} on graph. Status is {}. ", previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME),
- previousToscaElement.getMetadataProperty(GraphPropertyEnum.VERSION), status);
+ previousToscaElement.getMetadataProperty(GraphPropertyEnum.VERSION), status);
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
if (result == null) {
@@ -178,7 +183,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.STATE, properties);
if (status != JanusGraphOperationStatus.OK) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.STATE, user.getUniqueId(),
- previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
}
@@ -187,26 +192,26 @@ public abstract class ToscaElementOperation extends BaseOperation {
.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
if (status != JanusGraphOperationStatus.OK) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.LAST_MODIFIER, user.getUniqueId(),
- nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
}
if (result == null) {
Either<GraphVertex, JanusGraphOperationStatus> creatorVertexRes = janusGraphDao.getParentVertex(previousToscaElement,
- EdgeLabelEnum.CREATOR, JsonParseFlagEnum.NoParse);
+ EdgeLabelEnum.CREATOR, JsonParseFlagEnum.NoParse);
if (creatorVertexRes.isRight()) {
status = creatorVertexRes.right().value();
CommonUtility.addRecordToLog(log,
- LogLevelEnum.DEBUG, FAILED_TO_GET_CREATOR_VERTEX_OF_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS,
- EdgeLabelEnum.CREATOR,
- nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ LogLevelEnum.DEBUG, FAILED_TO_GET_CREATOR_VERTEX_OF_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS,
+ EdgeLabelEnum.CREATOR,
+ nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
status = janusGraphDao.createEdge(creatorVertexRes.left().value().getVertex(), createdToscaElementVertex.getVertex(),
- EdgeLabelEnum.CREATOR, new HashMap<>());
+ EdgeLabelEnum.CREATOR, new HashMap<>());
if (status != JanusGraphOperationStatus.OK) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.CREATOR, user.getUniqueId(),
- nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
}
@@ -219,7 +224,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
.createEdge(createdToscaElementVertex.getVertex(), currVertex, EdgeLabelEnum.getEdgeLabelEnum(currEdge.label()), currEdge);
if (status != JanusGraphOperationStatus.OK) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from tosca element vertex {} to vertex with label {} on graph. Status is {}. ", currEdge.label(), createdToscaElementVertex.getUniqueId(),
- currVertex.property(GraphPropertyEnum.LABEL.getProperty()), status);
+ currVertex.property(GraphPropertyEnum.LABEL.getProperty()), status);
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
break;
}
@@ -327,6 +332,10 @@ public abstract class ToscaElementOperation extends BaseOperation {
if (toscaVersion != null) {
nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.TOSCA_DEFINITIONS_VERSION, toscaVersion);
}
+ final Map<String, DataTypeDataDefinition> dataTypes = toscaElement.getDataTypes();
+ if (MapUtils.isNotEmpty(dataTypes)) {
+ nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.DATA_TYPES, dataTypes);
+ }
}
protected StorageOperationStatus assosiateToUsers(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
@@ -738,12 +747,12 @@ public abstract class ToscaElementOperation extends BaseOperation {
Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = janusGraphDao.getChildrenVertices(userV, EdgeLabelEnum.STATE, JsonParseFlagEnum.NoParse);
if (childrenVertecies.isRight() && childrenVertecies.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.STATE, childrenVertecies.right().value());
- return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childrenVertecies.right().value()));
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childrenVertecies.right().value()));
}
// get all resource with current state
if (childrenVertecies.isLeft()) {
- componentsPerUser = fetchComponents(userId, lifecycleStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.STATE);
+ componentsPerUser = fetchComponents(userId, lifecycleStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.STATE);
if (componentsPerUser != null) {
for (T comp : componentsPerUser) {
@@ -932,11 +941,60 @@ public abstract class ToscaElementOperation extends BaseOperation {
if (toscaVersion != null) {
toscaElement.setToscaVersion((String) toscaVersion);
}
+ final Object dataTypes = jsonMetada.get(ToscaTagNamesEnum.DATA_TYPES.getElementName());
+ if (dataTypes != null) {
+ final Map<String, DataTypeDataDefinition> dataTypeDefinitionMap = new HashMap<>();
+
+ final Map<String, Object> toscaAttributes = (Map<String, Object>) dataTypes;
+
+ for (final Entry<String, Object> attributeNameValue : toscaAttributes.entrySet()) {
+ final Object value = attributeNameValue.getValue();
+ final String key = attributeNameValue.getKey();
+ if (value instanceof Map) {
+ final DataTypeDefinition dataTypeDefinition =
+ createDataTypeDefinitionWithName(attributeNameValue);
+ dataTypeDefinitionMap.put(dataTypeDefinition.getName(), dataTypeDefinition);
+ } else {
+ dataTypeDefinitionMap.put(key, createDataType(String.valueOf(value)));
+ }
+ }
+ toscaElement.setDataTypes(dataTypeDefinitionMap);
+ }
}
}
return (T) toscaElement;
}
+ public static DataTypeDefinition createDataType(final String dataTypeName) {
+ final DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName(dataTypeName);
+ return dataType;
+ }
+
+ public static DataTypeDefinition createDataTypeDefinitionWithName(final Entry<String, Object> attributeNameValue) {
+ final Map<String, Object> attributeMap = (Map<String, Object>) attributeNameValue.getValue();
+ final DataTypeDefinition dataType = createDataType(attributeNameValue.getKey());
+ setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, dataType::setDescription);
+ setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DERIVED_FROM_NAME, dataType::setDerivedFromName);
+ // TODO - find the way to set the properties
+// CommonImportManager.setProperties(attributeMap, dataType::setProperties);
+ final Object derivedFrom = attributeMap.get(JsonPresentationFields.DERIVED_FROM.getPresentation());
+ if (derivedFrom instanceof Map) {
+ final Map<String, Object> derivedFromMap = (Map<String, Object>) derivedFrom;
+ final DataTypeDefinition parentDataTypeDataDefinition = new DataTypeDefinition();
+ parentDataTypeDataDefinition
+ .setName((String) derivedFromMap.get(JsonPresentationFields.NAME.getPresentation()));
+ parentDataTypeDataDefinition
+ .setUniqueId((String) derivedFromMap.get(JsonPresentationFields.UNIQUE_ID.getPresentation()));
+ parentDataTypeDataDefinition
+ .setCreationTime((Long) derivedFromMap.get(JsonPresentationFields.CREATION_TIME.getPresentation()));
+ parentDataTypeDataDefinition.setModificationTime(
+ (Long) derivedFromMap.get(JsonPresentationFields.MODIFICATION_TIME.getPresentation()));
+ dataType.setDerivedFrom(parentDataTypeDataDefinition);
+ }
+ return dataType;
+ }
+
private Map<String, AttributeDataDefinition> getAttributesFromComponentV(final GraphVertex componentV) {
final Map<String, Object> jsonMetada = componentV.getMetadataJson();
final Map<String, AttributeDataDefinition> attributeDataDefinitionMap = new HashMap<>();
@@ -1185,7 +1243,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) {
Map<String, Object> getConfig = (Map<String, Object>) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts().entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel()))
- .findAny().get().getValue();
+ .findAny().get().getValue();
artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName"));
}
@@ -1355,7 +1413,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
public Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestComponents(ComponentTypeEnum
- componentType, List<ResourceTypeEnum> excludeTypes, JsonParseFlagEnum parseFlag) {
+ componentType, List<ResourceTypeEnum> excludeTypes, JsonParseFlagEnum parseFlag) {
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> propertiesHasNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
@@ -1413,7 +1471,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
protected Either<List<GraphVertex>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum
- componentType) {
+ componentType) {
// get all components marked for delete
Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
@@ -1437,7 +1495,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
protected JanusGraphOperationStatus setAdditionalInformationFromGraph(GraphVertex componentV, ToscaElement
- toscaElement) {
+ toscaElement) {
Either<Map<String, AdditionalInfoParameterDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ADDITIONAL_INFORMATION);
if (result.isLeft()) {
toscaElement.setAdditionalInformation(result.left().value());
@@ -1451,16 +1509,16 @@ public abstract class ToscaElementOperation extends BaseOperation {
// --------------------------------------------
public abstract <T extends
- ToscaElement> Either<T, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView);
+ ToscaElement> Either<T, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView);
public abstract <T extends
- ToscaElement> Either<T, StorageOperationStatus> getToscaElement(GraphVertex toscaElementVertex, ComponentParametersView componentParametersView);
+ ToscaElement> Either<T, StorageOperationStatus> getToscaElement(GraphVertex toscaElementVertex, ComponentParametersView componentParametersView);
public abstract <T extends
- ToscaElement> Either<T, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex);
+ ToscaElement> Either<T, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex);
public abstract <T extends
- ToscaElement> Either<T, StorageOperationStatus> createToscaElement(ToscaElement toscaElement);
+ ToscaElement> Either<T, StorageOperationStatus> createToscaElement(ToscaElement toscaElement);
protected abstract <T extends ToscaElement> JanusGraphOperationStatus
setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement);
@@ -1478,6 +1536,6 @@ public abstract class ToscaElementOperation extends BaseOperation {
updateDerived(T toscaElementToUpdate, GraphVertex updateElementV);
public abstract <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T
- toscaElementToUpdate, JsonParseFlagEnum flag);
+ toscaElementToUpdate, JsonParseFlagEnum flag);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
index 5ceb7f194c..839ae27a19 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
@@ -260,6 +260,7 @@ public class ModelConverter {
convertCapabilities(nodeType, resource);
convertRequirements(nodeType, resource);
convertInterfaces(nodeType, resource);
+ convertDataTypes(nodeType, resource);
} else {
TopologyTemplate topologyTemplate = (TopologyTemplate) toscaElement;
@@ -813,6 +814,11 @@ public class ModelConverter {
if (toscaVersion != null) {
nodeType.setToscaVersion(toscaVersion);
}
+ final List<DataTypeDefinition> dataTypes = resource.getDataTypes();
+ if (CollectionUtils.isNotEmpty(dataTypes)) {
+ nodeType.setDataTypes(dataTypes.stream()
+ .collect(Collectors.toMap(DataTypeDefinition::getName, dataTypeDefinition -> dataTypeDefinition)));
+ }
convertCommonToscaData(component, nodeType);
convertAdditionalInformation(component, nodeType);
convertArtifacts(resource, nodeType);
@@ -1259,23 +1265,24 @@ public class ModelConverter {
}
}
- private static void convertDataTypes(TopologyTemplate topologyTemplate, Component component) {
- Map<String, DataTypeDataDefinition> dataTypeDataMap = topologyTemplate.getDataTypes();
+ private static void convertDataTypes(final ToscaElement toscaElement, final Component component) {
+ final Map<String, DataTypeDataDefinition> dataTypeDataMap = toscaElement.getDataTypes();
if (MapUtils.isNotEmpty(dataTypeDataMap)) {
- List<DataTypeDefinition> dataTypeMap = dataTypeDataMap.values().stream().map(e -> {
- DataTypeDefinition dataType = new DataTypeDefinition(e);
-
- if(CollectionUtils.isNotEmpty(e.getPropertiesData())) {
- log.debug("#convertDataTypes - propertiesData is not null. {}",
- ReflectionToStringBuilder.toString(e.getPropertiesData()));
- dataType.setProperties(e.getPropertiesData().stream()
+ final List<DataTypeDefinition> dataTypeDefinitionList =
+ dataTypeDataMap.values().stream().map(dataTypeDataDefinition -> {
+ final DataTypeDefinition dataTypeDefinition = new DataTypeDefinition(dataTypeDataDefinition);
+
+ if (CollectionUtils.isNotEmpty(dataTypeDataDefinition.getPropertiesData())) {
+ log.debug("#convertDataTypes - propertiesData is not null. {}",
+ ReflectionToStringBuilder.toString(dataTypeDataDefinition.getPropertiesData()));
+ dataTypeDefinition.setProperties(dataTypeDataDefinition.getPropertiesData().stream()
.map(PropertyDefinition::new).collect(Collectors.toList()));
- } else {
- log.debug("#convertDataTypes - propertiesData is null. ignore.");
- }
- return dataType;
- }).collect(Collectors.toList());
- component.setDataTypes(dataTypeMap);
+ } else {
+ log.debug("#convertDataTypes - propertiesData is null. ignore.");
+ }
+ return dataTypeDefinition;
+ }).collect(Collectors.toList());
+ component.setDataTypes(dataTypeDefinitionList);
}
}
@@ -1342,11 +1349,13 @@ public class ModelConverter {
toscaElement.setMetadataValue(JsonPresentationFields.TAGS, component.getTags());
toscaElement.setMetadataValue(JsonPresentationFields.INVARIANT_UUID, component.getInvariantUUID());
toscaElement.setMetadataValue(JsonPresentationFields.CONTACT_ID, component.getContactId());
+ final List<DataTypeDefinition> dataTypes = component.getDataTypes();
+ if (CollectionUtils.isNotEmpty(dataTypes)) {
+ toscaElement.setDataTypes(dataTypes.stream()
+ .collect(Collectors.toMap(DataTypeDefinition::getName, dataTypeDefinition -> dataTypeDefinition)));
+ }
}
-
-
-
private static void setComponentInstancesToComponent(TopologyTemplate topologyTemplate, Component component) {
List<ComponentInstance> componentInstances = new ArrayList<>();
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java
index 9b6b6f6e1b..12f4628a1a 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
import fj.data.Either;
+import java.util.Map.Entry;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -31,20 +32,25 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.ModelTestBase;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.EntryData;
+import org.openecomp.sdc.be.utils.TypeUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.*;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
@@ -53,7 +59,7 @@ import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
-public class ToscaElementOperationTest extends ModelTestBase{
+public class ToscaElementOperationTest extends ModelTestBase {
private List<GraphVertex> allVertices = new ArrayList<>();
private boolean isInitialized = false;
@@ -65,7 +71,7 @@ public class ToscaElementOperationTest extends ModelTestBase{
private JanusGraphDao janusGraphDao;
@BeforeClass
- public static void initTest(){
+ public static void initTest() {
ModelTestBase.init();
}
@@ -83,11 +89,11 @@ public class ToscaElementOperationTest extends ModelTestBase{
}
}
-
@Test
public void testGetAllHighestResourcesNoFilter() {
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE, null, true);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.RESOURCE, null, true);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -99,13 +105,11 @@ public class ToscaElementOperationTest extends ModelTestBase{
}, null);
assertEquals(highestResources.stream().count(), highestResourcesExpectedCount);
}
-
-
-
@Test
public void testGetAllResourcesCertifiedNoFilter() {
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE, null, false);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.RESOURCE, null, false);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -140,7 +144,8 @@ public class ToscaElementOperationTest extends ModelTestBase{
assertTrue(genericTestGetResourcesWithExcludeList(excludeList));
// exclude CP & VL & VF & VFC
- excludeList = Arrays.asList(ResourceTypeEnum.VL, ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC);
+ excludeList = Arrays
+ .asList(ResourceTypeEnum.VL, ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC);
assertTrue(genericTestGetResourcesWithExcludeList(excludeList));
}
@@ -155,13 +160,15 @@ public class ToscaElementOperationTest extends ModelTestBase{
assertTrue(genericTestGetCertifiedResourcesWithExcludeList(excludeList));
// exclude CP & VL & VF & VFC
- excludeList = Arrays.asList(ResourceTypeEnum.VL, ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC);
+ excludeList = Arrays
+ .asList(ResourceTypeEnum.VL, ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC);
assertTrue(genericTestGetCertifiedResourcesWithExcludeList(excludeList));
}
@Test
public void testGetAllHighestServicesNoFilter() {
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.SERVICE, null, true);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.SERVICE, null, true);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -176,7 +183,8 @@ public class ToscaElementOperationTest extends ModelTestBase{
@Test
public void testGetAllCertifiedServicesNoFilter() {
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.SERVICE, null, false);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.SERVICE, null, false);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -202,7 +210,8 @@ public class ToscaElementOperationTest extends ModelTestBase{
@Test
public void testGetServicesExcludeList() {
List<ResourceTypeEnum> excludeList = Arrays.asList(ResourceTypeEnum.VF, ResourceTypeEnum.VFCMT);
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.SERVICE, excludeList, true);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.SERVICE, excludeList, true);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -218,7 +227,8 @@ public class ToscaElementOperationTest extends ModelTestBase{
@Test
public void testGetCertifiedServicesExcludeList() {
List<ResourceTypeEnum> excludeList = Arrays.asList(ResourceTypeEnum.VL);
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.SERVICE, excludeList, false);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.SERVICE, excludeList, false);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -253,8 +263,54 @@ public class ToscaElementOperationTest extends ModelTestBase{
assertEquals(null, result);
}
+ @Test
+ public void testCreateDataType() {
+ final String expected = "newDataType";
+ final DataTypeDefinition result = ToscaElementOperation.createDataType(expected);
+ assertNotNull(result);
+ assertEquals(expected, result.getName());
+ }
+
+ @Test
+ public void testCreateDataTypeDefinitionWithName() {
+ final String expected = "newDataType";
+ final String description = "DESCRIPTION";
+ final String derivedFromName = "DERIVED_FROM_NAME";
+ final String uniqueId = "UNIQUE_ID";
+
+ final Map<String, Object> attributeMap = new HashMap<>();
+ attributeMap.put(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName(), description);
+ attributeMap.put(TypeUtils.ToscaTagNamesEnum.DERIVED_FROM_NAME.getElementName(), derivedFromName);
+
+ final Map<String, Object> derivedFromMap = new HashMap<>();
+ derivedFromMap.put(JsonPresentationFields.NAME.getPresentation(), derivedFromName);
+ derivedFromMap.put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
+ final long creationTime = System.currentTimeMillis();
+ derivedFromMap.put(JsonPresentationFields.CREATION_TIME.getPresentation(), creationTime);
+ final long modificationTime = System.currentTimeMillis();
+ derivedFromMap.put(JsonPresentationFields.MODIFICATION_TIME.getPresentation(), modificationTime);
+
+ attributeMap.put(JsonPresentationFields.DERIVED_FROM.getPresentation(), derivedFromMap);
+
+ final Entry<String, Object> attributeNameValue = new EntryData<>(expected, attributeMap);
+ final DataTypeDefinition result = ToscaElementOperation.createDataTypeDefinitionWithName(attributeNameValue);
+
+ assertNotNull(result);
+ assertEquals(derivedFromName, result.getDerivedFromName());
+ assertEquals(description, result.getDescription());
+
+ final DataTypeDefinition resultDerivedFrom = result.getDerivedFrom();
+ assertNotNull(resultDerivedFrom);
+ assertEquals(derivedFromName, resultDerivedFrom.getName());
+ assertEquals(uniqueId, resultDerivedFrom.getUniqueId());
+ assertEquals(creationTime, resultDerivedFrom.getCreationTime().longValue());
+ assertEquals(modificationTime, resultDerivedFrom.getModificationTime().longValue());
+
+ }
+
private boolean genericTestGetResourcesWithExcludeList(List<ResourceTypeEnum> excludeList) {
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE,excludeList, true);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.RESOURCE, excludeList, true);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -272,7 +328,8 @@ public class ToscaElementOperationTest extends ModelTestBase{
}
private boolean genericTestGetCertifiedResourcesWithExcludeList(List<ResourceTypeEnum> excludeList) {
- Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE, excludeList, false);
+ Either<List<ToscaElement>, StorageOperationStatus> highestResourcesRes = toscaElementOperation
+ .getElementCatalogData(ComponentTypeEnum.RESOURCE, excludeList, false);
assertTrue(highestResourcesRes.isLeft());
List<ToscaElement> highestResources = highestResourcesRes.left().value();
// calculate expected count value
@@ -313,34 +370,41 @@ public class ToscaElementOperationTest extends ModelTestBase{
{
put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- }
+ }
};
// add vertices with higestVersion = true
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, highstVerticesProps, ResourceTypeEnum.VF));
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, highstVerticesProps, ResourceTypeEnum.VFC));
- allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, highstVerticesProps, ResourceTypeEnum.VFCMT));
+ allVertices
+ .add(GraphTestUtils.createResourceVertex(janusGraphDao, highstVerticesProps, ResourceTypeEnum.VFCMT));
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, highstVerticesProps, ResourceTypeEnum.VL));
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, highstVerticesProps, ResourceTypeEnum.CP));
allVertices.add(GraphTestUtils.createServiceVertex(janusGraphDao, highstVerticesProps));
// add vertices with non-additional properties
- for (int i=0 ; i<2 ; i++) {
+ for (int i = 0; i < 2; i++) {
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, new HashMap<>(), ResourceTypeEnum.VF));
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, new HashMap<>(), ResourceTypeEnum.VFC));
- allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, new HashMap<>(), ResourceTypeEnum.VFCMT));
+ allVertices
+ .add(GraphTestUtils.createResourceVertex(janusGraphDao, new HashMap<>(), ResourceTypeEnum.VFCMT));
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, new HashMap<>(), ResourceTypeEnum.VL));
allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, new HashMap<>(), ResourceTypeEnum.CP));
allVertices.add(GraphTestUtils.createServiceVertex(janusGraphDao, new HashMap<>()));
}
// add certified vertices
- for (int i=0; i<3; i++) {
- allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VF));
- allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VFC));
- allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VFCMT));
- allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VL));
- allVertices.add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.CP));
+ for (int i = 0; i < 3; i++) {
+ allVertices
+ .add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VF));
+ allVertices
+ .add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VFC));
+ allVertices.add(
+ GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VFCMT));
+ allVertices
+ .add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.VL));
+ allVertices
+ .add(GraphTestUtils.createResourceVertex(janusGraphDao, certifiedVerticesProps, ResourceTypeEnum.CP));
allVertices.add(GraphTestUtils.createServiceVertex(janusGraphDao, certifiedVerticesProps));
}
//allVertices.stream().forEach( v -> System.out.println("type: "+v.getMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE)));
@@ -348,36 +412,36 @@ public class ToscaElementOperationTest extends ModelTestBase{
//System.out.println("graph is: " + result);
}
- private long calculateCount(HashMap<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> doesntHaveProps){
+ private long calculateCount(HashMap<GraphPropertyEnum, Object> hasProps,
+ Map<GraphPropertyEnum, Object> doesntHaveProps) {
return allVertices.stream().
- filter(v -> {
- Map<GraphPropertyEnum, Object> vertexProps = v.getMetadataProperties();
- if (hasProps != null) {
- for (Map.Entry<GraphPropertyEnum, Object> prop: hasProps.entrySet()){
- Object value = vertexProps.get(prop.getKey());
- if ( value == null || !value.equals(prop.getValue())) {
- return false;
- }
+ filter(v -> {
+ Map<GraphPropertyEnum, Object> vertexProps = v.getMetadataProperties();
+ if (hasProps != null) {
+ for (Map.Entry<GraphPropertyEnum, Object> prop : hasProps.entrySet()) {
+ Object value = vertexProps.get(prop.getKey());
+ if (value == null || !value.equals(prop.getValue())) {
+ return false;
}
}
-
- if (doesntHaveProps != null) {
- for (Map.Entry<GraphPropertyEnum, Object> prop : doesntHaveProps.entrySet()) {
- Object value = vertexProps.get(prop.getKey());
- Object propValue = prop.getValue();
- if ( value != null && propValue != null && propValue instanceof List ) {
- for (ResourceTypeEnum propVal : (List<ResourceTypeEnum>)propValue) {
- if (propVal.name().equals(value)) {
- return false;
- }
+ }
+
+ if (doesntHaveProps != null) {
+ for (Map.Entry<GraphPropertyEnum, Object> prop : doesntHaveProps.entrySet()) {
+ Object value = vertexProps.get(prop.getKey());
+ Object propValue = prop.getValue();
+ if (value != null && propValue != null && propValue instanceof List) {
+ for (ResourceTypeEnum propVal : (List<ResourceTypeEnum>) propValue) {
+ if (propVal.name().equals(value)) {
+ return false;
}
}
- else if (value != null && value.equals(propValue)){
- return false;
- }
+ } else if (value != null && value.equals(propValue)) {
+ return false;
}
}
- return true;
- }).count();
+ }
+ return true;
+ }).count();
}
}