aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java20
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/ToscaElement.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java5
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java28
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java132
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java5
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java1
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java4
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java2
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/JsonObjectTest.java34
11 files changed, 197 insertions, 43 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
index dee4088d04..1b5038efde 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
@@ -104,6 +104,14 @@ public abstract class Component implements PropertiesOwner {
componentMetadataDefinition.getMetadataDataDefinition().setCategorySpecificMetadata(categorySpecificMetadata);
}
+ public String getModel() {
+ return getComponentMetadataDefinition().getMetadataDataDefinition().getModel();
+ }
+
+ public void setModel(final String model) {
+ getComponentMetadataDefinition().getMetadataDataDefinition().setModel(model);
+ }
+
@JsonIgnore
public ComponentMetadataDefinition getComponentMetadataDefinition() {
return componentMetadataDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java
index d6151c3d78..752fad2278 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java
@@ -35,15 +35,17 @@ public class UploadResourceInfo {
private List<UploadArtifactInfo> artifactList;
private String contactId, name, resourceIconPath, icon, vendorName, vendorRelease, resourceVendorModelNumber;
private String resourceType = "VFC";
+ private String model;
public UploadResourceInfo(String payload, String payloadName, String description, String category, List<String> tags,
- List<UploadArtifactInfo> artifactsList) {
+ List<UploadArtifactInfo> artifactsList, String modelName) {
super();
this.payloadData = payload;
this.payloadName = payloadName;
this.description = description;
this.tags = tags;
this.artifactList = artifactsList;
+ this.model = modelName;
if (category != null) {
String[] arr = category.split("/");
if (arr.length >= 2) {
@@ -101,6 +103,14 @@ public class UploadResourceInfo {
this.artifactList = artifactsList;
}
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(final String model) {
+ this.model = model;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@@ -116,6 +126,7 @@ public class UploadResourceInfo {
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
result = prime * result + ((vendorName == null) ? 0 : vendorName.hashCode());
result = prime * result + ((vendorRelease == null) ? 0 : vendorRelease.hashCode());
+ result = prime * result + ((model == null) ? 0 : model.hashCode());
result = prime * result + ((resourceVendorModelNumber == null) ? 0 : resourceVendorModelNumber.hashCode());
return result;
}
@@ -195,6 +206,13 @@ public class UploadResourceInfo {
} else if (!tags.equals(other.tags)) {
return false;
}
+ if (model == null) {
+ if (other.model != null) {
+ return false;
+ }
+ } else if (!model.equals(other.model)) {
+ return false;
+ }
if (vendorName == null) {
if (other.vendorName != null) {
return false;
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 c176ec812b..38fb83bcf2 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
@@ -59,6 +59,7 @@ public abstract class ToscaElement {
private Map<String, MapPropertiesDataDefinition> capabilitiesProperties;
private Map<String, ListRequirementDataDefinition> requirements;
private Map<String, DataTypeDataDefinition> dataTypes;
+ private String model;
// User
private String creatorUserId;
private String creatorFullName;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
index 3369d65f76..21c25a2289 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
@@ -137,6 +137,11 @@ public class NodeTypeOperation extends ToscaElementOperation {
if (addAdditionalInformation != StorageOperationStatus.OK) {
return Either.right(addAdditionalInformation);
}
+ final StorageOperationStatus associateNodeTypeToModel = associateResourceMetadataToModel(nodeTypeVertex, nodeType);
+ if (associateNodeTypeToModel != StorageOperationStatus.OK) {
+ return Either.right(associateNodeTypeToModel);
+ }
+
return Either.left(nodeType);
}
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 884f040d07..eb85090755 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
@@ -73,8 +73,10 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
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.datamodel.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier;
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.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
@@ -95,6 +97,8 @@ public abstract class ToscaElementOperation extends BaseOperation {
private static Logger log = Logger.getLogger(ToscaElementOperation.class.getName());
@Autowired
protected CategoryOperation categoryOperation;
+ @Autowired
+ protected ModelOperation modelOperation;
public static DataTypeDefinition createDataType(final String dataTypeName) {
final DataTypeDefinition dataType = new DataTypeDefinition();
@@ -339,6 +343,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_ARCHIVED));
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.ARCHIVE_TIME, toscaElement.getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_VSP_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.MODEL, toscaElement.getMetadataValue(JsonPresentationFields.MODEL));
toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null)
.forEach(e -> nodeTypeVertex.setJsonMetadataField(e.getKey(), e.getValue()));
nodeTypeVertex.setUniqueId(toscaElement.getUniqueId());
@@ -420,6 +425,29 @@ public abstract class ToscaElementOperation extends BaseOperation {
return StorageOperationStatus.OK;
}
+ protected StorageOperationStatus associateResourceMetadataToModel(final GraphVertex nodeTypeVertex, final ToscaElement nodeType) {
+ if (nodeType.getMetadataValue(JsonPresentationFields.MODEL) == null) {
+ return StorageOperationStatus.OK;
+ }
+ final String model = ((String) nodeType.getMetadataValue(JsonPresentationFields.MODEL));
+ final JanusGraphOperationStatus createEdge = janusGraphDao
+ .createEdge(getModelVertex(model), nodeTypeVertex, EdgeLabelEnum.MODEL_ELEMENT, new HashMap<>());
+ if (createEdge != JanusGraphOperationStatus.OK) {
+ log.trace("Failed to associate resource {} to model {}", nodeType.getUniqueId(), model);
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ private GraphVertex getModelVertex(final String modelName) {
+ log.debug("getModelVertex: fetching model {}", modelName);
+ final Optional<GraphVertex> modelVertexByNameOptional = modelOperation.findModelVertexByName(modelName);
+ if (modelVertexByNameOptional.isEmpty()) {
+ throw ModelOperationExceptionSupplier.invalidModel(modelName).get();
+ }
+ return modelVertexByNameOptional.get();
+ }
+
protected Either<GraphVertex, StorageOperationStatus> getResourceCategoryVertex(String elementId, String subcategoryName, String categoryName) {
Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
if (category.isRight()) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 205a48e9b2..814ac01eac 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -39,6 +39,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiPredicate;
@@ -112,7 +113,6 @@ import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData;
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.operations.exception.OperationException;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -348,19 +348,57 @@ public class ToscaOperationFacade {
return ModelConverter.isAtomicComponent(component) ? nodeTypeOperation : topologyTemplateOperation;
}
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceNameAndModel(final String toscaResourceName,
+ final String model) {
+ return getLatestByNameAndModel(toscaResourceName, JsonParseFlagEnum.ParseMetadata, new ComponentParametersView(), model);
+ }
+
+ private <T extends Component> Either<T, StorageOperationStatus> getLatestByNameAndModel(final String nodeName,
+ final JsonParseFlagEnum parseFlag,
+ final ComponentParametersView filter,
+ final String model) {
+ Either<T, StorageOperationStatus> result;
+ final Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ final Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, nodeName);
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ propertiesToMatch.put(GraphPropertyEnum.MODEL, model);
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> highestResources = janusGraphDao
+ .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag);
+ if (highestResources.isRight()) {
+ final JanusGraphOperationStatus status = highestResources.right().value();
+ log.debug("failed to find resource with name {}. status={} ", nodeName, status);
+ result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ return result;
+ }
+ final List<GraphVertex> resources = highestResources.left().value();
+ double version = 0.0;
+ GraphVertex highestResource = null;
+ for (final GraphVertex vertex : resources) {
+ final Object versionObj = vertex.getMetadataProperty(GraphPropertyEnum.VERSION);
+ double resourceVersion = Double.parseDouble((String) versionObj);
+ if (resourceVersion > version) {
+ version = resourceVersion;
+ highestResource = vertex;
+ }
+ }
+ return getToscaElementByOperation(highestResource, filter);
+ }
+
public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
- return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
+ return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, null);
}
public <T extends Component> Either<T, StorageOperationStatus> getFullLatestComponentByToscaResourceName(String toscaResourceName) {
ComponentParametersView fetchAllFilter = new ComponentParametersView();
fetchAllFilter.setIgnoreServicePath(true);
fetchAllFilter.setIgnoreCapabiltyProperties(false);
- return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, JsonParseFlagEnum.ParseAll, fetchAllFilter);
+ return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, JsonParseFlagEnum.ParseAll, fetchAllFilter, null);
}
- public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) {
- return getLatestByName(GraphPropertyEnum.NAME, resourceName);
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName, String modelName) {
+ return getLatestByName(GraphPropertyEnum.NAME, resourceName, modelName);
}
public StorageOperationStatus validateCsarUuidUniqueness(String csarUUID) {
@@ -483,6 +521,25 @@ public class ToscaOperationFacade {
return predicateCriteria;
}
+ public Optional<GraphVertex> isNodeAssociatedToModel(final String model, Resource resource) {
+ return getNodeModelVertices(resource, model);
+ }
+
+ public Optional<GraphVertex> getNodeModelVertices(final Resource resource, final String model) {
+ final Either<GraphVertex, JanusGraphOperationStatus> vertex = janusGraphDao
+ .getVertexById(resource.getUniqueId(), JsonParseFlagEnum.NoParse);
+ if (vertex.isRight() || Objects.isNull(vertex.left().value())) {
+ return Optional.empty();
+ }
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> nodeModelVertices = janusGraphDao
+ .getParentVertices(vertex.left().value(), EdgeLabelEnum.MODEL_ELEMENT, JsonParseFlagEnum.NoParse);
+ if (nodeModelVertices.isRight() || Objects.isNull(nodeModelVertices.left().value())) {
+ return Optional.empty();
+ }
+ return nodeModelVertices.left().value().stream().filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.NAME).equals(model))
+ .findFirst();
+ }
+
private boolean isValidForVendorRelease(final GraphVertex resource, final String vendorRelease) {
if (!vendorRelease.equals("1.0")) {
try {
@@ -733,18 +790,19 @@ public class ToscaOperationFacade {
}
private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName,
- JsonParseFlagEnum parseFlag) {
- return getLatestByName(property, nodeName, parseFlag, new ComponentParametersView());
+ JsonParseFlagEnum parseFlag, String modelName) {
+ return getLatestByName(property, nodeName, parseFlag, new ComponentParametersView(), modelName);
}
- // endregion
private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName,
- JsonParseFlagEnum parseFlag, ComponentParametersView filter) {
+ JsonParseFlagEnum parseFlag, ComponentParametersView filter,
+ String model) {
Either<T, StorageOperationStatus> result;
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(property, nodeName);
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ propertiesToMatch.put(GraphPropertyEnum.MODEL, model);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
Either<List<GraphVertex>, JanusGraphOperationStatus> highestResources = janusGraphDao
.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag);
@@ -769,8 +827,8 @@ public class ToscaOperationFacade {
}
// region - Component Get By ..
- private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName) {
- return getLatestByName(property, nodeName, JsonParseFlagEnum.ParseMetadata);
+ private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName, String modelName) {
+ return getLatestByName(property, nodeName, JsonParseFlagEnum.ParseMetadata, modelName);
}
public <T extends Component> Either<List<T>, StorageOperationStatus> getBySystemName(ComponentTypeEnum componentType, String systemName) {
@@ -841,8 +899,8 @@ public class ToscaOperationFacade {
}
public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVendorRelease(final ComponentTypeEnum componentType,
- final String name, final String vendorRelease,
- final JsonParseFlagEnum parseFlag) {
+ final String name, final String vendorRelease,
+ final JsonParseFlagEnum parseFlag) {
Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
hasProperties.put(GraphPropertyEnum.NAME, name);
@@ -851,8 +909,8 @@ public class ToscaOperationFacade {
hasProperties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
}
Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = getVendorVersionPredicate(vendorRelease);
- Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao
- .getByCriteria(null, hasProperties, hasNotProperties, predicateCriteria, parseFlag);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao.getByCriteria(null, hasProperties, hasNotProperties,
+ predicateCriteria, parseFlag);
if (getResourceRes.isRight()) {
JanusGraphOperationStatus status = getResourceRes.right().value();
log.debug("failed to find resource with name {}, version {}. Status is {} ", name, predicateCriteria, status);
@@ -2006,16 +2064,11 @@ public class ToscaOperationFacade {
}
return result;
}
-
public Either<Boolean, StorageOperationStatus> validateComponentNameUniqueness(String name, ResourceTypeEnum resourceType,
ComponentTypeEnum componentType) {
- VertexTypeEnum vertexType = ModelConverter.isAtomicComponent(resourceType) ? VertexTypeEnum.NODE_TYPE : VertexTypeEnum.TOPOLOGY_TEMPLATE;
String normalizedName = ValidationUtils.normaliseComponentName(name);
- Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
- properties.put(GraphPropertyEnum.NORMALIZED_NAME, normalizedName);
- properties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
Either<List<GraphVertex>, JanusGraphOperationStatus> vertexEither = janusGraphDao
- .getByCriteria(vertexType, properties, JsonParseFlagEnum.NoParse);
+ .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), JsonParseFlagEnum.NoParse);
if (vertexEither.isRight() && vertexEither.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
log.debug("failed to get vertex from graph with property normalizedName: {}", normalizedName);
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(vertexEither.right().value()));
@@ -2023,6 +2076,41 @@ public class ToscaOperationFacade {
return Either.left(CollectionUtils.isEmpty(vertexEither.isLeft() ? vertexEither.left().value() : null));
}
+ public Either<Boolean, StorageOperationStatus> validateComponentNameAndModelExists(final String resourceName, final String model,
+ final ResourceTypeEnum resourceType,
+ final ComponentTypeEnum componentType) {
+ Either<Boolean, StorageOperationStatus> result = validateComponentNameAndModelUniqueness(resourceName, model, resourceType, componentType);
+ if (result.isLeft()) {
+ result = Either.left(!result.left().value());
+ }
+ return result;
+ }
+
+ private Either<Boolean, StorageOperationStatus> validateComponentNameAndModelUniqueness(final String resourceName, final String modelName,
+ final ResourceTypeEnum resourceType,
+ final ComponentTypeEnum componentType) {
+ final String normalizedName = ValidationUtils.normaliseComponentName(resourceName);
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> vertexEither = janusGraphDao
+ .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), null, null, JsonParseFlagEnum.NoParse);
+ if (vertexEither.isRight() && vertexEither.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
+ log.debug("failed to get vertex from graph with property normalizedName: {} and model: {}", normalizedName, modelName);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(vertexEither.right().value()));
+ }
+ return Either.left(CollectionUtils.isEmpty(vertexEither.isLeft() ? vertexEither.left().value().stream()
+ .filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.NAME).equals(modelName)).collect(Collectors.toList()) : null));
+ }
+
+ private VertexTypeEnum getVertexTypeEnum(final ResourceTypeEnum resourceType) {
+ return ModelConverter.isAtomicComponent(resourceType) ? VertexTypeEnum.NODE_TYPE : VertexTypeEnum.TOPOLOGY_TEMPLATE;
+ }
+
+ private Map<GraphPropertyEnum, Object> propertiesToMatch(final String normalizedName, final ComponentTypeEnum componentType) {
+ final Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
+ properties.put(GraphPropertyEnum.NORMALIZED_NAME, normalizedName);
+ properties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+ return properties;
+ }
+
private void fillNodeTypePropsMap(final Map<GraphPropertyEnum, Object> hasProps, final Map<GraphPropertyEnum, Object> hasNotProps,
final String internalComponentType) {
final Configuration configuration = ConfigurationManager.getConfigurationManager().getConfiguration();
@@ -3242,6 +3330,6 @@ public class ToscaOperationFacade {
}
public <T extends Component> Either<T, StorageOperationStatus> getLatestByServiceName(String serviceName) {
- return getLatestByName(GraphPropertyEnum.NAME, serviceName);
+ return getLatestByName(GraphPropertyEnum.NAME, serviceName, null);
}
}
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 225a068aaf..193270974e 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
@@ -718,6 +718,9 @@ public class ModelConverter {
component.setSystemName((String) toscaElement.getMetadataValue(JsonPresentationFields.SYSTEM_NAME));
component.setDerivedFromGenericType(toscaElement.getDerivedFromGenericType());
component.setDerivedFromGenericVersion(toscaElement.getDerivedFromGenericVersion());
+ if(toscaElement.getModel() != null) {
+ component.setModel(toscaElement.getModel());
+ }
Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
if (MapUtils.isNotEmpty(properties)) {
List<PropertyDefinition> propertiesMap = properties.values().stream().map(x -> new PropertyDefinition(x)).collect(Collectors.toList());
@@ -733,6 +736,7 @@ public class ModelConverter {
resource.setToscaResourceName((String) toscaElement.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
resource.setVendorName((String) toscaElement.getMetadataValue(JsonPresentationFields.VENDOR_NAME));
resource.setVendorRelease((String) toscaElement.getMetadataValue(JsonPresentationFields.VENDOR_RELEASE));
+ resource.setModel((String) toscaElement.getMetadataValue(JsonPresentationFields.MODEL));
// field isn't mandatory , but shouldn't be null(should be an empty string instead)
if (((String) toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER)) != null) {
resource.setResourceVendorModelNumber((String) toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER));
@@ -1294,6 +1298,7 @@ public class ModelConverter {
toscaElement.setMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME, ((Resource) component).getToscaResourceName());
toscaElement.setMetadataValue(JsonPresentationFields.VENDOR_NAME, ((Resource) component).getVendorName());
toscaElement.setMetadataValue(JsonPresentationFields.VENDOR_RELEASE, ((Resource) component).getVendorRelease());
+ toscaElement.setMetadataValue(JsonPresentationFields.MODEL, component.getModel());
// field isn't mandatory , but shouldn't be null(should be an empty string instead)
if (((Resource) component).getResourceVendorModelNumber() != null) {
toscaElement
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java
index 3c8521ae79..4fbb5fbef3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java
@@ -41,6 +41,7 @@ public enum StorageOperationStatus {
OPERATION_NOT_SUPPORTED,
CATEGORY_NOT_FOUND,
PARENT_RESOURCE_NOT_FOUND,
+ MODEL_NOT_FOUND,
MULTIPLE_PARENT_RESOURCE_FOUND,
INCONSISTENCY,
GRAPH_IS_NOT_AVAILABLE,
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java
index 46743565de..7af24fce92 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadResourceInfoTest.java
@@ -36,8 +36,8 @@ public class UploadResourceInfoTest {
@Test
public void testCtor() throws Exception {
- new UploadResourceInfo("mock", "mock", "mock", "mock/mock/mock", new LinkedList<>(), new LinkedList<>());
-
+ new UploadResourceInfo("mock", "mock", "mock", "mock/mock/mock", new LinkedList<>(), new LinkedList<>(),
+ "modelName");
}
@Test
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
index b0f2fa5010..a19e7c431f 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
@@ -263,6 +263,7 @@ public class ToscaOperationFacadeTest {
Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, "toscaResourceName");
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ propertiesToMatch.put(GraphPropertyEnum.MODEL, null);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll))
@@ -441,6 +442,7 @@ public class ToscaOperationFacadeTest {
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ propertiesToMatch.put(GraphPropertyEnum.MODEL, null);
Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/JsonObjectTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/JsonObjectTest.java
index a201b30fd9..787aca1caa 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/JsonObjectTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/JsonObjectTest.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.
@@ -20,46 +20,44 @@
package org.openecomp.sdc.be.model.operations;
+import static org.junit.Assert.assertEquals;
+
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.UploadArtifactInfo;
-import java.io.IOException;
-import java.util.ArrayList;
-
-import static org.junit.Assert.assertEquals;
-
public class JsonObjectTest {
private ObjectMapper mapper;
UploadResourceInfo inputObjectRef;
private final String INPUT_RESOURCE_STRING = "{ \"payloadData\" : \"My Test Object\", \"payloadName\" : \"TestName\", " + " \"description\":\"my_description\",\"tags\":[\"tag1\"], "
- + "\"artifactList\" : [ { \"artifactName\" : \"myArtifact0\", \"artifactPath\" : \"scripts/\", \"artifactType\" : \"PUPPET\", " + " \"artifactDescription\" : \"This is Description\", \"artifactData\" : null }, "
- + "{ \"artifactName\" : \"myArtifact1\", \"artifactPath\" : \"scripts/\", \"artifactType\" : \"PUPPET\", \"artifactDescription\" : \"This is Description\", "
- + " \"artifactData\" : null } ], \"contactId\" : null, \"name\" : null, \"resourceIconPath\" : null, \"vendorName\" : null, \"vendorRelease\" : null , \"resourceType\" : \"VFC\" }";
+ + "\"artifactList\" : [ { \"artifactName\" : \"myArtifact0\", \"artifactPath\" : \"scripts/\", \"artifactType\" : \"PUPPET\", " + " \"artifactDescription\" : \"This is Description\", \"artifactData\" : null }, "
+ + "{ \"artifactName\" : \"myArtifact1\", \"artifactPath\" : \"scripts/\", \"artifactType\" : \"PUPPET\", \"artifactDescription\" : \"This is Description\", "
+ + " \"artifactData\" : null } ], \"contactId\" : null, \"name\" : null, \"resourceIconPath\" : null, \"vendorName\" : null, \"vendorRelease\" : null , \"resourceType\" : \"VFC\", \"model\":\"model1\"}";
@Before
public void setup() {
mapper = new ObjectMapper();
- ArrayList<UploadArtifactInfo> artifactList = new ArrayList<>();
+ final ArrayList<UploadArtifactInfo> artifactList = new ArrayList<>();
for (int i = 0; i < 2; i++) {
UploadArtifactInfo artifactInfo = new UploadArtifactInfo("myArtifact" + i, "scripts/", ArtifactTypeEnum.PUPPET, "This is Description");
artifactList.add(artifactInfo);
}
- ArrayList<String> tags = new ArrayList<>();
- tags.add("tag1");
- inputObjectRef = new UploadResourceInfo("My Test Object", "TestName", "my_description", null, tags, artifactList);
-
+ inputObjectRef = new UploadResourceInfo("My Test Object", "TestName", "my_description", null,
+ Arrays.asList("tag1"), artifactList, "model1");
}
@Test
- public void testStringToUploadResourceInfo() throws JsonParseException, JsonMappingException, IOException {
- UploadResourceInfo resourceObjectTest = mapper.readValue(INPUT_RESOURCE_STRING, UploadResourceInfo.class);
+ public void testStringToUploadResourceInfo() throws IOException {
+ final UploadResourceInfo resourceObjectTest = mapper.readValue(INPUT_RESOURCE_STRING, UploadResourceInfo.class);
assertEquals(inputObjectRef, resourceObjectTest);
}
@@ -72,4 +70,4 @@ public class JsonObjectTest {
assertEquals(unFormattedString, INPUT_RESOURCE_STRING.replace("\n", "").replace("\t", "").replace(" ", ""));
}
-}
+} \ No newline at end of file